From ec6512aa773d741ce1c11e3d8019af0dfaf79ce4 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sun, 10 Nov 2019 22:44:02 +1300 Subject: [PATCH] Paper experimental fix --- .../disguise/utilities/DisguiseUtilities.java | 34 ++++++------------- 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index d09c6118..5557a133 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -86,6 +86,7 @@ public class DisguiseUtilities { private static long velocityTime; private static int velocityID; private static HashMap> disguiseLoading = new HashMap<>(); + private static boolean runningPaper = Bukkit.getServer().getBukkitVersion().contains("Paper"); public static void setPlayerVelocity(Player player) { velocityID = player.getEntityId(); @@ -736,22 +737,6 @@ public class DisguiseUtilities { }, LibsDisguises.getInstance().getConfig().getBoolean("ContactMojangServers", true)); } - /** - * Pass in a set, check if it's a hashset. If it's not, return false. If you pass in something else, you failed. - * - * @param obj - * @return - */ - private static boolean isHashSet(Object obj) { - if (obj instanceof HashSet) - return true; // It's Spigot/Bukkit - - if (obj instanceof Set) - return false; // It's PaperSpigot/SportsBukkit - - throw new IllegalArgumentException("Object passed was not either a hashset or set!"); - } - /** * Thread safe to use. This returns a GameProfile. And if its GameProfile doesn't have a skin blob. Then it does * a lookup @@ -1255,11 +1240,12 @@ public class DisguiseUtilities { Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(player); if (entityTrackerEntry != null) { - Object trackedPlayersObj = ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers") - .get(entityTrackerEntry); // If the tracker exists. Remove himself from his tracker - if (isHashSet(trackedPlayersObj)) { + if (runningPaper) { + Object trackedPlayersObj = ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers") + .get(entityTrackerEntry); + ((Set) trackedPlayersObj).remove(ReflectionManager.getNmsEntity(player)); } else { ((Map) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayerMap") @@ -1545,12 +1531,12 @@ public class DisguiseUtilities { setupSelfDisguiseScoreboard(player); - // Add himself to his own entity tracker - Object trackedPlayersObj = ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers") - .get(entityTrackerEntry); - // Check for code differences in PaperSpigot vs Spigot - if (isHashSet(trackedPlayersObj)) { + if (runningPaper) { + // Add himself to his own entity tracker + Object trackedPlayersObj = ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers") + .get(entityTrackerEntry); + ((Set) trackedPlayersObj).add(ReflectionManager.getNmsEntity(player)); } else { ((Map) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayerMap")