Solved How to identify custom item which in my hand

Discussion in 'Plugin Development' started by chanCraft, Dec 6, 2019.

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

    chanCraft

    Code:
    ItemStack diamondExplorer_Stack = new ItemStack(Material.DIAMOND);
        ItemMeta diamondExplorer_Meta = diamondExplorer_Stack.getItemMeta();
        String diamondExplorer_Name = "diamond explorer";
      
        public void onEnable() {
          
            CustomItemCreation();
          
          
        }
        void CustomItemCreation()
        {
            diamondExplorer_Meta.setDisplayName(diamondExplorer_Name);
            diamondExplorer_Meta.setLore(Arrays.asList("diamond"));
          
            diamondExplorer_Stack.setItemMeta(diamondExplorer_Meta);
          
        }
      
        public void onPlayerJoin(PlayerJoinEvent event)
        {
            Player player = event.getPlayer();
          
            player.getInventory().addItem(diamondExplorer_Stack);
        }
      
        public void onRightClick(PlayerInteractEvent event)
        {
            Player player = event.getPlayer();
            if(event.getAction() == Action.RIGHT_CLICK_AIR)
            {
                if(player.getInventory().getItemInMainHand().getItemMeta().getDisplayName() == diamondExplorer_Name)
                {
                    Bukkit.getServer().broadcastMessage("right button Click");
                }
                else
                {
                    Bukkit.getServer().broadcastMessage("NO");
                }
                  
              
            }
        }
    i call this class from another main class

    i made a custom item which form diamond and i want to announce message when i holding custom item and press the right click

    but if i just right click holding original diamond at least once
    that's always announce message "NO" even i holding custom item


    i spend a few hours to fix them but i don't caught what is my problem as code
     
  2. Offline

    timtower Moderator Moderator

    @chanCraft no need for the onEnable if it isn't the main class.
    You are missing the @EventHandlers
    Strings are compared with equals and equalsIgnoreCase, not with ==
     
    chanCraft likes this.
  3. Offline

    chanCraft

    thanks a lot!
     
Thread Status:
Not open for further replies.

Share This Page