Solved setDisplayName() not working

Discussion in 'Plugin Development' started by HawKyre, Jun 14, 2019.

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

    HawKyre

    Hey there, I'm trying to make a little program for which I need to get the display name of an ItemStack.
    I tried doing the following, but the get method send a blank string to the console.
    Code:
    item.getItemMeta().setDisplayName("The beginner's axe");
           
    Bukkit.getConsoleSender().sendMessage( ChatColor.RED + item.getItemMeta().getDisplayName() );
    This is obviously not the functionality that I want in my program, but I think it's a better way of presenting the problem. Any help on this? I can't really see why that wouldn't work...
     
  2. Offline

    timtower Administrator Administrator Moderator

    @HawKyre Get the ItemMeta.
    Apply the display name.
    Set the ItemMeta to the ItemStack again
     
  3. Offline

    HawKyre

    Oh, so the ItemMeta isn't settable attribute by attribute? Why is that?

    It works, so thanks a lot ^^
     
  4. Offline

    timtower Administrator Administrator Moderator

    Believe that getItemMeta() returns a copy.
     
  5. Offline

    KarimAKL

    Code:Java
    1. @Nullable
    2. public ItemMeta getItemMeta() {
    3. return this.meta == null ? Bukkit.getItemFactory().getItemMeta(this.type) : this.meta.clone();
    4. }

    Yeah, it returns a clone.
     
  6. Offline

    HawKyre

    Oh, thanks guys ^^
     
Thread Status:
Not open for further replies.

Share This Page