Removing Custom Named items

Discussion in 'Spigot Plugin Development' started by PracticalX, May 13, 2017.

  1. Hello! Currently my code does not work, I'm trying to make it so whenever I right-click a book named Unique Enchantment Book, it runs a code.. But if its a normal book it does not..

    This currently does not work, its my code..

    Code (Text):
    @EventHandler(priority=EventPriority.HIGH)
            public void onPlayerUse(PlayerInteractEvent event){
                Player p = event.getPlayer();
               if(event.getAction().equals(Action.RIGHT_CLICK_AIR)){
                  ItemStack i = p.getItemInHand();
                  ItemMeta im = i.getItemMeta();
                  if (im.getDisplayName().equalsIgnoreCase("§e§lUnique Enchant Book")) {
                      p.getInventory().removeItem(p.getInventory().getItemInHand());
                  }
               }
            }
     
     
  2. Did you register the listener? Or does the event even fire?

    May after you remove the item use p.updateInventory()
     
  3. And may just use p.setItemInHand(null); should work too
     
  4. Yes, listeners are implemented, and I changed it to null :D