T2C-CommandGUI/CommandGUI V2/src/main/java/de/jatitv/commandguiv2/Spigot/gui/GuiBuilder.java

121 lines
4.7 KiB
Java

package de.jatitv.commandguiv2.Spigot.gui;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import de.jatitv.commandguiv2.Spigot.Main;
import de.jatitv.commandguiv2.Spigot.Objekte.Slot;
import de.jatitv.commandguiv2.Spigot.config.config.SelectConfig;
import de.jatitv.commandguiv2.Util;
import net.t2code.lib.Spigot.Lib.items.ItemVersion;
import net.t2code.lib.Spigot.Lib.replace.Replace;
import org.bukkit.Material;
import org.bukkit.entity.Player;
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.UUID;
public class GuiBuilder {
private static String prefix = Util.getPrefix();
protected static void item(Slot slot, Player player, Inventory inventory) {
ItemStack item = new ItemStack(Material.valueOf(slot.item.toUpperCase().replace(".", "_")));
ItemMeta itemMeta = item.getItemMeta();
setMeta(itemMeta, player, slot);
item.setItemMeta(itemMeta);
Integer am;
if (slot.itemAmount == 0) {
am = 1;
} else am = slot.itemAmount;
item.setAmount(am);
inventory.setItem(slot.slot, item);
}
protected static void item(String material, Slot slot, Player player, Inventory inventory) {
ItemStack item = new ItemStack(Material.valueOf(material));
ItemMeta itemMeta = item.getItemMeta();
setMeta(itemMeta, player, slot);
item.setItemMeta(itemMeta);
Integer am;
if (slot.itemAmount == 0) {
am = 1;
} else am = slot.itemAmount;
item.setAmount(am);
inventory.setItem(slot.slot, item);
}
protected static void base64(String base64Value, Slot slot, Player player, Inventory inventory) {
ItemStack item = ItemVersion.getHeadIS();
SkullMeta itemMeta = (SkullMeta) item.getItemMeta();
setMeta(itemMeta, player, slot);
GameProfile profile = new GameProfile(UUID.randomUUID(), "");
profile.getProperties().put("textures", new Property("textures", base64Value));
Field profileField = null;
try {
profileField = itemMeta.getClass().getDeclaredField("profile");
profileField.setAccessible(true);
profileField.set(itemMeta, profile);
} catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) {
e.printStackTrace();
}
item.setItemMeta(itemMeta);
Integer am;
if (slot.itemAmount == 0) {
am = 1;
} else am = slot.itemAmount;
item.setAmount(am);
inventory.setItem(slot.slot, item);
}
protected static void base64(Slot slot, Player player, Inventory inventory) {
ItemStack item = ItemVersion.getHeadIS();
SkullMeta itemMeta = (SkullMeta) item.getItemMeta();
setMeta(itemMeta, player, slot);
GameProfile profile = new GameProfile(UUID.randomUUID(), "");
profile.getProperties().put("textures", new Property("textures", slot.base64Value));
Field profileField = null;
try {
profileField = itemMeta.getClass().getDeclaredField("profile");
profileField.setAccessible(true);
profileField.set(itemMeta, profile);
} catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) {
e.printStackTrace();
}
item.setItemMeta(itemMeta);
Integer am;
if (slot.itemAmount == 0) {
am = 1;
} else am = slot.itemAmount;
item.setAmount(am);
inventory.setItem(slot.slot, item);
}
protected static void playerHead(Slot slot, Player player, Inventory inventory) {
ItemStack item = ItemVersion.getHeadIS();
SkullMeta itemMeta = (SkullMeta) item.getItemMeta();
setMeta(itemMeta, player, slot);
item.setItemMeta(itemMeta);
Integer am;
if (slot.itemAmount == 0) {
am = 1;
} else am = slot.itemAmount;
item.setAmount(am);
inventory.setItem(slot.slot, item);
}
private static void setMeta(ItemMeta itemMeta, Player player, Slot slot) {
if (Main.PaPi) {
itemMeta.setDisplayName(Replace.replace(prefix, player, slot.name.replace("[player]", player.getName())));
itemMeta.setLore(Replace.replacePrice(prefix, player, slot.lore, slot.price + " " + SelectConfig.Currency));
} else {
itemMeta.setDisplayName(Replace.replace(prefix, slot.name.replace("[player]", player.getName())));
itemMeta.setLore(Replace.replacePrice(prefix, slot.lore, slot.price + " " + SelectConfig.Currency));
}
}
}