This commit is contained in:
ImproperIssues
2023-04-23 02:58:32 -07:00
parent f033f73a73
commit 8c2f2b2e29
2 changed files with 11 additions and 3 deletions

View File

@@ -4,6 +4,7 @@ import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import java.util.UUID;
@@ -42,4 +43,11 @@ public abstract class ItemUtils {
OfflinePlayer p = Bukkit.getOfflinePlayer(owner);
return skullOf(p.getName());
}
public static String getDisplay(ItemStack item) {
String def = StringUtils.capitalizeWords(item.getType().name());
ItemMeta meta = item.getItemMeta();
if (meta == null) return def;
return meta.hasDisplayName() ? meta.getDisplayName() : def;
}
}

View File

@@ -19,8 +19,8 @@ public abstract class ShulkerUtils {
private static final Map<UUID,ItemStack> lastOpenedBox = new HashMap<>();
public static Inventory getOf(ShulkerBox box) {
final String display = box.getCustomName();
public static Inventory getOf(ItemStack item, ShulkerBox box) {
final String display = ItemUtils.getDisplay(item);
final Inventory inv = Bukkit.createInventory(null, box.getInventory().getSize(), Text.color("&7Viewing " + display));
inv.setContents(box.getInventory().getContents());
@@ -40,7 +40,7 @@ public abstract class ShulkerUtils {
final BlockStateMeta meta = (BlockStateMeta) item.getItemMeta();
final ShulkerBox box = (ShulkerBox) meta.getBlockState();
p.openInventory(getOf(box));
p.openInventory(getOf(item, box));
lastOpenedBox.put(p.getUniqueId(),item);
}