Solved Events Triggering Twice

Discussion in 'Spigot Plugin Development' started by Donkelyn, Sep 25, 2019.

  1. So basically, everytime I go to trigger an event, it happens twice. I think it has something to do with the item in my main hand. I'll drop my code below and hope someone can help me out !

    public void onPlayerClicks(PlayerInteractEvent event)
    Player p = event.getPlayer();
    Action a = event.getAction();
    ItemStack iActivate = p.getInventory().getItemInMainHand();
    if (a.equals(Action.RIGHT_CLICK_BLOCK))
    if (iActivate.getType() == Material.BLAZE_ROD )
    if (p.hasPermission("blaze"))
    p.getInventory().addItem(new ItemStack(Material.BLAZE_POWDER,3));
    p.playSound(p.getLocation(), Sound.ENTITY_FIREWORK_ROCKET_BLAST, 1 , 1);
    p.addPotionEffect(new PotionEffect(PotionEffectType.LEVITATION, 20, 20));
    } else
    p.sendMessage("You need to be a blaze to do that!");
  2. It's because the event is being called for each hand (main hand and off hand). Check if event.getHand() is the hand you want.
    • Agree Agree x 1
  3. where do I specify the player then?