Tiny performance boost

This commit is contained in:
libraryaddict 2014-09-26 16:50:57 +12:00
parent d672013583
commit 96e7cd181a
2 changed files with 18 additions and 2 deletions

View File

@ -29,6 +29,7 @@ import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.vehicle.VehicleEnterEvent; 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 @EventHandler
public void onRespawn(PlayerRespawnEvent event) { public void onRespawn(PlayerRespawnEvent event) {
Disguise[] disguises = DisguiseAPI.getDisguises(event.getPlayer()); Disguise[] disguises = DisguiseAPI.getDisguises(event.getPlayer());
@ -361,5 +367,5 @@ public class DisguiseListener implements Listener {
disguiseRunnable.put(player, runnable); disguiseRunnable.put(player, runnable);
disguiseEntity.put(player, disguise); disguiseEntity.put(player, disguise);
} }
} }

View File

@ -86,6 +86,7 @@ public class ReflectionManager {
*/ */
private static Map<String, Map<String, Map<String, String>>> ForgeMethodMappings; private static Map<String, Map<String, Map<String, String>>> ForgeMethodMappings;
private static final Method ihmGet; private static final Method ihmGet;
private static HashMap<String, Boolean> is1_8 = new HashMap<String, Boolean>();
private static final boolean isForge = Bukkit.getServer().getName().contains("Cauldron") private static final boolean isForge = Bukkit.getServer().getName().contains("Cauldron")
|| Bukkit.getServer().getName().contains("MCPC-Plus"); || Bukkit.getServer().getName().contains("MCPC-Plus");
private static final Field pingField; private static final Field pingField;
@ -551,12 +552,17 @@ public class ReflectionManager {
public static boolean is1_8(Player player) { public static boolean is1_8(Player player) {
if (LibVersion.is1_7_10()) { if (LibVersion.is1_7_10()) {
if (is1_8.containsKey(player.getName())) {
return is1_8.get(player.getName());
}
try { try {
Object nmsEntity = getNmsEntity(player); Object nmsEntity = getNmsEntity(player);
Object connection = getNmsField(nmsEntity.getClass(), "playerConnection").get(nmsEntity); Object connection = getNmsField(nmsEntity.getClass(), "playerConnection").get(nmsEntity);
Field networkManager = getNmsField(connection.getClass(), "networkManager"); Field networkManager = getNmsField(connection.getClass(), "networkManager");
Method getVersion = getNmsMethod(networkManager.getType(), "getVersion"); 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) { } catch (Exception ex) {
ex.printStackTrace(); 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) { public static void setAllowSleep(Player player) {
try { try {
Object nmsEntity = getNmsEntity(player); Object nmsEntity = getNmsEntity(player);