92 lines
3.6 KiB
Java
92 lines
3.6 KiB
Java
package net.t2code.t2codelib.SPIGOT.api.items;
|
|
|
|
import com.mojang.authlib.GameProfile;
|
|
import com.mojang.authlib.properties.Property;
|
|
import net.t2code.t2codelib.SPIGOT.api.minecraftVersion.T2CmcVersion;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.inventory.Inventory;
|
|
import org.bukkit.inventory.ItemStack;
|
|
import org.bukkit.inventory.meta.ItemMeta;
|
|
import org.bukkit.inventory.meta.SkullMeta;
|
|
|
|
import java.lang.reflect.Field;
|
|
import java.util.List;
|
|
import java.util.UUID;
|
|
|
|
public class T2CitemBuilder {
|
|
public static final boolean getLegacy = T2CmcVersion.isMc1_8() || T2CmcVersion.isMc1_9() || T2CmcVersion.isMc1_10() || T2CmcVersion.isMc1_11() || T2CmcVersion.isMc1_12();
|
|
|
|
public static void fillItem(boolean enable, String item, Integer lines, Inventory inventory) {
|
|
if (!enable) return;
|
|
fillItem(item, lines, inventory);
|
|
}
|
|
|
|
public static void fillItem(String item, Integer lines, Inventory inventory) {
|
|
try {
|
|
ItemStack glass;
|
|
if (getLegacy) {
|
|
glass = new ItemStack(Material.valueOf("STAINED_GLASS_PANE"), 1, Short.parseShort(item));
|
|
} else glass = new ItemStack(Material.valueOf(item.toUpperCase().replace(".", "_")));
|
|
ItemMeta itemMetaglass = glass.getItemMeta();
|
|
assert itemMetaglass != null;
|
|
itemMetaglass.setDisplayName("");
|
|
glass.setItemMeta(itemMetaglass);
|
|
glass.setAmount(1);
|
|
for (int i = 0; i < 9 * lines; i++) {
|
|
inventory.setItem(i, glass);
|
|
}
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
public static ItemStack itemStack(Material material, Integer amount, String displayName, List<String> lore) {
|
|
ItemStack itemStack = new ItemStack(material);
|
|
ItemMeta itemMeta = itemStack.getItemMeta();
|
|
|
|
itemMeta.setDisplayName(displayName);
|
|
itemMeta.setLore(lore);
|
|
itemStack.setItemMeta(itemMeta);
|
|
|
|
itemStack.setAmount(amount);
|
|
return itemStack;
|
|
}
|
|
|
|
public static void setItem(Integer slot, Integer amount, String material, String displayName, List<String> lore, Inventory inventory) {
|
|
ItemStack item;
|
|
if (getLegacy && material.contains(",")) {
|
|
String[] split = material.split(",");
|
|
item = new ItemStack(Material.valueOf(split[0]), 1, Short.parseShort(split[1]));
|
|
} else item = new ItemStack(Material.valueOf(material));
|
|
ItemMeta itemMeta = item.getItemMeta();
|
|
itemMeta.setDisplayName(displayName);
|
|
itemMeta.setLore(lore);
|
|
item.setItemMeta(itemMeta);
|
|
item.setAmount(amount);
|
|
inventory.setItem(slot, item);
|
|
}
|
|
|
|
public static ItemStack base64(String base64Value, Integer amount, String displayName, List<String> lore) {
|
|
ItemStack itemStack = new ItemStack(T2CitemVersion.getHead());
|
|
SkullMeta itemMeta = (SkullMeta) itemStack.getItemMeta();
|
|
|
|
GameProfile profile = new GameProfile(UUID.randomUUID(), "");
|
|
profile.getProperties().put("textures", new Property("textures", base64Value));
|
|
Field profileField;
|
|
try {
|
|
profileField = itemMeta.getClass().getDeclaredField("profile");
|
|
profileField.setAccessible(true);
|
|
profileField.set(itemMeta, profile);
|
|
} catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
itemMeta.setDisplayName(displayName);
|
|
itemMeta.setLore(lore);
|
|
itemStack.setItemMeta(itemMeta);
|
|
|
|
itemStack.setAmount(amount);
|
|
return itemStack;
|
|
}
|
|
}
|