-
-
Notifications
You must be signed in to change notification settings - Fork 102
/
Audience.java
749 lines (698 loc) · 28.3 KB
/
Audience.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
/*
* This file is part of adventure, licensed under the MIT License.
*
* Copyright (c) 2017-2022 KyoriPowered
*
* 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 net.kyori.adventure.audience;
import java.util.Arrays;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Collector;
import net.kyori.adventure.bossbar.BossBar;
import net.kyori.adventure.chat.ChatType;
import net.kyori.adventure.chat.SignedMessage;
import net.kyori.adventure.identity.Identified;
import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.identity.PlayerIdentified;
import net.kyori.adventure.identity.PlayerIdentity;
import net.kyori.adventure.inventory.Book;
import net.kyori.adventure.pointer.Pointered;
import net.kyori.adventure.sound.Sound;
import net.kyori.adventure.sound.SoundStop;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentLike;
import net.kyori.adventure.title.Title;
import net.kyori.adventure.title.TitlePart;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
/**
* A receiver of Minecraft media.
*
* <p><code>Audience</code> is designed to be a universal interface for any player,
* command sender, console, or otherwise who can receive text, titles,
* boss bars, and other Minecraft media. It is also designed for a group of
* receivers such as a team, server, world, or permission.</p>
* <p>In the past, Minecraft platforms have typically reserved methods such as
* <code>showTitle</code> for a <code>Player</code> interface. While this is good
* textbook object-oriented design, it presents two key drawbacks: 1) there
* is no abstraction for groups of players, such as a <code>Server</code> or a
* <code>Team</code> and 2) it add boilerplate for handling special cases like
* console or command senders.</p>
* <p>Consider the use-case of sending a message and title to every player on a
* server, and also sending a message to console. Without an <code>Audience</code>,
* the code might look like this:</p>
* <pre>
* Server server;
* for (Player player : server.getPlayers()) {
* player.sendMessage(...);
* player.showTitle(...);
* }
* server.getConsole().sendMessage(...);</pre>
* <p>Now, if <code>Server</code> implemented <code>Audience</code>, its unified interface
* would allow users to easily send media without if-guarding console or
* iterating through the list of players:</p>
* <pre>
* Server server;
* server.sendMessage(...); // Sends a message to players and console
* server.showTitle(...); // Shows a title to players, silently ignored by console</pre>
* <p>When an <code>Audience</code> is unable to perform an operation, such as sending
* a boss bar to console, it will silently fail, without logging. This
* requirement allows users to easily send media to a group of
* <code>Audience</code>s without checking each for compatibility.</p>
* <p>While the scope of <code>Audience</code> may be expanded in the future to support
* new Minecraft media such as the player list, its interface will remain stateless
* and any new methods will be stubbed by default.</p>
*
* @see ForwardingAudience
* @since 4.0.0
*/
public interface Audience extends Pointered {
/**
* Gets an audience that does nothing.
*
* @return a do-nothing audience
* @since 4.0.0
*/
static @NotNull Audience empty() {
return EmptyAudience.INSTANCE;
}
/**
* Creates an audience that forwards to many other audiences.
*
* @param audiences an array of audiences, can be empty
* @return an audience
* @see ForwardingAudience
* @since 4.0.0
*/
static @NotNull Audience audience(final @NotNull Audience@NotNull... audiences) {
final int length = audiences.length;
if (length == 0) {
return empty();
} else if (length == 1) {
return audiences[0];
}
return audience(Arrays.asList(audiences));
}
/**
* Creates an audience that forwards to many other audiences.
*
* <p>The underlying <code>Iterable</code> is not copied, therefore any changes
* made will be reflected in <code>Audience</code>.</p>
*
* @param audiences an iterable of audiences, can be empty
* @return an audience
* @see ForwardingAudience
* @since 4.0.0
*/
static @NotNull ForwardingAudience audience(final @NotNull Iterable<? extends Audience> audiences) {
return () -> audiences;
}
/**
* Provides a collector to create a forwarding audience from a stream of audiences.
*
* <p>The audience produced is immutable and can be reused as desired.</p>
*
* @return a collector to create a forwarding audience
* @since 4.0.0
*/
static @NotNull Collector<? super Audience, ?, ForwardingAudience> toAudience() {
return Audiences.COLLECTOR;
}
/**
* Filters this audience.
*
* <p>The returned {@code Audience} may be the same, or a completely different one.</p>
*
* <p>Container audiences such as {@link ForwardingAudience} may or may not have their own identity.
* If they do, they <em>may</em> test themselves against the provided {@code filter} first, and if the test fails return an empty audience skipping any contained children.
* If they do not, they <em>must not</em> test themselves against the filter, only testing their children.</p>
*
* @param filter a filter that determines if an audience should be included
* @return an audience providing a snapshot of all audiences that match the predicate when this method is invoked
* @since 4.9.0
*/
default @NotNull Audience filterAudience(final @NotNull Predicate<? super Audience> filter) {
return filter.test(this)
? this
: empty();
}
/**
* Executes an action against all audiences.
*
* <p>If you implement {@code Audience} and not {@link ForwardingAudience} in your own code, and your audience forwards to
* other audiences, then you <b>must</b> override this method and provide each audience to {@code action}.</p>
*
* <p>If an implementation of {@code Audience} has its own identity distinct from its contained children, it <em>may</em> test
* itself against the provided {@code filter} first, and if the test fails return an empty audience skipping any contained children.
* If it does not, it <em>must not</em> test itself against the filter, only testing its children.</p>
*
* @param action the action
* @since 4.9.0
*/
default void forEachAudience(final @NotNull Consumer<? super Audience> action) {
action.accept(this);
}
/**
* Sends a system chat message with to this {@link Audience} with the {@link ChatType#SYSTEM system} chat type.
*
* @param message a message
* @see Component
* @see #sendMessage(Identified, ComponentLike)
* @see #sendMessage(Identity, ComponentLike)
* @since 4.1.0
*/
@ForwardingAudienceOverrideNotRequired
default void sendMessage(final @NotNull ComponentLike message) {
this.sendMessage(message, ChatType.SYSTEM);
}
/**
* Sends a player chat message from the given {@link Identified} to this {@link Audience} with the {@link ChatType#SYSTEM system} chat type.
*
* @param source the source of the message
* @param message a message
* @see Component
* @since 4.0.0
* @deprecated since 4.12.0, client errors and can reject identified messages without {@link SignedMessage} data, this may be unsupported in the future, use {@link #sendMessage(ComponentLike, SignedMessage, PlayerIdentified)} instead
*/
@Deprecated
@ForwardingAudienceOverrideNotRequired
default void sendMessage(final @NotNull Identified source, final @NotNull ComponentLike message) {
this.sendMessage(source, message.asComponent());
}
/**
* Sends a player chat message from the entity represented by the given {@link Identity} to this {@link Audience} with the {@link ChatType#SYSTEM system} chat type.
*
* @param source the identity of the source of the message
* @param message a message
* @see Component
* @since 4.0.0
* @deprecated since 4.12.0, client errors and can reject identified messages without {@link SignedMessage} data, this may be unsupported in the future, use {@link #sendMessage(ComponentLike, SignedMessage, PlayerIdentified)} instead
*/
@Deprecated
@ForwardingAudienceOverrideNotRequired
default void sendMessage(final @NotNull Identity source, final @NotNull ComponentLike message) {
this.sendMessage(source, message.asComponent());
}
/**
* Sends a system chat message with to this {@link Audience} with the {@link ChatType#SYSTEM system} chat type.
*
* @param message a message
* @see Component
* @see #sendMessage(Identified, Component)
* @see #sendMessage(Identity, Component)
* @since 4.1.0
*/
@ForwardingAudienceOverrideNotRequired
default void sendMessage(final @NotNull Component message) {
this.sendMessage(message, ChatType.SYSTEM);
}
/**
* Sends a player chat message from the given {@link Identified} to this {@link Audience} with the {@link ChatType#SYSTEM system} chat type.
*
* @param source the source of the message
* @param message a message
* @see Component
* @since 4.0.0
* @deprecated since 4.12.0, the client errors on receiving and can reject identified messages without {@link SignedMessage} data, this may be unsupported in the future, use {@link #sendMessage(Component, SignedMessage, PlayerIdentified)} instead
*/
@Deprecated
default void sendMessage(final @NotNull Identified source, final @NotNull Component message) {
this.sendMessage(source, message, MessageType.SYSTEM);
}
/**
* Sends a player chat message from the entity represented by the given {@link Identity} to this {@link Audience} with the {@link ChatType#SYSTEM system} chat type.
*
* @param source the identity of the source of the message
* @param message a message
* @see Component
* @since 4.0.0
* @deprecated since 4.12.0, the client errors on receiving and can reject identified messages without {@link SignedMessage} data, this may be unsupported in the future, use {@link #sendMessage(Component, SignedMessage, PlayerIdentity)} instead
*/
@Deprecated
@ForwardingAudienceOverrideNotRequired
default void sendMessage(final @NotNull Identity source, final @NotNull Component message) {
this.sendMessage(source, message, MessageType.SYSTEM);
}
/**
* Sends a system chat message this {@link Audience} with the {@link ChatType} corresponding to the provided {@link MessageType}.
*
* @param message a message
* @param type the type
* @see Component
* @see #sendMessage(Identified, ComponentLike, MessageType)
* @see #sendMessage(Identity, ComponentLike, MessageType)
* @since 4.1.0
* @deprecated for removal since 4.12.0, {@link MessageType} is deprecated for removal, use {@link #sendMessage(ComponentLike, ChatType)}
*/
@ApiStatus.ScheduledForRemoval(inVersion = "5.0.0")
@Deprecated
@ForwardingAudienceOverrideNotRequired
default void sendMessage(final @NotNull ComponentLike message, final @NotNull MessageType type) {
this.sendMessage(message, (ChatType) type);
}
/**
* Sends a player chat message from the given {@link Identified} to this {@link Audience} with the {@link ChatType} corresponding to the provided {@link MessageType}.
*
* @param source the source of the message
* @param message a message
* @param type the type
* @see Component
* @since 4.0.0
* @deprecated for removal since 4.12.0, {@link MessageType} is deprecated for removal and the client errors on receiving and can reject identified messages without {@link SignedMessage} data, use {@link #sendMessage(Component, SignedMessage, PlayerIdentified, ChatType)} instead
*/
@ApiStatus.ScheduledForRemoval(inVersion = "5.0.0")
@Deprecated
@ForwardingAudienceOverrideNotRequired
default void sendMessage(final @NotNull Identified source, final @NotNull ComponentLike message, final @NotNull MessageType type) {
this.sendMessage(source, message.asComponent(), type);
}
/**
* Sends a player chat message from the entity represented by the given {@link Identity} to this {@link Audience} with the {@link ChatType#SYSTEM system} chat type.
*
* @param source the identity of the source of the message
* @param message a message
* @param type the type
* @see Component
* @since 4.0.0
* @deprecated for removal since 4.12.0, {@link MessageType} is deprecated for removal and the client errors on receiving and can reject identified messages without {@link SignedMessage} data, use {@link #sendMessage(Component, SignedMessage, PlayerIdentity, ChatType)} instead
*/
@ApiStatus.ScheduledForRemoval(inVersion = "5.0.0")
@Deprecated
@ForwardingAudienceOverrideNotRequired
default void sendMessage(final @NotNull Identity source, final @NotNull ComponentLike message, final @NotNull MessageType type) {
this.sendMessage(source, message.asComponent(), type);
}
/**
* Sends a system chat message to this {@link Audience} with the {@link ChatType} corresponding to the provided {@link MessageType}.
*
* @param message a message
* @param type the type
* @see Component
* @see #sendMessage(Identified, Component, MessageType)
* @see #sendMessage(Identity, Component, MessageType)
* @since 4.1.0
* @deprecated for removal since 4.12.0, {@link MessageType} is deprecated for removal, use {@link #sendMessage(Component, ChatType)} instead
*/
@ApiStatus.ScheduledForRemoval(inVersion = "5.0.0")
@Deprecated
@ForwardingAudienceOverrideNotRequired
default void sendMessage(final @NotNull Component message, final @NotNull MessageType type) {
this.sendMessage(message, (ChatType) type);
}
/**
* Sends a player chat message from the given {@link Identified} to this {@link Audience} with the {@link ChatType} corresponding to the provided {@link MessageType}.
*
* @param source the source of the message
* @param message a message
* @param type the type
* @see Component
* @since 4.0.0
* @deprecated for removal since 4.12.0, {@link MessageType} is deprecated for removal and the client errors on receiving and can reject identified messages without {@link SignedMessage} data, use {@link #sendMessage(Component, SignedMessage, PlayerIdentified, ChatType)} instead
*/
@ApiStatus.ScheduledForRemoval(inVersion = "5.0.0")
@Deprecated
default void sendMessage(final @NotNull Identified source, final @NotNull Component message, final @NotNull MessageType type) {
}
/**
* Sends a player chat message from the entity represented by the given {@link Identity} to this {@link Audience} with the {@link ChatType} corresponding to the provided {@link MessageType}.
*
* @param source the identity of the source of the message
* @param message a message
* @param type the type
* @see Component
* @since 4.0.0
* @deprecated for removal since 4.12.0, {@link MessageType} is deprecated for removal and the client errors on receiving and can reject identified messages without {@link SignedMessage} data, use use {@link #sendMessage(Component, SignedMessage, PlayerIdentity, ChatType)} instead
*/
@ApiStatus.ScheduledForRemoval(inVersion = "5.0.0")
@Deprecated
default void sendMessage(final @NotNull Identity source, final @NotNull Component message, final @NotNull MessageType type) {
}
/**
* Sends a system chat message to this {@link Audience} with the provided {@link ChatType}.
*
* @param message the message
* @param chatType the chat type
* @since 4.12.0
*/
@ForwardingAudienceOverrideNotRequired
default void sendMessage(final @NotNull ComponentLike message, final @NotNull ChatType chatType) {
this.sendMessage(message.asComponent(), chatType);
}
/**
* Sends a system chat message to this {@link Audience} with the provided {@link ChatType}.
*
* @param message the message
* @param chatType the chat type
* @since 4.12.0
*/
default void sendMessage(final @NotNull Component message, final @NotNull ChatType chatType) {
}
/**
* Sends a signed player chat message from the given {@link PlayerIdentified} to this {@link Audience} with the {@link ChatType#CHAT chat} chat type.
*
* @param message the message
* @param signedMessage the signed message data
* @param source the source of the message
* @since 4.12.0
*/
@ForwardingAudienceOverrideNotRequired
default void sendMessage(final @NotNull ComponentLike message, final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentified source) {
this.sendMessage(message.asComponent(), signedMessage, source);
}
/**
* Sends a signed player chat message from the given {@link PlayerIdentified} to this {@link Audience} with the {@link ChatType#CHAT chat} chat type.
*
* @param message the message
* @param signedMessage the signed message data
* @param source the source of the message
* @since 4.12.0
*/
@ForwardingAudienceOverrideNotRequired
default void sendMessage(final @NotNull Component message, final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentified source) {
this.sendMessage(message, signedMessage, source, ChatType.CHAT);
}
/**
* Sends a signed player chat message from player identified by the provided {@link PlayerIdentity} to this {@link Audience} with the {@link ChatType#CHAT chat} chat type.
*
* @param message the message
* @param signedMessage the signed message data
* @param source the identity of the source of the message
* @since 4.12.0
*/
@ForwardingAudienceOverrideNotRequired
default void sendMessage(final @NotNull ComponentLike message, final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentity source) {
this.sendMessage(message.asComponent(), signedMessage, source);
}
/**
* Sends a signed player chat message from player identified by the provided {@link PlayerIdentity} to this {@link Audience} with the {@link ChatType#CHAT chat} chat type.
*
* @param message the message
* @param signedMessage the signed message data
* @param source the identity of the source of the message
* @since 4.12.0
*/
@ForwardingAudienceOverrideNotRequired
default void sendMessage(final @NotNull Component message, final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentity source) {
this.sendMessage(message, signedMessage, source, ChatType.CHAT);
}
/**
* Sends a signed player chat message from the given {@link PlayerIdentified} to this {@link Audience} with the provided {@link ChatType}.
*
* @param message the message
* @param signedMessage the signed message data
* @param source the source of the message
* @param chatType the chat type
* @since 4.12.0
*/
@ForwardingAudienceOverrideNotRequired
default void sendMessage(final @NotNull ComponentLike message, final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentified source, final @NotNull ChatType chatType) {
this.sendMessage(message.asComponent(), signedMessage, source, chatType);
}
/**
* Sends a signed player chat message from the given {@link PlayerIdentified} to this {@link Audience} with the provided {@link ChatType} chat type.
*
* @param message the message
* @param signedMessage the signed message data
* @param source the source of the message
* @param chatType the chat type
* @since 4.12.0
*/
default void sendMessage(final @NotNull Component message, final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentified source, final @NotNull ChatType chatType) {
}
/**
* Sends a signed player chat message from player identified by the provided {@link PlayerIdentity} to this {@link Audience} with the provided {@link ChatType}.
*
* @param message the message
* @param signedMessage the signed message data
* @param source the identity of the source of the message
* @param chatType the chat type
* @since 4.12.0
*/
@ForwardingAudienceOverrideNotRequired
default void sendMessage(final @NotNull ComponentLike message, final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentity source, final @NotNull ChatType chatType) {
this.sendMessage(message.asComponent(), signedMessage, source, chatType);
}
/**
* Sends a signed player chat message from player identified by the provided {@link PlayerIdentity} to this {@link Audience} with the provided {@link ChatType}.
*
* @param message the message
* @param signedMessage the signed message data
* @param source the identity of the source of the message
* @param chatType the chat type
* @since 4.12.0
*/
default void sendMessage(final @NotNull Component message, final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentity source, final @NotNull ChatType chatType) {
}
/**
* Sends a message on the action bar.
*
* @param message a message
* @see Component
* @since 4.0.0
*/
@ForwardingAudienceOverrideNotRequired
default void sendActionBar(final @NotNull ComponentLike message) {
this.sendActionBar(message.asComponent());
}
/**
* Sends a message on the action bar.
*
* @param message a message
* @see Component
* @since 4.0.0
*/
default void sendActionBar(final @NotNull Component message) {
}
/**
* Sends the player list header.
*
* <p>Depending on the implementation of this {@code Audience}, an existing footer may be displayed. If you wish
* to set both the header and the footer, please use {@link #sendPlayerListHeaderAndFooter(ComponentLike, ComponentLike)}.</p>
*
* @param header the header
* @since 4.3.0
*/
@ForwardingAudienceOverrideNotRequired
default void sendPlayerListHeader(final @NotNull ComponentLike header) {
this.sendPlayerListHeader(header.asComponent());
}
/**
* Sends the player list header.
*
* <p>Depending on the implementation of this {@code Audience}, an existing footer may be displayed. If you wish
* to set both the header and the footer, please use {@link #sendPlayerListHeaderAndFooter(Component, Component)}.</p>
*
* @param header the header
* @since 4.3.0
*/
default void sendPlayerListHeader(final @NotNull Component header) {
this.sendPlayerListHeaderAndFooter(header, Component.empty());
}
/**
* Sends the player list footer.
*
* <p>Depending on the implementation of this {@code Audience}, an existing footer may be displayed. If you wish
* to set both the header and the footer, please use {@link #sendPlayerListHeaderAndFooter(ComponentLike, ComponentLike)}.</p>
*
* @param footer the footer
* @since 4.3.0
*/
@ForwardingAudienceOverrideNotRequired
default void sendPlayerListFooter(final @NotNull ComponentLike footer) {
this.sendPlayerListFooter(footer.asComponent());
}
/**
* Sends the player list footer.
*
* <p>Depending on the implementation of this {@code Audience}, an existing footer may be displayed. If you wish
* to set both the header and the footer, please use {@link #sendPlayerListHeaderAndFooter(Component, Component)}.</p>
*
* @param footer the footer
* @since 4.3.0
*/
default void sendPlayerListFooter(final @NotNull Component footer) {
this.sendPlayerListHeaderAndFooter(Component.empty(), footer);
}
/**
* Sends the player list header and footer.
*
* @param header the header
* @param footer the footer
* @since 4.3.0
*/
@ForwardingAudienceOverrideNotRequired
default void sendPlayerListHeaderAndFooter(final @NotNull ComponentLike header, final @NotNull ComponentLike footer) {
this.sendPlayerListHeaderAndFooter(header.asComponent(), footer.asComponent());
}
/**
* Sends the player list header and footer.
*
* @param header the header
* @param footer the footer
* @since 4.3.0
*/
default void sendPlayerListHeaderAndFooter(final @NotNull Component header, final @NotNull Component footer) {
}
/**
* Shows a title.
*
* @param title a title
* @see Title
* @since 4.0.0
*/
@ForwardingAudienceOverrideNotRequired
default void showTitle(final @NotNull Title title) {
final Title.Times times = title.times();
if (times != null) this.sendTitlePart(TitlePart.TIMES, times);
this.sendTitlePart(TitlePart.SUBTITLE, title.subtitle());
this.sendTitlePart(TitlePart.TITLE, title.title());
}
/**
* Shows a part of a title.
*
* @param part the part
* @param value the value
* @param <T> the type of the value of the part
* @throws IllegalArgumentException if a title part that is not in {@link TitlePart} is used
* @since 4.9.0
*/
default <T> void sendTitlePart(final @NotNull TitlePart<T> part, final @NotNull T value) {
}
/**
* Clears the title, if one is being displayed.
*
* @see Title
* @since 4.0.0
*/
default void clearTitle() {
}
/**
* Resets the title and timings back to their default.
*
* @see Title
* @since 4.0.0
*/
default void resetTitle() {
}
/**
* Shows a boss bar.
*
* @param bar a boss bar
* @see BossBar
* @since 4.0.0
*/
default void showBossBar(final @NotNull BossBar bar) {
}
/**
* Hides a boss bar.
*
* @param bar a boss bar
* @see BossBar
* @since 4.0.0
*/
default void hideBossBar(final @NotNull BossBar bar) {
}
/**
* Plays a sound at the location of the recipient of the sound.
*
* <p>To play a sound that follows the recipient, use {@link #playSound(Sound, Sound.Emitter)} with {@link Sound.Emitter#self()}.</p>
*
* @param sound a sound
* @see Sound
* @since 4.0.0
*/
default void playSound(final @NotNull Sound sound) {
}
/**
* Plays a sound at a location.
*
* @param sound a sound
* @param x x coordinate
* @param y y coordinate
* @param z z coordinate
* @see Sound
* @since 4.0.0
*/
default void playSound(final @NotNull Sound sound, final double x, final double y, final double z) {
}
/**
* Plays a sound from an emitter, usually an entity.
*
* <p>
* Sounds played using this method will follow the emitter unless the sound is a custom sound.
* In this case the sound will be played at the location of the emitter and will not follow them.
* </p>
*
* <p>To play a sound that follows the recipient, use {@link Sound.Emitter#self()}.</p>
*
* <p><b>Note</b>: Due to <a href="https://bugs.mojang.com/browse/MC-138832">MC-138832</a>, the volume and pitch may be ignored when using this method.</p>
*
* @param sound a sound
* @param emitter an emitter
* @since 4.8.0
*/
default void playSound(final @NotNull Sound sound, final Sound.@NotNull Emitter emitter) {
}
/**
* Stops a sound.
*
* @param sound the sound
* @since 4.8.0
*/
@ForwardingAudienceOverrideNotRequired
default void stopSound(final @NotNull Sound sound) {
this.stopSound(Objects.requireNonNull(sound, "sound").asStop());
}
/**
* Stops a sound, or many sounds.
*
* @param stop a sound stop
* @see SoundStop
* @since 4.0.0
*/
default void stopSound(final @NotNull SoundStop stop) {
}
/**
* Opens a book.
*
* <p>When possible, no item should persist after closing the book.</p>
*
* @param book a book
* @see Book
* @since 4.0.0
*/
@ForwardingAudienceOverrideNotRequired
default void openBook(final Book.@NotNull Builder book) {
this.openBook(book.build());
}
/**
* Opens a book.
*
* <p>When possible, no item should persist after closing the book.</p>
*
* @param book a book
* @see Book
* @since 4.0.0
*/
default void openBook(final @NotNull Book book) {
}
}