Solved Player looking at block

Discussion in 'Plugin Development' started by Dagovrek222, May 15, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    Dagovrek222

    Hey,

    I am trying to make a plugin where I want to summon a lightningbolt at the location a player is looking.
    As far as I could find this code should work:
    Code:
    Player p = event.getPlayer();
    p.getWorld().strikeLightning(p.getTargetBlock(null, 200).getLocation());
    However, I get an error at "getTargetBlock(null, 200)"
    This is the error:
    I dont really know what I should do with this. I hope anyone knows how I can fix this.
     

    Attached Files:

  2. Offline

    I Al Istannen

    @Dagovrek222
    There are two methods:
    getTargetBlock(HashSet<Byte> transparent, int maxDistance)
    and
    getTargetBlock(Set<Material> transparent, int maxDistance)
    Now, the only thing different is the first argument "transparent". If you pass an HashSet<Byte>, the first method gets called. If you pass a Set<Material> the second one will be called.
    "null" however is no type. It can be both. So the program doesn't know what to call. This creates the error "is ambiguous", because it is.

    To solve it, you will need to tell exactly what type the first argument is. You cast it to the specified type. If you want to call the first, you write "(HashSet<Byte>) null", for the second "(Set<Material>) null".
     
    Last edited: May 17, 2016
    Dagovrek222 likes this.
  3. Offline

    Dagovrek222

    Thank you very much :)
     
  4. Offline

    I Al Istannen

    @Dagovrek222
    Just realized, welcome to the forum ;)
    If you want the other person to see what you wrote, "Tahg" them by writing "@" and then the name (like I did) or clicking the "Tahg User" button on the right bottom of every post. The other way is quoting them / liking the post. To quote, just select something they wrote and click on "+Quote". Then, at the bottom of the page, where you write your answer, click "Insert Quotes".

    Glad I could help ;)
     
    Last edited: May 15, 2016
    Dagovrek222 likes this.
Thread Status:
Not open for further replies.

Share This Page