From f03b8f18191d36ee1d5a5a6f03c28972b03efe2c Mon Sep 17 00:00:00 2001 From: AlexDev_ <56083016+alexdev03@users.noreply.github.com> Date: Sat, 21 Oct 2023 13:58:38 +0200 Subject: [PATCH] Added an option to remove name tags if prefix & suffix are empty (#108) --- docs/Nametags.md | 3 +++ .../java/net/william278/velocitab/config/Settings.java | 5 +++++ .../william278/velocitab/packet/UpdateTeamsPacket.java | 8 +++++--- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/docs/Nametags.md b/docs/Nametags.md index 8844dab..1f94c2c 100644 --- a/docs/Nametags.md +++ b/docs/Nametags.md @@ -26,6 +26,9 @@ send_scoreboard_packets: true Only players on servers which are part of groups that specify nametag formats will have their nametag formatted. To disable nametag formatting, remove all groups from the `nametags` section of the config file (leaving it empty). +## Removing name tags +In order to remove nametags, you must remove your nametag format from the config file. If you want to remove nametags for all groups, you can set the `nametags` section to empty `nametags: {}`. After that be sure to set `remove_nametags` to `true` to make sure the nametags are removed from players. + ## Formatting limitations Nametags must adhere to the following restrictions: * A %username% placeholder must be present. This is used for delimiting the scoreboard prefix, name, and suffix to facilitate formatting. diff --git a/src/main/java/net/william278/velocitab/config/Settings.java b/src/main/java/net/william278/velocitab/config/Settings.java index 96da5af..981fc8f 100644 --- a/src/main/java/net/william278/velocitab/config/Settings.java +++ b/src/main/java/net/william278/velocitab/config/Settings.java @@ -69,6 +69,11 @@ public class Settings { + "\nNametag formats must contain a %username%. Docs: https://william278.net/docs/velocitab/nametags") private Map nametags = Map.of("default", "&f%prefix%%username%&f%suffix%"); + @Getter + @YamlKey("remove_nametags") + @YamlComment("Whether to remove nametag from players' heads if the nametag associated with their server group is empty.") + private boolean removeNametags = false; + @Getter @YamlComment("Which text formatter to use (MINEDOWN, MINIMESSAGE, or LEGACY)") @YamlKey("formatting_type") diff --git a/src/main/java/net/william278/velocitab/packet/UpdateTeamsPacket.java b/src/main/java/net/william278/velocitab/packet/UpdateTeamsPacket.java index fe42990..34e6d41 100644 --- a/src/main/java/net/william278/velocitab/packet/UpdateTeamsPacket.java +++ b/src/main/java/net/william278/velocitab/packet/UpdateTeamsPacket.java @@ -69,7 +69,7 @@ public class UpdateTeamsPacket implements MinecraftPacket { .mode(UpdateMode.CREATE_TEAM) .displayName(displayName) .friendlyFlags(List.of(FriendlyFlag.CAN_HURT_FRIENDLY)) - .nameTagVisibility(isNametagPresent(prefix, suffix) ? NameTagVisibility.ALWAYS : NameTagVisibility.NEVER) + .nameTagVisibility(isNametagPresent(prefix, suffix, plugin) ? NameTagVisibility.ALWAYS : NameTagVisibility.NEVER) .collisionRule(CollisionRule.ALWAYS) .color(getLastColor(prefix)) .prefix(prefix == null ? "" : prefix) @@ -77,7 +77,9 @@ public class UpdateTeamsPacket implements MinecraftPacket { .entities(Arrays.asList(teamMembers)); } - private static boolean isNametagPresent(@Nullable String prefix, @Nullable String suffix) { + private static boolean isNametagPresent(@Nullable String prefix, @Nullable String suffix, @NotNull Velocitab plugin) { + if (!plugin.getSettings().isRemoveNametags()) return true; + return prefix != null && !prefix.isEmpty() || suffix != null && !suffix.isEmpty(); } @@ -89,7 +91,7 @@ public class UpdateTeamsPacket implements MinecraftPacket { .mode(UpdateMode.UPDATE_INFO) .displayName(teamName) .friendlyFlags(List.of(FriendlyFlag.CAN_HURT_FRIENDLY)) - .nameTagVisibility(isNametagPresent(prefix, suffix) ? NameTagVisibility.ALWAYS : NameTagVisibility.NEVER) + .nameTagVisibility(isNametagPresent(prefix, suffix, plugin) ? NameTagVisibility.ALWAYS : NameTagVisibility.NEVER) .collisionRule(CollisionRule.ALWAYS) .color(getLastColor(prefix)) .prefix(prefix == null ? "" : prefix)