mirror of
https://github.com/Jikoo/OpenInv.git
synced 2026-11-04 08:42:05 -05:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3820d2e974 | ||
|
|
337ba2c35a | ||
|
|
fdf7f68c51 | ||
|
|
f1253fea6f | ||
|
|
5af49a6bbd | ||
|
|
e8c01c7893 | ||
|
|
1675952e94 | ||
|
|
35e39ffd3e | ||
|
|
7da27a0da0 | ||
|
|
180ceaf7e1 | ||
|
|
e608233ad9 | ||
|
|
d787516fce | ||
|
|
50c522b8f6 | ||
|
|
0192f5a6a9 | ||
|
|
8123679c46 | ||
|
|
1d37aad00a | ||
|
|
27a6e59682 | ||
|
|
f72e22c2a1 | ||
|
|
55053dacbf | ||
|
|
dacb07bd41 | ||
|
|
06d3fd7df9 | ||
|
|
4acf43b0fe | ||
|
|
a570001eaf | ||
|
|
70c53521c1 | ||
|
|
9021ef9a22 | ||
|
|
722ab4d2a3 | ||
|
|
5f04575780 | ||
|
|
0f5368b134 | ||
|
|
b43a32139d | ||
|
|
98d819c49a | ||
|
|
8f058fb206 | ||
|
|
60a32b7af5 | ||
|
|
61f7d5cee5 | ||
|
|
3d65681c6f | ||
|
|
cf2f53f9e9 | ||
|
|
95ae1cfa0a | ||
|
|
07451de7a3 | ||
|
|
872e14e1a6 | ||
|
|
f5e534f758 | ||
|
|
16a4c8f71b | ||
|
|
7f4216995c | ||
|
|
f945868a21 | ||
|
|
ee923c0881 | ||
|
|
80d48ed218 | ||
|
|
8de1f778f0 | ||
|
|
8955882737 | ||
|
|
037b3f89cd | ||
|
|
43b4360bb6 | ||
|
|
e03c43555d | ||
|
|
43a13e6254 | ||
|
|
ab3dddbc19 | ||
|
|
d35fc6713b | ||
|
|
9c8a16adc9 | ||
|
|
b93900cf3b | ||
|
|
63fccdcf91 | ||
|
|
960acbfe9d | ||
|
|
3c904499c5 | ||
|
|
baa6b3d734 | ||
|
|
7f6c339e06 | ||
|
|
00736c8d30 | ||
|
|
cb1ec77c24 | ||
|
|
c8c8a72819 | ||
|
|
16f91ddc9f | ||
|
|
c83511e475 | ||
|
|
c095a78013 | ||
|
|
4441cdcf04 | ||
|
|
9940b9d840 | ||
|
|
fb409f8024 | ||
|
|
08b43a8aca | ||
|
|
3df3d41a7f | ||
|
|
16cba8a137 | ||
|
|
f1b86b4eb1 | ||
|
|
172e1cd55b | ||
|
|
d8b5aa145b | ||
|
|
2ffff99acf | ||
|
|
743c46f322 | ||
|
|
e3285a6d61 | ||
|
|
806fb848a7 | ||
|
|
b269a5ed3c | ||
|
|
8c102c4400 | ||
|
|
080d02f93f | ||
|
|
54f9d30a89 | ||
|
|
6063959362 | ||
|
|
d80b8a6f4d | ||
|
|
13621901ad | ||
|
|
20cc6e004e | ||
|
|
80585dfc07 | ||
|
|
9e37b42c63 | ||
|
|
58be5cffc9 | ||
|
|
e8c8e625c0 | ||
|
|
0ee3f8c1b2 | ||
|
|
99f9099981 | ||
|
|
70ae432158 | ||
|
|
ad05f427fd | ||
|
|
252e93f872 | ||
|
|
0267090cb6 | ||
|
|
1e26c33311 | ||
|
|
34f5319f48 | ||
|
|
642e287507 | ||
|
|
4504ba2b99 | ||
|
|
9691d16506 | ||
|
|
1897790db5 | ||
|
|
cad76c6559 | ||
|
|
119ff48461 | ||
|
|
b589f79e57 | ||
|
|
f742cf5b77 | ||
|
|
19d030dd4d | ||
|
|
17dec41fea | ||
|
|
b5599450f5 | ||
|
|
b2c13b40e2 | ||
|
|
03c0fea7ab | ||
|
|
9ca5b2d826 | ||
|
|
7a9bb11133 | ||
|
|
8647f8e156 | ||
|
|
2a07673b1a | ||
|
|
8418cb14fe | ||
|
|
6647334072 | ||
|
|
e479a5eaa7 | ||
|
|
1c40091cfa | ||
|
|
8c2ec2121a | ||
|
|
ad06b46b37 | ||
|
|
05ac5c92c8 | ||
|
|
0c8c364c45 | ||
|
|
b89f34915e | ||
|
|
ada819b30a | ||
|
|
7a2cef50ec | ||
|
|
268e91007c | ||
|
|
f4ed616fb8 | ||
|
|
456909966f | ||
|
|
51649bf2ab | ||
|
|
e44697f856 | ||
|
|
414b141b37 | ||
|
|
0db487c6eb | ||
|
|
3b907e1b37 | ||
|
|
d564773be6 | ||
|
|
e834e940e2 | ||
|
|
cd73430bb2 | ||
|
|
1c1dc9505b | ||
|
|
1a76e6fd57 | ||
|
|
48a61e6043 | ||
|
|
4de2c2fe6d | ||
|
|
e4fdd613ae | ||
|
|
9f50de5dfe | ||
|
|
e9d63f31ed | ||
|
|
73e003bde4 | ||
|
|
04ed652073 | ||
|
|
49e408ee7a | ||
|
|
0df5e39a6d | ||
|
|
7ab3e0c03f | ||
|
|
348fde9173 | ||
|
|
6c69350c30 | ||
|
|
19eafddfac | ||
|
|
8a388b5620 | ||
|
|
206fff2c0a | ||
|
|
6656e431b6 | ||
|
|
f8df83b31d | ||
|
|
eb98bd79d3 | ||
|
|
e948fdc011 | ||
|
|
f5c31c32d3 | ||
|
|
56f8cf4d71 | ||
|
|
7f1f6ccc82 | ||
|
|
9196ab3e61 | ||
|
|
0ac7575bad | ||
|
|
b0c7c8421e | ||
|
|
9b54e4e22e | ||
|
|
5ac09bc5a3 | ||
|
|
4e89a04b36 | ||
|
|
73a9c743a6 | ||
|
|
8d897664ef | ||
|
|
03ea798ee0 | ||
|
|
08d4a0ea27 | ||
|
|
cd7219f472 | ||
|
|
532dffc068 | ||
|
|
6df4de1dd3 | ||
|
|
df913e33c3 | ||
|
|
21f6b005cd | ||
|
|
d2ce3a542a | ||
|
|
2c51423882 | ||
|
|
b8636cd385 | ||
|
|
46b8b0c928 | ||
|
|
8229d5f0d9 | ||
|
|
c6d36cc9cf | ||
|
|
54f078724f | ||
|
|
847f22f63f | ||
|
|
f121c113f0 | ||
|
|
8d60cd0726 | ||
|
|
7b504971b1 | ||
|
|
c1a20a4e24 | ||
|
|
5d75640cee | ||
|
|
cace6f6726 | ||
|
|
1967f4ebb1 | ||
|
|
fbdda9637e | ||
|
|
336aee88e2 | ||
|
|
d50b7433c7 | ||
|
|
e64261669b | ||
|
|
e8ab490d95 | ||
|
|
5eaf6243fb | ||
|
|
5e2cf56d6f | ||
|
|
0f0bde3e49 | ||
|
|
4198b7f22a | ||
|
|
8c15b3d078 | ||
|
|
335d849525 | ||
|
|
0fb9e5eed3 | ||
|
|
fe11217a27 | ||
|
|
5fea7f3e02 | ||
|
|
dbceff086a | ||
|
|
64899e5c3d | ||
|
|
bca080be7c | ||
|
|
09842fd168 | ||
|
|
7d63500c79 | ||
|
|
7fbb9a9da6 | ||
|
|
0597d7d9db | ||
|
|
1f2c2b6a49 | ||
|
|
59fff35fcc | ||
|
|
bb80d93510 | ||
|
|
8bf63e7f12 | ||
|
|
ebc063d34d | ||
|
|
b895cb400b | ||
|
|
1cfa9bdd81 | ||
|
|
e5b4e81ff9 | ||
|
|
e39dbc0044 | ||
|
|
09b3f83816 | ||
|
|
7cca23f7b1 | ||
|
|
dfdef394ce | ||
|
|
6325b353dc | ||
|
|
7a07ee0b3d | ||
|
|
e97ac3db88 | ||
|
|
f72b6749c4 | ||
|
|
f1bcb496cf | ||
|
|
89beeca853 | ||
|
|
282f8630ab | ||
|
|
8f374ef2a5 | ||
|
|
3d81fdd0ca | ||
|
|
2dde9ba28f | ||
|
|
96d2d2482a | ||
|
|
e543053eff | ||
|
|
8134887666 | ||
|
|
7ee6206ffb | ||
|
|
b81eab8191 | ||
|
|
8b71d3549f | ||
|
|
dd82f59516 | ||
|
|
80d3fb72e6 | ||
|
|
2ed23b24e5 | ||
|
|
b6d61d4cc9 | ||
|
|
c3f7eaebf4 | ||
|
|
52c90e1cea | ||
|
|
d887ff8eae | ||
|
|
0d5fb6a0ef | ||
|
|
6f8a6e868a | ||
|
|
70c1ecfc09 | ||
|
|
176272a4b9 | ||
|
|
c102e6650e | ||
|
|
c8fee82291 | ||
|
|
0ae9982ce5 | ||
|
|
59d358d907 | ||
|
|
2621181c5d | ||
|
|
48d044af8c | ||
|
|
9a7623c209 | ||
|
|
78354fdf68 | ||
|
|
859179d1fc | ||
|
|
79f53e9086 | ||
|
|
c14d777519 | ||
|
|
1829babe69 | ||
|
|
5aa959f1ac | ||
|
|
bc7e13f245 | ||
|
|
73edebff54 | ||
|
|
faf1d387e9 | ||
|
|
deed277376 | ||
|
|
28fc5aea70 | ||
|
|
bfcf0233fa | ||
|
|
3cf1aae89b | ||
|
|
db62878681 | ||
|
|
21cd52c166 | ||
|
|
9d715b61c0 | ||
|
|
d636cdd839 | ||
|
|
1bebdb5602 | ||
|
|
57caf85500 | ||
|
|
922586c925 | ||
|
|
9ec7bebecb | ||
|
|
5a7d1399b5 | ||
|
|
cc7481fa9a | ||
|
|
70d20aceb6 | ||
|
|
ac52211ce4 | ||
|
|
6f2bdccc89 | ||
|
|
6f23ed2528 | ||
|
|
2d36249dbb | ||
|
|
2f370ad641 | ||
|
|
1233f587c5 | ||
|
|
23ebea405e | ||
|
|
1bde75f9b3 | ||
|
|
6ee2546efd | ||
|
|
0e6acdff36 | ||
|
|
3d4bed04d5 | ||
|
|
e885bf9a65 | ||
|
|
e15c566b82 | ||
|
|
c1ffd09d50 | ||
|
|
bd5e47760e | ||
|
|
2fe0322570 | ||
|
|
767476a759 | ||
|
|
dc8e36d11f | ||
|
|
79b2a97c9e | ||
|
|
81eb60f628 | ||
|
|
e39f092f14 | ||
|
|
4816737b90 | ||
|
|
86bf24e7af | ||
|
|
381dbb2a78 | ||
|
|
46f3396b47 | ||
|
|
7b16391a80 | ||
|
|
801530490d | ||
|
|
d7e78177e0 | ||
|
|
e5128fa8db | ||
|
|
1efc0d4904 | ||
|
|
961a900632 | ||
|
|
0120d35a9a | ||
|
|
c443615c1d | ||
|
|
b872f94855 | ||
|
|
2679a520a5 | ||
|
|
d0648cc463 | ||
|
|
1ceaf296f2 | ||
|
|
1e0fb7bdb1 | ||
|
|
8c7698b40e | ||
|
|
6b38cb7201 | ||
|
|
23e2a7e534 | ||
|
|
1093b6d911 | ||
|
|
89db744113 | ||
|
|
fcb9ccb6e6 | ||
|
|
9c934e440d | ||
|
|
c2d60642c3 | ||
|
|
0653d12e49 | ||
|
|
f34b342cdd | ||
|
|
70d8999b48 | ||
|
|
a5b21cbbf5 | ||
|
|
44e514d8c2 | ||
|
|
6407f1d8e4 | ||
|
|
0b761a6fc3 | ||
|
|
6ad6e0c6bc | ||
|
|
fdf920062b | ||
|
|
9502b29fe3 | ||
|
|
c9ba401a6e | ||
|
|
b6e8e2ba42 | ||
|
|
ac00261afb | ||
|
|
f21019eba8 | ||
|
|
525982ce64 | ||
|
|
65c3358b22 | ||
|
|
d6152f2f24 | ||
|
|
cc3d96590f | ||
|
|
60c1d91e25 | ||
|
|
7903942b51 | ||
|
|
22407aa865 | ||
|
|
173f49680b | ||
|
|
3103e8822b | ||
|
|
a547ab79fb | ||
|
|
bb75c723a7 | ||
|
|
9bb94be7e2 | ||
|
|
f78a5b4fba | ||
|
|
4ca222f031 | ||
|
|
4fdfe15caa | ||
|
|
3aa31391be | ||
|
|
abd529be66 | ||
|
|
027d4e5637 | ||
|
|
f8fb8cd034 | ||
|
|
6a31015ee2 | ||
|
|
3e2b601997 | ||
|
|
160ae47bf5 | ||
|
|
98fbcebfd9 | ||
|
|
d236dd27b3 | ||
|
|
dd90b5281f | ||
|
|
b4601bb6c1 | ||
|
|
e3d9cea027 | ||
|
|
556a8bcfce | ||
|
|
8599997e03 | ||
|
|
ea99bd5fd4 | ||
|
|
2f36a4d4dc | ||
|
|
e5ebf11d32 | ||
|
|
4336b454b7 | ||
|
|
b198931f30 | ||
|
|
64af4dddb0 | ||
|
|
f613c0a522 | ||
|
|
1cae4c7a8e | ||
|
|
ff7243db6a | ||
|
|
07a8e3b973 | ||
|
|
9fccea60f7 | ||
|
|
9a2b379a64 | ||
|
|
4d800361d8 | ||
|
|
2cfc55813b | ||
|
|
0f41701429 | ||
|
|
9e0ca479a5 | ||
|
|
bd207e948a | ||
|
|
30425d2baa | ||
|
|
e3acb5384a | ||
|
|
6c4818dfd9 | ||
|
|
5b18656485 | ||
|
|
7ab86f2af9 | ||
|
|
2b563e0e1b | ||
|
|
2a0e0d33d8 | ||
|
|
889c2ffdab | ||
|
|
c440f618c9 | ||
|
|
ccc6f4b4a6 | ||
|
|
ae6c3bd292 | ||
|
|
0e3bdb8741 | ||
|
|
e09e7c59c7 | ||
|
|
18c7916d79 | ||
|
|
15ee6ef9a5 | ||
|
|
24224e4f9d | ||
|
|
6563b4f6ce | ||
|
|
1d5a836fd0 | ||
|
|
3ba82683ec | ||
|
|
6e5c332272 | ||
|
|
1c9d133ed1 | ||
|
|
dad1e16c18 | ||
|
|
519dd7da33 | ||
|
|
1bd7932cc5 | ||
|
|
dad00d2d9c | ||
|
|
502f661be3 | ||
|
|
804d30bcc7 | ||
|
|
db8b67082b | ||
|
|
b2156edcc7 | ||
|
|
45de495699 | ||
|
|
f45d332727 | ||
|
|
9705cb156b | ||
|
|
1c45ef517f | ||
|
|
3fee84fc58 | ||
|
|
00113cc4d4 | ||
|
|
788f022e74 | ||
|
|
da55790fd2 | ||
|
|
1a6d513603 | ||
|
|
a5b02ab26a | ||
|
|
0c3ce2dfb3 | ||
|
|
a1f4649a09 | ||
|
|
100d0e12cd | ||
|
|
3e629798e5 | ||
|
|
7c1f15974c | ||
|
|
d992237766 | ||
|
|
c93464e643 | ||
|
|
56afefc82b | ||
|
|
f0a66570d2 | ||
|
|
201a3578bf | ||
|
|
1228fc2de2 | ||
|
|
2561e75ae5 | ||
|
|
80661b9465 | ||
|
|
53701da34f | ||
|
|
9cf4712813 | ||
|
|
abe8fccdb5 | ||
|
|
4499bb5453 | ||
|
|
5405b7d7b9 | ||
|
|
34199d12a4 | ||
|
|
67131ab9f9 | ||
|
|
723381cb2b | ||
|
|
34e7252d77 | ||
|
|
a1b2df74cc | ||
|
|
7210f9153e | ||
|
|
dcdfac0d3b | ||
|
|
c7b4554a6c | ||
|
|
c51acb4e72 | ||
|
|
23d41cd6c8 | ||
|
|
8bc389496b | ||
|
|
1cc36d08bd | ||
|
|
c8938f451d | ||
|
|
4f2665fedc | ||
|
|
7d93bb06ad | ||
|
|
19c491411f | ||
|
|
65c6eb2693 | ||
|
|
ab1f4ace8a | ||
|
|
e7dc52bee4 | ||
|
|
a9c5799677 | ||
|
|
6d6257720a | ||
|
|
3e235fa688 | ||
|
|
dd02355ac2 | ||
|
|
4d3f5d67a8 | ||
|
|
7ad5faa2ce | ||
|
|
c28383ef36 | ||
|
|
5fbab1ab8f | ||
|
|
d97b092978 | ||
|
|
154bf56c2a | ||
|
|
d65a9caeb2 | ||
|
|
b3c4253606 | ||
|
|
b64000e89b | ||
|
|
3faf41ef18 | ||
|
|
db27d25a93 | ||
|
|
0f02e6fe66 | ||
|
|
ec07637e9f | ||
|
|
b269f3509c | ||
|
|
f2e4c8a3ad | ||
|
|
35839f1548 | ||
|
|
a4a462a1fa | ||
|
|
b9f901af66 | ||
|
|
1333056613 | ||
|
|
fb23df313a | ||
|
|
96dc400c83 | ||
|
|
b801d36f12 | ||
|
|
4c27599dd9 | ||
|
|
64ad0a5267 | ||
|
|
cba7f44192 | ||
|
|
e8ace6bd06 | ||
|
|
fd70f260ba | ||
|
|
be9874ba1d | ||
|
|
096faef161 | ||
|
|
df96d5106a | ||
|
|
fe77a1d2e7 | ||
|
|
3096e43540 | ||
|
|
2939551d65 | ||
|
|
fb74fd3ced | ||
|
|
393fe1d837 | ||
|
|
f80df9d83b | ||
|
|
5c006f8ebd | ||
|
|
57097e626e | ||
|
|
0f266c8a64 | ||
|
|
185f037254 | ||
|
|
e4d0020296 | ||
|
|
9e37cbbca8 | ||
|
|
adc35e9ad5 | ||
|
|
a469c732cc | ||
|
|
c5c1f47167 | ||
|
|
dc59356f76 | ||
|
|
d497772ad7 | ||
|
|
4f4d46974a | ||
|
|
96c38895e2 | ||
|
|
5753648d77 | ||
|
|
3725711b94 | ||
|
|
c22e18c096 | ||
|
|
6bff759d72 | ||
|
|
582c7201dd | ||
|
|
59a8ed70bb | ||
|
|
27812c133d | ||
|
|
165f3fb00e | ||
|
|
60dcb64558 | ||
|
|
077b34d304 | ||
|
|
8ce6e2f8d3 | ||
|
|
f5dce23f18 | ||
|
|
669cfd72aa | ||
|
|
9e66885690 | ||
|
|
a802769265 | ||
|
|
50c45b6616 | ||
|
|
eaf01fa32c | ||
|
|
4abaa6ea51 | ||
|
|
7c621bf899 | ||
|
|
f5c682ff2b | ||
|
|
e652b43670 | ||
|
|
f07cef5621 | ||
|
|
ded6421e33 | ||
|
|
cbb2b4d232 | ||
|
|
48c61eeb82 | ||
|
|
e3d1af010b | ||
|
|
2195677651 | ||
|
|
c72af5dbac | ||
|
|
931cdb6fb1 | ||
|
|
9db18613a1 | ||
|
|
784935a975 | ||
|
|
d9abe76531 | ||
|
|
ca85a392aa | ||
|
|
307f47e4d3 | ||
|
|
96c59f163d | ||
|
|
01f147b13c | ||
|
|
1c104b775f | ||
|
|
9a53e46dd3 | ||
|
|
6744e71127 | ||
|
|
12c3ebb798 | ||
|
|
32ec8d8147 | ||
|
|
443e0c489e | ||
|
|
7ab0003b62 | ||
|
|
12c0cac311 | ||
|
|
f54481e872 | ||
|
|
f27dd8a233 | ||
|
|
d6df1a0871 | ||
|
|
e34e51d127 | ||
|
|
5ca2ae461a | ||
|
|
4095e8039d | ||
|
|
73f390ab20 | ||
|
|
2f7d3bc235 | ||
|
|
ef486032f1 | ||
|
|
72ef873772 | ||
|
|
9b6e32a775 | ||
|
|
f05110c9b8 | ||
|
|
a41f89b011 | ||
|
|
d24827ffcb | ||
|
|
802ce28103 | ||
|
|
f31356b227 | ||
|
|
7942466863 | ||
|
|
db2cade4e2 | ||
|
|
718b4bb5dd | ||
|
|
6aa25dd2dc |
No files matched your search
+491
@@ -0,0 +1,491 @@
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
indent_size = 2
|
||||
indent_style = space
|
||||
insert_final_newline = false
|
||||
max_line_length = 120
|
||||
tab_width = 2
|
||||
ij_continuation_indent_size = 4
|
||||
ij_formatter_off_tag = @formatter:off
|
||||
ij_formatter_on_tag = @formatter:on
|
||||
ij_formatter_tags_enabled = true
|
||||
ij_smart_tabs = false
|
||||
ij_visual_guides =
|
||||
ij_wrap_on_typing = false
|
||||
|
||||
[*.java]
|
||||
ij_smart_tabs = true
|
||||
ij_java_align_consecutive_assignments = false
|
||||
ij_java_align_consecutive_variable_declarations = false
|
||||
ij_java_align_group_field_declarations = false
|
||||
ij_java_align_multiline_annotation_parameters = false
|
||||
ij_java_align_multiline_array_initializer_expression = false
|
||||
ij_java_align_multiline_assignment = false
|
||||
ij_java_align_multiline_binary_operation = false
|
||||
ij_java_align_multiline_chained_methods = false
|
||||
ij_java_align_multiline_deconstruction_list_components = true
|
||||
ij_java_align_multiline_extends_list = false
|
||||
ij_java_align_multiline_for = true
|
||||
ij_java_align_multiline_method_parentheses = false
|
||||
ij_java_align_multiline_parameters = false
|
||||
ij_java_align_multiline_parameters_in_calls = false
|
||||
ij_java_align_multiline_parenthesized_expression = false
|
||||
ij_java_align_multiline_records = true
|
||||
ij_java_align_multiline_resources = true
|
||||
ij_java_align_multiline_ternary_operation = false
|
||||
ij_java_align_multiline_text_blocks = false
|
||||
ij_java_align_multiline_throws_list = false
|
||||
ij_java_align_subsequent_simple_methods = false
|
||||
ij_java_align_throws_keyword = false
|
||||
ij_java_align_types_in_multi_catch = true
|
||||
ij_java_annotation_parameter_wrap = off
|
||||
ij_java_array_initializer_new_line_after_left_brace = false
|
||||
ij_java_array_initializer_right_brace_on_new_line = true
|
||||
ij_java_array_initializer_wrap = off
|
||||
ij_java_assert_statement_colon_on_next_line = false
|
||||
ij_java_assert_statement_wrap = off
|
||||
ij_java_assignment_wrap = off
|
||||
ij_java_binary_operation_sign_on_next_line = false
|
||||
ij_java_binary_operation_wrap = off
|
||||
ij_java_blank_lines_after_anonymous_class_header = 0
|
||||
ij_java_blank_lines_after_class_header = 0
|
||||
ij_java_blank_lines_after_imports = 1
|
||||
ij_java_blank_lines_after_package = 1
|
||||
ij_java_blank_lines_around_class = 1
|
||||
ij_java_blank_lines_around_field = 0
|
||||
ij_java_blank_lines_around_field_in_interface = 0
|
||||
ij_java_blank_lines_around_field_with_annotations = 0
|
||||
ij_java_blank_lines_around_initializer = 1
|
||||
ij_java_blank_lines_around_method = 1
|
||||
ij_java_blank_lines_around_method_in_interface = 1
|
||||
ij_java_blank_lines_before_class_end = 1
|
||||
ij_java_blank_lines_before_imports = 1
|
||||
ij_java_blank_lines_before_method_body = 0
|
||||
ij_java_blank_lines_before_package = 0
|
||||
ij_java_block_brace_style = end_of_line
|
||||
ij_java_block_comment_add_space = false
|
||||
ij_java_block_comment_at_first_column = true
|
||||
ij_java_builder_methods =
|
||||
ij_java_call_parameters_new_line_after_left_paren = false
|
||||
ij_java_call_parameters_right_paren_on_new_line = true
|
||||
ij_java_call_parameters_wrap = off
|
||||
ij_java_case_statement_on_separate_line = true
|
||||
ij_java_catch_on_new_line = false
|
||||
ij_java_class_annotation_wrap = split_into_lines
|
||||
ij_java_class_brace_style = end_of_line
|
||||
ij_java_class_count_to_use_import_on_demand = 1000
|
||||
ij_java_class_names_in_javadoc = 1
|
||||
ij_java_deconstruction_list_wrap = normal
|
||||
ij_java_do_not_indent_top_level_class_members = false
|
||||
ij_java_do_not_wrap_after_single_annotation = false
|
||||
ij_java_do_not_wrap_after_single_annotation_in_parameter = false
|
||||
ij_java_do_while_brace_force = never
|
||||
ij_java_doc_add_blank_line_after_description = true
|
||||
ij_java_doc_add_blank_line_after_param_comments = false
|
||||
ij_java_doc_add_blank_line_after_return = false
|
||||
ij_java_doc_add_p_tag_on_empty_lines = true
|
||||
ij_java_doc_align_exception_comments = false
|
||||
ij_java_doc_align_param_comments = false
|
||||
ij_java_doc_do_not_wrap_if_one_line = false
|
||||
ij_java_doc_enable_formatting = true
|
||||
ij_java_doc_enable_leading_asterisks = true
|
||||
ij_java_doc_indent_on_continuation = false
|
||||
ij_java_doc_keep_empty_lines = true
|
||||
ij_java_doc_keep_empty_parameter_tag = true
|
||||
ij_java_doc_keep_empty_return_tag = true
|
||||
ij_java_doc_keep_empty_throws_tag = true
|
||||
ij_java_doc_keep_invalid_tags = true
|
||||
ij_java_doc_param_description_on_new_line = false
|
||||
ij_java_doc_preserve_line_breaks = false
|
||||
ij_java_doc_use_throws_not_exception_tag = true
|
||||
ij_java_else_on_new_line = false
|
||||
ij_java_enum_constants_wrap = off
|
||||
ij_java_enum_field_annotation_wrap = off
|
||||
ij_java_extends_keyword_wrap = off
|
||||
ij_java_extends_list_wrap = off
|
||||
ij_java_field_annotation_wrap = split_into_lines
|
||||
ij_java_field_name_prefix =
|
||||
ij_java_field_name_suffix =
|
||||
ij_java_finally_on_new_line = false
|
||||
ij_java_for_brace_force = never
|
||||
ij_java_for_statement_new_line_after_left_paren = false
|
||||
ij_java_for_statement_right_paren_on_new_line = true
|
||||
ij_java_for_statement_wrap = off
|
||||
ij_java_generate_final_locals = false
|
||||
ij_java_generate_final_parameters = false
|
||||
ij_java_generate_use_type_annotation_before_type = true
|
||||
ij_java_if_brace_force = never
|
||||
ij_java_imports_layout = @*,*,|,java.**,|,$*
|
||||
ij_java_indent_case_from_switch = true
|
||||
ij_java_insert_inner_class_imports = false
|
||||
ij_java_insert_override_annotation = true
|
||||
ij_java_keep_blank_lines_before_right_brace = 2
|
||||
ij_java_keep_blank_lines_between_package_declaration_and_header = 2
|
||||
ij_java_keep_blank_lines_in_code = 2
|
||||
ij_java_keep_blank_lines_in_declarations = 2
|
||||
ij_java_keep_builder_methods_indents = false
|
||||
ij_java_keep_control_statement_in_one_line = true
|
||||
ij_java_keep_first_column_comment = true
|
||||
ij_java_keep_indents_on_empty_lines = false
|
||||
ij_java_keep_line_breaks = true
|
||||
ij_java_keep_multiple_expressions_in_one_line = false
|
||||
ij_java_keep_simple_blocks_in_one_line = false
|
||||
ij_java_keep_simple_classes_in_one_line = true
|
||||
ij_java_keep_simple_lambdas_in_one_line = false
|
||||
ij_java_keep_simple_methods_in_one_line = false
|
||||
ij_java_label_indent_absolute = false
|
||||
ij_java_label_indent_size = 0
|
||||
ij_java_lambda_brace_style = end_of_line
|
||||
ij_java_layout_on_demand_import_from_same_package_first = true
|
||||
ij_java_layout_static_imports_separately = true
|
||||
ij_java_line_comment_add_space = false
|
||||
ij_java_line_comment_add_space_on_reformat = false
|
||||
ij_java_line_comment_at_first_column = true
|
||||
ij_java_local_variable_name_prefix =
|
||||
ij_java_local_variable_name_suffix =
|
||||
ij_java_method_annotation_wrap = split_into_lines
|
||||
ij_java_method_brace_style = end_of_line
|
||||
ij_java_method_call_chain_wrap = off
|
||||
ij_java_method_parameters_new_line_after_left_paren = true
|
||||
ij_java_method_parameters_right_paren_on_new_line = true
|
||||
ij_java_method_parameters_wrap = on_every_item
|
||||
ij_java_modifier_list_wrap = false
|
||||
ij_java_multi_catch_types_wrap = normal
|
||||
ij_java_names_count_to_use_import_on_demand = 10
|
||||
ij_java_new_line_after_lparen_in_annotation = false
|
||||
ij_java_new_line_after_lparen_in_deconstruction_pattern = true
|
||||
ij_java_new_line_after_lparen_in_record_header = false
|
||||
ij_java_new_line_when_body_is_presented = false
|
||||
ij_java_packages_to_use_import_on_demand =
|
||||
ij_java_parameter_annotation_wrap = off
|
||||
ij_java_parameter_name_prefix =
|
||||
ij_java_parameter_name_suffix =
|
||||
ij_java_parentheses_expression_new_line_after_left_paren = false
|
||||
ij_java_parentheses_expression_right_paren_on_new_line = true
|
||||
ij_java_place_assignment_sign_on_next_line = false
|
||||
ij_java_prefer_longer_names = true
|
||||
ij_java_prefer_parameters_wrap = false
|
||||
ij_java_preserve_module_imports = true
|
||||
ij_java_record_components_wrap = normal
|
||||
ij_java_repeat_synchronized = true
|
||||
ij_java_replace_instanceof_and_cast = true
|
||||
ij_java_replace_null_check = true
|
||||
ij_java_replace_sum_lambda_with_method_ref = true
|
||||
ij_java_resource_list_new_line_after_left_paren = false
|
||||
ij_java_resource_list_right_paren_on_new_line = true
|
||||
ij_java_resource_list_wrap = off
|
||||
ij_java_rparen_on_new_line_in_annotation = true
|
||||
ij_java_rparen_on_new_line_in_deconstruction_pattern = true
|
||||
ij_java_rparen_on_new_line_in_record_header = true
|
||||
ij_java_space_after_closing_angle_bracket_in_type_argument = false
|
||||
ij_java_space_after_colon = true
|
||||
ij_java_space_after_comma = true
|
||||
ij_java_space_after_comma_in_type_arguments = true
|
||||
ij_java_space_after_for_semicolon = true
|
||||
ij_java_space_after_quest = true
|
||||
ij_java_space_after_type_cast = true
|
||||
ij_java_space_before_annotation_array_initializer_left_brace = false
|
||||
ij_java_space_before_annotation_parameter_list = false
|
||||
ij_java_space_before_array_initializer_left_brace = false
|
||||
ij_java_space_before_catch_keyword = true
|
||||
ij_java_space_before_catch_left_brace = true
|
||||
ij_java_space_before_catch_parentheses = true
|
||||
ij_java_space_before_class_left_brace = true
|
||||
ij_java_space_before_colon = true
|
||||
ij_java_space_before_colon_in_foreach = true
|
||||
ij_java_space_before_comma = false
|
||||
ij_java_space_before_deconstruction_list = false
|
||||
ij_java_space_before_do_left_brace = true
|
||||
ij_java_space_before_else_keyword = true
|
||||
ij_java_space_before_else_left_brace = true
|
||||
ij_java_space_before_finally_keyword = true
|
||||
ij_java_space_before_finally_left_brace = true
|
||||
ij_java_space_before_for_left_brace = true
|
||||
ij_java_space_before_for_parentheses = true
|
||||
ij_java_space_before_for_semicolon = false
|
||||
ij_java_space_before_if_left_brace = true
|
||||
ij_java_space_before_if_parentheses = true
|
||||
ij_java_space_before_method_call_parentheses = false
|
||||
ij_java_space_before_method_left_brace = true
|
||||
ij_java_space_before_method_parentheses = false
|
||||
ij_java_space_before_opening_angle_bracket_in_type_parameter = false
|
||||
ij_java_space_before_quest = true
|
||||
ij_java_space_before_switch_left_brace = true
|
||||
ij_java_space_before_switch_parentheses = true
|
||||
ij_java_space_before_synchronized_left_brace = true
|
||||
ij_java_space_before_synchronized_parentheses = true
|
||||
ij_java_space_before_try_left_brace = true
|
||||
ij_java_space_before_try_parentheses = true
|
||||
ij_java_space_before_type_parameter_list = false
|
||||
ij_java_space_before_while_keyword = true
|
||||
ij_java_space_before_while_left_brace = true
|
||||
ij_java_space_before_while_parentheses = true
|
||||
ij_java_space_inside_one_line_enum_braces = false
|
||||
ij_java_space_within_empty_array_initializer_braces = false
|
||||
ij_java_space_within_empty_method_call_parentheses = false
|
||||
ij_java_space_within_empty_method_parentheses = false
|
||||
ij_java_spaces_around_additive_operators = true
|
||||
ij_java_spaces_around_annotation_eq = true
|
||||
ij_java_spaces_around_assignment_operators = true
|
||||
ij_java_spaces_around_bitwise_operators = true
|
||||
ij_java_spaces_around_equality_operators = true
|
||||
ij_java_spaces_around_lambda_arrow = true
|
||||
ij_java_spaces_around_logical_operators = true
|
||||
ij_java_spaces_around_method_ref_dbl_colon = false
|
||||
ij_java_spaces_around_multiplicative_operators = true
|
||||
ij_java_spaces_around_relational_operators = true
|
||||
ij_java_spaces_around_shift_operators = true
|
||||
ij_java_spaces_around_type_bounds_in_type_parameters = true
|
||||
ij_java_spaces_around_unary_operator = false
|
||||
ij_java_spaces_inside_block_braces_when_body_is_present = false
|
||||
ij_java_spaces_within_angle_brackets = false
|
||||
ij_java_spaces_within_annotation_parentheses = false
|
||||
ij_java_spaces_within_array_initializer_braces = false
|
||||
ij_java_spaces_within_braces = false
|
||||
ij_java_spaces_within_brackets = false
|
||||
ij_java_spaces_within_cast_parentheses = false
|
||||
ij_java_spaces_within_catch_parentheses = false
|
||||
ij_java_spaces_within_deconstruction_list = false
|
||||
ij_java_spaces_within_for_parentheses = false
|
||||
ij_java_spaces_within_if_parentheses = false
|
||||
ij_java_spaces_within_method_call_parentheses = false
|
||||
ij_java_spaces_within_method_parentheses = false
|
||||
ij_java_spaces_within_parentheses = false
|
||||
ij_java_spaces_within_record_header = false
|
||||
ij_java_spaces_within_switch_parentheses = false
|
||||
ij_java_spaces_within_synchronized_parentheses = false
|
||||
ij_java_spaces_within_try_parentheses = false
|
||||
ij_java_spaces_within_while_parentheses = false
|
||||
ij_java_special_else_if_treatment = true
|
||||
ij_java_static_field_name_prefix =
|
||||
ij_java_static_field_name_suffix =
|
||||
ij_java_subclass_name_prefix =
|
||||
ij_java_subclass_name_suffix = Impl
|
||||
ij_java_switch_expressions_wrap = normal
|
||||
ij_java_ternary_operation_signs_on_next_line = false
|
||||
ij_java_ternary_operation_wrap = off
|
||||
ij_java_test_name_prefix =
|
||||
ij_java_test_name_suffix = Test
|
||||
ij_java_throws_keyword_wrap = off
|
||||
ij_java_throws_list_wrap = off
|
||||
ij_java_use_external_annotations = false
|
||||
ij_java_use_fq_class_names = false
|
||||
ij_java_use_relative_indents = false
|
||||
ij_java_use_single_class_imports = true
|
||||
ij_java_variable_annotation_wrap = off
|
||||
ij_java_visibility = public
|
||||
ij_java_while_brace_force = never
|
||||
ij_java_while_on_new_line = false
|
||||
ij_java_wrap_comments = false
|
||||
ij_java_wrap_first_method_in_call_chain = false
|
||||
ij_java_wrap_long_lines = false
|
||||
ij_java_wrap_semicolon_after_call_chain = false
|
||||
|
||||
[*.properties]
|
||||
ij_properties_align_group_field_declarations = false
|
||||
ij_properties_keep_blank_lines = false
|
||||
ij_properties_key_value_delimiter = equals
|
||||
ij_properties_spaces_around_key_value_delimiter = false
|
||||
|
||||
[.editorconfig]
|
||||
ij_editorconfig_align_group_field_declarations = false
|
||||
ij_editorconfig_space_after_colon = false
|
||||
ij_editorconfig_space_after_comma = true
|
||||
ij_editorconfig_space_before_colon = false
|
||||
ij_editorconfig_space_before_comma = false
|
||||
ij_editorconfig_spaces_around_assignment_operators = true
|
||||
|
||||
[{*.ant,*.fxml,*.jhm,*.jnlp,*.jrxml,*.jspx,*.pom,*.rng,*.tagx,*.tld,*.wsdl,*.xml,*.xsd,*.xsl,*.xslt,*.xul}]
|
||||
ij_xml_align_attributes = true
|
||||
ij_xml_align_text = false
|
||||
ij_xml_attribute_wrap = normal
|
||||
ij_xml_block_comment_add_space = false
|
||||
ij_xml_block_comment_at_first_column = true
|
||||
ij_xml_keep_blank_lines = 2
|
||||
ij_xml_keep_indents_on_empty_lines = false
|
||||
ij_xml_keep_line_breaks = true
|
||||
ij_xml_keep_line_breaks_in_text = true
|
||||
ij_xml_keep_whitespaces = false
|
||||
ij_xml_keep_whitespaces_around_cdata = preserve
|
||||
ij_xml_keep_whitespaces_inside_cdata = false
|
||||
ij_xml_line_comment_at_first_column = true
|
||||
ij_xml_space_after_tag_name = false
|
||||
ij_xml_space_around_equals_in_attribute = false
|
||||
ij_xml_space_inside_empty_tag = false
|
||||
ij_xml_text_wrap = normal
|
||||
|
||||
[{*.bash,*.sh,*.zsh}]
|
||||
ij_shell_binary_ops_start_line = false
|
||||
ij_shell_keep_column_alignment_padding = false
|
||||
ij_shell_minify_program = false
|
||||
ij_shell_redirect_followed_by_space = false
|
||||
ij_shell_switch_cases_indented = false
|
||||
ij_shell_use_unix_line_separator = true
|
||||
|
||||
[{*.kt,*.kts}]
|
||||
ij_kotlin_align_in_columns_case_branch = false
|
||||
ij_kotlin_align_multiline_binary_operation = false
|
||||
ij_kotlin_align_multiline_extends_list = false
|
||||
ij_kotlin_align_multiline_method_parentheses = false
|
||||
ij_kotlin_align_multiline_parameters = true
|
||||
ij_kotlin_align_multiline_parameters_in_calls = false
|
||||
ij_kotlin_allow_trailing_comma = false
|
||||
ij_kotlin_allow_trailing_comma_on_call_site = false
|
||||
ij_kotlin_assignment_wrap = normal
|
||||
ij_kotlin_blank_lines_after_class_header = 0
|
||||
ij_kotlin_blank_lines_around_block_when_branches = 0
|
||||
ij_kotlin_blank_lines_before_declaration_with_comment_or_annotation_on_separate_line = 1
|
||||
ij_kotlin_block_comment_add_space = false
|
||||
ij_kotlin_block_comment_at_first_column = true
|
||||
ij_kotlin_call_parameters_new_line_after_left_paren = true
|
||||
ij_kotlin_call_parameters_right_paren_on_new_line = true
|
||||
ij_kotlin_call_parameters_wrap = on_every_item
|
||||
ij_kotlin_catch_on_new_line = false
|
||||
ij_kotlin_class_annotation_wrap = split_into_lines
|
||||
ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL
|
||||
ij_kotlin_continuation_indent_for_chained_calls = false
|
||||
ij_kotlin_continuation_indent_for_expression_bodies = false
|
||||
ij_kotlin_continuation_indent_in_argument_lists = false
|
||||
ij_kotlin_continuation_indent_in_elvis = false
|
||||
ij_kotlin_continuation_indent_in_if_conditions = false
|
||||
ij_kotlin_continuation_indent_in_parameter_lists = false
|
||||
ij_kotlin_continuation_indent_in_supertype_lists = false
|
||||
ij_kotlin_else_on_new_line = false
|
||||
ij_kotlin_enum_constants_wrap = off
|
||||
ij_kotlin_extends_list_wrap = normal
|
||||
ij_kotlin_field_annotation_wrap = split_into_lines
|
||||
ij_kotlin_finally_on_new_line = false
|
||||
ij_kotlin_if_rparen_on_new_line = true
|
||||
ij_kotlin_import_nested_classes = false
|
||||
ij_kotlin_imports_layout = *,java.**,javax.**,kotlin.**,^
|
||||
ij_kotlin_indent_before_arrow_on_new_line = true
|
||||
ij_kotlin_insert_whitespaces_in_simple_one_line_method = true
|
||||
ij_kotlin_keep_blank_lines_before_right_brace = 2
|
||||
ij_kotlin_keep_blank_lines_in_code = 2
|
||||
ij_kotlin_keep_blank_lines_in_declarations = 2
|
||||
ij_kotlin_keep_first_column_comment = true
|
||||
ij_kotlin_keep_indents_on_empty_lines = false
|
||||
ij_kotlin_keep_line_breaks = true
|
||||
ij_kotlin_lbrace_on_next_line = false
|
||||
ij_kotlin_line_break_after_multiline_when_entry = true
|
||||
ij_kotlin_line_comment_add_space = false
|
||||
ij_kotlin_line_comment_add_space_on_reformat = false
|
||||
ij_kotlin_line_comment_at_first_column = true
|
||||
ij_kotlin_method_annotation_wrap = split_into_lines
|
||||
ij_kotlin_method_call_chain_wrap = normal
|
||||
ij_kotlin_method_parameters_new_line_after_left_paren = true
|
||||
ij_kotlin_method_parameters_right_paren_on_new_line = true
|
||||
ij_kotlin_method_parameters_wrap = on_every_item
|
||||
ij_kotlin_name_count_to_use_star_import = 5
|
||||
ij_kotlin_name_count_to_use_star_import_for_members = 3
|
||||
ij_kotlin_packages_to_use_import_on_demand = java.util.*,kotlinx.android.synthetic.**,io.ktor.**
|
||||
ij_kotlin_parameter_annotation_wrap = off
|
||||
ij_kotlin_space_after_comma = true
|
||||
ij_kotlin_space_after_extend_colon = true
|
||||
ij_kotlin_space_after_type_colon = true
|
||||
ij_kotlin_space_before_catch_parentheses = true
|
||||
ij_kotlin_space_before_comma = false
|
||||
ij_kotlin_space_before_extend_colon = true
|
||||
ij_kotlin_space_before_for_parentheses = true
|
||||
ij_kotlin_space_before_if_parentheses = true
|
||||
ij_kotlin_space_before_lambda_arrow = true
|
||||
ij_kotlin_space_before_type_colon = false
|
||||
ij_kotlin_space_before_when_parentheses = true
|
||||
ij_kotlin_space_before_while_parentheses = true
|
||||
ij_kotlin_spaces_around_additive_operators = true
|
||||
ij_kotlin_spaces_around_assignment_operators = true
|
||||
ij_kotlin_spaces_around_elvis = true
|
||||
ij_kotlin_spaces_around_equality_operators = true
|
||||
ij_kotlin_spaces_around_function_type_arrow = true
|
||||
ij_kotlin_spaces_around_logical_operators = true
|
||||
ij_kotlin_spaces_around_multiplicative_operators = true
|
||||
ij_kotlin_spaces_around_range = false
|
||||
ij_kotlin_spaces_around_relational_operators = true
|
||||
ij_kotlin_spaces_around_unary_operator = false
|
||||
ij_kotlin_spaces_around_when_arrow = true
|
||||
ij_kotlin_variable_annotation_wrap = off
|
||||
ij_kotlin_while_on_new_line = false
|
||||
ij_kotlin_wrap_elvis_expressions = 1
|
||||
ij_kotlin_wrap_expression_body_functions = 1
|
||||
ij_kotlin_wrap_first_method_in_call_chain = false
|
||||
|
||||
[{*.har,*.json,*.jsonc,*.mcmeta,.prettierrc}]
|
||||
ij_json_array_wrapping = split_into_lines
|
||||
ij_json_keep_blank_lines_in_code = 0
|
||||
ij_json_keep_indents_on_empty_lines = false
|
||||
ij_json_keep_line_breaks = true
|
||||
ij_json_keep_trailing_comma = false
|
||||
ij_json_object_wrapping = split_into_lines
|
||||
ij_json_property_alignment = do_not_align
|
||||
ij_json_space_after_colon = true
|
||||
ij_json_space_after_comma = true
|
||||
ij_json_space_before_colon = false
|
||||
ij_json_space_before_comma = false
|
||||
ij_json_spaces_within_braces = false
|
||||
ij_json_spaces_within_brackets = false
|
||||
ij_json_wrap_long_lines = false
|
||||
|
||||
[{*.htm,*.html,*.sht,*.shtm,*.shtml}]
|
||||
ij_html_add_new_line_before_tags = body,div,p,form,h1,h2,h3
|
||||
ij_html_align_attributes = true
|
||||
ij_html_align_text = false
|
||||
ij_html_attribute_wrap = normal
|
||||
ij_html_block_comment_add_space = false
|
||||
ij_html_block_comment_at_first_column = true
|
||||
ij_html_do_not_align_children_of_min_lines = 0
|
||||
ij_html_do_not_break_if_inline_tags = title,h1,h2,h3,h4,h5,h6,p
|
||||
ij_html_do_not_indent_children_of_tags = html,body,thead,tbody,tfoot
|
||||
ij_html_enforce_quotes = false
|
||||
ij_html_inline_tags = a,abbr,acronym,b,basefont,bdo,big,br,cite,cite,code,dfn,em,font,i,img,input,kbd,label,q,s,samp,select,small,span,strike,strong,sub,sup,textarea,tt,u,var
|
||||
ij_html_keep_blank_lines = 2
|
||||
ij_html_keep_indents_on_empty_lines = false
|
||||
ij_html_keep_line_breaks = true
|
||||
ij_html_keep_line_breaks_in_text = true
|
||||
ij_html_keep_whitespaces = false
|
||||
ij_html_keep_whitespaces_inside = span,pre,textarea
|
||||
ij_html_line_comment_at_first_column = true
|
||||
ij_html_new_line_after_last_attribute = never
|
||||
ij_html_new_line_before_first_attribute = never
|
||||
ij_html_quote_style = double
|
||||
ij_html_remove_new_line_before_tags = br
|
||||
ij_html_space_after_tag_name = false
|
||||
ij_html_space_around_equality_in_attribute = false
|
||||
ij_html_space_inside_empty_tag = false
|
||||
ij_html_text_wrap = normal
|
||||
|
||||
[{*.markdown,*.md}]
|
||||
ij_markdown_force_one_space_after_blockquote_symbol = true
|
||||
ij_markdown_force_one_space_after_header_symbol = true
|
||||
ij_markdown_force_one_space_after_list_bullet = true
|
||||
ij_markdown_force_one_space_between_words = true
|
||||
ij_markdown_format_tables = true
|
||||
ij_markdown_insert_quote_arrows_on_wrap = true
|
||||
ij_markdown_keep_indents_on_empty_lines = false
|
||||
ij_markdown_keep_line_breaks_inside_text_blocks = true
|
||||
ij_markdown_max_lines_around_block_elements = 1
|
||||
ij_markdown_max_lines_around_header = 1
|
||||
ij_markdown_max_lines_between_paragraphs = 1
|
||||
ij_markdown_min_lines_around_block_elements = 1
|
||||
ij_markdown_min_lines_around_header = 1
|
||||
ij_markdown_min_lines_between_paragraphs = 1
|
||||
ij_markdown_wrap_text_if_long = true
|
||||
ij_markdown_wrap_text_inside_blockquotes = true
|
||||
|
||||
[{*.toml,Cargo.lock,Cargo.toml.orig,Gopkg.lock,Pipfile,poetry.lock,uv.lock}]
|
||||
ij_toml_keep_indents_on_empty_lines = false
|
||||
|
||||
[{*.yaml,*.yml}]
|
||||
ij_yaml_align_values_properties = do_not_align
|
||||
ij_yaml_autoinsert_sequence_marker = true
|
||||
ij_yaml_block_mapping_on_new_line = false
|
||||
ij_yaml_indent_sequence_value = true
|
||||
ij_yaml_keep_indents_on_empty_lines = false
|
||||
ij_yaml_keep_line_breaks = true
|
||||
ij_yaml_line_comment_add_space = false
|
||||
ij_yaml_line_comment_add_space_on_reformat = false
|
||||
ij_yaml_line_comment_at_first_column = true
|
||||
ij_yaml_sequence_on_new_line = false
|
||||
ij_yaml_space_before_colon = false
|
||||
ij_yaml_spaces_within_braces = true
|
||||
ij_yaml_spaces_within_brackets = true
|
||||
@@ -0,0 +1,11 @@
|
||||
# Use lf endings by default.
|
||||
* text=auto eol=lf
|
||||
|
||||
# Declare text file types just in case
|
||||
*.java text
|
||||
*.yml text
|
||||
*.xml text
|
||||
*.md text
|
||||
|
||||
# Exclude binary files
|
||||
*.png binary
|
||||
@@ -0,0 +1,19 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "monthly"
|
||||
- package-ecosystem: "gradle"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "monthly"
|
||||
ignore:
|
||||
# The SQLite JDBC is provided by Spigot and, for now, Paper.
|
||||
# To ensure it is still present even if Paper stops providing it,
|
||||
# we need to declare it as a library.
|
||||
# To prevent needlessly downloading (and loading) a second copy,
|
||||
# we want to ensure that we are using the provided version.
|
||||
- dependency-name: "org.xerial:sqlite-jdbc"
|
||||
# Spigot and Spigot API updates are manual.
|
||||
- dependency-name: "org.spigotmc:*"
|
||||
@@ -0,0 +1,55 @@
|
||||
name: Auto-merge Dependabot PRs
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: [ "Pull Request" ]
|
||||
types: [ completed ]
|
||||
|
||||
jobs:
|
||||
merge-dependabot:
|
||||
if: "github.actor == 'dependabot[bot]'
|
||||
&& github.event.workflow_run.event == 'pull_request'
|
||||
&& github.event.workflow_run.conclusion == 'success'"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
# Note: this is directly from GitHub's example for using data from a triggering workflow:
|
||||
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#using-data-from-the-triggering-workflow
|
||||
- name: 'Download artifact'
|
||||
uses: actions/github-script@v9
|
||||
with:
|
||||
script: |
|
||||
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
run_id: context.payload.workflow_run.id,
|
||||
});
|
||||
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
|
||||
return artifact.name == "pr_number"
|
||||
})[0];
|
||||
let download = await github.rest.actions.downloadArtifact({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
artifact_id: matchArtifact.id,
|
||||
archive_format: 'zip',
|
||||
});
|
||||
let fs = require('fs');
|
||||
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/pr_number.zip`, Buffer.from(download.data));
|
||||
|
||||
# This might be a useless use of cat, but I'm not sure what shell Actions is going to be running.
|
||||
- name: Add Pull Number Variable
|
||||
run: |-
|
||||
unzip pr_number.zip
|
||||
echo "PR_NUMBER=$(cat pr_number)" >> "$GITHUB_ENV"
|
||||
|
||||
- name: Approve
|
||||
uses: hmarr/auto-approve-action@v4.0.0
|
||||
with:
|
||||
github-token: "${{ secrets.GITHUB_TOKEN }}"
|
||||
pull-request-number: "${{ env.PR_NUMBER }}"
|
||||
- name: Merge
|
||||
uses: pascalgn/automerge-action@v0.16.4
|
||||
env:
|
||||
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
|
||||
MERGE_LABELS: "dependencies,java"
|
||||
MERGE_METHOD: "squash"
|
||||
PULL_REQUEST: "${{ env.PR_NUMBER }}"
|
||||
@@ -0,0 +1,36 @@
|
||||
name: OpenInv CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'master'
|
||||
tags-ignore:
|
||||
- '**'
|
||||
paths-ignore:
|
||||
- resource-pack/openinv-legibility-pack/**
|
||||
# Enable running CI via other Actions, i.e. for drafting releases and handling PRs.
|
||||
workflow_call:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
|
||||
- uses: actions/setup-java@v6
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '25'
|
||||
|
||||
- uses: gradle/actions/setup-gradle@v5
|
||||
|
||||
- name: Build with Gradle
|
||||
run: ./gradlew build
|
||||
|
||||
# Upload artifacts
|
||||
- name: Upload Distributable Jar
|
||||
id: upload-final
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: dist
|
||||
path: ./dist/*
|
||||
@@ -0,0 +1,38 @@
|
||||
name: Draft Github Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '**'
|
||||
|
||||
jobs:
|
||||
run-ci:
|
||||
uses: Jikoo/OpenInv/.github/workflows/ci.yml@master
|
||||
draft-release:
|
||||
needs: [ run-ci ]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Download build
|
||||
uses: actions/download-artifact@v8
|
||||
with:
|
||||
name: dist
|
||||
path: dist
|
||||
|
||||
- name: Create Release
|
||||
id: create-release
|
||||
uses: softprops/action-gh-release@v3.0.3
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
name: "OpenInv ${{ github.ref_name }}"
|
||||
body: |-
|
||||
## Supported server versions
|
||||
|
||||
**Paper:** TODO VERSION, 26.1.2, 1.21.11, 1.21.10, 1.21.9, 1.21.8, 1.21.7, 1.21.6
|
||||
**Spigot:** TODO VERSION
|
||||
|
||||
TODO HELLO HUMAN, PRESS THE GENERATE CHANGELOG BUTTON PLEASE.
|
||||
Don't forget to add a newline after the resulting header and prettify the tag compare link!
|
||||
draft: true
|
||||
prerelease: false
|
||||
files: ./dist/**
|
||||
@@ -0,0 +1,110 @@
|
||||
name: Release to external sites
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [ released ]
|
||||
|
||||
jobs:
|
||||
curseforge_release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- &parse-paper-versions
|
||||
name: Parse Paper Versions
|
||||
id: parse_versions
|
||||
run: |
|
||||
# Find line declaring Paper versions.
|
||||
raw=$(grep "\\*\\*Paper:\\*\\*" <<< "${{ github.event.release.body }}")
|
||||
|
||||
# Enable extended glob pattern to match 0 or more whitespace characters.
|
||||
shopt -s extglob
|
||||
# Trim Paper versions identifier prefix.
|
||||
raw=${raw/*([[:space:]])'**'Paper:'**'*([[:space:]])/}
|
||||
# Replace commas and optional spaces with a newline.
|
||||
raw=${raw//,*([[:space:]])/$'\n'}
|
||||
# Turn extglob back off.
|
||||
shopt -u extglob
|
||||
|
||||
echo "$raw"
|
||||
printf "PAPER_VERSIONS<<EOF\n%s\nEOF\n" "$raw" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- &fetch-release-asset
|
||||
name: Fetch Github Release Asset
|
||||
uses: dsaltares/fetch-gh-release-asset@1.1.2
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
version: ${{ github.event.release.id }}
|
||||
file: OpenInv.jar
|
||||
|
||||
- name: Create CurseForge Release
|
||||
uses: Kira-NT/mc-publish@v3.3
|
||||
with:
|
||||
curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }}
|
||||
curseforge-id: 31432
|
||||
files: ./OpenInv.jar
|
||||
game-versions: "${{ steps.parse_versions.outputs.PAPER_VERSIONS }}"
|
||||
game-version-filter: releases
|
||||
loaders: |
|
||||
spigot
|
||||
paper
|
||||
folia
|
||||
|
||||
modrinth_release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- *parse-paper-versions
|
||||
- *fetch-release-asset
|
||||
|
||||
- name: Create Modrinth Release
|
||||
uses: Kira-NT/mc-publish@v3.3
|
||||
with:
|
||||
modrinth-id: 1UlvXbzL
|
||||
modrinth-featured: false
|
||||
modrinth-unfeature-mode: none
|
||||
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}
|
||||
files: ./OpenInv.jar
|
||||
game-versions: "${{ steps.parse_versions.outputs.PAPER_VERSIONS }}"
|
||||
game-version-filter: releases
|
||||
loaders: |
|
||||
spigot
|
||||
paper
|
||||
folia
|
||||
|
||||
hangar_release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Parse Hangar Paper Versions
|
||||
id: parse_versions
|
||||
run: |
|
||||
# Find line declaring Paper versions.
|
||||
raw=$(grep "\\*\\*Paper:\\*\\*" <<< "${{ github.event.release.body }}")
|
||||
# Trim Paper versions identifier prefix.
|
||||
raw="${raw/'**'Paper:'**'/}"
|
||||
# Trim leading and trailing spaces.
|
||||
raw="${raw##[[:space:]]}"
|
||||
raw="${raw%%[[:space:]]}"
|
||||
|
||||
# Generate JSON for Hangar. GitHub Actions provides jq 1.7 in the 24.04 image.
|
||||
# Split on comma and optional spaces.
|
||||
hangar_versions=$(jq -nc --arg versions "$raw" '{"PAPER": $versions | split(", *";null)}')
|
||||
|
||||
echo "$hangar_versions"
|
||||
echo "HANGAR_PAPER_VERSIONS=$hangar_versions" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- *fetch-release-asset
|
||||
|
||||
- name: Create Hangar Release
|
||||
uses: benwoo1110/hangar-upload-action@v1
|
||||
with:
|
||||
api_token: ${{ secrets.HANGAR_TOKEN }}
|
||||
slug: 'OpenInv'
|
||||
version: ${{ github.event.release.tag_name }}
|
||||
channel: release
|
||||
description: "${{ github.event.release.body }}"
|
||||
files: |-
|
||||
[
|
||||
{
|
||||
"path": "./OpenInv.jar",
|
||||
"platforms": ["PAPER"]
|
||||
}
|
||||
]
|
||||
platform_dependencies: "${{ steps.parse_versions.outputs.HANGAR_PAPER_VERSIONS }}"
|
||||
@@ -0,0 +1,22 @@
|
||||
name: Pull Request
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
run-ci:
|
||||
uses: Jikoo/OpenInv/.github/workflows/ci.yml@master
|
||||
store-dependabot-pr-data:
|
||||
if: "github.actor == 'dependabot[bot]' && github.event_name == 'pull_request'"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
# Note: this is directly from GitHub's example for using data from a triggering workflow:
|
||||
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#using-data-from-the-triggering-workflow
|
||||
- name: Store Pull Number
|
||||
run: |
|
||||
mkdir -p ./pr
|
||||
echo ${{ github.event.number }} > ./pr/pr_number
|
||||
- uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: pr_number
|
||||
path: pr/
|
||||
@@ -0,0 +1,24 @@
|
||||
name: Resource Pack CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'master'
|
||||
tags-ignore:
|
||||
- '**'
|
||||
paths:
|
||||
- resource-pack/openinv-legibility-pack/**
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
|
||||
- name: Build resource pack
|
||||
id: upload-resource-pack
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: openinv-legibility-pack
|
||||
path: ./resource-pack/openinv-legibility-pack/
|
||||
compression-level: 9
|
||||
+11
-7
@@ -1,10 +1,14 @@
|
||||
**/.settings
|
||||
**/.gitignore
|
||||
**/.project
|
||||
**/.classpath
|
||||
**/.idea
|
||||
**/target
|
||||
**/bin
|
||||
**/lib
|
||||
**/out
|
||||
**dependency-reduced-pom.xml
|
||||
**/.idea/
|
||||
**/.gradle/
|
||||
**.iml
|
||||
**/target/
|
||||
**/bin/
|
||||
**/out/
|
||||
**/build/
|
||||
**/dist/
|
||||
**/dependency-reduced-pom.xml
|
||||
**/pom.xml.versionsBackup
|
||||
**/.vscode/
|
||||
@@ -1,28 +0,0 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinv</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>openinvadapter1_4_5</artifactId>
|
||||
<name>OpenInvAdapter1_4_5</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvplugin</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.4.5-R1.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -1,168 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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.lishid.openinv.internal.v1_4_5;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_4_5.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_4_5.BlockEnderChest;
|
||||
import net.minecraft.server.v1_4_5.EntityOcelot;
|
||||
import net.minecraft.server.v1_4_5.EntityPlayer;
|
||||
import net.minecraft.server.v1_4_5.IInventory;
|
||||
import net.minecraft.server.v1_4_5.InventoryEnderChest;
|
||||
import net.minecraft.server.v1_4_5.InventoryLargeChest;
|
||||
import net.minecraft.server.v1_4_5.Packet100OpenWindow;
|
||||
import net.minecraft.server.v1_4_5.TileEntityChest;
|
||||
import net.minecraft.server.v1_4_5.TileEntityEnderChest;
|
||||
import net.minecraft.server.v1_4_5.World;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_4_5.entity.CraftPlayer;
|
||||
|
||||
public class AnySilentContainer implements IAnySilentContainer {
|
||||
|
||||
@Override
|
||||
public boolean isAnySilentContainer(org.bukkit.block.Block block) {
|
||||
return block.getType() == Material.ENDER_CHEST || block.getState() instanceof org.bukkit.block.Chest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) {
|
||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||
World world = player.world;
|
||||
|
||||
if (block instanceof BlockEnderChest) {
|
||||
// Ender chests are not blocked by ocelots.
|
||||
return world.t(block.getX(), block.getY() + 1, block.getZ());
|
||||
}
|
||||
|
||||
// If block or ocelot on top
|
||||
if (isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
|
||||
|
||||
// If block next to chest is chest and has a block or ocelot on top
|
||||
if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
|
||||
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() + 1);
|
||||
} else if(world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
|
||||
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() - 1);
|
||||
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
|
||||
return isBlockedChest(world, block.getX() + 1, block.getY() + 1, block.getZ());
|
||||
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
|
||||
return isBlockedChest(world, block.getX() - 1, block.getY() + 1, block.getZ());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isBlockedChest(World world, int x, int y, int z) {
|
||||
return world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z);
|
||||
}
|
||||
|
||||
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
|
||||
for (Object localEntity : world.a(EntityOcelot.class,
|
||||
AxisAlignedBB.a(x, y + 1, z, x + 1, y + 2, z + 1))) {
|
||||
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
|
||||
if (localEntityOcelot.isSitting()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) {
|
||||
|
||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||
|
||||
// Silent ender chest is API-only
|
||||
if (silentchest && block.getType() == Material.ENDER_CHEST) {
|
||||
p.openInventory(p.getEnderChest());
|
||||
return true;
|
||||
}
|
||||
|
||||
World world = player.world;
|
||||
Object tile = world.getTileEntity(block.getX(), block.getY(), block.getZ());
|
||||
|
||||
if (tile == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (tile instanceof TileEntityEnderChest) {
|
||||
// Anychest ender chest. See net.minecraft.server.BlockEnderChest
|
||||
InventoryEnderChest enderChest = player.getEnderChest();
|
||||
enderChest.a((TileEntityEnderChest) tile);
|
||||
player.openContainer(enderChest);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(tile instanceof IInventory)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
|
||||
|
||||
if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
|
||||
tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1));
|
||||
} else if (world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
|
||||
tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), (IInventory) tile);
|
||||
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
|
||||
tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ()));
|
||||
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
|
||||
tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), (IInventory) tile);
|
||||
}
|
||||
|
||||
boolean returnValue = false;
|
||||
if (!silentchest) {
|
||||
player.openContainer((IInventory) tile);
|
||||
returnValue = true;
|
||||
} else {
|
||||
try {
|
||||
int windowId = 0;
|
||||
try {
|
||||
Field windowID = player.getClass().getDeclaredField("containerCounter");
|
||||
windowID.setAccessible(true);
|
||||
windowId = windowID.getInt(player);
|
||||
windowId = windowId % 100 + 1;
|
||||
windowID.setInt(player, windowId);
|
||||
} catch (NoSuchFieldException e) {}
|
||||
|
||||
player.netServerHandler.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) tile).getName(), ((IInventory) tile).getSize()));
|
||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) tile));
|
||||
player.activeContainer.windowId = windowId;
|
||||
player.activeContainer.addSlotListener(player);
|
||||
returnValue = true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
||||
}
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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.lishid.openinv.internal.v1_4_5;
|
||||
|
||||
import com.lishid.openinv.internal.IInventoryAccess;
|
||||
import com.lishid.openinv.internal.ISpecialEnderChest;
|
||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||
import com.lishid.openinv.internal.InternalAccessor;
|
||||
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_4_5.IInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_4_5.inventory.CraftInventory;
|
||||
|
||||
public class InventoryAccess implements IInventoryAccess {
|
||||
|
||||
@Override
|
||||
public boolean isSpecialPlayerInventory(Inventory inventory) {
|
||||
if (inventory instanceof CraftInventory) {
|
||||
return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
|
||||
}
|
||||
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialPlayerInventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISpecialPlayerInventory getSpecialPlayerInventory(Inventory inventory) {
|
||||
IInventory inv;
|
||||
if (inventory instanceof CraftInventory) {
|
||||
inv = ((CraftInventory) inventory).getInventory();
|
||||
} else {
|
||||
inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
|
||||
}
|
||||
|
||||
if (inv instanceof SpecialPlayerInventory) {
|
||||
return (SpecialPlayerInventory) inv;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSpecialEnderChest(Inventory inventory) {
|
||||
if (inventory instanceof CraftInventory) {
|
||||
return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
|
||||
}
|
||||
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialEnderChest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISpecialEnderChest getSpecialEnderChest(Inventory inventory) {
|
||||
IInventory inv;
|
||||
if (inventory instanceof CraftInventory) {
|
||||
inv = ((CraftInventory) inventory).getInventory();
|
||||
} else {
|
||||
inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
|
||||
}
|
||||
|
||||
if (inv instanceof SpecialEnderChest) {
|
||||
return (SpecialEnderChest) inv;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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.lishid.openinv.internal.v1_4_5;
|
||||
|
||||
import com.lishid.openinv.internal.IPlayerDataManager;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_4_5.EntityPlayer;
|
||||
import net.minecraft.server.v1_4_5.ItemInWorldManager;
|
||||
import net.minecraft.server.v1_4_5.MinecraftServer;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_4_5.CraftServer;
|
||||
|
||||
public class PlayerDataManager implements IPlayerDataManager {
|
||||
|
||||
@Override
|
||||
public Player loadPlayer(OfflinePlayer offline) {
|
||||
// Ensure the player has data
|
||||
if (offline == null || !offline.hasPlayedBefore()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
|
||||
// Create an entity to load the player data
|
||||
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(),
|
||||
new ItemInWorldManager(server.getWorldServer(0)));
|
||||
|
||||
// Get the bukkit entity
|
||||
Player target = (entity == null) ? null : entity.getBukkitEntity();
|
||||
if (target != null) {
|
||||
// Load data
|
||||
target.loadData();
|
||||
}
|
||||
// Return the entity
|
||||
return target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerDataID(OfflinePlayer player) {
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfflinePlayer getPlayerByID(String identifier) {
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(identifier);
|
||||
// Ensure player is a real player, otherwise return null
|
||||
if (player == null || !player.hasPlayedBefore() && !player.isOnline()) {
|
||||
return null;
|
||||
}
|
||||
return player;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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.lishid.openinv.internal.v1_4_5;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_4_5.ContainerChest;
|
||||
import net.minecraft.server.v1_4_5.EntityHuman;
|
||||
import net.minecraft.server.v1_4_5.IInventory;
|
||||
import net.minecraft.server.v1_4_5.ItemStack;
|
||||
import net.minecraft.server.v1_4_5.PlayerInventory;
|
||||
|
||||
public class SilentContainerChest extends ContainerChest {
|
||||
|
||||
public SilentContainerChest(IInventory i1, IInventory i2) {
|
||||
super(i1, i2);
|
||||
// Send close signal
|
||||
i2.f();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void b(EntityHuman entityHuman) {
|
||||
// Don't send close signal twice, might screw up
|
||||
PlayerInventory playerinventory = entityHuman.inventory;
|
||||
|
||||
if (playerinventory.getCarried() != null) {
|
||||
ItemStack carried = playerinventory.getCarried();
|
||||
playerinventory.setCarried(null);
|
||||
entityHuman.drop(carried);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,128 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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.lishid.openinv.internal.v1_4_5;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialEnderChest;
|
||||
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_4_5.IInventory;
|
||||
import net.minecraft.server.v1_4_5.InventoryEnderChest;
|
||||
import net.minecraft.server.v1_4_5.InventorySubcontainer;
|
||||
import net.minecraft.server.v1_4_5.ItemStack;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_4_5.entity.CraftHumanEntity;
|
||||
import org.bukkit.craftbukkit.v1_4_5.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_4_5.inventory.CraftInventory;
|
||||
|
||||
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
|
||||
|
||||
private final InventoryEnderChest enderChest;
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
private final List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
||||
private boolean playerOnline = false;
|
||||
private CraftPlayer owner;
|
||||
private int maxStack = MAX_STACK;
|
||||
|
||||
public SpecialEnderChest(Player p, Boolean online) {
|
||||
super(((CraftPlayer) p).getHandle().getEnderChest().getName(),
|
||||
((CraftPlayer) p).getHandle().getEnderChest().getSize());
|
||||
CraftPlayer player = (CraftPlayer) p;
|
||||
this.enderChest = player.getHandle().getEnderChest();
|
||||
this.owner = player;
|
||||
this.items = enderChest.getContents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
try {
|
||||
owner = (CraftPlayer) player;
|
||||
InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest();
|
||||
Field field = playerEnderChest.getClass().getField("items");
|
||||
field.setAccessible(true);
|
||||
field.set(playerEnderChest, this.items);
|
||||
} catch (Exception e) {}
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
return this.items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(CraftHumanEntity who) {
|
||||
transaction.add(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(CraftHumanEntity who) {
|
||||
transaction.remove(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HumanEntity> getViewers() {
|
||||
return transaction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryHolder getOwner() {
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxStackSize(int size) {
|
||||
maxStack = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxStackSize() {
|
||||
return maxStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
enderChest.update();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,237 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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.lishid.openinv.internal.v1_4_5;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_4_5.ItemStack;
|
||||
import net.minecraft.server.v1_4_5.PlayerInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_4_5.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_4_5.inventory.CraftInventory;
|
||||
|
||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
|
||||
|
||||
private final ItemStack[] extra = new ItemStack[5];
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
private boolean playerOnline = false;
|
||||
|
||||
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
|
||||
super(((CraftPlayer) bukkitPlayer).getHandle());
|
||||
this.playerOnline = online;
|
||||
this.items = player.inventory.items;
|
||||
this.armor = player.inventory.armor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
this.player = ((CraftPlayer) player).getHandle();
|
||||
this.player.inventory.items = this.items;
|
||||
this.player.inventory.armor = this.armor;
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
ItemStack[] contents = new ItemStack[getSize()];
|
||||
System.arraycopy(items, 0, contents, 0, items.length);
|
||||
System.arraycopy(armor, 0, contents, items.length, armor.length);
|
||||
return contents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return super.getSize() + 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
return is[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitStack(int i, int j) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack;
|
||||
|
||||
if (is[i].count <= j) {
|
||||
itemstack = is[i];
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else {
|
||||
itemstack = is[i].a(j);
|
||||
if (is[i].count == 0) {
|
||||
is[i] = null;
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitWithoutUpdate(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack = is[i];
|
||||
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int i, ItemStack itemstack) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
// Effects
|
||||
if (is == this.extra) {
|
||||
player.drop(itemstack);
|
||||
itemstack = null;
|
||||
}
|
||||
|
||||
is[i] = itemstack;
|
||||
|
||||
player.defaultContainer.b();
|
||||
}
|
||||
|
||||
private int getReversedItemSlotNum(int i) {
|
||||
if (i >= 27)
|
||||
return i - 27;
|
||||
else
|
||||
return i + 9;
|
||||
}
|
||||
|
||||
private int getReversedArmorSlotNum(int i) {
|
||||
if (i == 0)
|
||||
return 3;
|
||||
if (i == 1)
|
||||
return 2;
|
||||
if (i == 2)
|
||||
return 1;
|
||||
if (i == 3)
|
||||
return 0;
|
||||
else
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (player.getName().length() > 16) {
|
||||
return player.getName().substring(0, 16);
|
||||
}
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinv</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>openinvadapter1_4_6</artifactId>
|
||||
<name>OpenInvAdapter1_4_6</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvplugin</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.4.6-R0.3</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -1,168 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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.lishid.openinv.internal.v1_4_6;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_4_6.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_4_6.BlockEnderChest;
|
||||
import net.minecraft.server.v1_4_6.EntityOcelot;
|
||||
import net.minecraft.server.v1_4_6.EntityPlayer;
|
||||
import net.minecraft.server.v1_4_6.IInventory;
|
||||
import net.minecraft.server.v1_4_6.InventoryEnderChest;
|
||||
import net.minecraft.server.v1_4_6.InventoryLargeChest;
|
||||
import net.minecraft.server.v1_4_6.Packet100OpenWindow;
|
||||
import net.minecraft.server.v1_4_6.TileEntityChest;
|
||||
import net.minecraft.server.v1_4_6.TileEntityEnderChest;
|
||||
import net.minecraft.server.v1_4_6.World;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_4_6.entity.CraftPlayer;
|
||||
|
||||
public class AnySilentContainer implements IAnySilentContainer {
|
||||
|
||||
@Override
|
||||
public boolean isAnySilentContainer(org.bukkit.block.Block block) {
|
||||
return block.getType() == Material.ENDER_CHEST || block.getState() instanceof org.bukkit.block.Chest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) {
|
||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||
World world = player.world;
|
||||
|
||||
if (block instanceof BlockEnderChest) {
|
||||
// Ender chests are not blocked by ocelots.
|
||||
return world.t(block.getX(), block.getY() + 1, block.getZ());
|
||||
}
|
||||
|
||||
// If block or ocelot on top
|
||||
if (isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
|
||||
|
||||
// If block next to chest is chest and has a block or ocelot on top
|
||||
if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
|
||||
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() + 1);
|
||||
} else if(world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
|
||||
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() - 1);
|
||||
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
|
||||
return isBlockedChest(world, block.getX() + 1, block.getY() + 1, block.getZ());
|
||||
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
|
||||
return isBlockedChest(world, block.getX() - 1, block.getY() + 1, block.getZ());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isBlockedChest(World world, int x, int y, int z) {
|
||||
return world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z);
|
||||
}
|
||||
|
||||
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
|
||||
for (Object localEntity : world.a(EntityOcelot.class,
|
||||
AxisAlignedBB.a(x, y + 1, z, x + 1, y + 2, z + 1))) {
|
||||
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
|
||||
if (localEntityOcelot.isSitting()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) {
|
||||
|
||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||
|
||||
// Silent ender chest is API-only
|
||||
if (silentchest && block.getType() == Material.ENDER_CHEST) {
|
||||
p.openInventory(p.getEnderChest());
|
||||
return true;
|
||||
}
|
||||
|
||||
World world = player.world;
|
||||
Object tile = world.getTileEntity(block.getX(), block.getY(), block.getZ());
|
||||
|
||||
if (tile == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (tile instanceof TileEntityEnderChest) {
|
||||
// Anychest ender chest. See net.minecraft.server.BlockEnderChest
|
||||
InventoryEnderChest enderChest = player.getEnderChest();
|
||||
enderChest.a((TileEntityEnderChest) tile);
|
||||
player.openContainer(enderChest);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(tile instanceof IInventory)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
|
||||
|
||||
if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
|
||||
tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1));
|
||||
} else if (world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
|
||||
tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), (IInventory) tile);
|
||||
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
|
||||
tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ()));
|
||||
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
|
||||
tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), (IInventory) tile);
|
||||
}
|
||||
|
||||
boolean returnValue = false;
|
||||
if (!silentchest) {
|
||||
player.openContainer((IInventory) tile);
|
||||
returnValue = true;
|
||||
} else {
|
||||
try {
|
||||
int windowId = 0;
|
||||
try {
|
||||
Field windowID = player.getClass().getDeclaredField("containerCounter");
|
||||
windowID.setAccessible(true);
|
||||
windowId = windowID.getInt(player);
|
||||
windowId = windowId % 100 + 1;
|
||||
windowID.setInt(player, windowId);
|
||||
} catch (NoSuchFieldException e) {}
|
||||
|
||||
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) tile).getName(), ((IInventory) tile).getSize()));
|
||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) tile));
|
||||
player.activeContainer.windowId = windowId;
|
||||
player.activeContainer.addSlotListener(player);
|
||||
returnValue = true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
||||
}
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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.lishid.openinv.internal.v1_4_6;
|
||||
|
||||
import com.lishid.openinv.internal.IInventoryAccess;
|
||||
import com.lishid.openinv.internal.ISpecialEnderChest;
|
||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||
import com.lishid.openinv.internal.InternalAccessor;
|
||||
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_4_6.IInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_4_6.inventory.CraftInventory;
|
||||
|
||||
public class InventoryAccess implements IInventoryAccess {
|
||||
|
||||
@Override
|
||||
public boolean isSpecialPlayerInventory(Inventory inventory) {
|
||||
if (inventory instanceof CraftInventory) {
|
||||
return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
|
||||
}
|
||||
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialPlayerInventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISpecialPlayerInventory getSpecialPlayerInventory(Inventory inventory) {
|
||||
IInventory inv;
|
||||
if (inventory instanceof CraftInventory) {
|
||||
inv = ((CraftInventory) inventory).getInventory();
|
||||
} else {
|
||||
inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
|
||||
}
|
||||
|
||||
if (inv instanceof SpecialPlayerInventory) {
|
||||
return (SpecialPlayerInventory) inv;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSpecialEnderChest(Inventory inventory) {
|
||||
if (inventory instanceof CraftInventory) {
|
||||
return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
|
||||
}
|
||||
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialEnderChest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISpecialEnderChest getSpecialEnderChest(Inventory inventory) {
|
||||
IInventory inv;
|
||||
if (inventory instanceof CraftInventory) {
|
||||
inv = ((CraftInventory) inventory).getInventory();
|
||||
} else {
|
||||
inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
|
||||
}
|
||||
|
||||
if (inv instanceof SpecialEnderChest) {
|
||||
return (SpecialEnderChest) inv;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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.lishid.openinv.internal.v1_4_6;
|
||||
|
||||
import com.lishid.openinv.internal.IPlayerDataManager;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_4_6.EntityPlayer;
|
||||
import net.minecraft.server.v1_4_6.MinecraftServer;
|
||||
import net.minecraft.server.v1_4_6.PlayerInteractManager;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_4_6.CraftServer;
|
||||
|
||||
public class PlayerDataManager implements IPlayerDataManager {
|
||||
|
||||
@Override
|
||||
public Player loadPlayer(OfflinePlayer offline) {
|
||||
// Ensure the player has data
|
||||
if (offline == null || !offline.hasPlayedBefore()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
|
||||
// Create an entity to load the player data
|
||||
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(),
|
||||
new PlayerInteractManager(server.getWorldServer(0)));
|
||||
|
||||
// Get the bukkit entity
|
||||
Player target = (entity == null) ? null : entity.getBukkitEntity();
|
||||
if (target != null) {
|
||||
// Load data
|
||||
target.loadData();
|
||||
}
|
||||
// Return the entity
|
||||
return target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerDataID(OfflinePlayer player) {
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfflinePlayer getPlayerByID(String identifier) {
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(identifier);
|
||||
// Ensure player is a real player, otherwise return null
|
||||
if (player == null || !player.hasPlayedBefore() && !player.isOnline()) {
|
||||
return null;
|
||||
}
|
||||
return player;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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.lishid.openinv.internal.v1_4_6;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_4_6.ContainerChest;
|
||||
import net.minecraft.server.v1_4_6.EntityHuman;
|
||||
import net.minecraft.server.v1_4_6.IInventory;
|
||||
import net.minecraft.server.v1_4_6.ItemStack;
|
||||
import net.minecraft.server.v1_4_6.PlayerInventory;
|
||||
|
||||
public class SilentContainerChest extends ContainerChest {
|
||||
|
||||
public SilentContainerChest(IInventory i1, IInventory i2) {
|
||||
super(i1, i2);
|
||||
// Send close signal
|
||||
i2.f();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void b(EntityHuman entityHuman) {
|
||||
// Don't send close signal twice, might screw up
|
||||
PlayerInventory playerinventory = entityHuman.inventory;
|
||||
|
||||
if (playerinventory.getCarried() != null) {
|
||||
ItemStack carried = playerinventory.getCarried();
|
||||
playerinventory.setCarried(null);
|
||||
entityHuman.drop(carried);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,128 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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.lishid.openinv.internal.v1_4_6;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialEnderChest;
|
||||
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_4_6.IInventory;
|
||||
import net.minecraft.server.v1_4_6.InventoryEnderChest;
|
||||
import net.minecraft.server.v1_4_6.InventorySubcontainer;
|
||||
import net.minecraft.server.v1_4_6.ItemStack;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_4_6.entity.CraftHumanEntity;
|
||||
import org.bukkit.craftbukkit.v1_4_6.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_4_6.inventory.CraftInventory;
|
||||
|
||||
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
|
||||
|
||||
private final InventoryEnderChest enderChest;
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
private final List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
||||
private boolean playerOnline = false;
|
||||
private CraftPlayer owner;
|
||||
private int maxStack = MAX_STACK;
|
||||
|
||||
public SpecialEnderChest(Player p, Boolean online) {
|
||||
super(((CraftPlayer) p).getHandle().getEnderChest().getName(),
|
||||
((CraftPlayer) p).getHandle().getEnderChest().getSize());
|
||||
CraftPlayer player = (CraftPlayer) p;
|
||||
this.enderChest = player.getHandle().getEnderChest();
|
||||
this.owner = player;
|
||||
this.items = enderChest.getContents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
try {
|
||||
owner = (CraftPlayer) player;
|
||||
InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest();
|
||||
Field field = playerEnderChest.getClass().getField("items");
|
||||
field.setAccessible(true);
|
||||
field.set(playerEnderChest, this.items);
|
||||
} catch (Exception e) {}
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
return this.items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(CraftHumanEntity who) {
|
||||
transaction.add(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(CraftHumanEntity who) {
|
||||
transaction.remove(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HumanEntity> getViewers() {
|
||||
return transaction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryHolder getOwner() {
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxStackSize(int size) {
|
||||
maxStack = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxStackSize() {
|
||||
return maxStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
enderChest.update();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,229 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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.lishid.openinv.internal.v1_4_6;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_4_6.ItemStack;
|
||||
import net.minecraft.server.v1_4_6.PlayerInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_4_6.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_4_6.inventory.CraftInventory;
|
||||
|
||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
|
||||
|
||||
private final ItemStack[] extra = new ItemStack[5];
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
private boolean playerOnline = false;
|
||||
|
||||
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
|
||||
super(((CraftPlayer) bukkitPlayer).getHandle());
|
||||
this.playerOnline = online;
|
||||
this.items = player.inventory.items;
|
||||
this.armor = player.inventory.armor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
this.player = ((CraftPlayer) player).getHandle();
|
||||
this.player.inventory.items = this.items;
|
||||
this.player.inventory.armor = this.armor;
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
ItemStack[] contents = new ItemStack[getSize()];
|
||||
System.arraycopy(items, 0, contents, 0, items.length);
|
||||
System.arraycopy(armor, 0, contents, items.length, armor.length);
|
||||
return contents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return super.getSize() + 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
} else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
} else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
return is[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitStack(int i, int j) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
} else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
} else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack;
|
||||
|
||||
if (is[i].count <= j) {
|
||||
itemstack = is[i];
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
} else {
|
||||
itemstack = is[i].a(j);
|
||||
if (is[i].count == 0) {
|
||||
is[i] = null;
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitWithoutUpdate(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
} else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
} else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack = is[i];
|
||||
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int i, ItemStack itemstack) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
} else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
} else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
// Effects
|
||||
if (is == this.extra) {
|
||||
player.drop(itemstack);
|
||||
itemstack = null;
|
||||
}
|
||||
|
||||
is[i] = itemstack;
|
||||
|
||||
player.defaultContainer.b();
|
||||
}
|
||||
|
||||
private int getReversedItemSlotNum(int i) {
|
||||
if (i >= 27) {
|
||||
return i - 27;
|
||||
}
|
||||
return i + 9;
|
||||
}
|
||||
|
||||
private int getReversedArmorSlotNum(int i) {
|
||||
if (i == 0) {
|
||||
return 3;
|
||||
}
|
||||
if (i == 1) {
|
||||
return 2;
|
||||
}
|
||||
if (i == 2) {
|
||||
return 1;
|
||||
}
|
||||
if (i == 3) {
|
||||
return 0;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (player.getName().length() > 16) {
|
||||
return player.getName().substring(0, 16);
|
||||
}
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,139 +0,0 @@
|
||||
## About
|
||||
OpenInv is a [Bukkit plugin](https://dev.bukkit.org/bukkit-plugins/openinv/) which allows users to open and edit anyone's inventory or ender chest - online or not!
|
||||
|
||||
## Features
|
||||
- **OpenInv**: Open anyone's inventory, even if they're offline.
|
||||
- Read-only mode! No edits allowed! Don't grant the permission `OpenInv.editinv`
|
||||
- Cross-world support! Don't grant `OpenInv.crossworld`
|
||||
- No self-opening! Don't grant `OpenInv.openself`
|
||||
- Drop items as the player! Place items in the unused slots to the right of the armor to drop them
|
||||
- **OpenEnder**: Open anyone's inventory, even if they're offline.
|
||||
- Read-only mode! No edits allowed! Don't grant `OpenInv.editender`
|
||||
- Cross-world support! Don't grant `OpenInv.crossworld`
|
||||
- No self-opening! Don't grant `OpenInv.openself`
|
||||
- **SilentChest**: Open containers without displaying an animation or making sound.
|
||||
- **AnyChest**: Open containers, even if blocked by ocelots or blocks.
|
||||
|
||||
## Commands
|
||||
<table width=100%>
|
||||
<tr>
|
||||
<th width=175px>Command</th>
|
||||
<th>Aliases</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>/openinv [player]</td>
|
||||
<td>oi, inv, open</td>
|
||||
<td>Open a player's inventory. If unspecified, will select last player opened or own if none opened previously.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>/openender [player]</td>
|
||||
<td>oe</td>
|
||||
<td>Open a player's ender chest. If unspecified, will select last player opened or own if none opened previously.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>/searchinv <item> [minAmount]</td>
|
||||
<td>si</td>
|
||||
<td>Lists all online players that have a certain item in their inventory.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>/searchender <item> [minAmount]</td>
|
||||
<td>se</td>
|
||||
<td>Lists all online players that have a certain item in their ender chest.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>/anychest [check]</td>
|
||||
<td>ac</td>
|
||||
<td>Check or toggle the AnyChest function, allowing opening blocked containers.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>/silentchest [check]</td>
|
||||
<td>sc</td>
|
||||
<td>Check or toggle the SilentChest function, allowing opening containers silently.</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
## Permissions
|
||||
<table>
|
||||
<tr>
|
||||
<th>Node</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OpenInv.*</td>
|
||||
<td>Gives permission to use all of OpenInv.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OpenInv.openinv</td>
|
||||
<td>Required to use /openinv.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OpenInv.openself</td>
|
||||
<td>Required to open own inventory.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OpenInv.editinv</td>
|
||||
<td>Required to make changes to open inventories.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OpenInv.openender</td>
|
||||
<td>Required to use /openender.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OpenInv.editinv</td>
|
||||
<td>Required to make changes to open ender chests.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OpenInv.openenderall</td>
|
||||
<td>Allows users to open others' ender chests. Without it, users can only open their own.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OpenInv.exempt</td>
|
||||
<td>Prevents the player's inventory being opened by others.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OpenInv.override</td>
|
||||
<td>Allows bypassing of the exempt permission.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OpenInv.crossworld</td>
|
||||
<td>Allows cross-world usage of /openinv and /openender.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OpenInv.search</td>
|
||||
<td>Required to use /searchinv and /searchender.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OpenInv.anychest</td>
|
||||
<td>Required to use /anychest.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OpenInv.silent</td>
|
||||
<td>Required to use /silentchest.</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
## For Developers
|
||||
To compile, the relevant Craftbukkit/Spigot jars must be installed in your local repository using the install plugin.
|
||||
Ex: `mvn install:install-file -Dpackaging=jar -Dfile=spigot-1.11-R0.1-SNAPSHOT.jar -DgroupId=org.spigotmc -DartifactId=spigot -Dversion=1.11-R0.1-SNAPSHOT`
|
||||
|
||||
Compiling OpenInv for a specific version is very easy - just compile the correct module.
|
||||
|
||||
Compiling for a set of versions is slightly more complex. You'll need to use a profile for the versions you want to compile. Provided profiles are latest, modern (versions 1.8+), and all. For more information, check out the [official guide](http://maven.apache.org/guides/introduction/introduction-to-profiles.html).
|
||||
|
||||
## License
|
||||
```
|
||||
Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
|
||||
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, version 3.
|
||||
|
||||
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/>.
|
||||
```
|
||||
@@ -0,0 +1,65 @@
|
||||
## About
|
||||
|
||||
OpenInv is a Bukkit plugin which allows users to open and edit anyone's
|
||||
inventory or ender chest - online or not!
|
||||
|
||||
Downloads are available on [GitHub](https://github.com/Jikoo/OpenInv/releases), [DBO](https://dev.bukkit.org/projects/openinv)/[CurseForge](https://www.curseforge.com/minecraft/bukkit-plugins/openinv), [Modrinth](https://modrinth.com/plugin/openinv), and [Hangar](https://hangar.papermc.io/jikoo/OpenInv).
|
||||
|
||||
## Features
|
||||
|
||||
- **OpenInv**: Open anyone's inventory, even if they're offline.
|
||||
- Read-only mode! Don't grant edit permission.
|
||||
- Cross-world support! Allow access only from the same world.
|
||||
- No duplicate slots! Only armor is accessible when opening self (if allowed at all)!
|
||||
- Drop items as the player! Place items in the dropper slot in the bottom right. Can be disabled via permission!
|
||||
- Allow any item in armor slots! Configurable via permission.
|
||||
- **OpenEnder**: Open anyone's ender chest, even if they're offline.
|
||||
- Allow access only to own ender chest! Don't grant permission to open others.
|
||||
- Read-only mode! Don't grant edit permission.
|
||||
- Cross-world support! Allow access only from the same world.
|
||||
- **SilentContainer**: Open containers without displaying an animation or making sound.
|
||||
- **AnyContainer**: Open containers, even if blocked by ocelots or blocks.
|
||||
- **Resource Pack Support**: Personalize view using resource pack tricks like custom fonts and characters. See [the wiki](https://github.com/Jikoo/OpenInv/wiki/Customizing-Inventories) for details.
|
||||
|
||||
## Commands
|
||||
|
||||
See [the wiki](https://github.com/Jikoo/OpenInv/wiki/Commands).
|
||||
|
||||
## Permissions
|
||||
|
||||
See [the wiki](https://github.com/Jikoo/OpenInv/wiki/Permissions)
|
||||
|
||||
## For Developers
|
||||
|
||||
### As a Dependency
|
||||
|
||||
The OpenInv API is available via [JitPack](https://jitpack.io/).
|
||||
|
||||
```xml
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
```
|
||||
|
||||
```xml
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.Jikoo</groupId>
|
||||
<artifactId>OpenInv</artifactId>
|
||||
<version>${openinv.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
```
|
||||
|
||||
Note that since JitPack only builds the API now, the "full" OpenInv jar on JitPack is actually the openinvapi artifact.
|
||||
This is a change from previous dependency declaration that I hope to revert.
|
||||
|
||||
### Compilation
|
||||
|
||||
Execute the gradle wrapper:
|
||||
`./gradlew build`
|
||||
|
||||
If you encounter issues with building the Spigot module, try running BuildTools manually.
|
||||
@@ -0,0 +1,31 @@
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://hub.spigotmc.org/nexus/content/groups/public/")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly(libs.spigotapi)
|
||||
implementation(project(":openinvapi"))
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain.languageVersion = JavaLanguageVersion.of(21)
|
||||
}
|
||||
|
||||
tasks.withType<JavaCompile>().configureEach {
|
||||
options.release = 21
|
||||
}
|
||||
|
||||
tasks.processResources {
|
||||
expand("version" to version)
|
||||
}
|
||||
|
||||
tasks.register<Copy>("distributeAddons") {
|
||||
into(rootProject.layout.projectDirectory.dir("dist"))
|
||||
from(tasks.jar)
|
||||
rename("openinvtogglepersist.*\\.jar", "OITogglePersist.jar")
|
||||
}
|
||||
|
||||
tasks.assemble {
|
||||
dependsOn(tasks.named("distributeAddons"))
|
||||
}
|
||||
+152
@@ -0,0 +1,152 @@
|
||||
package com.github.jikoo.openinv.togglepersist;
|
||||
|
||||
import com.google.errorprone.annotations.Keep;
|
||||
import com.lishid.openinv.event.PlayerToggledEvent;
|
||||
import com.lishid.openinv.util.setting.PlayerToggle;
|
||||
import com.lishid.openinv.util.setting.PlayerToggles;
|
||||
import org.bukkit.configuration.Configuration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class TogglePersist extends JavaPlugin implements Listener {
|
||||
|
||||
private final Map<UUID, Set<String>> enabledToggles = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
getServer().getPluginManager().registerEvents(this, this);
|
||||
|
||||
File file = new File(getDataFolder(), "toggles.yml");
|
||||
|
||||
// If there's no save file, there's nothing to load.
|
||||
if (!file.exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Configuration loaded = YamlConfiguration.loadConfiguration(file);
|
||||
|
||||
// For each toggle, enable loaded players.
|
||||
for (String toggleName : loaded.getKeys(false)) {
|
||||
PlayerToggle toggle = PlayerToggles.get(toggleName);
|
||||
// Ensure toggle exists.
|
||||
if (toggle == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (String idString : loaded.getStringList(toggleName)) {
|
||||
// Ensure valid UUID.
|
||||
UUID uuid;
|
||||
try {
|
||||
uuid = UUID.fromString(idString);
|
||||
} catch (IllegalArgumentException e) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Track that toggle is enabled.
|
||||
set(uuid, toggleName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void set(UUID playerId, String toggleName) {
|
||||
enabledToggles.compute(
|
||||
playerId,
|
||||
(uuid, toggles) -> {
|
||||
if (toggles == null) {
|
||||
toggles = new HashSet<>();
|
||||
}
|
||||
toggles.add(toggleName);
|
||||
return toggles;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
Map<String, List<String>> converted = getSaveData();
|
||||
|
||||
YamlConfiguration data = new YamlConfiguration();
|
||||
for (Map.Entry<String, List<String>> playerToggle : converted.entrySet()) {
|
||||
data.set(playerToggle.getKey(), playerToggle.getValue());
|
||||
}
|
||||
|
||||
File file = new File(getDataFolder(), "toggles.yml");
|
||||
try {
|
||||
data.save(file);
|
||||
} catch (IOException e) {
|
||||
getLogger().log(Level.SEVERE, "Unable to save player toggle states", e);
|
||||
}
|
||||
}
|
||||
|
||||
private @NotNull Map<String, List<String>> getSaveData() {
|
||||
Map<String, List<String>> converted = new HashMap<>();
|
||||
|
||||
for (Map.Entry<UUID, Set<String>> playerToggles : enabledToggles.entrySet()) {
|
||||
String idString = playerToggles.getKey().toString();
|
||||
for (String toggleName : playerToggles.getValue()) {
|
||||
// Add player ID to listing for each enabled toggle.
|
||||
converted.compute(
|
||||
toggleName,
|
||||
(name, ids) -> {
|
||||
if (ids == null) {
|
||||
ids = new ArrayList<>();
|
||||
}
|
||||
ids.add(idString);
|
||||
return ids;
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
return converted;
|
||||
}
|
||||
|
||||
@Keep
|
||||
@EventHandler
|
||||
private void onPlayerJoin(@NotNull PlayerJoinEvent event) {
|
||||
UUID playerId = event.getPlayer().getUniqueId();
|
||||
Set<String> toggleNames = enabledToggles.get(playerId);
|
||||
|
||||
if (toggleNames == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (String toggleName : toggleNames) {
|
||||
PlayerToggle toggle = PlayerToggles.get(toggleName);
|
||||
if (toggle != null) {
|
||||
toggle.set(playerId, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Keep
|
||||
@EventHandler
|
||||
private void onToggleSet(@NotNull PlayerToggledEvent event) {
|
||||
if (event.isEnabled()) {
|
||||
set(event.getPlayerId(), event.getToggle().getName());
|
||||
} else {
|
||||
enabledToggles.computeIfPresent(
|
||||
event.getPlayerId(),
|
||||
(uuid, toggles) -> {
|
||||
toggles.remove(event.getToggle().getName());
|
||||
return toggles.isEmpty() ? null : toggles;
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
name: OITogglePersist
|
||||
main: com.github.jikoo.openinv.togglepersist.TogglePersist
|
||||
version: ${version}
|
||||
author: Jikoo
|
||||
description: An OpenInv addon allowing /anycontainer and /silentcontainer to persist across sessions.
|
||||
api-version: "1.20"
|
||||
depend: [ OpenInv ]
|
||||
@@ -0,0 +1,30 @@
|
||||
plugins {
|
||||
`maven-publish`
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://hub.spigotmc.org/nexus/content/groups/public/")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly(libs.spigotapi)
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain.languageVersion = JavaLanguageVersion.of(21)
|
||||
}
|
||||
|
||||
tasks.withType<JavaCompile>().configureEach {
|
||||
options.release = 21
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
create<MavenPublication>("jitpack") {
|
||||
groupId = "com.github.Jikoo.OpenInv"
|
||||
artifactId = "openinvapi"
|
||||
from(components["java"])
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2023 lishid. All rights reserved.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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.lishid.openinv;
|
||||
|
||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
||||
import com.lishid.openinv.internal.ISpecialEnderChest;
|
||||
import com.lishid.openinv.internal.ISpecialInventory;
|
||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Interface defining behavior for the OpenInv plugin.
|
||||
*/
|
||||
@NullMarked
|
||||
public interface IOpenInv {
|
||||
|
||||
/**
|
||||
* Check if the server version is supported by OpenInv.
|
||||
*
|
||||
* @return true if the server version is supported
|
||||
*/
|
||||
boolean isSupportedVersion();
|
||||
|
||||
/**
|
||||
* Check the configuration value for whether OpenInv saves player data when unloading players. This is exclusively
|
||||
* for users who do not allow editing of inventories, only viewing, and wish to prevent any possibility of bugs such
|
||||
* as lishid#40. If true, OpenInv will not ever save any edits made to players.
|
||||
*
|
||||
* @return false unless configured otherwise
|
||||
*/
|
||||
boolean disableSaving();
|
||||
|
||||
/**
|
||||
* Check the configuration value for whether OpenInv allows offline access. If true, OpenInv will not load or allow
|
||||
* modification of players while they are not online. This does not prevent other plugins from using existing loaded
|
||||
* players who have gone offline.
|
||||
*
|
||||
* @return false unless configured otherwise
|
||||
* @since 4.2.0
|
||||
*/
|
||||
boolean disableOfflineAccess();
|
||||
|
||||
/**
|
||||
* Check the configuration value for whether OpenInv uses history for opening commands. If false, OpenInv will use
|
||||
* the previous parameterized search when no parameters are provided.
|
||||
*
|
||||
* @return false unless configured otherwise
|
||||
* @since 4.3.0
|
||||
*/
|
||||
boolean noArgsOpensSelf();
|
||||
|
||||
/**
|
||||
* Get the active {@link IAnySilentContainer} implementation.
|
||||
*
|
||||
* @return the active implementation for the server version
|
||||
* @throws IllegalStateException if the server version is unsupported
|
||||
*/
|
||||
IAnySilentContainer getAnySilentContainer();
|
||||
|
||||
/**
|
||||
* Get whether a user has AnyContainer mode enabled.
|
||||
*
|
||||
* @param offline the user to obtain the state of
|
||||
* @return true if AnyContainer mode is enabled
|
||||
*/
|
||||
boolean getAnyContainerStatus(OfflinePlayer offline);
|
||||
|
||||
/**
|
||||
* Set whether a user has AnyContainer mode enabled.
|
||||
*
|
||||
* @param offline the user to set the state of
|
||||
* @param status the state of the mode
|
||||
*/
|
||||
void setAnyContainerStatus(OfflinePlayer offline, boolean status);
|
||||
|
||||
/**
|
||||
* Get whether a user has SilentContainer mode enabled.
|
||||
*
|
||||
* @param offline the user to obtain the state of
|
||||
* @return true if SilentContainer mode is enabled
|
||||
*/
|
||||
boolean getSilentContainerStatus(OfflinePlayer offline);
|
||||
|
||||
/**
|
||||
* Set whether a user has SilentContainer mode enabled.
|
||||
*
|
||||
* @param offline the user to set the state of
|
||||
* @param status the state of the mode
|
||||
*/
|
||||
void setSilentContainerStatus(OfflinePlayer offline, boolean status);
|
||||
|
||||
/**
|
||||
* Get an {@link ISpecialEnderChest} for a user.
|
||||
*
|
||||
* @param player the {@link Player} owning the inventory
|
||||
* @param online whether the owner is currently online
|
||||
* @return the created inventory
|
||||
* @throws IllegalStateException if the server version is unsupported
|
||||
* @throws InstantiationException if there was an issue creating the inventory
|
||||
*/
|
||||
ISpecialEnderChest getSpecialEnderChest(
|
||||
Player player,
|
||||
boolean online
|
||||
) throws InstantiationException;
|
||||
|
||||
/**
|
||||
* Get an {@link ISpecialPlayerInventory} for a user.
|
||||
*
|
||||
* @param player the {@link Player} owning the inventory
|
||||
* @param online whether the owner is currently online
|
||||
* @return the created inventory
|
||||
* @throws IllegalStateException if the server version is unsupported
|
||||
* @throws InstantiationException if there was an issue creating the inventory
|
||||
*/
|
||||
ISpecialPlayerInventory getSpecialInventory(
|
||||
Player player,
|
||||
boolean online
|
||||
) throws InstantiationException;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #openInventory(Player, ISpecialInventory, boolean)}
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "5.2.0")
|
||||
@Nullable InventoryView openInventory(Player player, ISpecialInventory inventory);
|
||||
|
||||
/**
|
||||
* Open an {@link ISpecialInventory} for a {@link Player}.
|
||||
*
|
||||
* @param player the viewer
|
||||
* @param inventory the inventory to open
|
||||
* @param viewOnly whether the inventory should be view-only
|
||||
* @return the resulting {@link InventoryView}
|
||||
*/
|
||||
@Nullable InventoryView openInventory(Player player, ISpecialInventory inventory, boolean viewOnly);
|
||||
|
||||
/**
|
||||
* Check if a {@link Player} is currently loaded by OpenInv.
|
||||
*
|
||||
* @param playerUuid the {@link UUID} of the {@code Player}
|
||||
* @return whether the {@code Player} is loaded
|
||||
* @since 4.2.0
|
||||
*/
|
||||
boolean isPlayerLoaded(UUID playerUuid);
|
||||
|
||||
/**
|
||||
* Load a {@link Player} from an {@link OfflinePlayer}. If the user has not played before or the default world for
|
||||
* the server is not loaded, this will return {@code null}.
|
||||
*
|
||||
* @param offline the {@code OfflinePlayer} to load a {@code Player} for
|
||||
* @return the loaded {@code Player}
|
||||
* @throws IllegalStateException if the server version is unsupported
|
||||
*/
|
||||
@Nullable Player loadPlayer(final OfflinePlayer offline);
|
||||
|
||||
/**
|
||||
* Match an existing {@link OfflinePlayer}. If the name is a {@link UUID#toString() UUID string}, this will only
|
||||
* return the user if they have actually played on the server before, unlike {@link Bukkit#getOfflinePlayer(UUID)}.
|
||||
*
|
||||
* <p>This method is potentially very heavily blocking. It should not ever be called on the
|
||||
* main thread, and if it is, a stack trace will be displayed alerting server owners to the
|
||||
* call.
|
||||
*
|
||||
* @param name the string to match
|
||||
* @return the user with the closest matching name
|
||||
*/
|
||||
@Nullable OfflinePlayer matchPlayer(String name);
|
||||
|
||||
/**
|
||||
* Forcibly close inventories of and unload any cached data for a user.
|
||||
*
|
||||
* @param offline the {@link OfflinePlayer} to unload
|
||||
*/
|
||||
void unload(OfflinePlayer offline);
|
||||
|
||||
Logger getLogger();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.lishid.openinv.event;
|
||||
|
||||
import com.google.errorprone.annotations.RestrictedApi;
|
||||
import com.lishid.openinv.internal.ISpecialInventory;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
/**
|
||||
* Event fired before OpenInv saves a player's data when closing an {@link ISpecialInventory}.
|
||||
*/
|
||||
@NullMarked
|
||||
public class OpenPlayerSaveEvent extends PlayerSaveEvent {
|
||||
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
|
||||
private final ISpecialInventory inventory;
|
||||
|
||||
/**
|
||||
* Construct a new {@code OpenPlayerSaveEvent}.
|
||||
*
|
||||
* <p>The constructor is not considered part of the API, and may be subject to change.</p>
|
||||
*
|
||||
* @param player the player to be saved
|
||||
* @param inventory the {@link ISpecialInventory} being closed
|
||||
*/
|
||||
@RestrictedApi(
|
||||
explanation = "Constructor is not considered part of the API and may be subject to change.",
|
||||
link = "",
|
||||
allowedOnPath = ".*/com/lishid/openinv/event/OpenEvents.java"
|
||||
)
|
||||
@ApiStatus.Internal
|
||||
OpenPlayerSaveEvent(Player player, ISpecialInventory inventory) {
|
||||
super(player);
|
||||
this.inventory = inventory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link ISpecialInventory} that triggered the save by being closed.
|
||||
*
|
||||
* @return the special inventory
|
||||
*/
|
||||
public ISpecialInventory getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.lishid.openinv.event;
|
||||
|
||||
|
||||
import com.google.errorprone.annotations.RestrictedApi;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
/**
|
||||
* Event fired before a {@link Player} loaded via OpenInv is saved.
|
||||
*/
|
||||
@NullMarked
|
||||
public class PlayerSaveEvent extends PlayerEvent implements Cancellable {
|
||||
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
|
||||
private boolean cancelled = false;
|
||||
|
||||
/**
|
||||
* Construct a new {@code PlayerSaveEvent}.
|
||||
*
|
||||
* <p>The constructor is not considered part of the API, and may be subject to change.</p>
|
||||
*
|
||||
* @param player the player to be saved
|
||||
*/
|
||||
@RestrictedApi(
|
||||
explanation = "Constructor is not considered part of the API and may be subject to change.",
|
||||
link = "",
|
||||
allowedOnPath = ".*/com/lishid/openinv/event/(OpenPlayerSaveEvent|OpenEvents).java"
|
||||
)
|
||||
@ApiStatus.Internal
|
||||
PlayerSaveEvent(Player player) {
|
||||
super(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether the event is cancelled.
|
||||
*
|
||||
* @return true if the event is cancelled
|
||||
*/
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether the event is cancelled.
|
||||
*
|
||||
* @param cancel whether the event is cancelled
|
||||
*/
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancelled = cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package com.lishid.openinv.event;
|
||||
|
||||
import com.google.errorprone.annotations.RestrictedApi;
|
||||
import com.lishid.openinv.util.setting.PlayerToggle;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Event fired after OpenInv modifies a toggleable setting for a player.
|
||||
*/
|
||||
@NullMarked
|
||||
public class PlayerToggledEvent extends Event {
|
||||
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
|
||||
private final PlayerToggle toggle;
|
||||
private final UUID uuid;
|
||||
private final boolean enabled;
|
||||
|
||||
@RestrictedApi(
|
||||
explanation = "Constructor is not considered part of the API and may be subject to change.",
|
||||
link = "",
|
||||
allowedOnPath = ".*/com/lishid/openinv/event/OpenEvents.java"
|
||||
)
|
||||
@ApiStatus.Internal
|
||||
PlayerToggledEvent(PlayerToggle toggle, UUID uuid, boolean enabled) {
|
||||
this.toggle = toggle;
|
||||
this.uuid = uuid;
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link PlayerToggle} affected.
|
||||
*
|
||||
* @return the toggle
|
||||
*/
|
||||
public PlayerToggle getToggle() {
|
||||
return toggle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link UUID} of the player whose setting was changed.
|
||||
*
|
||||
* @return the player ID
|
||||
*/
|
||||
public UUID getPlayerId() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether the toggle is enabled.
|
||||
*
|
||||
* @return true if the toggle is enabled
|
||||
*/
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2023 lishid. All rights reserved.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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.lishid.openinv.internal;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.EnderChest;
|
||||
import org.bukkit.block.data.Directional;
|
||||
import org.bukkit.entity.Cat;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.util.BoundingBox;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
@NullMarked
|
||||
public interface IAnySilentContainer {
|
||||
|
||||
/**
|
||||
* Forcibly open the container at the given coordinates for the Player. This will open blocked containers! Be sure
|
||||
* to check {@link #isAnyContainerNeeded(Block)} first if that is not desirable.
|
||||
*
|
||||
* @param player the {@link Player} opening the container
|
||||
* @param silent whether the container's noise is to be silenced
|
||||
* @param block the {@link Block} of the container
|
||||
* @return true if the container can be opened
|
||||
*/
|
||||
boolean activateContainer(Player player, boolean silent, Block block);
|
||||
|
||||
/**
|
||||
* Perform operations required to close the current container silently.
|
||||
*
|
||||
* @param player the {@link Player} closing a container
|
||||
*/
|
||||
void deactivateContainer(Player player);
|
||||
|
||||
/**
|
||||
* Check if the container at the given coordinates is blocked.
|
||||
*
|
||||
* @param block the {@link Block} of the container
|
||||
* @return true if the container is blocked
|
||||
*/
|
||||
boolean isAnyContainerNeeded(Block block);
|
||||
|
||||
/**
|
||||
* Check if a shulker box block cannot be opened under ordinary circumstances.
|
||||
*
|
||||
* @param shulkerBox the shulker box block
|
||||
* @return whether the container is blocked
|
||||
*/
|
||||
default boolean isShulkerBlocked(Block shulkerBox) {
|
||||
Directional directional = (Directional) shulkerBox.getBlockData();
|
||||
BlockFace facing = directional.getFacing();
|
||||
// Construct a new 1-block bounding box at the origin.
|
||||
BoundingBox box = new BoundingBox(0, 0, 0, 1, 1, 1);
|
||||
// Expand the box in the direction the shulker will open.
|
||||
box.expand(facing, 0.5);
|
||||
// Move the box away from the origin by a block so only the expansion intersects with a box around the origin.
|
||||
box.shift(facing.getOppositeFace().getDirection());
|
||||
// Check if the relative block's collision shape (which will be at the origin) intersects with the expanded box.
|
||||
return shulkerBox.getRelative(facing).getCollisionShape().overlaps(box);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a chest cannot be opened under ordinary circumstances.
|
||||
*
|
||||
* @param chest the chest block
|
||||
* @return whether the container is blocked
|
||||
*/
|
||||
default boolean isChestBlocked(Block chest) {
|
||||
org.bukkit.block.Block relative = chest.getRelative(0, 1, 0);
|
||||
return relative.getType().isOccluding()
|
||||
|| !chest.getWorld().getNearbyEntities(BoundingBox.of(relative), Cat.class::isInstance).isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given {@link Block} is a container which can be unblocked or silenced.
|
||||
*
|
||||
* @param block the potential container
|
||||
* @return true if the type is a supported container
|
||||
*/
|
||||
boolean isAnySilentContainer(Block block);
|
||||
|
||||
/**
|
||||
* Check if the given {@link BlockState} is a container which can be unblocked or silenced.
|
||||
*
|
||||
* @param blockState the potential container
|
||||
* @return true if the type is a supported container
|
||||
*/
|
||||
default boolean isAnySilentContainer(BlockState blockState) {
|
||||
return (blockState instanceof InventoryHolder holder && isAnySilentContainer(holder))
|
||||
|| blockState instanceof EnderChest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given {@link InventoryHolder} is a container which can be unblocked or silenced.
|
||||
*
|
||||
* @param holder the potential container
|
||||
* @return true if the type is a supported container
|
||||
*/
|
||||
default boolean isAnySilentContainer(@Nullable InventoryHolder holder) {
|
||||
return holder instanceof org.bukkit.block.EnderChest
|
||||
|| holder instanceof org.bukkit.block.Chest
|
||||
|| holder instanceof org.bukkit.block.DoubleChest
|
||||
|| holder instanceof org.bukkit.block.ShulkerBox
|
||||
|| holder instanceof org.bukkit.block.Barrel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given {@link Inventory} belongs to a container which can be unblocked or silenced.
|
||||
*
|
||||
* @param inventory the potential container inventory
|
||||
* @return true if the type is a supported container
|
||||
*/
|
||||
boolean isAnySilentContainer(Inventory inventory);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2022 lishid. All rights reserved.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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.lishid.openinv.internal;
|
||||
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
/**
|
||||
* An {@link ISpecialInventory} representing an ender chest.
|
||||
*/
|
||||
@NullMarked
|
||||
public interface ISpecialEnderChest extends ISpecialInventory {
|
||||
|
||||
@Override
|
||||
default InventoryType getBukkitType() {
|
||||
return InventoryType.ENDER_CHEST;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2022 lishid. All rights reserved.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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.lishid.openinv.internal;
|
||||
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
/**
|
||||
* Interface defining behavior for special inventories backed by other inventories' content listings.
|
||||
*/
|
||||
@NullMarked
|
||||
public interface ISpecialInventory {
|
||||
|
||||
/**
|
||||
* Get the {@link Inventory} associated with this {@code ISpecialInventory}.
|
||||
*
|
||||
* @return the Bukkit inventory
|
||||
*/
|
||||
Inventory getBukkitInventory();
|
||||
|
||||
/**
|
||||
* Get the {@link InventoryType} corresponding to this {@code ISpecialInventory}.
|
||||
*
|
||||
* @return the type of Bukkit inventory
|
||||
*/
|
||||
InventoryType getBukkitType();
|
||||
|
||||
/**
|
||||
* Set the owning {@link Player} instance to a newly-joined user.
|
||||
*
|
||||
* @param player the user coming online
|
||||
*/
|
||||
void setPlayerOnline(Player player);
|
||||
|
||||
/**
|
||||
* Mark the owner of the inventory offline.
|
||||
*
|
||||
* @deprecated No longer used by implementations.
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "5.1.11")
|
||||
default void setPlayerOffline() {}
|
||||
|
||||
/**
|
||||
* Get whether the inventory is being viewed by any users.
|
||||
*
|
||||
* @return true if the inventory is being viewed
|
||||
*/
|
||||
default boolean isInUse() {
|
||||
return !getBukkitInventory().getViewers().isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link Player} who owns the inventory.
|
||||
*
|
||||
* @return the {@link HumanEntity} who owns the inventory
|
||||
*/
|
||||
HumanEntity getPlayer();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2022 lishid. All rights reserved.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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.lishid.openinv.internal;
|
||||
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
/**
|
||||
* An {@link ISpecialInventory} representing a player inventory.
|
||||
*/
|
||||
@NullMarked
|
||||
public interface ISpecialPlayerInventory extends ISpecialInventory {
|
||||
|
||||
@Override
|
||||
default InventoryType getBukkitType() {
|
||||
return InventoryType.PLAYER;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2022 lishid. All rights reserved.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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.lishid.openinv.util;
|
||||
|
||||
import com.google.errorprone.annotations.RestrictedApi;
|
||||
import com.lishid.openinv.internal.ISpecialEnderChest;
|
||||
import com.lishid.openinv.internal.ISpecialInventory;
|
||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
@NullMarked
|
||||
public final class InventoryAccess {
|
||||
|
||||
private static @Nullable BiFunction<Inventory, Class<? extends ISpecialInventory>, @Nullable ISpecialInventory> provider;
|
||||
|
||||
public static boolean isUsable() {
|
||||
return provider != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an {@link Inventory} is an {@link ISpecialPlayerInventory} implementation.
|
||||
*
|
||||
* @param inventory the Bukkit inventory
|
||||
* @return true if backed by the correct implementation
|
||||
*/
|
||||
public static boolean isPlayerInventory(Inventory inventory) {
|
||||
return getPlayerInventory(inventory) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link ISpecialPlayerInventory} backing an {@link Inventory}. Returns {@code null} if the inventory is
|
||||
* not backed by the correct class.
|
||||
*
|
||||
* @param inventory the Bukkit inventory
|
||||
* @return the backing implementation if available
|
||||
*/
|
||||
public static @Nullable ISpecialPlayerInventory getPlayerInventory(Inventory inventory) {
|
||||
return provider == null ? null : (ISpecialPlayerInventory) provider.apply(inventory, ISpecialPlayerInventory.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an {@link Inventory} is an {@link ISpecialEnderChest} implementation.
|
||||
*
|
||||
* @param inventory the Bukkit inventory
|
||||
* @return true if backed by the correct implementation
|
||||
*/
|
||||
public static boolean isEnderChest(Inventory inventory) {
|
||||
return getEnderChest(inventory) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link ISpecialEnderChest} backing an {@link Inventory}. Returns {@code null} if the inventory is
|
||||
* not backed by the correct class.
|
||||
*
|
||||
* @param inventory the Bukkit inventory
|
||||
* @return the backing implementation if available
|
||||
*/
|
||||
public static @Nullable ISpecialEnderChest getEnderChest(Inventory inventory) {
|
||||
return provider == null ? null : (ISpecialEnderChest) provider.apply(inventory, ISpecialEnderChest.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a {@link ISpecialInventory} backing an {@link Inventory}. Returns {@code null} if the inventory is not backed
|
||||
* by the correct class.
|
||||
*
|
||||
* @param inventory the Bukkit inventory
|
||||
* @return the backing implementation if available
|
||||
*/
|
||||
public static @Nullable ISpecialInventory getInventory(Inventory inventory) {
|
||||
return provider == null ? null : provider.apply(inventory, ISpecialInventory.class);
|
||||
}
|
||||
|
||||
@RestrictedApi(
|
||||
explanation = "Not part of the API.",
|
||||
link = "",
|
||||
allowedOnPath = ".*/com/lishid/openinv/util/InternalAccessor.java"
|
||||
)
|
||||
@ApiStatus.Internal
|
||||
static void setProvider(
|
||||
@Nullable BiFunction<Inventory, Class<? extends ISpecialInventory>, @Nullable ISpecialInventory> provider
|
||||
) {
|
||||
InventoryAccess.provider = provider;
|
||||
}
|
||||
|
||||
private InventoryAccess() {
|
||||
throw new IllegalStateException("Cannot create instance of utility class.");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2022 lishid. All rights reserved.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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.lishid.openinv.util;
|
||||
|
||||
import org.bukkit.permissions.Permissible;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
/**
|
||||
* An enum containing all permissions directly checked by OpenInv.
|
||||
*
|
||||
* <p>Note that this is not an exhaustive list! This does not contain
|
||||
* all permissions managed by Bukkit, largely parent nodes.</p>
|
||||
*/
|
||||
@NullMarked
|
||||
public enum Permissions {
|
||||
|
||||
/// Permission to open one's own inventory.
|
||||
INVENTORY_OPEN_SELF("inventory.open.self"),
|
||||
/// Permission to open someone else's inventory.
|
||||
INVENTORY_OPEN_OTHER("inventory.open.other"),
|
||||
/**
|
||||
* Permission to edit one's own inventory.
|
||||
*
|
||||
* <p>Note that this does not guarantee that the user has access to open the inventory!
|
||||
* Be sure to check {@link #INVENTORY_OPEN_SELF} first.</p>
|
||||
*/
|
||||
INVENTORY_EDIT_SELF("inventory.edit.self"),
|
||||
/**
|
||||
* Permission to edit someone else's inventory.
|
||||
*
|
||||
* <p>Note that this does not guarantee that the user has access to open the inventory!
|
||||
* Be sure to check {@link #INVENTORY_OPEN_OTHER} first.</p>
|
||||
*/
|
||||
INVENTORY_EDIT_OTHER("inventory.edit.other"),
|
||||
/// Permission to insert any item into the head slot.
|
||||
INVENTORY_SLOT_HEAD_ANY("inventory.slot.head.any"),
|
||||
/// Permission to insert any item into the chest slot.
|
||||
INVENTORY_SLOT_CHEST_ANY("inventory.slot.chest.any"),
|
||||
/// Permission to insert any item into the legs slot.
|
||||
INVENTORY_SLOT_LEGS_ANY("inventory.slot.legs.any"),
|
||||
/// Permission to insert any item into the feet slot.
|
||||
INVENTORY_SLOT_FEET_ANY("inventory.slot.feet.any"),
|
||||
/// Permission to drop items as the player via the drop slot.
|
||||
INVENTORY_SLOT_DROP("inventory.slot.drop"),
|
||||
|
||||
/// Permission to open one's own ender chest.
|
||||
ENDERCHEST_OPEN_SELF("enderchest.open.self"),
|
||||
/// Permission to open someone else's ender chest.
|
||||
ENDERCHEST_OPEN_OTHER("enderchest.open.other"),
|
||||
/**
|
||||
* Permission to edit one's own ender chest.
|
||||
*
|
||||
* <p>Note that this does not guarantee that the user has access to open the inventory!
|
||||
* Be sure to check {@link #ENDERCHEST_OPEN_SELF} first.</p>
|
||||
*/
|
||||
ENDERCHEST_EDIT_SELF("enderchest.edit.self"),
|
||||
/**
|
||||
* Permission to edit someone else's ender chest.
|
||||
*
|
||||
* <p>Note that this does not guarantee that the user has access to open the inventory!
|
||||
* Be sure to check {@link #ENDERCHEST_OPEN_OTHER} first.</p>
|
||||
*/
|
||||
ENDERCHEST_EDIT_OTHER("enderchest.edit.other"),
|
||||
|
||||
/// Permission to clear one's own inventory.
|
||||
CLEAR_SELF("clear.self"),
|
||||
/// Permission to clear someone else's inventory.
|
||||
CLEAR_OTHER("clear.other"),
|
||||
|
||||
/// Permission to view inventories and ender chests from other worlds.
|
||||
ACCESS_CROSSWORLD("access.crossworld"),
|
||||
/// Permission to access offline players' inventories and ender chests.
|
||||
ACCESS_OFFLINE("access.offline"),
|
||||
/// Permission to access online players' inventories and ender chests.
|
||||
ACCESS_ONLINE("access.online"),
|
||||
/// Permission granting the ability to edit players with the same access level.
|
||||
ACCESS_EQUAL_EDIT("access.equal.edit"),
|
||||
/// Permission to view, but not edit, players with the same access level.
|
||||
ACCESS_EQUAL_VIEW("access.equal.view"),
|
||||
/// Permission to deny access to players with the same access level.
|
||||
ACCESS_EQUAL_DENY("access.equal.deny"),
|
||||
|
||||
/// Permission to perform inventory interaction while in spectator mode.
|
||||
SPECTATE_CLICK("spectate.click"),
|
||||
|
||||
/// Permission to use the AnyContainer feature.
|
||||
CONTAINER_ANY("container.any"),
|
||||
/// Permission to use the AnyContainer feature but not the command to toggle it.
|
||||
CONTAINER_ANY_USE("container.any.use"),
|
||||
/// Permission to use the SilentContainer feature.
|
||||
CONTAINER_SILENT("container.silent"),
|
||||
/// Permission to use the SilentContainer feature but not the command to toggle it.
|
||||
CONTAINER_SILENT_USE("container.silent.use"),
|
||||
/// Permission to search inventories and ender chests.
|
||||
SEARCH_INVENTORY("search.inventory"),
|
||||
/// Permission to search containers.
|
||||
SEARCH_CONTAINER("search.container");
|
||||
|
||||
private final String permission;
|
||||
|
||||
Permissions(String permission) {
|
||||
this.permission = "openinv." + permission;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a {@link Permissible} has this permission.
|
||||
*
|
||||
* @param permissible the Permissible
|
||||
* @return true if the permission is granted
|
||||
*/
|
||||
public boolean hasPermission(Permissible permissible) {
|
||||
return permissible.hasPermission(permission);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.lishid.openinv.util.setting;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* A per-player setting that may be enabled or disabled.
|
||||
*/
|
||||
@NullMarked
|
||||
public interface PlayerToggle {
|
||||
|
||||
/**
|
||||
* Get the name of the setting.
|
||||
*
|
||||
* @return the setting name
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Get the state of the toggle for a particular player ID.
|
||||
*
|
||||
* @param uuid the player ID
|
||||
* @return true if the setting is enabled
|
||||
*/
|
||||
boolean is(UUID uuid);
|
||||
|
||||
/**
|
||||
* Get the state of the toggle for a particular {@link Player},
|
||||
* accounting for permissions required to use the feature.
|
||||
*
|
||||
* @param player the player
|
||||
* @return true if the setting is enabled and the player has the required permissions
|
||||
*/
|
||||
boolean is(Player player);
|
||||
|
||||
/**
|
||||
* Set the state of the toggle for a particular player ID.
|
||||
*
|
||||
* @param uuid the player ID
|
||||
* @param enabled whether the setting is enabled
|
||||
* @return true if the setting changed as a result of being set
|
||||
*/
|
||||
boolean set(UUID uuid, boolean enabled);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
package com.lishid.openinv.util.setting;
|
||||
|
||||
import com.lishid.openinv.util.Permissions;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.UnmodifiableView;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Utility class containing all of OpenInv's {@link PlayerToggle PlayerToggles}.
|
||||
*/
|
||||
@NullMarked
|
||||
public final class PlayerToggles {
|
||||
|
||||
private static final Map<String, PlayerToggle> TOGGLES = new HashMap<>();
|
||||
private static final PlayerToggle ANY = add(new MemoryToggle("AnyContainer") {
|
||||
@Override
|
||||
public boolean is(Player player) {
|
||||
return is(player.getUniqueId())
|
||||
&& (Permissions.CONTAINER_ANY.hasPermission(player) || Permissions.CONTAINER_ANY_USE.hasPermission(player));
|
||||
}
|
||||
});
|
||||
private static final PlayerToggle SILENT = add(new MemoryToggle("SilentContainer") {
|
||||
@Override
|
||||
public boolean is(Player player) {
|
||||
return is(player.getUniqueId())
|
||||
&& (Permissions.CONTAINER_SILENT.hasPermission(player) || Permissions.CONTAINER_SILENT_USE.hasPermission(player));
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Get the AnyContainer toggle.
|
||||
*
|
||||
* @return the AnyContainer toggle
|
||||
*/
|
||||
public static PlayerToggle any() {
|
||||
return ANY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SilentContainer toggle.
|
||||
*
|
||||
* @return the SilentContainer toggle
|
||||
*/
|
||||
public static PlayerToggle silent() {
|
||||
return SILENT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a toggle by name.
|
||||
*
|
||||
* @param toggleName the name of the toggle
|
||||
* @return the toggle, or null if no such toggle exists.
|
||||
*/
|
||||
public static @Nullable PlayerToggle get(String toggleName) {
|
||||
PlayerToggle toggle = TOGGLES.get(toggleName);
|
||||
if (toggle == null) {
|
||||
toggle = TOGGLES.get(toggleName.toLowerCase(Locale.ENGLISH));
|
||||
}
|
||||
return toggle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an unmodifable view of all toggles available.
|
||||
*
|
||||
* @return a view of all toggles available
|
||||
*/
|
||||
public static @UnmodifiableView Collection<PlayerToggle> get() {
|
||||
return Collections.unmodifiableCollection(TOGGLES.values());
|
||||
}
|
||||
|
||||
private static PlayerToggle add(PlayerToggle toggle) {
|
||||
TOGGLES.put(toggle.getName().toLowerCase(Locale.ENGLISH), toggle);
|
||||
return toggle;
|
||||
}
|
||||
|
||||
private PlayerToggles() {
|
||||
throw new IllegalStateException("Cannot create instance of utility class.");
|
||||
}
|
||||
|
||||
private static abstract class MemoryToggle implements PlayerToggle {
|
||||
|
||||
private final Set<UUID> enabled;
|
||||
private final String name;
|
||||
|
||||
private MemoryToggle(String name) {
|
||||
enabled = new HashSet<>();
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean is(UUID uuid) {
|
||||
return enabled.contains(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean set(UUID uuid, boolean enabled) {
|
||||
if (enabled) {
|
||||
return this.enabled.add(uuid);
|
||||
} else {
|
||||
return this.enabled.remove(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,208 +0,0 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinv</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>openinvassembly</artifactId>
|
||||
<name>OpenInvAssembly</name>
|
||||
|
||||
<profiles>
|
||||
|
||||
<profile>
|
||||
<id>latest</id>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvadapter1_11_R1</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</profile>
|
||||
|
||||
<profile>
|
||||
<id>modern</id>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvadapter1_8_R1</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvadapter1_8_R2</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvadapter1_8_R3</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvadapter1_9_R1</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvadapter1_9_R2</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvadapter1_10_R1</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvadapter1_11_R1</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</profile>
|
||||
|
||||
<profile>
|
||||
<id>all</id>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvadapter1_4_5</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvadapter1_4_6</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvadapter1_4_R1</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvadapter1_5_R2</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvadapter1_5_R3</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvadapter1_6_R1</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvadapter1_6_R2</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvadapter1_6_R3</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvadapter1_7_R1</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvadapter1_7_R2</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvadapter1_7_R3</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvadapter1_7_R4</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvadapter1_8_R1</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvadapter1_8_R2</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvadapter1_8_R3</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvadapter1_9_R1</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvadapter1_9_R2</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvadapter1_10_R1</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvadapter1_11_R1</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</profile>
|
||||
|
||||
</profiles>
|
||||
|
||||
<build>
|
||||
<directory>../target</directory>
|
||||
<finalName>OpenInv</finalName>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>2.4.3</version>
|
||||
<configuration>
|
||||
<!--
|
||||
~ This keeps the final file clean, but may cause issues for people not familiar with the setup.
|
||||
~ If you're having trouble with the final product missing files, remove or tweak this configuration.
|
||||
-->
|
||||
<minimizeJar>true</minimizeJar>
|
||||
<filters>
|
||||
<filter>
|
||||
<artifact>com.lishid:*</artifact>
|
||||
<includes>
|
||||
<include>com/lishid/openinv/**/*</include>
|
||||
<include>plugin.yml</include>
|
||||
</includes>
|
||||
</filter>
|
||||
</filters>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,47 @@
|
||||
plugins {
|
||||
`java-library`
|
||||
alias(libs.plugins.paperweight) apply false
|
||||
alias(libs.plugins.shadow) apply false
|
||||
alias(libs.plugins.errorprone.gradle)
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
}
|
||||
|
||||
// Allow submodules to target higher Java release versions.
|
||||
java.disableAutoTargetJvm()
|
||||
|
||||
subprojects {
|
||||
apply(plugin = "java-library")
|
||||
apply(plugin = rootProject.libs.plugins.errorprone.gradle.get().pluginId)
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly(rootProject.libs.jspecify)
|
||||
compileOnly(rootProject.libs.annotations)
|
||||
errorprone(rootProject.libs.errorprone.core)
|
||||
}
|
||||
|
||||
tasks {
|
||||
withType<JavaCompile>().configureEach {
|
||||
options.encoding = Charsets.UTF_8.name()
|
||||
}
|
||||
withType<Javadoc>().configureEach {
|
||||
options.encoding = Charsets.UTF_8.name()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Task to delete ./dist where final files are output.
|
||||
tasks.register("cleanDist") {
|
||||
delete("dist")
|
||||
}
|
||||
|
||||
tasks.clean {
|
||||
// Also delete distribution folder when cleaning.
|
||||
dependsOn(tasks.named("cleanDist"))
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
plugins {
|
||||
`kotlin-dsl`
|
||||
}
|
||||
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
mavenCentral()
|
||||
}
|
||||
Whitespace-only changes.
@@ -0,0 +1,107 @@
|
||||
package com.github.jikoo.openinv
|
||||
|
||||
import org.gradle.api.file.DirectoryProperty
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.provider.ValueSource
|
||||
import org.gradle.api.provider.ValueSourceParameters
|
||||
import org.gradle.process.ExecOperations
|
||||
import java.io.File
|
||||
import java.net.URI
|
||||
import java.nio.file.Files
|
||||
import javax.inject.Inject
|
||||
|
||||
abstract class BuildToolsValueSource : ValueSource<File, BuildToolsValueSource.Parameters> {
|
||||
|
||||
@get:Inject
|
||||
abstract val exec: ExecOperations
|
||||
|
||||
interface Parameters : ValueSourceParameters {
|
||||
val installDir: DirectoryProperty
|
||||
val workingDir: DirectoryProperty
|
||||
|
||||
val spigotVersion: Property<String>
|
||||
val spigotRevision: Property<String>
|
||||
|
||||
val ignoreCached: Property<Boolean>
|
||||
|
||||
val javaHome: DirectoryProperty
|
||||
val javaExecutable: Property<String>
|
||||
}
|
||||
|
||||
override fun obtain(): File {
|
||||
val version = parameters.spigotVersion.get()
|
||||
val revision = parameters.spigotRevision.get()
|
||||
val spigotLocation = parameters.installDir.get().asFile.resolve("spigot-$version.jar")
|
||||
// If Spigot is already installed, don't reinstall.
|
||||
if (!parameters.ignoreCached.get() && spigotLocation.exists()) {
|
||||
println("Skipping Spigot installation, $version is present")
|
||||
return spigotLocation
|
||||
}
|
||||
|
||||
val buildTools = installBuildTools(parameters.workingDir.get().asFile)
|
||||
|
||||
println("Installing Spigot $version (rev $revision)")
|
||||
|
||||
exec.javaexec {
|
||||
environment["JAVA_HOME"] = parameters.javaHome.get()
|
||||
executable = parameters.javaExecutable.get()
|
||||
workingDir = buildTools.parentFile
|
||||
classpath(buildTools)
|
||||
args = listOf("--nogui", "--rev", revision)
|
||||
}.rethrowFailure()
|
||||
|
||||
val spigotBuild = buildTools.parentFile.resolve("Spigot/Spigot-Server/target/spigot-$version.jar")
|
||||
|
||||
if (!spigotBuild.exists()) {
|
||||
throw IllegalStateException(
|
||||
"Spigot build completed, but $spigotBuild does not exist! Did BuildTools change output location?"
|
||||
)
|
||||
}
|
||||
|
||||
spigotBuild.copyTo(spigotLocation, overwrite = true)
|
||||
|
||||
// Mark work for delete.
|
||||
cleanUp(buildTools.parentFile)
|
||||
|
||||
if (!spigotLocation.exists()) {
|
||||
throw IllegalStateException(
|
||||
"Failed to install Spigot $version from $revision. Does the revision point to a different version?"
|
||||
)
|
||||
}
|
||||
|
||||
return spigotLocation
|
||||
}
|
||||
|
||||
private fun installBuildTools(workingDir: File): File {
|
||||
val buildTools = workingDir.resolve("BuildTools.jar")
|
||||
if (buildTools.exists()) {
|
||||
return buildTools
|
||||
}
|
||||
|
||||
workingDir.mkdirs()
|
||||
|
||||
val buildToolsUrl =
|
||||
"https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar"
|
||||
println("Downloading $buildToolsUrl")
|
||||
val stream = URI.create(buildToolsUrl).toURL().openStream()
|
||||
Files.copy(stream, buildTools.toPath())
|
||||
stream.close()
|
||||
|
||||
return buildTools
|
||||
}
|
||||
|
||||
private fun cleanUp(dir: File) {
|
||||
dir.deleteOnExit()
|
||||
if (!dir.isDirectory) {
|
||||
return
|
||||
}
|
||||
|
||||
dir.listFiles()?.forEach {
|
||||
if (it.isDirectory) {
|
||||
cleanUp(it)
|
||||
} else {
|
||||
it.deleteOnExit()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.github.jikoo.openinv
|
||||
|
||||
import org.gradle.api.model.ObjectFactory
|
||||
import org.gradle.jvm.toolchain.JavaToolchainSpec
|
||||
|
||||
abstract class SpigotDependencyExtension(
|
||||
objects: ObjectFactory
|
||||
) {
|
||||
|
||||
val version = objects.property(String::class.java)
|
||||
val revision = objects.property(String::class.java)
|
||||
.convention(version.map {
|
||||
it.replace("-R\\d+\\.\\d+-SNAPSHOT".toRegex(), "")
|
||||
})
|
||||
val classifier = objects.property(String::class.java).convention("")
|
||||
val java = objects.property(JavaToolchainSpec::class.java)
|
||||
val ignoreCached = objects.property(Boolean::class.java).convention(false)
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.github.jikoo.openinv
|
||||
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.plugins.JavaPluginExtension
|
||||
import org.gradle.jvm.toolchain.JavaToolchainService
|
||||
import java.io.File
|
||||
import javax.inject.Inject
|
||||
|
||||
abstract class SpigotSetup : Plugin<Project> {
|
||||
|
||||
@get:Inject
|
||||
abstract val javaToolchainService: JavaToolchainService
|
||||
|
||||
override fun apply(target: Project) {
|
||||
target.plugins.apply("java")
|
||||
|
||||
// Set up extension for configuring Spigot dependency.
|
||||
val spigotExt = target.dependencies.extensions.findByType(SpigotDependencyExtension::class.java)
|
||||
?: target.dependencies.extensions.create(
|
||||
"spigot",
|
||||
SpigotDependencyExtension::class.java,
|
||||
target.objects
|
||||
)
|
||||
|
||||
target.afterEvaluate {
|
||||
// Get Java requirements, defaulting to version used for compilation.
|
||||
spigotExt.java.convention(target.extensions.getByType(JavaPluginExtension::class.java).toolchain)
|
||||
val launcher = javaToolchainService.launcherFor(spigotExt.java.get()).get()
|
||||
|
||||
// Install Spigot with BuildTools.
|
||||
val spigot: File = target.providers.of(BuildToolsValueSource::class.java) {
|
||||
parameters {
|
||||
installDir.set(target.gradle.gradleUserHomeDir.resolve("caches/spigot"))
|
||||
workingDir.set(target.layout.buildDirectory.dir("tmp/buildtools"))
|
||||
spigotVersion.set(spigotExt.version)
|
||||
spigotRevision.set(spigotExt.revision)
|
||||
ignoreCached.set(spigotExt.ignoreCached)
|
||||
javaHome.set(launcher.metadata.installationPath)
|
||||
javaExecutable.set(launcher.executablePath.asFile.path)
|
||||
}
|
||||
}.get()
|
||||
|
||||
// Add Spigot dependency.
|
||||
val dependency = target.dependencies.create(files(spigot))
|
||||
target.dependencies.add("compileOnly", dependency)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
repositories {
|
||||
maven("https://hub.spigotmc.org/nexus/content/groups/public/")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly(libs.spigotapi)
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain.languageVersion = JavaLanguageVersion.of(21)
|
||||
}
|
||||
|
||||
tasks.withType<JavaCompile>().configureEach {
|
||||
options.release = 21
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(":openinvapi"))
|
||||
compileOnly(libs.slf4j.api)
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.github.jikoo.openinv.internal;
|
||||
|
||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
||||
import com.lishid.openinv.internal.ISpecialEnderChest;
|
||||
import com.lishid.openinv.internal.ISpecialInventory;
|
||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
@NullMarked
|
||||
public interface Accessor {
|
||||
|
||||
PlayerManager getPlayerManager();
|
||||
|
||||
IAnySilentContainer getAnySilentContainer();
|
||||
|
||||
ISpecialPlayerInventory createPlayerInventory(Player player);
|
||||
|
||||
ISpecialEnderChest createEnderChest(Player player);
|
||||
|
||||
<T extends ISpecialInventory> @Nullable T get(Inventory bukkitInventory, Class<T> clazz);
|
||||
|
||||
void reload(ConfigurationSection config);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2022 lishid. All rights reserved.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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.jikoo.openinv.internal;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialInventory;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
@NullMarked
|
||||
public interface PlayerManager {
|
||||
|
||||
/**
|
||||
* Loads a Player for an OfflinePlayer.
|
||||
* </p>
|
||||
* This method is potentially blocking, and should not be called on the main thread.
|
||||
*
|
||||
* @param offline the OfflinePlayer
|
||||
* @return the Player loaded
|
||||
*/
|
||||
@Nullable Player loadPlayer(OfflinePlayer offline);
|
||||
|
||||
/**
|
||||
* Creates a new Player from an existing one that will function slightly better offline.
|
||||
*
|
||||
* @return the Player
|
||||
*/
|
||||
Player inject(Player player);
|
||||
|
||||
/**
|
||||
* Opens an ISpecialInventory for a Player.
|
||||
*
|
||||
* @param player the Player opening the ISpecialInventory
|
||||
* @param inventory the Inventory
|
||||
*
|
||||
* @return the InventoryView opened
|
||||
*/
|
||||
@Nullable InventoryView openInventory(Player player, ISpecialInventory inventory, boolean viewOnly);
|
||||
|
||||
}
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
package com.github.jikoo.openinv.internal.container;
|
||||
|
||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
||||
import org.bukkit.block.Barrel;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.EnderChest;
|
||||
import org.bukkit.block.ShulkerBox;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.type.Chest;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
@NullMarked
|
||||
public abstract class AnySilentContainerBase implements IAnySilentContainer {
|
||||
|
||||
public enum StateType {
|
||||
ENDER_CHEST,
|
||||
SHULKER_BOX,
|
||||
CHEST,
|
||||
BARREL,
|
||||
OTHER
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnyContainerNeeded(Block block) {
|
||||
return isAnyContainerNeeded(getStateType(block), block);
|
||||
}
|
||||
|
||||
protected boolean isAnyContainerNeeded(StateType material, Block block) {
|
||||
return switch (material) {
|
||||
// Enderchests require a non-occluding block on top to open.
|
||||
case ENDER_CHEST -> block.getRelative(0, 1, 0).getType().isOccluding();
|
||||
// Shulker boxes require half a block clear in the direction they open.
|
||||
case SHULKER_BOX -> isShulkerBlocked(block);
|
||||
// Chests require that the block above not be occluding or occupied by a cat.
|
||||
case CHEST -> isChestBlocked(block);
|
||||
// Barrels need silent but not any. All others unsupported.
|
||||
default -> false;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChestBlocked(Block block) {
|
||||
if (IAnySilentContainer.super.isChestBlocked(block)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
BlockData blockData = block.getBlockData();
|
||||
if (!(blockData instanceof Chest chest) || chest.getType() == Chest.Type.SINGLE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
BlockFace relativeFace = switch (chest.getFacing()) {
|
||||
case NORTH -> chest.getType() == Chest.Type.RIGHT ? BlockFace.WEST : BlockFace.EAST;
|
||||
case EAST -> chest.getType() == Chest.Type.RIGHT ? BlockFace.NORTH : BlockFace.SOUTH;
|
||||
case SOUTH -> chest.getType() == Chest.Type.RIGHT ? BlockFace.EAST : BlockFace.WEST;
|
||||
case WEST -> chest.getType() == Chest.Type.RIGHT ? BlockFace.SOUTH : BlockFace.NORTH;
|
||||
default -> BlockFace.SELF;
|
||||
};
|
||||
Block relative = block.getRelative(relativeFace);
|
||||
|
||||
if (relative.getType() != block.getType()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
BlockData relativeData = relative.getBlockData();
|
||||
if (!(relativeData instanceof Chest relativeChest)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (relativeChest.getFacing() != chest.getFacing()
|
||||
|| relativeChest.getType() != (chest.getType() == Chest.Type.RIGHT ? Chest.Type.LEFT : Chest.Type.RIGHT)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return IAnySilentContainer.super.isChestBlocked(relative);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnySilentContainer(Block block) {
|
||||
return isAnySilentContainer(getState(block));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnySilentContainer(Inventory inventory) {
|
||||
return isAnySilentContainer(getHolder(inventory));
|
||||
}
|
||||
|
||||
protected StateType getStateType(Block block) {
|
||||
return switch (getState(block)) {
|
||||
case Barrel ignored -> StateType.BARREL;
|
||||
case EnderChest ignored -> StateType.ENDER_CHEST;
|
||||
case ShulkerBox ignored -> StateType.SHULKER_BOX;
|
||||
case org.bukkit.block.Chest ignored -> StateType.CHEST;
|
||||
default -> StateType.OTHER;
|
||||
};
|
||||
}
|
||||
|
||||
protected abstract BlockState getState(Block block);
|
||||
|
||||
protected abstract @Nullable InventoryHolder getHolder(Inventory inventory);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.github.jikoo.openinv.internal.container;
|
||||
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
@NullMarked
|
||||
public interface InternalOwned<T> {
|
||||
|
||||
T getOwnerHandle();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.github.jikoo.openinv.internal.container;
|
||||
|
||||
public interface ViewOnly {
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.github.jikoo.openinv.internal.container.slot;
|
||||
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
/**
|
||||
* An interface defining behaviors for entries in a {@link net.minecraft.world.Container Container}. Used to reduce duplicate content reordering.
|
||||
*/
|
||||
@NullMarked
|
||||
public interface Content<P, I, C, S> {
|
||||
|
||||
/**
|
||||
* Update internal holder.
|
||||
*
|
||||
* @param holder the new holder
|
||||
*/
|
||||
void setHolder(P holder);
|
||||
|
||||
/**
|
||||
* Get the current item.
|
||||
*
|
||||
* @return the current item
|
||||
*/
|
||||
I get();
|
||||
|
||||
/**
|
||||
* Remove the current item.
|
||||
*
|
||||
* @return the current item
|
||||
*/
|
||||
I remove();
|
||||
|
||||
/**
|
||||
* Remove some of the current item.
|
||||
*
|
||||
* @return the current item
|
||||
*/
|
||||
I removePartial(int amount);
|
||||
|
||||
/**
|
||||
* Set the current item. If slot is currently not usable, will drop item instead.
|
||||
*
|
||||
* @param itemStack the item to set
|
||||
*/
|
||||
void set(I itemStack);
|
||||
|
||||
/**
|
||||
* Get a {@link net.minecraft.world.inventory.Slot Slot} for use in a {@link net.minecraft.world.inventory.AbstractContainerMenu ContainerMenu}. Will
|
||||
* impose any specific restrictions to insertion or removal.
|
||||
*
|
||||
* @param container the backing container
|
||||
* @param slot the slot of the backing container represented
|
||||
* @param x clientside x dimension from top left of inventory, not used
|
||||
* @param y clientside y dimension from top left of inventory, not used
|
||||
* @return a menu slot
|
||||
*/
|
||||
S asSlot(C container, int slot, int x, int y);
|
||||
|
||||
/**
|
||||
* Get a loose Bukkit translation of what this slot stores. For example, any slot that drops items at the owner rather
|
||||
* than insert them will report itself as being {@link org.bukkit.event.inventory.InventoryType.SlotType#OUTSIDE}.
|
||||
*
|
||||
* @return the closes Bukkit slot type
|
||||
*/
|
||||
org.bukkit.event.inventory.InventoryType.SlotType getSlotType();
|
||||
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package com.github.jikoo.openinv.internal.container.slot;
|
||||
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
@NullMarked
|
||||
public interface InventoryFactory<P, I, C, S, E> {
|
||||
|
||||
Content<P, I, C, S> newCrafting(P holder, int index);
|
||||
|
||||
Content<P, I, C, S> newCraftingResult(P holder);
|
||||
|
||||
Content<P, I, C, S> newCursor(P holder);
|
||||
|
||||
Content<P, I, C, S> newDrop(P holder);
|
||||
|
||||
Content<P, I, C, S> newEquipment(P holder, E equipmentSlot);
|
||||
|
||||
Content<P, I, C, S> newList(P holder, int index, InventoryType.SlotType slotType, Function<P, List<I>> listSupplier);
|
||||
|
||||
Content<P, I, C, S> newOffHand(P holder);
|
||||
|
||||
Content<P, I, C, S> newViewOnly(P holder);
|
||||
|
||||
Content<P, I, C, S> newViewOnly(P holder, I itemStack);
|
||||
|
||||
S wrapViewOnly(S wrapped);
|
||||
|
||||
ItemStack asBukkitMirror(I itemStack);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,309 @@
|
||||
package com.github.jikoo.openinv.lang;
|
||||
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.Configuration;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* A simple language manager supporting both custom and bundled languages.
|
||||
*/
|
||||
@NullMarked
|
||||
public class LanguageManager {
|
||||
|
||||
private final Plugin plugin;
|
||||
private final File folder;
|
||||
private final String defaultLocale;
|
||||
private final Map<String, YamlConfiguration> locales;
|
||||
|
||||
public LanguageManager(Plugin plugin, String defaultLocale) {
|
||||
this.plugin = plugin;
|
||||
this.defaultLocale = defaultLocale;
|
||||
this.locales = new HashMap<>();
|
||||
this.folder = new File(plugin.getDataFolder(), "locale");
|
||||
|
||||
if (!folder.exists() && !folder.mkdirs()) {
|
||||
plugin.getLogger().warning(() -> "Unable to create " + folder.getPath() + "! Languages may not be editable.");
|
||||
}
|
||||
|
||||
reload();
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
this.locales.clear();
|
||||
getOrLoadLocale(defaultLocale);
|
||||
}
|
||||
|
||||
private YamlConfiguration getOrLoadLocale(String locale) {
|
||||
YamlConfiguration loaded = locales.get(locale);
|
||||
if (loaded != null) {
|
||||
return loaded;
|
||||
}
|
||||
|
||||
LangLocation lang = bestMatch(locale, null);
|
||||
|
||||
// If a parent was a better match, check if it is already loaded.
|
||||
if (!locale.equals(lang.locale)) {
|
||||
loaded = locales.get(lang.locale);
|
||||
if (loaded != null) {
|
||||
locales.put(locale, loaded);
|
||||
return loaded;
|
||||
}
|
||||
}
|
||||
|
||||
// Load locale config from disk and bundled locale defaults.
|
||||
YamlConfiguration localeConfig = loadLocale(lang);
|
||||
|
||||
// If the locale is not the default locale, also handle any missing translations from the default locale.
|
||||
if (!locale.equals(defaultLocale)) {
|
||||
addTranslationFallthrough(lang, localeConfig);
|
||||
|
||||
if (plugin.getConfig().getBoolean("settings.secret.warn-about-guess-section", true)
|
||||
&& localeConfig.isConfigurationSection("guess")) {
|
||||
// Warn that guess section exists. This should run once per language per server restart
|
||||
// when accessed by a user to hint to server owners that they can make UX improvements.
|
||||
plugin.getLogger().info(() -> "[LanguageManager] Missing translations from " + lang.locale + ".yml! Check the guess section!");
|
||||
}
|
||||
}
|
||||
|
||||
locales.put(locale, localeConfig);
|
||||
locales.put(lang.locale, localeConfig);
|
||||
|
||||
return localeConfig;
|
||||
}
|
||||
|
||||
private LangLocation bestMatch(String locale, @Nullable LangLocation initial) {
|
||||
File file = new File(folder, locale + ".yml");
|
||||
InputStream bundled = plugin.getResource("locale/" + locale + ".yml");
|
||||
|
||||
if (file.exists() || bundled != null) {
|
||||
return new LangLocation(locale, file, bundled);
|
||||
}
|
||||
|
||||
if (initial == null) {
|
||||
initial = new LangLocation(locale, file, null);
|
||||
}
|
||||
|
||||
int lastSeparator = locale.lastIndexOf('_');
|
||||
|
||||
// Must be at least some content before separator.
|
||||
if (lastSeparator < 1) {
|
||||
return initial;
|
||||
}
|
||||
|
||||
return bestMatch(locale.substring(0, lastSeparator), initial);
|
||||
}
|
||||
|
||||
private YamlConfiguration loadLocale(LangLocation lang) {
|
||||
YamlConfiguration localeConfigDefaults;
|
||||
if (lang.bundled == null) {
|
||||
localeConfigDefaults = new YamlConfiguration();
|
||||
} else {
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(lang.bundled, StandardCharsets.UTF_8))) {
|
||||
localeConfigDefaults = YamlConfiguration.loadConfiguration(reader);
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().log(Level.WARNING, e, () -> "[LanguageManager] Unable to load resource " + lang.locale + ".yml");
|
||||
localeConfigDefaults = new YamlConfiguration();
|
||||
}
|
||||
}
|
||||
|
||||
if (!lang.file.exists()) {
|
||||
// If the file does not exist on disk, save bundled defaults.
|
||||
try {
|
||||
localeConfigDefaults.save(lang.file);
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().log(Level.WARNING, e, () -> "[LanguageManager] Unable to save resource " + lang.locale + ".yml");
|
||||
}
|
||||
// Return loaded bundled locale.
|
||||
return localeConfigDefaults;
|
||||
}
|
||||
|
||||
// If the file does exist on disk, load it.
|
||||
YamlConfiguration localeConfig = YamlConfiguration.loadConfiguration(lang.file);
|
||||
// Check for missing translations from the bundled file.
|
||||
List<String> newKeys = getMissingKeys(localeConfigDefaults, localeConfig::isSet);
|
||||
|
||||
if (newKeys.isEmpty()) {
|
||||
return localeConfig;
|
||||
}
|
||||
|
||||
// Get guess section for missing keys.
|
||||
ConfigurationSection guess = localeConfig.getConfigurationSection("guess");
|
||||
|
||||
for (String newKey : newKeys) {
|
||||
// Set all missing keys to defaults.
|
||||
localeConfig.set(newKey, localeConfigDefaults.get(newKey));
|
||||
|
||||
// Delete relevant guess keys in case this is a new translation.
|
||||
if (guess != null) {
|
||||
guess.set(newKey, null);
|
||||
}
|
||||
}
|
||||
|
||||
// If guess section is empty, delete it.
|
||||
if (guess != null && guess.getKeys(false).isEmpty()) {
|
||||
localeConfig.set("guess", null);
|
||||
}
|
||||
|
||||
plugin.getLogger().info(() -> "[LanguageManager] Added new translation keys to " + lang.locale + ".yml: " + String.join(", ", newKeys));
|
||||
|
||||
// Write new keys to disk.
|
||||
try {
|
||||
localeConfig.save(lang.file);
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().log(Level.WARNING, e, () -> "[LanguageManager] Unable to save resource " + lang.locale + ".yml");
|
||||
}
|
||||
|
||||
return localeConfig;
|
||||
}
|
||||
|
||||
private void addTranslationFallthrough(LangLocation location, YamlConfiguration localeConfig) {
|
||||
YamlConfiguration defaultLocaleConfig = locales.get(defaultLocale);
|
||||
|
||||
// Get missing keys. Keys that already have a guess value are not new and don't need to trigger another write.
|
||||
List<String> missingKeys = getMissingKeys(
|
||||
defaultLocaleConfig,
|
||||
key -> localeConfig.isSet(key) || localeConfig.isSet("guess." + key)
|
||||
);
|
||||
|
||||
if (!missingKeys.isEmpty()) {
|
||||
// Set up guess section for missing keys.
|
||||
for (String key : missingKeys) {
|
||||
localeConfig.set("guess." + key, defaultLocaleConfig.get(key));
|
||||
}
|
||||
|
||||
// Write modified guess section to disk.
|
||||
try {
|
||||
localeConfig.save(location.file);
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().log(Level.WARNING, e, () -> "[LanguageManager] Unable to save resource " + location.locale + ".yml");
|
||||
}
|
||||
}
|
||||
|
||||
// Fall through to default locale.
|
||||
localeConfig.setDefaults(defaultLocaleConfig);
|
||||
}
|
||||
|
||||
private List<String> getMissingKeys(
|
||||
Configuration configurationDefault,
|
||||
Predicate<String> nodeSetPredicate
|
||||
) {
|
||||
List<String> missingKeys = new ArrayList<>();
|
||||
for (String key : configurationDefault.getKeys(true)) {
|
||||
if (!configurationDefault.isConfigurationSection(key) && !nodeSetPredicate.test(key)) {
|
||||
// Missing keys are non-section keys that fail the predicate.
|
||||
missingKeys.add(key);
|
||||
}
|
||||
}
|
||||
return missingKeys;
|
||||
}
|
||||
|
||||
public @Nullable String getValue(String key, @Nullable String locale) {
|
||||
String value = getOrLoadLocale(locale == null ? defaultLocale : locale.toLowerCase(Locale.ENGLISH)).getString(key);
|
||||
if (value == null || value.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
value = ChatColor.translateAlternateColorCodes('&', value);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public @Nullable String getValue(
|
||||
String key,
|
||||
@Nullable String locale,
|
||||
Replacement... replacements
|
||||
) {
|
||||
String value = getValue(key, locale);
|
||||
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (Replacement replacement : replacements) {
|
||||
value = value.replace(replacement.placeholder(), replacement.value());
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public @Nullable String getLocalizedMessage(CommandSender sender, String key) {
|
||||
return getValue(key, getLocale(sender));
|
||||
}
|
||||
|
||||
public @Nullable String getLocalizedMessage(
|
||||
CommandSender sender,
|
||||
String key,
|
||||
Replacement... replacements
|
||||
) {
|
||||
return getValue(key, getLocale(sender), replacements);
|
||||
}
|
||||
|
||||
private String getLocale(CommandSender sender) {
|
||||
if (sender instanceof Player player) {
|
||||
return player.getLocale();
|
||||
} else {
|
||||
return plugin.getConfig().getString("settings.locale", "en");
|
||||
}
|
||||
}
|
||||
|
||||
public void sendMessage(CommandSender sender, String key) {
|
||||
String message = getLocalizedMessage(sender, key);
|
||||
|
||||
if (message != null && !message.isEmpty()) {
|
||||
sender.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendMessage(CommandSender sender, String key, Replacement... replacements) {
|
||||
String message = getLocalizedMessage(sender, key, replacements);
|
||||
|
||||
if (message != null && !message.isEmpty()) {
|
||||
sender.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendSystemMessage(Player player, String key) {
|
||||
String message = getLocalizedMessage(player, key);
|
||||
|
||||
if (message == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int newline = message.indexOf('\n');
|
||||
if (newline != -1) {
|
||||
// No newlines in action bar chat.
|
||||
message = message.substring(0, newline);
|
||||
}
|
||||
|
||||
if (message.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacy(message));
|
||||
}
|
||||
|
||||
private record LangLocation(String locale, File file, @Nullable InputStream bundled) {}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.github.jikoo.openinv.lang;
|
||||
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
/**
|
||||
* A data holder for string replacement in translations.
|
||||
*
|
||||
* @param placeholder the placeholder to be replaced
|
||||
* @param value the value to insert
|
||||
*/
|
||||
@NullMarked
|
||||
public record Replacement(String placeholder, String value) {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
package com.github.jikoo.openinv.util;
|
||||
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
import org.slf4j.Marker;
|
||||
import org.slf4j.helpers.LegacyAbstractLogger;
|
||||
import org.slf4j.helpers.MessageFormatter;
|
||||
import org.slf4j.helpers.NormalizedParameters;
|
||||
import org.slf4j.spi.LocationAwareLogger;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* An adapter for wrapping a {@link java.util.logging.Logger} as a {@link org.slf4j.Logger}.
|
||||
* <br>Largely based on {@code JDK14LoggerAdapter}, which is not present at runtime.
|
||||
*/
|
||||
@NullMarked
|
||||
public class JulLoggerAdapter extends LegacyAbstractLogger implements LocationAwareLogger {
|
||||
|
||||
private final Logger wrapped;
|
||||
|
||||
public JulLoggerAdapter(Logger wrapped) {
|
||||
this.wrapped = wrapped;
|
||||
this.name = wrapped.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getFullyQualifiedCallerName() {
|
||||
return JulLoggerAdapter.class.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleNormalizedLoggingCall(
|
||||
org.slf4j.event.Level slf4jLevel,
|
||||
Marker marker,
|
||||
String msg,
|
||||
Object[] args,
|
||||
Throwable thrown
|
||||
) {
|
||||
Level level = fromSlf4jLevel(slf4jLevel);
|
||||
|
||||
if (wrapped.isLoggable(level)) {
|
||||
normalizedLog(getFullyQualifiedCallerName(), level, msg, args, thrown);
|
||||
}
|
||||
}
|
||||
|
||||
private void normalizedLog(String fqcn, Level level, String msg, Object[] args, Throwable thrown) {
|
||||
String formatted = MessageFormatter.basicArrayFormat(msg, args);
|
||||
LogRecord logRecord = new LogRecord(level, formatted);
|
||||
logRecord.setLoggerName(getName());
|
||||
logRecord.setThrown(thrown);
|
||||
|
||||
addSource(fqcn, logRecord);
|
||||
|
||||
wrapped.log(logRecord);
|
||||
}
|
||||
|
||||
private void addSource(String fqcn, LogRecord logRecord) {
|
||||
StackWalker.getInstance().walk(stream -> stream
|
||||
// Start at index 2 - this is an internal method, so we want at least the caller's caller.
|
||||
.skip(2)
|
||||
// Walk at maximum 10 frames.
|
||||
.limit(10)
|
||||
.filter(frame -> isIgnored(frame.getClassName(), fqcn))
|
||||
.findFirst()
|
||||
).ifPresent(frame -> {
|
||||
logRecord.setSourceClassName(frame.getClassName());
|
||||
logRecord.setSourceMethodName(frame.getMethodName());
|
||||
});
|
||||
}
|
||||
|
||||
private boolean isIgnored(String className, String fqcn) {
|
||||
if (className.equals(fqcn)) {
|
||||
return true;
|
||||
}
|
||||
// Ignore slf4j classes - they shouldn't be the source.
|
||||
if (className.startsWith("org.slf4j.")) {
|
||||
return true;
|
||||
}
|
||||
return className.equals(getFullyQualifiedCallerName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(Marker marker, String callerFqn, int levelInt, String msg, Object[] args, Throwable thrown) {
|
||||
Level level = fromSlf4jLevel(org.slf4j.event.Level.intToLevel(levelInt));
|
||||
|
||||
if (!wrapped.isLoggable(level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
NormalizedParameters params = NormalizedParameters.normalize(msg, args, thrown);
|
||||
normalizedLog(callerFqn, level, params.getMessage(), params.getArguments(), params.getThrowable());
|
||||
}
|
||||
|
||||
private Level fromSlf4jLevel(org.slf4j.event.Level level) {
|
||||
return switch (level) {
|
||||
case TRACE -> Level.FINEST;
|
||||
case DEBUG -> Level.FINE;
|
||||
case INFO -> Level.INFO;
|
||||
case WARN -> Level.WARNING;
|
||||
case ERROR -> Level.SEVERE;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTraceEnabled() {
|
||||
return wrapped.isLoggable(Level.FINEST);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugEnabled() {
|
||||
return wrapped.isLoggable(Level.FINE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInfoEnabled() {
|
||||
return wrapped.isLoggable(Level.INFO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWarnEnabled() {
|
||||
return wrapped.isLoggable(Level.WARNING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isErrorEnabled() {
|
||||
return wrapped.isLoggable(Level.SEVERE);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.github.jikoo.openinv.util;
|
||||
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* A utility for making reflection easier.
|
||||
*/
|
||||
@NullMarked
|
||||
public final class ReflectionHelper {
|
||||
|
||||
/**
|
||||
* Grab an {@link Object} stored in a {@link Field} of another {@code Object}.
|
||||
*
|
||||
* <p>This casts the field to the correct class. Any issues will result in a {@code null} return value.
|
||||
*
|
||||
* @param fieldType the {@link Class} of {@code Object} stored in the {@code Field}
|
||||
* @param holder the containing {@code Object}
|
||||
* @param <T> the type of stored {@code Object}
|
||||
* @return the first matching {@code Object} or {@code null} if none match
|
||||
*/
|
||||
public static <T> @Nullable T grabObjectByType(final Object holder, final Class<T> fieldType) {
|
||||
Field field = grabFieldByType(holder.getClass(), fieldType);
|
||||
|
||||
if (field != null) {
|
||||
try {
|
||||
return fieldType.cast(field.get(holder));
|
||||
} catch (IllegalAccessException ignored) {
|
||||
// Ignore issues obtaining field
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Grab a {@link Field} of an {@link Object}
|
||||
*
|
||||
* @param fieldType the {@link Class} of the object
|
||||
* @param holderType the containing {@code Class}
|
||||
* @return the first matching object or {@code null} if none match
|
||||
*/
|
||||
public static @Nullable Field grabFieldByType(Class<?> holderType, Class<?> fieldType) {
|
||||
for (Field field : holderType.getDeclaredFields()) {
|
||||
if (fieldType.isAssignableFrom(field.getType())) {
|
||||
field.setAccessible(true);
|
||||
return field;
|
||||
}
|
||||
}
|
||||
|
||||
if (holderType.getSuperclass() != null) {
|
||||
return grabFieldByType(fieldType, holderType.getSuperclass());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private ReflectionHelper() {
|
||||
throw new IllegalStateException("Cannot create instance of utility class.");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.lishid.openinv.event;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialInventory;
|
||||
import com.lishid.openinv.util.setting.PlayerToggle;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Construct and call events.
|
||||
*/
|
||||
@NullMarked
|
||||
public final class OpenEvents {
|
||||
|
||||
public static boolean saveCancelled(Player player) {
|
||||
return call(new PlayerSaveEvent(player));
|
||||
}
|
||||
|
||||
public static boolean saveCancelled(ISpecialInventory inventory) {
|
||||
return call(new OpenPlayerSaveEvent((Player) inventory.getPlayer(), inventory));
|
||||
}
|
||||
|
||||
public static void notifyPlayerToggle(PlayerToggle toggle, UUID uuid, boolean state) {
|
||||
Bukkit.getPluginManager().callEvent(new PlayerToggledEvent(toggle, uuid, state));
|
||||
}
|
||||
|
||||
private static <T extends Event & Cancellable> boolean call(T event) {
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
return event.isCancelled();
|
||||
}
|
||||
|
||||
private OpenEvents() {
|
||||
throw new IllegalStateException("Cannot create instance of utility class.");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
# Project meta
|
||||
group=com.lishid.openinv
|
||||
version=5.3.4
|
||||
description=A Bukkit plugin for opening normally-inaccessible inventories.
|
||||
|
||||
# Gradle configuration
|
||||
org.gradle.parallel=true
|
||||
org.gradle.caching=true
|
||||
org.gradle.configuration-cache=true
|
||||
@@ -0,0 +1,33 @@
|
||||
[versions]
|
||||
spigotapi = "1.21.3-R0.1-SNAPSHOT"
|
||||
planarwrappers = "3.3.0"
|
||||
jspecify = "1.0.1"
|
||||
annotations = "26.1.0"
|
||||
paperweight = "2.0.0-beta.21"
|
||||
shadow = "9.6.1"
|
||||
folia-scheduler-wrapper = "v0.0.3"
|
||||
errorprone-core = "2.50.0"
|
||||
errorprone-gradle = "5.1.1"
|
||||
slf4j = "2.0.18"
|
||||
sqlite-jdbc = "3.49.1.0"
|
||||
mockito-core = "5.23.0"
|
||||
junit-jupiter = "6.1.3"
|
||||
hamcrest = "3.0"
|
||||
|
||||
[libraries]
|
||||
spigotapi = { module = "org.spigotmc:spigot-api", version.ref = "spigotapi" }
|
||||
planarwrappers = { module = "com.github.jikoo:planarwrappers", version.ref = "planarwrappers" }
|
||||
jspecify = { module = "org.jspecify:jspecify", version.ref = "jspecify" }
|
||||
annotations = { module = "org.jetbrains:annotations", version.ref = "annotations" }
|
||||
folia-scheduler-wrapper = { module = "com.github.NahuLD.folia-scheduler-wrapper:folia-scheduler-wrapper", version.ref = "folia-scheduler-wrapper" }
|
||||
errorprone-core = { module = "com.google.errorprone:error_prone_core", version.ref = "errorprone-core" }
|
||||
slf4j-api = { module = "org.slf4j:slf4j-api", version.ref = "slf4j" }
|
||||
sqlite-jdbc = { module = "org.xerial:sqlite-jdbc", version.ref = "sqlite-jdbc" }
|
||||
mockito-core = { module = "org.mockito:mockito-core", version.ref = "mockito-core" }
|
||||
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit-jupiter" }
|
||||
hamcrest = { module = "org.hamcrest:hamcrest", version.ref = "hamcrest" }
|
||||
|
||||
[plugins]
|
||||
paperweight = { id = "io.papermc.paperweight.userdev", version.ref = "paperweight" }
|
||||
shadow = { id = "com.gradleup.shadow", version.ref = "shadow" }
|
||||
errorprone-gradle = { id = "net.ltgt.errorprone", version.ref = "errorprone-gradle" }
|
||||
Vendored
BIN
Binary file not shown.
+9
@@ -0,0 +1,9 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.7.1-bin.zip
|
||||
networkTimeout=10000
|
||||
retries=0
|
||||
retryBackOffMs=500
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
@@ -0,0 +1,248 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015 the original authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# gradlew start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh gradlew
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/3d91ce3b8caaf77ad09f381f43615b715b53f72c/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# This is normally unused
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
} >&2
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
} >&2
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "$( uname )" in #(
|
||||
CYGWIN* ) cygwin=true ;; #(
|
||||
Darwin* ) darwin=true ;; #(
|
||||
MSYS* | MINGW* ) msys=true ;; #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||
else
|
||||
JAVACMD=$JAVA_HOME/bin/java
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
if ! command -v java >/dev/null 2>&1
|
||||
then
|
||||
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
done
|
||||
fi
|
||||
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command:
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
if ! command -v xargs >/dev/null 2>&1
|
||||
then
|
||||
die "xargs is not available"
|
||||
fi
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
Vendored
+82
@@ -0,0 +1,82 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
@rem SPDX-License-Identifier: Apache-2.0
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem gradlew startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables, and ensure extensions are enabled
|
||||
setlocal EnableExtensions
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%"=="" set DIRNAME=.
|
||||
@rem This is normally unused
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
"%COMSPEC%" /c exit 1
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
"%COMSPEC%" /c exit 1
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
|
||||
|
||||
@rem Execute gradlew
|
||||
@rem endlocal doesn't take effect until after the line is parsed and variables are expanded
|
||||
@rem which allows us to clear the local environment before executing the java command
|
||||
endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* & call :exitWithErrorLevel
|
||||
|
||||
:exitWithErrorLevel
|
||||
@rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts
|
||||
"%COMSPEC%" /c exit %ERRORLEVEL%
|
||||
@@ -0,0 +1,25 @@
|
||||
plugins {
|
||||
alias(libs.plugins.paperweight)
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain.languageVersion = JavaLanguageVersion.of(21)
|
||||
}
|
||||
|
||||
tasks.withType<JavaCompile>().configureEach {
|
||||
options.release = 21
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(":openinvapi")) {
|
||||
exclude(group = "org.spigotmc", module = "spigot-api")
|
||||
}
|
||||
implementation(project(":openinvcommon")) {
|
||||
exclude(group = "org.spigotmc", module = "spigot-api")
|
||||
}
|
||||
implementation(project(":openinvadapterpaper26_1")) {
|
||||
exclude(group = "io.papermc.paper", module = "dev-bundle")
|
||||
}
|
||||
|
||||
paperweight.paperDevBundle("1.21.11-R0.1-SNAPSHOT")
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package com.lishid.openinv.internal.paper1_21_11;
|
||||
|
||||
import com.github.jikoo.openinv.lang.LanguageManager;
|
||||
import com.lishid.openinv.internal.ISpecialEnderChest;
|
||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||
import com.lishid.openinv.internal.paper1_21_11.container.OpenEnderChest;
|
||||
import com.lishid.openinv.internal.paper1_21_11.container.OpenInventory;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@NullMarked
|
||||
public class InternalAccessor extends com.lishid.openinv.internal.paper26_1.InternalAccessor {
|
||||
|
||||
public InternalAccessor(Logger logger, LanguageManager lang) {
|
||||
super(logger, lang);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISpecialEnderChest createEnderChest(Player player) {
|
||||
return new OpenEnderChest(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISpecialPlayerInventory createPlayerInventory(Player player) {
|
||||
return new OpenInventory(factory, player);
|
||||
}
|
||||
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package com.lishid.openinv.internal.paper1_21_11.container;
|
||||
|
||||
import com.github.jikoo.openinv.internal.container.slot.InventoryFactory;
|
||||
import com.lishid.openinv.internal.paper1_21_11.container.menu.OpenEnderChestMenu;
|
||||
import com.lishid.openinv.internal.paper26_3.container.menu.OpenChestMenu;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
@NullMarked
|
||||
public class OpenEnderChest extends com.lishid.openinv.internal.paper26_3.container.OpenEnderChest {
|
||||
|
||||
public OpenEnderChest(org.bukkit.entity.Player player) {
|
||||
super(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable OpenChestMenu<?> createMenu(
|
||||
InventoryFactory<ServerPlayer, ItemStack, Container, Slot, EquipmentSlot> factory,
|
||||
Player player,
|
||||
int i,
|
||||
boolean viewOnly
|
||||
) {
|
||||
if (player instanceof ServerPlayer serverPlayer) {
|
||||
return new OpenEnderChestMenu(factory, this, serverPlayer, i, viewOnly);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package com.lishid.openinv.internal.paper1_21_11.container;
|
||||
|
||||
import com.github.jikoo.openinv.internal.container.slot.InventoryFactory;
|
||||
import com.lishid.openinv.internal.paper1_21_11.container.menu.OpenInventoryMenu;
|
||||
import com.lishid.openinv.internal.paper26_3.container.menu.OpenChestMenu;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
@NullMarked
|
||||
public class OpenInventory extends com.lishid.openinv.internal.paper26_3.container.OpenInventory {
|
||||
|
||||
public OpenInventory(
|
||||
InventoryFactory<ServerPlayer, ItemStack, Container, Slot, EquipmentSlot> factory,
|
||||
org.bukkit.entity.Player bukkitPlayer
|
||||
) {
|
||||
super(factory, bukkitPlayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable OpenChestMenu<?> createMenu(Player player, int i, boolean viewOnly) {
|
||||
if (player instanceof ServerPlayer serverPlayer) {
|
||||
return new OpenInventoryMenu(factory, this, serverPlayer, i, viewOnly);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
package com.lishid.openinv.internal.paper1_21_11.container.menu;
|
||||
|
||||
import com.github.jikoo.openinv.internal.container.slot.InventoryFactory;
|
||||
import com.lishid.openinv.internal.paper26_3.container.OpenEnderChest;
|
||||
import com.lishid.openinv.internal.paper26_3.container.menu.OpenSyncMenu;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.ClickType;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
@NullMarked
|
||||
public class OpenEnderChestMenu extends OpenSyncMenu<OpenEnderChest> {
|
||||
|
||||
public OpenEnderChestMenu(
|
||||
InventoryFactory<ServerPlayer, ItemStack, Container, Slot, EquipmentSlot> factory,
|
||||
OpenEnderChest enderChest,
|
||||
ServerPlayer viewer,
|
||||
int containerId,
|
||||
boolean viewOnly
|
||||
) {
|
||||
super(getChestMenuType(enderChest.getContainerSize()), containerId, factory, enderChest, viewer, viewOnly);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack quickMoveStack(Player player, int index) {
|
||||
if (viewOnly) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
// See ChestMenu
|
||||
Slot slot = this.slots.get(index);
|
||||
|
||||
if (slot.isFake() || !slot.hasItem()) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
ItemStack itemStack = slot.getItem();
|
||||
ItemStack original = itemStack.copy();
|
||||
|
||||
if (index < topSize) {
|
||||
if (!this.moveItemStackTo(itemStack, topSize, this.slots.size(), true)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
} else if (!this.moveItemStackTo(itemStack, 0, topSize, false)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
if (itemStack.isEmpty()) {
|
||||
slot.setByPlayer(ItemStack.EMPTY);
|
||||
} else {
|
||||
slot.setChanged();
|
||||
}
|
||||
|
||||
return original;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clicked(int i, int j, ClickType clickType, Player player) {
|
||||
if (viewOnly) {
|
||||
if (clickType == ClickType.QUICK_CRAFT) {
|
||||
sendAllDataToRemote();
|
||||
}
|
||||
return;
|
||||
}
|
||||
super.clicked(i, j, clickType, player);
|
||||
}
|
||||
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package com.lishid.openinv.internal.paper1_21_11.container.menu;
|
||||
|
||||
import com.github.jikoo.openinv.internal.container.slot.InventoryFactory;
|
||||
import com.lishid.openinv.internal.paper26_3.container.BaseOpenInventory;
|
||||
import com.lishid.openinv.internal.paper26_3.container.menu.BaseOpenInventoryMenu;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.ClickType;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
@NullMarked
|
||||
public class OpenInventoryMenu extends BaseOpenInventoryMenu {
|
||||
|
||||
public OpenInventoryMenu(
|
||||
InventoryFactory<ServerPlayer, ItemStack, Container, Slot, EquipmentSlot> factory,
|
||||
BaseOpenInventory inventory,
|
||||
ServerPlayer viewer,
|
||||
int i,
|
||||
boolean viewOnly
|
||||
) {
|
||||
super(factory, inventory, viewer, i, viewOnly);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clicked(int i, int j, ClickType clickType, Player player) {
|
||||
if (viewOnly) {
|
||||
if (clickType == ClickType.QUICK_CRAFT) {
|
||||
sendAllDataToRemote();
|
||||
}
|
||||
return;
|
||||
}
|
||||
super.clicked(i, j, clickType, player);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
plugins {
|
||||
alias(libs.plugins.paperweight)
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
}
|
||||
|
||||
// Paper is compiled with Java 25, so we have to use a Java 25 toolchain.
|
||||
java {
|
||||
toolchain.languageVersion.set(JavaLanguageVersion.of(25))
|
||||
}
|
||||
|
||||
// To minimize duplicate code, the adapter for 1.21.11 is built off of this module, so we need to target Java 21.
|
||||
tasks.withType<JavaCompile>().configureEach {
|
||||
options.release = 21
|
||||
}
|
||||
|
||||
// As a result, we have to specifically tell Gradle it's okay if our dependencies require Java 25,
|
||||
// because secretly sometimes they don't!
|
||||
configurations.matching { it.isCanBeResolved && it.name.endsWith("Classpath") }.all {
|
||||
attributes {
|
||||
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 25)
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(":openinvapi")) {
|
||||
exclude(group = "org.spigotmc", module = "spigot-api")
|
||||
}
|
||||
implementation(project(":openinvcommon")) {
|
||||
exclude(group = "org.spigotmc", module = "spigot-api")
|
||||
}
|
||||
api(project(":openinvadapterpaper26_2")) {
|
||||
exclude(group = "io.papermc.paper", module = "dev-bundle")
|
||||
}
|
||||
|
||||
paperweight.paperDevBundle("26.1.2.build.+")
|
||||
}
|
||||
|
||||
tasks.reobfJar {
|
||||
enabled = false
|
||||
}
|
||||
|
||||
configurations.reobf.get().outgoing.artifacts.clear()
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
package com.lishid.openinv.internal.paper26_1;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialEnderChest;
|
||||
import com.github.jikoo.openinv.internal.container.slot.InventoryFactory;
|
||||
import com.lishid.openinv.internal.paper26_1.container.AnySilentContainer;
|
||||
import com.lishid.openinv.internal.paper26_1.container.OpenEnderChest;
|
||||
import com.lishid.openinv.internal.paper26_1.player.PlayerManager;
|
||||
import com.lishid.openinv.internal.paper26_3.container.slot.placeholder.PlaceholderLoader;
|
||||
import com.github.jikoo.openinv.lang.LanguageManager;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@NullMarked
|
||||
public class InternalAccessor extends com.lishid.openinv.internal.paper26_2.InternalAccessor {
|
||||
|
||||
public InternalAccessor(Logger logger, LanguageManager lang) {
|
||||
super(logger, lang);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PlayerManager createPlayerManager(
|
||||
Logger logger,
|
||||
InventoryFactory<ServerPlayer, ItemStack, Container, Slot, EquipmentSlot> factory
|
||||
) {
|
||||
return new PlayerManager(logger, factory);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AnySilentContainer createAnySilentContainer(
|
||||
Logger logger,
|
||||
LanguageManager lang
|
||||
) {
|
||||
return new AnySilentContainer(logger, lang);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PlaceholderLoader createPlaceholderLoader() {
|
||||
return new com.lishid.openinv.internal.paper26_1.container.slot.placeholder.PlaceholderLoader();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISpecialEnderChest createEnderChest(Player player) {
|
||||
return new OpenEnderChest(player);
|
||||
}
|
||||
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package com.lishid.openinv.internal.paper26_1.container;
|
||||
|
||||
import com.github.jikoo.openinv.lang.LanguageManager;
|
||||
import net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@NullMarked
|
||||
public class AnySilentContainer extends com.lishid.openinv.internal.paper26_3.container.AnySilentContainer {
|
||||
|
||||
public AnySilentContainer(Logger logger, LanguageManager lang) {
|
||||
super(logger, lang);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hasLootTable(RandomizableContainerBlockEntity lootable) {
|
||||
return lootable.lootTable != null;
|
||||
}
|
||||
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package com.lishid.openinv.internal.paper26_1.container;
|
||||
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
@NullMarked
|
||||
public class OpenEnderChest extends com.lishid.openinv.internal.paper26_3.container.OpenEnderChest {
|
||||
|
||||
public OpenEnderChest(org.bukkit.entity.Player player) {
|
||||
super(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NonNullList<ItemStack> getEnderChestItems(ServerPlayer owner) {
|
||||
return owner.getEnderChestInventory().items;
|
||||
}
|
||||
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package com.lishid.openinv.internal.paper26_1.container.slot.placeholder;
|
||||
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.Items;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
@NullMarked
|
||||
public class PlaceholderLoader extends com.lishid.openinv.internal.paper26_3.container.slot.placeholder.PlaceholderLoader {
|
||||
|
||||
@Override
|
||||
protected Item getDefaultCursorItem() {
|
||||
return Items.WHITE_BANNER;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Item getDefaultNotSlotItem() {
|
||||
return Items.WHITE_STAINED_GLASS_PANE;
|
||||
}
|
||||
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
package com.lishid.openinv.internal.paper26_1.player;
|
||||
|
||||
import com.github.jikoo.openinv.internal.container.slot.InventoryFactory;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.storage.LevelData;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@NullMarked
|
||||
public class PlayerManager extends com.lishid.openinv.internal.paper26_3.player.PlayerManager {
|
||||
|
||||
public PlayerManager(
|
||||
Logger logger,
|
||||
InventoryFactory<ServerPlayer, ItemStack, Container, Slot, EquipmentSlot> factory
|
||||
) {
|
||||
super(logger, factory);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removeAdvancementListeners(ServerPlayer entity) {
|
||||
entity.getAdvancements().stopListening();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LevelData.RespawnData getRespawnData(ServerLevel level) {
|
||||
return level.levelData.getRespawnData();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Vec3 getAdjustedSpawnLocation(
|
||||
ServerPlayer player,
|
||||
ServerLevel level,
|
||||
LevelData.RespawnData respawnData
|
||||
) {
|
||||
return player.adjustSpawnLocation(level, respawnData.pos()).getBottomCenter();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setServerLevel(ServerPlayer player, ServerLevel level) {
|
||||
player.spawnIn(level);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
plugins {
|
||||
alias(libs.plugins.paperweight)
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
}
|
||||
|
||||
// Paper is compiled with Java 25, so we have to use a Java 25 toolchain.
|
||||
java {
|
||||
toolchain.languageVersion.set(JavaLanguageVersion.of(25))
|
||||
}
|
||||
|
||||
// To minimize duplicate code, the adapter for 1.21.11 is built off of this module, so we need to target Java 21.
|
||||
tasks.withType<JavaCompile>().configureEach {
|
||||
options.release = 21
|
||||
}
|
||||
|
||||
// As a result, we have to specifically tell Gradle it's okay if our dependencies require Java 25,
|
||||
// because secretly sometimes they don't!
|
||||
configurations.matching { it.isCanBeResolved && it.name.endsWith("Classpath") }.all {
|
||||
attributes {
|
||||
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 25)
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(":openinvapi")) {
|
||||
exclude(group = "org.spigotmc", module = "spigot-api")
|
||||
}
|
||||
implementation(project(":openinvcommon")) {
|
||||
exclude(group = "org.spigotmc", module = "spigot-api")
|
||||
}
|
||||
api(project(":openinvadapterpaper26_3")) {
|
||||
exclude(group = "io.papermc.paper", module = "dev-bundle")
|
||||
}
|
||||
|
||||
paperweight.paperDevBundle("26.2.build.+")
|
||||
}
|
||||
|
||||
tasks.reobfJar {
|
||||
enabled = false
|
||||
}
|
||||
|
||||
configurations.reobf.get().outgoing.artifacts.clear()
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package com.lishid.openinv.internal.paper26_2;
|
||||
|
||||
import com.github.jikoo.openinv.internal.container.slot.InventoryFactory;
|
||||
import com.lishid.openinv.internal.paper26_2.container.slot.OpenInventoryFactory;
|
||||
import com.github.jikoo.openinv.lang.LanguageManager;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@NullMarked
|
||||
public class InternalAccessor extends com.lishid.openinv.internal.paper26_3.InternalAccessor {
|
||||
|
||||
public InternalAccessor(Logger logger, LanguageManager lang) {
|
||||
super(logger, lang);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InventoryFactory<ServerPlayer, ItemStack, Container, Slot, EquipmentSlot> createInventoryFactory() {
|
||||
return new OpenInventoryFactory();
|
||||
}
|
||||
|
||||
}
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
package com.lishid.openinv.internal.paper26_2.container.slot;
|
||||
|
||||
import com.github.jikoo.openinv.internal.container.slot.Content;
|
||||
import com.lishid.openinv.internal.paper26_3.container.slot.ContentCrafting;
|
||||
import com.lishid.openinv.internal.paper26_3.container.slot.ContentCursor;
|
||||
import com.lishid.openinv.internal.paper26_3.container.slot.ContentDrop;
|
||||
import com.lishid.openinv.internal.paper26_3.container.slot.ContentViewOnly;
|
||||
import com.lishid.openinv.internal.paper26_3.container.slot.SlotViewOnly;
|
||||
import com.lishid.openinv.internal.paper26_3.container.slot.placeholder.Placeholders;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
@NullMarked
|
||||
public class OpenInventoryFactory extends com.lishid.openinv.internal.paper26_3.container.slot.OpenInventoryFactory {
|
||||
|
||||
@Override
|
||||
public Content<ServerPlayer, ItemStack, Container, Slot> newCrafting(
|
||||
ServerPlayer holder,
|
||||
int index
|
||||
) {
|
||||
return new ContentCrafting(holder, index) {
|
||||
@Override
|
||||
public void set(ItemStack itemStack) {
|
||||
if (isAvailable(holder)) {
|
||||
items.set(index, itemStack);
|
||||
holder.inventoryMenu.slotsChanged(holder.inventoryMenu.getCraftSlots());
|
||||
} else {
|
||||
this.holder.drop(itemStack, false);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Content<ServerPlayer, ItemStack, Container, Slot> newCursor(ServerPlayer holder) {
|
||||
return new ContentCursor(holder) {
|
||||
@Override
|
||||
public void set(ItemStack itemStack) {
|
||||
if (isAvailable()) {
|
||||
holder.containerMenu.setCarried(itemStack);
|
||||
} else {
|
||||
this.holder.drop(itemStack, false);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Content<ServerPlayer, ItemStack, Container, Slot> newDrop(ServerPlayer holder) {
|
||||
return new ContentDrop(holder) {
|
||||
@Override
|
||||
public void set(ItemStack itemStack) {
|
||||
this.holder.drop(itemStack, false);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Content<ServerPlayer, ItemStack, Container, Slot> newViewOnly(ServerPlayer holder) {
|
||||
return newViewOnly(holder, Placeholders.notSlot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Content<ServerPlayer, ItemStack, Container, Slot> newViewOnly(
|
||||
ServerPlayer holder,
|
||||
ItemStack itemStack
|
||||
) {
|
||||
return new ContentViewOnly(holder) {
|
||||
@Override
|
||||
public void set(ItemStack itemStack) {
|
||||
this.holder.drop(itemStack, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Slot asSlot(Container container, int slot, int x, int y) {
|
||||
return new SlotViewOnly(container, slot, x, y) {
|
||||
@Override
|
||||
public ItemStack getOrDefault() {
|
||||
return itemStack;
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.inventory.ItemStack asBukkitMirror(ItemStack itemStack) {
|
||||
return CraftItemStack.asCraftMirror(itemStack);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
plugins {
|
||||
alias(libs.plugins.paperweight)
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
}
|
||||
|
||||
// Paper is compiled with Java 25, so we have to use a Java 25 toolchain.
|
||||
java {
|
||||
toolchain.languageVersion.set(JavaLanguageVersion.of(25))
|
||||
}
|
||||
|
||||
// To minimize duplicate code, the adapter for 1.21.11 is built off of this module, so we need to target Java 21.
|
||||
tasks.withType<JavaCompile>().configureEach {
|
||||
options.release = 21
|
||||
}
|
||||
|
||||
// As a result, we have to specifically tell Gradle it's okay if our dependencies require Java 25,
|
||||
// because secretly sometimes they don't!
|
||||
configurations.matching { it.isCanBeResolved && it.name.endsWith("Classpath") }.all {
|
||||
attributes {
|
||||
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 25)
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(":openinvapi")) {
|
||||
exclude(group = "org.spigotmc", module = "spigot-api")
|
||||
}
|
||||
implementation(project(":openinvcommon")) {
|
||||
exclude(group = "org.spigotmc", module = "spigot-api")
|
||||
}
|
||||
|
||||
paperweight.paperDevBundle("26.3.build.+")
|
||||
}
|
||||
|
||||
tasks.reobfJar {
|
||||
enabled = false
|
||||
}
|
||||
|
||||
configurations.reobf.get().outgoing.artifacts.clear()
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
package com.lishid.openinv.internal.paper26_3;
|
||||
|
||||
import com.github.jikoo.openinv.internal.Accessor;
|
||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
||||
import com.lishid.openinv.internal.ISpecialEnderChest;
|
||||
import com.lishid.openinv.internal.ISpecialInventory;
|
||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||
import com.github.jikoo.openinv.internal.container.slot.InventoryFactory;
|
||||
import com.lishid.openinv.internal.paper26_3.container.AnySilentContainer;
|
||||
import com.lishid.openinv.internal.paper26_3.container.OpenEnderChest;
|
||||
import com.lishid.openinv.internal.paper26_3.container.OpenInventory;
|
||||
import com.lishid.openinv.internal.paper26_3.container.slot.OpenInventoryFactory;
|
||||
import com.lishid.openinv.internal.paper26_3.container.slot.placeholder.PlaceholderLoader;
|
||||
import com.lishid.openinv.internal.paper26_3.player.PlayerManager;
|
||||
import com.github.jikoo.openinv.lang.LanguageManager;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventory;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@NullMarked
|
||||
public class InternalAccessor implements Accessor {
|
||||
|
||||
protected final Logger logger;
|
||||
private final PlayerManager manager;
|
||||
protected final InventoryFactory<ServerPlayer, ItemStack, Container, Slot, EquipmentSlot> factory;
|
||||
private final AnySilentContainer anySilentContainer;
|
||||
|
||||
public InternalAccessor(Logger logger, LanguageManager lang) {
|
||||
this.logger = logger;
|
||||
factory = createInventoryFactory();
|
||||
manager = createPlayerManager(logger, factory);
|
||||
anySilentContainer = createAnySilentContainer(logger, lang);
|
||||
}
|
||||
|
||||
protected InventoryFactory<ServerPlayer, ItemStack, Container, Slot, EquipmentSlot> createInventoryFactory() {
|
||||
return new OpenInventoryFactory();
|
||||
}
|
||||
|
||||
protected PlayerManager createPlayerManager(
|
||||
Logger logger,
|
||||
InventoryFactory<ServerPlayer, ItemStack, Container, Slot, EquipmentSlot> factory
|
||||
) {
|
||||
return new PlayerManager(logger, factory);
|
||||
}
|
||||
|
||||
protected AnySilentContainer createAnySilentContainer(
|
||||
Logger logger,
|
||||
LanguageManager lang
|
||||
) {
|
||||
return new AnySilentContainer(logger, lang);
|
||||
}
|
||||
|
||||
protected PlaceholderLoader createPlaceholderLoader() {
|
||||
return new PlaceholderLoader();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerManager getPlayerManager() {
|
||||
return manager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAnySilentContainer getAnySilentContainer() {
|
||||
return anySilentContainer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISpecialPlayerInventory createPlayerInventory(Player player) {
|
||||
return new OpenInventory(factory, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISpecialEnderChest createEnderChest(Player player) {
|
||||
return new OpenEnderChest(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends ISpecialInventory> @Nullable T get(Inventory bukkitInventory, Class<T> clazz) {
|
||||
if (!(bukkitInventory instanceof CraftInventory craftInventory)) {
|
||||
return null;
|
||||
}
|
||||
Container container = craftInventory.getInventory();
|
||||
if (clazz.isInstance(container)) {
|
||||
return clazz.cast(container);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload(ConfigurationSection config) {
|
||||
ConfigurationSection placeholders = config.getConfigurationSection("placeholders");
|
||||
try {
|
||||
// Reset placeholders to defaults and try to load configuration.
|
||||
createPlaceholderLoader().load(placeholders);
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.WARNING, "Caught exception loading placeholder overrides!", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+233
@@ -0,0 +1,233 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2023 lishid. All rights reserved.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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.lishid.openinv.internal.paper26_3.container;
|
||||
|
||||
import com.github.jikoo.openinv.internal.container.AnySilentContainerBase;
|
||||
import com.lishid.openinv.internal.paper26_3.container.menu.OpenChestMenu;
|
||||
import com.lishid.openinv.internal.paper26_3.player.PlayerManager;
|
||||
import com.github.jikoo.openinv.util.ReflectionHelper;
|
||||
import com.github.jikoo.openinv.lang.LanguageManager;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.level.ServerPlayerGameMode;
|
||||
import net.minecraft.world.MenuProvider;
|
||||
import net.minecraft.world.SimpleMenuProvider;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.inventory.ChestMenu;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.inventory.PlayerEnderChestContainer;
|
||||
import net.minecraft.world.level.GameType;
|
||||
import net.minecraft.world.level.block.BarrelBlock;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.ChestBlock;
|
||||
import net.minecraft.world.level.block.ShulkerBoxBlock;
|
||||
import net.minecraft.world.level.block.TrappedChestBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.EnderChestBlockEntity;
|
||||
import net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Statistic;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@NullMarked
|
||||
public class AnySilentContainer extends AnySilentContainerBase {
|
||||
|
||||
private final Logger logger;
|
||||
private final LanguageManager lang;
|
||||
private @Nullable Field serverPlayerGameModeGameType;
|
||||
|
||||
public AnySilentContainer(Logger logger, LanguageManager lang) {
|
||||
this.logger = logger;
|
||||
this.lang = lang;
|
||||
try {
|
||||
try {
|
||||
this.serverPlayerGameModeGameType = ServerPlayerGameMode.class.getDeclaredField("gameModeForPlayer");
|
||||
this.serverPlayerGameModeGameType.setAccessible(true);
|
||||
} catch (NoSuchFieldException e) {
|
||||
logger.warning("The field ServerPlayerGameMode#gameModeForPlayer is no longer present!");
|
||||
logger.warning("Please report this at https://github.com/Jikoo/OpenInv/issues");
|
||||
logger.warning("Attempting to fall through using reflection. Please verify that SilentContainer does not fail.");
|
||||
// N.B. gameModeForPlayer is (for now) declared before previousGameModeForPlayer so silent shouldn't break.
|
||||
this.serverPlayerGameModeGameType = ReflectionHelper.grabFieldByType(ServerPlayerGameMode.class, GameType.class);
|
||||
}
|
||||
} catch (SecurityException e) {
|
||||
logger.warning("Unable to directly write player game mode! SilentContainer will fail.");
|
||||
logger.log(java.util.logging.Level.WARNING, "Error obtaining GameType field", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activateContainer(
|
||||
final Player bukkitPlayer,
|
||||
final boolean silentchest,
|
||||
final org.bukkit.block.Block bukkitBlock
|
||||
) {
|
||||
|
||||
// Silent ender chest is API-only
|
||||
if (silentchest && bukkitBlock.getType() == Material.ENDER_CHEST) {
|
||||
bukkitPlayer.openInventory(bukkitPlayer.getEnderChest());
|
||||
bukkitPlayer.incrementStatistic(Statistic.ENDERCHEST_OPENED);
|
||||
return true;
|
||||
}
|
||||
|
||||
ServerPlayer player = PlayerManager.getHandle(bukkitPlayer);
|
||||
|
||||
final net.minecraft.world.level.Level level = ((Entity) player).level();
|
||||
final BlockPos blockPos = new BlockPos(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
|
||||
final BlockEntity blockEntity = level.getBlockEntity(blockPos);
|
||||
|
||||
if (blockEntity == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (blockEntity instanceof EnderChestBlockEntity enderChestTile) {
|
||||
// Anychest ender chest. See net.minecraft.world.level.block.EnderChestBlock
|
||||
PlayerEnderChestContainer enderChest = player.getEnderChestInventory();
|
||||
enderChest.setActiveChest(enderChestTile);
|
||||
player.openMenu(
|
||||
new SimpleMenuProvider(
|
||||
(containerCounter, playerInventory, ignored) -> {
|
||||
MenuType<?> containers = OpenChestMenu.getChestMenuType(enderChest.getContainerSize());
|
||||
int rows = enderChest.getContainerSize() / 9;
|
||||
return new ChestMenu(containers, containerCounter, playerInventory, enderChest, rows);
|
||||
}, Component.translatable("container.enderchest")
|
||||
)
|
||||
);
|
||||
bukkitPlayer.incrementStatistic(Statistic.ENDERCHEST_OPENED);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(blockEntity instanceof @Nullable MenuProvider menuProvider)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
BlockState blockState = level.getBlockState(blockPos);
|
||||
Block block = blockState.getBlock();
|
||||
|
||||
if (block instanceof ChestBlock chestBlock) {
|
||||
|
||||
// boolean flag: do not check if chest is blocked
|
||||
menuProvider = chestBlock.getMenuProvider(blockState, level, blockPos, true);
|
||||
|
||||
if (menuProvider == null) {
|
||||
lang.sendSystemMessage(bukkitPlayer, "messages.error.lootNotGenerated");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (block instanceof TrappedChestBlock) {
|
||||
bukkitPlayer.incrementStatistic(Statistic.TRAPPED_CHEST_TRIGGERED);
|
||||
} else {
|
||||
bukkitPlayer.incrementStatistic(Statistic.CHEST_OPENED);
|
||||
}
|
||||
}
|
||||
|
||||
if (block instanceof ShulkerBoxBlock) {
|
||||
bukkitPlayer.incrementStatistic(Statistic.SHULKER_BOX_OPENED);
|
||||
}
|
||||
|
||||
if (block instanceof BarrelBlock) {
|
||||
bukkitPlayer.incrementStatistic(Statistic.OPEN_BARREL);
|
||||
}
|
||||
|
||||
// AnyChest only - SilentChest not active, container unsupported, or unnecessary.
|
||||
if (!silentchest || player.gameMode.getGameModeForPlayer() == GameType.SPECTATOR) {
|
||||
player.openMenu(menuProvider);
|
||||
return true;
|
||||
}
|
||||
|
||||
// SilentChest requires access to setting players' game mode directly.
|
||||
if (this.serverPlayerGameModeGameType == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (blockEntity instanceof RandomizableContainerBlockEntity lootable) {
|
||||
if (hasLootTable(lootable)) {
|
||||
lang.sendSystemMessage(bukkitPlayer, "messages.error.lootNotGenerated");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
GameType gameType = player.gameMode.getGameModeForPlayer();
|
||||
this.forceGameType(player, GameType.SPECTATOR);
|
||||
player.openMenu(menuProvider);
|
||||
this.forceGameType(player, gameType);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean hasLootTable(RandomizableContainerBlockEntity lootable) {
|
||||
return lootable.getLootTable() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deactivateContainer(final Player bukkitPlayer) {
|
||||
if (this.serverPlayerGameModeGameType == null || bukkitPlayer.getGameMode() == GameMode.SPECTATOR) {
|
||||
return;
|
||||
}
|
||||
|
||||
ServerPlayer player = PlayerManager.getHandle(bukkitPlayer);
|
||||
|
||||
// Force game mode change without informing plugins or players.
|
||||
// Regular game mode set calls GameModeChangeEvent and is cancellable.
|
||||
GameType gameType = player.gameMode.getGameModeForPlayer();
|
||||
this.forceGameType(player, GameType.SPECTATOR);
|
||||
|
||||
// ServerPlayer#closeContainer cannot be called without entering an
|
||||
// infinite loop because this method is called during inventory close.
|
||||
// From ServerPlayer#closeContainer -> CraftEventFactory#handleInventoryCloseEvent
|
||||
player.containerMenu.transferTo(player.inventoryMenu, player.getBukkitEntity());
|
||||
// From ServerPlayer#closeContainer
|
||||
player.doCloseContainer();
|
||||
// Regular inventory close will handle the rest - packet sending, etc.
|
||||
|
||||
// Revert forced game mode.
|
||||
this.forceGameType(player, gameType);
|
||||
}
|
||||
|
||||
private void forceGameType(final ServerPlayer player, final GameType gameMode) {
|
||||
if (this.serverPlayerGameModeGameType == null) {
|
||||
// No need to warn repeatedly, error on startup and lack of function should be enough.
|
||||
return;
|
||||
}
|
||||
try {
|
||||
this.serverPlayerGameModeGameType.setAccessible(true);
|
||||
this.serverPlayerGameModeGameType.set(player.gameMode, gameMode);
|
||||
} catch (IllegalArgumentException | IllegalAccessException e) {
|
||||
logger.log(java.util.logging.Level.WARNING, "Error bypassing GameModeChangeEvent", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected org.bukkit.block.BlockState getState(org.bukkit.block.Block block) {
|
||||
return block.getState(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nullable InventoryHolder getHolder(Inventory inventory) {
|
||||
return inventory.getHolder(false);
|
||||
}
|
||||
|
||||
}
|
||||
+313
@@ -0,0 +1,313 @@
|
||||
package com.lishid.openinv.internal.paper26_3.container;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||
import com.github.jikoo.openinv.internal.container.InternalOwned;
|
||||
import com.github.jikoo.openinv.internal.container.slot.Content;
|
||||
import com.github.jikoo.openinv.internal.container.slot.InventoryFactory;
|
||||
import com.lishid.openinv.internal.paper26_3.container.bukkit.OpenPlayerInventory;
|
||||
import com.lishid.openinv.internal.paper26_3.container.menu.OpenChestMenu;
|
||||
import com.lishid.openinv.internal.paper26_3.container.menu.OpenInventoryMenu;
|
||||
import com.lishid.openinv.internal.paper26_3.container.slot.placeholder.Placeholders;
|
||||
import com.lishid.openinv.internal.paper26_3.player.PlayerManager;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.entity.CraftHumanEntity;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventory;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@NullMarked
|
||||
public abstract class BaseOpenInventory implements Container, InternalOwned<ServerPlayer>, ISpecialPlayerInventory {
|
||||
|
||||
protected final InventoryFactory<ServerPlayer, ItemStack, Container, Slot, EquipmentSlot> factory;
|
||||
protected final List<Content<ServerPlayer, ItemStack, Container, Slot>> slots;
|
||||
private final int size;
|
||||
protected ServerPlayer owner;
|
||||
private int maxStackSize = 99;
|
||||
protected @Nullable CraftInventory bukkitEntity;
|
||||
public List<HumanEntity> transaction = new ArrayList<>();
|
||||
|
||||
public BaseOpenInventory(
|
||||
InventoryFactory<ServerPlayer, ItemStack, Container, Slot, EquipmentSlot> factory,
|
||||
org.bukkit.entity.Player bukkitPlayer
|
||||
) {
|
||||
this.factory = factory;
|
||||
owner = PlayerManager.getHandle(bukkitPlayer);
|
||||
|
||||
// Get total size, rounding up to nearest 9 for client compatibility.
|
||||
int rawSize = owner.getInventory().getContainerSize() + owner.inventoryMenu.getCraftSlots().getContainerSize() + 1;
|
||||
size = ((int) Math.ceil(rawSize / 9.0)) * 9;
|
||||
|
||||
slots = NonNullList.withSize(size, factory.newViewOnly(owner));
|
||||
setupSlots();
|
||||
}
|
||||
|
||||
protected void setupSlots() {
|
||||
// Top of inventory: Regular contents.
|
||||
int nextIndex = addMainInventory();
|
||||
|
||||
// If inventory is expected size, we can arrange slots to be pretty.
|
||||
Inventory ownerInv = owner.getInventory();
|
||||
if (ownerInv.getNonEquipmentItems().size() == 36
|
||||
&& owner.inventoryMenu.getCraftSlots().getContainerSize() == 4
|
||||
&& (Inventory.EQUIPMENT_SLOT_MAPPING.size() == 5 || Inventory.EQUIPMENT_SLOT_MAPPING.size() == 7)) {
|
||||
// Armor slots: Bottom left.
|
||||
addArmor(36);
|
||||
// Off-hand: Below chestplate.
|
||||
addOffHand(46);
|
||||
// Drop slot: Bottom right.
|
||||
slots.set(53, factory.newDrop(owner));
|
||||
// Cursor slot: Above drop.
|
||||
slots.set(44, factory.newCursor(owner));
|
||||
|
||||
// Crafting is displayed in the bottom right corner.
|
||||
// As we're using the pretty view, this is a 3x2.
|
||||
addCrafting(41, true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise we'll just add elements linearly.
|
||||
nextIndex = addArmor(nextIndex);
|
||||
nextIndex = addOffHand(nextIndex);
|
||||
nextIndex = addCrafting(nextIndex, false);
|
||||
slots.set(nextIndex, factory.newCursor(owner));
|
||||
// Drop slot last.
|
||||
slots.set(slots.size() - 1, factory.newDrop(owner));
|
||||
}
|
||||
|
||||
private int addMainInventory() {
|
||||
int listSize = owner.getInventory().getNonEquipmentItems().size();
|
||||
// Hotbar slots are 0-8. We want those to appear on the bottom of the inventory like a normal player inventory,
|
||||
// so everything else needs to move up a row.
|
||||
int hotbarDiff = listSize - 9;
|
||||
for (int localIndex = 0; localIndex < listSize; ++localIndex) {
|
||||
InventoryType.SlotType type;
|
||||
int invIndex;
|
||||
if (localIndex < hotbarDiff) {
|
||||
invIndex = localIndex + 9;
|
||||
type = InventoryType.SlotType.CONTAINER;
|
||||
} else {
|
||||
type = InventoryType.SlotType.QUICKBAR;
|
||||
invIndex = localIndex - hotbarDiff;
|
||||
}
|
||||
|
||||
slots.set(
|
||||
localIndex,
|
||||
factory.newList(owner, invIndex, type, holder -> holder.getInventory().getNonEquipmentItems())
|
||||
);
|
||||
}
|
||||
return listSize;
|
||||
}
|
||||
|
||||
private int addArmor(int startIndex) {
|
||||
// Armor slots go bottom to top; boots are first and helmet is last.
|
||||
// Since we have to display horizontally due to space restrictions,
|
||||
// making the left side the "top" is more user-friendly.
|
||||
EquipmentSlot[] sorted = Inventory.EQUIPMENT_SLOT_MAPPING.int2ObjectEntrySet()
|
||||
.stream()
|
||||
.sorted(Comparator.comparingInt(Int2ObjectMap.Entry::getIntKey))
|
||||
.map(Map.Entry::getValue)
|
||||
.toArray(EquipmentSlot[]::new);
|
||||
int localIndex = 0;
|
||||
for (int i = sorted.length - 1; i >= 0; --i) {
|
||||
// Skip off-hand, handled separately. Also skip non-player slots.
|
||||
if (sorted[i].getType() != EquipmentSlot.Type.HUMANOID_ARMOR) {
|
||||
continue;
|
||||
}
|
||||
|
||||
slots.set(startIndex + localIndex, factory.newEquipment(owner, sorted[i]));
|
||||
++localIndex;
|
||||
}
|
||||
|
||||
return startIndex + localIndex;
|
||||
}
|
||||
|
||||
private int addOffHand(int startIndex) {
|
||||
// No off-hand?
|
||||
if (!Inventory.EQUIPMENT_SLOT_MAPPING.containsValue(EquipmentSlot.OFFHAND)) {
|
||||
return startIndex;
|
||||
}
|
||||
|
||||
slots.set(startIndex, factory.newOffHand(owner));
|
||||
return startIndex + 1;
|
||||
}
|
||||
|
||||
private int addCrafting(int startIndex, boolean pretty) {
|
||||
int listSize = owner.inventoryMenu.getCraftSlots().getContents().size();
|
||||
pretty &= listSize == 4;
|
||||
|
||||
for (int localIndex = 0; localIndex < listSize; ++localIndex) {
|
||||
// Pretty display is a 2x2 rather than linear.
|
||||
// If index is in top row, grid is not 2x2, or pretty is disabled, just use current index.
|
||||
// Otherwise, subtract 2 and add 9 to start in the same position on the next row.
|
||||
int modIndex = startIndex + (localIndex < 2 || !pretty ? localIndex : localIndex + 7);
|
||||
|
||||
slots.set(modIndex, factory.newCrafting(owner, localIndex));
|
||||
}
|
||||
|
||||
if (pretty) {
|
||||
slots.set(startIndex + 2, factory.newViewOnly(owner, Placeholders.craftingOutput));
|
||||
slots.set(startIndex + 11, factory.newCraftingResult(owner));
|
||||
}
|
||||
|
||||
return startIndex + listSize;
|
||||
}
|
||||
|
||||
public Slot getMenuSlot(int index, int x, int y) {
|
||||
return slots.get(index).asSlot(this, index, x, y);
|
||||
}
|
||||
|
||||
public InventoryType.SlotType getSlotType(int index) {
|
||||
return slots.get(index).getSlotType();
|
||||
}
|
||||
|
||||
public abstract Component getTitle(ServerPlayer player, @Nullable OpenChestMenu<?> menu);
|
||||
|
||||
@Override
|
||||
public ServerPlayer getOwnerHandle() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.inventory.Inventory getBukkitInventory() {
|
||||
if (bukkitEntity == null) {
|
||||
bukkitEntity = new OpenPlayerInventory(this);
|
||||
}
|
||||
return bukkitEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(org.bukkit.entity.Player player) {
|
||||
ServerPlayer newOwner = PlayerManager.getHandle(player);
|
||||
// Only transfer regular inventory - crafting and cursor slots are transient.
|
||||
newOwner.getInventory().replaceWith(owner.getInventory());
|
||||
owner = newOwner;
|
||||
// Update slots to point to new inventory.
|
||||
slots.forEach(slot -> slot.setHolder(newOwner));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !transaction.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Player getPlayer() {
|
||||
return getOwner();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getContainerSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return slots.stream().map(Content::get).allMatch(ItemStack::isEmpty);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int index) {
|
||||
return slots.get(index).get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItem(int index, int amount) {
|
||||
return slots.get(index).removePartial(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItemNoUpdate(int index) {
|
||||
return slots.get(index).remove();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int index, ItemStack itemStack) {
|
||||
slots.get(index).set(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxStackSize() {
|
||||
return maxStackSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxStackSize(int maxStackSize) {
|
||||
this.maxStackSize = maxStackSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChanged() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stillValid(Player player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getContents() {
|
||||
NonNullList<ItemStack> contents = NonNullList.withSize(getContainerSize(), ItemStack.EMPTY);
|
||||
for (int i = 0; i < getContainerSize(); ++i) {
|
||||
contents.set(i, getItem(i));
|
||||
}
|
||||
return contents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(CraftHumanEntity viewer) {
|
||||
transaction.add(viewer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(CraftHumanEntity viewer) {
|
||||
transaction.remove(viewer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HumanEntity> getViewers() {
|
||||
return transaction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Player getOwner() {
|
||||
return owner.getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return owner.getBukkitEntity().getLocation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearContent() {
|
||||
owner.getInventory().clearContent();
|
||||
owner.inventoryMenu.getCraftSlots().clearContent();
|
||||
owner.inventoryMenu.slotsChanged(owner.inventoryMenu.getCraftSlots());
|
||||
owner.containerMenu.setCarried(ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
public @Nullable OpenChestMenu<?> createMenu(Player player, int i, boolean viewOnly) {
|
||||
if (player instanceof ServerPlayer serverPlayer) {
|
||||
return new OpenInventoryMenu(factory, this, serverPlayer, i, viewOnly);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+214
@@ -0,0 +1,214 @@
|
||||
package com.lishid.openinv.internal.paper26_3.container;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialEnderChest;
|
||||
import com.github.jikoo.openinv.internal.container.InternalOwned;
|
||||
import com.github.jikoo.openinv.internal.container.slot.InventoryFactory;
|
||||
import com.lishid.openinv.internal.paper26_3.container.menu.OpenChestMenu;
|
||||
import com.lishid.openinv.internal.paper26_3.container.menu.OpenEnderChestMenu;
|
||||
import com.lishid.openinv.internal.paper26_3.player.PlayerManager;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.ContainerHelper;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.entity.player.StackedItemContents;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.inventory.StackedContentsCompatible;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.entity.CraftHumanEntity;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventory;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@NullMarked
|
||||
public class OpenEnderChest implements Container, StackedContentsCompatible, InternalOwned<ServerPlayer>,
|
||||
ISpecialEnderChest {
|
||||
|
||||
private @Nullable CraftInventory inventory;
|
||||
private ServerPlayer owner;
|
||||
private NonNullList<ItemStack> items;
|
||||
private int maxStack = 64;
|
||||
private final List<HumanEntity> transaction = new ArrayList<>();
|
||||
|
||||
public OpenEnderChest(org.bukkit.entity.Player player) {
|
||||
this.owner = PlayerManager.getHandle(player);
|
||||
this.items = getEnderChestItems(owner);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerPlayer getOwnerHandle() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.inventory.Inventory getBukkitInventory() {
|
||||
if (inventory == null) {
|
||||
inventory = new CraftInventory(this) {
|
||||
@Override
|
||||
public InventoryType getType() {
|
||||
return InventoryType.ENDER_CHEST;
|
||||
}
|
||||
};
|
||||
}
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(org.bukkit.entity.Player player) {
|
||||
owner = PlayerManager.getHandle(player);
|
||||
NonNullList<ItemStack> activeItems = getEnderChestItems(owner);
|
||||
|
||||
// Guard against size changing. Theoretically on Purpur all row variations still have 6 rows internally.
|
||||
int max = Math.min(items.size(), activeItems.size());
|
||||
for (int index = 0; index < max; ++index) {
|
||||
activeItems.set(index, items.get(index));
|
||||
}
|
||||
|
||||
items = activeItems;
|
||||
}
|
||||
|
||||
protected NonNullList<ItemStack> getEnderChestItems(ServerPlayer owner) {
|
||||
return owner.getEnderChestInventory().getItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Player getPlayer() {
|
||||
return owner.getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getContainerSize() {
|
||||
return items.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return items.stream().allMatch(ItemStack::isEmpty);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int index) {
|
||||
return index >= 0 && index < items.size() ? items.get(index) : ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItem(int index, int amount) {
|
||||
ItemStack itemstack = ContainerHelper.removeItem(items, index, amount);
|
||||
|
||||
if (!itemstack.isEmpty()) {
|
||||
setChanged();
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItemNoUpdate(int index) {
|
||||
return index >= 0 && index < items.size() ? items.set(index, ItemStack.EMPTY) : ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int index, ItemStack itemStack) {
|
||||
if (index >= 0 && index < items.size()) {
|
||||
items.set(index, itemStack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxStackSize() {
|
||||
return maxStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChanged() {
|
||||
this.owner.getEnderChestInventory().setChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stillValid(Player player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getContents() {
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(CraftHumanEntity craftHumanEntity) {
|
||||
transaction.add(craftHumanEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(CraftHumanEntity craftHumanEntity) {
|
||||
transaction.remove(craftHumanEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HumanEntity> getViewers() {
|
||||
return transaction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Player getOwner() {
|
||||
return getPlayer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxStackSize(int size) {
|
||||
maxStack = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Location getLocation() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearContent() {
|
||||
items.clear();
|
||||
setChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillStackedContents(StackedItemContents stackedContents) {
|
||||
for (ItemStack itemstack : items) {
|
||||
stackedContents.accountStack(itemstack);
|
||||
}
|
||||
}
|
||||
|
||||
public Component getTitle(@Nullable OpenChestMenu<?> menu) {
|
||||
MutableComponent component;
|
||||
if (menu != null && menu.isViewOnly()) {
|
||||
component = Component.translatableWithFallback("openinv.container.enderchest.viewonly", "[RO] ");
|
||||
} else {
|
||||
component = Component.translatableWithFallback("openinv.container.enderchest.editable", "");
|
||||
}
|
||||
return component
|
||||
.append(Component.translatableWithFallback("openinv.container.enderchest.prefix", "", owner.getName()))
|
||||
.append(Component.translatable("container.enderchest"))
|
||||
.append(Component.translatableWithFallback("openinv.container.enderchest.suffix", " - %s", owner.getName()));
|
||||
}
|
||||
|
||||
public @Nullable OpenChestMenu<?> createMenu(
|
||||
InventoryFactory<ServerPlayer, ItemStack, Container, Slot, EquipmentSlot> factory,
|
||||
Player player,
|
||||
int i,
|
||||
boolean viewOnly
|
||||
) {
|
||||
if (player instanceof ServerPlayer serverPlayer) {
|
||||
return new OpenEnderChestMenu(factory, this, serverPlayer, i, viewOnly);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
package com.lishid.openinv.internal.paper26_3.container;
|
||||
|
||||
import com.github.jikoo.openinv.internal.container.slot.InventoryFactory;
|
||||
import com.lishid.openinv.internal.paper26_3.container.menu.OpenChestMenu;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.FontDescription;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
@NullMarked
|
||||
public class OpenInventory extends BaseOpenInventory {
|
||||
|
||||
public OpenInventory(
|
||||
InventoryFactory<ServerPlayer, ItemStack, Container, Slot, EquipmentSlot> factory,
|
||||
Player bukkitPlayer
|
||||
) {
|
||||
super(factory, bukkitPlayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getTitle(@Nullable ServerPlayer viewer, @Nullable OpenChestMenu<?> menu) {
|
||||
MutableComponent component = Component.empty();
|
||||
// Prefix for use with custom bitmap image fonts.
|
||||
if (owner.equals(viewer)) {
|
||||
component.append(
|
||||
Component.translatableWithFallback("openinv.container.inventory.self", "")
|
||||
.withStyle(style -> style
|
||||
.withFont(new FontDescription.Resource(Identifier.parse("openinv:font/inventory")))
|
||||
.withColor(ChatFormatting.WHITE)));
|
||||
} else {
|
||||
component.append(
|
||||
Component.translatableWithFallback("openinv.container.inventory.other", "")
|
||||
.withStyle(style -> style
|
||||
.withFont(new FontDescription.Resource(Identifier.parse("openinv:font/inventory")))
|
||||
.withColor(ChatFormatting.WHITE)));
|
||||
}
|
||||
if (menu != null && menu.isViewOnly()) {
|
||||
component.append(Component.translatableWithFallback("openinv.container.inventory.viewonly", "[RO] "));
|
||||
} else {
|
||||
component.append(Component.translatableWithFallback("openinv.container.inventory.editable", ""));
|
||||
}
|
||||
// Normal title: "Inventory - OwnerName"
|
||||
component.append(Component.translatableWithFallback("openinv.container.inventory.prefix", "", owner.getName()))
|
||||
.append(Component.translatable("container.inventory"))
|
||||
.append(Component.translatableWithFallback("openinv.container.inventory.suffix", " - %s", owner.getName()));
|
||||
return component;
|
||||
}
|
||||
|
||||
}
|
||||
+174
@@ -0,0 +1,174 @@
|
||||
package com.lishid.openinv.internal.paper26_3.container.bukkit;
|
||||
|
||||
import com.github.jikoo.openinv.internal.container.ViewOnly;
|
||||
import net.minecraft.world.Container;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventory;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.ListIterator;
|
||||
|
||||
/**
|
||||
* A locked down "empty" inventory that rejects plugin interaction.
|
||||
*/
|
||||
@NullMarked
|
||||
public class OpenDummyInventory extends CraftInventory implements ViewOnly {
|
||||
|
||||
private final InventoryType type;
|
||||
|
||||
public OpenDummyInventory(Container inventory, InventoryType type) {
|
||||
super(inventory);
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ItemStack getItem(int index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int index, @Nullable ItemStack item) {
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("NonApiType")
|
||||
@Override
|
||||
public HashMap<Integer, ItemStack> addItem(ItemStack... items) throws IllegalArgumentException {
|
||||
return arrayToHashMap(items);
|
||||
}
|
||||
|
||||
@SuppressWarnings("NonApiType")
|
||||
@Override
|
||||
public HashMap<Integer, ItemStack> removeItem(ItemStack... items) throws IllegalArgumentException {
|
||||
return arrayToHashMap(items);
|
||||
}
|
||||
|
||||
@SuppressWarnings("NonApiType")
|
||||
private static HashMap<Integer, ItemStack> arrayToHashMap(ItemStack[] items) {
|
||||
HashMap<Integer, ItemStack> ignored = new HashMap<>();
|
||||
for (int index = 0; index < items.length; ++index) {
|
||||
ignored.put(index, items[index]);
|
||||
}
|
||||
return ignored;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
return new ItemStack[getSize()];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContents(ItemStack[] items) throws IllegalArgumentException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getStorageContents() {
|
||||
return new ItemStack[getSize()];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStorageContents(ItemStack[] items) throws IllegalArgumentException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Material material) throws IllegalArgumentException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(@Nullable ItemStack item) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Material material, int amount) throws IllegalArgumentException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(@Nullable ItemStack item, int amount) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAtLeast(@Nullable ItemStack item, int amount) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("NonApiType")
|
||||
@Override
|
||||
public HashMap<Integer, ItemStack> all(
|
||||
Material material
|
||||
) throws IllegalArgumentException {
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
@SuppressWarnings("NonApiType")
|
||||
@Override
|
||||
public HashMap<Integer, ItemStack> all(@Nullable ItemStack item) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int first(Material material) throws IllegalArgumentException {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int first(ItemStack item) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int firstEmpty() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(Material material) throws IllegalArgumentException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(ItemStack item) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear(int index) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListIterator<ItemStack> iterator() {
|
||||
return Collections.emptyListIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListIterator<ItemStack> iterator(int index) {
|
||||
return Collections.emptyListIterator();
|
||||
}
|
||||
|
||||
}
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
package com.lishid.openinv.internal.paper26_3.container.bukkit;
|
||||
|
||||
import net.minecraft.world.Container;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
@NullMarked
|
||||
public class OpenDummyPlayerInventory extends OpenDummyInventory implements PlayerInventory {
|
||||
|
||||
public OpenDummyPlayerInventory(Container inventory) {
|
||||
super(inventory, InventoryType.PLAYER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HumanEntity getHolder() {
|
||||
return (HumanEntity) super.getHolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getArmorContents() {
|
||||
return new ItemStack[4];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getExtraContents() {
|
||||
return new ItemStack[4];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getHelmet() {
|
||||
return ItemStack.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getChestplate() {
|
||||
return ItemStack.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getLeggings() {
|
||||
return ItemStack.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getBoots() {
|
||||
return ItemStack.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(EquipmentSlot slot, @Nullable ItemStack item) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(EquipmentSlot slot) {
|
||||
return ItemStack.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setArmorContents(@Nullable ItemStack[] items) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setExtraContents(@Nullable ItemStack[] items) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHelmet(@Nullable ItemStack helmet) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChestplate(@Nullable ItemStack chestplate) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLeggings(@Nullable ItemStack leggings) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBoots(@Nullable ItemStack boots) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemInMainHand() {
|
||||
return ItemStack.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemInMainHand(@Nullable ItemStack item) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemInOffHand() {
|
||||
return ItemStack.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemInOffHand(@Nullable ItemStack item) {
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("InlineMeSuggester")
|
||||
@Deprecated
|
||||
@Override
|
||||
public ItemStack getItemInHand() {
|
||||
return ItemStack.empty();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public void setItemInHand(@Nullable ItemStack stack) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeldItemSlot() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHeldItemSlot(int slot) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+218
@@ -0,0 +1,218 @@
|
||||
package com.lishid.openinv.internal.paper26_3.container.bukkit;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.lishid.openinv.internal.paper26_3.container.BaseOpenInventory;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventory;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@NullMarked
|
||||
public class OpenPlayerInventory extends CraftInventory implements PlayerInventory {
|
||||
|
||||
public OpenPlayerInventory(BaseOpenInventory inventory) {
|
||||
super(inventory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseOpenInventory getInventory() {
|
||||
return (BaseOpenInventory) super.getInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
return asCraftMirror(getInventory().getOwnerHandle().getInventory().getContents());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContents(@Nullable ItemStack[] items) {
|
||||
Inventory internal = getInventory().getOwnerHandle().getInventory();
|
||||
int size = internal.getContainerSize();
|
||||
Preconditions.checkArgument(items.length <= size, "items.length must be <= %s", size);
|
||||
|
||||
for (int index = 0; index < size; ++index) {
|
||||
if (index < items.length) {
|
||||
internal.setItem(index, CraftItemStack.asNMSCopy(items[index]));
|
||||
} else {
|
||||
internal.setItem(index, net.minecraft.world.item.ItemStack.EMPTY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getStorageContents() {
|
||||
return asCraftMirror(getInventory().getOwnerHandle().getInventory().getNonEquipmentItems());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStorageContents(@Nullable ItemStack[] items) throws IllegalArgumentException {
|
||||
NonNullList<net.minecraft.world.item.ItemStack> list = getInventory().getOwnerHandle().getInventory().getNonEquipmentItems();
|
||||
int size = list.size();
|
||||
Preconditions.checkArgument(items.length <= size, "items.length must be <= %s", size);
|
||||
for (int index = 0; index < items.length; ++index) {
|
||||
list.set(index, CraftItemStack.asNMSCopy(items[index]));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryType getType() {
|
||||
return InventoryType.PLAYER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Player getHolder() {
|
||||
return getInventory().getOwner();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getArmorContents() {
|
||||
return asCraftMirror(getInventory().getOwnerHandle().getInventory().getArmorContents());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setArmorContents(@Nullable ItemStack[] items) {
|
||||
int size = Inventory.EQUIPMENT_SLOTS_SORTED_BY_INDEX.length;
|
||||
Preconditions.checkArgument(items.length <= size, "items.length must be <= %s", size);
|
||||
for (int index = 0; index < items.length; ++index) {
|
||||
getInventory().getOwnerHandle().getInventory().equipment.set(
|
||||
Inventory.EQUIPMENT_SLOTS_SORTED_BY_INDEX[index],
|
||||
CraftItemStack.asNMSCopy(items[index])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getExtraContents() {
|
||||
return asCraftMirror(List.of(getInventory().getOwnerHandle().getInventory().equipment.get(EquipmentSlot.OFFHAND)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setExtraContents(@Nullable ItemStack[] items) {
|
||||
Preconditions.checkArgument(items.length <= 1, "items.length must be <= 1");
|
||||
for (ItemStack item : items) {
|
||||
getInventory().getOwnerHandle().getInventory().equipment.set(EquipmentSlot.OFFHAND, CraftItemStack.asNMSCopy(item));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getHelmet() {
|
||||
return getInventory().getOwner().getInventory().getHelmet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHelmet(@Nullable ItemStack helmet) {
|
||||
getInventory().getOwner().getInventory().setHelmet(helmet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getChestplate() {
|
||||
return getInventory().getOwner().getInventory().getChestplate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChestplate(@Nullable ItemStack chestplate) {
|
||||
getInventory().getOwner().getInventory().setChestplate(chestplate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getLeggings() {
|
||||
return getInventory().getOwner().getInventory().getLeggings();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLeggings(@Nullable ItemStack leggings) {
|
||||
getInventory().getOwner().getInventory().setLeggings(leggings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getBoots() {
|
||||
return getInventory().getOwner().getInventory().getBoots();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBoots(@Nullable ItemStack boots) {
|
||||
getInventory().getOwner().getInventory().setBoots(boots);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemInMainHand() {
|
||||
return getInventory().getOwner().getInventory().getItemInMainHand();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemInMainHand(@Nullable ItemStack item) {
|
||||
getInventory().getOwner().getInventory().setItemInMainHand(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemInOffHand() {
|
||||
return getInventory().getOwner().getInventory().getItemInOffHand();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemInOffHand(@Nullable ItemStack item) {
|
||||
getInventory().getOwner().getInventory().setItemInOffHand(item);
|
||||
}
|
||||
|
||||
@SuppressWarnings("InlineMeSuggester")
|
||||
@Deprecated
|
||||
@Override
|
||||
public ItemStack getItemInHand() {
|
||||
return getItemInMainHand();
|
||||
}
|
||||
|
||||
@SuppressWarnings("InlineMeSuggester")
|
||||
@Deprecated
|
||||
@Override
|
||||
public void setItemInHand(@Nullable ItemStack stack) {
|
||||
setItemInMainHand(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeldItemSlot() {
|
||||
Inventory internal = getInventory().getOwnerHandle().getInventory();
|
||||
return internal.getNonEquipmentItems().size() - 9 + internal.getSelectedSlot();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHeldItemSlot(int slot) {
|
||||
slot %= 9;
|
||||
getInventory().getOwnerHandle().getInventory().setSelectedSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(org.bukkit.inventory.EquipmentSlot slot) {
|
||||
return switch (slot) {
|
||||
case HAND -> getItemInMainHand();
|
||||
case OFF_HAND -> getItemInOffHand();
|
||||
case FEET -> getBoots();
|
||||
case LEGS -> getLeggings();
|
||||
case CHEST -> getChestplate();
|
||||
case HEAD -> getHelmet();
|
||||
default -> throw new IllegalArgumentException("Unsupported EquipmentSlot " + slot);
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(org.bukkit.inventory.EquipmentSlot slot, @Nullable ItemStack item) {
|
||||
switch (slot) {
|
||||
case HAND -> setItemInMainHand(item);
|
||||
case OFF_HAND -> setItemInOffHand(item);
|
||||
case FEET -> setBoots(item);
|
||||
case LEGS -> setLeggings(item);
|
||||
case CHEST -> setChestplate(item);
|
||||
case HEAD -> setHelmet(item);
|
||||
default -> throw new IllegalArgumentException("Unsupported EquipmentSlot " + slot);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package com.lishid.openinv.internal.paper26_3.container.bukkit;
|
||||
|
||||
import com.lishid.openinv.internal.paper26_3.container.BaseOpenInventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
@NullMarked
|
||||
public class OpenPlayerInventorySelf extends OpenPlayerInventory {
|
||||
|
||||
private final int offset;
|
||||
|
||||
public OpenPlayerInventorySelf(BaseOpenInventory inventory, int offset) {
|
||||
super(inventory);
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ItemStack getItem(int index) {
|
||||
return super.getItem(offset + index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int index, @Nullable ItemStack item) {
|
||||
super.setItem(offset + index, item);
|
||||
}
|
||||
|
||||
}
|
||||
+273
@@ -0,0 +1,273 @@
|
||||
package com.lishid.openinv.internal.paper26_3.container.menu;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.github.jikoo.openinv.internal.container.slot.InventoryFactory;
|
||||
import com.lishid.openinv.internal.paper26_3.container.BaseOpenInventory;
|
||||
import com.lishid.openinv.internal.paper26_3.container.bukkit.OpenDummyPlayerInventory;
|
||||
import com.lishid.openinv.internal.paper26_3.container.bukkit.OpenPlayerInventorySelf;
|
||||
import com.lishid.openinv.internal.paper26_3.container.slot.ContentDrop;
|
||||
import com.lishid.openinv.internal.paper26_3.container.slot.SlotEquipment;
|
||||
import com.lishid.openinv.internal.paper26_3.container.slot.SlotViewOnly;
|
||||
import com.lishid.openinv.util.Permissions;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.ChestMenu;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventoryView;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
@NullMarked
|
||||
public class BaseOpenInventoryMenu extends OpenSyncMenu<BaseOpenInventory> {
|
||||
|
||||
private int offset;
|
||||
|
||||
public BaseOpenInventoryMenu(
|
||||
InventoryFactory<ServerPlayer, ItemStack, Container, Slot, EquipmentSlot> factory,
|
||||
BaseOpenInventory inventory,
|
||||
ServerPlayer viewer,
|
||||
int i,
|
||||
boolean viewOnly
|
||||
) {
|
||||
super(getMenuType(inventory, viewer), i, factory, inventory, viewer, viewOnly);
|
||||
}
|
||||
|
||||
private static MenuType<ChestMenu> getMenuType(BaseOpenInventory inventory, ServerPlayer viewer) {
|
||||
int size = inventory.getContainerSize();
|
||||
// Disallow duplicate access to own main inventory contents.
|
||||
if (inventory.getOwnerHandle().equals(viewer)) {
|
||||
size -= viewer.getInventory().getNonEquipmentItems().size();
|
||||
size = ((int) Math.ceil(size / 9.0)) * 9;
|
||||
}
|
||||
|
||||
return getChestMenuType(size);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void preSlotSetup() {
|
||||
offset = ownContainer ? viewer.getInventory().getNonEquipmentItems().size() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Slot getUpperSlot(int index, int x, int y) {
|
||||
index += offset;
|
||||
Slot slot = container.getMenuSlot(index, x, y);
|
||||
|
||||
// If the slot cannot be interacted with there's nothing to configure.
|
||||
if (slot.getClass().equals(SlotViewOnly.class)) {
|
||||
return slot;
|
||||
}
|
||||
|
||||
// Remove drop slot if viewer is not allowed to use it.
|
||||
if (slot instanceof ContentDrop.SlotDrop
|
||||
&& (viewOnly || !Permissions.INVENTORY_SLOT_DROP.hasPermission(viewer.getBukkitEntity()))) {
|
||||
return new SlotViewOnly(container, index, x, y);
|
||||
}
|
||||
|
||||
if (slot instanceof SlotEquipment equipment) {
|
||||
if (viewOnly) {
|
||||
return factory.wrapViewOnly(slot);
|
||||
}
|
||||
|
||||
Permissions perm = switch (equipment.getEquipmentSlot()) {
|
||||
case HEAD -> Permissions.INVENTORY_SLOT_HEAD_ANY;
|
||||
case CHEST -> Permissions.INVENTORY_SLOT_CHEST_ANY;
|
||||
case LEGS -> Permissions.INVENTORY_SLOT_LEGS_ANY;
|
||||
case FEET -> Permissions.INVENTORY_SLOT_FEET_ANY;
|
||||
// Off-hand can hold anything, not just equipment.
|
||||
default -> null;
|
||||
};
|
||||
|
||||
// If the viewer doesn't have permission, only allow equipment the viewee can equip in the slot.
|
||||
if (perm != null && !perm.hasPermission(viewer.getBukkitEntity())) {
|
||||
equipment.onlyEquipmentFor(container.getOwnerHandle());
|
||||
}
|
||||
|
||||
// Equipment slots are a core part of the inventory, so they will always be shown.
|
||||
return slot;
|
||||
}
|
||||
|
||||
// When viewing own inventory, only allow access to equipment and drop slots (equipment allowed above).
|
||||
if (ownContainer && !(slot instanceof ContentDrop.SlotDrop)) {
|
||||
return new SlotViewOnly(container, index, x, y);
|
||||
}
|
||||
|
||||
if (viewOnly) {
|
||||
return factory.wrapViewOnly(slot);
|
||||
}
|
||||
|
||||
return slot;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CraftInventoryView<OpenChestMenu<BaseOpenInventory>, Inventory> createBukkitEntity() {
|
||||
org.bukkit.inventory.Inventory bukkitInventory;
|
||||
if (viewOnly) {
|
||||
bukkitInventory = new OpenDummyPlayerInventory(container);
|
||||
} else if (ownContainer) {
|
||||
bukkitInventory = new OpenPlayerInventorySelf(container, offset);
|
||||
} else {
|
||||
bukkitInventory = container.getBukkitInventory();
|
||||
}
|
||||
|
||||
return new CraftInventoryView<>(viewer.getBukkitEntity(), bukkitInventory, this) {
|
||||
@Override
|
||||
public org.bukkit.inventory.@Nullable ItemStack getItem(int index) {
|
||||
if (viewOnly || index < 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Slot slot = slots.get(index);
|
||||
return factory.asBukkitMirror(slot.hasItem() ? slot.getItem() : ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInTop(int rawSlot) {
|
||||
return rawSlot < topSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Inventory getInventory(int rawSlot) {
|
||||
if (viewOnly) {
|
||||
return null;
|
||||
}
|
||||
if (rawSlot == InventoryView.OUTSIDE || rawSlot == -1) {
|
||||
return null;
|
||||
}
|
||||
Preconditions.checkArgument(
|
||||
rawSlot >= 0 && rawSlot < topSize + offset + BOTTOM_INVENTORY_SIZE,
|
||||
"Slot %s outside of inventory",
|
||||
rawSlot
|
||||
);
|
||||
if (rawSlot > topSize) {
|
||||
return getBottomInventory();
|
||||
}
|
||||
Slot slot = slots.get(rawSlot);
|
||||
if (slot.isFake()) {
|
||||
return null;
|
||||
}
|
||||
return getTopInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int convertSlot(int rawSlot) {
|
||||
if (viewOnly) {
|
||||
return InventoryView.OUTSIDE;
|
||||
}
|
||||
if (rawSlot < 0) {
|
||||
return rawSlot;
|
||||
}
|
||||
if (rawSlot < topSize) {
|
||||
Slot slot = slots.get(rawSlot);
|
||||
if (slot.isFake()) {
|
||||
return InventoryView.OUTSIDE;
|
||||
}
|
||||
return rawSlot;
|
||||
}
|
||||
|
||||
int slot = rawSlot - topSize;
|
||||
|
||||
if (slot >= 27) {
|
||||
slot -= 27;
|
||||
} else {
|
||||
slot += 9;
|
||||
}
|
||||
|
||||
return slot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryType.SlotType getSlotType(int slot) {
|
||||
if (viewOnly || slot < 0) {
|
||||
return InventoryType.SlotType.OUTSIDE;
|
||||
}
|
||||
if (slot >= topSize) {
|
||||
slot -= topSize;
|
||||
if (slot >= 27) {
|
||||
return InventoryType.SlotType.QUICKBAR;
|
||||
}
|
||||
return InventoryType.SlotType.CONTAINER;
|
||||
}
|
||||
return BaseOpenInventoryMenu.this.container.getSlotType(offset + slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int countSlots() {
|
||||
return topSize + BOTTOM_INVENTORY_SIZE;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack quickMoveStack(Player player, int index) {
|
||||
if (viewOnly) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
// See ChestMenu and InventoryMenu
|
||||
Slot slot = this.slots.get(index);
|
||||
|
||||
if (!slot.hasItem() || slot.isFake()) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
ItemStack itemStack = slot.getItem();
|
||||
ItemStack originalStack = itemStack.copy();
|
||||
|
||||
if (index < topSize) {
|
||||
// If we're moving top to bottom, do a normal transfer.
|
||||
if (!this.moveItemStackTo(itemStack, topSize, this.slots.size(), true)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
} else {
|
||||
EquipmentSlot equipmentSlot = player.getEquipmentSlotForItem(itemStack);
|
||||
boolean movedGear = switch (equipmentSlot) {
|
||||
// If this is gear, try to move it to the correct slot first.
|
||||
case OFFHAND, FEET, LEGS, CHEST, HEAD -> {
|
||||
// Locate the correct slot in the contents following the main inventory.
|
||||
for (int extra = container.getOwnerHandle().getInventory().getNonEquipmentItems().size() - offset; extra < topSize; ++extra) {
|
||||
Slot extraSlot = getSlot(extra);
|
||||
if (extraSlot instanceof SlotEquipment equipSlot
|
||||
&& equipSlot.getEquipmentSlot() == equipmentSlot) {
|
||||
// If we've found a matching slot, try to move to it.
|
||||
// If this succeeds, even partially, we will not attempt to move to other slots.
|
||||
// Otherwise, armor is already occupied, so we'll fall through to main inventory.
|
||||
yield this.moveItemStackTo(itemStack, extra, extra + 1, false);
|
||||
}
|
||||
}
|
||||
yield false;
|
||||
}
|
||||
// Non-gear gets no special treatment.
|
||||
default -> false;
|
||||
};
|
||||
|
||||
// If main inventory is not available, there's nowhere else to move.
|
||||
if (offset != 0) {
|
||||
if (!movedGear) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
} else {
|
||||
// If we didn't move to a gear slot, try to move to a main inventory slot.
|
||||
if (!movedGear && !this.moveItemStackTo(itemStack, 0, container.getOwnerHandle().getInventory().getNonEquipmentItems().size(), true)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (itemStack.isEmpty()) {
|
||||
slot.setByPlayer(ItemStack.EMPTY);
|
||||
} else {
|
||||
slot.setChanged();
|
||||
}
|
||||
|
||||
return originalStack;
|
||||
}
|
||||
|
||||
}
|
||||
+281
@@ -0,0 +1,281 @@
|
||||
package com.lishid.openinv.internal.paper26_3.container.menu;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialInventory;
|
||||
import com.github.jikoo.openinv.internal.container.InternalOwned;
|
||||
import com.github.jikoo.openinv.internal.container.slot.InventoryFactory;
|
||||
import com.lishid.openinv.internal.paper26_3.container.bukkit.OpenDummyInventory;
|
||||
import com.lishid.openinv.internal.paper26_3.container.slot.SlotViewOnly;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.ChestMenu;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventoryView;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* An extension of {@link AbstractContainerMenu} storing and managing data common to all special inventories.
|
||||
*/
|
||||
@NullMarked
|
||||
public abstract class OpenChestMenu<T extends Container & ISpecialInventory & InternalOwned<ServerPlayer>>
|
||||
extends AbstractContainerMenu {
|
||||
|
||||
protected static final int BOTTOM_INVENTORY_SIZE = 36;
|
||||
|
||||
protected final InventoryFactory<ServerPlayer, ItemStack, Container, Slot, EquipmentSlot> factory;
|
||||
protected final T container;
|
||||
protected final ServerPlayer viewer;
|
||||
protected final boolean viewOnly;
|
||||
protected final boolean ownContainer;
|
||||
protected final int topSize;
|
||||
private @Nullable CraftInventoryView<OpenChestMenu<T>, Inventory> bukkitEntity;
|
||||
|
||||
protected OpenChestMenu(
|
||||
MenuType<ChestMenu> type,
|
||||
int containerCounter,
|
||||
InventoryFactory<ServerPlayer, ItemStack, Container, Slot, EquipmentSlot> factory,
|
||||
T container,
|
||||
ServerPlayer viewer,
|
||||
boolean viewOnly
|
||||
) {
|
||||
super(type, containerCounter);
|
||||
this.factory = factory;
|
||||
this.container = container;
|
||||
this.viewer = viewer;
|
||||
this.viewOnly = viewOnly;
|
||||
ownContainer = container.getOwnerHandle().equals(viewer);
|
||||
topSize = getTopSize(viewer);
|
||||
|
||||
preSlotSetup();
|
||||
|
||||
int upperRows = topSize / 9;
|
||||
// View's upper inventory - our container
|
||||
for (int row = 0; row < upperRows; ++row) {
|
||||
for (int col = 0; col < 9; ++col) {
|
||||
// x and y for client purposes, but hey, we're thorough here.
|
||||
// Adapted from net.minecraft.world.inventory.ChestMenu
|
||||
int x = 8 + col * 18;
|
||||
int y = 18 + row * 18;
|
||||
int index = row * 9 + col;
|
||||
|
||||
// Guard against weird inventory sizes.
|
||||
if (index >= container.getContainerSize()) {
|
||||
addSlot(new SlotViewOnly(container, index, x, y));
|
||||
continue;
|
||||
}
|
||||
|
||||
Slot slot = getUpperSlot(index, x, y);
|
||||
|
||||
addSlot(slot);
|
||||
}
|
||||
}
|
||||
|
||||
// View's lower inventory - viewer inventory
|
||||
int playerInvPad = (upperRows - 4) * 18;
|
||||
for (int row = 0; row < 3; ++row) {
|
||||
for (int col = 0; col < 9; ++col) {
|
||||
int x = 8 + col * 18;
|
||||
int y = playerInvPad + row * 18 + 103;
|
||||
addSlot(new Slot(viewer.getInventory(), row * 9 + col + 9, x, y));
|
||||
}
|
||||
}
|
||||
// Hotbar
|
||||
for (int col = 0; col < 9; ++col) {
|
||||
int x = 8 + col * 18;
|
||||
int y = playerInvPad + 161;
|
||||
addSlot(new Slot(viewer.getInventory(), col, x, y));
|
||||
}
|
||||
}
|
||||
|
||||
public static MenuType<ChestMenu> getChestMenuType(int inventorySize) {
|
||||
inventorySize = ((int) Math.ceil(inventorySize / 9.0)) * 9;
|
||||
return switch (inventorySize) {
|
||||
case 9 -> MenuType.GENERIC_9x1;
|
||||
case 18 -> MenuType.GENERIC_9x2;
|
||||
case 27 -> MenuType.GENERIC_9x3;
|
||||
case 36 -> MenuType.GENERIC_9x4;
|
||||
case 45 -> MenuType.GENERIC_9x5;
|
||||
case 54 -> MenuType.GENERIC_9x6;
|
||||
default -> throw new IllegalArgumentException("Inventory size unsupported: " + inventorySize);
|
||||
};
|
||||
}
|
||||
|
||||
protected void preSlotSetup() {
|
||||
}
|
||||
|
||||
protected Slot getUpperSlot(int index, int x, int y) {
|
||||
Slot slot = new Slot(container, index, x, y);
|
||||
if (viewOnly) {
|
||||
return factory.wrapViewOnly(slot);
|
||||
}
|
||||
return slot;
|
||||
}
|
||||
|
||||
public boolean isViewOnly() {
|
||||
return viewOnly;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final CraftInventoryView<OpenChestMenu<T>, Inventory> getBukkitView() {
|
||||
if (bukkitEntity == null) {
|
||||
bukkitEntity = createBukkitEntity();
|
||||
}
|
||||
|
||||
return bukkitEntity;
|
||||
}
|
||||
|
||||
protected CraftInventoryView<OpenChestMenu<T>, Inventory> createBukkitEntity() {
|
||||
Inventory top;
|
||||
if (viewOnly) {
|
||||
top = new OpenDummyInventory(container, container.getBukkitType());
|
||||
} else {
|
||||
top = container.getBukkitInventory();
|
||||
}
|
||||
return new CraftInventoryView<>(viewer.getBukkitEntity(), top, this) {
|
||||
@Override
|
||||
public @Nullable Inventory getInventory(int rawSlot) {
|
||||
if (viewOnly) {
|
||||
return null;
|
||||
}
|
||||
return super.getInventory(rawSlot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int convertSlot(int rawSlot) {
|
||||
if (viewOnly) {
|
||||
return InventoryView.OUTSIDE;
|
||||
}
|
||||
return super.convertSlot(rawSlot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryType.SlotType getSlotType(int slot) {
|
||||
if (viewOnly) {
|
||||
return InventoryType.SlotType.OUTSIDE;
|
||||
}
|
||||
return super.getSlotType(slot);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private int getTopSize(ServerPlayer viewer) {
|
||||
MenuType<?> menuType = getType();
|
||||
if (MenuType.GENERIC_9x1.equals(menuType)) {
|
||||
return 9;
|
||||
} else if (MenuType.GENERIC_9x2.equals(menuType)) {
|
||||
return 18;
|
||||
} else if (MenuType.GENERIC_9x3.equals(menuType)) {
|
||||
return 27;
|
||||
} else if (MenuType.GENERIC_9x4.equals(menuType)) {
|
||||
return 36;
|
||||
} else if (MenuType.GENERIC_9x5.equals(menuType)) {
|
||||
return 45;
|
||||
} else if (MenuType.GENERIC_9x6.equals(menuType)) {
|
||||
return 54;
|
||||
}
|
||||
// This is a bit gross, but allows us a safe fallthrough.
|
||||
return menuType.create(-1, viewer.getInventory()).slots.size() - BOTTOM_INVENTORY_SIZE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reimplementation of {@link AbstractContainerMenu#moveItemStackTo(ItemStack, int, int, boolean)} that ignores fake
|
||||
* slots and respects {@link Slot#hasItem()}.
|
||||
*
|
||||
* @param itemStack the stack to quick-move
|
||||
* @param rangeLow the start of the range of slots that can be moved to, inclusive
|
||||
* @param rangeHigh the end of the range of slots that can be moved to, exclusive
|
||||
* @param topDown whether to start at the top of the range or bottom
|
||||
* @return whether the stack was modified as a result of being quick-moved
|
||||
*/
|
||||
@Override
|
||||
protected boolean moveItemStackTo(ItemStack itemStack, int rangeLow, int rangeHigh, boolean topDown) {
|
||||
boolean modified = false;
|
||||
boolean stackable = itemStack.isStackable();
|
||||
Slot firstEmpty = null;
|
||||
|
||||
for (int index = topDown ? rangeHigh - 1 : rangeLow;
|
||||
!itemStack.isEmpty() && (topDown ? index >= rangeLow : index < rangeHigh);
|
||||
index += topDown ? -1 : 1
|
||||
) {
|
||||
Slot slot = slots.get(index);
|
||||
// If the slot cannot be added to, check the next slot.
|
||||
if (slot.isFake() || !slot.mayPlace(itemStack)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (slot.hasItem()) {
|
||||
// If the item isn't stackable, check the next slot.
|
||||
if (!stackable) {
|
||||
continue;
|
||||
}
|
||||
// Otherwise, add as many as we can from our stack to the slot.
|
||||
modified |= addToExistingStack(itemStack, slot);
|
||||
} else {
|
||||
// If this is the first empty slot, keep track of it for later use.
|
||||
if (firstEmpty == null) {
|
||||
firstEmpty = slot;
|
||||
}
|
||||
// If the item isn't stackable, we've located the slot we're adding it to, so we're done.
|
||||
if (!stackable) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If the item hasn't been fully added yet, add as many as we can to the first open slot.
|
||||
if (!itemStack.isEmpty() && firstEmpty != null) {
|
||||
firstEmpty.setByPlayer(itemStack.split(Math.min(itemStack.getCount(), firstEmpty.getMaxStackSize(itemStack))));
|
||||
firstEmpty.setChanged();
|
||||
modified = true;
|
||||
}
|
||||
|
||||
return modified;
|
||||
}
|
||||
|
||||
private static boolean addToExistingStack(ItemStack itemStack, Slot slot) {
|
||||
ItemStack existing = slot.getItem();
|
||||
|
||||
// If the items aren't the same, we can't add our item.
|
||||
if (!ItemStack.isSameItemSameComponents(itemStack, existing)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int max = slot.getMaxStackSize(existing);
|
||||
int existingCount = existing.getCount();
|
||||
|
||||
// If the stack is already full, we can't add more.
|
||||
if (existingCount >= max) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int total = existingCount + itemStack.getCount();
|
||||
|
||||
// If the existing item can accept the entirety of our item, we're done!
|
||||
if (total <= max) {
|
||||
itemStack.setCount(0);
|
||||
existing.setCount(total);
|
||||
slot.setChanged();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Otherwise, add as many as we can.
|
||||
itemStack.shrink(max - existingCount);
|
||||
existing.setCount(max);
|
||||
slot.setChanged();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stillValid(Player player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
package com.lishid.openinv.internal.paper26_3.container.menu;
|
||||
|
||||
import com.github.jikoo.openinv.internal.container.slot.InventoryFactory;
|
||||
import com.lishid.openinv.internal.paper26_3.container.OpenEnderChest;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.ContainerInput;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
@NullMarked
|
||||
public class OpenEnderChestMenu extends OpenSyncMenu<OpenEnderChest> {
|
||||
|
||||
public OpenEnderChestMenu(
|
||||
InventoryFactory<ServerPlayer, ItemStack, Container, Slot, EquipmentSlot> factory,
|
||||
OpenEnderChest enderChest,
|
||||
ServerPlayer viewer,
|
||||
int containerId,
|
||||
boolean viewOnly
|
||||
) {
|
||||
super(getChestMenuType(enderChest.getContainerSize()), containerId, factory, enderChest, viewer, viewOnly);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack quickMoveStack(Player player, int index) {
|
||||
if (viewOnly) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
// See ChestMenu
|
||||
Slot slot = this.slots.get(index);
|
||||
|
||||
if (slot.isFake() || !slot.hasItem()) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
ItemStack itemStack = slot.getItem();
|
||||
ItemStack original = itemStack.copy();
|
||||
|
||||
if (index < topSize) {
|
||||
if (!this.moveItemStackTo(itemStack, topSize, this.slots.size(), true)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
} else if (!this.moveItemStackTo(itemStack, 0, topSize, false)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
if (itemStack.isEmpty()) {
|
||||
slot.setByPlayer(ItemStack.EMPTY);
|
||||
} else {
|
||||
slot.setChanged();
|
||||
}
|
||||
|
||||
return original;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clicked(int slotIndex, int buttonNum, ContainerInput containerInput, Player player) {
|
||||
if (viewOnly) {
|
||||
if (containerInput == ContainerInput.QUICK_CRAFT) {
|
||||
sendAllDataToRemote();
|
||||
}
|
||||
}
|
||||
super.clicked(slotIndex, buttonNum, containerInput, player);
|
||||
}
|
||||
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package com.lishid.openinv.internal.paper26_3.container.menu;
|
||||
|
||||
import com.github.jikoo.openinv.internal.container.slot.InventoryFactory;
|
||||
import com.lishid.openinv.internal.paper26_3.container.BaseOpenInventory;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.ContainerInput;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
@NullMarked
|
||||
public class OpenInventoryMenu extends BaseOpenInventoryMenu {
|
||||
|
||||
public OpenInventoryMenu(
|
||||
InventoryFactory<ServerPlayer, ItemStack, Container, Slot, EquipmentSlot> factory,
|
||||
BaseOpenInventory inventory,
|
||||
ServerPlayer viewer,
|
||||
int i,
|
||||
boolean viewOnly
|
||||
) {
|
||||
super(factory, inventory, viewer, i, viewOnly);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clicked(int slotIndex, int buttonNum, ContainerInput containerInput, Player player) {
|
||||
if (viewOnly) {
|
||||
if (containerInput == ContainerInput.QUICK_CRAFT) {
|
||||
sendAllDataToRemote();
|
||||
}
|
||||
}
|
||||
super.clicked(slotIndex, buttonNum, containerInput, player);
|
||||
}
|
||||
|
||||
}
|
||||
+169
@@ -0,0 +1,169 @@
|
||||
package com.lishid.openinv.internal.paper26_3.container.menu;
|
||||
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.lishid.openinv.internal.ISpecialInventory;
|
||||
import com.github.jikoo.openinv.internal.container.InternalOwned;
|
||||
import com.github.jikoo.openinv.internal.container.slot.InventoryFactory;
|
||||
import com.lishid.openinv.internal.paper26_3.container.slot.SlotPlaceholder;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.ChestMenu;
|
||||
import net.minecraft.world.inventory.ContainerListener;
|
||||
import net.minecraft.world.inventory.ContainerSynchronizer;
|
||||
import net.minecraft.world.inventory.DataSlot;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.inventory.RemoteSlot;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* An extension of {@link OpenChestMenu} that supports {@link SlotPlaceholder placeholders}.
|
||||
*/
|
||||
@NullMarked
|
||||
public abstract class OpenSyncMenu<T extends Container & ISpecialInventory & InternalOwned<ServerPlayer>>
|
||||
extends OpenChestMenu<T> {
|
||||
|
||||
// Syncher fields required to send placeholder items.
|
||||
// All fields intentionally shadow AbstractContainerMenu fields so that warnings
|
||||
// will be generated if they are no longer necessary.
|
||||
protected @Nullable ContainerSynchronizer synchronizer;
|
||||
protected final List<ContainerListener> listeners = new ArrayList<>();
|
||||
private @Nullable RemoteSlot remoteCarried = RemoteSlot.PLACEHOLDER;
|
||||
protected boolean suppressRemoteUpdates;
|
||||
|
||||
protected OpenSyncMenu(
|
||||
MenuType<ChestMenu> type,
|
||||
int containerCounter,
|
||||
InventoryFactory<ServerPlayer, ItemStack, Container, Slot, EquipmentSlot> factory,
|
||||
T container,
|
||||
ServerPlayer viewer,
|
||||
boolean viewOnly
|
||||
) {
|
||||
super(type, containerCounter, factory, container, viewer, viewOnly);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void broadcastChanges() {
|
||||
for (int index = 0; index < this.slots.size(); ++index) {
|
||||
Slot slot = this.slots.get(index);
|
||||
ItemStack itemstack = slot instanceof SlotPlaceholder placeholder ? placeholder.getOrDefault() : slot.getItem();
|
||||
Supplier<ItemStack> supplier = Suppliers.memoize(itemstack::copy);
|
||||
this.triggerSlotListeners(index, itemstack, supplier);
|
||||
this.synchronizeSlotToRemote(index, itemstack, supplier);
|
||||
}
|
||||
|
||||
// See private synchronizeCarriedToRemote
|
||||
if (!suppressRemoteUpdates && !getRemoteCarried().matches(getCarried())) {
|
||||
this.broadcastCarriedItem();
|
||||
}
|
||||
|
||||
for (int index = 0; index < this.dataSlots.size(); ++index) {
|
||||
DataSlot dataSlot = this.dataSlots.get(index);
|
||||
int current = dataSlot.get();
|
||||
if (dataSlot.checkAndClearUpdateFlag()) {
|
||||
// See private updateDataSlotListeners
|
||||
for (ContainerListener containerListener : this.listeners) {
|
||||
containerListener.dataChanged(this, index, current);
|
||||
}
|
||||
}
|
||||
|
||||
// See private synchronizeDataSlotToRemote
|
||||
if (!suppressRemoteUpdates && remoteDataSlots.getInt(index) != current) {
|
||||
remoteDataSlots.set(index, current);
|
||||
if (synchronizer != null) {
|
||||
synchronizer.sendDataChange(this, index, current);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendAllDataToRemote() {
|
||||
List<ItemStack> contentsCopy = new ArrayList<>();
|
||||
for (int index = 0; index < slots.size(); ++index) {
|
||||
Slot slot = slots.get(index);
|
||||
ItemStack itemStack = slot instanceof SlotPlaceholder placeholder ? placeholder.getOrDefault() : slot.getItem();
|
||||
contentsCopy.add(itemStack.copy());
|
||||
this.remoteSlots.get(index).force(itemStack);
|
||||
}
|
||||
|
||||
getRemoteCarried().force(getCarried());
|
||||
|
||||
for (int index = 0; index < this.dataSlots.size(); ++index) {
|
||||
this.remoteDataSlots.set(index, this.dataSlots.get(index).get());
|
||||
}
|
||||
|
||||
if (this.synchronizer != null) {
|
||||
this.synchronizer.sendInitialData(this, contentsCopy, this.getCarried().copy(), this.remoteDataSlots.toIntArray());
|
||||
this.synchronizer.sendOffHandSlotChange();
|
||||
}
|
||||
}
|
||||
|
||||
protected RemoteSlot getRemoteCarried() {
|
||||
if (remoteCarried != null) {
|
||||
return remoteCarried;
|
||||
}
|
||||
|
||||
try {
|
||||
Field remoteCarried = AbstractContainerMenu.class.getDeclaredField("remoteCarried");
|
||||
remoteCarried.setAccessible(true);
|
||||
Object slot = remoteCarried.get(this);
|
||||
if (slot instanceof RemoteSlot remoteSlot) {
|
||||
this.remoteCarried = remoteSlot;
|
||||
} else {
|
||||
this.remoteCarried = RemoteSlot.PLACEHOLDER;
|
||||
}
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
remoteCarried = RemoteSlot.PLACEHOLDER;
|
||||
}
|
||||
|
||||
return remoteCarried;
|
||||
}
|
||||
|
||||
// Overrides from here on are purely to capture the contents of fields that aren't exposed.
|
||||
// Note that super calls should likely always be last! Some send data to remotes after updating state.
|
||||
@Override
|
||||
public void addSlotListener(ContainerListener containerListener) {
|
||||
if (!this.listeners.contains(containerListener)) {
|
||||
this.listeners.add(containerListener);
|
||||
}
|
||||
super.addSlotListener(containerListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSynchronizer(ContainerSynchronizer containerSynchronizer) {
|
||||
this.synchronizer = containerSynchronizer;
|
||||
// Unset carried slot so we re-capture it when sending slots.
|
||||
// setSynchronizer calls sendAllDataToRemote, so we can't just do the reflection here once after the fact.
|
||||
this.remoteCarried = null;
|
||||
super.setSynchronizer(containerSynchronizer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeSlotListener(ContainerListener containerListener) {
|
||||
this.listeners.remove(containerListener);
|
||||
super.removeSlotListener(containerListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void suppressRemoteUpdates() {
|
||||
this.suppressRemoteUpdates = true;
|
||||
super.suppressRemoteUpdates();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resumeRemoteUpdates() {
|
||||
this.suppressRemoteUpdates = false;
|
||||
super.resumeRemoteUpdates();
|
||||
}
|
||||
|
||||
}
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
package com.lishid.openinv.internal.paper26_3.container.slot;
|
||||
|
||||
import com.github.jikoo.openinv.internal.container.slot.Content;
|
||||
import com.lishid.openinv.internal.paper26_3.container.slot.placeholder.Placeholders;
|
||||
import com.lishid.openinv.internal.paper26_3.player.OpenPlayer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.util.Prediction;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.ContainerHelper;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A slot in a survival crafting inventory. Unavailable when not online in a survival mode.
|
||||
*/
|
||||
@NullMarked
|
||||
public class ContentCrafting implements Content<ServerPlayer, ItemStack, Container, Slot> {
|
||||
|
||||
private final int index;
|
||||
protected ServerPlayer holder;
|
||||
protected List<ItemStack> items;
|
||||
|
||||
protected ContentCrafting(ServerPlayer holder, int index) {
|
||||
setHolder(holder);
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public static boolean isAvailable(ServerPlayer holder) {
|
||||
// Player must be online and not in creative - since the creative client is (semi-)authoritative,
|
||||
// it ignores changes without extra help, and will delete the item as a result.
|
||||
// Spectator mode is technically possible but may cause the item to be dropped if the client opens an inventory.
|
||||
return OpenPlayer.isConnected(holder.connection) && holder.gameMode.isSurvival();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHolder(ServerPlayer holder) {
|
||||
this.holder = holder;
|
||||
// Note: CraftingContainer#getItems is immutable! Be careful with updates.
|
||||
this.items = holder.inventoryMenu.getCraftSlots().getContents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack get() {
|
||||
return isAvailable(holder) ? items.get(index) : ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack remove() {
|
||||
if (!isAvailable(holder)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
ItemStack removed = items.remove(index);
|
||||
if (removed.isEmpty()) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
holder.inventoryMenu.slotsChanged(holder.inventoryMenu.getCraftSlots());
|
||||
return removed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removePartial(int amount) {
|
||||
if (!isAvailable(holder)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
ItemStack removed = ContainerHelper.removeItem(items, index, amount);
|
||||
if (removed.isEmpty()) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
holder.inventoryMenu.slotsChanged(holder.inventoryMenu.getCraftSlots());
|
||||
return removed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(ItemStack itemStack) {
|
||||
if (isAvailable(holder)) {
|
||||
items.set(index, itemStack);
|
||||
holder.inventoryMenu.slotsChanged(holder.inventoryMenu.getCraftSlots());
|
||||
} else {
|
||||
this.holder.drop(itemStack, false, Prediction.SERVER_ONLY);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Slot asSlot(Container container, int slot, int x, int y) {
|
||||
return new SlotCrafting(container, slot, x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryType.SlotType getSlotType() {
|
||||
return isAvailable(holder) ? InventoryType.SlotType.CRAFTING : InventoryType.SlotType.OUTSIDE;
|
||||
}
|
||||
|
||||
public class SlotCrafting extends SlotPlaceholder {
|
||||
|
||||
private SlotCrafting(Container container, int index, int x, int y) {
|
||||
super(container, index, x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getOrDefault() {
|
||||
return isAvailable(holder) ? items.get(ContentCrafting.this.index) : Placeholders.survivalOnly(holder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mayPickup(Player player) {
|
||||
return isAvailable(holder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mayPlace(ItemStack itemStack) {
|
||||
return isAvailable(holder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasItem() {
|
||||
return isAvailable(holder) && super.hasItem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFake() {
|
||||
return !isAvailable(holder);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
package com.lishid.openinv.internal.paper26_3.container.slot;
|
||||
|
||||
import com.lishid.openinv.internal.paper26_3.container.slot.placeholder.Placeholders;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.inventory.InventoryMenu;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
/**
|
||||
* A slot allowing viewing of the crafting result.
|
||||
*
|
||||
* <p>Unmodifiable because I said so. Use your own crafting grid.</p>
|
||||
*/
|
||||
@NullMarked
|
||||
class ContentCraftingResult extends ContentViewOnly {
|
||||
|
||||
ContentCraftingResult(ServerPlayer holder) {
|
||||
super(holder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack get() {
|
||||
InventoryMenu inventoryMenu = holder.inventoryMenu;
|
||||
return inventoryMenu.getResultSlot().getItem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Slot asSlot(Container container, int slot, int x, int y) {
|
||||
return new SlotViewOnly(container, slot, x, y) {
|
||||
@Override
|
||||
public ItemStack getOrDefault() {
|
||||
if (!ContentCrafting.isAvailable(holder)) {
|
||||
return Placeholders.survivalOnly(holder);
|
||||
}
|
||||
InventoryMenu inventoryMenu = holder.inventoryMenu;
|
||||
return inventoryMenu.getResultSlot().getItem();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryType.SlotType getSlotType() {
|
||||
return InventoryType.SlotType.RESULT;
|
||||
}
|
||||
|
||||
}
|
||||
Loaded 100 of 370 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user