Solved Why is this launching two times?

Discussion in 'Plugin Development' started by AnOrangeGamer, Aug 6, 2015.

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

    AnOrangeGamer

    So I'm making a grenade plugin and for some odd reason this event launches two times.

    Code:
      
    @EventHandler
        public void onPlayerInteract(PlayerInteractEvent e) {
            Player p = (Player) e.getPlayer();
            if(p.getItemInHand().getType() != Material.SNOW_BALL) return;
            ItemStack s = p.getItemInHand();
            ItemMeta sm = s.getItemMeta();
            if(sm.getDisplayName() == null) return;
            if(!sm.getDisplayName().equalsIgnoreCase("High Explosive Grenade")) return;
            Snowball sn = p.launchProjectile(Snowball.class);
            sn.setShooter(p);
          
            ItemStack snow = new ItemStack(Material.SNOW_BALL, 1);
            ItemMeta snowm = snow.getItemMeta();
            snowm.setDisplayName("High Explosive Grenade");
            snow.setItemMeta(snowm);
          
            p.getInventory().removeItem(snow);
            p.getWorld().playSound(p.getLocation(), Sound.BAT_TAKEOFF, 10.0F, 1.0F);
            snowballs.add(sn);
            e.setCancelled(true);
        }
    
    When I do this, sure it cancels the event, but for some reason it launches two snowballs and takes away two snowballs from my inventory. It's as if the event is launching twice. Why is this?
    Thanks.
     
  2. Offline

    Timbals

    Can you show us the code where you register the event? And please double check if you are somehow registering the event multiple times.
     
    AnOrangeGamer likes this.
  3. Offline

    AnOrangeGamer

    Stupid me was being stupid. Registered the event twice, hadn't thought about it until now. Thanks for bringing it to my mind.
     
Thread Status:
Not open for further replies.

Share This Page