Create T2CitemBuilder.java
This commit is contained in:
parent
74e05ff7c5
commit
63d80b9e5e
@ -0,0 +1,77 @@
|
|||||||
|
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 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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user