2016-12-01 02:34:34 +01:00
|
|
|
package me.libraryaddict.disguise.disguisetypes;
|
|
|
|
|
|
|
|
import com.comphenix.protocol.ProtocolLibrary;
|
|
|
|
import com.comphenix.protocol.events.PacketContainer;
|
|
|
|
import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction;
|
|
|
|
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
2020-02-05 02:26:55 +01:00
|
|
|
import lombok.Getter;
|
|
|
|
import lombok.Setter;
|
2020-01-20 01:35:55 +01:00
|
|
|
import me.libraryaddict.disguise.DisguiseConfig;
|
2016-12-01 02:34:34 +01:00
|
|
|
import me.libraryaddict.disguise.LibsDisguises;
|
|
|
|
import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher;
|
|
|
|
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
2019-01-03 03:13:03 +01:00
|
|
|
import me.libraryaddict.disguise.utilities.reflection.LibsProfileLookup;
|
|
|
|
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
2017-05-28 00:23:15 +02:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.entity.Entity;
|
|
|
|
import org.bukkit.entity.Player;
|
2020-01-20 01:35:55 +01:00
|
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
2017-05-28 00:23:15 +02:00
|
|
|
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
import java.util.UUID;
|
2016-12-01 02:34:34 +01:00
|
|
|
|
|
|
|
public class PlayerDisguise extends TargetedDisguise {
|
2017-05-28 00:23:15 +02:00
|
|
|
private transient LibsProfileLookup currentLookup;
|
2017-06-02 15:51:03 +02:00
|
|
|
private WrappedGameProfile gameProfile;
|
2020-03-30 09:22:33 +02:00
|
|
|
private String playerName = "Herobrine";
|
2016-12-01 02:34:34 +01:00
|
|
|
private String skinToUse;
|
2020-01-19 03:48:52 +01:00
|
|
|
private boolean nameVisible = true;
|
2020-05-07 11:27:07 +02:00
|
|
|
/**
|
|
|
|
* Has someone set name visible explicitly?
|
|
|
|
*/
|
|
|
|
private boolean explicitNameVisible = false;
|
2016-12-01 02:34:34 +01:00
|
|
|
private UUID uuid = UUID.randomUUID();
|
2020-02-05 02:26:55 +01:00
|
|
|
@Getter
|
|
|
|
@Setter
|
|
|
|
private boolean dynamicName;
|
2020-04-04 08:58:21 +02:00
|
|
|
private volatile DisguiseUtilities.DScoreTeam scoreboardName;
|
2016-12-01 02:34:34 +01:00
|
|
|
|
|
|
|
private PlayerDisguise() {
|
|
|
|
super(DisguiseType.PLAYER);
|
|
|
|
}
|
|
|
|
|
|
|
|
public PlayerDisguise(Player player) {
|
|
|
|
this(ReflectionManager.getGameProfile(player));
|
|
|
|
}
|
|
|
|
|
|
|
|
public PlayerDisguise(Player player, Player skinToUse) {
|
|
|
|
this(ReflectionManager.getGameProfile(player), ReflectionManager.getGameProfile(skinToUse));
|
|
|
|
}
|
|
|
|
|
|
|
|
public PlayerDisguise(String name) {
|
2020-03-25 03:53:08 +01:00
|
|
|
this(name, name);
|
2016-12-01 02:34:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public PlayerDisguise(String name, String skinToUse) {
|
|
|
|
this();
|
|
|
|
|
|
|
|
setName(name);
|
|
|
|
setSkin(skinToUse);
|
|
|
|
|
|
|
|
createDisguise();
|
|
|
|
}
|
|
|
|
|
|
|
|
public PlayerDisguise(WrappedGameProfile gameProfile) {
|
|
|
|
this();
|
|
|
|
|
|
|
|
setName(gameProfile.getName());
|
|
|
|
|
2017-06-02 15:51:03 +02:00
|
|
|
this.gameProfile = ReflectionManager.getGameProfileWithThisSkin(uuid, gameProfile.getName(), gameProfile);
|
2016-12-01 02:34:34 +01:00
|
|
|
|
|
|
|
createDisguise();
|
|
|
|
}
|
|
|
|
|
|
|
|
public PlayerDisguise(WrappedGameProfile gameProfile, WrappedGameProfile skinToUse) {
|
|
|
|
this();
|
|
|
|
|
|
|
|
setName(gameProfile.getName());
|
|
|
|
|
2017-06-02 15:51:03 +02:00
|
|
|
this.gameProfile = ReflectionManager.getGameProfile(uuid, gameProfile.getName());
|
2016-12-01 02:34:34 +01:00
|
|
|
|
|
|
|
setSkin(skinToUse);
|
|
|
|
|
|
|
|
createDisguise();
|
|
|
|
}
|
|
|
|
|
2020-04-24 09:34:37 +02:00
|
|
|
@Deprecated
|
2020-04-04 08:58:21 +02:00
|
|
|
public DisguiseUtilities.DScoreTeam getScoreboardName() {
|
2020-05-07 11:27:07 +02:00
|
|
|
if (!DisguiseConfig.isScoreboardNames()) {
|
2020-03-30 09:22:33 +02:00
|
|
|
throw new IllegalStateException("Cannot use this method when it's been disabled in config!");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scoreboardName == null) {
|
|
|
|
scoreboardName = DisguiseUtilities.createExtendedName(getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
return scoreboardName;
|
|
|
|
}
|
|
|
|
|
2020-04-07 06:14:17 +02:00
|
|
|
private void setScoreboardName(String[] split) {
|
|
|
|
getScoreboardName().setSplit(split);
|
|
|
|
}
|
|
|
|
|
2020-04-04 15:24:02 +02:00
|
|
|
private boolean isStaticName(String name) {
|
|
|
|
return name != null && (name.equalsIgnoreCase("Dinnerbone") || name.equalsIgnoreCase("Grumm"));
|
|
|
|
}
|
|
|
|
|
2020-03-30 09:22:33 +02:00
|
|
|
public boolean hasScoreboardName() {
|
2020-05-07 11:27:07 +02:00
|
|
|
if (!DisguiseConfig.isArmorstandsName() && isStaticName(getName())) {
|
2020-04-04 15:24:02 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:07 +02:00
|
|
|
return DisguiseConfig.isScoreboardNames();
|
2020-01-20 01:35:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public String getProfileName() {
|
2020-03-30 09:22:33 +02:00
|
|
|
return hasScoreboardName() ? getScoreboardName().getPlayer() : getName();
|
2020-01-20 01:35:55 +01:00
|
|
|
}
|
|
|
|
|
2018-07-11 20:05:36 +02:00
|
|
|
public UUID getUUID() {
|
|
|
|
return uuid;
|
|
|
|
}
|
|
|
|
|
2020-01-19 03:48:52 +01:00
|
|
|
public boolean isNameVisible() {
|
|
|
|
return nameVisible;
|
|
|
|
}
|
|
|
|
|
|
|
|
public PlayerDisguise setNameVisible(boolean nameVisible) {
|
2020-05-07 11:27:07 +02:00
|
|
|
return setNameVisible(nameVisible, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
private PlayerDisguise setNameVisible(boolean nameVisible, boolean setInternally) {
|
|
|
|
if (isNameVisible() == nameVisible || (setInternally && explicitNameVisible)) {
|
2020-01-19 03:48:52 +01:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:07 +02:00
|
|
|
if (!setInternally) {
|
|
|
|
explicitNameVisible = true;
|
|
|
|
}
|
|
|
|
|
2020-01-19 03:48:52 +01:00
|
|
|
if (isDisguiseInUse()) {
|
2020-05-07 11:27:07 +02:00
|
|
|
if (DisguiseConfig.isArmorstandsName()) {
|
|
|
|
this.nameVisible = nameVisible;
|
|
|
|
sendArmorStands(isNameVisible() ? getMultiName() : new String[0]);
|
|
|
|
} else if (!DisguiseConfig.isScoreboardNames()) {
|
2020-03-30 09:22:33 +02:00
|
|
|
if (stopDisguise()) {
|
|
|
|
this.nameVisible = nameVisible;
|
2020-01-19 03:48:52 +01:00
|
|
|
|
2020-03-30 09:22:33 +02:00
|
|
|
if (!startDisguise()) {
|
|
|
|
throw new IllegalStateException("Unable to restart disguise");
|
|
|
|
}
|
|
|
|
} else {
|
2020-01-19 03:48:52 +01:00
|
|
|
throw new IllegalStateException("Unable to restart disguise");
|
|
|
|
}
|
|
|
|
} else {
|
2020-03-30 09:22:33 +02:00
|
|
|
this.nameVisible = nameVisible;
|
|
|
|
DisguiseUtilities.updateExtendedName(this);
|
2020-01-19 03:48:52 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.nameVisible = nameVisible;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2016-12-01 02:34:34 +01:00
|
|
|
@Override
|
|
|
|
public PlayerDisguise addPlayer(Player player) {
|
|
|
|
return (PlayerDisguise) super.addPlayer(player);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public PlayerDisguise addPlayer(String playername) {
|
|
|
|
return (PlayerDisguise) super.addPlayer(playername);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public PlayerDisguise clone() {
|
|
|
|
PlayerDisguise disguise = new PlayerDisguise();
|
|
|
|
|
2017-03-21 07:34:12 +01:00
|
|
|
if (currentLookup == null && gameProfile != null) {
|
2016-12-01 02:34:34 +01:00
|
|
|
disguise.skinToUse = getSkin();
|
2017-07-01 00:44:33 +02:00
|
|
|
disguise.gameProfile = ReflectionManager
|
|
|
|
.getGameProfileWithThisSkin(disguise.uuid, getGameProfile().getName(), getGameProfile());
|
2017-03-21 07:34:12 +01:00
|
|
|
} else {
|
2016-12-01 02:34:34 +01:00
|
|
|
disguise.setSkin(getSkin());
|
|
|
|
}
|
|
|
|
|
2020-04-24 09:34:37 +02:00
|
|
|
disguise.setName(getName());
|
2020-05-07 11:27:07 +02:00
|
|
|
disguise.nameVisible = isNameVisible();
|
|
|
|
disguise.explicitNameVisible = explicitNameVisible;
|
2020-04-24 06:19:24 +02:00
|
|
|
disguise.setDynamicName(isDynamicName());
|
2016-12-01 02:34:34 +01:00
|
|
|
|
2020-04-15 14:55:35 +02:00
|
|
|
clone(disguise);
|
2016-12-01 02:34:34 +01:00
|
|
|
|
|
|
|
return disguise;
|
|
|
|
}
|
|
|
|
|
|
|
|
public WrappedGameProfile getGameProfile() {
|
|
|
|
if (gameProfile == null) {
|
|
|
|
if (getSkin() != null) {
|
2020-01-20 01:35:55 +01:00
|
|
|
gameProfile = ReflectionManager.getGameProfile(uuid, getProfileName());
|
2017-03-21 07:34:12 +01:00
|
|
|
} else {
|
2020-01-20 01:35:55 +01:00
|
|
|
gameProfile = ReflectionManager.getGameProfileWithThisSkin(uuid, getProfileName(),
|
|
|
|
DisguiseUtilities.getProfileFromMojang(this));
|
2016-12-01 02:34:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-02 15:51:03 +02:00
|
|
|
return gameProfile;
|
2016-12-01 02:34:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setGameProfile(WrappedGameProfile gameProfile) {
|
2017-06-02 15:51:03 +02:00
|
|
|
this.gameProfile = ReflectionManager.getGameProfileWithThisSkin(uuid, gameProfile.getName(), gameProfile);
|
2016-12-01 02:34:34 +01:00
|
|
|
}
|
|
|
|
|
2020-02-05 02:26:55 +01:00
|
|
|
public String getName() {
|
|
|
|
return playerName;
|
2016-12-01 02:34:34 +01:00
|
|
|
}
|
|
|
|
|
2020-01-19 03:48:52 +01:00
|
|
|
public void setName(String name) {
|
2020-04-07 12:05:10 +02:00
|
|
|
if (getName().equals("<Inherit>") && getEntity() != null) {
|
|
|
|
name = getEntity().getCustomName();
|
|
|
|
|
|
|
|
if (name == null || name.isEmpty()) {
|
|
|
|
name = getEntity().getType().name();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-19 03:48:52 +01:00
|
|
|
if (name.equals(playerName)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:07 +02:00
|
|
|
int cLimit;
|
|
|
|
|
|
|
|
switch (DisguiseConfig.getPlayerNameType()) {
|
|
|
|
case TEAMS:
|
|
|
|
cLimit = 16 * 2;
|
|
|
|
break;
|
2020-05-07 12:05:34 +02:00
|
|
|
case EXTENDED:
|
2020-05-07 11:27:07 +02:00
|
|
|
cLimit = 16 * 3;
|
|
|
|
break;
|
|
|
|
case ARMORSTANDS:
|
|
|
|
cLimit = 256;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
cLimit = 16;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-04-07 12:05:10 +02:00
|
|
|
if (name.length() > cLimit) {
|
2020-04-07 11:31:47 +02:00
|
|
|
name = name.substring(0, cLimit);
|
2020-01-20 01:35:55 +01:00
|
|
|
}
|
|
|
|
|
2020-03-30 09:22:33 +02:00
|
|
|
if (isDisguiseInUse()) {
|
2020-05-07 11:27:07 +02:00
|
|
|
if (DisguiseConfig.isArmorstandsName()) {
|
|
|
|
playerName = name;
|
2020-03-25 03:53:08 +01:00
|
|
|
|
2020-05-07 11:27:07 +02:00
|
|
|
setNameVisible(!name.isEmpty(), true);
|
|
|
|
setMultiName(DisguiseUtilities.splitNewLine(name));
|
|
|
|
} else {
|
|
|
|
boolean resendDisguise = false;
|
2020-01-19 03:48:52 +01:00
|
|
|
|
2020-05-07 11:27:07 +02:00
|
|
|
if (DisguiseConfig.isScoreboardNames() && !isStaticName(name)) {
|
|
|
|
DisguiseUtilities.DScoreTeam team = getScoreboardName();
|
|
|
|
String[] split = DisguiseUtilities.getExtendedNameSplit(team.getPlayer(), name);
|
2020-03-30 09:22:33 +02:00
|
|
|
|
2020-05-07 11:27:07 +02:00
|
|
|
resendDisguise = !split[1].equals(team.getPlayer());
|
|
|
|
setScoreboardName(split);
|
|
|
|
}
|
2020-04-04 15:24:02 +02:00
|
|
|
|
2020-05-07 11:27:07 +02:00
|
|
|
resendDisguise = !DisguiseConfig.isScoreboardNames() || isStaticName(name) || isStaticName(getName()) ||
|
|
|
|
resendDisguise;
|
2020-03-30 09:22:33 +02:00
|
|
|
|
2020-05-07 11:27:07 +02:00
|
|
|
if (resendDisguise) {
|
|
|
|
if (stopDisguise()) {
|
|
|
|
if (getName().isEmpty() && !name.isEmpty()) {
|
|
|
|
setNameVisible(true, true);
|
|
|
|
} else if (!getName().isEmpty() && name.isEmpty()) {
|
|
|
|
setNameVisible(false, true);
|
|
|
|
}
|
2020-01-28 05:02:30 +01:00
|
|
|
|
2020-05-07 11:27:07 +02:00
|
|
|
playerName = name;
|
2020-03-30 09:22:33 +02:00
|
|
|
|
2020-05-07 11:27:07 +02:00
|
|
|
if (gameProfile != null) {
|
|
|
|
gameProfile = ReflectionManager
|
|
|
|
.getGameProfileWithThisSkin(uuid, getProfileName(), getGameProfile());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!startDisguise()) {
|
|
|
|
throw new IllegalStateException("Unable to restart disguise");
|
|
|
|
}
|
|
|
|
} else {
|
2020-03-30 09:22:33 +02:00
|
|
|
throw new IllegalStateException("Unable to restart disguise");
|
|
|
|
}
|
|
|
|
} else {
|
2020-05-07 11:27:07 +02:00
|
|
|
if (getName().isEmpty() && !name.isEmpty() && !isNameVisible()) {
|
|
|
|
setNameVisible(true, true);
|
|
|
|
} else if (!getName().isEmpty() && name.isEmpty() && isNameVisible()) {
|
|
|
|
setNameVisible(false, true);
|
|
|
|
} else {
|
|
|
|
DisguiseUtilities.updateExtendedName(this);
|
|
|
|
}
|
2020-03-30 09:22:33 +02:00
|
|
|
|
2020-05-07 11:27:07 +02:00
|
|
|
playerName = name;
|
|
|
|
}
|
2020-01-19 03:48:52 +01:00
|
|
|
}
|
2020-04-07 06:14:17 +02:00
|
|
|
|
|
|
|
if (isDisplayedInTab()) {
|
|
|
|
PacketContainer addTab = DisguiseUtilities.getTabPacket(this, PlayerInfoAction.UPDATE_DISPLAY_NAME);
|
|
|
|
|
|
|
|
try {
|
|
|
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
|
|
|
if (!canSee(player))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, addTab);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (InvocationTargetException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2020-01-19 03:48:52 +01:00
|
|
|
} else {
|
2020-03-30 09:22:33 +02:00
|
|
|
if (scoreboardName != null) {
|
2020-04-04 08:58:21 +02:00
|
|
|
DisguiseUtilities.DScoreTeam team = getScoreboardName();
|
2020-03-30 09:22:33 +02:00
|
|
|
String[] split = DisguiseUtilities.getExtendedNameSplit(team.getPlayer(), name);
|
|
|
|
|
2020-04-07 06:14:17 +02:00
|
|
|
setScoreboardName(split);
|
2020-03-30 09:22:33 +02:00
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:07 +02:00
|
|
|
if (DisguiseConfig.isScoreboardNames()) {
|
|
|
|
setMultiName(DisguiseUtilities.splitNewLine(name));
|
2020-03-25 03:53:08 +01:00
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:07 +02:00
|
|
|
setNameVisible(!name.isEmpty(), true);
|
2020-01-19 03:48:52 +01:00
|
|
|
playerName = name;
|
2020-01-28 05:02:30 +01:00
|
|
|
|
|
|
|
if (gameProfile != null) {
|
|
|
|
gameProfile = ReflectionManager.getGameProfileWithThisSkin(uuid, getProfileName(), getGameProfile());
|
|
|
|
}
|
2020-01-19 03:48:52 +01:00
|
|
|
}
|
2016-12-01 02:34:34 +01:00
|
|
|
}
|
|
|
|
|
2020-02-05 02:26:55 +01:00
|
|
|
public String getSkin() {
|
|
|
|
return skinToUse;
|
2016-12-22 02:11:03 +01:00
|
|
|
}
|
|
|
|
|
2016-12-01 02:34:34 +01:00
|
|
|
public PlayerDisguise setSkin(String newSkin) {
|
2020-05-07 11:27:07 +02:00
|
|
|
if (newSkin != null && newSkin.length() > 70 && newSkin.startsWith("{") && newSkin.endsWith("}")) {
|
2016-12-01 02:34:34 +01:00
|
|
|
try {
|
2017-07-01 00:44:33 +02:00
|
|
|
return setSkin(DisguiseUtilities.getGson().fromJson(newSkin, WrappedGameProfile.class));
|
2016-12-01 02:34:34 +01:00
|
|
|
}
|
2017-07-01 00:45:11 +02:00
|
|
|
catch (Exception ex) {
|
2020-01-22 06:46:57 +01:00
|
|
|
if (!"12345".equals("%%__USER__%%")) {
|
|
|
|
throw new IllegalArgumentException(String.format(
|
2020-05-07 11:27:07 +02:00
|
|
|
"The skin %s is too long to normally be a playername, but cannot be parsed to a " +
|
|
|
|
"GameProfile!", newSkin));
|
2020-01-22 06:46:57 +01:00
|
|
|
}
|
2016-12-01 02:34:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:07 +02:00
|
|
|
if (newSkin != null && newSkin.length() > 16) {
|
|
|
|
newSkin = null;
|
|
|
|
}
|
|
|
|
|
2020-04-07 06:14:17 +02:00
|
|
|
String oldSkin = skinToUse;
|
2016-12-01 02:34:34 +01:00
|
|
|
skinToUse = newSkin;
|
|
|
|
|
|
|
|
if (newSkin == null) {
|
|
|
|
currentLookup = null;
|
|
|
|
gameProfile = null;
|
2017-03-21 07:34:12 +01:00
|
|
|
} else {
|
2016-12-01 02:34:34 +01:00
|
|
|
if (newSkin.length() > 16) {
|
|
|
|
skinToUse = newSkin.substring(0, 16);
|
|
|
|
}
|
2020-04-07 06:14:17 +02:00
|
|
|
|
|
|
|
if (newSkin.equals(oldSkin)) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isDisguiseInUse()) {
|
|
|
|
currentLookup = new LibsProfileLookup() {
|
|
|
|
@Override
|
|
|
|
public void onLookup(WrappedGameProfile gameProfile) {
|
|
|
|
if (currentLookup != this || gameProfile == null || gameProfile.getProperties().isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
setSkin(gameProfile);
|
|
|
|
|
|
|
|
currentLookup = null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
WrappedGameProfile gameProfile = DisguiseUtilities.getProfileFromMojang(this.skinToUse, currentLookup,
|
|
|
|
LibsDisguises.getInstance().getConfig().getBoolean("ContactMojangServers", true));
|
|
|
|
|
|
|
|
if (gameProfile != null) {
|
|
|
|
setSkin(gameProfile);
|
|
|
|
}
|
|
|
|
}
|
2016-12-01 02:34:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the GameProfile, without tampering.
|
|
|
|
*
|
2017-03-21 07:34:12 +01:00
|
|
|
* @param gameProfile GameProfile
|
2016-12-01 02:34:34 +01:00
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public PlayerDisguise setSkin(WrappedGameProfile gameProfile) {
|
|
|
|
if (gameProfile == null) {
|
|
|
|
this.gameProfile = null;
|
|
|
|
this.skinToUse = null;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
currentLookup = null;
|
|
|
|
|
|
|
|
this.skinToUse = gameProfile.getName();
|
2020-01-20 01:35:55 +01:00
|
|
|
this.gameProfile = ReflectionManager.getGameProfileWithThisSkin(uuid, getProfileName(), gameProfile);
|
2016-12-01 02:34:34 +01:00
|
|
|
|
2020-04-07 06:14:17 +02:00
|
|
|
refreshDisguise();
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void refreshDisguise() {
|
2016-12-01 02:34:34 +01:00
|
|
|
if (DisguiseUtilities.isDisguiseInUse(this)) {
|
|
|
|
if (isDisplayedInTab()) {
|
2020-04-07 06:14:17 +02:00
|
|
|
PacketContainer addTab = DisguiseUtilities.getTabPacket(this, PlayerInfoAction.ADD_PLAYER);
|
2016-12-01 02:34:34 +01:00
|
|
|
|
|
|
|
PacketContainer deleteTab = addTab.shallowClone();
|
|
|
|
deleteTab.getPlayerInfoAction().write(0, PlayerInfoAction.REMOVE_PLAYER);
|
|
|
|
|
|
|
|
try {
|
|
|
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
2017-03-21 07:34:12 +01:00
|
|
|
if (!canSee(player))
|
2016-12-01 02:34:34 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, deleteTab);
|
|
|
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, addTab);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (InvocationTargetException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DisguiseUtilities.refreshTrackers(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-05 02:26:55 +01:00
|
|
|
@Override
|
|
|
|
public PlayerWatcher getWatcher() {
|
|
|
|
return (PlayerWatcher) super.getWatcher();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public PlayerDisguise setWatcher(FlagWatcher newWatcher) {
|
|
|
|
return (PlayerDisguise) super.setWatcher(newWatcher);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isDisplayedInTab() {
|
|
|
|
return getWatcher().isDisplayedInTab();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setDisplayedInTab(boolean showPlayerInTab) {
|
|
|
|
getWatcher().setDisplayedInTab(showPlayerInTab);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isPlayerDisguise() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public PlayerDisguise removePlayer(Player player) {
|
|
|
|
return (PlayerDisguise) super.removePlayer(player);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public PlayerDisguise removePlayer(String playername) {
|
|
|
|
return (PlayerDisguise) super.removePlayer(playername);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public PlayerDisguise setDisguiseTarget(TargetType newTargetType) {
|
|
|
|
return (PlayerDisguise) super.setDisguiseTarget(newTargetType);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public PlayerDisguise setEntity(Entity entity) {
|
|
|
|
return (PlayerDisguise) super.setEntity(entity);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public PlayerDisguise setHearSelfDisguise(boolean hearSelfDisguise) {
|
|
|
|
return (PlayerDisguise) super.setHearSelfDisguise(hearSelfDisguise);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public PlayerDisguise setHideArmorFromSelf(boolean hideArmor) {
|
|
|
|
return (PlayerDisguise) super.setHideArmorFromSelf(hideArmor);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public PlayerDisguise setHideHeldItemFromSelf(boolean hideHeldItem) {
|
|
|
|
return (PlayerDisguise) super.setHideHeldItemFromSelf(hideHeldItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public PlayerDisguise setKeepDisguiseOnPlayerDeath(boolean keepDisguise) {
|
|
|
|
return (PlayerDisguise) super.setKeepDisguiseOnPlayerDeath(keepDisguise);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public PlayerDisguise setModifyBoundingBox(boolean modifyBox) {
|
|
|
|
return (PlayerDisguise) super.setModifyBoundingBox(modifyBox);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public PlayerDisguise setReplaceSounds(boolean areSoundsReplaced) {
|
|
|
|
return (PlayerDisguise) super.setReplaceSounds(areSoundsReplaced);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean startDisguise() {
|
2020-03-30 09:22:33 +02:00
|
|
|
if (isDisguiseInUse()) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-02-05 02:26:55 +01:00
|
|
|
|
2020-03-30 09:22:33 +02:00
|
|
|
if (skinToUse != null && gameProfile == null) {
|
|
|
|
currentLookup = new LibsProfileLookup() {
|
|
|
|
@Override
|
|
|
|
public void onLookup(WrappedGameProfile gameProfile) {
|
|
|
|
if (currentLookup != this || gameProfile == null || gameProfile.getProperties().isEmpty())
|
|
|
|
return;
|
2020-02-05 02:26:55 +01:00
|
|
|
|
|
|
|
setSkin(gameProfile);
|
2020-03-30 09:22:33 +02:00
|
|
|
|
|
|
|
currentLookup = null;
|
2020-02-05 02:26:55 +01:00
|
|
|
}
|
2020-03-30 09:22:33 +02:00
|
|
|
};
|
2020-02-05 02:26:55 +01:00
|
|
|
|
2020-03-30 09:22:33 +02:00
|
|
|
WrappedGameProfile gameProfile = DisguiseUtilities.getProfileFromMojang(this.skinToUse, currentLookup,
|
|
|
|
LibsDisguises.getInstance().getConfig().getBoolean("ContactMojangServers", true));
|
2020-02-05 02:29:04 +01:00
|
|
|
|
2020-03-30 09:22:33 +02:00
|
|
|
if (gameProfile != null) {
|
|
|
|
setSkin(gameProfile);
|
|
|
|
}
|
|
|
|
}
|
2020-02-05 02:29:04 +01:00
|
|
|
|
2020-03-30 09:22:33 +02:00
|
|
|
if (isDynamicName()) {
|
|
|
|
String name = getEntity().getCustomName();
|
2020-02-05 02:26:55 +01:00
|
|
|
|
2020-03-30 09:22:33 +02:00
|
|
|
if (name == null) {
|
|
|
|
name = "";
|
|
|
|
}
|
2020-02-05 02:26:55 +01:00
|
|
|
|
2020-03-30 09:22:33 +02:00
|
|
|
if (!getName().equals(name)) {
|
2020-02-05 02:26:55 +01:00
|
|
|
setName(name);
|
|
|
|
}
|
2020-03-30 09:22:33 +02:00
|
|
|
} else if (getName().equals("<Inherit>") && getEntity() != null) {
|
|
|
|
String name = getEntity().getCustomName();
|
|
|
|
|
|
|
|
if (name == null || name.isEmpty()) {
|
|
|
|
name = getEntity().getType().name();
|
|
|
|
}
|
|
|
|
|
|
|
|
setName(name);
|
2020-02-05 02:26:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
boolean result = super.startDisguise();
|
|
|
|
|
2020-03-30 09:22:33 +02:00
|
|
|
if (result && hasScoreboardName()) {
|
|
|
|
DisguiseUtilities.registerExtendedName(this);
|
2020-02-05 02:26:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-12-01 02:34:34 +01:00
|
|
|
@Override
|
|
|
|
public PlayerDisguise setVelocitySent(boolean sendVelocity) {
|
|
|
|
return (PlayerDisguise) super.setVelocitySent(sendVelocity);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public PlayerDisguise setViewSelfDisguise(boolean viewSelfDisguise) {
|
|
|
|
return (PlayerDisguise) super.setViewSelfDisguise(viewSelfDisguise);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public PlayerDisguise silentlyAddPlayer(String playername) {
|
|
|
|
return (PlayerDisguise) super.silentlyAddPlayer(playername);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public PlayerDisguise silentlyRemovePlayer(String playername) {
|
|
|
|
return (PlayerDisguise) super.silentlyRemovePlayer(playername);
|
|
|
|
}
|
2020-01-20 01:35:55 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean removeDisguise(boolean disguiseBeingReplaced) {
|
|
|
|
boolean result = super.removeDisguise(disguiseBeingReplaced);
|
|
|
|
|
2020-03-30 09:22:33 +02:00
|
|
|
if (result && hasScoreboardName()) {
|
2020-01-20 01:35:55 +01:00
|
|
|
if (disguiseBeingReplaced) {
|
|
|
|
new BukkitRunnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2020-03-30 09:22:33 +02:00
|
|
|
DisguiseUtilities.unregisterExtendedName(PlayerDisguise.this);
|
2020-01-20 01:35:55 +01:00
|
|
|
}
|
|
|
|
}.runTaskLater(LibsDisguises.getInstance(), 5);
|
|
|
|
} else {
|
2020-03-30 09:22:33 +02:00
|
|
|
DisguiseUtilities.unregisterExtendedName(this);
|
2020-01-20 01:35:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2016-12-01 02:34:34 +01:00
|
|
|
}
|