From 43e6e6cc362cee03f32ef15645bacc7fc2f7316a Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sat, 19 Apr 2014 18:22:27 +1200 Subject: [PATCH] Changed the names and some methods so its easily used by outside plugins --- .../disguise/utilities/DisguiseUtilities.java | 53 +++++++------------ .../disguise/utilities/PacketsManager.java | 2 +- 2 files changed, 21 insertions(+), 34 deletions(-) diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index b31a0f23..c71b34e7 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -263,7 +263,15 @@ public class DisguiseUtilities { return players; } - public static Object getProfile(final String playerName) { + public static Object getProfileFromMojang(String playerName) { + return getProfileFromMojang(playerName, true); + } + + /** + * Thread safe to use. This returns a GameProfile. And if its GameProfile doesn't have a skin blob. Then it does a lookup + * using schedulers. + */ + public static Object getProfileFromMojang(final String playerName, final boolean updateDisguises) { if (gameProfiles.containsKey(playerName)) { if (gameProfiles.get(playerName) != null) { return gameProfiles.get(playerName); @@ -287,13 +295,17 @@ public class DisguiseUtilities { public void run() { if (gameProfiles.containsKey(playerName) && gameProfiles.get(playerName) == null) { gameProfiles.put(playerName, gameProfile); - for (HashSet disguises : DisguiseUtilities.getDisguises().values()) { - for (TargetedDisguise disguise : disguises) { - if (disguise.getType() == DisguiseType.PLAYER - && ((PlayerDisguise) disguise).getName().equals(playerName)) { - DisguiseUtilities.refreshTrackers((TargetedDisguise) disguise); - if (disguise.getEntity() instanceof Player && disguise.isSelfDisguiseVisible()) { - DisguiseUtilities.sendSelfDisguise((Player) disguise.getEntity(), disguise); + if (updateDisguises) { + for (HashSet disguises : DisguiseUtilities.getDisguises().values()) { + for (TargetedDisguise disguise : disguises) { + if (disguise.getType() == DisguiseType.PLAYER + && ((PlayerDisguise) disguise).getName().equals(playerName)) { + DisguiseUtilities.refreshTrackers((TargetedDisguise) disguise); + if (disguise.getEntity() instanceof Player + && disguise.isSelfDisguiseVisible()) { + DisguiseUtilities.sendSelfDisguise((Player) disguise.getEntity(), + disguise); + } } } } @@ -365,31 +377,6 @@ public class DisguiseUtilities { return ReflectionManager.grabSkullBlob(gameprofile); } - /** - * This is safe to call from the main thread - */ - public static void lookupGameProfileAndStore(final String playerName) { - if (!gameProfiles.containsKey(playerName)) { - gameProfiles.put(playerName, null); - Bukkit.getScheduler().scheduleAsyncDelayedTask(libsDisguises, new Runnable() { - public void run() { - try { - final Object gameProfile = lookupGameProfile(playerName); - Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() { - public void run() { - if (gameProfiles.containsKey(playerName) && gameProfiles.get(playerName) == null) { - gameProfiles.put(playerName, gameProfile); - } - } - }); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - }); - } - } - /** * @param Resends * the entity to all the watching players, which is where the magic begins diff --git a/src/me/libraryaddict/disguise/utilities/PacketsManager.java b/src/me/libraryaddict/disguise/utilities/PacketsManager.java index 2cd9a659..0da15078 100644 --- a/src/me/libraryaddict/disguise/utilities/PacketsManager.java +++ b/src/me/libraryaddict/disguise/utilities/PacketsManager.java @@ -201,7 +201,7 @@ public class PacketsManager { } } else { Object gameProfile = null; - gameProfile = DisguiseUtilities.getProfile(((PlayerDisguise) disguise).getName()); + gameProfile = DisguiseUtilities.getProfileFromMojang(((PlayerDisguise) disguise).getName()); spawnPackets[0].getModifier().write(1, gameProfile); } StructureModifier intMods = spawnPackets[0].getIntegers();