diff --git a/Artifacts/SubServers.Bungee.jar b/Artifacts/SubServers.Bungee.jar index c66d4829..672042b1 100644 Binary files a/Artifacts/SubServers.Bungee.jar and b/Artifacts/SubServers.Bungee.jar differ diff --git a/Artifacts/SubServers.Client.Bukkit.jar b/Artifacts/SubServers.Client.Bukkit.jar index c2f65bcb..4061d9cf 100644 Binary files a/Artifacts/SubServers.Client.Bukkit.jar and b/Artifacts/SubServers.Client.Bukkit.jar differ diff --git a/Artifacts/SubServers.Host.jar b/Artifacts/SubServers.Host.jar index 5d663c4b..a34c3a89 100644 Binary files a/Artifacts/SubServers.Host.jar and b/Artifacts/SubServers.Host.jar differ diff --git a/Javadoc/SubServers.Bungee.jar b/Javadoc/SubServers.Bungee.jar index d5d18730..d76b8dbb 100644 Binary files a/Javadoc/SubServers.Bungee.jar and b/Javadoc/SubServers.Bungee.jar differ diff --git a/Javadoc/SubServers.Bungee/index-all.html b/Javadoc/SubServers.Bungee/index-all.html index 0972e3f1..5135a45d 100644 --- a/Javadoc/SubServers.Bungee/index-all.html +++ b/Javadoc/SubServers.Bungee/index-all.html @@ -149,7 +149,7 @@
Thrown if 192- or 256-bit AES encryption or decryption is attempted, but not available on the particular Java platform.
-
allowConnection(InetAddress) - Static method in class net.ME1312.SubServers.Bungee.Network.SubDataServer
+
allowConnection(String) - Static method in class net.ME1312.SubServers.Bungee.Network.SubDataServer
Allow Connections from an Address
@@ -388,7 +388,7 @@
deleteSubServer(UUID, String) - Method in class net.ME1312.SubServers.Bungee.Host.Internal.InternalHost
 
