shulker
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user