133 lines
5.8 KiB
Java
133 lines
5.8 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.objects.guis.Gui;
|
|
import de.jatitv.commandguiv2.Spigot.objects.functions.Function;
|
|
import de.jatitv.commandguiv2.Spigot.config.config.SelectConfig;
|
|
import de.jatitv.commandguiv2.Spigot.system.Papi;
|
|
import de.jatitv.commandguiv2.Spigot.system.Placeholder;
|
|
import de.jatitv.commandguiv2.Util;
|
|
import net.t2code.lib.Spigot.Lib.items.ItemVersion;
|
|
import net.t2code.lib.Spigot.Lib.minecraftVersion.MCVersion;
|
|
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(Function function, Integer slot, Player player, Inventory inventory) {
|
|
ItemStack item;
|
|
if (Main.legacy && function.item.toUpperCase().contains(",")) {
|
|
String[] split = function.item.toUpperCase().split(",");
|
|
item = new ItemStack(Material.valueOf(split[0]), 1, Short.parseShort(split[1]));
|
|
} else item = new ItemStack(Material.valueOf(function.item.toUpperCase().replace(".", "_")));
|
|
ItemMeta itemMeta = item.getItemMeta();
|
|
setDisplayNameAndLore(itemMeta, player, function);
|
|
item.setItemMeta(itemMeta);
|
|
Integer am;
|
|
if (function.itemAmount == 0) {
|
|
am = 1;
|
|
} else am = function.itemAmount;
|
|
item.setAmount(am);
|
|
inventory.setItem(slot, item);
|
|
}
|
|
|
|
protected static void item(String material, Function function, Integer slot, Player player, Inventory inventory) {
|
|
ItemStack item;
|
|
if (Main.legacy && 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();
|
|
setDisplayNameAndLore(itemMeta, player, function);
|
|
item.setItemMeta(itemMeta);
|
|
Integer am;
|
|
if (function.itemAmount == 0) {
|
|
am = 1;
|
|
} else am = function.itemAmount;
|
|
item.setAmount(am);
|
|
inventory.setItem(slot, item);
|
|
}
|
|
|
|
|
|
private static void setDisplayNameAndLore(ItemMeta itemMeta, Player player, Function slot) {
|
|
if (Main.PaPi) {
|
|
itemMeta.setDisplayName(Replace.replace(prefix, player, Placeholder.replace(slot.name, player)));
|
|
itemMeta.setLore(Replace.replacePrice(prefix, player, Placeholder.replace(slot.lore, player), slot.price + " " + SelectConfig.Currency));
|
|
} else {
|
|
itemMeta.setDisplayName(Replace.replace(prefix, Placeholder.replace(slot.name,player)));
|
|
itemMeta.setLore(Replace.replacePrice(prefix, Placeholder.replace(slot.lore,player), slot.price + " " + SelectConfig.Currency));
|
|
}
|
|
}
|
|
|
|
protected static void base64(String base64Value, Function function, Integer slot, Player player, Inventory inventory) {
|
|
ItemStack item = ItemVersion.getHeadIS();
|
|
SkullMeta itemMeta = (SkullMeta) item.getItemMeta();
|
|
setBase64(itemMeta, base64Value);
|
|
setDisplayNameAndLore(itemMeta, player, function);
|
|
item.setItemMeta(itemMeta);
|
|
Integer am;
|
|
if (function.itemAmount == 0) {
|
|
am = 1;
|
|
} else am = function.itemAmount;
|
|
item.setAmount(am);
|
|
inventory.setItem(slot, item);
|
|
}
|
|
|
|
private static void setBase64(ItemMeta itemMeta, String base64Value) {
|
|
GameProfile profile = new GameProfile(UUID.randomUUID(), "");
|
|
profile.getProperties().put("textures", new Property("textures", base64Value == null ? "" : base64Value));
|
|
Field profileField;
|
|
try {
|
|
profileField = itemMeta.getClass().getDeclaredField("profile");
|
|
profileField.setAccessible(true);
|
|
profileField.set(itemMeta, profile);
|
|
} catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
protected static void base64(Function function, Integer slot, Player player, Inventory inventory) {
|
|
base64(function.base64Value, function, slot, player, inventory);
|
|
}
|
|
|
|
protected static void playerHead(Function function, Integer slot, Player player, Inventory inventory, String skullName) {
|
|
ItemStack item = ItemVersion.getHeadIS();
|
|
SkullMeta itemMeta = (SkullMeta) item.getItemMeta();
|
|
setDisplayNameAndLore(itemMeta, player, function);
|
|
itemMeta.setOwner(skullName);
|
|
item.setItemMeta(itemMeta);
|
|
Integer am;
|
|
if (function.itemAmount == 0) {
|
|
am = 1;
|
|
} else am = function.itemAmount;
|
|
item.setAmount(am);
|
|
inventory.setItem(slot, item);
|
|
}
|
|
|
|
public static void fillItem(Inventory inventory, Gui gui) {
|
|
ItemStack glass;
|
|
if (MCVersion.minecraft1_8 || MCVersion.minecraft1_9 || MCVersion.minecraft1_10 || MCVersion.minecraft1_11 || MCVersion.minecraft1_12) {
|
|
glass = new ItemStack(Material.valueOf("STAINED_GLASS_PANE"), 1, Short.parseShort(gui.guiFillItemItem));
|
|
} else glass = new ItemStack(Material.valueOf(gui.guiFillItemItem.toUpperCase().replace(".", "_")));
|
|
ItemMeta itemMetaglass = glass.getItemMeta();
|
|
itemMetaglass.setDisplayName(" ");
|
|
glass.setItemMeta(itemMetaglass);
|
|
glass.setAmount(1);
|
|
for (int i = 0; i < 9 * gui.guiLines; i++) {
|
|
inventory.setItem(i, glass);
|
|
}
|
|
}
|
|
}
|