Solved Getting messages twice when right clicking endercrystal?

Discussion in 'Spigot Plugin Development' started by FroZenKeyboard, May 1, 2017.

  1. So i got this code:

    Code (Text):
        @EventHandler
        public void onInteract(PlayerInteractEntityEvent e) {
           
            if(e.getRightClicked().getType() == EntityType.ENDER_CRYSTAL) {
                if(points.getInt("points." + e.getPlayer().getUniqueId()) == 0) {
                    e.getPlayer().sendMessage(Crates + "§5You got no points!");
                }else if(points.getInt("points." + e.getPlayer().getUniqueId()) > 0) {
                    playCrateEffects(e.getPlayer());
                        int kills = points.getInt("points." + e.getPlayer().getUniqueId());
                        points.set("points." + e.getPlayer().getUniqueId(), Integer.valueOf(kills - 1));
                        e.getPlayer().sendMessage("§7T");
                      try {
                        points.save(file);
                      } catch (IOException e1) {
                        e1.printStackTrace();
                      }
                }
            }
                }
    And everytime i click the ender crystal, it sends the "T" message twice. I know it's the 1.9 update, two hands. But i found nothing that really helped.

    Thanks.
     
  2. Because sometime the event is fired twice, once every hand. Maybe you can do a short cooldown using a Set<Player> and a bukkitRunnable
     
  3. I know why it's comming. And how could a runnable fix that?
     
  4. BananaPuncher714

    Supporter

    Use e.getHand() to determine which one is right clicking. There's this thing called Google that gives answers to those who look.
    Code (Text):
    if ( !e.getHand().equals( EquipmentSlot.HAND ) ) return;
    That returns if they player isn't using their main hand.
     
    • Winner Winner x 1
    • Useful Useful x 1
  5. Umh, seems like this is a better way.
     
    • Like Like x 1
  6. Thank you! It worked, thanks to @BananaPuncher714!
     
    • Like Like x 1