[SOLVED] PlayerInteractEvent can't trigger twice

Discussion in 'Programming' started by Hukuzard, Feb 23, 2020.

  1. Good morning, everyone.

    I'm encountering a small problem on my plugin. The idea is to be able to perform a particular action when a player clicks on his feet. To do this, I subscribe to the PlayerInteractEvent like this

    Code (Java):

        @EventHandler
        void onPlayerInteract(PlayerInteractEvent playerInteractEvent) {
            Player player = playerInteractEvent.getPlayer();

            this.ifHand(playerInteractEvent.getHand(), () -> {
                if (Games.hasItemInHand(player, Games.ITEM_COMMAND, GameCommand.CommandLabel.WW)) {
                    playerInteractEvent.setCancelled(true);
                    playerInteractEvent.getPlayer().performCommand(GameCommand.CommandLabel.WW.name().toLowerCase());
                } else {
                    Games.applyOnTarget(player, target -> this.interaction(player, target, playerInteractEvent)); //<= the event is canceled in the "interaction" method
                }
            });
        }

    (The ifHand method just allows me to avoid triggering the event twice).

    Here's the problem: when I perform this action the first time, everything goes well: I have my whole scenario running. However, the second time, nothing happens (even if I put a logger at the start of the method, nothing is displayed) and I don't have a stack displayed.

    Thank you in advance for your answers.

    Update: this problem does not appear when I levitate. It occurs only when I click on a block.
     
    #1 Hukuzard, Feb 23, 2020
    Last edited: Feb 23, 2020
  2. Update : NVM, just found that the first event was, indeed, PlayerInteractEvent , but the second one was
    EntityDamageByEntityEvent because I had set up an invisible armorstand on the player...