Skip to content

Commit

Permalink
fix gui not backwards compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
alvindimas05 committed Aug 19, 2024
1 parent 609090a commit 3960fbb
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 10 deletions.
40 changes: 36 additions & 4 deletions src/main/java/org/alvindimas05/lagassist/Reflection.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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()){
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/alvindimas05/lagassist/gui/AdminGUI.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/alvindimas05/lagassist/gui/ClientGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
9 changes: 5 additions & 4 deletions src/main/java/org/alvindimas05/lagassist/gui/HopperGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 3960fbb

Please sign in to comment.