How to cancel Firework launch event?

Discussion in 'Spigot Plugin Development' started by Smily420, May 5, 2017.

Thread Status:
Not open for further replies.
  1. This is the code I have right now but it dosen't seem to be working.
    Code (Text):
        @EventHandler
        public void FireWorkLaunch (PlayerInteractEvent e) {
            Player p = e.getPlayer();
            if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
                if (p.getItemInHand().equals(Material.FIREWORK) && (p.getItemInHand().getItemMeta().getDisplayName().contains("Kangaroo"))) {
                    e.setCancelled(true);
                    return;
                }
            }
           
        }
     
  2. You do not want to do .equals you should do:

    Code (Text):
        public void fireWorkLaunch(PlayerInteractEvent e) {
            Player p = e.getPlayer();
            if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
                if (p.getItemInHand().getType() == Material.FIREWORK
                        && p.getItemInHand().getItemMeta().getDisplayName().contains("Kangaroo")) {
                    e.setCancelled(true);
                    return;
                }
            }
        }
     
  3. Are you registering the listener class this is in?
     
  4. Thanks, It works!
    Yes
     
Thread Status:
Not open for further replies.