Solved Error when getting players location (Reach Check)

Discussion in 'Spigot Plugin Development' started by Lookups, Jun 25, 2018.

  1. Well, I can't tell without more code (there's not enough info with just that class to tell), but it's an NPE, so that means something in the operations of line 29 is null.

    Let's examine what those could be (learning how to tell (AKA guess) what's null in a line is a valuable skill).

    Because the null occurs at line 29, and not later, we can infer that the null is something used in the creation of the Util, not just that the resulting Util is the only thing that's null.

    That leaves one of these two things:
    - user.getPlayer().getLocation()
    - entity.getLocation()

    Those are the two arguments given to create the Util, and so are 99.9% the cause of the NPE.
    entity.getLocation() I believe refers to an event, since the stack trace lists "HitListener" as the next class down in the list, which sounds like an event listener.

    So, it's possible that the entity, whatever it is, from "entity.getLocation()" either doesn't have a location or just doesn't exist.

    The second possiblity is that user.getPlayer().getLocation() is the problem. That has two parts. Either the user.getPlayer() is returning a null (no value for it), or the user.getPlayer() is fine, but trying to get that player's location is null. Odds are, it's not getPlayer().getLocation(), as there's relatively few times where doing getLocation() on a player returns a null.

    By process of elimination, that leaves user.getPlayer() as the likely cause, if user.getPlayer().getLocation() is the cause.

    End result: Odds are, either "user.getPlayer()", or "entity.getLocation()" is returning a null. Track those calls back in your plugin, and see if either is null (if statements may be helpful here ;) ).

    Let me know once you figured out which one, and if you still need help on fixing it!
  2. Thank you for the quick response. I'm currently trying to resolve the issue with what you said.
    I'm also currently trying to test the anticheat with a official build of Spigot.
    I'll keep you up to date.
    • Like Like x 1
  3. Okay, i've tested it: It was because of the spigot.
    Now i'm here with another issue:
    I'm having a EE (EventException) from player.player
    File where i declarated player:
  4. Mind sending me the error?

    Also, a quick code-efficiency thing: You've got a lot of repeated calls in there that would be more efficient if done ahead of time. Try getting the player's name as a string, and use the string instead of continuously using player.getName().

    Likewise, try storing the plugin config in a FileConfiguration variable, and reference that variable instead of using getConfig() each time.

    These are all fairly common mistakes, and won't cause too many problems now, but when the plugins get bigger and the code gets more complicated, they can cause some issues with both readability and efficiency in the plugin :)
  5. JanTuck


    The JIT is pretty good at asking care of the efficiency issues. But readability might improve yes.
  6. Is that really an optimization that JIT compilation is capable of doing? I know they've gotten pretty smart with it, but I thought that repeated calls like that(in this case, player.getName() or plugin.getConfig()) couldn't be assumed to return the same result each time, and thus had to be left as-is?

    After all, it's exceptionally hard to tell for certain that the operations between those calls wouldn't impact those variables. It's possible for a person to tell, but can JIT really check that itself?
  7. For methods that get called multiple times as OP has done, I wouldn't be surprised to see it get inlined