Added an option to remove name tags if prefix & suffix are empty (#108)

This commit is contained in:
AlexDev_ 2023-10-21 13:58:38 +02:00 committed by GitHub
parent 887359ddd0
commit f03b8f1819
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 3 deletions

View File

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

View File

@ -69,6 +69,11 @@ public class Settings {
+ "\nNametag formats must contain a %username%. Docs: https://william278.net/docs/velocitab/nametags")
private Map<String, String> 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")

View File

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