Fix up player disguises skins

This commit is contained in:
libraryaddict 2016-06-14 21:08:53 +12:00
parent 6e77551f2e
commit f498867d5c
5 changed files with 256 additions and 204 deletions

View File

@ -14,28 +14,14 @@ import me.libraryaddict.disguise.utilities.ReflectionManager;
public class PlayerDisguise extends TargetedDisguise
{
private LibsProfileLookup currentLookup;
private WrappedGameProfile gameProfile;
private String playerName;
private String skinToUse;
public PlayerDisguise(String name)
private PlayerDisguise()
{
if (name.length() > 16)
{
name = name.substring(0, 16);
}
playerName = name;
createDisguise(DisguiseType.PLAYER);
}
public PlayerDisguise(String name, String skinToUse)
{
this(name);
setSkin(skinToUse);
// Internal usage only
}
public PlayerDisguise(Player player)
@ -48,18 +34,40 @@ public class PlayerDisguise extends TargetedDisguise
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)
{
this(gameProfile.getName());
setName(gameProfile.getName());
this.gameProfile = gameProfile;
createDisguise(DisguiseType.PLAYER);
}
public PlayerDisguise(WrappedGameProfile gameProfile, WrappedGameProfile skinToUse)
{
this(gameProfile);
setName(gameProfile.getName());
this.gameProfile = gameProfile;
setSkin(skinToUse);
createDisguise(DisguiseType.PLAYER);
}
@Override
@ -77,12 +85,14 @@ public class PlayerDisguise extends TargetedDisguise
@Override
public PlayerDisguise clone()
{
PlayerDisguise disguise = new PlayerDisguise(getName());
PlayerDisguise disguise = new PlayerDisguise();
disguise.playerName = getName();
if (disguise.currentLookup == null && disguise.gameProfile != null)
{
disguise.skinToUse = getSkin();
disguise.gameProfile = gameProfile;
disguise.gameProfile = ReflectionManager.getClonedProfile(getGameProfile());
}
else
{
@ -98,12 +108,9 @@ public class PlayerDisguise extends TargetedDisguise
disguise.setModifyBoundingBox(isModifyBoundingBox());
disguise.setWatcher(getWatcher().clone(disguise));
return disguise;
}
disguise.createDisguise(DisguiseType.PLAYER);
public void setGameProfile(WrappedGameProfile gameProfile)
{
this.gameProfile = ReflectionManager.getGameProfileWithThisSkin(null, gameProfile.getName(), gameProfile);
return disguise;
}
public WrappedGameProfile getGameProfile()
@ -170,6 +177,11 @@ public class PlayerDisguise extends TargetedDisguise
return (PlayerDisguise) super.setEntity(entity);
}
public void setGameProfile(WrappedGameProfile gameProfile)
{
this.gameProfile = ReflectionManager.getGameProfileWithThisSkin(null, gameProfile.getName(), gameProfile);
}
@Override
public PlayerDisguise setHearSelfDisguise(boolean hearSelfDisguise)
{
@ -212,37 +224,46 @@ public class PlayerDisguise extends TargetedDisguise
return (PlayerDisguise) super.setModifyBoundingBox(modifyBox);
}
private void setName(String name)
{
if (name.length() > 16)
{
name = name.substring(0, 16);
}
playerName = name;
}
@Override
public PlayerDisguise setReplaceSounds(boolean 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;
this.gameProfile = null;
currentLookup = null;
gameProfile = null;
}
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()
{
@Override
public void onLookup(WrappedGameProfile gameProfile)
{
if (currentLookup == this && gameProfile != null)
{
if (currentLookup != this || gameProfile == null)
return;
setSkin(gameProfile);
if (!gameProfile.getProperties().isEmpty() && DisguiseUtilities.isDisguiseInUse(PlayerDisguise.this))
@ -252,17 +273,16 @@ public class PlayerDisguise extends TargetedDisguise
currentLookup = null;
}
}
};
WrappedGameProfile gameProfile = DisguiseUtilities.getProfileFromMojang(this.skinToUse, currentLookup);
WrappedGameProfile gameProfile = DisguiseUtilities.getProfileFromMojang(this.skinToUse, currentLookup,
LibsDisguises.getInstance().getConfig().getBoolean("ContactMojangServers", true));
if (gameProfile != null)
{
setSkin(gameProfile);
}
}
}
return this;
}
@ -286,6 +306,7 @@ public class PlayerDisguise extends TargetedDisguise
if (LibsDisguises.getInstance().getConfig().getBoolean("ContactMojangServers", true))
{
Validate.notEmpty(gameProfile.getName(), "Name must be set");
this.skinToUse = gameProfile.getName();
this.gameProfile = ReflectionManager.getGameProfileWithThisSkin(null, getName(), gameProfile);
}

View File

@ -640,6 +640,7 @@ public class DisguiseUtilities
public static WrappedGameProfile getProfileFromMojang(final PlayerDisguise disguise)
{
final String nameToFetch = disguise.getSkin() != null ? disguise.getSkin() : disguise.getName();
final boolean remove = getAddedByPlugins().contains(nameToFetch.toLowerCase());
return getProfileFromMojang(nameToFetch, new LibsProfileLookup()
@ -662,7 +663,7 @@ public class DisguiseUtilities
DisguiseUtilities.refreshTrackers(disguise);
}
}
});
}, LibsDisguises.getInstance().getConfig().getBoolean("ContactMojangServers", true));
}
/**
@ -688,10 +689,20 @@ public class DisguiseUtilities
*/
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();
@ -715,6 +726,7 @@ public class DisguiseUtilities
if (!gameProfile.getProperties().isEmpty())
{
gameProfiles.put(playerName, gameProfile);
return gameProfile;
}
}
@ -736,8 +748,11 @@ public class DisguiseUtilities
@Override
public void run()
{
if (!gameProfile.getProperties().isEmpty())
if (gameProfile.getProperties().isEmpty())
{
return;
}
if (gameProfiles.containsKey(playerName) && gameProfiles.get(playerName) == null)
{
gameProfiles.put(playerName, gameProfile);
@ -758,7 +773,6 @@ public class DisguiseUtilities
}
}
}
}
});
}
catch (Exception e)
@ -786,6 +800,7 @@ public class DisguiseUtilities
{
runnables.put(playerName, new ArrayList<>());
}
runnables.get(playerName).add(runnable);
}
@ -798,7 +813,16 @@ public class DisguiseUtilities
*/
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()

View File

@ -221,7 +221,7 @@ public class PacketsManager
{
PlayerDisguise playerDisguise = (PlayerDisguise) disguise;
String name = playerDisguise.getSkin() != null ? playerDisguise.getSkin() : playerDisguise.getName();
String name = playerDisguise.getName();
int entityId = disguisedEntity.getEntityId();
boolean removeName = false;

View File

@ -438,12 +438,19 @@ public class ReflectionManager
return null;
}
public static WrappedGameProfile getClonedProfile(WrappedGameProfile gameProfile)
{
return getGameProfileWithThisSkin(null, gameProfile.getName(), gameProfile);
}
public static WrappedGameProfile getGameProfileWithThisSkin(UUID uuid, String playerName, WrappedGameProfile profileWithSkin)
{
try
{
WrappedGameProfile gameProfile = new WrappedGameProfile(uuid != null ? uuid : UUID.randomUUID(), playerName);
gameProfile.getProperties().putAll(profileWithSkin.getProperties());
return gameProfile;
}
catch (Exception ex)