Add ability to customize name above head

This commit is contained in:
libraryaddict 2020-10-09 10:18:52 +13:00
parent 1ed3a149ea
commit 1795e03e31
4 changed files with 33 additions and 9 deletions

View File

@ -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"));

View File

@ -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<String> getAllowedDisguises(DisguisePermissions permissions) {

View File

@ -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);
}
}

View File

@ -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!