LibsDisguises/src/me/libraryaddict/disguise/disguisetypes/PlayerDisguise.java

137 lines
4.4 KiB
Java
Raw Normal View History

package me.libraryaddict.disguise.disguisetypes;
2013-05-17 23:05:19 +02:00
import java.util.UUID;
import org.apache.commons.lang.Validate;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
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 {
private LibsProfileLookup currentLookup;
private WrappedGameProfile gameProfile;
2013-05-17 23:05:19 +02:00
private String playerName;
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;
createDisguise(DisguiseType.PLAYER);
}
@Deprecated
public PlayerDisguise(String name, boolean replaceSounds) {
this(name);
this.setReplaceSounds(replaceSounds);
2013-05-17 23:05:19 +02:00
}
@Deprecated
public PlayerDisguise(String name, String skinToUse) {
this(name);
setSkin(skinToUse);
}
@Override
public PlayerDisguise clone() {
PlayerDisguise disguise = new PlayerDisguise(getName());
if (disguise.currentLookup == null && disguise.gameProfile != null) {
disguise.skinToUse = getSkin();
disguise.gameProfile = gameProfile;
} else {
disguise.setSkin(getSkin());
}
disguise.setReplaceSounds(isSoundsReplaced());
disguise.setViewSelfDisguise(isSelfDisguiseVisible());
disguise.setHearSelfDisguise(isSelfDisguiseSoundsReplaced());
disguise.setHideArmorFromSelf(isHidingArmorFromSelf());
disguise.setHideHeldItemFromSelf(isHidingHeldItemFromSelf());
disguise.setVelocitySent(isVelocitySent());
2014-01-04 10:15:18 +01:00
disguise.setModifyBoundingBox(isModifyBoundingBox());
disguise.setWatcher(getWatcher().clone(disguise));
return disguise;
}
@Deprecated
public WrappedGameProfile getGameProfile() {
if (getSkin() != null) {
if (gameProfile != null) {
return gameProfile;
}
return ReflectionManager.getGameProfile(null, getName());
} else {
return DisguiseUtilities.getProfileFromMojang(this);
}
}
2013-05-17 23:05:19 +02:00
public String getName() {
return playerName;
}
@Deprecated
public String getSkin() {
return skinToUse;
}
2013-12-01 17:10:38 +01:00
@Override
public boolean isPlayerDisguise() {
return true;
}
@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
public void onLookup(WrappedGameProfile gameProfile) {
if (currentLookup == this && gameProfile != null) {
setSkin(gameProfile);
if (!gameProfile.getProperties().isEmpty() && DisguiseUtilities.isDisguiseInUse(PlayerDisguise.this)) {
DisguiseUtilities.refreshTrackers(PlayerDisguise.this);
}
}
}
};
2014-06-06 03:59:22 +02:00
WrappedGameProfile gameProfile = DisguiseUtilities.getProfileFromMojang(this.skinToUse, currentLookup);
if (gameProfile != null) {
setSkin(gameProfile);
}
}
}
}
/**
* 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
}