93 lines
2.6 KiB
Java
93 lines
2.6 KiB
Java
package dev.zontreck.ase.guis;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.NamespacedKey;
|
|
import org.bukkit.inventory.ItemStack;
|
|
import org.bukkit.inventory.meta.ItemMeta;
|
|
import org.bukkit.inventory.meta.SkullMeta;
|
|
import org.bukkit.persistence.PersistentDataContainer;
|
|
import org.bukkit.persistence.PersistentDataType;
|
|
|
|
import dev.zontreck.ase.AriasServerEssentials;
|
|
import net.kyori.adventure.text.Component;
|
|
|
|
/**
|
|
* This is a primitive item.
|
|
*/
|
|
public class PrimitiveItem {
|
|
public static final String GUI_TAG = "ase_cgui";
|
|
public Material itemType;
|
|
public Component name;
|
|
public Component[] itemLore;
|
|
public boolean isGUIButton;
|
|
public boolean isSkull = false;
|
|
public String skullOwner = "";
|
|
|
|
public PrimitiveItem(Material type, Component name, boolean isGUIButton, Component... lore) {
|
|
itemType = type;
|
|
this.name = name;
|
|
itemLore = lore;
|
|
this.isGUIButton = isGUIButton;
|
|
}
|
|
|
|
public PrimitiveItem(Material type, Component name, boolean isGUIButton) {
|
|
itemType = type;
|
|
this.name = name;
|
|
itemLore = new Component[0];
|
|
this.isGUIButton = isGUIButton;
|
|
}
|
|
|
|
public ItemStack generate() {
|
|
ItemStack item = new ItemStack(itemType, 1);
|
|
|
|
List<Component> lore = new ArrayList<>();
|
|
for (Component component : itemLore) {
|
|
lore.add(component);
|
|
}
|
|
|
|
ItemMeta meta = item.getItemMeta();
|
|
|
|
PersistentDataContainer data = meta.getPersistentDataContainer();
|
|
|
|
meta.lore(lore);
|
|
meta.customName(name);
|
|
|
|
if (isGUIButton) {
|
|
data.set(NamespacedKey.fromString(GUI_TAG, AriasServerEssentials.getSelf()), PersistentDataType.BOOLEAN,
|
|
true);
|
|
}
|
|
|
|
if (isSkull) {
|
|
SkullMeta skullMeta = (SkullMeta) meta;
|
|
skullMeta.setOwningPlayer(Bukkit.getOfflinePlayer(skullOwner));
|
|
meta = skullMeta;
|
|
}
|
|
|
|
item.setItemMeta(meta);
|
|
return item;
|
|
}
|
|
|
|
public static boolean isGUIButton(ItemStack item) {
|
|
if (item == null || item.getType() == Material.AIR) {
|
|
return false;
|
|
}
|
|
ItemMeta meta = item.getItemMeta();
|
|
if (meta == null) {
|
|
return false;
|
|
}
|
|
PersistentDataContainer data = meta.getPersistentDataContainer();
|
|
return data.has(NamespacedKey.fromString(GUI_TAG, AriasServerEssentials.getSelf()),
|
|
PersistentDataType.BOOLEAN);
|
|
}
|
|
|
|
public void skull(String string) {
|
|
isSkull = true;
|
|
skullOwner = string;
|
|
itemType = Material.PLAYER_HEAD;
|
|
}
|
|
|
|
}
|