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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com>
Date: Mon, 1 Aug 2022 22:50:29 -0400
Subject: [PATCH] Brigadier based command API
Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
diff --git a/build.gradle.kts b/build.gradle.kts
index 76aa23da778b0fe8a093429c56cb29b044359b40..ab84a1405acc1f0d5f267892243b82b8dab03e21 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -27,6 +27,7 @@ configurations.api {
}
dependencies {
+ api("com.mojang:brigadier:1.2.9") // Paper - Brigadier command api
// api dependencies are listed transitively to API consumers
api("com.google.guava:guava:32.1.2-jre")
api("com.google.code.gson:gson:2.10.1")
@@ -93,9 +94,29 @@ sourceSets {
}
}
// Paper end
+// Paper start - brigadier API
+val outgoingVariants = arrayOf("runtimeElements", "apiElements", "sourcesElements", "javadocElements")
+configurations {
+ val outgoing = outgoingVariants.map { named(it) }
+ for (config in outgoing) {
+ config {
+ outgoing {
+ capability("${project.group}:${project.name}:${project.version}")
+ capability("io.papermc.paper:paper-mojangapi:${project.version}")
+ capability("com.destroystokyo.paper:paper-mojangapi:${project.version}")
+ }
+ }
+ }
+}
+// Paper end
configure<PublishingExtension> {
publications.create<MavenPublication>("maven") {
+ // Paper start - brigadier API
+ outgoingVariants.forEach {
+ suppressPomMetadataWarningsFor(it)
+ }
+ // Paper end
from(components["java"])
}
}
diff --git a/src/main/java/com/destroystokyo/paper/brigadier/BukkitBrigadierCommand.java b/src/main/java/com/destroystokyo/paper/brigadier/BukkitBrigadierCommand.java
new file mode 100644
index 0000000000000000000000000000000000000000..03a1078446f84b998cd7fe8d64abecb2e36bab0a
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/brigadier/BukkitBrigadierCommand.java
@@ -0,0 +1,16 @@
+package com.destroystokyo.paper.brigadier;
+
+import com.mojang.brigadier.Command;
+import com.mojang.brigadier.suggestion.SuggestionProvider;
+
+import java.util.function.Predicate;
+
+/**
+ * Brigadier {@link Command}, {@link SuggestionProvider}, and permission checker for Bukkit {@link Command}s.
+ *
+ * @param <S> command source type
+ * @deprecated For removal, see {@link io.papermc.paper.command.brigadier.Commands} on how to use the new Brigadier API.
+ */
+@Deprecated(forRemoval = true, since = "1.20.6")
+public interface BukkitBrigadierCommand <S extends BukkitBrigadierCommandSource> extends Command<S>, Predicate<S>, SuggestionProvider<S> {
+}
diff --git a/src/main/java/com/destroystokyo/paper/brigadier/BukkitBrigadierCommandSource.java b/src/main/java/com/destroystokyo/paper/brigadier/BukkitBrigadierCommandSource.java
new file mode 100644
index 0000000000000000000000000000000000000000..28b44789e3be586c4b680fff56e5d2ff095f9ac2
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/brigadier/BukkitBrigadierCommandSource.java
@@ -0,0 +1,25 @@
+package com.destroystokyo.paper.brigadier;
+
+import org.bukkit.Location;
+import org.bukkit.World;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Entity;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * @deprecated For removal, see {@link io.papermc.paper.command.brigadier.Commands} on how to use the new Brigadier API.
+ */
+@Deprecated(forRemoval = true)
+public interface BukkitBrigadierCommandSource {
+
+ @Nullable
+ Entity getBukkitEntity();
+
+ @Nullable
+ World getBukkitWorld();
+
+ @Nullable
+ Location getBukkitLocation();
+
+ CommandSender getBukkitSender();
+}
diff --git a/src/main/java/com/destroystokyo/paper/event/brigadier/AsyncPlayerSendCommandsEvent.java b/src/main/java/com/destroystokyo/paper/event/brigadier/AsyncPlayerSendCommandsEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..9e1b70d438c4341ec944503b5bbe6b1f08bc0478
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/event/brigadier/AsyncPlayerSendCommandsEvent.java
@@ -0,0 +1,73 @@
+package com.destroystokyo.paper.event.brigadier;
+
+import com.mojang.brigadier.tree.RootCommandNode;
+import io.papermc.paper.command.brigadier.CommandSourceStack;
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.player.PlayerEvent;
+import org.jetbrains.annotations.ApiStatus;
+import org.jspecify.annotations.NullMarked;
+
+/**
+ * Fired any time a Brigadier RootCommandNode is generated for a player to inform the client of commands.
+ * You may manipulate this CommandNode to change what the client sees.
+ *
+ * <p>This event may fire on login, world change, and permission rebuilds, by plugin request, and potentially future means.</p>
+ *
+ * <p>This event will fire before {@link org.bukkit.event.player.PlayerCommandSendEvent}, so no filtering has been done by
+ * other plugins yet.</p>
+ *
+ * <p>WARNING: This event will potentially (and most likely) fire twice! Once for Async, and once again for Sync.
+ * It is important that you check event.isAsynchronous() and event.hasFiredAsync() to ensure you only act once.
+ * If for some reason we are unable to send this asynchronously in the future, only the sync method will fire.</p>
+ *
+ * <p>Your logic should look like this:
+ * {@code if (event.isAsynchronous() || !event.hasFiredAsync()) { // do stuff }}</p>
+ *
+ * <p>If your logic is not safe to run asynchronously, only react to the synchronous version.</p>
+ *
+ * <p>This is a draft/experimental API and is subject to change.</p>
+ */
+@ApiStatus.Experimental
+@NullMarked
+public class AsyncPlayerSendCommandsEvent<S extends CommandSourceStack> extends PlayerEvent {
+
+ private static final HandlerList HANDLER_LIST = new HandlerList();
+ private final RootCommandNode<S> node;
+ private final boolean hasFiredAsync;
+
+ @ApiStatus.Internal
+ public AsyncPlayerSendCommandsEvent(final Player player, final RootCommandNode<S> node, final boolean hasFiredAsync) {
+ super(player, !Bukkit.isPrimaryThread());
+ this.node = node;
+ this.hasFiredAsync = hasFiredAsync;
+ }
+
+ /**
+ * Gets the full Root Command Node being sent to the client, which is mutable.
+ *
+ * @return the root command node
+ */
+ public RootCommandNode<S> getCommandNode() {
+ return this.node;
+ }
+
+ /**
+ * Gets if this event has already fired asynchronously.
+ *
+ * @return whether this event has already fired asynchronously
+ */
+ public boolean hasFiredAsync() {
+ return this.hasFiredAsync;
+ }
+
+ @Override
+ public HandlerList getHandlers() {
+ return HANDLER_LIST;
+ }
+
+ public static HandlerList getHandlerList() {
+ return HANDLER_LIST;
+ }
+}
diff --git a/src/main/java/com/destroystokyo/paper/event/brigadier/AsyncPlayerSendSuggestionsEvent.java b/src/main/java/com/destroystokyo/paper/event/brigadier/AsyncPlayerSendSuggestionsEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..faade9d35514687f21a0e8b62fa2e392d4ad238a
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/event/brigadier/AsyncPlayerSendSuggestionsEvent.java
@@ -0,0 +1,85 @@
+package com.destroystokyo.paper.event.brigadier;
+
+import com.mojang.brigadier.suggestion.Suggestions;
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.player.PlayerEvent;
+import org.jetbrains.annotations.ApiStatus;
+import org.jspecify.annotations.NullMarked;
+
+/**
+ * Called when sending {@link Suggestions} to the client. Will be called asynchronously if a plugin
+ * marks the {@link com.destroystokyo.paper.event.server.AsyncTabCompleteEvent} event handled asynchronously,
+ * otherwise called synchronously.
+ */
+@NullMarked
+public class AsyncPlayerSendSuggestionsEvent extends PlayerEvent implements Cancellable {
+
+ private static final HandlerList HANDLER_LIST = new HandlerList();
+ private boolean cancelled = false;
+
+ private Suggestions suggestions;
+ private final String buffer;
+
+ @ApiStatus.Internal
+ public AsyncPlayerSendSuggestionsEvent(final Player player, final Suggestions suggestions, final String buffer) {
+ super(player, !Bukkit.isPrimaryThread());
+ this.suggestions = suggestions;
+ this.buffer = buffer;
+ }
+
+ /**
+ * Gets the input buffer sent to request these suggestions.
+ *
+ * @return the input buffer
+ */
+ public String getBuffer() {
+ return this.buffer;
+ }
+
+ /**
+ * Gets the suggestions to be sent to client.
+ *
+ * @return the suggestions
+ */
+ public Suggestions getSuggestions() {
+ return this.suggestions;
+ }
+
+ /**
+ * Sets the suggestions to be sent to client.
+ *
+ * @param suggestions suggestions
+ */
+ public void setSuggestions(final Suggestions suggestions) {
+ this.suggestions = suggestions;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isCancelled() {
+ return this.cancelled;
+ }
+
+ /**
+ * Cancels sending suggestions to the client.
+ * {@inheritDoc}
+ */
+ @Override
+ public void setCancelled(final boolean cancel) {
+ this.cancelled = cancel;
+ }
+
+ @Override
+ public HandlerList getHandlers() {
+ return HANDLER_LIST;
+ }
+
+ public static HandlerList getHandlerList() {
+ return HANDLER_LIST;
+ }
+}
diff --git a/src/main/java/com/destroystokyo/paper/event/brigadier/CommandRegisteredEvent.java b/src/main/java/com/destroystokyo/paper/event/brigadier/CommandRegisteredEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..acc2bd2ec56e64b9d4bd8677d99448a97ecb5201
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/event/brigadier/CommandRegisteredEvent.java
@@ -0,0 +1,171 @@
+package com.destroystokyo.paper.event.brigadier;
+
+import com.destroystokyo.paper.brigadier.BukkitBrigadierCommand;
+import com.mojang.brigadier.tree.ArgumentCommandNode;
+import com.mojang.brigadier.tree.LiteralCommandNode;
+import com.mojang.brigadier.tree.RootCommandNode;
+import org.bukkit.Warning;
+import org.bukkit.command.Command;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.server.ServerEvent;
+import org.jetbrains.annotations.ApiStatus;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Fired anytime the server synchronizes Bukkit commands to Brigadier.
+ *
+ * <p>Allows a plugin to control the command node structure for its commands.
+ * This is done at Plugin Enable time after commands have been registered, but may also
+ * run at a later point in the server lifetime due to plugins, a server reload, etc.</p>
+ *
+ * <p>This is a draft/experimental API and is subject to change.</p>
+ * @deprecated For removal, use the new brigadier api.
+ */
+@ApiStatus.Experimental
+@Deprecated(since = "1.20.6")
+@Warning(reason = "This event has been superseded by the Commands API and will be removed in a future release. Listen to LifecycleEvents.COMMANDS instead.", value = true)
+public class CommandRegisteredEvent<S extends com.destroystokyo.paper.brigadier.BukkitBrigadierCommandSource> extends ServerEvent implements Cancellable {
+
+ private static final HandlerList handlers = new HandlerList();
+ private final String commandLabel;
+ private final Command command;
+ private final com.destroystokyo.paper.brigadier.BukkitBrigadierCommand<S> brigadierCommand;
+ private final RootCommandNode<S> root;
+ private final ArgumentCommandNode<S, String> defaultArgs;
+ private LiteralCommandNode<S> literal;
+ private boolean rawCommand = false;
+ private boolean cancelled = false;
+
+ public CommandRegisteredEvent(String commandLabel, com.destroystokyo.paper.brigadier.BukkitBrigadierCommand<S> brigadierCommand, Command command, RootCommandNode<S> root, LiteralCommandNode<S> literal, ArgumentCommandNode<S, String> defaultArgs) {
+ this.commandLabel = commandLabel;
+ this.brigadierCommand = brigadierCommand;
+ this.command = command;
+ this.root = root;
+ this.literal = literal;
+ this.defaultArgs = defaultArgs;
+ }
+
+ /**
+ * Gets the command label of the {@link Command} being registered.
+ *
+ * @return the command label
+ */
+ public String getCommandLabel() {
+ return this.commandLabel;
+ }
+
+ /**
+ * Gets the {@link BukkitBrigadierCommand} for the {@link Command} being registered. This can be used
+ * as the {@link com.mojang.brigadier.Command command executor} or
+ * {@link com.mojang.brigadier.suggestion.SuggestionProvider} of a {@link com.mojang.brigadier.tree.CommandNode}
+ * to delegate to the {@link Command} being registered.
+ *
+ * @return the {@link BukkitBrigadierCommand}
+ */
+ public BukkitBrigadierCommand<S> getBrigadierCommand() {
+ return this.brigadierCommand;
+ }
+
+ /**
+ * Gets the {@link Command} being registered.
+ *
+ * @return the {@link Command}
+ */
+ public Command getCommand() {
+ return this.command;
+ }
+
+ /**
+ * Gets the {@link RootCommandNode} which is being registered to.
+ *
+ * @return the {@link RootCommandNode}
+ */
+ public RootCommandNode<S> getRoot() {
+ return this.root;
+ }
+
+ /**
+ * Gets the Bukkit APIs default arguments node (greedy string), for if
+ * you wish to reuse it.
+ *
+ * @return default arguments node
+ */
+ public ArgumentCommandNode<S, String> getDefaultArgs() {
+ return this.defaultArgs;
+ }
+
+ /**
+ * Gets the {@link LiteralCommandNode} to be registered for the {@link Command}.
+ *
+ * @return the {@link LiteralCommandNode}
+ */
+ public LiteralCommandNode<S> getLiteral() {
+ return this.literal;
+ }
+
+ /**
+ * Sets the {@link LiteralCommandNode} used to register this command. The default literal is mutable, so
+ * this is primarily if you want to completely replace the object.
+ *
+ * @param literal new node
+ */
+ public void setLiteral(LiteralCommandNode<S> literal) {
+ this.literal = literal;
+ }
+
+ /**
+ * Gets whether this command should is treated as "raw".
+ *
+ * @see #setRawCommand(boolean)
+ * @return whether this command is treated as "raw"
+ */
+ public boolean isRawCommand() {
+ return this.rawCommand;
+ }
+
+ /**
+ * Sets whether this command should be treated as "raw".
+ *
+ * <p>A "raw" command will only use the node provided by this event for
+ * sending the command tree to the client. For execution purposes, the default
+ * greedy string execution of a standard Bukkit {@link Command} is used.</p>
+ *
+ * <p>On older versions of Paper, this was the default and only behavior of this
+ * event.</p>
+ *
+ * @param rawCommand whether this command should be treated as "raw"
+ */
+ public void setRawCommand(final boolean rawCommand) {
+ this.rawCommand = rawCommand;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isCancelled() {
+ return this.cancelled;
+ }
+
+ /**
+ * Cancels registering this command to Brigadier, but will remain in Bukkit Command Map. Can be used to hide a
+ * command from all players.
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public void setCancelled(boolean cancel) {
+ this.cancelled = cancel;
+ }
+
+ @NotNull
+ public HandlerList getHandlers() {
+ return handlers;
+ }
+
+ @NotNull
+ public static HandlerList getHandlerList() {
+ return handlers;
+ }
+}
diff --git a/src/main/java/io/papermc/paper/brigadier/PaperBrigadier.java b/src/main/java/io/papermc/paper/brigadier/PaperBrigadier.java
new file mode 100644
index 0000000000000000000000000000000000000000..9df87708206e26167a2c4934deff7fc6f1657106
--- /dev/null
+++ b/src/main/java/io/papermc/paper/brigadier/PaperBrigadier.java
@@ -0,0 +1,47 @@
+package io.papermc.paper.brigadier;
+
+import com.mojang.brigadier.Message;
+import io.papermc.paper.command.brigadier.MessageComponentSerializer;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.ComponentLike;
+import net.kyori.adventure.text.TextComponent;
+import org.checkerframework.checker.nullness.qual.NonNull;
+
+/**
+ * Helper methods to bridge the gaps between Brigadier and Paper-MojangAPI.
+ * @deprecated for removal. See {@link MessageComponentSerializer} for a direct replacement of functionality found in
+ * this class.
+ * As a general entrypoint to brigadier on paper, see {@link io.papermc.paper.command.brigadier.Commands}.
+ */
+@Deprecated(forRemoval = true, since = "1.20.6")
+public final class PaperBrigadier {
+ private PaperBrigadier() {
+ throw new RuntimeException("PaperBrigadier is not to be instantiated!");
+ }
+
+ /**
+ * Create a new Brigadier {@link Message} from a {@link ComponentLike}.
+ *
+ * <p>Mostly useful for creating rich suggestion tooltips in combination with other Paper-MojangAPI APIs.</p>
+ *
+ * @param componentLike The {@link ComponentLike} to use for the {@link Message} contents
+ * @return A new Brigadier {@link Message}
+ */
+ public static @NonNull Message message(final @NonNull ComponentLike componentLike) {
+ return MessageComponentSerializer.message().serialize(componentLike.asComponent());
+ }
+
+ /**
+ * Create a new {@link Component} from a Brigadier {@link Message}.
+ *
+ * <p>If the {@link Message} was created from a {@link Component}, it will simply be
+ * converted back, otherwise a new {@link TextComponent} will be created with the
+ * content of {@link Message#getString()}</p>
+ *
+ * @param message The {@link Message} to create a {@link Component} from
+ * @return The created {@link Component}
+ */
+ public static @NonNull Component componentFromMessage(final @NonNull Message message) {
+ return MessageComponentSerializer.message().deserialize(message);
+ }
+}
diff --git a/src/main/java/io/papermc/paper/command/brigadier/BasicCommand.java b/src/main/java/io/papermc/paper/command/brigadier/BasicCommand.java
new file mode 100644
index 0000000000000000000000000000000000000000..c89d6c4c38e2390cb11ffba182f8741d3726cfd1
--- /dev/null
+++ b/src/main/java/io/papermc/paper/command/brigadier/BasicCommand.java
@@ -0,0 +1,62 @@
+package io.papermc.paper.command.brigadier;
+
+import java.util.Collection;
+import java.util.Collections;
+import org.bukkit.command.CommandSender;
+import org.jetbrains.annotations.ApiStatus;
+import org.jspecify.annotations.NullMarked;
+import org.jspecify.annotations.Nullable;
+
+/**
+ * Implementing this interface allows for easily creating "Bukkit-style" {@code String[] args} commands.
+ * The implementation handles converting the command to a representation compatible with Brigadier on registration, usually in the form of {@literal /commandlabel <greedy_string>}.
+ */
+@ApiStatus.Experimental
+@NullMarked
+@FunctionalInterface
+public interface BasicCommand {
+
+ /**
+ * Executes the command with the given {@link CommandSourceStack} and arguments.
+ *
+ * @param commandSourceStack the commandSourceStack of the command
+ * @param args the arguments of the command ignoring repeated spaces
+ */
+ @ApiStatus.OverrideOnly
+ void execute(CommandSourceStack commandSourceStack, String[] args);
+
+ /**
+ * Suggests possible completions for the given command {@link CommandSourceStack} and arguments.
+ *
+ * @param commandSourceStack the commandSourceStack of the command
+ * @param args the arguments of the command including repeated spaces
+ * @return a collection of suggestions
+ */
+ @ApiStatus.OverrideOnly
+ default Collection<String> suggest(final CommandSourceStack commandSourceStack, final String[] args) {
+ return Collections.emptyList();
+ }
+
+ /**
+ * Checks whether a command sender can receive and run the root command.
+ *
+ * @param sender the command sender trying to execute the command
+ * @return whether the command sender fulfills the root command requirement
+ * @see #permission()
+ */
+ @ApiStatus.OverrideOnly
+ default boolean canUse(final CommandSender sender) {
+ final String permission = this.permission();
+ return permission == null || sender.hasPermission(permission);
+ }
+
+ /**
+ * Returns the permission for the root command used in {@link #canUse(CommandSender)} by default.
+ *
+ * @return the permission for the root command used in {@link #canUse(CommandSender)}
+ */
+ @ApiStatus.OverrideOnly
+ default @Nullable String permission() {
+ return null;
+ }
+}
diff --git a/src/main/java/io/papermc/paper/command/brigadier/CommandRegistrationFlag.java b/src/main/java/io/papermc/paper/command/brigadier/CommandRegistrationFlag.java
new file mode 100644
index 0000000000000000000000000000000000000000..7e24babf746de474c8deec4b147e22031e8dadb2
--- /dev/null
+++ b/src/main/java/io/papermc/paper/command/brigadier/CommandRegistrationFlag.java
@@ -0,0 +1,14 @@
+package io.papermc.paper.command.brigadier;
+
+import org.jetbrains.annotations.ApiStatus;
+
+/**
+ * A {@link CommandRegistrationFlag} is used in {@link Commands} registration for internal purposes.
+ * <p>
+ * A command library may use this to achieve more specific customization on how their commands are registered.
+ * @apiNote Stability of these flags is not promised! This api is not intended for public use.
+ */
+@ApiStatus.Internal
+public enum CommandRegistrationFlag {
+ FLATTEN_ALIASES
+}
diff --git a/src/main/java/io/papermc/paper/command/brigadier/CommandSourceStack.java b/src/main/java/io/papermc/paper/command/brigadier/CommandSourceStack.java
new file mode 100644
index 0000000000000000000000000000000000000000..ac6f5b754a15e85ce09de4ed4cdee2044b45022c
--- /dev/null
+++ b/src/main/java/io/papermc/paper/command/brigadier/CommandSourceStack.java
@@ -0,0 +1,51 @@
+package io.papermc.paper.command.brigadier;
+
+import org.bukkit.Location;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Entity;
+import org.jetbrains.annotations.ApiStatus;
+import org.jspecify.annotations.NullMarked;
+import org.jspecify.annotations.Nullable;
+
+/**
+ * The command source type for Brigadier commands registered using Paper API.
+ * <p>
+ * While the general use case for CommandSourceStack is similar to that of {@link CommandSender}, it provides access to
+ * important additional context for the command execution.
+ * Specifically, commands such as {@literal /execute} may alter the location or executor of the source stack before
+ * passing it to another command.
+ * <p>The {@link CommandSender} returned by {@link #getSender()} may be a "no-op"
+ * instance of {@link CommandSender} in cases where the server either doesn't
+ * exist yet, or no specific sender is available. Methods on such a {@link CommandSender}
+ * will either have no effect or throw an {@link UnsupportedOperationException}.</p>
+ */
+@ApiStatus.Experimental
+@NullMarked
+@ApiStatus.NonExtendable
+public interface CommandSourceStack {
+
+ /**
+ * Gets the location that this command is being executed at.
+ *
+ * @return a cloned location instance.
+ */
+ Location getLocation();
+
+ /**
+ * Gets the command sender that executed this command.
+ * The sender of a command source stack is the one that initiated/triggered the execution of a command.
+ * It differs to {@link #getExecutor()} as the executor can be changed by a command, e.g. {@literal /execute}.
+ *
+ * @return the command sender instance
+ */
+ CommandSender getSender();
+
+ /**
+ * Gets the entity that executes this command.
+ * May not always be {@link #getSender()} as the executor of a command can be changed to a different entity
+ * than the one that triggered the command.
+ *
+ * @return entity that executes this command
+ */
+ @Nullable Entity getExecutor();
+}
diff --git a/src/main/java/io/papermc/paper/command/brigadier/Commands.java b/src/main/java/io/papermc/paper/command/brigadier/Commands.java
new file mode 100644
index 0000000000000000000000000000000000000000..e32559772a39af781d89de101b3f7483a339e317
--- /dev/null
+++ b/src/main/java/io/papermc/paper/command/brigadier/Commands.java
@@ -0,0 +1,267 @@
+package io.papermc.paper.command.brigadier;
+
+import com.mojang.brigadier.CommandDispatcher;
+import com.mojang.brigadier.arguments.ArgumentType;
+import com.mojang.brigadier.builder.LiteralArgumentBuilder;
+import com.mojang.brigadier.builder.RequiredArgumentBuilder;
+import com.mojang.brigadier.tree.LiteralCommandNode;
+import io.papermc.paper.plugin.bootstrap.BootstrapContext;
+import io.papermc.paper.plugin.bootstrap.PluginBootstrap;
+import io.papermc.paper.plugin.configuration.PluginMeta;
+import io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager;
+import io.papermc.paper.plugin.lifecycle.event.registrar.Registrar;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Set;
+import org.jetbrains.annotations.ApiStatus;
+import org.jetbrains.annotations.Unmodifiable;
+import org.jspecify.annotations.NullMarked;
+import org.jspecify.annotations.Nullable;
+
+/**
+ * The registrar for custom commands. Supports Brigadier commands and {@link BasicCommand}.
+ * <p>
+ * An example of a command being registered is below
+ * <pre>{@code
+ * class YourPluginClass extends JavaPlugin {
+ *
+ * @Override
+ * public void onEnable() {
+ * LifecycleEventManager<Plugin> manager = this.getLifecycleManager();
+ * manager.registerEventHandler(LifecycleEvents.COMMANDS, event -> {
+ * final Commands commands = event.registrar();
+ * commands.register(
+ * Commands.literal("new-command")
+ * .executes(ctx -> {
+ * ctx.getSource().getSender().sendPlainMessage("some message");
+ * return Command.SINGLE_SUCCESS;
+ * })
+ * .build(),
+ * "some bukkit help description string",
+ * List.of("an-alias")
+ * );
+ * });
+ * }
+ * }
+ * }</pre>
+ * <p>
+ * You can also register commands in {@link PluginBootstrap} by getting the {@link LifecycleEventManager} from
+ * {@link BootstrapContext}.
+ * Commands registered in the {@link PluginBootstrap} will be available for datapack's
+ * command function parsing.
+ * Note that commands registered via {@link PluginBootstrap} with the same literals as a vanilla command will override
+ * that command within all loaded datapacks.
+ * </p>
+ * <p>The {@code register} methods that <b>do not</b> have {@link PluginMeta} as a parameter will
+ * implicitly use the {@link PluginMeta} for the plugin that the {@link io.papermc.paper.plugin.lifecycle.event.handler.LifecycleEventHandler}
+ * was registered with.</p>
+ *
+ * @see io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents#COMMANDS
+ */
+@ApiStatus.Experimental
+@NullMarked
+@ApiStatus.NonExtendable
+public interface Commands extends Registrar {
+
+ /**
+ * Utility to create a literal command node builder with the correct generic.
+ *
+ * @param literal literal name
+ * @return a new builder instance
+ */
+ static LiteralArgumentBuilder<CommandSourceStack> literal(final String literal) {
+ return LiteralArgumentBuilder.literal(literal);
+ }
+
+ /**
+ * Utility to create a required argument builder with the correct generic.
+ *
+ * @param name the name of the argument
+ * @param argumentType the type of the argument
+ * @param <T> the generic type of the argument value
+ * @return a new required argument builder
+ */
+ static <T> RequiredArgumentBuilder<CommandSourceStack, T> argument(final String name, final ArgumentType<T> argumentType) {
+ return RequiredArgumentBuilder.argument(name, argumentType);
+ }
+
+ /**
+ * Gets the underlying {@link CommandDispatcher}.
+ *
+ * <p><b>Note:</b> This is a delicate API that must be used with care to ensure a consistent user experience.</p>
+ *
+ * <p>When registering commands, it should be preferred to use the {@link #register(PluginMeta, LiteralCommandNode, String, Collection) register methods}
+ * over directly registering to the dispatcher wherever possible.
+ * {@link #register(PluginMeta, LiteralCommandNode, String, Collection) Register methods} automatically handle
+ * command namespacing, command help, plugin association with commands, and more.</p>
+ *
+ * <p>Example use cases for this method <b>may</b> include:
+ * <ul>
+ * <li>Implementing integration between an external command framework and Paper (although {@link #register(PluginMeta, LiteralCommandNode, String, Collection) register methods} should still be preferred where possible)</li>
+ * <li>Registering new child nodes to an existing plugin command (for example an "addon" plugin to another plugin may want to do this)</li>
+ * <li>Retrieving existing command nodes to build redirects</li>
+ * </ul>
+ *
+ * @return the dispatcher instance
+ */
+ @ApiStatus.Experimental
+ CommandDispatcher<CommandSourceStack> getDispatcher();
+
+ /**
+ * Registers a command for the current plugin context.
+ *
+ * <p>Commands have certain overriding behavior:
+ * <ul>
+ * <li>Aliases will not override already existing commands (excluding namespaced ones)</li>
+ * <li>The main command/namespaced label will override already existing commands</li>
+ * </ul>
+ *
+ * @param node the built literal command node
+ * @return successfully registered root command labels (including aliases and namespaced variants)
+ */
+ default @Unmodifiable Set<String> register(final LiteralCommandNode<CommandSourceStack> node) {
+ return this.register(node, null, Collections.emptyList());
+ }
+
+ /**
+ * Registers a command for the current plugin context.
+ *
+ * <p>Commands have certain overriding behavior:
+ * <ul>
+ * <li>Aliases will not override already existing commands (excluding namespaced ones)</li>
+ * <li>The main command/namespaced label will override already existing commands</li>
+ * </ul>
+ *
+ * @param node the built literal command node
+ * @param description the help description for the root literal node
+ * @return successfully registered root command labels (including aliases and namespaced variants)
+ */
+ default @Unmodifiable Set<String> register(final LiteralCommandNode<CommandSourceStack> node, final @Nullable String description) {
+ return this.register(node, description, Collections.emptyList());
+ }
+
+ /**
+ * Registers a command for the current plugin context.
+ *
+ * <p>Commands have certain overriding behavior:
+ * <ul>
+ * <li>Aliases will not override already existing commands (excluding namespaced ones)</li>
+ * <li>The main command/namespaced label will override already existing commands</li>
+ * </ul>
+ *
+ * @param node the built literal command node
+ * @param aliases a collection of aliases to register the literal node's command to
+ * @return successfully registered root command labels (including aliases and namespaced variants)
+ */
+ default @Unmodifiable Set<String> register(final LiteralCommandNode<CommandSourceStack> node, final Collection<String> aliases) {
+ return this.register(node, null, aliases);
+ }
+
+ /**
+ * Registers a command for the current plugin context.
+ *
+ * <p>Commands have certain overriding behavior:
+ * <ul>
+ * <li>Aliases will not override already existing commands (excluding namespaced ones)</li>
+ * <li>The main command/namespaced label will override already existing commands</li>
+ * </ul>
+ *
+ * @param node the built literal command node
+ * @param description the help description for the root literal node
+ * @param aliases a collection of aliases to register the literal node's command to
+ * @return successfully registered root command labels (including aliases and namespaced variants)
+ */
+ @Unmodifiable Set<String> register(LiteralCommandNode<CommandSourceStack> node, @Nullable String description, Collection<String> aliases);
+
+ /**
+ * Registers a command for a plugin.
+ *
+ * <p>Commands have certain overriding behavior:
+ * <ul>
+ * <li>Aliases will not override already existing commands (excluding namespaced ones)</li>
+ * <li>The main command/namespaced label will override already existing commands</li>
+ * </ul>
+ *
+ * @param pluginMeta the owning plugin's meta
+ * @param node the built literal command node
+ * @param description the help description for the root literal node
+ * @param aliases a collection of aliases to register the literal node's command to
+ * @return successfully registered root command labels (including aliases and namespaced variants)
+ */
+ @Unmodifiable Set<String> register(PluginMeta pluginMeta, LiteralCommandNode<CommandSourceStack> node, @Nullable String description, Collection<String> aliases);
+
+ /**
+ * This allows configuring the registration of your command, which is not intended for public use.
+ * See {@link Commands#register(PluginMeta, LiteralCommandNode, String, Collection)} for more information.
+ *
+ * @param pluginMeta the owning plugin's meta
+ * @param node the built literal command node
+ * @param description the help description for the root literal node
+ * @param aliases a collection of aliases to register the literal node's command to
+ * @param flags a collection of registration flags that control registration behaviour.
+ * @return successfully registered root command labels (including aliases and namespaced variants)
+ *
+ * @apiNote This method is not guaranteed to be stable as it is not intended for public use.
+ * See {@link CommandRegistrationFlag} for a more indepth explanation of this method's use-case.
+ */
+ @ApiStatus.Internal
+ @Unmodifiable Set<String> registerWithFlags(PluginMeta pluginMeta, LiteralCommandNode<CommandSourceStack> node, @Nullable String description, Collection<String> aliases, Set<CommandRegistrationFlag> flags);
+
+ /**
+ * Registers a command under the same logic as {@link Commands#register(LiteralCommandNode, String, Collection)}.
+ *
+ * @param label the label of the to-be-registered command
+ * @param basicCommand the basic command instance to register
+ * @return successfully registered root command labels (including aliases and namespaced variants)
+ */
+ default @Unmodifiable Set<String> register(final String label, final BasicCommand basicCommand) {
+ return this.register(label, null, Collections.emptyList(), basicCommand);
+ }
+
+ /**
+ * Registers a command under the same logic as {@link Commands#register(LiteralCommandNode, String, Collection)}.
+ *
+ * @param label the label of the to-be-registered command
+ * @param description the help description for the root literal node
+ * @param basicCommand the basic command instance to register
+ * @return successfully registered root command labels (including aliases and namespaced variants)
+ */
+ default @Unmodifiable Set<String> register(final String label, final @Nullable String description, final BasicCommand basicCommand) {
+ return this.register(label, description, Collections.emptyList(), basicCommand);
+ }
+
+ /**
+ * Registers a command under the same logic as {@link Commands#register(LiteralCommandNode, String, Collection)}.
+ *
+ * @param label the label of the to-be-registered command
+ * @param aliases a collection of aliases to register the basic command under.
+ * @param basicCommand the basic command instance to register
+ * @return successfully registered root command labels (including aliases and namespaced variants)
+ */
+ default @Unmodifiable Set<String> register(final String label, final Collection<String> aliases, final BasicCommand basicCommand) {
+ return this.register(label, null, aliases, basicCommand);
+ }
+
+ /**
+ * Registers a command under the same logic as {@link Commands#register(LiteralCommandNode, String, Collection)}.
+ *
+ * @param label the label of the to-be-registered command
+ * @param description the help description for the root literal node
+ * @param aliases a collection of aliases to register the basic command under.
+ * @param basicCommand the basic command instance to register
+ * @return successfully registered root command labels (including aliases and namespaced variants)
+ */
+ @Unmodifiable Set<String> register(String label, @Nullable String description, Collection<String> aliases, BasicCommand basicCommand);
+
+ /**
+ * Registers a command under the same logic as {@link Commands#register(PluginMeta, LiteralCommandNode, String, Collection)}.
+ *
+ * @param pluginMeta the owning plugin's meta
+ * @param label the label of the to-be-registered command
+ * @param description the help description for the root literal node
+ * @param aliases a collection of aliases to register the basic command under.
+ * @param basicCommand the basic command instance to register
+ * @return successfully registered root command labels (including aliases and namespaced variants)
+ */
+ @Unmodifiable Set<String> register(PluginMeta pluginMeta, String label, @Nullable String description, Collection<String> aliases, BasicCommand basicCommand);
+}
diff --git a/src/main/java/io/papermc/paper/command/brigadier/MessageComponentSerializer.java b/src/main/java/io/papermc/paper/command/brigadier/MessageComponentSerializer.java
new file mode 100644
index 0000000000000000000000000000000000000000..19f3dc12426be09613a13b5889f77627a81305f4
--- /dev/null
+++ b/src/main/java/io/papermc/paper/command/brigadier/MessageComponentSerializer.java
@@ -0,0 +1,25 @@
+package io.papermc.paper.command.brigadier;
+
+import com.mojang.brigadier.Message;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.serializer.ComponentSerializer;
+import org.jetbrains.annotations.ApiStatus;
+import org.jspecify.annotations.NullMarked;
+
+/**
+ * A component serializer for converting between {@link Message} and {@link Component}.
+ */
+@ApiStatus.Experimental
+@NullMarked
+@ApiStatus.NonExtendable
+public interface MessageComponentSerializer extends ComponentSerializer<Component, Component, Message> {
+
+ /**
+ * A component serializer for converting between {@link Message} and {@link Component}.
+ *
+ * @return serializer instance
+ */
+ static MessageComponentSerializer message() {
+ return MessageComponentSerializerHolder.PROVIDER.orElseThrow();
+ }
+}
diff --git a/src/main/java/io/papermc/paper/command/brigadier/MessageComponentSerializerHolder.java b/src/main/java/io/papermc/paper/command/brigadier/MessageComponentSerializerHolder.java
new file mode 100644
index 0000000000000000000000000000000000000000..2db12952461c92a64505d6646f6f49f824e83050
--- /dev/null
+++ b/src/main/java/io/papermc/paper/command/brigadier/MessageComponentSerializerHolder.java
@@ -0,0 +1,12 @@
+package io.papermc.paper.command.brigadier;
+
+import java.util.Optional;
+import java.util.ServiceLoader;
+import org.jetbrains.annotations.ApiStatus;
+
+@ApiStatus.Internal
+final class MessageComponentSerializerHolder {
+
+ static final Optional<MessageComponentSerializer> PROVIDER = ServiceLoader.load(MessageComponentSerializer.class)
+ .findFirst();
+}
diff --git a/src/main/java/io/papermc/paper/command/brigadier/argument/ArgumentTypes.java b/src/main/java/io/papermc/paper/command/brigadier/argument/ArgumentTypes.java
new file mode 100644
index 0000000000000000000000000000000000000000..9abb9ff33672036bb548c688c5661dc8f237aae2
--- /dev/null
+++ b/src/main/java/io/papermc/paper/command/brigadier/argument/ArgumentTypes.java
@@ -0,0 +1,371 @@
+package io.papermc.paper.command.brigadier.argument;
+
+import com.mojang.brigadier.arguments.ArgumentType;
+import io.papermc.paper.command.brigadier.argument.predicate.ItemStackPredicate;
+import io.papermc.paper.command.brigadier.argument.range.DoubleRangeProvider;
+import io.papermc.paper.command.brigadier.argument.range.IntegerRangeProvider;
+import io.papermc.paper.command.brigadier.argument.resolvers.BlockPositionResolver;
+import io.papermc.paper.command.brigadier.argument.resolvers.FinePositionResolver;
+import io.papermc.paper.command.brigadier.argument.resolvers.PlayerProfileListResolver;
+import io.papermc.paper.command.brigadier.argument.resolvers.selector.EntitySelectorArgumentResolver;
+import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
+import io.papermc.paper.entity.LookAnchor;
+import io.papermc.paper.registry.RegistryKey;
+import io.papermc.paper.registry.TypedKey;
+import java.util.UUID;
+import net.kyori.adventure.key.Key;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.format.NamedTextColor;
+import net.kyori.adventure.text.format.Style;
+import org.bukkit.GameMode;
+import org.bukkit.HeightMap;
+import org.bukkit.NamespacedKey;
+import org.bukkit.World;
+import org.bukkit.block.BlockState;
+import org.bukkit.block.structure.Mirror;
+import org.bukkit.block.structure.StructureRotation;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.scoreboard.Criteria;
+import org.bukkit.scoreboard.DisplaySlot;
+import org.jetbrains.annotations.ApiStatus;
+import org.jspecify.annotations.NullMarked;
+
+import static io.papermc.paper.command.brigadier.argument.VanillaArgumentProvider.provider;
+
+/**
+ * Vanilla Minecraft includes several custom {@link ArgumentType}s that are recognized by the client.
+ * Many of these argument types include client-side completions and validation, and some include command signing context.
+ *
+ * <p>This class allows creating instances of these types for use in plugin commands, with friendly API result types.</p>
+ *
+ * <p>{@link CustomArgumentType} is provided for customizing parsing or result types server-side, while sending the vanilla argument type to the client.</p>
+ */
+@ApiStatus.Experimental
+@NullMarked
+public final class ArgumentTypes {
+
+ /**
+ * Represents a selector that can capture any
+ * single entity.
+ *
+ * @return argument that takes one entity
+ */
+ public static ArgumentType<EntitySelectorArgumentResolver> entity() {
+ return provider().entity();
+ }
+
+ /**
+ * Represents a selector that can capture multiple
+ * entities.
+ *
+ * @return argument that takes multiple entities
+ */
+ public static ArgumentType<EntitySelectorArgumentResolver> entities() {
+ return provider().entities();
+ }
+
+ /**
+ * Represents a selector that can capture a
+ * singular player entity.
+ *
+ * @return argument that takes one player
+ */
+ public static ArgumentType<PlayerSelectorArgumentResolver> player() {
+ return provider().player();
+ }
+
+ /**
+ * Represents a selector that can capture multiple
+ * player entities.
+ *
+ * @return argument that takes multiple players
+ */
+ public static ArgumentType<PlayerSelectorArgumentResolver> players() {
+ return provider().players();
+ }
+
+ /**
+ * A selector argument that provides a list
+ * of player profiles.
+ *
+ * @return player profile argument
+ */
+ public static ArgumentType<PlayerProfileListResolver> playerProfiles() {
+ return provider().playerProfiles();
+ }
+
+ /**
+ * A block position argument.
+ *
+ * @return block position argument
+ */
+ public static ArgumentType<BlockPositionResolver> blockPosition() {
+ return provider().blockPosition();
+ }
+
+ /**
+ * A fine position argument.
+ *
+ * @return fine position argument
+ * @see #finePosition(boolean) to center whole numbers
+ */
+ public static ArgumentType<FinePositionResolver> finePosition() {
+ return finePosition(false);
+ }
+
+ /**
+ * A fine position argument.
+ *
+ * @param centerIntegers if whole numbers should be centered (+0.5)
+ * @return fine position argument
+ */
+ public static ArgumentType<FinePositionResolver> finePosition(final boolean centerIntegers) {
+ return provider().finePosition(centerIntegers);
+ }
+
+ /**
+ * A blockstate argument which will provide rich parsing for specifying
+ * the specific block variant and then the block entity NBT if applicable.
+ *
+ * @return argument
+ */
+ public static ArgumentType<BlockState> blockState() {
+ return provider().blockState();
+ }
+
+ /**
+ * An ItemStack argument which provides rich parsing for
+ * specifying item material and item NBT information.
+ *
+ * @return argument
+ */
+ public static ArgumentType<ItemStack> itemStack() {
+ return provider().itemStack();
+ }
+
+ /**
+ * An item predicate argument.
+ *
+ * @return argument
+ */
+ public static ArgumentType<ItemStackPredicate> itemPredicate() {
+ return provider().itemStackPredicate();
+ }
+
+ /**
+ * An argument for parsing {@link NamedTextColor}s.
+ *
+ * @return argument
+ */
+ public static ArgumentType<NamedTextColor> namedColor() {
+ return provider().namedColor();
+ }
+
+ /**
+ * A component argument.
+ *
+ * @return argument
+ */
+ public static ArgumentType<Component> component() {
+ return provider().component();
+ }
+
+ /**
+ * A style argument.
+ *
+ * @return argument
+ */
+ public static ArgumentType<Style> style() {
+ return provider().style();
+ }
+
+ /**
+ * A signed message argument.
+ * This argument can be resolved to retrieve the underlying
+ * signed message.
+ *
+ * @return argument
+ */
+ public static ArgumentType<SignedMessageResolver> signedMessage() {
+ return provider().signedMessage();
+ }
+
+ /**
+ * A scoreboard display slot argument.
+ *
+ * @return argument
+ */
+ public static ArgumentType<DisplaySlot> scoreboardDisplaySlot() {
+ return provider().scoreboardDisplaySlot();
+ }
+
+ /**
+ * A namespaced key argument.
+ *
+ * @return argument
+ */
+ public static ArgumentType<NamespacedKey> namespacedKey() {
+ return provider().namespacedKey();
+ }
+
+ /**
+ * A key argument.
+ *
+ * @return argument
+ */
+ // include both key types as we are slowly moving to use adventure's key
+ public static ArgumentType<Key> key() {
+ return provider().key();
+ }
+
+ /**
+ * An inclusive range of integers that may be unbounded on either end.
+ *
+ * @return argument
+ */
+ public static ArgumentType<IntegerRangeProvider> integerRange() {
+ return provider().integerRange();
+ }
+
+ /**
+ * An inclusive range of doubles that may be unbounded on either end.
+ *
+ * @return argument
+ */
+ public static ArgumentType<DoubleRangeProvider> doubleRange() {
+ return provider().doubleRange();
+ }
+
+ /**
+ * A world argument.
+ *
+ * @return argument
+ */
+ public static ArgumentType<World> world() {
+ return provider().world();
+ }
+
+ /**
+ * A game mode argument.
+ *
+ * @return argument
+ */
+ public static ArgumentType<GameMode> gameMode() {
+ return provider().gameMode();
+ }
+
+ /**
+ * An argument for getting a heightmap type.
+ *
+ * @return argument
+ */
+ public static ArgumentType<HeightMap> heightMap() {
+ return provider().heightMap();
+ }
+
+ /**
+ * A uuid argument.
+ *
+ * @return argument
+ */
+ public static ArgumentType<UUID> uuid() {
+ return provider().uuid();
+ }
+
+ /**
+ * An objective criteria argument
+ *
+ * @return argument
+ */
+ public static ArgumentType<Criteria> objectiveCriteria() {
+ return provider().objectiveCriteria();
+ }
+
+ /**
+ * An entity anchor argument.
+ *
+ * @return argument
+ */
+ public static ArgumentType<LookAnchor> entityAnchor() {
+ return provider().entityAnchor();
+ }
+
+ /**
+ * A time argument, returning the number of ticks.
+ * <p>Examples:
+ * <ul>
+ * <li> "1d"
+ * <li> "5s"
+ * <li> "2"
+ * <li> "6t"
+ * </ul>
+ *
+ * @return argument
+ */
+ public static ArgumentType<Integer> time() {
+ return time(0);
+ }
+
+ /**
+ * A time argument, returning the number of ticks.
+ * <p>Examples:
+ * <ul>
+ * <li> "1d"
+ * <li> "5s"
+ * <li> "2"
+ * <li> "6t"
+ * </ul>
+ *
+ * @param mintime The minimum time required for this argument.
+ * @return argument
+ */
+ public static ArgumentType<Integer> time(final int mintime) {
+ return provider().time(mintime);
+ }
+
+ /**
+ * A template mirror argument
+ *
+ * @return argument
+ * @see Mirror
+ */
+ public static ArgumentType<Mirror> templateMirror() {
+ return provider().templateMirror();
+ }
+
+ /**
+ * A template rotation argument.
+ *
+ * @return argument
+ * @see StructureRotation
+ */
+ public static ArgumentType<StructureRotation> templateRotation() {
+ return provider().templateRotation();
+ }
+
+ /**
+ * An argument for a resource in a {@link org.bukkit.Registry}.
+ *
+ * @param registryKey the registry's key
+ * @return argument
+ * @param <T> the registry value type
+ */
+ public static <T> ArgumentType<T> resource(final RegistryKey<T> registryKey) {
+ return provider().resource(registryKey);
+ }
+
+ /**
+ * An argument for a typed key for a {@link org.bukkit.Registry}.
+ *
+ * @param registryKey the registry's key
+ * @return argument
+ * @param <T> the registry value type
+ * @see RegistryArgumentExtractor#getTypedKey(com.mojang.brigadier.context.CommandContext, RegistryKey, String)
+ */
+ public static <T> ArgumentType<TypedKey<T>> resourceKey(final RegistryKey<T> registryKey) {
+ return provider().resourceKey(registryKey);
+ }
+
+ private ArgumentTypes() {
+ }
+}
diff --git a/src/main/java/io/papermc/paper/command/brigadier/argument/CustomArgumentType.java b/src/main/java/io/papermc/paper/command/brigadier/argument/CustomArgumentType.java
new file mode 100644
index 0000000000000000000000000000000000000000..91d40ef0bdbdee3609e33577782c5cce29deda6a
--- /dev/null
+++ b/src/main/java/io/papermc/paper/command/brigadier/argument/CustomArgumentType.java
@@ -0,0 +1,107 @@
+package io.papermc.paper.command.brigadier.argument;
+
+import com.mojang.brigadier.StringReader;
+import com.mojang.brigadier.arguments.ArgumentType;
+import com.mojang.brigadier.context.CommandContext;
+import com.mojang.brigadier.exceptions.CommandSyntaxException;
+import com.mojang.brigadier.suggestion.Suggestions;
+import com.mojang.brigadier.suggestion.SuggestionsBuilder;
+import java.util.Collection;
+import java.util.concurrent.CompletableFuture;
+import org.jetbrains.annotations.ApiStatus;
+import org.jspecify.annotations.NullMarked;
+
+/**
+ * An argument type that wraps around a native-to-vanilla argument type.
+ * This argument receives special handling in that the native argument type will
+ * be sent to the client for possible client-side completions and syntax validation.
+ * <p>
+ * When implementing this class, you have to create your own parsing logic from a
+ * {@link StringReader}. If only want to convert from the native type ({@code N}) to the custom
+ * type ({@code T}), implement {@link Converted} instead.
+ *
+ * @param <T> custom type
+ * @param <N> type with an argument native to vanilla Minecraft (from {@link ArgumentTypes})
+ */
+@ApiStatus.Experimental
+@NullMarked
+public interface CustomArgumentType<T, N> extends ArgumentType<T> {
+
+ /**
+ * Parses the argument into the custom type ({@code T}). Keep in mind
+ * that this parsing will be done on the server. This means that if
+ * you throw a {@link CommandSyntaxException} during parsing, this
+ * will only show up to the user after the user has executed the command
+ * not while they are still entering it.
+ *
+ * @param reader string reader input
+ * @return parsed value
+ * @throws CommandSyntaxException if an error occurs while parsing
+ */
+ @Override
+ T parse(final StringReader reader) throws CommandSyntaxException;
+
+ /**
+ * Gets the native type that this argument uses,
+ * the type that is sent to the client.
+ *
+ * @return native argument type
+ */
+ ArgumentType<N> getNativeType();
+
+ /**
+ * Cannot be controlled by the server.
+ * Returned in cases where there are multiple arguments in the same node.
+ * This helps differentiate and tell the player what the possible inputs are.
+ *
+ * @return client set examples
+ */
+ @Override
+ @ApiStatus.NonExtendable
+ default Collection<String> getExamples() {
+ return this.getNativeType().getExamples();
+ }
+
+ /**
+ * Provides a list of suggestions to show to the client.
+ *
+ * @param context command context
+ * @param builder suggestion builder
+ * @return suggestions
+ * @param <S> context type
+ */
+ @Override
+ default <S> CompletableFuture<Suggestions> listSuggestions(final CommandContext<S> context, final SuggestionsBuilder builder) {
+ return ArgumentType.super.listSuggestions(context, builder);
+ }
+
+ /**
+ * An argument type that wraps around a native-to-vanilla argument type.
+ * This argument receives special handling in that the native argument type will
+ * be sent to the client for possible client-side completions and syntax validation.
+ * <p>
+ * The parsed native type will be converted via {@link #convert(Object)}.
+ * Implement {@link CustomArgumentType} if you want to handle parsing the type manually.
+ *
+ * @param <T> custom type
+ * @param <N> type with an argument native to vanilla Minecraft (from {@link ArgumentTypes})
+ */
+ @ApiStatus.Experimental
+ interface Converted<T, N> extends CustomArgumentType<T, N> {
+
+ @ApiStatus.NonExtendable
+ @Override
+ default T parse(final StringReader reader) throws CommandSyntaxException {
+ return this.convert(this.getNativeType().parse(reader));
+ }
+
+ /**
+ * Converts the value from the native type to the custom argument type.
+ *
+ * @param nativeType native argument provided value
+ * @return converted value
+ * @throws CommandSyntaxException if an exception occurs while parsing
+ */
+ T convert(N nativeType) throws CommandSyntaxException;
+ }
+}
diff --git a/src/main/java/io/papermc/paper/command/brigadier/argument/RegistryArgumentExtractor.java b/src/main/java/io/papermc/paper/command/brigadier/argument/RegistryArgumentExtractor.java
new file mode 100644
index 0000000000000000000000000000000000000000..c6123342df9610a97752030955a43df18e8d0cbd
--- /dev/null
+++ b/src/main/java/io/papermc/paper/command/brigadier/argument/RegistryArgumentExtractor.java
@@ -0,0 +1,36 @@
+package io.papermc.paper.command.brigadier.argument;
+
+import com.mojang.brigadier.context.CommandContext;
+import io.papermc.paper.registry.RegistryKey;
+import io.papermc.paper.registry.TypedKey;
+import org.jspecify.annotations.NullMarked;
+
+/**
+ * Utilities for extracting registry-related arguments from a {@link CommandContext}.
+ */
+@NullMarked
+public final class RegistryArgumentExtractor {
+
+ /**
+ * Gets a typed key argument from a command context.
+ *
+ * @param context the command context
+ * @param registryKey the registry key for the typed key
+ * @param name the argument name
+ * @return the typed key argument
+ * @param <T> the value type
+ * @param <S> the sender type
+ * @throws IllegalArgumentException if the registry key doesn't match the typed key
+ */
+ @SuppressWarnings("unchecked")
+ public static <T, S> TypedKey<T> getTypedKey(final CommandContext<S> context, final RegistryKey<T> registryKey, final String name) {
+ final TypedKey<T> typedKey = context.getArgument(name, TypedKey.class);
+ if (typedKey.registryKey().equals(registryKey)) {
+ return typedKey;
+ }
+ throw new IllegalArgumentException(registryKey + " is not the correct registry for " + typedKey);
+ }
+
+ private RegistryArgumentExtractor() {
+ }
+}
diff --git a/src/main/java/io/papermc/paper/command/brigadier/argument/SignedMessageResolver.java b/src/main/java/io/papermc/paper/command/brigadier/argument/SignedMessageResolver.java
new file mode 100644
index 0000000000000000000000000000000000000000..2f2c1729c5d9f1a6b6171c0ed5326b9b631f3c20
--- /dev/null
+++ b/src/main/java/io/papermc/paper/command/brigadier/argument/SignedMessageResolver.java
@@ -0,0 +1,42 @@
+package io.papermc.paper.command.brigadier.argument;
+
+import com.mojang.brigadier.context.CommandContext;
+import com.mojang.brigadier.exceptions.CommandSyntaxException;
+import io.papermc.paper.command.brigadier.CommandSourceStack;
+import java.util.concurrent.CompletableFuture;
+import net.kyori.adventure.chat.SignedMessage;
+import org.jetbrains.annotations.ApiStatus;
+import org.jspecify.annotations.NullMarked;
+
+/**
+ * A resolver for a {@link SignedMessage}
+ *
+ * @see ArgumentTypes#signedMessage()
+ */
+@ApiStatus.Experimental
+@NullMarked
+@ApiStatus.NonExtendable
+public interface SignedMessageResolver {
+
+ /**
+ * Gets the string content of the message
+ *
+ * @return string content
+ */
+ String content();
+
+ /**
+ * Resolves this signed message. This will the {@link CommandContext}
+ * and signed arguments sent by the client.
+ * <p>
+ * In the case that signed message information isn't provided, a "system"
+ * signed message will be returned instead.
+ *
+ * @param argumentName argument name
+ * @param context the command context
+ * @return a completable future for the {@link SignedMessage}
+ * @throws CommandSyntaxException syntax exception
+ */
+ CompletableFuture<SignedMessage> resolveSignedMessage(String argumentName, CommandContext<CommandSourceStack> context) throws CommandSyntaxException;
+
+}
diff --git a/src/main/java/io/papermc/paper/command/brigadier/argument/VanillaArgumentProvider.java b/src/main/java/io/papermc/paper/command/brigadier/argument/VanillaArgumentProvider.java
new file mode 100644
index 0000000000000000000000000000000000000000..4f640bd3e536fb79db54dcedd5807e7de402acef
--- /dev/null
+++ b/src/main/java/io/papermc/paper/command/brigadier/argument/VanillaArgumentProvider.java
@@ -0,0 +1,106 @@
+package io.papermc.paper.command.brigadier.argument;
+
+import com.mojang.brigadier.arguments.ArgumentType;
+import io.papermc.paper.command.brigadier.argument.predicate.ItemStackPredicate;
+import io.papermc.paper.command.brigadier.argument.range.DoubleRangeProvider;
+import io.papermc.paper.command.brigadier.argument.range.IntegerRangeProvider;
+import io.papermc.paper.command.brigadier.argument.resolvers.BlockPositionResolver;
+import io.papermc.paper.command.brigadier.argument.resolvers.FinePositionResolver;
+import io.papermc.paper.command.brigadier.argument.resolvers.PlayerProfileListResolver;
+import io.papermc.paper.command.brigadier.argument.resolvers.selector.EntitySelectorArgumentResolver;
+import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
+import io.papermc.paper.entity.LookAnchor;
+import io.papermc.paper.registry.RegistryKey;
+import io.papermc.paper.registry.TypedKey;
+import java.util.Optional;
+import java.util.ServiceLoader;
+import java.util.UUID;
+import net.kyori.adventure.key.Key;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.format.NamedTextColor;
+import net.kyori.adventure.text.format.Style;
+import org.bukkit.GameMode;
+import org.bukkit.HeightMap;
+import org.bukkit.NamespacedKey;
+import org.bukkit.World;
+import org.bukkit.block.BlockState;
+import org.bukkit.block.structure.Mirror;
+import org.bukkit.block.structure.StructureRotation;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.scoreboard.Criteria;
+import org.bukkit.scoreboard.DisplaySlot;
+import org.jetbrains.annotations.ApiStatus;
+import org.jspecify.annotations.NullMarked;
+
+@ApiStatus.Internal
+@NullMarked
+interface VanillaArgumentProvider {
+
+ Optional<VanillaArgumentProvider> PROVIDER = ServiceLoader.load(VanillaArgumentProvider.class)
+ .findFirst();
+
+ static VanillaArgumentProvider provider() {
+ return PROVIDER.orElseThrow();
+ }
+
+ ArgumentType<EntitySelectorArgumentResolver> entity();
+
+ ArgumentType<PlayerSelectorArgumentResolver> player();
+
+ ArgumentType<EntitySelectorArgumentResolver> entities();
+
+ ArgumentType<PlayerSelectorArgumentResolver> players();
+
+ ArgumentType<PlayerProfileListResolver> playerProfiles();
+
+ ArgumentType<BlockPositionResolver> blockPosition();
+
+ ArgumentType<FinePositionResolver> finePosition(boolean centerIntegers);
+
+ ArgumentType<BlockState> blockState();
+
+ ArgumentType<ItemStack> itemStack();
+
+ ArgumentType<ItemStackPredicate> itemStackPredicate();
+
+ ArgumentType<NamedTextColor> namedColor();
+
+ ArgumentType<Component> component();
+
+ ArgumentType<Style> style();
+
+ ArgumentType<SignedMessageResolver> signedMessage();
+
+ ArgumentType<DisplaySlot> scoreboardDisplaySlot();
+
+ ArgumentType<NamespacedKey> namespacedKey();
+
+ // include both key types as we are slowly moving to use adventure's key
+ ArgumentType<Key> key();
+
+ ArgumentType<IntegerRangeProvider> integerRange();
+
+ ArgumentType<DoubleRangeProvider> doubleRange();
+
+ ArgumentType<World> world();
+
+ ArgumentType<GameMode> gameMode();
+
+ ArgumentType<HeightMap> heightMap();
+
+ ArgumentType<UUID> uuid();
+
+ ArgumentType<Criteria> objectiveCriteria();
+
+ ArgumentType<LookAnchor> entityAnchor();
+
+ ArgumentType<Integer> time(int minTicks);
+
+ ArgumentType<Mirror> templateMirror();
+
+ ArgumentType<StructureRotation> templateRotation();
+
+ <T> ArgumentType<TypedKey<T>> resourceKey(RegistryKey<T> registryKey);
+
+ <T> ArgumentType<T> resource(RegistryKey<T> registryKey);
+}
diff --git a/src/main/java/io/papermc/paper/command/brigadier/argument/predicate/ItemStackPredicate.java b/src/main/java/io/papermc/paper/command/brigadier/argument/predicate/ItemStackPredicate.java
new file mode 100644
index 0000000000000000000000000000000000000000..ba0cfb3c53f6a5a29b1719ed271a8f13d5f52f24
--- /dev/null
+++ b/src/main/java/io/papermc/paper/command/brigadier/argument/predicate/ItemStackPredicate.java
@@ -0,0 +1,15 @@
+package io.papermc.paper.command.brigadier.argument.predicate;
+
+import java.util.function.Predicate;
+import org.bukkit.inventory.ItemStack;
+import org.jetbrains.annotations.ApiStatus;
+
+/**
+ * A predicate for ItemStack.
+ *
+ * @see io.papermc.paper.command.brigadier.argument.ArgumentTypes#itemPredicate()
+ */
+@ApiStatus.Experimental
+@ApiStatus.NonExtendable
+public interface ItemStackPredicate extends Predicate<ItemStack> {
+}
diff --git a/src/main/java/io/papermc/paper/command/brigadier/argument/range/DoubleRangeProvider.java b/src/main/java/io/papermc/paper/command/brigadier/argument/range/DoubleRangeProvider.java
new file mode 100644
index 0000000000000000000000000000000000000000..82c978ba42a787fd0cdc936e42c8e12ffa4ff8bf
--- /dev/null
+++ b/src/main/java/io/papermc/paper/command/brigadier/argument/range/DoubleRangeProvider.java
@@ -0,0 +1,14 @@
+package io.papermc.paper.command.brigadier.argument.range;
+
+import org.jetbrains.annotations.ApiStatus;
+
+/**
+ * A provider for a {@link com.google.common.collect.Range} of doubles.
+ *
+ * @see io.papermc.paper.command.brigadier.argument.ArgumentTypes#doubleRange()
+ */
+@ApiStatus.Experimental
+@ApiStatus.NonExtendable
+public non-sealed interface DoubleRangeProvider extends RangeProvider<Double> {
+
+}
diff --git a/src/main/java/io/papermc/paper/command/brigadier/argument/range/IntegerRangeProvider.java b/src/main/java/io/papermc/paper/command/brigadier/argument/range/IntegerRangeProvider.java
new file mode 100644
index 0000000000000000000000000000000000000000..06ffff68d2652ef8eb40aa723803c24ecd013721
--- /dev/null
+++ b/src/main/java/io/papermc/paper/command/brigadier/argument/range/IntegerRangeProvider.java
@@ -0,0 +1,14 @@
+package io.papermc.paper.command.brigadier.argument.range;
+
+import org.jetbrains.annotations.ApiStatus;
+
+/**
+ * A provider for a {@link com.google.common.collect.Range} of integers.
+ *
+ * @see io.papermc.paper.command.brigadier.argument.ArgumentTypes#integerRange()
+ */
+@ApiStatus.Experimental
+@ApiStatus.NonExtendable
+public non-sealed interface IntegerRangeProvider extends RangeProvider<Integer> {
+
+}
diff --git a/src/main/java/io/papermc/paper/command/brigadier/argument/range/RangeProvider.java b/src/main/java/io/papermc/paper/command/brigadier/argument/range/RangeProvider.java
new file mode 100644
index 0000000000000000000000000000000000000000..af1c01ab0d2146225c54a7766788007314f59328
--- /dev/null
+++ b/src/main/java/io/papermc/paper/command/brigadier/argument/range/RangeProvider.java
@@ -0,0 +1,22 @@
+package io.papermc.paper.command.brigadier.argument.range;
+
+import com.google.common.collect.Range;
+import org.jetbrains.annotations.ApiStatus;
+import org.jspecify.annotations.NullMarked;
+
+/**
+ * A provider for a range of numbers
+ *
+ * @param <T>
+ * @see io.papermc.paper.command.brigadier.argument.ArgumentTypes
+ */
+@ApiStatus.Experimental
+@NullMarked
+public sealed interface RangeProvider<T extends Comparable<?>> permits DoubleRangeProvider, IntegerRangeProvider {
+
+ /**
+ * Provides the given range.
+ * @return range
+ */
+ Range<T> range();
+}
diff --git a/src/main/java/io/papermc/paper/command/brigadier/argument/resolvers/ArgumentResolver.java b/src/main/java/io/papermc/paper/command/brigadier/argument/resolvers/ArgumentResolver.java
new file mode 100644
index 0000000000000000000000000000000000000000..60439269d8b1535c779ae8bd008c8f28cc7e4133
--- /dev/null
+++ b/src/main/java/io/papermc/paper/command/brigadier/argument/resolvers/ArgumentResolver.java
@@ -0,0 +1,27 @@
+package io.papermc.paper.command.brigadier.argument.resolvers;
+
+import com.mojang.brigadier.exceptions.CommandSyntaxException;
+import io.papermc.paper.command.brigadier.CommandSourceStack;
+import org.jetbrains.annotations.ApiStatus;
+import org.jspecify.annotations.NullMarked;
+
+/**
+ * An {@link ArgumentResolver} is capable of resolving
+ * an argument value using a {@link CommandSourceStack}.
+ *
+ * @param <T> resolved type
+ * @see io.papermc.paper.command.brigadier.argument.ArgumentTypes
+ */
+@ApiStatus.Experimental
+@NullMarked
+@ApiStatus.NonExtendable
+public interface ArgumentResolver<T> {
+
+ /**
+ * Resolves the argument with the given
+ * command source stack.
+ * @param sourceStack source stack
+ * @return resolved
+ */
+ T resolve(CommandSourceStack sourceStack) throws CommandSyntaxException;
+}
diff --git a/src/main/java/io/papermc/paper/command/brigadier/argument/resolvers/BlockPositionResolver.java b/src/main/java/io/papermc/paper/command/brigadier/argument/resolvers/BlockPositionResolver.java
new file mode 100644
index 0000000000000000000000000000000000000000..908f40dbf3e52bdfc8577a8916884e9fa4557a7c
--- /dev/null
+++ b/src/main/java/io/papermc/paper/command/brigadier/argument/resolvers/BlockPositionResolver.java
@@ -0,0 +1,16 @@
+package io.papermc.paper.command.brigadier.argument.resolvers;
+
+import io.papermc.paper.command.brigadier.CommandSourceStack;
+import io.papermc.paper.math.BlockPosition;
+import org.jetbrains.annotations.ApiStatus;
+
+/**
+ * An {@link ArgumentResolver} that's capable of resolving
+ * a block position argument value using a {@link CommandSourceStack}.
+ *
+ * @see io.papermc.paper.command.brigadier.argument.ArgumentTypes#blockPosition()
+ */
+@ApiStatus.Experimental
+@ApiStatus.NonExtendable
+public interface BlockPositionResolver extends ArgumentResolver<BlockPosition> {
+}
diff --git a/src/main/java/io/papermc/paper/command/brigadier/argument/resolvers/FinePositionResolver.java b/src/main/java/io/papermc/paper/command/brigadier/argument/resolvers/FinePositionResolver.java
new file mode 100644
index 0000000000000000000000000000000000000000..e2fc26016b8d68fd0d69c8ca962f61fe65471b24
--- /dev/null
+++ b/src/main/java/io/papermc/paper/command/brigadier/argument/resolvers/FinePositionResolver.java
@@ -0,0 +1,17 @@
+package io.papermc.paper.command.brigadier.argument.resolvers;
+
+import io.papermc.paper.command.brigadier.CommandSourceStack;
+import io.papermc.paper.math.FinePosition;
+import org.jetbrains.annotations.ApiStatus;
+
+/**
+ * An {@link ArgumentResolver} that's capable of resolving
+ * a fine position argument value using a {@link CommandSourceStack}.
+ *
+ * @see io.papermc.paper.command.brigadier.argument.ArgumentTypes#finePosition()
+ * @see io.papermc.paper.command.brigadier.argument.ArgumentTypes#finePosition(boolean)
+ */
+@ApiStatus.Experimental
+@ApiStatus.NonExtendable
+public interface FinePositionResolver extends ArgumentResolver<FinePosition> {
+}
diff --git a/src/main/java/io/papermc/paper/command/brigadier/argument/resolvers/PlayerProfileListResolver.java b/src/main/java/io/papermc/paper/command/brigadier/argument/resolvers/PlayerProfileListResolver.java
new file mode 100644
index 0000000000000000000000000000000000000000..89024e67fd81a9cd8a9d1ef5bb78d1c8bcb4fcc5
--- /dev/null
+++ b/src/main/java/io/papermc/paper/command/brigadier/argument/resolvers/PlayerProfileListResolver.java
@@ -0,0 +1,17 @@
+package io.papermc.paper.command.brigadier.argument.resolvers;
+
+import com.destroystokyo.paper.profile.PlayerProfile;
+import io.papermc.paper.command.brigadier.CommandSourceStack;
+import java.util.Collection;
+import org.jetbrains.annotations.ApiStatus;
+
+/**
+ * An {@link ArgumentResolver} that's capable of resolving
+ * argument value using a {@link CommandSourceStack}.
+ *
+ * @see io.papermc.paper.command.brigadier.argument.ArgumentTypes#playerProfiles()
+ */
+@ApiStatus.Experimental
+@ApiStatus.NonExtendable
+public interface PlayerProfileListResolver extends ArgumentResolver<Collection<PlayerProfile>> {
+}
diff --git a/src/main/java/io/papermc/paper/command/brigadier/argument/resolvers/selector/EntitySelectorArgumentResolver.java b/src/main/java/io/papermc/paper/command/brigadier/argument/resolvers/selector/EntitySelectorArgumentResolver.java
new file mode 100644
index 0000000000000000000000000000000000000000..15d05c28040180a00b16cf05c8b059ce66793fa8
--- /dev/null
+++ b/src/main/java/io/papermc/paper/command/brigadier/argument/resolvers/selector/EntitySelectorArgumentResolver.java
@@ -0,0 +1,19 @@
+package io.papermc.paper.command.brigadier.argument.resolvers.selector;
+
+import io.papermc.paper.command.brigadier.CommandSourceStack;
+import io.papermc.paper.command.brigadier.argument.resolvers.ArgumentResolver;
+import java.util.List;
+import org.bukkit.entity.Entity;
+import org.jetbrains.annotations.ApiStatus;
+
+/**
+ * An {@link ArgumentResolver} that's capable of resolving
+ * an entity selector argument value using a {@link CommandSourceStack}.
+ *
+ * @see io.papermc.paper.command.brigadier.argument.ArgumentTypes#entity()
+ * @see io.papermc.paper.command.brigadier.argument.ArgumentTypes#entities()
+ */
+@ApiStatus.Experimental
+@ApiStatus.NonExtendable
+public interface EntitySelectorArgumentResolver extends SelectorArgumentResolver<List<Entity>> {
+}
diff --git a/src/main/java/io/papermc/paper/command/brigadier/argument/resolvers/selector/PlayerSelectorArgumentResolver.java b/src/main/java/io/papermc/paper/command/brigadier/argument/resolvers/selector/PlayerSelectorArgumentResolver.java
new file mode 100644
index 0000000000000000000000000000000000000000..a973555b7a013df7f9700841f41220c8afa0301e
--- /dev/null
+++ b/src/main/java/io/papermc/paper/command/brigadier/argument/resolvers/selector/PlayerSelectorArgumentResolver.java
@@ -0,0 +1,19 @@
+package io.papermc.paper.command.brigadier.argument.resolvers.selector;
+
+import io.papermc.paper.command.brigadier.CommandSourceStack;
+import io.papermc.paper.command.brigadier.argument.resolvers.ArgumentResolver;
+import java.util.List;
+import org.bukkit.entity.Player;
+import org.jetbrains.annotations.ApiStatus;
+
+/**
+ * An {@link ArgumentResolver} that's capable of resolving
+ * a player selector argument value using a {@link CommandSourceStack}.
+ *
+ * @see io.papermc.paper.command.brigadier.argument.ArgumentTypes#player()
+ * @see io.papermc.paper.command.brigadier.argument.ArgumentTypes#players()
+ */
+@ApiStatus.Experimental
+@ApiStatus.NonExtendable
+public interface PlayerSelectorArgumentResolver extends SelectorArgumentResolver<List<Player>> {
+}
diff --git a/src/main/java/io/papermc/paper/command/brigadier/argument/resolvers/selector/SelectorArgumentResolver.java b/src/main/java/io/papermc/paper/command/brigadier/argument/resolvers/selector/SelectorArgumentResolver.java
new file mode 100644
index 0000000000000000000000000000000000000000..906ce6eff30ebd9ec3010ce03b471418843e6588
--- /dev/null
+++ b/src/main/java/io/papermc/paper/command/brigadier/argument/resolvers/selector/SelectorArgumentResolver.java
@@ -0,0 +1,17 @@
+package io.papermc.paper.command.brigadier.argument.resolvers.selector;
+
+import io.papermc.paper.command.brigadier.CommandSourceStack;
+import io.papermc.paper.command.brigadier.argument.resolvers.ArgumentResolver;
+import org.jetbrains.annotations.ApiStatus;
+
+/**
+ * An {@link ArgumentResolver} that's capable of resolving
+ * a selector argument value using a {@link CommandSourceStack}.
+ *
+ * @param <T> resolved type
+ * @see <a href="https://minecraft.wiki/w/Target_selectors">Target Selectors</a>
+ */
+@ApiStatus.Experimental
+@ApiStatus.NonExtendable
+public interface SelectorArgumentResolver<T> extends ArgumentResolver<T> {
+}
diff --git a/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/LifecycleEvents.java b/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/LifecycleEvents.java
index f70814de0d6c40b2c1c9921b8abdd1162e1d3995..ab6b262cf0d2d17962ed012b2ea7b8f1db8bc576 100644
--- a/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/LifecycleEvents.java
+++ b/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/LifecycleEvents.java
@@ -1,9 +1,11 @@
package io.papermc.paper.plugin.lifecycle.event.types;
+import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.plugin.bootstrap.BootstrapContext;
import io.papermc.paper.plugin.lifecycle.event.LifecycleEvent;
import io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager;
import io.papermc.paper.plugin.lifecycle.event.LifecycleEventOwner;
+import io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.NullMarked;
@@ -17,6 +19,13 @@ import org.jspecify.annotations.NullMarked;
@NullMarked
public final class LifecycleEvents {
+ /**
+ * This event is for registering commands to the server's brigadier command system. You can register a handler for this event in
+ * {@link org.bukkit.plugin.java.JavaPlugin#onEnable()} or {@link io.papermc.paper.plugin.bootstrap.PluginBootstrap#bootstrap(BootstrapContext)}.
+ * @see Commands an example of a command being registered
+ */
+ public static final LifecycleEventType.Prioritizable<LifecycleEventOwner, ReloadableRegistrarEvent<Commands>> COMMANDS = prioritized("commands", LifecycleEventOwner.class);
+
//<editor-fold desc="helper methods" defaultstate="collapsed">
@ApiStatus.Internal
static <E extends LifecycleEvent> LifecycleEventType.Monitorable<Plugin, E> plugin(final String name) {
diff --git a/src/main/java/org/bukkit/command/Command.java b/src/main/java/org/bukkit/command/Command.java
index 03d2643d166824458c88a49f20270e93b14f3988..0a26fffe9b1e5080b5639767a03af11006108b4a 100644
--- a/src/main/java/org/bukkit/command/Command.java
+++ b/src/main/java/org/bukkit/command/Command.java
@@ -520,4 +520,9 @@ public abstract class Command {
public String toString() {
return getClass().getName() + '(' + name + ')';
}
+
+ // Paper start
+ @org.jetbrains.annotations.ApiStatus.Internal
+ public boolean canBeOverriden() { return false; }
+ // Paper end
}
diff --git a/src/main/java/org/bukkit/command/FormattedCommandAlias.java b/src/main/java/org/bukkit/command/FormattedCommandAlias.java
index 9d4f553c04784cca63901a56a7aea62a5cae1d72..abe256e1e45ce28036da4aa1586715bc8a1a3414 100644
--- a/src/main/java/org/bukkit/command/FormattedCommandAlias.java
+++ b/src/main/java/org/bukkit/command/FormattedCommandAlias.java
@@ -117,7 +117,7 @@ public class FormattedCommandAlias extends Command {
index = formatString.indexOf('$', index);
}
- return formatString;
+ return formatString.trim(); // Paper - Causes an extra space at the end, breaks with brig commands
}
@NotNull
diff --git a/src/main/java/org/bukkit/command/SimpleCommandMap.java b/src/main/java/org/bukkit/command/SimpleCommandMap.java
index b5f9cd2bd191f8b071c6c95706ddbef97d3c244e..5df19bd701c67506689fc7f49d91f99ebfbc83f0 100644
--- a/src/main/java/org/bukkit/command/SimpleCommandMap.java
+++ b/src/main/java/org/bukkit/command/SimpleCommandMap.java
@@ -23,10 +23,14 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class SimpleCommandMap implements CommandMap {
- protected final Map<String, Command> knownCommands = new HashMap<String, Command>();
+ protected final Map<String, Command> knownCommands; // Paper
private final Server server;
- public SimpleCommandMap(@NotNull final Server server) {
+ // Paper start
+ @org.jetbrains.annotations.ApiStatus.Internal
+ public SimpleCommandMap(@NotNull final Server server, Map<String, Command> backing) {
+ this.knownCommands = backing;
+ // Paper end
this.server = server;
setDefaultCommands();
}
@@ -103,7 +107,10 @@ public class SimpleCommandMap implements CommandMap {
*/
private synchronized boolean register(@NotNull String label, @NotNull Command command, boolean isAlias, @NotNull String fallbackPrefix) {
knownCommands.put(fallbackPrefix + ":" + label, command);
- if ((command instanceof BukkitCommand || isAlias) && knownCommands.containsKey(label)) {
+ // Paper start
+ Command known = knownCommands.get(label);
+ if ((command instanceof BukkitCommand || isAlias) && (known != null && !known.canBeOverriden())) {
+ // Paper end
// Request is for an alias/fallback command and it conflicts with
// a existing command or previous alias ignore it
// Note: This will mean it gets removed from the commands list of active aliases
@@ -115,7 +122,9 @@ public class SimpleCommandMap implements CommandMap {
// If the command exists but is an alias we overwrite it, otherwise we return
Command conflict = knownCommands.get(label);
if (conflict != null && conflict.getLabel().equals(label)) {
+ if (!conflict.canBeOverriden()) { // Paper
return false;
+ } // Paper
}
if (!isAlias) {
diff --git a/src/main/java/org/bukkit/command/defaults/ReloadCommand.java b/src/main/java/org/bukkit/command/defaults/ReloadCommand.java
index 3ec32b46264cfff857b50129b5e0fa5584943ec6..bdfe68b386b5ca2878475e548d3c9a3808fce848 100644
--- a/src/main/java/org/bukkit/command/defaults/ReloadCommand.java
+++ b/src/main/java/org/bukkit/command/defaults/ReloadCommand.java
@@ -18,6 +18,9 @@ public class ReloadCommand extends BukkitCommand {
this.setAliases(Arrays.asList("rl"));
}
+ @org.jetbrains.annotations.ApiStatus.Internal // Paper
+ public static final String RELOADING_DISABLED_MESSAGE = "A lifecycle event handler has been registered which makes reloading plugins not possible"; // Paper
+
@Override
public boolean execute(@NotNull CommandSender sender, @NotNull String currentAlias, @NotNull String[] args) { // Paper
if (!testPermission(sender)) return true;
@@ -51,7 +54,16 @@ public class ReloadCommand extends BukkitCommand {
Command.broadcastCommandMessage(sender, ChatColor.RED + "Please note that this command is not supported and may cause issues when using some plugins.");
Command.broadcastCommandMessage(sender, ChatColor.RED + "If you encounter any issues please use the /stop command to restart your server.");
- Bukkit.reload();
+ // Paper start - lifecycle events
+ try {
+ Bukkit.reload();
+ } catch (final IllegalStateException ex) {
+ if (ex.getMessage().equals(RELOADING_DISABLED_MESSAGE)) {
+ Command.broadcastCommandMessage(sender, ChatColor.RED + RELOADING_DISABLED_MESSAGE);
+ return true;
+ }
+ }
+ // Paper end - lifecycle events
Command.broadcastCommandMessage(sender, ChatColor.GREEN + "Reload complete.");
return true;
diff --git a/src/main/java/org/bukkit/event/server/TabCompleteEvent.java b/src/main/java/org/bukkit/event/server/TabCompleteEvent.java
index 6465e290c090d82986352d5ab7ba5dc65bd3dc17..c71c122ccc4775d030688f7b8df0b4feb49136f4 100644
--- a/src/main/java/org/bukkit/event/server/TabCompleteEvent.java
+++ b/src/main/java/org/bukkit/event/server/TabCompleteEvent.java
@@ -18,6 +18,8 @@ import org.jetbrains.annotations.NotNull;
* themselves. Plugins wishing to remove commands from tab completion are
* advised to ensure the client does not have permission for the relevant
* commands, or use {@link PlayerCommandSendEvent}.
+ * @apiNote Only called for bukkit API commands {@link org.bukkit.command.Command} and
+ * {@link org.bukkit.command.CommandExecutor} and not for brigadier commands ({@link io.papermc.paper.command.brigadier.Commands}).
*/
public class TabCompleteEvent extends Event implements Cancellable {
|