From bcf3fd5d8baf271dab3f5a995772af06cb818402 Mon Sep 17 00:00:00 2001 From: Brianna Date: Thu, 2 May 2019 19:12:18 -0400 Subject: [PATCH] Added support for 1.8-1.14 in the same build. --- Read_this_before_your_first_use.txt | 20 -- pom.xml | 2 +- .../songoda/ultimatekits/UltimateKits.java | 37 ++- .../conversion/hooks/DefaultHook.java | 16 +- .../ultimatekits/gui/GUIBlockEditor.java | 15 +- .../ultimatekits/gui/GUIDecorOptions.java | 5 +- .../ultimatekits/gui/GUIDisplayKit.java | 5 +- .../ultimatekits/gui/GUIGUIOptions.java | 6 +- .../ultimatekits/gui/GUIGeneralOptions.java | 10 +- .../ultimatekits/gui/GUIKitEditor.java | 13 +- .../ultimatekits/gui/GUIKitSelector.java | 6 +- .../ultimatekits/gui/GUISellingOptions.java | 10 +- .../handlers/ParticleHandler.java | 28 +- .../com/songoda/ultimatekits/kit/Kit.java | 3 +- .../com/songoda/ultimatekits/kit/KitItem.java | 4 +- .../listeners/InteractListeners.java | 4 +- .../ultimatekits/tasks/CrateAnimateTask.java | 7 +- .../ultimatekits/utils/ItemSerializer.java | 251 ++++------------ .../songoda/ultimatekits/utils/Methods.java | 34 +-- .../ultimatekits/utils/ServerVersion.java | 27 ++ .../ultimatekits/utils/SettingsManager.java | 282 ++++++++---------- .../utils/gui/AbstractAnvilGUI.java | 2 +- .../ultimatekits/utils/gui/AbstractGUI.java | 20 +- .../songoda/ultimatekits/utils/gui/Range.java | 5 +- 24 files changed, 336 insertions(+), 476 deletions(-) delete mode 100644 Read_this_before_your_first_use.txt create mode 100644 src/main/java/com/songoda/ultimatekits/utils/ServerVersion.java diff --git a/Read_this_before_your_first_use.txt b/Read_this_before_your_first_use.txt deleted file mode 100644 index 8f7f9e4..0000000 --- a/Read_this_before_your_first_use.txt +++ /dev/null @@ -1,20 +0,0 @@ -Hey loves, - -Thanks for downloading our plugin ^_^ In order to -use holograms with it you will need a plugin called -arconix. It basically takes a bunch of methods that -we use all over the place throughout our plugin lineup -and stores it in one place so we don't have to write -new code every time we need to get something simple -done. So make sure to stay up to date with the latest -updates for it. - -Link to download: -https://gitlab.com/Songoda/Arconix/-/jobs/artifacts/master/download?job=build - -If you need help you can always join our -discord in which is listed at the bottom of all of -our plugin pages. - -Enjoy <3 -Brianna & The Songoda Team. \ No newline at end of file diff --git a/pom.xml b/pom.xml index f163958..888da6a 100644 --- a/pom.xml +++ b/pom.xml @@ -83,7 +83,7 @@ org.spigotmc spigot - 1.14-pre5 + 1.14 com.songoda diff --git a/src/main/java/com/songoda/ultimatekits/UltimateKits.java b/src/main/java/com/songoda/ultimatekits/UltimateKits.java index 587c78f..ed975fe 100644 --- a/src/main/java/com/songoda/ultimatekits/UltimateKits.java +++ b/src/main/java/com/songoda/ultimatekits/UltimateKits.java @@ -14,6 +14,7 @@ import com.songoda.ultimatekits.utils.*; import com.songoda.ultimatekits.utils.updateModules.LocaleModule; import com.songoda.update.Plugin; import com.songoda.update.SongodaUpdate; +import org.apache.commons.lang.ArrayUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; @@ -41,6 +42,8 @@ public class UltimateKits extends JavaPlugin { private Locale locale; + private ServerVersion serverVersion = ServerVersion.fromPackageName(Bukkit.getServer().getClass().getPackage().getName()); + private ConfigWrapper kitFile = new ConfigWrapper(this, "", "kit.yml"); private ConfigWrapper dataFile = new ConfigWrapper(this, "", "data.yml"); private ConfigWrapper keyFile = new ConfigWrapper(this, "", "keys.yml"); @@ -67,27 +70,8 @@ public class UltimateKits extends JavaPlugin { * On plugin enable. */ - private boolean checkVersion() { - int workingVersion = 13; - int currentVersion = Integer.parseInt(Bukkit.getServer().getClass() - .getPackage().getName().split("\\.")[3].split("_")[1]); - - if (currentVersion < workingVersion) { - Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> { - Bukkit.getConsoleSender().sendMessage(""); - Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "You installed the 1." + workingVersion + "+ only version of " + this.getDescription().getName() + " on a 1." + currentVersion + " server. Since you are on the wrong version we disabled the plugin for you. Please install correct version to continue using " + this.getDescription().getName() + "."); - Bukkit.getConsoleSender().sendMessage(""); - }, 20L); - return false; - } - return true; - } - @Override public void onEnable() { - // Check to make sure the Bukkit version is compatible. - if (!checkVersion()) return; - INSTANCE = this; console.sendMessage(Methods.formatText("&a=============================")); @@ -235,6 +219,21 @@ public class UltimateKits extends JavaPlugin { } } + public ServerVersion getServerVersion() { + return serverVersion; + } + + public boolean isServerVersion(ServerVersion version) { + return serverVersion == version; + } + public boolean isServerVersion(ServerVersion... versions) { + return ArrayUtils.contains(versions, serverVersion); + } + + public boolean isServerVersionAtLeast(ServerVersion version) { + return serverVersion.ordinal() >= version.ordinal(); + } + /* * Saves registered kits to file. */ diff --git a/src/main/java/com/songoda/ultimatekits/conversion/hooks/DefaultHook.java b/src/main/java/com/songoda/ultimatekits/conversion/hooks/DefaultHook.java index 2756b53..0e174c3 100644 --- a/src/main/java/com/songoda/ultimatekits/conversion/hooks/DefaultHook.java +++ b/src/main/java/com/songoda/ultimatekits/conversion/hooks/DefaultHook.java @@ -15,7 +15,7 @@ public class DefaultHook implements Hook { for (Kits kit : Kits.values()) { if (!kit.name().equalsIgnoreCase(kitName)) continue; for (String string : kit.items) { - items.add(UltimateKits.getInstance().getItemSerializer().deserializeItemStack(string)); + items.add(UltimateKits.getInstance().getItemSerializer().deserializeItemStackFromJson(string)); } } @@ -41,9 +41,17 @@ public class DefaultHook implements Hook { } public enum Kits { - TOOLS(10, "STONE_PICKAXE 1", "STONE_AXE 1", "STONE_SHOVEL 1", "STONE_HOE 1"), - BETTER_TOOLS(300, "DIAMOND_PICKAXE 1 DIG_SPEED:5 DURABILITY:2", "DIAMOND_AXE 1 DIG_SPEED:2 DURABILITY:2", "DIAMOND_SHOVEL 1 DIG_SPEED:1", "DIAMOND_HOE 1 DURABILITY:3"), - BRIANNA(0, "PLAYER_HEAD:3 1 player:Songoda"); + TOOLS(10, "{id:\"minecraft:stone_pickaxe\",Count:1b}", + "{id:\"minecraft:stone_axe\",Count:1b}", + "{id:\"minecraft:stone_hoe\",Count:1b}", + "{id:\"minecraft:stone_shovel\",Count:1b}"), + + BETTER_TOOLS(300, "{id:\"minecraft:diamond_axe\",Count:1b,tag:{Enchantments:[{lvl:2s,id:\"minecraft:efficiency\"},{lvl:2s,id:\"minecraft:unbreaking\"}]}}", + "{id:\"minecraft:diamond_pickaxe\",Count:1b,tag:{Enchantments:[{lvl:5s,id:\"minecraft:efficiency\"},{lvl:2s,id:\"minecraft:unbreaking\"}]}}", + "{id:\"minecraft:diamond_shovel\",Count:1b,tag:{Enchantments:[{lvl:1s,id:\"minecraft:efficiency\"}]}}", + "{id:\"minecraft:diamond_hoe\",Count:1b,tag:{Enchantments:[{lvl:3s,id:\"minecraft:unbreaking\"}]}}"), + + BRIANNA(0, "{id:\"minecraft:player_head\",Count:1b,tag:{SkullOwner:{Id:\"2626974f-5838-44c6-994d-f6c723d40b79\",Properties:{textures:[{Signature:\"Zx+6l8ZZACSIdWtHdllX6yqcLWC57ly7CTxO40SVbxwO3D1bMIQOjmeUbq3WkOb9lNIRvtH3oGcC6U9l1vICCIV3/oQZ4hxEs4yxmmGHmsK9Qm/oa4ZfaWNKdjio7kOWBqf8I+0zImXB1ptjAEfRJ1RCIaFW80amWLDeOhDhMfPTEOCP80ZfP29aGd91KPAVYOokvv/SX9BD4OaaStDt5Cbterfz0JwwBoogrYAIrkQuvxYlFkVHL1rO5ygLXiWGvF0lBqpeEX7r3QPT0D9iU92/zQ98v0N1klrOW4eK2tpAuhfI2mJ3nwKUKedssgAhmmEgG/doeByXJMlbfQxEfUifq7lHXm/sVD/Gd9pHJSMGQzenwhitiJpm7XHMRFUAJVi8Gt29TCXektC2E0VlsmDRQDb/fYQRPW2KgXpB2TpHzqFGMTjQCNtp4AEBgxaFrH87nXckkJGY+SFGUvcUE3D0u+026gwDUlrGB1Fr5leOF9tPSSu5r7h5i9t1m/LvO0SwPEl0UzeISX8JaJ0fLkvVmTV/lWGzXAZX7xgte0336uy0zYIovzE3wnDbb5iE9NM6+Zja4zU0PQi19gzK272zoC4SCEh6/h2yhU8cEtl8StoNSCk14puZz/XYCfbLpJBJz8x/E1R8WBbes0G2A5nsQGqMqWl0lz20zNd1eYk=\",Value:\"eyJ0aW1lc3RhbXAiOjE1NTY4MzcwMDk4NjksInByb2ZpbGVJZCI6IjI2MjY5NzRmNTgzODQ0YzY5OTRkZjZjNzIzZDQwYjc5IiwicHJvZmlsZU5hbWUiOiJTb25nb2RhIiwic2lnbmF0dXJlUmVxdWlyZWQiOnRydWUsInRleHR1cmVzIjp7IlNLSU4iOnsidXJsIjoiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS8zNTI4ZGZiNGYwZWUxNGQ4ZDhhM2RhMTM4YTYzYjZlOGI1MWJmZTIwNTYxZjhjZTliYjFhOTBhNjhjMTI5NWE1IiwibWV0YWRhdGEiOnsibW9kZWwiOiJzbGltIn19fX0=\"}]},Name:\"Songoda\"},Damage:3}}"); public String[] items; public int delay; diff --git a/src/main/java/com/songoda/ultimatekits/gui/GUIBlockEditor.java b/src/main/java/com/songoda/ultimatekits/gui/GUIBlockEditor.java index 9bd9a08..ac09779 100644 --- a/src/main/java/com/songoda/ultimatekits/gui/GUIBlockEditor.java +++ b/src/main/java/com/songoda/ultimatekits/gui/GUIBlockEditor.java @@ -4,6 +4,7 @@ import com.songoda.ultimatekits.UltimateKits; import com.songoda.ultimatekits.kit.KitBlockData; import com.songoda.ultimatekits.kit.KitType; import com.songoda.ultimatekits.utils.Methods; +import com.songoda.ultimatekits.utils.ServerVersion; import com.songoda.ultimatekits.utils.gui.AbstractGUI; import org.bukkit.Location; import org.bukkit.Material; @@ -64,9 +65,9 @@ public class GUIBlockEditor extends AbstractGUI { lore.add(Methods.formatText("&6Claim")); } - createButton(11, Material.COMPARATOR, "&5&lSwitch kit type", lore); + createButton(11, UltimateKits.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? Material.COMPARATOR : Material.valueOf("REDSTONE_COMPARATOR"), "&5&lSwitch kit type", lore); - createButton(13, Material.POPPY, "&9&lDecor Options", + createButton(13, UltimateKits.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? Material.POPPY : Material.valueOf("RED_ROSE"), "&9&lDecor Options", "&7Click to edit the decoration", "&7options for this kit."); @@ -94,12 +95,10 @@ public class GUIBlockEditor extends AbstractGUI { instance.getHologram().update(kitBlockData); constructGUI(); }); - registerClickable(13, (player, inventory, cursor, slot, type) -> { - new GUIDecorOptions(UltimateKits.getInstance(), player, kitBlockData.getLocation()); - }); - registerClickable(15, (player, inventory, cursor, slot, type) -> { - new GUIKitEditor(UltimateKits.getInstance(), player, kitBlockData.getKit(), this, null, 0); - }); + registerClickable(13, (player, inventory, cursor, slot, type) -> + new GUIDecorOptions(UltimateKits.getInstance(), player, kitBlockData.getLocation())); + registerClickable(15, (player, inventory, cursor, slot, type) -> + new GUIKitEditor(UltimateKits.getInstance(), player, kitBlockData.getKit(), this, null, 0)); } @Override diff --git a/src/main/java/com/songoda/ultimatekits/gui/GUIDecorOptions.java b/src/main/java/com/songoda/ultimatekits/gui/GUIDecorOptions.java index f61dd23..216b069 100644 --- a/src/main/java/com/songoda/ultimatekits/gui/GUIDecorOptions.java +++ b/src/main/java/com/songoda/ultimatekits/gui/GUIDecorOptions.java @@ -4,6 +4,7 @@ import com.songoda.ultimatekits.UltimateKits; import com.songoda.ultimatekits.kit.Kit; import com.songoda.ultimatekits.kit.KitBlockData; import com.songoda.ultimatekits.utils.Methods; +import com.songoda.ultimatekits.utils.ServerVersion; import com.songoda.ultimatekits.utils.gui.AbstractGUI; import org.bukkit.Location; import org.bukkit.Material; @@ -51,8 +52,8 @@ public class GUIDecorOptions extends AbstractGUI { createButton(8, Material.valueOf(UltimateKits.getInstance().getConfig().getString("Interfaces.Exit Icon")), UltimateKits.getInstance().getLocale().getMessage("interface.button.exit")); - ItemStack head2 = new ItemStack(Material.PLAYER_HEAD, 1, (byte) 3); - ItemStack back = Methods.addTexture(head2, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"); + ItemStack head = new ItemStack(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.PLAYER_HEAD : Material.valueOf("SKULL_ITEM"), 1, (byte) 3); + ItemStack back = Methods.addTexture(head, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"); inventory.setItem(0, back); createButton(0, back, UltimateKits.getInstance().getLocale().getMessage("interface.button.back")); diff --git a/src/main/java/com/songoda/ultimatekits/gui/GUIDisplayKit.java b/src/main/java/com/songoda/ultimatekits/gui/GUIDisplayKit.java index 3c84652..c1cafd6 100644 --- a/src/main/java/com/songoda/ultimatekits/gui/GUIDisplayKit.java +++ b/src/main/java/com/songoda/ultimatekits/gui/GUIDisplayKit.java @@ -3,6 +3,7 @@ package com.songoda.ultimatekits.gui; import com.songoda.ultimatekits.UltimateKits; import com.songoda.ultimatekits.kit.Kit; import com.songoda.ultimatekits.utils.Methods; +import com.songoda.ultimatekits.utils.ServerVersion; import com.songoda.ultimatekits.utils.gui.AbstractGUI; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -198,8 +199,8 @@ public class GUIDisplayKit extends AbstractGUI { if (back != null && !plugin.getConfig().getBoolean("Interfaces.Do Not Use Glass Borders")) { - ItemStack head2 = new ItemStack(Material.PLAYER_HEAD, 1, (byte) 3); - ItemStack skull2 = Methods.addTexture(head2, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"); + ItemStack head = new ItemStack(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.PLAYER_HEAD : Material.valueOf("SKULL_ITEM"), 1, (byte) 3); + ItemStack skull2 = Methods.addTexture(head, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"); SkullMeta skull2Meta = (SkullMeta) skull2.getItemMeta(); skull2.setDurability((short) 3); skull2Meta.setDisplayName(UltimateKits.getInstance().getLocale().getMessage("interface.button.back")); diff --git a/src/main/java/com/songoda/ultimatekits/gui/GUIGUIOptions.java b/src/main/java/com/songoda/ultimatekits/gui/GUIGUIOptions.java index c989356..9cd4f38 100644 --- a/src/main/java/com/songoda/ultimatekits/gui/GUIGUIOptions.java +++ b/src/main/java/com/songoda/ultimatekits/gui/GUIGUIOptions.java @@ -3,6 +3,7 @@ package com.songoda.ultimatekits.gui; import com.songoda.ultimatekits.UltimateKits; import com.songoda.ultimatekits.kit.Kit; import com.songoda.ultimatekits.utils.Methods; +import com.songoda.ultimatekits.utils.ServerVersion; import com.songoda.ultimatekits.utils.gui.AbstractAnvilGUI; import com.songoda.ultimatekits.utils.gui.AbstractGUI; import org.bukkit.Material; @@ -53,9 +54,8 @@ public class GUIGUIOptions extends AbstractGUI { createButton(8, Material.valueOf(UltimateKits.getInstance().getConfig().getString("Interfaces.Exit Icon")), UltimateKits.getInstance().getLocale().getMessage("interface.button.exit")); - ItemStack head2 = new ItemStack(Material.PLAYER_HEAD, 1, (byte) 3); - ItemStack back = head2; - back = Methods.addTexture(head2, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"); + ItemStack head = new ItemStack(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.PLAYER_HEAD : Material.valueOf("SKULL_ITEM"), 1, (byte) 3); + ItemStack back = Methods.addTexture(head, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"); SkullMeta skull2Meta = (SkullMeta) back.getItemMeta(); back.setDurability((short) 3); skull2Meta.setDisplayName(UltimateKits.getInstance().getLocale().getMessage("interface.button.back")); diff --git a/src/main/java/com/songoda/ultimatekits/gui/GUIGeneralOptions.java b/src/main/java/com/songoda/ultimatekits/gui/GUIGeneralOptions.java index 8776e36..f629907 100644 --- a/src/main/java/com/songoda/ultimatekits/gui/GUIGeneralOptions.java +++ b/src/main/java/com/songoda/ultimatekits/gui/GUIGeneralOptions.java @@ -3,6 +3,7 @@ package com.songoda.ultimatekits.gui; import com.songoda.ultimatekits.UltimateKits; import com.songoda.ultimatekits.kit.Kit; import com.songoda.ultimatekits.utils.Methods; +import com.songoda.ultimatekits.utils.ServerVersion; import com.songoda.ultimatekits.utils.gui.AbstractAnvilGUI; import com.songoda.ultimatekits.utils.gui.AbstractGUI; import org.bukkit.Material; @@ -52,9 +53,8 @@ public class GUIGeneralOptions extends AbstractGUI { createButton(8, Material.valueOf(UltimateKits.getInstance().getConfig().getString("Interfaces.Exit Icon")), UltimateKits.getInstance().getLocale().getMessage("interface.button.exit")); - ItemStack head2 = new ItemStack(Material.PLAYER_HEAD, 1, (byte) 3); - ItemStack back = head2; - back = Methods.addTexture(head2, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"); + ItemStack head = new ItemStack(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.PLAYER_HEAD : Material.valueOf("SKULL_ITEM"), 1, (byte) 3); + ItemStack back = Methods.addTexture(head, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"); SkullMeta skull2Meta = (SkullMeta) back.getItemMeta(); back.setDurability((short) 3); skull2Meta.setDisplayName(UltimateKits.getInstance().getLocale().getMessage("interface.button.back")); @@ -62,7 +62,7 @@ public class GUIGeneralOptions extends AbstractGUI { inventory.setItem(0, back); - createButton(11, Material.CLOCK, "&9&lChange Delay", + createButton(11, plugin.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? Material.CLOCK : Material.valueOf("WATCH"), "&9&lChange Delay", "&7Currently set to: &a" + kit.getDelay() + "&7.", "", "&7Use this to alter this kit delay.", @@ -110,7 +110,7 @@ public class GUIGeneralOptions extends AbstractGUI { gui.setSlot(AbstractAnvilGUI.AnvilSlot.INPUT_LEFT, item); gui.open(); - gui.setCloseSound(Sound.ENTITY_GENERIC_EXPLODE); + gui.setCloseSound(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Sound.ENTITY_GENERIC_EXPLODE : Sound.valueOf("EXPLODE")); })); registerClickable(11, ((player1, inventory1, cursor, slot, type) -> { diff --git a/src/main/java/com/songoda/ultimatekits/gui/GUIKitEditor.java b/src/main/java/com/songoda/ultimatekits/gui/GUIKitEditor.java index 412a251..f316f40 100644 --- a/src/main/java/com/songoda/ultimatekits/gui/GUIKitEditor.java +++ b/src/main/java/com/songoda/ultimatekits/gui/GUIKitEditor.java @@ -5,6 +5,7 @@ import com.songoda.ultimatekits.kit.Kit; import com.songoda.ultimatekits.kit.KitAnimation; import com.songoda.ultimatekits.kit.KitItem; import com.songoda.ultimatekits.utils.Methods; +import com.songoda.ultimatekits.utils.ServerVersion; import com.songoda.ultimatekits.utils.gui.AbstractAnvilGUI; import com.songoda.ultimatekits.utils.gui.AbstractGUI; import com.songoda.ultimatekits.utils.gui.Range; @@ -66,9 +67,9 @@ public class GUIKitEditor extends AbstractGUI { createButton(8, Material.valueOf(UltimateKits.getInstance().getConfig().getString("Interfaces.Exit Icon")), UltimateKits.getInstance().getLocale().getMessage("interface.button.exit")); - ItemStack head2 = new ItemStack(Material.PLAYER_HEAD, 1, (byte) 3); + ItemStack head = new ItemStack(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.PLAYER_HEAD : Material.valueOf("SKULL_ITEM"), 1, (byte) 3); ItemStack back; - back = Methods.addTexture(head2, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"); + back = Methods.addTexture(head, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"); SkullMeta skull2Meta = (SkullMeta) back.getItemMeta(); back.setDurability((short) 3); skull2Meta.setDisplayName(UltimateKits.getInstance().getLocale().getMessage("interface.button.back")); @@ -83,7 +84,7 @@ public class GUIKitEditor extends AbstractGUI { itmeta.setLore(lore); it.setItemMeta(itmeta); - ItemStack glass = new ItemStack(Material.GRAY_STAINED_GLASS_PANE, 1); + ItemStack glass = new ItemStack(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.GRAY_STAINED_GLASS_PANE : Material.valueOf("STAINED_GLASS_PANE"), 1); ItemMeta glassmeta = glass.getItemMeta(); glassmeta.setDisplayName(Methods.formatText("&" + kit.getName().replaceAll(".(?!$)", "$0&"))); glass.setItemMeta(glassmeta); @@ -237,7 +238,7 @@ public class GUIKitEditor extends AbstractGUI { private void getInvItems() { isInInventory = false; - createButton(9, player.getInventory(), Material.REDSTONE_TORCH, "&6General Options", + createButton(9, player.getInventory(), plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.REDSTONE_TORCH : Material.valueOf("REDSTONE_TORCH_ON"), "&6General Options", "&7Click to edit adjust", "&7general options."); @@ -253,7 +254,7 @@ public class GUIKitEditor extends AbstractGUI { "&7Click to add a command", "&7to this kit."); - createButton(14, player.getInventory(), Material.SUNFLOWER, "&6Add Economy", + createButton(14, player.getInventory(), plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.SUNFLOWER : Material.valueOf("DOUBLE_PLANT"), "&6Add Economy", "&7Click to add money", "&7to this kit."); @@ -530,7 +531,7 @@ public class GUIKitEditor extends AbstractGUI { player.updateInventory(); } - player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_YES, 1F, 1F); + player.playSound(player.getLocation(), plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Sound.ENTITY_VILLAGER_YES : Sound.valueOf("VILLAGER_YES"), 1F, 1F); }); } diff --git a/src/main/java/com/songoda/ultimatekits/gui/GUIKitSelector.java b/src/main/java/com/songoda/ultimatekits/gui/GUIKitSelector.java index 669fccc..67c3cd8 100644 --- a/src/main/java/com/songoda/ultimatekits/gui/GUIKitSelector.java +++ b/src/main/java/com/songoda/ultimatekits/gui/GUIKitSelector.java @@ -3,6 +3,7 @@ package com.songoda.ultimatekits.gui; import com.songoda.ultimatekits.UltimateKits; import com.songoda.ultimatekits.kit.Kit; import com.songoda.ultimatekits.utils.Methods; +import com.songoda.ultimatekits.utils.ServerVersion; import com.songoda.ultimatekits.utils.gui.AbstractGUI; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -219,15 +220,14 @@ public class GUIKitSelector extends AbstractGUI { infometa.setLore(lore); info.setItemMeta(infometa); - ItemStack head = new ItemStack(Material.PLAYER_HEAD, 1, (byte) 3); + ItemStack head = new ItemStack(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.PLAYER_HEAD : Material.valueOf("SKULL_ITEM"), 1, (byte) 3); ItemStack skull = Methods.addTexture(head, "http://textures.minecraft.net/texture/1b6f1a25b6bc199946472aedb370522584ff6f4e83221e5946bd2e41b5ca13b"); SkullMeta skullMeta = (SkullMeta) skull.getItemMeta(); skull.setDurability((short) 3); skullMeta.setDisplayName(plugin.getLocale().getMessage("interface.button.next")); skull.setItemMeta(skullMeta); - ItemStack head2 = new ItemStack(Material.PLAYER_HEAD, 1, (byte) 3); - ItemStack skull2 = Methods.addTexture(head2, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"); + ItemStack skull2 = Methods.addTexture(head, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"); SkullMeta skull2Meta = (SkullMeta) skull2.getItemMeta(); skull2.setDurability((short) 3); skull2Meta.setDisplayName(plugin.getLocale().getMessage("interface.button.next")); diff --git a/src/main/java/com/songoda/ultimatekits/gui/GUISellingOptions.java b/src/main/java/com/songoda/ultimatekits/gui/GUISellingOptions.java index 61b4c9d..b7c34e3 100644 --- a/src/main/java/com/songoda/ultimatekits/gui/GUISellingOptions.java +++ b/src/main/java/com/songoda/ultimatekits/gui/GUISellingOptions.java @@ -3,6 +3,7 @@ package com.songoda.ultimatekits.gui; import com.songoda.ultimatekits.UltimateKits; import com.songoda.ultimatekits.kit.Kit; import com.songoda.ultimatekits.utils.Methods; +import com.songoda.ultimatekits.utils.ServerVersion; import com.songoda.ultimatekits.utils.gui.AbstractAnvilGUI; import com.songoda.ultimatekits.utils.gui.AbstractGUI; import org.bukkit.Material; @@ -53,9 +54,8 @@ public class GUISellingOptions extends AbstractGUI { createButton(8, Material.valueOf(UltimateKits.getInstance().getConfig().getString("Interfaces.Exit Icon")), UltimateKits.getInstance().getLocale().getMessage("interface.button.exit")); - ItemStack head2 = new ItemStack(Material.PLAYER_HEAD, 1, (byte) 3); - ItemStack back = head2; - back = Methods.addTexture(head2, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"); + ItemStack head = new ItemStack(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.PLAYER_HEAD : Material.valueOf("SKULL_ITEM"), 1, (byte) 3); + ItemStack back = Methods.addTexture(head, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"); SkullMeta skull2Meta = (SkullMeta) back.getItemMeta(); back.setDurability((short) 3); skull2Meta.setDisplayName(UltimateKits.getInstance().getLocale().getMessage("interface.button.back")); @@ -101,7 +101,7 @@ public class GUISellingOptions extends AbstractGUI { lore.add(Methods.formatText("&7purchase this kit for")); lore.add(Methods.formatText("&7requires &aVault&7.")); - createButton(15, Material.SUNFLOWER, "&a&lSet kit price", lore); + createButton(15, plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.SUNFLOWER : Material.valueOf("DOUBLE_PLANT"), "&a&lSet kit price", lore); } @Override @@ -133,7 +133,7 @@ public class GUISellingOptions extends AbstractGUI { gui.setOnClose((player2, inventory3) -> init(setTitle, inventory.getSize())); - ItemStack item = new ItemStack(Material.SUNFLOWER); + ItemStack item = new ItemStack(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.SUNFLOWER : Material.valueOf("DOUBLE_PLANT")); ItemMeta meta = item.getItemMeta(); meta.setDisplayName("Enter Price (No $)"); item.setItemMeta(meta); diff --git a/src/main/java/com/songoda/ultimatekits/handlers/ParticleHandler.java b/src/main/java/com/songoda/ultimatekits/handlers/ParticleHandler.java index 65563e1..c6216b9 100644 --- a/src/main/java/com/songoda/ultimatekits/handlers/ParticleHandler.java +++ b/src/main/java/com/songoda/ultimatekits/handlers/ParticleHandler.java @@ -3,6 +3,7 @@ package com.songoda.ultimatekits.handlers; import com.songoda.ultimatekits.UltimateKits; import com.songoda.ultimatekits.kit.KitBlockData; import com.songoda.ultimatekits.utils.Debugger; +import com.songoda.ultimatekits.utils.ServerVersion; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -13,27 +14,28 @@ import java.util.Map; */ public class ParticleHandler { - private final UltimateKits instance; + private final UltimateKits plugin; - public ParticleHandler(UltimateKits instance) { - this.instance = instance; + public ParticleHandler(UltimateKits plugin) { + this.plugin = plugin; checkDefaults(); Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(UltimateKits.getInstance(), this::applyParticles, 0, 10L); } private void applyParticles() { try { - int amt = instance.getConfig().getInt("data.particlesettings.ammount"); - String type = instance.getConfig().getString("data.particlesettings.type"); + int amt = plugin.getConfig().getInt("data.particlesettings.ammount"); + String type = plugin.getConfig().getString("data.particlesettings.type"); - Map kitBlocks = instance.getKitManager().getKitLocations(); + Map kitBlocks = plugin.getKitManager().getKitLocations(); for (KitBlockData kitBlockData : kitBlocks.values()) { if (kitBlockData.getLocation().getWorld() == null || !kitBlockData.hasParticles()) continue; Location location = kitBlockData.getLocation(); location.add(.5, 0, .5); - location.getWorld().spawnParticle(org.bukkit.Particle.valueOf(type), location, amt, 0.25, 0.25, 0.25); + if (plugin.isServerVersionAtLeast(ServerVersion.V1_8)) + location.getWorld().spawnParticle(org.bukkit.Particle.valueOf(type), location, amt, 0.25, 0.25, 0.25); } } catch (Exception ex) { @@ -43,13 +45,13 @@ public class ParticleHandler { private void checkDefaults() { try { - if (instance.getConfig().getInt("data.particlesettings.ammount") == 0) { - instance.getConfig().set("data.particlesettings.ammount", 25); - instance.saveConfig(); + if (plugin.getConfig().getInt("data.particlesettings.ammount") == 0) { + plugin.getConfig().set("data.particlesettings.ammount", 25); + plugin.saveConfig(); } - if (instance.getConfig().getString("data.particlesettings.type") != null) return; - instance.getConfig().set("data.particlesettings.type", "SPELL_WITCH"); - instance.saveConfig(); + if (plugin.getConfig().getString("data.particlesettings.type") != null) return; + plugin.getConfig().set("data.particlesettings.type", "SPELL_WITCH"); + plugin.saveConfig(); } catch (Exception ex) { Debugger.runReport(ex); } diff --git a/src/main/java/com/songoda/ultimatekits/kit/Kit.java b/src/main/java/com/songoda/ultimatekits/kit/Kit.java index 4fb17cc..84971eb 100644 --- a/src/main/java/com/songoda/ultimatekits/kit/Kit.java +++ b/src/main/java/com/songoda/ultimatekits/kit/Kit.java @@ -10,6 +10,7 @@ import com.songoda.ultimatekits.kit.type.KitContentItem; import com.songoda.ultimatekits.tasks.CrateAnimateTask; import com.songoda.ultimatekits.utils.Debugger; import com.songoda.ultimatekits.utils.Methods; +import com.songoda.ultimatekits.utils.ServerVersion; import com.songoda.ultimatekits.utils.gui.AbstractGUI; import me.clip.placeholderapi.PlaceholderAPI; import net.milkbowl.vault.economy.Economy; @@ -125,7 +126,7 @@ public class Kit { return; } if (plugin.getConfig().getBoolean("Main.Sounds Enabled") && kitAnimation == KitAnimation.NONE) { - player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 0.6F, 15.0F); + player.playSound(player.getLocation(), UltimateKits.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? Sound.ENTITY_PLAYER_LEVELUP : Sound.valueOf("LEVEL_UP"), 0.6F, 15.0F); } if (useKey) { if (player.getItemInHand().getType() != Material.TRIPWIRE_HOOK || !player.getItemInHand().hasItemMeta()) { diff --git a/src/main/java/com/songoda/ultimatekits/kit/KitItem.java b/src/main/java/com/songoda/ultimatekits/kit/KitItem.java index 3ea3831..dbea6a0 100644 --- a/src/main/java/com/songoda/ultimatekits/kit/KitItem.java +++ b/src/main/java/com/songoda/ultimatekits/kit/KitItem.java @@ -31,7 +31,7 @@ public class KitItem { } else if (line.startsWith("/")) { this.content = new KitContentCommand(line.substring(1)); } else { - this.content = new KitContentItem(UltimateKits.getInstance().getItemSerializer().deserializeLegacyItemStack(line)); + this.content = new KitContentItem(UltimateKits.getInstance().getItemSerializer().deserializeItemStackFromJson(line)); } } @@ -46,7 +46,7 @@ public class KitItem { } else if (line.startsWith("/")) { this.content = new KitContentCommand(line.substring(1)); } else { - this.content = new KitContentItem(UltimateKits.getInstance().getItemSerializer().deserializeLegacyItemStack(line)); + this.content = new KitContentItem(UltimateKits.getInstance().getItemSerializer().deserializeItemStackFromJson(line)); } } diff --git a/src/main/java/com/songoda/ultimatekits/listeners/InteractListeners.java b/src/main/java/com/songoda/ultimatekits/listeners/InteractListeners.java index db3971d..7b34501 100644 --- a/src/main/java/com/songoda/ultimatekits/listeners/InteractListeners.java +++ b/src/main/java/com/songoda/ultimatekits/listeners/InteractListeners.java @@ -7,6 +7,7 @@ import com.songoda.ultimatekits.kit.KitBlockData; import com.songoda.ultimatekits.kit.KitType; import com.songoda.ultimatekits.utils.Debugger; import com.songoda.ultimatekits.utils.Methods; +import com.songoda.ultimatekits.utils.ServerVersion; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Player; @@ -29,7 +30,8 @@ public class InteractListeners implements Listener { public void onBlockInteract(PlayerInteractEvent event) { try { boolean chand = true; // This needs to be out of my code. - if (event.getHand() != EquipmentSlot.HAND) { + if (instance.isServerVersionAtLeast(ServerVersion.V1_9) + && event.getHand() != EquipmentSlot.HAND) { chand = false; } diff --git a/src/main/java/com/songoda/ultimatekits/tasks/CrateAnimateTask.java b/src/main/java/com/songoda/ultimatekits/tasks/CrateAnimateTask.java index d283052..8987861 100644 --- a/src/main/java/com/songoda/ultimatekits/tasks/CrateAnimateTask.java +++ b/src/main/java/com/songoda/ultimatekits/tasks/CrateAnimateTask.java @@ -4,6 +4,7 @@ import com.songoda.ultimatekits.UltimateKits; import com.songoda.ultimatekits.kit.Kit; import com.songoda.ultimatekits.kit.KitItem; import com.songoda.ultimatekits.utils.Methods; +import com.songoda.ultimatekits.utils.ServerVersion; import org.apache.commons.lang.WordUtils; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -87,7 +88,7 @@ public class CrateAnimateTask extends BukkitRunnable { } for (int i = 9; i < 18; i++) { - inventory.setItem(i, new ItemStack(Material.GRAY_STAINED_GLASS_PANE)); + inventory.setItem(i, new ItemStack(plugin.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? Material.GRAY_STAINED_GLASS_PANE : Material.valueOf("STAINED_GLASS_PANE"))); } @@ -95,7 +96,7 @@ public class CrateAnimateTask extends BukkitRunnable { inventory.setItem(22, new ItemStack(Material.TRIPWIRE_HOOK)); if (!done) { - player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 5f, 5f); + player.playSound(player.getLocation(), plugin.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? Sound.UI_BUTTON_CLICK : Sound.valueOf("CLICK"), 5f, 5f); this.items.addFirst(this.items.getLast()); this.items.removeLast(); } @@ -112,7 +113,7 @@ public class CrateAnimateTask extends BukkitRunnable { for (ItemStack item2 : overfilled.values()) { player.getWorld().dropItemNaturally(player.getLocation(), item2); } - player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 10f, 10f); + player.playSound(player.getLocation(), UltimateKits.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? Sound.ENTITY_PLAYER_LEVELUP : Sound.valueOf("LEVEL_UP"), 10f, 10f); player.sendMessage(plugin.getReferences().getPrefix() + plugin.getLocale().getMessage("event.create.won", WordUtils.capitalize(give.getType().name().toLowerCase().replace("_", " ")))); Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, this::finish, 50); } diff --git a/src/main/java/com/songoda/ultimatekits/utils/ItemSerializer.java b/src/main/java/com/songoda/ultimatekits/utils/ItemSerializer.java index 76dcc20..c2ae38b 100644 --- a/src/main/java/com/songoda/ultimatekits/utils/ItemSerializer.java +++ b/src/main/java/com/songoda/ultimatekits/utils/ItemSerializer.java @@ -1,5 +1,6 @@ package com.songoda.ultimatekits.utils; +import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.UUID; @@ -22,235 +23,93 @@ import org.bukkit.potion.PotionEffectType; import com.songoda.ultimatekits.UltimateKits; public class ItemSerializer { - + // classes needed for reflections - + private Class classMojangsonParser = Class.forName(formatNMS("net.minecraft.server.NMS.MojangsonParser")); private Class classItemStack = Class.forName(formatNMS("net.minecraft.server.NMS.ItemStack")); private Class classCraftItemStack = Class.forName(formatNMS("org.bukkit.craftbukkit.NMS.inventory.CraftItemStack")); private Class classNBTTagCompound = Class.forName(formatNMS("net.minecraft.server.NMS.NBTTagCompound")); private Class classBukkitItemStack = Class.forName("org.bukkit.inventory.ItemStack"); - + + private Constructor constructorItemStack; + // reflected methods - + private Method methodParseString; - private Method methodToItemStack; + private Method methodCreateStack; private Method methodTobItemStack; private Method methodTocItemStack; private Method methodSaveTagToStack; private Method methodToString; - + /** * Initializes all reflection methods - * + * * @throws NoSuchMethodException * @throws SecurityException * @throws ClassNotFoundException */ public ItemSerializer() throws NoSuchMethodException, SecurityException, ClassNotFoundException { methodParseString = classMojangsonParser.getMethod("parse", String.class); - methodToItemStack = classItemStack.getMethod("a", classNBTTagCompound); + if (UltimateKits.getInstance().isServerVersionAtLeast(ServerVersion.V1_11)) + constructorItemStack = classItemStack.getConstructor(classNBTTagCompound); + else + methodCreateStack = classItemStack.getMethod("createStack", classNBTTagCompound); methodTobItemStack = classCraftItemStack.getMethod("asBukkitCopy", classItemStack); - + methodTocItemStack = classCraftItemStack.getDeclaredMethod("asNMSCopy", classBukkitItemStack); methodSaveTagToStack = classItemStack.getMethod("save", classNBTTagCompound); methodToString = classNBTTagCompound.getMethod("toString"); } - - /** - * Inserts the version declaration for any string containing NMS - * - * @param s the string to format, must contain NMS. - * @return formatted string - */ - private String formatNMS(String s) { + + /** + * Inserts the version declaration for any string containing NMS + * + * @param s the string to format, must contain NMS. + * @return formatted string + */ + private String formatNMS(String s) { String packageName = Bukkit.getServer().getClass().getPackage().getName(); - String nmsVersion = packageName.substring(packageName.lastIndexOf('.') + 1); - return s.replace("NMS", nmsVersion); - } + String nmsVersion = packageName.substring(packageName.lastIndexOf('.') + 1); + return s.replace("NMS", nmsVersion); + } - /** - * Deserializes a JSON String - * - * @param jsonString the JSON String to parse - * @return the deserialized ItemStack - */ - public ItemStack deserializeItemStackFromJson(String jsonString) { - try { - Object nbtTagCompound = methodParseString.invoke(null, jsonString); - Object citemStack = methodToItemStack.invoke(null, nbtTagCompound); - - return (ItemStack) methodTobItemStack.invoke(null, citemStack); - } catch (Exception ex) { - ex.printStackTrace(); - return null; - } - } + /** + * Deserializes a JSON String + * + * @param jsonString the JSON String to parse + * @return the deserialized ItemStack + */ + public ItemStack deserializeItemStackFromJson(String jsonString) { + try { + Object nbtTagCompound = methodParseString.invoke(null, jsonString); + Object citemStack = UltimateKits.getInstance().isServerVersionAtLeast(ServerVersion.V1_11) ? constructorItemStack.newInstance(nbtTagCompound) : methodCreateStack.invoke(null, nbtTagCompound); - /** - * Serializes an item stack - * - * @param itemStack the ItemStack to parse - * @return condensed JSON String - */ - public String serializeItemStackToJson(ItemStack itemStack) { - try { + return (ItemStack) methodTobItemStack.invoke(null, citemStack); + } catch (Exception ex) { + ex.printStackTrace(); + return null; + } + } + + /** + * Serializes an item stack + * + * @param itemStack the ItemStack to parse + * @return condensed JSON String + */ + public String serializeItemStackToJson(ItemStack itemStack) { + try { Object citemStack = methodTocItemStack.invoke(null, itemStack); Object nbtTagCompoundObject = classNBTTagCompound.newInstance(); - + methodSaveTagToStack.invoke(citemStack, nbtTagCompoundObject); - + return (String) methodToString.invoke(nbtTagCompoundObject); } catch (Exception e) { e.printStackTrace(); return null; } - } - - - /** - * Deserializes a string to an item stack, support both formats - * - * @param string the formatted string - * @return the deserialized ItemStack - */ - public ItemStack deserializeLegacyItemStack(String string) { - if(string.contains("{")) { - // string is json - return deserializeItemStackFromJson(string); - } - // old format - return deserializeItemStack(string); - } - - /** - * This method is not able to handle skulls or in general nbt tags. - * Method is still existing for converting purposes. - * - * @deprecated use {@link #serializeItemStackToJson(ItemStack is)} instead. - */ - @Deprecated - public ItemStack deserializeItemStack(String string) { - string = string.replace("&", "§"); - String[] splited = string.split("\\s+"); - - String[] val = splited[0].split(":"); - ItemStack item = new ItemStack(Material.valueOf(val[0])); - - if (item.getType() == Material.PLAYER_HEAD) { - item = new ItemStack(Material.PLAYER_HEAD, 1, (byte) 3); - } - - ItemMeta meta = item.getItemMeta(); - - if (val.length == 2) { - item.setDurability(Short.parseShort(val[1])); - } - if (splited.length >= 2) { - if (Methods.isNumeric(splited[1])) { - item.setAmount(Integer.parseInt(splited[1])); - } - - for (String st : splited) { - String str = unfixLine(st); - if (!str.contains(":")) continue; - String[] ops = str.split(":", 2); - - String option = ops[0]; - String value = ops[1]; - - if (Enchantment.getByName(option.replace(" ", "_").toUpperCase()) != null) { - Enchantment enchantment = Enchantment.getByName(option.replace(" ", "_").toUpperCase()); - if (item.getType() != Material.ENCHANTED_BOOK) { - meta.addEnchant(enchantment, Integer.parseInt(value), true); - } else { - ((EnchantmentStorageMeta) meta).addStoredEnchant(enchantment, Integer.parseInt(value), true); - } - } - - String effect = ""; - int duration = 0; - int hit = 0; - - value = value.replace("_", " "); - switch (option) { - case "title": - if (item.getType() == Material.WRITTEN_BOOK) { - ((BookMeta) meta).setTitle(value); - } else meta.setDisplayName(value); - break; - case "lore": - String[] parts = value.split("\\|"); - ArrayList lore = new ArrayList<>(); - for (String line : parts) - lore.add(Methods.formatText(line)); - meta.setLore(lore); - break; - case "player": - if (item.getType() == Material.PLAYER_HEAD) { - if (value.length() == 36) - ((SkullMeta) meta).setOwningPlayer(Bukkit.getOfflinePlayer(UUID.fromString(value))); - else - ((SkullMeta) meta).setOwner(value); - } - break; - case "author": - if (item.getType() == Material.WRITTEN_BOOK) { - ((BookMeta) meta).setAuthor(value); - } - break; - case "effect": - case "duration": - hit++; - if (option.equalsIgnoreCase("effect")) { - effect = value; - } else { - duration = Integer.parseInt(value); - } - - if (hit == 2) { - PotionEffect effect2 = PotionEffectType.getByName(effect).createEffect(duration, 0); - ((PotionMeta) meta).addCustomEffect(effect2, false); - } - - break; - case "id": - if (item.getType() == Material.WRITTEN_BOOK) { - if (!UltimateKits.getInstance().getDataFile().getConfig().contains("Books.pages." + value)) - continue; - ConfigurationSection cs = UltimateKits.getInstance().getDataFile().getConfig().getConfigurationSection("Books.pages." + value); - for (String key : cs.getKeys(false)) { - ((BookMeta) meta).addPage(UltimateKits.getInstance().getDataFile().getConfig().getString("Books.pages." + value + "." + key)); - } - } - break; - case "color": - switch (item.getType()) { - case POTION: - //ToDO: this - break; - case LEATHER_HELMET: - case LEATHER_CHESTPLATE: - case LEATHER_LEGGINGS: - case LEATHER_BOOTS: - ((LeatherArmorMeta) meta).setColor(Color.fromRGB(Integer.parseInt(value))); - break; - } - break; - } - } - } - item.setItemMeta(meta); - return item; - } - - private String fixLine(String line) { - line = line.replace(" ", "_"); - return line; - } - - private String unfixLine(String line) { - line = line.replace("_", " "); - return line; - } -} + } +} \ No newline at end of file diff --git a/src/main/java/com/songoda/ultimatekits/utils/Methods.java b/src/main/java/com/songoda/ultimatekits/utils/Methods.java index 20795b6..fc71715 100644 --- a/src/main/java/com/songoda/ultimatekits/utils/Methods.java +++ b/src/main/java/com/songoda/ultimatekits/utils/Methods.java @@ -25,35 +25,27 @@ public class Methods { public static ItemStack getGlass() { - try { - UltimateKits instance = UltimateKits.getInstance(); - return Methods.getGlass(instance.getConfig().getBoolean("Interfaces.Replace Glass Type 1 With Rainbow Glass"), instance.getConfig().getInt("Interfaces.Glass Type 1")); - } catch (Exception e) { - Debugger.runReport(e); - } - return null; + UltimateKits instance = UltimateKits.getInstance(); + return Methods.getGlass(instance.getConfig().getBoolean("Interfaces.Replace Glass Type 1 With Rainbow Glass"), instance.getConfig().getInt("Interfaces.Glass Type 1")); } public static ItemStack getBackgroundGlass(boolean type) { - try { - UltimateKits instance = UltimateKits.getInstance(); - if (type) - return getGlass(false, instance.getConfig().getInt("Interfaces.Glass Type 2")); - else - return getGlass(false, instance.getConfig().getInt("Interfaces.Glass Type 3")); - } catch (Exception e) { - Debugger.runReport(e); - } - return null; + UltimateKits instance = UltimateKits.getInstance(); + if (type) + return getGlass(false, instance.getConfig().getInt("Interfaces.Glass Type 2")); + else + return getGlass(false, instance.getConfig().getInt("Interfaces.Glass Type 3")); } private static ItemStack getGlass(Boolean rainbow, int type) { int randomNum = 1 + (int) (Math.random() * 6); ItemStack glass; if (rainbow) { - glass = new ItemStack(Material.LEGACY_STAINED_GLASS_PANE, 1, (short) randomNum); + glass = new ItemStack(UltimateKits.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? + Material.LEGACY_STAINED_GLASS_PANE : Material.valueOf("STAINED_GLASS_PANE"), 1, (short) randomNum); } else { - glass = new ItemStack(Material.LEGACY_STAINED_GLASS_PANE, 1, (short) type); + glass = new ItemStack(UltimateKits.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? + Material.LEGACY_STAINED_GLASS_PANE : Material.valueOf("STAINED_GLASS_PANE"), 1, (short) type); } ItemMeta glassmeta = glass.getItemMeta(); glassmeta.setDisplayName("§l"); @@ -157,10 +149,10 @@ public class Methods { public static String formatTitle(String text) { if (text == null || text.equals("")) return ""; - /* if (UltimateKits.getInstance().isServerVersionAtLeast(ServerVersion.V1_9)) { + if (!UltimateKits.getInstance().isServerVersionAtLeast(ServerVersion.V1_9)) { if (text.length() > 31) text = text.substring(0, 29) + "..."; - } */ + } text = formatText(text); return text; } diff --git a/src/main/java/com/songoda/ultimatekits/utils/ServerVersion.java b/src/main/java/com/songoda/ultimatekits/utils/ServerVersion.java new file mode 100644 index 0000000..dff3ec1 --- /dev/null +++ b/src/main/java/com/songoda/ultimatekits/utils/ServerVersion.java @@ -0,0 +1,27 @@ +package com.songoda.ultimatekits.utils; + +public enum ServerVersion { + + UNKNOWN("unknown_server_version"), + V1_7("org.bukkit.craftbukkit.v1_7"), + V1_8("org.bukkit.craftbukkit.v1_8"), + V1_9("org.bukkit.craftbukkit.v1_9"), + V1_10("org.bukkit.craftbukkit.v1_10"), + V1_11("org.bukkit.craftbukkit.v1_11"), + V1_12("org.bukkit.craftbukkit.v1_12"), + V1_13("org.bukkit.craftbukkit.v1_13"), + V1_14("org.bukkit.craftbukkit.v1_14"); + + + private final String packagePrefix; + + private ServerVersion(String packagePrefix) { + this.packagePrefix = packagePrefix; + } + + public static ServerVersion fromPackageName(String packageName) { + for (ServerVersion version : values()) + if (packageName.startsWith(version.packagePrefix)) return version; + return ServerVersion.UNKNOWN; + } +} \ No newline at end of file diff --git a/src/main/java/com/songoda/ultimatekits/utils/SettingsManager.java b/src/main/java/com/songoda/ultimatekits/utils/SettingsManager.java index 33e673d..53317dd 100644 --- a/src/main/java/com/songoda/ultimatekits/utils/SettingsManager.java +++ b/src/main/java/com/songoda/ultimatekits/utils/SettingsManager.java @@ -23,229 +23,201 @@ import java.util.regex.Pattern; */ public class SettingsManager implements Listener { - private static ConfigWrapper defs; + private static final Pattern SETTINGS_PATTERN = Pattern.compile("(.{1,28}(?:\\s|$))|(.{0,28})", Pattern.DOTALL); private final UltimateKits instance; - private Map current = new HashMap<>(); private String pluginName = "UltimateKits"; private Map cat = new HashMap<>(); + private Map current = new HashMap<>(); - public SettingsManager(UltimateKits instance) { - this.instance = instance; - instance.saveResource("SettingDefinitions.yml", true); - defs = new ConfigWrapper(instance, "", "SettingDefinitions.yml"); - defs.createNewFile("Loading data file", "UltimateKits SettingDefinitions file"); - instance.getServer().getPluginManager().registerEvents(this, instance); + public SettingsManager(UltimateKits plugin) { + this.instance = plugin; + Bukkit.getPluginManager().registerEvents(this, plugin); } @EventHandler - public void onInventoryClick(InventoryClickEvent e) { - if (e.getInventory() == null - || e.getCurrentItem() == null - || !e.getCurrentItem().hasItemMeta() - || !e.getCurrentItem().getItemMeta().hasDisplayName() - || e.getWhoClicked().getOpenInventory().getTopInventory() != e.getInventory()) { + public void onInventoryClick(InventoryClickEvent event) { + ItemStack clickedItem = event.getCurrentItem(); + + if (event.getInventory() != event.getWhoClicked().getOpenInventory().getTopInventory() + || clickedItem == null || !clickedItem.hasItemMeta() + || !clickedItem.getItemMeta().hasDisplayName()) { return; } - if (e.getView().getTitle().equals(pluginName + " Settings Manager")) { - if (e.getCurrentItem().getType().name().contains("STAINED_GLASS")) { - e.setCancelled(true); - return; - } + if (event.getView().getTitle().equals(pluginName + " Settings Manager")) { + event.setCancelled(true); + if (clickedItem.getType().name().contains("STAINED_GLASS")) return; - String type = ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName()); - cat.put((Player) e.getWhoClicked(), type); - openEditor((Player) e.getWhoClicked()); - e.setCancelled(true); - } else if (e.getView().getTitle().equals(pluginName + " Settings KitEditor")) { + String type = ChatColor.stripColor(clickedItem.getItemMeta().getDisplayName()); + this.cat.put((Player) event.getWhoClicked(), type); + this.openEditor((Player) event.getWhoClicked()); + } else if (event.getView().getTitle().equals(pluginName + " Settings Editor")) { + event.setCancelled(true); + if (clickedItem.getType().name().contains("STAINED_GLASS")) return; - if (e.getCurrentItem().getType().name().contains("STAINED_GLASS")) { - e.setCancelled(true); - return; - } + Player player = (Player) event.getWhoClicked(); - Player p = (Player) e.getWhoClicked(); - e.setCancelled(true); - - String key = cat.get(p) + "." + ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName()); + String key = cat.get(player) + "." + ChatColor.stripColor(clickedItem.getItemMeta().getDisplayName()); if (instance.getConfig().get(key).getClass().getName().equals("java.lang.Boolean")) { - boolean bool = (Boolean) instance.getConfig().get(key); - if (!bool) - instance.getConfig().set(key, true); - else - instance.getConfig().set(key, false); - finishEditing(p); + this.instance.getConfig().set(key, !instance.getConfig().getBoolean(key)); + this.finishEditing(player); } else { - editObject(p, key); + this.editObject(player, key); } } } @EventHandler - public void onChat(AsyncPlayerChatEvent e) { - final Player p = e.getPlayer(); - if (!current.containsKey(p)) { - return; - } - switch (instance.getConfig().get(current.get(p)).getClass().getName()) { - case "java.lang.Integer": - instance.getConfig().set(current.get(p), Integer.parseInt(e.getMessage())); - break; - case "java.lang.Double": - instance.getConfig().set(current.get(p), Double.parseDouble(e.getMessage())); - break; - case "java.lang.String": - instance.getConfig().set(current.get(p), e.getMessage()); - break; + public void onChat(AsyncPlayerChatEvent event) { + Player player = event.getPlayer(); + if (!current.containsKey(player)) return; + + String value = current.get(player); + FileConfiguration config = instance.getConfig(); + if (config.isInt(value)) { + config.set(value, Integer.parseInt(event.getMessage())); + } else if (config.isDouble(value)) { + config.set(value, Double.parseDouble(event.getMessage())); + } else if (config.isString(value)) { + config.set(value, event.getMessage()); } Bukkit.getScheduler().scheduleSyncDelayedTask(UltimateKits.getInstance(), () -> - this.finishEditing(p), 0L); - - e.setCancelled(true); + this.finishEditing(player), 0L); + event.setCancelled(true); } - private void finishEditing(Player p) { - current.remove(p); - instance.saveConfig(); - openEditor(p); + private void finishEditing(Player player) { + this.current.remove(player); + this.instance.saveConfig(); + this.openEditor(player); } + private void editObject(Player player, String current) { + this.current.put(player, ChatColor.stripColor(current)); - private void editObject(Player p, String current) { - this.current.put(p, ChatColor.stripColor(current)); - p.closeInventory(); - p.sendMessage(""); - p.sendMessage(Methods.formatText("&7Please enter a value for &6" + current + "&7.")); - if (instance.getConfig().get(current).getClass().getName().equals("java.lang.Integer")) { - p.sendMessage(Methods.formatText("&cUse only numbers.")); + player.closeInventory(); + player.sendMessage(""); + player.sendMessage(Methods.formatText("&7Please enter a value for &6" + current + "&7.")); + if (instance.getConfig().isInt(current) || instance.getConfig().isDouble(current)) { + player.sendMessage(Methods.formatText("&cUse only numbers.")); } - p.sendMessage(""); + player.sendMessage(""); } - public void openSettingsManager(Player p) { - Inventory i = Bukkit.createInventory(null, 27, pluginName + " Settings Manager"); - int nu = 0; - while (nu != 27) { - i.setItem(nu, Methods.getGlass()); - nu++; + public void openSettingsManager(Player player) { + Inventory inventory = Bukkit.createInventory(null, 27, pluginName + " Settings Manager"); + ItemStack glass = Methods.getGlass(); + for (int i = 0; i < inventory.getSize(); i++) { + inventory.setItem(i, glass); } - int spot = 10; - for (String key : instance.getConfig().getConfigurationSection("").getKeys(false)) { - ItemStack item = new ItemStack(Material.WHITE_WOOL, 1, (byte) (spot - 9)); //ToDo: Make this function as it was meant to. + int slot = 10; + for (String key : instance.getConfig().getDefaultSection().getKeys(false)) { + ItemStack item = new ItemStack(instance.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.WHITE_WOOL : Material.valueOf("WOOL"), 1, (byte) (slot - 9)); //ToDo: Make this function as it was meant to. ItemMeta meta = item.getItemMeta(); meta.setLore(Collections.singletonList(Methods.formatText("&6Click To Edit This Category."))); meta.setDisplayName(Methods.formatText("&f&l" + key)); item.setItemMeta(meta); - i.setItem(spot, item); - spot++; + inventory.setItem(slot, item); + slot++; } - p.openInventory(i); + + player.openInventory(inventory); } - private void openEditor(Player p) { - Inventory i = Bukkit.createInventory(null, 54, pluginName + " Settings KitEditor"); + private void openEditor(Player player) { + Inventory inventory = Bukkit.createInventory(null, 54, pluginName + " Settings Editor"); + FileConfiguration config = instance.getConfig(); - int num = 0; - for (String key : instance.getConfig().getConfigurationSection(cat.get(p)).getKeys(true)) { - String fKey = cat.get(p) + "." + key; + int slot = 0; + for (String key : config.getConfigurationSection(cat.get(player)).getKeys(true)) { + String fKey = cat.get(player) + "." + key; ItemStack item = new ItemStack(Material.DIAMOND_HELMET); ItemMeta meta = item.getItemMeta(); meta.setDisplayName(Methods.formatText("&6" + key)); - ArrayList lore = new ArrayList<>(); - switch (instance.getConfig().get(fKey).getClass().getName()) { - case "java.lang.Boolean": - item.setType(Material.LEVER); - boolean bool = (Boolean) instance.getConfig().get(fKey); - - if (!bool) - lore.add(Methods.formatText("&c" + false)); - else - lore.add(Methods.formatText("&a" + true)); - - break; - case "java.lang.String": - item.setType(Material.PAPER); - String str = (String) instance.getConfig().get(fKey); - lore.add(Methods.formatText("&9" + str)); - break; - case "java.lang.Integer": - item.setType(Material.CLOCK); - - int in = (Integer) instance.getConfig().get(fKey); - lore.add(Methods.formatText("&5" + in)); - break; - default: - continue; + List lore = new ArrayList<>(); + if (config.isBoolean(fKey)) { + item.setType(Material.LEVER); + lore.add(Methods.formatText(config.getBoolean(fKey) ? "&atrue" : "&cfalse")); + } else if (config.isString(fKey)) { + item.setType(Material.PAPER); + lore.add(Methods.formatText("&9" + config.getString(fKey))); + } else if (config.isInt(fKey)) { + item.setType(instance.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.CLOCK : Material.valueOf("WATCH")); + lore.add(Methods.formatText("&5" + config.getInt(fKey))); } - if (defs.getConfig().contains(fKey)) { - String text = defs.getConfig().getString(key); - Pattern regex = Pattern.compile("(.{1,28}(?:\\s|$))|(.{0,28})", Pattern.DOTALL); - Matcher m = regex.matcher(text); - while (m.find()) { - if (m.end() != text.length() || m.group().length() != 0) - lore.add(Methods.formatText("&7" + m.group())); - } - } meta.setLore(lore); item.setItemMeta(meta); - i.setItem(num, item); - num++; + inventory.setItem(slot, item); + slot++; } - p.openInventory(i); + + player.openInventory(inventory); } public void updateSettings() { - for (settings s : settings.values()) { - FileConfiguration config = instance.getConfig(); - if (config.contains(s.oldSetting)) { - config.addDefault(s.setting, config.get(s.oldSetting)); - config.set(s.setting, config.get(s.oldSetting)); - config.set(s.oldSetting, null); - } else if (s.setting.equals("Main.Upgrade Particle Type")) { - config.addDefault(s.setting, s.option); - } else - config.addDefault(s.setting, s.option); + FileConfiguration config = instance.getConfig(); + + for (Setting setting : Setting.values()) { + config.addDefault(setting.setting, setting.option); } } - public enum settings { - o3("Only-Show-Kits-With-Perms", "Main.Only Show Players Kits They Have Permission To Use", false), - o4("Kits-Free-With-Perms", "Main.Allow Players To Receive Kits For Free If They Have Permission", true), - o5("Dont-Preview-Commands", "Main.Dont Preview Commands In Kits", false), - o6("Hologram-Layout", "Main.Hologram Layout", Arrays.asList("{TITLE}", "{LEFT-CLICK}", "{RIGHT-CLICK}")), - o7("EnableSound", "Main.Sounds Enabled", true), - o8("Sound", "Main.Sound Played While Clicking In Inventories", "ENTITY_ENDERMAN_TELEPORT"), - o85("-", "Main.Prevent The Redeeming of a Kit When Inventory Is Full", true), - o342("-", "Main.Display Chance In Preview", true), - CURRENCY_SYMBOL("-", "Main.Currency Symbol", "$"), - o9("Exit-Icon", "Interfaces.Exit Icon", "OAK_DOOR"), - o10("Buy-Icon", "Interfaces.Buy Icon", "EMERALD"), - o11("Glass-Type-1", "Interfaces.Glass Type 1", 7), - o12("Glass-Type-2", "Interfaces.Glass Type 2", 11), - o13("Glass-Type-3", "Interfaces.Glass Type 3", 3), - o14("Rainbow-Glass", "Interfaces.Replace Glass Type 1 With Rainbow Glass", false), - o15("glassless", "Interfaces.Do Not Use Glass Borders", false), + public enum Setting { + o3("Main.Only Show Players Kits They Have Permission To Use", false), + o4("Main.Allow Players To Receive Kits For Free If They Have Permission", true), + o5("Main.Dont Preview Commands In Kits", false), + o6("Main.Hologram Layout", Arrays.asList("{TITLE}", "{LEFT-CLICK}", "{RIGHT-CLICK}")), + o7("Main.Sounds Enabled", true), + o8("Main.Sound Played While Clicking In Inventories", UltimateKits.getInstance().isServerVersion(ServerVersion.V1_13) ? "ENTITY_ENDERMAN_TELEPORT" : "ENTITY_ENDERMEN_TELEPORT"), + o85("Main.Prevent The Redeeming of a Kit When Inventory Is Full", true), + o342("Main.Display Chance In Preview", true), + CURRENCY_SYMBOL("Main.Currency Symbol", "$"), - LANGUGE_MODE("-", "System.Language Mode", "en_US"), - o16("Debug-Mode", "System.Debugger Enabled", false); + EXIT_ICON("Interfaces.Exit Icon", UltimateKits.getInstance().isServerVersion(ServerVersion.V1_13) ? "OAK_DOOR" : "WOOD_DOOR"), + BUY_ICON("Interfaces.Buy Icon", "EMERALD"), + GLASS_TYPE_1("Interfaces.Glass Type 1", 7), + GLASS_TYPE_2("Interfaces.Glass Type 2", 11), + GLASS_TYPE_3("Interfaces.Glass Type 3", 3), + o14( "Interfaces.Replace Glass Type 1 With Rainbow Glass", false), + o15("Interfaces.Do Not Use Glass Borders", false), + + LANGUGE_MODE("System.Language Mode", "en_US"), + o16("System.Debugger Enabled", false); private String setting; - private String oldSetting; private Object option; - settings(String oldSetting, String setting, Object option) { - this.oldSetting = oldSetting; + Setting(String setting, Object option) { this.setting = setting; this.option = option; } + public List getStringList() { + return UltimateKits.getInstance().getConfig().getStringList(setting); + } + + public boolean getBoolean() { + return UltimateKits.getInstance().getConfig().getBoolean(setting); + } + + public int getInt() { + return UltimateKits.getInstance().getConfig().getInt(setting); + } + + public String getString() { + return UltimateKits.getInstance().getConfig().getString(setting); + } + + public char getChar() { return UltimateKits.getInstance().getConfig().getString(setting).charAt(0); } + + } } diff --git a/src/main/java/com/songoda/ultimatekits/utils/gui/AbstractAnvilGUI.java b/src/main/java/com/songoda/ultimatekits/utils/gui/AbstractAnvilGUI.java index 531eb72..304b895 100644 --- a/src/main/java/com/songoda/ultimatekits/utils/gui/AbstractAnvilGUI.java +++ b/src/main/java/com/songoda/ultimatekits/utils/gui/AbstractAnvilGUI.java @@ -301,4 +301,4 @@ public class AbstractAnvilGUI { } } -} +} \ No newline at end of file diff --git a/src/main/java/com/songoda/ultimatekits/utils/gui/AbstractGUI.java b/src/main/java/com/songoda/ultimatekits/utils/gui/AbstractGUI.java index 9551d90..3818bc5 100644 --- a/src/main/java/com/songoda/ultimatekits/utils/gui/AbstractGUI.java +++ b/src/main/java/com/songoda/ultimatekits/utils/gui/AbstractGUI.java @@ -26,7 +26,7 @@ import java.util.Map; public abstract class AbstractGUI implements Listener { private static boolean listenersInitialized = false; - protected Player player; + protected final Player player; protected Inventory inventory = null; protected String setTitle = null; protected boolean cancelBottom = false; @@ -76,7 +76,7 @@ public abstract class AbstractGUI implements Listener { } } } - + Map entries = new HashMap<>(gui.clickables); for (Map.Entry entry : entries.entrySet()) { @@ -116,9 +116,9 @@ public abstract class AbstractGUI implements Listener { public void init(String title, int slots) { if (inventory == null || inventory.getSize() != slots - || !ChatColor.translateAlternateColorCodes('&', title).equals(player.getOpenInventory().getTitle())) { + || Methods.formatTitle(title) != player.getOpenInventory().getTitle()) { this.inventory = Bukkit.getServer().createInventory(new GUIHolder(), slots, Methods.formatTitle(title)); - this.setTitle = Methods.formatText(title); + this.setTitle = Methods.formatTitle(title); if (this.clickables.size() == 0) registerClickables(); if (this.onCloses.size() == 0) @@ -156,10 +156,22 @@ public abstract class AbstractGUI implements Listener { return item; } + protected ItemStack createButton(int slot, ItemStack item, String name, ArrayList lore) { + return createButton(slot, inventory, item, name, lore.toArray(new String[0])); + } + + protected ItemStack createButton(int slot, ItemStack item, String name, String... lore) { return createButton(slot, inventory, item, name, lore); } + protected ItemStack createButton(int slot, Object item, String name, String... lore) { + if (item instanceof ItemStack) + return createButton(slot, inventory, (ItemStack)item, name, lore); + else + return createButton(slot, inventory, (Material)item, name, lore); + } + protected ItemStack createButton(int slot, Inventory inventory, Material material, String name, String... lore) { return createButton(slot, inventory, new ItemStack(material), name, lore); } diff --git a/src/main/java/com/songoda/ultimatekits/utils/gui/Range.java b/src/main/java/com/songoda/ultimatekits/utils/gui/Range.java index 5c635fe..7411943 100644 --- a/src/main/java/com/songoda/ultimatekits/utils/gui/Range.java +++ b/src/main/java/com/songoda/ultimatekits/utils/gui/Range.java @@ -1,5 +1,7 @@ package com.songoda.ultimatekits.utils.gui; +import com.songoda.ultimatekits.UltimateKits; +import com.songoda.ultimatekits.utils.ServerVersion; import org.bukkit.Sound; import org.bukkit.event.inventory.ClickType; @@ -9,13 +11,14 @@ public class Range { private int max; private ClickType clickType; private boolean bottom; - private Sound onClickSound = Sound.UI_BUTTON_CLICK; + private Sound onClickSound; public Range(int min, int max, ClickType clickType, boolean bottom) { this.min = min; this.max = max; this.clickType = clickType; this.bottom = bottom; + if (UltimateKits.getInstance().isServerVersionAtLeast(ServerVersion.V1_9)) onClickSound = Sound.UI_BUTTON_CLICK; } public Range(int min, int max, Sound onClickSound, ClickType clickType, boolean bottom) {