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

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