-
denyConnection(InetAddress) - Static method in class net.ME1312.SubServers.Bungee.Network.SubDataServer
+
denyConnection(String) - Static method in class net.ME1312.SubServers.Bungee.Network.SubDataServer
Deny Connections from an Address
diff --git a/Javadoc/SubServers.Bungee/net/ME1312/SubServers/Bungee/Network/SubDataServer.html b/Javadoc/SubServers.Bungee/net/ME1312/SubServers/Bungee/Network/SubDataServer.html index 5c8817ae..e6091ea0 100644 --- a/Javadoc/SubServers.Bungee/net/ME1312/SubServers/Bungee/Network/SubDataServer.html +++ b/Javadoc/SubServers.Bungee/net/ME1312/SubServers/Bungee/Network/SubDataServer.html @@ -177,7 +177,7 @@ extends java.lang.Object static void -allowConnection(java.net.InetAddress address) +allowConnection(java.lang.String address)
Allow Connections from an Address
@@ -190,7 +190,7 @@ extends java.lang.Object static void -denyConnection(java.net.InetAddress address) +denyConnection(java.lang.String address)
Deny Connections from an Address
@@ -588,13 +588,13 @@ extends java.lang.Object - + - + + + + + + + + + diff --git a/Javadoc/SubServers.Host.jar b/Javadoc/SubServers.Host.jar index 7e263251..49f25c2a 100644 Binary files a/Javadoc/SubServers.Host.jar and b/Javadoc/SubServers.Host.jar differ diff --git a/SubServers.Bungee/src.jar b/SubServers.Bungee/src.jar index 239e84c1..c36bf60f 100644 Binary files a/SubServers.Bungee/src.jar and b/SubServers.Bungee/src.jar differ diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Host.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Host.java index b1472d0c..2ec611e5 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Host.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Host.java @@ -35,7 +35,7 @@ public abstract class Host implements ExtraDataHandler { */ public Host(SubPlugin plugin, String name, Boolean enabled, InetAddress address, String directory, String gitBash) { if (name.contains(" ")) throw new InvalidHostException("Host names cannot have spaces: " + name); - SubDataServer.allowConnection(address); + SubDataServer.allowConnection(address.getHostAddress()); } /** diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/ServerContainer.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/ServerContainer.java index f8aae521..a54dc9fc 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/ServerContainer.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/ServerContainer.java @@ -37,7 +37,7 @@ public class ServerContainer extends BungeeServerInfo implements Server { super(name, address, ChatColor.translateAlternateColorCodes('&', motd), restricted); if (Util.isNull(name, address, motd, hidden, restricted)) throw new NullPointerException(); if (name.contains(" ")) throw new InvalidServerException("Server names cannot have spaces: " + name); - SubDataServer.allowConnection(getAddress().getAddress()); + SubDataServer.allowConnection(getAddress().getAddress().getHostAddress()); this.motd = motd; this.restricted = restricted; this.hidden = hidden; diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/SubDataServer.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/SubDataServer.java index c4dcad75..accc0cfe 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/SubDataServer.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/SubDataServer.java @@ -14,6 +14,8 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * SubDataServer Class @@ -22,7 +24,7 @@ public final class SubDataServer { private static int MAX_QUEUE = 64; private static HashMap, String> pOut = new HashMap, String>(); private static HashMap> pIn = new HashMap>(); - private static List allowedAddresses = new ArrayList(); + private static List allowedAddresses = new ArrayList(); private static boolean defaults = false; private HashMap clients = new HashMap(); private ServerSocket server; @@ -50,10 +52,10 @@ public final class SubDataServer { if (Util.isNull(plugin, port, encryption, MAX_QUEUE)) throw new NullPointerException(); if (address == null) { server = new ServerSocket(port, MAX_QUEUE); - allowConnection(InetAddress.getByName("127.0.0.1")); + allowConnection("127.0.0.1"); } else { server = new ServerSocket(port, MAX_QUEUE, address); - allowConnection(address); + allowConnection(address.getHostAddress()); } this.plugin = plugin; this.encryption = encryption; @@ -65,7 +67,7 @@ public final class SubDataServer { defaults = true; for (String s : plugin.config.get().getSection("Settings").getSection("SubData").getStringList("Allowed-Connections", new ArrayList())) { try { - allowedAddresses.add(InetAddress.getByName(s)); + allowedAddresses.add(s); } catch (Exception e) { e.printStackTrace(); } @@ -152,7 +154,7 @@ public final class SubDataServer { */ public Client addClient(Socket socket) throws IOException { if (Util.isNull(socket)) throw new NullPointerException(); - if (allowedAddresses.contains(socket.getInetAddress())) { + if (checkConnection(socket.getInetAddress())) { Client client = new Client(this, socket); System.out.println("SubData > " + client.getAddress().toString() + " has connected"); clients.put(client.getAddress().toString(), client); @@ -341,17 +343,34 @@ public final class SubDataServer { * * @param address Address to allow */ - public static void allowConnection(InetAddress address) { + public static void allowConnection(String address) { if (Util.isNull(address)) throw new NullPointerException(); if (!allowedAddresses.contains(address)) allowedAddresses.add(address); } + private boolean checkConnection(InetAddress address) { + boolean whitelisted = false; + Matcher regaddress = Pattern.compile("^(\\d{1,3}).(\\d{1,3}).(\\d{1,3}).(\\d{1,3})$").matcher(address.getHostAddress()); + if (regaddress.find()) { + for (String allowed : allowedAddresses) if (!whitelisted) { + Matcher regallowed = Pattern.compile("^(\\d{1,3}|%).(\\d{1,3}|%).(\\d{1,3}|%).(\\d{1,3}|%)$").matcher(allowed); + if (regallowed.find() && ( + (regaddress.group(1).equals(regallowed.group(1)) || regallowed.group(1).equals("%")) && + (regaddress.group(2).equals(regallowed.group(2)) || regallowed.group(2).equals("%")) && + (regaddress.group(3).equals(regallowed.group(3)) || regallowed.group(3).equals("%")) && + (regaddress.group(4).equals(regallowed.group(4)) || regallowed.group(4).equals("%")) + )) whitelisted = true; + } + } + return whitelisted; + } + /** * Deny Connections from an Address * * @param address Address to deny */ - public static void denyConnection(InetAddress address) { + public static void denyConnection(String address) { if (Util.isNull(address)) throw new NullPointerException(); allowedAddresses.remove(address); } diff --git a/SubServers.Client/Bukkit/src.jar b/SubServers.Client/Bukkit/src.jar index 49820181..4a86252b 100644 Binary files a/SubServers.Client/Bukkit/src.jar and b/SubServers.Client/Bukkit/src.jar differ diff --git a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/InternalUIHandler.java b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/InternalUIHandler.java index 2120e0b8..635e53b2 100644 --- a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/InternalUIHandler.java +++ b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/InternalUIHandler.java @@ -51,7 +51,6 @@ public class InternalUIHandler implements UIHandler, Listener { enabled = false; } - @SuppressWarnings("ConstantConditions") @EventHandler(priority = EventPriority.HIGHEST) public void click(InventoryClickEvent event) { Player player = (Player) event.getWhoClicked(); diff --git a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/InternalUIRenderer.java b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/InternalUIRenderer.java index 1adbb7c8..9970c827 100644 --- a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/InternalUIRenderer.java +++ b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/InternalUIRenderer.java @@ -1,7 +1,9 @@ package net.ME1312.SubServers.Client.Bukkit.Graphic; import net.ME1312.SubServers.Client.Bukkit.Library.Container; +import net.ME1312.SubServers.Client.Bukkit.Library.NamedContainer; import net.ME1312.SubServers.Client.Bukkit.Library.Util; +import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version; import net.ME1312.SubServers.Client.Bukkit.Network.Packet.PacketDownloadHostInfo; import net.ME1312.SubServers.Client.Bukkit.Network.Packet.PacketDownloadServerInfo; import net.ME1312.SubServers.Client.Bukkit.Network.Packet.PacketDownloadServerList; @@ -65,37 +67,16 @@ public class InternalUIRenderer extends UIRenderer { reopen(); } - @SuppressWarnings("deprecation") - private ItemStack parseItem(String str) { - final Container item = new Container(str); - // int - Matcher matcher = Pattern.compile("(?i)^(\\d+)$").matcher(item.get()); - if (matcher.find()) { - return new ItemStack(Integer.parseInt(matcher.group(1))); - } - // int:int - matcher.reset(); - matcher = Pattern.compile("(?i)^(\\d+):(\\d+)$").matcher(item.get()); - if (matcher.find()) { - return new ItemStack(Integer.parseInt(matcher.group(1)), 1, Short.parseShort(matcher.group(2))); - } - // minecraft:name - if (item.get().startsWith("minecraft:")) { - item.set(item.get().substring(10)); - } - // bukkit name - if (!Util.isException(() -> Material.valueOf(item.get().toUpperCase()))) { - return new ItemStack(Material.valueOf(item.get().toUpperCase())); - } - // vault name - if (!Util.isException(() -> Class.forName("net.milkbowl.vault.item.Items"))) { - net.milkbowl.vault.item.ItemInfo info = net.milkbowl.vault.item.Items.itemByString(item.get()); - if (info != null) { - return new ItemStack(info.getType(), 1, info.getSubTypeId()); + ItemStack createItem(String material, String newdata, short olddata) { + try { + if (plugin.api.getGameVersion().compareTo(new Version("1.13")) < 0) { + return ItemStack.class.getConstructor(Material.class, int.class, short.class).newInstance(Material.valueOf(material), 1, olddata); + } else { + return new ItemStack(Material.valueOf(newdata), 1); } + } catch (Exception e) { + return new ItemStack(Material.AIR); } - - return new ItemStack(Material.ENDER_CHEST); } public void hostMenu(final int page) { @@ -111,7 +92,7 @@ public class InternalUIRenderer extends UIRenderer { ItemStack block; ItemMeta blockMeta; - ItemStack div = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 15); + ItemStack div = createItem("STAINED_GLASS_PANE", "AIR", (short) 15); ItemMeta divMeta = div.getItemMeta(); divMeta.setDisplayName(ChatColor.RESET.toString()); div.setItemMeta(divMeta); @@ -123,7 +104,7 @@ public class InternalUIRenderer extends UIRenderer { int area = (count % 9 == 0) ? count : (int) (Math.floor(count / 9) + 1) * 9; Inventory inv = Bukkit.createInventory(null, 18 + area, plugin.lang.getSection("Lang").getColoredString("Interface.Host-Menu.Title", '&')); - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 7); block.setItemMeta(divMeta); while (i < area) { inv.setItem(i, block); @@ -142,7 +123,7 @@ public class InternalUIRenderer extends UIRenderer { disabled = (short) (((i & 1) == 0) ? 2 : 14); if (json.getJSONObject("hosts").getJSONObject(host).getBoolean("enabled")) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, enabled); + block = createItem("STAINED_GLASS_PANE", "AIR", enabled); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(ChatColor.AQUA + json.getJSONObject("hosts").getJSONObject(host).getString("display")); LinkedList lore = new LinkedList(); @@ -152,7 +133,7 @@ public class InternalUIRenderer extends UIRenderer { if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) lore.add(ChatColor.WHITE + json.getJSONObject("hosts").getJSONObject(host).getString("address")); blockMeta.setLore(lore); } else { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, disabled); + block = createItem("STAINED_GLASS_PANE", "AIR", disabled); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(ChatColor.RED + json.getJSONObject("hosts").getJSONObject(host).getString("display")); LinkedList lore = new LinkedList(); @@ -176,7 +157,7 @@ public class InternalUIRenderer extends UIRenderer { } if (hosts.size() == 0) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 14); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Menu.No-Hosts", '&')); block.setItemMeta(blockMeta); @@ -193,7 +174,7 @@ public class InternalUIRenderer extends UIRenderer { i = inv.getSize() - 9; if (min != 0) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 4); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back-Arrow", '&')); block.setItemMeta(blockMeta); @@ -201,7 +182,7 @@ public class InternalUIRenderer extends UIRenderer { inv.setItem(i++, block); } else i += 2; i++; - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 1); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 1); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Menu.Group-Menu", '&')); block.setItemMeta(blockMeta); @@ -210,7 +191,7 @@ public class InternalUIRenderer extends UIRenderer { inv.setItem(i++, block); i++; if (hosts.size() - 1 > max) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 4); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Next-Arrow", '&')); block.setItemMeta(blockMeta); @@ -235,7 +216,7 @@ public class InternalUIRenderer extends UIRenderer { ItemStack block; ItemMeta blockMeta; - ItemStack div = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 15); + ItemStack div = createItem("STAINED_GLASS_PANE", "AIR", (short) 15); ItemMeta divMeta = div.getItemMeta(); divMeta.setDisplayName(ChatColor.RESET.toString()); div.setItemMeta(divMeta); @@ -249,16 +230,16 @@ public class InternalUIRenderer extends UIRenderer { } if (!(Bukkit.getPlayer(player).hasPermission("subservers.host.create.*") || Bukkit.getPlayer(player).hasPermission("subservers.host.create." + host.toLowerCase()))) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 7); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Admin.Creator", '&'))); blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Invalid-Permission", '&').replace("$str$", "subservers.host.create." + host.toLowerCase()))); } else if (!json.getJSONObject("host").getBoolean("enabled")) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 7); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Admin.Creator", '&'))); } else { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 4); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Admin.Creator", '&')); } @@ -270,7 +251,7 @@ public class InternalUIRenderer extends UIRenderer { inv.setItem(11, block); inv.setItem(12, block); - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 5); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 5); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Admin.SubServers", '&')); block.setItemMeta(blockMeta); @@ -282,11 +263,11 @@ public class InternalUIRenderer extends UIRenderer { inv.setItem(16, block); if (!json.getJSONObject("host").getBoolean("enabled")) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 7); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Admin.Plugins", '&'))); } else { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 11); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 11); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Admin.Plugins", '&')); } @@ -295,7 +276,7 @@ public class InternalUIRenderer extends UIRenderer { inv.setItem(28, block); if (json.getJSONObject("host").getBoolean("enabled")) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 11); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 11); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(ChatColor.AQUA + json.getJSONObject("host").getString("display")); LinkedList lore = new LinkedList(); @@ -305,7 +286,7 @@ public class InternalUIRenderer extends UIRenderer { if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) lore.add(ChatColor.WHITE + json.getJSONObject("host").getString("address")); blockMeta.setLore(lore); } else { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 14); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(ChatColor.RED + json.getJSONObject("host").getString("display")); LinkedList lore = new LinkedList(); @@ -322,7 +303,7 @@ public class InternalUIRenderer extends UIRenderer { if (hasHistory()) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 14); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back", '&')); block.setItemMeta(blockMeta); @@ -350,7 +331,7 @@ public class InternalUIRenderer extends UIRenderer { setDownloading(null); ItemStack block; ItemMeta blockMeta; - ItemStack div = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 15); + ItemStack div = createItem("STAINED_GLASS_PANE", "AIR", (short) 15); ItemMeta divMeta = div.getItemMeta(); divMeta.setDisplayName(ChatColor.RESET.toString()); div.setItemMeta(divMeta); @@ -364,11 +345,11 @@ public class InternalUIRenderer extends UIRenderer { } if (options.getName() == null) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 14); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(ChatColor.RED + plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Name", '&')); } else { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 5); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 5); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(ChatColor.GREEN + plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Name", '&')); blockMeta.setLore(Arrays.asList(ChatColor.GRAY + options.getName())); @@ -379,11 +360,11 @@ public class InternalUIRenderer extends UIRenderer { inv.setItem(12, block); if (options.getPort() <= 0) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 14); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(ChatColor.RED + plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Port", '&')); } else { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 5); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 5); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(ChatColor.GREEN + plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Port", '&')); blockMeta.setLore(Arrays.asList(ChatColor.GRAY.toString() + options.getPort())); @@ -394,11 +375,11 @@ public class InternalUIRenderer extends UIRenderer { inv.setItem(16, block); if (options.getTemplate() == null) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 14); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(ChatColor.RED + plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Template", '&')); } else { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 5); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 5); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(ChatColor.GREEN + plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Template", '&')); blockMeta.setLore(Arrays.asList(ChatColor.GRAY + options.getTemplate())); @@ -409,11 +390,11 @@ public class InternalUIRenderer extends UIRenderer { inv.setItem(30, block); if (options.getVersion() == null) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 14); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(ChatColor.RED + plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Version", '&')); } else { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 5); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 5); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(ChatColor.GREEN + plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Version", '&')); blockMeta.setLore(Arrays.asList(ChatColor.GRAY + "v" + options.getVersion().toString())); @@ -424,12 +405,12 @@ public class InternalUIRenderer extends UIRenderer { inv.setItem(34, block); if (!options.hasHistory()) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 7); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(ChatColor.GRAY + ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Undo", '&'))); block.setItemMeta(blockMeta); } else { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 1); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 1); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Undo", '&')); block.setItemMeta(blockMeta); @@ -439,13 +420,13 @@ public class InternalUIRenderer extends UIRenderer { inv.setItem(46, block); if (options.getName() == null || options.getTemplate() == null || options.getVersion() == null || options.getPort() <= 0 && options.getMemory() < 256) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 7); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(ChatColor.GRAY + ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Submit", '&'))); blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Form-Incomplete", '&'))); block.setItemMeta(blockMeta); } else { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 4); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Submit", '&')); block.setItemMeta(blockMeta); @@ -456,7 +437,7 @@ public class InternalUIRenderer extends UIRenderer { inv.setItem(50, block); if (hasHistory()) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 14); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back", '&')); block.setItemMeta(blockMeta); @@ -489,7 +470,7 @@ public class InternalUIRenderer extends UIRenderer { ItemStack block; ItemMeta blockMeta; - ItemStack div = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 15); + ItemStack div = createItem("STAINED_GLASS_PANE", "AIR", (short) 15); ItemMeta divMeta = div.getItemMeta(); divMeta.setDisplayName(ChatColor.RESET.toString()); div.setItemMeta(divMeta); @@ -501,7 +482,7 @@ public class InternalUIRenderer extends UIRenderer { int area = (count % 9 == 0)?count: (int) (Math.floor(count / 9) + 1) * 9; Inventory inv = Bukkit.createInventory(null, 18 + area, plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Template.Title", '&').replace("$str$", json.getJSONObject("host").getString("display"))); - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 7); block.setItemMeta(divMeta); while (i < area) { inv.setItem(i, block); @@ -515,7 +496,7 @@ public class InternalUIRenderer extends UIRenderer { if (templates.indexOf(template) >= min && templates.indexOf(template) <= max) { if (even && (i == 4 || i == 13 || i == 22 || i == 31)) inv.setItem(i++, adiv); - block = parseItem(json.getJSONObject("host").getJSONObject("creator").getJSONObject("templates").getJSONObject(template).getString("icon")); + block = parseItem(json.getJSONObject("host").getJSONObject("creator").getJSONObject("templates").getJSONObject(template).getString("icon"), new ItemStack(Material.ENDER_CHEST)); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(ChatColor.YELLOW + json.getJSONObject("host").getJSONObject("creator").getJSONObject("templates").getJSONObject(template).getString("display")); LinkedList lore = new LinkedList(); @@ -536,7 +517,7 @@ public class InternalUIRenderer extends UIRenderer { } if (templates.size() == 0) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 14); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Template.No-Templates", '&')); block.setItemMeta(blockMeta); @@ -553,7 +534,7 @@ public class InternalUIRenderer extends UIRenderer { i = inv.getSize() - 9; if (min != 0) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 4); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back-Arrow", '&')); block.setItemMeta(blockMeta); @@ -561,7 +542,7 @@ public class InternalUIRenderer extends UIRenderer { inv.setItem(i++, block); } else i += 2; i++; - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 14); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back", '&')); block.setItemMeta(blockMeta); @@ -570,7 +551,7 @@ public class InternalUIRenderer extends UIRenderer { inv.setItem(i++, block); i++; if (templates.size() - 1 > max) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 4); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Next-Arrow", '&')); block.setItemMeta(blockMeta); @@ -602,7 +583,7 @@ public class InternalUIRenderer extends UIRenderer { ItemStack block; ItemMeta blockMeta; - ItemStack div = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 15); + ItemStack div = createItem("STAINED_GLASS_PANE", "AIR", (short) 15); ItemMeta divMeta = div.getItemMeta(); divMeta.setDisplayName(ChatColor.RESET.toString()); div.setItemMeta(divMeta); @@ -614,7 +595,7 @@ public class InternalUIRenderer extends UIRenderer { int area = (count % 9 == 0) ? count : (int) (Math.floor(count / 9) + 1) * 9; Inventory inv = Bukkit.createInventory(null, 18 + area, plugin.lang.getSection("Lang").getColoredString("Interface.Host-Plugin.Title", '&').replace("$str$", json.getJSONObject("host").getString("display"))); - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 7); block.setItemMeta(divMeta); while (i < area) { inv.setItem(i, block); @@ -642,7 +623,7 @@ public class InternalUIRenderer extends UIRenderer { } if (renderers.size() == 0) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 14); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Plugin.No-Plugins", '&')); block.setItemMeta(blockMeta); @@ -659,7 +640,7 @@ public class InternalUIRenderer extends UIRenderer { i = inv.getSize() - 9; if (min != 0) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 4); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back-Arrow", '&')); block.setItemMeta(blockMeta); @@ -668,7 +649,7 @@ public class InternalUIRenderer extends UIRenderer { } else i += 2; i++; if (hasHistory()) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 14); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back", '&')); block.setItemMeta(blockMeta); @@ -678,7 +659,7 @@ public class InternalUIRenderer extends UIRenderer { i++; } if (renderers.size() - 1 > max) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 4); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Next-Arrow", '&')); block.setItemMeta(blockMeta); @@ -705,7 +686,7 @@ public class InternalUIRenderer extends UIRenderer { ItemStack block; ItemMeta blockMeta; - ItemStack div = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 15); + ItemStack div = createItem("STAINED_GLASS_PANE", "AIR", (short) 15); ItemMeta divMeta = div.getItemMeta(); divMeta.setDisplayName(ChatColor.RESET.toString()); div.setItemMeta(divMeta); @@ -717,7 +698,7 @@ public class InternalUIRenderer extends UIRenderer { int area = (count % 9 == 0) ? count : (int) (Math.floor(count / 9) + 1) * 9; Inventory inv = Bukkit.createInventory(null, 18 + area, plugin.lang.getSection("Lang").getColoredString("Interface.Group-Menu.Title", '&')); - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 7); block.setItemMeta(divMeta); while (i < area) { inv.setItem(i, block); @@ -734,7 +715,7 @@ public class InternalUIRenderer extends UIRenderer { if (even && (i == 4 || i == 13 || i == 22 || i == 31)) inv.setItem(i++, adiv); color = (short) (((i & 1) == 0) ? 1 : 4); - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, color); + block = createItem("STAINED_GLASS_PANE", "AIR", color); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(ChatColor.GOLD + group); LinkedList lore = new LinkedList(); @@ -754,7 +735,7 @@ public class InternalUIRenderer extends UIRenderer { } if (groups.size() == 0) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 14); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Group-Menu.No-Groups", '&')); block.setItemMeta(blockMeta); @@ -771,7 +752,7 @@ public class InternalUIRenderer extends UIRenderer { i = inv.getSize() - 9; if (min != 0) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 4); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back-Arrow", '&')); block.setItemMeta(blockMeta); @@ -779,7 +760,7 @@ public class InternalUIRenderer extends UIRenderer { inv.setItem(i++, block); } else i += 2; i++; - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 5); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 5); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Group-Menu.Server-Menu", '&')); block.setItemMeta(blockMeta); @@ -788,7 +769,7 @@ public class InternalUIRenderer extends UIRenderer { inv.setItem(i++, block); i++; if (groups.size() - 1 > max) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 4); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Next-Arrow", '&')); block.setItemMeta(blockMeta); @@ -839,7 +820,7 @@ public class InternalUIRenderer extends UIRenderer { ItemStack block; ItemMeta blockMeta; - ItemStack div = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 15); + ItemStack div = createItem("STAINED_GLASS_PANE", "AIR", (short) 15); ItemMeta divMeta = div.getItemMeta(); divMeta.setDisplayName(ChatColor.RESET.toString()); div.setItemMeta(divMeta); @@ -851,7 +832,7 @@ public class InternalUIRenderer extends UIRenderer { int area = (count % 9 == 0) ? count : (int) (Math.floor(count / 9) + 1) * 9; Inventory inv = Bukkit.createInventory(null, 18 + area, (host == null)?((group == null)?plugin.lang.getSection("Lang").getColoredString("Interface.Server-Menu.Title", '&'):plugin.lang.getSection("Lang").getColoredString("Interface.Group-SubServer.Title", '&').replace("$str$", group)):plugin.lang.getSection("Lang").getColoredString("Interface.Host-SubServer.Title", '&').replace("$str$", json.getJSONObject("hosts").getJSONObject(host).getString("display"))); - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 7); block.setItemMeta(divMeta); while (i < area) { inv.setItem(i, block); @@ -873,7 +854,7 @@ public class InternalUIRenderer extends UIRenderer { disabled = (short) (((i & 1) == 0) ? 2 : 14); if (hosts.get(server) == null) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, external); + block = createItem("STAINED_GLASS_PANE", "AIR", external); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(ChatColor.AQUA + json.getJSONObject("servers").getJSONObject(server).getString("display")); LinkedList lore = new LinkedList(); @@ -885,7 +866,7 @@ public class InternalUIRenderer extends UIRenderer { lore.add(ChatColor.WHITE + ((plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false))?json.getJSONObject("servers").getJSONObject(server).getString("address"):json.getJSONObject("servers").getJSONObject(server).getString("address").split(":")[json.getJSONObject("servers").getJSONObject(server).getString("address").split(":").length - 1])); blockMeta.setLore(lore); } else if (json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getBoolean("temp")) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, temp); + block = createItem("STAINED_GLASS_PANE", "AIR", temp); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(ChatColor.AQUA + json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getString("display")); LinkedList lore = new LinkedList(); @@ -896,7 +877,7 @@ public class InternalUIRenderer extends UIRenderer { lore.add(ChatColor.WHITE + ((plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false))?json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getString("address"):json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getString("address").split(":")[json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getString("address").split(":").length - 1])); blockMeta.setLore(lore); } else if (json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getBoolean("running")) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, online); + block = createItem("STAINED_GLASS_PANE", "AIR", online); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(ChatColor.GREEN + json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getString("display")); LinkedList lore = new LinkedList(); @@ -906,7 +887,7 @@ public class InternalUIRenderer extends UIRenderer { lore.add(ChatColor.WHITE + ((plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false))?json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getString("address"):json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getString("address").split(":")[json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getString("address").split(":").length - 1])); blockMeta.setLore(lore); } else if (json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getBoolean("enabled") && json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getJSONArray("incompatible").length() == 0) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, offline); + block = createItem("STAINED_GLASS_PANE", "AIR", offline); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(ChatColor.YELLOW + json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getString("display")); LinkedList lore = new LinkedList(); @@ -916,7 +897,7 @@ public class InternalUIRenderer extends UIRenderer { lore.add(ChatColor.WHITE + ((plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false))?json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getString("address"):json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getString("address").split(":")[json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getString("address").split(":").length - 1])); blockMeta.setLore(lore); } else { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, disabled); + block = createItem("STAINED_GLASS_PANE", "AIR", disabled); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(ChatColor.RED + json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getString("display")); LinkedList lore = new LinkedList(); @@ -948,7 +929,7 @@ public class InternalUIRenderer extends UIRenderer { } if (servers.size() == 0) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 14); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Server-Menu.No-Servers", '&')); block.setItemMeta(blockMeta); @@ -965,7 +946,7 @@ public class InternalUIRenderer extends UIRenderer { i = inv.getSize() - 9; if (min != 0) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 4); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back-Arrow", '&')); block.setItemMeta(blockMeta); @@ -974,7 +955,7 @@ public class InternalUIRenderer extends UIRenderer { } else i += 2; i++; if (host == null || group == null || hasHistory()) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) ((host == null && group == null)?11:14)); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) ((host == null && group == null)?11:14)); blockMeta = block.getItemMeta(); blockMeta.setDisplayName((host == null && group == null)?plugin.lang.getSection("Lang").getColoredString("Interface.Server-Menu.Host-Menu", '&'):plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back", '&')); block.setItemMeta(blockMeta); @@ -984,7 +965,7 @@ public class InternalUIRenderer extends UIRenderer { i++; } if (servers.size() - 1 > max) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 4); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Next-Arrow", '&')); block.setItemMeta(blockMeta); @@ -1008,7 +989,7 @@ public class InternalUIRenderer extends UIRenderer { lastVisitedObjects[0] = subserver; ItemStack block; ItemMeta blockMeta; - ItemStack div = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 15); + ItemStack div = createItem("STAINED_GLASS_PANE", "AIR", (short) 15); ItemMeta divMeta = div.getItemMeta(); divMeta.setDisplayName(ChatColor.RESET.toString()); div.setItemMeta(divMeta); @@ -1024,12 +1005,12 @@ public class InternalUIRenderer extends UIRenderer { if (json.getJSONObject("server").getBoolean("running")) { if (!(Bukkit.getPlayer(player).hasPermission("subservers.subserver.terminate.*") || Bukkit.getPlayer(player).hasPermission("subservers.subserver.terminate." + subserver.toLowerCase()))) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 7); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Terminate", '&'))); blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Invalid-Permission", '&').replace("$str$", "subservers.subserver.terminate." + subserver.toLowerCase()))); } else { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 14); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Terminate", '&')); } @@ -1039,12 +1020,12 @@ public class InternalUIRenderer extends UIRenderer { inv.setItem(10, block); if (!(Bukkit.getPlayer(player).hasPermission("subservers.subserver.stop.*") || Bukkit.getPlayer(player).hasPermission("subservers.subserver.stop." + subserver.toLowerCase()))) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 7); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Stop", '&'))); blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Invalid-Permission", '&').replace("$str$", "subservers.subserver.stop." + subserver.toLowerCase()))); } else { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 2); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 2); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Stop", '&')); } @@ -1055,12 +1036,12 @@ public class InternalUIRenderer extends UIRenderer { inv.setItem(12, block); if (!(Bukkit.getPlayer(player).hasPermission("subservers.subserver.command.*") || Bukkit.getPlayer(player).hasPermission("subservers.subserver.command." + subserver.toLowerCase()))) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 7); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Command", '&'))); blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Invalid-Permission", '&').replace("$str$", "subservers.subserver.command." + subserver.toLowerCase()))); } else { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 4); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Command", '&')); } @@ -1073,16 +1054,16 @@ public class InternalUIRenderer extends UIRenderer { inv.setItem(16, block); } else { if (!(Bukkit.getPlayer(player).hasPermission("subservers.subserver.start.*") || Bukkit.getPlayer(player).hasPermission("subservers.subserver.start." + subserver.toLowerCase()))) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 7); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Start", '&'))); blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Invalid-Permission", '&').replace("$str$", "subservers.subserver.start." + subserver.toLowerCase()))); } else if (!json.getJSONObject("server").getBoolean("enabled") || json.getJSONObject("server").getJSONArray("incompatible").length() != 0) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 7); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Start", '&'))); } else { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 5); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 5); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Start", '&')); } @@ -1096,11 +1077,11 @@ public class InternalUIRenderer extends UIRenderer { } if (!json.getJSONObject("server").getBoolean("enabled")) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 7); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Plugins", '&'))); } else { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 11); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 11); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Plugins", '&')); } @@ -1109,7 +1090,7 @@ public class InternalUIRenderer extends UIRenderer { inv.setItem(28, block); if (json.getJSONObject("server").getBoolean("temp")) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 11); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 11); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(ChatColor.AQUA + json.getJSONObject("server").getString("display")); LinkedList lore = new LinkedList(); @@ -1120,7 +1101,7 @@ public class InternalUIRenderer extends UIRenderer { lore.add(ChatColor.WHITE + json.getJSONObject("server").getString("address")); blockMeta.setLore(lore); } else if (json.getJSONObject("server").getBoolean("running")) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 5); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 5); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(ChatColor.GREEN + json.getJSONObject("server").getString("display")); LinkedList lore = new LinkedList(); @@ -1130,7 +1111,7 @@ public class InternalUIRenderer extends UIRenderer { lore.add(ChatColor.WHITE + json.getJSONObject("server").getString("address")); blockMeta.setLore(lore); } else if (json.getJSONObject("server").getBoolean("enabled") && json.getJSONObject("server").getJSONArray("incompatible").length() == 0) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 4); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(ChatColor.YELLOW + json.getJSONObject("server").getString("display")); LinkedList lore = new LinkedList(); @@ -1140,7 +1121,7 @@ public class InternalUIRenderer extends UIRenderer { lore.add(ChatColor.WHITE + json.getJSONObject("server").getString("address")); blockMeta.setLore(lore); } else { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 14); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(ChatColor.RED + json.getJSONObject("server").getString("display")); LinkedList lore = new LinkedList(); @@ -1164,7 +1145,7 @@ public class InternalUIRenderer extends UIRenderer { inv.setItem(32, block); if (hasHistory()) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 14); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back", '&')); block.setItemMeta(blockMeta); @@ -1197,7 +1178,7 @@ public class InternalUIRenderer extends UIRenderer { ItemStack block; ItemMeta blockMeta; - ItemStack div = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 15); + ItemStack div = createItem("STAINED_GLASS_PANE", "AIR", (short) 15); ItemMeta divMeta = div.getItemMeta(); divMeta.setDisplayName(ChatColor.RESET.toString()); div.setItemMeta(divMeta); @@ -1209,7 +1190,7 @@ public class InternalUIRenderer extends UIRenderer { int area = (count % 9 == 0) ? count : (int) (Math.floor(count / 9) + 1) * 9; Inventory inv = Bukkit.createInventory(null, 18 + area, plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Plugin.Title", '&').replace("$str$", json.getJSONObject("server").getString("display"))); - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 7); block.setItemMeta(divMeta); while (i < area) { inv.setItem(i, block); @@ -1237,7 +1218,7 @@ public class InternalUIRenderer extends UIRenderer { } if (renderers.size() == 0) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 14); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Plugin.No-Plugins", '&')); block.setItemMeta(blockMeta); @@ -1254,7 +1235,7 @@ public class InternalUIRenderer extends UIRenderer { i = inv.getSize() - 9; if (min != 0) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 4); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back-Arrow", '&')); block.setItemMeta(blockMeta); @@ -1263,7 +1244,7 @@ public class InternalUIRenderer extends UIRenderer { } else i += 2; i++; if (hasHistory()) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 14); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back", '&')); block.setItemMeta(blockMeta); @@ -1273,7 +1254,7 @@ public class InternalUIRenderer extends UIRenderer { i++; } if (renderers.size() - 1 > max) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); + block = createItem("STAINED_GLASS_PANE", "AIR", (short) 4); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Next-Arrow", '&')); block.setItemMeta(blockMeta); diff --git a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/UIRenderer.java b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/UIRenderer.java index 9d0e7276..323aab65 100644 --- a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/UIRenderer.java +++ b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/UIRenderer.java @@ -8,9 +8,14 @@ import net.ME1312.SubServers.Client.Bukkit.Network.Packet.PacketCreateServer; import net.ME1312.SubServers.Client.Bukkit.SubPlugin; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; import org.bukkit.scheduler.BukkitTask; import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * GUI Renderer Layout Class @@ -19,7 +24,7 @@ public abstract class UIRenderer { protected static HashMap hostPlugins = new HashMap(); protected static HashMap subserverPlugins = new HashMap(); private NamedContainer tdownload = null; - private BukkitTask download = null; + private int download = -1; private final UUID player; private SubPlugin plugin; @@ -87,14 +92,14 @@ public abstract class UIRenderer { * Attempt to send a Title Message * * @param str Message - * @param fadein FadeIn Transition length - * @param stay How long the message should stay - * @param fadeout FadeOut Transition length + * @param fadein FadeIn Transition length (in ticks) + * @param stay How long the message should stay (in ticks) + * @param fadeout FadeOut Transition length (in ticks) * @return Success Status */ public boolean sendTitle(String str, int fadein, int stay, int fadeout) { if (Util.isNull(str, fadein, stay, fadeout)) throw new NullPointerException(); - if (Bukkit.getPluginManager().getPlugin("TitleManager") != null && plugin.config.get().getSection("Settings").getBoolean("Use-Title-Messages", true)) { + if (plugin.config.get().getSection("Settings").getBoolean("Use-Title-Messages", true)) { String line1, line2; if (!str.startsWith("\n") && str.contains("\n")) { line1 = str.split("\\n")[0]; @@ -104,18 +109,25 @@ public abstract class UIRenderer { line2 = ChatColor.RESET.toString(); } try { - io.puharesource.mc.titlemanager.api.TitleObject obj = io.puharesource.mc.titlemanager.api.TitleObject.class.getConstructor(String.class, String.class).newInstance(line1, line2); - if (fadein >= 0) obj.setFadeIn(fadein); - if (stay >= 0) obj.setStay(stay); - if (fadeout >= 0) obj.setFadeOut(fadeout); - obj.send(Bukkit.getPlayer(player)); - return true; + if (plugin.api.getGameVersion().compareTo(new Version("1.11")) >= 0) { + if (ChatColor.stripColor(line1).length() == 0 && ChatColor.stripColor(line2).length() == 0) { + Bukkit.getPlayer(player).resetTitle(); + } else { + Bukkit.getPlayer(player).sendTitle(line1, line2, (fadein >= 0)?fadein:10, (stay >= 0)?stay:70, (fadeout >= 0)?fadeout:20); + } + return true; + } else if (Bukkit.getPluginManager().getPlugin("TitleManager") != null) { + io.puharesource.mc.titlemanager.api.TitleObject obj = io.puharesource.mc.titlemanager.api.TitleObject.class.getConstructor(String.class, String.class).newInstance(line1, line2); + if (fadein >= 0) obj.setFadeIn(fadein); + if (stay >= 0) obj.setStay(stay); + if (fadeout >= 0) obj.setFadeOut(fadeout); + obj.send(Bukkit.getPlayer(player)); + return true; + } else return false; } catch (Throwable e) { return false; } - } else { - return false; - } + } else return false; } /** @@ -124,10 +136,11 @@ public abstract class UIRenderer { * @param subtitle Subtitle to display (or null to hide) */ public void setDownloading(String subtitle) { - if (subtitle != null && !(Bukkit.getPluginManager().getPlugin("TitleManager") != null && plugin.config.get().getSection("Settings").getBoolean("Use-Title-Messages", true))) { - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> { + if (subtitle != null && !(plugin.config.get().getSection("Settings").getBoolean("Use-Title-Messages", true) && (plugin.api.getGameVersion().compareTo(new Version("1.11")) >= 0 || Bukkit.getPluginManager().getPlugin("TitleManager") != null))) { + if (download != -1) Bukkit.getScheduler().cancelTask(download); + download = Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> { if (tdownload != null) Bukkit.getPlayer(player).sendMessage(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Downloading", '&').replace("$str$", subtitle)); - download = null; + download = -1; }, 50L); } if (subtitle != null && tdownload == null) { tdownload = new NamedContainer(subtitle, 0); @@ -169,13 +182,70 @@ public abstract class UIRenderer { if (tdownload != null) { tdownload = null; } - if (download != null) { - download.cancel(); - download = null; + if (download != -1) { + Bukkit.getScheduler().cancelTask(download); + download = -1; } } } + /** + * Parse an ItemStack from a String + * + * @param str String to parse + * @return ItemStack + */ + public ItemStack parseItem(String str) { + return parseItem(str, new ItemStack(Material.AIR)); + } + + /** + * Parse an ItemStack from a String + * + * @param str String to parse + * @param def Default to return if unable to parse + * @return ItemStack + */ + public ItemStack parseItem(String str, ItemStack def) { + final Container item = new Container(str); + if (plugin.api.getGameVersion().compareTo(new Version("1.13")) < 0) { + try { + // int + Matcher matcher = Pattern.compile("(?i)^(\\d+)$").matcher(item.get()); + if (matcher.find()) { + return ItemStack.class.getConstructor(int.class, int.class).newInstance(Integer.parseInt(matcher.group(1)), 1); + } + // int:int + matcher.reset(); + matcher = Pattern.compile("(?i)^(\\d+):(\\d+)$").matcher(item.get()); + if (matcher.find()) { + return ItemStack.class.getConstructor(int.class, int.class, short.class).newInstance(Integer.parseInt(matcher.group(1)), 1, Short.parseShort(matcher.group(2))); + } + } catch (Exception e) { + return def; + } + } + // minecraft:name + if (item.get().toLowerCase().startsWith("minecraft:")) { + item.set(item.get().substring(10)); + } + // bukkit name + if (!Util.isException(() -> Material.valueOf(item.get().toUpperCase()))) { + return new ItemStack(Material.valueOf(item.get().toUpperCase()), 1); + } + // vault name + if (!Util.isException(() -> Class.forName("net.milkbowl.vault.item.Items"))) { + net.milkbowl.vault.item.ItemInfo info = net.milkbowl.vault.item.Items.itemByString(item.get()); + if (info != null) { + ItemStack stack = info.toStack(); + stack.setAmount(1); + return stack; + } + } + + return def; + } + /** * Add Host Plugin * diff --git a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubAPI.java b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubAPI.java index f6eb34c4..be0f58bc 100644 --- a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubAPI.java +++ b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubAPI.java @@ -128,7 +128,7 @@ public final class SubAPI { */ public Version getGameVersion() { try { - return new Version(Bukkit.getServer().getVersion().split("\\(MC\\: ")[1].split("\\)")[0]); + return new Version(Bukkit.getBukkitVersion().split("-")[0]); } catch (ArrayIndexOutOfBoundsException e) { return new Version(plugin.version.toString().substring(0, plugin.version.toString().length() - 1)); } diff --git a/SubServers.Host/src.jar b/SubServers.Host/src.jar index bf63765b..d987d17e 100644 Binary files a/SubServers.Host/src.jar and b/SubServers.Host/src.jar differ