3131import net .labymod .serverapi .core .integration .LabyModIntegrationPlayer ;
3232import net .labymod .serverapi .core .integration .LabyModProtocolIntegration ;
3333import net .labymod .serverapi .core .model .display .Subtitle ;
34+ import net .labymod .serverapi .core .model .feature .DiscordRPC ;
35+ import net .labymod .serverapi .core .model .feature .InteractionMenuEntry ;
3436import net .labymod .serverapi .core .model .moderation .Permission ;
3537import net .labymod .serverapi .core .model .supplement .InputPrompt ;
3638import net .labymod .serverapi .core .model .supplement .ServerSwitchPrompt ;
3739import net .labymod .serverapi .core .packet .clientbound .game .display .SubtitlePacket ;
40+ import net .labymod .serverapi .core .packet .clientbound .game .display .TabListBannerPacket ;
41+ import net .labymod .serverapi .core .packet .clientbound .game .feature .DiscordRPCPacket ;
42+ import net .labymod .serverapi .core .packet .clientbound .game .feature .InteractionMenuPacket ;
43+ import net .labymod .serverapi .core .packet .clientbound .game .feature .PlayingGameModePacket ;
3844import net .labymod .serverapi .core .packet .clientbound .game .moderation .PermissionPacket ;
3945import net .labymod .serverapi .core .packet .clientbound .game .supplement .InputPromptPacket ;
4046import net .labymod .serverapi .core .packet .clientbound .game .supplement .ServerSwitchPromptPacket ;
@@ -129,7 +135,42 @@ protected AbstractLabyModPlayer(
129135 * @param component The component to set as subtitle
130136 */
131137 public void setSubtitle (@ NotNull ServerAPIComponent component ) {
132- this .setSubtitleInternal (Subtitle .create (this .uniqueId , component ));
138+ this .setSubtitle (Subtitle .create (this .uniqueId , component ));
139+ }
140+
141+ public void setSubtitle (@ Nullable Subtitle subtitle ) {
142+ if (Objects .equals (this .subtitle , subtitle )) {
143+ return ;
144+ }
145+
146+ this .subtitle = subtitle ;
147+
148+ List <Subtitle > subtitles = new ArrayList <>();
149+ if (subtitle == null ) {
150+ subtitle = Subtitle .create (this .uniqueId , null );
151+ subtitles .add (subtitle );
152+ }
153+
154+ LabyModProtocol labyModProtocol = this .protocolService .labyModProtocol ();
155+ SubtitlePacket packet = new SubtitlePacket (subtitle );
156+ for (AbstractLabyModPlayer <?> player : this .protocolService .getPlayers ()) {
157+ Subtitle playerSubtitle = player .getSubtitle ();
158+ if (playerSubtitle != null ) {
159+ subtitles .add (playerSubtitle );
160+ }
161+
162+ if (player .equals (this )) {
163+ continue ;
164+ }
165+
166+ labyModProtocol .sendPacket (player .getUniqueId (), packet );
167+ }
168+
169+ if (subtitles .isEmpty ()) {
170+ return ;
171+ }
172+
173+ this .sendLabyModPacket (new SubtitlePacket (subtitles ));
133174 }
134175
135176 /**
@@ -139,16 +180,66 @@ public void setSubtitle(@NotNull ServerAPIComponent component) {
139180 * @param size The size of the subtitle
140181 */
141182 public void setSubtitle (@ NotNull ServerAPIComponent component , double size ) {
142- this .setSubtitleInternal (Subtitle .create (this .uniqueId , component , size ));
183+ this .setSubtitle (Subtitle .create (this .uniqueId , component , size ));
143184 }
144185
145186 /**
146187 * Resets the subtitle of the player and sends it to all other online players
147188 */
148189 public void resetSubtitle () {
149- this .setSubtitleInternal (null );
190+ this .setSubtitle ((Subtitle ) null );
191+ }
192+
193+ /**
194+ * Sends the provided interaction menu entries to the player
195+ *
196+ * @param entries The entries to send
197+ */
198+ public void sendInteractionMenuEntries (@ NotNull InteractionMenuEntry ... entries ) {
199+ this .sendLabyModPacket (new InteractionMenuPacket (entries ));
200+ }
201+
202+ /**
203+ * Sends the provided interaction menu entries to the player
204+ *
205+ * @param entries The entries to send
206+ */
207+ public void sendInteractionMenuEntries (@ NotNull List <InteractionMenuEntry > entries ) {
208+ this .sendLabyModPacket (new InteractionMenuPacket (entries ));
209+ }
210+
211+ /**
212+ * Sends the provided game mode to the LabyMod Chat friends of the player
213+ *
214+ * @param gameMode The game mode to send or {@code null} to unset
215+ */
216+ public void sendPlayingGameMode (@ Nullable String gameMode ) {
217+ this .sendLabyModPacket (new PlayingGameModePacket (gameMode ));
218+ }
219+
220+ /**
221+ * Sends the provided discord rpc to the player
222+ *
223+ * @param discordRPC The discord rpc to send
224+ */
225+ public void sendDiscordRPC (@ NotNull DiscordRPC discordRPC ) {
226+ this .sendLabyModPacket (new DiscordRPCPacket (discordRPC ));
150227 }
151228
229+ /**
230+ * Sends the provided icon url as tab list banner to the player
231+ *
232+ * @param iconUrl The icon url to send or {@code null} to unset the banner
233+ */
234+ public void sendTabListBanner (@ Nullable String iconUrl ) {
235+ this .sendLabyModPacket (new TabListBannerPacket (iconUrl ));
236+ }
237+
238+ /**
239+ * Sends the provided packet to the player
240+ *
241+ * @param packet The packet to send
242+ */
152243 public void sendPacket (@ NotNull Packet packet ) {
153244 Class <? extends Packet > packetClass = packet .getClass ();
154245 for (Protocol protocol : this .protocolService .registry ().getProtocols ()) {
@@ -237,41 +328,6 @@ public void openServerSwitchPrompt(
237328 );
238329 }
239330
240- protected void setSubtitleInternal (@ Nullable Subtitle subtitle ) {
241- if (Objects .equals (this .subtitle , subtitle )) {
242- return ;
243- }
244-
245- this .subtitle = subtitle ;
246-
247- List <Subtitle > subtitles = new ArrayList <>();
248- if (subtitle == null ) {
249- subtitle = Subtitle .create (this .uniqueId , null );
250- subtitles .add (subtitle );
251- }
252-
253- LabyModProtocol labyModProtocol = this .protocolService .labyModProtocol ();
254- SubtitlePacket packet = new SubtitlePacket (subtitle );
255- for (AbstractLabyModPlayer <?> player : this .protocolService .getPlayers ()) {
256- Subtitle playerSubtitle = player .getSubtitle ();
257- if (playerSubtitle != null ) {
258- subtitles .add (playerSubtitle );
259- }
260-
261- if (player .equals (this )) {
262- continue ;
263- }
264-
265- labyModProtocol .sendPacket (player .getUniqueId (), packet );
266- }
267-
268- if (subtitles .isEmpty ()) {
269- return ;
270- }
271-
272- this .sendLabyModPacket (new SubtitlePacket (subtitles ));
273- }
274-
275331 private void sendLabyModPacket (@ NotNull Packet packet ) {
276332 this .protocolService .labyModProtocol .sendPacket (this .uniqueId , packet );
277333 }
0 commit comments