1.8.8 PlayerInteractEvent Right click on display name on item Getting error on console, help me xd.

Discussion in 'Spigot Plugin Development' started by DevelopmentHigh, Apr 2, 2020.


  1. Can someone explain why i getting eror when on console right click on air or block without a book item?
    And make code for me if you want to help (like this without error)

    Error:


    Code (Java):

    public class Naklik implements Listener {
       
       
        String prefix = ChatColor.translateAlternateColorCodes('&', "&8[&aKothListener&8] &9");
       
       
             
           
            @EventHandler
            public void interakt(PlayerInteractEvent event) {

                Player player = event.getPlayer();
               
               
               
                if(event.getAction() == Action.RIGHT_CLICK_AIR | event.getAction() == Action.RIGHT_CLICK_BLOCK){
                   
                    if(player.getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase("§c§lCapper rank")) {
                       
                        if(!(event.getPlayer().getItemInHand().getType() == Material.BOOK)){
                           
                            return;
                           
                        }
                       
                       
                        Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "setrank " + event.getPlayer().getName() + " capper 86400");
                       
                       
                       
                        return;
                    }
                   
                }
               
                       
            }
     

    Attached Files:

  2. Btw i learning java, i quit java 4 years ago and i again going to learn xd
    sry for bad english
     
  3. You have to check if the item in hand is null first.
    Code (Java):
    if (event.hasItem()) { ...
    Also, I recommend you to name your classes and methods with English names.
    It's totally fine to give message output to players and server in your language, but keep it international for everything else :)