|
| 1 | +The `ServerBadgePacket` is a client-bound packet that allows servers to display a badge in the tab list next to the player's name and in the nametag. |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | +## Set the Badge Infos |
| 7 | + |
| 8 | +???+ danger "Important Note" |
| 9 | + |
| 10 | + You must first send the Badge Infos before the badges can be displayed next to the players. |
| 11 | + |
| 12 | +The packet can either be sent via the `LabyModPlayer` object of the player, or directly via the `LabyModProtocol`. |
| 13 | + |
| 14 | +You can send one or more server badge info to the player. |
| 15 | + |
| 16 | +### Via the LabyModPlayer (Recommended) |
| 17 | + |
| 18 | +```java |
| 19 | +// Get the LabyModPlayer |
| 20 | +LabyModPlayer player = LabyModProtocolService.get().getPlayer(uniqueId); |
| 21 | + |
| 22 | +// Create a new ServerBadge |
| 23 | +ServerBadge owner = ServerBadge.create( |
| 24 | + 1, // The ID of the badge |
| 25 | + new Color(255, 0, 0), // The color of the badge |
| 26 | + "https://example.com/image_owner.png" // The URL of the badge image |
| 27 | +); |
| 28 | +ServerBadge developer = ServerBadge.create( |
| 29 | + 2, // The ID of the badge |
| 30 | + new Color(0, 0, 255), // The color of the badge |
| 31 | + "https://example.com/image_developer.png" // The URL of the badge image |
| 32 | +); |
| 33 | + |
| 34 | +// Register the badges |
| 35 | +player.registerBadges(List.of(owner, developer)); |
| 36 | +``` |
| 37 | + |
| 38 | +### Via the LabyModProtocol |
| 39 | + |
| 40 | +```java |
| 41 | +// Get the LabyModProtocol |
| 42 | +LabyModProtocol labyModProtocol = LabyModProtocolService.get().labyModProtocol(); |
| 43 | + |
| 44 | +// Create a new ServerBadge |
| 45 | +ServerBadge owner = ServerBadge.create( |
| 46 | + 1, // The ID of the badge |
| 47 | + new Color(255, 0, 0), // The color of the badge |
| 48 | + "https://example.com/image_owner.png" // The URL of the badge image |
| 49 | +); |
| 50 | +ServerBadge developer = ServerBadge.create( |
| 51 | + 2, // The ID of the badge |
| 52 | + new Color(0, 0, 255), // The color of the badge |
| 53 | + "https://example.com/image_developer.png" // The URL of the badge image |
| 54 | +); |
| 55 | + |
| 56 | +// Send the packet |
| 57 | +labyModProtocol.sendPacket(uniqueId, new ServerBadgePacket(owner, developer)); |
| 58 | +``` |
| 59 | + |
| 60 | +## Set the badges for the players. |
| 61 | + |
| 62 | +The packet can either be sent via the `LabyModPlayer` object of the player, or directly via the `LabyModProtocol`. |
| 63 | + |
| 64 | +### Via the LabyModPlayer (Recommended) |
| 65 | + |
| 66 | +```java |
| 67 | +// Get the LabyModPlayer |
| 68 | +LabyModPlayer player = LabyModProtocolService.get().getPlayer(uniqueId); |
| 69 | + |
| 70 | +// Create a new ServerUserBadge |
| 71 | +ServerUserBadge serverUserBadge = ServerUserBadge.create( |
| 72 | + uniqueId, // The UUID of the user who has the badge |
| 73 | + 1 // The ID of the badge |
| 74 | +); |
| 75 | + |
| 76 | +// Bind the badges |
| 77 | +player.bindBadges(List.of(serverUserBadge)); |
| 78 | +``` |
| 79 | + |
| 80 | +### Via the LabyModProtocol |
| 81 | + |
| 82 | +Now you can assign the badge to a player, which will then be displayed. |
| 83 | + |
| 84 | +```java |
| 85 | +// Get the LabyModProtocol |
| 86 | +LabyModProtocol labyModProtocol = LabyModProtocolService.get().labyModProtocol(); |
| 87 | + |
| 88 | +// Create a new ServerUserBadge |
| 89 | +ServerUserBadge serverUserBadge = ServerUserBadge.create( |
| 90 | + uniqueId, // The UUID of the user who has the badge |
| 91 | + 1 // The ID of the badge |
| 92 | +); |
| 93 | + |
| 94 | +// Send the packets |
| 95 | +labyModProtocol.sendPacket(uniqueId, new ServerUserBadgePacket(serverUserBadge)); |
| 96 | +``` |
0 commit comments