Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-4177

Plugin previously clearing item displayname with empty string

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • None
    • None
    • This server is running CraftBukkit version git-Spigot-69774b3-ff9bab1 (MC: 1.13) (Implementing API version 1.13-R0.1-SNAPSHOT)
    • Yes

      Plugins might have previously (before 1.13) used both, an empty string and null, to clear the display name of an ItemStack. Now if they use an empty String it will result in an empty ChatComponent (empty display name), while null will actually clear the display name (default item name being displayed then).

      Example: One plugin previously let admins configure an item's display name via the configuration and then simply forward the value of that setting to the following setItemStackName method. An empty string in the config ("") would result in the display name to be cleared. Now it creates an 'empty display name' instead.

      Minimal reproduction plugin:

      package de.blablubbabc.test2;
      
      import org.bukkit.Bukkit;
      import org.bukkit.Material;
      import org.bukkit.entity.Player;
      import org.bukkit.event.EventHandler;
      import org.bukkit.event.Listener;
      import org.bukkit.event.player.PlayerJoinEvent;
      import org.bukkit.inventory.ItemStack;
      import org.bukkit.inventory.meta.ItemMeta;
      import org.bukkit.plugin.java.JavaPlugin;
      
      public class Test extends JavaPlugin implements Listener {
      
      	public static Test INSTANCE = null;
      
      	@Override
      	public void onEnable() {
      		INSTANCE = this;
      		Bukkit.getPluginManager().registerEvents(this, this);
      	}
      
      	@Override
      	public void onDisable() {
      		INSTANCE = null;
      	}
      
      	@EventHandler
      	void onPlayerJoin(PlayerJoinEvent event) {
      		Bukkit.getScheduler().runTaskLater(this, () -> {
      			Player player = event.getPlayer();
      			player.getInventory().addItem(setItemStackName(new ItemStack(Material.BONE, 1), ""));
      		}, 1L);
      	}
      	
      	public static ItemStack setItemStackName(ItemStack item, String displayName) {
      		if (item == null) return null;
      		ItemMeta meta = item.getItemMeta();
      		if (meta != null) {
      			meta.setDisplayName(displayName);
      			item.setItemMeta(meta);
      		}
      		return item;
      	}
      }
      
      name: Test
      version: '1.0'
      description: Testing some stuff
      main: de.blablubbabc.test2.Test
      api-version: '1.13'
      

      This seems to be releated to the discussion inside ticket https://hub.spigotmc.org/jira/browse/SPIGOT-4016, where the behavior was reverted back to both "" and null indicating 'clear the name', I think.

      Between, this behavior must have changed recently. Some pre-release version I tested with before (cannot remember the exact build) was not affected. I assume this change in behavior was introduced by this commit: https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/commits/d4297cbe2d76f6dcd58f00d60de2fd312dedb762

      Bug reports which do not 1) contain a declaration of testing in Vanilla and without plugins, or 2) in the case of plugin API bugs, contain a minimal reproduction case (source + jar please) will be closed. Bug reports must contain step by step instructions to reproduce the bug from a clean server install with no assumptions or prior knowledge. Also make sure you include the full output of /version in your report. Please copy and paste this statement to the bottom of your report to indicate that you have read and understood it.
      

            Unassigned Unassigned
            blablubbabc blablubbabc
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: