Villager Interaction calls twice 1.14.4

Discussion in 'Spigot Plugin Development' started by FlenscrafterHD, Oct 10, 2019 at 12:21 PM.

  1. Hey guys,
    I recently tried to create an gamequeue join fuction.
    If a Player right clicks the villager he joins the gamequeue if he isnt already in the Queue. If he is already in the Queue he should quit.

    But my Problem is that if I right click the villager once I join and quit the Queue in the same time...
    Is it an Bug or something I can fix?

    For understanding purposes:
    Code (Java):
        @EventHandler
        public void onInteract(PlayerInteractEntityEvent e) {
            Player p = e.getPlayer();
           
            if(e.getRightClicked().getType() == EntityType.VILLAGER) {
                Villager vil = (Villager) e.getRightClicked();
                e.setCancelled(true);
                if(vil.getCustomName().equalsIgnoreCase(Main.getPrefix() + Main.getInstance().getMSG(Main.getInstance().cfg.getString("Villager.GameQueue")))) {
                    if(!isInGameQueue(p)){
    GameQueueManager.joinGameQueue(p);
    } else {
    GameQueueManager.quitGameQueue(p);
    }
                }
               }
    }
     
  2. The event is called for each hand. Mainhand and offhand.
     
  3. I would suggest if you have them in a queue just add a timestamp along with them, if its say within 500ms just ignore it? Or like ysl3000 said just ignore any offhand calls, with something like

    Code (Java):
    if (event.getHand() == EquipmentSlot.OFFHAND) {
      return;
    }
     
    • Agree Agree x 1
  4. thanks for your help
     
  5. Thanks you very much!