Getting custom item display name not working

Discussion in 'Plugin Development' started by revivedbear, Nov 20, 2017.

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

    revivedbear

    I have a piece of paper with a custom display name and I am trying to display that name (if it is in the player's hand, hence cursor) to the player with

    human.sendMessage(ChatColor.BLUE+ cursor.getItemMeta().getDisplayName());

    however, this just returns null
     
  2. Offline

    MightyOne

    show your code or we can not do anything for you.
     
  3. Offline

    revivedbear

    Code:
    @EventHandler(priority = EventPriority.NORMAL)
        public void onInventoryClick(InventoryClickEvent event) {
            HumanEntity human = event.getWhoClicked();
            ItemStack current = event.getCurrentItem();
            ItemStack cursor = event.getCursor();
    
            if(human instanceof Player && event.getAction() == InventoryAction.SWAP_WITH_CURSOR) {
                if(cursor.getType() == Material.NETHER_STAR) {
                    event.setCancelled(true);
                }
             
                if(current.getType() == Material.NETHER_STAR) {
           
                   
                    List<String> list = new ArrayList<String>();
                    ItemMeta itemmeta = cursor.getItemMeta();
                   
                    human.sendMessage(ChatColor.BLUE+ itemmeta.getDisplayName());
                   
                    list.add("certificate");
                    if(itemmeta.getDisplayName()=="police application"){
                        itemmeta.setDisplayName("poilce certificate");
                        itemmeta.setLore(list);
                        cursor.setItemMeta(itemmeta);
    
    So basically this checks if the player has clicked on a nether star in a chest with an item, if the display name of the item is "police application" then I want to change the name, however it doesn't change the name even if it is the correct name.
     
  4. Offline

    MightyOne

    You can not compare to Strings with ==. Use .equals (). AFAIK only Players can click so basically just get the player who clicked instead of HumanEntity
     
Thread Status:
Not open for further replies.

Share This Page