From 3c5f4e5185b8636d5a2f11e6d39de9e11942ec9f Mon Sep 17 00:00:00 2001 From: Brianna Date: Thu, 2 May 2019 22:29:45 -0400 Subject: [PATCH] Resolved issue with 1.14 and fixed claiming for crates. --- .../ultimatekits/gui/GUIKitSelector.java | 66 +++++++++---------- .../listeners/InteractListeners.java | 28 ++++---- .../ultimatekits/utils/ItemSerializer.java | 37 +++++------ .../ultimatekits/utils/SettingsManager.java | 4 +- 4 files changed, 62 insertions(+), 73 deletions(-) diff --git a/src/main/java/com/songoda/ultimatekits/gui/GUIKitSelector.java b/src/main/java/com/songoda/ultimatekits/gui/GUIKitSelector.java index 67c3cd8..783a977 100644 --- a/src/main/java/com/songoda/ultimatekits/gui/GUIKitSelector.java +++ b/src/main/java/com/songoda/ultimatekits/gui/GUIKitSelector.java @@ -201,7 +201,39 @@ public class GUIKitSelector extends AbstractGUI { } meta.setLore(lore); item.setItemMeta(meta); + + inventory.setItem(index, item); + registerClickable(index, ((player1, inventory1, cursor, slot, type) -> { + if (type == ClickType.MIDDLE && player.hasPermission("ultimatekits.admin")) { + kitsmode = !kitsmode; + constructGUI(); + return; + } + + if (kitsmode) { + if (type == ClickType.RIGHT) { + plugin.getKitManager().moveKit(kit, true); + } else if (type == ClickType.LEFT) { + plugin.getKitManager().moveKit(kit, false); + } + setUpPage(); + constructGUI(); + return; + } + + + if (type == ClickType.LEFT) { + kit.display(player, this); + return; + } + + if (type == ClickType.RIGHT) { + kit.buy(player); + constructGUI(); + } + })); + id++; } @@ -248,40 +280,6 @@ public class GUIKitSelector extends AbstractGUI { registerClickable(max - 5, (player, inventory, cursor, slot, type) -> player.closeInventory()); - registerClickable(glassless ? 0 : 10, glassless ? max : max - 11, (player1, inventory1, cursor, slot, type) -> { - String kitName = inventory1.getItem(slot).getItemMeta().getDisplayName().replace(String.valueOf(ChatColor.COLOR_CHAR), "").split(":")[0]; - - if (type == ClickType.MIDDLE && player.hasPermission("ultimatekits.admin")) { - kitsmode = !kitsmode; - constructGUI(); - return; - } - - Kit kit = plugin.getKitManager().getKit(kitName); - - if (kitsmode) { - if (type == ClickType.RIGHT) { - plugin.getKitManager().moveKit(kit, true); - } else if (type == ClickType.LEFT) { - plugin.getKitManager().moveKit(kit, false); - } - setUpPage(); - constructGUI(); - return; - } - - - if (type == ClickType.LEFT) { - kit.display(player, this); - return; - } - - if (type == ClickType.RIGHT) { - kit.buy(player); - constructGUI(); - } - }); - registerClickable(max - 6, ((player1, inventory1, cursor, slot, type) -> { if (page == 1) return; page --; diff --git a/src/main/java/com/songoda/ultimatekits/listeners/InteractListeners.java b/src/main/java/com/songoda/ultimatekits/listeners/InteractListeners.java index 7b34501..d21480c 100644 --- a/src/main/java/com/songoda/ultimatekits/listeners/InteractListeners.java +++ b/src/main/java/com/songoda/ultimatekits/listeners/InteractListeners.java @@ -51,28 +51,24 @@ public class InteractListeners implements Listener { if (player.isSneaking()) return; event.setCancelled(true); - if (player.getItemInHand() != null && player.getItemInHand().getType() != null && player.getItemInHand().getType() == Material.TRIPWIRE_HOOK) { + if (player.getItemInHand().getType() == Material.TRIPWIRE_HOOK) { event.setCancelled(true); kit.give(player, true, false, false); return; } if (kitBlockData.getType() != KitType.PREVIEW) { - if (kitBlockData.getType() == KitType.CRATE) { + if (!kit.hasPermission(player)) { + player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.general.noperms")); + return; + } + if (kit.getNextUse(player) <= 0) { + kit.give(player, false, false, false); + kit.updateDelay(player); + } else { long time = kit.getNextUse(player); - player.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + instance.getLocale().getMessage("event.crate.notyet", Methods.makeReadable(time)))); - } else if (kitBlockData.getType() == KitType.CLAIM) { - if (!kit.hasPermission(player)) { - player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.general.noperms")); - return; - } - if (kit.getNextUse(player) <= 0) { - kit.give(player, false, false, false); - kit.updateDelay(player); - } else { - long time = kit.getNextUse(player); - player.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + instance.getLocale().getMessage("event.crate.notyet", Methods.makeReadable(time)))); - } + player.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + + instance.getLocale().getMessage("event.crate.notyet", Methods.makeReadable(time)))); } } else if (kit.getLink() != null || kit.getPrice() != 0) { kit.buy(player); @@ -87,7 +83,7 @@ public class InteractListeners implements Listener { new GUIBlockEditor(instance, player, block.getLocation()); return; } - if (player.getItemInHand() != null && player.getItemInHand().getType() != null && player.getItemInHand().getType() == Material.TRIPWIRE_HOOK) { + if (player.getItemInHand().getType() == Material.TRIPWIRE_HOOK) { event.setCancelled(true); kit.give(player, true, false, false); return; diff --git a/src/main/java/com/songoda/ultimatekits/utils/ItemSerializer.java b/src/main/java/com/songoda/ultimatekits/utils/ItemSerializer.java index c2ae38b..a3ff8c0 100644 --- a/src/main/java/com/songoda/ultimatekits/utils/ItemSerializer.java +++ b/src/main/java/com/songoda/ultimatekits/utils/ItemSerializer.java @@ -1,26 +1,11 @@ package com.songoda.ultimatekits.utils; +import com.songoda.ultimatekits.UltimateKits; +import org.bukkit.Bukkit; +import org.bukkit.inventory.ItemStack; + import java.lang.reflect.Constructor; import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.UUID; - -import org.bukkit.Bukkit; -import org.bukkit.Color; -import org.bukkit.Material; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.BookMeta; -import org.bukkit.inventory.meta.EnchantmentStorageMeta; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.inventory.meta.LeatherArmorMeta; -import org.bukkit.inventory.meta.PotionMeta; -import org.bukkit.inventory.meta.SkullMeta; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; - -import com.songoda.ultimatekits.UltimateKits; public class ItemSerializer { @@ -38,6 +23,7 @@ public class ItemSerializer { private Method methodParseString; private Method methodCreateStack; + private Method methodToItemStack; private Method methodTobItemStack; private Method methodTocItemStack; private Method methodSaveTagToStack; @@ -52,7 +38,9 @@ public class ItemSerializer { */ public ItemSerializer() throws NoSuchMethodException, SecurityException, ClassNotFoundException { methodParseString = classMojangsonParser.getMethod("parse", String.class); - if (UltimateKits.getInstance().isServerVersionAtLeast(ServerVersion.V1_11)) + if (UltimateKits.getInstance().isServerVersionAtLeast(ServerVersion.V1_13)) + methodToItemStack = classItemStack.getMethod("a", classNBTTagCompound); + else if (UltimateKits.getInstance().isServerVersionAtLeast(ServerVersion.V1_11)) constructorItemStack = classItemStack.getConstructor(classNBTTagCompound); else methodCreateStack = classItemStack.getMethod("createStack", classNBTTagCompound); @@ -84,7 +72,14 @@ public class ItemSerializer { 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); + Object citemStack; + + if (UltimateKits.getInstance().isServerVersionAtLeast(ServerVersion.V1_13)) + citemStack = methodToItemStack.invoke(null, nbtTagCompound); + else if (UltimateKits.getInstance().isServerVersionAtLeast(ServerVersion.V1_11)) + citemStack = constructorItemStack.newInstance(nbtTagCompound); + else + citemStack = methodCreateStack.invoke(null, nbtTagCompound); return (ItemStack) methodTobItemStack.invoke(null, citemStack); } catch (Exception ex) { diff --git a/src/main/java/com/songoda/ultimatekits/utils/SettingsManager.java b/src/main/java/com/songoda/ultimatekits/utils/SettingsManager.java index 53317dd..774e79e 100644 --- a/src/main/java/com/songoda/ultimatekits/utils/SettingsManager.java +++ b/src/main/java/com/songoda/ultimatekits/utils/SettingsManager.java @@ -176,12 +176,12 @@ public class SettingsManager implements Listener { 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"), + o8("Main.Sound Played While Clicking In Inventories", UltimateKits.getInstance().isServerVersionAtLeast(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", "$"), - EXIT_ICON("Interfaces.Exit Icon", UltimateKits.getInstance().isServerVersion(ServerVersion.V1_13) ? "OAK_DOOR" : "WOOD_DOOR"), + EXIT_ICON("Interfaces.Exit Icon", UltimateKits.getInstance().isServerVersionAtLeast(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),