Add isDynamicName for player disguises with mobs custom names that change

This commit is contained in:
libraryaddict 2020-02-05 14:26:55 +13:00
parent a92916f112
commit fd2926241c
No known key found for this signature in database
GPG Key ID: 052E4FBCD257AEA4
3 changed files with 146 additions and 125 deletions

View File

@ -23,6 +23,7 @@ import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import me.libraryaddict.disguise.utilities.translations.LibsMsg; import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.ComponentBuilder;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
@ -174,12 +175,26 @@ public abstract class Disguise {
@Override @Override
public void run() { public void run() {
if (DisguiseConfig.isNotifyPlayerDisguised() && getEntity() instanceof Player && if (++actionBarTicks % 15 == 0) {
++actionBarTicks % 15 == 0 && DisguiseAPI.getDisguise(getEntity()) == Disguise.this) {
actionBarTicks = 0; actionBarTicks = 0;
((Player) getEntity()).spigot().sendMessage(ChatMessageType.ACTION_BAR, if (DisguiseConfig.isNotifyPlayerDisguised() && getEntity() instanceof Player &&
new ComponentBuilder(LibsMsg.ACTION_BAR_MESSAGE.get(getType().toReadable())).create()); DisguiseAPI.getDisguise(getEntity()) == Disguise.this) {
((Player) getEntity()).spigot().sendMessage(ChatMessageType.ACTION_BAR,
new ComponentBuilder(LibsMsg.ACTION_BAR_MESSAGE.get(getType().toReadable())).create());
}
if (Disguise.this instanceof PlayerDisguise && ((PlayerDisguise) Disguise.this).isDynamicName()) {
String name = getEntity().getCustomName();
if (name == null) {
name = "";
}
if (!((PlayerDisguise) Disguise.this).getName().equals(name)) {
((PlayerDisguise) Disguise.this).setName(name);
}
}
} }
// If entity is no longer valid. Remove it. // If entity is no longer valid. Remove it.

View File

@ -8,6 +8,8 @@ import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction;
import com.comphenix.protocol.wrappers.PlayerInfoData; import com.comphenix.protocol.wrappers.PlayerInfoData;
import com.comphenix.protocol.wrappers.WrappedChatComponent; import com.comphenix.protocol.wrappers.WrappedChatComponent;
import com.comphenix.protocol.wrappers.WrappedGameProfile; import com.comphenix.protocol.wrappers.WrappedGameProfile;
import lombok.Getter;
import lombok.Setter;
import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher;
@ -35,6 +37,9 @@ public class PlayerDisguise extends TargetedDisguise {
private String skinToUse; private String skinToUse;
private boolean nameVisible = true; private boolean nameVisible = true;
private UUID uuid = UUID.randomUUID(); private UUID uuid = UUID.randomUUID();
@Getter
@Setter
private boolean dynamicName;
private PlayerDisguise() { private PlayerDisguise() {
super(DisguiseType.PLAYER); super(DisguiseType.PLAYER);
@ -181,79 +186,12 @@ public class PlayerDisguise extends TargetedDisguise {
return gameProfile; return gameProfile;
} }
public String getName() {
return playerName;
}
public String getSkin() {
return skinToUse;
}
@Override
public PlayerWatcher getWatcher() {
return (PlayerWatcher) super.getWatcher();
}
public boolean isDisplayedInTab() {
return getWatcher().isDisplayedInTab();
}
@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);
}
public void setDisplayedInTab(boolean showPlayerInTab) {
getWatcher().setDisplayedInTab(showPlayerInTab);
}
@Override
public PlayerDisguise setEntity(Entity entity) {
return (PlayerDisguise) super.setEntity(entity);
}
public void setGameProfile(WrappedGameProfile gameProfile) { public void setGameProfile(WrappedGameProfile gameProfile) {
this.gameProfile = ReflectionManager.getGameProfileWithThisSkin(uuid, gameProfile.getName(), gameProfile); this.gameProfile = ReflectionManager.getGameProfileWithThisSkin(uuid, gameProfile.getName(), gameProfile);
} }
@Override public String getName() {
public PlayerDisguise setHearSelfDisguise(boolean hearSelfDisguise) { return playerName;
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);
} }
public void setName(String name) { public void setName(String name) {
@ -295,53 +233,8 @@ public class PlayerDisguise extends TargetedDisguise {
} }
} }
@Override public String getSkin() {
public PlayerDisguise setReplaceSounds(boolean areSoundsReplaced) { return skinToUse;
return (PlayerDisguise) super.setReplaceSounds(areSoundsReplaced);
}
@Override
public boolean startDisguise() {
if (!isDisguiseInUse()) {
if (skinToUse != null && gameProfile == null) {
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);
}
}
if (getName().equals("<Inherit>") && getEntity() != null) {
String name = getEntity().getCustomName();
if (name == null || name.isEmpty()) {
name = getEntity().getType().name();
}
setName(name);
}
}
boolean result = super.startDisguise();
if (result && hasExtendedName()) {
DisguiseUtilities.registerExtendedName(getName());
}
return result;
} }
public PlayerDisguise setSkin(String newSkin) { public PlayerDisguise setSkin(String newSkin) {
@ -423,6 +316,123 @@ public class PlayerDisguise extends TargetedDisguise {
return this; return this;
} }
@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() {
if (!isDisguiseInUse()) {
if (skinToUse != null && gameProfile == null) {
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);
}
}
if (getName().equals("<Inherit>") && getEntity() != null) {
String name = getEntity().getCustomName();
if (name == null || name.isEmpty()) {
name = getEntity().getType().name();
}
setName(name);
}
}
boolean result = super.startDisguise();
if (result && hasExtendedName()) {
DisguiseUtilities.registerExtendedName(getName());
}
return result;
}
@Override @Override
public PlayerDisguise setVelocitySent(boolean sendVelocity) { public PlayerDisguise setVelocitySent(boolean sendVelocity) {
return (PlayerDisguise) super.setVelocitySent(sendVelocity); return (PlayerDisguise) super.setVelocitySent(sendVelocity);
@ -433,11 +443,6 @@ public class PlayerDisguise extends TargetedDisguise {
return (PlayerDisguise) super.setViewSelfDisguise(viewSelfDisguise); return (PlayerDisguise) super.setViewSelfDisguise(viewSelfDisguise);
} }
@Override
public PlayerDisguise setWatcher(FlagWatcher newWatcher) {
return (PlayerDisguise) super.setWatcher(newWatcher);
}
@Override @Override
public PlayerDisguise silentlyAddPlayer(String playername) { public PlayerDisguise silentlyAddPlayer(String playername) {
return (PlayerDisguise) super.silentlyAddPlayer(playername); return (PlayerDisguise) super.silentlyAddPlayer(playername);

View File

@ -135,6 +135,7 @@ public class ParamInfoManager {
if (watcherClass == PlayerWatcher.class) { if (watcherClass == PlayerWatcher.class) {
try { try {
methods.add(PlayerDisguise.class.getMethod("setNameVisible", boolean.class)); methods.add(PlayerDisguise.class.getMethod("setNameVisible", boolean.class));
methods.add(PlayerDisguise.class.getMethod("setDynamicName", boolean.class));
} }
catch (NoSuchMethodException e) { catch (NoSuchMethodException e) {
e.printStackTrace(); e.printStackTrace();