Fix up player disguises skins
This commit is contained in:
		| @@ -14,28 +14,14 @@ import me.libraryaddict.disguise.utilities.ReflectionManager; | |||||||
|  |  | ||||||
| public class PlayerDisguise extends TargetedDisguise | public class PlayerDisguise extends TargetedDisguise | ||||||
| { | { | ||||||
|  |  | ||||||
|     private LibsProfileLookup currentLookup; |     private LibsProfileLookup currentLookup; | ||||||
|     private WrappedGameProfile gameProfile; |     private WrappedGameProfile gameProfile; | ||||||
|     private String playerName; |     private String playerName; | ||||||
|     private String skinToUse; |     private String skinToUse; | ||||||
|  |  | ||||||
|     public PlayerDisguise(String name) |     private PlayerDisguise() | ||||||
|     { |     { | ||||||
|         if (name.length() > 16) |         // Internal usage only | ||||||
|         { |  | ||||||
|             name = name.substring(0, 16); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         playerName = name; |  | ||||||
|         createDisguise(DisguiseType.PLAYER); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public PlayerDisguise(String name, String skinToUse) |  | ||||||
|     { |  | ||||||
|         this(name); |  | ||||||
|  |  | ||||||
|         setSkin(skinToUse); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public PlayerDisguise(Player player) |     public PlayerDisguise(Player player) | ||||||
| @@ -48,18 +34,40 @@ public class PlayerDisguise extends TargetedDisguise | |||||||
|         this(ReflectionManager.getGameProfile(player), ReflectionManager.getGameProfile(skinToUse)); |         this(ReflectionManager.getGameProfile(player), ReflectionManager.getGameProfile(skinToUse)); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public PlayerDisguise(String name) | ||||||
|  |     { | ||||||
|  |         setName(name); | ||||||
|  |         setSkin(name); | ||||||
|  |  | ||||||
|  |         createDisguise(DisguiseType.PLAYER); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public PlayerDisguise(String name, String skinToUse) | ||||||
|  |     { | ||||||
|  |         setName(name); | ||||||
|  |         setSkin(skinToUse); | ||||||
|  |  | ||||||
|  |         createDisguise(DisguiseType.PLAYER); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     public PlayerDisguise(WrappedGameProfile gameProfile) |     public PlayerDisguise(WrappedGameProfile gameProfile) | ||||||
|     { |     { | ||||||
|         this(gameProfile.getName()); |         setName(gameProfile.getName()); | ||||||
|  |  | ||||||
|         this.gameProfile = gameProfile; |         this.gameProfile = gameProfile; | ||||||
|  |  | ||||||
|  |         createDisguise(DisguiseType.PLAYER); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public PlayerDisguise(WrappedGameProfile gameProfile, WrappedGameProfile skinToUse) |     public PlayerDisguise(WrappedGameProfile gameProfile, WrappedGameProfile skinToUse) | ||||||
|     { |     { | ||||||
|         this(gameProfile); |         setName(gameProfile.getName()); | ||||||
|  |  | ||||||
|  |         this.gameProfile = gameProfile; | ||||||
|  |  | ||||||
|         setSkin(skinToUse); |         setSkin(skinToUse); | ||||||
|  |  | ||||||
|  |         createDisguise(DisguiseType.PLAYER); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
| @@ -77,12 +85,14 @@ public class PlayerDisguise extends TargetedDisguise | |||||||
|     @Override |     @Override | ||||||
|     public PlayerDisguise clone() |     public PlayerDisguise clone() | ||||||
|     { |     { | ||||||
|         PlayerDisguise disguise = new PlayerDisguise(getName()); |         PlayerDisguise disguise = new PlayerDisguise(); | ||||||
|  |  | ||||||
|  |         disguise.playerName = getName(); | ||||||
|  |  | ||||||
|         if (disguise.currentLookup == null && disguise.gameProfile != null) |         if (disguise.currentLookup == null && disguise.gameProfile != null) | ||||||
|         { |         { | ||||||
|             disguise.skinToUse = getSkin(); |             disguise.skinToUse = getSkin(); | ||||||
|             disguise.gameProfile = gameProfile; |             disguise.gameProfile = ReflectionManager.getClonedProfile(getGameProfile()); | ||||||
|         } |         } | ||||||
|         else |         else | ||||||
|         { |         { | ||||||
| @@ -98,12 +108,9 @@ public class PlayerDisguise extends TargetedDisguise | |||||||
|         disguise.setModifyBoundingBox(isModifyBoundingBox()); |         disguise.setModifyBoundingBox(isModifyBoundingBox()); | ||||||
|         disguise.setWatcher(getWatcher().clone(disguise)); |         disguise.setWatcher(getWatcher().clone(disguise)); | ||||||
|  |  | ||||||
|         return disguise; |         disguise.createDisguise(DisguiseType.PLAYER); | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public void setGameProfile(WrappedGameProfile gameProfile) |         return disguise; | ||||||
|     { |  | ||||||
|         this.gameProfile = ReflectionManager.getGameProfileWithThisSkin(null, gameProfile.getName(), gameProfile); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public WrappedGameProfile getGameProfile() |     public WrappedGameProfile getGameProfile() | ||||||
| @@ -170,6 +177,11 @@ public class PlayerDisguise extends TargetedDisguise | |||||||
|         return (PlayerDisguise) super.setEntity(entity); |         return (PlayerDisguise) super.setEntity(entity); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public void setGameProfile(WrappedGameProfile gameProfile) | ||||||
|  |     { | ||||||
|  |         this.gameProfile = ReflectionManager.getGameProfileWithThisSkin(null, gameProfile.getName(), gameProfile); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public PlayerDisguise setHearSelfDisguise(boolean hearSelfDisguise) |     public PlayerDisguise setHearSelfDisguise(boolean hearSelfDisguise) | ||||||
|     { |     { | ||||||
| @@ -212,55 +224,63 @@ public class PlayerDisguise extends TargetedDisguise | |||||||
|         return (PlayerDisguise) super.setModifyBoundingBox(modifyBox); |         return (PlayerDisguise) super.setModifyBoundingBox(modifyBox); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     private void setName(String name) | ||||||
|  |     { | ||||||
|  |         if (name.length() > 16) | ||||||
|  |         { | ||||||
|  |             name = name.substring(0, 16); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         playerName = name; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public PlayerDisguise setReplaceSounds(boolean areSoundsReplaced) |     public PlayerDisguise setReplaceSounds(boolean areSoundsReplaced) | ||||||
|     { |     { | ||||||
|         return (PlayerDisguise) super.setReplaceSounds(areSoundsReplaced); |         return (PlayerDisguise) super.setReplaceSounds(areSoundsReplaced); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public PlayerDisguise setSkin(String skinToUse) |     public PlayerDisguise setSkin(String newSkin) | ||||||
|     { |     { | ||||||
|         this.skinToUse = skinToUse; |         skinToUse = newSkin; | ||||||
|  |  | ||||||
|         if (skinToUse == null) |         if (newSkin == null) | ||||||
|         { |         { | ||||||
|             this.currentLookup = null; |             currentLookup = null; | ||||||
|             this.gameProfile = null; |             gameProfile = null; | ||||||
|         } |         } | ||||||
|         else |         else | ||||||
|         { |         { | ||||||
|             if (skinToUse.length() > 16) |             if (newSkin.length() > 16) | ||||||
|             { |             { | ||||||
|                 this.skinToUse = skinToUse.substring(0, 16); |                 skinToUse = newSkin.substring(0, 16); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             if (LibsDisguises.getInstance().getConfig().getBoolean("ContactMojangServers", true)) |             currentLookup = new LibsProfileLookup() | ||||||
|             { |             { | ||||||
|                 currentLookup = new LibsProfileLookup() |                 @Override | ||||||
|  |                 public void onLookup(WrappedGameProfile gameProfile) | ||||||
|                 { |                 { | ||||||
|                     @Override |                     if (currentLookup != this || gameProfile == null) | ||||||
|                     public void onLookup(WrappedGameProfile gameProfile) |                         return; | ||||||
|                     { |  | ||||||
|                         if (currentLookup == this && gameProfile != null) |  | ||||||
|                         { |  | ||||||
|                             setSkin(gameProfile); |  | ||||||
|  |  | ||||||
|                             if (!gameProfile.getProperties().isEmpty() && DisguiseUtilities.isDisguiseInUse(PlayerDisguise.this)) |  | ||||||
|                             { |  | ||||||
|                                 DisguiseUtilities.refreshTrackers(PlayerDisguise.this); |  | ||||||
|                             } |  | ||||||
|  |  | ||||||
|                             currentLookup = null; |  | ||||||
|                         } |  | ||||||
|                     } |  | ||||||
|                 }; |  | ||||||
|  |  | ||||||
|                 WrappedGameProfile gameProfile = DisguiseUtilities.getProfileFromMojang(this.skinToUse, currentLookup); |  | ||||||
|  |  | ||||||
|                 if (gameProfile != null) |  | ||||||
|                 { |  | ||||||
|                     setSkin(gameProfile); |                     setSkin(gameProfile); | ||||||
|  |  | ||||||
|  |                     if (!gameProfile.getProperties().isEmpty() && DisguiseUtilities.isDisguiseInUse(PlayerDisguise.this)) | ||||||
|  |                     { | ||||||
|  |                         DisguiseUtilities.refreshTrackers(PlayerDisguise.this); | ||||||
|  |                     } | ||||||
|  |  | ||||||
|  |                     currentLookup = null; | ||||||
|                 } |                 } | ||||||
|  |             }; | ||||||
|  |  | ||||||
|  |             WrappedGameProfile gameProfile = DisguiseUtilities.getProfileFromMojang(this.skinToUse, currentLookup, | ||||||
|  |                     LibsDisguises.getInstance().getConfig().getBoolean("ContactMojangServers", true)); | ||||||
|  |  | ||||||
|  |             if (gameProfile != null) | ||||||
|  |             { | ||||||
|  |                 setSkin(gameProfile); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -286,6 +306,7 @@ public class PlayerDisguise extends TargetedDisguise | |||||||
|         if (LibsDisguises.getInstance().getConfig().getBoolean("ContactMojangServers", true)) |         if (LibsDisguises.getInstance().getConfig().getBoolean("ContactMojangServers", true)) | ||||||
|         { |         { | ||||||
|             Validate.notEmpty(gameProfile.getName(), "Name must be set"); |             Validate.notEmpty(gameProfile.getName(), "Name must be set"); | ||||||
|  |  | ||||||
|             this.skinToUse = gameProfile.getName(); |             this.skinToUse = gameProfile.getName(); | ||||||
|             this.gameProfile = ReflectionManager.getGameProfileWithThisSkin(null, getName(), gameProfile); |             this.gameProfile = ReflectionManager.getGameProfileWithThisSkin(null, getName(), gameProfile); | ||||||
|         } |         } | ||||||
|   | |||||||
| @@ -640,6 +640,7 @@ public class DisguiseUtilities | |||||||
|     public static WrappedGameProfile getProfileFromMojang(final PlayerDisguise disguise) |     public static WrappedGameProfile getProfileFromMojang(final PlayerDisguise disguise) | ||||||
|     { |     { | ||||||
|         final String nameToFetch = disguise.getSkin() != null ? disguise.getSkin() : disguise.getName(); |         final String nameToFetch = disguise.getSkin() != null ? disguise.getSkin() : disguise.getName(); | ||||||
|  |  | ||||||
|         final boolean remove = getAddedByPlugins().contains(nameToFetch.toLowerCase()); |         final boolean remove = getAddedByPlugins().contains(nameToFetch.toLowerCase()); | ||||||
|  |  | ||||||
|         return getProfileFromMojang(nameToFetch, new LibsProfileLookup() |         return getProfileFromMojang(nameToFetch, new LibsProfileLookup() | ||||||
| @@ -662,7 +663,7 @@ public class DisguiseUtilities | |||||||
|                     DisguiseUtilities.refreshTrackers(disguise); |                     DisguiseUtilities.refreshTrackers(disguise); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         }); |         }, LibsDisguises.getInstance().getConfig().getBoolean("ContactMojangServers", true)); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -688,10 +689,20 @@ public class DisguiseUtilities | |||||||
|      */ |      */ | ||||||
|     public static WrappedGameProfile getProfileFromMojang(String playerName, LibsProfileLookup runnableIfCantReturn) |     public static WrappedGameProfile getProfileFromMojang(String playerName, LibsProfileLookup runnableIfCantReturn) | ||||||
|     { |     { | ||||||
|         return getProfileFromMojang(playerName, (Object) runnableIfCantReturn); |         return getProfileFromMojang(playerName, (Object) runnableIfCantReturn, true); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private static WrappedGameProfile getProfileFromMojang(final String origName, final Object runnable) |     /** | ||||||
|  |      * 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. The runnable is run once the GameProfile has been successfully dealt with | ||||||
|  |      */ | ||||||
|  |     public static WrappedGameProfile getProfileFromMojang(String playerName, LibsProfileLookup runnableIfCantReturn, | ||||||
|  |             boolean contactMojang) | ||||||
|  |     { | ||||||
|  |         return getProfileFromMojang(playerName, (Object) runnableIfCantReturn, contactMojang); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     private static WrappedGameProfile getProfileFromMojang(final String origName, final Object runnable, boolean contactMojang) | ||||||
|     { |     { | ||||||
|         final String playerName = origName.toLowerCase(); |         final String playerName = origName.toLowerCase(); | ||||||
|  |  | ||||||
| @@ -715,6 +726,7 @@ public class DisguiseUtilities | |||||||
|                 if (!gameProfile.getProperties().isEmpty()) |                 if (!gameProfile.getProperties().isEmpty()) | ||||||
|                 { |                 { | ||||||
|                     gameProfiles.put(playerName, gameProfile); |                     gameProfiles.put(playerName, gameProfile); | ||||||
|  |  | ||||||
|                     return gameProfile; |                     return gameProfile; | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
| @@ -736,25 +748,27 @@ public class DisguiseUtilities | |||||||
|                             @Override |                             @Override | ||||||
|                             public void run() |                             public void run() | ||||||
|                             { |                             { | ||||||
|                                 if (!gameProfile.getProperties().isEmpty()) |                                 if (gameProfile.getProperties().isEmpty()) | ||||||
|                                 { |                                 { | ||||||
|                                     if (gameProfiles.containsKey(playerName) && gameProfiles.get(playerName) == null) |                                     return; | ||||||
|                                     { |                                 } | ||||||
|                                         gameProfiles.put(playerName, gameProfile); |  | ||||||
|                                     } |  | ||||||
|  |  | ||||||
|                                     if (runnables.containsKey(playerName)) |                                 if (gameProfiles.containsKey(playerName) && gameProfiles.get(playerName) == null) | ||||||
|  |                                 { | ||||||
|  |                                     gameProfiles.put(playerName, gameProfile); | ||||||
|  |                                 } | ||||||
|  |  | ||||||
|  |                                 if (runnables.containsKey(playerName)) | ||||||
|  |                                 { | ||||||
|  |                                     for (Object obj : runnables.remove(playerName)) | ||||||
|                                     { |                                     { | ||||||
|                                         for (Object obj : runnables.remove(playerName)) |                                         if (obj instanceof Runnable) | ||||||
|                                         { |                                         { | ||||||
|                                             if (obj instanceof Runnable) |                                             ((Runnable) obj).run(); | ||||||
|                                             { |                                         } | ||||||
|                                                 ((Runnable) obj).run(); |                                         else if (obj instanceof LibsProfileLookup) | ||||||
|                                             } |                                         { | ||||||
|                                             else if (obj instanceof LibsProfileLookup) |                                             ((LibsProfileLookup) obj).onLookup(gameProfile); | ||||||
|                                             { |  | ||||||
|                                                 ((LibsProfileLookup) obj).onLookup(gameProfile); |  | ||||||
|                                             } |  | ||||||
|                                         } |                                         } | ||||||
|                                     } |                                     } | ||||||
|                                 } |                                 } | ||||||
| @@ -786,6 +800,7 @@ public class DisguiseUtilities | |||||||
|             { |             { | ||||||
|                 runnables.put(playerName, new ArrayList<>()); |                 runnables.put(playerName, new ArrayList<>()); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             runnables.get(playerName).add(runnable); |             runnables.get(playerName).add(runnable); | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -798,7 +813,16 @@ public class DisguiseUtilities | |||||||
|      */ |      */ | ||||||
|     public static WrappedGameProfile getProfileFromMojang(String playerName, Runnable runnableIfCantReturn) |     public static WrappedGameProfile getProfileFromMojang(String playerName, Runnable runnableIfCantReturn) | ||||||
|     { |     { | ||||||
|         return getProfileFromMojang(playerName, (Object) runnableIfCantReturn); |         return getProfileFromMojang(playerName, (Object) runnableIfCantReturn, 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. The runnable is run once the GameProfile has been successfully dealt with | ||||||
|  |      */ | ||||||
|  |     public static WrappedGameProfile getProfileFromMojang(String playerName, Runnable runnableIfCantReturn, boolean contactMojang) | ||||||
|  |     { | ||||||
|  |         return getProfileFromMojang(playerName, (Object) runnableIfCantReturn, contactMojang); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static HashSet<UUID> getSelfDisguised() |     public static HashSet<UUID> getSelfDisguised() | ||||||
|   | |||||||
| @@ -221,7 +221,7 @@ public class PacketsManager | |||||||
|         { |         { | ||||||
|             PlayerDisguise playerDisguise = (PlayerDisguise) disguise; |             PlayerDisguise playerDisguise = (PlayerDisguise) disguise; | ||||||
|  |  | ||||||
|             String name = playerDisguise.getSkin() != null ? playerDisguise.getSkin() : playerDisguise.getName(); |             String name = playerDisguise.getName(); | ||||||
|             int entityId = disguisedEntity.getEntityId(); |             int entityId = disguisedEntity.getEntityId(); | ||||||
|             boolean removeName = false; |             boolean removeName = false; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -438,12 +438,19 @@ public class ReflectionManager | |||||||
|         return null; |         return null; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public static WrappedGameProfile getClonedProfile(WrappedGameProfile gameProfile) | ||||||
|  |     { | ||||||
|  |         return getGameProfileWithThisSkin(null, gameProfile.getName(), gameProfile); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     public static WrappedGameProfile getGameProfileWithThisSkin(UUID uuid, String playerName, WrappedGameProfile profileWithSkin) |     public static WrappedGameProfile getGameProfileWithThisSkin(UUID uuid, String playerName, WrappedGameProfile profileWithSkin) | ||||||
|     { |     { | ||||||
|         try |         try | ||||||
|         { |         { | ||||||
|             WrappedGameProfile gameProfile = new WrappedGameProfile(uuid != null ? uuid : UUID.randomUUID(), playerName); |             WrappedGameProfile gameProfile = new WrappedGameProfile(uuid != null ? uuid : UUID.randomUUID(), playerName); | ||||||
|  |  | ||||||
|             gameProfile.getProperties().putAll(profileWithSkin.getProperties()); |             gameProfile.getProperties().putAll(profileWithSkin.getProperties()); | ||||||
|  |  | ||||||
|             return gameProfile; |             return gameProfile; | ||||||
|         } |         } | ||||||
|         catch (Exception ex) |         catch (Exception ex) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user