Solved PlayerInteractEvent not working with RIGHT_CLICK_AIR?

Discussion in 'Plugin Development' started by Drkmaster83, Jun 29, 2014.

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

    Drkmaster83

    I was trying to make a message send to the player for debug when they right click/left click air on a PlayerInteractEvent but it doesn't seem to want to send - even for the whole event, it will only send when there's a block involved.

    Edit: And I'm feeling crazy because it's quite bizarre and simple, but I'm not sure if it's a bug or if I'm going crazy.
     
  2. Offline

    MCForger

    Drkmaster83
    Could we see the code you wrote for PlayerInteractEvent.
     
  3. Offline

    Drkmaster83

    Code:
    @EventHandler
    public void onPlayerInteract(PlayerInteractEvent event) {
    Player player = event.getPlayer();
    System.out.println("Hello");
    }
    
    Well, after checking, this code will work for left-clicking in the air, just not right-clicking in the air.

    Edit: Don't ask, events are registered and all, and yes I do know Java.
     
  4. Offline

    000nick

    Pretty sure you still have to do "if (event.getAction == Action.RIGHT_CLICK_AIR", and also some null/air checks, too (depending on what your making with this).
     
  5. Offline

    B3N909

    Drkmaster83 000nick
    here is my code that works for me!
    Code:
    public void onPlayerInteract(PlayerInteractEvent event){
    if (event.getAction().toString() == "RIGHT_CLICK_AIR"){
    //DO SOME AMAZING STUFF
    }
    }
    
    the problem is that you need to make it to a string! Also you can do:
    Code:
    if(event.getAction().toString() == "RIGHT_CLICK_AIR" && event.getAction().toString() == "RIGHT_CLICK_BLOCK){
    }
    
    also works to check if the player right clicks air and blocks!
     
  6. Offline

    xTigerRebornx

    B3N909 Don't compare Strings with ==, also, there is no need to turn them into Strings, simply compare them as Enums
     
  7. Offline

    B3N909

    xTigerRebornx I do not know the best way of doing it like you stated... I just got that off another plugin that was using the same was... I needed to know how to use PlayerInteractEvent also and that is the way that I got it working!
     
  8. Offline

    Necrodoom

    B3N909 except it wouldn't work. You just copied this code of a plugin that has bad code, and you are using it because you don't know what it even does.
     
  9. Offline

    Drkmaster83

    But shouldn't PlayerInteractEvent trigger for left-clicking and right-clicking of air and blocks alike? Because it won't trigger for right-clicking air for me. xD
     
  10. B3N909 Using == for Strings will sometimes work but it won't always. Sometimes it'll be false when it should be true. Also, your second one will never work. How can the action be RIGHT_CLICK_AIR and RIGHT_CLICK_BLOCK?
     
  11. Offline

    Drkmaster83

  12. Offline

    fefe2008

    Drkmaster83
    Code:java
    1. @EventHandler
    2. public void onInteract(PlayerInteractEvent e){
    3. if ((e.getAction() == Action.LEFT_CLICK_AIR || (e.getAction() == Action.RIGHT_CLICK_AIR))){
    4. //send your Message or do whatever you want.
    5. }
    6. }
    7.  
    8. //This is untested as I dont have access to eclipse atm

    Im pretty sure i messed up on the () brackets
     
  13. Offline

    Drkmaster83

    Just to clarify, PlayerInteractEvent is firing for ALL Actions except for Action.RIGHT_CLICK_AIR while I have air in my hand. The moment I put any item in my hand, and interact using Action.RIGHT_CLICK_AIR, it will send me my debug messages.
     
  14. Offline

    SpaceManiac

    Yes, this is a limitation of the way the game works and isn't fixable by the server. It's impossible to know when a client has right clicked air when their hand is empty.
     
  15. Offline

    Drkmaster83

    Ultimately, I was modifying code made by a previous developer and he put an EventPriority.HIGHEST modification and ignoreCancelled = true modification on the EventHandler annotation that wouldn't let the event fire on RIGHT_CLICK_AIR with an item in your hand.

    Marking the thread as solved.
     
Thread Status:
Not open for further replies.

Share This Page