Add ability for player disguises to copy existing players display name

This commit is contained in:
libraryaddict 2020-09-26 12:00:44 +12:00
parent 0a3bda1a8e
commit a92c8fb55e
5 changed files with 56 additions and 11 deletions

View File

@ -258,6 +258,9 @@ public class DisguiseConfig {
@Getter
@Setter
private static long lastUpdateRequest;
@Getter
@Setter
private static boolean copyPlayerTeamInfo;
public static boolean isArmorstandsName() {
return getPlayerNameType() == PlayerNameType.ARMORSTANDS;
@ -678,6 +681,7 @@ public class DisguiseConfig {
setVelocitySent(config.getBoolean("SendVelocity"));
setViewDisguises(config.getBoolean("ViewSelfDisguises"));
setWarnScoreboardConflict(config.getBoolean("Scoreboard.WarnConflict"));
setCopyPlayerTeamInfo(config.getBoolean("Scoreboard.CopyPlayerTeamInfo"));
setWitherSkullPacketsEnabled(config.getBoolean("PacketsEnabled.WitherSkull"));
setWolfDyeable(config.getBoolean("DyeableWolf"));
setTablistRemoveDelay(config.getInt("TablistRemoveDelay"));

View File

@ -272,6 +272,12 @@ public class PlayerDisguise extends TargetedDisguise {
}
}
if (DisguiseConfig.isCopyPlayerTeamInfo() &&
(DisguiseConfig.getPlayerNameType() == DisguiseConfig.PlayerNameType.TEAMS ||
DisguiseConfig.getPlayerNameType() == DisguiseConfig.PlayerNameType.ARMORSTANDS)) {
name = DisguiseUtilities.getDisplayName(name);
}
if (name.equals(playerName)) {
return;
}
@ -337,13 +343,13 @@ public class PlayerDisguise extends TargetedDisguise {
try {
for (Player player : Bukkit.getOnlinePlayers()) {
if (!canSee(player))
if (!canSee(player)) {
continue;
}
ProtocolLibrary.getProtocolManager().sendServerPacket(player, addTab);
}
}
catch (InvocationTargetException e) {
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
@ -436,8 +442,9 @@ public class PlayerDisguise extends TargetedDisguise {
currentLookup = new LibsProfileLookup() {
@Override
public void onLookup(WrappedGameProfile gameProfile) {
if (currentLookup != this || gameProfile == null || gameProfile.getProperties().isEmpty())
if (currentLookup != this || gameProfile == null || gameProfile.getProperties().isEmpty()) {
return;
}
setSkin(gameProfile);
@ -485,8 +492,7 @@ public class PlayerDisguise extends TargetedDisguise {
string.contains(",\"name\":")) {
try {
return DisguiseUtilities.getGson().fromJson(string, WrappedGameProfile.class);
}
catch (Exception ex) {
} catch (Exception ex) {
throw new IllegalStateException(
"Tried to parse " + string + " to a GameProfile, but it has been formatted incorrectly!");
}
@ -505,14 +511,14 @@ public class PlayerDisguise extends TargetedDisguise {
try {
for (Player player : Bukkit.getOnlinePlayers()) {
if (!canSee(player))
if (!canSee(player)) {
continue;
}
ProtocolLibrary.getProtocolManager().sendServerPacket(player, deleteTab);
ProtocolLibrary.getProtocolManager().sendServerPacket(player, addTab);
}
}
catch (InvocationTargetException e) {
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
@ -604,8 +610,9 @@ public class PlayerDisguise extends TargetedDisguise {
currentLookup = new LibsProfileLookup() {
@Override
public void onLookup(WrappedGameProfile gameProfile) {
if (currentLookup != this || gameProfile == null || gameProfile.getProperties().isEmpty())
if (currentLookup != this || gameProfile == null || gameProfile.getProperties().isEmpty()) {
return;
}
setSkin(gameProfile);

View File

@ -235,6 +235,38 @@ public class DisguiseUtilities {
return team.getPrefix() + team.getColor() + player.getName() + team.getSuffix();
}
public static String getDisplayName(String playerName) {
if (StringUtils.isEmpty(playerName)) {
return playerName;
}
Team team = Bukkit.getScoreboardManager().getMainScoreboard().getEntryTeam(playerName);
if (team != null && (!StringUtils.isEmpty(team.getPrefix()) || !StringUtils.isEmpty(team.getSuffix()))) {
return team.getPrefix() + team.getColor() + playerName + team.getSuffix();
}
Player player = Bukkit.getPlayer(playerName);
if (player == null) {
return playerName;
}
team = Bukkit.getScoreboardManager().getMainScoreboard().getEntryTeam(player.getUniqueId().toString());
if (team == null || (StringUtils.isEmpty(team.getPrefix()) && StringUtils.isEmpty(team.getSuffix()))) {
String name = player.getDisplayName();
if (name.equals(playerName)) {
return player.getPlayerListName();
}
return name;
}
return team.getPrefix() + team.getColor() + player.getName() + team.getSuffix();
}
public static void saveViewPreferances() {
if (!DisguiseConfig.isSaveUserPreferences()) {
return;

View File

@ -158,7 +158,6 @@ public class PlayerSkinHandler implements Listener {
}
getCache().invalidate(player);
}
@EventHandler

View File

@ -109,6 +109,9 @@ Scoreboard:
# Should the scoreboard warn you if it detects a potential conflict?
# If self disguises are disabled, or the scoreboard is using IGNORE_SCOREBOARD then this does nothing.
WarnConflict: true
# When disguising as a player, should the prefix/suffix of the player disguise name copy the team info?
# Only takes effect if using PlayerNames TEAMS or ARMORSTANDS
CopyPlayerTeamInfo: true
# Shall I notify those with the correct permission when there's a LibsDisguises update?
# Disabling this will also disable notifications when the plugin updated