Skip to content

Commit 60a22d0

Browse files
authored
Add NametagVisibilityOverride to Nametag (#305)
# Conflicts: # gradle/libs.versions.toml
1 parent d653236 commit 60a22d0

9 files changed

Lines changed: 98 additions & 4 deletions

File tree

api/src/main/java/com/lunarclient/apollo/module/nametag/Nametag.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,13 @@ public final class Nametag {
4545
*/
4646
List<Component> lines;
4747

48+
/**
49+
* Returns the {@link NametagVisibilityOverride} override for this nametag.
50+
*
51+
* @return the visibility override
52+
* @since 1.2.9
53+
*/
54+
@Builder.Default
55+
NametagVisibilityOverride visibilityOverride = NametagVisibilityOverride.NONE;
56+
4857
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* This file is part of Apollo, licensed under the MIT License.
3+
*
4+
* Copyright (c) 2026 Moonsworth
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package com.lunarclient.apollo.module.nametag;
25+
26+
/**
27+
* Represents an override of the vanilla team-based nametag visibility
28+
* outcome for the target player, from the viewpoint of the receiving player.
29+
*
30+
* @since 1.2.9
31+
*/
32+
public enum NametagVisibilityOverride {
33+
34+
/**
35+
* The vanilla team-based nametag visibility applies.
36+
*
37+
* @since 1.2.9
38+
*/
39+
NONE,
40+
41+
/**
42+
* Shows the nametag, as if the target's team nametag visibility
43+
* were {@code always}, still respecting invisibility.
44+
*
45+
* @since 1.2.9
46+
*/
47+
SHOWN,
48+
49+
/**
50+
* Hides the nametag, as if the target's team nametag visibility
51+
* were {@code never}.
52+
*
53+
* <p>Applies even when the target is not on any team.</p>
54+
*
55+
* @since 1.2.9
56+
*/
57+
HIDDEN
58+
59+
}

common/src/main/java/com/lunarclient/apollo/module/nametag/NametagModuleImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ public void overrideNametag(@NonNull Recipients recipients, @NonNull UUID player
5050
builder.addAdventureJsonLines(ApolloComponent.toJson(line));
5151
}
5252

53+
NametagVisibilityOverride visibility = nametag.getVisibilityOverride();
54+
if (visibility != null && visibility != NametagVisibilityOverride.NONE) {
55+
builder.setVisibilityOverride(this.toProtobuf(visibility));
56+
}
57+
5358
ApolloManager.getNetworkManager().sendPacket(recipients, builder.build());
5459
}
5560

@@ -68,4 +73,8 @@ public void resetNametags(@NonNull Recipients recipients) {
6873
ApolloManager.getNetworkManager().sendPacket(recipients, message);
6974
}
7075

76+
private com.lunarclient.apollo.nametag.v1.NametagVisibilityOverride toProtobuf(NametagVisibilityOverride visibility) {
77+
return com.lunarclient.apollo.nametag.v1.NametagVisibilityOverride.forNumber(visibility.ordinal() + 1);
78+
}
79+
7180
}

docs/developers/lightweight/protobuf.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Available fields for each message, including their types, are available on the B
2626
<dependency>
2727
<groupId>com.lunarclient</groupId>
2828
<artifactId>apollo-protos</artifactId>
29-
<version>0.2.1</version>
29+
<version>0.2.4</version>
3030
</dependency>
3131
</dependencies>
3232
```
@@ -41,7 +41,7 @@ Available fields for each message, including their types, are available on the B
4141
}
4242
4343
dependencies {
44-
api 'com.lunarclient:apollo-protos:0.2.1'
44+
api 'com.lunarclient:apollo-protos:0.2.4'
4545
}
4646
```
4747
</Tab>
@@ -55,7 +55,7 @@ Available fields for each message, including their types, are available on the B
5555
}
5656

5757
dependencies {
58-
api("com.lunarclient:apollo-protos:0.2.1")
58+
api("com.lunarclient:apollo-protos:0.2.4")
5959
}
6060
```
6161
</Tab>

docs/developers/modules/nametag.mdx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public void overrideNametagExample(Player target) {
5050
.color(NamedTextColor.RED)
5151
.build()
5252
))
53+
.visibilityOverride(NametagVisibilityOverride.NONE)
5354
.build()
5455
);
5556
}
@@ -100,6 +101,15 @@ public void resetNametagsExample(Player viewer) {
100101
))
101102
```
102103

