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 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; } 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.