From 52b775de5a01b244746621094e5163d0c8e530e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Crist=C3=B3bal=20Veas?= Date: Sat, 20 Jul 2024 21:06:51 -0400 Subject: [PATCH 1/3] fix: detect 1.21 as a newer version correctly in enchantment fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cristóbal Veas --- .../team/devblook/akropolis/util/ItemStackBuilder.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/team/devblook/akropolis/util/ItemStackBuilder.java b/src/main/java/team/devblook/akropolis/util/ItemStackBuilder.java index b556ac5..0b5d39f 100644 --- a/src/main/java/team/devblook/akropolis/util/ItemStackBuilder.java +++ b/src/main/java/team/devblook/akropolis/util/ItemStackBuilder.java @@ -48,7 +48,12 @@ public class ItemStackBuilder { // Fix: unknown "ARROW_INFINITE" field on versions 1.20.6 or newer. try { // 1.20.6 -> 206 - final int version = Integer.parseInt(Bukkit.getMinecraftVersion().substring(2).replace(".", "")); + String strippedVersion = Bukkit.getMinecraftVersion() + .substring(2) + .replace(".", ""); + // 1.21 -> 21 -> 210 + int version = Integer.parseInt(strippedVersion.length() == 2 ? strippedVersion + "0" : strippedVersion); + Field field = null; // This would correspond to check if the version is higher or equals to // 1.20.6. From b03e1c9cd8ca697a74d9a42d295ef10e786596f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Crist=C3=B3bal=20Veas?= Date: Sat, 20 Jul 2024 21:07:34 -0400 Subject: [PATCH 2/3] revert: "chore: bump up version to 1.5.4" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 21bcee659d421ecb9112a76d044f78ff5f3d7351. Signed-off-by: Cristóbal Veas --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 2e862b0..9b20745 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ org.gradle.caching=true org.gradle.parallel=true org.gradle.jvmargs='-Dfile.encoding=UTF-8' -projectVersion=1.5.4 +projectVersion=1.5.3 libsPackage=team.devblook.akropolis.libs From 973f497cc2c366670b034dad6b22c7a0164d3611 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Crist=C3=B3bal=20Veas?= Date: Sat, 20 Jul 2024 21:42:29 -0400 Subject: [PATCH 3/3] fix: use reflection to get top inventory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cristóbal Veas --- .../akropolis/inventory/AbstractInventory.java | 2 +- .../akropolis/inventory/InventoryListener.java | 4 ++-- .../akropolis/inventory/InventoryManager.java | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/java/team/devblook/akropolis/inventory/AbstractInventory.java b/src/main/java/team/devblook/akropolis/inventory/AbstractInventory.java index e02d22f..622bf40 100644 --- a/src/main/java/team/devblook/akropolis/inventory/AbstractInventory.java +++ b/src/main/java/team/devblook/akropolis/inventory/AbstractInventory.java @@ -100,7 +100,7 @@ public List getOpenInventories() { @EventHandler public void onInventoryClose(InventoryCloseEvent event) { - if (event.getView().getTopInventory().getHolder() instanceof InventoryBuilder && refreshEnabled) { + if (InventoryManager.getTopInventory(event).getHolder() instanceof InventoryBuilder && refreshEnabled) { openInventories.remove(event.getPlayer().getUniqueId()); } } diff --git a/src/main/java/team/devblook/akropolis/inventory/InventoryListener.java b/src/main/java/team/devblook/akropolis/inventory/InventoryListener.java index 1515cad..f85594f 100644 --- a/src/main/java/team/devblook/akropolis/inventory/InventoryListener.java +++ b/src/main/java/team/devblook/akropolis/inventory/InventoryListener.java @@ -30,7 +30,7 @@ public class InventoryListener implements Listener { @EventHandler public void onInventoryClick(InventoryClickEvent event) { - if (event.getView().getTopInventory().getHolder() instanceof InventoryBuilder) { + if (InventoryManager.getTopInventory(event).getHolder() instanceof InventoryBuilder) { event.setCancelled(true); if (event.getWhoClicked() instanceof Player player) { @@ -40,7 +40,7 @@ public void onInventoryClick(InventoryClickEvent event) { if (itemStack == null || itemStack.getType() == Material.AIR) return; - InventoryBuilder customHolder = (InventoryBuilder) event.getView().getTopInventory().getHolder(); + InventoryBuilder customHolder = (InventoryBuilder) InventoryManager.getTopInventory(event).getHolder(); InventoryItem item = customHolder.getIcon(event.getRawSlot()); if (item == null) diff --git a/src/main/java/team/devblook/akropolis/inventory/InventoryManager.java b/src/main/java/team/devblook/akropolis/inventory/InventoryManager.java index 6f4f172..10d7d26 100644 --- a/src/main/java/team/devblook/akropolis/inventory/InventoryManager.java +++ b/src/main/java/team/devblook/akropolis/inventory/InventoryManager.java @@ -22,10 +22,14 @@ import org.bukkit.Bukkit; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryEvent; +import org.bukkit.inventory.Inventory; import team.devblook.akropolis.AkropolisPlugin; import team.devblook.akropolis.inventory.inventories.CustomGUI; import java.io.*; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; import java.util.UUID; @@ -114,6 +118,17 @@ private void loadCustomMenus() { } } + public static Inventory getTopInventory(InventoryEvent event) { + try { + Object view = event.getView(); + Method getTopInventory = view.getClass().getMethod("getTopInventory"); + getTopInventory.setAccessible(true); + return (Inventory) getTopInventory.invoke(view); + } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } + public Map getInventories() { return inventories; }