137 lines
6.3 KiB
Java
137 lines
6.3 KiB
Java
package net.t2code.commandguiv2.Spigot.gui;
|
|
|
|
import com.mojang.authlib.GameProfile;
|
|
import com.mojang.authlib.properties.Property;
|
|
import net.t2code.commandguiv2.Spigot.Main;
|
|
import net.t2code.commandguiv2.Spigot.objects.guis.Gui;
|
|
import net.t2code.commandguiv2.Spigot.objects.functions.Function;
|
|
import net.t2code.commandguiv2.Spigot.config.config.SelectConfig;
|
|
import net.t2code.commandguiv2.Spigot.objects.slots.Slot;
|
|
import net.t2code.commandguiv2.Spigot.system.Placeholder;
|
|
import net.t2code.commandguiv2.Util;
|
|
import net.t2code.t2codelib.SPIGOT.api.items.T2CitemBuilder;
|
|
import net.t2code.t2codelib.SPIGOT.api.items.T2CitemVersion;
|
|
import net.t2code.t2codelib.SPIGOT.api.messages.T2Creplace;
|
|
import net.t2code.t2codelib.SPIGOT.api.minecraftVersion.T2CmcVersion;
|
|
import org.bukkit.Bukkit;
|
|
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 org.bukkit.profile.PlayerProfile;
|
|
import org.bukkit.profile.PlayerTextures;
|
|
|
|
import java.lang.reflect.Field;
|
|
import java.net.MalformedURLException;
|
|
import java.net.URL;
|
|
import java.util.UUID;
|
|
|
|
public class GuiBuilder {
|
|
|
|
private static String prefix = Util.getPrefix();
|
|
|
|
protected static void item(Slot slot, Player player, Inventory inventory) {
|
|
Function function = Main.functionHashMap.get(slot.function);
|
|
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, slot);
|
|
item.setItemMeta(itemMeta);
|
|
Integer am;
|
|
if (function.itemAmount == 0) {
|
|
am = 1;
|
|
} else am = function.itemAmount;
|
|
item.setAmount(am);
|
|
inventory.setItem(slot.slot, item);
|
|
}
|
|
|
|
protected static void item(String material, Slot slot, Player player, Inventory inventory) {
|
|
Function function = Main.functionHashMap.get(slot.function);
|
|
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, slot);
|
|
item.setItemMeta(itemMeta);
|
|
Integer am;
|
|
if (function.itemAmount == 0) {
|
|
am = 1;
|
|
} else am = function.itemAmount;
|
|
item.setAmount(am);
|
|
inventory.setItem(slot.slot, item);
|
|
}
|
|
|
|
|
|
private static void setDisplayNameAndLore(ItemMeta itemMeta, Player player, Slot slot) {
|
|
Function function = Main.functionHashMap.get(slot.function);
|
|
if (Main.PaPi) {
|
|
itemMeta.setDisplayName(T2Creplace.replace(prefix, player, Placeholder.replace(function.name, player)));
|
|
if (slot.permission && !player.hasPermission(slot.permissionToUse) && function.noPermLoreEnable) {
|
|
itemMeta.setLore(T2Creplace.replacePrice(prefix, player, Placeholder.replace(function.noPermLore, player), function.price + " " + SelectConfig.getCurrency()));
|
|
} else itemMeta.setLore(T2Creplace.replacePrice(prefix, player, Placeholder.replace(function.lore, player), function.price + " " + SelectConfig.getCurrency()));
|
|
} else {
|
|
itemMeta.setDisplayName(T2Creplace.replace(prefix, Placeholder.replace(function.name, player)));
|
|
if (slot.permission && !player.hasPermission(slot.permissionToUse) && function.noPermLoreEnable) {
|
|
itemMeta.setLore(T2Creplace.replacePrice(prefix, Placeholder.replace(function.noPermLore, player), function.price + " " + SelectConfig.getCurrency()));
|
|
} else itemMeta.setLore(T2Creplace.replacePrice(prefix, Placeholder.replace(function.lore, player), function.price + " " + SelectConfig.getCurrency()));
|
|
}
|
|
}
|
|
|
|
protected static void base64(String base64Value, Slot slot, Player player, Inventory inventory) {
|
|
Function function = Main.functionHashMap.get(slot.function);
|
|
ItemStack item = T2CitemBuilder.base64(base64Value);
|
|
SkullMeta itemMeta = (SkullMeta) item.getItemMeta();
|
|
setDisplayNameAndLore(itemMeta, player, slot);
|
|
item.setItemMeta(itemMeta);
|
|
Integer am;
|
|
if (function.itemAmount == 0) {
|
|
am = 1;
|
|
} else am = function.itemAmount;
|
|
item.setAmount(am);
|
|
inventory.setItem(slot.slot, item);
|
|
}
|
|
|
|
|
|
|
|
protected static void base64(Slot slot, Player player, Inventory inventory) {
|
|
Function function = Main.functionHashMap.get(slot.function);
|
|
base64(function.base64Value, slot, player, inventory);
|
|
}
|
|
|
|
protected static void playerHead(Slot slot, Player player, Inventory inventory, String skullName) {
|
|
Function function = Main.functionHashMap.get(slot.function);
|
|
ItemStack item = T2CitemVersion.getHeadIS();
|
|
SkullMeta itemMeta = (SkullMeta) item.getItemMeta();
|
|
setDisplayNameAndLore(itemMeta, player, slot);
|
|
itemMeta.setOwner(skullName);
|
|
item.setItemMeta(itemMeta);
|
|
Integer am;
|
|
if (function.itemAmount == 0) {
|
|
am = 1;
|
|
} else am = function.itemAmount;
|
|
item.setAmount(am);
|
|
inventory.setItem(slot.slot, item);
|
|
}
|
|
|
|
public static void fillItem(Inventory inventory, Gui gui) {
|
|
ItemStack glass;
|
|
if (T2CmcVersion.isMc1_8() || T2CmcVersion.isMc1_9() || T2CmcVersion.isMc1_10() || T2CmcVersion.isMc1_11() || T2CmcVersion.isMc1_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);
|
|
}
|
|
}
|
|
}
|