From 96e7cd181a9e68a76775bac5ae720e708f29ec09 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Fri, 26 Sep 2014 16:50:57 +1200 Subject: [PATCH] Tiny performance boost --- src/me/libraryaddict/disguise/DisguiseListener.java | 8 +++++++- .../disguise/utilities/ReflectionManager.java | 12 +++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/me/libraryaddict/disguise/DisguiseListener.java b/src/me/libraryaddict/disguise/DisguiseListener.java index bc94663d..27af91f0 100644 --- a/src/me/libraryaddict/disguise/DisguiseListener.java +++ b/src/me/libraryaddict/disguise/DisguiseListener.java @@ -29,6 +29,7 @@ import org.bukkit.event.player.PlayerChangedWorldEvent; import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.vehicle.VehicleEnterEvent; @@ -162,6 +163,11 @@ public class DisguiseListener implements Listener { } } + @EventHandler + public void onQuit(PlayerQuitEvent event) { + ReflectionManager.removePlayer(event.getPlayer()); + } + @EventHandler public void onRespawn(PlayerRespawnEvent event) { Disguise[] disguises = DisguiseAPI.getDisguises(event.getPlayer()); @@ -361,5 +367,5 @@ public class DisguiseListener implements Listener { disguiseRunnable.put(player, runnable); disguiseEntity.put(player, disguise); } - + } diff --git a/src/me/libraryaddict/disguise/utilities/ReflectionManager.java b/src/me/libraryaddict/disguise/utilities/ReflectionManager.java index 2b8b88a3..e2738185 100644 --- a/src/me/libraryaddict/disguise/utilities/ReflectionManager.java +++ b/src/me/libraryaddict/disguise/utilities/ReflectionManager.java @@ -86,6 +86,7 @@ public class ReflectionManager { */ private static Map>> ForgeMethodMappings; private static final Method ihmGet; + private static HashMap is1_8 = new HashMap(); private static final boolean isForge = Bukkit.getServer().getName().contains("Cauldron") || Bukkit.getServer().getName().contains("MCPC-Plus"); private static final Field pingField; @@ -551,12 +552,17 @@ public class ReflectionManager { public static boolean is1_8(Player player) { if (LibVersion.is1_7_10()) { + if (is1_8.containsKey(player.getName())) { + return is1_8.get(player.getName()); + } try { Object nmsEntity = getNmsEntity(player); Object connection = getNmsField(nmsEntity.getClass(), "playerConnection").get(nmsEntity); Field networkManager = getNmsField(connection.getClass(), "networkManager"); Method getVersion = getNmsMethod(networkManager.getType(), "getVersion"); - return (Integer) getVersion.invoke(networkManager.get(connection)) >= 28; + boolean is18 = (Integer) getVersion.invoke(networkManager.get(connection)) >= 28; + is1_8.put(player.getName(), is18); + return is18; } catch (Exception ex) { ex.printStackTrace(); } @@ -578,6 +584,10 @@ public class ReflectionManager { } } + public static void removePlayer(Player player) { + is1_8.remove(player.getName()); + } + public static void setAllowSleep(Player player) { try { Object nmsEntity = getNmsEntity(player);