PlayerInteractEvent fired twice when opening a door

Discussion in 'Plugin Development' started by The_Spaceman, Jun 4, 2018.

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

    The_Spaceman

    When I open a door this event gets fired twice

    event:
    Code:
    
    @EventHandler@SuppressWarnings("unused")
    public void click(PlayerInteractEvent e) {
    
    System.out.println("event"); if (e.getAction().equals(Action.RIGHT_CLICK_AIR) ||
    !e.getAction().equals(Action.RIGHT_CLICK_BLOCK) ||
    !isSpecialBlock(e.getClickedBlock()) ||
    e.getPlayer().isSneaking()) {
    
    
    ItemStack is = e.getPlayer().getInventory().getItemInMainHand();
        if (openCompass(e.getPlayer(), is)) {
            e.setCancelled(true);}
        }
    }
    
    private boolean isSpecialBlock(Block block) {
    
    if (block.getState() instanceof InventoryHolder) {
    return true;
    }
    else if (block.getType().toString().contains("DOOR")) {
    return true;
    }
    
    return false;}
    
    //openCompass
    
    how should i fix this?
     
  2. Offline

    timtower Administrator Administrator Moderator

    @The_Spaceman Check the users hand, it fires for the main and offhand.
     
  3. Offline

    SavageAvocado

    Check is the player is using their main hand.

    Code:
    if(e.getHand() != EquipmentSlot.HAND) return;
     
  4. Offline

    The_Spaceman

    @timtower and @SavageAvocado

    tried it and it didn't work, but for some reason it works fine now. I have no idea what i have done to fix it...
     
  5. Offline

    timtower Administrator Administrator Moderator

Thread Status:
Not open for further replies.

Share This Page