diff --git a/src/main/java/world/bentobox/level/Level.java b/src/main/java/world/bentobox/level/Level.java index bfb89d3..96a2cf6 100644 --- a/src/main/java/world/bentobox/level/Level.java +++ b/src/main/java/world/bentobox/level/Level.java @@ -25,6 +25,7 @@ import world.bentobox.bentobox.api.flags.Flag; import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.database.objects.Island; +import world.bentobox.bentobox.hooks.CraftEngineHook; import world.bentobox.bentobox.hooks.ItemsAdderHook; import world.bentobox.bentobox.hooks.OraxenHook; import world.bentobox.bentobox.managers.RanksManager; @@ -516,12 +517,13 @@ public boolean isItemsAdder() { /** * Returns the custom-block plugin ID for an ItemStack, checking Oraxen, Nexo, - * and ItemsAdder in that order. Returns {@code null} when the item is not - * recognized as a custom block by any supported plugin. + * ItemsAdder, and CraftEngine in that order. Returns {@code null} when the item + * is not recognized as a custom block by any supported plugin. * * @param item the ItemStack to check (may be null) * @return a namespaced custom-block ID such as {@code "oraxen:my_block"}, - * {@code "nexo:my_block"}, or an ItemsAdder ID, or {@code null} + * {@code "nexo:my_block"}, an ItemsAdder ID, or a CraftEngine ID + * (e.g. {@code "default:my_block"}), or {@code null} */ @Nullable public String getCustomBlockId(ItemStack item) { @@ -549,6 +551,13 @@ public String getCustomBlockId(ItemStack item) { return id.get(); } } + // Check CraftEngine — IDs are already namespaced (e.g. "mynamespace:my_block") + if (isCraftEngine()) { + String id = CraftEngineHook.getItemId(item); + if (id != null) { + return id; + } + } return null; } diff --git a/src/main/java/world/bentobox/level/commands/IslandValueCommand.java b/src/main/java/world/bentobox/level/commands/IslandValueCommand.java index 3501911..098d0f2 100644 --- a/src/main/java/world/bentobox/level/commands/IslandValueCommand.java +++ b/src/main/java/world/bentobox/level/commands/IslandValueCommand.java @@ -107,14 +107,18 @@ private void printValue(User user, Object material) if (value != null) { + String displayName = (material instanceof String id) + ? Utils.getCustomBlockDisplayName(Utils.getCustomBlockItemStack(addon, id), id, user) + : Utils.prettifyObject(material, user); + Utils.sendMessage(user, user.getTranslation(this.getWorld(), "level.conversations.value", "[value]", - String.valueOf(value), MATERIAL, Utils.prettifyObject(material, user))); + String.valueOf(value), MATERIAL, displayName)); double underWater = this.addon.getSettings().getUnderWaterMultiplier(); if (underWater > 1.0) { Utils.sendMessage(user, user.getTranslation(this.getWorld(), "level.conversations.success-underwater", - "[value]", (underWater * value) + ""), MATERIAL, Utils.prettifyObject(material, user)); + "[value]", (underWater * value) + ""), MATERIAL, displayName); } // Show how many have been placed and how many are allowed diff --git a/src/main/java/world/bentobox/level/util/Utils.java b/src/main/java/world/bentobox/level/util/Utils.java index 2a40434..e585e2d 100644 --- a/src/main/java/world/bentobox/level/util/Utils.java +++ b/src/main/java/world/bentobox/level/util/Utils.java @@ -20,6 +20,7 @@ import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.api.user.User; +import world.bentobox.bentobox.hooks.CraftEngineHook; import world.bentobox.bentobox.hooks.ItemsAdderHook; import world.bentobox.bentobox.hooks.LangUtilsHook; import world.bentobox.bentobox.hooks.OraxenHook; @@ -226,10 +227,11 @@ public static String prettifyObject(Object object, User user) { /** * Returns the best available ItemStack for a custom-block string ID. - * Checks Oraxen, Nexo, and ItemsAdder in order; returns empty when none matches. + * Checks Oraxen, Nexo, ItemsAdder, and CraftEngine in order; returns empty when none matches. * * @param addon the Level addon - * @param id the custom block ID (e.g. "oraxen:my_block", "nexo:my_block", or an ItemsAdder ID) + * @param id the custom block ID (e.g. "oraxen:my_block", "nexo:my_block", an ItemsAdder ID, + * or a CraftEngine ID such as "default:my_block") * @return an Optional containing the representative ItemStack, or empty */ public static Optional getCustomBlockItemStack(Level addon, String id) { @@ -246,12 +248,18 @@ public static Optional getCustomBlockItemStack(Level addon, String id if (addon.isItemsAdder() && ItemsAdderHook.isInRegistry(id)) { return ItemsAdderHook.getItemStack(id); } + if (addon.isCraftEngine()) { + return CraftEngineHook.getItemStack(id); + } return Optional.empty(); } /** * Returns the display name from an ItemStack's meta when present, otherwise falls back to * {@link #prettifyObject(Object, User)} on the original key. + *

+ * Checks the legacy {@code display.Name} (used by Oraxen, Nexo, ItemsAdder) and then the + * modern {@code minecraft:item_name} component (used by CraftEngine and other 1.20.5+ items). * * @param itemStack the optional ItemStack (typically from a custom-block plugin) * @param key the raw key used as a fallback for prettification @@ -259,8 +267,17 @@ public static Optional getCustomBlockItemStack(Level addon, String id * @return the human-readable display name */ public static String getCustomBlockDisplayName(Optional itemStack, String key, User user) { - return itemStack.filter(is -> is.getItemMeta() != null && is.getItemMeta().hasDisplayName()) - .map(is -> is.getItemMeta().getDisplayName()).orElse(prettifyObject(key, user)); + if (itemStack.isEmpty() || itemStack.get().getItemMeta() == null) { + return prettifyObject(key, user); + } + org.bukkit.inventory.meta.ItemMeta meta = itemStack.get().getItemMeta(); + if (meta.hasDisplayName()) { + return meta.getDisplayName(); + } + if (meta.hasItemName()) { + return meta.getItemName(); + } + return prettifyObject(key, user); } public static String prettifyDescription(Object object, User user) {