From 62debf30c0a9c7cb9f48a466958bd9af41ee6721 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Wed, 23 Apr 2014 11:44:12 +1200 Subject: [PATCH] Don't permanantly store the game profile --- .../disguise/disguisetypes/Disguise.java | 14 ++++++++ .../disguise/utilities/DisguiseUtilities.java | 11 +++++++ .../disguise/utilities/PacketsManager.java | 8 +++++ .../disguise/utilities/ReflectionManager.java | 32 +++++++++---------- 4 files changed, 49 insertions(+), 16 deletions(-) diff --git a/src/me/libraryaddict/disguise/disguisetypes/Disguise.java b/src/me/libraryaddict/disguise/disguisetypes/Disguise.java index 7f625709..ff573d2d 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/Disguise.java +++ b/src/me/libraryaddict/disguise/disguisetypes/Disguise.java @@ -430,6 +430,20 @@ public abstract class Disguise { } } } + + if (isPlayerDisguise()) { + String name = ((PlayerDisguise) this).getName(); + if (!DisguiseUtilities.getAddedByPlugins().contains(name)) { + for (HashSet disguise : disguises.values()) { + for (Disguise d : disguise) { + if (d.isPlayerDisguise() && ((PlayerDisguise) d).getName().equals(name)) { + return; + } + } + } + DisguiseUtilities.removeGameprofile(name); + } + } } } diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index c39f59f1..78dc2bc6 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -38,6 +38,7 @@ import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.wrappers.WrappedDataWatcher; public class DisguiseUtilities { + private static HashSet addedByPlugins = new HashSet(); private static HashMap> futureDisguises = new HashMap>(); private static HashMap gameProfiles = new HashMap(); private static LibsDisguises libsDisguises; @@ -191,6 +192,10 @@ public class DisguiseUtilities { } } + public static HashSet getAddedByPlugins() { + return addedByPlugins; + } + public static TargetedDisguise getDisguise(Player observer, Entity entity) { UUID entityId = entity.getUniqueId(); if (futureDisguises.containsKey(entity.getEntityId())) { @@ -290,6 +295,7 @@ public class DisguiseUtilities { return gameProfiles.get(playerName); } } else { + getAddedByPlugins().add(playerName); Player player = Bukkit.getPlayerExact(playerName); if (player != null) { Object gameProfile = ReflectionManager.getGameProfile(player); @@ -317,6 +323,7 @@ public class DisguiseUtilities { } catch (Exception e) { if (gameProfiles.containsKey(playerName) && gameProfiles.get(playerName) == null) { gameProfiles.remove(playerName); + getAddedByPlugins().remove(playerName); } System.out.print("[LibsDisguises] Error when fetching " + playerName + "'s uuid from mojang: " + e.getMessage()); @@ -497,6 +504,10 @@ public class DisguiseUtilities { return false; } + public static void removeGameprofile(String string) { + gameProfiles.remove(string); + } + public static void removeSelfDisguise(Player player) { if (selfDisguisesIds.containsKey(player.getUniqueId())) { // Send a packet to destroy the fake entity diff --git a/src/me/libraryaddict/disguise/utilities/PacketsManager.java b/src/me/libraryaddict/disguise/utilities/PacketsManager.java index 0da15078..57635a3c 100644 --- a/src/me/libraryaddict/disguise/utilities/PacketsManager.java +++ b/src/me/libraryaddict/disguise/utilities/PacketsManager.java @@ -201,7 +201,15 @@ public class PacketsManager { } } else { Object gameProfile = null; + String name = ((PlayerDisguise) disguise).getName(); + boolean removeName = false; + if (!DisguiseUtilities.hasGameProfile(name)) { + removeName = !DisguiseUtilities.getAddedByPlugins().contains(name); + } gameProfile = DisguiseUtilities.getProfileFromMojang(((PlayerDisguise) disguise).getName()); + if (removeName) { + DisguiseUtilities.getAddedByPlugins().remove(name); + } spawnPackets[0].getModifier().write(1, gameProfile); } StructureModifier intMods = spawnPackets[0].getIntegers(); diff --git a/src/me/libraryaddict/disguise/utilities/ReflectionManager.java b/src/me/libraryaddict/disguise/utilities/ReflectionManager.java index 71772ff0..f9e9950b 100644 --- a/src/me/libraryaddict/disguise/utilities/ReflectionManager.java +++ b/src/me/libraryaddict/disguise/utilities/ReflectionManager.java @@ -281,6 +281,22 @@ public class ReflectionManager { return null; } + public static Object getSkullBlob(Object gameProfile) { + try { + Object minecraftServer = getNmsClass("MinecraftServer").getMethod("getServer").invoke(null); + for (Method method : getNmsClass("MinecraftServer").getMethods()) { + if (method.getReturnType().getSimpleName().equals("MinecraftSessionService")) { + Object session = method.invoke(minecraftServer); + return session.getClass().getMethod("fillProfileProperties", gameProfile.getClass(), boolean.class) + .invoke(session, gameProfile, true); + } + } + } catch (Exception ex) { + ex.printStackTrace(); + } + return null; + } + public static Float getSoundModifier(Object entity) { try { damageAndIdleSoundMethod.setAccessible(true); @@ -321,22 +337,6 @@ public class ReflectionManager { return null; } - public static Object getSkullBlob(Object gameProfile) { - try { - Object minecraftServer = getNmsClass("MinecraftServer").getMethod("getServer").invoke(null); - for (Method method : getNmsClass("MinecraftServer").getMethods()) { - if (method.getReturnType().getSimpleName().equals("MinecraftSessionService")) { - Object session = method.invoke(minecraftServer); - return session.getClass().getMethod("fillProfileProperties", gameProfile.getClass(), boolean.class) - .invoke(session, gameProfile, true); - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - return null; - } - public static boolean hasSkinBlob(Object gameprofile) { try { Field propField = gameprofile.getClass().getDeclaredField("properties");