Skip to content

Commit c29605d

Browse files
committed
add server badges
1 parent 0f20281 commit c29605d

File tree

6 files changed

+321
-10
lines changed

6 files changed

+321
-10
lines changed

core/src/main/java/net/labymod/serverapi/core/AbstractLabyModPlayer.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@
3030
import net.labymod.serverapi.api.packet.Packet;
3131
import net.labymod.serverapi.core.integration.LabyModIntegrationPlayer;
3232
import net.labymod.serverapi.core.integration.LabyModProtocolIntegration;
33-
import net.labymod.serverapi.core.model.display.EconomyDisplay;
34-
import net.labymod.serverapi.core.model.display.Subtitle;
35-
import net.labymod.serverapi.core.model.display.TabListFlag;
33+
import net.labymod.serverapi.core.model.display.*;
3634
import net.labymod.serverapi.core.model.feature.DiscordRPC;
3735
import net.labymod.serverapi.core.model.feature.InteractionMenuEntry;
3836
import net.labymod.serverapi.core.model.moderation.Permission;
@@ -43,9 +41,7 @@
4341
import net.labymod.serverapi.core.packet.clientbound.game.display.SubtitlePacket;
4442
import net.labymod.serverapi.core.packet.clientbound.game.display.TabListBannerPacket;
4543
import net.labymod.serverapi.core.packet.clientbound.game.display.TabListFlagPacket;
46-
import net.labymod.serverapi.core.packet.clientbound.game.feature.DiscordRPCPacket;
47-
import net.labymod.serverapi.core.packet.clientbound.game.feature.InteractionMenuPacket;
48-
import net.labymod.serverapi.core.packet.clientbound.game.feature.PlayingGameModePacket;
44+
import net.labymod.serverapi.core.packet.clientbound.game.feature.*;
4945
import net.labymod.serverapi.core.packet.clientbound.game.feature.marker.AddMarkerPacket;
5046
import net.labymod.serverapi.core.packet.clientbound.game.feature.marker.MarkerPacket;
5147
import net.labymod.serverapi.core.packet.clientbound.game.moderation.AddonDisablePacket;
@@ -451,6 +447,23 @@ public void updateReadTimeout(int seconds) {
451447
this.sendLabyModPacket(new UpdateReadTimeoutPacket(seconds));
452448
}
453449

