Door Location Matching

Discussion in 'Spigot Plugin Development' started by Arjan, Jan 23, 2016.

  1. Hello,

    This issue might be relatively easy to solve however, I've been breaking my neck all over this issue for the past couple of hours so I might have overlooked something.

    I have an in game system to add door location to a system so players can buy doors and have them 'private'.
    But the issue is, I can either click the top or bottom half of the door when creating it, which results in different locations (y+1 or y-1). Now, I'm trying to make it so that it will match the location with the one in the database with the door location that was tried to open. But, I feel like this is working although sometimes when I click the door I get a nullpointerexception.
    I've added this fairly simple line to the interaction event:
    Code (Text):
    System.out.println(event.getClickedBlock().getType().toString());
    Sometimes it says WOODEN_DOOR, but sometimes it also returns the nullpointerexception.

    This is an issue that I do not know how to tackle and Im pretty confused with why its throwing these errors.

    P.S. Most of the time the error occurs when clicking the top half of the door.

    Regards,
    Arjan
     
  2. It usually occurs on the top half of the door but it doesnt always return a nullpointer, while I'm most definetely interacting with the door and not something else.
     
  3. Post your whole EventHandler.
     
  4. It's literally only the player interact event with the output code.
     
  5. @Arjan a PlayerInteractEvent doesn't always have a block. If, for example, you click the air the block will be null and an NPE wíll be thrown.
     
  6. Well, I can see the 'hitbox' of the top part of the door when I click it.
     
  7. You might be double clicking or hell knows what. Be sure that the action equals RIGHT_CLICK_BLOCK.