forked from PaperMC/Paper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
0007-Adventure.patch
3780 lines (3607 loc) · 152 KB
/
0007-Adventure.patch
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
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Riley Park <[email protected]>
Date: Fri, 29 Jan 2021 17:21:55 +0100
Subject: [PATCH] Adventure
Co-authored-by: zml <[email protected]>
Co-authored-by: Jake Potrebic <[email protected]>
diff --git a/build.gradle.kts b/build.gradle.kts
index 17fd7162ab32785252bf2579daae8d47aec21684..479d4e3b91e902e9b30d351aa65c8b079555d7e0 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -10,6 +10,8 @@ java {
withJavadocJar()
}
+val adventureVersion = "4.8.1"
+
dependencies {
// api dependencies are listed transitively to API consumers
api("commons-lang:commons-lang:2.6")
@@ -19,6 +21,11 @@ dependencies {
api("org.yaml:snakeyaml:1.28")
api("com.googlecode.json-simple:json-simple:1.1.1") // Paper
api("it.unimi.dsi:fastutil:8.2.2")
+ api(platform("net.kyori:adventure-bom:$adventureVersion"))
+ api("net.kyori:adventure-api")
+ api("net.kyori:adventure-text-serializer-gson")
+ api("net.kyori:adventure-text-serializer-legacy")
+ api("net.kyori:adventure-text-serializer-plain")
compileOnly("org.apache.maven:maven-resolver-provider:3.8.1")
compileOnly("org.apache.maven.resolver:maven-resolver-connector-basic:1.7.0")
@@ -66,5 +73,11 @@ tasks.withType<Javadoc>().configureEach {
"https://javadoc.io/doc/org.yaml/snakeyaml/1.28/",
"https://javadoc.io/doc/org.jetbrains/annotations/21.0.1/", // Paper - we don't want Java 5 annotations
"https://javadoc.io/doc/net.md-5/bungeecord-chat/1.16-R0.4/",
+ // Paper start
+ "https://jd.adventure.kyori.net/api/$adventureVersion/",
+ "https://jd.adventure.kyori.net/text-serializer-gson/$adventureVersion/",
+ "https://jd.adventure.kyori.net/text-serializer-legacy/$adventureVersion/",
+ "https://jd.adventure.kyori.net/text-serializer-plain/$adventureVersion/",
+ // Paper end
)
}
diff --git a/src/main/java/co/aikar/timings/TimingsReportListener.java b/src/main/java/co/aikar/timings/TimingsReportListener.java
index ef58a6c00f444bd498a2d8fc4e457236f393954f..ecd149157d4fb80444f34bf5633d74bcdb63dec5 100644
--- a/src/main/java/co/aikar/timings/TimingsReportListener.java
+++ b/src/main/java/co/aikar/timings/TimingsReportListener.java
@@ -15,7 +15,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@SuppressWarnings("WeakerAccess")
-public class TimingsReportListener implements MessageCommandSender {
+public class TimingsReportListener implements net.kyori.adventure.audience.ForwardingAudience, MessageCommandSender { // Paper
private final List<CommandSender> senders;
private final Runnable onDone;
private String timingsURL;
@@ -74,4 +74,17 @@ public class TimingsReportListener implements MessageCommandSender {
this.senders.add(Bukkit.getConsoleSender());
}
}
+
+ // Paper start
+ @Override
+ public void sendMessage(final @NotNull net.kyori.adventure.identity.Identity source, final @NotNull net.kyori.adventure.text.Component message, final @NotNull net.kyori.adventure.audience.MessageType type) {
+ net.kyori.adventure.audience.ForwardingAudience.super.sendMessage(source, message, type);
+ }
+
+ @NotNull
+ @Override
+ public Iterable<? extends net.kyori.adventure.audience.Audience> audiences() {
+ return this.senders;
+ }
+ // Paper end
}
diff --git a/src/main/java/io/papermc/paper/chat/ChatRenderer.java b/src/main/java/io/papermc/paper/chat/ChatRenderer.java
new file mode 100644
index 0000000000000000000000000000000000000000..85fd5d6777b53bab09cc54c360bb75141635bdd3
--- /dev/null
+++ b/src/main/java/io/papermc/paper/chat/ChatRenderer.java
@@ -0,0 +1,75 @@
+package io.papermc.paper.chat;
+
+import net.kyori.adventure.audience.Audience;
+import net.kyori.adventure.text.Component;
+import org.bukkit.entity.Player;
+import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * A chat renderer is responsible for rendering chat messages sent by {@link Player}s to the server.
+ */
+@FunctionalInterface
+public interface ChatRenderer {
+ /**
+ * Renders a chat message. This will be called once for each receiving {@link Audience}.
+ *
+ * @param source the message source
+ * @param sourceDisplayName the display name of the source player
+ * @param message the chat message
+ * @param viewer the receiving {@link Audience}
+ * @return a rendered chat message
+ */
+ @NotNull
+ Component render(@NotNull Player source, @NotNull Component sourceDisplayName, @NotNull Component message, @NotNull Audience viewer);
+
+ /**
+ * Create a new instance of the default {@link ChatRenderer}.
+ *
+ * @return a new {@link ChatRenderer}
+ */
+ @NotNull
+ static ChatRenderer defaultRenderer() {
+ return viewerUnaware((source, sourceDisplayName, message) -> Component.translatable("chat.type.text", sourceDisplayName, message));
+ }
+
+ /**
+ * Creates a new viewer-unaware {@link ChatRenderer}, which will render the chat message a single time,
+ * displaying the same rendered message to every viewing {@link Audience}.
+ *
+ * @param renderer the viewer unaware renderer
+ * @return a new {@link ChatRenderer}
+ */
+ @NotNull
+ static ChatRenderer viewerUnaware(final @NotNull ViewerUnaware renderer) {
+ return new ChatRenderer() {
+ private @MonotonicNonNull Component message;
+
+ @Override
+ public @NotNull Component render(final @NotNull Player source, final @NotNull Component sourceDisplayName, final @NotNull Component message, final @NotNull Audience viewer) {
+ if (this.message == null) {
+ this.message = renderer.render(source, sourceDisplayName, message);
+ }
+ return this.message;
+ }
+ };
+ }
+
+ /**
+ * Similar to {@link ChatRenderer}, but without knowledge of the message viewer.
+ *
+ * @see ChatRenderer#viewerUnaware(ViewerUnaware)
+ */
+ interface ViewerUnaware {
+ /**
+ * Renders a chat message.
+ *
+ * @param source the message source
+ * @param sourceDisplayName the display name of the source player
+ * @param message the chat message
+ * @return a rendered chat message
+ */
+ @NotNull
+ Component render(@NotNull Player source, @NotNull Component sourceDisplayName, @NotNull Component message);
+ }
+}
diff --git a/src/main/java/io/papermc/paper/event/player/AbstractChatEvent.java b/src/main/java/io/papermc/paper/event/player/AbstractChatEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..fa03a5cb2d3e3e0a60d84bacc911d96c454f81da
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/player/AbstractChatEvent.java
@@ -0,0 +1,112 @@
+package io.papermc.paper.event.player;
+
+import java.util.Set;
+import io.papermc.paper.chat.ChatRenderer;
+import net.kyori.adventure.audience.Audience;
+import net.kyori.adventure.text.Component;
+import org.bukkit.entity.Player;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.player.PlayerEvent;
+import org.jetbrains.annotations.NotNull;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * An abstract implementation of a chat event, handling shared logic.
+ */
+public abstract class AbstractChatEvent extends PlayerEvent implements Cancellable {
+ private final Set<Audience> viewers;
+ private final Component originalMessage;
+ private ChatRenderer renderer;
+ private Component message;
+ private boolean cancelled = false;
+
+ AbstractChatEvent(final boolean async, final @NotNull Player player, final @NotNull Set<Audience> viewers, final @NotNull ChatRenderer renderer, final @NotNull Component message, final @NotNull Component originalMessage) {
+ super(player, async);
+ this.viewers = viewers;
+ this.renderer = renderer;
+ this.message = message;
+ this.originalMessage = originalMessage;
+ }
+
+ /**
+ * Gets a set of {@link Audience audiences} that this chat message will be displayed to.
+ *
+ * <p>The set returned is not guaranteed to be mutable and may auto-populate
+ * on access. Any listener accessing the returned set should be aware that
+ * it may reduce performance for a lazy set implementation.</p>
+ *
+ * <p>Listeners should be aware that modifying the list may throw {@link
+ * UnsupportedOperationException} if the event caller provides an
+ * unmodifiable set.</p>
+ *
+ * @return a set of {@link Audience audiences} who will receive the chat message
+ */
+ @NotNull
+ public final Set<Audience> viewers() {
+ return this.viewers;
+ }
+
+ /**
+ * Sets the chat renderer.
+ *
+ * @param renderer the chat renderer
+ * @throws NullPointerException if {@code renderer} is {@code null}
+ */
+ public final void renderer(final @NotNull ChatRenderer renderer) {
+ this.renderer = requireNonNull(renderer, "renderer");
+ }
+
+ /**
+ * Gets the chat renderer.
+ *
+ * @return the chat renderer
+ */
+ @NotNull
+ public final ChatRenderer renderer() {
+ return this.renderer;
+ }
+
+ /**
+ * Gets the user-supplied message.
+ * The return value will reflect changes made using {@link #message(Component)}.
+ *
+ * @return the user-supplied message
+ */
+ @NotNull
+ public final Component message() {
+ return this.message;
+ }
+
+ /**
+ * Sets the user-supplied message.
+ *
+ * @param message the user-supplied message
+ * @throws NullPointerException if {@code message} is {@code null}
+ */
+ public final void message(final @NotNull Component message) {
+ this.message = requireNonNull(message, "message");
+ }
+
+ /**
+ * Gets the original and unmodified user-supplied message.
+ * The return value will <b>not</b> reflect changes made using
+ * {@link #message(Component)}.
+ *
+ * @return the original user-supplied message
+ */
+ @NotNull
+ public final Component originalMessage() {
+ return this.originalMessage;
+ }
+
+ @Override
+ public final boolean isCancelled() {
+ return this.cancelled;
+ }
+
+ @Override
+ public final void setCancelled(final boolean cancelled) {
+ this.cancelled = cancelled;
+ }
+}
diff --git a/src/main/java/io/papermc/paper/event/player/AsyncChatEvent.java b/src/main/java/io/papermc/paper/event/player/AsyncChatEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..0d9e3c23027e3af90cb70e4bb6fb0ac1da35fc4d
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/player/AsyncChatEvent.java
@@ -0,0 +1,31 @@
+package io.papermc.paper.event.player;
+
+import java.util.Set;
+import io.papermc.paper.chat.ChatRenderer;
+import net.kyori.adventure.audience.Audience;
+import net.kyori.adventure.text.Component;
+import org.bukkit.entity.Player;
+import org.bukkit.event.HandlerList;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * An event fired when a {@link Player} sends a chat message to the server.
+ */
+public final class AsyncChatEvent extends AbstractChatEvent {
+ private static final HandlerList HANDLERS = new HandlerList();
+
+ public AsyncChatEvent(final boolean async, final @NotNull Player player, final @NotNull Set<Audience> viewers, final @NotNull ChatRenderer renderer, final @NotNull Component message, final @NotNull Component originalMessage) {
+ super(async, player, viewers, renderer, message, originalMessage);
+ }
+
+ @NotNull
+ @Override
+ public HandlerList getHandlers() {
+ return HANDLERS;
+ }
+
+ @NotNull
+ public static HandlerList getHandlerList() {
+ return HANDLERS;
+ }
+}
diff --git a/src/main/java/io/papermc/paper/event/player/ChatEvent.java b/src/main/java/io/papermc/paper/event/player/ChatEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..eb179aae1e1d2ce842442e49fe275827a430ccd0
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/player/ChatEvent.java
@@ -0,0 +1,36 @@
+package io.papermc.paper.event.player;
+
+import java.util.Set;
+import io.papermc.paper.chat.ChatRenderer;
+import net.kyori.adventure.audience.Audience;
+import net.kyori.adventure.text.Component;
+import org.bukkit.Warning;
+import org.bukkit.entity.Player;
+import org.bukkit.event.HandlerList;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * An event fired when a {@link Player} sends a chat message to the server.
+ *
+ * @deprecated Listening to this event forces chat to wait for the main thread, delaying chat messages. It is recommended to use {@link AsyncChatEvent} instead, wherever possible.
+ */
+@Deprecated
+@Warning(reason = "Listening to this event forces chat to wait for the main thread, delaying chat messages.")
+public final class ChatEvent extends AbstractChatEvent {
+ private static final HandlerList HANDLERS = new HandlerList();
+
+ public ChatEvent(final @NotNull Player player, final @NotNull Set<Audience> viewers, final @NotNull ChatRenderer renderer, final @NotNull Component message, final @NotNull Component originalMessage) {
+ super(false, player, viewers, renderer, message, originalMessage);
+ }
+
+ @NotNull
+ @Override
+ public HandlerList getHandlers() {
+ return HANDLERS;
+ }
+
+ @NotNull
+ public static HandlerList getHandlerList() {
+ return HANDLERS;
+ }
+}
diff --git a/src/main/java/io/papermc/paper/text/PaperComponents.java b/src/main/java/io/papermc/paper/text/PaperComponents.java
new file mode 100644
index 0000000000000000000000000000000000000000..77db592d05b754f879f8d1790642e9d9bbd30a4e
--- /dev/null
+++ b/src/main/java/io/papermc/paper/text/PaperComponents.java
@@ -0,0 +1,88 @@
+package io.papermc.paper.text;
+
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.flattener.ComponentFlattener;
+import net.kyori.adventure.text.format.NamedTextColor;
+import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
+import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
+import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer;
+import org.bukkit.Bukkit;
+import org.checkerframework.checker.nullness.qual.NonNull;
+
+/**
+ * Paper API-specific methods for working with {@link Component}s and related.
+ */
+public final class PaperComponents {
+ private PaperComponents() {
+ throw new RuntimeException("PaperComponents is not to be instantiated!");
+ }
+
+ /**
+ * Return a component flattener that can use game data to resolve extra information about components.
+ *
+ * @return a component flattener
+ */
+ public static @NonNull ComponentFlattener flattener() {
+ return Bukkit.getUnsafe().componentFlattener();
+ }
+
+ /**
+ * Get a serializer for {@link Component}s that will convert components to
+ * a plain-text string.
+ *
+ * <p>Implementations may provide a serializer capable of processing any
+ * information that requires access to implementation details.</p>
+ *
+ * @return a serializer to plain text
+ */
+ public static @NonNull PlainComponentSerializer plainSerializer() {
+ return Bukkit.getUnsafe().plainComponentSerializer();
+ }
+
+ /**
+ * Get a serializer for {@link Component}s that will convert to and from the
+ * standard JSON serialization format using Gson.
+ *
+ * <p>Implementations may provide a serializer capable of processing any
+ * information that requires implementation details, such as legacy
+ * (pre-1.16) hover events.</p>
+ *
+ * @return a json component serializer
+ */
+ public static @NonNull GsonComponentSerializer gsonSerializer() {
+ return Bukkit.getUnsafe().gsonComponentSerializer();
+ }
+
+ /**
+ * Get a serializer for {@link Component}s that will convert to and from the
+ * standard JSON serialization format using Gson, downsampling any RGB colors
+ * to their nearest {@link NamedTextColor} counterpart.
+ *
+ * <p>Implementations may provide a serializer capable of processing any
+ * information that requires implementation details, such as legacy
+ * (pre-1.16) hover events.</p>
+ *
+ * @return a json component serializer
+ */
+ public static @NonNull GsonComponentSerializer colorDownsamplingGsonSerializer() {
+ return Bukkit.getUnsafe().colorDownsamplingGsonComponentSerializer();
+ }
+
+ /**
+ * Get a serializer for {@link Component}s that will convert to and from the
+ * legacy component format used by Bukkit. This serializer uses the
+ * {@link LegacyComponentSerializer.Builder#useUnusualXRepeatedCharacterHexFormat()}
+ * option to match upstream behavior.
+ *
+ * <p>This legacy serializer uses the standard section symbol to mark
+ * formatting characters.</p>
+ *
+ * <p>Implementations may provide a serializer capable of processing any
+ * information that requires access to implementation details.</p>
+ *
+ * @return a section serializer
+ */
+ public static @NonNull LegacyComponentSerializer legacySectionSerializer() {
+ return Bukkit.getUnsafe().legacyComponentSerializer();
+ }
+}
diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
index 05595fea641dbbc3d5eefb262731faad5bdb7965..cc208227301b30c3717516ceb9529ca6cb2fd0de 100644
--- a/src/main/java/org/bukkit/Bukkit.java
+++ b/src/main/java/org/bukkit/Bukkit.java
@@ -302,7 +302,9 @@ public final class Bukkit {
*
* @param message the message
* @return the number of players
+ * @deprecated in favour of {@link Server#broadcast(net.kyori.adventure.text.Component)}
*/
+ @Deprecated // Paper
public static int broadcastMessage(@NotNull String message) {
return server.broadcastMessage(message);
}
@@ -860,6 +862,19 @@ public final class Bukkit {
server.shutdown();
}
+ // Paper start
+ /**
+ * Broadcast a message to all players.
+ * <p>
+ * This is the same as calling {@link #broadcast(net.kyori.adventure.text.Component,
+ * java.lang.String)} with the {@link Server#BROADCAST_CHANNEL_USERS} permission.
+ *
+ * @param message the message
+ * @return the number of players
+ */
+ public static int broadcast(@NotNull net.kyori.adventure.text.Component message) {
+ return server.broadcast(message);
+ }
/**
* Broadcasts the specified message to every user with the given
* permission name.
@@ -869,6 +884,21 @@ public final class Bukkit {
* permissibles} must have to receive the broadcast
* @return number of message recipients
*/
+ public static int broadcast(@NotNull net.kyori.adventure.text.Component message, @NotNull String permission) {
+ return server.broadcast(message, permission);
+ }
+ // Paper end
+ /**
+ * Broadcasts the specified message to every user with the given
+ * permission name.
+ *
+ * @param message message to broadcast
+ * @param permission the required permission {@link Permissible
+ * permissibles} must have to receive the broadcast
+ * @return number of message recipients
+ * @deprecated in favour of {@link #broadcast(net.kyori.adventure.text.Component, String)}
+ */
+ @Deprecated // Paper
public static int broadcast(@NotNull String message, @NotNull String permission) {
return server.broadcast(message, permission);
}
@@ -1068,6 +1098,7 @@ public final class Bukkit {
return server.createInventory(owner, type);
}
+ // Paper start
/**
* Creates an empty inventory with the specified type and title. If the type
* is {@link InventoryType#CHEST}, the new inventory has a size of 27;
@@ -1093,6 +1124,38 @@ public final class Bukkit {
* @see InventoryType#isCreatable()
*/
@NotNull
+ public static Inventory createInventory(@Nullable InventoryHolder owner, @NotNull InventoryType type, @NotNull net.kyori.adventure.text.Component title) {
+ return server.createInventory(owner, type, title);
+ }
+ // Paper end
+
+ /**
+ * Creates an empty inventory with the specified type and title. If the type
+ * is {@link InventoryType#CHEST}, the new inventory has a size of 27;
+ * otherwise the new inventory has the normal size for its type.<br>
+ * It should be noted that some inventory types do not support titles and
+ * may not render with said titles on the Minecraft client.
+ * <br>
+ * {@link InventoryType#WORKBENCH} will not process crafting recipes if
+ * created with this method. Use
+ * {@link Player#openWorkbench(Location, boolean)} instead.
+ * <br>
+ * {@link InventoryType#ENCHANTING} will not process {@link ItemStack}s
+ * for possible enchanting results. Use
+ * {@link Player#openEnchanting(Location, boolean)} instead.
+ *
+ * @param owner The holder of the inventory; can be null if there's no holder.
+ * @param type The type of inventory to create.
+ * @param title The title of the inventory, to be displayed when it is viewed.
+ * @return The new inventory.
+ * @throws IllegalArgumentException if the {@link InventoryType} cannot be
+ * viewed.
+ * @deprecated in favour of {@link #createInventory(InventoryHolder, InventoryType, net.kyori.adventure.text.Component)}
+ *
+ * @see InventoryType#isCreatable()
+ */
+ @Deprecated // Paper
+ @NotNull
public static Inventory createInventory(@Nullable InventoryHolder owner, @NotNull InventoryType type, @NotNull String title) {
return server.createInventory(owner, type, title);
}
@@ -1111,6 +1174,7 @@ public final class Bukkit {
return server.createInventory(owner, size);
}
+ // Paper start
/**
* Creates an empty inventory of type {@link InventoryType#CHEST} with the
* specified size and title.
@@ -1123,10 +1187,30 @@ public final class Bukkit {
* @throws IllegalArgumentException if the size is not a multiple of 9
*/
@NotNull
+ public static Inventory createInventory(@Nullable InventoryHolder owner, int size, @NotNull net.kyori.adventure.text.Component title) throws IllegalArgumentException {
+ return server.createInventory(owner, size, title);
+ }
+ // Paper end
+
+ /**
+ * Creates an empty inventory of type {@link InventoryType#CHEST} with the
+ * specified size and title.
+ *
+ * @param owner the holder of the inventory, or null to indicate no holder
+ * @param size a multiple of 9 as the size of inventory to create
+ * @param title the title of the inventory, displayed when inventory is
+ * viewed
+ * @return a new inventory
+ * @throws IllegalArgumentException if the size is not a multiple of 9
+ * @deprecated in favour of {@link #createInventory(InventoryHolder, InventoryType, net.kyori.adventure.text.Component)}
+ */
+ @Deprecated // Paper
+ @NotNull
public static Inventory createInventory(@Nullable InventoryHolder owner, int size, @NotNull String title) throws IllegalArgumentException {
return server.createInventory(owner, size, title);
}
+ // Paper start
/**
* Creates an empty merchant.
*
@@ -1134,7 +1218,20 @@ public final class Bukkit {
* when the merchant inventory is viewed
* @return a new merchant
*/
+ public static @NotNull Merchant createMerchant(@Nullable net.kyori.adventure.text.Component title) {
+ return server.createMerchant(title);
+ }
+ // Paper start
+ /**
+ * Creates an empty merchant.
+ *
+ * @param title the title of the corresponding merchant inventory, displayed
+ * when the merchant inventory is viewed
+ * @return a new merchant
+ * @deprecated in favour of {@link #createMerchant(net.kyori.adventure.text.Component)}
+ */
@NotNull
+ @Deprecated // Paper
public static Merchant createMerchant(@Nullable String title) {
return server.createMerchant(title);
}
@@ -1205,22 +1302,47 @@ public final class Bukkit {
return server.isPrimaryThread();
}
+ // Paper start
+ /**
+ * Gets the message that is displayed on the server list.
+ *
+ * @return the server's MOTD
+ */
+ @NotNull public static net.kyori.adventure.text.Component motd() {
+ return server.motd();
+ }
+ // Paper end
+
/**
* Gets the message that is displayed on the server list.
*
* @return the servers MOTD
+ * @deprecated in favour of {@link #motd()}
*/
@NotNull
+ @Deprecated // Paper
public static String getMotd() {
return server.getMotd();
}
+ // Paper start
+ /**
+ * Gets the default message that is displayed when the server is stopped.
+ *
+ * @return the shutdown message
+ */
+ public static @Nullable net.kyori.adventure.text.Component shutdownMessage() {
+ return server.shutdownMessage();
+ }
+ // Paper end
/**
* Gets the default message that is displayed when the server is stopped.
*
* @return the shutdown message
+ * @deprecated in favour of {@link #shutdownMessage()}
*/
@Nullable
+ @Deprecated // Paper
public static String getShutdownMessage() {
return server.getShutdownMessage();
}
diff --git a/src/main/java/org/bukkit/Nameable.java b/src/main/java/org/bukkit/Nameable.java
index fee814e01a653d2b53c56e8b566383ca44aa5346..2acdf2a6d3955923c721222b9da784f3278f6418 100644
--- a/src/main/java/org/bukkit/Nameable.java
+++ b/src/main/java/org/bukkit/Nameable.java
@@ -4,6 +4,30 @@ import org.jetbrains.annotations.Nullable;
public interface Nameable {
+ // Paper start
+ /**
+ * Gets the custom name.
+ *
+ * <p>This value has no effect on players, they will always use their real name.</p>
+ *
+ * @return the custom name
+ */
+ @Nullable net.kyori.adventure.text.Component customName();
+
+ /**
+ * Sets the custom name.
+ *
+ * <p>This name will be used in death messages and can be sent to the client as a nameplate over the mob.</p>
+ *
+ * <p>Setting the name to {@code null} will clear it.</p>
+ *
+ * <p>This value has no effect on players, they will always use their real name.</p>
+ *
+ * @param customName the custom name to set
+ */
+ void customName(final @Nullable net.kyori.adventure.text.Component customName);
+ // Paper end
+
/**
* Gets the custom name on a mob or block. If there is no name this method
* will return null.
diff --git a/src/main/java/org/bukkit/NamespacedKey.java b/src/main/java/org/bukkit/NamespacedKey.java
index 803fa0019869127ee8c7e4fb1777a59c43e66f8a..c65f0d6569c130b4920a9e71ad24af6427f1f030 100644
--- a/src/main/java/org/bukkit/NamespacedKey.java
+++ b/src/main/java/org/bukkit/NamespacedKey.java
@@ -19,7 +19,7 @@ import org.jetbrains.annotations.Nullable;
* underscores, hyphens, and forward slashes.
*
*/
-public final class NamespacedKey {
+public final class NamespacedKey implements net.kyori.adventure.key.Key { // Paper - implement Key
/**
* The namespace representing all inbuilt keys.
@@ -212,4 +212,24 @@ public final class NamespacedKey {
public static NamespacedKey fromString(@NotNull String key) {
return fromString(key, null);
}
+
+ // Paper start
+ @NotNull
+ @Override
+ public String namespace() {
+ return this.getNamespace();
+ }
+
+ @NotNull
+ @Override
+ public String value() {
+ return this.getKey();
+ }
+
+ @NotNull
+ @Override
+ public String asString() {
+ return this.namespace + ':' + this.key;
+ }
+ // Paper end
}
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
index bc4c4b6a10726347649a9232ee8ede28c967b8f4..cb0f365c4829f382a8fef8c176b7ea4028cac876 100644
--- a/src/main/java/org/bukkit/Server.java
+++ b/src/main/java/org/bukkit/Server.java
@@ -55,13 +55,13 @@ import org.jetbrains.annotations.Nullable;
/**
* Represents a server implementation.
*/
-public interface Server extends PluginMessageRecipient {
+public interface Server extends PluginMessageRecipient, net.kyori.adventure.audience.ForwardingAudience { // Paper
/**
* Used for all administrative messages, such as an operator using a
* command.
* <p>
- * For use in {@link #broadcast(java.lang.String, java.lang.String)}.
+ * For use in {@link #broadcast(net.kyori.adventure.text.Component, java.lang.String)}.
*/
public static final String BROADCAST_CHANNEL_ADMINISTRATIVE = "bukkit.broadcast.admin";
@@ -69,7 +69,7 @@ public interface Server extends PluginMessageRecipient {
* Used for all announcement messages, such as informing users that a
* player has joined.
* <p>
- * For use in {@link #broadcast(java.lang.String, java.lang.String)}.
+ * For use in {@link #broadcast(net.kyori.adventure.text.Component, java.lang.String)}.
*/
public static final String BROADCAST_CHANNEL_USERS = "bukkit.broadcast.user";
@@ -249,7 +249,9 @@ public interface Server extends PluginMessageRecipient {
*
* @param message the message
* @return the number of players
+ * @deprecated use {@link #broadcast(net.kyori.adventure.text.Component)}
*/
+ @Deprecated // Paper
public int broadcastMessage(@NotNull String message);
/**
@@ -723,8 +725,33 @@ public interface Server extends PluginMessageRecipient {
* @param permission the required permission {@link Permissible
* permissibles} must have to receive the broadcast
* @return number of message recipients
+ * @deprecated in favour of {@link #broadcast(net.kyori.adventure.text.Component, String)}
*/
+ @Deprecated // Paper
public int broadcast(@NotNull String message, @NotNull String permission);
+ // Paper start
+ /**
+ * Broadcast a message to all players.
+ * <p>
+ * This is the same as calling {@link #broadcast(net.kyori.adventure.text.Component,
+ * java.lang.String)} with the {@link #BROADCAST_CHANNEL_USERS} permission.
+ *
+ * @param message the message
+ * @return the number of players
+ */
+ int broadcast(@NotNull net.kyori.adventure.text.Component message);
+
+ /**
+ * Broadcasts the specified message to every user with the given
+ * permission name.
+ *
+ * @param message message to broadcast
+ * @param permission the required permission {@link Permissible
+ * permissibles} must have to receive the broadcast
+ * @return number of message recipients
+ */
+ int broadcast(@NotNull net.kyori.adventure.text.Component message, @NotNull String permission);
+ // Paper end
/**
* Gets the player by the given name, regardless if they are offline or
@@ -889,6 +916,7 @@ public interface Server extends PluginMessageRecipient {
@NotNull
Inventory createInventory(@Nullable InventoryHolder owner, @NotNull InventoryType type);
+ // Paper start
/**
* Creates an empty inventory with the specified type and title. If the type
* is {@link InventoryType#CHEST}, the new inventory has a size of 27;
@@ -914,6 +942,36 @@ public interface Server extends PluginMessageRecipient {
* @see InventoryType#isCreatable()
*/
@NotNull
+ Inventory createInventory(@Nullable InventoryHolder owner, @NotNull InventoryType type, @NotNull net.kyori.adventure.text.Component title);
+ // Paper end
+
+ /**
+ * Creates an empty inventory with the specified type and title. If the type
+ * is {@link InventoryType#CHEST}, the new inventory has a size of 27;
+ * otherwise the new inventory has the normal size for its type.<br>
+ * It should be noted that some inventory types do not support titles and
+ * may not render with said titles on the Minecraft client.
+ * <br>
+ * {@link InventoryType#WORKBENCH} will not process crafting recipes if
+ * created with this method. Use
+ * {@link Player#openWorkbench(Location, boolean)} instead.
+ * <br>
+ * {@link InventoryType#ENCHANTING} will not process {@link ItemStack}s
+ * for possible enchanting results. Use
+ * {@link Player#openEnchanting(Location, boolean)} instead.
+ *
+ * @param owner The holder of the inventory; can be null if there's no holder.
+ * @param type The type of inventory to create.
+ * @param title The title of the inventory, to be displayed when it is viewed.
+ * @return The new inventory.
+ * @throws IllegalArgumentException if the {@link InventoryType} cannot be
+ * viewed.
+ * @deprecated in favour of {@link #createInventory(InventoryHolder, InventoryType, net.kyori.adventure.text.Component)}
+ *
+ * @see InventoryType#isCreatable()
+ */
+ @Deprecated // Paper
+ @NotNull
Inventory createInventory(@Nullable InventoryHolder owner, @NotNull InventoryType type, @NotNull String title);
/**
@@ -928,6 +986,22 @@ public interface Server extends PluginMessageRecipient {
@NotNull
Inventory createInventory(@Nullable InventoryHolder owner, int size) throws IllegalArgumentException;
+ // Paper start
+ /**
+ * Creates an empty inventory of type {@link InventoryType#CHEST} with the
+ * specified size and title.
+ *
+ * @param owner the holder of the inventory, or null to indicate no holder
+ * @param size a multiple of 9 as the size of inventory to create
+ * @param title the title of the inventory, displayed when inventory is
+ * viewed
+ * @return a new inventory
+ * @throws IllegalArgumentException if the size is not a multiple of 9
+ */
+ @NotNull
+ Inventory createInventory(@Nullable InventoryHolder owner, int size, @NotNull net.kyori.adventure.text.Component title) throws IllegalArgumentException;
+ // Paper end
+
/**
* Creates an empty inventory of type {@link InventoryType#CHEST} with the
* specified size and title.
@@ -938,10 +1012,13 @@ public interface Server extends PluginMessageRecipient {
* viewed
* @return a new inventory
* @throws IllegalArgumentException if the size is not a multiple of 9
+ * @deprecated in favour of {@link #createInventory(InventoryHolder, int, net.kyori.adventure.text.Component)}
*/
+ @Deprecated // Paper
@NotNull
Inventory createInventory(@Nullable InventoryHolder owner, int size, @NotNull String title) throws IllegalArgumentException;
+ // Paper start
/**
* Creates an empty merchant.
*
@@ -949,7 +1026,18 @@ public interface Server extends PluginMessageRecipient {
* when the merchant inventory is viewed
* @return a new merchant
*/
+ @NotNull Merchant createMerchant(@Nullable net.kyori.adventure.text.Component title);
+ // Paper start
+ /**
+ * Creates an empty merchant.
+ *
+ * @param title the title of the corresponding merchant inventory, displayed
+ * when the merchant inventory is viewed
+ * @return a new merchant
+ * @deprecated in favour of {@link #createMerchant(net.kyori.adventure.text.Component)}
+ */
@NotNull
+ @Deprecated // Paper
Merchant createMerchant(@Nullable String title);
/**
@@ -1006,20 +1094,41 @@ public interface Server extends PluginMessageRecipient {
*/
boolean isPrimaryThread();
+ // Paper start
+ /**
+ * Gets the message that is displayed on the server list.
+ *
+ * @return the server's MOTD
+ */
+ @NotNull net.kyori.adventure.text.Component motd();
+ // Paper end
+
/**
* Gets the message that is displayed on the server list.
*
* @return the servers MOTD
+ * @deprecated in favour of {@link #motd()}
*/
@NotNull
+ @Deprecated // Paper
String getMotd();
+ // Paper start
+ /**
+ * Gets the default message that is displayed when the server is stopped.
+ *
+ * @return the shutdown message
+ */
+ @Nullable net.kyori.adventure.text.Component shutdownMessage();
+ // Paper end
/**
* Gets the default message that is displayed when the server is stopped.
*
* @return the shutdown message
+ * @deprecated in favour of {@link #shutdownMessage()}
*/
@Nullable
+ @Deprecated // Paper
String getShutdownMessage();
/**
@@ -1388,7 +1497,9 @@ public interface Server extends PluginMessageRecipient {
* Sends the component to the player
*
* @param component the components to send
+ * @deprecated use {@link #broadcast(net.kyori.adventure.text.Component)}
*/
+ @Deprecated // Paper
public void broadcast(@NotNull net.md_5.bungee.api.chat.BaseComponent component) {
throw new UnsupportedOperationException("Not supported yet.");
}
@@ -1397,7 +1508,9 @@ public interface Server extends PluginMessageRecipient {
* Sends an array of components as a single message to the player
*
* @param components the components to send
+ * @deprecated use {@link #broadcast(net.kyori.adventure.text.Component)}
*/
+ @Deprecated // Paper
public void broadcast(@NotNull net.md_5.bungee.api.chat.BaseComponent... components) {
throw new UnsupportedOperationException("Not supported yet.");
}
diff --git a/src/main/java/org/bukkit/Sound.java b/src/main/java/org/bukkit/Sound.java
index 2c8cc0c2af4741df9ae594ab9c436dea5347167c..445b6bf18e6ee26fe6cafca8cf5f1775bcd72d1e 100644
--- a/src/main/java/org/bukkit/Sound.java
+++ b/src/main/java/org/bukkit/Sound.java
@@ -10,7 +10,7 @@ import org.jetbrains.annotations.NotNull;
* guarantee values will not be removed from this Enum. As such, you should not
* depend on the ordinal values of this class.
*/
-public enum Sound implements Keyed {
+public enum Sound implements Keyed, net.kyori.adventure.sound.Sound.Type { // Paper - implement Sound.Type
AMBIENT_BASALT_DELTAS_ADDITIONS("ambient.basalt_deltas.additions"),
AMBIENT_BASALT_DELTAS_LOOP("ambient.basalt_deltas.loop"),
@@ -1214,4 +1214,12 @@ public enum Sound implements Keyed {
public NamespacedKey getKey() {
return key;
}
+
+ // Paper start
+ @NotNull
+ @Override
+ public net.kyori.adventure.key.@org.checkerframework.checker.nullness.qual.NonNull Key key() {
+ return this.key;
+ }
+ // Paper end
}
diff --git a/src/main/java/org/bukkit/SoundCategory.java b/src/main/java/org/bukkit/SoundCategory.java
index ac5e263d737973af077e3406a84a84baca4370db..2d91924b7f5ef16a91d40cdc1bfc3d68e0fda38d 100644
--- a/src/main/java/org/bukkit/SoundCategory.java
+++ b/src/main/java/org/bukkit/SoundCategory.java
@@ -3,7 +3,7 @@ package org.bukkit;
/**