104+
`.visibilityOverride(NametagVisibilityOverride)` overrides the vanilla team-based nametag visibility outcome for the target player, from the viewpoint of the receiving player.
105+
- `SHOWN` displays the nametag as if the target's team nametag visibility were `always` (still respecting invisibility)
106+
- `HIDDEN` hides the nametag as if it were `never`, even when the target is not on any team.
107+
- `NONE` keeps the vanilla behavior.
108+
109+
```java
110+
.visibilityOverride(NametagVisibilityOverride.NONE)
111+
```
112+
103113
</Tab>
104114

105115
<Tab>
@@ -129,6 +139,7 @@ public void overrideNametagExample(Player target) {
129139
OverrideNametagMessage message = OverrideNametagMessage.newBuilder()
130140
.setPlayerUuid(ProtobufUtil.createUuidProto(target.getUniqueId()))
131141
.addAllAdventureJsonLines(lines)
142+
.setVisibilityOverride(NametagVisibilityOverride.NAMETAG_VISIBILITY_OVERRIDE_NONE)
132143
.build();
133144

134145
ProtobufPacketUtil.broadcastPacket(message);
@@ -186,6 +197,7 @@ public void overrideNametagExample(Player target) {
186197
message.addProperty("@type", "type.googleapis.com/lunarclient.apollo.nametag.v1.OverrideNametagMessage");
187198
message.add("player_uuid", JsonUtil.createUuidObject(target.getUniqueId()));
188199
message.add("adventure_json_lines", lines);
200+
message.addProperty("visibility_override", "NAMETAG_VISIBILITY_OVERRIDE_NONE");
189201

190202
JsonPacketUtil.broadcastPacket(message);
191203
}

example/bukkit/api/src/main/java/com/lunarclient/apollo/example/api/module/NametagApiExample.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.lunarclient.apollo.example.module.impl.NametagExample;
2929
import com.lunarclient.apollo.module.nametag.Nametag;
3030
import com.lunarclient.apollo.module.nametag.NametagModule;
31+
import com.lunarclient.apollo.module.nametag.NametagVisibilityOverride;
3132
import com.lunarclient.apollo.player.ApolloPlayer;
3233
import com.lunarclient.apollo.recipients.Recipients;
3334
import java.util.Optional;
@@ -54,6 +55,7 @@ public void overrideNametagExample(Player target) {
5455
.color(NamedTextColor.RED)
5556
.build()
5657
))
58+
.visibilityOverride(NametagVisibilityOverride.NONE)
5759
.build()
5860
);
5961
}

example/bukkit/json/src/main/java/com/lunarclient/apollo/example/json/module/NametagJsonExample.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public void overrideNametagExample(Player target) {
5858
message.addProperty("@type", "type.googleapis.com/lunarclient.apollo.nametag.v1.OverrideNametagMessage");
5959
message.add("player_uuid", JsonUtil.createUuidObject(target.getUniqueId()));
6060
message.add("adventure_json_lines", lines);
61+
message.addProperty("visibility_override", "NAMETAG_VISIBILITY_OVERRIDE_NONE");
6162

6263
JsonPacketUtil.broadcastPacket(message);
6364
}

example/bukkit/proto/src/main/java/com/lunarclient/apollo/example/proto/module/NametagProtoExample.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.lunarclient.apollo.example.proto.util.AdventureUtil;
2929
import com.lunarclient.apollo.example.proto.util.ProtobufPacketUtil;
3030
import com.lunarclient.apollo.example.proto.util.ProtobufUtil;
31+
import com.lunarclient.apollo.nametag.v1.NametagVisibilityOverride;
3132
import com.lunarclient.apollo.nametag.v1.OverrideNametagMessage;
3233
import com.lunarclient.apollo.nametag.v1.ResetNametagMessage;
3334
import com.lunarclient.apollo.nametag.v1.ResetNametagsMessage;
@@ -59,6 +60,7 @@ public void overrideNametagExample(Player target) {
5960
OverrideNametagMessage message = OverrideNametagMessage.newBuilder()
6061
.setPlayerUuid(ProtobufUtil.createUuidProto(target.getUniqueId()))
6162
.addAllAdventureJsonLines(lines)
63+
.setVisibilityOverride(NametagVisibilityOverride.NAMETAG_VISIBILITY_OVERRIDE_NONE)
6264
.build();
6365

6466
ProtobufPacketUtil.broadcastPacket(message);

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ geantyref = "1.3.11"
1111
idea = "1.1.7"
1212
jetbrains = "24.0.1"
1313
lombok = "1.18.38"
14-
protobuf = "0.2.2"
14+
protobuf = "0.2.4"
1515
gson = "2.10.1"
1616
shadow = "9.4.1"
1717
spotless = "8.4.0"

0 commit comments

Comments
 (0)