Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/main/java/world/bentobox/level/Level.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 21 additions & 4 deletions src/main/java/world/bentobox/level/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ItemStack> getCustomBlockItemStack(Level addon, String id) {
Expand All @@ -246,21 +248,36 @@ public static Optional<ItemStack> 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.
* <p>
* 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
* @param user the user for translation lookups
* @return the human-readable display name
*/
public static String getCustomBlockDisplayName(Optional<ItemStack> 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) {
Expand Down
Loading