shulker
This commit is contained in:
@@ -4,6 +4,7 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.inventory.meta.SkullMeta;
|
import org.bukkit.inventory.meta.SkullMeta;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@@ -42,4 +43,11 @@ public abstract class ItemUtils {
|
|||||||
OfflinePlayer p = Bukkit.getOfflinePlayer(owner);
|
OfflinePlayer p = Bukkit.getOfflinePlayer(owner);
|
||||||
return skullOf(p.getName());
|
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<>();
|
private static final Map<UUID,ItemStack> lastOpenedBox = new HashMap<>();
|
||||||
|
|
||||||
public static Inventory getOf(ShulkerBox box) {
|
public static Inventory getOf(ItemStack item, ShulkerBox box) {
|
||||||
final String display = box.getCustomName();
|
final String display = ItemUtils.getDisplay(item);
|
||||||
final Inventory inv = Bukkit.createInventory(null, box.getInventory().getSize(), Text.color("&7Viewing " + display));
|
final Inventory inv = Bukkit.createInventory(null, box.getInventory().getSize(), Text.color("&7Viewing " + display));
|
||||||
|
|
||||||
inv.setContents(box.getInventory().getContents());
|
inv.setContents(box.getInventory().getContents());
|
||||||
@@ -40,7 +40,7 @@ public abstract class ShulkerUtils {
|
|||||||
final BlockStateMeta meta = (BlockStateMeta) item.getItemMeta();
|
final BlockStateMeta meta = (BlockStateMeta) item.getItemMeta();
|
||||||
final ShulkerBox box = (ShulkerBox) meta.getBlockState();
|
final ShulkerBox box = (ShulkerBox) meta.getBlockState();
|
||||||
|
|
||||||
p.openInventory(getOf(box));
|
p.openInventory(getOf(item, box));
|
||||||
lastOpenedBox.put(p.getUniqueId(),item);
|
lastOpenedBox.put(p.getUniqueId(),item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user