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
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Riley Park <riley.park@meino.net>
Date: Fri, 29 Jan 2021 17:54:03 +0100
Subject: [PATCH] Adventure
Co-authored-by: zml <zml@stellardrift.ca>
Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
diff --git a/src/main/java/com/destroystokyo/paper/PaperConfig.java b/src/main/java/com/destroystokyo/paper/PaperConfig.java
index 1d03a79e9010bc514b72a81ba0ad4a62aeff1bb7..429b74474ced04d8dd8f038b8590b8dfe178bf4d 100644
--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
@@ -217,4 +217,9 @@ public class PaperConfig {
" - Length: " + timeSummary(Timings.getHistoryLength() / 20) +
" - Server Name: " + timingsServerName);
}
+
+ public static boolean useDisplayNameInQuit = false;
+ private static void useDisplayNameInQuit() {
+ useDisplayNameInQuit = getBoolean("use-display-name-in-quit-message", useDisplayNameInQuit);
+ }
}
diff --git a/src/main/java/io/papermc/paper/adventure/AdventureComponent.java b/src/main/java/io/papermc/paper/adventure/AdventureComponent.java
new file mode 100644
index 0000000000000000000000000000000000000000..89597b4a3064c3c6001c7e927a848ee73a1b1fd9
--- /dev/null
+++ b/src/main/java/io/papermc/paper/adventure/AdventureComponent.java
@@ -0,0 +1,77 @@
+package io.papermc.paper.adventure;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonSerializationContext;
+import com.google.gson.JsonSerializer;
+import java.lang.reflect.Type;
+import java.util.List;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.TextComponent;
+import net.minecraft.network.chat.ChatModifier;
+import net.minecraft.network.chat.IChatBaseComponent;
+import net.minecraft.network.chat.IChatMutableComponent;
+import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+public final class AdventureComponent implements IChatBaseComponent {
+ final Component wrapped;
+ private @MonotonicNonNull IChatBaseComponent converted;
+
+ public AdventureComponent(final Component wrapped) {
+ this.wrapped = wrapped;
+ }
+
+ public IChatBaseComponent deepConverted() {
+ IChatBaseComponent converted = this.converted;
+ if (converted == null) {
+ converted = PaperAdventure.WRAPPER_AWARE_SERIALIZER.serialize(this.wrapped);
+ this.converted = converted;
+ }
+ return converted;
+ }
+
+ public @Nullable IChatBaseComponent deepConvertedIfPresent() {
+ return this.converted;
+ }
+
+ @Override
+ public ChatModifier getChatModifier() {
+ return this.deepConverted().getChatModifier();
+ }
+
+ @Override
+ public String getText() {
+ if (this.wrapped instanceof TextComponent) {
+ return ((TextComponent) this.wrapped).content();
+ } else {
+ return this.deepConverted().getText();
+ }
+ }
+
+ @Override
+ public String getString() {
+ return PaperAdventure.PLAIN.serialize(this.wrapped);
+ }
+
+ @Override
+ public List<IChatBaseComponent> getSiblings() {
+ return this.deepConverted().getSiblings();
+ }
+
+ @Override
+ public IChatMutableComponent g() {
+ return this.deepConverted().g();
+ }
+
+ @Override
+ public IChatMutableComponent mutableCopy() {
+ return this.deepConverted().mutableCopy();
+ }
+
+ public static class Serializer implements JsonSerializer<AdventureComponent> {
+ @Override
+ public JsonElement serialize(final AdventureComponent src, final Type type, final JsonSerializationContext context) {
+ return PaperAdventure.GSON.serializer().toJsonTree(src.wrapped, Component.class);
+ }
+ }
+}
diff --git a/src/main/java/io/papermc/paper/adventure/ChatProcessor.java b/src/main/java/io/papermc/paper/adventure/ChatProcessor.java
new file mode 100644
index 0000000000000000000000000000000000000000..50253e8dfffc84e26f02c6a470a5a8b078d90e12
--- /dev/null
+++ b/src/main/java/io/papermc/paper/adventure/ChatProcessor.java
@@ -0,0 +1,215 @@
+package io.papermc.paper.adventure;
+
+import io.papermc.paper.chat.ChatComposer;
+import io.papermc.paper.event.player.AbstractChatEvent;
+import io.papermc.paper.event.player.AsyncChatEvent;
+import io.papermc.paper.event.player.ChatEvent;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.function.Consumer;
+import java.util.regex.Pattern;
+
+import net.kyori.adventure.audience.MessageType;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.TextReplacementConfig;
+import net.kyori.adventure.text.event.ClickEvent;
+import net.minecraft.network.chat.ChatMessageType;
+import net.minecraft.network.chat.IChatBaseComponent;
+import net.minecraft.server.MinecraftServer;
+import net.minecraft.server.level.EntityPlayer;
+import org.bukkit.Bukkit;
+import org.bukkit.craftbukkit.entity.CraftPlayer;
+import org.bukkit.craftbukkit.util.LazyPlayerSet;
+import org.bukkit.craftbukkit.util.Waitable;
+import org.bukkit.entity.Player;
+import org.bukkit.event.Event;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.player.AsyncPlayerChatEvent;
+import org.bukkit.event.player.PlayerChatEvent;
+
+public final class ChatProcessor {
+ // <-- copied from adventure-text-serializer-legacy
+ private static final Pattern DEFAULT_URL_PATTERN = Pattern.compile("(?:(https?)://)?([-\\w_.]+\\.\\w{2,})(/\\S*)?");
+ private static final Pattern URL_SCHEME_PATTERN = Pattern.compile("^[a-z][a-z0-9+\\-.]*:");
+ private static final TextReplacementConfig URL_REPLACEMENT_CONFIG = TextReplacementConfig.builder()
+ .match(DEFAULT_URL_PATTERN)
+ .replacement(url -> {
+ String clickUrl = url.content();
+ if (!URL_SCHEME_PATTERN.matcher(clickUrl).find()) {
+ clickUrl = "http://" + clickUrl;
+ }
+ return url.clickEvent(ClickEvent.openUrl(clickUrl));
+ })
+ .build();
+ // copied from adventure-text-serializer-legacy -->
+ final MinecraftServer server;
+ final EntityPlayer player;
+ final String message;
+ final boolean async;
+
+ public ChatProcessor(final MinecraftServer server, final EntityPlayer player, final String message, final boolean async) {
+ this.server = server;
+ this.player = player;
+ this.message = message;
+ this.async = async;
+ }
+
+ @SuppressWarnings({"CodeBlock2Expr", "deprecated"})
+ public void process() {
+ this.processingLegacyFirst(
+ // continuing from AsyncPlayerChatEvent (without PlayerChatEvent)
+ event -> {
+ this.processModern(
+ legacyComposer(event.getFormat()),
+ event.getRecipients(),
+ PaperAdventure.LEGACY_SECTION_UXRC.deserialize(event.getMessage()),
+ event.isCancelled()
+ );
+ },
+ // continuing from AsyncPlayerChatEvent and PlayerChatEvent
+ event -> {
+ this.processModern(
+ legacyComposer(event.getFormat()),
+ event.getRecipients(),
+ PaperAdventure.LEGACY_SECTION_UXRC.deserialize(event.getMessage()),
+ event.isCancelled()
+ );
+ },
+ // no legacy events called, all nice and fresh!
+ () -> {
+ this.processModern(
+ ChatComposer.DEFAULT,
+ new LazyPlayerSet(this.server),
+ Component.text(this.message).replaceText(URL_REPLACEMENT_CONFIG),
+ false
+ );
+ }
+ );
+ }
+
+ @SuppressWarnings("deprecation")
+ private void processingLegacyFirst(
+ final Consumer<AsyncPlayerChatEvent> continueAfterAsync,
+ final Consumer<PlayerChatEvent> continueAfterAsyncAndSync,
+ final Runnable modernOnly
+ ) {
+ final boolean listenersOnAsyncEvent = anyListeners(AsyncPlayerChatEvent.getHandlerList());
+ final boolean listenersOnSyncEvent = anyListeners(PlayerChatEvent.getHandlerList());
+ if (listenersOnAsyncEvent || listenersOnSyncEvent) {
+ final CraftPlayer player = this.player.getBukkitEntity();
+ final AsyncPlayerChatEvent ae = new AsyncPlayerChatEvent(this.async, player, this.message, new LazyPlayerSet(this.server));
+ post(ae);
+ if (listenersOnSyncEvent) {
+ final PlayerChatEvent se = new PlayerChatEvent(player, ae.getMessage(), ae.getFormat(), ae.getRecipients());
+ se.setCancelled(ae.isCancelled()); // propagate cancelled state
+ this.queueIfAsyncOrRunImmediately(new Waitable<Void>() {
+ @Override
+ protected Void evaluate() {
+ post(se);
+ return null;
+ }
+ });
+ continueAfterAsyncAndSync.accept(se);
+ } else {
+ continueAfterAsync.accept(ae);
+ }
+ } else {
+ modernOnly.run();
+ }
+ }
+
+ private void processModern(final ChatComposer composer, final Set<Player> recipients, final Component message, final boolean cancelled) {
+ final AsyncChatEvent ae = this.createAsync(composer, recipients, message);
+ ae.setCancelled(cancelled); // propagate cancelled state
+ post(ae);
+ final boolean listenersOnSyncEvent = anyListeners(ChatEvent.getHandlerList());
+ if (listenersOnSyncEvent) {
+ this.continueWithSyncFromWhereAsyncLeftOff(ae);
+ } else {
+ this.complete(ae);
+ }
+ }
+
+ private void continueWithSyncFromWhereAsyncLeftOff(final AsyncChatEvent ae) {
+ this.queueIfAsyncOrRunImmediately(new Waitable<Void>() {
+ @Override
+ protected Void evaluate() {
+ final ChatEvent se = ChatProcessor.this.createSync(ae.composer(), ae.recipients(), ae.message());
+ se.setCancelled(ae.isCancelled()); // propagate cancelled state
+ post(se);
+ ChatProcessor.this.complete(se);
+ return null;
+ }
+ });
+ }
+
+ private void complete(final AbstractChatEvent event) {
+ if (event.isCancelled()) {
+ return;
+ }
+
+ final CraftPlayer player = this.player.getBukkitEntity();
+
+ final Component message = event.composer().composeChat(
+ event.getPlayer(),
+ displayName(player),
+ event.message()
+ );
+
+ this.server.console.sendMessage(message);
+
+ if (((LazyPlayerSet) event.recipients()).isLazy()) {
+ final IChatBaseComponent vanilla = PaperAdventure.asVanilla(message);
+ for (final EntityPlayer recipient : this.server.getPlayerList().players) {
+ recipient.sendMessage(vanilla, ChatMessageType.CHAT, this.player.getUniqueID());
+ }
+ } else {
+ for (final Player recipient : event.recipients()) {
+ recipient.sendMessage(player, message, MessageType.CHAT);
+ }
+ }
+ }
+
+ private AsyncChatEvent createAsync(final ChatComposer composer, final Set<Player> recipients, final Component message) {
+ return new AsyncChatEvent(this.async, this.player.getBukkitEntity(), recipients, composer, message);
+ }
+
+ private ChatEvent createSync(final ChatComposer composer, final Set<Player> recipients, final Component message) {
+ return new ChatEvent(this.player.getBukkitEntity(), recipients, composer, message);
+ }
+
+ private static String legacyDisplayName(final CraftPlayer player) {
+ return player.getDisplayName();
+ }
+
+ private static Component displayName(final CraftPlayer player) {
+ return player.displayName();
+ }
+
+ private static ChatComposer legacyComposer(final String format) {
+ return (player, displayName, message) -> PaperAdventure.LEGACY_SECTION_UXRC.deserialize(String.format(format, legacyDisplayName((CraftPlayer) player), PaperAdventure.LEGACY_SECTION_UXRC.serialize(message))).replaceText(URL_REPLACEMENT_CONFIG);
+ }
+
+ private void queueIfAsyncOrRunImmediately(final Waitable<Void> waitable) {
+ if (this.async) {
+ this.server.processQueue.add(waitable);
+ } else {
+ waitable.run();
+ }
+ try {
+ waitable.get();
+ } catch (final InterruptedException e) {
+ Thread.currentThread().interrupt(); // tag, you're it
+ } catch (final ExecutionException e) {
+ throw new RuntimeException("Exception processing chat", e.getCause());
+ }
+ }
+
+ private static void post(final Event event) {
+ Bukkit.getPluginManager().callEvent(event);
+ }
+
+ private static boolean anyListeners(final HandlerList handlers) {
+ return handlers.getRegisteredListeners().length > 0;
+ }
+}
diff --git a/src/main/java/io/papermc/paper/adventure/DisplayNames.java b/src/main/java/io/papermc/paper/adventure/DisplayNames.java
new file mode 100644
index 0000000000000000000000000000000000000000..b1d9d6276eb577ed3c66df1f89b3266d2c48eaf2
--- /dev/null
+++ b/src/main/java/io/papermc/paper/adventure/DisplayNames.java
@@ -0,0 +1,22 @@
+package io.papermc.paper.adventure;
+
+import net.minecraft.server.level.EntityPlayer;
+import org.bukkit.ChatColor;
+import org.bukkit.craftbukkit.entity.CraftPlayer;
+
+public final class DisplayNames {
+ private DisplayNames() {
+ }
+
+ public static String getLegacy(final CraftPlayer player) {
+ return getLegacy(player.getHandle());
+ }
+
+ public static String getLegacy(final EntityPlayer player) {
+ final String legacy = player.displayName;
+ if (legacy != null) {
+ return PaperAdventure.LEGACY_SECTION_UXRC.serialize(player.adventure$displayName) + ChatColor.getLastColors(player.displayName);
+ }
+ return PaperAdventure.LEGACY_SECTION_UXRC.serialize(player.adventure$displayName);
+ }
+}
diff --git a/src/main/java/io/papermc/paper/adventure/NBTLegacyHoverEventSerializer.java b/src/main/java/io/papermc/paper/adventure/NBTLegacyHoverEventSerializer.java
new file mode 100644
index 0000000000000000000000000000000000000000..caa9708f321f04cd02534161231c05999bda4acd
--- /dev/null
+++ b/src/main/java/io/papermc/paper/adventure/NBTLegacyHoverEventSerializer.java
@@ -0,0 +1,88 @@
+package io.papermc.paper.adventure;
+
+import com.mojang.brigadier.exceptions.CommandSyntaxException;
+import java.io.IOException;
+import java.util.UUID;
+import net.kyori.adventure.key.Key;
+import net.kyori.adventure.nbt.api.BinaryTagHolder;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.event.HoverEvent;
+import net.kyori.adventure.text.serializer.gson.LegacyHoverEventSerializer;
+import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer;
+import net.kyori.adventure.util.Codec;
+import net.minecraft.nbt.MojangsonParser;
+import net.minecraft.nbt.NBTBase;
+import net.minecraft.nbt.NBTTagCompound;
+
+final class NBTLegacyHoverEventSerializer implements LegacyHoverEventSerializer {
+ public static final NBTLegacyHoverEventSerializer INSTANCE = new NBTLegacyHoverEventSerializer();
+ private static final Codec<NBTTagCompound, String, CommandSyntaxException, RuntimeException> SNBT_CODEC = Codec.of(MojangsonParser::parse, NBTBase::toString);
+
+ static final String ITEM_TYPE = "id";
+ static final String ITEM_COUNT = "Count";
+ static final String ITEM_TAG = "tag";
+
+ static final String ENTITY_NAME = "name";
+ static final String ENTITY_TYPE = "type";
+ static final String ENTITY_ID = "id";
+
+ NBTLegacyHoverEventSerializer() {
+ }
+
+ @Override
+ public HoverEvent.ShowItem deserializeShowItem(final Component input) throws IOException {
+ final String raw = PlainComponentSerializer.plain().serialize(input);
+ try {
+ final NBTTagCompound contents = SNBT_CODEC.decode(raw);
+ final NBTTagCompound tag = contents.getCompound(ITEM_TAG);
+ return HoverEvent.ShowItem.of(
+ Key.key(contents.getString(ITEM_TYPE)),
+ contents.hasKey(ITEM_COUNT) ? contents.getByte(ITEM_COUNT) : 1,
+ tag.isEmpty() ? null : BinaryTagHolder.encode(tag, SNBT_CODEC)
+ );
+ } catch (final CommandSyntaxException ex) {
+ throw new IOException(ex);
+ }
+ }
+
+ @Override
+ public HoverEvent.ShowEntity deserializeShowEntity(final Component input, final Codec.Decoder<Component, String, ? extends RuntimeException> componentCodec) throws IOException {
+ final String raw = PlainComponentSerializer.plain().serialize(input);
+ try {
+ final NBTTagCompound contents = SNBT_CODEC.decode(raw);
+ return HoverEvent.ShowEntity.of(
+ Key.key(contents.getString(ENTITY_TYPE)),
+ UUID.fromString(contents.getString(ENTITY_ID)),
+ componentCodec.decode(contents.getString(ENTITY_NAME))
+ );
+ } catch (final CommandSyntaxException ex) {
+ throw new IOException(ex);
+ }
+ }
+
+ @Override
+ public Component serializeShowItem(final HoverEvent.ShowItem input) throws IOException {
+ final NBTTagCompound tag = new NBTTagCompound();
+ tag.setString(ITEM_TYPE, input.item().asString());
+ tag.setByte(ITEM_COUNT, (byte) input.count());
+ if (input.nbt() != null) {
+ try {
+ tag.set(ITEM_TAG, input.nbt().get(SNBT_CODEC));
+ } catch (final CommandSyntaxException ex) {
+ throw new IOException(ex);
+ }
+ }
+ return Component.text(SNBT_CODEC.encode(tag));
+ }
+
+ @Override
+ public Component serializeShowEntity(final HoverEvent.ShowEntity input, final Codec.Encoder<Component, String, ? extends RuntimeException> componentCodec) throws IOException {
+ final NBTTagCompound tag = new NBTTagCompound();
+ tag.setString(ENTITY_ID, input.id().toString());
+ tag.setString(ENTITY_TYPE, input.type().asString());
+ if (input.name() != null) {
+ tag.setString(ENTITY_NAME, componentCodec.encode(input.name()));
+ }
+ return Component.text(SNBT_CODEC.encode(tag));
+ }
+}
diff --git a/src/main/java/io/papermc/paper/adventure/PaperAdventure.java b/src/main/java/io/papermc/paper/adventure/PaperAdventure.java
new file mode 100644
index 0000000000000000000000000000000000000000..cd2da276c09dcf98c1c50dc66aa30dd3b67b43af
--- /dev/null
+++ b/src/main/java/io/papermc/paper/adventure/PaperAdventure.java
@@ -0,0 +1,344 @@
+package io.papermc.paper.adventure;
+
+import com.mojang.brigadier.exceptions.CommandSyntaxException;
+import io.netty.util.AttributeKey;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import net.kyori.adventure.bossbar.BossBar;
+import net.kyori.adventure.inventory.Book;
+import net.kyori.adventure.key.Key;
+import net.kyori.adventure.nbt.api.BinaryTagHolder;
+import net.kyori.adventure.sound.Sound;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.TranslatableComponent;
+import net.kyori.adventure.text.flattener.ComponentFlattener;
+import net.kyori.adventure.text.format.TextColor;
+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 net.kyori.adventure.translation.GlobalTranslator;
+import net.kyori.adventure.util.Codec;
+import net.minecraft.EnumChatFormat;
+import net.minecraft.locale.LocaleLanguage;
+import net.minecraft.nbt.MojangsonParser;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.nbt.NBTTagList;
+import net.minecraft.nbt.NBTTagString;
+import net.minecraft.network.chat.IChatBaseComponent;
+import net.minecraft.resources.MinecraftKey;
+import net.minecraft.sounds.SoundCategory;
+import net.minecraft.world.BossBattle;
+import net.minecraft.world.item.ItemStack;
+import org.bukkit.ChatColor;
+import org.checkerframework.checker.nullness.qual.NonNull;
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+public final class PaperAdventure {
+ public static final AttributeKey<Locale> LOCALE_ATTRIBUTE = AttributeKey.valueOf("adventure:locale");
+ private static final Pattern LOCALIZATION_PATTERN = Pattern.compile("%(?:(\\d+)\\$)?s");
+ public static final ComponentFlattener FLATTENER = ComponentFlattener.basic().toBuilder()
+ .complexMapper(TranslatableComponent.class, (translatable, consumer) -> {
+ final @NonNull String translated = LocaleLanguage.a().a(translatable.key());
+
+ final Matcher matcher = LOCALIZATION_PATTERN.matcher(translated);
+ final List<Component> args = translatable.args();
+ int argPosition = 0;
+ int lastIdx = 0;
+ while (matcher.find()) {
+ // append prior
+ if (lastIdx < matcher.start()) {
+ consumer.accept(Component.text(translated.substring(lastIdx, matcher.start())));
+ }
+ lastIdx = matcher.end();
+
+ final @Nullable String argIdx = matcher.group(1);
+ // calculate argument position
+ if (argIdx != null) {
+ try {
+ final int idx = Integer.parseInt(argIdx);
+ if (idx < args.size()) {
+ consumer.accept(args.get(idx));
+ }
+ } catch (final NumberFormatException ex) {
+ // ignore, drop the format placeholder
+ }
+ } else {
+ final int idx = argPosition++;
+ if (idx < args.size()) {
+ consumer.accept(args.get(idx));
+ }
+ }
+ }
+
+ // append tail
+ if (lastIdx < translated.length()) {
+ consumer.accept(Component.text(translated.substring(lastIdx)));
+ }
+ })
+ .build();
+ public static final LegacyComponentSerializer LEGACY_SECTION_UXRC = LegacyComponentSerializer.builder().flattener(FLATTENER).hexColors().useUnusualXRepeatedCharacterHexFormat().build();
+ public static final PlainComponentSerializer PLAIN = PlainComponentSerializer.builder().flattener(FLATTENER).build();
+ public static final GsonComponentSerializer GSON = GsonComponentSerializer.builder()
+ .legacyHoverEventSerializer(NBTLegacyHoverEventSerializer.INSTANCE)
+ .build();
+ public static final GsonComponentSerializer COLOR_DOWNSAMPLING_GSON = GsonComponentSerializer.builder()
+ .legacyHoverEventSerializer(NBTLegacyHoverEventSerializer.INSTANCE)
+ .downsampleColors()
+ .build();
+ private static final Codec<NBTTagCompound, String, IOException, IOException> NBT_CODEC = new Codec<NBTTagCompound, String, IOException, IOException>() {
+ @Override
+ public @NonNull NBTTagCompound decode(final @NonNull String encoded) throws IOException {
+ try {
+ return MojangsonParser.parse(encoded);
+ } catch (final CommandSyntaxException e) {
+ throw new IOException(e);
+ }
+ }
+
+ @Override
+ public @NonNull String encode(final @NonNull NBTTagCompound decoded) {
+ return decoded.toString();
+ }
+ };
+ static final WrapperAwareSerializer WRAPPER_AWARE_SERIALIZER = new WrapperAwareSerializer();
+
+ private PaperAdventure() {
+ }
+
+ // Key
+
+ public static MinecraftKey asVanilla(final Key key) {
+ return new MinecraftKey(key.namespace(), key.value());
+ }
+
+ public static MinecraftKey asVanillaNullable(final Key key) {
+ if (key == null) {
+ return null;
+ }
+ return new MinecraftKey(key.namespace(), key.value());
+ }
+
+ // Component
+
+ public static Component asAdventure(final IChatBaseComponent component) {
+ return GSON.serializer().fromJson(IChatBaseComponent.ChatSerializer.toJsonTree(component), Component.class);
+ }
+
+ public static ArrayList<Component> asAdventure(final List<IChatBaseComponent> vanillas) {
+ final ArrayList<Component> adventures = new ArrayList<>(vanillas.size());
+ for (final IChatBaseComponent vanilla : vanillas) {
+ adventures.add(asAdventure(vanilla));
+ }
+ return adventures;
+ }
+
+ public static ArrayList<Component> asAdventureFromJson(final List<String> jsonStrings) {
+ final ArrayList<Component> adventures = new ArrayList<>(jsonStrings.size());
+ for (final String json : jsonStrings) {
+ adventures.add(GsonComponentSerializer.gson().deserialize(json));
+ }
+ return adventures;
+ }
+
+ public static List<String> asJson(final List<Component> adventures) {
+ final List<String> jsons = new ArrayList<>(adventures.size());
+ for (final Component component : adventures) {
+ jsons.add(GsonComponentSerializer.gson().serialize(component));
+ }
+ return jsons;
+ }
+
+ public static IChatBaseComponent asVanilla(final Component component) {
+ if (true) return new AdventureComponent(component);
+ return IChatBaseComponent.ChatSerializer.fromJsonTree(GSON.serializer().toJsonTree(component));
+ }
+
+ public static List<IChatBaseComponent> asVanilla(final List<Component> adventures) {
+ final List<IChatBaseComponent> vanillas = new ArrayList<>(adventures.size());
+ for (final Component adventure : adventures) {
+ vanillas.add(asVanilla(adventure));
+ }
+ return vanillas;
+ }
+
+ public static String asJsonString(final Component component, final Locale locale) {
+ return GSON.serialize(
+ GlobalTranslator.render(
+ component,
+ // play it safe
+ locale != null
+ ? locale
+ : Locale.US
+ )
+ );
+ }
+
+ public static String asJsonString(final IChatBaseComponent component, final Locale locale) {
+ if (component instanceof AdventureComponent) {
+ return asJsonString(((AdventureComponent) component).wrapped, locale);
+ }
+ return IChatBaseComponent.ChatSerializer.componentToJson(component);
+ }
+
+ // thank you for being worse than wet socks, Bukkit
+ public static String superHackyLegacyRepresentationOfComponent(final Component component, final String string) {
+ return LEGACY_SECTION_UXRC.serialize(component) + ChatColor.getLastColors(string);
+ }
+
+ // BossBar
+
+ public static BossBattle.BarColor asVanilla(final BossBar.Color color) {
+ if (color == BossBar.Color.PINK) {
+ return BossBattle.BarColor.PINK;
+ } else if (color == BossBar.Color.BLUE) {
+ return BossBattle.BarColor.BLUE;
+ } else if (color == BossBar.Color.RED) {
+ return BossBattle.BarColor.RED;
+ } else if (color == BossBar.Color.GREEN) {
+ return BossBattle.BarColor.GREEN;
+ } else if (color == BossBar.Color.YELLOW) {
+ return BossBattle.BarColor.YELLOW;
+ } else if (color == BossBar.Color.PURPLE) {
+ return BossBattle.BarColor.PURPLE;
+ } else if (color == BossBar.Color.WHITE) {
+ return BossBattle.BarColor.WHITE;
+ }
+ throw new IllegalArgumentException(color.name());
+ }
+
+ public static BossBar.Color asAdventure(final BossBattle.BarColor color) {
+ if(color == BossBattle.BarColor.PINK) {
+ return BossBar.Color.PINK;
+ } else if(color == BossBattle.BarColor.BLUE) {
+ return BossBar.Color.BLUE;
+ } else if(color == BossBattle.BarColor.RED) {
+ return BossBar.Color.RED;
+ } else if(color == BossBattle.BarColor.GREEN) {
+ return BossBar.Color.GREEN;
+ } else if(color == BossBattle.BarColor.YELLOW) {
+ return BossBar.Color.YELLOW;
+ } else if(color == BossBattle.BarColor.PURPLE) {
+ return BossBar.Color.PURPLE;
+ } else if(color == BossBattle.BarColor.WHITE) {
+ return BossBar.Color.WHITE;
+ }
+ throw new IllegalArgumentException(color.name());
+ }
+
+ public static BossBattle.BarStyle asVanilla(final BossBar.Overlay overlay) {
+ if (overlay == BossBar.Overlay.PROGRESS) {
+ return BossBattle.BarStyle.PROGRESS;
+ } else if (overlay == BossBar.Overlay.NOTCHED_6) {
+ return BossBattle.BarStyle.NOTCHED_6;
+ } else if (overlay == BossBar.Overlay.NOTCHED_10) {
+ return BossBattle.BarStyle.NOTCHED_10;
+ } else if (overlay == BossBar.Overlay.NOTCHED_12) {
+ return BossBattle.BarStyle.NOTCHED_12;
+ } else if (overlay == BossBar.Overlay.NOTCHED_20) {
+ return BossBattle.BarStyle.NOTCHED_20;
+ }
+ throw new IllegalArgumentException(overlay.name());
+ }
+
+ public static BossBar.Overlay asAdventure(final BossBattle.BarStyle overlay) {
+ if (overlay == BossBattle.BarStyle.PROGRESS) {
+ return BossBar.Overlay.PROGRESS;
+ } else if (overlay == BossBattle.BarStyle.NOTCHED_6) {
+ return BossBar.Overlay.NOTCHED_6;
+ } else if (overlay == BossBattle.BarStyle.NOTCHED_10) {
+ return BossBar.Overlay.NOTCHED_10;
+ } else if (overlay == BossBattle.BarStyle.NOTCHED_12) {
+ return BossBar.Overlay.NOTCHED_12;
+ } else if (overlay == BossBattle.BarStyle.NOTCHED_20) {
+ return BossBar.Overlay.NOTCHED_20;
+ }
+ throw new IllegalArgumentException(overlay.name());
+ }
+
+ public static void setFlag(final BossBar bar, final BossBar.Flag flag, final boolean value) {
+ if (value) {
+ bar.addFlag(flag);
+ } else {
+ bar.removeFlag(flag);
+ }
+ }
+
+ // Book
+
+ public static ItemStack asItemStack(final Book book, final Locale locale) {
+ final ItemStack item = new ItemStack(net.minecraft.world.item.Items.WRITTEN_BOOK, 1);
+ final NBTTagCompound tag = item.getOrCreateTag();
+ tag.setString("title", asJsonString(book.title(), locale));
+ tag.setString("author", asJsonString(book.author(), locale));
+ final NBTTagList pages = new NBTTagList();
+ for (final Component page : book.pages()) {
+ pages.add(NBTTagString.create(asJsonString(page, locale)));
+ }
+ tag.set("pages", pages);
+ return item;
+ }
+
+ // Sounds
+
+ public static SoundCategory asVanilla(final Sound.Source source) {
+ if (source == Sound.Source.MASTER) {
+ return SoundCategory.MASTER;
+ } else if (source == Sound.Source.MUSIC) {
+ return SoundCategory.MUSIC;
+ } else if (source == Sound.Source.RECORD) {
+ return SoundCategory.RECORDS;
+ } else if (source == Sound.Source.WEATHER) {
+ return SoundCategory.WEATHER;
+ } else if (source == Sound.Source.BLOCK) {
+ return SoundCategory.BLOCKS;
+ } else if (source == Sound.Source.HOSTILE) {
+ return SoundCategory.HOSTILE;
+ } else if (source == Sound.Source.NEUTRAL) {
+ return SoundCategory.NEUTRAL;
+ } else if (source == Sound.Source.PLAYER) {
+ return SoundCategory.PLAYERS;
+ } else if (source == Sound.Source.AMBIENT) {
+ return SoundCategory.AMBIENT;
+ } else if (source == Sound.Source.VOICE) {
+ return SoundCategory.VOICE;
+ }
+ throw new IllegalArgumentException(source.name());
+ }
+
+ public static @Nullable SoundCategory asVanillaNullable(final Sound.@Nullable Source source) {
+ if (source == null) {
+ return null;
+ }
+ return asVanilla(source);
+ }
+
+ // NBT
+
+ public static @Nullable BinaryTagHolder asBinaryTagHolder(final @Nullable NBTTagCompound tag) {
+ if (tag == null) {
+ return null;
+ }
+ try {
+ return BinaryTagHolder.encode(tag, NBT_CODEC);
+ } catch (final IOException e) {
+ return null;
+ }
+ }
+
+ // Colors
+
+ public static @NonNull TextColor asAdventure(EnumChatFormat minecraftColor) {
+ if (minecraftColor.e() == null) {
+ throw new IllegalArgumentException("Not a valid color");
+ }
+ return TextColor.color(minecraftColor.e());
+ }
+
+ public static @Nullable EnumChatFormat asVanilla(TextColor color) {
+ return EnumChatFormat.getByHexValue(color.value());
+ }
+}
diff --git a/src/main/java/io/papermc/paper/adventure/VanillaBossBarListener.java b/src/main/java/io/papermc/paper/adventure/VanillaBossBarListener.java
new file mode 100644
index 0000000000000000000000000000000000000000..3a4158781e464d9a860bab72ed719a41929c8add
--- /dev/null
+++ b/src/main/java/io/papermc/paper/adventure/VanillaBossBarListener.java
@@ -0,0 +1,41 @@
+package io.papermc.paper.adventure;
+
+import java.util.Set;
+import java.util.function.Consumer;
+import net.kyori.adventure.bossbar.BossBar;
+import net.kyori.adventure.text.Component;
+import net.minecraft.network.protocol.game.PacketPlayOutBoss;
+import org.checkerframework.checker.nullness.qual.NonNull;
+
+public final class VanillaBossBarListener implements BossBar.Listener {
+ private final Consumer<PacketPlayOutBoss.Action> action;
+
+ public VanillaBossBarListener(final Consumer<PacketPlayOutBoss.Action> action) {
+ this.action = action;
+ }
+
+ @Override
+ public void bossBarNameChanged(final @NonNull BossBar bar, final @NonNull Component oldName, final @NonNull Component newName) {
+ this.action.accept(PacketPlayOutBoss.Action.UPDATE_NAME);
+ }
+
+ @Override
+ public void bossBarProgressChanged(final @NonNull BossBar bar, final float oldProgress, final float newProgress) {
+ this.action.accept(PacketPlayOutBoss.Action.UPDATE_PCT);
+ }
+
+ @Override
+ public void bossBarColorChanged(final @NonNull BossBar bar, final BossBar.@NonNull Color oldColor, final BossBar.@NonNull Color newColor) {
+ this.action.accept(PacketPlayOutBoss.Action.UPDATE_STYLE);
+ }
+
+ @Override
+ public void bossBarOverlayChanged(final @NonNull BossBar bar, final BossBar.@NonNull Overlay oldOverlay, final BossBar.@NonNull Overlay newOverlay) {
+ this.action.accept(PacketPlayOutBoss.Action.UPDATE_STYLE);
+ }
+
+ @Override
+ public void bossBarFlagsChanged(final @NonNull BossBar bar, final @NonNull Set<BossBar.Flag> flagsAdded, final @NonNull Set<BossBar.Flag> flagsRemoved) {
+ this.action.accept(PacketPlayOutBoss.Action.UPDATE_PROPERTIES);
+ }
+}
diff --git a/src/main/java/io/papermc/paper/adventure/WrapperAwareSerializer.java b/src/main/java/io/papermc/paper/adventure/WrapperAwareSerializer.java
new file mode 100644
index 0000000000000000000000000000000000000000..625b57a4274d6348a85897b92ff07fee7ae3a7ab
--- /dev/null
+++ b/src/main/java/io/papermc/paper/adventure/WrapperAwareSerializer.java
@@ -0,0 +1,20 @@
+package io.papermc.paper.adventure;
+
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.serializer.ComponentSerializer;
+import net.minecraft.network.chat.IChatBaseComponent;
+
+final class WrapperAwareSerializer implements ComponentSerializer<Component, Component, IChatBaseComponent> {
+ @Override
+ public Component deserialize(final IChatBaseComponent input) {
+ if (input instanceof AdventureComponent) {
+ return ((AdventureComponent) input).wrapped;
+ }
+ return PaperAdventure.GSON.serializer().fromJson(IChatBaseComponent.ChatSerializer.toJsonTree(input), Component.class);
+ }
+
+ @Override
+ public IChatBaseComponent serialize(final Component component) {
+ return IChatBaseComponent.ChatSerializer.fromJsonTree(PaperAdventure.GSON.serializer().toJsonTree(component));
+ }
+}
diff --git a/src/main/java/net/kyori/adventure/bossbar/HackyBossBarPlatformBridge.java b/src/main/java/net/kyori/adventure/bossbar/HackyBossBarPlatformBridge.java
new file mode 100644
index 0000000000000000000000000000000000000000..b3e26b9ecca7055760d05975d36c9ae74e0d7d4b
--- /dev/null
+++ b/src/main/java/net/kyori/adventure/bossbar/HackyBossBarPlatformBridge.java
@@ -0,0 +1,36 @@
+package net.kyori.adventure.bossbar;
+
+import io.papermc.paper.adventure.PaperAdventure;
+import io.papermc.paper.adventure.VanillaBossBarListener;
+import net.minecraft.server.level.BossBattleServer;
+import org.bukkit.craftbukkit.entity.CraftPlayer;
+
+public abstract class HackyBossBarPlatformBridge {
+ public BossBattleServer vanilla$bar;
+ private VanillaBossBarListener vanilla$listener;
+
+ public final void paper$playerShow(final CraftPlayer player) {
+ if (this.vanilla$bar == null) {
+ final BossBar $this = (BossBar) this;
+ this.vanilla$bar = new BossBattleServer(
+ PaperAdventure.asVanilla($this.name()),
+ PaperAdventure.asVanilla($this.color()),
+ PaperAdventure.asVanilla($this.overlay())
+ );
+ this.vanilla$bar.adventure = $this;
+ this.vanilla$listener = new VanillaBossBarListener(this.vanilla$bar::sendUpdate);
+ $this.addListener(this.vanilla$listener);
+ }
+ this.vanilla$bar.addPlayer(player.getHandle());
+ }
+
+ public final void paper$playerHide(final CraftPlayer player) {
+ if (this.vanilla$bar != null) {
+ this.vanilla$bar.removePlayer(player.getHandle());
+ if (this.vanilla$bar.getPlayers().isEmpty()) {
+ ((BossBar) this).removeListener(this.vanilla$listener);
+ this.vanilla$bar = null;
+ }
+ }
+ }
+}
diff --git a/src/main/java/net/minecraft/EnumChatFormat.java b/src/main/java/net/minecraft/EnumChatFormat.java
index 75e38f05c10713f773a8763100dfc0777521dba6..cd93f99e939438c572a4258d299a6038ebfc60a8 100644
--- a/src/main/java/net/minecraft/EnumChatFormat.java
+++ b/src/main/java/net/minecraft/EnumChatFormat.java
@@ -61,6 +61,7 @@ public enum EnumChatFormat {
return !this.A && this != EnumChatFormat.RESET;
}
+ @Nullable public Integer getHexValue() { return this.e(); } // Paper - OBFHELPER
@Nullable
public Integer e() {
return this.D;
@@ -84,6 +85,18 @@ public enum EnumChatFormat {
return s == null ? null : (EnumChatFormat) EnumChatFormat.w.get(c(s));
}
+ // Paper start
+ @Nullable public static EnumChatFormat getByHexValue(int i) {
+ for (EnumChatFormat value : values()) {
+ if (value.getHexValue() != null && value.getHexValue() == i) {
+ return value;
+ }
+ }
+
+ return null;
+ }
+ // Paper end
+
@Nullable
public static EnumChatFormat a(int i) {
if (i < 0) {
diff --git a/src/main/java/net/minecraft/nbt/NBTTagString.java b/src/main/java/net/minecraft/nbt/NBTTagString.java
index e26ef49d9dde8ed0fb4267b48cb597563967f313..0e41fdb6ba711fbd2240d62e2030b3a12e14c8d6 100644
--- a/src/main/java/net/minecraft/nbt/NBTTagString.java
+++ b/src/main/java/net/minecraft/nbt/NBTTagString.java
@@ -43,6 +43,7 @@ public class NBTTagString implements NBTBase {
this.data = s;
}
+ public static NBTTagString create(final String value) { return a(value); } // Paper - OBFHELPER
public static NBTTagString a(String s) {
return s.isEmpty() ? NBTTagString.b : new NBTTagString(s);
}
diff --git a/src/main/java/net/minecraft/network/PacketDataSerializer.java b/src/main/java/net/minecraft/network/PacketDataSerializer.java
index 5413bf93f7f0f4491fca1f07c47a925fdace7751..5f1c5dd7902f6cff5acae05e8c6bf58a1ba5bdf1 100644
--- a/src/main/java/net/minecraft/network/PacketDataSerializer.java
+++ b/src/main/java/net/minecraft/network/PacketDataSerializer.java
@@ -10,6 +10,7 @@ import io.netty.buffer.ByteBufOutputStream;
import io.netty.handler.codec.DecoderException;
import io.netty.handler.codec.EncoderException;
import io.netty.util.ByteProcessor;
+import io.papermc.paper.adventure.PaperAdventure; // Paper
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
@@ -44,6 +45,7 @@ import org.bukkit.craftbukkit.inventory.CraftItemStack; // CraftBukkit
public class PacketDataSerializer extends ByteBuf {
private final ByteBuf a;
+ public java.util.Locale adventure$locale; // Paper
public PacketDataSerializer(ByteBuf bytebuf) {
this.a = bytebuf;
@@ -165,8 +167,15 @@ public class PacketDataSerializer extends ByteBuf {
return IChatBaseComponent.ChatSerializer.a(this.e(262144));
}
+ // Paper start
+ public PacketDataSerializer writeComponent(final net.kyori.adventure.text.Component component) {
+ return this.writeUtf(PaperAdventure.asJsonString(component, this.adventure$locale), 262144);
+ }
+ // Paper end
+
public PacketDataSerializer a(IChatBaseComponent ichatbasecomponent) {
- return this.a(IChatBaseComponent.ChatSerializer.a(ichatbasecomponent), 262144);
+ //return this.a(IChatBaseComponent.ChatSerializer.a(ichatbasecomponent), 262144); // Paper - comment
+ return this.writeUtf(PaperAdventure.asJsonString(ichatbasecomponent, this.adventure$locale), 262144); // Paper
}
public <T extends Enum<T>> T a(Class<T> oclass) {
@@ -349,6 +358,7 @@ public class PacketDataSerializer extends ByteBuf {
return this.a(s, 32767);
}
+ public PacketDataSerializer writeUtf(final String string, final int maxLength) { return this.a(string, maxLength); } // Paper - OBFHELPER
public PacketDataSerializer a(String s, int i) {
byte[] abyte = s.getBytes(StandardCharsets.UTF_8);
diff --git a/src/main/java/net/minecraft/network/PacketEncoder.java b/src/main/java/net/minecraft/network/PacketEncoder.java
index dc8cc8d6c00176c8562086282f726dc1b24b2c65..2f6da89d6b25ba5144ec15b1bf0e8ed13278e85e 100644
--- a/src/main/java/net/minecraft/network/PacketEncoder.java
+++ b/src/main/java/net/minecraft/network/PacketEncoder.java
@@ -3,6 +3,7 @@ package net.minecraft.network;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
+import io.papermc.paper.adventure.PaperAdventure; // Paper
import java.io.IOException;
import net.minecraft.network.protocol.EnumProtocolDirection;
import net.minecraft.network.protocol.Packet;
@@ -37,6 +38,7 @@ public class PacketEncoder extends MessageToByteEncoder<Packet<?>> {
throw new IOException("Can't serialize unregistered packet");
} else {
PacketDataSerializer packetdataserializer = new PacketDataSerializer(bytebuf);
+ packetdataserializer.adventure$locale = channelhandlercontext.channel().attr(PaperAdventure.LOCALE_ATTRIBUTE).get(); // Paper
packetdataserializer.d(integer);
diff --git a/src/main/java/net/minecraft/network/chat/IChatBaseComponent.java b/src/main/java/net/minecraft/network/chat/IChatBaseComponent.java
index 85140d961722e86abfe7006a0ad752751e73c721..c7c191b0a9889450fdf495f5aa45d59f159f1401 100644
--- a/src/main/java/net/minecraft/network/chat/IChatBaseComponent.java
+++ b/src/main/java/net/minecraft/network/chat/IChatBaseComponent.java
@@ -1,5 +1,6 @@
package net.minecraft.network.chat;
+import io.papermc.paper.adventure.AdventureComponent; // Paper
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
@@ -111,6 +112,7 @@ public interface IChatBaseComponent extends Message, IChatFormatted, Iterable<IC
GsonBuilder gsonbuilder = new GsonBuilder();
gsonbuilder.disableHtmlEscaping();
+ gsonbuilder.registerTypeAdapter(AdventureComponent.class, new AdventureComponent.Serializer()); // Paper
gsonbuilder.registerTypeHierarchyAdapter(IChatBaseComponent.class, new IChatBaseComponent.ChatSerializer());
gsonbuilder.registerTypeHierarchyAdapter(ChatModifier.class, new ChatModifier.ChatModifierSerializer());
gsonbuilder.registerTypeAdapterFactory(new ChatTypeAdapterFactory());
@@ -351,10 +353,12 @@ public interface IChatBaseComponent extends Message, IChatFormatted, Iterable<IC
return jsonobject;
}
+ public static String componentToJson(final IChatBaseComponent component) { return a(component); } // Paper - OBFHELPER
public static String a(IChatBaseComponent ichatbasecomponent) {
return IChatBaseComponent.ChatSerializer.a.toJson(ichatbasecomponent);
}
+ public static JsonElement toJsonTree(final IChatBaseComponent component) { return b(component); } // Paper - OBFHELPER
public static JsonElement b(IChatBaseComponent ichatbasecomponent) {
return IChatBaseComponent.ChatSerializer.a.toJsonTree(ichatbasecomponent);
}
@@ -364,6 +368,7 @@ public interface IChatBaseComponent extends Message, IChatFormatted, Iterable<IC
return (IChatMutableComponent) ChatDeserializer.a(IChatBaseComponent.ChatSerializer.a, s, IChatMutableComponent.class, false);
}
+ public static @Nullable IChatBaseComponent fromJsonTree(final JsonElement json) { return a(json); } // Paper - OBFHELPER
@Nullable
public static IChatMutableComponent a(JsonElement jsonelement) {
return (IChatMutableComponent) IChatBaseComponent.ChatSerializer.a.fromJson(jsonelement, IChatMutableComponent.class);
diff --git a/src/main/java/net/minecraft/network/protocol/game/PacketPlayOutChat.java b/src/main/java/net/minecraft/network/protocol/game/PacketPlayOutChat.java
index 2bfe15e693271bcd4bbccfa436bae72178633135..edae451a54bfcd6b54e89c1619fb112a7763eb3b 100644
--- a/src/main/java/net/minecraft/network/protocol/game/PacketPlayOutChat.java
+++ b/src/main/java/net/minecraft/network/protocol/game/PacketPlayOutChat.java
@@ -11,6 +11,7 @@ import net.minecraft.network.protocol.Packet;
public class PacketPlayOutChat implements Packet<PacketListenerPlayOut> {
private IChatBaseComponent a;
+ public net.kyori.adventure.text.Component adventure$message; // Paper
public net.md_5.bungee.api.chat.BaseComponent[] components; // Spigot
private ChatMessageType b;
private UUID c;
@@ -32,6 +33,11 @@ public class PacketPlayOutChat implements Packet<PacketListenerPlayOut> {
@Override
public void b(PacketDataSerializer packetdataserializer) throws IOException {
+ // Paper start
+ if (this.adventure$message != null) {
+ packetdataserializer.writeComponent(this.adventure$message);
+ } else
+ // Paper end
// Spigot start
if (components != null) {
packetdataserializer.a(net.md_5.bungee.chat.ComponentSerializer.toString(components));
diff --git a/src/main/java/net/minecraft/network/protocol/game/PacketPlayOutPlayerListHeaderFooter.java b/src/main/java/net/minecraft/network/protocol/game/PacketPlayOutPlayerListHeaderFooter.java
index 0268b8e6595ee919bcd55a74ba872a2b7d2a17d8..4ff73a4fc5e8a8739e57d2bac65076812cbe5132 100644
--- a/src/main/java/net/minecraft/network/protocol/game/PacketPlayOutPlayerListHeaderFooter.java
+++ b/src/main/java/net/minecraft/network/protocol/game/PacketPlayOutPlayerListHeaderFooter.java
@@ -9,6 +9,10 @@ public class PacketPlayOutPlayerListHeaderFooter implements Packet<PacketListene
public IChatBaseComponent header;
public IChatBaseComponent footer;
+ // Paper start
+ public net.kyori.adventure.text.Component adventure$header;
+ public net.kyori.adventure.text.Component adventure$footer;
+ // Paper end
public PacketPlayOutPlayerListHeaderFooter() {}
@@ -20,6 +24,13 @@ public class PacketPlayOutPlayerListHeaderFooter implements Packet<PacketListene
@Override
public void b(PacketDataSerializer packetdataserializer) throws IOException {
+ // Paper start
+ if (this.adventure$header != null && this.adventure$footer != null) {
+ packetdataserializer.writeComponent(this.adventure$header);
+ packetdataserializer.writeComponent(this.adventure$footer);
+ return;
+ }
+ // Paper end
packetdataserializer.a(this.header);
packetdataserializer.a(this.footer);
}
diff --git a/src/main/java/net/minecraft/network/protocol/game/PacketPlayOutTitle.java b/src/main/java/net/minecraft/network/protocol/game/PacketPlayOutTitle.java
index 9c44a3d9273afaf4d35f4ff86727386b34d9eb06..fff22c40ba38575951e8e4821ade22b29d580a89 100644
--- a/src/main/java/net/minecraft/network/protocol/game/PacketPlayOutTitle.java
+++ b/src/main/java/net/minecraft/network/protocol/game/PacketPlayOutTitle.java
@@ -10,6 +10,7 @@ public class PacketPlayOutTitle implements Packet<PacketListenerPlayOut> {
private PacketPlayOutTitle.EnumTitleAction a;
private IChatBaseComponent b;
+ public net.kyori.adventure.text.Component adventure$text; // Paper
private int c;
private int d;
private int e;
@@ -51,6 +52,11 @@ public class PacketPlayOutTitle implements Packet<PacketListenerPlayOut> {
public void b(PacketDataSerializer packetdataserializer) throws IOException {
packetdataserializer.a((Enum) this.a);
if (this.a == PacketPlayOutTitle.EnumTitleAction.TITLE || this.a == PacketPlayOutTitle.EnumTitleAction.SUBTITLE || this.a == PacketPlayOutTitle.EnumTitleAction.ACTIONBAR) {
+ // Paper start
+ if (this.adventure$text != null) {
+ packetdataserializer.writeComponent(this.adventure$text);
+ } else
+ // Paper end
packetdataserializer.a(this.b);
}
diff --git a/src/main/java/net/minecraft/server/level/EntityPlayer.java b/src/main/java/net/minecraft/server/level/EntityPlayer.java
index e818bf022b74cae34a512d8c98b47ec3e5c74b9a..bb309790dc90aedabb3c48ea21cd87d1819d2261 100644
--- a/src/main/java/net/minecraft/server/level/EntityPlayer.java
+++ b/src/main/java/net/minecraft/server/level/EntityPlayer.java
@@ -143,6 +143,7 @@ import net.minecraft.world.item.enchantment.EnchantmentManager;
import net.minecraft.world.level.block.BlockChest;
import net.minecraft.world.level.dimension.DimensionManager;
import net.minecraft.world.scores.Scoreboard;
+import io.papermc.paper.adventure.PaperAdventure; // Paper
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
@@ -211,6 +212,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
// CraftBukkit start
public String displayName;
+ public net.kyori.adventure.text.Component adventure$displayName; // Paper
public IChatBaseComponent listName;
public org.bukkit.Location compassTarget;
public int newExp = 0;
@@ -241,6 +243,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
// CraftBukkit start
this.displayName = this.getName();
+ this.adventure$displayName = net.kyori.adventure.text.Component.text(this.getName()); // Paper
this.canPickUpLoot = true;
this.maxHealthCache = this.getMaxHealth();
}
@@ -694,23 +697,17 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
IChatBaseComponent defaultMessage = this.getCombatTracker().getDeathMessage();
- String deathmessage = defaultMessage.getString();
- org.bukkit.event.entity.PlayerDeathEvent event = CraftEventFactory.callPlayerDeathEvent(this, loot, deathmessage, keepInventory);
+ org.bukkit.event.entity.PlayerDeathEvent event = CraftEventFactory.callPlayerDeathEvent(this, loot, PaperAdventure.asAdventure(defaultMessage), defaultMessage.getString(), keepInventory); // Paper - Adventure
// SPIGOT-943 - only call if they have an inventory open
if (this.activeContainer != this.defaultContainer) {
this.closeInventory();
}
- String deathMessage = event.getDeathMessage();
+ net.kyori.adventure.text.Component deathMessage = event.deathMessage() != null ? event.deathMessage() : net.kyori.adventure.text.Component.empty(); // Paper - Adventure
- if (deathMessage != null && deathMessage.length() > 0 && flag) { // TODO: allow plugins to override?
- IChatBaseComponent ichatbasecomponent;
- if (deathMessage.equals(deathmessage)) {
- ichatbasecomponent = this.getCombatTracker().getDeathMessage();
- } else {
- ichatbasecomponent = org.bukkit.craftbukkit.util.CraftChatMessage.fromStringOrNull(deathMessage);
- }
+ if (deathMessage != null && deathMessage != net.kyori.adventure.text.Component.empty() && flag) { // Paper - Adventure // TODO: allow plugins to override?
+ IChatBaseComponent ichatbasecomponent = PaperAdventure.asVanilla(deathMessage); // Paper - Adventure
this.playerConnection.a((Packet) (new PacketPlayOutCombatEvent(this.getCombatTracker(), PacketPlayOutCombatEvent.EnumCombatEventType.ENTITY_DIED, ichatbasecomponent)), (future) -> {
if (!future.isSuccess()) {
@@ -1660,6 +1657,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
this.a(ichatbasecomponent, ChatMessageType.SYSTEM, uuid);
}
+ public void sendMessage(final IChatBaseComponent message, final ChatMessageType type, final UUID sender) { this.a(message, type, sender); } // Paper - OBFHELPER
public void a(IChatBaseComponent ichatbasecomponent, ChatMessageType chatmessagetype, UUID uuid) {
this.playerConnection.a((Packet) (new PacketPlayOutChat(ichatbasecomponent, chatmessagetype, uuid)), (future) -> {
if (!future.isSuccess() && (chatmessagetype == ChatMessageType.GAME_INFO || chatmessagetype == ChatMessageType.SYSTEM)) {
@@ -1682,6 +1680,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
}
public String locale = "en_us"; // CraftBukkit - add, lowercase
+ public java.util.Locale adventure$locale = java.util.Locale.US; // Paper
public void a(PacketPlayInSettings packetplayinsettings) {
// CraftBukkit start
if (getMainHand() != packetplayinsettings.getMainHand()) {
@@ -1693,6 +1692,10 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
this.server.server.getPluginManager().callEvent(event);
}
this.locale = packetplayinsettings.locale;
+ // Paper start
+ this.adventure$locale = net.kyori.adventure.translation.Translator.parseLocale(this.locale);
+ this.playerConnection.networkManager.channel.attr(PaperAdventure.LOCALE_ATTRIBUTE).set(this.adventure$locale);
+ // Paper end
this.clientViewDistance = packetplayinsettings.viewDistance;
// CraftBukkit end
this.bY = packetplayinsettings.d();
diff --git a/src/main/java/net/minecraft/server/network/LoginListener.java b/src/main/java/net/minecraft/server/network/LoginListener.java
index 49f6b20ceee1b58e66e72d161d20226fa17850fd..c4e3dd34c20c97ae1397cf51125f51a5b77d9437 100644
--- a/src/main/java/net/minecraft/server/network/LoginListener.java
+++ b/src/main/java/net/minecraft/server/network/LoginListener.java
@@ -37,6 +37,7 @@ import org.apache.logging.log4j.Logger;
// CraftBukkit start
import net.minecraft.network.chat.ChatComponentText;
+import io.papermc.paper.adventure.PaperAdventure; // Paper
import org.bukkit.craftbukkit.util.Waitable;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
import org.bukkit.event.player.PlayerPreLoginEvent;
@@ -300,7 +301,7 @@ public class LoginListener implements PacketLoginInListener {
if (PlayerPreLoginEvent.getHandlerList().getRegisteredListeners().length != 0) {
final PlayerPreLoginEvent event = new PlayerPreLoginEvent(playerName, address, uniqueId);
if (asyncEvent.getResult() != PlayerPreLoginEvent.Result.ALLOWED) {
- event.disallow(asyncEvent.getResult(), asyncEvent.getKickMessage());
+ event.disallow(asyncEvent.getResult(), asyncEvent.kickMessage()); // Paper - Adventure
}
Waitable<PlayerPreLoginEvent.Result> waitable = new Waitable<PlayerPreLoginEvent.Result>() {
@Override
@@ -311,12 +312,12 @@ public class LoginListener implements PacketLoginInListener {
LoginListener.this.server.processQueue.add(waitable);
if (waitable.get() != PlayerPreLoginEvent.Result.ALLOWED) {
- disconnect(event.getKickMessage());
+ disconnect(PaperAdventure.asVanilla(event.kickMessage())); // Paper - Adventure
return;
}
} else {
if (asyncEvent.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED) {
- disconnect(asyncEvent.getKickMessage());
+ disconnect(PaperAdventure.asVanilla(asyncEvent.kickMessage())); // Paper - Adventure
return;
}
}
diff --git a/src/main/java/net/minecraft/server/network/PacketStatusListener.java b/src/main/java/net/minecraft/server/network/PacketStatusListener.java
index 2a96564c1656d42a74c331a6178e511cd5347a66..d219eda271a71f786808a6958b829fca40a1aaba 100644
--- a/src/main/java/net/minecraft/server/network/PacketStatusListener.java
+++ b/src/main/java/net/minecraft/server/network/PacketStatusListener.java
@@ -56,7 +56,7 @@ public class PacketStatusListener implements PacketStatusInListener {
CraftIconCache icon = minecraftServer.server.getServerIcon();
ServerListPingEvent() {
- super(((InetSocketAddress) networkManager.getSocketAddress()).getAddress(), minecraftServer.getMotd(), minecraftServer.getPlayerList().getMaxPlayers());
+ super(((InetSocketAddress) networkManager.getSocketAddress()).getAddress(), minecraftServer.server.motd(), minecraftServer.getPlayerList().getMaxPlayers()); // Paper - Adventure
}
@Override
diff --git a/src/main/java/net/minecraft/server/network/PlayerConnection.java b/src/main/java/net/minecraft/server/network/PlayerConnection.java
index 4ed497ee04d9e9116e1f7d90bf975aeadd24aa93..a39f58e0c60b5e3ccc3b725f1f4167d52b230e11 100644
--- a/src/main/java/net/minecraft/server/network/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/network/PlayerConnection.java
@@ -159,6 +159,8 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
// CraftBukkit start
+import io.papermc.paper.adventure.ChatProcessor; // Paper
+import io.papermc.paper.adventure.PaperAdventure; // Paper
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import net.minecraft.network.protocol.game.PacketPlayOutAttachEntity;
@@ -390,21 +392,24 @@ public class PlayerConnection implements PacketListenerPlayIn {
return this.minecraftServer.a(this.player.getProfile());
}
- // CraftBukkit start
- @Deprecated
- public void disconnect(IChatBaseComponent ichatbasecomponent) {
- disconnect(CraftChatMessage.fromComponent(ichatbasecomponent));
+ public void disconnect(String s) {
+ // Paper start
+ this.disconnect(PaperAdventure.LEGACY_SECTION_UXRC.deserialize(s));
}
- // CraftBukkit end
- public void disconnect(String s) {
+ public void disconnect(final IChatBaseComponent reason) {
+ this.disconnect(PaperAdventure.asAdventure(reason));
+ }
+
+ public void disconnect(net.kyori.adventure.text.Component reason) {
+ // Paper end
// CraftBukkit start - fire PlayerKickEvent
if (this.processedDisconnect) {
return;
}
- String leaveMessage = EnumChatFormat.YELLOW + this.player.getName() + " left the game.";
+ net.kyori.adventure.text.Component leaveMessage = net.kyori.adventure.text.Component.translatable("multiplayer.player.left", net.kyori.adventure.text.format.NamedTextColor.YELLOW, this.player.getBukkitEntity().displayName()); // Paper - Adventure
- PlayerKickEvent event = new PlayerKickEvent(this.server.getPlayer(this.player), s, leaveMessage);
+ PlayerKickEvent event = new PlayerKickEvent(this.server.getPlayer(this.player), reason, leaveMessage); // Paper - Adventure
if (this.server.getServer().isRunning()) {
this.server.getPluginManager().callEvent(event);
@@ -415,8 +420,7 @@ public class PlayerConnection implements PacketListenerPlayIn {
return;
}
// Send the possibly modified leave message
- s = event.getReason();
- final IChatBaseComponent ichatbasecomponent = CraftChatMessage.fromString(s, true)[0];
+ final IChatBaseComponent ichatbasecomponent = PaperAdventure.asVanilla(event.reason()); // Paper - Adventure
// CraftBukkit end
this.networkManager.sendPacket(new PacketPlayOutKickDisconnect(ichatbasecomponent), (future) -> {
@@ -1632,9 +1636,11 @@ public class PlayerConnection implements PacketListenerPlayIn {
*/
this.player.p();
- String quitMessage = this.minecraftServer.getPlayerList().disconnect(this.player);
- if ((quitMessage != null) && (quitMessage.length() > 0)) {
- this.minecraftServer.getPlayerList().sendMessage(CraftChatMessage.fromString(quitMessage));
+ // Paper start - Adventure
+ net.kyori.adventure.text.Component quitMessage = this.minecraftServer.getPlayerList().disconnect(this.player);
+ if ((quitMessage != null) && !quitMessage.equals(net.kyori.adventure.text.Component.empty())) {
+ this.minecraftServer.getPlayerList().sendMessage(PaperAdventure.asVanilla(quitMessage));
+ // Paper end
}
// CraftBukkit end
ITextFilter itextfilter = this.player.Q();
@@ -1850,8 +1856,13 @@ public class PlayerConnection implements PacketListenerPlayIn {
this.handleCommand(s);
} else if (this.player.getChatFlags() == EnumChatVisibility.SYSTEM) {
// Do nothing, this is coming from a plugin
- } else {
- Player player = this.getPlayer();
+ // Paper start
+ } else if (true) {
+ final ChatProcessor cp = new ChatProcessor(this.minecraftServer, this.player, s, async);
+ cp.process();
+ // Paper end
+ } else if (false) { // Paper
+ Player player = this.getPlayer(); // Paper
AsyncPlayerChatEvent event = new AsyncPlayerChatEvent(async, player, s, new LazyPlayerSet(minecraftServer));
this.server.getPluginManager().callEvent(event);
@@ -2669,21 +2680,20 @@ public class PlayerConnection implements PacketListenerPlayIn {
return;
}
- // CraftBukkit start
- Player player = this.server.getPlayer(this.player);
- int x = packetplayinupdatesign.b().getX();
- int y = packetplayinupdatesign.b().getY();
- int z = packetplayinupdatesign.b().getZ();
- String[] lines = new String[4];
+ // CraftBukkit start // Paper start - Adventure
+ List<net.kyori.adventure.text.Component> lines = new java.util.ArrayList<>();
for (int i = 0; i < list.size(); ++i) {
- lines[i] = EnumChatFormat.a(new ChatComponentText(EnumChatFormat.a((String) list.get(i))).getString());
+ lines.add(net.kyori.adventure.text.Component.text(list.get(i)));
}
- SignChangeEvent event = new SignChangeEvent((org.bukkit.craftbukkit.block.CraftBlock) player.getWorld().getBlockAt(x, y, z), this.server.getPlayer(this.player), lines);
+ SignChangeEvent event = new SignChangeEvent(org.bukkit.craftbukkit.block.CraftBlock.at(worldserver, blockposition), this.getPlayer(), lines);
this.server.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
- System.arraycopy(org.bukkit.craftbukkit.block.CraftSign.sanitizeLines(event.getLines()), 0, tileentitysign.lines, 0, 4);
+ for (int i = 0; i < 4; i++) {
+ tileentitysign.a(i, PaperAdventure.asVanilla(event.line(i)));
+ }
+ // Paper end
tileentitysign.isEditable = false;
}
// CraftBukkit end
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
index c601a5c577e438a3fa8dd4c5f36dbe9494b03d52..15418868c2b92498139e66d913ee1c35b3abf0cf 100644
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
@@ -8,6 +8,7 @@ import com.mojang.authlib.GameProfile;
import com.mojang.serialization.DataResult;
import com.mojang.serialization.Dynamic;
import io.netty.buffer.Unpooled;
+import io.papermc.paper.adventure.PaperAdventure;
import java.io.File;
import java.net.SocketAddress;
import java.text.SimpleDateFormat;
@@ -92,6 +93,7 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
// CraftBukkit start
+import io.papermc.paper.adventure.PaperAdventure; // Paper
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
@@ -255,7 +257,7 @@ public abstract class PlayerList {
}
// CraftBukkit start
chatmessage.a(EnumChatFormat.YELLOW);
- String joinMessage = CraftChatMessage.fromComponent(chatmessage);
+ IChatBaseComponent joinMessage = chatmessage; // Paper - Adventure
playerconnection.a(entityplayer.locX(), entityplayer.locY(), entityplayer.locZ(), entityplayer.yaw, entityplayer.pitch);
this.players.add(entityplayer);
@@ -264,19 +266,18 @@ public abstract class PlayerList {
// this.sendAll(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, new EntityPlayer[]{entityplayer})); // CraftBukkit - replaced with loop below
// CraftBukkit start
- PlayerJoinEvent playerJoinEvent = new PlayerJoinEvent(cserver.getPlayer(entityplayer), joinMessage);
+ PlayerJoinEvent playerJoinEvent = new org.bukkit.event.player.PlayerJoinEvent(cserver.getPlayer(entityplayer), PaperAdventure.asAdventure(chatmessage)); // Paper - Adventure
cserver.getPluginManager().callEvent(playerJoinEvent);
if (!entityplayer.playerConnection.networkManager.isConnected()) {
return;
}
- joinMessage = playerJoinEvent.getJoinMessage();
+ final net.kyori.adventure.text.Component jm = playerJoinEvent.joinMessage();
- if (joinMessage != null && joinMessage.length() > 0) {
- for (IChatBaseComponent line : org.bukkit.craftbukkit.util.CraftChatMessage.fromString(joinMessage)) {
- server.getPlayerList().sendAll(new PacketPlayOutChat(line, ChatMessageType.SYSTEM, SystemUtils.b));
- }
+ if (jm != null && !jm.equals(net.kyori.adventure.text.Component.empty())) { // Paper - Adventure
+ joinMessage = PaperAdventure.asVanilla(jm); // Paper - Adventure
+ server.getPlayerList().sendAll(new PacketPlayOutChat(joinMessage, ChatMessageType.SYSTEM, SystemUtils.b)); // Paper - Adventure
}
// CraftBukkit end
@@ -473,7 +474,7 @@ public abstract class PlayerList {
}
- public String disconnect(EntityPlayer entityplayer) { // CraftBukkit - return string
+ public net.kyori.adventure.text.Component disconnect(EntityPlayer entityplayer) { // Paper - return Component
WorldServer worldserver = entityplayer.getWorldServer();
entityplayer.a(StatisticList.LEAVE_GAME);
@@ -484,7 +485,7 @@ public abstract class PlayerList {
entityplayer.closeInventory();
}
- PlayerQuitEvent playerQuitEvent = new PlayerQuitEvent(cserver.getPlayer(entityplayer), "\u00A7e" + entityplayer.getName() + " left the game");
+ PlayerQuitEvent playerQuitEvent = new PlayerQuitEvent(cserver.getPlayer(entityplayer), net.kyori.adventure.text.Component.translatable("multiplayer.player.left", net.kyori.adventure.text.format.NamedTextColor.YELLOW, com.destroystokyo.paper.PaperConfig.useDisplayNameInQuit ? entityplayer.getBukkitEntity().displayName() : net.kyori.adventure.text.Component.text(entityplayer.getName())));
cserver.getPluginManager().callEvent(playerQuitEvent);
entityplayer.getBukkitEntity().disconnect(playerQuitEvent.getQuitMessage());
@@ -545,7 +546,7 @@ public abstract class PlayerList {
cserver.getScoreboardManager().removePlayer(entityplayer.getBukkitEntity());
// CraftBukkit end
- return playerQuitEvent.getQuitMessage(); // CraftBukkit
+ return playerQuitEvent.quitMessage(); // Paper - Adventure
}
// CraftBukkit start - Whole method, SocketAddress to LoginListener, added hostname to signature, return EntityPlayer
@@ -591,10 +592,10 @@ public abstract class PlayerList {
}
// return chatmessage;
- if (!gameprofilebanentry.hasExpired()) event.disallow(PlayerLoginEvent.Result.KICK_BANNED, CraftChatMessage.fromComponent(chatmessage)); // Spigot
+ if (!gameprofilebanentry.hasExpired()) event.disallow(PlayerLoginEvent.Result.KICK_BANNED, PaperAdventure.asAdventure(chatmessage)); // Spigot // Paper - Adventure
} else if (!this.isWhitelisted(gameprofile)) {
chatmessage = new ChatMessage("multiplayer.disconnect.not_whitelisted");
- event.disallow(PlayerLoginEvent.Result.KICK_WHITELIST, org.spigotmc.SpigotConfig.whitelistMessage); // Spigot
+ event.disallow(PlayerLoginEvent.Result.KICK_WHITELIST, PaperAdventure.LEGACY_SECTION_UXRC.deserialize(org.spigotmc.SpigotConfig.whitelistMessage)); // Spigot // Paper - Adventure
} else if (getIPBans().isBanned(socketaddress) && !getIPBans().get(socketaddress).hasExpired()) {
IpBanEntry ipbanentry = this.l.get(socketaddress);
@@ -604,17 +605,17 @@ public abstract class PlayerList {
}
// return chatmessage;
- event.disallow(PlayerLoginEvent.Result.KICK_BANNED, CraftChatMessage.fromComponent(chatmessage));
+ event.disallow(PlayerLoginEvent.Result.KICK_BANNED, PaperAdventure.asAdventure(chatmessage)); // Paper - Adventure
} else {
// return this.players.size() >= this.maxPlayers && !this.f(gameprofile) ? new ChatMessage("multiplayer.disconnect.server_full") : null;
if (this.players.size() >= this.maxPlayers && !this.f(gameprofile)) {
- event.disallow(PlayerLoginEvent.Result.KICK_FULL, org.spigotmc.SpigotConfig.serverFullMessage); // Spigot
+ event.disallow(PlayerLoginEvent.Result.KICK_FULL, PaperAdventure.LEGACY_SECTION_UXRC.deserialize(org.spigotmc.SpigotConfig.serverFullMessage)); // Spigot // Paper - Adventure
}
}
cserver.getPluginManager().callEvent(event);
if (event.getResult() != PlayerLoginEvent.Result.ALLOWED) {
- loginlistener.disconnect(event.getKickMessage());
+ loginlistener.disconnect(PaperAdventure.asVanilla(event.kickMessage())); // Paper - Adventure
return null;
}
return entity;
@@ -1135,7 +1136,7 @@ public abstract class PlayerList {
public void shutdown() {
// CraftBukkit start - disconnect safely
for (EntityPlayer player : this.players) {
- player.playerConnection.disconnect(this.server.server.getShutdownMessage()); // CraftBukkit - add custom shutdown message
+ player.playerConnection.disconnect(PaperAdventure.asVanilla(this.server.server.shutdownMessage())); // CraftBukkit - add custom shutdown message // Paper - Adventure
}
// CraftBukkit end
diff --git a/src/main/java/net/minecraft/world/BossBattle.java b/src/main/java/net/minecraft/world/BossBattle.java
index f9154b306379c45f15fe55406aaa00351b0471e8..1fb9fea7683075f427edfa411c7747d60928d537 100644
--- a/src/main/java/net/minecraft/world/BossBattle.java
+++ b/src/main/java/net/minecraft/world/BossBattle.java
@@ -1,5 +1,6 @@
package net.minecraft.world;
+import io.papermc.paper.adventure.PaperAdventure;
import java.util.UUID;
import net.minecraft.EnumChatFormat;
import net.minecraft.network.chat.IChatBaseComponent;
@@ -14,6 +15,7 @@ public abstract class BossBattle {
protected boolean e;
protected boolean f;
protected boolean g;
+ public net.kyori.adventure.bossbar.BossBar adventure; // Paper
public BossBattle(UUID uuid, IChatBaseComponent ichatbasecomponent, BossBattle.BarColor bossbattle_barcolor, BossBattle.BarStyle bossbattle_barstyle) {
this.h = uuid;
@@ -28,61 +30,75 @@ public abstract class BossBattle {
}
public IChatBaseComponent j() {
+ if(this.adventure != null) return PaperAdventure.asVanilla(this.adventure.name()); // Paper
return this.title;
}
public void a(IChatBaseComponent ichatbasecomponent) {
+ if (this.adventure != null) this.adventure.name(PaperAdventure.asAdventure(ichatbasecomponent)); // Paper
this.title = ichatbasecomponent;
}
public float getProgress() {
+ if (this.adventure != null) return this.adventure.progress(); // Paper
return this.b;
}
public void a(float f) {
+ if (this.adventure != null) this.adventure.progress(f); // Paper
this.b = f;
}
public BossBattle.BarColor l() {
+ if (this.adventure != null) return PaperAdventure.asVanilla(this.adventure.color()); // Paper
return this.color;
}
public void a(BossBattle.BarColor bossbattle_barcolor) {
+ if(this.adventure != null) this.adventure.color(PaperAdventure.asAdventure(bossbattle_barcolor)); // Paper
this.color = bossbattle_barcolor;
}
public BossBattle.BarStyle m() {
+ if(this.adventure != null) return PaperAdventure.asVanilla(this.adventure.overlay()); // Paper
return this.style;
}
public void a(BossBattle.BarStyle bossbattle_barstyle) {
+ if(this.adventure != null) this.adventure.overlay(PaperAdventure.asAdventure(bossbattle_barstyle)); // Paper
this.style = bossbattle_barstyle;
}
public boolean isDarkenSky() {
+ if(this.adventure != null) return this.adventure.hasFlag(net.kyori.adventure.bossbar.BossBar.Flag.DARKEN_SCREEN); // Paper
return this.e;
}
public BossBattle a(boolean flag) {
+ if(this.adventure != null) PaperAdventure.setFlag(this.adventure, net.kyori.adventure.bossbar.BossBar.Flag.DARKEN_SCREEN, flag); // Paper
this.e = flag;
return this;
}
public boolean isPlayMusic() {
+ if(this.adventure != null) return this.adventure.hasFlag(net.kyori.adventure.bossbar.BossBar.Flag.PLAY_BOSS_MUSIC); // Paper
return this.f;
}
public BossBattle b(boolean flag) {
+ if(this.adventure != null) PaperAdventure.setFlag(this.adventure, net.kyori.adventure.bossbar.BossBar.Flag.PLAY_BOSS_MUSIC, flag); // Paper
this.f = flag;
return this;
}
public BossBattle c(boolean flag) {
+ if(this.adventure != null) PaperAdventure.setFlag(this.adventure, net.kyori.adventure.bossbar.BossBar.Flag.CREATE_WORLD_FOG, flag); // Paper
this.g = flag;
return this;
}
public boolean isCreateFog() {
+ if(this.adventure != null) return this.adventure.hasFlag(net.kyori.adventure.bossbar.BossBar.Flag.CREATE_WORLD_FOG); // Paper
return this.g;
}
diff --git a/src/main/java/net/minecraft/world/item/enchantment/Enchantment.java b/src/main/java/net/minecraft/world/item/enchantment/Enchantment.java
index 0134bbda9e6fc900b7eefa05442e25539bab3431..b76ef55145336cc8dc4857b79767f5a738ad5144 100644
--- a/src/main/java/net/minecraft/world/item/enchantment/Enchantment.java
+++ b/src/main/java/net/minecraft/world/item/enchantment/Enchantment.java
@@ -94,6 +94,7 @@ public abstract class Enchantment {
return this.f();
}
+ public final IChatBaseComponent getTranslationComponentForLevel(int level) { return this.d(level); } // Paper - OBFHELPER
public IChatBaseComponent d(int i) {
ChatMessage chatmessage = new ChatMessage(this.g());
diff --git a/src/main/java/net/minecraft/world/level/saveddata/maps/WorldMap.java b/src/main/java/net/minecraft/world/level/saveddata/maps/WorldMap.java
index 7ec93ddd7e7c9dc54e3e4dcfe0d1654c0b0a8536..3f057f0bd23bc1c693c8f04ee8acd6626c620008 100644
--- a/src/main/java/net/minecraft/world/level/saveddata/maps/WorldMap.java
+++ b/src/main/java/net/minecraft/world/level/saveddata/maps/WorldMap.java
@@ -32,6 +32,7 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
// CraftBukkit start
+import io.papermc.paper.adventure.PaperAdventure; // Paper
import java.util.UUID;
import org.bukkit.craftbukkit.CraftServer;
@@ -473,7 +474,7 @@ public class WorldMap extends PersistentBase {
for ( org.bukkit.map.MapCursor cursor : render.cursors) {
if (cursor.isVisible()) {
- icons.add(new MapIcon(MapIcon.Type.a(cursor.getRawType()), cursor.getX(), cursor.getY(), cursor.getDirection(), CraftChatMessage.fromStringOrNull(cursor.getCaption())));
+ icons.add(new MapIcon(MapIcon.Type.a(cursor.getRawType()), cursor.getX(), cursor.getY(), cursor.getDirection(), PaperAdventure.asVanilla(cursor.caption()))); // Paper - Adventure
}
}
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 6d68610d8ffdef4357cf61ac2f4cf6bf54157b15..2f6b49e3ae7a7407eaec9810af8bf72e3a4896de 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -563,8 +563,11 @@ public final class CraftServer implements Server {
}
@Override
+ @Deprecated // Paper start
public int broadcastMessage(String message) {
- return broadcast(message, BROADCAST_CHANNEL_USERS);
+ this.sendMessage(io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.deserialize(message));
+ return this.getOnlinePlayers().size() + 1;
+ // Paper end
}
public Player getPlayer(final EntityPlayer entity) {
@@ -1302,7 +1305,15 @@ public final class CraftServer implements Server {
return configuration.getInt("settings.spawn-radius", -1);
}
+ // Paper start
@Override
+ public net.kyori.adventure.text.Component shutdownMessage() {
+ String msg = getShutdownMessage();
+ return msg != null ? io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.deserialize(msg) : null;
+ }
+ // Paper end
+ @Override
+ @Deprecated // Paper
public String getShutdownMessage() {
return configuration.getString("settings.shutdown-message");
}
@@ -1418,7 +1429,15 @@ public final class CraftServer implements Server {
}
@Override
+ @Deprecated // Paper
public int broadcast(String message, String permission) {
+ // Paper start - Adventure
+ return this.broadcast(io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.deserialize(message), permission);
+ }
+
+ @Override
+ public int broadcast(net.kyori.adventure.text.Component message, String permission) {
+ // Paper end
Set<CommandSender> recipients = new HashSet<>();
for (Permissible permissible : getPluginManager().getPermissionSubscriptions(permission)) {
if (permissible instanceof CommandSender && permissible.hasPermission(permission)) {
@@ -1426,14 +1445,14 @@ public final class CraftServer implements Server {
}
}
- BroadcastMessageEvent broadcastMessageEvent = new BroadcastMessageEvent(!Bukkit.isPrimaryThread(), message, recipients);
+ BroadcastMessageEvent broadcastMessageEvent = new BroadcastMessageEvent(!Bukkit.isPrimaryThread(), message, recipients); // Paper - Adventure
getPluginManager().callEvent(broadcastMessageEvent);
if (broadcastMessageEvent.isCancelled()) {
return 0;
}
- message = broadcastMessageEvent.getMessage();
+ message = broadcastMessageEvent.message(); // Paper - Adventure
for (CommandSender recipient : recipients) {
recipient.sendMessage(message);
@@ -1659,6 +1678,14 @@ public final class CraftServer implements Server {
return CraftInventoryCreator.INSTANCE.createInventory(owner, type);
}
+ // Paper start
+ @Override
+ public Inventory createInventory(InventoryHolder owner, InventoryType type, net.kyori.adventure.text.Component title) {
+ Validate.isTrue(type.isCreatable(), "Cannot open an inventory of type ", type);
+ return CraftInventoryCreator.INSTANCE.createInventory(owner, type, title);
+ }
+ // Paper end
+
@Override
public Inventory createInventory(InventoryHolder owner, InventoryType type, String title) {
Validate.isTrue(type.isCreatable(), "Cannot open an inventory of type ", type);
@@ -1671,13 +1698,28 @@ public final class CraftServer implements Server {
return CraftInventoryCreator.INSTANCE.createInventory(owner, size);
}
+ // Paper start
+ @Override
+ public Inventory createInventory(InventoryHolder owner, int size, net.kyori.adventure.text.Component title) throws IllegalArgumentException {
+ Validate.isTrue(9 <= size && size <= 54 && size % 9 == 0, "Size for custom inventory must be a multiple of 9 between 9 and 54 slots (got " + size + ")");
+ return CraftInventoryCreator.INSTANCE.createInventory(owner, size, title);
+ }
+ // Paper end
+
@Override
public Inventory createInventory(InventoryHolder owner, int size, String title) throws IllegalArgumentException {
Validate.isTrue(9 <= size && size <= 54 && size % 9 == 0, "Size for custom inventory must be a multiple of 9 between 9 and 54 slots (got " + size + ")");
return CraftInventoryCreator.INSTANCE.createInventory(owner, size, title);
}
+ // Paper start
@Override
+ public Merchant createMerchant(net.kyori.adventure.text.Component title) {
+ return new org.bukkit.craftbukkit.inventory.CraftMerchantCustom(title == null ? InventoryType.MERCHANT.defaultTitle() : title);
+ }
+ // Paper end
+ @Override
+ @Deprecated // Paper
public Merchant createMerchant(String title) {
return new CraftMerchantCustom(title == null ? InventoryType.MERCHANT.getDefaultTitle() : title);
}
@@ -1721,6 +1763,12 @@ public final class CraftServer implements Server {
return Thread.currentThread().equals(console.serverThread) || console.hasStopped() || !org.spigotmc.AsyncCatcher.enabled; // All bets are off if we have shut down (e.g. due to watchdog)
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component motd() {
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(new net.minecraft.network.chat.ChatComponentText(console.getMotd()));
+ }
+ // Paper end
@Override
public String getMotd() {
return console.getMotd();
@@ -2149,5 +2197,15 @@ public final class CraftServer implements Server {
return null;
}
}
+
+ // Paper start
+ private Iterable<? extends net.kyori.adventure.audience.Audience> adventure$audiences;
+ @Override
+ public Iterable<? extends net.kyori.adventure.audience.Audience> audiences() {
+ if (this.adventure$audiences == null) {
+ this.adventure$audiences = com.google.common.collect.Iterables.concat(java.util.Collections.singleton(this.getConsoleSender()), this.getOnlinePlayers());
+ }
+ return this.adventure$audiences;
+ }
// Paper end
}
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBeacon.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBeacon.java
index ae735836accc6bf6f0831f72ff882720b69df792..d3ae5cadd88f9012203d2c04cbe38af9b215ef0b 100644
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBeacon.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBeacon.java
@@ -70,6 +70,19 @@ public class CraftBeacon extends CraftBlockEntityState<TileEntityBeacon> impleme
this.getSnapshot().secondaryEffect = (effect != null) ? MobEffectList.fromId(effect.getId()) : null;
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component customName() {
+ final TileEntityBeacon be = this.getSnapshot();
+ return be.customName != null ? io.papermc.paper.adventure.PaperAdventure.asAdventure(be.customName) : null;
+ }
+
+ @Override
+ public void customName(final net.kyori.adventure.text.Component customName) {
+ this.getSnapshot().setCustomName(customName != null ? io.papermc.paper.adventure.PaperAdventure.asVanilla(customName) : null);
+ }
+ // Paper end
+
@Override
public String getCustomName() {
TileEntityBeacon beacon = this.getSnapshot();
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftContainer.java b/src/main/java/org/bukkit/craftbukkit/block/CraftContainer.java
index e8ce890c551c9b809e8ba3f7449dc33f3a3a6b80..c99a59573653ee5d14e780137c769116bf781ea7 100644
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftContainer.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftContainer.java
@@ -32,6 +32,19 @@ public abstract class CraftContainer<T extends TileEntityContainer> extends Craf
this.getSnapshot().chestLock = (key == null) ? ChestLock.a : new ChestLock(key);
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component customName() {
+ final T be = this.getSnapshot();
+ return be.hasCustomName() ? io.papermc.paper.adventure.PaperAdventure.asAdventure(be.getCustomName()) : null;
+ }
+
+ @Override
+ public void customName(final net.kyori.adventure.text.Component customName) {
+ this.getSnapshot().setCustomName(customName != null ? io.papermc.paper.adventure.PaperAdventure.asVanilla(customName) : null);
+ }
+ // Paper end
+
@Override
public String getCustomName() {
T container = this.getSnapshot();
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftEnchantingTable.java b/src/main/java/org/bukkit/craftbukkit/block/CraftEnchantingTable.java
index a559a77aae870988f4dd5e6f5f1f08feb3fad054..75ee5cc96c0e54f99e2ce820289bb74f57c426a2 100644
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftEnchantingTable.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftEnchantingTable.java
@@ -16,6 +16,19 @@ public class CraftEnchantingTable extends CraftBlockEntityState<TileEntityEnchan
super(material, te);
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component customName() {
+ final TileEntityEnchantTable be = this.getSnapshot();
+ return be.hasCustomName() ? io.papermc.paper.adventure.PaperAdventure.asAdventure(be.getCustomName()) : null;
+ }
+
+ @Override
+ public void customName(final net.kyori.adventure.text.Component customName) {
+ this.getSnapshot().setCustomName(customName != null ? io.papermc.paper.adventure.PaperAdventure.asVanilla(customName) : null);
+ }
+ // Paper end
+
@Override
public String getCustomName() {
TileEntityEnchantTable enchant = this.getSnapshot();
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftSign.java b/src/main/java/org/bukkit/craftbukkit/block/CraftSign.java
index 50d3f9ea1e905522096ef930c144589a1f0d539e..f4b601277ef75e5bc39d541a0d13c6eed3b1ef2c 100644
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftSign.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftSign.java
@@ -13,8 +13,10 @@ import org.bukkit.craftbukkit.util.CraftChatMessage;
public class CraftSign extends CraftBlockEntityState<TileEntitySign> implements Sign {
// Lazily initialized only if requested:
- private String[] originalLines = null;
- private String[] lines = null;
+ // Paper start
+ private java.util.ArrayList<net.kyori.adventure.text.Component> originalLines = null; // ArrayList for RandomAccess
+ private java.util.ArrayList<net.kyori.adventure.text.Component> lines = null; // ArrayList for RandomAccess
+ // Paper end
public CraftSign(final Block block) {
super(block, TileEntitySign.class);
@@ -24,27 +26,52 @@ public class CraftSign extends CraftBlockEntityState<TileEntitySign> implements
super(material, te);
}
+ // Paper start
@Override
- public String[] getLines() {
- if (lines == null) {
- // Lazy initialization:
- TileEntitySign sign = this.getSnapshot();
- lines = new String[sign.lines.length];
- System.arraycopy(revertComponents(sign.lines), 0, lines, 0, lines.length);
- originalLines = new String[lines.length];
- System.arraycopy(lines, 0, originalLines, 0, originalLines.length);
+ public java.util.List<net.kyori.adventure.text.Component> lines() {
+ this.loadLines();
+ return this.lines;
+ }
+
+ @Override
+ public net.kyori.adventure.text.Component line(int index) {
+ this.loadLines();
+ return this.lines.get(index);
+ }
+
+ @Override
+ public void line(int index, net.kyori.adventure.text.Component line) {
+ this.loadLines();
+ this.lines.set(index, line);
+ }
+
+ private void loadLines() {
+ if (lines != null) {
+ return;
}
- return lines;
+
+ // Lazy initialization:
+ TileEntitySign sign = this.getSnapshot();
+ lines = io.papermc.paper.adventure.PaperAdventure.asAdventure(com.google.common.collect.Lists.newArrayList(sign.lines));
+ originalLines = new java.util.ArrayList<>(lines);
+ }
+ // Paper end
+ @Override
+ public String[] getLines() {
+ this.loadLines();
+ return this.lines.stream().map(io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC::serialize).toArray(String[]::new); // Paper
}
@Override
public String getLine(int index) throws IndexOutOfBoundsException {
- return getLines()[index];
+ this.loadLines();
+ return io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.serialize(this.lines.get(index)); // Paper
}
@Override
public void setLine(int index, String line) throws IndexOutOfBoundsException {
- getLines()[index] = line;
+ this.loadLines();
+ this.lines.set(index, line != null ? io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.deserialize(line) : net.kyori.adventure.text.Component.empty()); // Paper
}
@Override
@@ -72,16 +99,32 @@ public class CraftSign extends CraftBlockEntityState<TileEntitySign> implements
super.applyTo(sign);
if (lines != null) {
- for (int i = 0; i < lines.length; i++) {
- String line = (lines[i] == null) ? "" : lines[i];
- if (line.equals(originalLines[i])) {
+ // Paper start
+ for (int i = 0; i < this.lines.size(); ++i) {
+ net.kyori.adventure.text.Component component = this.lines.get(i);
+ net.kyori.adventure.text.Component origComp = this.originalLines.get(i);
+ if (component.equals(origComp)) {
continue; // The line contents are still the same, skip.
}
- sign.lines[i] = CraftChatMessage.fromString(line)[0];
+ sign.lines[i] = io.papermc.paper.adventure.PaperAdventure.asVanilla(component);
}
+ // Paper end
}
}
+ // Paper start
+ public static IChatBaseComponent[] sanitizeLines(java.util.List<net.kyori.adventure.text.Component> lines) {
+ IChatBaseComponent[] components = new IChatBaseComponent[4];
+ for (int i = 0; i < 4; i++) {
+ if (i < lines.size() && lines.get(i) != null) {
+ components[i] = io.papermc.paper.adventure.PaperAdventure.asVanilla(lines.get(i));
+ } else {
+ components[i] = new ChatComponentText("");
+ }
+ }
+ return components;
+ }
+ // Paper end
public static IChatBaseComponent[] sanitizeLines(String[] lines) {
IChatBaseComponent[] components = new IChatBaseComponent[4];
diff --git a/src/main/java/org/bukkit/craftbukkit/command/CraftConsoleCommandSender.java b/src/main/java/org/bukkit/craftbukkit/command/CraftConsoleCommandSender.java
index 089fe4a3458ed3106fa214f89a7004a5d3c6bb95..af986adfdb547cb61fbd52f0f89858f1a9e52cc3 100644
--- a/src/main/java/org/bukkit/craftbukkit/command/CraftConsoleCommandSender.java
+++ b/src/main/java/org/bukkit/craftbukkit/command/CraftConsoleCommandSender.java
@@ -80,4 +80,11 @@ public class CraftConsoleCommandSender extends ServerCommandSender implements Co
public boolean isConversing() {
return conversationTracker.isConversing();
}
+
+ // Paper start
+ @Override
+ public void sendMessage(final net.kyori.adventure.identity.Identity identity, final net.kyori.adventure.text.Component message, final net.kyori.adventure.audience.MessageType type) {
+ this.sendRawMessage(org.bukkit.craftbukkit.util.CraftChatMessage.fromComponent(io.papermc.paper.adventure.PaperAdventure.asVanilla(message)));
+ }
+ // Paper end
}
diff --git a/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java b/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java
index 8f694de2fb3827b9be0dd768ad90eb72c7d708e4..5a14430f63894bbe9daa42900cf5a6519bea4f45 100644
--- a/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java
+++ b/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java
@@ -187,6 +187,12 @@ public class CraftEnchantment extends Enchantment {
CraftEnchantment ench = (CraftEnchantment) other;
return !target.isCompatible(ench.target);
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component displayName(int level) {
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(getHandle().getTranslationComponentForLevel(level));
+ }
+ // Paper end
public net.minecraft.world.item.enchantment.Enchantment getHandle() {
return target;
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
index eea242af23825ad29ada6e997205e87edffb6bb9..3cf81734c8580f4d88ea97b6ac737a370b413c84 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
@@ -768,6 +768,19 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
return getHandle().getVehicle().getBukkitEntity();
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component customName() {
+ final IChatBaseComponent name = this.getHandle().getCustomName();
+ return name != null ? io.papermc.paper.adventure.PaperAdventure.asAdventure(name) : null;
+ }
+
+ @Override
+ public void customName(final net.kyori.adventure.text.Component customName) {
+ this.getHandle().setCustomName(customName != null ? io.papermc.paper.adventure.PaperAdventure.asVanilla(customName) : null);
+ }
+ // Paper end
+
@Override
public void setCustomName(String name) {
// sane limit for name length
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
index 3a4e2261d0b0cd17df3f96e75f3c509156679c48..105d0388998d1e35e634d2163fe1a44aa7037ac8 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
@@ -316,9 +316,12 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
container = CraftEventFactory.callInventoryOpenEvent(player, container);
if (container == null) return;
- String title = container.getBukkitView().getTitle();
+ //String title = container.getBukkitView().getTitle(); // Paper - comment
+ net.kyori.adventure.text.Component adventure$title = container.getBukkitView().title(); // Paper
+ if (adventure$title == null) adventure$title = io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.deserialize(container.getBukkitView().getTitle()); // Paper
- player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(container.windowId, windowType, CraftChatMessage.fromString(title)[0]));
+ //player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(container.windowId, windowType, CraftChatMessage.fromString(title)[0])); // Paper // Paper - comment
+ player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(container.windowId, windowType, io.papermc.paper.adventure.PaperAdventure.asVanilla(adventure$title))); // Paper
getHandle().activeContainer = container;
getHandle().activeContainer.addSlotListener(player);
}
@@ -387,8 +390,12 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
// Now open the window
Containers<?> windowType = CraftContainer.getNotchInventoryType(inventory.getTopInventory());
- String title = inventory.getTitle();
- player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(container.windowId, windowType, CraftChatMessage.fromString(title)[0]));
+
+ //String title = inventory.getTitle(); // Paper - comment
+ net.kyori.adventure.text.Component adventure$title = inventory.title(); // Paper
+ if (adventure$title == null) adventure$title = io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.deserialize(inventory.getTitle()); // Paper
+ //player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(container.windowId, windowType, CraftChatMessage.fromString(title)[0])); // Paper - comment
+ player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(container.windowId, windowType, io.papermc.paper.adventure.PaperAdventure.asVanilla(adventure$title))); // Paper
player.activeContainer = container;
player.activeContainer.addSlotListener(player);
}
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index 597b3b061c707081e7665d5896f5d73676e691d6..137870c7d18c9ef3ae637e83c5457d42ec40c669 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -240,14 +240,39 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
@Override
public String getDisplayName() {
+ if(true) return io.papermc.paper.adventure.DisplayNames.getLegacy(this); // Paper
return getHandle().displayName;
}
@Override
public void setDisplayName(final String name) {
+ this.getHandle().adventure$displayName = name != null ? io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.deserialize(name) : net.kyori.adventure.text.Component.text(this.getName()); // Paper
getHandle().displayName = name == null ? getName() : name;
}
+ // Paper start
+ @Override
+ public void playerListName(net.kyori.adventure.text.Component name) {
+ getHandle().listName = name == null ? null : io.papermc.paper.adventure.PaperAdventure.asVanilla(name);
+ for (EntityPlayer player : server.getHandle().players) {
+ if (player.getBukkitEntity().canSee(this)) {
+ player.playerConnection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.UPDATE_DISPLAY_NAME, getHandle()));
+ }
+ }
+ }
+ @Override
+ public net.kyori.adventure.text.Component playerListName() {
+ return getHandle().listName == null ? net.kyori.adventure.text.Component.text(getName()) : io.papermc.paper.adventure.PaperAdventure.asAdventure(getHandle().listName);
+ }
+ @Override
+ public net.kyori.adventure.text.Component playerListHeader() {
+ return playerListHeader;
+ }
+ @Override
+ public net.kyori.adventure.text.Component playerListFooter() {
+ return playerListFooter;
+ }
+ // Paper end
@Override
public String getPlayerListName() {
return getHandle().listName == null ? getName() : CraftChatMessage.fromComponent(getHandle().listName);
@@ -266,35 +291,35 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
}
}
- private IChatBaseComponent playerListHeader;
- private IChatBaseComponent playerListFooter;
+ private net.kyori.adventure.text.Component playerListHeader; // Paper - Adventure
+ private net.kyori.adventure.text.Component playerListFooter; // Paper - Adventure
@Override
public String getPlayerListHeader() {
- return (playerListHeader == null) ? null : CraftChatMessage.fromComponent(playerListHeader);
+ return (playerListHeader == null) ? null : io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.serialize(playerListHeader); // Paper - Adventure
}
@Override
public String getPlayerListFooter() {
- return (playerListFooter == null) ? null : CraftChatMessage.fromComponent(playerListFooter);
+ return (playerListFooter == null) ? null : io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.serialize(playerListFooter); // Paper - Adventure
}
@Override
public void setPlayerListHeader(String header) {
- this.playerListHeader = CraftChatMessage.fromStringOrNull(header, true);
+ this.playerListHeader = header == null ? null : io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.deserialize(header); // Paper - Adventure
updatePlayerListHeaderFooter();
}
@Override
public void setPlayerListFooter(String footer) {
- this.playerListFooter = CraftChatMessage.fromStringOrNull(footer, true);
+ this.playerListFooter = footer == null ? null : io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.deserialize(footer); // Paper - Adventure
updatePlayerListHeaderFooter();
}
@Override
public void setPlayerListHeaderFooter(String header, String footer) {
- this.playerListHeader = CraftChatMessage.fromStringOrNull(header, true);
- this.playerListFooter = CraftChatMessage.fromStringOrNull(footer, true);
+ this.playerListHeader = header == null ? null : io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.deserialize(header); // Paper - Adventure
+ this.playerListFooter = footer == null ? null : io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.deserialize(footer); // Paper - Adventure
updatePlayerListHeaderFooter();
}
@@ -302,8 +327,8 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
if (getHandle().playerConnection == null) return;
PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter();
- packet.header = (this.playerListHeader == null) ? new ChatComponentText("") : this.playerListHeader;
- packet.footer = (this.playerListFooter == null) ? new ChatComponentText("") : this.playerListFooter;
+ packet.header = (this.playerListHeader == null) ? new ChatComponentText("") : io.papermc.paper.adventure.PaperAdventure.asVanilla(this.playerListHeader); // Paper - Adventure
+ packet.footer = (this.playerListFooter == null) ? new ChatComponentText("") : io.papermc.paper.adventure.PaperAdventure.asVanilla(this.playerListFooter); // Paper - Adventure
getHandle().playerConnection.sendPacket(packet);
}
@@ -335,6 +360,19 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
getHandle().playerConnection.disconnect(message == null ? "" : message);
}
+ // Paper start
+ @Override
+ public void kick(final net.kyori.adventure.text.Component message) {
+ org.spigotmc.AsyncCatcher.catchOp("player kick");
+ final PlayerConnection connection = this.getHandle().playerConnection;
+ if (connection != null) {
+ connection.disconnect(io.papermc.paper.adventure.PaperAdventure.asVanilla(
+ message == null ? net.kyori.adventure.text.Component.empty() : message
+ ));
+ }
+ }
+ // Paper end
+
@Override
public void setCompassTarget(Location loc) {
if (getHandle().playerConnection == null) return;
@@ -561,6 +599,37 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
getHandle().playerConnection.sendPacket(packet);
}
+ // Paper start
+ @Override
+ public void sendSignChange(Location loc, List<net.kyori.adventure.text.Component> lines) {
+ this.sendSignChange(loc, lines, org.bukkit.DyeColor.BLACK);
+ }
+ @Override
+ public void sendSignChange(Location loc, List<net.kyori.adventure.text.Component> lines, DyeColor dyeColor) {
+ if (getHandle().playerConnection == null) {
+ return;
+ }
+ if (lines == null) {
+ lines = new java.util.ArrayList<>(4);
+ }
+ Validate.notNull(loc, "Location cannot be null");
+ Validate.notNull(dyeColor, "DyeColor cannot be null");
+ if (lines.size() < 4) {
+ throw new IllegalArgumentException("Must have at least 4 lines");
+ }
+ IChatBaseComponent[] components = CraftSign.sanitizeLines(lines);
+ this.sendSignChange0(components, loc, dyeColor);
+ }
+
+ private void sendSignChange0(IChatBaseComponent[] components, Location loc, DyeColor dyeColor) {
+ TileEntitySign sign = new TileEntitySign();
+ sign.setPosition(new BlockPosition(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
+ sign.setColor(EnumColor.fromColorIndex(dyeColor.getWoolData()));
+ System.arraycopy(components, 0, sign.lines, 0, sign.lines.length);
+
+ getHandle().playerConnection.sendPacket(sign.getUpdatePacket());
+ }
+ // Paper end
@Override
public void sendSignChange(Location loc, String[] lines) {
sendSignChange(loc, lines, DyeColor.BLACK);
@@ -583,12 +652,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
}
IChatBaseComponent[] components = CraftSign.sanitizeLines(lines);
- TileEntitySign sign = new TileEntitySign();
+ /*TileEntitySign sign = new TileEntitySign(); // Paper
sign.setPosition(new BlockPosition(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
sign.setColor(EnumColor.fromColorIndex(dyeColor.getWoolData()));
System.arraycopy(components, 0, sign.lines, 0, sign.lines.length);
- getHandle().playerConnection.sendPacket(sign.getUpdatePacket());
+ getHandle().playerConnection.sendPacket(sign.getUpdatePacket());*/ // Paper
+ this.sendSignChange0(components, loc, dyeColor); // Paper
}
@Override
@@ -1688,6 +1758,12 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
return (getHandle().clientViewDistance == null) ? Bukkit.getViewDistance() : getHandle().clientViewDistance;
}
+ // Paper start
+ @Override
+ public java.util.Locale locale() {
+ return getHandle().adventure$locale;
+ }
+ // Paper end
@Override
public String getLocale() {
return getHandle().locale;
@@ -1711,6 +1787,138 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
getInventory().setItemInMainHand(hand);
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component displayName() {
+ return this.getHandle().adventure$displayName;
+ }
+
+ @Override
+ public void displayName(final net.kyori.adventure.text.Component displayName) {
+ this.getHandle().adventure$displayName = displayName != null ? displayName : net.kyori.adventure.text.Component.text(this.getName());
+ this.getHandle().displayName = null;
+ }
+
+ @Override
+ public void sendMessage(final net.kyori.adventure.identity.Identity identity, final net.kyori.adventure.text.Component message, final net.kyori.adventure.audience.MessageType type) {
+ final PacketPlayOutChat packet = new PacketPlayOutChat(null, type == net.kyori.adventure.audience.MessageType.CHAT ? net.minecraft.network.chat.ChatMessageType.CHAT : net.minecraft.network.chat.ChatMessageType.SYSTEM, identity.uuid());
+ packet.adventure$message = message;
+ this.getHandle().playerConnection.sendPacket(packet);
+ }
+
+ @Override
+ public void sendActionBar(final net.kyori.adventure.text.Component message) {
+ final PacketPlayOutTitle packet = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.ACTIONBAR, null);
+ packet.adventure$text = message;
+ this.getHandle().playerConnection.sendPacket(packet);
+ }
+
+ @Override
+ public void sendPlayerListHeader(final net.kyori.adventure.text.Component header) {
+ this.playerListHeader = header;
+ this.adventure$sendPlayerListHeaderAndFooter();
+ }
+
+ @Override
+ public void sendPlayerListFooter(final net.kyori.adventure.text.Component footer) {
+ this.playerListFooter = footer;
+ this.adventure$sendPlayerListHeaderAndFooter();
+ }
+
+ @Override
+ public void sendPlayerListHeaderAndFooter(final net.kyori.adventure.text.Component header, final net.kyori.adventure.text.Component footer) {
+ this.playerListHeader = header;
+ this.playerListFooter = footer;
+ this.adventure$sendPlayerListHeaderAndFooter();
+ }
+
+ private void adventure$sendPlayerListHeaderAndFooter() {
+ final PlayerConnection connection = this.getHandle().playerConnection;
+ if (connection == null) return;
+ final PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter();
+ packet.adventure$header = (this.playerListHeader == null) ? net.kyori.adventure.text.Component.empty() : this.playerListHeader;
+ packet.adventure$footer = (this.playerListFooter == null) ? net.kyori.adventure.text.Component.empty() : this.playerListFooter;
+ connection.sendPacket(packet);
+ }
+
+ @Override
+ public void showTitle(final net.kyori.adventure.title.Title title) {
+ final PlayerConnection connection = this.getHandle().playerConnection;
+ final net.kyori.adventure.title.Title.Times times = title.times();
+ if (times != null) {
+ connection.sendPacket(new PacketPlayOutTitle(ticks(times.fadeIn()), ticks(times.stay()), ticks(times.fadeOut())));
+ }
+ final PacketPlayOutTitle sp = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.SUBTITLE, null);
+ sp.adventure$text = title.subtitle();
+ connection.sendPacket(sp);
+ final PacketPlayOutTitle tp = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.TITLE, null);
+ tp.adventure$text = title.title();
+ connection.sendPacket(tp);
+ }
+
+ private static int ticks(final java.time.Duration duration) {
+ if (duration == null) {
+ return -1;
+ }
+ return (int) (duration.toMillis() / 50L);
+ }
+
+ @Override
+ public void clearTitle() {
+ this.getHandle().playerConnection.sendPacket(new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.CLEAR, null));
+ }
+
+ // resetTitle implemented above
+
+ @Override
+ public void showBossBar(final net.kyori.adventure.bossbar.BossBar bar) {
+ ((net.kyori.adventure.bossbar.HackyBossBarPlatformBridge) bar).paper$playerShow(this);
+ }
+
+ @Override
+ public void hideBossBar(final net.kyori.adventure.bossbar.BossBar bar) {
+ ((net.kyori.adventure.bossbar.HackyBossBarPlatformBridge) bar).paper$playerHide(this);
+ }
+
+ @Override
+ public void playSound(final net.kyori.adventure.sound.Sound sound) {
+ final Vec3D pos = this.getHandle().getPositionVector();
+ this.playSound(sound, pos.x, pos.y, pos.z);
+ }
+
+ @Override
+ public void playSound(final net.kyori.adventure.sound.Sound sound, final double x, final double y, final double z) {
+ final MinecraftKey name = io.papermc.paper.adventure.PaperAdventure.asVanilla(sound.name());
+ final java.util.Optional<net.minecraft.sounds.SoundEffect> event = net.minecraft.core.IRegistry.SOUND_EVENT.getOptional(name);
+ if (event.isPresent()) {
+ this.getHandle().playerConnection.sendPacket(new PacketPlayOutNamedSoundEffect(event.get(), io.papermc.paper.adventure.PaperAdventure.asVanilla(sound.source()), x, y, z, sound.volume(), sound.pitch()));
+ } else {
+ this.getHandle().playerConnection.sendPacket(new PacketPlayOutCustomSoundEffect(name, io.papermc.paper.adventure.PaperAdventure.asVanilla(sound.source()), new Vec3D(x, y, z), sound.volume(), sound.pitch()));
+ }
+ }
+
+ @Override
+ public void stopSound(final net.kyori.adventure.sound.SoundStop stop) {
+ this.getHandle().playerConnection.sendPacket(new PacketPlayOutStopSound(
+ io.papermc.paper.adventure.PaperAdventure.asVanillaNullable(stop.sound()),
+ io.papermc.paper.adventure.PaperAdventure.asVanillaNullable(stop.source())
+ ));
+ }
+
+ @Override
+ public void openBook(final net.kyori.adventure.inventory.Book book) {
+ final java.util.Locale locale = this.getHandle().adventure$locale;
+ final net.minecraft.world.item.ItemStack item = io.papermc.paper.adventure.PaperAdventure.asItemStack(book, locale);
+ final EntityPlayer player = this.getHandle();
+ final PlayerConnection connection = player.playerConnection;
+ final net.minecraft.world.entity.player.PlayerInventory inventory = player.inventory;
+ final int slot = inventory.items.size() + inventory.itemInHandIndex;
+ connection.sendPacket(new net.minecraft.network.protocol.game.PacketPlayOutSetSlot(0, slot, item));
+ connection.sendPacket(new net.minecraft.network.protocol.game.PacketPlayOutOpenBook(net.minecraft.world.EnumHand.MAIN_HAND));
+ connection.sendPacket(new net.minecraft.network.protocol.game.PacketPlayOutSetSlot(0, slot, inventory.getItemInHand()));
+ }
+ // Paper end
+
// Spigot start
private final Player.Spigot spigot = new Player.Spigot()
{
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
index c925582b84b6576e869a93874da8ef94ca26a39c..9175d66ec9ad2e8155d6dea64beadfa73b93cd48 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -767,9 +767,9 @@ public class CraftEventFactory {
return event;
}
- public static PlayerDeathEvent callPlayerDeathEvent(EntityPlayer victim, List<org.bukkit.inventory.ItemStack> drops, String deathMessage, boolean keepInventory) {
+ public static PlayerDeathEvent callPlayerDeathEvent(EntityPlayer victim, List<org.bukkit.inventory.ItemStack> drops, net.kyori.adventure.text.Component deathMessage, String stringDeathMessage, boolean keepInventory) { // Paper - Adventure
CraftPlayer entity = victim.getBukkitEntity();
- PlayerDeathEvent event = new PlayerDeathEvent(entity, drops, victim.getExpReward(), 0, deathMessage);
+ PlayerDeathEvent event = new PlayerDeathEvent(entity, drops, victim.getExpReward(), 0, deathMessage, stringDeathMessage); // Paper - Adventure
event.setKeepInventory(keepInventory);
org.bukkit.World world = entity.getWorld();
Bukkit.getServer().getPluginManager().callEvent(event);
@@ -793,7 +793,7 @@ public class CraftEventFactory {
* Server methods
*/
public static ServerListPingEvent callServerListPingEvent(Server craftServer, InetAddress address, String motd, int numPlayers, int maxPlayers) {
- ServerListPingEvent event = new ServerListPingEvent(address, motd, numPlayers, maxPlayers);
+ ServerListPingEvent event = new ServerListPingEvent(address, craftServer.motd(), numPlayers, maxPlayers); // Paper - Adventure
craftServer.getPluginManager().callEvent(event);
return event;
}
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftContainer.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftContainer.java
index 384520dd734449d4e4f5243fbaad5f666b0c965c..614ab2d73db2293116f2272f6cd5c16da446132d 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftContainer.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftContainer.java
@@ -39,6 +39,7 @@ public class CraftContainer extends Container {
private final InventoryView view;
private InventoryType cachedType;
+ private net.kyori.adventure.text.Component adventure$title; // Paper
private String cachedTitle;
private Container delegate;
private final int cachedSize;
@@ -50,7 +51,9 @@ public class CraftContainer extends Container {
IInventory top = ((CraftInventory) view.getTopInventory()).getInventory();
PlayerInventory bottom = (PlayerInventory) ((CraftInventory) view.getBottomInventory()).getInventory();
cachedType = view.getType();
- cachedTitle = view.getTitle();
+ this.adventure$title = view.title(); // Paper
+ if (this.adventure$title == null) this.adventure$title = io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.deserialize(view.getTitle()); // Paper
+ //cachedTitle = view.getTitle(); // Paper - comment
cachedSize = getSize();
setupSlots(top, bottom, player);
}
@@ -77,6 +80,13 @@ public class CraftContainer extends Container {
return inventory.getType();
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component title() {
+ return inventory instanceof CraftInventoryCustom ? ((CraftInventoryCustom.MinecraftInventory) ((CraftInventory) inventory).getInventory()).title() : net.kyori.adventure.text.Component.text(inventory.getType().getDefaultTitle());
+ }
+ // Paper end
+
@Override
public String getTitle() {
return inventory instanceof CraftInventoryCustom ? ((CraftInventoryCustom.MinecraftInventory) ((CraftInventory) inventory).getInventory()).getTitle() : inventory.getType().getDefaultTitle();
@@ -95,7 +105,8 @@ public class CraftContainer extends Container {
@Override
public boolean c(EntityHuman entityhuman) {
- if (cachedType == view.getType() && cachedSize == getSize() && cachedTitle.equals(view.getTitle())) {
+ if (cachedType == view.getType() && cachedSize == getSize() && this.adventure$title.equals(view.title())) { // Paper
+ //if (cachedType == view.getType() && cachedSize == getSize() && cachedTitle.equals(view.getTitle())) { // Paper - comment
return true;
}
// If the window type has changed for some reason, update the player
@@ -103,7 +114,9 @@ public class CraftContainer extends Container {
// as good a place as any to put something like this.
boolean typeChanged = (cachedType != view.getType());
cachedType = view.getType();
- cachedTitle = view.getTitle();
+ this.adventure$title = view.title(); // Paper
+ if (this.adventure$title == null) this.adventure$title = io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.deserialize(view.getTitle()); // Paper
+ //cachedTitle = view.getTitle(); // Paper - comment
if (view.getPlayer() instanceof CraftPlayer) {
CraftPlayer player = (CraftPlayer) view.getPlayer();
Containers<?> type = getNotchInventoryType(view.getTopInventory());
@@ -115,7 +128,8 @@ public class CraftContainer extends Container {
setupSlots(top, bottom, player.getHandle());
}
int size = getSize();
- player.getHandle().playerConnection.sendPacket(new PacketPlayOutOpenWindow(this.windowId, type, new ChatComponentText(cachedTitle)));
+ player.getHandle().playerConnection.sendPacket(new PacketPlayOutOpenWindow(this.windowId, type, io.papermc.paper.adventure.PaperAdventure.asVanilla(this.adventure$title))); // Paper
+ //player.getHandle().playerConnection.sendPacket(new PacketPlayOutOpenWindow(this.windowId, type, new ChatComponentText(cachedTitle))); // Paper - comment
player.updateInventory();
}
return true;
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryCustom.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryCustom.java
index a537cc4ac5d052168f96a1ae73b6b17a380436ab..21347cf02cc01c90a81e7dd8264ef11968d9f145 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryCustom.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryCustom.java
@@ -19,6 +19,12 @@ public class CraftInventoryCustom extends CraftInventory {
super(new MinecraftInventory(owner, type));
}
+ // Paper start
+ public CraftInventoryCustom(InventoryHolder owner, InventoryType type, net.kyori.adventure.text.Component title) {
+ super(new MinecraftInventory(owner, type, title));
+ }
+ // Paper end
+
public CraftInventoryCustom(InventoryHolder owner, InventoryType type, String title) {
super(new MinecraftInventory(owner, type, title));
}
@@ -27,6 +33,12 @@ public class CraftInventoryCustom extends CraftInventory {
super(new MinecraftInventory(owner, size));
}
+ // Paper start
+ public CraftInventoryCustom(InventoryHolder owner, int size, net.kyori.adventure.text.Component title) {
+ super(new MinecraftInventory(owner, size, title));
+ }
+ // Paper end
+
public CraftInventoryCustom(InventoryHolder owner, int size, String title) {
super(new MinecraftInventory(owner, size, title));
}
@@ -36,9 +48,17 @@ public class CraftInventoryCustom extends CraftInventory {
private int maxStack = MAX_STACK;
private final List<HumanEntity> viewers;
private final String title;
+ private final net.kyori.adventure.text.Component adventure$title; // Paper
private InventoryType type;
private final InventoryHolder owner;
+ // Paper start
+ public MinecraftInventory(InventoryHolder owner, InventoryType type, net.kyori.adventure.text.Component title) {
+ this(owner, type.getDefaultSize(), title);
+ this.type = type;
+ }
+ // Paper end
+
public MinecraftInventory(InventoryHolder owner, InventoryType type) {
this(owner, type.getDefaultSize(), type.getDefaultTitle());
this.type = type;
@@ -57,11 +77,24 @@ public class CraftInventoryCustom extends CraftInventory {
Validate.notNull(title, "Title cannot be null");
this.items = NonNullList.a(size, ItemStack.b);
this.title = title;
+ this.adventure$title = io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.deserialize(title);
this.viewers = new ArrayList<HumanEntity>();
this.owner = owner;
this.type = InventoryType.CHEST;
}
+ // Paper start
+ public MinecraftInventory(final InventoryHolder owner, final int size, final net.kyori.adventure.text.Component title) {
+ Validate.notNull(title, "Title cannot be null");
+ this.items = NonNullList.a(size, ItemStack.b);
+ this.title = io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.serialize(title);
+ this.adventure$title = title;
+ this.viewers = new ArrayList<HumanEntity>();
+ this.owner = owner;
+ this.type = InventoryType.CHEST;
+ }
+ // Paper end
+
@Override
public int getSize() {
return items.size();
@@ -183,6 +216,12 @@ public class CraftInventoryCustom extends CraftInventory {
return null;
}
+ // Paper start
+ public net.kyori.adventure.text.Component title() {
+ return this.adventure$title;
+ }
+ // Paper end
+
public String getTitle() {
return title;
}
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryView.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryView.java
index 04073ed45f8068d80e58d3927b5ebc3160c6a8c6..9949bb8cac73b2f1f02b51079c0e244f923af8e9 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryView.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryView.java
@@ -64,6 +64,13 @@ public class CraftInventoryView extends InventoryView {
return CraftItemStack.asCraftMirror(container.getSlot(slot).getItem());
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component title() {
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.container.getTitle());
+ }
+ // Paper end
+
@Override
public String getTitle() {
return CraftChatMessage.fromComponent(container.getTitle());
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
index 89a3617068421bb86baf4e8bfd9df2d0626adff7..6d320bbe0c75cc0df504faacf0f7d24804b90d5f 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
@@ -334,4 +334,12 @@ public final class CraftItemFactory implements ItemFactory {
public Material updateMaterial(ItemMeta meta, Material material) throws IllegalArgumentException {
return ((CraftMetaItem) meta).updateMaterial(material);
}
+
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.event.HoverEvent<net.kyori.adventure.text.event.HoverEvent.ShowItem> asHoverEvent(final ItemStack item, final java.util.function.UnaryOperator<net.kyori.adventure.text.event.HoverEvent.ShowItem> op) {
+ final net.minecraft.nbt.NBTTagCompound tag = CraftItemStack.asNMSCopy(item).getTag();
+ return net.kyori.adventure.text.event.HoverEvent.showItem(op.apply(net.kyori.adventure.text.event.HoverEvent.ShowItem.of(item.getType().getKey(), item.getAmount(), io.papermc.paper.adventure.PaperAdventure.asBinaryTagHolder(tag))));
+ }
+ // Paper end
}
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMerchantCustom.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMerchantCustom.java
index ef10c7ab1d615cdba182eca63eb14309339a5314..206c133ebc6c44038585236b0628543b8bed278c 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMerchantCustom.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMerchantCustom.java
@@ -14,10 +14,17 @@ import org.apache.commons.lang.Validate;
public class CraftMerchantCustom extends CraftMerchant {
+ @Deprecated // Paper - Adventure
public CraftMerchantCustom(String title) {
super(new MinecraftMerchant(title));
getMerchant().craftMerchant = this;
}
+ // Paper start
+ public CraftMerchantCustom(net.kyori.adventure.text.Component title) {
+ super(new MinecraftMerchant(title));
+ getMerchant().craftMerchant = this;
+ }
+ // Paper end
@Override
public String toString() {
@@ -37,10 +44,17 @@ public class CraftMerchantCustom extends CraftMerchant {
private World tradingWorld;
protected CraftMerchant craftMerchant;
+ @Deprecated // Paper - Adventure
public MinecraftMerchant(String title) {
Validate.notNull(title, "Title cannot be null");
this.title = new ChatComponentText(title);
}
+ // Paper start
+ public MinecraftMerchant(net.kyori.adventure.text.Component title) {
+ Validate.notNull(title, "Title cannot be null");
+ this.title = io.papermc.paper.adventure.PaperAdventure.asVanilla(title);
+ }
+ // Paper end
@Override
public CraftMerchant getCraftMerchant() {
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java
index 4cdc504df4cad6f7725f6d18482e88433523943a..af1f45bb8bbe380eec1dcdef1beacb06c9d932a8 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java
@@ -1,8 +1,9 @@
package org.bukkit.craftbukkit.inventory;
import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap.Builder;
import com.google.common.collect.Lists;
+
+import com.google.common.collect.ImmutableMap; // Paper
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -269,6 +270,135 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta {
this.generation = (generation == null) ? null : generation.ordinal();
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component title() {
+ return this.title == null ? null : io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.deserialize(this.title);
+ }
+
+ @Override
+ public org.bukkit.inventory.meta.BookMeta title(net.kyori.adventure.text.Component title) {
+ this.setTitle(title == null ? null : io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.serialize(title));
+ return this;
+ }
+
+ @Override
+ public net.kyori.adventure.text.Component author() {
+ return this.author == null ? null : io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.deserialize(this.author);
+ }
+
+ @Override
+ public org.bukkit.inventory.meta.BookMeta author(net.kyori.adventure.text.Component author) {
+ this.setAuthor(author == null ? null : io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.serialize(author));
+ return this;
+ }
+
+ @Override
+ public net.kyori.adventure.text.Component page(final int page) {
+ Validate.isTrue(isValidPage(page), "Invalid page number");
+ return this instanceof CraftMetaBookSigned ? net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson().deserialize(pages.get(page - 1)) : io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.deserialize(pages.get(page - 1));
+ }
+
+ @Override
+ public void page(final int page, net.kyori.adventure.text.Component data) {
+ if (!isValidPage(page)) {
+ throw new IllegalArgumentException("Invalid page number " + page + "/" + pages.size());
+ }
+ if (data == null) {
+ data = net.kyori.adventure.text.Component.empty();
+ }
+ pages.set(page - 1, this instanceof CraftMetaBookSigned ? net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson().serialize(data) : io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.serialize(data));
+ }
+
+ @Override
+ public List<net.kyori.adventure.text.Component> pages() {
+ if (this.pages == null) return ImmutableList.of();
+ if (this instanceof CraftMetaBookSigned)
+ return pages.stream().map(net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson()::deserialize).collect(ImmutableList.toImmutableList());
+ else
+ return pages.stream().map(io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC::deserialize).collect(ImmutableList.toImmutableList());
+ }
+
+ @Override
+ public BookMeta pages(List<net.kyori.adventure.text.Component> pages) {
+ if (this.pages != null) this.pages.clear();
+ for (net.kyori.adventure.text.Component page : pages) {
+ addPages(page);
+ }
+ return this;
+ }
+
+ @Override
+ public BookMeta pages(net.kyori.adventure.text.Component... pages) {
+ if (this.pages != null) this.pages.clear();
+ addPages(pages);
+ return this;
+ }
+
+ @Override
+ public void addPages(net.kyori.adventure.text.Component... pages) {
+ if (this.pages == null) this.pages = new ArrayList<>();
+ for (net.kyori.adventure.text.Component page : pages) {
+ if (this.pages.size() >= MAX_PAGES) {
+ return;
+ }
+
+ if (page == null) {
+ page = net.kyori.adventure.text.Component.empty();
+ }
+
+ this.pages.add(this instanceof CraftMetaBookSigned ? net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson().serialize(page) : io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.serialize(page));
+ }
+ }
+
+ private CraftMetaBook(net.kyori.adventure.text.Component title, net.kyori.adventure.text.Component author, List<net.kyori.adventure.text.Component> pages) {
+ super((org.bukkit.craftbukkit.inventory.CraftMetaItem) org.bukkit.Bukkit.getItemFactory().getItemMeta(org.bukkit.Material.WRITABLE_BOOK));
+ this.title = title == null ? null : io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.serialize(title);
+ this.author = author == null ? null : io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.serialize(author);
+ this.pages = pages.subList(0, Math.min(MAX_PAGES, pages.size())).stream().map(io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC::serialize).collect(java.util.stream.Collectors.toList());
+ }
+
+ static final class CraftMetaBookBuilder implements BookMetaBuilder {
+ private net.kyori.adventure.text.Component title = null;
+ private net.kyori.adventure.text.Component author = null;
+ private final List<net.kyori.adventure.text.Component> pages = new java.util.ArrayList<>();
+
+ @Override
+ public BookMetaBuilder title(net.kyori.adventure.text.Component title) {
+ this.title = title;
+ return this;
+ }
+
+ @Override
+ public BookMetaBuilder author(net.kyori.adventure.text.Component author) {
+ this.author = author;
+ return this;
+ }
+
+ @Override
+ public BookMetaBuilder addPage(net.kyori.adventure.text.Component page) {
+ this.pages.add(page);
+ return this;
+ }
+
+ @Override
+ public BookMetaBuilder pages(net.kyori.adventure.text.Component... pages) {
+ java.util.Collections.addAll(this.pages, pages);
+ return this;
+ }
+
+ @Override
+ public BookMetaBuilder pages(java.util.Collection<net.kyori.adventure.text.Component> pages) {
+ this.pages.addAll(pages);
+ return this;
+ }
+
+ @Override
+ public BookMeta build() {
+ return new CraftMetaBook(title, author, pages);
+ }
+ }
+ // Paper end
@Override
public String getPage(final int page) {
Validate.isTrue(isValidPage(page), "Invalid page number");
@@ -413,7 +543,7 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta {
}
@Override
- Builder<String, Object> serialize(Builder<String, Object> builder) {
+ ImmutableMap.Builder<String, Object> serialize(ImmutableMap.Builder<String, Object> builder) {
super.serialize(builder);
if (hasTitle()) {
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java
index 0835541f51e643ae824c197be7100d5849b5e92a..0d58ec9834797ad7b9acaae6353dcf0385c53fd4 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java
@@ -1,6 +1,6 @@
package org.bukkit.craftbukkit.inventory;
-import com.google.common.collect.ImmutableMap.Builder;
+import com.google.common.collect.ImmutableMap; // Paper
import java.util.Map;
import net.minecraft.nbt.NBTTagCompound;
import org.bukkit.Material;
@@ -84,7 +84,7 @@ class CraftMetaBookSigned extends CraftMetaBook implements BookMeta {
}
@Override
- Builder<String, Object> serialize(Builder<String, Object> builder) {
+ ImmutableMap.Builder<String, Object> serialize(ImmutableMap.Builder<String, Object> builder) {
super.serialize(builder);
return builder;
}
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
index 928328c292a1322cab478bc748761baf8608e4b0..7a11b2ddfa4244459253c918315aaab78ef2eb4a 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
@@ -745,6 +745,18 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
return !(hasDisplayName() || hasLocalizedName() || hasEnchants() || (lore != null) || hasCustomModelData() || hasBlockData() || hasRepairCost() || !unhandledTags.isEmpty() || !persistentDataContainer.isEmpty() || hideFlag != 0 || isUnbreakable() || hasDamage() || hasAttributeModifiers());
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component displayName() {
+ return displayName == null ? null : net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson().deserialize(displayName);
+ }
+
+ @Override
+ public void displayName(final net.kyori.adventure.text.Component displayName) {
+ this.displayName = displayName == null ? null : net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson().serialize(displayName);
+ }
+ // Paper end
+
@Override
public String getDisplayName() {
return CraftChatMessage.fromJSONComponent(displayName);
@@ -780,6 +792,18 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
return this.lore != null && !this.lore.isEmpty();
}
+ // Paper start
+ @Override
+ public List<net.kyori.adventure.text.Component> lore() {
+ return this.lore != null ? io.papermc.paper.adventure.PaperAdventure.asAdventureFromJson(this.lore) : null;
+ }
+
+ @Override
+ public void lore(final List<net.kyori.adventure.text.Component> lore) {
+ this.lore = lore != null ? io.papermc.paper.adventure.PaperAdventure.asJson(lore) : null;
+ }
+ // Paper end
+
@Override
public boolean hasRepairCost() {
return repairCost > 0;
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftCustomInventoryConverter.java b/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftCustomInventoryConverter.java
index ed4415f6dd588c08c922efd5beebb3b124beb9d6..78a7ac47f20e84ccd67ff44d0bc7a2f2faa0d476 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftCustomInventoryConverter.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftCustomInventoryConverter.java
@@ -12,6 +12,13 @@ public class CraftCustomInventoryConverter implements CraftInventoryCreator.Inve
return new CraftInventoryCustom(holder, type);
}
+ // Paper start
+ @Override
+ public Inventory createInventory(InventoryHolder owner, InventoryType type, net.kyori.adventure.text.Component title) {
+ return new CraftInventoryCustom(owner, type, title);
+ }
+ // Paper end
+
@Override
public Inventory createInventory(InventoryHolder owner, InventoryType type, String title) {
return new CraftInventoryCustom(owner, type, title);
@@ -21,6 +28,12 @@ public class CraftCustomInventoryConverter implements CraftInventoryCreator.Inve
return new CraftInventoryCustom(owner, size);
}
+ // Paper start
+ public Inventory createInventory(InventoryHolder owner, int size, net.kyori.adventure.text.Component title) {
+ return new CraftInventoryCustom(owner, size, title);
+ }
+ // Paper end
+
public Inventory createInventory(InventoryHolder owner, int size, String title) {
return new CraftInventoryCustom(owner, size, title);
}
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftInventoryCreator.java b/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftInventoryCreator.java
index b51321c8dd70a90ab149f456c7ffb4587c4fbd34..94d807c5d09f165c6eedd0a1c4026c2b833806a0 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftInventoryCreator.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftInventoryCreator.java
@@ -43,6 +43,17 @@ public final class CraftInventoryCreator {
return converterMap.get(type).createInventory(holder, type);
}
+ // Paper start
+ public Inventory createInventory(InventoryHolder holder, InventoryType type, net.kyori.adventure.text.Component title) {
+ // Paper start
+ if (holder != null) {
+ return DEFAULT_CONVERTER.createInventory(holder, type, title);
+ }
+ //noinspection ConstantConditions // Paper end
+ return converterMap.get(type).createInventory(holder, type, title);
+ }
+ // Paper end
+
public Inventory createInventory(InventoryHolder holder, InventoryType type, String title) {
return converterMap.get(type).createInventory(holder, type, title);
}
@@ -51,6 +62,12 @@ public final class CraftInventoryCreator {
return DEFAULT_CONVERTER.createInventory(holder, size);
}
+ // Paper start
+ public Inventory createInventory(InventoryHolder holder, int size, net.kyori.adventure.text.Component title) {
+ return DEFAULT_CONVERTER.createInventory(holder, size, title);
+ }
+ // Paper end
+
public Inventory createInventory(InventoryHolder holder, int size, String title) {
return DEFAULT_CONVERTER.createInventory(holder, size, title);
}
@@ -59,6 +76,10 @@ public final class CraftInventoryCreator {
Inventory createInventory(InventoryHolder holder, InventoryType type);
+ // Paper start
+ Inventory createInventory(InventoryHolder holder, InventoryType type, net.kyori.adventure.text.Component title);
+ // Paper end
+
Inventory createInventory(InventoryHolder holder, InventoryType type, String title);
}
}
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftTileInventoryConverter.java b/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftTileInventoryConverter.java
index f35e66dab9ff63ca05d7e303c71106c0e9971309..2bd4e644ffbde2e1133b25824a2829bc6b33fa84 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftTileInventoryConverter.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftTileInventoryConverter.java
@@ -31,6 +31,18 @@ public abstract class CraftTileInventoryConverter implements CraftInventoryCreat
return getInventory(getTileEntity());
}
+ // Paper start
+ @Override
+ public Inventory createInventory(InventoryHolder owner, InventoryType type, net.kyori.adventure.text.Component title) {
+ IInventory te = getTileEntity();
+ if (te instanceof TileEntityLootable) {
+ ((TileEntityLootable) te).setCustomName(io.papermc.paper.adventure.PaperAdventure.asVanilla(title));
+ }
+
+ return getInventory(te);
+ }
+ // Paper end
+
@Override
public Inventory createInventory(InventoryHolder holder, InventoryType type, String title) {
IInventory te = getTileEntity();
@@ -54,6 +66,15 @@ public abstract class CraftTileInventoryConverter implements CraftInventoryCreat
return furnace;
}
+ // Paper start
+ @Override
+ public Inventory createInventory(InventoryHolder owner, InventoryType type, net.kyori.adventure.text.Component title) {
+ IInventory tileEntity = getTileEntity();
+ ((TileEntityFurnace) tileEntity).setCustomName(io.papermc.paper.adventure.PaperAdventure.asVanilla(title));
+ return getInventory(tileEntity);
+ }
+ // Paper end
+
@Override
public Inventory createInventory(InventoryHolder owner, InventoryType type, String title) {
IInventory tileEntity = getTileEntity();
@@ -74,6 +95,18 @@ public abstract class CraftTileInventoryConverter implements CraftInventoryCreat
return new TileEntityBrewingStand();
}
+ // Paper start
+ @Override
+ public Inventory createInventory(InventoryHolder owner, InventoryType type, net.kyori.adventure.text.Component title) {
+ // BrewingStand does not extend TileEntityLootable
+ IInventory tileEntity = getTileEntity();
+ if (tileEntity instanceof TileEntityBrewingStand) {
+ ((TileEntityBrewingStand) tileEntity).setCustomName(io.papermc.paper.adventure.PaperAdventure.asVanilla(title));
+ }
+ return getInventory(tileEntity);
+ }
+ // Paper end
+
@Override
public Inventory createInventory(InventoryHolder holder, InventoryType type, String title) {
// BrewingStand does not extend TileEntityLootable
diff --git a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftObjective.java b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftObjective.java
index 8fedca656af0783f3d97a7ccde3a113f97911084..df3deee12b11508b76c5f8f927fac8db54a7e397 100644
--- a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftObjective.java
+++ b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftObjective.java
@@ -31,6 +31,21 @@ final class CraftObjective extends CraftScoreboardComponent implements Objective
return objective.getName();
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component displayName() throws IllegalStateException {
+ CraftScoreboard scoreboard = checkState();
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(objective.getDisplayName());
+ }
+ @Override
+ public void displayName(net.kyori.adventure.text.Component displayName) throws IllegalStateException, IllegalArgumentException {
+ if (displayName == null) {
+ displayName = net.kyori.adventure.text.Component.empty();
+ }
+ CraftScoreboard scoreboard = checkState();
+ objective.setDisplayName(io.papermc.paper.adventure.PaperAdventure.asVanilla(displayName));
+ }
+ // Paper end
@Override
public String getDisplayName() throws IllegalStateException {
CraftScoreboard scoreboard = checkState();
diff --git a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java
index 954389b818de93cf0ab046edc5dc032fceea391b..6ea491f6308317059c4bc6735abbdce370df0f34 100644
--- a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java
+++ b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java
@@ -28,6 +28,27 @@ public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard {
public CraftObjective registerNewObjective(String name, String criteria) throws IllegalArgumentException {
return registerNewObjective(name, criteria, name);
}
+ // Paper start
+ @Override
+ public CraftObjective registerNewObjective(String name, String criteria, net.kyori.adventure.text.Component displayName) {
+ return registerNewObjective(name, criteria, displayName, org.bukkit.scoreboard.RenderType.INTEGER);
+ }
+ @Override
+ public CraftObjective registerNewObjective(String name, String criteria, net.kyori.adventure.text.Component displayName, RenderType renderType) {
+ if (displayName == null) {
+ displayName = net.kyori.adventure.text.Component.empty();
+ }
+ Validate.notNull(name, "Objective name cannot be null");
+ Validate.notNull(criteria, "Criteria cannot be null");
+ Validate.notNull(displayName, "Display name cannot be null");
+ Validate.notNull(renderType, "RenderType cannot be null");
+ Validate.isTrue(name.length() <= 16, "The name '" + name + "' is longer than the limit of 16 characters");
+ Validate.isTrue(board.getObjective(name) == null, "An objective of name '" + name + "' already exists");
+ CraftCriteria craftCriteria = CraftCriteria.getFromBukkit(criteria);
+ ScoreboardObjective objective = board.registerObjective(name, craftCriteria.criteria, io.papermc.paper.adventure.PaperAdventure.asVanilla(displayName), CraftScoreboardTranslations.fromBukkitRender(renderType));
+ return new CraftObjective(this, objective);
+ }
+ // Paper end
@Override
public CraftObjective registerNewObjective(String name, String criteria, String displayName) throws IllegalArgumentException {
@@ -36,7 +57,7 @@ public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard {
@Override
public CraftObjective registerNewObjective(String name, String criteria, String displayName, RenderType renderType) throws IllegalArgumentException {
- Validate.notNull(name, "Objective name cannot be null");
+ /*Validate.notNull(name, "Objective name cannot be null"); // Paper
Validate.notNull(criteria, "Criteria cannot be null");
Validate.notNull(displayName, "Display name cannot be null");
Validate.notNull(renderType, "RenderType cannot be null");
@@ -46,7 +67,8 @@ public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard {
CraftCriteria craftCriteria = CraftCriteria.getFromBukkit(criteria);
ScoreboardObjective objective = board.registerObjective(name, craftCriteria.criteria, CraftChatMessage.fromStringOrNull(displayName), CraftScoreboardTranslations.fromBukkitRender(renderType));
- return new CraftObjective(this, objective);
+ return new CraftObjective(this, objective);*/ // Paper
+ return registerNewObjective(name, criteria, io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.deserialize(displayName), renderType); // Paper
}
@Override
diff --git a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftTeam.java b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftTeam.java
index a213c2e3b2680c6d1bd38853580cbdb52ae7779e..c631934fe9d205a06956c900d5b58a1d8a781c19 100644
--- a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftTeam.java
+++ b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftTeam.java
@@ -29,6 +29,55 @@ final class CraftTeam extends CraftScoreboardComponent implements Team {
return team.getName();
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component displayName() throws IllegalStateException {
+ CraftScoreboard scoreboard = checkState();
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(team.getDisplayName());
+ }
+ @Override
+ public void displayName(net.kyori.adventure.text.Component displayName) throws IllegalStateException, IllegalArgumentException {
+ if (displayName == null) displayName = net.kyori.adventure.text.Component.empty();
+ CraftScoreboard scoreboard = checkState();
+ team.setDisplayName(io.papermc.paper.adventure.PaperAdventure.asVanilla(displayName));
+ }
+ @Override
+ public net.kyori.adventure.text.Component prefix() throws IllegalStateException {
+ CraftScoreboard scoreboard = checkState();
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(team.getPrefix());
+ }
+ @Override
+ public void prefix(net.kyori.adventure.text.Component prefix) throws IllegalStateException, IllegalArgumentException {
+ if (prefix == null) prefix = net.kyori.adventure.text.Component.empty();
+ CraftScoreboard scoreboard = checkState();
+ team.setPrefix(io.papermc.paper.adventure.PaperAdventure.asVanilla(prefix));
+ }
+ @Override
+ public net.kyori.adventure.text.Component suffix() throws IllegalStateException {
+ CraftScoreboard scoreboard = checkState();
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(team.getSuffix());
+ }
+ @Override
+ public void suffix(net.kyori.adventure.text.Component suffix) throws IllegalStateException, IllegalArgumentException {
+ if (suffix == null) suffix = net.kyori.adventure.text.Component.empty();
+ CraftScoreboard scoreboard = checkState();
+ team.setSuffix(io.papermc.paper.adventure.PaperAdventure.asVanilla(suffix));
+ }
+ @Override
+ public net.kyori.adventure.text.format.TextColor color() throws IllegalStateException {
+ CraftScoreboard scoreboard = checkState();
+ if (team.getColor().getHexValue() == null) throw new IllegalStateException("Team colors must have hex values");
+ net.kyori.adventure.text.format.TextColor color = net.kyori.adventure.text.format.TextColor.color(team.getColor().getHexValue());
+ if (!(color instanceof net.kyori.adventure.text.format.NamedTextColor)) throw new IllegalStateException("Team doesn't have a NamedTextColor");
+ return (net.kyori.adventure.text.format.NamedTextColor) color;
+ }
+ @Override
+ public void color(net.kyori.adventure.text.format.NamedTextColor color) {
+ if (color == null) color = net.kyori.adventure.text.format.NamedTextColor.WHITE;
+ CraftScoreboard scoreboard = checkState();
+ team.setColor(io.papermc.paper.adventure.PaperAdventure.asVanilla(color));
+ }
+ // Paper end
@Override
public String getDisplayName() throws IllegalStateException {
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftChatMessage.java b/src/main/java/org/bukkit/craftbukkit/util/CraftChatMessage.java
index 6a0b4cd36ac54df41642e8499c50e59f2b347b48..666af6cc91bd12ba5d5a846d663a5aabf861fbc4 100644
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftChatMessage.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftChatMessage.java
@@ -290,6 +290,7 @@ public final class CraftChatMessage {
public static String fromComponent(IChatBaseComponent component) {
if (component == null) return "";
+ if (component instanceof io.papermc.paper.adventure.AdventureComponent) component = ((io.papermc.paper.adventure.AdventureComponent) component).deepConverted();
StringBuilder out = new StringBuilder();
boolean hadFormat = false;
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
index 65131f0977fa55c4761c34ce52720170feb61a72..8f737f63f280c00c1276bd1dc3ecf60448732ca8 100644
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
@@ -59,6 +59,33 @@ public final class CraftMagicNumbers implements UnsafeValues {
private CraftMagicNumbers() {}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.flattener.ComponentFlattener componentFlattener() {
+ return io.papermc.paper.adventure.PaperAdventure.FLATTENER;
+ }
+
+ @Override
+ public net.kyori.adventure.text.serializer.gson.GsonComponentSerializer colorDownsamplingGsonComponentSerializer() {
+ return io.papermc.paper.adventure.PaperAdventure.COLOR_DOWNSAMPLING_GSON;
+ }
+
+ @Override
+ public net.kyori.adventure.text.serializer.gson.GsonComponentSerializer gsonComponentSerializer() {
+ return io.papermc.paper.adventure.PaperAdventure.GSON;
+ }
+
+ @Override
+ public net.kyori.adventure.text.serializer.plain.PlainComponentSerializer plainComponentSerializer() {
+ return io.papermc.paper.adventure.PaperAdventure.PLAIN;
+ }
+
+ @Override
+ public net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer legacyComponentSerializer() {
+ return io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC;
+ }
+ // Paper end
+
public static IBlockData getBlock(MaterialData material) {
return getBlock(material.getItemType(), material.getData());
}
|