Solved setDisplayName() not working

Discussion in 'Plugin Development' started by HawKyre, Jun 14, 2019 at 3:39 AM.

  1. Offline


    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.
    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 Ninja on the waves Moderator

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


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

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

    timtower Ninja on the waves Moderator

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


    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


    Oh, thanks guys ^^

Share This Page