Duplicate message on event

Discussion in 'Bukkit Help' started by Sckoco, Mar 14, 2020.

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

    Sckoco

    Hey guys !

    I have this strange problem happening everytime I do a PlayerInteractEntityEvent.
    To be clear, I'm trying to send a message to a player when he does a right click on a villager. But everytime, I do it, I receive the message two times...

    Is there a solution for this ?

    Here is my code :

    Code:
    public void onInteract(PlayerInteractEntityEvent event) {
        Player player = event.getPlayer();
        Entity entity = event.getRightClicked();
        if(entity instanceof Villager) {
            Villager villager = (Villager) entity;
            String name = villager.getCustomName();
            player.sendMessage(main.getConfig().getConfigurationSection("quetes").getString(name+".q1"));
        }
    }
     
  2. Online

    timtower Administrator Administrator Moderator

    @Sckoco Did you register the event twice?
     
  3. Offline

    Sckoco

    What do you mean by register the event twice ?

    This event is the only I have on my plugin at the moment
     
  4. Offline

    Sensevx

    PlayerInteractEvent calls for two hands, both off-hand and main hand so you need to check which hand.

    Code:
    if (e.getHand() == EquipmentSlot.HAND) {
        // ... Your code with test
    }
     
  5. Online

    timtower Administrator Administrator Moderator

    @Sckoco Please post your main class and the listener class (if it is not the same one)
     
    Last edited: Mar 14, 2020
  6. Offline

    Sckoco

    Here is the two classes you asked

    There is french in the code because I'm a belgian guy ^^
     

    Attached Files:

  7. Online

    timtower Administrator Administrator Moderator

    @Sckoco Then you might indeed want to check the hand being used by the player.
     
  8. Offline

    Sckoco

    The message appears one time now !
    Thanks for your help
     
  9. Offline

    Machine Maker

    Please mark this thread as Solved if your issue has been resolved.
     
Thread Status:
Not open for further replies.

Share This Page