Add effective name to ItemStack (#11770)

This commit is contained in:
masmc05
2024-12-25 22:56:24 +02:00
committed by GitHub
parent 140577b762
commit a07cec16f8
2 changed files with 20 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import com.google.common.collect.ImmutableMap;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
@ -710,6 +711,17 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, Translat
return Bukkit.getServer().getItemFactory().displayName(this);
}
/**
* Gets the effective name of this item stack shown to player in inventory.
* It takes into account the display name (with italics) from the item meta,
* the potion effect, translatable name, rarity etc.
*
* @return the effective name of this item stack
*/
public @NotNull Component effectiveName() {
return this.craftDelegate.effectiveName();
}
/**
* Minecraft updates are converting simple item stacks into more complex NBT oriented Item Stacks.
*