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-07-11 06:36:47 +02:00
|
|
|
import org.bukkit.entity.Entity;
|
2014-07-11 07:16:19 +02:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2014-07-11 07:16:19 +02:00
|
|
|
public PlayerDisguise addPlayer(Player player) {
|
|
|
|
return (PlayerDisguise) super.addPlayer(player);
|
|
|
|
}
|
|
|
|
|
|
|
|
public PlayerDisguise addPlayer(String playername) {
|
|
|
|
return (PlayerDisguise) super.addPlayer(playername);
|
|
|
|
}
|
|
|
|
|
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-07-11 07:16:19 +02:00
|
|
|
public PlayerDisguise removePlayer(Player player) {
|
|
|
|
return (PlayerDisguise) super.removePlayer(player);
|
|
|
|
}
|
|
|
|
|
|
|
|
public PlayerDisguise removePlayer(String playername) {
|
|
|
|
return (PlayerDisguise) super.removePlayer(playername);
|
|
|
|
}
|
|
|
|
|
|
|
|
public PlayerDisguise setDisguiseTarget(TargetType newTargetType) {
|
|
|
|
return (PlayerDisguise) super.setDisguiseTarget(newTargetType);
|
|
|
|
}
|
|
|
|
|
2014-07-11 06:36:47 +02:00
|
|
|
@Override
|
|
|
|
public PlayerDisguise setEntity(Entity entity) {
|
2014-07-11 07:07:47 +02:00
|
|
|
return (PlayerDisguise) super.setEntity(entity);
|
|
|
|
}
|
|
|
|
|
|
|
|
public PlayerDisguise setHearSelfDisguise(boolean hearSelfDisguise) {
|
|
|
|
return (PlayerDisguise) super.setHearSelfDisguise(hearSelfDisguise);
|
|
|
|
}
|
|
|
|
|
|
|
|
public PlayerDisguise setHideArmorFromSelf(boolean hideArmor) {
|
|
|
|
return (PlayerDisguise) super.setHideArmorFromSelf(hideArmor);
|
|
|
|
}
|
|
|
|
|
|
|
|
public PlayerDisguise setHideHeldItemFromSelf(boolean hideHeldItem) {
|
|
|
|
return (PlayerDisguise) super.setHideHeldItemFromSelf(hideHeldItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
public PlayerDisguise setKeepDisguiseOnEntityDespawn(boolean keepDisguise) {
|
|
|
|
return (PlayerDisguise) super.setKeepDisguiseOnEntityDespawn(keepDisguise);
|
|
|
|
}
|
|
|
|
|
|
|
|
public PlayerDisguise setKeepDisguiseOnPlayerDeath(boolean keepDisguise) {
|
|
|
|
return (PlayerDisguise) super.setKeepDisguiseOnPlayerDeath(keepDisguise);
|
|
|
|
}
|
|
|
|
|
|
|
|
public PlayerDisguise setKeepDisguiseOnPlayerLogout(boolean keepDisguise) {
|
|
|
|
return (PlayerDisguise) super.setKeepDisguiseOnPlayerLogout(keepDisguise);
|
|
|
|
}
|
|
|
|
|
|
|
|
public PlayerDisguise setModifyBoundingBox(boolean modifyBox) {
|
|
|
|
return (PlayerDisguise) super.setModifyBoundingBox(modifyBox);
|
|
|
|
}
|
|
|
|
|
|
|
|
public PlayerDisguise setReplaceSounds(boolean areSoundsReplaced) {
|
|
|
|
return (PlayerDisguise) super.setReplaceSounds(areSoundsReplaced);
|
2014-07-11 06:36:47 +02:00
|
|
|
}
|
|
|
|
|
2014-05-31 20:47:05 +02:00
|
|
|
@Deprecated
|
2014-07-11 06:37:34 +02:00
|
|
|
public PlayerDisguise setSkin(String skinToUse) {
|
2014-07-26 01:21:16 +02:00
|
|
|
if (LibVersion.is1_7_6()) {
|
|
|
|
this.skinToUse = skinToUse;
|
|
|
|
if (skinToUse == null) {
|
|
|
|
this.currentLookup = null;
|
|
|
|
this.gameProfile = null;
|
|
|
|
} else {
|
|
|
|
if (skinToUse.length() > 16) {
|
|
|
|
this.skinToUse = skinToUse.substring(0, 16);
|
|
|
|
}
|
2014-05-31 20:47:05 +02:00
|
|
|
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-07-11 06:37:34 +02:00
|
|
|
return this;
|
2014-05-31 20:47:05 +02:00
|
|
|
}
|
|
|
|
|
2014-06-05 14:08:54 +02:00
|
|
|
/**
|
|
|
|
* Set the GameProfile, without tampering.
|
|
|
|
*
|
|
|
|
* @param gameProfile
|
|
|
|
* GameProfile
|
2014-07-11 07:07:47 +02:00
|
|
|
* @return
|
2014-06-05 14:08:54 +02:00
|
|
|
*/
|
|
|
|
@Deprecated
|
2014-07-11 06:37:34 +02:00
|
|
|
public PlayerDisguise setSkin(WrappedGameProfile gameProfile) {
|
2014-06-05 14:08:54 +02:00
|
|
|
if (gameProfile == null) {
|
|
|
|
this.gameProfile = null;
|
|
|
|
this.skinToUse = null;
|
2014-07-11 06:37:53 +02:00
|
|
|
return this;
|
2014-06-05 14:08:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2014-07-11 06:37:34 +02:00
|
|
|
return this;
|
2014-06-05 14:08:54 +02:00
|
|
|
}
|
|
|
|
|
2014-07-11 07:07:47 +02:00
|
|
|
public PlayerDisguise setVelocitySent(boolean sendVelocity) {
|
|
|
|
return (PlayerDisguise) super.setVelocitySent(sendVelocity);
|
|
|
|
}
|
|
|
|
|
|
|
|
public PlayerDisguise setViewSelfDisguise(boolean viewSelfDisguise) {
|
|
|
|
return (PlayerDisguise) super.setViewSelfDisguise(viewSelfDisguise);
|
|
|
|
}
|
|
|
|
|
|
|
|
public PlayerDisguise setWatcher(FlagWatcher newWatcher) {
|
|
|
|
return (PlayerDisguise) super.setWatcher(newWatcher);
|
|
|
|
}
|
2014-07-11 07:16:19 +02:00
|
|
|
|
|
|
|
public PlayerDisguise silentlyAddPlayer(String playername) {
|
|
|
|
return (PlayerDisguise) super.silentlyAddPlayer(playername);
|
|
|
|
}
|
|
|
|
|
|
|
|
public PlayerDisguise silentlyRemovePlayer(String playername) {
|
|
|
|
return (PlayerDisguise) super.silentlyRemovePlayer(playername);
|
|
|
|
}
|
2013-05-17 23:05:19 +02:00
|
|
|
}
|