450+
/**
451+
* Registers the provided server badges to the player.
452+
* Use {@link #bindBadges(List)} to bind the registered badges to a player.
453+
* @param badges The badges to register
454+
*/
455+
public void registerBadges(List<ServerBadge> badges) {
456+
this.sendLabyModPacket(new ServerBadgePacket(badges));
457+
}
458+
459+
/**
460+
* Bind the registered badges (of {@link #registerBadges(List)}) to a player
461+
* @param badges The badges to bind
462+
*/
463+
public void bindBadges(List<ServerUserBadge> badges) {
464+
this.sendLabyModPacket(new ServerUserBadgePacket(badges));
465+
}
466+
454467
/**
455468
* Sends the provided packet to the player
456469
*

core/src/main/java/net/labymod/serverapi/core/LabyModProtocol.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@
3131
import net.labymod.serverapi.core.packet.clientbound.game.display.SubtitlePacket;
3232
import net.labymod.serverapi.core.packet.clientbound.game.display.TabListBannerPacket;
3333
import net.labymod.serverapi.core.packet.clientbound.game.display.TabListFlagPacket;
34-
import net.labymod.serverapi.core.packet.clientbound.game.feature.DiscordRPCPacket;
35-
import net.labymod.serverapi.core.packet.clientbound.game.feature.EmotePacket;
36-
import net.labymod.serverapi.core.packet.clientbound.game.feature.InteractionMenuPacket;
37-
import net.labymod.serverapi.core.packet.clientbound.game.feature.PlayingGameModePacket;
34+
import net.labymod.serverapi.core.packet.clientbound.game.feature.*;
3835
import net.labymod.serverapi.core.packet.clientbound.game.feature.marker.AddMarkerPacket;
3936
import net.labymod.serverapi.core.packet.clientbound.game.feature.marker.MarkerPacket;
4037
import net.labymod.serverapi.core.packet.clientbound.game.moderation.AddonDisablePacket;
@@ -93,5 +90,7 @@ private void registerPackets() {
9390
this.registerPacket(34, InstalledAddonsResponsePacket.class, Direction.SERVERBOUND);
9491
this.registerPacket(35, AddonStateChangedPacket.class, Direction.SERVERBOUND);
9592
this.registerPacket(36, UpdateReadTimeoutPacket.class, Direction.CLIENTBOUND);
93+
this.registerPacket(37, ServerBadgePacket.class, Direction.CLIENTBOUND);
94+
this.registerPacket(38, ServerUserBadgePacket.class, Direction.CLIENTBOUND);
9695
}
9796
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2025 LabyMedia GmbH
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+
25+
package net.labymod.serverapi.core.model.display;
26+
27+
import java.awt.*;
28+
29+
public class ServerBadge {
30+
31+
private final int badgeId;
32+
private final Color color;
33+
private final String iconUrl;
34+
35+
private ServerBadge(int badgeId, Color color, String iconUrl) {
36+
this.badgeId = badgeId;
37+
this.color = color;
38+
this.iconUrl = iconUrl;
39+
}
40+
41+
public static ServerBadge create(
42+
int badgeId,
43+
Color color,
44+
String url
45+
) {
46+
return new ServerBadge(badgeId, color, url);
47+
}
48+
49+
public int getBadgeId() {
50+
return this.badgeId;
51+
}
52+
53+
public Color getColor() {
54+
return this.color;
55+
}
56+
57+
public String getIconUrl() {
58+
return this.iconUrl;
59+
}
60+
61+
@Override
62+
public String toString() {
63+
return "ServerBadge{" +
64+
"badgeId=" + this.badgeId +
65+
", color=" + this.color +
66+
", iconUrl='" + this.iconUrl + '\'' +
67+
'}';
68+
}
69+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2025 LabyMedia GmbH
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+
25+
package net.labymod.serverapi.core.model.display;
26+
27+
import org.jetbrains.annotations.NotNull;
28+
29+
import java.util.Arrays;
30+
import java.util.Objects;
31+
import java.util.UUID;
32+
33+
public class ServerUserBadge {
34+
35+
private final UUID uniqueId;
36+
private final int[] badgeIds;
37+
38+
private ServerUserBadge(@NotNull UUID uniqueId, int[] badgeIds) {
39+
Objects.requireNonNull(uniqueId, "Unique id cannot be null");
40+
this.uniqueId = uniqueId;
41+
this.badgeIds = badgeIds;
42+
}
43+
44+
public static ServerUserBadge create(
45+
@NotNull UUID uniqueId,
46+
int... badgeIds
47+
) {
48+
return new ServerUserBadge(uniqueId, badgeIds);
49+
}
50+
51+
public UUID getUniqueId() {
52+
return this.uniqueId;
53+
}
54+
55+
public int[] getBadgeIds() {
56+
return this.badgeIds;
57+
}
58+
59+
@Override
60+
public String toString() {
61+
return "ServerUserBadge{" +
62+
"uniqueId=" + this.uniqueId +
63+
", badgeIds=" + Arrays.toString(this.badgeIds) +
64+
'}';
65+
}
66+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2025 LabyMedia GmbH
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+
25+
package net.labymod.serverapi.core.packet.clientbound.game.feature;
26+
27+
import net.labymod.serverapi.api.packet.Packet;
28+
import net.labymod.serverapi.api.payload.io.PayloadReader;
29+
import net.labymod.serverapi.api.payload.io.PayloadWriter;
30+
import net.labymod.serverapi.core.model.display.ServerBadge;
31+
import org.jetbrains.annotations.NotNull;
32+
33+
import java.awt.*;
34+
import java.util.Arrays;
35+
import java.util.Collections;
36+
import java.util.List;
37+
38+
public class ServerBadgePacket implements Packet {
39+
40+
private List<ServerBadge> badges;
41+
42+
public ServerBadgePacket(List<ServerBadge> flags) {
43+
this.badges = flags;
44+
}
45+
46+
public ServerBadgePacket(ServerBadge... flags) {
47+
this.badges = Collections.unmodifiableList(Arrays.asList(flags));
48+
}
49+
50+
@Override
51+
public void read(@NotNull PayloadReader reader) {
52+
this.badges = reader.readList(() -> ServerBadge.create(
53+
reader.readVarInt(),
54+
new Color(reader.readInt()),
55+
reader.readString()
56+
));
57+
}
58+
59+
@Override
60+
public void write(@NotNull PayloadWriter writer) {
61+
writer.writeCollection(this.badges, (badge) -> {
62+
writer.writeVarInt(badge.getBadgeId());
63+
writer.writeInt(badge.getColor().getRGB());
64+
writer.writeString(badge.getIconUrl());
65+
});
66+
}
67+
68+
public @NotNull List<ServerBadge> getBadges() {
69+
return this.badges;
70+
}
71+
72+
@Override
73+
public String toString() {
74+
return "ServerBadge{" +
75+
"badges=" + this.badges +
76+
'}';
77+
}
78+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2025 LabyMedia GmbH
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+
25+
package net.labymod.serverapi.core.packet.clientbound.game.feature;
26+
27+
import net.labymod.serverapi.api.packet.Packet;
28+
import net.labymod.serverapi.api.payload.io.PayloadReader;
29+
import net.labymod.serverapi.api.payload.io.PayloadWriter;
30+
import net.labymod.serverapi.core.model.display.ServerUserBadge;
31+
import org.jetbrains.annotations.NotNull;
32+
33+
import java.util.Arrays;
34+
import java.util.Collections;
35+
import java.util.List;
36+
import java.util.UUID;
37+
38+
public class ServerUserBadgePacket implements Packet {
39+
40+
private List<ServerUserBadge> badges;
41+
42+
public ServerUserBadgePacket(List<ServerUserBadge> flags) {
43+
this.badges = flags;
44+
}
45+
46+
public ServerUserBadgePacket(ServerUserBadge... flags) {
47+
this.badges = Collections.unmodifiableList(Arrays.asList(flags));
48+
}
49+
50+
@Override
51+
public void read(@NotNull PayloadReader reader) {
52+
this.badges = reader.readList(() -> {
53+
UUID uuid = reader.readUUID();
54+
int badgeCount = reader.readVarInt();
55+
int[] badgeIds = new int[badgeCount];
56+
for (int i = 0; i < badgeCount; i++) {
57+
badgeIds[i] = reader.readVarInt();
58+
}
59+
return ServerUserBadge.create(uuid, badgeIds);
60+
});
61+
}
62+
63+
@Override
64+
public void write(@NotNull PayloadWriter writer) {
65+
writer.writeCollection(this.badges, (badge) -> {
66+
writer.writeUUID(badge.getUniqueId());
67+
68+
int[] badgeIds = badge.getBadgeIds();
69+
writer.writeVarInt(badgeIds.length);
70+
for (int badgeId : badgeIds) {
71+
writer.writeVarInt(badgeId);
72+
}
73+
});
74+
}
75+
76+
public @NotNull List<ServerUserBadge> getBadges() {
77+
return this.badges;
78+
}
79+
80+
@Override
81+
public String toString() {
82+
return "ServerBadgePacket{" +
83+
"badges=" + this.badges +
84+
'}';
85+
}
86+
}

0 commit comments

Comments
 (0)