From b239ba1920460a727303a1628648f2fbc0006acb Mon Sep 17 00:00:00 2001 From: ItsNature Date: Tue, 11 Aug 2026 05:33:13 +0200 Subject: [PATCH] Add `NametagVisibilityOverride` to `Nametag` --- .../apollo/module/nametag/Nametag.java | 9 +++ .../nametag/NametagVisibilityOverride.java | 59 +++++++++++++++++++ .../module/nametag/NametagModuleImpl.java | 9 +++ docs/developers/lightweight/protobuf.mdx | 6 +- docs/developers/modules/nametag.mdx | 12 ++++ .../example/api/module/NametagApiExample.java | 2 + .../json/module/NametagJsonExample.java | 1 + .../proto/module/NametagProtoExample.java | 2 + gradle/libs.versions.toml | 2 +- 9 files changed, 98 insertions(+), 4 deletions(-) create mode 100644 api/src/main/java/com/lunarclient/apollo/module/nametag/NametagVisibilityOverride.java diff --git a/api/src/main/java/com/lunarclient/apollo/module/nametag/Nametag.java b/api/src/main/java/com/lunarclient/apollo/module/nametag/Nametag.java index 5089ffd8..a45544b3 100644 --- a/api/src/main/java/com/lunarclient/apollo/module/nametag/Nametag.java +++ b/api/src/main/java/com/lunarclient/apollo/module/nametag/Nametag.java @@ -45,4 +45,13 @@ public final class Nametag { */ List lines; + /** + * Returns the {@link NametagVisibilityOverride} override for this nametag. + * + * @return the visibility override + * @since 1.2.9 + */ + @Builder.Default + NametagVisibilityOverride visibilityOverride = NametagVisibilityOverride.NONE; + } diff --git a/api/src/main/java/com/lunarclient/apollo/module/nametag/NametagVisibilityOverride.java b/api/src/main/java/com/lunarclient/apollo/module/nametag/NametagVisibilityOverride.java new file mode 100644 index 00000000..4c0b5ff2 --- /dev/null +++ b/api/src/main/java/com/lunarclient/apollo/module/nametag/NametagVisibilityOverride.java @@ -0,0 +1,59 @@ +/* + * This file is part of Apollo, licensed under the MIT License. + * + * Copyright (c) 2026 Moonsworth + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.lunarclient.apollo.module.nametag; + +/** + * Represents an override of the vanilla team-based nametag visibility + * outcome for the target player, from the viewpoint of the receiving player. + * + * @since 1.2.9 + */ +public enum NametagVisibilityOverride { + + /** + * The vanilla team-based nametag visibility applies. + * + * @since 1.2.9 + */ + NONE, + + /** + * Shows the nametag, as if the target's team nametag visibility + * were {@code always}, still respecting invisibility. + * + * @since 1.2.9 + */ + SHOWN, + + /** + * Hides the nametag, as if the target's team nametag visibility + * were {@code never}. + * + *

Applies even when the target is not on any team.

+ * + * @since 1.2.9 + */ + HIDDEN + +} diff --git a/common/src/main/java/com/lunarclient/apollo/module/nametag/NametagModuleImpl.java b/common/src/main/java/com/lunarclient/apollo/module/nametag/NametagModuleImpl.java index 5254595d..e055f0a0 100644 --- a/common/src/main/java/com/lunarclient/apollo/module/nametag/NametagModuleImpl.java +++ b/common/src/main/java/com/lunarclient/apollo/module/nametag/NametagModuleImpl.java @@ -50,6 +50,11 @@ public void overrideNametag(@NonNull Recipients recipients, @NonNull UUID player builder.addAdventureJsonLines(ApolloComponent.toJson(line)); } + NametagVisibilityOverride visibility = nametag.getVisibilityOverride(); + if (visibility != null && visibility != NametagVisibilityOverride.NONE) { + builder.setVisibilityOverride(this.toProtobuf(visibility)); + } + ApolloManager.getNetworkManager().sendPacket(recipients, builder.build()); } @@ -68,4 +73,8 @@ public void resetNametags(@NonNull Recipients recipients) { ApolloManager.getNetworkManager().sendPacket(recipients, message); } + private com.lunarclient.apollo.nametag.v1.NametagVisibilityOverride toProtobuf(NametagVisibilityOverride visibility) { + return com.lunarclient.apollo.nametag.v1.NametagVisibilityOverride.forNumber(visibility.ordinal() + 1); + } + } diff --git a/docs/developers/lightweight/protobuf.mdx b/docs/developers/lightweight/protobuf.mdx index 2759440a..0bb373d6 100644 --- a/docs/developers/lightweight/protobuf.mdx +++ b/docs/developers/lightweight/protobuf.mdx @@ -26,7 +26,7 @@ Available fields for each message, including their types, are available on the B com.lunarclient apollo-protos - 0.2.1 + 0.2.4 ``` @@ -41,7 +41,7 @@ Available fields for each message, including their types, are available on the B } dependencies { - api 'com.lunarclient:apollo-protos:0.2.1' + api 'com.lunarclient:apollo-protos:0.2.4' } ``` @@ -55,7 +55,7 @@ Available fields for each message, including their types, are available on the B } dependencies { - api("com.lunarclient:apollo-protos:0.2.1") + api("com.lunarclient:apollo-protos:0.2.4") } ``` diff --git a/docs/developers/modules/nametag.mdx b/docs/developers/modules/nametag.mdx index 081f8acd..0c8ecd3d 100644 --- a/docs/developers/modules/nametag.mdx +++ b/docs/developers/modules/nametag.mdx @@ -50,6 +50,7 @@ public void overrideNametagExample(Player target) { .color(NamedTextColor.RED) .build() )) + .visibilityOverride(NametagVisibilityOverride.NONE) .build() ); } @@ -100,6 +101,15 @@ public void resetNametagsExample(Player viewer) { )) ``` +`.visibilityOverride(NametagVisibilityOverride)` overrides the vanilla team-based nametag visibility outcome for the target player, from the viewpoint of the receiving player. +- `SHOWN` displays the nametag as if the target's team nametag visibility were `always` (still respecting invisibility) +- `HIDDEN` hides the nametag as if it were `never`, even when the target is not on any team. +- `NONE` keeps the vanilla behavior. + +```java +.visibilityOverride(NametagVisibilityOverride.NONE) +``` + @@ -129,6 +139,7 @@ public void overrideNametagExample(Player target) { OverrideNametagMessage message = OverrideNametagMessage.newBuilder() .setPlayerUuid(ProtobufUtil.createUuidProto(target.getUniqueId())) .addAllAdventureJsonLines(lines) + .setVisibilityOverride(NametagVisibilityOverride.NAMETAG_VISIBILITY_OVERRIDE_NONE) .build(); ProtobufPacketUtil.broadcastPacket(message); @@ -186,6 +197,7 @@ public void overrideNametagExample(Player target) { message.addProperty("@type", "type.googleapis.com/lunarclient.apollo.nametag.v1.OverrideNametagMessage"); message.add("player_uuid", JsonUtil.createUuidObject(target.getUniqueId())); message.add("adventure_json_lines", lines); + message.addProperty("visibility_override", "NAMETAG_VISIBILITY_OVERRIDE_NONE"); JsonPacketUtil.broadcastPacket(message); } diff --git a/example/bukkit/api/src/main/java/com/lunarclient/apollo/example/api/module/NametagApiExample.java b/example/bukkit/api/src/main/java/com/lunarclient/apollo/example/api/module/NametagApiExample.java index 132d5d86..a6af0c60 100644 --- a/example/bukkit/api/src/main/java/com/lunarclient/apollo/example/api/module/NametagApiExample.java +++ b/example/bukkit/api/src/main/java/com/lunarclient/apollo/example/api/module/NametagApiExample.java @@ -28,6 +28,7 @@ import com.lunarclient.apollo.example.module.impl.NametagExample; import com.lunarclient.apollo.module.nametag.Nametag; import com.lunarclient.apollo.module.nametag.NametagModule; +import com.lunarclient.apollo.module.nametag.NametagVisibilityOverride; import com.lunarclient.apollo.player.ApolloPlayer; import com.lunarclient.apollo.recipients.Recipients; import java.util.Optional; @@ -54,6 +55,7 @@ public void overrideNametagExample(Player target) { .color(NamedTextColor.RED) .build() )) + .visibilityOverride(NametagVisibilityOverride.NONE) .build() ); } diff --git a/example/bukkit/json/src/main/java/com/lunarclient/apollo/example/json/module/NametagJsonExample.java b/example/bukkit/json/src/main/java/com/lunarclient/apollo/example/json/module/NametagJsonExample.java index 0b2f1de7..460b4cd5 100644 --- a/example/bukkit/json/src/main/java/com/lunarclient/apollo/example/json/module/NametagJsonExample.java +++ b/example/bukkit/json/src/main/java/com/lunarclient/apollo/example/json/module/NametagJsonExample.java @@ -58,6 +58,7 @@ public void overrideNametagExample(Player target) { message.addProperty("@type", "type.googleapis.com/lunarclient.apollo.nametag.v1.OverrideNametagMessage"); message.add("player_uuid", JsonUtil.createUuidObject(target.getUniqueId())); message.add("adventure_json_lines", lines); + message.addProperty("visibility_override", "NAMETAG_VISIBILITY_OVERRIDE_NONE"); JsonPacketUtil.broadcastPacket(message); } diff --git a/example/bukkit/proto/src/main/java/com/lunarclient/apollo/example/proto/module/NametagProtoExample.java b/example/bukkit/proto/src/main/java/com/lunarclient/apollo/example/proto/module/NametagProtoExample.java index 07e5dbeb..8c59b086 100644 --- a/example/bukkit/proto/src/main/java/com/lunarclient/apollo/example/proto/module/NametagProtoExample.java +++ b/example/bukkit/proto/src/main/java/com/lunarclient/apollo/example/proto/module/NametagProtoExample.java @@ -28,6 +28,7 @@ import com.lunarclient.apollo.example.proto.util.AdventureUtil; import com.lunarclient.apollo.example.proto.util.ProtobufPacketUtil; import com.lunarclient.apollo.example.proto.util.ProtobufUtil; +import com.lunarclient.apollo.nametag.v1.NametagVisibilityOverride; import com.lunarclient.apollo.nametag.v1.OverrideNametagMessage; import com.lunarclient.apollo.nametag.v1.ResetNametagMessage; import com.lunarclient.apollo.nametag.v1.ResetNametagsMessage; @@ -59,6 +60,7 @@ public void overrideNametagExample(Player target) { OverrideNametagMessage message = OverrideNametagMessage.newBuilder() .setPlayerUuid(ProtobufUtil.createUuidProto(target.getUniqueId())) .addAllAdventureJsonLines(lines) + .setVisibilityOverride(NametagVisibilityOverride.NAMETAG_VISIBILITY_OVERRIDE_NONE) .build(); ProtobufPacketUtil.broadcastPacket(message); diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 8f52700a..5099e64b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -11,7 +11,7 @@ geantyref = "1.3.11" idea = "1.1.7" jetbrains = "24.0.1" lombok = "1.18.38" -protobuf = "0.2.1" +protobuf = "0.2.4" gson = "2.10.1" shadow = "9.4.1" spotless = "8.4.0"