Solved RIGHT_CLICK_BLOCK is called twice in PlayerInteractEvent

Discussion in 'Plugin Development' started by nirpisa201, Apr 26, 2016.

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


        public void PlayerClickBlock(PlayerInteractEvent event){
            Player p = event.getPlayer();
            if(event.getAction() == Action.LEFT_CLICK_BLOCK){
            }else if(event.getAction() == Action.RIGHT_CLICK_BLOCK){
    When I right click, I get "right" twice
    Any suggestions?
  2. Online

    timtower Moderator Moderator

  3. Offline


    You are making this run twice. your saying if it isnt not a left click then send the message "right", also your saying if the player right clicks the air then send them the message "right".
    Try to remove the "else" and just create another if like this.
    1. if(event.getAction() == Action.LEFT_CLICK_BLOCK){
    2. p.sendMessage("left");
    3. }
    4. if(event.getAction() == Action.RIGHT_CLICK_BLOCK){
    5. p.sendMessage("right");
    6. }
    7. }
  4. Offline


    @nirpisa201 Someone said here that in 1.9 the event gets called twice for right click for the off hand (the "left" one)
    If you're not in 1.9 then your mouse is a bad person, you registered the listener twice or there is another event handler being a horrible person.

    @krizzdawg The else is perfectly fine there the code won't get executed twice since the second if is part of the else
  5. Offline


    @nirpisa201 I just had the same issue, and after looking it up I found out how to fix it.

        public void onPlayerInteract(PlayerInteractEvent event) {
            EquipmentSlot e = event.getHand(); //Get the hand of the event and set it to 'e'.
            if (e.equals(EquipmentSlot.HAND)) { //If the event is fired by HAND (main hand)
               //Do stuff
    nahkd123 likes this.
  6. Offline


    @Cosmicluck there is no function "getHand()" in PlayerInteractEvent
  7. Offline


    Are you using 1.9? Cause I had the same issue with 1.9 and that fixed it.
  8. Offline


    Yes I am using spigot server for minecraft 1.9
  9. Offline

    I Al Istannen

    Do you have a 1.9 Spigot jar in the Build Path? (In eclipse: Right click Project -> Properties -> "Java Build Path" on the left -> "Libraries" tab and then look there.

    It is definitly there in 1.9, as you can see here.
  10. Offline


Thread Status:
Not open for further replies.

Share This Page