2013-09-25 16:49:24 +02:00
|
|
|
package me.libraryaddict.disguise.disguisetypes;
|
2013-05-17 23:05:19 +02:00
|
|
|
|
2014-06-05 13:52:04 +02:00
|
|
|
import java.util.UUID;
|
|
|
|
|
2014-06-05 14:08:54 +02:00
|
|
|
import org.apache.commons.lang.Validate;
|
2014-05-31 20:53:01 +02:00
|
|
|
|
2014-06-04 22:40:15 +02:00
|
|
|
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
|
|
|
|
2014-05-31 20:47:05 +02:00
|
|
|
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
|
|
|
import me.libraryaddict.disguise.utilities.LibsProfileLookup;
|
|
|
|
import me.libraryaddict.disguise.utilities.ReflectionManager;
|
|
|
|
import me.libraryaddict.disguise.utilities.ReflectionManager.LibVersion;
|
|
|
|
|
2013-12-01 16:37:07 +01:00
|
|
|
public class PlayerDisguise extends TargetedDisguise {
|
2014-05-31 20:47:05 +02:00
|
|
|
private LibsProfileLookup currentLookup;
|
2014-06-04 22:40:15 +02:00
|
|
|
private WrappedGameProfile gameProfile;
|
2013-05-17 23:05:19 +02:00
|
|
|
private String playerName;
|
2014-05-31 20:47:05 +02:00
|
|
|
private String skinToUse;
|
2013-05-17 23:05:19 +02:00
|
|
|
|
|
|
|
public PlayerDisguise(String name) {
|
|
|
|
if (name.length() > 16)
|
|
|
|
name = name.substring(0, 16);
|
|
|
|
playerName = name;
|
2014-05-14 00:34:41 +02:00
|
|
|
createDisguise(DisguiseType.PLAYER);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Deprecated
|
|
|
|
public PlayerDisguise(String name, boolean replaceSounds) {
|
|
|
|
this(name);
|
|
|
|
this.setReplaceSounds(replaceSounds);
|
2013-05-17 23:05:19 +02:00
|
|
|
}
|
|
|
|
|
2014-05-31 20:47:05 +02:00
|
|
|
@Deprecated
|
|
|
|
public PlayerDisguise(String name, String skinToUse) {
|
|
|
|
this(name);
|
|
|
|
setSkin(skinToUse);
|
|
|
|
}
|
|
|
|
|
2013-11-05 17:37:10 +01:00
|
|
|
@Override
|
2013-07-16 07:23:38 +02:00
|
|
|
public PlayerDisguise clone() {
|
2014-05-14 00:34:41 +02:00
|
|
|
PlayerDisguise disguise = new PlayerDisguise(getName());
|
2014-05-31 20:47:05 +02:00
|
|
|
if (disguise.currentLookup == null && disguise.gameProfile != null) {
|
|
|
|
disguise.skinToUse = getSkin();
|
|
|
|
disguise.gameProfile = gameProfile;
|
|
|
|
} else {
|
|
|
|
disguise.setSkin(getSkin());
|
|
|
|
}
|
2014-05-14 00:34:41 +02:00
|
|
|
disguise.setReplaceSounds(isSoundsReplaced());
|
2013-11-22 20:52:15 +01:00
|
|
|
disguise.setViewSelfDisguise(isSelfDisguiseVisible());
|
2013-11-22 21:19:30 +01:00
|
|
|
disguise.setHearSelfDisguise(isSelfDisguiseSoundsReplaced());
|
2013-11-05 17:37:10 +01:00
|
|
|
disguise.setHideArmorFromSelf(isHidingArmorFromSelf());
|
|
|
|
disguise.setHideHeldItemFromSelf(isHidingHeldItemFromSelf());
|
|
|
|
disguise.setVelocitySent(isVelocitySent());
|
2014-01-04 10:15:18 +01:00
|
|
|
disguise.setModifyBoundingBox(isModifyBoundingBox());
|
2013-11-05 17:37:10 +01:00
|
|
|
disguise.setWatcher(getWatcher().clone(disguise));
|
2013-07-16 07:23:38 +02:00
|
|
|
return disguise;
|
|
|
|
}
|
|
|
|
|
2014-05-31 20:47:05 +02:00
|
|
|
@Deprecated
|
2014-06-04 22:40:15 +02:00
|
|
|
public WrappedGameProfile getGameProfile() {
|
2014-05-31 20:47:05 +02:00
|
|
|
if (getSkin() != null) {
|
|
|
|
if (gameProfile != null) {
|
|
|
|
return gameProfile;
|
|
|
|
}
|
|
|
|
return ReflectionManager.getGameProfile(null, getName());
|
|
|
|
} else {
|
2014-05-31 20:53:01 +02:00
|
|
|
return DisguiseUtilities.getProfileFromMojang(this);
|
2014-05-31 20:47:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-17 23:05:19 +02:00
|
|
|
public String getName() {
|
|
|
|
return playerName;
|
|
|
|
}
|
|
|
|
|
2014-05-31 20:47:05 +02:00
|
|
|
@Deprecated
|
|
|
|
public String getSkin() {
|
|
|
|
return skinToUse;
|
|
|
|
}
|
|
|
|
|
2013-12-01 17:10:38 +01:00
|
|
|
@Override
|
|
|
|
public boolean isPlayerDisguise() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-05-31 20:47:05 +02:00
|
|
|
@Deprecated
|
|
|
|
public void setSkin(String skinToUse) {
|
|
|
|
this.skinToUse = skinToUse;
|
|
|
|
if (skinToUse == null) {
|
|
|
|
this.currentLookup = null;
|
|
|
|
this.gameProfile = null;
|
|
|
|
} else {
|
|
|
|
if (skinToUse.length() > 16) {
|
|
|
|
this.skinToUse = skinToUse.substring(0, 16);
|
|
|
|
}
|
|
|
|
if (LibVersion.is1_7()) {
|
|
|
|
currentLookup = new LibsProfileLookup() {
|
|
|
|
|
|
|
|
@Override
|
2014-06-04 22:40:15 +02:00
|
|
|
public void onLookup(WrappedGameProfile gameProfile) {
|
2014-05-31 20:47:05 +02:00
|
|
|
if (currentLookup == this && gameProfile != null) {
|
2014-06-05 14:08:54 +02:00
|
|
|
setSkin(gameProfile);
|
2014-07-03 11:30:09 +02:00
|
|
|
if (!gameProfile.getProperties().isEmpty() && DisguiseUtilities.isDisguiseInUse(PlayerDisguise.this)) {
|
2014-05-31 20:47:05 +02:00
|
|
|
DisguiseUtilities.refreshTrackers(PlayerDisguise.this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2014-06-06 03:59:22 +02:00
|
|
|
WrappedGameProfile gameProfile = DisguiseUtilities.getProfileFromMojang(this.skinToUse, currentLookup);
|
|
|
|
if (gameProfile != null) {
|
|
|
|
setSkin(gameProfile);
|
2014-05-31 20:47:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-05 14:08:54 +02:00
|
|
|
/**
|
|
|
|
* Set the GameProfile, without tampering.
|
|
|
|
*
|
|
|
|
* @param gameProfile
|
|
|
|
* GameProfile
|
|
|
|
*/
|
|
|
|
@Deprecated
|
|
|
|
public void setSkin(WrappedGameProfile gameProfile) {
|
|
|
|
if (gameProfile == null) {
|
|
|
|
this.gameProfile = null;
|
|
|
|
this.skinToUse = null;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Validate.notEmpty(gameProfile.getName(), "Name must be set");
|
|
|
|
this.skinToUse = gameProfile.getName();
|
|
|
|
this.gameProfile = ReflectionManager.getGameProfileWithThisSkin(
|
|
|
|
gameProfile.getId() != null ? UUID.fromString(gameProfile.getId()) : null, getName(), gameProfile);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-05-17 23:05:19 +02:00
|
|
|
}
|