From 1795e03e31271f7670f9c9266b5cbffb5a0a0db1 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Fri, 9 Oct 2020 10:18:52 +1300 Subject: [PATCH] Add ability to customize name above head --- .../disguise/DisguiseConfig.java | 4 ++++ .../commands/DisguiseBaseCommand.java | 9 +++++++- .../DisguiseEntityInteraction.java | 23 ++++++++++++------- src/main/resources/config.yml | 6 +++++ 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java b/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java index 100982ec..1ab4f6d3 100644 --- a/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java +++ b/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java @@ -261,6 +261,9 @@ public class DisguiseConfig { @Getter @Setter private static boolean copyPlayerTeamInfo; + @Getter + @Setter + private static String nameAboveDisguise; public static boolean isArmorstandsName() { return getPlayerNameType() == PlayerNameType.ARMORSTANDS; @@ -663,6 +666,7 @@ public class DisguiseConfig { setMovementPacketsEnabled(config.getBoolean("PacketsEnabled.Movement")); setNameAboveHeadAlwaysVisible(config.getBoolean("NameAboveHeadAlwaysVisible")); setNameOfPlayerShownAboveDisguise(config.getBoolean("ShowNamesAboveDisguises")); + setNameAboveDisguise(config.getString("NameAboveDisguise")); setPlayerDisguisesTablistExpires(config.getInt("PlayerDisguisesTablistExpiry")); setPlayerHideArmor(config.getBoolean("PlayerHideArmor")); setRetaliationCombat(config.getBoolean("RetaliationCombat")); diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java b/src/main/java/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java index 79d0df90..27a48b3f 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java @@ -1,5 +1,6 @@ package me.libraryaddict.disguise.commands; +import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.commands.disguise.DisguiseCommand; import me.libraryaddict.disguise.commands.disguise.DisguiseEntityCommand; import me.libraryaddict.disguise.commands.disguise.DisguisePlayerCommand; @@ -209,7 +210,13 @@ public abstract class DisguiseBaseCommand implements CommandExecutor { } protected String getDisplayName(CommandSender player) { - return DisguiseUtilities.getDisplayName(player); + String name = DisguiseConfig.getNameAboveDisguise().replace("%simple%", player.getName()); + + if (name.contains("%complex%")) { + name = name.replace("%complex%", DisguiseUtilities.getDisplayName(player)); + } + + return ChatColor.translateAlternateColorCodes('&', name); } protected ArrayList getAllowedDisguises(DisguisePermissions permissions) { diff --git a/src/main/java/me/libraryaddict/disguise/commands/interactions/DisguiseEntityInteraction.java b/src/main/java/me/libraryaddict/disguise/commands/interactions/DisguiseEntityInteraction.java index 1ddf45a6..8ceca7a0 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/interactions/DisguiseEntityInteraction.java +++ b/src/main/java/me/libraryaddict/disguise/commands/interactions/DisguiseEntityInteraction.java @@ -11,6 +11,8 @@ import me.libraryaddict.disguise.utilities.LibsEntityInteract; import me.libraryaddict.disguise.utilities.parser.DisguiseParseException; import me.libraryaddict.disguise.utilities.parser.DisguiseParser; import me.libraryaddict.disguise.utilities.translations.LibsMsg; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; @@ -38,15 +40,13 @@ public class DisguiseEntityInteraction implements LibsEntityInteract { try { disguise = DisguiseParser.parseDisguise(p, entity, "disguiseentity", disguiseArgs, DisguiseParser.getPermissions(p, "disguiseentity")); - } - catch (DisguiseParseException e) { + } catch (DisguiseParseException e) { if (e.getMessage() != null) { DisguiseUtilities.sendMessage(p, e.getMessage()); } return; - } - catch (Exception e) { + } catch (Exception e) { e.printStackTrace(); return; } @@ -58,10 +58,7 @@ public class DisguiseEntityInteraction implements LibsEntityInteract { if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise() && !entity.hasPermission("libsdisguises.hidename")) { if (disguise.getWatcher() instanceof LivingWatcher) { - Team team = ((Player) entity).getScoreboard().getEntryTeam(entity.getName()); - - disguise.getWatcher().setCustomName((team == null ? "" : team.getPrefix()) + entity.getName() + - (team == null ? "" : team.getSuffix())); + disguise.getWatcher().setCustomName(getDisplayName(entity)); if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) { disguise.getWatcher().setCustomNameVisible(true); @@ -105,4 +102,14 @@ public class DisguiseEntityInteraction implements LibsEntityInteract { } } } + + protected String getDisplayName(CommandSender player) { + String name = DisguiseConfig.getNameAboveDisguise().replace("%simple%", player.getName()); + + if (name.contains("%complex%")) { + name = name.replace("%complex%", DisguiseUtilities.getDisplayName(player)); + } + + return ChatColor.translateAlternateColorCodes('&', name); + } } \ No newline at end of file diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 4f6dd2f2..89c62f97 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -206,6 +206,12 @@ ShowNamesAboveDisguises: false # If this is true, then the name shown above the head appears regardless of if you are looking at the disguise directly or not. NameAboveHeadAlwaysVisible: true +# What should the name be shown as? +# Two placeholders can be used. +# %simple% = The very basic name, 'libraryaddict' +# %complex% = Name will be grabbed from scoreboard or display name if scoreboard fails. +NameAboveDisguise: %complex% + # This modifies the bounding box, This is stuff like can a arrow hit them. # If you turn this to true, arrows will act like they hit the disguise in the right place! # Clients will not see any difference in the hitboxes they are attacking, this is a server-sided calculation!