diff --git a/src/main/java/org/alvindimas05/lagassist/Reflection.java b/src/main/java/org/alvindimas05/lagassist/Reflection.java index 8bfb4e6..75ecfb2 100644 --- a/src/main/java/org/alvindimas05/lagassist/Reflection.java +++ b/src/main/java/org/alvindimas05/lagassist/Reflection.java @@ -1,9 +1,6 @@ package org.alvindimas05.lagassist; -import java.lang.reflect.Array; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Method; +import java.lang.reflect.*; import java.util.Collection; import java.util.HashMap; import java.util.List; @@ -19,12 +16,14 @@ import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.MapMeta; import org.bukkit.map.MapView; import org.bukkit.plugin.Plugin; import org.bukkit.scoreboard.Scoreboard; import org.json.simple.JSONObject; +import org.bukkit.inventory.Inventory; import org.alvindimas05.lagassist.utils.VersionMgr; @@ -87,6 +86,39 @@ public static void Enabler() { Methods.getServer.mthd = getMethod(Classes.MinecraftServer.getType(), "getServer"); } + public static Inventory getTopInventory(InventoryEvent event) { + try { + Object view = event.getView(); + Method m = view.getClass().getMethod("getTopInventory"); + m.setAccessible(true); + return (Inventory) m.invoke(view); + } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } + + public static Inventory getBottomInventory(InventoryEvent event) { + try { + Object view = event.getView(); + Method m = view.getClass().getMethod("getBottomInventory"); + m.setAccessible(true); + return (Inventory) m.invoke(view); + } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } + + public static String getInventoryViewTitle(InventoryEvent event){ + try { + Object view = event.getView(); + Method m = view.getClass().getMethod("getTitle"); + m.setAccessible(true); + return (String) m.invoke(view); + } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } + @SuppressWarnings("deprecation") public static void sendAction(Player player, String s) { if(VersionMgr.isV1_8()){ diff --git a/src/main/java/org/alvindimas05/lagassist/gui/AdminGUI.java b/src/main/java/org/alvindimas05/lagassist/gui/AdminGUI.java index 81e85e6..cf13469 100644 --- a/src/main/java/org/alvindimas05/lagassist/gui/AdminGUI.java +++ b/src/main/java/org/alvindimas05/lagassist/gui/AdminGUI.java @@ -1,5 +1,6 @@ package org.alvindimas05.lagassist.gui; +import org.alvindimas05.lagassist.Reflection; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -66,7 +67,7 @@ public void onInventoryClick(InventoryClickEvent e) { return; } - if (!ChatColor.stripColor(e.getView().getTitle()).equals("LagAssist Tools")) { + if (!ChatColor.stripColor(Reflection.getInventoryViewTitle(e)).equals("LagAssist Tools")) { return; } diff --git a/src/main/java/org/alvindimas05/lagassist/gui/ClientGUI.java b/src/main/java/org/alvindimas05/lagassist/gui/ClientGUI.java index 4e58729..bbefce1 100644 --- a/src/main/java/org/alvindimas05/lagassist/gui/ClientGUI.java +++ b/src/main/java/org/alvindimas05/lagassist/gui/ClientGUI.java @@ -3,6 +3,7 @@ import java.util.HashMap; import java.util.Map; +import org.alvindimas05.lagassist.Reflection; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -119,7 +120,8 @@ public void onInventoryClick(InventoryClickEvent e) { } - if (!(ChatColor.stripColor(e.getView().getTitle())).equals(ChatColor.stripColor(ClientMain.guiname))) { + if (!(ChatColor.stripColor(Reflection.getInventoryViewTitle(e))) + .equals(ChatColor.stripColor(ClientMain.guiname))) { return; } diff --git a/src/main/java/org/alvindimas05/lagassist/gui/HopperGUI.java b/src/main/java/org/alvindimas05/lagassist/gui/HopperGUI.java index a48fa73..99facd5 100644 --- a/src/main/java/org/alvindimas05/lagassist/gui/HopperGUI.java +++ b/src/main/java/org/alvindimas05/lagassist/gui/HopperGUI.java @@ -5,6 +5,7 @@ import java.util.Map; import java.util.Set; +import org.alvindimas05.lagassist.Reflection; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -114,8 +115,8 @@ public void onInventoryClick(InventoryClickEvent e) { Inventory clicked = e.getClickedInventory(); - Inventory invent = e.getView().getTopInventory(); - Inventory bottom = e.getView().getBottomInventory(); + Inventory invent = Reflection.getTopInventory(e); + Inventory bottom = Reflection.getBottomInventory(e); // Click outside inv. if (invent == null) { @@ -126,7 +127,7 @@ public void onInventoryClick(InventoryClickEvent e) { ItemStack hand = e.getCursor(); ItemStack itm = e.getCurrentItem(); - if (!(e.getView().getTitle()).equals(HopperFilter.guiname)) { + if (!(Reflection.getInventoryViewTitle(e)).equals(HopperFilter.guiname)) { return; } @@ -178,7 +179,7 @@ public void onInventoryDrag(InventoryDragEvent e) { return; } - if (!(e.getView().getTitle()).equals(HopperFilter.guiname)) { + if (!(Reflection.getInventoryViewTitle(e)).equals(HopperFilter.guiname)) { return; }