Compare commits
696
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a3739319af | ||
|
|
5513c0f14b | ||
|
|
6869ac594f | ||
|
|
1bad630ec1 | ||
|
|
ba21fa9a8b | ||
|
|
7d01583cea | ||
|
|
90968ca195 | ||
|
|
3e1cffee7e | ||
|
|
d6564e6263 | ||
|
|
24b7b97c09 | ||
|
|
bf0448ab15 | ||
|
|
6c3b66ef84 | ||
|
|
507281fd18 | ||
|
|
c46c536ea9 | ||
|
|
fb15ac5742 | ||
|
|
427a305b61 | ||
|
|
ded4f5103f | ||
|
|
004c1aadab | ||
|
|
2f0ffb163c | ||
|
|
be03ffe93f | ||
|
|
b943f195f3 | ||
|
|
31e7fba37d | ||
|
|
14c75f19fb | ||
|
|
3fef6fa51c | ||
|
|
b6c62bb055 | ||
|
|
c3edd14b90 | ||
|
|
7014999f65 | ||
|
|
d3b32b4e22 | ||
|
|
b94a86e5fa | ||
|
|
9038fd149a | ||
|
|
65cf7c0b92 | ||
|
|
c1d2c6c049 | ||
|
|
b2a9b6a98c | ||
|
|
1cf80df77a | ||
|
|
2606094a40 | ||
|
|
ddf014b852 | ||
|
|
be2f392c91 | ||
|
|
91c370327b | ||
|
|
6dfdfc8363 | ||
|
|
e09c596020 | ||
|
|
5bf7dba140 | ||
|
|
7d74474fde | ||
|
|
14195de83e | ||
|
|
8e16c5564d | ||
|
|
803a50542c | ||
|
|
150acb64c3 | ||
|
|
009f0a7c13 | ||
|
|
db99d1f187 | ||
|
|
6514b84adf | ||
|
|
e40dfe35b8 | ||
|
|
fee0ff6e26 | ||
|
|
9ed447164a | ||
|
|
6102208f45 | ||
|
|
ec31fb0cbb | ||
|
|
c4660b4821 | ||
|
|
978be6bbcc | ||
|
|
ee8b1e9458 | ||
|
|
4fdd047026 | ||
|
|
5c22920393 | ||
|
|
8a18947fd2 | ||
|
|
e903aa52e3 | ||
|
|
9ff8cf30b4 | ||
|
|
8092bbdb3b | ||
|
|
bff9ef2f6b | ||
|
|
cc1bd65841 | ||
|
|
8a84b1fc15 | ||
|
|
3015f40531 | ||
|
|
f4e5dab1d8 | ||
|
|
2792dd4c78 | ||
|
|
b4d45f0fba | ||
|
|
3443a482b3 | ||
|
|
d89af56959 | ||
|
|
80d7c4a5a9 | ||
|
|
810b205cfa | ||
|
|
0c452ab842 | ||
|
|
be414fceb6 | ||
|
|
95099e9763 | ||
|
|
f806773cbe | ||
|
|
9af8bab57f | ||
|
|
20c5d9f28a | ||
|
|
cbe474dafa | ||
|
|
af90c6534b | ||
|
|
4130fcf172 | ||
|
|
e321a169c2 | ||
|
|
54d4614600 | ||
|
|
8fc10e8f62 | ||
|
|
e770a1c9ee | ||
|
|
c999f3a810 | ||
|
|
8e070aac9a | ||
|
|
faecd9dd9c | ||
|
|
e40d8c875f | ||
|
|
10765058f8 | ||
|
|
c71d6da310 | ||
|
|
4ec106e36f | ||
|
|
66a7ef3ffa | ||
|
|
3d858013e6 | ||
|
|
3c15e5409f | ||
|
|
206d484f27 | ||
|
|
e2949ade16 | ||
|
|
896ed7ff07 | ||
|
|
4ca682704a | ||
|
|
2275091e76 | ||
|
|
dd71d9ae69 | ||
|
|
b2d3aee10e | ||
|
|
1891307753 | ||
|
|
399d831d04 | ||
|
|
29ad41f42f | ||
|
|
bab19e14bd | ||
|
|
286ea801d8 | ||
|
|
6320cc314e | ||
|
|
cb094f1af3 | ||
|
|
d00d138a21 | ||
|
|
8b86b3e48b | ||
|
|
3232c69a5a | ||
|
|
4ee24812f4 | ||
|
|
a2139718a5 | ||
|
|
57e536b8b2 | ||
|
|
ab0e4030c3 | ||
|
|
89fe7f43a7 | ||
|
|
fffb4e08b8 | ||
|
|
1b071e6564 | ||
|
|
efb1b1e1eb | ||
|
|
60421a6727 | ||
|
|
7f7107a79a | ||
|
|
94827892cc | ||
|
|
78d0d674b5 | ||
|
|
ed681fadd1 | ||
|
|
35de72c331 | ||
|
|
018d611b2b | ||
|
|
852d34cdcf | ||
|
|
d4fead85b8 | ||
|
|
a8bbc97d00 | ||
|
|
94d77e94da | ||
|
|
b1e2a746e3 | ||
|
|
1b8e23dcf5 | ||
|
|
ecd87f2fc6 | ||
|
|
22453a2fac | ||
|
|
80c1413811 | ||
|
|
0fcd8d57c0 | ||
|
|
750d8813f3 | ||
|
|
ca546a9e59 | ||
|
|
29fd80865c | ||
|
|
ab253a0976 | ||
|
|
5545de8886 | ||
|
|
637aecbf4b | ||
|
|
aaf6d41766 | ||
|
|
f814d0ecf8 | ||
|
|
f20e8432b1 | ||
|
|
0e558e4baf | ||
|
|
5eb7d5b3fc | ||
|
|
4a5382b14c | ||
|
|
c2b006ddab | ||
|
|
e4b60d55f3 | ||
|
|
4521ce8037 | ||
|
|
73490b8ff6 | ||
|
|
0549c8e486 | ||
|
|
af7c0d346f | ||
|
|
9a5da1bc9a | ||
|
|
96a601da74 | ||
|
|
f29626311c | ||
|
|
ea0b9a497e | ||
|
|
b11e76494e | ||
|
|
cb3a62cf71 | ||
|
|
992d4855e7 | ||
|
|
a684b56dc3 | ||
|
|
e6c86a7e4f | ||
|
|
73e34d8f0b | ||
|
|
d006974e7b | ||
|
|
0742f24973 | ||
|
|
76bde2568b | ||
|
|
40bd7d60d4 | ||
|
|
6d7718428a | ||
|
|
92229a90e9 | ||
|
|
7dd6fbd9af | ||
|
|
2fa285ddde | ||
|
|
8962c80495 | ||
|
|
2dccce47bf | ||
|
|
6231e8c7d4 | ||
|
|
5ba3080d00 | ||
|
|
a110c549be | ||
|
|
021460ba08 | ||
|
|
74d14166d5 | ||
|
|
f24add4246 | ||
|
|
acf631a54f | ||
|
|
a6b4087454 | ||
|
|
f392495474 | ||
|
|
b8fdd74f96 | ||
|
|
9dba5d40ca | ||
|
|
78c7709add | ||
|
|
7a0908faaf | ||
|
|
0624b1766f | ||
|
|
651de583b6 | ||
|
|
c29847af02 | ||
|
|
87c8147514 | ||
|
|
57778b5eb3 | ||
|
|
f2d136af0a | ||
|
|
22d568f30e | ||
|
|
49a81fa4f7 | ||
|
|
57f9a8fe3a | ||
|
|
94c731afbf | ||
|
|
98304cb41e | ||
|
|
70d68d7860 | ||
|
|
5502c4a434 | ||
|
|
f424b9bd66 | ||
|
|
c8d0733935 | ||
|
|
c2ba3304f7 | ||
|
|
510bf9301c | ||
|
|
8a64746b18 | ||
|
|
feab6ba0bd | ||
|
|
f11a5dd31c | ||
|
|
5a3a4f6507 | ||
|
|
40fa932d33 | ||
|
|
1355ca6bdd | ||
|
|
5639c2b85e | ||
|
|
baa8837987 | ||
|
|
38f2783149 | ||
|
|
43a5e2c590 | ||
|
|
9a124b8e68 | ||
|
|
02b9e9260f | ||
|
|
d109e9dd54 | ||
|
|
2ea24250a0 | ||
|
|
39d555f3ec | ||
|
|
6e09ec2e2b | ||
|
|
f91de06044 | ||
|
|
63e3563a1a | ||
|
|
655d97c73a | ||
|
|
a7c8f21d31 | ||
|
|
f23ff3d421 | ||
|
|
766f0c0a32 | ||
|
|
e13d52a518 | ||
|
|
329b8adefa | ||
|
|
5bb90aa0de | ||
|
|
a7949eb096 | ||
|
|
a4288ca29c | ||
|
|
9b1e92b555 | ||
|
|
104615edb5 | ||
|
|
9f54ca6843 | ||
|
|
46919017e1 | ||
|
|
0a1ce38c7e | ||
|
|
f60d5230c3 | ||
|
|
8034f5dc89 | ||
|
|
265ade55d0 | ||
|
|
cffcbaf596 | ||
|
|
4dc90a2920 | ||
|
|
e5b5845ebf | ||
|
|
b5f6a7f6b8 | ||
|
|
f916addda3 | ||
|
|
d275fb8d8b | ||
|
|
3ce8971215 | ||
|
|
5866e4ede1 | ||
|
|
a47040e18a | ||
|
|
631b41d9d0 | ||
|
|
8b9cf0c283 | ||
|
|
e7afd771f8 | ||
|
|
98446b5afc | ||
|
|
0fbfca81a1 | ||
|
|
33f1eab93b | ||
|
|
38fcccd7c9 | ||
|
|
053768ccfa | ||
|
|
d11a0406cb | ||
|
|
5966ca1355 | ||
|
|
72944a00c0 | ||
|
|
671c935134 | ||
|
|
c931974779 | ||
|
|
5e6d0bffde | ||
|
|
c08719acc7 | ||
|
|
e76b00c880 | ||
|
|
b30d56ed0b | ||
|
|
211b85a51b | ||
|
|
f895ff0e0a | ||
|
|
3726f6629a | ||
|
|
33aae65e35 | ||
|
|
6f0f6eaa24 | ||
|
|
d6ee3b356e | ||
|
|
2d495b7570 | ||
|
|
5a8acfdffd | ||
|
|
1938f9f3bf | ||
|
|
672b8e47fd | ||
|
|
846d0a893e | ||
|
|
fb45b5b35a | ||
|
|
1205020451 | ||
|
|
3ed2735d0e | ||
|
|
5b3d6ae7a2 | ||
|
|
e3d9638b47 | ||
|
|
9ec6118159 | ||
|
|
7b800a9015 | ||
|
|
ba0feb31f0 | ||
|
|
36b73752f7 | ||
|
|
6f0586ce23 | ||
|
|
59159d47a0 | ||
|
|
23c0fc9bff | ||
|
|
c34690197d | ||
|
|
c98425cb99 | ||
|
|
55f4280ccb | ||
|
|
b9299dfa96 | ||
|
|
b1fb30163c | ||
|
|
50b8776aa9 | ||
|
|
d47b450307 | ||
|
|
1f41447a02 | ||
|
|
af251d03b8 | ||
|
|
1445057145 | ||
|
|
a306ac26b9 | ||
|
|
df6a334a00 | ||
|
|
c43ea28f59 | ||
|
|
596f1b57ce | ||
|
|
386238aae8 | ||
|
|
e7dcb4c96e | ||
|
|
6049e37d87 | ||
|
|
a41e747da7 | ||
|
|
c4c61dff3c | ||
|
|
84b85c8f00 | ||
|
|
f9b3786c16 | ||
|
|
d2350ad383 | ||
|
|
f6c554da02 | ||
|
|
721532ee44 | ||
|
|
7ff8c40402 | ||
|
|
df6d7fa741 | ||
|
|
c936c9da31 | ||
|
|
3a5aa401f0 | ||
|
|
9c5263bf20 | ||
|
|
28cb480ac3 | ||
|
|
838426e1bf | ||
|
|
d486863a64 | ||
|
|
cd98e8488b | ||
|
|
a7c6f88a11 | ||
|
|
c15b88e77f | ||
|
|
1a2d39d68f | ||
|
|
fe8ca640cc | ||
|
|
26eee81455 | ||
|
|
8c63a7c7b6 | ||
|
|
d221869491 | ||
|
|
539b814a5a | ||
|
|
d0da1d710b | ||
|
|
2771959dd8 | ||
|
|
aa17d098c4 | ||
|
|
7a1f432652 | ||
|
|
bca60bfa19 | ||
|
|
94e2dc0378 | ||
|
|
e8bdd02838 | ||
|
|
b962876dfd | ||
|
|
f0135204e3 | ||
|
|
5bedb44e11 | ||
|
|
4e3ada1bd8 | ||
|
|
38d68418dc | ||
|
|
5f8efaaf0f | ||
|
|
9b8de173e4 | ||
|
|
de4594fbdc | ||
|
|
5eae00ef0b | ||
|
|
3c418473d8 | ||
|
|
1e919053c6 | ||
|
|
30ff648bad | ||
|
|
6c5d9beb76 | ||
|
|
3e828ea9ee | ||
|
|
4ef8b381d7 | ||
|
|
24838cd7d9 | ||
|
|
e17b877b5f | ||
|
|
8b85bc8d4d | ||
|
|
fca9ad22fe | ||
|
|
8f7ec3d38a | ||
|
|
41969994b2 | ||
|
|
667652bfb8 | ||
|
|
2da42185e8 | ||
|
|
fd1b918956 | ||
|
|
828013bf77 | ||
|
|
6e30fb393a | ||
|
|
cbfca6c5fa | ||
|
|
945ca46491 | ||
|
|
f7d5252bf0 | ||
|
|
a624a76427 | ||
|
|
39f9ed008c | ||
|
|
a0096b3032 | ||
|
|
ae1a0258fe | ||
|
|
f863ad026f | ||
|
|
abea90564f | ||
|
|
3bdd110864 | ||
|
|
b2e47f48a5 | ||
|
|
513de88321 | ||
|
|
4a2146d16d | ||
|
|
5a49cf2687 | ||
|
|
65fba0b83d | ||
|
|
5272557f58 | ||
|
|
51abf38d3f | ||
|
|
33abe17a2b | ||
|
|
593015dd0b | ||
|
|
079a2fcc53 | ||
|
|
b9d4ed6a60 | ||
|
|
aec45f19e4 | ||
|
|
0aaa4f42b1 | ||
|
|
75dfc63d3b | ||
|
|
ac501a26b2 | ||
|
|
3ebf39d3bd | ||
|
|
363931875f | ||
|
|
b1802fbc0c | ||
|
|
9f9cdca53a | ||
|
|
00c85f3e41 | ||
|
|
b48a91bcee | ||
|
|
709edd8b21 | ||
|
|
90edf6002e | ||
|
|
4e151f8dfb | ||
|
|
0165e8a4ac | ||
|
|
385000b608 | ||
|
|
a1b7c947a0 | ||
|
|
ab5163bc66 | ||
|
|
38b25b6d48 | ||
|
|
9d5d4858cf | ||
|
|
2e6c43ba06 | ||
|
|
f180a4a172 | ||
|
|
5ce6b8bf9e | ||
|
|
b61602741b | ||
|
|
13ba9e7b81 | ||
|
|
d4c9444fd5 | ||
|
|
b6c079af66 | ||
|
|
a18d288079 | ||
|
|
c3d8f91e85 | ||
|
|
0ca2f5c50a | ||
|
|
cdc7ed36e0 | ||
|
|
5d63308a22 | ||
|
|
214706dbb6 | ||
|
|
fa3b563c70 | ||
|
|
55e31483e7 | ||
|
|
aa34910468 | ||
|
|
5e44913a5e | ||
|
|
b8dc964112 | ||
|
|
890844fb60 | ||
|
|
fc57c9e077 | ||
|
|
f12ef113aa | ||
|
|
e8144ece97 | ||
|
|
b611ad5522 | ||
|
|
53e1014c8d | ||
|
|
69f992a984 | ||
|
|
fde9db39b7 | ||
|
|
6c6a2535c8 | ||
|
|
23d06075dd | ||
|
|
926fd1ae50 | ||
|
|
756add003f | ||
|
|
aaf00bf167 | ||
|
|
d72c8df72c | ||
|
|
800ffafb96 | ||
|
|
ba2d9ae9f0 | ||
|
|
31d07e4a39 | ||
|
|
ec36a5d1d8 | ||
|
|
08ba59e1d9 | ||
|
|
851c74e827 | ||
|
|
b31893e035 | ||
|
|
4718fb985d | ||
|
|
aed9bc14fa | ||
|
|
1daad13da3 | ||
|
|
65a984e805 | ||
|
|
a923b950f6 | ||
|
|
ac5790411f | ||
|
|
cd3449ade2 | ||
|
|
75af221f77 | ||
|
|
6f9b2cf5e9 | ||
|
|
4b4dd492cf | ||
|
|
68471d32c8 | ||
|
|
b7d0ce9518 | ||
|
|
58abfc0c1e | ||
|
|
a3f6adac2f | ||
|
|
f0c9af4464 | ||
|
|
f43fff899f | ||
|
|
9291fd8953 | ||
|
|
feb975010e | ||
|
|
5c34c8e6c3 | ||
|
|
8aaf40fc74 | ||
|
|
c6fcab2923 | ||
|
|
64006b91a4 | ||
|
|
625a66f45a | ||
|
|
0c6208f931 | ||
|
|
be32f464c5 | ||
|
|
3389baf40e | ||
|
|
edc85e68e8 | ||
|
|
3f9f093934 | ||
|
|
31426cc69c | ||
|
|
cec8c9789f | ||
|
|
f771e15ce0 | ||
|
|
68a3702cd6 | ||
|
|
8f4f688fb8 | ||
|
|
0a380344c5 | ||
|
|
ab458ded62 | ||
|
|
3bc78c1aec | ||
|
|
0feebb6819 | ||
|
|
cdb48e0ab6 | ||
|
|
85e819d72f | ||
|
|
10d44fe3cb | ||
|
|
6b5ada3c5d | ||
|
|
2f0861c7b7 | ||
|
|
abc8695a29 | ||
|
|
c6577646ce | ||
|
|
a6c68b2d0e | ||
|
|
23e0861192 | ||
|
|
7539aa345c | ||
|
|
2a076a61a0 | ||
|
|
bf0ec04cec | ||
|
|
fea687bba9 | ||
|
|
25e83d6181 | ||
|
|
95a91bb1f2 | ||
|
|
e1e057eabb | ||
|
|
f81120f8ed | ||
|
|
e44ad5edc2 | ||
|
|
c35d0854bc | ||
|
|
47dbb5e9c0 | ||
|
|
702894dd07 | ||
|
|
4801196942 | ||
|
|
c88a9c412c | ||
|
|
4012472404 | ||
|
|
54f3f3c221 | ||
|
|
873557151b | ||
|
|
32e96f3f51 | ||
|
|
cdffd10999 | ||
|
|
1524a546d8 | ||
|
|
40d7be6236 | ||
|
|
98b2b7b631 | ||
|
|
54704811b3 | ||
|
|
54241497b5 | ||
|
|
99637743f5 | ||
|
|
702452c3a1 | ||
|
|
7e424cd46b | ||
|
|
58401fc18e | ||
|
|
7285eeff5a | ||
|
|
cfb57e7a99 | ||
|
|
93cd6f39f9 | ||
|
|
9975706ba8 | ||
|
|
9b88a9ef98 | ||
|
|
548c6183a4 | ||
|
|
19d271881c | ||
|
|
a64978cb0a | ||
|
|
527beda70f | ||
|
|
127421a1d2 | ||
|
|
4a188bd116 | ||
|
|
cd6db40a0d | ||
|
|
d050c10eab | ||
|
|
82e5b68119 | ||
|
|
3f00e1d817 | ||
|
|
7296072bcb | ||
|
|
132ae43496 | ||
|
|
2465ba9306 | ||
|
|
2e10b151c9 | ||
|
|
9a338cd897 | ||
|
|
7c0bac33df | ||
|
|
db8c4ce08d | ||
|
|
af52640237 | ||
|
|
b6d71a79a1 | ||
|
|
407257c2ce | ||
|
|
19e7bc6190 | ||
|
|
e0beccff4d | ||
|
|
1728e667ea | ||
|
|
c2cce6fac7 | ||
|
|
9cf38bc325 | ||
|
|
c0522d7836 | ||
|
|
dc1ac3beb3 | ||
|
|
d59a11a340 | ||
|
|
a8e95c23ac | ||
|
|
607b8dde56 | ||
|
|
a0ccfb4875 | ||
|
|
afcf98e2c8 | ||
|
|
51d74ae7ea | ||
|
|
7b6308c4e0 | ||
|
|
cdbe0df0f3 | ||
|
|
d799ba7190 | ||
|
|
8c03d2e3a0 | ||
|
|
7c2994e54d | ||
|
|
e1e61feebf | ||
|
|
e6fb117182 | ||
|
|
a7aa3eae68 | ||
|
|
d38089a46a | ||
|
|
e2a980adde | ||
|
|
a4e116d34f | ||
|
|
6b61682fe4 | ||
|
|
0c4709ac57 | ||
|
|
c6a542d206 | ||
|
|
d67028f568 | ||
|
|
af48ee3938 | ||
|
|
945919c1e0 | ||
|
|
38de7a4b94 | ||
|
|
419232a075 | ||
|
|
e705b2725d | ||
|
|
004702f642 | ||
|
|
4c29d39292 | ||
|
|
24e8ff4fb4 | ||
|
|
cf61f74ade | ||
|
|
72ab24b419 | ||
|
|
8c8357bfbc | ||
|
|
59d36b6e55 | ||
|
|
decf5579a3 | ||
|
|
187f5a54c6 | ||
|
|
647c05fe98 | ||
|
|
a089b98f6d | ||
|
|
9d21b834cc | ||
|
|
069e872204 | ||
|
|
e945c9c56f | ||
|
|
b8058b57d8 | ||
|
|
7ce167157a | ||
|
|
0503e99c50 | ||
|
|
413d5e1eb5 | ||
|
|
51ebbb7914 | ||
|
|
2b98d5c90b | ||
|
|
099ea9b7e9 | ||
|
|
ce703febc3 | ||
|
|
dce59f99fd | ||
|
|
5ff498b6f0 | ||
|
|
32b85dce18 | ||
|
|
89b8d823c4 | ||
|
|
fc0f1eec68 | ||
|
|
765fb79321 | ||
|
|
eb42c1b473 | ||
|
|
ce484ecac5 | ||
|
|
cb3e4d33a7 | ||
|
|
12c01eb2fa | ||
|
|
c4b8a17437 | ||
|
|
5dde544e07 | ||
|
|
d16ad2154d | ||
|
|
245da7a870 | ||
|
|
2a0b217718 | ||
|
|
582cfa7b57 | ||
|
|
1b295dc827 | ||
|
|
a83248f70d | ||
|
|
42a1375c00 | ||
|
|
fbe89306f5 | ||
|
|
faeb2f55d3 | ||
|
|
239cc09c9f | ||
|
|
6aac1faac4 | ||
|
|
ea4ab05bff | ||
|
|
d53f39bbc7 | ||
|
|
8f28b71ee2 | ||
|
|
58df1fcc91 | ||
|
|
060b919fa3 | ||
|
|
7d0d4aa672 | ||
|
|
e3cde54ab2 | ||
|
|
d681345e41 | ||
|
|
3939b534ad | ||
|
|
a8afbd2a0b | ||
|
|
7d7cbb4445 | ||
|
|
1c5dceb47d | ||
|
|
876fbf6fbf | ||
|
|
b469ce2a69 | ||
|
|
6f7823e8cb | ||
|
|
2619a4398d | ||
|
|
d411fe44fe | ||
|
|
67af517510 | ||
|
|
cce862bc57 | ||
|
|
319750e3f9 | ||
|
|
78ccd8b2d5 | ||
|
|
50ef62f4fb | ||
|
|
05a5b5284b | ||
|
|
8c6865405d | ||
|
|
a204b5d521 | ||
|
|
da0128b330 | ||
|
|
84b005a3b0 | ||
|
|
38fd7eae6d | ||
|
|
e3d08fa0de | ||
|
|
0da59c3585 | ||
|
|
b4145fda44 | ||
|
|
5df58a116d | ||
|
|
7899d8cb46 | ||
|
|
b47e0f20ef | ||
|
|
63a7121653 | ||
|
|
7927c89ba2 | ||
|
|
db5c97a324 | ||
|
|
d4b919430f | ||
|
|
d52df749fa | ||
|
|
63eac8f0f6 | ||
|
|
0d7a618d87 | ||
|
|
7a8d440475 | ||
|
|
89b63802ac | ||
|
|
17e8b51205 | ||
|
|
8bb12b6913 | ||
|
|
8a194d1ff6 | ||
|
|
45bc1e3d80 | ||
|
|
a812e22312 | ||
|
|
b7c9015b39 | ||
|
|
98c7c0d49c | ||
|
|
dc10e3cca6 | ||
|
|
54ae21fd5d | ||
|
|
5d851e849a | ||
|
|
09ef7c2e80 | ||
|
|
e8d7fc30a5 | ||
|
|
5fbb6d7349 | ||
|
|
28b67601c1 | ||
|
|
ba02780727 | ||
|
|
2c756925a1 | ||
|
|
ac37b708c0 | ||
|
|
6b92403dea | ||
|
|
f63da3d3d2 | ||
|
|
de763c948c | ||
|
|
4469b93ed9 | ||
|
|
873c09d224 | ||
|
|
646b0a1050 | ||
|
|
470975ca77 | ||
|
|
2005daa11f | ||
|
|
e28f4e3993 | ||
|
|
f9390aa69d | ||
|
|
3f6bb1a03d | ||
|
|
911dffccc2 | ||
|
|
3368b7fcc5 | ||
|
|
ea273ba4b6 | ||
|
|
f3b14030b1 |
No files matched your search
@@ -11,44 +11,51 @@ jobs:
|
||||
packages: write
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up JDK 8
|
||||
uses: actions/setup-java@v2
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
java-version: '8'
|
||||
java-version: '17'
|
||||
distribution: 'adopt'
|
||||
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
|
||||
settings-path: ${{ github.workspace }} # location for the settings.xml file
|
||||
|
||||
- name: Build with Gradle
|
||||
run: gradle shadowJar
|
||||
run: chmod +x gradlew && ./gradlew build
|
||||
|
||||
- name: Upload build artifacts api
|
||||
uses: actions/upload-artifact@v1
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: api-build
|
||||
path: api/build/libs
|
||||
|
||||
- name: Upload build artifacts spigot
|
||||
uses: actions/upload-artifact@v1
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: spigot-build
|
||||
path: spigot/build/libs
|
||||
|
||||
- name: Upload build artifacts netty-common
|
||||
uses: actions/upload-artifact@v1
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: netty-common-build
|
||||
path: netty-common/build/libs
|
||||
|
||||
- name: Upload build artifacts bungeecord
|
||||
uses: actions/upload-artifact@v1
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: bungeecord-build
|
||||
path: bungeecord/build/libs
|
||||
|
||||
- name: Upload build artifacts velocity
|
||||
uses: actions/upload-artifact@v1
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: velocity-build
|
||||
path: velocity/build/libs
|
||||
path: velocity/build/libs
|
||||
|
||||
- name: Upload build artifacts fabric
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: fabric-build
|
||||
path: fabric/build/libs
|
||||
@@ -102,6 +102,7 @@ $RECYCLE.BIN/
|
||||
|
||||
.gradle
|
||||
build/
|
||||
bin/
|
||||
|
||||
# Ignore Gradle GUI config
|
||||
gradle-app.setting
|
||||
@@ -118,3 +119,7 @@ run/
|
||||
!gradle-wrapper.jar
|
||||
/src/main/resources/plugin.yml
|
||||
/.idea/
|
||||
.vscode/
|
||||
.project
|
||||
.settings/
|
||||
.classpath
|
||||
@@ -1,15 +1,20 @@
|
||||
# packetevents
|
||||
|
||||
[](https://jitpack.io/#retrooper/packetevents)
|
||||
[](https://github.com/retrooper/packetevents/blob/2.0/LICENSE) [](https://github.com/retrooper/packetevents/actions) [](https://discord.gg/prqzNg9tRU)
|
||||
|
||||
PacketEvents is a powerful packet library. Our packet wrappers are efficient and easy to use. With our API, you can write code that runs on many platforms including Spigot, BungeeCord, Velocity, and even client-sided Fabric! Switch to PacketEvents today by joining \
|
||||
PacketEvents is a fast and efficient multi-platform packet processing library. Our packet wrappers are easy to use with multi-version support. With our API you can write code that runs on Spigot, BungeeCord, Velocity, and Fabric! Switch to PacketEvents today by joining \
|
||||
our [Discord Server](https://discord.me/packetevents) for help.
|
||||
|
||||
### Links
|
||||
* [Find release builds on SpigotMC](https://www.spigotmc.org/resources/packetevents-api.80279/)
|
||||
* [Find release builds on Modrinth](https://modrinth.com/plugin/packetevents)
|
||||
* [Find development builds on Jenkins](https://ci.codemc.io/job/retrooper/job/packetevents)
|
||||
* [View documentation on our JavaDocs Page](https://packetevents.github.io/javadocs)
|
||||
|
||||
### Setup
|
||||
[Learn more](https://github.com/retrooper/packetevents/wiki/Setup-2.0)
|
||||
[How to Setup PacketEvents](https://github.com/retrooper/packetevents/wiki/Depending-on-pre%E2%80%90built-PacketEvents)
|
||||
|
||||
### Examples / How to use PacketEvents
|
||||
[Example repository](https://github.com/retrooper/packetevents-example)
|
||||
|
||||
### Sponsorships
|
||||
[](https://www.ej-technologies.com/products/jprofiler/overview.html)
|
||||
@@ -18,15 +23,6 @@ our [Discord Server](https://discord.me/packetevents) for help.
|
||||
PacketEvents optionally collects statistics using [bStats](https://bstats.org/)\
|
||||
Check out our [bStats page](https://bstats.org/plugin/bukkit/packetevents/11327)
|
||||
|
||||
This library is licensed under the GPLv3 (General Public License version 3). Here are a few sources to learn more about the license.\
|
||||
[](https://github.com/retrooper/packetevents/blob/2.0/LICENSE)
|
||||
### GPL Resources
|
||||
* https://www.gnu.org/philosophy/free-sw.html
|
||||
* https://www.gnu.org/philosophy/free-sw.html#clarifying
|
||||
* https://www.gnu.org/licenses/copyleft.en.html
|
||||
* https://www.gnu.org/licenses/quick-guide-gplv3.html
|
||||
* https://gpl-violations.org/faq/sourcecode-faq/
|
||||
|
||||
### Credit to these projects
|
||||
[wiki.vg/Protocol](https://wiki.vg/Protocol)\
|
||||
[netty](https://github.com/netty/netty)\
|
||||
|
||||
+58
-1
@@ -1,3 +1,60 @@
|
||||
import com.github.retrooper.MappingCompressionTask
|
||||
|
||||
// papermc repo + disableAutoTargetJvm needed for mockbukkit
|
||||
repositories {
|
||||
maven { url 'https://repo.papermc.io/repository/maven-public/' }
|
||||
}
|
||||
|
||||
java {
|
||||
disableAutoTargetJvm()
|
||||
sourceSets {
|
||||
main {
|
||||
resources {
|
||||
srcDirs += ["$buildDir.canonicalPath/mappings/generated"]
|
||||
}
|
||||
}
|
||||
|
||||
test {
|
||||
resources {
|
||||
srcDirs += ["$buildDir.canonicalPath/mappings/generated"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly(adventureDependencies)
|
||||
}
|
||||
|
||||
testImplementation(adventureDependencies)
|
||||
testImplementation(project(":netty-common"))
|
||||
testImplementation("com.github.seeseemelk:MockBukkit-v1.20:3.9.0")
|
||||
testImplementation("org.slf4j:slf4j-simple:2.0.7")
|
||||
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.0")
|
||||
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.10.0")
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
task generateMapping(type: MappingCompressionTask) {
|
||||
mappingsDir = rootDir.toPath().resolve("mappings")
|
||||
outDir = project.buildDir.toPath().resolve("mappings/generated/assets/mappings")
|
||||
outputs.upToDateWhen {
|
||||
def gen_modified = project.buildDir.toPath().resolve("mappings/generated/assets/mappings").toFile().lastModified()
|
||||
def list = []
|
||||
project.rootProject.projectDir.toPath().resolve("mappings").toFile().eachFileRecurse(groovy.io.FileType.FILES) { file ->
|
||||
list << file
|
||||
}
|
||||
|
||||
for (File file : list) {
|
||||
if (file.lastModified() > gen_modified) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
tasks.processResources.dependsOn(generateMapping)
|
||||
@@ -18,20 +18,15 @@
|
||||
|
||||
package com.github.retrooper.packetevents;
|
||||
|
||||
import com.github.retrooper.packetevents.injector.ChannelInjector;
|
||||
import com.github.retrooper.packetevents.manager.player.PlayerManager;
|
||||
import com.github.retrooper.packetevents.manager.protocol.ProtocolManager;
|
||||
import com.github.retrooper.packetevents.manager.server.ServerManager;
|
||||
import com.github.retrooper.packetevents.netty.NettyManager;
|
||||
import com.github.retrooper.packetevents.settings.PacketEventsSettings;
|
||||
import com.github.retrooper.packetevents.util.LogManager;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
public final class PacketEvents {
|
||||
private static PacketEventsAPI<?> API;
|
||||
|
||||
//Put these variable names anywhere else, they are really only for the injectors
|
||||
@ApiStatus.Internal
|
||||
public static String IDENTIFIER, ENCODER_NAME, DECODER_NAME, CONNECTION_HANDLER_NAME, SERVER_CHANNEL_HANDLER_NAME,
|
||||
TIMEOUT_HANDLER_NAME;
|
||||
TIMEOUT_HANDLER_NAME;
|
||||
|
||||
public static PacketEventsAPI<?> getAPI() {
|
||||
return API;
|
||||
@@ -40,87 +35,4 @@ public final class PacketEvents {
|
||||
public static void setAPI(PacketEventsAPI<?> api) {
|
||||
API = api;
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public abstract static class Context<T> {
|
||||
private final Object pluginInstance;
|
||||
private final ProtocolManager protocolManager;
|
||||
private final ServerManager serverManager;
|
||||
private final PlayerManager playerManager;
|
||||
private final NettyManager nettyManager;
|
||||
private final ChannelInjector injector;
|
||||
private final LogManager logManager;
|
||||
protected boolean lateBind = false;
|
||||
|
||||
public Context(Object pluginInstance, ProtocolManager protocolManager, ServerManager serverManager, PlayerManager playerManager,
|
||||
NettyManager nettyManager, ChannelInjector injector, LogManager logManager) {
|
||||
this.pluginInstance = pluginInstance;
|
||||
this.protocolManager = protocolManager;
|
||||
this.serverManager = serverManager;
|
||||
this.playerManager = playerManager;
|
||||
this.nettyManager = nettyManager;
|
||||
this.injector = injector;
|
||||
this.logManager = logManager;
|
||||
}
|
||||
|
||||
protected abstract PacketEventsAPI<T> build();
|
||||
|
||||
public Object getPluginInstance() {
|
||||
return pluginInstance;
|
||||
}
|
||||
|
||||
public ProtocolManager getProtocolManager() {
|
||||
return protocolManager;
|
||||
}
|
||||
|
||||
public ServerManager getServerManager() {
|
||||
return serverManager;
|
||||
}
|
||||
|
||||
public PlayerManager getPlayerManager() {
|
||||
return playerManager;
|
||||
}
|
||||
|
||||
public NettyManager getNettyManager() {
|
||||
return nettyManager;
|
||||
}
|
||||
|
||||
public ChannelInjector getInjector() {
|
||||
return injector;
|
||||
}
|
||||
|
||||
public LogManager getLogManager() {
|
||||
return logManager;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private Context<?> context = null;
|
||||
private PacketEventsSettings settings = new PacketEventsSettings();
|
||||
public Builder context(Context<?> context) {
|
||||
this.context = context;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder settings(PacketEventsSettings settings) {
|
||||
this.settings = settings;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PacketEventsAPI<?> build() {
|
||||
if (context == null) {
|
||||
throw new IllegalStateException("Failed to build a PacketEvents instance. Please specify a PacketEvents context in the PacketEvents builder to allow PacketEvents to load the correct implementation.");
|
||||
}
|
||||
PacketEventsAPI<?> api = context.build();
|
||||
api.setSettings(settings);
|
||||
//The implementation may have already set the API.
|
||||
if (getAPI() == null) {
|
||||
setAPI(api);
|
||||
}
|
||||
return api;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,23 +33,19 @@ import java.util.logging.Logger;
|
||||
|
||||
public abstract class PacketEventsAPI<T> {
|
||||
private static final EventManager EVENT_MANAGER = new EventManager();
|
||||
private static final PacketEventsSettings SETTINGS = new PacketEventsSettings();
|
||||
private static final UpdateChecker UPDATE_CHECKER = new UpdateChecker();
|
||||
private static final LogManager LOG_MANAGER = new LogManager();
|
||||
private final Logger LOGGER = Logger.getLogger(PacketEventsAPI.class.getName());
|
||||
private PacketEventsSettings settings = new PacketEventsSettings();
|
||||
private static final LogManager LOG_MANAGER = new LogManager();
|
||||
//TODO UPDATE
|
||||
private static final PEVersion VERSION = new PEVersion(2, 0, 0);
|
||||
private static final PEVersion VERSION = new PEVersion(2, 3, 0);
|
||||
|
||||
public EventManager getEventManager() {
|
||||
return EVENT_MANAGER;
|
||||
}
|
||||
|
||||
public PacketEventsSettings getSettings() {
|
||||
return settings;
|
||||
}
|
||||
|
||||
public void setSettings(PacketEventsSettings settings) {
|
||||
this.settings = settings;
|
||||
return SETTINGS;
|
||||
}
|
||||
|
||||
public UpdateChecker getUpdateChecker() {
|
||||
|
||||
@@ -19,15 +19,16 @@
|
||||
package com.github.retrooper.packetevents.event;
|
||||
|
||||
import com.github.retrooper.packetevents.PacketEvents;
|
||||
import com.github.retrooper.packetevents.exception.InvalidHandshakeException;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class EventManager {
|
||||
private final Map<Byte, HashSet<PacketListenerCommon>> listenersMap = new ConcurrentHashMap<>();
|
||||
private final Map<PacketListenerPriority, Set<PacketListenerCommon>> listenersMap =
|
||||
Collections.synchronizedMap(new EnumMap<>(PacketListenerPriority.class));
|
||||
|
||||
/**
|
||||
* Call the PacketEvent.
|
||||
@@ -43,14 +44,17 @@ public class EventManager {
|
||||
}
|
||||
|
||||
public void callEvent(PacketEvent event, @Nullable Runnable postCallListenerAction) {
|
||||
for (byte priority = PacketListenerPriority.LOWEST.getId(); priority <= PacketListenerPriority.MONITOR.getId(); priority++) {
|
||||
HashSet<PacketListenerCommon> listeners = listenersMap.get(priority);
|
||||
for (PacketListenerPriority priority : PacketListenerPriority.values()) {
|
||||
Set<PacketListenerCommon> listeners = listenersMap.get(priority);
|
||||
if (listeners != null) {
|
||||
for (PacketListenerCommon listener : listeners) {
|
||||
try {
|
||||
event.call(listener);
|
||||
} catch (Throwable t) {
|
||||
PacketEvents.getAPI().getLogger().log(Level.WARNING, "PacketEvents caught an unhandled exception while calling your listener.", t);
|
||||
} catch (Exception t) {
|
||||
// ignore handshake exceptions
|
||||
if (t.getClass() != InvalidHandshakeException.class) {
|
||||
PacketEvents.getAPI().getLogger().log(Level.WARNING, "PacketEvents caught an unhandled exception while calling your listener.", t);
|
||||
}
|
||||
}
|
||||
if (postCallListenerAction != null) {
|
||||
postCallListenerAction.run();
|
||||
@@ -58,7 +62,8 @@ public class EventManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (event instanceof ProtocolPacketEvent && PacketEvents.getAPI().getSettings().shouldListenersReadOnly()) {
|
||||
// For performance reasons, we don't want to re-encode the packet if it's not needed.
|
||||
if (event instanceof ProtocolPacketEvent && !((ProtocolPacketEvent<?>) event).needsReEncode()) {
|
||||
((ProtocolPacketEvent<?>) event).setLastUsedWrapper(null);
|
||||
}
|
||||
|
||||
@@ -75,13 +80,12 @@ public class EventManager {
|
||||
* @param listener {@link PacketListenerCommon}
|
||||
*/
|
||||
public PacketListenerCommon registerListener(PacketListenerCommon listener) {
|
||||
byte priority = listener.getPriority().getId();
|
||||
HashSet<PacketListenerCommon> listenerSet = listenersMap.get(priority);
|
||||
Set<PacketListenerCommon> listenerSet = listenersMap.get(listener.getPriority());
|
||||
if (listenerSet == null) {
|
||||
listenerSet = new HashSet<>();
|
||||
listenerSet = ConcurrentHashMap.newKeySet();
|
||||
}
|
||||
listenerSet.add(listener);
|
||||
listenersMap.put(priority, listenerSet);
|
||||
listenersMap.put(listener.getPriority(), listenerSet);
|
||||
return listener;
|
||||
}
|
||||
|
||||
@@ -98,7 +102,7 @@ public class EventManager {
|
||||
}
|
||||
|
||||
public void unregisterListener(PacketListenerCommon listener) {
|
||||
HashSet<PacketListenerCommon> listenerSet = listenersMap.get(listener.getPriority().getId());
|
||||
Set<PacketListenerCommon> listenerSet = listenersMap.get(listener.getPriority());
|
||||
if (listenerSet == null) return;
|
||||
listenerSet.remove(listener);
|
||||
}
|
||||
|
||||
@@ -47,20 +47,13 @@ public class PacketReceiveEvent extends ProtocolPacketEvent<Object> {
|
||||
|
||||
@Override
|
||||
public PacketReceiveEvent clone() {
|
||||
if (this instanceof PacketHandshakeReceiveEvent) {
|
||||
return ((PacketHandshakeReceiveEvent)this).clone();
|
||||
}
|
||||
else if (this instanceof PacketStatusReceiveEvent) {
|
||||
return ((PacketStatusReceiveEvent)this).clone();
|
||||
}
|
||||
else if (this instanceof PacketLoginReceiveEvent) {
|
||||
return ((PacketLoginReceiveEvent)this).clone();
|
||||
}
|
||||
else if (this instanceof PacketPlayReceiveEvent) {
|
||||
return ((PacketPlayReceiveEvent)this).clone();
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
try {
|
||||
Object clonedBuffer = ByteBufHelper.retainedDuplicate(getByteBuf());
|
||||
return new PacketReceiveEvent(getPacketId(), getPacketType(), getServerVersion(),
|
||||
getChannel(), getUser(), getPlayer(), clonedBuffer);
|
||||
} catch (PacketProcessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -18,9 +18,7 @@
|
||||
|
||||
package com.github.retrooper.packetevents.event;
|
||||
|
||||
import com.github.retrooper.packetevents.event.simple.PacketLoginSendEvent;
|
||||
import com.github.retrooper.packetevents.event.simple.PacketPlaySendEvent;
|
||||
import com.github.retrooper.packetevents.event.simple.PacketStatusSendEvent;
|
||||
import com.github.retrooper.packetevents.event.simple.PacketHandshakeSendEvent;
|
||||
import com.github.retrooper.packetevents.exception.PacketProcessException;
|
||||
import com.github.retrooper.packetevents.manager.server.ServerVersion;
|
||||
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
|
||||
@@ -28,7 +26,12 @@ import com.github.retrooper.packetevents.protocol.PacketSide;
|
||||
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
|
||||
import com.github.retrooper.packetevents.protocol.player.User;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PacketSendEvent extends ProtocolPacketEvent<Object> {
|
||||
private List<Runnable> tasksAfterSend = null;
|
||||
|
||||
protected PacketSendEvent(Object channel, User user, Object player, Object rawByteBuf,
|
||||
boolean autoProtocolTranslation) throws PacketProcessException {
|
||||
super(PacketSide.SERVER, channel, user, player, rawByteBuf, autoProtocolTranslation);
|
||||
@@ -48,19 +51,27 @@ public class PacketSendEvent extends ProtocolPacketEvent<Object> {
|
||||
listener.onPacketSend(this);
|
||||
}
|
||||
|
||||
|
||||
public List<Runnable> getTasksAfterSend() {
|
||||
if (tasksAfterSend == null) {
|
||||
tasksAfterSend = new ArrayList<>();
|
||||
}
|
||||
return tasksAfterSend;
|
||||
}
|
||||
|
||||
public boolean hasTasksAfterSend() {
|
||||
return tasksAfterSend != null && !tasksAfterSend.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketSendEvent clone() {
|
||||
if (this instanceof PacketStatusSendEvent) {
|
||||
return ((PacketStatusSendEvent)this).clone();
|
||||
}
|
||||
else if (this instanceof PacketLoginSendEvent) {
|
||||
return ((PacketLoginSendEvent)this).clone();
|
||||
}
|
||||
else if (this instanceof PacketPlaySendEvent) {
|
||||
return ((PacketPlaySendEvent)this).clone();
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
try {
|
||||
Object clonedBuffer = ByteBufHelper.retainedDuplicate(getByteBuf());
|
||||
return new PacketSendEvent(getPacketId(), getPacketType(), getServerVersion(),
|
||||
getChannel(), getUser(), getPlayer(), clonedBuffer);
|
||||
} catch (PacketProcessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@
|
||||
package com.github.retrooper.packetevents.event;
|
||||
|
||||
import com.github.retrooper.packetevents.PacketEvents;
|
||||
import com.github.retrooper.packetevents.exception.InvalidDisconnectPacketSend;
|
||||
import com.github.retrooper.packetevents.exception.PacketProcessException;
|
||||
import com.github.retrooper.packetevents.manager.server.ServerVersion;
|
||||
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
|
||||
@@ -51,6 +52,7 @@ public abstract class ProtocolPacketEvent<T> extends PacketEvent implements Play
|
||||
private PacketWrapper<?> lastUsedWrapper;
|
||||
private List<Runnable> postTasks = null;
|
||||
private boolean cloned;
|
||||
private boolean needsReEncode = PacketEvents.getAPI().getSettings().reEncodeByDefault();
|
||||
|
||||
public ProtocolPacketEvent(PacketSide packetSide, Object channel,
|
||||
User user, T player, Object byteBuf,
|
||||
@@ -76,12 +78,17 @@ public abstract class ProtocolPacketEvent<T> extends PacketEvent implements Play
|
||||
throw new PacketProcessException("Failed to read the Packet ID of a packet. (Size: " + size + ")");
|
||||
}
|
||||
ClientVersion version = serverVersion.toClientVersion();
|
||||
this.packetType = PacketType.getById(packetSide, user.getConnectionState(),
|
||||
ConnectionState state = packetSide == PacketSide.CLIENT ? user.getDecoderState() : user.getEncoderState();
|
||||
this.packetType = PacketType.getById(packetSide, state,
|
||||
version, packetID);
|
||||
if (this.packetType == null) {
|
||||
throw new PacketProcessException("Failed to map the Packet ID " + packetID + " to a PacketType constant. Bound: " + packetSide.getOpposite() + ", Connection state: " + user.getConnectionState() + ", Server version: " + serverVersion.getReleaseName());
|
||||
// mojang messed up and keeps sending disconnect packets in the wrong protocol state
|
||||
if (PacketType.getById(packetSide, ConnectionState.PLAY, version, packetID) == PacketType.Play.Server.DISCONNECT) {
|
||||
throw new InvalidDisconnectPacketSend();
|
||||
}
|
||||
throw new PacketProcessException("Failed to map the Packet ID " + packetID + " to a PacketType constant. Bound: " + packetSide.getOpposite() + ", Connection state: " + user.getDecoderState() + ", Server version: " + serverVersion.getReleaseName());
|
||||
}
|
||||
this.connectionState = user.getConnectionState();
|
||||
this.connectionState = state;
|
||||
}
|
||||
|
||||
public ProtocolPacketEvent(int packetID, PacketTypeCommon packetType, ServerVersion serverVersion, Object channel,
|
||||
@@ -93,10 +100,21 @@ public abstract class ProtocolPacketEvent<T> extends PacketEvent implements Play
|
||||
this.byteBuf = byteBuf;
|
||||
this.packetID = packetID;
|
||||
this.packetType = packetType;
|
||||
this.connectionState = user.getConnectionState();
|
||||
|
||||
this.connectionState = (packetType != null && packetType.getSide() == PacketSide.SERVER)
|
||||
? user.getEncoderState() : user.getDecoderState();
|
||||
cloned = true;
|
||||
}
|
||||
|
||||
public void markForReEncode(boolean needsReEncode) {
|
||||
this.needsReEncode = needsReEncode;
|
||||
}
|
||||
|
||||
public boolean needsReEncode() {
|
||||
return needsReEncode;
|
||||
}
|
||||
|
||||
|
||||
public boolean isClone() {
|
||||
return cloned;
|
||||
}
|
||||
@@ -151,7 +169,6 @@ public abstract class ProtocolPacketEvent<T> extends PacketEvent implements Play
|
||||
this.byteBuf = byteBuf;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public int getPacketId() {
|
||||
return packetID;
|
||||
}
|
||||
|
||||
+16
-2
@@ -41,7 +41,11 @@ public abstract class SimplePacketListenerAbstract extends PacketListenerCommon
|
||||
onPacketStatusReceive((PacketStatusReceiveEvent) event);
|
||||
} else if (event instanceof PacketLoginReceiveEvent) {
|
||||
onPacketLoginReceive((PacketLoginReceiveEvent) event);
|
||||
} else if (event instanceof PacketPlayReceiveEvent) {
|
||||
}
|
||||
else if (event instanceof PacketConfigReceiveEvent) {
|
||||
onPacketConfigReceive((PacketConfigReceiveEvent) event);
|
||||
}
|
||||
else if (event instanceof PacketPlayReceiveEvent) {
|
||||
onPacketPlayReceive((PacketPlayReceiveEvent) event);
|
||||
}
|
||||
}
|
||||
@@ -52,7 +56,11 @@ public abstract class SimplePacketListenerAbstract extends PacketListenerCommon
|
||||
onPacketStatusSend((PacketStatusSendEvent) event);
|
||||
} else if (event instanceof PacketLoginSendEvent) {
|
||||
onPacketLoginSend((PacketLoginSendEvent) event);
|
||||
} else if (event instanceof PacketPlaySendEvent) {
|
||||
}
|
||||
else if (event instanceof PacketConfigSendEvent) {
|
||||
onPacketConfigSend((PacketConfigSendEvent) event);
|
||||
}
|
||||
else if (event instanceof PacketPlaySendEvent) {
|
||||
onPacketPlaySend((PacketPlaySendEvent) event);
|
||||
}
|
||||
}
|
||||
@@ -72,6 +80,12 @@ public abstract class SimplePacketListenerAbstract extends PacketListenerCommon
|
||||
public void onPacketLoginSend(PacketLoginSendEvent event) {
|
||||
}
|
||||
|
||||
public void onPacketConfigReceive(PacketConfigReceiveEvent event) {
|
||||
}
|
||||
|
||||
public void onPacketConfigSend(PacketConfigSendEvent event) {
|
||||
}
|
||||
|
||||
public void onPacketPlayReceive(PacketPlayReceiveEvent event) {
|
||||
}
|
||||
|
||||
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.event.simple;
|
||||
|
||||
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
|
||||
import com.github.retrooper.packetevents.exception.PacketProcessException;
|
||||
import com.github.retrooper.packetevents.manager.server.ServerVersion;
|
||||
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
|
||||
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
|
||||
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
|
||||
import com.github.retrooper.packetevents.protocol.player.User;
|
||||
|
||||
public class PacketConfigReceiveEvent extends PacketReceiveEvent {
|
||||
|
||||
public PacketConfigReceiveEvent(Object channel, User user,
|
||||
Object player, Object rawByteBuf,
|
||||
boolean autoProtocolTranslation) throws PacketProcessException {
|
||||
super(channel, user, player, rawByteBuf, autoProtocolTranslation);
|
||||
}
|
||||
|
||||
protected PacketConfigReceiveEvent(int packetId, PacketTypeCommon packetType,
|
||||
ServerVersion serverVersion,
|
||||
Object channel,
|
||||
User user, Object player, Object byteBuf) throws PacketProcessException {
|
||||
super(packetId, packetType, serverVersion, channel, user, player, byteBuf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketConfigReceiveEvent clone() {
|
||||
try {
|
||||
Object clonedBuffer = ByteBufHelper.retainedDuplicate(getByteBuf());
|
||||
return new PacketConfigReceiveEvent(getPacketId(), getPacketType(), getServerVersion(),
|
||||
getChannel(), getUser(), getPlayer(), clonedBuffer);
|
||||
} catch (PacketProcessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public PacketType.Configuration.Client getPacketType() {
|
||||
return (PacketType.Configuration.Client) super.getPacketType();
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.event.simple;
|
||||
|
||||
import com.github.retrooper.packetevents.event.PacketSendEvent;
|
||||
import com.github.retrooper.packetevents.exception.PacketProcessException;
|
||||
import com.github.retrooper.packetevents.manager.server.ServerVersion;
|
||||
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
|
||||
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
|
||||
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
|
||||
import com.github.retrooper.packetevents.protocol.player.User;
|
||||
|
||||
public class PacketConfigSendEvent extends PacketSendEvent {
|
||||
|
||||
public PacketConfigSendEvent(Object channel, User user,
|
||||
Object player, Object rawByteBuf,
|
||||
boolean autoProtocolTranslation) throws PacketProcessException {
|
||||
super(channel, user, player, rawByteBuf, autoProtocolTranslation);
|
||||
}
|
||||
|
||||
protected PacketConfigSendEvent(int packetId, PacketTypeCommon packetType,
|
||||
ServerVersion serverVersion,
|
||||
Object channel,
|
||||
User user, Object player, Object byteBuf) throws PacketProcessException {
|
||||
super(packetId, packetType, serverVersion, channel, user, player, byteBuf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketConfigSendEvent clone() {
|
||||
try {
|
||||
Object clonedBuffer = ByteBufHelper.retainedDuplicate(getByteBuf());
|
||||
return new PacketConfigSendEvent(getPacketId(), getPacketType(), getServerVersion(),
|
||||
getChannel(), getUser(), getPlayer(), clonedBuffer);
|
||||
} catch (PacketProcessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public PacketType.Configuration.Server getPacketType() {
|
||||
return (PacketType.Configuration.Server) super.getPacketType();
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package com.github.retrooper.packetevents.exception;
|
||||
|
||||
public class CancelPacketException extends RuntimeException {
|
||||
public static final CancelPacketException INSTANCE = new CancelPacketException();
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package com.github.retrooper.packetevents.exception;
|
||||
|
||||
public class InvalidDisconnectPacketSend extends RuntimeException {
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package com.github.retrooper.packetevents.exception;
|
||||
|
||||
public class InvalidHandshakeException extends RuntimeException {
|
||||
}
|
||||
+1
-1
@@ -18,7 +18,7 @@
|
||||
|
||||
package com.github.retrooper.packetevents.exception;
|
||||
|
||||
public class PacketProcessException extends Exception {
|
||||
public class PacketProcessException extends RuntimeException {
|
||||
public PacketProcessException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
|
||||
@@ -18,9 +18,7 @@
|
||||
|
||||
package com.github.retrooper.packetevents.injector;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.ConnectionState;
|
||||
import com.github.retrooper.packetevents.protocol.player.User;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface ChannelInjector {
|
||||
default boolean isServerBound() {
|
||||
@@ -31,13 +29,9 @@ public interface ChannelInjector {
|
||||
|
||||
void uninject();
|
||||
|
||||
User getUser(Object channel);
|
||||
|
||||
void changeConnectionState(Object channel, @Nullable ConnectionState connectionState);
|
||||
|
||||
void updateUser(Object channel, User user);
|
||||
|
||||
void setPlayer(Object channel, Object player);
|
||||
|
||||
boolean hasPlayer(Object player);
|
||||
boolean isProxy();
|
||||
}
|
||||
+78
-27
@@ -27,20 +27,30 @@ import com.github.retrooper.packetevents.manager.protocol.ProtocolManager;
|
||||
import com.github.retrooper.packetevents.manager.server.ServerVersion;
|
||||
import com.github.retrooper.packetevents.protocol.ConnectionState;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTInt;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTList;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTString;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTType;
|
||||
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
|
||||
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
import com.github.retrooper.packetevents.protocol.player.User;
|
||||
import com.github.retrooper.packetevents.protocol.player.UserProfile;
|
||||
import com.github.retrooper.packetevents.resources.ResourceLocation;
|
||||
import com.github.retrooper.packetevents.wrapper.configuration.server.WrapperConfigServerRegistryData;
|
||||
import com.github.retrooper.packetevents.wrapper.configuration.server.WrapperConfigServerRegistryData.RegistryElement;
|
||||
import com.github.retrooper.packetevents.wrapper.handshaking.client.WrapperHandshakingClientHandshake;
|
||||
import com.github.retrooper.packetevents.wrapper.login.server.WrapperLoginServerLoginSuccess;
|
||||
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerJoinGame;
|
||||
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerRespawn;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.List;
|
||||
|
||||
public class InternalPacketListener extends PacketListenerAbstract {
|
||||
|
||||
private static final ResourceLocation DIMENSION_TYPE_REGISTRY_KEY =
|
||||
ResourceLocation.minecraft("dimension_type");
|
||||
|
||||
public InternalPacketListener() {
|
||||
this(PacketListenerPriority.LOWEST);
|
||||
}
|
||||
@@ -71,44 +81,85 @@ public class InternalPacketListener extends PacketListenerAbstract {
|
||||
|
||||
PacketEvents.getAPI().getLogManager().debug("Mapped player UUID with their channel.");
|
||||
|
||||
//Update connection state(injectors might do some adjustments when we transition into PLAY state)
|
||||
//This also updates it for the user instance
|
||||
event.getPostTasks().add(() -> {
|
||||
PacketEvents.getAPI().getInjector().changeConnectionState(channel, ConnectionState.PLAY);
|
||||
PacketEvents.getAPI().getLogManager().debug("Transitioned " + profile.getName() + " into the PLAY state!");
|
||||
});
|
||||
// Switch the user's connection state to new state, but the variable event.getConnectionState() remains LOGIN
|
||||
// We switch user state immediately to remain in sync with vanilla, allowing you to encode packets immediately
|
||||
boolean proxy = PacketEvents.getAPI().getInjector().isProxy();
|
||||
if (proxy ? event.getUser().getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_20_2)
|
||||
: event.getServerVersion().isNewerThanOrEquals(ServerVersion.V_1_20_2)) {
|
||||
user.setEncoderState(ConnectionState.CONFIGURATION);
|
||||
} else {
|
||||
user.setConnectionState(ConnectionState.PLAY);
|
||||
}
|
||||
}
|
||||
|
||||
// Join game can be used to update world height, and sets dimension data
|
||||
// The server sends dimension information in configuration phase >= 1.20.2
|
||||
else if (event.getPacketType() == PacketType.Configuration.Server.REGISTRY_DATA) {
|
||||
WrapperConfigServerRegistryData registryData = new WrapperConfigServerRegistryData(event);
|
||||
|
||||
// Store world data
|
||||
NBTCompound registryDataTag = registryData.getRegistryData();
|
||||
NBTList<NBTCompound> list = null;
|
||||
if (registryDataTag != null) { // <1.20.5
|
||||
list = registryDataTag
|
||||
.getCompoundTagOrNull(DIMENSION_TYPE_REGISTRY_KEY.toString())
|
||||
.getCompoundListTagOrNull("value");
|
||||
} else if (DIMENSION_TYPE_REGISTRY_KEY.equals(registryData.getRegistryKey())) { // >=1.20.5
|
||||
// remap to legacy format
|
||||
list = new NBTList<>(NBTType.COMPOUND);
|
||||
List<RegistryElement> elements = registryData.getElements();
|
||||
if (elements != null) {
|
||||
int i = 0;
|
||||
for (RegistryElement element : elements) {
|
||||
NBTCompound tag = new NBTCompound();
|
||||
tag.setTag("name", new NBTString(element.getId().toString()));
|
||||
tag.setTag("id", new NBTInt(i++));
|
||||
if (element.getData() != null) { // may be null because of known packs not being sent
|
||||
tag.setTag("element", element.getData());
|
||||
}
|
||||
list.addTag(tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (list != null) {
|
||||
user.setWorldNBT(list);
|
||||
}
|
||||
}
|
||||
|
||||
// The server sends dimension information in login packet for >= 1.17 and < 1.20.2
|
||||
else if (event.getPacketType() == PacketType.Play.Server.JOIN_GAME) {
|
||||
WrapperPlayServerJoinGame joinGame = new WrapperPlayServerJoinGame(event);
|
||||
user.setEntityId(joinGame.getEntityId());
|
||||
user.setDimension(joinGame.getDimension());
|
||||
if (event.getServerVersion().isOlderThanOrEquals(ServerVersion.V_1_16_5)) {
|
||||
return; // Fixed world height, no tags are sent to the client
|
||||
}
|
||||
|
||||
// Store world height
|
||||
NBTList<NBTCompound> list = joinGame.getDimensionCodec().getCompoundTagOrNull("minecraft:dimension_type").getCompoundListTagOrNull("value");
|
||||
user.setWorldNBT(list);
|
||||
// Store world data
|
||||
NBTCompound dimensionCodec = joinGame.getDimensionCodec();
|
||||
if (dimensionCodec != null) {
|
||||
NBTList<NBTCompound> list = dimensionCodec
|
||||
.getCompoundTagOrNull(DIMENSION_TYPE_REGISTRY_KEY.toString())
|
||||
.getCompoundListTagOrNull("value");
|
||||
user.setWorldNBT(list);
|
||||
}
|
||||
|
||||
// Update world height
|
||||
NBTCompound worldNBT = user.getWorldNBT(joinGame.getDimension().getDimensionName()).getCompoundTagOrNull("element");
|
||||
user.setMinWorldHeight(worldNBT.getNumberTagOrNull("min_y").getAsInt());
|
||||
user.setTotalWorldHeight(worldNBT.getNumberTagOrNull("height").getAsInt());
|
||||
user.switchDimensionType(joinGame.getServerVersion(), joinGame.getDimension());
|
||||
}
|
||||
|
||||
// Respawn is used to switch dimensions
|
||||
else if (event.getPacketType() == PacketType.Play.Server.RESPAWN) {
|
||||
WrapperPlayServerRespawn respawn = new WrapperPlayServerRespawn(event);
|
||||
user.setDimension(respawn.getDimension());
|
||||
if (event.getServerVersion().isOlderThanOrEquals(ServerVersion.V_1_16_5)) {
|
||||
return; // Fixed world height, no tags are sent to the client
|
||||
}
|
||||
|
||||
WrapperPlayServerRespawn respawn = new WrapperPlayServerRespawn(event);
|
||||
|
||||
NBTCompound worldNBT = user.getWorldNBT(respawn.getDimension().getDimensionName()).getCompoundTagOrNull("element"); // This is 1.17+, it always sends the world name
|
||||
user.setMinWorldHeight(worldNBT.getNumberTagOrNull("min_y").getAsInt());
|
||||
user.setTotalWorldHeight(worldNBT.getNumberTagOrNull("height").getAsInt());
|
||||
user.switchDimensionType(respawn.getServerVersion(), respawn.getDimension());
|
||||
} else if (event.getPacketType() == PacketType.Play.Server.CONFIGURATION_START) {
|
||||
user.setEncoderState(ConnectionState.CONFIGURATION);
|
||||
} else if (event.getPacketType() == PacketType.Configuration.Server.CONFIGURATION_END) {
|
||||
user.setEncoderState(ConnectionState.PLAY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,17 +172,17 @@ public class InternalPacketListener extends PacketListenerAbstract {
|
||||
WrapperHandshakingClientHandshake handshake = new WrapperHandshakingClientHandshake(event);
|
||||
ConnectionState nextState = handshake.getNextConnectionState();
|
||||
ClientVersion clientVersion = handshake.getClientVersion();
|
||||
if (clientVersion == ClientVersion.UNKNOWN) {
|
||||
return;
|
||||
}
|
||||
//Update client version for this event call(and user)
|
||||
user.setClientVersion(clientVersion);
|
||||
PacketEvents.getAPI().getLogManager().debug("Processed " + address.getHostString() + ":" + address.getPort() + "'s client version. Client Version: " + clientVersion.getReleaseName());
|
||||
event.getPostTasks().add(() -> {
|
||||
//Transition into the LOGIN OR STATUS connection state
|
||||
PacketEvents.getAPI().getInjector().changeConnectionState(channel, nextState);
|
||||
PacketEvents.getAPI().getLogManager().debug("Transitioned " + address.getHostString() + ":" + address.getPort() + " into the " + nextState + " state!");
|
||||
});
|
||||
//Transition into LOGIN or STATUS connection state immediately, to remain in sync with vanilla
|
||||
user.setConnectionState(nextState);
|
||||
} else if (event.getPacketType() == PacketType.Login.Client.LOGIN_SUCCESS_ACK) {
|
||||
user.setDecoderState(ConnectionState.CONFIGURATION);
|
||||
} else if (event.getPacketType() == PacketType.Play.Client.CONFIGURATION_ACK) {
|
||||
user.setDecoderState(ConnectionState.CONFIGURATION);
|
||||
} else if (event.getPacketType() == PacketType.Configuration.Client.CONFIGURATION_END_ACK) {
|
||||
user.setDecoderState(ConnectionState.PLAY);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+22
-18
@@ -20,12 +20,12 @@ package com.github.retrooper.packetevents.manager.protocol;
|
||||
|
||||
import com.github.retrooper.packetevents.PacketEvents;
|
||||
import com.github.retrooper.packetevents.netty.channel.ChannelHelper;
|
||||
import com.github.retrooper.packetevents.protocol.ConnectionState;
|
||||
import com.github.retrooper.packetevents.protocol.ProtocolVersion;
|
||||
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
import com.github.retrooper.packetevents.protocol.player.User;
|
||||
import com.github.retrooper.packetevents.util.PacketTransformationUtil;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
@@ -34,6 +34,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public interface ProtocolManager {
|
||||
Map<UUID, Object> CHANNELS = new ConcurrentHashMap<>();
|
||||
// Use SocketAddress because ProtocolLib wraps Channels with NettyChannelProxy class
|
||||
Map<Object, User> USERS = new ConcurrentHashMap<>();
|
||||
|
||||
default Collection<User> getUsers() {
|
||||
@@ -91,67 +92,70 @@ public interface ProtocolManager {
|
||||
}
|
||||
}
|
||||
|
||||
//TODO Make it clear that this only updates the connection state in our user.
|
||||
//Sometimes you should use getInjector().changeConnectionState because that can allow the injector to make adjustments.
|
||||
//This is very important, especially on Spigot.
|
||||
//As soon as we switch to the play state on spigot, our injector makes some adjustments.
|
||||
default void changeConnectionState(Object channel, ConnectionState connectionState) {
|
||||
getUser(channel).setConnectionState(connectionState);
|
||||
}
|
||||
|
||||
default void setClientVersion(Object channel, ClientVersion version) {
|
||||
getUser(channel).setClientVersion(version);
|
||||
}
|
||||
|
||||
default Object[] transformWrappers(PacketWrapper<?> wrapper) {
|
||||
@ApiStatus.Internal
|
||||
default Object[] transformWrappers(PacketWrapper<?> wrapper, Object channel, boolean outgoing) {
|
||||
//It is possible that our packet transformer util decides to transform one wrapper into multiple packets.
|
||||
//(Correcting some mistakes on your end)
|
||||
PacketWrapper<?>[] wrappers = PacketTransformationUtil.transform(wrapper);
|
||||
Object[] buffers = new Object[wrappers.length];
|
||||
for (int i = 0; i < wrappers.length; i++) {
|
||||
wrappers[i].prepareForSend();
|
||||
wrappers[i].prepareForSend(channel, outgoing);
|
||||
buffers[i] = wrappers[i].buffer;
|
||||
// Fix race condition when sending packets to multiple people (due to when the buffer is freed)
|
||||
wrappers[i].buffer = null;
|
||||
}
|
||||
return buffers;
|
||||
}
|
||||
|
||||
default void sendPacket(Object channel, PacketWrapper<?> wrapper) {
|
||||
Object[] transformed = transformWrappers(wrapper);
|
||||
Object[] transformed = transformWrappers(wrapper, channel, true);
|
||||
sendPackets(channel, transformed);
|
||||
}
|
||||
|
||||
default void sendPacketSilently(Object channel, PacketWrapper<?> wrapper) {
|
||||
Object[] transformed = transformWrappers(wrapper);
|
||||
Object[] transformed = transformWrappers(wrapper, channel, true);
|
||||
sendPacketsSilently(channel, transformed);
|
||||
}
|
||||
|
||||
default void writePacket(Object channel, PacketWrapper<?> wrapper) {
|
||||
Object[] transformed = transformWrappers(wrapper);
|
||||
Object[] transformed = transformWrappers(wrapper, channel, true);
|
||||
writePackets(channel, transformed);
|
||||
}
|
||||
|
||||
default void writePacketSilently(Object channel, PacketWrapper<?> wrapper) {
|
||||
Object[] transformed = transformWrappers(wrapper);
|
||||
Object[] transformed = transformWrappers(wrapper, channel, true);
|
||||
writePacketsSilently(channel, transformed);
|
||||
}
|
||||
|
||||
default void receivePacket(Object channel, PacketWrapper<?> wrapper) {
|
||||
Object[] transformed = transformWrappers(wrapper);
|
||||
Object[] transformed = transformWrappers(wrapper, channel, false);
|
||||
receivePackets(channel, transformed);
|
||||
}
|
||||
|
||||
default void receivePacketSilently(Object channel, PacketWrapper<?> wrapper) {
|
||||
Object[] transformed = transformWrappers(wrapper);
|
||||
Object[] transformed = transformWrappers(wrapper, channel, false);
|
||||
receivePacketsSilently(channel, transformed);
|
||||
}
|
||||
|
||||
default User getUser(Object channel) {
|
||||
return USERS.get(channel);
|
||||
Object pipeline = ChannelHelper.getPipeline(channel);
|
||||
return USERS.get(pipeline);
|
||||
}
|
||||
|
||||
default User removeUser(Object channel) {
|
||||
Object pipeline = ChannelHelper.getPipeline(channel);
|
||||
return USERS.remove(pipeline);
|
||||
}
|
||||
|
||||
default void setUser(Object channel, User user) {
|
||||
synchronized (channel) {
|
||||
USERS.put(channel, user);
|
||||
Object pipeline = ChannelHelper.getPipeline(channel);
|
||||
USERS.put(pipeline, user);
|
||||
}
|
||||
PacketEvents.getAPI().getInjector().updateUser(channel, user);
|
||||
}
|
||||
|
||||
+3
-1
@@ -46,7 +46,9 @@ public enum ServerVersion {
|
||||
V_1_17(755), V_1_17_1(756),
|
||||
V_1_18(757), V_1_18_1(757), V_1_18_2(758),
|
||||
//1.19.1 and 1.19.2 have the same protocol version
|
||||
V_1_19(759), V_1_19_1(760), V_1_19_2(760),
|
||||
V_1_19(759), V_1_19_1(760), V_1_19_2(760), V_1_19_3(761), V_1_19_4(762),
|
||||
//1.20 and 1.20.1 have the same protocol version. 1.20.3 and 1.20.4 have the same protocol version. 1.20.5 and 1.20.6 have the same protocol version
|
||||
V_1_20(763), V_1_20_1(763), V_1_20_2(764), V_1_20_3(765), V_1_20_4(765), V_1_20_5(766), V_1_20_6(766),
|
||||
//TODO UPDATE Add server version constant
|
||||
ERROR(-1, true);
|
||||
|
||||
|
||||
+12
-2
@@ -18,6 +18,8 @@
|
||||
|
||||
package com.github.retrooper.packetevents.netty.buffer;
|
||||
|
||||
import com.github.retrooper.packetevents.exception.PacketProcessException;
|
||||
|
||||
import java.io.*;
|
||||
//TODO give netty credit
|
||||
public class ByteBufInputStream extends InputStream implements DataInput {
|
||||
@@ -204,7 +206,8 @@ public class ByteBufInputStream extends InputStream implements DataInput {
|
||||
}
|
||||
|
||||
public String readUTF() throws IOException {
|
||||
return DataInputStream.readUTF(this);
|
||||
String text = DataInputStream.readUTF(this);
|
||||
return text;
|
||||
}
|
||||
|
||||
public int readUnsignedByte() throws IOException {
|
||||
@@ -225,7 +228,14 @@ public class ByteBufInputStream extends InputStream implements DataInput {
|
||||
if (fieldSize < 0) {
|
||||
throw new IndexOutOfBoundsException("fieldSize cannot be a negative number");
|
||||
} else if (fieldSize > this.available()) {
|
||||
throw new EOFException("fieldSize is too long! Length is " + fieldSize + ", but maximum is " + this.available());
|
||||
int value = this.available();
|
||||
String msg = "fieldSize is too long! Length is " + fieldSize + ", but maximum is " + value;
|
||||
if (value == 0) {
|
||||
throw new PacketProcessException(msg);
|
||||
}
|
||||
else {
|
||||
throw new EOFException(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,6 +81,10 @@ public class ChannelHelper {
|
||||
return Arrays.toString(pipelineHandlerNames(channel).toArray(new String[0]));
|
||||
}
|
||||
|
||||
public static Object getPipeline(Object channel) {
|
||||
return PacketEvents.getAPI().getNettyManager().getChannelOperator().getPipeline(channel);
|
||||
}
|
||||
|
||||
public static Object getPipelineHandler(Object channel, String name) {
|
||||
return PacketEvents.getAPI().getNettyManager().getChannelOperator().getPipelineHandler(channel, name);
|
||||
}
|
||||
@@ -89,6 +93,10 @@ public class ChannelHelper {
|
||||
return PacketEvents.getAPI().getNettyManager().getChannelOperator().getPipelineContext(channel, handlerName);
|
||||
}
|
||||
|
||||
public static Object pooledByteBuf(Object channel) {
|
||||
return PacketEvents.getAPI().getNettyManager().getChannelOperator().pooledByteBuf(channel);
|
||||
}
|
||||
|
||||
public static void runInEventLoop(Object channel, Runnable runnable) {
|
||||
PacketEvents.getAPI().getNettyManager().getChannelOperator().runInEventLoop(channel, runnable);
|
||||
}
|
||||
|
||||
+18
-3
@@ -20,26 +20,41 @@ package com.github.retrooper.packetevents.netty.channel;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public interface ChannelOperator {
|
||||
Set<Class<? extends Throwable>> getIgnoredHandlerExceptions();
|
||||
|
||||
SocketAddress remoteAddress(Object channel);
|
||||
|
||||
SocketAddress localAddress(Object channel);
|
||||
|
||||
boolean isOpen(Object channel);
|
||||
|
||||
Object close(Object channel);
|
||||
|
||||
Object write(Object channel, Object buffer);
|
||||
|
||||
Object flush(Object channel);
|
||||
|
||||
Object writeAndFlush(Object channel, Object buffer);
|
||||
|
||||
Object fireChannelRead(Object channel, Object buffer);
|
||||
|
||||
Object writeInContext(Object channel, String ctx, Object buffer);
|
||||
|
||||
Object flushInContext(Object channel, String ctx);
|
||||
|
||||
Object writeAndFlushInContext(Object channel, String ctx, Object buffer);
|
||||
|
||||
Object fireChannelReadInContext(Object channel, String ctx, Object buffer);
|
||||
|
||||
List<String> pipelineHandlerNames(Object channel);
|
||||
|
||||
Object getPipelineHandler(Object channel, String name);
|
||||
|
||||
Object getPipelineContext(Object channel, String name);
|
||||
|
||||
Object getPipeline(Object channel);
|
||||
|
||||
void runInEventLoop(Object channel, Runnable runnable);
|
||||
|
||||
Object pooledByteBuf(Object channel);
|
||||
}
|
||||
@@ -23,7 +23,7 @@ package com.github.retrooper.packetevents.protocol;
|
||||
* @since 1.8
|
||||
*/
|
||||
public enum ConnectionState {
|
||||
HANDSHAKING, STATUS, LOGIN, PLAY;
|
||||
HANDSHAKING, STATUS, LOGIN, PLAY, CONFIGURATION;
|
||||
|
||||
public static ConnectionState getById(int id) {
|
||||
if (id >= values().length || id < 0) {
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2023 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.attribute;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.mapper.MappedEntity;
|
||||
|
||||
public interface Attribute extends MappedEntity {
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.attribute;
|
||||
|
||||
public enum AttributeOperation {
|
||||
ADDITION,
|
||||
MULTIPLY_BASE,
|
||||
MULTIPLY_TOTAL,
|
||||
}
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2023 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.attribute;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
import com.github.retrooper.packetevents.resources.ResourceLocation;
|
||||
import com.github.retrooper.packetevents.util.mappings.MappingHelper;
|
||||
import com.github.retrooper.packetevents.util.mappings.TypesBuilder;
|
||||
import com.github.retrooper.packetevents.util.mappings.TypesBuilderData;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Attributes {
|
||||
|
||||
private static final Map<String, Attribute> ATTRIBUTE_MAP = new HashMap<>();
|
||||
private static final Map<Byte, Map<Integer, Attribute>> ATTRIBUTE_ID_MAP = new HashMap<>();
|
||||
private static final TypesBuilder TYPES_BUILDER = new TypesBuilder("attribute/attribute_mappings");
|
||||
|
||||
public static Attribute define(String key) {
|
||||
TypesBuilderData data = TYPES_BUILDER.define(key);
|
||||
Attribute attribute = new Attribute() {
|
||||
@Override
|
||||
public ResourceLocation getName() {
|
||||
return data.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId(ClientVersion version) {
|
||||
return MappingHelper.getId(version, TYPES_BUILDER, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof Attribute) {
|
||||
return this.getName().equals(((Attribute) obj).getName());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
MappingHelper.registerMapping(TYPES_BUILDER, ATTRIBUTE_MAP, ATTRIBUTE_ID_MAP, attribute);
|
||||
return attribute;
|
||||
}
|
||||
|
||||
// with minecraft:key
|
||||
public static Attribute getByName(String name) {
|
||||
return ATTRIBUTE_MAP.get(name);
|
||||
}
|
||||
|
||||
public static Attribute getById(ClientVersion version, int id) {
|
||||
int index = TYPES_BUILDER.getDataIndex(version);
|
||||
Map<Integer, Attribute> idMap = ATTRIBUTE_ID_MAP.get((byte) index);
|
||||
return idMap.get(id);
|
||||
}
|
||||
|
||||
public static final Attribute GENERIC_ARMOR = define("generic.armor");
|
||||
public static final Attribute GENERIC_ARMOR_TOUGHNESS = define("generic.armor_toughness");
|
||||
public static final Attribute GENERIC_ATTACK_DAMAGE = define("generic.attack_damage");
|
||||
public static final Attribute GENERIC_ATTACK_KNOCKBACK = define("generic.attack_knockback");
|
||||
public static final Attribute GENERIC_ATTACK_SPEED = define("generic.attack_speed");
|
||||
public static final Attribute GENERIC_FLYING_SPEED = define("generic.flying_speed");
|
||||
public static final Attribute GENERIC_FOLLOW_RANGE = define("generic.follow_range");
|
||||
@ApiStatus.Obsolete // renamed in 1.20.5
|
||||
public static final Attribute HORSE_JUMP_STRENGTH = define("horse.jump_strength");
|
||||
public static final Attribute GENERIC_KNOCKBACK_RESISTANCE = define("generic.knockback_resistance");
|
||||
public static final Attribute GENERIC_LUCK = define("generic.luck");
|
||||
public static final Attribute GENERIC_MAX_HEALTH = define("generic.max_health");
|
||||
public static final Attribute GENERIC_MOVEMENT_SPEED = define("generic.movement_speed");
|
||||
public static final Attribute ZOMBIE_SPAWN_REINFORCEMENTS = define("zombie.spawn_reinforcements");
|
||||
|
||||
// Added in 1.20.2
|
||||
public static final Attribute GENERIC_MAX_ABSORPTION = define("generic.max_absorption");
|
||||
|
||||
// added in 1.20.5
|
||||
public static final Attribute PLAYER_BLOCK_BREAK_SPEED = define("player.block_break_speed");
|
||||
public static final Attribute PLAYER_BLOCK_INTERACTION_RANGE = define("player.block_interaction_range");
|
||||
public static final Attribute PLAYER_ENTITY_INTERACTION_RANGE = define("player.entity_interaction_range");
|
||||
public static final Attribute GENERIC_FALL_DAMAGE_MULTIPLIER = define("generic.fall_damage_multiplier");
|
||||
public static final Attribute GENERIC_GRAVITY = define("generic.gravity");
|
||||
public static final Attribute GENERIC_JUMP_STRENGTH = define("generic.jump_strength");
|
||||
public static final Attribute GENERIC_SAFE_FALL_DISTANCE = define("generic.safe_fall_distance");
|
||||
public static final Attribute GENERIC_SCALE = define("generic.scale");
|
||||
public static final Attribute GENERIC_STEP_HEIGHT = define("generic.step_height");
|
||||
|
||||
static {
|
||||
TYPES_BUILDER.unloadFileMappings();
|
||||
}
|
||||
}
|
||||
@@ -20,8 +20,9 @@ package com.github.retrooper.packetevents.protocol.chat;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
import com.github.retrooper.packetevents.resources.ResourceLocation;
|
||||
import com.github.retrooper.packetevents.util.TypesBuilder;
|
||||
import com.github.retrooper.packetevents.util.TypesBuilderData;
|
||||
import com.github.retrooper.packetevents.util.mappings.MappingHelper;
|
||||
import com.github.retrooper.packetevents.util.mappings.TypesBuilder;
|
||||
import com.github.retrooper.packetevents.util.mappings.TypesBuilderData;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -30,20 +31,11 @@ public class ChatTypes {
|
||||
private static final Map<String, ChatType> CHAT_TYPE_MAP = new HashMap<>();
|
||||
//Key - mappings version, value - map with chat type ids and chat types
|
||||
private static final Map<Byte, Map<Integer, ChatType>> CHAT_TYPE_ID_MAP = new HashMap<>();
|
||||
private static final TypesBuilder TYPES_BUILDER = new TypesBuilder("chat/chat_type_mappings",
|
||||
ClientVersion.V_1_18_2,
|
||||
ClientVersion.V_1_19,
|
||||
ClientVersion.V_1_19_1);
|
||||
|
||||
static {
|
||||
TYPES_BUILDER.unloadFileMappings();
|
||||
}
|
||||
private static final TypesBuilder TYPES_BUILDER = new TypesBuilder("chat/chat_type_mappings");
|
||||
|
||||
public static ChatType define(String key) {
|
||||
TypesBuilderData data = TYPES_BUILDER.define(key);
|
||||
ChatType chatType = new ChatType() {
|
||||
private final int[] ids = data.getData();
|
||||
|
||||
@Override
|
||||
public ResourceLocation getName() {
|
||||
return data.getName();
|
||||
@@ -51,16 +43,10 @@ public class ChatTypes {
|
||||
|
||||
@Override
|
||||
public int getId(ClientVersion version) {
|
||||
int index = TYPES_BUILDER.getDataIndex(version);
|
||||
return ids[index];
|
||||
return MappingHelper.getId(version, TYPES_BUILDER, data);
|
||||
}
|
||||
};
|
||||
CHAT_TYPE_MAP.put(chatType.getName().toString(), chatType);
|
||||
for (ClientVersion version : TYPES_BUILDER.getVersions()) {
|
||||
int index = TYPES_BUILDER.getDataIndex(version);
|
||||
Map<Integer, ChatType> typeIdMap = CHAT_TYPE_ID_MAP.computeIfAbsent((byte) index, k -> new HashMap<>());
|
||||
typeIdMap.put(chatType.getId(version), chatType);
|
||||
}
|
||||
MappingHelper.registerMapping(TYPES_BUILDER, CHAT_TYPE_MAP, CHAT_TYPE_ID_MAP, chatType);
|
||||
return chatType;
|
||||
}
|
||||
|
||||
@@ -91,4 +77,8 @@ public class ChatTypes {
|
||||
public static final ChatType MSG_COMMAND = define("msg_command");
|
||||
@Deprecated
|
||||
public static final ChatType TEAM_MSG_COMMAND = define("team_msg_command");
|
||||
|
||||
static {
|
||||
TYPES_BUILDER.unloadFileMappings();
|
||||
}
|
||||
}
|
||||
+37
-2
@@ -5,6 +5,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.BitSet;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -32,6 +33,22 @@ public class LastSeenMessages {
|
||||
return entries;
|
||||
}
|
||||
|
||||
public static class Packed {
|
||||
private List<MessageSignature.Packed> packedMessageSignatures;
|
||||
|
||||
public Packed(List<MessageSignature.Packed> packedMessageSignatures) {
|
||||
this.packedMessageSignatures = packedMessageSignatures;
|
||||
}
|
||||
|
||||
public List<MessageSignature.Packed> getPackedMessageSignatures() {
|
||||
return packedMessageSignatures;
|
||||
}
|
||||
|
||||
public void setPackedMessageSignatures(List<MessageSignature.Packed> packedMessageSignatures) {
|
||||
this.packedMessageSignatures = packedMessageSignatures;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Entry {
|
||||
private final UUID uuid;
|
||||
private final byte[] signature;
|
||||
@@ -50,11 +67,11 @@ public class LastSeenMessages {
|
||||
}
|
||||
}
|
||||
|
||||
public static class Update {
|
||||
public static class LegacyUpdate {
|
||||
private final LastSeenMessages lastSeenMessages;
|
||||
private final @Nullable Entry lastReceived;
|
||||
|
||||
public Update(LastSeenMessages lastSeenMessages, @Nullable Entry lastReceived) {
|
||||
public LegacyUpdate(LastSeenMessages lastSeenMessages, @Nullable Entry lastReceived) {
|
||||
this.lastSeenMessages = lastSeenMessages;
|
||||
this.lastReceived = lastReceived;
|
||||
}
|
||||
@@ -67,4 +84,22 @@ public class LastSeenMessages {
|
||||
return lastReceived;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Update {
|
||||
private final int offset;
|
||||
private final BitSet acknowledged;
|
||||
|
||||
public Update(int offset, BitSet acknowledged) {
|
||||
this.offset = offset;
|
||||
this.acknowledged = acknowledged;
|
||||
}
|
||||
|
||||
public int getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
public BitSet getAcknowledged() {
|
||||
return acknowledged;
|
||||
}
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2023 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.chat;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class MessageSignature {
|
||||
private byte[] bytes;
|
||||
|
||||
public MessageSignature(byte[] bytes) {
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
public byte[] getBytes() {
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public void setBytes(byte[] bytes) {
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
public static class Packed {
|
||||
private int id;
|
||||
private @Nullable MessageSignature fullSignature;
|
||||
|
||||
public Packed(@Nullable MessageSignature fullSignature) {
|
||||
this.id = -1;
|
||||
this.fullSignature = fullSignature;
|
||||
}
|
||||
|
||||
public Packed(int id) {
|
||||
this.id = id;
|
||||
this.fullSignature = null;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Optional<MessageSignature> getFullSignature() {
|
||||
return Optional.ofNullable(fullSignature);
|
||||
}
|
||||
|
||||
public void setFullSignature(@Nullable MessageSignature fullSignature) {
|
||||
this.fullSignature = fullSignature;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.chat;
|
||||
|
||||
import com.github.retrooper.packetevents.resources.ResourceLocation;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class Node {
|
||||
private byte flags;
|
||||
private List<Integer> children;
|
||||
private int redirectNodeIndex;
|
||||
private Optional<String> name;
|
||||
private Optional<Integer> parserID;
|
||||
private Optional<List<Object>> properties;
|
||||
private Optional<ResourceLocation> suggestionsType;
|
||||
|
||||
public Node(byte flags, List<Integer> children, int redirectNodeIndex, @Nullable String name, @Nullable Integer parserID, @Nullable List<Object> properties, @Nullable ResourceLocation suggestionsType) {
|
||||
this.flags = flags;
|
||||
this.children = children;
|
||||
this.redirectNodeIndex = redirectNodeIndex;
|
||||
this.name = Optional.ofNullable(name);
|
||||
this.parserID = Optional.ofNullable(parserID);
|
||||
this.properties = Optional.ofNullable(properties);
|
||||
this.suggestionsType = Optional.ofNullable(suggestionsType);
|
||||
}
|
||||
|
||||
public byte getFlags() {
|
||||
return flags;
|
||||
}
|
||||
|
||||
public void setFlags(byte flags) {
|
||||
this.flags = flags;
|
||||
}
|
||||
|
||||
public List<Integer> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
public void setChildren(List<Integer> children) {
|
||||
this.children = children;
|
||||
}
|
||||
|
||||
public int getRedirectNodeIndex() {
|
||||
return redirectNodeIndex;
|
||||
}
|
||||
|
||||
public void setRedirectNodeIndex(int redirectNodeIndex) {
|
||||
this.redirectNodeIndex = redirectNodeIndex;
|
||||
}
|
||||
|
||||
public Optional<String> getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(Optional<String> name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Optional<Integer> getParserID() {
|
||||
return parserID;
|
||||
}
|
||||
|
||||
public void setParserID(Optional<Integer> parserID) {
|
||||
this.parserID = parserID;
|
||||
}
|
||||
|
||||
public Optional<List<Object>> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public void setProperties(Optional<List<Object>> properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public Optional<ResourceLocation> getSuggestionsType() {
|
||||
return suggestionsType;
|
||||
}
|
||||
|
||||
public void setSuggestionsType(Optional<ResourceLocation> suggestionsType) {
|
||||
this.suggestionsType = suggestionsType;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,275 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.chat;
|
||||
|
||||
import com.github.retrooper.packetevents.manager.server.ServerVersion;
|
||||
import com.github.retrooper.packetevents.protocol.mapper.MappedEntity;
|
||||
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
import com.github.retrooper.packetevents.resources.ResourceLocation;
|
||||
import com.github.retrooper.packetevents.util.mappings.MappingHelper;
|
||||
import com.github.retrooper.packetevents.util.mappings.TypesBuilder;
|
||||
import com.github.retrooper.packetevents.util.mappings.TypesBuilderData;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class Parsers {
|
||||
|
||||
private static final List<Parser> ALL_PARSERS = new ArrayList<>(); // support for old methods
|
||||
private static final Map<String, Parser> PARSER_MAP = new HashMap<>();
|
||||
private static final Map<Byte, Map<Integer, Parser>> PARSER_ID_MAP = new HashMap<>();
|
||||
private static final TypesBuilder TYPES_BUILDER = new TypesBuilder("command/argument_parser_mappings");
|
||||
|
||||
public static Parser define(String key) {
|
||||
return define(key, null, null);
|
||||
}
|
||||
|
||||
public static Parser define(String key, @Nullable Reader reader, @Nullable Writer writer) {
|
||||
TypesBuilderData data = TYPES_BUILDER.define(key);
|
||||
Parser parser = new Parser(data, reader, writer);
|
||||
|
||||
ALL_PARSERS.add(parser);
|
||||
MappingHelper.registerMapping(TYPES_BUILDER, PARSER_MAP, PARSER_ID_MAP, parser);
|
||||
return parser;
|
||||
}
|
||||
|
||||
// with key
|
||||
public static Parser getByName(String name) {
|
||||
return PARSER_MAP.get(name);
|
||||
}
|
||||
|
||||
public static Parser getById(ClientVersion version, int id) {
|
||||
int index = TYPES_BUILDER.getDataIndex(version);
|
||||
Map<Integer, Parser> idMap = PARSER_ID_MAP.get((byte) index);
|
||||
return idMap.get(id);
|
||||
}
|
||||
|
||||
public static List<Parser> getParsers() {
|
||||
return Collections.unmodifiableList(ALL_PARSERS);
|
||||
}
|
||||
|
||||
public static final Parser BRIGADIER_BOOL = define("brigadier:bool", null, null);
|
||||
public static final Parser BRIGADIER_FLOAT = define("brigadier:float",
|
||||
packetWrapper -> {
|
||||
byte flags = packetWrapper.readByte();
|
||||
float min = (flags & 0x01) != 0 ? packetWrapper.readFloat() : -Float.MAX_VALUE;
|
||||
float max = (flags & 0x02) != 0 ? packetWrapper.readFloat() : Float.MAX_VALUE;
|
||||
return Arrays.asList(flags, min, max);
|
||||
},
|
||||
(packetWrapper, properties) -> {
|
||||
byte flags = (byte) properties.get(0);
|
||||
packetWrapper.writeByte(flags);
|
||||
if ((flags & 0x01) != 0) packetWrapper.writeFloat((float) properties.get(1));
|
||||
if ((flags & 0x02) != 0) packetWrapper.writeFloat((float) properties.get(2));
|
||||
}
|
||||
);
|
||||
public static final Parser BRIGADIER_DOUBLE = define("brigadier:double",
|
||||
packetWrapper -> {
|
||||
byte flags = packetWrapper.readByte();
|
||||
double min = (flags & 0x01) != 0 ? packetWrapper.readDouble() : -Double.MAX_VALUE;
|
||||
double max = (flags & 0x02) != 0 ? packetWrapper.readDouble() : Double.MAX_VALUE;
|
||||
return Arrays.asList(flags, min, max);
|
||||
},
|
||||
(packetWrapper, properties) -> {
|
||||
byte flags = (byte) properties.get(0);
|
||||
packetWrapper.writeByte(flags);
|
||||
if ((flags & 0x01) != 0) packetWrapper.writeDouble((double) properties.get(1));
|
||||
if ((flags & 0x02) != 0) packetWrapper.writeDouble((double) properties.get(2));
|
||||
}
|
||||
);
|
||||
public static final Parser BRIGADIER_INTEGER = define("brigadier:integer",
|
||||
packetWrapper -> {
|
||||
byte flags = packetWrapper.readByte();
|
||||
int min = (flags & 0x01) != 0 ? packetWrapper.readInt() : Integer.MIN_VALUE;
|
||||
int max = (flags & 0x02) != 0 ? packetWrapper.readInt() : Integer.MAX_VALUE;
|
||||
return Arrays.asList(flags, min, max);
|
||||
},
|
||||
(packetWrapper, properties) -> {
|
||||
byte flags = (byte) properties.get(0);
|
||||
packetWrapper.writeByte(flags);
|
||||
if ((flags & 0x01) != 0) packetWrapper.writeInt((int) properties.get(1));
|
||||
if ((flags & 0x02) != 0) packetWrapper.writeInt((int) properties.get(2));
|
||||
}
|
||||
);
|
||||
public static final Parser BRIGADIER_LONG = define("brigadier:long",
|
||||
packetWrapper -> {
|
||||
byte flags = packetWrapper.readByte();
|
||||
long min = (flags & 0x01) != 0 ? packetWrapper.readLong() : Long.MIN_VALUE;
|
||||
long max = (flags & 0x02) != 0 ? packetWrapper.readLong() : Long.MAX_VALUE;
|
||||
return Arrays.asList(flags, min, max);
|
||||
},
|
||||
(packetWrapper, properties) -> {
|
||||
byte flags = (byte) properties.get(0);
|
||||
packetWrapper.writeByte(flags);
|
||||
if ((flags & 0x01) != 0) packetWrapper.writeLong((long) properties.get(1));
|
||||
if ((flags & 0x02) != 0) packetWrapper.writeLong((long) properties.get(2));
|
||||
}
|
||||
);
|
||||
public static final Parser BRIGADIER_STRING = define("brigadier:string",
|
||||
packetWrapper -> Collections.singletonList(packetWrapper.readVarInt()),
|
||||
(packetWrapper, properties) -> packetWrapper.writeVarInt((Integer) properties.get(0))
|
||||
);
|
||||
public static final Parser ENTITY = define("entity",
|
||||
packetWrapper -> Collections.singletonList(packetWrapper.readByte()),
|
||||
(packetWrapper, properties) -> packetWrapper.writeByte(((Byte) properties.get(0)).intValue())
|
||||
);
|
||||
public static final Parser GAME_PROFILE = define("game_profile", null, null);
|
||||
public static final Parser BLOCK_POS = define("block_pos", null, null);
|
||||
public static final Parser COLUMN_POS = define("column_pos", null, null);
|
||||
public static final Parser VEC3 = define("vec3", null, null);
|
||||
public static final Parser VEC2 = define("vec2", null, null);
|
||||
public static final Parser BLOCK_STATE = define("block_state", null, null);
|
||||
public static final Parser BLOCK_PREDICATE = define("block_predicate", null, null);
|
||||
public static final Parser ITEM_STACK = define("item_stack", null, null);
|
||||
public static final Parser ITEM_PREDICATE = define("item_predicate", null, null);
|
||||
public static final Parser COLOR = define("color", null, null);
|
||||
public static final Parser COMPONENT = define("component", null, null);
|
||||
public static final Parser STYLE = define("style", null, null);
|
||||
public static final Parser MESSAGE = define("message", null, null);
|
||||
public static final Parser NBT = define("nbt", null, null);
|
||||
public static final Parser NBT_TAG = define("nbt_tag", null, null);
|
||||
public static final Parser NBT_PATH = define("nbt_path", null, null);
|
||||
public static final Parser OBJECTIVE = define("objective", null, null);
|
||||
public static final Parser OBJECTIVE_CRITERIA = define("objective_criteria", null, null);
|
||||
public static final Parser OPERATION = define("operation", null, null);
|
||||
public static final Parser PARTICLE = define("particle", null, null);
|
||||
public static final Parser ANGLE = define("angle", null, null);
|
||||
public static final Parser ROTATION = define("rotation", null, null);
|
||||
public static final Parser SCOREBOARD_SLOT = define("scoreboard_slot", null, null);
|
||||
public static final Parser SCORE_HOLDER = define("score_holder",
|
||||
packetWrapper -> Collections.singletonList(packetWrapper.readByte()),
|
||||
(packetWrapper, properties) -> packetWrapper.writeByte(((Byte) properties.get(0)).intValue())
|
||||
);
|
||||
public static final Parser SWIZZLE = define("swizzle", null, null);
|
||||
public static final Parser TEAM = define("team", null, null);
|
||||
public static final Parser ITEM_SLOT = define("item_slot", null, null);
|
||||
public static final Parser ITEM_SLOTS = define("item_slots", null, null);
|
||||
public static final Parser RESOURCE_LOCATION = define("resource_location", null, null);
|
||||
public static final Parser FUNCTION = define("function", null, null);
|
||||
public static final Parser ENTITY_ANCHOR = define("entity_anchor", null, null);
|
||||
public static final Parser INT_RANGE = define("int_range", null, null);
|
||||
public static final Parser FLOAT_RANGE = define("float_range", null, null);
|
||||
public static final Parser DIMENSION = define("dimension", null, null);
|
||||
public static final Parser GAMEMODE = define("gamemode", null, null);
|
||||
public static final Parser TIME = define("time",
|
||||
wrapper -> Collections.singletonList(wrapper.getServerVersion()
|
||||
.isNewerThanOrEquals(ServerVersion.V_1_19_4) ? wrapper.readInt() : 0),
|
||||
(wrapper, properties) -> {
|
||||
if (wrapper.getServerVersion().isNewerThanOrEquals(ServerVersion.V_1_19_4)) {
|
||||
wrapper.writeInt((int) properties.get(0));
|
||||
}
|
||||
}
|
||||
);
|
||||
public static final Parser RESOURCE_OR_TAG = define("resource_or_tag",
|
||||
packetWrapper -> Collections.singletonList(packetWrapper.readIdentifier()),
|
||||
(packetWrapper, properties) -> packetWrapper.writeIdentifier((ResourceLocation) properties.get(0))
|
||||
);
|
||||
public static final Parser RESOURCE_OR_TAG_KEY = define("resource_or_tag_key",
|
||||
packetWrapper -> Collections.singletonList(packetWrapper.readIdentifier()),
|
||||
(packetWrapper, properties) -> packetWrapper.writeIdentifier((ResourceLocation) properties.get(0))
|
||||
);
|
||||
public static final Parser RESOURCE = define("resource",
|
||||
packetWrapper -> Collections.singletonList(packetWrapper.readIdentifier()),
|
||||
(packetWrapper, properties) -> packetWrapper.writeIdentifier((ResourceLocation) properties.get(0))
|
||||
);
|
||||
public static final Parser RESOURCE_KEY = define("resource_key",
|
||||
packetWrapper -> Collections.singletonList(packetWrapper.readIdentifier()),
|
||||
(packetWrapper, properties) -> packetWrapper.writeIdentifier((ResourceLocation) properties.get(0))
|
||||
);
|
||||
public static final Parser TEMPLATE_MIRROR = define("template_mirror", null, null);
|
||||
public static final Parser TEMPLATE_ROTATION = define("template_rotation", null, null);
|
||||
public static final Parser HEIGHTMAP = define("heightmap", null, null);
|
||||
public static final Parser LOOT_TABLE = define("loot_table", null, null);
|
||||
public static final Parser LOOT_PREDICATE = define("loot_predicate", null, null);
|
||||
public static final Parser LOOT_MODIFIER = define("loot_modifier", null, null);
|
||||
public static final Parser UUID = define("uuid", null, null);
|
||||
|
||||
static {
|
||||
TYPES_BUILDER.unloadFileMappings();
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Reader extends Function<PacketWrapper<?>, List<Object>> {}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Writer extends BiConsumer<PacketWrapper<?>, List<Object>> {}
|
||||
|
||||
public static final class Parser implements MappedEntity {
|
||||
|
||||
private final TypesBuilderData data;
|
||||
private final Reader reader;
|
||||
private final Writer writer;
|
||||
|
||||
@Deprecated
|
||||
public Parser(String name, @Nullable Function<PacketWrapper<?>, List<Object>> read, @Nullable BiConsumer<PacketWrapper<?>, List<Object>> write) {
|
||||
this(
|
||||
new TypesBuilderData(new ResourceLocation(name), new int[0]),
|
||||
read == null ? null : read::apply,
|
||||
write == null ? null : write::accept
|
||||
);
|
||||
}
|
||||
|
||||
private Parser(TypesBuilderData data, @Nullable Reader reader, Writer writer) {
|
||||
this.data = data;
|
||||
this.reader = reader;
|
||||
this.writer = writer;
|
||||
}
|
||||
|
||||
public Optional<List<Object>> readProperties(PacketWrapper<?> wrapper) {
|
||||
if (this.reader != null) {
|
||||
return Optional.of(this.reader.apply(wrapper));
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public void writeProperties(PacketWrapper<?> wrapper, List<Object> properties) {
|
||||
if (this.writer != null) {
|
||||
this.writer.accept(wrapper, properties);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getName() {
|
||||
return this.data.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId(ClientVersion version) {
|
||||
int index = TYPES_BUILDER.getDataIndex(version);
|
||||
return this.data.getData()[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof Parser) {
|
||||
return this.getName().equals(((Parser) obj).getName());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.chat;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.player.PublicProfileKey;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class RemoteChatSession {
|
||||
private final UUID sessionId;
|
||||
private final PublicProfileKey publicProfileKey;
|
||||
|
||||
public RemoteChatSession(UUID sessionId, PublicProfileKey publicProfileKey) {
|
||||
this.sessionId = sessionId;
|
||||
this.publicProfileKey = publicProfileKey;
|
||||
}
|
||||
|
||||
public UUID getSessionId() {
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
public PublicProfileKey getPublicProfileKey() {
|
||||
return publicProfileKey;
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package com.github.retrooper.packetevents.protocol.chat;
|
||||
|
||||
public class SignedCommandArgument {
|
||||
private String argument;
|
||||
private byte[] signature;
|
||||
|
||||
public SignedCommandArgument(String argument, byte[] signature) {
|
||||
this.argument = argument;
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
public String getArgument() {
|
||||
return argument;
|
||||
}
|
||||
|
||||
public void setArgument(String argument) {
|
||||
this.argument = argument;
|
||||
}
|
||||
|
||||
public byte[] getSignature() {
|
||||
return signature;
|
||||
}
|
||||
|
||||
public void setSignature(byte[] signature) {
|
||||
this.signature = signature;
|
||||
}
|
||||
}
|
||||
+3
-13
@@ -24,10 +24,9 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ChatMessage_v1_19 extends ChatMessage {
|
||||
//We'll extend ChatMessage_v1_16 for now, hopefully no breaking changes in the future
|
||||
public class ChatMessage_v1_19 extends ChatMessage_v1_16 {
|
||||
private @Nullable Component unsignedChatContent;
|
||||
private UUID senderUUID;
|
||||
private Component senderDisplayName;
|
||||
private @Nullable Component teamName;
|
||||
private Instant timestamp;
|
||||
@@ -37,9 +36,8 @@ public class ChatMessage_v1_19 extends ChatMessage {
|
||||
public ChatMessage_v1_19(Component chatContent, @Nullable Component unsignedChatContent, ChatType type,
|
||||
UUID senderUUID, Component senderDisplayName, @Nullable Component teamName, Instant timestamp,
|
||||
long salt, byte[] signature) {
|
||||
super(chatContent, type);
|
||||
super(chatContent, type, senderUUID);
|
||||
this.unsignedChatContent = unsignedChatContent;
|
||||
this.senderUUID = senderUUID;
|
||||
this.senderDisplayName = senderDisplayName;
|
||||
this.teamName = teamName;
|
||||
this.timestamp = timestamp;
|
||||
@@ -51,10 +49,6 @@ public class ChatMessage_v1_19 extends ChatMessage {
|
||||
return unsignedChatContent;
|
||||
}
|
||||
|
||||
public UUID getSenderUUID() {
|
||||
return senderUUID;
|
||||
}
|
||||
|
||||
public Component getSenderDisplayName() {
|
||||
return senderDisplayName;
|
||||
}
|
||||
@@ -79,10 +73,6 @@ public class ChatMessage_v1_19 extends ChatMessage {
|
||||
this.unsignedChatContent = unsignedChatContent;
|
||||
}
|
||||
|
||||
public void setSenderUUID(UUID senderUUID) {
|
||||
this.senderUUID = senderUUID;
|
||||
}
|
||||
|
||||
public void setSenderDisplayName(Component senderDisplayName) {
|
||||
this.senderDisplayName = senderDisplayName;
|
||||
}
|
||||
|
||||
+3
-13
@@ -26,11 +26,10 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ChatMessage_v1_19_1 extends ChatMessage {
|
||||
//We'll extend ChatMessage_v1_16 for now, hopefully no breaking changes in the future
|
||||
public class ChatMessage_v1_19_1 extends ChatMessage_v1_16 {
|
||||
private String plainContent;
|
||||
private @Nullable Component unsignedChatContent;
|
||||
private UUID senderUUID;
|
||||
private ChatTypeBoundNetwork chatType;
|
||||
private byte @Nullable [] previousSignature;
|
||||
private byte[] signature;
|
||||
@@ -46,10 +45,9 @@ public class ChatMessage_v1_19_1 extends ChatMessage {
|
||||
Instant timestamp, long salt,
|
||||
LastSeenMessages lastSeenMessages,
|
||||
FilterMask filterMask) {
|
||||
super(decoratedChatContent, chatType.getType());
|
||||
super(decoratedChatContent, chatType.getType(), senderUUID);
|
||||
this.plainContent = plainContent;
|
||||
this.unsignedChatContent = unsignedChatContent;
|
||||
this.senderUUID = senderUUID;
|
||||
this.chatType = chatType;
|
||||
this.previousSignature = previousSignature;
|
||||
this.signature = signature;
|
||||
@@ -79,14 +77,6 @@ public class ChatMessage_v1_19_1 extends ChatMessage {
|
||||
this.unsignedChatContent = unsignedChatContent;
|
||||
}
|
||||
|
||||
public UUID getSenderUUID() {
|
||||
return senderUUID;
|
||||
}
|
||||
|
||||
public void setSenderUUID(UUID senderUUID) {
|
||||
this.senderUUID = senderUUID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChatType getType() {
|
||||
return chatType.getType();
|
||||
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
package com.github.retrooper.packetevents.protocol.chat.message;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.chat.LastSeenMessages;
|
||||
import com.github.retrooper.packetevents.protocol.chat.filter.FilterMask;
|
||||
import com.github.retrooper.packetevents.util.adventure.AdventureSerializer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
//We'll extend ChatMessage_v1_16 for now, hopefully no breaking changes in the future
|
||||
public class ChatMessage_v1_19_3 extends ChatMessage_v1_16 {
|
||||
int index;
|
||||
byte[] signature;
|
||||
String plainContent;
|
||||
Instant timestamp;
|
||||
long salt;
|
||||
LastSeenMessages.Packed lastSeenMessagesPacked;
|
||||
@Nullable Component unsignedChatContent;
|
||||
FilterMask filterMask;
|
||||
ChatMessage_v1_19_1.ChatTypeBoundNetwork chatType;
|
||||
|
||||
public ChatMessage_v1_19_3(UUID senderUUID, int index, byte[] signature, String plainContent, Instant timestamp, long salt, LastSeenMessages.Packed lastSeenMessagesPacked, @Nullable Component unsignedChatContent, FilterMask filterMask, ChatMessage_v1_19_1.ChatTypeBoundNetwork chatType) {
|
||||
super(Component.text(plainContent), chatType.getType(), senderUUID);
|
||||
this.index = index;
|
||||
this.signature = signature;
|
||||
this.plainContent = plainContent;
|
||||
this.timestamp = timestamp;
|
||||
this.salt = salt;
|
||||
this.lastSeenMessagesPacked = lastSeenMessagesPacked;
|
||||
this.unsignedChatContent = unsignedChatContent;
|
||||
this.filterMask = filterMask;
|
||||
this.chatType = chatType;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public void setIndex(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public byte[] getSignature() {
|
||||
return signature;
|
||||
}
|
||||
|
||||
public void setSignature(byte[] signature) {
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getChatContent() {
|
||||
return Component.text(plainContent);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public void setChatContent(Component chatContent) {
|
||||
throw new UnsupportedOperationException("PacketEvents is not able to serialize components to plain-text. Please use the #setPlainContent instead to update the content.");
|
||||
}
|
||||
|
||||
public String getPlainContent() {
|
||||
return plainContent;
|
||||
}
|
||||
|
||||
public void setPlainContent(String plainContent) {
|
||||
this.plainContent = plainContent;
|
||||
}
|
||||
|
||||
public Instant getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public void setTimestamp(Instant timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
public long getSalt() {
|
||||
return salt;
|
||||
}
|
||||
|
||||
public void setSalt(long salt) {
|
||||
this.salt = salt;
|
||||
}
|
||||
|
||||
public LastSeenMessages.Packed getLastSeenMessagesPacked() {
|
||||
return lastSeenMessagesPacked;
|
||||
}
|
||||
|
||||
public void setLastSeenMessagesPacked(LastSeenMessages.Packed lastSeenMessagesPacked) {
|
||||
this.lastSeenMessagesPacked = lastSeenMessagesPacked;
|
||||
}
|
||||
|
||||
public Optional<Component> getUnsignedChatContent() {
|
||||
return Optional.ofNullable(unsignedChatContent);
|
||||
}
|
||||
|
||||
public void setUnsignedChatContent(@Nullable Component unsignedChatContent) {
|
||||
this.unsignedChatContent = unsignedChatContent;
|
||||
}
|
||||
|
||||
public FilterMask getFilterMask() {
|
||||
return filterMask;
|
||||
}
|
||||
|
||||
public void setFilterMask(FilterMask filterMask) {
|
||||
this.filterMask = filterMask;
|
||||
}
|
||||
|
||||
public ChatMessage_v1_19_1.ChatTypeBoundNetwork getChatType() {
|
||||
return chatType;
|
||||
}
|
||||
|
||||
public void setChatType(ChatMessage_v1_19_1.ChatTypeBoundNetwork chatType) {
|
||||
this.chatType = chatType;
|
||||
}
|
||||
}
|
||||
+5
-11
@@ -40,7 +40,9 @@ public class ChatMessageProcessor_v1_19_1 implements ChatMessageProcessor {
|
||||
byte[] signature = wrapper.readByteArray();
|
||||
String plainContent = wrapper.readString(256);
|
||||
Component chatContent = wrapper.readOptional(PacketWrapper::readComponent);
|
||||
if (chatContent == null) {
|
||||
if (chatContent == null && plainContent.isEmpty()) {
|
||||
chatContent = Component.empty();
|
||||
} else if (chatContent == null) {
|
||||
chatContent = Component.text(plainContent);
|
||||
}
|
||||
Instant timestamp = wrapper.readTimestamp();
|
||||
@@ -48,13 +50,7 @@ public class ChatMessageProcessor_v1_19_1 implements ChatMessageProcessor {
|
||||
LastSeenMessages lastSeenMessages = wrapper.readLastSeenMessages();
|
||||
Component unsignedChatContent = wrapper.readOptional(PacketWrapper::readComponent);
|
||||
FilterMask filterMask = wrapper.readFilterMask();
|
||||
|
||||
int id = wrapper.readVarInt();
|
||||
ChatType type = ChatTypes.getById(wrapper.getServerVersion().toClientVersion(), id);
|
||||
Component name = wrapper.readComponent();
|
||||
Component targetName = wrapper.readOptional(PacketWrapper::readComponent);
|
||||
ChatMessage_v1_19_1.ChatTypeBoundNetwork chatType = new ChatMessage_v1_19_1.ChatTypeBoundNetwork(type, name, targetName);
|
||||
|
||||
ChatMessage_v1_19_1.ChatTypeBoundNetwork chatType = wrapper.readChatTypeBoundNetwork();
|
||||
return new ChatMessage_v1_19_1(plainContent, chatContent, unsignedChatContent, senderUUID, chatType,
|
||||
previousSignature, signature, timestamp, salt, lastSeenMessages, filterMask);
|
||||
}
|
||||
@@ -72,8 +68,6 @@ public class ChatMessageProcessor_v1_19_1 implements ChatMessageProcessor {
|
||||
wrapper.writeLastSeenMessages(newData.getLastSeenMessages());
|
||||
wrapper.writeOptional(newData.getUnsignedChatContent(), PacketWrapper::writeComponent);
|
||||
wrapper.writeFilterMask(newData.getFilterMask());
|
||||
wrapper.writeVarInt(newData.getChatType().getType().getId(wrapper.getServerVersion().toClientVersion()));
|
||||
wrapper.writeComponent(newData.getChatType().getName());
|
||||
wrapper.writeOptional(newData.getChatType().getTargetName(), PacketWrapper::writeComponent);
|
||||
wrapper.writeChatTypeBoundNetwork(newData.getChatType());
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package com.github.retrooper.packetevents.protocol.chat.message.reader.impl;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.chat.LastSeenMessages;
|
||||
import com.github.retrooper.packetevents.protocol.chat.filter.FilterMask;
|
||||
import com.github.retrooper.packetevents.protocol.chat.message.ChatMessage;
|
||||
import com.github.retrooper.packetevents.protocol.chat.message.ChatMessage_v1_19_1;
|
||||
import com.github.retrooper.packetevents.protocol.chat.message.ChatMessage_v1_19_3;
|
||||
import com.github.retrooper.packetevents.protocol.chat.message.reader.ChatMessageProcessor;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ChatMessageProcessor_v1_19_3 implements ChatMessageProcessor {
|
||||
@Override
|
||||
public ChatMessage readChatMessage(@NotNull PacketWrapper<?> wrapper) {
|
||||
UUID senderUUID = wrapper.readUUID();
|
||||
int index = wrapper.readVarInt();
|
||||
byte[] signature = wrapper.readOptional((w) -> w.readBytes(256));
|
||||
String plainContent = wrapper.readString(256);
|
||||
Instant timestamp = wrapper.readTimestamp();
|
||||
long salt = wrapper.readLong();
|
||||
LastSeenMessages.Packed lastSeenMessagesPacked = wrapper.readLastSeenMessagesPacked();
|
||||
Component unsignedChatContent = wrapper.readOptional(PacketWrapper::readComponent);
|
||||
FilterMask filterMask = wrapper.readFilterMask();
|
||||
ChatMessage_v1_19_1.ChatTypeBoundNetwork chatType = wrapper.readChatTypeBoundNetwork();
|
||||
|
||||
return new ChatMessage_v1_19_3(senderUUID, index, signature, plainContent, timestamp, salt, lastSeenMessagesPacked, unsignedChatContent, filterMask, chatType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeChatMessage(@NotNull PacketWrapper<?> wrapper, @NotNull ChatMessage data) {
|
||||
ChatMessage_v1_19_3 newData = (ChatMessage_v1_19_3) data;
|
||||
wrapper.writeUUID(newData.getSenderUUID());
|
||||
wrapper.writeVarInt(newData.getIndex());
|
||||
wrapper.writeOptional(newData.getSignature(), PacketWrapper::writeBytes);
|
||||
wrapper.writeString(newData.getPlainContent());
|
||||
wrapper.writeTimestamp(newData.getTimestamp());
|
||||
wrapper.writeLong(newData.getSalt());
|
||||
wrapper.writeLastSeenMessagesPacked(newData.getLastSeenMessagesPacked());
|
||||
wrapper.writeOptional(newData.getUnsignedChatContent().orElse(null), PacketWrapper::writeComponent);
|
||||
wrapper.writeFilterMask(newData.getFilterMask());
|
||||
wrapper.writeChatTypeBoundNetwork(newData.getChatType());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.color;
|
||||
|
||||
import net.kyori.adventure.util.RGBLike;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Range;
|
||||
|
||||
public final class Color implements RGBLike {
|
||||
|
||||
private static final int BIT_MASK = 0xFF;
|
||||
|
||||
private final int red, green, blue;
|
||||
|
||||
public Color(@Range(from = 0L, to = 255L) int red, @Range(from = 0L, to = 255L) int green, @Range(from = 0L, to = 255L) int blue) {
|
||||
this.red = red;
|
||||
this.green = green;
|
||||
this.blue = blue;
|
||||
}
|
||||
|
||||
public Color(int rgb) {
|
||||
this((rgb >> 16) & BIT_MASK, (rgb >> 8) & BIT_MASK, rgb & BIT_MASK);
|
||||
}
|
||||
|
||||
public @NotNull Color withRed(@Range(from = 0L, to = 255L) int red) {
|
||||
return new Color(red, green, blue);
|
||||
}
|
||||
|
||||
public @NotNull Color withGreen(@Range(from = 0L, to = 255L) int green) {
|
||||
return new Color(red, green, blue);
|
||||
}
|
||||
|
||||
public @NotNull Color withBlue(@Range(from = 0L, to = 255L) int blue) {
|
||||
return new Color(red, green, blue);
|
||||
}
|
||||
|
||||
public int asRGB() {
|
||||
int rgb = red;
|
||||
rgb = (rgb << 8) + green;
|
||||
return (rgb << 8) + blue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Range(from = 0L, to = 255L) int red() {
|
||||
return red;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Range(from = 0L, to = 255L) int green() {
|
||||
return green;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Range(from = 0L, to = 255L) int blue() {
|
||||
return blue;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.color;
|
||||
|
||||
import net.kyori.adventure.util.RGBLike;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public enum DyeColor implements RGBLike {
|
||||
WHITE(new Color(0xf9fffe), new Color(0xffffff), new Color(0xf0f0f0), 8),
|
||||
|
||||
ORANGE(new Color(0xf9801d), new Color(0xff681f), new Color(0xeb8844), 15),
|
||||
|
||||
MAGENTA(new Color(0xc74ebd), new Color(0xff00ff), new Color(0xc354cd), 16),
|
||||
|
||||
LIGHT_BLUE(new Color(0x3ab3da), new Color(0x9ac0cd), new Color(0x6689d3), 17),
|
||||
|
||||
YELLOW(new Color(0xfed83d), new Color(0xffff00), new Color(0xdecf2a), 18),
|
||||
|
||||
LIME(new Color(0x80c71f), new Color(0xbfff00), new Color(0x41cd34), 19),
|
||||
|
||||
PINK(new Color(0xf38baa), new Color(0xff69b4), new Color(0xd88198), 20),
|
||||
|
||||
GRAY(new Color(0x474f52), new Color(0x808080), new Color(0x434343), 21),
|
||||
|
||||
LIGHT_GRAY(new Color(0x9d9d97), new Color(0xd3d3d3), new Color(0xababab), 22),
|
||||
|
||||
CYAN(new Color(0x169c9c), new Color(0xffff), new Color(0x287697), 23),
|
||||
|
||||
PURPLE(new Color(0x8932b8), new Color(0xa020f0), new Color(0x7b2fbe), 24),
|
||||
|
||||
BLUE(new Color(0x3c44aa), new Color(0xff), new Color(0x253192), 25),
|
||||
|
||||
BROWN(new Color(0x835432), new Color(0x8b4513), new Color(0x51301a), 26),
|
||||
|
||||
GREEN(new Color(0x5e7c16), new Color(0xff00), new Color(0x3b511a), 27),
|
||||
|
||||
RED(new Color(0xb02e26), new Color(0xff0000), new Color(0xb3312c), 28),
|
||||
|
||||
BLACK(new Color(0x1d1d21), new Color(0x0), new Color(0x1e1b1b), 29);
|
||||
|
||||
private final Color textureDiffuseColor;
|
||||
|
||||
private final Color textColor;
|
||||
|
||||
private final Color fireworkColor;
|
||||
|
||||
private final int mapColorId;
|
||||
|
||||
DyeColor(@NotNull Color textureDiffuseColor, @NotNull Color textColor,
|
||||
@NotNull Color fireworkColor, int mapColorId) {
|
||||
this.textureDiffuseColor = textureDiffuseColor;
|
||||
this.textColor = textColor;
|
||||
this.fireworkColor = fireworkColor;
|
||||
this.mapColorId = mapColorId;
|
||||
}
|
||||
|
||||
public @NotNull Color color() {
|
||||
return this.textureDiffuseColor;
|
||||
}
|
||||
|
||||
public @NotNull Color textColor() {
|
||||
return this.textColor;
|
||||
}
|
||||
|
||||
public @NotNull Color fireworkColor() {
|
||||
return this.fireworkColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int red() {
|
||||
return this.textureDiffuseColor.red();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int green() {
|
||||
return this.textureDiffuseColor.green();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int blue() {
|
||||
return this.textureDiffuseColor.blue();
|
||||
}
|
||||
|
||||
public int mapColorId() {
|
||||
return this.mapColorId;
|
||||
}
|
||||
}
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.component;
|
||||
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class ComponentPredicate implements Predicate<IComponentMap> {
|
||||
|
||||
private List<ComponentValue<?>> requiredComponents;
|
||||
|
||||
public ComponentPredicate(List<ComponentValue<?>> requiredComponents) {
|
||||
this.requiredComponents = requiredComponents;
|
||||
}
|
||||
|
||||
public static ComponentPredicate read(PacketWrapper<?> wrapper) {
|
||||
List<ComponentValue<?>> components = wrapper.readList(ComponentValue::read);
|
||||
return new ComponentPredicate(components);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, ComponentPredicate predicate) {
|
||||
wrapper.writeList(predicate.requiredComponents, ComponentValue::write);
|
||||
}
|
||||
|
||||
public static ComponentPredicate emptyPredicate() {
|
||||
return new ComponentPredicate(new ArrayList<>());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static ComponentPredicate fromPatches(PatchableComponentMap components) {
|
||||
Map<ComponentType<?>, Optional<?>> patches = components.getPatches();
|
||||
List<ComponentValue<?>> values = new ArrayList<>(patches.size());
|
||||
for (Map.Entry<ComponentType<?>, Optional<?>> patch : patches.entrySet()) {
|
||||
if (patch.getValue().isPresent()) {
|
||||
values.add(new ComponentValue<>(
|
||||
(ComponentType<Object>) patch.getKey(),
|
||||
patch.getValue().get()
|
||||
));
|
||||
}
|
||||
}
|
||||
return new ComponentPredicate(values);
|
||||
}
|
||||
|
||||
public PatchableComponentMap asPatches(StaticComponentMap base) {
|
||||
PatchableComponentMap patched = new PatchableComponentMap(base);
|
||||
for (ComponentValue<?> component : this.requiredComponents) {
|
||||
patched.set(component);
|
||||
}
|
||||
return patched;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(IComponentMap components) {
|
||||
for (ComponentValue<?> component : this.requiredComponents) {
|
||||
Optional<?> value = components.getOptional(component.getType());
|
||||
if (!value.isPresent() || !component.getValue().equals(value.get())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public List<ComponentValue<?>> getRequiredComponents() {
|
||||
return this.requiredComponents;
|
||||
}
|
||||
|
||||
public void setRequiredComponents(List<ComponentValue<?>> requiredComponents) {
|
||||
this.requiredComponents = requiredComponents;
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.component;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.mapper.MappedEntity;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
|
||||
public interface ComponentType<T> extends MappedEntity {
|
||||
|
||||
T read(PacketWrapper<?> wrapper);
|
||||
|
||||
void write(PacketWrapper<?> wrapper, T content);
|
||||
}
|
||||
+256
@@ -0,0 +1,256 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.component;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.color.DyeColor;
|
||||
import com.github.retrooper.packetevents.protocol.component.builtin.item.ArmorTrim;
|
||||
import com.github.retrooper.packetevents.protocol.component.builtin.item.BannerLayers;
|
||||
import com.github.retrooper.packetevents.protocol.component.builtin.item.BundleContents;
|
||||
import com.github.retrooper.packetevents.protocol.component.builtin.item.ChargedProjectiles;
|
||||
import com.github.retrooper.packetevents.protocol.component.builtin.item.DebugStickState;
|
||||
import com.github.retrooper.packetevents.protocol.component.builtin.item.FireworkExplosion;
|
||||
import com.github.retrooper.packetevents.protocol.component.builtin.item.FoodProperties;
|
||||
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemAdventurePredicate;
|
||||
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemAttributeModifiers;
|
||||
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemBees;
|
||||
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemBlockStateProperties;
|
||||
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemContainerContents;
|
||||
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemContainerLoot;
|
||||
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemDyeColor;
|
||||
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemEnchantments;
|
||||
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemFireworks;
|
||||
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemLock;
|
||||
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemLore;
|
||||
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemMapDecorations;
|
||||
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemMapPostProcessingState;
|
||||
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemPotionContents;
|
||||
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemProfile;
|
||||
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemRarity;
|
||||
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemRecipes;
|
||||
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemTool;
|
||||
import com.github.retrooper.packetevents.protocol.component.builtin.item.LodestoneTracker;
|
||||
import com.github.retrooper.packetevents.protocol.component.builtin.item.PotDecorations;
|
||||
import com.github.retrooper.packetevents.protocol.component.builtin.item.SuspiciousStewEffects;
|
||||
import com.github.retrooper.packetevents.protocol.component.builtin.item.WritableBookContent;
|
||||
import com.github.retrooper.packetevents.protocol.component.builtin.item.WrittenBookContent;
|
||||
import com.github.retrooper.packetevents.protocol.item.instrument.Instrument;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
|
||||
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
import com.github.retrooper.packetevents.resources.ResourceLocation;
|
||||
import com.github.retrooper.packetevents.util.Dummy;
|
||||
import com.github.retrooper.packetevents.util.mappings.MappingHelper;
|
||||
import com.github.retrooper.packetevents.util.mappings.TypesBuilder;
|
||||
import com.github.retrooper.packetevents.util.mappings.TypesBuilderData;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class ComponentTypes {
|
||||
|
||||
private static final Map<String, ComponentType<?>> COMPONENT_TYPE_MAP = new HashMap<>();
|
||||
private static final Map<Byte, Map<Integer, ComponentType<?>>> COMPONENT_TYPE_ID_MAP = new HashMap<>();
|
||||
private static final TypesBuilder TYPES_BUILDER = new TypesBuilder("item/item_component_mappings");
|
||||
|
||||
public static <T> ComponentType<T> define(String key) {
|
||||
return define(key, null, null);
|
||||
}
|
||||
|
||||
public static <T> ComponentType<T> define(String key, @Nullable Reader<T> reader, @Nullable Writer<T> writer) {
|
||||
TypesBuilderData data = TYPES_BUILDER.define(key);
|
||||
ComponentType<T> type = new ComponentType<T>() {
|
||||
@Override
|
||||
public T read(PacketWrapper<?> wrapper) {
|
||||
return reader == null ? null : reader.apply(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(PacketWrapper<?> wrapper, T content) {
|
||||
if (writer != null) {
|
||||
writer.accept(wrapper, content);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getName() {
|
||||
return data.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId(ClientVersion version) {
|
||||
return MappingHelper.getId(version, TYPES_BUILDER, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof ComponentType<?>) {
|
||||
return this.getName().equals(((ComponentType<?>) obj).getName());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Component[" + this.getName() + "]";
|
||||
}
|
||||
};
|
||||
|
||||
MappingHelper.registerMapping(TYPES_BUILDER, COMPONENT_TYPE_MAP, COMPONENT_TYPE_ID_MAP, type);
|
||||
return type;
|
||||
}
|
||||
|
||||
// with key
|
||||
public static ComponentType<?> getByName(String name) {
|
||||
return COMPONENT_TYPE_MAP.get(name);
|
||||
}
|
||||
|
||||
public static ComponentType<?> getById(ClientVersion version, int id) {
|
||||
int index = TYPES_BUILDER.getDataIndex(version);
|
||||
Map<Integer, ComponentType<?>> idMap = COMPONENT_TYPE_ID_MAP.get((byte) index);
|
||||
return idMap.get(id);
|
||||
}
|
||||
|
||||
// item component types
|
||||
public static final ComponentType<NBTCompound> CUSTOM_DATA = define("custom_data",
|
||||
PacketWrapper::readNBT, PacketWrapper::writeNBT);
|
||||
public static final ComponentType<Integer> MAX_STACK_SIZE = define("max_stack_size",
|
||||
PacketWrapper::readVarInt, PacketWrapper::writeVarInt);
|
||||
public static final ComponentType<Integer> MAX_DAMAGE = define("max_damage",
|
||||
PacketWrapper::readVarInt, PacketWrapper::writeVarInt);
|
||||
public static final ComponentType<Integer> DAMAGE = define("damage",
|
||||
PacketWrapper::readVarInt, PacketWrapper::writeVarInt);
|
||||
public static final ComponentType<Boolean> UNBREAKABLE = define("unbreakable",
|
||||
PacketWrapper::readBoolean, PacketWrapper::writeBoolean);
|
||||
public static final ComponentType<Component> CUSTOM_NAME = define("custom_name",
|
||||
PacketWrapper::readComponent, PacketWrapper::writeComponent);
|
||||
public static final ComponentType<Component> ITEM_NAME = define("item_name",
|
||||
PacketWrapper::readComponent, PacketWrapper::writeComponent);
|
||||
public static final ComponentType<ItemLore> LORE = define("lore",
|
||||
ItemLore::read, ItemLore::write);
|
||||
public static final ComponentType<ItemRarity> RARITY = define("rarity",
|
||||
wrapper -> wrapper.readEnum(ItemRarity.values()), PacketWrapper::writeEnum);
|
||||
public static final ComponentType<ItemEnchantments> ENCHANTMENTS = define("enchantments",
|
||||
ItemEnchantments::read, ItemEnchantments::write);
|
||||
public static final ComponentType<ItemAdventurePredicate> CAN_PLACE_ON = define("can_place_on",
|
||||
ItemAdventurePredicate::read, ItemAdventurePredicate::write);
|
||||
public static final ComponentType<ItemAdventurePredicate> CAN_BREAK = define("can_break",
|
||||
ItemAdventurePredicate::read, ItemAdventurePredicate::write);
|
||||
public static final ComponentType<ItemAttributeModifiers> ATTRIBUTE_MODIFIERS = define("attribute_modifiers",
|
||||
ItemAttributeModifiers::read, ItemAttributeModifiers::write);
|
||||
public static final ComponentType<Integer> CUSTOM_MODEL_DATA = define("custom_model_data",
|
||||
PacketWrapper::readVarInt, PacketWrapper::writeVarInt);
|
||||
public static final ComponentType<Dummy> HIDE_ADDITIONAL_TOOLTIP = define("hide_additional_tooltip",
|
||||
Dummy::dummyRead, Dummy::dummyWrite);
|
||||
public static final ComponentType<Dummy> HIDE_TOOLTIP = define("hide_tooltip",
|
||||
Dummy::dummyRead, Dummy::dummyWrite);
|
||||
public static final ComponentType<Integer> REPAIR_COST = define("repair_cost",
|
||||
PacketWrapper::readVarInt, PacketWrapper::writeVarInt);
|
||||
public static final ComponentType<Dummy> CREATIVE_SLOT_LOCK = define("creative_slot_lock",
|
||||
Dummy::dummyRead, Dummy::dummyWrite);
|
||||
public static final ComponentType<Boolean> ENCHANTMENT_GLINT_OVERRIDE = define("enchantment_glint_override",
|
||||
PacketWrapper::readBoolean, PacketWrapper::writeBoolean);
|
||||
public static final ComponentType<Dummy> INTANGIBLE_PROJECTILE = define("intangible_projectile",
|
||||
Dummy::dummyReadNbt, Dummy::dummyWriteNbt);
|
||||
public static final ComponentType<FoodProperties> FOOD = define("food",
|
||||
FoodProperties::read, FoodProperties::write);
|
||||
public static final ComponentType<Dummy> FIRE_RESISTANT = define("fire_resistant",
|
||||
Dummy::dummyRead, Dummy::dummyWrite);
|
||||
public static final ComponentType<ItemTool> TOOL = define("tool",
|
||||
ItemTool::read, ItemTool::write);
|
||||
public static final ComponentType<ItemEnchantments> STORED_ENCHANTMENTS = define("stored_enchantments",
|
||||
ItemEnchantments::read, ItemEnchantments::write);
|
||||
public static final ComponentType<ItemDyeColor> DYED_COLOR = define("dyed_color",
|
||||
ItemDyeColor::read, ItemDyeColor::write);
|
||||
public static final ComponentType<Integer> MAP_COLOR = define("map_color",
|
||||
PacketWrapper::readInt, PacketWrapper::writeInt);
|
||||
public static final ComponentType<Integer> MAP_ID = define("map_id",
|
||||
PacketWrapper::readVarInt, PacketWrapper::writeVarInt);
|
||||
public static final ComponentType<ItemMapDecorations> MAP_DECORATIONS = define("map_decorations",
|
||||
ItemMapDecorations::read, ItemMapDecorations::write);
|
||||
public static final ComponentType<ItemMapPostProcessingState> MAP_POST_PROCESSING = define("map_post_processing",
|
||||
wrapper -> wrapper.readEnum(ItemMapPostProcessingState.values()), PacketWrapper::writeEnum);
|
||||
public static final ComponentType<ChargedProjectiles> CHARGED_PROJECTILES = define("charged_projectiles",
|
||||
ChargedProjectiles::read, ChargedProjectiles::write);
|
||||
public static final ComponentType<BundleContents> BUNDLE_CONTENTS = define("bundle_contents",
|
||||
BundleContents::read, BundleContents::write);
|
||||
public static final ComponentType<ItemPotionContents> POTION_CONTENTS = define("potion_contents",
|
||||
ItemPotionContents::read, ItemPotionContents::write);
|
||||
public static final ComponentType<SuspiciousStewEffects> SUSPICIOUS_STEW_EFFECTS = define("suspicious_stew_effects",
|
||||
SuspiciousStewEffects::read, SuspiciousStewEffects::write);
|
||||
public static final ComponentType<WritableBookContent> WRITABLE_BOOK_CONTENT = define("writable_book_content",
|
||||
WritableBookContent::read, WritableBookContent::write);
|
||||
public static final ComponentType<WrittenBookContent> WRITTEN_BOOK_CONTENT = define("written_book_content",
|
||||
WrittenBookContent::read, WrittenBookContent::write);
|
||||
public static final ComponentType<ArmorTrim> TRIM = define("trim",
|
||||
ArmorTrim::read, ArmorTrim::write);
|
||||
public static final ComponentType<DebugStickState> DEBUG_STICK_STATE = define("debug_stick_state",
|
||||
DebugStickState::read, DebugStickState::write);
|
||||
public static final ComponentType<NBTCompound> ENTITY_DATA = define("entity_data",
|
||||
PacketWrapper::readNBT, PacketWrapper::writeNBT);
|
||||
public static final ComponentType<NBTCompound> BUCKET_ENTITY_DATA = define("bucket_entity_data",
|
||||
PacketWrapper::readNBT, PacketWrapper::writeNBT);
|
||||
public static final ComponentType<NBTCompound> BLOCK_ENTITY_DATA = define("block_entity_data",
|
||||
PacketWrapper::readNBT, PacketWrapper::writeNBT);
|
||||
public static final ComponentType<Instrument> INSTRUMENT = define("instrument",
|
||||
Instrument::read, Instrument::write);
|
||||
public static final ComponentType<Integer> OMINOUS_BOTTLE_AMPLIFIER = define("ominous_bottle_amplifier",
|
||||
PacketWrapper::readVarInt, PacketWrapper::writeVarInt);
|
||||
public static final ComponentType<ItemRecipes> RECIPES = define("recipes",
|
||||
ItemRecipes::read, ItemRecipes::write);
|
||||
public static final ComponentType<LodestoneTracker> LODESTONE_TRACKER = define("lodestone_tracker",
|
||||
LodestoneTracker::read, LodestoneTracker::write);
|
||||
public static final ComponentType<FireworkExplosion> FIREWORK_EXPLOSION = define("firework_explosion",
|
||||
FireworkExplosion::read, FireworkExplosion::write);
|
||||
public static final ComponentType<ItemFireworks> FIREWORKS = define("fireworks",
|
||||
ItemFireworks::read, ItemFireworks::write);
|
||||
public static final ComponentType<ItemProfile> PROFILE = define("profile",
|
||||
ItemProfile::read, ItemProfile::write);
|
||||
public static final ComponentType<ResourceLocation> NOTE_BLOCK_SOUND = define("note_block_sound",
|
||||
PacketWrapper::readIdentifier, PacketWrapper::writeIdentifier);
|
||||
public static final ComponentType<BannerLayers> BANNER_PATTERNS = define("banner_patterns",
|
||||
BannerLayers::read, BannerLayers::write);
|
||||
public static final ComponentType<DyeColor> BASE_COLOR = define("base_color",
|
||||
wrapper -> wrapper.readEnum(DyeColor.values()), PacketWrapper::writeEnum);
|
||||
public static final ComponentType<PotDecorations> POT_DECORATIONS = define("pot_decorations",
|
||||
PotDecorations::read, PotDecorations::write);
|
||||
public static final ComponentType<ItemContainerContents> CONTAINER = define("container",
|
||||
ItemContainerContents::read, ItemContainerContents::write);
|
||||
public static final ComponentType<ItemBlockStateProperties> BLOCK_STATE = define("block_state",
|
||||
ItemBlockStateProperties::read, ItemBlockStateProperties::write);
|
||||
public static final ComponentType<ItemBees> BEES = define("bees",
|
||||
ItemBees::read, ItemBees::write);
|
||||
public static final ComponentType<ItemLock> LOCK = define("lock",
|
||||
ItemLock::read, ItemLock::write);
|
||||
public static final ComponentType<ItemContainerLoot> CONTAINER_LOOT = define("container_loot",
|
||||
ItemContainerLoot::read, ItemContainerLoot::write);
|
||||
|
||||
static {
|
||||
TYPES_BUILDER.unloadFileMappings();
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Reader<T> extends Function<PacketWrapper<?>, T> {}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Writer<T> extends BiConsumer<PacketWrapper<?>, T> {}
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.component;
|
||||
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public final class ComponentValue<T> {
|
||||
|
||||
private final ComponentType<T> type;
|
||||
private final T value;
|
||||
|
||||
public ComponentValue(ComponentType<T> type, T value) {
|
||||
this.type = type;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static ComponentValue<?> read(PacketWrapper<?> wrapper) {
|
||||
ComponentType<?> type = wrapper.readMappedEntity(ComponentTypes::getById);
|
||||
return read0(wrapper, type);
|
||||
}
|
||||
|
||||
private static <T> ComponentValue<T> read0(PacketWrapper<?> wrapper, ComponentType<T> type) {
|
||||
// additional method required here for proper handling because of how generics work
|
||||
return new ComponentValue<>(type, type.read(wrapper));
|
||||
}
|
||||
|
||||
public static <T> void write(PacketWrapper<?> wrapper, ComponentValue<T> value) {
|
||||
wrapper.writeMappedEntity(value.type);
|
||||
value.type.write(wrapper, value.value);
|
||||
}
|
||||
|
||||
public ComponentType<T> getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public T getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof ComponentValue)) return false;
|
||||
ComponentValue<?> that = (ComponentValue<?>) obj;
|
||||
if (!this.type.equals(that.type)) return false;
|
||||
return this.value.equals(that.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.type, this.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ComponentValue{type=" + this.type + ", value=" + this.value + '}';
|
||||
}
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.component;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface IComponentMap {
|
||||
|
||||
default <T> Optional<T> getOptional(ComponentType<T> type) {
|
||||
return Optional.ofNullable(this.get(type));
|
||||
}
|
||||
|
||||
boolean has(ComponentType<?> type);
|
||||
|
||||
@Contract("_, !null -> !null")
|
||||
default <T> @Nullable T getOr(ComponentType<T> type, @Nullable T otherValue) {
|
||||
T value = this.get(type);
|
||||
if (value != null) {
|
||||
return value;
|
||||
}
|
||||
return otherValue;
|
||||
}
|
||||
|
||||
<T> @Nullable T get(ComponentType<T> type);
|
||||
|
||||
default <T> void set(ComponentValue<T> component) {
|
||||
this.set(component.getType(), component.getValue());
|
||||
}
|
||||
|
||||
default <T> void set(ComponentType<T> type, @Nullable T value) {
|
||||
this.set(type, Optional.ofNullable(value));
|
||||
}
|
||||
|
||||
default <T> void unset(ComponentType<T> type) {
|
||||
this.set(type, Optional.empty());
|
||||
}
|
||||
|
||||
<T> void set(ComponentType<T> type, Optional<T> value);
|
||||
}
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.component;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
public class PatchableComponentMap implements IComponentMap {
|
||||
|
||||
public static final PatchableComponentMap EMPTY = new PatchableComponentMap(
|
||||
Collections.emptyMap(), Collections.emptyMap());
|
||||
|
||||
private final Map<ComponentType<?>, ?> base;
|
||||
private final Map<ComponentType<?>, Optional<?>> patches;
|
||||
|
||||
public PatchableComponentMap(StaticComponentMap base) {
|
||||
this(base.getDelegate(), new HashMap<>());
|
||||
}
|
||||
|
||||
public PatchableComponentMap(Map<ComponentType<?>, ?> base) {
|
||||
this(base, new HashMap<>());
|
||||
}
|
||||
|
||||
public PatchableComponentMap(
|
||||
StaticComponentMap base,
|
||||
Map<ComponentType<?>, Optional<?>> patches
|
||||
) {
|
||||
this(base.getDelegate(), patches);
|
||||
}
|
||||
|
||||
public PatchableComponentMap(
|
||||
Map<ComponentType<?>, ?> base,
|
||||
Map<ComponentType<?>, Optional<?>> patches
|
||||
) {
|
||||
this.base = Collections.unmodifiableMap(new HashMap<>(base));
|
||||
this.patches = patches;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked") // no
|
||||
@Override
|
||||
public <T> @Nullable T get(ComponentType<T> type) {
|
||||
Optional<?> patched = this.patches.get(type);
|
||||
if (patched != null) {
|
||||
return (T) patched.orElse(null);
|
||||
}
|
||||
return (T) this.base.get(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void set(ComponentType<T> type, Optional<T> value) {
|
||||
Object baseVal = this.base.get(type);
|
||||
T newVal = value.orElse(null);
|
||||
if (Objects.equals(baseVal, newVal)) {
|
||||
this.patches.remove(type); // fallback to base
|
||||
} else {
|
||||
this.patches.put(type, value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean has(ComponentType<?> type) {
|
||||
Optional<?> patched = this.patches.get(type);
|
||||
return patched != null ? patched.isPresent() : this.base.containsKey(type);
|
||||
}
|
||||
|
||||
public PatchableComponentMap copy() {
|
||||
return new PatchableComponentMap(this.base, new HashMap<>(this.patches));
|
||||
}
|
||||
|
||||
public Map<ComponentType<?>, ?> getBase() {
|
||||
return this.base;
|
||||
}
|
||||
|
||||
public Map<ComponentType<?>, Optional<?>> getPatches() {
|
||||
return this.patches;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PatchableComponentMap{base=" + this.base + ", patches=" + this.patches + '}';
|
||||
}
|
||||
}
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.component;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemAttributeModifiers;
|
||||
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemEnchantments;
|
||||
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemLore;
|
||||
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemRarity;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class StaticComponentMap implements IComponentMap {
|
||||
|
||||
public static final StaticComponentMap EMPTY = new StaticComponentMap(Collections.emptyMap());
|
||||
public static final StaticComponentMap SHARED_ITEM_COMPONENTS = builder()
|
||||
.set(ComponentTypes.MAX_STACK_SIZE, 64)
|
||||
.set(ComponentTypes.LORE, ItemLore.EMPTY)
|
||||
.set(ComponentTypes.ENCHANTMENTS, ItemEnchantments.EMPTY)
|
||||
.set(ComponentTypes.REPAIR_COST, 0)
|
||||
.set(ComponentTypes.ATTRIBUTE_MODIFIERS, ItemAttributeModifiers.EMPTY)
|
||||
.set(ComponentTypes.RARITY, ItemRarity.COMMON)
|
||||
.build();
|
||||
|
||||
private final boolean empty;
|
||||
private final Map<ComponentType<?>, ?> delegate;
|
||||
|
||||
public StaticComponentMap(Map<ComponentType<?>, ?> delegate) {
|
||||
this.empty = delegate.isEmpty();
|
||||
this.delegate = this.empty ? Collections.emptyMap()
|
||||
: Collections.unmodifiableMap(new HashMap<>(delegate));
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean has(ComponentType<?> type) {
|
||||
return !this.empty && this.delegate.containsKey(type);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked") // no
|
||||
@Override
|
||||
public <T> @Nullable T get(ComponentType<T> type) {
|
||||
return this.empty ? null : (T) this.delegate.get(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void set(ComponentType<T> type, Optional<T> value) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public StaticComponentMap merge(StaticComponentMap prioritizedMap) {
|
||||
return builder().setAll(this).setAll(prioritizedMap).build();
|
||||
}
|
||||
|
||||
public Map<ComponentType<?>, ?> getDelegate() {
|
||||
return this.delegate;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return this.empty;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private final Map<ComponentType<?>, Object> map = new HashMap<>();
|
||||
|
||||
public Builder() {
|
||||
}
|
||||
|
||||
public StaticComponentMap build() {
|
||||
return new StaticComponentMap(this.map);
|
||||
}
|
||||
|
||||
public Builder setAll(StaticComponentMap map) {
|
||||
return this.setAll(map.getDelegate());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Builder setAll(Map<ComponentType<?>, ?> map) {
|
||||
for (Map.Entry<ComponentType<?>, ?> entry : map.entrySet()) {
|
||||
this.set((ComponentType<Object>) entry.getKey(), entry.getValue());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T> Builder set(ComponentType<T> type, Optional<T> value) {
|
||||
return this.set(type, value.orElse(null));
|
||||
}
|
||||
|
||||
public <T> Builder set(ComponentType<T> type, @Nullable T value) {
|
||||
if (value == null) {
|
||||
this.map.remove(type);
|
||||
} else {
|
||||
this.map.put(type, value);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.component.builtin.item;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.item.trimmaterial.TrimMaterial;
|
||||
import com.github.retrooper.packetevents.protocol.item.trimpattern.TrimPattern;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class ArmorTrim {
|
||||
|
||||
private TrimMaterial material;
|
||||
private TrimPattern pattern;
|
||||
private boolean showInTooltip;
|
||||
|
||||
public ArmorTrim(TrimMaterial material, TrimPattern pattern, boolean showInTooltip) {
|
||||
this.material = material;
|
||||
this.pattern = pattern;
|
||||
this.showInTooltip = showInTooltip;
|
||||
}
|
||||
|
||||
public static ArmorTrim read(PacketWrapper<?> wrapper) {
|
||||
TrimMaterial material = TrimMaterial.read(wrapper);
|
||||
TrimPattern pattern = TrimPattern.read(wrapper);
|
||||
boolean showInTooltip = wrapper.readBoolean();
|
||||
return new ArmorTrim(material, pattern, showInTooltip);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, ArmorTrim trim) {
|
||||
TrimMaterial.write(wrapper, trim.material);
|
||||
TrimPattern.write(wrapper, trim.pattern);
|
||||
wrapper.writeBoolean(trim.showInTooltip);
|
||||
}
|
||||
|
||||
public TrimMaterial getMaterial() {
|
||||
return this.material;
|
||||
}
|
||||
|
||||
public void setMaterial(TrimMaterial material) {
|
||||
this.material = material;
|
||||
}
|
||||
|
||||
public TrimPattern getPattern() {
|
||||
return this.pattern;
|
||||
}
|
||||
|
||||
public void setPattern(TrimPattern pattern) {
|
||||
this.pattern = pattern;
|
||||
}
|
||||
|
||||
public boolean isShowInTooltip() {
|
||||
return this.showInTooltip;
|
||||
}
|
||||
|
||||
public void setShowInTooltip(boolean showInTooltip) {
|
||||
this.showInTooltip = showInTooltip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof ArmorTrim)) return false;
|
||||
ArmorTrim armorTrim = (ArmorTrim) obj;
|
||||
if (this.showInTooltip != armorTrim.showInTooltip) return false;
|
||||
if (!this.material.equals(armorTrim.material)) return false;
|
||||
return this.pattern.equals(armorTrim.pattern);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.material, this.pattern, this.showInTooltip);
|
||||
}
|
||||
}
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.component.builtin.item;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.color.DyeColor;
|
||||
import com.github.retrooper.packetevents.protocol.item.banner.BannerPattern;
|
||||
import com.github.retrooper.packetevents.protocol.item.banner.BannerPatterns;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class BannerLayers {
|
||||
|
||||
private List<Layer> layers;
|
||||
|
||||
public BannerLayers(List<Layer> layers) {
|
||||
this.layers = layers;
|
||||
}
|
||||
|
||||
public static BannerLayers read(PacketWrapper<?> wrapper) {
|
||||
List<Layer> layers = wrapper.readList(Layer::read);
|
||||
return new BannerLayers(layers);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, BannerLayers patterns) {
|
||||
wrapper.writeList(patterns.layers, Layer::write);
|
||||
}
|
||||
|
||||
public void addLayer(Layer layer) {
|
||||
this.layers.add(layer);
|
||||
}
|
||||
|
||||
public List<Layer> getLayers() {
|
||||
return this.layers;
|
||||
}
|
||||
|
||||
public void setLayers(List<Layer> layers) {
|
||||
this.layers = layers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof BannerLayers)) return false;
|
||||
BannerLayers that = (BannerLayers) obj;
|
||||
return this.layers.equals(that.layers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(this.layers);
|
||||
}
|
||||
|
||||
public static class Layer {
|
||||
|
||||
private BannerPattern pattern;
|
||||
private DyeColor color;
|
||||
|
||||
public Layer(BannerPattern pattern, DyeColor color) {
|
||||
this.pattern = pattern;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public static Layer read(PacketWrapper<?> wrapper) {
|
||||
BannerPattern pattern = wrapper.readMappedEntityOrDirect(
|
||||
BannerPatterns::getById, BannerPattern::readDirect);
|
||||
DyeColor color = wrapper.readEnum(DyeColor.values());
|
||||
return new Layer(pattern, color);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, Layer layer) {
|
||||
wrapper.writeMappedEntityOrDirect(layer.pattern, BannerPattern::writeDirect);
|
||||
wrapper.writeEnum(layer.color);
|
||||
}
|
||||
|
||||
public BannerPattern getPattern() {
|
||||
return this.pattern;
|
||||
}
|
||||
|
||||
public void setPattern(BannerPattern pattern) {
|
||||
this.pattern = pattern;
|
||||
}
|
||||
|
||||
public DyeColor getColor() {
|
||||
return this.color;
|
||||
}
|
||||
|
||||
public void setColor(DyeColor color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof Layer)) return false;
|
||||
Layer layer = (Layer) obj;
|
||||
if (!this.pattern.equals(layer.pattern)) return false;
|
||||
return this.color == layer.color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.pattern, this.color);
|
||||
}
|
||||
}
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.component.builtin.item;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.item.ItemStack;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class BundleContents {
|
||||
|
||||
private List<ItemStack> items;
|
||||
|
||||
public BundleContents(List<ItemStack> items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
public static BundleContents read(PacketWrapper<?> wrapper) {
|
||||
List<ItemStack> items = wrapper.readList(PacketWrapper::readPresentItemStack);
|
||||
return new BundleContents(items);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, BundleContents projectiles) {
|
||||
wrapper.writeList(projectiles.items, PacketWrapper::writePresentItemStack);
|
||||
}
|
||||
|
||||
public void addItem(ItemStack itemStack) {
|
||||
this.items.add(itemStack);
|
||||
}
|
||||
|
||||
public List<ItemStack> getItems() {
|
||||
return this.items;
|
||||
}
|
||||
|
||||
public void setItems(List<ItemStack> items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof BundleContents)) return false;
|
||||
BundleContents that = (BundleContents) obj;
|
||||
return this.items.equals(that.items);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(this.items);
|
||||
}
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.component.builtin.item;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.item.ItemStack;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ChargedProjectiles {
|
||||
|
||||
private List<ItemStack> items;
|
||||
|
||||
public ChargedProjectiles(List<ItemStack> items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
public static ChargedProjectiles read(PacketWrapper<?> wrapper) {
|
||||
List<ItemStack> items = wrapper.readList(PacketWrapper::readPresentItemStack);
|
||||
return new ChargedProjectiles(items);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, ChargedProjectiles projectiles) {
|
||||
wrapper.writeList(projectiles.items, PacketWrapper::writePresentItemStack);
|
||||
}
|
||||
|
||||
public void addItem(ItemStack itemStack) {
|
||||
this.items.add(itemStack);
|
||||
}
|
||||
|
||||
public List<ItemStack> getItems() {
|
||||
return this.items;
|
||||
}
|
||||
|
||||
public void setItems(List<ItemStack> items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof ChargedProjectiles)) return false;
|
||||
ChargedProjectiles that = (ChargedProjectiles) obj;
|
||||
return this.items.equals(that.items);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(this.items);
|
||||
}
|
||||
}
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.component.builtin.item;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBT;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTString;
|
||||
import com.github.retrooper.packetevents.protocol.world.states.type.StateType;
|
||||
import com.github.retrooper.packetevents.protocol.world.states.type.StateTypes;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class DebugStickState {
|
||||
|
||||
private Map<StateType, String> properties;
|
||||
|
||||
public DebugStickState(Map<StateType, String> properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public static DebugStickState read(PacketWrapper<?> wrapper) {
|
||||
NBTCompound compound = wrapper.readNBT();
|
||||
Map<StateType, String> properties = new HashMap<>(compound.size());
|
||||
for (Map.Entry<String, NBT> tag : compound.getTags().entrySet()) {
|
||||
StateType stateType = StateTypes.getByName(tag.getKey());
|
||||
String property = ((NBTString) tag.getValue()).getValue();
|
||||
properties.put(stateType, property);
|
||||
}
|
||||
return new DebugStickState(properties);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, DebugStickState state) {
|
||||
NBTCompound compound = new NBTCompound();
|
||||
for (Map.Entry<StateType, String> property : state.properties.entrySet()) {
|
||||
compound.setTag(property.getKey().getName(),
|
||||
new NBTString(property.getValue()));
|
||||
}
|
||||
wrapper.writeNBT(compound);
|
||||
}
|
||||
|
||||
public @Nullable String getProperty(StateType stateType) {
|
||||
return this.properties.get(stateType);
|
||||
}
|
||||
|
||||
public void setProperty(StateType stateType, @Nullable String property) {
|
||||
if (property != null) {
|
||||
this.properties.put(stateType, property);
|
||||
} else {
|
||||
this.properties.remove(stateType);
|
||||
}
|
||||
}
|
||||
|
||||
public Map<StateType, String> getProperties() {
|
||||
return this.properties;
|
||||
}
|
||||
|
||||
public void setProperties(Map<StateType, String> properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof DebugStickState)) return false;
|
||||
DebugStickState that = (DebugStickState) o;
|
||||
return this.properties.equals(that.properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(this.properties);
|
||||
}
|
||||
}
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.component.builtin.item;
|
||||
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class FireworkExplosion {
|
||||
|
||||
private Shape shape;
|
||||
private List<Integer> colors;
|
||||
private List<Integer> fadeColors;
|
||||
private boolean hasTrail;
|
||||
private boolean hasTwinkle;
|
||||
|
||||
public FireworkExplosion(
|
||||
Shape shape, List<Integer> colors, List<Integer> fadeColors,
|
||||
boolean hasTrail, boolean hasTwinkle
|
||||
) {
|
||||
this.shape = shape;
|
||||
this.colors = colors;
|
||||
this.fadeColors = fadeColors;
|
||||
this.hasTrail = hasTrail;
|
||||
this.hasTwinkle = hasTwinkle;
|
||||
}
|
||||
|
||||
public static FireworkExplosion read(PacketWrapper<?> wrapper) {
|
||||
Shape shape = wrapper.readEnum(Shape.values());
|
||||
List<Integer> colors = wrapper.readList(PacketWrapper::readInt);
|
||||
List<Integer> fadeColors = wrapper.readList(PacketWrapper::readInt);
|
||||
boolean hasTrail = wrapper.readBoolean();
|
||||
boolean hasTwinkle = wrapper.readBoolean();
|
||||
return new FireworkExplosion(shape, colors, fadeColors, hasTrail, hasTwinkle);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, FireworkExplosion explosion) {
|
||||
wrapper.writeEnum(explosion.shape);
|
||||
wrapper.writeList(explosion.colors, PacketWrapper::writeInt);
|
||||
wrapper.writeList(explosion.fadeColors, PacketWrapper::writeInt);
|
||||
wrapper.writeBoolean(explosion.hasTrail);
|
||||
wrapper.writeBoolean(explosion.hasTwinkle);
|
||||
}
|
||||
|
||||
public Shape getShape() {
|
||||
return this.shape;
|
||||
}
|
||||
|
||||
public void setShape(Shape shape) {
|
||||
this.shape = shape;
|
||||
}
|
||||
|
||||
public void addColor(int color) {
|
||||
this.colors.add(color);
|
||||
}
|
||||
|
||||
public List<Integer> getColors() {
|
||||
return this.colors;
|
||||
}
|
||||
|
||||
public void setColors(List<Integer> colors) {
|
||||
this.colors = colors;
|
||||
}
|
||||
|
||||
public void addFadeColor(int color) {
|
||||
this.fadeColors.add(color);
|
||||
}
|
||||
|
||||
public List<Integer> getFadeColors() {
|
||||
return this.fadeColors;
|
||||
}
|
||||
|
||||
public void setFadeColors(List<Integer> fadeColors) {
|
||||
this.fadeColors = fadeColors;
|
||||
}
|
||||
|
||||
public boolean isHasTrail() {
|
||||
return this.hasTrail;
|
||||
}
|
||||
|
||||
public void setHasTrail(boolean hasTrail) {
|
||||
this.hasTrail = hasTrail;
|
||||
}
|
||||
|
||||
public boolean isHasTwinkle() {
|
||||
return this.hasTwinkle;
|
||||
}
|
||||
|
||||
public void setHasTwinkle(boolean hasTwinkle) {
|
||||
this.hasTwinkle = hasTwinkle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof FireworkExplosion)) return false;
|
||||
FireworkExplosion that = (FireworkExplosion) obj;
|
||||
if (this.hasTrail != that.hasTrail) return false;
|
||||
if (this.hasTwinkle != that.hasTwinkle) return false;
|
||||
if (this.shape != that.shape) return false;
|
||||
if (!this.colors.equals(that.colors)) return false;
|
||||
return this.fadeColors.equals(that.fadeColors);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.shape, this.colors, this.fadeColors, this.hasTrail, this.hasTwinkle);
|
||||
}
|
||||
|
||||
public enum Shape {
|
||||
SMALL_BALL,
|
||||
LARGE_BALL,
|
||||
STAR,
|
||||
CREEPER,
|
||||
BURST,
|
||||
}
|
||||
}
|
||||
+174
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.component.builtin.item;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.potion.PotionEffect;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class FoodProperties {
|
||||
|
||||
private int nutrition;
|
||||
private float saturation;
|
||||
private boolean canAlwaysEat;
|
||||
private float eatSeconds;
|
||||
private List<PossibleEffect> effects;
|
||||
|
||||
public FoodProperties(int nutrition, float saturation, boolean canAlwaysEat, float eatSeconds, List<PossibleEffect> effects) {
|
||||
this.nutrition = nutrition;
|
||||
this.saturation = saturation;
|
||||
this.canAlwaysEat = canAlwaysEat;
|
||||
this.eatSeconds = eatSeconds;
|
||||
this.effects = effects;
|
||||
}
|
||||
|
||||
public static FoodProperties read(PacketWrapper<?> wrapper) {
|
||||
int nutrition = wrapper.readVarInt();
|
||||
float saturation = wrapper.readFloat();
|
||||
boolean canAlwaysEat = wrapper.readBoolean();
|
||||
float eatSeconds = wrapper.readFloat();
|
||||
List<PossibleEffect> effects = wrapper.readList(PossibleEffect::read);
|
||||
return new FoodProperties(nutrition, saturation, canAlwaysEat, eatSeconds, effects);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, FoodProperties props) {
|
||||
wrapper.writeVarInt(props.nutrition);
|
||||
wrapper.writeFloat(props.saturation);
|
||||
wrapper.writeBoolean(props.canAlwaysEat);
|
||||
wrapper.writeFloat(props.eatSeconds);
|
||||
wrapper.writeList(props.effects, PossibleEffect::write);
|
||||
}
|
||||
|
||||
public int getNutrition() {
|
||||
return this.nutrition;
|
||||
}
|
||||
|
||||
public void setNutrition(int nutrition) {
|
||||
this.nutrition = nutrition;
|
||||
}
|
||||
|
||||
public float getSaturation() {
|
||||
return this.saturation;
|
||||
}
|
||||
|
||||
public void setSaturation(float saturation) {
|
||||
this.saturation = saturation;
|
||||
}
|
||||
|
||||
public boolean isCanAlwaysEat() {
|
||||
return this.canAlwaysEat;
|
||||
}
|
||||
|
||||
public void setCanAlwaysEat(boolean canAlwaysEat) {
|
||||
this.canAlwaysEat = canAlwaysEat;
|
||||
}
|
||||
|
||||
public float getEatSeconds() {
|
||||
return this.eatSeconds;
|
||||
}
|
||||
|
||||
public void setEatSeconds(float eatSeconds) {
|
||||
this.eatSeconds = eatSeconds;
|
||||
}
|
||||
|
||||
public void addEffect(PossibleEffect effect) {
|
||||
this.effects.add(effect);
|
||||
}
|
||||
|
||||
public List<PossibleEffect> getEffects() {
|
||||
return this.effects;
|
||||
}
|
||||
|
||||
public void setEffects(List<PossibleEffect> effects) {
|
||||
this.effects = effects;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof FoodProperties)) return false;
|
||||
FoodProperties that = (FoodProperties) obj;
|
||||
if (this.nutrition != that.nutrition) return false;
|
||||
if (Float.compare(that.saturation, this.saturation) != 0) return false;
|
||||
if (this.canAlwaysEat != that.canAlwaysEat) return false;
|
||||
if (Float.compare(that.eatSeconds, this.eatSeconds) != 0) return false;
|
||||
return this.effects.equals(that.effects);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.nutrition, this.saturation, this.canAlwaysEat, this.eatSeconds, this.effects);
|
||||
}
|
||||
|
||||
public static class PossibleEffect {
|
||||
|
||||
private PotionEffect effect;
|
||||
private float probability;
|
||||
|
||||
public PossibleEffect(PotionEffect effect, float probability) {
|
||||
this.effect = effect;
|
||||
this.probability = probability;
|
||||
}
|
||||
|
||||
public static PossibleEffect read(PacketWrapper<?> wrapper) {
|
||||
PotionEffect effect = PotionEffect.read(wrapper);
|
||||
float probability = wrapper.readFloat();
|
||||
return new PossibleEffect(effect, probability);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, PossibleEffect effect) {
|
||||
PotionEffect.write(wrapper, effect.effect);
|
||||
wrapper.writeFloat(effect.probability);
|
||||
}
|
||||
|
||||
public PotionEffect getEffect() {
|
||||
return this.effect;
|
||||
}
|
||||
|
||||
public void setEffect(PotionEffect effect) {
|
||||
this.effect = effect;
|
||||
}
|
||||
|
||||
public float getProbability() {
|
||||
return this.probability;
|
||||
}
|
||||
|
||||
public void setProbability(float probability) {
|
||||
this.probability = probability;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof PossibleEffect)) return false;
|
||||
PossibleEffect that = (PossibleEffect) obj;
|
||||
if (Float.compare(that.probability, this.probability) != 0) return false;
|
||||
return this.effect.equals(that.effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.effect, this.probability);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+329
@@ -0,0 +1,329 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.component.builtin.item;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.mapper.MappedEntitySet;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
|
||||
import com.github.retrooper.packetevents.protocol.world.states.type.StateType;
|
||||
import com.github.retrooper.packetevents.protocol.world.states.type.StateTypes;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
// why do I have to implement this mess, I just want to deserialize items
|
||||
public class ItemAdventurePredicate {
|
||||
|
||||
private List<BlockPredicate> predicates;
|
||||
private boolean showInTooltip;
|
||||
|
||||
public ItemAdventurePredicate(List<BlockPredicate> predicates, boolean showInTooltip) {
|
||||
this.predicates = predicates;
|
||||
this.showInTooltip = showInTooltip;
|
||||
}
|
||||
|
||||
public static ItemAdventurePredicate read(PacketWrapper<?> wrapper) {
|
||||
List<BlockPredicate> predicates = wrapper.readList(BlockPredicate::read);
|
||||
boolean showInTooltip = wrapper.readBoolean();
|
||||
return new ItemAdventurePredicate(predicates, showInTooltip);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, ItemAdventurePredicate predicate) {
|
||||
wrapper.writeList(predicate.predicates, BlockPredicate::write);
|
||||
wrapper.writeBoolean(predicate.showInTooltip);
|
||||
}
|
||||
|
||||
public void addPredicate(BlockPredicate predicate) {
|
||||
this.predicates.add(predicate);
|
||||
}
|
||||
|
||||
public List<BlockPredicate> getPredicates() {
|
||||
return this.predicates;
|
||||
}
|
||||
|
||||
public void setPredicates(List<BlockPredicate> predicates) {
|
||||
this.predicates = predicates;
|
||||
}
|
||||
|
||||
public boolean isShowInTooltip() {
|
||||
return this.showInTooltip;
|
||||
}
|
||||
|
||||
public void setShowInTooltip(boolean showInTooltip) {
|
||||
this.showInTooltip = showInTooltip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof ItemAdventurePredicate)) return false;
|
||||
ItemAdventurePredicate that = (ItemAdventurePredicate) obj;
|
||||
if (this.showInTooltip != that.showInTooltip) return false;
|
||||
return this.predicates.equals(that.predicates);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.predicates, this.showInTooltip);
|
||||
}
|
||||
|
||||
public static class BlockPredicate {
|
||||
|
||||
private @Nullable MappedEntitySet<StateType.Mapped> blocks;
|
||||
private @Nullable List<PropertyMatcher> properties;
|
||||
private @Nullable NBTCompound nbt;
|
||||
|
||||
public BlockPredicate(
|
||||
@Nullable MappedEntitySet<StateType.Mapped> blocks,
|
||||
@Nullable List<PropertyMatcher> properties,
|
||||
@Nullable NBTCompound nbt
|
||||
) {
|
||||
this.blocks = blocks;
|
||||
this.properties = properties;
|
||||
this.nbt = nbt;
|
||||
}
|
||||
|
||||
public static BlockPredicate read(PacketWrapper<?> wrapper) {
|
||||
MappedEntitySet<StateType.Mapped> blocks = wrapper.readOptional(
|
||||
ew -> MappedEntitySet.read(ew, StateTypes::getMappedById));
|
||||
List<PropertyMatcher> properties = wrapper.readList(PropertyMatcher::read);
|
||||
NBTCompound nbt = wrapper.readNBT();
|
||||
return new BlockPredicate(blocks, properties, nbt);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, BlockPredicate predicate) {
|
||||
wrapper.writeOptional(predicate.blocks, MappedEntitySet::write);
|
||||
wrapper.writeOptional(predicate.properties,
|
||||
(ew, val) -> ew.writeList(val, PropertyMatcher::write));
|
||||
wrapper.writeOptional(predicate.nbt, PacketWrapper::writeNBT);
|
||||
}
|
||||
|
||||
public @Nullable MappedEntitySet<StateType.Mapped> getBlocks() {
|
||||
return this.blocks;
|
||||
}
|
||||
|
||||
public void setBlocks(@Nullable MappedEntitySet<StateType.Mapped> blocks) {
|
||||
this.blocks = blocks;
|
||||
}
|
||||
|
||||
public void addProperty(PropertyMatcher propertyMatcher) {
|
||||
if (this.properties == null) {
|
||||
this.properties = new ArrayList<>(4);
|
||||
}
|
||||
this.properties.add(propertyMatcher);
|
||||
}
|
||||
|
||||
public @Nullable List<PropertyMatcher> getProperties() {
|
||||
return this.properties;
|
||||
}
|
||||
|
||||
public void setProperties(@Nullable List<PropertyMatcher> properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public @Nullable NBTCompound getNbt() {
|
||||
return this.nbt;
|
||||
}
|
||||
|
||||
public void setNbt(@Nullable NBTCompound nbt) {
|
||||
this.nbt = nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof BlockPredicate)) return false;
|
||||
BlockPredicate that = (BlockPredicate) obj;
|
||||
if (!Objects.equals(this.blocks, that.blocks)) return false;
|
||||
if (!Objects.equals(this.properties, that.properties)) return false;
|
||||
return Objects.equals(this.nbt, that.nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.blocks, this.properties, this.nbt);
|
||||
}
|
||||
}
|
||||
|
||||
public static class PropertyMatcher {
|
||||
|
||||
private String name;
|
||||
private ValueMatcher matcher;
|
||||
|
||||
public PropertyMatcher(String name, ValueMatcher matcher) {
|
||||
this.name = name;
|
||||
this.matcher = matcher;
|
||||
}
|
||||
|
||||
public static PropertyMatcher read(PacketWrapper<?> wrapper) {
|
||||
String name = wrapper.readString();
|
||||
ValueMatcher matcher = ValueMatcher.read(wrapper);
|
||||
return new PropertyMatcher(name, matcher);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, PropertyMatcher matcher) {
|
||||
wrapper.writeString(matcher.name);
|
||||
ValueMatcher.write(wrapper, matcher.matcher);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public ValueMatcher getMatcher() {
|
||||
return this.matcher;
|
||||
}
|
||||
|
||||
public void setMatcher(ValueMatcher matcher) {
|
||||
this.matcher = matcher;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof PropertyMatcher)) return false;
|
||||
PropertyMatcher that = (PropertyMatcher) obj;
|
||||
if (!this.name.equals(that.name)) return false;
|
||||
return this.matcher.equals(that.matcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.name, this.matcher);
|
||||
}
|
||||
}
|
||||
|
||||
public interface ValueMatcher {
|
||||
|
||||
static ValueMatcher read(PacketWrapper<?> wrapper) {
|
||||
if (wrapper.readBoolean()) {
|
||||
return ExactValueMatcher.read(wrapper);
|
||||
}
|
||||
return RangedValueMatcher.read(wrapper);
|
||||
}
|
||||
|
||||
static void write(PacketWrapper<?> wrapper, ValueMatcher matcher) {
|
||||
if (matcher instanceof ExactValueMatcher) {
|
||||
wrapper.writeBoolean(true);
|
||||
ExactValueMatcher.write(wrapper, (ExactValueMatcher) matcher);
|
||||
} else if (matcher instanceof RangedValueMatcher) {
|
||||
wrapper.writeBoolean(false);
|
||||
RangedValueMatcher.write(wrapper, (RangedValueMatcher) matcher);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Illegal matcher implementation: " + matcher);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class ExactValueMatcher implements ValueMatcher {
|
||||
|
||||
private String value;
|
||||
|
||||
public ExactValueMatcher(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static ExactValueMatcher read(PacketWrapper<?> wrapper) {
|
||||
return new ExactValueMatcher(wrapper.readString());
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, ExactValueMatcher matcher) {
|
||||
wrapper.writeString(matcher.value);
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof ExactValueMatcher)) return false;
|
||||
ExactValueMatcher that = (ExactValueMatcher) obj;
|
||||
return this.value.equals(that.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(this.value);
|
||||
}
|
||||
}
|
||||
|
||||
public static class RangedValueMatcher implements ValueMatcher {
|
||||
|
||||
private @Nullable String minValue;
|
||||
private @Nullable String maxValue;
|
||||
|
||||
public RangedValueMatcher(@Nullable String minValue, @Nullable String maxValue) {
|
||||
this.minValue = minValue;
|
||||
this.maxValue = maxValue;
|
||||
}
|
||||
|
||||
public static RangedValueMatcher read(PacketWrapper<?> wrapper) {
|
||||
String minValue = wrapper.readOptional(PacketWrapper::readString);
|
||||
String maxValue = wrapper.readOptional(PacketWrapper::readString);
|
||||
return new RangedValueMatcher(minValue, maxValue);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, RangedValueMatcher matcher) {
|
||||
wrapper.writeOptional(matcher.minValue, PacketWrapper::writeString);
|
||||
wrapper.writeOptional(matcher.maxValue, PacketWrapper::writeString);
|
||||
}
|
||||
|
||||
public @Nullable String getMinValue() {
|
||||
return this.minValue;
|
||||
}
|
||||
|
||||
public void setMinValue(@Nullable String minValue) {
|
||||
this.minValue = minValue;
|
||||
}
|
||||
|
||||
public @Nullable String getMaxValue() {
|
||||
return this.maxValue;
|
||||
}
|
||||
|
||||
public void setMaxValue(@Nullable String maxValue) {
|
||||
this.maxValue = maxValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof RangedValueMatcher)) return false;
|
||||
RangedValueMatcher that = (RangedValueMatcher) obj;
|
||||
if (!Objects.equals(this.minValue, that.minValue)) return false;
|
||||
return Objects.equals(this.maxValue, that.maxValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.minValue, this.maxValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
+264
@@ -0,0 +1,264 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.component.builtin.item;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.attribute.Attribute;
|
||||
import com.github.retrooper.packetevents.protocol.attribute.AttributeOperation;
|
||||
import com.github.retrooper.packetevents.protocol.attribute.Attributes;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ItemAttributeModifiers {
|
||||
|
||||
public static final ItemAttributeModifiers EMPTY = new ItemAttributeModifiers(
|
||||
Collections.emptyList(), true) {
|
||||
@Override
|
||||
public void setShowInTooltip(boolean showInTooltip) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
};
|
||||
|
||||
private List<ModifierEntry> modifiers;
|
||||
private boolean showInTooltip;
|
||||
|
||||
public ItemAttributeModifiers(List<ModifierEntry> modifiers, boolean showInTooltip) {
|
||||
this.modifiers = modifiers;
|
||||
this.showInTooltip = showInTooltip;
|
||||
}
|
||||
|
||||
public static ItemAttributeModifiers read(PacketWrapper<?> wrapper) {
|
||||
List<ModifierEntry> modifiers = wrapper.readList(ModifierEntry::read);
|
||||
boolean showInTooltip = wrapper.readBoolean();
|
||||
return new ItemAttributeModifiers(modifiers, showInTooltip);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, ItemAttributeModifiers modifiers) {
|
||||
wrapper.writeList(modifiers.modifiers, ModifierEntry::write);
|
||||
wrapper.writeBoolean(modifiers.showInTooltip);
|
||||
}
|
||||
|
||||
public void addModifier(ModifierEntry modifier) {
|
||||
this.modifiers.add(modifier);
|
||||
}
|
||||
|
||||
public List<ModifierEntry> getModifiers() {
|
||||
return this.modifiers;
|
||||
}
|
||||
|
||||
public void setModifiers(List<ModifierEntry> modifiers) {
|
||||
this.modifiers = modifiers;
|
||||
}
|
||||
|
||||
public boolean isShowInTooltip() {
|
||||
return this.showInTooltip;
|
||||
}
|
||||
|
||||
public void setShowInTooltip(boolean showInTooltip) {
|
||||
this.showInTooltip = showInTooltip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof ItemAttributeModifiers)) return false;
|
||||
ItemAttributeModifiers that = (ItemAttributeModifiers) obj;
|
||||
if (this.showInTooltip != that.showInTooltip) return false;
|
||||
return this.modifiers.equals(that.modifiers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.modifiers, this.showInTooltip);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ItemAttributeModifiers{modifiers=" + this.modifiers + ", showInTooltip=" + this.showInTooltip + '}';
|
||||
}
|
||||
|
||||
public static class ModifierEntry {
|
||||
|
||||
private Attribute attribute;
|
||||
private Modifier modifier;
|
||||
private EquipmentSlotGroup slotGroup;
|
||||
|
||||
public ModifierEntry(Attribute attribute, Modifier modifier, EquipmentSlotGroup slotGroup) {
|
||||
this.attribute = attribute;
|
||||
this.modifier = modifier;
|
||||
this.slotGroup = slotGroup;
|
||||
}
|
||||
|
||||
public static ModifierEntry read(PacketWrapper<?> wrapper) {
|
||||
Attribute attribute = wrapper.readMappedEntity(Attributes::getById);
|
||||
Modifier modifier = Modifier.read(wrapper);
|
||||
EquipmentSlotGroup slot = wrapper.readEnum(EquipmentSlotGroup.values());
|
||||
return new ModifierEntry(attribute, modifier, slot);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, ModifierEntry entry) {
|
||||
wrapper.writeMappedEntity(entry.attribute);
|
||||
Modifier.write(wrapper, entry.modifier);
|
||||
wrapper.writeEnum(entry.slotGroup);
|
||||
}
|
||||
|
||||
public Attribute getAttribute() {
|
||||
return this.attribute;
|
||||
}
|
||||
|
||||
public void setAttribute(Attribute attribute) {
|
||||
this.attribute = attribute;
|
||||
}
|
||||
|
||||
public Modifier getModifier() {
|
||||
return this.modifier;
|
||||
}
|
||||
|
||||
public void setModifier(Modifier modifier) {
|
||||
this.modifier = modifier;
|
||||
}
|
||||
|
||||
public EquipmentSlotGroup getSlotGroup() {
|
||||
return this.slotGroup;
|
||||
}
|
||||
|
||||
public void setSlotGroup(EquipmentSlotGroup slotGroup) {
|
||||
this.slotGroup = slotGroup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof ModifierEntry)) return false;
|
||||
ModifierEntry that = (ModifierEntry) obj;
|
||||
if (!this.attribute.equals(that.attribute)) return false;
|
||||
if (!this.modifier.equals(that.modifier)) return false;
|
||||
return this.slotGroup == that.slotGroup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.attribute, this.modifier, this.slotGroup);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ModifierEntry{attribute=" + this.attribute + ", modifier=" + this.modifier + ", slotGroup=" + this.slotGroup + '}';
|
||||
}
|
||||
}
|
||||
|
||||
public static class Modifier {
|
||||
|
||||
private UUID id;
|
||||
private String name;
|
||||
private double value;
|
||||
private AttributeOperation operation;
|
||||
|
||||
public Modifier(UUID id, String name, double value, AttributeOperation operation) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
this.operation = operation;
|
||||
}
|
||||
|
||||
public static Modifier read(PacketWrapper<?> wrapper) {
|
||||
UUID id = wrapper.readUUID();
|
||||
String name = wrapper.readString();
|
||||
double value = wrapper.readDouble();
|
||||
AttributeOperation operation = wrapper.readEnum(AttributeOperation.values());
|
||||
return new Modifier(id, name, value, operation);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, Modifier modifier) {
|
||||
wrapper.writeUUID(modifier.id);
|
||||
wrapper.writeString(modifier.name);
|
||||
wrapper.writeDouble(modifier.value);
|
||||
wrapper.writeEnum(modifier.operation);
|
||||
}
|
||||
|
||||
public UUID getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public double getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void setValue(double value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public AttributeOperation getOperation() {
|
||||
return this.operation;
|
||||
}
|
||||
|
||||
public void setOperation(AttributeOperation operation) {
|
||||
this.operation = operation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof Modifier)) return false;
|
||||
Modifier modifier = (Modifier) obj;
|
||||
if (Double.compare(modifier.value, this.value) != 0) return false;
|
||||
if (!this.id.equals(modifier.id)) return false;
|
||||
if (!this.name.equals(modifier.name)) return false;
|
||||
return this.operation == modifier.operation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.id, this.name, this.value, this.operation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Modifier{id=" + this.id + ", name='" + this.name + '\'' + ", value=" + this.value + ", operation=" + this.operation + '}';
|
||||
}
|
||||
}
|
||||
|
||||
public enum EquipmentSlotGroup {
|
||||
ANY,
|
||||
MAINHAND,
|
||||
OFFHAND,
|
||||
HAND,
|
||||
FEET,
|
||||
LEGS,
|
||||
CHEST,
|
||||
HEAD,
|
||||
ARMOR,
|
||||
BODY,
|
||||
}
|
||||
}
|
||||
+133
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.component.builtin.item;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ItemBees {
|
||||
|
||||
private List<BeeEntry> bees;
|
||||
|
||||
public ItemBees(List<BeeEntry> bees) {
|
||||
this.bees = bees;
|
||||
}
|
||||
|
||||
public static ItemBees read(PacketWrapper<?> wrapper) {
|
||||
List<BeeEntry> bees = wrapper.readList(BeeEntry::read);
|
||||
return new ItemBees(bees);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, ItemBees bees) {
|
||||
wrapper.writeList(bees.bees, BeeEntry::write);
|
||||
}
|
||||
|
||||
public void addBee(BeeEntry bee) {
|
||||
this.bees.add(bee);
|
||||
}
|
||||
|
||||
public List<BeeEntry> getBees() {
|
||||
return this.bees;
|
||||
}
|
||||
|
||||
public void setBees(List<BeeEntry> bees) {
|
||||
this.bees = bees;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof ItemBees)) return false;
|
||||
ItemBees itemBees = (ItemBees) obj;
|
||||
return this.bees.equals(itemBees.bees);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(this.bees);
|
||||
}
|
||||
|
||||
public static class BeeEntry {
|
||||
|
||||
private NBTCompound entityData;
|
||||
private int ticksInHive;
|
||||
private int minTicksInHive;
|
||||
|
||||
public BeeEntry(NBTCompound entityData, int ticksInHive, int minTicksInHive) {
|
||||
this.entityData = entityData;
|
||||
this.ticksInHive = ticksInHive;
|
||||
this.minTicksInHive = minTicksInHive;
|
||||
}
|
||||
|
||||
public static BeeEntry read(PacketWrapper<?> wrapper) {
|
||||
NBTCompound entityData = wrapper.readNBT();
|
||||
int ticksInHive = wrapper.readVarInt();
|
||||
int minTicksInHive = wrapper.readVarInt();
|
||||
return new BeeEntry(entityData, ticksInHive, minTicksInHive);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, BeeEntry bee) {
|
||||
wrapper.writeNBT(bee.entityData);
|
||||
wrapper.writeVarInt(bee.ticksInHive);
|
||||
wrapper.writeVarInt(bee.minTicksInHive);
|
||||
}
|
||||
|
||||
public NBTCompound getEntityData() {
|
||||
return this.entityData;
|
||||
}
|
||||
|
||||
public void setEntityData(NBTCompound entityData) {
|
||||
this.entityData = entityData;
|
||||
}
|
||||
|
||||
public int getTicksInHive() {
|
||||
return this.ticksInHive;
|
||||
}
|
||||
|
||||
public void setTicksInHive(int ticksInHive) {
|
||||
this.ticksInHive = ticksInHive;
|
||||
}
|
||||
|
||||
public int getMinTicksInHive() {
|
||||
return this.minTicksInHive;
|
||||
}
|
||||
|
||||
public void setMinTicksInHive(int minTicksInHive) {
|
||||
this.minTicksInHive = minTicksInHive;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof BeeEntry)) return false;
|
||||
BeeEntry beeEntry = (BeeEntry) obj;
|
||||
if (this.ticksInHive != beeEntry.ticksInHive) return false;
|
||||
if (this.minTicksInHive != beeEntry.minTicksInHive) return false;
|
||||
return this.entityData.equals(beeEntry.entityData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.entityData, this.ticksInHive, this.minTicksInHive);
|
||||
}
|
||||
}
|
||||
}
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.component.builtin.item;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.world.states.type.StateValue;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ItemBlockStateProperties {
|
||||
|
||||
private Map<String, String> properties;
|
||||
|
||||
public ItemBlockStateProperties(Map<String, String> properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public static ItemBlockStateProperties read(PacketWrapper<?> wrapper) {
|
||||
Map<String, String> properties = wrapper.readMap(
|
||||
PacketWrapper::readString, PacketWrapper::readString);
|
||||
return new ItemBlockStateProperties(properties);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, ItemBlockStateProperties props) {
|
||||
wrapper.writeMap(props.properties,
|
||||
PacketWrapper::writeString,
|
||||
PacketWrapper::writeString);
|
||||
}
|
||||
|
||||
public @Nullable Object getProperty(StateValue stateValue) {
|
||||
String value = this.getProperty(stateValue.getName());
|
||||
if (value != null) {
|
||||
return stateValue.getParser().apply(value);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public @Nullable String getProperty(String key) {
|
||||
return this.properties.get(key);
|
||||
}
|
||||
|
||||
public void setProperty(StateValue stateValue, @Nullable Object value) {
|
||||
this.setProperty(stateValue.getName(), value == null ? null : value.toString());
|
||||
}
|
||||
|
||||
public void setProperty(String key, @Nullable String value) {
|
||||
if (value == null) {
|
||||
this.properties.remove(key);
|
||||
} else {
|
||||
this.properties.put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void unsetProperty(StateValue stateValue) {
|
||||
this.unsetProperty(stateValue.getName());
|
||||
}
|
||||
|
||||
public void unsetProperty(String key) {
|
||||
this.setProperty(key, null);
|
||||
}
|
||||
|
||||
public Map<String, String> getProperties() {
|
||||
return this.properties;
|
||||
}
|
||||
|
||||
public void setProperties(Map<String, String> properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof ItemBlockStateProperties)) return false;
|
||||
ItemBlockStateProperties that = (ItemBlockStateProperties) obj;
|
||||
return this.properties.equals(that.properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(this.properties);
|
||||
}
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.component.builtin.item;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.item.ItemStack;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ItemContainerContents {
|
||||
|
||||
private List<ItemStack> items;
|
||||
|
||||
public ItemContainerContents(List<ItemStack> items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
public static ItemContainerContents read(PacketWrapper<?> wrapper) {
|
||||
List<ItemStack> items = wrapper.readList(PacketWrapper::readItemStack);
|
||||
return new ItemContainerContents(items);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, ItemContainerContents contents) {
|
||||
wrapper.writeList(contents.items, PacketWrapper::writeItemStack);
|
||||
}
|
||||
|
||||
public void addItem(ItemStack itemStack) {
|
||||
this.items.add(itemStack);
|
||||
}
|
||||
|
||||
public List<ItemStack> getItems() {
|
||||
return this.items;
|
||||
}
|
||||
|
||||
public void setItems(List<ItemStack> items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof ItemContainerContents)) return false;
|
||||
ItemContainerContents that = (ItemContainerContents) obj;
|
||||
return this.items.equals(that.items);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(this.items);
|
||||
}
|
||||
}
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.component.builtin.item;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTLong;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTNumber;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTString;
|
||||
import com.github.retrooper.packetevents.resources.ResourceLocation;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class ItemContainerLoot {
|
||||
|
||||
private ResourceLocation lootTable;
|
||||
private long seed;
|
||||
|
||||
public ItemContainerLoot(ResourceLocation lootTable, long seed) {
|
||||
this.lootTable = lootTable;
|
||||
this.seed = seed;
|
||||
}
|
||||
|
||||
public static ItemContainerLoot read(PacketWrapper<?> wrapper) {
|
||||
NBTCompound compound = wrapper.readNBT();
|
||||
ResourceLocation lootTable = new ResourceLocation(compound.getStringTagValueOrThrow("loot_table"));
|
||||
NBTNumber seedTag = compound.getNumberTagOrNull("seed");
|
||||
long seed = seedTag == null ? 0L : seedTag.getAsLong();
|
||||
return new ItemContainerLoot(lootTable, seed);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, ItemContainerLoot loot) {
|
||||
NBTCompound compound = new NBTCompound();
|
||||
compound.setTag("loot_table", new NBTString(loot.lootTable.toString()));
|
||||
if (loot.seed != 0L) {
|
||||
compound.setTag("seed", new NBTLong(loot.seed));
|
||||
}
|
||||
wrapper.writeNBT(compound);
|
||||
}
|
||||
|
||||
public ResourceLocation getLootTable() {
|
||||
return this.lootTable;
|
||||
}
|
||||
|
||||
public void setLootTable(ResourceLocation lootTable) {
|
||||
this.lootTable = lootTable;
|
||||
}
|
||||
|
||||
public long getSeed() {
|
||||
return this.seed;
|
||||
}
|
||||
|
||||
public void setSeed(long seed) {
|
||||
this.seed = seed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof ItemContainerLoot)) return false;
|
||||
ItemContainerLoot that = (ItemContainerLoot) obj;
|
||||
if (this.seed != that.seed) return false;
|
||||
return this.lootTable.equals(that.lootTable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.lootTable, this.seed);
|
||||
}
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.component.builtin.item;
|
||||
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class ItemDyeColor {
|
||||
|
||||
private int rgb;
|
||||
private boolean showInTooltip;
|
||||
|
||||
public ItemDyeColor(int rgb, boolean showInTooltip) {
|
||||
this.rgb = rgb;
|
||||
this.showInTooltip = showInTooltip;
|
||||
}
|
||||
|
||||
public static ItemDyeColor read(PacketWrapper<?> wrapper) {
|
||||
int rgb = wrapper.readInt();
|
||||
boolean showInTooltip = wrapper.readBoolean();
|
||||
return new ItemDyeColor(rgb, showInTooltip);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, ItemDyeColor color) {
|
||||
wrapper.writeInt(color.rgb);
|
||||
wrapper.writeBoolean(color.showInTooltip);
|
||||
}
|
||||
|
||||
public int getRgb() {
|
||||
return this.rgb;
|
||||
}
|
||||
|
||||
public void setRgb(int rgb) {
|
||||
this.rgb = rgb;
|
||||
}
|
||||
|
||||
public boolean isShowInTooltip() {
|
||||
return this.showInTooltip;
|
||||
}
|
||||
|
||||
public void setShowInTooltip(boolean showInTooltip) {
|
||||
this.showInTooltip = showInTooltip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof ItemDyeColor)) return false;
|
||||
ItemDyeColor that = (ItemDyeColor) obj;
|
||||
if (this.rgb != that.rgb) return false;
|
||||
return this.showInTooltip == that.showInTooltip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.rgb, this.showInTooltip);
|
||||
}
|
||||
}
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.component.builtin.item;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.item.enchantment.type.EnchantmentType;
|
||||
import com.github.retrooper.packetevents.protocol.item.enchantment.type.EnchantmentTypes;
|
||||
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ItemEnchantments implements Iterable<Map.Entry<EnchantmentType, Integer>> {
|
||||
|
||||
public static final ItemEnchantments EMPTY = new ItemEnchantments(
|
||||
Collections.emptyMap(), true) {
|
||||
@Override
|
||||
public void setShowInTooltip(boolean showInTooltip) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
};
|
||||
|
||||
private Map<EnchantmentType, Integer> enchantments;
|
||||
private boolean showInTooltip;
|
||||
|
||||
public ItemEnchantments(Map<EnchantmentType, Integer> enchantments, boolean showInTooltip) {
|
||||
this.enchantments = Collections.unmodifiableMap(enchantments);
|
||||
this.showInTooltip = showInTooltip;
|
||||
}
|
||||
|
||||
public static ItemEnchantments read(PacketWrapper<?> wrapper) {
|
||||
ClientVersion version = wrapper.getServerVersion().toClientVersion();
|
||||
Map<EnchantmentType, Integer> enchantments = wrapper.readMap(
|
||||
ew -> EnchantmentTypes.getById(version, ew.readVarInt()),
|
||||
PacketWrapper::readVarInt
|
||||
);
|
||||
boolean showInTooltip = wrapper.readBoolean();
|
||||
return new ItemEnchantments(enchantments, showInTooltip);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, ItemEnchantments enchantments) {
|
||||
ClientVersion version = wrapper.getServerVersion().toClientVersion();
|
||||
wrapper.writeMap(enchantments.getEnchantments(),
|
||||
(ew, enchantment) -> ew.writeVarInt(enchantment.getId(version)),
|
||||
PacketWrapper::writeVarInt
|
||||
);
|
||||
wrapper.writeBoolean(enchantments.isShowInTooltip());
|
||||
}
|
||||
|
||||
public int getEnchantmentLevel(EnchantmentType enchantment) {
|
||||
return this.enchantments.getOrDefault(enchantment, 0);
|
||||
}
|
||||
|
||||
public void setEnchantmentLevel(EnchantmentType enchantment, int level) {
|
||||
if (level == 0) {
|
||||
this.enchantments.remove(enchantment);
|
||||
} else {
|
||||
this.enchantments.put(enchantment, level);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return this.getEnchantmentCount() < 1;
|
||||
}
|
||||
|
||||
public int getEnchantmentCount() {
|
||||
return this.enchantments.size();
|
||||
}
|
||||
|
||||
public Map<EnchantmentType, Integer> getEnchantments() {
|
||||
return this.enchantments;
|
||||
}
|
||||
|
||||
public void setEnchantments(Map<EnchantmentType, Integer> enchantments) {
|
||||
this.enchantments = enchantments;
|
||||
}
|
||||
|
||||
public boolean isShowInTooltip() {
|
||||
return this.showInTooltip;
|
||||
}
|
||||
|
||||
public void setShowInTooltip(boolean showInTooltip) {
|
||||
this.showInTooltip = showInTooltip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Map.Entry<EnchantmentType, Integer>> iterator() {
|
||||
return this.enchantments.entrySet().iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof ItemEnchantments)) return false;
|
||||
ItemEnchantments that = (ItemEnchantments) obj;
|
||||
if (this.showInTooltip != that.showInTooltip) return false;
|
||||
return this.enchantments.equals(that.enchantments);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.enchantments, this.showInTooltip);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ItemEnchantments{enchantments=" + this.enchantments + ", showInTooltip=" + this.showInTooltip + '}';
|
||||
}
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.component.builtin.item;
|
||||
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ItemFireworks {
|
||||
|
||||
private int flightDuration;
|
||||
private List<FireworkExplosion> explosions;
|
||||
|
||||
public ItemFireworks(int flightDuration, List<FireworkExplosion> explosions) {
|
||||
this.flightDuration = flightDuration;
|
||||
this.explosions = explosions;
|
||||
}
|
||||
|
||||
public static ItemFireworks read(PacketWrapper<?> wrapper) {
|
||||
int flightDuration = wrapper.readVarInt();
|
||||
List<FireworkExplosion> explosions = wrapper.readList(FireworkExplosion::read);
|
||||
return new ItemFireworks(flightDuration, explosions);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, ItemFireworks fireworks) {
|
||||
wrapper.writeVarInt(fireworks.flightDuration);
|
||||
wrapper.writeList(fireworks.explosions, FireworkExplosion::write);
|
||||
}
|
||||
|
||||
public int getFlightDuration() {
|
||||
return this.flightDuration;
|
||||
}
|
||||
|
||||
public void setFlightDuration(int flightDuration) {
|
||||
this.flightDuration = flightDuration;
|
||||
}
|
||||
|
||||
public void addExplosion(FireworkExplosion explosion) {
|
||||
this.explosions.add(explosion);
|
||||
}
|
||||
|
||||
public List<FireworkExplosion> getExplosions() {
|
||||
return this.explosions;
|
||||
}
|
||||
|
||||
public void setExplosions(List<FireworkExplosion> explosions) {
|
||||
this.explosions = explosions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof ItemFireworks)) return false;
|
||||
ItemFireworks that = (ItemFireworks) obj;
|
||||
if (this.flightDuration != that.flightDuration) return false;
|
||||
return this.explosions.equals(that.explosions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.flightDuration, this.explosions);
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.component.builtin.item;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTString;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class ItemLock {
|
||||
|
||||
private String code;
|
||||
|
||||
public ItemLock(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public static ItemLock read(PacketWrapper<?> wrapper) {
|
||||
NBTString codeTag = (NBTString) wrapper.readNBTRaw();
|
||||
return new ItemLock(codeTag.getValue());
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, ItemLock lock) {
|
||||
wrapper.writeNBTRaw(new NBTString(lock.code));
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof ItemLock)) return false;
|
||||
ItemLock itemLock = (ItemLock) obj;
|
||||
return this.code.equals(itemLock.code);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(this.code);
|
||||
}
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.component.builtin.item;
|
||||
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ItemLore {
|
||||
|
||||
public static final ItemLore EMPTY = new ItemLore(Collections.emptyList());
|
||||
|
||||
private List<Component> lines;
|
||||
|
||||
public ItemLore(List<Component> lines) {
|
||||
this.lines = lines;
|
||||
}
|
||||
|
||||
public static ItemLore read(PacketWrapper<?> wrapper) {
|
||||
List<Component> lines = wrapper.readList(PacketWrapper::readComponent);
|
||||
return new ItemLore(lines);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, ItemLore lore) {
|
||||
wrapper.writeList(lore.lines, PacketWrapper::writeComponent);
|
||||
}
|
||||
|
||||
public void addLine(Component line) {
|
||||
this.lines.add(line);
|
||||
}
|
||||
|
||||
public List<Component> getLines() {
|
||||
return this.lines;
|
||||
}
|
||||
|
||||
public void setLines(List<Component> lines) {
|
||||
this.lines = lines;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof ItemLore)) return false;
|
||||
ItemLore itemLore = (ItemLore) obj;
|
||||
return this.lines.equals(itemLore.lines);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.lines);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ItemLore{lines=" + this.lines + '}';
|
||||
}
|
||||
}
|
||||
+176
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.component.builtin.item;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.item.mapdecoration.MapDecorationType;
|
||||
import com.github.retrooper.packetevents.protocol.item.mapdecoration.MapDecorationTypes;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBT;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTDouble;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTFloat;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTString;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ItemMapDecorations {
|
||||
|
||||
private Map<String, Decoration> decorations;
|
||||
|
||||
public ItemMapDecorations(Map<String, Decoration> decorations) {
|
||||
this.decorations = decorations;
|
||||
}
|
||||
|
||||
public static ItemMapDecorations read(PacketWrapper<?> wrapper) {
|
||||
NBTCompound compound = wrapper.readNBT();
|
||||
Map<String, Decoration> decorations = new HashMap<>(compound.size());
|
||||
for (Map.Entry<String, NBT> tag : compound.getTags().entrySet()) {
|
||||
Decoration decoration = Decoration.readCompound((NBTCompound) tag.getValue());
|
||||
decorations.put(tag.getKey(), decoration);
|
||||
}
|
||||
return new ItemMapDecorations(decorations);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, ItemMapDecorations decorations) {
|
||||
NBTCompound compound = new NBTCompound();
|
||||
for (Map.Entry<String, Decoration> decoration : decorations.decorations.entrySet()) {
|
||||
NBTCompound entry = new NBTCompound();
|
||||
Decoration.writeCompound(entry, decoration.getValue());
|
||||
compound.setTag(decoration.getKey(), entry);
|
||||
}
|
||||
wrapper.writeNBT(compound);
|
||||
}
|
||||
|
||||
public @Nullable Decoration getDecoration(String key) {
|
||||
return this.decorations.get(key);
|
||||
}
|
||||
|
||||
public void setDecoration(String key, @Nullable Decoration decoration) {
|
||||
if (decoration != null) {
|
||||
this.decorations.put(key, decoration);
|
||||
} else {
|
||||
this.decorations.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, Decoration> getDecorations() {
|
||||
return this.decorations;
|
||||
}
|
||||
|
||||
public void setDecorations(Map<String, Decoration> decorations) {
|
||||
this.decorations = decorations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof ItemMapDecorations)) return false;
|
||||
ItemMapDecorations that = (ItemMapDecorations) obj;
|
||||
return this.decorations.equals(that.decorations);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(this.decorations);
|
||||
}
|
||||
|
||||
public static final class Decoration {
|
||||
|
||||
private MapDecorationType type;
|
||||
private double x;
|
||||
private double z;
|
||||
private float rotation;
|
||||
|
||||
public Decoration(MapDecorationType type, double x, double z, float rotation) {
|
||||
this.type = type;
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
this.rotation = rotation;
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static Decoration readCompound(NBTCompound compound) {
|
||||
MapDecorationType type = MapDecorationTypes.getByName(compound.getStringTagValueOrThrow("type"));
|
||||
double x = compound.getNumberTagOrThrow("x").getAsDouble();
|
||||
double z = compound.getNumberTagOrThrow("z").getAsDouble();
|
||||
float rotation = compound.getNumberTagOrThrow("rotation").getAsFloat();
|
||||
return new Decoration(type, x, z, rotation);
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static void writeCompound(NBTCompound compound, Decoration decoration) {
|
||||
compound.setTag("type", new NBTString(decoration.type.getName().toString()));
|
||||
compound.setTag("x", new NBTDouble(decoration.x));
|
||||
compound.setTag("z", new NBTDouble(decoration.z));
|
||||
compound.setTag("float", new NBTFloat(decoration.rotation));
|
||||
}
|
||||
|
||||
public MapDecorationType getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public void setType(MapDecorationType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public double getX() {
|
||||
return this.x;
|
||||
}
|
||||
|
||||
public void setX(double x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public double getZ() {
|
||||
return this.z;
|
||||
}
|
||||
|
||||
public void setZ(double z) {
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public float getRotation() {
|
||||
return this.rotation;
|
||||
}
|
||||
|
||||
public void setRotation(float rotation) {
|
||||
this.rotation = rotation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof Decoration)) return false;
|
||||
Decoration that = (Decoration) obj;
|
||||
if (Double.compare(that.x, this.x) != 0) return false;
|
||||
if (Double.compare(that.z, this.z) != 0) return false;
|
||||
if (Float.compare(that.rotation, this.rotation) != 0) return false;
|
||||
return this.type.equals(that.type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.type, this.x, this.z, this.rotation);
|
||||
}
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.component.builtin.item;
|
||||
|
||||
public enum ItemMapPostProcessingState {
|
||||
LOCKED,
|
||||
SCALED,
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.component.builtin.item;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.potion.Potion;
|
||||
import com.github.retrooper.packetevents.protocol.potion.PotionEffect;
|
||||
import com.github.retrooper.packetevents.protocol.potion.Potions;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ItemPotionContents {
|
||||
|
||||
private @Nullable Potion potion;
|
||||
private @Nullable Integer customColor;
|
||||
private List<PotionEffect> customEffects;
|
||||
|
||||
public ItemPotionContents(
|
||||
@Nullable Potion potion,
|
||||
@Nullable Integer customColor,
|
||||
List<PotionEffect> customEffects
|
||||
) {
|
||||
this.potion = potion;
|
||||
this.customColor = customColor;
|
||||
this.customEffects = customEffects;
|
||||
}
|
||||
|
||||
public static ItemPotionContents read(PacketWrapper<?> wrapper) {
|
||||
Potion potionId = wrapper.readOptional(ew -> ew.readMappedEntity(Potions::getById));
|
||||
Integer customColor = wrapper.readOptional(PacketWrapper::readInt);
|
||||
List<PotionEffect> customEffects = wrapper.readList(PotionEffect::read);
|
||||
return new ItemPotionContents(potionId, customColor, customEffects);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, ItemPotionContents contents) {
|
||||
wrapper.writeOptional(contents.potion, PacketWrapper::writeMappedEntity);
|
||||
wrapper.writeOptional(contents.customColor, PacketWrapper::writeInt);
|
||||
wrapper.writeList(contents.customEffects, PotionEffect::write);
|
||||
}
|
||||
|
||||
public @Nullable Potion getPotion() {
|
||||
return this.potion;
|
||||
}
|
||||
|
||||
public void setPotion(@Nullable Potion potion) {
|
||||
this.potion = potion;
|
||||
}
|
||||
|
||||
public @Nullable Integer getCustomColor() {
|
||||
return this.customColor;
|
||||
}
|
||||
|
||||
public void setCustomColor(@Nullable Integer customColor) {
|
||||
this.customColor = customColor;
|
||||
}
|
||||
|
||||
private void addCustomEffect(PotionEffect effect) {
|
||||
this.customEffects.add(effect);
|
||||
}
|
||||
|
||||
public List<PotionEffect> getCustomEffects() {
|
||||
return this.customEffects;
|
||||
}
|
||||
|
||||
public void setCustomEffects(List<PotionEffect> customEffects) {
|
||||
this.customEffects = customEffects;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof ItemPotionContents)) return false;
|
||||
ItemPotionContents that = (ItemPotionContents) obj;
|
||||
if (!Objects.equals(this.potion, that.potion)) return false;
|
||||
if (!Objects.equals(this.customColor, that.customColor)) return false;
|
||||
return this.customEffects.equals(that.customEffects);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.potion, this.customColor, this.customEffects);
|
||||
}
|
||||
}
|
||||
+165
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.component.builtin.item;
|
||||
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ItemProfile {
|
||||
|
||||
private @Nullable String name;
|
||||
private @Nullable UUID id;
|
||||
private List<Property> properties;
|
||||
|
||||
public ItemProfile(
|
||||
@Nullable String name,
|
||||
@Nullable UUID id,
|
||||
List<Property> properties
|
||||
) {
|
||||
this.name = name;
|
||||
this.id = id;
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public static ItemProfile read(PacketWrapper<?> wrapper) {
|
||||
String name = wrapper.readOptional(ew -> ew.readString(16));
|
||||
UUID id = wrapper.readOptional(PacketWrapper::readUUID);
|
||||
List<Property> properties = wrapper.readList(Property::read);
|
||||
return new ItemProfile(name, id, properties);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, ItemProfile profile) {
|
||||
wrapper.writeOptional(profile.name, (ew, name) -> ew.writeString(name, 16));
|
||||
wrapper.writeOptional(profile.id, PacketWrapper::writeUUID);
|
||||
wrapper.writeList(profile.properties, Property::write);
|
||||
}
|
||||
|
||||
public @Nullable String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(@Nullable String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public @Nullable UUID getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setId(@Nullable UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void addProperty(Property property) {
|
||||
this.properties.add(property);
|
||||
}
|
||||
|
||||
public List<Property> getProperties() {
|
||||
return this.properties;
|
||||
}
|
||||
|
||||
public void setProperties(List<Property> properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof ItemProfile)) return false;
|
||||
ItemProfile that = (ItemProfile) obj;
|
||||
if (!Objects.equals(this.name, that.name)) return false;
|
||||
if (!Objects.equals(this.id, that.id)) return false;
|
||||
return this.properties.equals(that.properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.name, this.id, this.properties);
|
||||
}
|
||||
|
||||
public static class Property {
|
||||
|
||||
private String name;
|
||||
private String value;
|
||||
private @Nullable String signature;
|
||||
|
||||
public Property(String name, String value, @Nullable String signature) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
public static Property read(PacketWrapper<?> wrapper) {
|
||||
String name = wrapper.readString(64);
|
||||
String value = wrapper.readString(32767);
|
||||
String signature = wrapper.readOptional(ew -> ew.readString(1024));
|
||||
return new Property(name, value, signature);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, Property property) {
|
||||
wrapper.writeString(property.name, 64);
|
||||
wrapper.writeString(property.value, 32767);
|
||||
wrapper.writeOptional(property.signature,
|
||||
(ew, signature) -> ew.writeString(signature, 1024));
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public @Nullable String getSignature() {
|
||||
return this.signature;
|
||||
}
|
||||
|
||||
public void setSignature(@Nullable String signature) {
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof Property)) return false;
|
||||
Property property = (Property) obj;
|
||||
if (!this.name.equals(property.name)) return false;
|
||||
if (!this.value.equals(property.value)) return false;
|
||||
return Objects.equals(this.signature, property.signature);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.name, this.value, this.signature);
|
||||
}
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.component.builtin.item;
|
||||
|
||||
public enum ItemRarity {
|
||||
COMMON,
|
||||
UNCOMMON,
|
||||
RARE,
|
||||
EPIC,
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.component.builtin.item;
|
||||
|
||||
import com.github.retrooper.packetevents.resources.ResourceLocation;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ItemRecipes {
|
||||
|
||||
private List<ResourceLocation> recipes;
|
||||
|
||||
public ItemRecipes(List<ResourceLocation> recipes) {
|
||||
this.recipes = recipes;
|
||||
}
|
||||
|
||||
public static ItemRecipes read(PacketWrapper<?> wrapper) {
|
||||
List<ResourceLocation> recipes = wrapper.readList(PacketWrapper::readIdentifier);
|
||||
return new ItemRecipes(recipes);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, ItemRecipes recipes) {
|
||||
wrapper.writeList(recipes.recipes, PacketWrapper::writeIdentifier);
|
||||
}
|
||||
|
||||
public void addRecipe(ResourceLocation recipeKey) {
|
||||
this.recipes.add(recipeKey);
|
||||
}
|
||||
|
||||
public void removeRecipe(ResourceLocation recipeKey) {
|
||||
this.recipes.remove(recipeKey);
|
||||
}
|
||||
|
||||
public List<ResourceLocation> getRecipes() {
|
||||
return this.recipes;
|
||||
}
|
||||
|
||||
public void setRecipes(List<ResourceLocation> recipes) {
|
||||
this.recipes = recipes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof ItemRecipes)) return false;
|
||||
ItemRecipes that = (ItemRecipes) obj;
|
||||
return this.recipes.equals(that.recipes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(this.recipes);
|
||||
}
|
||||
}
|
||||
+166
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.component.builtin.item;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.mapper.MappedEntitySet;
|
||||
import com.github.retrooper.packetevents.protocol.world.states.type.StateType;
|
||||
import com.github.retrooper.packetevents.protocol.world.states.type.StateTypes;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ItemTool {
|
||||
|
||||
private List<Rule> rules;
|
||||
private float defaultMiningSpeed;
|
||||
private int damagePerBlock;
|
||||
|
||||
public ItemTool(List<Rule> rules, float defaultMiningSpeed, int damagePerBlock) {
|
||||
this.rules = rules;
|
||||
this.defaultMiningSpeed = defaultMiningSpeed;
|
||||
this.damagePerBlock = damagePerBlock;
|
||||
}
|
||||
|
||||
public static ItemTool read(PacketWrapper<?> wrapper) {
|
||||
List<Rule> rules = wrapper.readList(Rule::read);
|
||||
float defaultMiningSpeed = wrapper.readFloat();
|
||||
int damagePerBlock = wrapper.readVarInt();
|
||||
return new ItemTool(rules, defaultMiningSpeed, damagePerBlock);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, ItemTool tool) {
|
||||
wrapper.writeList(tool.rules, Rule::write);
|
||||
wrapper.writeFloat(tool.defaultMiningSpeed);
|
||||
wrapper.writeVarInt(tool.damagePerBlock);
|
||||
}
|
||||
|
||||
public void addRule(Rule rule) {
|
||||
this.rules.add(rule);
|
||||
}
|
||||
|
||||
public List<Rule> getRules() {
|
||||
return this.rules;
|
||||
}
|
||||
|
||||
public void setRules(List<Rule> rules) {
|
||||
this.rules = rules;
|
||||
}
|
||||
|
||||
public float getDefaultMiningSpeed() {
|
||||
return this.defaultMiningSpeed;
|
||||
}
|
||||
|
||||
public void setDefaultMiningSpeed(float defaultMiningSpeed) {
|
||||
this.defaultMiningSpeed = defaultMiningSpeed;
|
||||
}
|
||||
|
||||
public int getDamagePerBlock() {
|
||||
return this.damagePerBlock;
|
||||
}
|
||||
|
||||
public void setDamagePerBlock(int damagePerBlock) {
|
||||
this.damagePerBlock = damagePerBlock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof ItemTool)) return false;
|
||||
ItemTool itemTool = (ItemTool) obj;
|
||||
if (Float.compare(itemTool.defaultMiningSpeed, this.defaultMiningSpeed) != 0) return false;
|
||||
if (this.damagePerBlock != itemTool.damagePerBlock) return false;
|
||||
return this.rules.equals(itemTool.rules);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.rules, this.defaultMiningSpeed, this.damagePerBlock);
|
||||
}
|
||||
|
||||
public static class Rule {
|
||||
|
||||
private MappedEntitySet<StateType.Mapped> blocks;
|
||||
private @Nullable Float speed;
|
||||
private @Nullable Boolean correctForDrops;
|
||||
|
||||
public Rule(
|
||||
MappedEntitySet<StateType.Mapped> blocks,
|
||||
@Nullable Float speed,
|
||||
@Nullable Boolean correctForDrops
|
||||
) {
|
||||
this.blocks = blocks;
|
||||
this.speed = speed;
|
||||
this.correctForDrops = correctForDrops;
|
||||
}
|
||||
|
||||
public static Rule read(PacketWrapper<?> wrapper) {
|
||||
MappedEntitySet<StateType.Mapped> blocks = MappedEntitySet.read(wrapper, StateTypes::getMappedById);
|
||||
Float speed = wrapper.readOptional(PacketWrapper::readFloat);
|
||||
Boolean correctForDrops = wrapper.readOptional(PacketWrapper::readBoolean);
|
||||
return new Rule(blocks, speed, correctForDrops);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, Rule rule) {
|
||||
MappedEntitySet.write(wrapper, rule.blocks);
|
||||
wrapper.writeOptional(rule.speed, PacketWrapper::writeFloat);
|
||||
wrapper.writeOptional(rule.correctForDrops, PacketWrapper::writeBoolean);
|
||||
}
|
||||
|
||||
public MappedEntitySet<StateType.Mapped> getBlocks() {
|
||||
return this.blocks;
|
||||
}
|
||||
|
||||
public void setBlocks(MappedEntitySet<StateType.Mapped> blocks) {
|
||||
this.blocks = blocks;
|
||||
}
|
||||
|
||||
public @Nullable Float getSpeed() {
|
||||
return this.speed;
|
||||
}
|
||||
|
||||
public void setSpeed(@Nullable Float speed) {
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
public @Nullable Boolean getCorrectForDrops() {
|
||||
return this.correctForDrops;
|
||||
}
|
||||
|
||||
public void setCorrectForDrops(@Nullable Boolean correctForDrops) {
|
||||
this.correctForDrops = correctForDrops;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof Rule)) return false;
|
||||
Rule rule = (Rule) obj;
|
||||
if (!this.blocks.equals(rule.blocks)) return false;
|
||||
if (!Objects.equals(this.speed, rule.speed)) return false;
|
||||
return Objects.equals(this.correctForDrops, rule.correctForDrops);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.blocks, this.speed, this.correctForDrops);
|
||||
}
|
||||
}
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.component.builtin.item;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.world.WorldBlockPosition;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class LodestoneTracker {
|
||||
|
||||
private @Nullable WorldBlockPosition target;
|
||||
private boolean tracked;
|
||||
|
||||
public LodestoneTracker(@Nullable WorldBlockPosition target, boolean tracked) {
|
||||
this.target = target;
|
||||
this.tracked = tracked;
|
||||
}
|
||||
|
||||
public static LodestoneTracker read(PacketWrapper<?> wrapper) {
|
||||
WorldBlockPosition target = wrapper.readOptional(PacketWrapper::readWorldBlockPosition);
|
||||
boolean tracked = wrapper.readBoolean();
|
||||
return new LodestoneTracker(target, tracked);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, LodestoneTracker tracker) {
|
||||
wrapper.writeOptional(tracker.target, PacketWrapper::writeWorldBlockPosition);
|
||||
wrapper.writeBoolean(tracker.tracked);
|
||||
}
|
||||
|
||||
public @Nullable WorldBlockPosition getTarget() {
|
||||
return this.target;
|
||||
}
|
||||
|
||||
public void setTarget(@Nullable WorldBlockPosition target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public boolean isTracked() {
|
||||
return this.tracked;
|
||||
}
|
||||
|
||||
public void setTracked(boolean tracked) {
|
||||
this.tracked = tracked;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof LodestoneTracker)) return false;
|
||||
LodestoneTracker that = (LodestoneTracker) obj;
|
||||
if (this.tracked != that.tracked) return false;
|
||||
return Objects.equals(this.target, that.target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.target, this.tracked);
|
||||
}
|
||||
}
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.component.builtin.item;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.item.type.ItemType;
|
||||
import com.github.retrooper.packetevents.protocol.item.type.ItemTypes;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Queue;
|
||||
|
||||
public class PotDecorations {
|
||||
|
||||
private @Nullable ItemType back;
|
||||
private @Nullable ItemType left;
|
||||
private @Nullable ItemType right;
|
||||
private @Nullable ItemType front;
|
||||
|
||||
private PotDecorations(Queue<ItemType> items) {
|
||||
this(items.poll(), items.poll(), items.poll(), items.poll());
|
||||
}
|
||||
|
||||
public PotDecorations(
|
||||
@Nullable ItemType back,
|
||||
@Nullable ItemType left,
|
||||
@Nullable ItemType right,
|
||||
@Nullable ItemType front
|
||||
) {
|
||||
this.back = back;
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
this.front = front;
|
||||
}
|
||||
|
||||
private List<ItemType> asList() {
|
||||
return Arrays.asList(this.back, this.left, this.right, this.front);
|
||||
}
|
||||
|
||||
private static @Nullable ItemType readItem(PacketWrapper<?> wrapper) {
|
||||
ItemType type = wrapper.readMappedEntity(ItemTypes::getById);
|
||||
return type == ItemTypes.BRICK ? null : type;
|
||||
}
|
||||
|
||||
public static PotDecorations read(PacketWrapper<?> wrapper) {
|
||||
Queue<ItemType> items = wrapper.<ItemType, Queue<ItemType>>readCollection(
|
||||
ArrayDeque::new, PotDecorations::readItem);
|
||||
return new PotDecorations(items);
|
||||
}
|
||||
|
||||
private static void writeItem(PacketWrapper<?> wrapper, @Nullable ItemType type) {
|
||||
wrapper.writeMappedEntity(type == null ? ItemTypes.BRICK : type);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, PotDecorations decorations) {
|
||||
wrapper.writeList(decorations.asList(), PotDecorations::writeItem);
|
||||
}
|
||||
|
||||
public @Nullable ItemType getBack() {
|
||||
return this.back;
|
||||
}
|
||||
|
||||
public void setBack(@Nullable ItemType back) {
|
||||
this.back = back;
|
||||
}
|
||||
|
||||
public @Nullable ItemType getLeft() {
|
||||
return this.left;
|
||||
}
|
||||
|
||||
public void setLeft(@Nullable ItemType left) {
|
||||
this.left = left;
|
||||
}
|
||||
|
||||
public @Nullable ItemType getRight() {
|
||||
return this.right;
|
||||
}
|
||||
|
||||
public void setRight(@Nullable ItemType right) {
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
public @Nullable ItemType getFront() {
|
||||
return this.front;
|
||||
}
|
||||
|
||||
public void setFront(@Nullable ItemType front) {
|
||||
this.front = front;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof PotDecorations)) return false;
|
||||
PotDecorations that = (PotDecorations) obj;
|
||||
if (!Objects.equals(this.back, that.back)) return false;
|
||||
if (!Objects.equals(this.left, that.left)) return false;
|
||||
if (!Objects.equals(this.right, that.right)) return false;
|
||||
return Objects.equals(this.front, that.front);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.back, this.left, this.right, this.front);
|
||||
}
|
||||
}
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.component.builtin.item;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.potion.PotionType;
|
||||
import com.github.retrooper.packetevents.protocol.potion.PotionTypes;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class SuspiciousStewEffects {
|
||||
|
||||
private List<EffectEntry> effects;
|
||||
|
||||
public SuspiciousStewEffects(List<EffectEntry> effects) {
|
||||
this.effects = effects;
|
||||
}
|
||||
|
||||
public static SuspiciousStewEffects read(PacketWrapper<?> wrapper) {
|
||||
List<EffectEntry> effects = wrapper.readList(EffectEntry::read);
|
||||
return new SuspiciousStewEffects(effects);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, SuspiciousStewEffects effects) {
|
||||
wrapper.writeList(effects.effects, EffectEntry::write);
|
||||
}
|
||||
|
||||
public void addEffect(EffectEntry effect) {
|
||||
this.effects.add(effect);
|
||||
}
|
||||
|
||||
public List<EffectEntry> getEffects() {
|
||||
return this.effects;
|
||||
}
|
||||
|
||||
public void setEffects(List<EffectEntry> effects) {
|
||||
this.effects = effects;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof SuspiciousStewEffects)) return false;
|
||||
SuspiciousStewEffects that = (SuspiciousStewEffects) obj;
|
||||
return this.effects.equals(that.effects);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(this.effects);
|
||||
}
|
||||
|
||||
public static class EffectEntry {
|
||||
|
||||
private PotionType type;
|
||||
private int duration;
|
||||
|
||||
public EffectEntry(PotionType type, int duration) {
|
||||
this.type = type;
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
public static EffectEntry read(PacketWrapper<?> wrapper) {
|
||||
PotionType type = wrapper.readMappedEntity(PotionTypes::getById);
|
||||
int duration = wrapper.readVarInt();
|
||||
return new EffectEntry(type, duration);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, EffectEntry effect) {
|
||||
wrapper.writeMappedEntity(effect.type);
|
||||
wrapper.writeVarInt(effect.duration);
|
||||
}
|
||||
|
||||
public PotionType getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public void setType(PotionType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public int getDuration() {
|
||||
return this.duration;
|
||||
}
|
||||
|
||||
public void setDuration(int duration) {
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof EffectEntry)) return false;
|
||||
EffectEntry that = (EffectEntry) obj;
|
||||
if (this.duration != that.duration) return false;
|
||||
return this.type.equals(that.type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.type, this.duration);
|
||||
}
|
||||
}
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.component.builtin.item;
|
||||
|
||||
import com.github.retrooper.packetevents.util.Filterable;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class WritableBookContent {
|
||||
|
||||
private List<Filterable<String>> pages;
|
||||
|
||||
public WritableBookContent(List<Filterable<String>> pages) {
|
||||
this.pages = pages;
|
||||
}
|
||||
|
||||
public static WritableBookContent read(PacketWrapper<?> wrapper) {
|
||||
List<Filterable<String>> pages = wrapper.readList(ew -> Filterable.read(
|
||||
ew, eew -> eew.readString(1024)));
|
||||
return new WritableBookContent(pages);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, WritableBookContent content) {
|
||||
wrapper.writeList(content.pages, (ew, page) -> Filterable.write(
|
||||
ew, page, (eew, text) -> eew.writeString(text, 1024)));
|
||||
}
|
||||
|
||||
public @Nullable Filterable<String> getPage(int index) {
|
||||
return index >= 0 && index < this.pages.size() ? this.pages.get(index) : null;
|
||||
}
|
||||
|
||||
public void addPage(Filterable<String> page) {
|
||||
this.pages.add(page);
|
||||
}
|
||||
|
||||
public List<Filterable<String>> getPages() {
|
||||
return this.pages;
|
||||
}
|
||||
|
||||
public void setPages(List<Filterable<String>> pages) {
|
||||
this.pages = pages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof WritableBookContent)) return false;
|
||||
WritableBookContent that = (WritableBookContent) obj;
|
||||
return this.pages.equals(that.pages);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(this.pages);
|
||||
}
|
||||
}
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.component.builtin.item;
|
||||
|
||||
import com.github.retrooper.packetevents.util.Filterable;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class WrittenBookContent {
|
||||
|
||||
private Filterable<String> title;
|
||||
private String author;
|
||||
private int generation;
|
||||
private List<Filterable<Component>> pages;
|
||||
private boolean resolved;
|
||||
|
||||
public WrittenBookContent(
|
||||
Filterable<String> title, String author, int generation,
|
||||
List<Filterable<Component>> pages, boolean resolved
|
||||
) {
|
||||
this.title = title;
|
||||
this.author = author;
|
||||
this.generation = generation;
|
||||
this.pages = pages;
|
||||
this.resolved = resolved;
|
||||
}
|
||||
|
||||
public static WrittenBookContent read(PacketWrapper<?> wrapper) {
|
||||
Filterable<String> title = Filterable.read(wrapper, ew -> ew.readString(32));
|
||||
String author = wrapper.readString();
|
||||
int generation = wrapper.readVarInt();
|
||||
List<Filterable<Component>> pages = wrapper.readList(ew -> Filterable.read(
|
||||
ew, PacketWrapper::readComponent));
|
||||
boolean resolved = wrapper.readBoolean();
|
||||
return new WrittenBookContent(title, author, generation, pages, resolved);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, WrittenBookContent content) {
|
||||
Filterable.write(wrapper, content.title, (ew, text) -> ew.writeString(text, 32));
|
||||
wrapper.writeString(content.author);
|
||||
wrapper.writeVarInt(content.generation);
|
||||
wrapper.writeList(content.pages, (ew, page) -> Filterable.write(
|
||||
ew, page, PacketWrapper::writeComponent));
|
||||
wrapper.writeBoolean(content.resolved);
|
||||
}
|
||||
|
||||
public Filterable<String> getTitle() {
|
||||
return this.title;
|
||||
}
|
||||
|
||||
public void setTitle(Filterable<String> title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
return this.author;
|
||||
}
|
||||
|
||||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
public int getGeneration() {
|
||||
return this.generation;
|
||||
}
|
||||
|
||||
public void setGeneration(int generation) {
|
||||
this.generation = generation;
|
||||
}
|
||||
|
||||
public @Nullable Filterable<Component> getPage(int index) {
|
||||
return index >= 0 && index < this.pages.size() ? this.pages.get(index) : null;
|
||||
}
|
||||
|
||||
public void addPage(Filterable<Component> page) {
|
||||
this.pages.add(page);
|
||||
}
|
||||
|
||||
public List<Filterable<Component>> getPages() {
|
||||
return this.pages;
|
||||
}
|
||||
|
||||
public void setPages(List<Filterable<Component>> pages) {
|
||||
this.pages = pages;
|
||||
}
|
||||
|
||||
public boolean isResolved() {
|
||||
return this.resolved;
|
||||
}
|
||||
|
||||
public void setResolved(boolean resolved) {
|
||||
this.resolved = resolved;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof WrittenBookContent)) return false;
|
||||
WrittenBookContent that = (WrittenBookContent) obj;
|
||||
if (this.generation != that.generation) return false;
|
||||
if (this.resolved != that.resolved) return false;
|
||||
if (!this.title.equals(that.title)) return false;
|
||||
if (!this.author.equals(that.author)) return false;
|
||||
return this.pages.equals(that.pages);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.title, this.author, this.generation, this.pages, this.resolved);
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2023 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.entity.armadillo;
|
||||
|
||||
public enum ArmadilloState {
|
||||
|
||||
IDLE,
|
||||
ROLLING,
|
||||
SCARED,
|
||||
UNROLLING,
|
||||
}
|
||||
+90
-34
@@ -20,25 +20,27 @@ package com.github.retrooper.packetevents.protocol.entity.data;
|
||||
|
||||
import com.github.retrooper.packetevents.PacketEvents;
|
||||
import com.github.retrooper.packetevents.manager.server.ServerVersion;
|
||||
import com.github.retrooper.packetevents.protocol.entity.armadillo.ArmadilloState;
|
||||
import com.github.retrooper.packetevents.protocol.entity.pose.EntityPose;
|
||||
import com.github.retrooper.packetevents.protocol.entity.sniffer.SnifferState;
|
||||
import com.github.retrooper.packetevents.protocol.entity.villager.VillagerData;
|
||||
import com.github.retrooper.packetevents.protocol.item.ItemStack;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
|
||||
import com.github.retrooper.packetevents.protocol.particle.Particle;
|
||||
import com.github.retrooper.packetevents.protocol.particle.type.ParticleType;
|
||||
import com.github.retrooper.packetevents.protocol.particle.type.ParticleTypes;
|
||||
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
import com.github.retrooper.packetevents.protocol.world.BlockFace;
|
||||
import com.github.retrooper.packetevents.protocol.world.WorldBlockPosition;
|
||||
import com.github.retrooper.packetevents.resources.ResourceLocation;
|
||||
import com.github.retrooper.packetevents.util.TypesBuilder;
|
||||
import com.github.retrooper.packetevents.util.TypesBuilderData;
|
||||
import com.github.retrooper.packetevents.util.Quaternion4f;
|
||||
import com.github.retrooper.packetevents.util.Vector3f;
|
||||
import com.github.retrooper.packetevents.util.Vector3i;
|
||||
import com.github.retrooper.packetevents.util.mappings.TypesBuilder;
|
||||
import com.github.retrooper.packetevents.util.mappings.TypesBuilderData;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
@@ -53,13 +55,7 @@ public class EntityDataTypes {
|
||||
|
||||
private static final Map<String, EntityDataType<?>> ENTITY_DATA_TYPE_MAP = new HashMap<>();
|
||||
private static final Map<Byte, Map<Integer, EntityDataType<?>>> ENTITY_DATA_TYPE_ID_MAP = new HashMap<>();
|
||||
protected static final TypesBuilder TYPES_BUILDER = new TypesBuilder("entity/entity_data_type_mappings",
|
||||
ClientVersion.V_1_8,
|
||||
ClientVersion.V_1_9,
|
||||
ClientVersion.V_1_11,
|
||||
ClientVersion.V_1_13,
|
||||
ClientVersion.V_1_14,
|
||||
ClientVersion.V_1_19);
|
||||
protected static final TypesBuilder TYPES_BUILDER = new TypesBuilder("entity/entity_data_type_mappings");
|
||||
|
||||
public static final EntityDataType<Byte> BYTE = define("byte", PacketWrapper::readByte, PacketWrapper::writeByte);
|
||||
|
||||
@@ -79,13 +75,19 @@ public class EntityDataTypes {
|
||||
}
|
||||
});
|
||||
|
||||
public static final EntityDataType<Long> LONG = define("long", PacketWrapper::readVarLong, PacketWrapper::writeVarLong);
|
||||
|
||||
public static final EntityDataType<Float> FLOAT = define("float", PacketWrapper::readFloat, PacketWrapper::writeFloat);
|
||||
|
||||
public static final EntityDataType<String> STRING = define("string", PacketWrapper::readString, PacketWrapper::writeString);
|
||||
|
||||
public static final EntityDataType<Component> COMPONENT = define("component", PacketWrapper::readComponent, PacketWrapper::writeComponent);
|
||||
@Deprecated
|
||||
public static final EntityDataType<String> COMPONENT = define("component", PacketWrapper::readComponentJSON, PacketWrapper::writeComponentJSON);
|
||||
public static final EntityDataType<Component> ADV_COMPONENT = define("component", PacketWrapper::readComponent, PacketWrapper::writeComponent);
|
||||
|
||||
public static final EntityDataType<Optional<Component>> OPTIONAL_COMPONENT = define("optional_component", readOptionalComponentDeserializer(), writeOptionalComponentSerializer());
|
||||
@Deprecated
|
||||
public static final EntityDataType<Optional<String>> OPTIONAL_COMPONENT = define("optional_component", readOptionalComponentJSONDeserializer(), writeOptionalComponentJSONSerializer());
|
||||
public static final EntityDataType<Optional<Component>> OPTIONAL_ADV_COMPONENT = define("optional_component", readOptionalComponentDeserializer(), writeOptionalComponentSerializer());
|
||||
|
||||
public static final EntityDataType<ItemStack> ITEMSTACK = define("itemstack", PacketWrapper::readItemStack, PacketWrapper::writeItemStack);
|
||||
|
||||
@@ -136,18 +138,14 @@ public class EntityDataTypes {
|
||||
(PacketWrapper<?> wrapper, Optional<UUID> value) ->
|
||||
wrapper.writeOptional(value.orElse(null), PacketWrapper::writeUUID));
|
||||
|
||||
public static final EntityDataType<Integer> BLOCK_STATE = define("block_state",
|
||||
readIntDeserializer(), writeIntSerializer());
|
||||
|
||||
public static final EntityDataType<Integer> OPTIONAL_BLOCK_STATE = define("optional_block_state", readIntDeserializer(), writeIntSerializer());
|
||||
|
||||
public static final EntityDataType<NBTCompound> NBT = define("nbt", PacketWrapper::readNBT, PacketWrapper::writeNBT);
|
||||
|
||||
public static final EntityDataType<Particle> PARTICLE = define("particle", wrapper -> {
|
||||
int id = wrapper.readVarInt();
|
||||
ParticleType type = ParticleTypes.getById(PacketEvents.getAPI().getServerManager().getVersion().toClientVersion(), id);
|
||||
return new Particle(type, type.readDataFunction().apply(wrapper));
|
||||
}, (wrapper, particle) -> {
|
||||
wrapper.writeVarInt(particle.getType().getId(PacketEvents.getAPI().getServerManager().getVersion().toClientVersion()));
|
||||
particle.getType().writeDataFunction().accept(wrapper, particle.getData());
|
||||
});
|
||||
public static final EntityDataType<Particle<?>> PARTICLE = define("particle", Particle::read, Particle::write);
|
||||
|
||||
public static final EntityDataType<VillagerData> VILLAGER_DATA = define("villager_data", PacketWrapper::readVillagerData, PacketWrapper::writeVillagerData);
|
||||
|
||||
@@ -176,6 +174,42 @@ public class EntityDataTypes {
|
||||
|
||||
public static final EntityDataType<Integer> PAINTING_VARIANT_TYPE = define("painting_variant_type", readIntDeserializer(), writeIntSerializer());
|
||||
|
||||
public static final EntityDataType<SnifferState> SNIFFER_STATE = define("sniffer_state", (PacketWrapper<?> wrapper) -> {
|
||||
int id = wrapper.readVarInt();
|
||||
return SnifferState.values()[id];
|
||||
}, (PacketWrapper<?> wrapper, SnifferState value) -> wrapper.writeVarInt(value.ordinal()));
|
||||
|
||||
public static final EntityDataType<Vector3f> VECTOR3F = define("vector3f",
|
||||
(PacketWrapper<?> wrapper) -> new Vector3f(wrapper.readFloat(), wrapper.readFloat(), wrapper.readFloat()),
|
||||
(PacketWrapper<?> wrapper, Vector3f value) -> {
|
||||
wrapper.writeFloat(value.x);
|
||||
wrapper.writeFloat(value.y);
|
||||
wrapper.writeFloat(value.z);
|
||||
});
|
||||
|
||||
public static final EntityDataType<Quaternion4f> QUATERNION = define("quaternion",
|
||||
(PacketWrapper<?> wrapper) -> new Quaternion4f(wrapper.readFloat(), wrapper.readFloat(), wrapper.readFloat(), wrapper.readFloat()),
|
||||
(PacketWrapper<?> wrapper, Quaternion4f value) -> {
|
||||
wrapper.writeFloat(value.getX());
|
||||
wrapper.writeFloat(value.getY());
|
||||
wrapper.writeFloat(value.getZ());
|
||||
wrapper.writeFloat(value.getW());
|
||||
});
|
||||
|
||||
// Added in 1.20.5
|
||||
public static final EntityDataType<ArmadilloState> ARMADILLO_STATE = define("armadillo_state",
|
||||
(PacketWrapper<?> wrapper) -> ArmadilloState.values()[wrapper.readVarInt()],
|
||||
(PacketWrapper<?> wrapper, ArmadilloState value) -> wrapper.writeVarInt(value.ordinal())
|
||||
);
|
||||
|
||||
public static final EntityDataType<List<Particle<?>>> PARTICLES = define("particles",
|
||||
wrapper -> wrapper.readList(Particle::read),
|
||||
(wrapper, particles) -> wrapper.writeList(particles, Particle::write)
|
||||
);
|
||||
|
||||
public static final EntityDataType<Integer> WOLF_VARIANT =
|
||||
define("wolf_variant_type", readIntDeserializer(), writeIntSerializer());
|
||||
|
||||
public static EntityDataType<?> getById(ClientVersion version, int id) {
|
||||
int index = TYPES_BUILDER.getDataIndex(version);
|
||||
Map<Integer, EntityDataType<?>> typeIdMap = ENTITY_DATA_TYPE_ID_MAP.get((byte) index);
|
||||
@@ -229,26 +263,44 @@ public class EntityDataTypes {
|
||||
};
|
||||
}
|
||||
|
||||
private static <T> Function<PacketWrapper<?>, T> readOptionalComponentDeserializer() {
|
||||
@Deprecated
|
||||
private static Function<PacketWrapper<?>, Optional<String>> readOptionalComponentJSONDeserializer() {
|
||||
return (PacketWrapper<?> wrapper) -> {
|
||||
if (wrapper.readBoolean()) {
|
||||
return (T) Optional.of(wrapper.readComponent());
|
||||
return Optional.of(wrapper.readComponentJSON());
|
||||
} else {
|
||||
return (T) Optional.empty();
|
||||
return Optional.empty();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static <T> BiConsumer<PacketWrapper<?>, T> writeOptionalComponentSerializer() {
|
||||
return (PacketWrapper<?> wrapper, T value) -> {
|
||||
if (value instanceof Optional) {
|
||||
Optional<Component> optional = (Optional<Component>) value;
|
||||
if (optional.isPresent()) {
|
||||
wrapper.writeBoolean(true);
|
||||
wrapper.writeComponent(optional.get());
|
||||
} else {
|
||||
wrapper.writeBoolean(false);
|
||||
}
|
||||
@Deprecated
|
||||
private static BiConsumer<PacketWrapper<?>, Optional<String>> writeOptionalComponentJSONSerializer() {
|
||||
return (PacketWrapper<?> wrapper, Optional<String> value) -> {
|
||||
if (value != null && value.isPresent()) {
|
||||
wrapper.writeBoolean(true);
|
||||
wrapper.writeComponentJSON(value.get());
|
||||
} else {
|
||||
wrapper.writeBoolean(false);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static Function<PacketWrapper<?>, Optional<Component>> readOptionalComponentDeserializer() {
|
||||
return (PacketWrapper<?> wrapper) -> {
|
||||
if (wrapper.readBoolean()) {
|
||||
return Optional.of(wrapper.readComponent());
|
||||
} else {
|
||||
return Optional.empty();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static BiConsumer<PacketWrapper<?>, Optional<Component>> writeOptionalComponentSerializer() {
|
||||
return (PacketWrapper<?> wrapper, Optional<Component> value) -> {
|
||||
if (value != null && value.isPresent()) {
|
||||
wrapper.writeBoolean(true);
|
||||
wrapper.writeComponent(value.get());
|
||||
} else {
|
||||
wrapper.writeBoolean(false);
|
||||
}
|
||||
@@ -313,4 +365,8 @@ public class EntityDataTypes {
|
||||
}
|
||||
}
|
||||
|
||||
static {
|
||||
TYPES_BUILDER.unloadFileMappings();
|
||||
}
|
||||
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package com.github.retrooper.packetevents.protocol.entity.data;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This is an interface that provides a list of entity data.
|
||||
* This allows custom addon libraries to implement metadata classes for various entities
|
||||
* which can then be used in our API.
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public interface EntityMetadataProvider {
|
||||
/**
|
||||
* PacketEvents is retrieving the metadata of this specific entity.
|
||||
* PacketEvents provides you with the protocol version that the library is running on
|
||||
* to allow you tu specify different metadata depending on the version.
|
||||
* You are free to ignore it at the cost of your features not working on all versions.
|
||||
* @param version The protocol version of the format we expect the metadata to be in.
|
||||
* @return Metadata (list of entity data)
|
||||
*/
|
||||
List<EntityData> entityData(ClientVersion version);
|
||||
|
||||
/**
|
||||
* Similar to {@link #entityData(ClientVersion)} but does not provide a protocol version.
|
||||
* It is not advised to use nor implement this.
|
||||
* It is deprecated because it restricts you by not providing you the format in which the metadata should be.
|
||||
* @return Metadata (list of entity data)
|
||||
* @deprecated Does not specify format of metadata, therefore not advised to use this. It will assume the current latest version.
|
||||
*/
|
||||
@Deprecated
|
||||
default List<EntityData> entityData() {
|
||||
return entityData(ClientVersion.getLatest());
|
||||
}
|
||||
}
|
||||
-343
@@ -1,343 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.entity.data.provider;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
|
||||
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
|
||||
import com.github.retrooper.packetevents.protocol.entity.pose.EntityPose;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class EntityDataProvider implements DataProvider {
|
||||
@Nullable
|
||||
private Component customName;
|
||||
|
||||
private boolean customNameVisible;
|
||||
private EntityPose pose = EntityPose.STANDING;
|
||||
private int airTicks;
|
||||
private int ticksFrozenInPowderedSnow = 0;
|
||||
private boolean onFire;
|
||||
private boolean crouching;
|
||||
//Now unused
|
||||
private boolean riding;
|
||||
|
||||
private boolean sprinting;
|
||||
private boolean swimming;
|
||||
private boolean invisible;
|
||||
private boolean glowing;
|
||||
private boolean flyingWithElytra;
|
||||
private boolean silent;
|
||||
private boolean hasGravity = true;
|
||||
|
||||
@Nullable
|
||||
public Component getCustomName() {
|
||||
return customName;
|
||||
}
|
||||
|
||||
public void setCustomName(@Nullable Component customName) {
|
||||
this.customName = customName;
|
||||
}
|
||||
|
||||
public boolean isCustomNameVisible() {
|
||||
return customNameVisible;
|
||||
}
|
||||
|
||||
public void setCustomNameVisible(boolean customNameVisible) {
|
||||
this.customNameVisible = customNameVisible;
|
||||
}
|
||||
|
||||
public EntityPose getPose() {
|
||||
return pose;
|
||||
}
|
||||
|
||||
public void setPose(EntityPose pose) {
|
||||
this.pose = pose;
|
||||
}
|
||||
|
||||
public int getAirTicks() {
|
||||
return airTicks;
|
||||
}
|
||||
|
||||
public void setAirTicks(int airTicks) {
|
||||
this.airTicks = airTicks;
|
||||
}
|
||||
|
||||
public int getTicksFrozenInPowderedSnow() {
|
||||
return ticksFrozenInPowderedSnow;
|
||||
}
|
||||
|
||||
public void setTicksFrozenInPowderedSnow(int ticksFrozenInPowderedSnow) {
|
||||
this.ticksFrozenInPowderedSnow = ticksFrozenInPowderedSnow;
|
||||
}
|
||||
|
||||
public boolean isOnFire() {
|
||||
return onFire;
|
||||
}
|
||||
|
||||
public void setOnFire(boolean onFire) {
|
||||
this.onFire = onFire;
|
||||
}
|
||||
|
||||
public boolean isCrouching() {
|
||||
return crouching;
|
||||
}
|
||||
|
||||
public void setCrouching(boolean crouching) {
|
||||
this.crouching = crouching;
|
||||
}
|
||||
|
||||
public boolean isRiding() {
|
||||
return riding;
|
||||
}
|
||||
|
||||
public void setRiding(boolean riding) {
|
||||
this.riding = riding;
|
||||
}
|
||||
|
||||
public boolean isSprinting() {
|
||||
return sprinting;
|
||||
}
|
||||
|
||||
public void setSprinting(boolean sprinting) {
|
||||
this.sprinting = sprinting;
|
||||
}
|
||||
|
||||
public boolean isSwimming() {
|
||||
return swimming;
|
||||
}
|
||||
|
||||
public void setSwimming(boolean swimming) {
|
||||
this.swimming = swimming;
|
||||
}
|
||||
|
||||
public boolean isInvisible() {
|
||||
return invisible;
|
||||
}
|
||||
|
||||
public void setInvisible(boolean invisible) {
|
||||
this.invisible = invisible;
|
||||
}
|
||||
|
||||
public boolean isGlowing() {
|
||||
return glowing;
|
||||
}
|
||||
|
||||
public void setGlowing(boolean glowing) {
|
||||
this.glowing = glowing;
|
||||
}
|
||||
|
||||
public boolean isFlyingWithElytra() {
|
||||
return flyingWithElytra;
|
||||
}
|
||||
|
||||
public void setFlyingWithElytra(boolean flyingWithElytra) {
|
||||
this.flyingWithElytra = flyingWithElytra;
|
||||
}
|
||||
|
||||
public boolean isSilent() {
|
||||
return silent;
|
||||
}
|
||||
|
||||
public void setSilent(boolean silent) {
|
||||
this.silent = silent;
|
||||
}
|
||||
|
||||
public boolean isHasGravity() {
|
||||
return hasGravity;
|
||||
}
|
||||
|
||||
public void setHasGravity(boolean hasGravity) {
|
||||
this.hasGravity = hasGravity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntityData> encode() {
|
||||
byte mask = 0x00;
|
||||
if (onFire) {
|
||||
mask |= 0x01;
|
||||
}
|
||||
if (crouching) {
|
||||
mask |= 0x02;
|
||||
}
|
||||
//TODO Rethink, should we add this?
|
||||
if (riding) {
|
||||
mask |= 0x04;
|
||||
}
|
||||
if (sprinting) {
|
||||
mask |= 0x08;
|
||||
}
|
||||
if (swimming) {
|
||||
mask |= 0x10;
|
||||
}
|
||||
if (invisible) {
|
||||
mask |= 0x20;
|
||||
}
|
||||
if (glowing) {
|
||||
mask |= 0x40;
|
||||
}
|
||||
if (flyingWithElytra) {
|
||||
mask |= 0x80;
|
||||
}
|
||||
List<EntityData> metadata = new ArrayList<>(8);
|
||||
metadata.add(new EntityData(0, EntityDataTypes.BYTE, mask));
|
||||
metadata.add(new EntityData(1, EntityDataTypes.INT, airTicks));
|
||||
metadata.add(new EntityData(2, EntityDataTypes.OPTIONAL_COMPONENT, Optional.ofNullable(customName)));
|
||||
metadata.add(new EntityData(3, EntityDataTypes.BOOLEAN, customNameVisible));
|
||||
metadata.add(new EntityData(4, EntityDataTypes.BOOLEAN, silent));
|
||||
metadata.add(new EntityData(5, EntityDataTypes.BOOLEAN, !hasGravity));
|
||||
metadata.add(new EntityData(6, EntityDataTypes.ENTITY_POSE, pose));
|
||||
metadata.add(new EntityData(7, EntityDataTypes.INT, ticksFrozenInPowderedSnow));
|
||||
return metadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(List<EntityData> data) {
|
||||
for (EntityData entityData : data) {
|
||||
switch (entityData.getIndex()) {
|
||||
case 0:
|
||||
byte mask = (byte) entityData.getValue();
|
||||
onFire = (mask & 0x01) != 0;
|
||||
crouching = (mask & 0x02) != 0;
|
||||
riding = (mask & 0x04) != 0;
|
||||
sprinting = (mask & 0x08) != 0;
|
||||
swimming = (mask & 0x10) != 0;
|
||||
invisible = (mask & 0x20) != 0;
|
||||
glowing = (mask & 0x40) != 0;
|
||||
flyingWithElytra = (mask & 0x80) != 0;
|
||||
break;
|
||||
case 1:
|
||||
airTicks = (int) entityData.getValue();
|
||||
break;
|
||||
case 2:
|
||||
customName = ((Optional<Component>) entityData.getValue()).orElse(null);
|
||||
break;
|
||||
case 3:
|
||||
customNameVisible = (boolean) entityData.getValue();
|
||||
break;
|
||||
case 4:
|
||||
silent = (boolean) entityData.getValue();
|
||||
break;
|
||||
case 5:
|
||||
hasGravity = !(boolean) entityData.getValue();
|
||||
break;
|
||||
case 6:
|
||||
pose = (EntityPose) entityData.getValue();
|
||||
break;
|
||||
case 7:
|
||||
ticksFrozenInPowderedSnow = (int) entityData.getValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static EntityBuilder<EntityBuilder> builderEntity() {
|
||||
return new EntityBuilder<>(new EntityDataProvider());
|
||||
}
|
||||
|
||||
public static class EntityBuilder<T extends EntityBuilder> {
|
||||
protected EntityDataProvider provider;
|
||||
|
||||
public EntityBuilder(EntityDataProvider provider) {
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
public T customName(@Nullable Component customName) {
|
||||
((EntityDataProvider) provider).setCustomName(customName);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T customNameVisible(boolean customNameVisible) {
|
||||
((EntityDataProvider) provider).setCustomNameVisible(customNameVisible);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T pose(EntityPose pose) {
|
||||
((EntityDataProvider) provider).setPose(pose);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T onFire(boolean onFire) {
|
||||
((EntityDataProvider) provider).setOnFire(onFire);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T crouching(boolean crouching) {
|
||||
((EntityDataProvider) provider).setCrouching(crouching);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T riding(boolean riding) {
|
||||
((EntityDataProvider) provider).setRiding(riding);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T sprinting(boolean sprinting) {
|
||||
((EntityDataProvider) provider).setSprinting(sprinting);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T swimming(boolean swimming) {
|
||||
((EntityDataProvider) provider).setSwimming(swimming);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T invisible(boolean invisible) {
|
||||
((EntityDataProvider) provider).setInvisible(invisible);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T glowing(boolean glowing) {
|
||||
((EntityDataProvider) provider).setGlowing(glowing);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T flyingWithElytra(boolean flyingWithElytra) {
|
||||
((EntityDataProvider) provider).setFlyingWithElytra(flyingWithElytra);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T silent(boolean silent) {
|
||||
((EntityDataProvider) provider).setSilent(silent);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T hasGravity(boolean hasGravity) {
|
||||
((EntityDataProvider) provider).setHasGravity(hasGravity);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T airTicks(int airTicks) {
|
||||
((EntityDataProvider) provider).setAirTicks(airTicks);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T ticksFrozenInPowderedSnow(int ticksFrozenInPowderedSnow) {
|
||||
((EntityDataProvider) provider).setTicksFrozenInPowderedSnow(ticksFrozenInPowderedSnow);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public <K extends EntityDataProvider> K build() {
|
||||
return (K) provider;
|
||||
}
|
||||
}
|
||||
}
|
||||
-232
@@ -1,232 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.entity.data.provider;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
|
||||
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
|
||||
import com.github.retrooper.packetevents.protocol.player.InteractionHand;
|
||||
import com.github.retrooper.packetevents.util.Vector3i;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class LivingEntityDataProvider extends EntityDataProvider {
|
||||
private boolean handActive;
|
||||
private InteractionHand hand = InteractionHand.MAIN_HAND;
|
||||
private boolean isInRiptideSpinAttack;
|
||||
private float health = 1.0f;
|
||||
private int potionEffectColor;
|
||||
private boolean potionEffectAmbient;
|
||||
private int arrowInBodyCount;
|
||||
private int beeStingsInBodyCount;
|
||||
@Nullable
|
||||
private Vector3i sleepingPosition;
|
||||
|
||||
|
||||
public boolean isHandActive() {
|
||||
return handActive;
|
||||
}
|
||||
|
||||
public void setHandActive(boolean handActive) {
|
||||
this.handActive = handActive;
|
||||
}
|
||||
|
||||
public InteractionHand getHand() {
|
||||
return hand;
|
||||
}
|
||||
|
||||
public void setHand(InteractionHand hand) {
|
||||
this.hand = hand;
|
||||
}
|
||||
|
||||
public boolean isInRiptideSpinAttack() {
|
||||
return isInRiptideSpinAttack;
|
||||
}
|
||||
|
||||
public void setInRiptideSpinAttack(boolean inRiptideSpinAttack) {
|
||||
isInRiptideSpinAttack = inRiptideSpinAttack;
|
||||
}
|
||||
|
||||
public float getHealth() {
|
||||
return health;
|
||||
}
|
||||
|
||||
public void setHealth(float health) {
|
||||
this.health = health;
|
||||
}
|
||||
|
||||
public int getPotionEffectColor() {
|
||||
return potionEffectColor;
|
||||
}
|
||||
|
||||
public void setPotionEffectColor(int potionEffectColor) {
|
||||
this.potionEffectColor = potionEffectColor;
|
||||
}
|
||||
|
||||
public boolean isPotionEffectAmbient() {
|
||||
return potionEffectAmbient;
|
||||
}
|
||||
|
||||
public void setPotionEffectAmbient(boolean potionEffectAmbient) {
|
||||
this.potionEffectAmbient = potionEffectAmbient;
|
||||
}
|
||||
|
||||
public int getArrowInBodyCount() {
|
||||
return arrowInBodyCount;
|
||||
}
|
||||
|
||||
public void setArrowInBodyCount(int arrowInBodyCount) {
|
||||
this.arrowInBodyCount = arrowInBodyCount;
|
||||
}
|
||||
|
||||
public int getBeeStingsInBodyCount() {
|
||||
return beeStingsInBodyCount;
|
||||
}
|
||||
|
||||
public void setBeeStingsInBodyCount(int beeStingsInBodyCount) {
|
||||
this.beeStingsInBodyCount = beeStingsInBodyCount;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Vector3i getSleepingPosition() {
|
||||
return sleepingPosition;
|
||||
}
|
||||
|
||||
public void setSleepingPosition(@Nullable Vector3i sleepingPosition) {
|
||||
this.sleepingPosition = sleepingPosition;
|
||||
}
|
||||
|
||||
public static LivingEntityBuilder<LivingEntityBuilder> builderLivingEntity() {
|
||||
return new LivingEntityBuilder<>(new LivingEntityDataProvider());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntityData> encode() {
|
||||
List<EntityData> metadata = super.encode();
|
||||
byte mask = 0x00;
|
||||
if (handActive) {
|
||||
mask |= 0x01;
|
||||
}
|
||||
|
||||
//TODO Confirm
|
||||
if (hand == InteractionHand.OFF_HAND) {
|
||||
mask |= 0x02;
|
||||
}
|
||||
|
||||
if (isInRiptideSpinAttack) {
|
||||
mask |= 0x04;
|
||||
}
|
||||
|
||||
|
||||
metadata.add(new EntityData(8, EntityDataTypes.BYTE, mask));
|
||||
metadata.add(new EntityData(9, EntityDataTypes.FLOAT, health));
|
||||
metadata.add(new EntityData(10, EntityDataTypes.INT, potionEffectColor));
|
||||
metadata.add(new EntityData(11, EntityDataTypes.BOOLEAN, potionEffectAmbient));
|
||||
metadata.add(new EntityData(12, EntityDataTypes.INT, arrowInBodyCount));
|
||||
metadata.add(new EntityData(13, EntityDataTypes.INT, beeStingsInBodyCount));
|
||||
metadata.add(new EntityData(14, EntityDataTypes.OPTIONAL_BLOCK_POSITION, Optional.ofNullable(sleepingPosition)));
|
||||
return metadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(List<EntityData> data) {
|
||||
super.decode(data);
|
||||
for (EntityData entityData : data) {
|
||||
switch (entityData.getIndex()) {
|
||||
case 8:
|
||||
byte mask = (byte) entityData.getValue();
|
||||
handActive = (mask & 0x01) != 0;
|
||||
//TODO Test, look into
|
||||
hand = (mask & 0x02) != 0 ? InteractionHand.OFF_HAND : InteractionHand.MAIN_HAND;
|
||||
isInRiptideSpinAttack = (mask & 0x04) != 0;
|
||||
break;
|
||||
case 9:
|
||||
health = (float) entityData.getValue();
|
||||
break;
|
||||
case 10:
|
||||
potionEffectColor = (int) entityData.getValue();
|
||||
break;
|
||||
case 11:
|
||||
potionEffectAmbient = (boolean) entityData.getValue();
|
||||
break;
|
||||
case 12:
|
||||
arrowInBodyCount = (int) entityData.getValue();
|
||||
break;
|
||||
case 13:
|
||||
beeStingsInBodyCount = (int) entityData.getValue();
|
||||
break;
|
||||
case 14:
|
||||
sleepingPosition = ((Optional<Vector3i>) entityData.getValue()).orElse(null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class LivingEntityBuilder<T extends LivingEntityBuilder> extends EntityDataProvider.EntityBuilder<T> {
|
||||
public LivingEntityBuilder(LivingEntityDataProvider livingEntityDataProvider) {
|
||||
super(livingEntityDataProvider);
|
||||
}
|
||||
|
||||
public T handActive(boolean handActive) {
|
||||
((LivingEntityDataProvider) provider).setHandActive(handActive);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T hand(InteractionHand hand) {
|
||||
((LivingEntityDataProvider) provider).setHand(hand);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T isInRiptideSpinAttack(boolean isInRiptideSpinAttack) {
|
||||
((LivingEntityDataProvider) provider).setInRiptideSpinAttack(isInRiptideSpinAttack);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T health(float health) {
|
||||
((LivingEntityDataProvider) provider).setHealth(health);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T potionEffectColor(int potionEffectColor) {
|
||||
((LivingEntityDataProvider) provider).setPotionEffectColor(potionEffectColor);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T potionEffectAmbient(boolean potionEffectAmbient) {
|
||||
((LivingEntityDataProvider) provider).setPotionEffectAmbient(potionEffectAmbient);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T arrowInBodyCount(int arrowInBodyCount) {
|
||||
((LivingEntityDataProvider) provider).setArrowInBodyCount(arrowInBodyCount);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T beeStingsInBodyCount(int beeStingsInBodyCount) {
|
||||
((LivingEntityDataProvider) provider).setBeeStingsInBodyCount(beeStingsInBodyCount);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T sleepingPosition(@Nullable Vector3i sleepingPosition) {
|
||||
((LivingEntityDataProvider) provider).setSleepingPosition(sleepingPosition);
|
||||
return (T) this;
|
||||
}
|
||||
}
|
||||
}
|
||||
-168
@@ -1,168 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.entity.data.provider;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
|
||||
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
|
||||
import com.github.retrooper.packetevents.protocol.player.HumanoidArm;
|
||||
import com.github.retrooper.packetevents.protocol.player.SkinSection;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PlayerDataProvider extends LivingEntityDataProvider {
|
||||
private float additionalHealth;
|
||||
private int score;
|
||||
private byte skinPartsMask = SkinSection.ALL.getMask();
|
||||
private HumanoidArm mainArm = HumanoidArm.RIGHT;
|
||||
private NBTCompound leftShoulderNBT = new NBTCompound();
|
||||
private NBTCompound rightShoulderNBT = new NBTCompound();
|
||||
|
||||
public float getAdditionalHealth() {
|
||||
return additionalHealth;
|
||||
}
|
||||
|
||||
public void setAdditionalHealth(float additionalHealth) {
|
||||
this.additionalHealth = additionalHealth;
|
||||
}
|
||||
|
||||
public int getScore() {
|
||||
return score;
|
||||
}
|
||||
|
||||
public void setScore(int score) {
|
||||
this.score = score;
|
||||
}
|
||||
|
||||
public byte getSkinPartsMask() {
|
||||
return skinPartsMask;
|
||||
}
|
||||
|
||||
public void setSkinPartsMask(byte skinPartsMask) {
|
||||
this.skinPartsMask = skinPartsMask;
|
||||
}
|
||||
|
||||
public HumanoidArm getMainArm() {
|
||||
return mainArm;
|
||||
}
|
||||
|
||||
public void setMainArm(HumanoidArm mainArm) {
|
||||
this.mainArm = mainArm;
|
||||
}
|
||||
|
||||
public NBTCompound getLeftShoulderNBT() {
|
||||
return leftShoulderNBT;
|
||||
}
|
||||
|
||||
public void setLeftShoulderNBT(NBTCompound leftShoulderNBT) {
|
||||
this.leftShoulderNBT = leftShoulderNBT;
|
||||
}
|
||||
|
||||
public NBTCompound getRightShoulderNBT() {
|
||||
return rightShoulderNBT;
|
||||
}
|
||||
|
||||
public void setRightShoulderNBT(NBTCompound rightShoulderNBT) {
|
||||
this.rightShoulderNBT = rightShoulderNBT;
|
||||
}
|
||||
|
||||
public static PlayerBuilder<PlayerBuilder> builderPlayer() {
|
||||
return new PlayerBuilder<>(new PlayerDataProvider());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntityData> encode() {
|
||||
List<EntityData> metadata = super.encode();
|
||||
metadata.add(new EntityData(15, EntityDataTypes.FLOAT, additionalHealth));
|
||||
metadata.add(new EntityData(16, EntityDataTypes.INT, score));
|
||||
metadata.add(new EntityData(17, EntityDataTypes.BYTE, skinPartsMask));
|
||||
metadata.add(new EntityData(18, EntityDataTypes.BYTE, (byte) mainArm.ordinal()));
|
||||
metadata.add(new EntityData(19, EntityDataTypes.NBT, leftShoulderNBT));
|
||||
metadata.add(new EntityData(20, EntityDataTypes.NBT, rightShoulderNBT));
|
||||
return metadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(List<EntityData> data) {
|
||||
super.decode(data);
|
||||
for (EntityData entityData : data) {
|
||||
switch (entityData.getIndex()) {
|
||||
case 15:
|
||||
additionalHealth = (float) entityData.getValue();
|
||||
break;
|
||||
case 16:
|
||||
score = (int) entityData.getValue();
|
||||
break;
|
||||
case 17:
|
||||
skinPartsMask = (byte) entityData.getValue();
|
||||
break;
|
||||
case 18:
|
||||
mainArm = HumanoidArm.VALUES[(byte) entityData.getValue()];
|
||||
break;
|
||||
case 19:
|
||||
leftShoulderNBT = (NBTCompound) entityData.getValue();
|
||||
break;
|
||||
case 20:
|
||||
rightShoulderNBT = (NBTCompound) entityData.getValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class PlayerBuilder<T extends PlayerBuilder> extends LivingEntityDataProvider.LivingEntityBuilder<T> {
|
||||
public PlayerBuilder(PlayerDataProvider entityDataProvider) {
|
||||
super(entityDataProvider);
|
||||
}
|
||||
|
||||
public T additionalHealth(float additionalHealth) {
|
||||
((PlayerDataProvider)provider).setAdditionalHealth(additionalHealth);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T score(int score) {
|
||||
((PlayerDataProvider)provider).setScore(score);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T skinPartsMask(byte skinPartsMask) {
|
||||
((PlayerDataProvider)provider).setSkinPartsMask(skinPartsMask);
|
||||
return (T)this;
|
||||
}
|
||||
|
||||
public T skinParts(SkinSection skinSections) {
|
||||
((PlayerDataProvider)provider).setSkinPartsMask(skinSections.getMask());
|
||||
return (T)this;
|
||||
}
|
||||
|
||||
public T mainArm(HumanoidArm mainArm) {
|
||||
((PlayerDataProvider)provider).setMainArm(mainArm);
|
||||
return (T)this;
|
||||
}
|
||||
|
||||
public T leftShoulderNBT(NBTCompound leftShoulderNBT) {
|
||||
((PlayerDataProvider)provider).setLeftShoulderNBT(leftShoulderNBT);
|
||||
return (T)this;
|
||||
}
|
||||
|
||||
public T rightShoulderNBT(NBTCompound rightShoulderNBT) {
|
||||
((PlayerDataProvider)provider).setRightShoulderNBT(rightShoulderNBT);
|
||||
return (T)this;
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
-1
@@ -31,15 +31,23 @@ public enum EntityPose {
|
||||
DYING,
|
||||
CROAKING,
|
||||
USING_TONGUE,
|
||||
SITTING,
|
||||
ROARING,
|
||||
SNIFFING,
|
||||
EMERGING,
|
||||
DIGGING;
|
||||
DIGGING,
|
||||
//Added in 1.20.4
|
||||
SLIDING,
|
||||
SHOOTING,
|
||||
INHALING;
|
||||
|
||||
public int getId(ClientVersion version) {
|
||||
if (this == DYING && version.isOlderThan(ClientVersion.V_1_17)) {
|
||||
return 6;
|
||||
}
|
||||
if (this.ordinal() >= 11 && version.isOlderThan(ClientVersion.V_1_19_3)) {
|
||||
return this.ordinal() - 1;
|
||||
}
|
||||
return ordinal();
|
||||
}
|
||||
|
||||
@@ -48,6 +56,10 @@ public enum EntityPose {
|
||||
if (id == 6 && version.isOlderThan(ClientVersion.V_1_17)) {
|
||||
return DYING;
|
||||
}
|
||||
// The SITTING pose was added in 1.19.3, shifting Warden's poses by 1
|
||||
if (id >= 10 && version.isOlderThan(ClientVersion.V_1_19_3)) {
|
||||
id++;
|
||||
}
|
||||
return values()[id];
|
||||
}
|
||||
}
|
||||
+9
-8
@@ -16,13 +16,14 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.entity.data.provider;
|
||||
package com.github.retrooper.packetevents.protocol.entity.sniffer;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface DataProvider {
|
||||
List<EntityData> encode();
|
||||
void decode(List<EntityData> data);
|
||||
public enum SnifferState {
|
||||
IDLING,
|
||||
FEELING_HAPPY,
|
||||
SCENTING,
|
||||
SNIFFING,
|
||||
SEARCHING,
|
||||
DIGGING,
|
||||
RISING
|
||||
}
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.entity.transform;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.entity.type.EntityType;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
|
||||
import com.github.retrooper.packetevents.protocol.player.UserProfile;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class EntityTransformType {
|
||||
public static final EntityTransformType IDENTITY = new EntityTransformType(null, 1.0F, null);
|
||||
|
||||
private @Nullable TypeModifier typeModifier;
|
||||
private float scale;
|
||||
private @Nullable UserProfile playerSkin;
|
||||
|
||||
//Scale must be between 0.1F and 16.0F
|
||||
public EntityTransformType(@Nullable TypeModifier typeModifier, float scale, @Nullable UserProfile playerSkin) {
|
||||
this.typeModifier = typeModifier;
|
||||
this.scale = scale;
|
||||
this.playerSkin = playerSkin;
|
||||
}
|
||||
|
||||
public Optional<TypeModifier> getTypeModifier() {
|
||||
return Optional.ofNullable(typeModifier);
|
||||
}
|
||||
|
||||
public void setTypeModifier(@Nullable TypeModifier typeModifier) {
|
||||
this.typeModifier = typeModifier;
|
||||
}
|
||||
|
||||
public float getScale() {
|
||||
return scale;
|
||||
}
|
||||
|
||||
public void setScale(float scale) {
|
||||
this.scale = scale;
|
||||
}
|
||||
|
||||
public Optional<UserProfile> getPlayerSkin() {
|
||||
return Optional.ofNullable(playerSkin);
|
||||
}
|
||||
|
||||
public void setPlayerSkin(@Nullable UserProfile playerSkin) {
|
||||
this.playerSkin = playerSkin;
|
||||
}
|
||||
|
||||
public static class TypeModifier {
|
||||
private EntityType entityType;
|
||||
private @Nullable NBTCompound tag;
|
||||
|
||||
public TypeModifier(EntityType entityType, @Nullable NBTCompound tag) {
|
||||
this.entityType = entityType;
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public EntityType getEntityType() {
|
||||
return entityType;
|
||||
}
|
||||
|
||||
public void setEntityType(EntityType entityType) {
|
||||
this.entityType = entityType;
|
||||
}
|
||||
|
||||
public Optional<NBTCompound> getTag() {
|
||||
return Optional.ofNullable(tag);
|
||||
}
|
||||
|
||||
public void setTag(@Nullable NBTCompound tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
}
|
||||
}
|
||||
+29
-26
@@ -20,8 +20,8 @@ package com.github.retrooper.packetevents.protocol.entity.type;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
import com.github.retrooper.packetevents.resources.ResourceLocation;
|
||||
import com.github.retrooper.packetevents.util.TypesBuilder;
|
||||
import com.github.retrooper.packetevents.util.TypesBuilderData;
|
||||
import com.github.retrooper.packetevents.util.mappings.TypesBuilder;
|
||||
import com.github.retrooper.packetevents.util.mappings.TypesBuilderData;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -33,30 +33,8 @@ public class EntityTypes {
|
||||
//Key - mappings version, value - map with entity type ids and entity types
|
||||
private static final Map<Byte, Map<Integer, EntityType>> ENTITY_TYPE_ID_MAP = new HashMap<>();
|
||||
private static final Map<Byte, Map<Integer, EntityType>> LEGACY_ENTITY_TYPE_ID_MAP = new HashMap<>();
|
||||
private static final TypesBuilder TYPES_BUILDER = new TypesBuilder("entity/entity_type_mappings",
|
||||
ClientVersion.V_1_10,
|
||||
ClientVersion.V_1_11,
|
||||
ClientVersion.V_1_12,
|
||||
ClientVersion.V_1_13,
|
||||
ClientVersion.V_1_14,
|
||||
ClientVersion.V_1_15,
|
||||
ClientVersion.V_1_16,
|
||||
ClientVersion.V_1_16_2,
|
||||
ClientVersion.V_1_17,
|
||||
ClientVersion.V_1_19);
|
||||
private static final TypesBuilder LEGACY_TYPES_BUILDER = new TypesBuilder("entity/legacy_entity_type_mappings",
|
||||
ClientVersion.V_1_8,
|
||||
ClientVersion.V_1_9,
|
||||
ClientVersion.V_1_10,
|
||||
ClientVersion.V_1_11,
|
||||
ClientVersion.V_1_12,
|
||||
ClientVersion.V_1_13);
|
||||
|
||||
|
||||
static {
|
||||
TYPES_BUILDER.unloadFileMappings();
|
||||
LEGACY_TYPES_BUILDER.unloadFileMappings();
|
||||
}
|
||||
private static final TypesBuilder TYPES_BUILDER = new TypesBuilder("entity/entity_type_mappings");
|
||||
private static final TypesBuilder LEGACY_TYPES_BUILDER = new TypesBuilder("entity/legacy_entity_type_mappings");
|
||||
|
||||
public static EntityType define(String key, @Nullable EntityType parent) {
|
||||
TypesBuilderData data = TYPES_BUILDER.define(key);
|
||||
@@ -178,6 +156,7 @@ public class EntityTypes {
|
||||
public static final EntityType BOAT = define("boat", ENTITY);
|
||||
public static final EntityType CHEST_BOAT = define("chest_boat", BOAT);
|
||||
public static final EntityType CAT = define("cat", ABSTRACT_TAMEABLE_ANIMAL);
|
||||
public static final EntityType CAMEL = define("camel", ABSTRACT_HORSE);
|
||||
public static final EntityType SPIDER = define("spider", ABSTRACT_MONSTER);
|
||||
public static final EntityType CAVE_SPIDER = define("cave_spider", SPIDER);
|
||||
public static final EntityType CHICKEN = define("chicken", ABSTRACT_ANIMAL);
|
||||
@@ -298,4 +277,28 @@ public class EntityTypes {
|
||||
public static final EntityType MINECART_TNT = define("minecart_tnt", MINECART_ABSTRACT);
|
||||
public static final EntityType MINECART_HOPPER = define("minecart_hopper", MINECART_ABSTRACT);
|
||||
public static final EntityType MINECART_MOB_SPAWNER = define("minecart_mob_spawner", MINECART_ABSTRACT);
|
||||
|
||||
// Added in 1.19.4
|
||||
public static final EntityType DISPLAY = define("display", ENTITY);
|
||||
public static final EntityType BLOCK_DISPLAY = define("block_display", DISPLAY);
|
||||
public static final EntityType ITEM_DISPLAY = define("item_display", DISPLAY);
|
||||
public static final EntityType TEXT_DISPLAY = define("text_display", DISPLAY);
|
||||
public static final EntityType INTERACTION = define("interaction", DISPLAY);
|
||||
public static final EntityType SNIFFER = define("sniffer", ABSTRACT_ANIMAL);
|
||||
|
||||
// Added in 1.20.3
|
||||
public static final EntityType BREEZE = define("breeze", ABSTRACT_MONSTER);
|
||||
public static final EntityType ABSTRACT_WIND_CHARGE = define("abstract_wind_charge", PROJECTILE_ABSTRACT);
|
||||
public static final EntityType WIND_CHARGE = define("wind_charge", ABSTRACT_WIND_CHARGE);
|
||||
|
||||
// Added in 1.20.5
|
||||
public static final EntityType ARMADILLO = define("armadillo", ABSTRACT_ANIMAL);
|
||||
public static final EntityType BOGGED = define("bogged", ABSTRACT_SKELETON);
|
||||
public static final EntityType BREEZE_WIND_CHARGE = define("breeze_wind_charge", ABSTRACT_WIND_CHARGE);
|
||||
public static final EntityType OMINOUS_ITEM_SPAWNER = define("ominous_item_spawner", ENTITY);
|
||||
|
||||
static {
|
||||
TYPES_BUILDER.unloadFileMappings();
|
||||
LEGACY_TYPES_BUILDER.unloadFileMappings();
|
||||
}
|
||||
}
|
||||
+16
-1
@@ -18,16 +18,23 @@
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.entity.villager;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.entity.villager.level.VillagerLevel;
|
||||
import com.github.retrooper.packetevents.protocol.entity.villager.profession.VillagerProfession;
|
||||
import com.github.retrooper.packetevents.protocol.entity.villager.profession.VillagerProfessions;
|
||||
import com.github.retrooper.packetevents.protocol.entity.villager.type.VillagerType;
|
||||
import com.github.retrooper.packetevents.protocol.entity.villager.type.VillagerTypes;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class VillagerData {
|
||||
|
||||
private VillagerType type;
|
||||
private VillagerProfession profession;
|
||||
private int level;
|
||||
|
||||
public VillagerData(VillagerType type, VillagerProfession profession, VillagerLevel level) {
|
||||
this(type, profession, level.getId());
|
||||
}
|
||||
|
||||
public VillagerData(VillagerType type, VillagerProfession profession, int level) {
|
||||
this.type = type;
|
||||
this.profession = profession;
|
||||
@@ -55,10 +62,18 @@ public class VillagerData {
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return level;
|
||||
return this.level;
|
||||
}
|
||||
|
||||
public @Nullable VillagerLevel getVillagerLevel() {
|
||||
return VillagerLevel.getById(this.level);
|
||||
}
|
||||
|
||||
public void setLevel(int level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public void setLevel(VillagerLevel level) {
|
||||
this.level = level.getId();
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.entity.villager.level;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public enum VillagerLevel {
|
||||
|
||||
NOVICE,
|
||||
APPRENTICE,
|
||||
JOURNEYMAN,
|
||||
EXPERT,
|
||||
MASTER;
|
||||
|
||||
private static final VillagerLevel[] VALUES = values();
|
||||
|
||||
public static @Nullable VillagerLevel getById(int id) {
|
||||
if (id >= 1 && id <= VALUES.length) {
|
||||
return VALUES[id - 1];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return this.ordinal() + 1;
|
||||
}
|
||||
}
|
||||
|
||||
-2
@@ -19,7 +19,6 @@
|
||||
package com.github.retrooper.packetevents.protocol.entity.villager.profession;
|
||||
|
||||
import com.github.retrooper.packetevents.resources.ResourceLocation;
|
||||
import com.github.retrooper.packetevents.util.TypesBuilder;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -50,7 +49,6 @@ public class VillagerProfessions {
|
||||
return VILLAGER_PROFESSION_ID_MAP.get((byte)id);
|
||||
}
|
||||
|
||||
|
||||
public static VillagerProfession getByName(String name) {
|
||||
return VILLAGER_PROFESSION_MAP.get(name);
|
||||
}
|
||||
|
||||
@@ -18,18 +18,36 @@
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.item;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.component.ComponentType;
|
||||
import com.github.retrooper.packetevents.protocol.component.ComponentTypes;
|
||||
import com.github.retrooper.packetevents.protocol.component.PatchableComponentMap;
|
||||
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemEnchantments;
|
||||
import com.github.retrooper.packetevents.protocol.item.enchantment.Enchantment;
|
||||
import com.github.retrooper.packetevents.protocol.item.enchantment.type.EnchantmentType;
|
||||
import com.github.retrooper.packetevents.protocol.item.enchantment.type.EnchantmentTypes;
|
||||
import com.github.retrooper.packetevents.protocol.item.type.ItemType;
|
||||
import com.github.retrooper.packetevents.protocol.item.type.ItemTypes;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.*;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTInt;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTList;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTShort;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTString;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTType;
|
||||
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import static com.github.retrooper.packetevents.protocol.component.ComponentTypes.DAMAGE;
|
||||
import static com.github.retrooper.packetevents.protocol.component.ComponentTypes.ENCHANTMENTS;
|
||||
import static com.github.retrooper.packetevents.protocol.component.ComponentTypes.MAX_DAMAGE;
|
||||
import static com.github.retrooper.packetevents.protocol.component.ComponentTypes.MAX_STACK_SIZE;
|
||||
import static com.github.retrooper.packetevents.protocol.component.ComponentTypes.STORED_ENCHANTMENTS;
|
||||
|
||||
public class ItemStack {
|
||||
public static final ItemStack EMPTY = new ItemStack(ItemTypes.AIR, 0, new NBTCompound(), 0);
|
||||
@@ -37,20 +55,35 @@ public class ItemStack {
|
||||
private int amount;
|
||||
@Nullable
|
||||
private NBTCompound nbt;
|
||||
@Nullable // lazy loaded
|
||||
private PatchableComponentMap components; // Added in 1.20.5
|
||||
private int legacyData = -1;
|
||||
|
||||
private boolean cachedIsEmpty = false;
|
||||
|
||||
private ItemStack(ItemType type, int amount, @Nullable NBTCompound nbt, int legacyData) {
|
||||
this(type, amount, nbt, null, legacyData);
|
||||
}
|
||||
|
||||
private ItemStack(
|
||||
ItemType type,
|
||||
int amount,
|
||||
@Nullable NBTCompound nbt,
|
||||
@Nullable PatchableComponentMap components,
|
||||
int legacyData
|
||||
) {
|
||||
this.type = type;
|
||||
this.amount = amount;
|
||||
this.nbt = nbt;
|
||||
this.components = components;
|
||||
this.legacyData = legacyData;
|
||||
updateCachedEmptyStatus();
|
||||
}
|
||||
|
||||
public int getMaxStackSize() {
|
||||
return getType().getMaxAmount();
|
||||
return this.getComponentOr(MAX_STACK_SIZE,
|
||||
// fallback to legacy specified max stack size
|
||||
this.getType().getMaxAmount());
|
||||
}
|
||||
|
||||
public boolean isStackable() {
|
||||
@@ -58,11 +91,9 @@ public class ItemStack {
|
||||
}
|
||||
|
||||
public boolean isDamageableItem() {
|
||||
if (!this.cachedIsEmpty && this.getType().getMaxDurability() > 0) {
|
||||
NBTCompound tag = this.getNBT();
|
||||
return tag == null || !tag.getBoolean("Unbreakable");
|
||||
}
|
||||
return false;
|
||||
return !this.cachedIsEmpty && this.getMaxDamage() > 0
|
||||
&& (this.nbt == null || !this.nbt.getBoolean("Unbreakable"))
|
||||
&& !this.getComponentOr(ComponentTypes.UNBREAKABLE, false);
|
||||
}
|
||||
|
||||
public boolean isDamaged() {
|
||||
@@ -70,17 +101,27 @@ public class ItemStack {
|
||||
}
|
||||
|
||||
public int getDamageValue() {
|
||||
if (nbt == null) return 0;
|
||||
NBTInt damage = this.nbt.getTagOfTypeOrNull("Damage", NBTInt.class);
|
||||
return damage == null ? 0 : damage.getAsInt();
|
||||
if (this.nbt != null) {
|
||||
NBTInt damage = this.nbt.getTagOfTypeOrNull("Damage", NBTInt.class);
|
||||
if (damage != null) {
|
||||
return damage.getAsInt();
|
||||
}
|
||||
}
|
||||
return this.getComponentOr(DAMAGE, 0);
|
||||
}
|
||||
|
||||
public void setDamageValue(int damage) {
|
||||
this.getOrCreateTag().setTag("Damage", new NBTInt(Math.max(0, damage)));
|
||||
int cappedDamage = Math.max(0, damage);
|
||||
// set in legacy nbt
|
||||
this.getOrCreateTag().setTag("Damage", new NBTInt(cappedDamage));
|
||||
// set in components
|
||||
this.setComponent(DAMAGE, cappedDamage);
|
||||
}
|
||||
|
||||
public int getMaxDamage() {
|
||||
return this.getType().getMaxDurability();
|
||||
return this.getComponentOr(MAX_DAMAGE,
|
||||
// fallback to legacy specified max durability
|
||||
this.getType().getMaxDurability());
|
||||
}
|
||||
|
||||
public NBTCompound getOrCreateTag() {
|
||||
@@ -125,7 +166,12 @@ public class ItemStack {
|
||||
}
|
||||
|
||||
public ItemStack copy() {
|
||||
return cachedIsEmpty ? EMPTY : new ItemStack(type, amount, nbt == null ? new NBTCompound() : nbt.copy(), legacyData);
|
||||
return cachedIsEmpty ? EMPTY : new ItemStack(
|
||||
type, amount,
|
||||
nbt == null ? null : nbt.copy(),
|
||||
components == null ? null : components.copy(),
|
||||
legacyData
|
||||
);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -137,6 +183,58 @@ public class ItemStack {
|
||||
this.nbt = nbt;
|
||||
}
|
||||
|
||||
public <T> T getComponentOr(ComponentType<T> type, T otherValue) {
|
||||
if (this.hasComponentPatches()) {
|
||||
return this.getComponents().getOr(type, otherValue);
|
||||
}
|
||||
return this.getType().getComponents().getOr(type, otherValue);
|
||||
}
|
||||
|
||||
public <T> Optional<T> getComponent(ComponentType<T> type) {
|
||||
if (this.hasComponentPatches()) {
|
||||
return this.getComponents().getOptional(type);
|
||||
}
|
||||
return this.getType().getComponents().getOptional(type);
|
||||
}
|
||||
|
||||
public <T> void setComponent(ComponentType<T> type, T value) {
|
||||
this.getComponents().set(type, value);
|
||||
}
|
||||
|
||||
public <T> void unsetComponent(ComponentType<T> type) {
|
||||
this.getComponents().unset(type);
|
||||
}
|
||||
|
||||
public <T> void setComponent(ComponentType<T> type, Optional<T> value) {
|
||||
this.getComponents().set(type, value);
|
||||
}
|
||||
|
||||
public boolean hasComponent(ComponentType<?> type) {
|
||||
if (this.hasComponentPatches()) {
|
||||
return this.getComponents().has(type);
|
||||
}
|
||||
return this.getType().getComponents().has(type);
|
||||
}
|
||||
|
||||
public boolean hasComponentPatches() {
|
||||
return this.components != null && !this.components.getPatches().isEmpty();
|
||||
}
|
||||
|
||||
public PatchableComponentMap getComponents() {
|
||||
if (this.components == null) { // lazy load on access
|
||||
this.components = new PatchableComponentMap(
|
||||
this.type.getComponents(), new HashMap<>(4));
|
||||
}
|
||||
return this.components;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param components if set null will reset to components of {@link ItemType}
|
||||
*/
|
||||
public void setComponents(@Nullable PatchableComponentMap components) {
|
||||
this.components = components;
|
||||
}
|
||||
|
||||
public int getLegacyData() {
|
||||
return legacyData;
|
||||
}
|
||||
@@ -152,47 +250,101 @@ public class ItemStack {
|
||||
}
|
||||
|
||||
public boolean isEnchanted(ClientVersion version) {
|
||||
String tagName = getEnchantmentsTagName(version);
|
||||
return !isEmpty() && this.nbt != null && this.nbt.getCompoundListTagOrNull(tagName) != null && !this.nbt.getCompoundListTagOrNull(tagName).getTags().isEmpty();
|
||||
}
|
||||
|
||||
private List<Enchantment> getEnchantments(@Nullable NBTCompound nbt, ClientVersion version) {
|
||||
String tagName = getEnchantmentsTagName(version);
|
||||
|
||||
if (nbt == null || nbt.getCompoundListTagOrNull(tagName) == null)
|
||||
return new ArrayList<>(0);
|
||||
|
||||
NBTList<NBTCompound> nbtList = nbt.getCompoundListTagOrNull(tagName);
|
||||
List<NBTCompound> compounds = nbtList.getTags();
|
||||
List<Enchantment> enchantments = new ArrayList<>(compounds.size());
|
||||
|
||||
for (NBTCompound compound : compounds) {
|
||||
EnchantmentType type = getEnchantmentTypeFromTag(compound, version);
|
||||
|
||||
if (type != null) {
|
||||
NBTShort levelTag = compound.getTagOfTypeOrNull("lvl", NBTShort.class);
|
||||
int level = levelTag.getAsInt();
|
||||
Enchantment enchantment = Enchantment.builder().type(type).level(level).build();
|
||||
enchantments.add(enchantment);
|
||||
}
|
||||
if (this.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return enchantments;
|
||||
// check for components
|
||||
if (!this.getComponentOr(ENCHANTMENTS, ItemEnchantments.EMPTY).isEmpty()
|
||||
|| !this.getComponentOr(STORED_ENCHANTMENTS, ItemEnchantments.EMPTY).isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
// check for legacy nbt
|
||||
if (this.nbt != null) {
|
||||
String tagName = this.getEnchantmentsTagName(version);
|
||||
NBTList<NBTCompound> enchantments = this.nbt.getCompoundListTagOrNull(tagName);
|
||||
return enchantments != null && !enchantments.getTags().isEmpty();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<Enchantment> getEnchantments(ClientVersion version) {
|
||||
return getEnchantments(this.nbt, version);
|
||||
if (this.isEmpty()) {
|
||||
return new ArrayList<>(0);
|
||||
}
|
||||
|
||||
// check for components
|
||||
Optional<ItemEnchantments> optEnchantments = this.getComponent(ENCHANTMENTS);
|
||||
Optional<ItemEnchantments> optStoredEnchantments = this.getComponent(STORED_ENCHANTMENTS);
|
||||
if (optEnchantments.isPresent() || optStoredEnchantments.isPresent()) {
|
||||
ItemEnchantments enchantments = optEnchantments.orElse(ItemEnchantments.EMPTY);
|
||||
ItemEnchantments storedEnchantments = optStoredEnchantments.orElse(ItemEnchantments.EMPTY);
|
||||
List<Enchantment> enchantmentsList = new ArrayList<>(
|
||||
enchantments.getEnchantmentCount() + storedEnchantments.getEnchantmentCount());
|
||||
for (Map.Entry<EnchantmentType, Integer> enchantment : enchantments) {
|
||||
enchantmentsList.add(new Enchantment(enchantment.getKey(), enchantment.getValue()));
|
||||
}
|
||||
for (Map.Entry<EnchantmentType, Integer> enchantment : storedEnchantments) {
|
||||
enchantmentsList.add(new Enchantment(enchantment.getKey(), enchantment.getValue()));
|
||||
}
|
||||
return enchantmentsList;
|
||||
}
|
||||
|
||||
// check for legacy nbt
|
||||
if (this.nbt != null) {
|
||||
String tagName = this.getEnchantmentsTagName(version);
|
||||
NBTList<NBTCompound> nbtList = this.nbt.getCompoundListTagOrNull(tagName);
|
||||
if (nbtList != null) {
|
||||
List<NBTCompound> compounds = nbtList.getTags();
|
||||
List<Enchantment> enchantments = new ArrayList<>(compounds.size());
|
||||
|
||||
for (NBTCompound compound : compounds) {
|
||||
EnchantmentType type = getEnchantmentTypeFromTag(compound, version);
|
||||
|
||||
if (type != null) {
|
||||
NBTShort levelTag = compound.getTagOfTypeOrNull("lvl", NBTShort.class);
|
||||
int level = levelTag.getAsInt();
|
||||
Enchantment enchantment = Enchantment.builder().type(type).level(level).build();
|
||||
enchantments.add(enchantment);
|
||||
}
|
||||
}
|
||||
return enchantments;
|
||||
}
|
||||
}
|
||||
|
||||
return new ArrayList<>(0);
|
||||
}
|
||||
|
||||
public int getEnchantmentLevel(EnchantmentType enchantment, ClientVersion version) {
|
||||
if (isEnchanted(version)) {
|
||||
// isEnchanted() is true, so we can assume that nbt is not null
|
||||
assert nbt != null;
|
||||
String tagName = getEnchantmentsTagName(version);
|
||||
for (NBTCompound base : nbt.getCompoundListTagOrNull(tagName).getTags()) {
|
||||
EnchantmentType type = getEnchantmentTypeFromTag(base, version);
|
||||
if (enchantment == type) {
|
||||
return base.getTagOfTypeOrNull("lvl", NBTShort.class).getAsInt();
|
||||
if (this.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// check for components
|
||||
Optional<ItemEnchantments> optEnchantments = this.getComponent(ENCHANTMENTS);
|
||||
if (optEnchantments.isPresent()) {
|
||||
int level = optEnchantments.get().getEnchantmentLevel(enchantment);
|
||||
if (level > 0) {
|
||||
return level;
|
||||
}
|
||||
}
|
||||
Optional<ItemEnchantments> optStoredEnchantments = this.getComponent(STORED_ENCHANTMENTS);
|
||||
if (optStoredEnchantments.isPresent()) {
|
||||
int level = optStoredEnchantments.get().getEnchantmentLevel(enchantment);
|
||||
if (level > 0) {
|
||||
return level;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.nbt != null) {
|
||||
String tagName = this.getEnchantmentsTagName(version);
|
||||
NBTList<NBTCompound> nbtList = this.nbt.getCompoundListTagOrNull(tagName);
|
||||
if (nbtList != null) {
|
||||
for (NBTCompound base : nbtList.getTags()) {
|
||||
EnchantmentType type = getEnchantmentTypeFromTag(base, version);
|
||||
if (enchantment == type) {
|
||||
NBTShort nbtShort = base.getTagOfTypeOrNull("lvl", NBTShort.class);
|
||||
return nbtShort != null ? nbtShort.getAsInt() : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -200,8 +352,7 @@ public class ItemStack {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static EnchantmentType getEnchantmentTypeFromTag(NBTCompound tag, ClientVersion version) {
|
||||
private static @Nullable EnchantmentType getEnchantmentTypeFromTag(NBTCompound tag, ClientVersion version) {
|
||||
if (version.isNewerThanOrEquals(ClientVersion.V_1_13)) {
|
||||
String id = tag.getStringTagValueOrNull("id");
|
||||
return EnchantmentTypes.getByName(id);
|
||||
@@ -212,6 +363,7 @@ public class ItemStack {
|
||||
}
|
||||
|
||||
public void setEnchantments(List<Enchantment> enchantments, ClientVersion version) {
|
||||
// set in legacy nbt
|
||||
nbt = getOrCreateTag(); // Create tag if null
|
||||
String tagName = getEnchantmentsTagName(version);
|
||||
if (enchantments.isEmpty()) {
|
||||
@@ -235,8 +387,20 @@ public class ItemStack {
|
||||
assert nbt != null; // NBT was created in getOrCreateTag()
|
||||
nbt.setTag(tagName, new NBTList<>(NBTType.COMPOUND, list));
|
||||
}
|
||||
|
||||
// set in components
|
||||
Map<EnchantmentType, Integer> enchantmentsMap = new HashMap<>(enchantments.size());
|
||||
for (Enchantment enchantment : enchantments) {
|
||||
enchantmentsMap.put(enchantment.getType(), enchantment.getLevel());
|
||||
}
|
||||
ComponentType<ItemEnchantments> componentType = this.type == ItemTypes.ENCHANTED_BOOK
|
||||
? STORED_ENCHANTMENTS : ENCHANTMENTS;
|
||||
Optional<ItemEnchantments> prevEnchantments = this.getComponent(componentType);
|
||||
boolean showInTooltip = prevEnchantments.map(ItemEnchantments::isShowInTooltip).orElse(true);
|
||||
this.setComponent(componentType, new ItemEnchantments(enchantmentsMap, showInTooltip));
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getEnchantmentsTagName(ClientVersion version) {
|
||||
String tagName = version.isNewerThanOrEquals(ClientVersion.V_1_13) ? "Enchantments" : "ench";
|
||||
if (type == ItemTypes.ENCHANTED_BOOK) {
|
||||
@@ -254,11 +418,24 @@ public class ItemStack {
|
||||
}
|
||||
|
||||
public static boolean isSameItemSameTags(ItemStack stack, ItemStack otherStack) {
|
||||
return stack.is(otherStack.getType()) && ItemStack.tagMatches(stack, otherStack);
|
||||
return stack.is(otherStack.getType())
|
||||
&& (stack.isEmpty() && otherStack.isEmpty()
|
||||
|| (ItemStack.tagMatches(stack, otherStack)
|
||||
&& Objects.equals(stack.components, otherStack.components)));
|
||||
}
|
||||
|
||||
public static boolean tagMatches(ItemStack left, ItemStack right) {
|
||||
return left.isEmpty() && right.isEmpty() || (!left.isEmpty() && !right.isEmpty() && ((left.nbt != null || right.nbt == null) && (left.nbt == null || left.nbt.equals(right.nbt))));
|
||||
if (left == right) {
|
||||
return true;
|
||||
}
|
||||
if (left == null) {
|
||||
return right.isEmpty();
|
||||
}
|
||||
if (right == null) {
|
||||
return left.isEmpty();
|
||||
}
|
||||
return Objects.equals(left.nbt, right.nbt)
|
||||
&& Objects.equals(left.components, right.components);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -270,6 +447,7 @@ public class ItemStack {
|
||||
return getType().equals(itemStack.getType())
|
||||
&& amount == itemStack.amount
|
||||
&& Objects.equals(nbt, itemStack.nbt)
|
||||
&& Objects.equals(components, itemStack.components)
|
||||
&& legacyData == itemStack.legacyData;
|
||||
}
|
||||
return false;
|
||||
@@ -283,7 +461,8 @@ public class ItemStack {
|
||||
String identifier = type == null ? "null" : type.getName().toString();
|
||||
int maxAmount = getType().getMaxAmount();
|
||||
return "ItemStack[type=" + identifier + ", amount=" + amount + "/" + maxAmount
|
||||
+ ", nbt tag names: " + (nbt != null ? nbt.getTagNames() : "[null]") + ", legacyData=" + legacyData + "]";
|
||||
+ ", nbt tag names: " + (nbt != null ? nbt.getTagNames() : "[null]")
|
||||
+ ", legacyData=" + legacyData + ", components=" + components + "]";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -299,6 +478,7 @@ public class ItemStack {
|
||||
private ItemType type;
|
||||
private int amount = 1;
|
||||
private NBTCompound nbt = null;
|
||||
private PatchableComponentMap components = null;
|
||||
private int legacyData = -1;
|
||||
|
||||
public Builder type(ItemType type) {
|
||||
@@ -316,13 +496,18 @@ public class ItemStack {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder components(@Nullable PatchableComponentMap components) {
|
||||
this.components = components;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder legacyData(int legacyData) {
|
||||
this.legacyData = legacyData;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemStack build() {
|
||||
return new ItemStack(type, amount, nbt, legacyData);
|
||||
return new ItemStack(type, amount, nbt, components, legacyData);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.item.armormaterial;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.mapper.MappedEntity;
|
||||
|
||||
public interface ArmorMaterial extends MappedEntity {
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.item.armormaterial;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
import com.github.retrooper.packetevents.resources.ResourceLocation;
|
||||
import com.github.retrooper.packetevents.util.mappings.MappingHelper;
|
||||
import com.github.retrooper.packetevents.util.mappings.TypesBuilder;
|
||||
import com.github.retrooper.packetevents.util.mappings.TypesBuilderData;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ArmorMaterials {
|
||||
|
||||
private static final Map<String, ArmorMaterial> MATERIAL_MAP = new HashMap<>();
|
||||
private static final Map<Byte, Map<Integer, ArmorMaterial>> MATERIAL_ID_MAP = new HashMap<>();
|
||||
private static final TypesBuilder TYPES_BUILDER = new TypesBuilder("item/item_armor_material_mappings");
|
||||
|
||||
public static ArmorMaterial define(String key) {
|
||||
TypesBuilderData data = TYPES_BUILDER.define(key);
|
||||
ArmorMaterial instrument = new ArmorMaterial() {
|
||||
@Override
|
||||
public ResourceLocation getName() {
|
||||
return data.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId(ClientVersion version) {
|
||||
return TYPES_BUILDER.getDataIndex(version);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof ArmorMaterial) {
|
||||
return getName().equals(((ArmorMaterial) obj).getName());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
MappingHelper.registerMapping(TYPES_BUILDER, MATERIAL_MAP, MATERIAL_ID_MAP, instrument);
|
||||
return instrument;
|
||||
}
|
||||
|
||||
// with key
|
||||
public static ArmorMaterial getByName(String name) {
|
||||
return MATERIAL_MAP.get(name);
|
||||
}
|
||||
|
||||
public static ArmorMaterial getById(ClientVersion version, int id) {
|
||||
int index = TYPES_BUILDER.getDataIndex(version);
|
||||
Map<Integer, ArmorMaterial> idMap = MATERIAL_ID_MAP.get((byte) index);
|
||||
return idMap.get(id);
|
||||
}
|
||||
|
||||
public static final ArmorMaterial LEATHER = define("leather");
|
||||
public static final ArmorMaterial CHAINMAIL = define("chainmail");
|
||||
public static final ArmorMaterial IRON = define("iron");
|
||||
public static final ArmorMaterial GOLD = define("gold");
|
||||
public static final ArmorMaterial DIAMOND = define("diamond");
|
||||
|
||||
// Added with 1.13
|
||||
public static final ArmorMaterial TURTLE = define("turtle");
|
||||
|
||||
// Added with 1.16
|
||||
public static final ArmorMaterial NETHERITE = define("netherite");
|
||||
|
||||
// Added with 1.20.5
|
||||
public static final ArmorMaterial ARMADILLO = define("armadillo");
|
||||
|
||||
static {
|
||||
TYPES_BUILDER.unloadFileMappings();
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.item.banner;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.mapper.MappedEntity;
|
||||
import com.github.retrooper.packetevents.resources.ResourceLocation;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
|
||||
public interface BannerPattern extends MappedEntity {
|
||||
|
||||
ResourceLocation getAssetId();
|
||||
|
||||
String getTranslationKey();
|
||||
|
||||
static BannerPattern readDirect(PacketWrapper<?> wrapper) {
|
||||
ResourceLocation assetId = wrapper.readIdentifier();
|
||||
String translationKey = wrapper.readString();
|
||||
return new StaticBannerPattern(assetId, translationKey);
|
||||
}
|
||||
|
||||
static void writeDirect(PacketWrapper<?> wrapper, BannerPattern pattern) {
|
||||
wrapper.writeIdentifier(pattern.getAssetId());
|
||||
wrapper.writeString(pattern.getTranslationKey());
|
||||
}
|
||||
}
|
||||
+133
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.item.banner;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
import com.github.retrooper.packetevents.resources.ResourceLocation;
|
||||
import com.github.retrooper.packetevents.util.mappings.MappingHelper;
|
||||
import com.github.retrooper.packetevents.util.mappings.TypesBuilder;
|
||||
import com.github.retrooper.packetevents.util.mappings.TypesBuilderData;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class BannerPatterns {
|
||||
|
||||
private static final Map<String, BannerPattern> PATTERN_TYPE_MAP = new HashMap<>();
|
||||
private static final Map<Byte, Map<Integer, BannerPattern>> PATTERN_TYPE_ID_MAP = new HashMap<>();
|
||||
private static final TypesBuilder TYPES_BUILDER = new TypesBuilder("item/item_banner_pattern_mappings");
|
||||
|
||||
public static BannerPattern define(String key) {
|
||||
ResourceLocation assetId = ResourceLocation.minecraft(key);
|
||||
String translationKey = "block.minecraft.banner." + key;
|
||||
return define(key, assetId, translationKey);
|
||||
}
|
||||
|
||||
public static BannerPattern define(String key, ResourceLocation assetId, String translationKey) {
|
||||
TypesBuilderData data = TYPES_BUILDER.define(key);
|
||||
BannerPattern pattern = new BannerPattern() {
|
||||
@Override
|
||||
public ResourceLocation getAssetId() {
|
||||
return assetId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTranslationKey() {
|
||||
return translationKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getName() {
|
||||
return data.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId(ClientVersion version) {
|
||||
return TYPES_BUILDER.getDataIndex(version);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof BannerPattern) {
|
||||
return getName().equals(((BannerPattern) obj).getName());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
MappingHelper.registerMapping(TYPES_BUILDER, PATTERN_TYPE_MAP, PATTERN_TYPE_ID_MAP, pattern);
|
||||
return pattern;
|
||||
}
|
||||
|
||||
// with key
|
||||
public static BannerPattern getByName(String name) {
|
||||
return PATTERN_TYPE_MAP.get(name);
|
||||
}
|
||||
|
||||
public static BannerPattern getById(ClientVersion version, int id) {
|
||||
int index = TYPES_BUILDER.getDataIndex(version);
|
||||
Map<Integer, BannerPattern> idMap = PATTERN_TYPE_ID_MAP.get((byte) index);
|
||||
return idMap.get(id);
|
||||
}
|
||||
|
||||
public static final BannerPattern SQUARE_BOTTOM_LEFT = define("square_bottom_left");
|
||||
public static final BannerPattern STRIPE_BOTTOM = define("stripe_bottom");
|
||||
public static final BannerPattern CREEPER = define("creeper");
|
||||
public static final BannerPattern HALF_HORIZONTAL = define("half_horizontal");
|
||||
public static final BannerPattern STRIPE_MIDDLE = define("stripe_middle");
|
||||
public static final BannerPattern BASE = define("base");
|
||||
public static final BannerPattern DIAGONAL_UP_RIGHT = define("diagonal_up_right");
|
||||
public static final BannerPattern HALF_HORIZONTAL_BOTTOM = define("half_horizontal_bottom");
|
||||
public static final BannerPattern SMALL_STRIPES = define("small_stripes");
|
||||
public static final BannerPattern GRADIENT_UP = define("gradient_up");
|
||||
public static final BannerPattern CIRCLE = define("circle");
|
||||
public static final BannerPattern STRIPE_DOWNLEFT = define("stripe_downleft");
|
||||
public static final BannerPattern RHOMBUS = define("rhombus");
|
||||
public static final BannerPattern TRIANGLES_BOTTOM = define("triangles_bottom");
|
||||
public static final BannerPattern STRIPE_CENTER = define("stripe_center");
|
||||
public static final BannerPattern SQUARE_BOTTOM_RIGHT = define("square_bottom_right");
|
||||
public static final BannerPattern DIAGONAL_RIGHT = define("diagonal_right");
|
||||
public static final BannerPattern MOJANG = define("mojang");
|
||||
public static final BannerPattern STRIPE_LEFT = define("stripe_left");
|
||||
public static final BannerPattern SQUARE_TOP_LEFT = define("square_top_left");
|
||||
public static final BannerPattern TRIANGLE_BOTTOM = define("triangle_bottom");
|
||||
public static final BannerPattern SKULL = define("skull");
|
||||
public static final BannerPattern SQUARE_TOP_RIGHT = define("square_top_right");
|
||||
public static final BannerPattern GLOBE = define("globe");
|
||||
public static final BannerPattern STRIPE_TOP = define("stripe_top");
|
||||
public static final BannerPattern CROSS = define("cross");
|
||||
public static final BannerPattern BRICKS = define("bricks");
|
||||
public static final BannerPattern HALF_VERTICAL = define("half_vertical");
|
||||
public static final BannerPattern STRIPE_DOWNRIGHT = define("stripe_downright");
|
||||
public static final BannerPattern TRIANGLES_TOP = define("triangles_top");
|
||||
public static final BannerPattern STRIPE_RIGHT = define("stripe_right");
|
||||
public static final BannerPattern DIAGONAL_UP_LEFT = define("diagonal_up_left");
|
||||
public static final BannerPattern HALF_VERTICAL_RIGHT = define("half_vertical_right");
|
||||
public static final BannerPattern TRIANGLE_TOP = define("triangle_top");
|
||||
public static final BannerPattern FLOWER = define("flower");
|
||||
public static final BannerPattern STRAIGHT_CROSS = define("straight_cross");
|
||||
public static final BannerPattern GRADIENT = define("gradient");
|
||||
public static final BannerPattern CURLY_BORDER = define("curly_border");
|
||||
public static final BannerPattern BORDER = define("border");
|
||||
public static final BannerPattern PIGLIN = define("piglin");
|
||||
public static final BannerPattern DIAGONAL_LEFT = define("diagonal_left");
|
||||
|
||||
static {
|
||||
TYPES_BUILDER.unloadFileMappings();
|
||||
}
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.item.banner;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
import com.github.retrooper.packetevents.resources.ResourceLocation;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class StaticBannerPattern implements BannerPattern {
|
||||
|
||||
private final ResourceLocation assetId;
|
||||
private final String translationKey;
|
||||
|
||||
public StaticBannerPattern(ResourceLocation assetId, String translationKey) {
|
||||
this.assetId = assetId;
|
||||
this.translationKey = translationKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getAssetId() {
|
||||
return this.assetId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTranslationKey() {
|
||||
return this.translationKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getName() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId(ClientVersion version) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRegistered() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof StaticBannerPattern)) return false;
|
||||
StaticBannerPattern that = (StaticBannerPattern) obj;
|
||||
if (!this.assetId.equals(that.assetId)) return false;
|
||||
return this.translationKey.equals(that.translationKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.assetId, this.translationKey);
|
||||
}
|
||||
}
|
||||
+1
-2
@@ -19,13 +19,12 @@
|
||||
package com.github.retrooper.packetevents.protocol.item.enchantment;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.item.enchantment.type.EnchantmentType;
|
||||
import com.github.retrooper.packetevents.protocol.item.enchantment.type.EnchantmentTypes;
|
||||
|
||||
public class Enchantment {
|
||||
private EnchantmentType type;
|
||||
private int level;
|
||||
|
||||
private Enchantment(EnchantmentType type, int level) {
|
||||
public Enchantment(EnchantmentType type, int level) {
|
||||
this.type = type;
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
+22
-20
@@ -20,28 +20,30 @@ package com.github.retrooper.packetevents.protocol.item.enchantment.type;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
import com.github.retrooper.packetevents.resources.ResourceLocation;
|
||||
import com.github.retrooper.packetevents.util.TypesBuilder;
|
||||
import com.github.retrooper.packetevents.util.TypesBuilderData;
|
||||
import com.github.retrooper.packetevents.util.mappings.MappingHelper;
|
||||
import com.github.retrooper.packetevents.util.mappings.TypesBuilder;
|
||||
import com.github.retrooper.packetevents.util.mappings.TypesBuilderData;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class EnchantmentTypes {
|
||||
|
||||
private static final Map<String, String> STRING_UPDATER = new HashMap<>();
|
||||
|
||||
static {
|
||||
// renamed in 24w03a, during the 1.20.5 update
|
||||
STRING_UPDATER.put("minecraft:sweeping", "minecraft:sweeping_edge");
|
||||
}
|
||||
|
||||
private static final Map<String, EnchantmentType> ENCHANTMENT_TYPE_MAPPINGS = new HashMap<>();
|
||||
private static final Map<Byte, Map<Integer, EnchantmentType>> ENCHANTMENT_TYPE_ID_MAPPINGS = new HashMap<>();
|
||||
private static final TypesBuilder TYPES_BUILDER = new TypesBuilder("enchantment/enchantment_type_mappings",
|
||||
ClientVersion.V_1_12,
|
||||
ClientVersion.V_1_13,
|
||||
ClientVersion.V_1_14,
|
||||
ClientVersion.V_1_16,
|
||||
ClientVersion.V_1_19);
|
||||
private static final TypesBuilder TYPES_BUILDER = new TypesBuilder("enchantment/enchantment_type_mappings");
|
||||
|
||||
public static EnchantmentType define(String key) {
|
||||
TypesBuilderData data = TYPES_BUILDER.define(key);
|
||||
EnchantmentType enchantmentType = new EnchantmentType() {
|
||||
private final int[] ids = data.getData();
|
||||
|
||||
@Override
|
||||
public ResourceLocation getName() {
|
||||
return data.getName();
|
||||
@@ -49,8 +51,7 @@ public class EnchantmentTypes {
|
||||
|
||||
@Override
|
||||
public int getId(ClientVersion version) {
|
||||
int index = TYPES_BUILDER.getDataIndex(version);
|
||||
return ids[index];
|
||||
return MappingHelper.getId(version, TYPES_BUILDER, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -62,18 +63,14 @@ public class EnchantmentTypes {
|
||||
}
|
||||
};
|
||||
|
||||
ENCHANTMENT_TYPE_MAPPINGS.put(enchantmentType.getName().toString(), enchantmentType);
|
||||
for (ClientVersion version : TYPES_BUILDER.getVersions()) {
|
||||
int index = TYPES_BUILDER.getDataIndex(version);
|
||||
Map<Integer, EnchantmentType> typeIdMap = ENCHANTMENT_TYPE_ID_MAPPINGS.computeIfAbsent((byte) index, k -> new HashMap<>());
|
||||
typeIdMap.put(enchantmentType.getId(version), enchantmentType);
|
||||
}
|
||||
MappingHelper.registerMapping(TYPES_BUILDER, ENCHANTMENT_TYPE_MAPPINGS, ENCHANTMENT_TYPE_ID_MAPPINGS, enchantmentType);
|
||||
return enchantmentType;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static EnchantmentType getByName(String name) {
|
||||
return ENCHANTMENT_TYPE_MAPPINGS.get(name);
|
||||
String fixedName = STRING_UPDATER.getOrDefault(name, name);
|
||||
return ENCHANTMENT_TYPE_MAPPINGS.get(fixedName);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -102,7 +99,7 @@ public class EnchantmentTypes {
|
||||
public static final EnchantmentType KNOCKBACK = define("knockback");
|
||||
public static final EnchantmentType FIRE_ASPECT = define("fire_aspect");
|
||||
public static final EnchantmentType MOB_LOOTING = define("looting");
|
||||
public static final EnchantmentType SWEEPING_EDGE = define("sweeping");
|
||||
public static final EnchantmentType SWEEPING_EDGE = define("sweeping_edge");
|
||||
public static final EnchantmentType BLOCK_EFFICIENCY = define("efficiency");
|
||||
public static final EnchantmentType SILK_TOUCH = define("silk_touch");
|
||||
public static final EnchantmentType UNBREAKING = define("unbreaking");
|
||||
@@ -123,6 +120,11 @@ public class EnchantmentTypes {
|
||||
public static final EnchantmentType MENDING = define("mending");
|
||||
public static final EnchantmentType VANISHING_CURSE = define("vanishing_curse");
|
||||
|
||||
// Added in 1.20.5
|
||||
public static final EnchantmentType DENSITY = define("density");
|
||||
public static final EnchantmentType BREACH = define("breach");
|
||||
public static final EnchantmentType WIND_BURST = define("wind_burst");
|
||||
|
||||
static {
|
||||
TYPES_BUILDER.unloadFileMappings();
|
||||
}
|
||||
|
||||
Loaded 100 of 479 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user