mirror of https://github.com/taoneill/war.git
Compare commits
705 Commits
Author | SHA1 | Date |
---|---|---|
|
7b982c2687 | |
|
3217c0a732 | |
|
2e6466fab2 | |
|
98afe494c1 | |
|
20e3e70461 | |
|
26acfa6a53 | |
|
3470a0cc54 | |
|
66ef1b9cc2 | |
|
0dde3acaed | |
|
03c9ad95ee | |
|
87cea1a1b4 | |
|
2af9379287 | |
|
b24e495df7 | |
|
6b90371fce | |
|
81f839a0a2 | |
|
8b76d2068f | |
|
99b6bdb3dd | |
|
a0174935fe | |
|
5e4f0022df | |
|
db7a7864f9 | |
|
7f7babf104 | |
|
bca78e5d0c | |
|
4e83ffada1 | |
|
69a148fc6a | |
|
0a02e25f4a | |
|
0babe82368 | |
|
47be664a93 | |
|
821c66c556 | |
|
22cbba62b3 | |
|
eb7b600aef | |
|
4f00befeb2 | |
|
f6b41bd015 | |
|
f1caca70f5 | |
|
e45b0eb0bb | |
|
910310aab4 | |
|
8ce9586b8d | |
|
0f09410c66 | |
|
57d29f464c | |
|
9135e5bf22 | |
|
994fec5a14 | |
|
d3b5795dda | |
|
a4038c6df1 | |
|
200bb5a3c0 | |
|
372576a396 | |
|
ddfa24f626 | |
|
b7cf69666c | |
|
ef26173ba1 | |
|
b7138d65bd | |
|
b772b71803 | |
|
9c3c43c4f6 | |
|
c5adfa7023 | |
|
00ec38c739 | |
|
66445eb61d | |
|
334620e4b1 | |
|
13e5d38277 | |
|
5c992c95ee | |
|
53c683abf3 | |
|
8d908c1c50 | |
|
8ad26d51fe | |
|
e3c154ba7a | |
|
f6175451ee | |
|
aa41a11daf | |
|
dc4de5f6a5 | |
|
82741751cf | |
|
5b4accb707 | |
|
624f278734 | |
|
c1ad45e555 | |
|
f7aa952fb6 | |
|
9149b66142 | |
|
2b5190434d | |
|
e786c09bd0 | |
|
2c529f7647 | |
|
7561fd8ffb | |
|
4f60ebb780 | |
|
33add7df0d | |
|
9281ad5c4d | |
|
df1e5a56df | |
|
bdc961c7e1 | |
|
382261eb83 | |
|
d4976ecbb4 | |
|
92002a06a2 | |
|
5e93ab6bc4 | |
|
463d51d41b | |
|
aeda124c1c | |
|
9bd9f76b9e | |
|
14054454af | |
|
181fb64c50 | |
|
7ed33e8965 | |
|
a529e0c1fe | |
|
e229f9fc4e | |
|
367f5d1a73 | |
|
1ad05dd5f3 | |
|
0a80198084 | |
|
09e0919042 | |
|
8bf6d6047d | |
|
f00ed85c4b | |
|
43bbb24dd5 | |
|
64ae4c617f | |
|
72a2f08d70 | |
|
4106dd887f | |
|
1d6ffcea7e | |
|
6294922225 | |
|
bed0385476 | |
|
0e481bb5d5 | |
|
b17e38cfd2 | |
|
5146a7c9c8 | |
|
20223d1c12 | |
|
4fde95ee7b | |
|
7ee243e20d | |
|
82267764e1 | |
|
0c9ed4b238 | |
|
95ee0c1972 | |
|
95cc2c7a34 | |
|
2ef0f3e324 | |
|
076e8ce9bd | |
|
ce1b60b85f | |
|
a92b2ea4ae | |
|
c6c93ba44f | |
|
20068cbb15 | |
|
b011d3a46f | |
|
bc07a60b51 | |
|
dc764de258 | |
|
a45a833e68 | |
|
fdc4e90635 | |
|
0805a04cad | |
|
ca03c96173 | |
|
59779eb0e5 | |
|
0af348f2cb | |
|
c16bc6ca5f | |
|
228ec2299b | |
|
a120393060 | |
|
84a5750063 | |
|
034b51ae03 | |
|
300f2e383b | |
|
346fd25955 | |
|
df871c1c5b | |
|
67bb509735 | |
|
7ef61af277 | |
|
78ef1dd4fc | |
|
60b62c8b71 | |
|
d040edcc4e | |
|
21f91a00fc | |
|
6eed5bbe19 | |
|
5c2474cb70 | |
|
cc2b13633c | |
|
99bfbc5e58 | |
|
77b943ce5e | |
|
2926387ee4 | |
|
0f35c4dc4c | |
|
66158ae44b | |
|
d4d5778175 | |
|
31a2deef0f | |
|
df85b176b7 | |
|
97646becc3 | |
|
b0fadd4459 | |
|
c7e33dd1ca | |
|
c6d2c6cbcc | |
|
ceeea15794 | |
|
3791a027a0 | |
|
13a6f8ba79 | |
|
a4e8a4be83 | |
|
c44d18f8f8 | |
|
215551ec15 | |
|
a039e65a8a | |
|
9e6b0d9f17 | |
|
df6f47907f | |
|
f814f71cf3 | |
|
dd6f425368 | |
|
7621bdd321 | |
|
f44c2528e7 | |
|
ac12c2af29 | |
|
60e74eff99 | |
|
aacd93b960 | |
|
1722c86a71 | |
|
6e9efc7a8a | |
|
3c80815428 | |
|
5913f73fcb | |
|
a7458bf261 | |
|
39b0ead3bd | |
|
e38b2aa62b | |
|
a4f1b29922 | |
|
e2f6e02ae7 | |
|
2bddae16a2 | |
|
d94b7b3e78 | |
|
f1ce78907e | |
|
12b5f8350f | |
|
dbac21aa44 | |
|
0dc7ac837f | |
|
26ec11f46c | |
|
17aef5e162 | |
|
c66120c4fa | |
|
2738d2e358 | |
|
b367cc53ad | |
|
890e78fd5d | |
|
ea0df4f22b | |
|
5a571e7329 | |
|
200ae92e0f | |
|
c56fac6c34 | |
|
bf3795ded1 | |
|
fb375002de | |
|
ebd95a4e16 | |
|
756ca37a82 | |
|
bf7e1a9847 | |
|
13396f85a4 | |
|
c4b268910b | |
|
5c954a19b4 | |
|
21688ba4d0 | |
|
728111217e | |
|
3b0b0c6720 | |
|
da14a8fc4d | |
|
a5cd846b2a | |
|
423654d21e | |
|
e3e20fc704 | |
|
856d697d79 | |
|
4317b2fc8c | |
|
2d91b3cf90 | |
|
d724f5a382 | |
|
e6c1e64fef | |
|
dd88a5ccbe | |
|
0955df7503 | |
|
ce72ba36fa | |
|
e83c53061d | |
|
101bff45c5 | |
|
8dac3f4ea9 | |
|
6b35645150 | |
|
0fbf381748 | |
|
a3f73b5fe7 | |
|
9ca2ed1f46 | |
|
c3d7b74109 | |
|
c87799c03d | |
|
bff034a299 | |
|
0245476130 | |
|
381047f915 | |
|
666f604133 | |
|
d71adaa8ab | |
|
39a8becdfe | |
|
00af397929 | |
|
f14d21a35f | |
|
cd47e28e9f | |
|
e6d2bd0950 | |
|
411021fc35 | |
|
120af8e817 | |
|
5aaf25c1c7 | |
|
ff5318c8f6 | |
|
41ecb512ed | |
|
bdc8b4057c | |
|
b6d1ea2c90 | |
|
6304b39fc8 | |
|
afa82ce13f | |
|
1b1c74ed26 | |
|
b2d0a5c355 | |
|
06d6ae9bdb | |
|
9139f9df45 | |
|
6056ff0c87 | |
|
14d4efea9d | |
|
53aa9cda52 | |
|
c6e98769e5 | |
|
4835d0f37d | |
|
7a90119c97 | |
|
b504b5b014 | |
|
520bac05da | |
|
0557d94911 | |
|
a1634b8b94 | |
|
2dc7d4aa75 | |
|
60e4eafc13 | |
|
623af5d16a | |
|
9f657c4a59 | |
|
6c33314288 | |
|
e80bdc9e2a | |
|
4dfead7ec8 | |
|
c6b04faa55 | |
|
4bebb2d50e | |
|
4867b8cf03 | |
|
68b5ca755b | |
|
b7ae19a439 | |
|
a258bd8995 | |
|
380025f147 | |
|
1d6fdbe126 | |
|
894791215c | |
|
af9d4db788 | |
|
7f36e6991f | |
|
ae190ed315 | |
|
33117b9db0 | |
|
1d47f79eca | |
|
305b2454c7 | |
|
2c773710ba | |
|
6b29226004 | |
|
d0c1878c30 | |
|
2afc40fb00 | |
|
bdae9df6b7 | |
|
59b9b3078c | |
|
eea3af9c1c | |
|
5d9b654240 | |
|
37f68d4716 | |
|
fc03a0cf74 | |
|
f8e771c9e0 | |
|
61d691c1dd | |
|
d7a6bf9e53 | |
|
9ea65c051f | |
|
a4d8075ad1 | |
|
ea454e3027 | |
|
4b69b14e10 | |
|
a9c09c3f16 | |
|
a4a3ced0e5 | |
|
668285ac97 | |
|
13067f35ad | |
|
445aae7f8f | |
|
d027a53e02 | |
|
c54e893e41 | |
|
f06afb5aa3 | |
|
ee7dab194a | |
|
9019b4f780 | |
|
4ffaadf3da | |
|
e8e2c0c472 | |
|
06272803f1 | |
|
bbdfef0ca6 | |
|
4e1b5670a4 | |
|
6ff3cbe0c3 | |
|
1eed5ca366 | |
|
a86683a98a | |
|
934292df88 | |
|
940ad072d4 | |
|
a610181954 | |
|
92b949343c | |
|
80fd939922 | |
|
25f93ab26c | |
|
e53eb7965e | |
|
4d04f39e3b | |
|
6a452ebb8f | |
|
ad1c591acd | |
|
2745803050 | |
|
38c91b5623 | |
|
25bbf5b185 | |
|
2adb328115 | |
|
9ff98d0bbf | |
|
fb7ceaec55 | |
|
0d7f2feef4 | |
|
576993f97e | |
|
5c3fca5001 | |
|
6eeb5be673 | |
|
589d197bf1 | |
|
1bae53670e | |
|
143afa4473 | |
|
983e90ca38 | |
|
dd6beb3b82 | |
|
e1c6397f22 | |
|
0b1d428266 | |
|
bd872be244 | |
|
b196618515 | |
|
b6f9afb745 | |
|
f7e0b73465 | |
|
b057cac73d | |
|
a532bbaf93 | |
|
0cf0024e55 | |
|
007344a63e | |
|
60356e56ab | |
|
177543ad20 | |
|
a37766d31b | |
|
cd158cc9a9 | |
|
ccd6649d06 | |
|
4996a7457d | |
|
1325611775 | |
|
1b9f06e3ca | |
|
d9701b910d | |
|
1061c24c5b | |
|
856da8cc77 | |
|
ff04f24a85 | |
|
9f828fe790 | |
|
95308c8bc9 | |
|
82c8397547 | |
|
8913f7ae5c | |
|
d327c34b10 | |
|
73f7dbe8a2 | |
|
9f9d6ba7c1 | |
|
06427445b7 | |
|
00c6397df4 | |
|
0811431b0a | |
|
599e6b11d5 | |
|
1266462635 | |
|
f947f204b9 | |
|
23893c60da | |
|
095b073051 | |
|
dc4b770aaa | |
|
9cc39281d7 | |
|
66df711006 | |
|
48311e4d95 | |
|
1ba2fa2e06 | |
|
c6a8bc555c | |
|
e0a2d6092b | |
|
5abdf43986 | |
|
b62e8ffd53 | |
|
3277491c64 | |
|
bceda1932e | |
|
880f7ce528 | |
|
0518fd0be4 | |
|
8788c9c4b6 | |
|
bcfa109944 | |
|
1e8b1b8193 | |
|
f20b275ba9 | |
|
25e034965d | |
|
cb9a34f5bd | |
|
c7af5843fb | |
|
e8776d3d74 | |
|
fa2be3d357 | |
|
3b0518ece0 | |
|
aeeb458408 | |
|
73e29c2025 | |
|
3e452e9e21 | |
|
6871c76a70 | |
|
082d89ec08 | |
|
2c25017b40 | |
|
49376848ff | |
|
174126209b | |
|
e9f56967cb | |
|
5f0bc9f2b8 | |
|
0019e7e107 | |
|
e1b895a966 | |
|
ae13d93da1 | |
|
f013c209a8 | |
|
44df6a3f62 | |
|
7e6a2988a6 | |
|
7fef7c9649 | |
|
66b4af4d1a | |
|
8fcd24da2c | |
|
f56c5571dd | |
|
27584c51bb | |
|
5dcaac9351 | |
|
ec35b6088a | |
|
6dfb485ec2 | |
|
05b827d265 | |
|
8891b97a9d | |
|
9dae88a5fc | |
|
5d19aec2b3 | |
|
22e79c51f4 | |
|
b303e8e540 | |
|
00e8349b40 | |
|
ef75e5a323 | |
|
a0c8e1eb7e | |
|
d59dfd09e1 | |
|
8f6c895d05 | |
|
14050f11d9 | |
|
af381857b7 | |
|
be469fc663 | |
|
65aff76af1 | |
|
15c3fadbb3 | |
|
bc77ce5892 | |
|
84d4f35c2f | |
|
2c8498fec4 | |
|
4a26f437ba | |
|
bb300cf372 | |
|
45716af6b8 | |
|
736f270a4a | |
|
50ebc9ad0c | |
|
f743ddeb15 | |
|
38bcafae01 | |
|
92bd84da75 | |
|
b1724b3fe3 | |
|
7b838272ae | |
|
135d1856cc | |
|
42d4491b2e | |
|
6206df0c41 | |
|
554335b6bd | |
|
1bf770d340 | |
|
a1f1b65d6e | |
|
5565024a7c | |
|
d0c2cc6078 | |
|
e7d8a33d3b | |
|
af3e0f08b3 | |
|
797ca9246b | |
|
354955c04e | |
|
b1c09b564e | |
|
b205feb937 | |
|
423304bb9d | |
|
e9193565f3 | |
|
57f81479fe | |
|
38b93ce16d | |
|
ba1a0fef3a | |
|
0e48e6539f | |
|
b910d9e640 | |
|
5a03b6c50d | |
|
54ab0d72f3 | |
|
4c561a79dc | |
|
a00081ace7 | |
|
e03365cff6 | |
|
654841c81d | |
|
6361e4e92e | |
|
47adca43c4 | |
|
3c3a172de4 | |
|
66d9aaddc5 | |
|
2edcb2d302 | |
|
1d9dcb8a00 | |
|
88b2e5051d | |
|
ba30e6ca42 | |
|
0132699d0e | |
|
41b84280c8 | |
|
ccf78bd951 | |
|
f4c1eca815 | |
|
4447cb8344 | |
|
067dffb3a1 | |
|
daaa3ba7c0 | |
|
f211d43689 | |
|
311a5ea4e8 | |
|
6bf848967e | |
|
0869d30911 | |
|
bd6d02ba76 | |
|
6c0212d405 | |
|
15d4497c5e | |
|
cbf11a704e | |
|
d57d181f68 | |
|
84452d6654 | |
|
771547f622 | |
|
c2f027b7b2 | |
|
2f22b039a9 | |
|
06653e6633 | |
|
6929b81dc4 | |
|
5bad6a26cc | |
|
22239e712e | |
|
e3918180fc | |
|
9f8e3ce575 | |
|
9c78c0787d | |
|
4d12279ca7 | |
|
7fae2a22ff | |
|
ab576e09da | |
|
1975cce13b | |
|
5b1ec9d994 | |
|
aaef9f9915 | |
|
55b5ecfdbf | |
|
6fa2d91130 | |
|
dbf5995337 | |
|
f475aa0fc9 | |
|
338e8eb338 | |
|
9e7ec98789 | |
|
7cafc2dde5 | |
|
daa2431362 | |
|
ad85404786 | |
|
297ac1e460 | |
|
e1417811cf | |
|
c5290030bf | |
|
9c3c722645 | |
|
04b917807c | |
|
eb2e7ed91c | |
|
e1d5602830 | |
|
12109175c0 | |
|
e81ba0faae | |
|
21f7547766 | |
|
b652d12849 | |
|
6efbf2f62d | |
|
dd244b7f32 | |
|
50872d6802 | |
|
628c33778e | |
|
b9c0030e3c | |
|
3032c6a0fc | |
|
55ac717f89 | |
|
568833b1bf | |
|
d84ed6e410 | |
|
4f6f67bd92 | |
|
498eb1e80a | |
|
3aad54cefe | |
|
e32745662b | |
|
1c7bf3c7f2 | |
|
362f625871 | |
|
d81a198feb | |
|
b8fba72f2d | |
|
02cd9ad28d | |
|
df68687092 | |
|
a5988c242c | |
|
e1fa801664 | |
|
4b9c0d0a1c | |
|
c9d3a9867d | |
|
08ca02cbad | |
|
07ad330083 | |
|
a3509bd3f4 | |
|
fc70b78040 | |
|
1cf30f18b8 | |
|
e3f7dd1989 | |
|
13955e1ca0 | |
|
091c237406 | |
|
a184ff4bf1 | |
|
aba1e25569 | |
|
58e59c75c2 | |
|
29353f9c73 | |
|
b775997046 | |
|
01b86036dd | |
|
fc1621f4c6 | |
|
31e4f3cb38 | |
|
ccb9d45305 | |
|
f9beef2073 | |
|
89d7509b0c | |
|
4f1be9cb78 | |
|
e1c33a2fef | |
|
f197a7d60d | |
|
46fd5ff1bb | |
|
109b513600 | |
|
37c9084e85 | |
|
10ae82999b | |
|
bb66feab2d | |
|
03b987ee37 | |
|
6b3d55f563 | |
|
62503d353c | |
|
5298e5c87c | |
|
00a6743370 | |
|
3b7f308fba | |
|
662c0622a0 | |
|
f9d33cf803 | |
|
9221582e2a | |
|
6e8c06ee30 | |
|
466fbf7692 | |
|
82663da3f7 | |
|
5ad5f26084 | |
|
eea1771605 | |
|
e8d4f02059 | |
|
23cb281a15 | |
|
0accca079a | |
|
00edf1e344 | |
|
3aca473cc9 | |
|
18c1b498fb | |
|
7251ed06e3 | |
|
b91e2174a6 | |
|
1ec9f0178c | |
|
c68f864be9 | |
|
9a58dad30f | |
|
7dd4572d77 | |
|
0c987ddad3 | |
|
be0c6fd57d | |
|
816067f76d | |
|
b4d0e89ec8 | |
|
9eec0b92e8 | |
|
bd472264e8 | |
|
28d2e90ee0 | |
|
eaf713fb1e | |
|
ce625ee4b1 | |
|
82367f22e6 | |
|
4d8179c8fd | |
|
41f7bc881b | |
|
81495be56b | |
|
9704598f39 | |
|
06ba048797 | |
|
b45af8cad0 | |
|
7c5aefaade | |
|
4187c59aa7 | |
|
897048e90f | |
|
5d5f2ada5e | |
|
88d8632931 | |
|
3f164f60c5 | |
|
003b89f904 | |
|
55046e7895 | |
|
ccedb36138 | |
|
d24709bbd6 | |
|
6f2b7c92c4 | |
|
0ac179bb89 | |
|
33bebcd928 | |
|
6a7fad99db | |
|
6dfb261c05 | |
|
6cc5ee64bc | |
|
fbf4dc26fc | |
|
72afd7068d | |
|
efa3b63ea9 | |
|
b1ceaa3f46 | |
|
317b813c4f | |
|
2692f7ec8e | |
|
8e74abb69a | |
|
c866f17a3c | |
|
3b137a76b6 | |
|
f099539e39 | |
|
05d5a8d8be | |
|
567718662a | |
|
8bafd9f372 | |
|
c9680d7556 | |
|
64dbaaa00d | |
|
317eaa6c35 | |
|
5a16e08c7a | |
|
1e6d8d1e1d | |
|
5cd2d90173 | |
|
78eafe7ba8 | |
|
1723aae771 | |
|
40f14a7bb0 | |
|
f3f596db3c | |
|
0abd111f72 | |
|
0753f76350 | |
|
4222b2eedf | |
|
81ce4627f0 | |
|
6c39559c04 | |
|
e5497786f3 | |
|
e33a19cc4f | |
|
f2be251106 | |
|
d598c921d5 | |
|
894bbaca43 | |
|
31bd3523e1 | |
|
61ecb3b7ba | |
|
9f53f0265e | |
|
631ff256c1 | |
|
6f3b4c8275 | |
|
84f6abb0d5 | |
|
07b3b21077 | |
|
9204df2dc2 | |
|
20032dddbf | |
|
dbe7fdfc11 | |
|
7de2886f19 | |
|
cd6c4fc10a | |
|
f76419a4b9 | |
|
546fe01d6a | |
|
7c0484063a | |
|
1c9c3f40a4 | |
|
f2079ddae7 | |
|
4349c7fd17 |
|
@ -2,12 +2,15 @@
|
|||
.*
|
||||
# except for .gitignore
|
||||
!.gitignore
|
||||
!.classpath
|
||||
!.project
|
||||
.classpath
|
||||
.project
|
||||
|
||||
# Ignore all classfiles
|
||||
*.class
|
||||
|
||||
# Ignore bin
|
||||
*/bin/*
|
||||
*/lib/*
|
||||
bin
|
||||
*/lib/*
|
||||
*/target/*
|
||||
dependency-reduced-pom.xml
|
||||
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
Copyright (c) 2012 Thomas-Antoine O'Neill aka tommytony, http://war.tommytony.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -0,0 +1,36 @@
|
|||
![War logo](http://i.imgur.com/LFdiF.png "War - Minecraft PVP Arenas - TDM, CTF and more!")
|
||||
|
||||
War - Minecraft PVP Arenas (TDM, CTF and more!)
|
||||
===============================================
|
||||
|
||||
War is a plugin for Bukkit that adds PVP arenas and team deathmatch gamemodes to Minecraft servers.
|
||||
|
||||
Official website
|
||||
----------------
|
||||
Visit http://war.tommytony.com for more info, videos and links.
|
||||
|
||||
Features
|
||||
--------
|
||||
- Built on the popular Bukkit mod API (http://bukkit.org)
|
||||
- Capture-the-flag and team deathmatch arenas, called warzones
|
||||
- Warzone blocks are saved and reset at the end of every game, for safely destructible maps
|
||||
- Other game types: capture points and explosive-based objectives
|
||||
- Up to 16 teams!
|
||||
- Tons of customizable game rules, item loadouts and options (see [Instructions](http://war.tommytony.com/instructions))
|
||||
|
||||
Downloads
|
||||
---------
|
||||
All official releases are at https://github.com/taoneill/war/downloads.
|
||||
|
||||
Dev Builds
|
||||
----------
|
||||
Development builds are available at https://cmastudios.me/cgi-bin/war.py.
|
||||
|
||||
Author
|
||||
------
|
||||
tommytony started the plugin in December 2010 on hMod and has been maintaining it since with the help of contributors.
|
||||
Reach him at taoneill@tommytony.com.
|
||||
|
||||
License
|
||||
-------
|
||||
War is licensed loosely under the MIT License (but still comes with the weird baggage of Bukkit licensing)
|
|
@ -1,3 +0,0 @@
|
|||
War, a simple hmod plugin that adds team deathmatch to minecraft multiplayer.
|
||||
|
||||
All credit goes to Mojang and the hey0 team for being so awesome.
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
|
@ -1,17 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>minecraft.hmod.war.test</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -1,12 +0,0 @@
|
|||
#Thu Dec 16 22:49:21 EST 2010
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.6
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.6
|
|
@ -1,9 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
|
||||
<classpathentry kind="lib" path="C:/dev/war/minecraft.hmod.war/lib/Minecraft_Mod133.jar" sourcepath="/hmod"/>
|
||||
<classpathentry kind="lib" path="C:/dev/war/minecraft.hmod.war/lib/minecraft_server-beta1.1_02.jar"/>
|
||||
<classpathentry kind="lib" path="C:/dev/war/minecraft.hmod.war/lib/mysql-connector-java-bin133.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
|
@ -1,17 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>minecraft.hmod.war</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -1,12 +0,0 @@
|
|||
#Sat Dec 11 12:21:43 EST 2010
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.6
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.6
|
|
@ -1,5 +0,0 @@
|
|||
|
||||
public class Battle {
|
||||
|
||||
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
|
||||
public class BlockColumnSetter implements Runnable {
|
||||
|
||||
private final int x;
|
||||
private final int z;
|
||||
private final Server server;
|
||||
private final int[][][] initialState;
|
||||
private final int i;
|
||||
private final int k;
|
||||
|
||||
public BlockColumnSetter(Server server, int[][][] initialState, int x, int z, int i, int k) {
|
||||
this.server = server;
|
||||
this.initialState = initialState;
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
this.i = i;
|
||||
this.k = k;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for(int j = 0; j < 128; j++) {
|
||||
server.setBlockAt(initialState[i][j][k], x, j, z);
|
||||
}
|
||||
server.messageAll("Reset x=" + x + " z=" + z);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,112 +0,0 @@
|
|||
|
||||
public class Monument {
|
||||
private Location location;
|
||||
private int[] initialState = new int[10];
|
||||
private War war = null;
|
||||
private Team ownerTeam = null;
|
||||
private final String name;
|
||||
|
||||
public Monument(String name, War war, Location location) {
|
||||
this.name = name;
|
||||
this.location = location;
|
||||
this.war = war;
|
||||
int x = (int)location.x;
|
||||
int y = (int)location.y;
|
||||
int z = (int)location.z;
|
||||
initialState[0] = war.getServer().getBlockIdAt(x+1, y-1, z+1);
|
||||
initialState[1] = war.getServer().getBlockIdAt(x+1, y-1, z);
|
||||
initialState[2] = war.getServer().getBlockIdAt(x+1, y-1, z-1);
|
||||
initialState[3] = war.getServer().getBlockIdAt(x, y-1, z+1);
|
||||
initialState[4] = war.getServer().getBlockIdAt(x, y-1, z);
|
||||
initialState[5] = war.getServer().getBlockIdAt(x, y-1, z-1);
|
||||
initialState[6] = war.getServer().getBlockIdAt(x-1, y-1, z+1);
|
||||
initialState[7] = war.getServer().getBlockIdAt(x-1, y-1, z);
|
||||
initialState[8] = war.getServer().getBlockIdAt(x-1, y-1, z-1);
|
||||
initialState[9] = war.getServer().getBlockIdAt(x, y, z);
|
||||
this.reset();
|
||||
}
|
||||
|
||||
public boolean isNear(Location playerLocation) {
|
||||
int x = (int)getLocation().x;
|
||||
int y = (int)getLocation().y;
|
||||
int z = (int)getLocation().z;
|
||||
int playerX = (int)playerLocation.x;
|
||||
int playerY = (int)playerLocation.y;
|
||||
int playerZ = (int)playerLocation.z;
|
||||
int diffX = Math.abs(playerX - x);
|
||||
int diffY = Math.abs(playerY - y);
|
||||
int diffZ = Math.abs(playerZ - z);
|
||||
if(diffX < 6 && diffY < 6 && diffZ < 6) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isOwner(Team team) {
|
||||
if(team == ownerTeam) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasOwner() {
|
||||
return ownerTeam != null;
|
||||
}
|
||||
|
||||
public void ignite(Team team) {
|
||||
ownerTeam = team;
|
||||
}
|
||||
|
||||
public void smother() {
|
||||
ownerTeam = null;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
this.ownerTeam = null;
|
||||
int x = (int)getLocation().x;
|
||||
int y = (int)getLocation().y;
|
||||
int z = (int)getLocation().z;
|
||||
war.getServer().setBlockAt(49, x+1, y-1, z+1);
|
||||
war.getServer().setBlockAt(49, x+1, y-1, z);
|
||||
war.getServer().setBlockAt(49, x+1, y-1, z-1);
|
||||
war.getServer().setBlockAt(49, x, y-1, z+1);
|
||||
war.getServer().setBlockAt(87, x, y-1, z);
|
||||
war.getServer().setBlockAt(49, x, y-1, z-1);
|
||||
war.getServer().setBlockAt(49, x-1, y-1, z+1);
|
||||
war.getServer().setBlockAt(49, x-1, y-1, z);
|
||||
war.getServer().setBlockAt(49, x-1, y-1, z-1);
|
||||
war.getServer().setBlockAt(0, x, y, z);
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
int x = (int)getLocation().x;
|
||||
int y = (int)getLocation().y;
|
||||
int z = (int)getLocation().z;
|
||||
war.getServer().setBlockAt(initialState[0], x+1, y-1, z+1);
|
||||
war.getServer().setBlockAt(initialState[1], x+1, y-1, z);
|
||||
war.getServer().setBlockAt(initialState[2], x+1, y-1, z-1);
|
||||
war.getServer().setBlockAt(initialState[3], x, y-1, z+1);
|
||||
war.getServer().setBlockAt(initialState[4], x, y-1, z);
|
||||
war.getServer().setBlockAt(initialState[5], x, y-1, z-1);
|
||||
war.getServer().setBlockAt(initialState[6], x-1, y-1, z+1);
|
||||
war.getServer().setBlockAt(initialState[7], x-1, y-1, z);
|
||||
war.getServer().setBlockAt(initialState[8], x-1, y-1, z-1);
|
||||
war.getServer().setBlockAt(initialState[9], x, y, z);
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setOwnerTeam(Team team) {
|
||||
this.ownerTeam = team;
|
||||
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
|
||||
public class NotReadyException extends Exception {
|
||||
|
||||
}
|
|
@ -1,86 +0,0 @@
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Team {
|
||||
private List<Player> players = new ArrayList<Player>();
|
||||
private Location teamSpawn = null;
|
||||
private String name;
|
||||
private int remainingTickets;
|
||||
private int[] oldSpawnState = new int[10];
|
||||
private int points = 0;
|
||||
|
||||
public Team(String name, Location teamSpawn) {
|
||||
this.setName(name);
|
||||
this.teamSpawn = teamSpawn;
|
||||
this.remainingTickets = War.LIFEPOOL;
|
||||
}
|
||||
|
||||
public void setTeamSpawn(Location teamSpawn) {
|
||||
this.teamSpawn = teamSpawn;
|
||||
}
|
||||
|
||||
public Location getTeamSpawn() {
|
||||
return teamSpawn;
|
||||
}
|
||||
|
||||
public void addPlayer(Player player) {
|
||||
this.players.add(player);
|
||||
}
|
||||
|
||||
public List<Player> getPlayers() {
|
||||
return players;
|
||||
}
|
||||
|
||||
public void teamcast(String message) {
|
||||
for(Player player : players) {
|
||||
player.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean removePlayer(String name) {
|
||||
Player thePlayer = null;
|
||||
for(Player player : players) {
|
||||
if(player.getName().equals(name)) {
|
||||
thePlayer = player;
|
||||
}
|
||||
}
|
||||
if(thePlayer != null) {
|
||||
players.remove(thePlayer);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setRemainingTickets(int remainingTickets) {
|
||||
this.remainingTickets = remainingTickets;
|
||||
}
|
||||
|
||||
public int getRemainingTickets() {
|
||||
return remainingTickets;
|
||||
}
|
||||
|
||||
public int[] getOldSpawnState() {
|
||||
return oldSpawnState;
|
||||
}
|
||||
|
||||
public void setOldSpawnState(int[] oldSpawnState) {
|
||||
this.oldSpawnState = oldSpawnState;
|
||||
}
|
||||
|
||||
public void addPoint() {
|
||||
points++;
|
||||
}
|
||||
|
||||
public int getPoints() {
|
||||
return points;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,150 +0,0 @@
|
|||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
||||
|
||||
public class War extends Plugin {
|
||||
|
||||
public static final int LIFEPOOL = 5;
|
||||
private WarListener listener = new WarListener(this);
|
||||
private Logger log;
|
||||
String name = "War";
|
||||
String version = "0.1";
|
||||
|
||||
|
||||
private final List<Warzone> warzones = new ArrayList<Warzone>();
|
||||
|
||||
public void initialize() {
|
||||
this.log = Logger.getLogger("Minecraft");
|
||||
getLogger().info(name + " " + version + " initialized");
|
||||
|
||||
etc.getLoader().addListener(
|
||||
PluginLoader.Hook.COMMAND,
|
||||
listener,
|
||||
this,
|
||||
PluginListener.Priority.MEDIUM);
|
||||
etc.getLoader().addListener( PluginLoader.Hook.LOGIN,
|
||||
listener,
|
||||
this,
|
||||
PluginListener.Priority.MEDIUM);
|
||||
etc.getLoader().addListener( PluginLoader.Hook.HEALTH_CHANGE,
|
||||
listener,
|
||||
this,
|
||||
PluginListener.Priority.MEDIUM);
|
||||
etc.getLoader().addListener( PluginLoader.Hook.DAMAGE,
|
||||
listener,
|
||||
this,
|
||||
PluginListener.Priority.HIGH);
|
||||
etc.getLoader().addListener( PluginLoader.Hook.PLAYER_MOVE,
|
||||
listener,
|
||||
this,
|
||||
PluginListener.Priority.MEDIUM);
|
||||
etc.getLoader().addListener( PluginLoader.Hook.DISCONNECT,
|
||||
listener,
|
||||
this,
|
||||
PluginListener.Priority.MEDIUM);
|
||||
etc.getLoader().addListener( PluginLoader.Hook.IGNITE,
|
||||
listener,
|
||||
this,
|
||||
PluginListener.Priority.MEDIUM);
|
||||
etc.getLoader().addListener( PluginLoader.Hook.FLOW,
|
||||
listener,
|
||||
this,
|
||||
PluginListener.Priority.MEDIUM);
|
||||
|
||||
|
||||
// etc.getLoader().addListener(
|
||||
// PluginLoader.Hook.BLOCK_CREATED,
|
||||
// listener,
|
||||
// this,
|
||||
// PluginListener.Priority.MEDIUM);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public Team getPlayerTeam(String playerName) {
|
||||
for(Warzone warzone : warzones) {
|
||||
Team team = warzone.getPlayerTeam(playerName);
|
||||
if(team != null) return team;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Warzone getPlayerWarzone(String playerName) {
|
||||
for(Warzone warzone : warzones) {
|
||||
Team team = warzone.getPlayerTeam(playerName);
|
||||
if(team != null) return warzone;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public Logger getLogger() {
|
||||
return log;
|
||||
}
|
||||
|
||||
public Warzone warzone(Location location) {
|
||||
for(Warzone warzone : warzones) {
|
||||
if(warzone.contains(location)) return warzone;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean inAnyWarzone(Location location) {
|
||||
if(warzone(location) == null) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean inWarzone(String warzoneName, Location location) {
|
||||
Warzone currentZone = warzone(location);
|
||||
if(currentZone == null) {
|
||||
return false;
|
||||
} else if (warzoneName.equals(currentZone.getName())){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void addWarzone(Warzone zone) {
|
||||
warzones.add(zone);
|
||||
}
|
||||
|
||||
public Server getServer() {
|
||||
// TODO Auto-generated method stub
|
||||
return etc.getServer();
|
||||
}
|
||||
|
||||
public List<Warzone> getWarzones() {
|
||||
return warzones;
|
||||
}
|
||||
|
||||
public String str(String str) {
|
||||
String out = Colors.LightGray + "[war] " + Colors.White + str;
|
||||
return out;
|
||||
}
|
||||
|
||||
public Warzone findWarzone(String warzoneName) {
|
||||
for(Warzone warzone : warzones) {
|
||||
if(warzone.getName().equals(warzoneName)) {
|
||||
return warzone;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,558 +0,0 @@
|
|||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.logging.Level;
|
||||
|
||||
|
||||
|
||||
public class WarListener extends PluginListener {
|
||||
|
||||
private final War war;
|
||||
private Random random = null;
|
||||
|
||||
public WarListener(War war) {
|
||||
this.war = war;
|
||||
random = new Random(war.getServer().getTime());
|
||||
}
|
||||
|
||||
public void onLogin(Player player) {
|
||||
player.sendMessage(war.str("War is on! Pick your battle (try /warzones)."));
|
||||
}
|
||||
|
||||
public boolean onCommand(Player player, java.lang.String[] split) {
|
||||
String command = split[0];
|
||||
|
||||
// Player commands: /warzones, /warzone, /teams, /join, /leave
|
||||
|
||||
// warzones
|
||||
if(command.equals("/warzones")){
|
||||
|
||||
String warzonesMessage = "Warzones: ";
|
||||
if(war.getWarzones().isEmpty()){
|
||||
warzonesMessage += "none.";
|
||||
}
|
||||
for(Warzone warzone : war.getWarzones()) {
|
||||
|
||||
warzonesMessage += warzone.getName() + " ("
|
||||
+ warzone.getTeams().size() + " teams, ";
|
||||
int playerTotal = 0;
|
||||
for(Team team : warzone.getTeams()) {
|
||||
playerTotal += team.getPlayers().size();
|
||||
}
|
||||
warzonesMessage += playerTotal + " players) ";
|
||||
}
|
||||
player.sendMessage(war.str(warzonesMessage + " Use /warzone <zone-name> to " +
|
||||
"teleport to a warzone, " +
|
||||
"then use /teams and /join <team-name>."));
|
||||
return true;
|
||||
}
|
||||
|
||||
// warzone
|
||||
else if(command.equals("/warzone")) {
|
||||
if(split.length < 2) {
|
||||
player.sendMessage(war.str("Usage: /warzone <warzone-name>."));
|
||||
} else {
|
||||
for(Warzone warzone : war.getWarzones()) {
|
||||
if(warzone.getName().equals(split[1])){
|
||||
player.teleportTo(warzone.getTeleport());
|
||||
player.sendMessage(war.str("You've landed in warzone " + warzone.getName() +
|
||||
". Use the /join command. " + getAllTeamsMsg(player)));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
player.sendMessage("No such warzone.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// /teams
|
||||
else if(command.equals("/teams")){
|
||||
if(!war.inAnyWarzone(player.getLocation())) {
|
||||
player.sendMessage(war.str("Usage: /teams. " +
|
||||
"Must be in a warzone (try /warzones and /warzone)."));
|
||||
} else {
|
||||
player.sendMessage(war.str("" + getAllTeamsMsg(player)));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// /join <teamname>
|
||||
else if(command.equals("/join")) {
|
||||
if(split.length < 2 || !war.inAnyWarzone(player.getLocation())) {
|
||||
player.sendMessage(war.str("Usage: /join <team-name>." +
|
||||
" Teams are warzone specific." +
|
||||
" You must be inside a warzone to join a team."));
|
||||
} else {
|
||||
// drop from old team if any
|
||||
Team previousTeam = war.getPlayerTeam(player.getName());
|
||||
if(previousTeam != null) {
|
||||
if(!previousTeam.removePlayer(player.getName())){
|
||||
war.getLogger().log(Level.WARNING, "Could not remove player " + player.getName() + " from team " + previousTeam.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// join new team
|
||||
String name = split[1];
|
||||
List<Team> teams = war.warzone(player.getLocation()).getTeams();
|
||||
boolean foundTeam = false;
|
||||
for(Team team : teams) {
|
||||
if(team.getName().equals(name)) {
|
||||
team.addPlayer(player);
|
||||
Warzone zone = war.warzone(player.getLocation());
|
||||
zone.respawnPlayer(team, player);
|
||||
foundTeam = true;
|
||||
}
|
||||
}
|
||||
if(foundTeam) {
|
||||
for(Team team : teams){
|
||||
team.teamcast(war.str("" + player.getName() + " joined " + name));
|
||||
}
|
||||
} else {
|
||||
player.sendMessage(war.str("No such team. Try /teams."));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// /leave
|
||||
else if(command.equals("/leave")) {
|
||||
if(!war.inAnyWarzone(player.getLocation()) || war.getPlayerTeam(player.getName()) == null) {
|
||||
player.sendMessage(war.str("Usage: /leave. " +
|
||||
"Must be in a team already."));
|
||||
} else {
|
||||
Team playerTeam = war.getPlayerTeam(player.getName());
|
||||
playerTeam.removePlayer(player.getName());
|
||||
player.sendMessage(war.str("Left the team. You can now exit the warzone."));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// /team <msg>
|
||||
else if(command.equals("/team")) {
|
||||
if(!war.inAnyWarzone(player.getLocation())) {
|
||||
player.sendMessage(war.str("Usage: /team <message>. " +
|
||||
"Sends a message only to your teammates."));
|
||||
} else {
|
||||
Team playerTeam = war.getPlayerTeam(player.getName());
|
||||
String teamMessage = player.getName();
|
||||
for(int j = 1 ; j<split.length; j++) {
|
||||
String part = split[j];
|
||||
teamMessage += part + " ";
|
||||
}
|
||||
playerTeam.teamcast(war.str(teamMessage));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Mod commands : /restartbattle
|
||||
|
||||
// /restartbattle
|
||||
else if(command.equals("/restartbattle")) {
|
||||
if(!war.inAnyWarzone(player.getLocation())) {
|
||||
player.sendMessage(war.str("Usage: /restartbattle. Must be in warzone."));
|
||||
} else {
|
||||
Warzone warzone = war.warzone(player.getLocation());
|
||||
for(Team team: warzone.getTeams()) {
|
||||
team.teamcast(war.str("The battle has ended. " + getAllTeamsMsg(player) + " Resetting warzone " + warzone.getName() + "..."));
|
||||
}
|
||||
int resetBlocks = warzone.resetState();
|
||||
player.sendMessage(war.str("Warzone reset. " + resetBlocks + " blocks reset."));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Warzone maker commands: /setwarzone, /setwarzonestart, /resetwarzone, /newteam, /setteamspawn, .. /setmonument?
|
||||
|
||||
// /newteam <teamname>
|
||||
else if(command.equals("/newteam")) {
|
||||
if(split.length < 2 || !war.inAnyWarzone(player.getLocation())) {
|
||||
player.sendMessage(war.str("Usage: /newteam <team-name>." +
|
||||
" Sets the team spawn to the current location. " +
|
||||
"Must be in a warzone (try /warzones and /warzone). "));
|
||||
} else {
|
||||
String name = split[1];
|
||||
Team newTeam = new Team(name, player.getLocation());
|
||||
war.warzone(player.getLocation()).getTeams().add(newTeam);
|
||||
addSpawnArea(newTeam, player.getLocation(), 41);
|
||||
player.sendMessage(war.str("Team " + name + " created with spawn here."));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// /setteamspawn
|
||||
else if(command.equals("/setteamspawn")) {
|
||||
if(split.length < 2 || !war.inAnyWarzone(player.getLocation())) {
|
||||
player.sendMessage(war.str("Usage: /setteamspawn <team-name>. " +
|
||||
"Sets the team spawn. " +
|
||||
"Must be in warzone and team must already exist."));
|
||||
} else {
|
||||
List<Team> teams = war.warzone(player.getLocation()).getTeams();
|
||||
Team team = null;
|
||||
for(Team t : teams) {
|
||||
if(t.getName().equals(split[1])) {
|
||||
team = t;
|
||||
}
|
||||
}
|
||||
if(team != null) {
|
||||
removeSpawnArea(team);
|
||||
addSpawnArea(team, player.getLocation(), 41);
|
||||
team.setTeamSpawn(player.getLocation());
|
||||
player.sendMessage(war.str("Team " + team.getName() + " spawn relocated."));
|
||||
} else {
|
||||
player.sendMessage(war.str("Usage: /setteamspawn <team-name>. " +
|
||||
"Sets the team spawn. " +
|
||||
"Must be in warzone and team must already exist."));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// /setwarzone
|
||||
else if(command.equals("/setwarzone")) {
|
||||
if(split.length < 3 || (split.length == 3 && (!split[2].equals("southeast") && !split[2].equals("northwest")
|
||||
&& !split[2].equals("se") && !split[2].equals("nw")))) {
|
||||
player.sendMessage(war.str("Usage: /setwarzone <warzone-name> <'southeast'/'northwest'>. " +
|
||||
"Defines the battleground boundary. " +
|
||||
"The warzone is reset at the start of every battle. " +
|
||||
"This command overwrites any previously saved blocks " +
|
||||
"(i.e. make sure you reset with /restartbattle " +
|
||||
"or /resetwarzone before changing the boundary). "));
|
||||
} else {
|
||||
Warzone warzone = war.findWarzone(split[1]);
|
||||
if(warzone == null) {
|
||||
// create the warzone
|
||||
Warzone newZone = new Warzone(war.getServer(), split[1]);
|
||||
war.addWarzone(newZone);
|
||||
if(split[2].equals("northwest") || split[2].equals("nw")) {
|
||||
newZone.setNorthwest(player.getLocation());
|
||||
player.sendMessage(war.str("Warzone " + newZone.getName() + " added. Northwesternmost point set at x=" + (int)newZone.getNorthwest().x + " z=" + (int)newZone.getNorthwest().z + "."));
|
||||
} else {
|
||||
newZone.setSoutheast(player.getLocation());
|
||||
player.sendMessage(war.str("Warzone " + newZone.getName() + " added. Southeasternmost point set at x=" + (int)newZone.getSoutheast().x + " z=" + (int)newZone.getSoutheast().z + "."));
|
||||
}
|
||||
} else {
|
||||
String message = "";
|
||||
if(split[2].equals("northwest") || split[2].equals("nw")) {
|
||||
warzone.setNorthwest(player.getLocation());
|
||||
message += "Northwesternmost point set at x=" + (int)warzone.getNorthwest().x + " z=" + (int)warzone.getNorthwest().z + " on warzone " + warzone.getName() + ".";
|
||||
} else {
|
||||
warzone.setSoutheast(player.getLocation());
|
||||
message += "Southeasternmost point set at x=" + (int)warzone.getSoutheast().x + " z=" + (int)warzone.getSoutheast().z + " on warzone " + warzone.getName() + ".";
|
||||
}
|
||||
|
||||
if(warzone.getNorthwest() == null) {
|
||||
message += " Still missing northwesternmost point.";
|
||||
}
|
||||
if(warzone.getSoutheast() == null) {
|
||||
message += " Still missing southeasternmost point.";
|
||||
}
|
||||
if(warzone.getNorthwest() != null && warzone.getSoutheast() != null) {
|
||||
if(warzone.ready()) {
|
||||
message += " Warzone " + warzone.getName() + " almost ready. Use /newteam while inside the warzone to create new teams. Make sure to use /setwarzonestart to " +
|
||||
"set the warzone teleport point and initial state.";
|
||||
} else if (warzone.tooSmall()) {
|
||||
message += " Warzone " + warzone.getName() + " is too small. Min north-south size: 20. Min east-west size: 20.";
|
||||
} else if (warzone.tooBig()) {
|
||||
message += " Warzone " + warzone.getName() + " is too Big. Max north-south size: 1000. Max east-west size: 1000.";
|
||||
}
|
||||
}
|
||||
player.sendMessage(war.str(message));
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// /setwarzonestart
|
||||
else if(command.equals("/setwarzonestart")) {
|
||||
if(!war.inAnyWarzone(player.getLocation())) {
|
||||
player.sendMessage(war.str("Usage: /setwarzonestart. Must be in warzone. " +
|
||||
"Changes the warzone state at the beginning of every battle. " +
|
||||
"Also sets the teleport point for this warzone " +
|
||||
"(i.e. make sure to use /warzone or the warzone tp point will change). " +
|
||||
"Just like /setwarzone, this command overwrites any previously saved blocks " +
|
||||
"(i.e. make sure you reset with /restartbattle " +
|
||||
"or /resetwarzone before changing start state). "));
|
||||
} else {
|
||||
Warzone warzone = war.warzone(player.getLocation());
|
||||
int savedBlocks = warzone.saveState();
|
||||
warzone.setTeleport(player.getLocation());
|
||||
player.sendMessage(war.str("Warzone " + warzone.getName() + " initial state and teleport location changed. Saved " + savedBlocks + " blocks."));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// /resetwarzone
|
||||
else if(command.equals("/resetwarzone")) {
|
||||
if(!war.inAnyWarzone(player.getLocation())) {
|
||||
player.sendMessage(war.str("Usage: /resetwarzone. Must be in warzone."));
|
||||
} else {
|
||||
Warzone warzone = war.warzone(player.getLocation());
|
||||
for(Team team: warzone.getTeams()) {
|
||||
team.teamcast(war.str("Resetting warzone " + warzone.getName() + "..."));
|
||||
}
|
||||
int resetBlocks = warzone.resetState();
|
||||
Location playerLoc = player.getLocation();
|
||||
player.sendMessage(war.str("Warzone reset. " + resetBlocks + " blocks reset."));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// /monument
|
||||
else if(command.equals("/monument")) {
|
||||
if(!war.inAnyWarzone(player.getLocation())) {
|
||||
player.sendMessage(war.str("Usage: /monument <name>. Must be in warzone."));
|
||||
} else {
|
||||
Warzone warzone = war.warzone(player.getLocation());
|
||||
Monument monument = new Monument(split[1], war, player.getLocation());
|
||||
warzone.getMomuments().add(monument);
|
||||
player.sendMessage(war.str("Monument " + monument.getName() + " created."));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void removeSpawnArea(Team team) {
|
||||
// Reset spawn to what it was before the gold blocks
|
||||
int[] spawnState = team.getOldSpawnState();
|
||||
int x = (int)team.getTeamSpawn().x;
|
||||
int y = (int)team.getTeamSpawn().y;
|
||||
int z = (int)team.getTeamSpawn().z;
|
||||
war.getServer().setBlockAt(spawnState[0], x+1, y-1, z+1);
|
||||
war.getServer().setBlockAt(spawnState[1], x+1, y-1, z);
|
||||
war.getServer().setBlockAt(spawnState[2], x+1, y-1, z-1);
|
||||
war.getServer().setBlockAt(spawnState[3], x, y-1, z+1);
|
||||
war.getServer().setBlockAt(spawnState[4], x, y-1, z);
|
||||
war.getServer().setBlockAt(spawnState[5], x, y-1, z-1);
|
||||
war.getServer().setBlockAt(spawnState[6], x-1, y-1, z+1);
|
||||
war.getServer().setBlockAt(spawnState[7], x-1, y-1, z);
|
||||
war.getServer().setBlockAt(spawnState[8], x-1, y-1, z-1);
|
||||
war.getServer().setBlockAt(spawnState[9], x, y, z);
|
||||
|
||||
}
|
||||
|
||||
private void addSpawnArea(Team team, Location location, int blockType) {
|
||||
// Save the spawn state (i.e. the nine block under the player spawn)
|
||||
int[] spawnState = new int[10];
|
||||
int x = (int)location.x;
|
||||
int y = (int)location.y;
|
||||
int z = (int)location.z;
|
||||
spawnState[0] = war.getServer().getBlockIdAt(x+1, y-1, z+1);
|
||||
spawnState[1] = war.getServer().getBlockIdAt(x+1, y-1, z);
|
||||
spawnState[2] = war.getServer().getBlockIdAt(x+1, y-1, z-1);
|
||||
spawnState[3] = war.getServer().getBlockIdAt(x, y-1, z+1);
|
||||
spawnState[4] = war.getServer().getBlockIdAt(x, y-1, z);
|
||||
spawnState[5] = war.getServer().getBlockIdAt(x, y-1, z-1);
|
||||
spawnState[6] = war.getServer().getBlockIdAt(x-1, y-1, z+1);
|
||||
spawnState[7] = war.getServer().getBlockIdAt(x-1, y-1, z);
|
||||
spawnState[8] = war.getServer().getBlockIdAt(x-1, y-1, z-1);
|
||||
spawnState[9] = war.getServer().getBlockIdAt(x, y, z);
|
||||
team.setTeamSpawn(location);
|
||||
team.setOldSpawnState(spawnState);
|
||||
// Set the spawn as gold blocks
|
||||
war.getServer().setBlockAt(blockType, x+1, y-1, z+1);
|
||||
war.getServer().setBlockAt(blockType, x+1, y-1, z);
|
||||
war.getServer().setBlockAt(blockType, x+1, y-1, z-1);
|
||||
war.getServer().setBlockAt(blockType, x, y-1, z+1);
|
||||
war.getServer().setBlockAt(blockType, x, y-1, z);
|
||||
war.getServer().setBlockAt(blockType, x, y-1, z-1);
|
||||
war.getServer().setBlockAt(blockType, x-1, y-1, z+1);
|
||||
war.getServer().setBlockAt(blockType, x-1, y-1, z);
|
||||
war.getServer().setBlockAt(blockType, x-1, y-1, z-1);
|
||||
|
||||
Block block = new Block(63, x, y, z, 8);
|
||||
war.getServer().setBlock(block);
|
||||
block = war.getServer().getBlockAt(x, y, z);
|
||||
ComplexBlock complexBlock = war.getServer().getComplexBlock(x, y, z);
|
||||
Sign sign = (Sign)complexBlock;
|
||||
sign.setText(0, "Team");
|
||||
sign.setText(1, team.getName());
|
||||
sign.setText(2, "spawn");
|
||||
sign.update();
|
||||
}
|
||||
|
||||
public boolean onDamage(PluginLoader.DamageType damageType, BaseEntity attacker, BaseEntity defender, int damageAmount) {
|
||||
if(attacker != null && defender != null && attacker.isPlayer() && defender.isPlayer()) {
|
||||
// only let adversaries (same warzone, different team) attack each other
|
||||
Player a = attacker.getPlayer();
|
||||
Player d = defender.getPlayer();
|
||||
Warzone attackerWarzone = war.warzone(a.getLocation());
|
||||
Team attackerTeam = war.getPlayerTeam(a.getName());
|
||||
Warzone defenderWarzone = war.warzone(d.getLocation());
|
||||
Team defenderTeam = war.getPlayerTeam(d.getName());
|
||||
if(attackerTeam != null && defenderTeam != null
|
||||
&& attackerTeam != defenderTeam
|
||||
&& attackerWarzone == defenderWarzone) {
|
||||
war.getLogger().log(Level.INFO, a.getName() + " hit " + d.getName() + " for " + damageAmount);
|
||||
return false; // adversaries!
|
||||
} else {
|
||||
a.sendMessage(war.str("Your attack missed!"));
|
||||
if(attackerTeam == null) {
|
||||
a.sendMessage(war.str(" You must join a team " +
|
||||
", then you'll be able to damage people " +
|
||||
"in the other teams in that warzone."));
|
||||
} else if (defenderTeam == null) {
|
||||
a.sendMessage(war.str("Your target is not in a team."));
|
||||
} else if (attackerTeam == defenderTeam) {
|
||||
a.sendMessage(war.str("Your target is on your team."));
|
||||
} else if (attackerWarzone != defenderWarzone) {
|
||||
a.sendMessage(war.str("Your target is playing in another warzone."));
|
||||
}
|
||||
return true; // no pvp outside of the war battles, no friendly fire either
|
||||
}
|
||||
}
|
||||
// mobs are always dangerous
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean onHealthChange(Player player, int before, int after) {
|
||||
|
||||
if(after <= 0) {
|
||||
Team team = war.getPlayerTeam(player.getName());
|
||||
if(team != null){
|
||||
// teleport to team spawn upon death
|
||||
Warzone zone = war.warzone(player.getLocation());
|
||||
boolean roundOver = false;
|
||||
synchronized(zone) {
|
||||
int remaining = team.getRemainingTickets();
|
||||
if(remaining == 0) { // your death caused your team to lose
|
||||
List<Team> teams = zone.getTeams();
|
||||
for(Team t : teams) {
|
||||
t.teamcast(war.str(player.getName() + " died but team " + team.getName() + "'s life pool was empty. "));
|
||||
t.teamcast(war.str("The battle is over. Team " + team.getName() + " lost. "));
|
||||
t.teamcast(war.str("A new battle begins. Team life pools are being reset..."));
|
||||
if(!t.getName().equals(team.getName())) {
|
||||
// all other teams get a point
|
||||
t.addPoint();
|
||||
}
|
||||
}
|
||||
zone.resetState();
|
||||
roundOver = true;
|
||||
} else {
|
||||
team.setRemainingTickets(remaining - 1);
|
||||
}
|
||||
}
|
||||
if(!roundOver) {
|
||||
zone.respawnPlayer(team, player);
|
||||
player.sendMessage(war.str("You died!"));
|
||||
List<Team> teams = zone.getTeams();
|
||||
for(Team t : teams) {
|
||||
t.teamcast(war.str(player.getName() + " died. Team " + team.getName() + " has " + team.getRemainingTickets() + "/" + War.LIFEPOOL + " lives left."));
|
||||
if(team.getRemainingTickets() == 0) {
|
||||
t.teamcast(war.str("Team " + team.getName() + "'s life pool is empty. One more death and they will lose!"));
|
||||
}
|
||||
}
|
||||
war.getLogger().log(Level.INFO, player.getName() + " died and was tp'd back to team " + team.getName() + "'s spawn");
|
||||
} else {
|
||||
war.getLogger().log(Level.INFO, player.getName() + " died and battle ended in team " + team.getName() + "'s disfavor");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void onPlayerMove(Player player, Location from, Location to) {
|
||||
Warzone playerWarzone = war.getPlayerWarzone(player.getName());
|
||||
Team playerTeam = war.getPlayerTeam(player.getName());
|
||||
if(player != null && from != null && to != null &&
|
||||
playerTeam != null && !playerWarzone.contains(to)) {
|
||||
player.sendMessage(war.str("Can't go outside the warzone boundary! Use /leave to exit the battle."));
|
||||
if(playerWarzone.contains(from)){
|
||||
player.teleportTo(from);
|
||||
} else {
|
||||
// somehow the player made it out of the zone
|
||||
player.teleportTo(playerTeam.getTeamSpawn());
|
||||
player.sendMessage(war.str("Brought you back to your team spawn. Use /leave to exit the battle."));
|
||||
}
|
||||
}
|
||||
|
||||
if(to != null && playerTeam != null
|
||||
&& playerWarzone.nearAnyOwnedMonument(to, playerTeam)
|
||||
&& random.nextInt(42) == 3 ) { // one chance out of many of getting healed
|
||||
player.setHealth(30);
|
||||
player.sendMessage(war.str("Your dance has awakened the monument's voodoo. You were granted full health!"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private String getAllTeamsMsg(Player player){
|
||||
String teamsMessage = "Teams: ";
|
||||
if(war.warzone(player.getLocation()).getTeams().isEmpty()){
|
||||
teamsMessage += "none.";
|
||||
}
|
||||
for(Team team : war.warzone(player.getLocation()).getTeams()) {
|
||||
teamsMessage += team.getName() + " (" + team.getPoints() + " points, "+ team.getRemainingTickets() + "/" + War.LIFEPOOL + " lives left. ";
|
||||
for(Player member : team.getPlayers()) {
|
||||
teamsMessage += member.getName() + " ";
|
||||
}
|
||||
teamsMessage += ") ";
|
||||
}
|
||||
return teamsMessage;
|
||||
}
|
||||
|
||||
public void onDisconnect(Player player) {
|
||||
Team team = war.getPlayerTeam(player.getName());
|
||||
if(team != null) {
|
||||
team.removePlayer(player.getName());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean onIgnite(Block block, Player player) {
|
||||
if(player != null) {
|
||||
Team team = war.getPlayerTeam(player.getName());
|
||||
Warzone zone = war.getPlayerWarzone(player.getName());
|
||||
if(team != null && block != null && zone != null && zone.isMonumentFirestone(block)) {
|
||||
Monument monument = zone.getMonumentForFirestone(block);
|
||||
if(!monument.hasOwner()) {
|
||||
monument.ignite(team);
|
||||
List<Team> teams = zone.getTeams();
|
||||
for(Team t : teams) {
|
||||
t.teamcast(war.str("Monument " + monument.getName() + " has been ignited by team " + team.getName() + "."));
|
||||
}
|
||||
} else {
|
||||
player.sendMessage(war.str("Monument must be smothered first."));
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean onFlow(Block blockFrom, Block blockTo) {
|
||||
Block block = null;
|
||||
if(blockTo != null) {
|
||||
block = blockTo;
|
||||
} else if (blockFrom != null) {
|
||||
block = blockFrom;
|
||||
}
|
||||
|
||||
if(block != null) {
|
||||
Warzone zone = war.warzone(new Location(block.getX(), block.getY(), block.getZ()));
|
||||
if(zone != null &&
|
||||
((blockTo != null && zone.isMonumentFirestone(blockTo)
|
||||
|| (blockFrom != null && zone.isMonumentFirestone(blockFrom))))) {
|
||||
Monument monument = null;
|
||||
if(blockTo != null) monument = zone.getMonumentForFirestone(blockTo);
|
||||
if(monument == null && blockFrom != null) monument = zone.getMonumentForFirestone(blockFrom);
|
||||
if(monument.hasOwner()) {
|
||||
monument.setOwnerTeam(null);
|
||||
List<Team> teams = zone.getTeams();
|
||||
for(Team team : teams) {
|
||||
team.teamcast(war.str("Monument " + monument.getName() + " has been smothered."));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,281 +0,0 @@
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Warzone {
|
||||
private String name;
|
||||
private Location northwest;
|
||||
private Location southeast;
|
||||
private final List<Team> teams = new ArrayList<Team>();
|
||||
private final List<Monument> monuments = new ArrayList<Monument>();
|
||||
private final Server server;
|
||||
|
||||
private int[][][] initialState = null;
|
||||
private Location teleport;
|
||||
|
||||
public Warzone(Server server, String name) {
|
||||
this.server = server;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public boolean ready() {
|
||||
if(getNorthwest() != null && getSoutheast() != null
|
||||
&& !tooSmall() && !tooBig()) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean tooSmall() {
|
||||
if((getSoutheast().x - getNorthwest().x < 20)
|
||||
|| (getNorthwest().z - getSoutheast().z < 20)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean tooBig() {
|
||||
if((getSoutheast().x - getNorthwest().x > 1000)
|
||||
|| (getNorthwest().z - getSoutheast().z > 1000)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean contains(Location point) {
|
||||
return ready() && point.x <= getSoutheast().x && point.x >= getNorthwest().x
|
||||
&& point.z <= getNorthwest().z && point.z >= getSoutheast().z;
|
||||
}
|
||||
|
||||
|
||||
public List<Team> getTeams() {
|
||||
return teams;
|
||||
}
|
||||
|
||||
public Team getPlayerTeam(String playerName) {
|
||||
for(Team team : teams) {
|
||||
for(Player player : team.getPlayers()) {
|
||||
if(player.getName().equals(playerName)) {
|
||||
return team;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setNorthwest(Location northwest) {
|
||||
// remove old nw sign, if any (replace with air)
|
||||
if(this.northwest != null) {
|
||||
int x = (int)this.northwest.x;
|
||||
int y = (int)this.northwest.y;
|
||||
int z = (int)this.northwest.z;
|
||||
Block block = new Block(0, x, y, z);
|
||||
server.setBlock(block);
|
||||
}
|
||||
this.northwest = northwest;
|
||||
// add sign
|
||||
int x = (int)northwest.x;
|
||||
int y = (int)northwest.y;
|
||||
int z = (int)northwest.z;
|
||||
Block block = new Block(63, x, y, z, 10); // towards southeast
|
||||
server.setBlock(block);
|
||||
block = server.getBlockAt(x, y, z);
|
||||
ComplexBlock complexBlock = server.getComplexBlock(x, y, z);
|
||||
Sign sign = (Sign)complexBlock;
|
||||
sign.setText(0, "Northwest");
|
||||
sign.setText(1, "corner of");
|
||||
sign.setText(2, "warzone");
|
||||
sign.setText(3, name);
|
||||
sign.update();
|
||||
|
||||
saveState();
|
||||
}
|
||||
|
||||
public Location getNorthwest() {
|
||||
return northwest;
|
||||
}
|
||||
|
||||
public void setSoutheast(Location southeast) {
|
||||
// remove old se sign, if any (replace with air)
|
||||
if(this.southeast != null) {
|
||||
int x = (int)this.southeast.x;
|
||||
int y = (int)this.southeast.y;
|
||||
int z = (int)this.southeast.z;
|
||||
Block block = new Block(0, x, y, z);
|
||||
server.setBlock(block);
|
||||
}
|
||||
this.southeast = southeast;
|
||||
// add sign
|
||||
int x = (int)southeast.x;
|
||||
int y = (int)southeast.y;
|
||||
int z = (int)southeast.z;
|
||||
Block block = new Block(63, x, y, z, 2); // towards northwest
|
||||
server.setBlock(block);
|
||||
block = server.getBlockAt(x, y, z);
|
||||
ComplexBlock complexBlock = server.getComplexBlock(x, y, z);
|
||||
Sign sign = (Sign)complexBlock;
|
||||
sign.setText(0, "Southeast");
|
||||
sign.setText(1, "corner of");
|
||||
sign.setText(2, "warzone");
|
||||
sign.setText(3, name);
|
||||
sign.update();
|
||||
|
||||
saveState();
|
||||
}
|
||||
|
||||
public Location getSoutheast() {
|
||||
return southeast;
|
||||
}
|
||||
|
||||
public void setTeleport(Location location) {
|
||||
this.teleport = location;
|
||||
}
|
||||
|
||||
public Location getTeleport() {
|
||||
return this.teleport;
|
||||
}
|
||||
|
||||
public int saveState() {
|
||||
if(ready()){
|
||||
int northSouth = ((int)(southeast.x)) - ((int)(northwest.x));
|
||||
int eastWest = ((int)(northwest.z)) - ((int)(southeast.z));
|
||||
initialState = new int[northSouth][128][eastWest];
|
||||
int noOfSavedBlocks = 0;
|
||||
int x = (int)northwest.x;
|
||||
int minY = 0;
|
||||
int maxY = 128;
|
||||
for(int i = 0; i < northSouth; i++){
|
||||
int y = minY;
|
||||
for(int j = 0; j < maxY - minY; j++) {
|
||||
int z = (int)southeast.z;
|
||||
for(int k = 0; k < eastWest; k++) {
|
||||
initialState[i][j][k] = server.getBlockIdAt(x, y, z);
|
||||
noOfSavedBlocks++;
|
||||
z++;
|
||||
}
|
||||
y++;
|
||||
}
|
||||
x++;
|
||||
}
|
||||
return noOfSavedBlocks;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Goes back to the saved state of the warzone (resets only block types, not physics).
|
||||
* Also teleports all players back to their respective spawns.
|
||||
* @return
|
||||
*/
|
||||
public int resetState() {
|
||||
if(ready() && initialState != null){
|
||||
// reset blocks
|
||||
int northSouth = ((int)(southeast.x)) - ((int)(northwest.x));
|
||||
int eastWest = ((int)(northwest.z)) - ((int)(southeast.z));
|
||||
int noOfResetBlocks = 0;
|
||||
int noOfFailures = 0;
|
||||
int x = (int)northwest.x;
|
||||
int minY = 0;
|
||||
int maxY = 128;
|
||||
for(int i = 0; i < northSouth; i++){
|
||||
int y = minY;
|
||||
for(int j = 0; j < maxY - minY; j++) {
|
||||
int z = (int)southeast.z;
|
||||
for(int k = 0; k < eastWest; k++) {
|
||||
int currentType = server.getBlockIdAt(x, y, z);
|
||||
int initialType = initialState[i][j][k];
|
||||
if(currentType != initialType) {
|
||||
if(server.setBlockAt(initialType,x, y, z)) {
|
||||
noOfResetBlocks++;
|
||||
} else {
|
||||
noOfFailures++;
|
||||
}
|
||||
}
|
||||
z++;
|
||||
}
|
||||
y++;
|
||||
}
|
||||
x++;
|
||||
}
|
||||
|
||||
// everyone back to team spawn with full health
|
||||
for(Team team : teams) {
|
||||
for(Player player : team.getPlayers()) {
|
||||
respawnPlayer(team, player);
|
||||
}
|
||||
team.setRemainingTickets(War.LIFEPOOL);
|
||||
}
|
||||
|
||||
// reset monuments
|
||||
for(Monument monument : monuments) {
|
||||
monument.reset();
|
||||
}
|
||||
|
||||
this.setNorthwest(this.getNorthwest());
|
||||
this.setSoutheast(this.getSoutheast());
|
||||
|
||||
return noOfResetBlocks;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void endRound() {
|
||||
|
||||
}
|
||||
|
||||
public void respawnPlayer(Team team, Player player) {
|
||||
Inventory playerInv = player.getInventory();
|
||||
playerInv.clearContents();
|
||||
playerInv.update();
|
||||
playerInv.setSlot(new Item(Item.Type.StoneSword), 0);
|
||||
playerInv.setSlot(new Item(Item.Type.Bow), 1);
|
||||
playerInv.setSlot(new Item(Item.Type.Arrow, 12), 2);
|
||||
playerInv.setSlot(new Item(Item.Type.StonePickaxe), 3);
|
||||
playerInv.setSlot(new Item(Item.Type.StoneSpade), 4);
|
||||
playerInv.addItem(new Item(Item.Type.Bread, 3));
|
||||
playerInv.setSlot(new Item(Item.Type.LeatherBoots), 100);
|
||||
playerInv.setSlot(new Item(Item.Type.LeatherLeggings), 101);
|
||||
playerInv.setSlot(new Item(Item.Type.LeatherChestplate), 102);
|
||||
playerInv.setSlot(new Item(Item.Type.LeatherHelmet), 103);
|
||||
playerInv.update();
|
||||
player.setHealth(30);
|
||||
player.setFireTicks(0);
|
||||
player.teleportTo(team.getTeamSpawn());
|
||||
}
|
||||
|
||||
public boolean isMonumentFirestone(Block block) {
|
||||
for(Monument monument : monuments) {
|
||||
int x = (int)monument.getLocation().x;
|
||||
int y = (int)monument.getLocation().y;
|
||||
int z = (int)monument.getLocation().z;
|
||||
if(x == block.getX() && y == block.getY() && z == block.getZ()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Monument getMonumentForFirestone(Block block) {
|
||||
for(Monument monument : monuments) {
|
||||
int x = (int)monument.getLocation().x;
|
||||
int y = (int)monument.getLocation().y;
|
||||
int z = (int)monument.getLocation().z;
|
||||
if(x == block.getX() && y == block.getY() && z == block.getZ()) {
|
||||
return monument;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean nearAnyOwnedMonument(Location to, Team team) {
|
||||
for(Monument monument : monuments) {
|
||||
if(monument.isNear(to) && monument.isOwner(team)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<Monument> getMomuments() {
|
||||
return monuments;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,137 @@
|
|||
<?xml version="1.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>
|
||||
<groupId>com.tommytony</groupId>
|
||||
<artifactId>war</artifactId>
|
||||
<version>2.1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>War</name>
|
||||
<url>http://war.tommytony.com</url>
|
||||
<description>Minecraft PVP arenas (called warzones) for a fast-paced and structured PVP experience with TDM, CTF and more!</description>
|
||||
<prerequisites>
|
||||
<maven>2.2.1</maven>
|
||||
</prerequisites>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>maven.cmastudios.me</id>
|
||||
<url>https://maven.cmastudios.me/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>sk89q-repo</id>
|
||||
<url>https://maven.sk89q.com/repo/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<issueManagement>
|
||||
<system>Github issues</system>
|
||||
<url>https://github.com/taoneill/war/issues</url>
|
||||
</issueManagement>
|
||||
<scm>
|
||||
<connection>scm:git:git://github.com/taoneill/war.git</connection>
|
||||
<developerConnection>scm:git:git@github.com:taoneill/war.git</developerConnection>
|
||||
<tag>HEAD</tag>
|
||||
<url>https://github.com/taoneill/war</url>
|
||||
</scm>
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>maven.cmastudios.me</id>
|
||||
<url>s3://maven.cmastudios.me/</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.0.2</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>1.7.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>org.mcstats.bukkit:metrics</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
<minimizeJar>false</minimizeJar>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>org.mcstats</pattern>
|
||||
<shadedPattern>com.tommytony.war.metrics</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<extensions>
|
||||
<extension>
|
||||
<groupId>org.kuali.maven.wagons</groupId>
|
||||
<artifactId>maven-s3-wagon</artifactId>
|
||||
<version>1.2.1</version>
|
||||
</extension>
|
||||
</extensions>
|
||||
<resources>
|
||||
<resource>
|
||||
<filtering>true</filtering>
|
||||
<directory>${basedir}/src/main/resources/</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.13-R0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-all</artifactId>
|
||||
<version>1.9.5</version>
|
||||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.tommytony</groupId>
|
||||
<artifactId>worldedit-bukkit</artifactId>
|
||||
<version>7.0.0-beta-01</version>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mcstats.bukkit</groupId>
|
||||
<artifactId>metrics</artifactId>
|
||||
<version>R8-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.milkbowl.vault</groupId>
|
||||
<artifactId>Vault</artifactId>
|
||||
<version>1.2.32</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,772 @@
|
|||
package com.tommytony.war;
|
||||
|
||||
import com.tommytony.war.config.*;
|
||||
import com.tommytony.war.utility.Direction;
|
||||
import com.tommytony.war.volume.Volume;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.Sign;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
public class Team {
|
||||
private final Warzone warzone;
|
||||
Random teamSpawnRandomizer = new Random();
|
||||
private List<Player> players = new ArrayList<Player>();
|
||||
private List<Player> teamChatPlayers = new ArrayList<Player>();
|
||||
private List<Location> teamSpawns;
|
||||
private Location teamFlag = null;
|
||||
private String name;
|
||||
private int remainingLives;
|
||||
private int points = 0;
|
||||
private Map<Location, Volume> spawnVolumes;
|
||||
private Volume flagVolume;
|
||||
private TeamKind kind;
|
||||
private TeamConfigBag teamConfig;
|
||||
private InventoryBag inventories;
|
||||
|
||||
public Team(String name, TeamKind kind, List<Location> teamSpawn, Warzone warzone) {
|
||||
this.warzone = warzone;
|
||||
this.teamConfig = new TeamConfigBag(warzone);
|
||||
this.inventories = new InventoryBag(warzone); // important constructors for cascading configs
|
||||
this.setName(name);
|
||||
this.teamSpawns = new ArrayList<Location>(teamSpawn);
|
||||
this.spawnVolumes = new HashMap<Location, Volume>();
|
||||
for (Location spawn : teamSpawn) {
|
||||
this.setSpawnVolume(spawn, new Volume(name + teamSpawns.indexOf(spawn), warzone.getWorld()));
|
||||
}
|
||||
this.kind = kind;
|
||||
this.setFlagVolume(null); // no flag at the start
|
||||
}
|
||||
|
||||
public static Team getTeamByPlayerName(String playerName) {
|
||||
for (Warzone warzone : War.war.getWarzones()) {
|
||||
Team team = warzone.getPlayerTeam(playerName);
|
||||
if (team != null) {
|
||||
return team;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Warzone getZone() {
|
||||
return this.warzone;
|
||||
}
|
||||
|
||||
public TeamKind getKind() {
|
||||
return this.kind;
|
||||
}
|
||||
|
||||
private void createSpawnVolume(Location teamSpawn) {
|
||||
Volume spawnVolume = this.spawnVolumes.get(teamSpawn);
|
||||
if (spawnVolume.isSaved()) {
|
||||
spawnVolume.resetBlocks();
|
||||
}
|
||||
int x = teamSpawn.getBlockX();
|
||||
int y = teamSpawn.getBlockY();
|
||||
int z = teamSpawn.getBlockZ();
|
||||
|
||||
TeamSpawnStyle style = this.getTeamConfig().resolveSpawnStyle();
|
||||
if (style.equals(TeamSpawnStyle.INVISIBLE)) {
|
||||
spawnVolume.setCornerOne(this.warzone.getWorld().getBlockAt(x, y - 1, z));
|
||||
spawnVolume.setCornerTwo(this.warzone.getWorld().getBlockAt(x, y + 3, z));
|
||||
} else if (style.equals(TeamSpawnStyle.SMALL)) {
|
||||
spawnVolume.setCornerOne(this.warzone.getWorld().getBlockAt(x - 1, y - 1, z - 1));
|
||||
spawnVolume.setCornerTwo(this.warzone.getWorld().getBlockAt(x + 1, y + 3, z + 1));
|
||||
} else {
|
||||
// flat or big
|
||||
spawnVolume.setCornerOne(this.warzone.getWorld().getBlockAt(x - 2, y - 1, z - 2));
|
||||
spawnVolume.setCornerTwo(this.warzone.getWorld().getBlockAt(x + 2, y + 3, z + 2));
|
||||
}
|
||||
}
|
||||
|
||||
public void initializeTeamSpawns() {
|
||||
for (Location teamSpawn : this.spawnVolumes.keySet()) {
|
||||
initializeTeamSpawn(teamSpawn);
|
||||
}
|
||||
}
|
||||
|
||||
public void initializeTeamSpawn(Location teamSpawn) {
|
||||
// Set the spawn
|
||||
int x = teamSpawn.getBlockX();
|
||||
int y = teamSpawn.getBlockY();
|
||||
int z = teamSpawn.getBlockZ();
|
||||
|
||||
ItemStack light = this.warzone.getWarzoneMaterials().getLightBlock();
|
||||
|
||||
TeamSpawnStyle style = this.getTeamConfig().resolveSpawnStyle();
|
||||
if (!style.equals(TeamSpawnStyle.INVISIBLE)) {
|
||||
// first ring
|
||||
this.setBlock(x + 1, y - 1, z + 1, this.kind);
|
||||
this.setBlock(x + 1, y - 1, z, this.kind);
|
||||
this.setBlock(x + 1, y - 1, z - 1, this.kind);
|
||||
this.setBlock(x, y - 1, z + 1, this.kind);
|
||||
BlockState lightBlock = this.warzone.getWorld().getBlockAt(x, y - 1, z).getState();
|
||||
lightBlock.setType(light.getType());
|
||||
lightBlock.setData(light.getData());
|
||||
lightBlock.update(true);
|
||||
this.setBlock(x, y - 1, z - 1, this.kind);
|
||||
this.setBlock(x - 1, y - 1, z + 1, this.kind);
|
||||
this.setBlock(x - 1, y - 1, z, this.kind);
|
||||
this.setBlock(x - 1, y - 1, z - 1, this.kind);
|
||||
}
|
||||
|
||||
// Orientation
|
||||
int yaw = 0;
|
||||
if (teamSpawn.getYaw() >= 0) {
|
||||
yaw = (int) (teamSpawn.getYaw() % 360);
|
||||
} else {
|
||||
yaw = (int) (360 + (teamSpawn.getYaw() % 360));
|
||||
}
|
||||
Block signBlock = null;
|
||||
BlockFace signDirection = null;
|
||||
|
||||
if (style.equals(TeamSpawnStyle.SMALL)) {
|
||||
// SMALL style
|
||||
if (yaw >= 0 && yaw < 90) {
|
||||
signDirection = BlockFace.SOUTH_WEST.getOppositeFace();
|
||||
signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(Direction.NORTH()).getRelative(Direction.WEST());
|
||||
} else if (yaw >= 90 && yaw <= 180) {
|
||||
signDirection = BlockFace.NORTH_WEST.getOppositeFace();
|
||||
signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(Direction.NORTH()).getRelative(Direction.EAST());
|
||||
} else if (yaw >= 180 && yaw < 270) {
|
||||
signDirection = BlockFace.NORTH_EAST.getOppositeFace();
|
||||
signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(Direction.SOUTH()).getRelative(Direction.EAST());
|
||||
} else if (yaw >= 270 && yaw <= 360) {
|
||||
signDirection = BlockFace.SOUTH_EAST.getOppositeFace();
|
||||
signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(Direction.SOUTH()).getRelative(Direction.WEST());
|
||||
}
|
||||
} else if (!style.equals(TeamSpawnStyle.INVISIBLE)) {
|
||||
// outer ring (FLAT or BIG)
|
||||
this.setBlock(x + 2, y - 1, z + 2, this.kind);
|
||||
this.setBlock(x + 2, y - 1, z + 1, this.kind);
|
||||
this.setBlock(x + 2, y - 1, z, this.kind);
|
||||
this.setBlock(x + 2, y - 1, z - 1, this.kind);
|
||||
this.setBlock(x + 2, y - 1, z - 2, this.kind);
|
||||
|
||||
this.setBlock(x - 1, y - 1, z + 2, this.kind);
|
||||
this.setBlock(x - 1, y - 1, z - 2, this.kind);
|
||||
|
||||
this.setBlock(x, y - 1, z + 2, this.kind);
|
||||
this.setBlock(x, y - 1, z - 2, this.kind);
|
||||
|
||||
this.setBlock(x + 1, y - 1, z + 2, this.kind);
|
||||
this.setBlock(x + 1, y - 1, z - 2, this.kind);
|
||||
|
||||
this.setBlock(x - 2, y - 1, z + 2, this.kind);
|
||||
this.setBlock(x - 2, y - 1, z + 1, this.kind);
|
||||
this.setBlock(x - 2, y - 1, z, this.kind);
|
||||
this.setBlock(x - 2, y - 1, z - 1, this.kind);
|
||||
this.setBlock(x - 2, y - 1, z - 2, this.kind);
|
||||
|
||||
if (yaw >= 0 && yaw < 90) {
|
||||
signDirection = BlockFace.SOUTH_WEST.getOppositeFace();
|
||||
signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(Direction.NORTH(), 2).getRelative(Direction.WEST(), 2);
|
||||
|
||||
if (style.equals(TeamSpawnStyle.BIG)) {
|
||||
// rim
|
||||
this.setBlock(x - 2, y, z - 1, this.kind);
|
||||
this.setBlock(x - 2, y, z - 2, this.kind);
|
||||
this.setBlock(x - 1, y, z - 2, this.kind);
|
||||
this.setBlock(x, y, z - 2, this.kind);
|
||||
this.setBlock(x + 1, y, z - 2, this.kind);
|
||||
this.setBlock(x + 2, y, z - 2, this.kind);
|
||||
this.setBlock(x + 2, y, z - 1, this.kind);
|
||||
this.setBlock(x + 2, y, z, this.kind);
|
||||
this.setBlock(x + 2, y, z + 1, this.kind);
|
||||
this.setBlock(x + 2, y, z + 2, this.kind);
|
||||
this.setBlock(x + 1, y, z + 2, this.kind);
|
||||
|
||||
// tower
|
||||
this.setBlock(x, y + 1, z - 2, this.kind);
|
||||
this.setBlock(x + 1, y + 1, z - 2, this.kind);
|
||||
this.setBlock(x + 2, y + 1, z - 2, this.kind);
|
||||
this.setBlock(x + 2, y + 1, z - 1, this.kind);
|
||||
this.setBlock(x + 2, y + 1, z, this.kind);
|
||||
|
||||
this.setBlock(x + 1, y + 2, z - 2, this.kind);
|
||||
this.setBlock(x + 2, y + 2, z - 2, this.kind);
|
||||
this.setBlock(x + 2, y + 2, z - 1, this.kind);
|
||||
|
||||
this.setBlock(x + 2, y + 3, z - 2, this.kind);
|
||||
}
|
||||
} else if (yaw >= 90 && yaw <= 180) {
|
||||
signDirection = BlockFace.NORTH_WEST.getOppositeFace();
|
||||
signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(Direction.NORTH(), 2).getRelative(Direction.EAST(), 2);
|
||||
if (style.equals(TeamSpawnStyle.BIG)) {
|
||||
// rim
|
||||
this.setBlock(x + 1, y, z - 2, this.kind);
|
||||
this.setBlock(x + 2, y, z - 2, this.kind);
|
||||
this.setBlock(x + 2, y, z - 1, this.kind);
|
||||
this.setBlock(x + 2, y, z, this.kind);
|
||||
this.setBlock(x + 2, y, z + 1, this.kind);
|
||||
this.setBlock(x + 2, y, z + 2, this.kind);
|
||||
this.setBlock(x + 1, y, z + 2, this.kind);
|
||||
this.setBlock(x, y, z + 2, this.kind);
|
||||
this.setBlock(x - 1, y, z + 2, this.kind);
|
||||
this.setBlock(x - 2, y, z + 2, this.kind);
|
||||
this.setBlock(x - 2, y, z + 1, this.kind);
|
||||
|
||||
// tower
|
||||
this.setBlock(x + 2, y + 1, z, this.kind);
|
||||
this.setBlock(x + 2, y + 1, z + 1, this.kind);
|
||||
this.setBlock(x + 2, y + 1, z + 2, this.kind);
|
||||
this.setBlock(x + 1, y + 1, z + 2, this.kind);
|
||||
this.setBlock(x, y + 1, z + 2, this.kind);
|
||||
|
||||
this.setBlock(x + 2, y + 2, z + 1, this.kind);
|
||||
this.setBlock(x + 2, y + 2, z + 2, this.kind);
|
||||
this.setBlock(x + 1, y + 2, z + 2, this.kind);
|
||||
|
||||
this.setBlock(x + 2, y + 3, z + 2, this.kind);
|
||||
}
|
||||
} else if (yaw >= 180 && yaw < 270) {
|
||||
signDirection = BlockFace.NORTH_EAST.getOppositeFace();
|
||||
signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(Direction.SOUTH(), 2).getRelative(Direction.EAST(), 2);
|
||||
if (style.equals(TeamSpawnStyle.BIG)) {
|
||||
// rim
|
||||
this.setBlock(x + 2, y, z + 1, this.kind);
|
||||
this.setBlock(x + 2, y, z + 2, this.kind);
|
||||
this.setBlock(x + 1, y, z + 2, this.kind);
|
||||
this.setBlock(x, y, z + 2, this.kind);
|
||||
this.setBlock(x - 1, y, z + 2, this.kind);
|
||||
this.setBlock(x - 2, y, z + 2, this.kind);
|
||||
this.setBlock(x - 2, y, z + 1, this.kind);
|
||||
this.setBlock(x - 2, y, z, this.kind);
|
||||
this.setBlock(x - 2, y, z - 1, this.kind);
|
||||
this.setBlock(x - 2, y, z - 2, this.kind);
|
||||
this.setBlock(x - 1, y, z - 2, this.kind);
|
||||
|
||||
// tower
|
||||
this.setBlock(x, y + 1, z + 2, this.kind);
|
||||
this.setBlock(x - 1, y + 1, z + 2, this.kind);
|
||||
this.setBlock(x - 2, y + 1, z + 2, this.kind);
|
||||
this.setBlock(x - 2, y + 1, z + 1, this.kind);
|
||||
this.setBlock(x - 2, y + 1, z, this.kind);
|
||||
|
||||
this.setBlock(x - 1, y + 2, z + 2, this.kind);
|
||||
this.setBlock(x - 2, y + 2, z + 2, this.kind);
|
||||
this.setBlock(x - 2, y + 2, z + 1, this.kind);
|
||||
|
||||
this.setBlock(x - 2, y + 3, z + 2, this.kind);
|
||||
}
|
||||
} else if (yaw >= 270 && yaw <= 360) {
|
||||
signDirection = BlockFace.SOUTH_EAST.getOppositeFace();
|
||||
signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(Direction.SOUTH(), 2).getRelative(Direction.WEST(), 2);
|
||||
if (style.equals(TeamSpawnStyle.BIG)) {
|
||||
// rim
|
||||
this.setBlock(x - 1, y, z + 2, this.kind);
|
||||
this.setBlock(x - 2, y, z + 2, this.kind);
|
||||
this.setBlock(x - 2, y, z + 1, this.kind);
|
||||
this.setBlock(x - 2, y, z, this.kind);
|
||||
this.setBlock(x - 2, y, z - 1, this.kind);
|
||||
this.setBlock(x - 2, y, z - 2, this.kind);
|
||||
this.setBlock(x - 1, y, z - 2, this.kind);
|
||||
this.setBlock(x, y, z - 2, this.kind);
|
||||
this.setBlock(x + 1, y, z - 2, this.kind);
|
||||
this.setBlock(x + 2, y, z - 2, this.kind);
|
||||
this.setBlock(x + 2, y, z - 1, this.kind);
|
||||
|
||||
// tower
|
||||
this.setBlock(x - 2, y + 1, z, this.kind);
|
||||
this.setBlock(x - 2, y + 1, z - 1, this.kind);
|
||||
this.setBlock(x - 2, y + 1, z - 2, this.kind);
|
||||
this.setBlock(x - 1, y + 1, z - 2, this.kind);
|
||||
this.setBlock(x, y + 1, z - 2, this.kind);
|
||||
|
||||
this.setBlock(x - 2, y + 2, z - 1, this.kind);
|
||||
this.setBlock(x - 2, y + 2, z - 2, this.kind);
|
||||
this.setBlock(x - 1, y + 2, z - 2, this.kind);
|
||||
|
||||
this.setBlock(x - 2, y + 3, z - 2, this.kind);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (signBlock != null) {
|
||||
String[] lines;
|
||||
if (this.getTeamConfig().resolveInt(TeamConfig.LIFEPOOL) == -1) {
|
||||
lines = MessageFormat
|
||||
.format(War.war.getString("sign.team.unlimited"),
|
||||
this.name,
|
||||
this.players.size(),
|
||||
this.getTeamConfig().resolveInt(
|
||||
TeamConfig.TEAMSIZE),
|
||||
this.points,
|
||||
this.getTeamConfig().resolveInt(
|
||||
TeamConfig.MAXSCORE)).split("\n");
|
||||
} else {
|
||||
lines = MessageFormat
|
||||
.format(War.war.getString("sign.team.limited"),
|
||||
this.name,
|
||||
this.players.size(),
|
||||
this.getTeamConfig().resolveInt(
|
||||
TeamConfig.TEAMSIZE),
|
||||
this.points,
|
||||
this.getTeamConfig().resolveInt(
|
||||
TeamConfig.MAXSCORE),
|
||||
this.remainingLives,
|
||||
this.getTeamConfig().resolveInt(
|
||||
TeamConfig.LIFEPOOL)).split("\n");
|
||||
}
|
||||
signBlock.setType(Material.SIGN);
|
||||
org.bukkit.block.Sign block = (org.bukkit.block.Sign) signBlock
|
||||
.getState();
|
||||
org.bukkit.material.Sign data = (Sign) block.getData();
|
||||
data.setFacingDirection(signDirection);
|
||||
block.setData(data);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
block.setLine(i, lines[i]);
|
||||
}
|
||||
block.update(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void setBlock(int x, int y, int z, TeamKind kind) {
|
||||
BlockState block = this.warzone.getWorld().getBlockAt(x, y, z).getState();
|
||||
block.setType(kind.getMaterial());
|
||||
block.update(true);
|
||||
}
|
||||
|
||||
public void addTeamSpawn(Location teamSpawn) {
|
||||
if (!this.teamSpawns.contains(teamSpawn)) {
|
||||
this.teamSpawns.add(teamSpawn);
|
||||
}
|
||||
// this resets the block to old state
|
||||
this.setSpawnVolume(teamSpawn, new Volume(name + teamSpawns.indexOf(teamSpawn), warzone.getWorld()));
|
||||
this.createSpawnVolume(teamSpawn);
|
||||
this.spawnVolumes.get(teamSpawn).saveBlocks();
|
||||
|
||||
this.initializeTeamSpawn(teamSpawn);
|
||||
}
|
||||
|
||||
public List<Location> getTeamSpawns() {
|
||||
return this.teamSpawns;
|
||||
}
|
||||
|
||||
public Location getRandomSpawn() {
|
||||
return this.teamSpawns.get(teamSpawnRandomizer.nextInt(this.teamSpawns.size()));
|
||||
}
|
||||
|
||||
public void addPlayer(Player player) {
|
||||
this.players.add(player);
|
||||
if (this.warzone.getScoreboard() != null && this.warzone.getScoreboardType() != ScoreboardType.NONE) {
|
||||
player.setScoreboard(this.warzone.getScoreboard());
|
||||
}
|
||||
warzone.updateScoreboard();
|
||||
boolean cooldownEnabled = War.war.getWarConfig().getBoolean(WarConfig.DISABLECOOLDOWN);
|
||||
if(cooldownEnabled) {
|
||||
player.getAttribute(Attribute.GENERIC_ATTACK_SPEED).setBaseValue(1024.0);
|
||||
} else {
|
||||
player.getAttribute(Attribute.GENERIC_ATTACK_SPEED).setBaseValue(4.0);
|
||||
}
|
||||
}
|
||||
|
||||
public List<Player> getPlayers() {
|
||||
return this.players;
|
||||
}
|
||||
|
||||
public void teamcast(String message) {
|
||||
// by default a teamcast is a notification
|
||||
teamcast(message, true);
|
||||
}
|
||||
|
||||
public void teamcast(String message, boolean isNotification) {
|
||||
for (Player player : this.players) {
|
||||
War.war.msg(player, message);
|
||||
}
|
||||
}
|
||||
|
||||
public void teamcast(String message, Object... args) {
|
||||
// by default a teamcast is a notification
|
||||
teamcast(message, true, args);
|
||||
}
|
||||
|
||||
public void teamcast(String message, boolean isNotification, Object... args) {
|
||||
for (Player player : this.players) {
|
||||
War.war.msg(player, message, args);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an achievement to all players on the team.
|
||||
* Currently implemented using SpoutCraft.
|
||||
* @param line1 Achievement first line
|
||||
* @param line2 Achievement second line
|
||||
* @param icon Item to display in the achievement
|
||||
* @param ticks Duration the achievement should be displayed
|
||||
*/
|
||||
public void sendAchievement(String line1, String line2, ItemStack icon, int ticks) {
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void removePlayer(Player thePlayer) {
|
||||
this.players.remove(thePlayer);
|
||||
synchronized (teamChatPlayers) {
|
||||
this.teamChatPlayers.remove(thePlayer);
|
||||
}
|
||||
this.warzone.dropAllStolenObjects(thePlayer, false);
|
||||
thePlayer.setFireTicks(0);
|
||||
thePlayer.setRemainingAir(300);
|
||||
if (!this.warzone.getReallyDeadFighters().contains(thePlayer.getName())) {
|
||||
this.warzone.restorePlayerState(thePlayer);
|
||||
}
|
||||
this.warzone.getLoadoutSelections().remove(thePlayer);
|
||||
warzone.updateScoreboard();
|
||||
thePlayer.getAttribute(Attribute.GENERIC_ATTACK_SPEED).setBaseValue(4.0);
|
||||
}
|
||||
|
||||
public int getRemainingLives() {
|
||||
return this.remainingLives;
|
||||
}
|
||||
|
||||
public void setRemainingLives(int remainingLives) {
|
||||
this.remainingLives = remainingLives;
|
||||
warzone.updateScoreboard();
|
||||
}
|
||||
|
||||
public void addPoint() {
|
||||
boolean atLeastOnePlayerOnTeam = this.players.size() != 0;
|
||||
boolean atLeastOnePlayerOnOtherTeam = false;
|
||||
for (Team team : this.warzone.getTeams()) {
|
||||
if (!team.getName().equals(this.getName()) && team.getPlayers().size() > 0) {
|
||||
atLeastOnePlayerOnOtherTeam = true;
|
||||
}
|
||||
}
|
||||
if (atLeastOnePlayerOnTeam && atLeastOnePlayerOnOtherTeam) {
|
||||
this.points++;
|
||||
} else if (!atLeastOnePlayerOnOtherTeam) {
|
||||
this.teamcast("zone.score.empty");
|
||||
}
|
||||
this.warzone.updateScoreboard();
|
||||
}
|
||||
|
||||
public int getPoints() {
|
||||
return this.points;
|
||||
}
|
||||
|
||||
public Map<Location, Volume> getSpawnVolumes() {
|
||||
|
||||
return this.spawnVolumes;
|
||||
}
|
||||
|
||||
public void resetSign() {
|
||||
for (Entry<Location, Volume> spawnEntry : this.getSpawnVolumes().entrySet()) {
|
||||
spawnEntry.getValue().resetBlocks();
|
||||
this.initializeTeamSpawn(spawnEntry.getKey()); // reset everything instead of just sign
|
||||
}
|
||||
if (this.warzone.getLobby() != null) {
|
||||
this.warzone.getLobby().resetTeamGateSign(this);
|
||||
}
|
||||
if (War.war.getWarHub() != null) {
|
||||
War.war.getWarHub().resetZoneSign(warzone);
|
||||
}
|
||||
}
|
||||
|
||||
public void setSpawnVolume(Location spawnLocation, Volume volume) {
|
||||
this.spawnVolumes.put(spawnLocation, volume);
|
||||
}
|
||||
|
||||
public void resetPoints() {
|
||||
this.points = 0;
|
||||
warzone.updateScoreboard();
|
||||
}
|
||||
|
||||
public Volume getFlagVolume() {
|
||||
return this.flagVolume;
|
||||
}
|
||||
|
||||
public void setFlagVolume(Volume flagVolume) {
|
||||
this.flagVolume = flagVolume;
|
||||
}
|
||||
|
||||
private void setFlagVolume() {
|
||||
if (this.flagVolume == null) {
|
||||
this.flagVolume = new Volume(this.getName() + "flag", this.warzone.getWorld());
|
||||
}
|
||||
if (this.flagVolume.isSaved()) {
|
||||
this.flagVolume.resetBlocks();
|
||||
}
|
||||
int x = this.teamFlag.getBlockX();
|
||||
int y = this.teamFlag.getBlockY();
|
||||
int z = this.teamFlag.getBlockZ();
|
||||
this.flagVolume.setCornerOne(this.warzone.getWorld().getBlockAt(x - 1, y - 1, z - 1));
|
||||
this.flagVolume.setCornerTwo(this.warzone.getWorld().getBlockAt(x + 1, y + 3, z + 1));
|
||||
}
|
||||
|
||||
public void initializeTeamFlag() {
|
||||
// make air (old two-high above floor)
|
||||
Volume airGap = new Volume(new Location(this.flagVolume.getWorld(),
|
||||
this.flagVolume.getCornerOne().getX(), this.flagVolume
|
||||
.getCornerOne().getY() + 1, this.flagVolume
|
||||
.getCornerOne().getZ()), new Location(
|
||||
this.flagVolume.getWorld(), this.flagVolume.getCornerTwo()
|
||||
.getX(), this.flagVolume.getCornerOne().getY() + 2,
|
||||
this.flagVolume.getCornerTwo().getZ()));
|
||||
airGap.setToMaterial(Material.AIR);
|
||||
|
||||
// Set the flag blocks
|
||||
int x = this.teamFlag.getBlockX();
|
||||
int y = this.teamFlag.getBlockY();
|
||||
int z = this.teamFlag.getBlockZ();
|
||||
|
||||
// first ring
|
||||
BlockState current = this.warzone.getWorld().getBlockAt(x + 1, y - 1, z + 1).getState();
|
||||
current.setType(this.warzone.getWarzoneMaterials().getMainBlock().getType());
|
||||
current.setData(this.warzone.getWarzoneMaterials().getMainBlock().getData());
|
||||
current.update(true);
|
||||
current = this.warzone.getWorld().getBlockAt(x + 1, y - 1, z).getState();
|
||||
current.setType(this.warzone.getWarzoneMaterials().getMainBlock().getType());
|
||||
current.setData(this.warzone.getWarzoneMaterials().getMainBlock().getData());
|
||||
current.update(true);
|
||||
current = this.warzone.getWorld().getBlockAt(x + 1, y - 1, z - 1).getState();
|
||||
current.setType(this.warzone.getWarzoneMaterials().getMainBlock().getType());
|
||||
current.setData(this.warzone.getWarzoneMaterials().getMainBlock().getData());
|
||||
current.update(true);
|
||||
current = this.warzone.getWorld().getBlockAt(x, y - 1, z + 1).getState();
|
||||
current.setType(this.warzone.getWarzoneMaterials().getMainBlock().getType());
|
||||
current.setData(this.warzone.getWarzoneMaterials().getMainBlock().getData());
|
||||
current.update(true);
|
||||
current = this.warzone.getWorld().getBlockAt(x, y - 1, z).getState();
|
||||
current.setType(this.warzone.getWarzoneMaterials().getLightBlock().getType());
|
||||
current.setData(this.warzone.getWarzoneMaterials().getLightBlock().getData());
|
||||
current.update(true);
|
||||
current = this.warzone.getWorld().getBlockAt(x, y - 1, z - 1).getState();
|
||||
current.setType(this.warzone.getWarzoneMaterials().getMainBlock().getType());
|
||||
current.setData(this.warzone.getWarzoneMaterials().getMainBlock().getData());
|
||||
current.update(true);
|
||||
current = this.warzone.getWorld().getBlockAt(x - 1, y - 1, z + 1).getState();
|
||||
current.setType(this.warzone.getWarzoneMaterials().getMainBlock().getType());
|
||||
current.setData(this.warzone.getWarzoneMaterials().getMainBlock().getData());
|
||||
current.update(true);
|
||||
current = this.warzone.getWorld().getBlockAt(x - 1, y - 1, z).getState();
|
||||
current.setType(this.warzone.getWarzoneMaterials().getMainBlock().getType());
|
||||
current.setData(this.warzone.getWarzoneMaterials().getMainBlock().getData());
|
||||
current.update(true);
|
||||
current = this.warzone.getWorld().getBlockAt(x - 1, y - 1, z - 1).getState();
|
||||
current.setType(this.warzone.getWarzoneMaterials().getMainBlock().getType());
|
||||
current.setData(this.warzone.getWarzoneMaterials().getMainBlock().getData());
|
||||
current.update(true);
|
||||
|
||||
// flag
|
||||
BlockState flagBlock = this.warzone.getWorld().getBlockAt(x, y + 1, z).getState();
|
||||
flagBlock.setType(this.kind.getMaterial());
|
||||
flagBlock.update(true);
|
||||
|
||||
// Flag post using Orientation
|
||||
int yaw = 0;
|
||||
if (this.teamFlag.getYaw() >= 0) {
|
||||
yaw = (int) (this.teamFlag.getYaw() % 360);
|
||||
} else {
|
||||
yaw = (int) (360 + (this.teamFlag.getYaw() % 360));
|
||||
}
|
||||
if ((yaw >= 0 && yaw < 45) || (yaw >= 315 && yaw <= 360)) {
|
||||
current = this.warzone.getWorld().getBlockAt(x, y, z - 1).getState();
|
||||
current.setType(this.warzone.getWarzoneMaterials().getStandBlock().getType());
|
||||
current.setData(this.warzone.getWarzoneMaterials().getStandBlock().getData());
|
||||
current.update(true);
|
||||
current = this.warzone.getWorld().getBlockAt(x, y + 1, z - 1).getState();
|
||||
current.setType(this.warzone.getWarzoneMaterials().getStandBlock().getType());
|
||||
current.setData(this.warzone.getWarzoneMaterials().getStandBlock().getData());
|
||||
current.update(true);
|
||||
} else if (yaw >= 45 && yaw < 135) {
|
||||
current = this.warzone.getWorld().getBlockAt(x + 1, y, z).getState();
|
||||
current.setType(this.warzone.getWarzoneMaterials().getStandBlock().getType());
|
||||
current.setData(this.warzone.getWarzoneMaterials().getStandBlock().getData());
|
||||
current.update(true);
|
||||
current = this.warzone.getWorld().getBlockAt(x + 1, y + 1, z).getState();
|
||||
current.setType(this.warzone.getWarzoneMaterials().getStandBlock().getType());
|
||||
current.setData(this.warzone.getWarzoneMaterials().getStandBlock().getData());
|
||||
current.update(true);
|
||||
} else if (yaw >= 135 && yaw < 225) {
|
||||
current = this.warzone.getWorld().getBlockAt(x, y, z + 1).getState();
|
||||
current.setType(this.warzone.getWarzoneMaterials().getStandBlock().getType());
|
||||
current.setData(this.warzone.getWarzoneMaterials().getStandBlock().getData());
|
||||
current.update(true);
|
||||
current = this.warzone.getWorld().getBlockAt(x, y + 1, z + 1).getState();
|
||||
current.setType(this.warzone.getWarzoneMaterials().getStandBlock().getType());
|
||||
current.setData(this.warzone.getWarzoneMaterials().getStandBlock().getData());
|
||||
current.update(true);
|
||||
} else if (yaw >= 225 && yaw < 315) {
|
||||
current = this.warzone.getWorld().getBlockAt(x - 1, y, z).getState();
|
||||
current.setType(this.warzone.getWarzoneMaterials().getStandBlock().getType());
|
||||
current.setData(this.warzone.getWarzoneMaterials().getStandBlock().getData());
|
||||
current.update(true);
|
||||
current = this.warzone.getWorld().getBlockAt(x - 1, y + 1, z).getState();
|
||||
current.setType(this.warzone.getWarzoneMaterials().getStandBlock().getType());
|
||||
current.setData(this.warzone.getWarzoneMaterials().getStandBlock().getData());
|
||||
current.update(true);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isTeamFlagBlock(Block block) {
|
||||
if (this.teamFlag != null) {
|
||||
int flagX = this.teamFlag.getBlockX();
|
||||
int flagY = this.teamFlag.getBlockY() + 1;
|
||||
int flagZ = this.teamFlag.getBlockZ();
|
||||
if (block.getX() == flagX && block.getY() == flagY && block.getZ() == flagZ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Location getTeamFlag() {
|
||||
return this.teamFlag;
|
||||
}
|
||||
|
||||
public void setTeamFlag(Location teamFlag) {
|
||||
this.teamFlag = teamFlag;
|
||||
|
||||
// this resets the block to old state
|
||||
this.setFlagVolume();
|
||||
this.getFlagVolume().saveBlocks();
|
||||
|
||||
this.initializeTeamFlag();
|
||||
}
|
||||
|
||||
public void deleteTeamFlag() {
|
||||
this.getFlagVolume().resetBlocks();
|
||||
this.setFlagVolume(null);
|
||||
this.teamFlag = null;
|
||||
|
||||
// remove volume file
|
||||
String filePath = War.war.getDataFolder().getPath() + "/dat/warzone-" + this.warzone.getName() + "/volume-" + this.getName() + "flag.dat";
|
||||
if (!new File(filePath).delete()) {
|
||||
War.war.log("Failed to delete file " + filePath, Level.WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
public InventoryBag getInventories() {
|
||||
return this.inventories ;
|
||||
}
|
||||
|
||||
public TeamConfigBag getTeamConfig() {
|
||||
return this.teamConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if any team spawns contain a certain location.
|
||||
*
|
||||
* @param loc Location to check if contained by a spawn.
|
||||
* @return true if loc is part of a spawn volume, false otherwise.
|
||||
*/
|
||||
public boolean isSpawnLocation(Location loc) {
|
||||
for (Volume spawnVolume : this.spawnVolumes.values()) {
|
||||
if (spawnVolume.contains(loc)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isFull() {
|
||||
return this.getPlayers().size() == this.getTeamConfig().resolveInt(TeamConfig.TEAMSIZE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of player usernames for players on this team.
|
||||
*
|
||||
* @return array of usernames.
|
||||
*/
|
||||
public List<String> getPlayerNames() {
|
||||
List<String> ret = new ArrayList<String>(this.players.size());
|
||||
for (Player player : this.players) {
|
||||
ret.add(player.getName());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a player on this team can modify a certain type of block defined in the block whitelist.
|
||||
*
|
||||
* @param type Type of block to check.
|
||||
* @return true if this block can be modified, false otherwise.
|
||||
*/
|
||||
public boolean canModify(Material type) {
|
||||
for (String whitelistedBlock : this.getTeamConfig()
|
||||
.resolveString(TeamConfig.BLOCKWHITELIST).split(",")) {
|
||||
if (whitelistedBlock.equalsIgnoreCase("all")) {
|
||||
return true;
|
||||
}
|
||||
if (type.toString().equalsIgnoreCase(whitelistedBlock)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a team chat message with proper formatting.
|
||||
*
|
||||
* @param sender Player sending the message
|
||||
* @param message Message to send
|
||||
*/
|
||||
public void sendTeamChatMessage(OfflinePlayer sender, String message) {
|
||||
String player = this.getKind().getColor() + ChatColor.stripColor(sender.getName()) + ChatColor.WHITE;
|
||||
String output = String.format("%s: %s", player, message);
|
||||
teamcast(output, false);
|
||||
War.war.getLogger().info("[TeamChat] " + output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a player on this team has toggled on team chat. Thread safe.
|
||||
*
|
||||
* @param player Player to check
|
||||
* @return true if the player has toggled on team chat
|
||||
*/
|
||||
public boolean isInTeamChat(Player player) {
|
||||
synchronized (teamChatPlayers) {
|
||||
return this.teamChatPlayers.contains(player);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a player to team chat. Thread safe.
|
||||
* @param player Player to add
|
||||
* @throws IllegalArgumentException Player is already in team chat
|
||||
*/
|
||||
public void addTeamChatPlayer(Player player) {
|
||||
Validate.isTrue(!isInTeamChat(player), "Player is already in team chat");
|
||||
synchronized (teamChatPlayers) {
|
||||
this.teamChatPlayers.add(player);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a player from team chat. Thread safe.
|
||||
*
|
||||
* @param player Player to remove
|
||||
*/
|
||||
public void removeTeamChatPlayer(Player player) {
|
||||
synchronized (teamChatPlayers) {
|
||||
this.teamChatPlayers.remove(player);
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,39 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
|
||||
|
||||
/**
|
||||
* Represents a command that may only be used by War admins
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractOptionalWarAdminCommand extends AbstractWarCommand {
|
||||
|
||||
public AbstractOptionalWarAdminCommand(WarCommandHandler handler, CommandSender sender, String[] args, boolean mustBeWarAdmin) throws NotWarAdminException {
|
||||
super(handler, sender, args);
|
||||
|
||||
if (mustBeWarAdmin && !isSenderWarAdmin()) {
|
||||
throw new NotWarAdminException();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSenderWarAdmin() {
|
||||
if (this.getSender() instanceof Player) {
|
||||
if (!War.war.isWarAdmin((Player) this.getSender())) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} else if (!(this.getSender() instanceof ConsoleCommandSender)) {
|
||||
return false;
|
||||
} else {
|
||||
// ConsoleCommandSender is admin
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
|
||||
|
||||
/**
|
||||
* Represents a command that may only used by zone makers or regular users
|
||||
*
|
||||
* @author tommytony
|
||||
*/
|
||||
public abstract class AbstractOptionalZoneMakerCommand extends AbstractWarCommand {
|
||||
|
||||
public AbstractOptionalZoneMakerCommand(WarCommandHandler handler, CommandSender sender, String[] args, boolean zoneMakersOnly) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
|
||||
if (zoneMakersOnly && !this.isSenderZoneMaker()) {
|
||||
throw new NotZoneMakerException();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSenderZoneMaker() {
|
||||
if (this.getSender() instanceof Player) {
|
||||
// for players check War.isZoneMaker()
|
||||
if (!War.war.isZoneMaker((Player) this.getSender())) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} else if (!(this.getSender() instanceof ConsoleCommandSender)) {
|
||||
return false;
|
||||
} else {
|
||||
// ConsoleCommandSender is admin
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSenderAuthorOfZone(Warzone zone) {
|
||||
if (this.getSender() instanceof Player) {
|
||||
if (War.war.isWarAdmin((Player) this.getSender())) {
|
||||
// War admin has rights over all warzones
|
||||
return true;
|
||||
}
|
||||
|
||||
// Not War admin, is he author?
|
||||
boolean isAuthor = zone.isAuthor((Player) this.getSender());
|
||||
if (!isAuthor) {
|
||||
War.war.badMsg(this.getSender(), "You can't do this because you are not an author of the " + zone.getName() + " warzone." );
|
||||
}
|
||||
return isAuthor;
|
||||
} else {
|
||||
// From console, you can do anything
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
|
||||
/**
|
||||
* Represents a command that may only be used by War admins
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractWarAdminCommand extends AbstractOptionalWarAdminCommand {
|
||||
|
||||
public AbstractWarAdminCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotWarAdminException {
|
||||
super(handler, sender, args, true);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
|
||||
|
||||
/**
|
||||
* Represents a war command
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public abstract class AbstractWarCommand {
|
||||
|
||||
/**
|
||||
* The sender of this command
|
||||
*
|
||||
* @var sender
|
||||
*/
|
||||
private CommandSender sender;
|
||||
|
||||
/**
|
||||
* The arguments of this command
|
||||
*
|
||||
* @var args
|
||||
*/
|
||||
protected String[] args;
|
||||
|
||||
/**
|
||||
* Instance of WarCommandHandler
|
||||
*
|
||||
* @var handler
|
||||
*/
|
||||
protected WarCommandHandler handler;
|
||||
|
||||
public AbstractWarCommand(WarCommandHandler handler, CommandSender sender, String[] args) {
|
||||
this.handler = handler;
|
||||
this.setSender(sender);
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the command
|
||||
*
|
||||
* @return true if command was used the right way
|
||||
*/
|
||||
abstract public boolean handle();
|
||||
|
||||
/**
|
||||
* Sends a success message
|
||||
*
|
||||
* @param message message to send
|
||||
*/
|
||||
public void msg(String message) {
|
||||
War.war.msg(this.getSender(), message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a failure message
|
||||
*
|
||||
* @param message message to send
|
||||
*/
|
||||
public void badMsg(String message) {
|
||||
War.war.badMsg(this.getSender(), message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a success message.
|
||||
* @param message Message or key to translate
|
||||
* @param args Arguments for the formatter
|
||||
*/
|
||||
public void msg(String message, Object... args) {
|
||||
War.war.msg(this.getSender(), message, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a failure message.
|
||||
* @param message Message or key to translate
|
||||
* @param args Arguments for the formatter
|
||||
*/
|
||||
public void badMsg(String message, Object... args) {
|
||||
War.war.badMsg(this.getSender(), message, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the command-sender
|
||||
*
|
||||
* @param sender new sender
|
||||
*/
|
||||
public void setSender(CommandSender sender) {
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the command-sender
|
||||
*
|
||||
* @return Command-Sender
|
||||
*/
|
||||
public CommandSender getSender() {
|
||||
return this.sender;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
|
||||
/**
|
||||
* Represents a command that may only be used by zone makers
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public abstract class AbstractZoneMakerCommand extends AbstractOptionalZoneMakerCommand {
|
||||
|
||||
public AbstractZoneMakerCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args, true);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
import com.tommytony.war.structure.Bomb;
|
||||
import com.tommytony.war.structure.ZoneLobby;
|
||||
|
||||
/**
|
||||
* Deletes a bomb.
|
||||
*
|
||||
* @author tommytony
|
||||
*/
|
||||
public class DeleteBombCommand extends AbstractZoneMakerCommand {
|
||||
public DeleteBombCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
Warzone zone;
|
||||
|
||||
if (this.args.length == 0) {
|
||||
return false;
|
||||
} else if (this.args.length == 2) {
|
||||
zone = Warzone.getZoneByName(this.args[0]);
|
||||
this.args[0] = this.args[1];
|
||||
} else if (this.args.length == 1) {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
zone = Warzone.getZoneByLocation((Player) this.getSender());
|
||||
if (zone == null) {
|
||||
ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender());
|
||||
if (lobby == null) {
|
||||
return false;
|
||||
}
|
||||
zone = lobby.getZone();
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Bomb bomb = zone.getBomb(this.args[0]);
|
||||
if (bomb != null) {
|
||||
bomb.getVolume().resetBlocks();
|
||||
zone.getBombs().remove(bomb);
|
||||
WarzoneYmlMapper.save(zone);
|
||||
this.msg("Bomb " + bomb.getName() + " removed.");
|
||||
War.war.log(this.getSender().getName() + " deleted bomb " + bomb.getName() + " in warzone " + zone.getName(), Level.INFO);
|
||||
} else {
|
||||
this.badMsg("No such bomb.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
import com.tommytony.war.structure.Cake;
|
||||
import com.tommytony.war.structure.ZoneLobby;
|
||||
|
||||
/**
|
||||
* Deletes a cake.
|
||||
*
|
||||
* @author tommytony
|
||||
*/
|
||||
public class DeleteCakeCommand extends AbstractZoneMakerCommand {
|
||||
public DeleteCakeCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
Warzone zone;
|
||||
|
||||
if (this.args.length == 0) {
|
||||
return false;
|
||||
} else if (this.args.length == 2) {
|
||||
zone = Warzone.getZoneByName(this.args[0]);
|
||||
this.args[0] = this.args[1];
|
||||
} else if (this.args.length == 1) {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
zone = Warzone.getZoneByLocation((Player) this.getSender());
|
||||
if (zone == null) {
|
||||
ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender());
|
||||
if (lobby == null) {
|
||||
return false;
|
||||
}
|
||||
zone = lobby.getZone();
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Cake cake = zone.getCake(this.args[0]);
|
||||
if (cake != null) {
|
||||
cake.getVolume().resetBlocks();
|
||||
zone.getCakes().remove(cake);
|
||||
WarzoneYmlMapper.save(zone);
|
||||
this.msg("Cake " + cake.getName() + " removed.");
|
||||
War.war.log(this.getSender().getName() + " deleted cake " + cake.getName() + " in warzone " + zone.getName(), Level.INFO);
|
||||
} else {
|
||||
this.badMsg("No such cake.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
import com.tommytony.war.structure.CapturePoint;
|
||||
import com.tommytony.war.structure.Monument;
|
||||
import com.tommytony.war.structure.ZoneLobby;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Deletes a capture point.
|
||||
*
|
||||
* @author Connor Monahan
|
||||
*/
|
||||
public class DeleteCapturePointCommand extends AbstractZoneMakerCommand {
|
||||
public DeleteCapturePointCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
Warzone zone;
|
||||
|
||||
if (this.args.length == 0) {
|
||||
return false;
|
||||
} else if (this.args.length == 2) {
|
||||
zone = Warzone.getZoneByName(this.args[0]);
|
||||
this.args[0] = this.args[1];
|
||||
} else if (this.args.length == 1) {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
zone = Warzone.getZoneByLocation((Player) this.getSender());
|
||||
if (zone == null) {
|
||||
ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender());
|
||||
if (lobby == null) {
|
||||
return false;
|
||||
}
|
||||
zone = lobby.getZone();
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
CapturePoint cp = zone.getCapturePoint(this.args[0]);
|
||||
if (cp != null) {
|
||||
cp.getVolume().resetBlocks();
|
||||
zone.getCapturePoints().remove(cp);
|
||||
WarzoneYmlMapper.save(zone);
|
||||
this.msg("Capture point " + cp.getName() + " removed.");
|
||||
War.war.log(this.getSender().getName() + " deleted capture point " + cp.getName() + " in warzone " + zone.getName(), Level.INFO);
|
||||
} else {
|
||||
this.badMsg("No such capture point.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
import com.tommytony.war.structure.Monument;
|
||||
import com.tommytony.war.structure.ZoneLobby;
|
||||
|
||||
/**
|
||||
* Deletes a monument.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class DeleteMonumentCommand extends AbstractZoneMakerCommand {
|
||||
public DeleteMonumentCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
Warzone zone;
|
||||
|
||||
if (this.args.length == 0) {
|
||||
return false;
|
||||
} else if (this.args.length == 2) {
|
||||
zone = Warzone.getZoneByName(this.args[0]);
|
||||
this.args[0] = this.args[1];
|
||||
} else if (this.args.length == 1) {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
zone = Warzone.getZoneByLocation((Player) this.getSender());
|
||||
if (zone == null) {
|
||||
ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender());
|
||||
if (lobby == null) {
|
||||
return false;
|
||||
}
|
||||
zone = lobby.getZone();
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Monument monument = zone.getMonument(this.args[0]);
|
||||
if (monument != null) {
|
||||
monument.getVolume().resetBlocks();
|
||||
zone.getMonuments().remove(monument);
|
||||
WarzoneYmlMapper.save(zone);
|
||||
this.msg("Monument " + monument.getName() + " removed.");
|
||||
War.war.log(this.getSender().getName() + " deleted monument " + monument.getName() + " in warzone " + zone.getName(), Level.INFO);
|
||||
} else {
|
||||
this.badMsg("No such monument.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.config.TeamKind;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
import com.tommytony.war.structure.ZoneLobby;
|
||||
import com.tommytony.war.volume.Volume;
|
||||
|
||||
/**
|
||||
* Deletes a team.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class DeleteTeamCommand extends AbstractZoneMakerCommand {
|
||||
public DeleteTeamCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
Warzone zone;
|
||||
|
||||
if (this.args.length == 0) {
|
||||
return false;
|
||||
} else if (this.args.length == 2) {
|
||||
zone = Warzone.getZoneByName(this.args[0]);
|
||||
this.args[0] = this.args[1];
|
||||
} else if (this.args.length == 1) {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
zone = Warzone.getZoneByLocation((Player) this.getSender());
|
||||
if (zone == null) {
|
||||
ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender());
|
||||
if (lobby == null) {
|
||||
return false;
|
||||
}
|
||||
zone = lobby.getZone();
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Team team = zone.getTeamByKind(TeamKind.teamKindFromString(this.args[0]));
|
||||
if (team != null) {
|
||||
if (team.getFlagVolume() != null) {
|
||||
team.getFlagVolume().resetBlocks();
|
||||
}
|
||||
for (Volume spawnVolume : team.getSpawnVolumes().values()) {
|
||||
spawnVolume.resetBlocks();
|
||||
}
|
||||
zone.getTeams().remove(team);
|
||||
if (zone.getLobby() != null) {
|
||||
zone.getLobby().setLocation(zone.getTeleport());
|
||||
zone.getLobby().initialize();
|
||||
}
|
||||
WarzoneYmlMapper.save(zone);
|
||||
this.msg("Team " + team.getName() + " removed.");
|
||||
War.war.log(this.getSender().getName() + " deleted team " + team.getName() + " in warzone " + zone.getName(), Level.INFO);
|
||||
} else {
|
||||
this.badMsg("No such team.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
import com.tommytony.war.structure.ZoneLobby;
|
||||
|
||||
/**
|
||||
* Deletes a monument.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class DeleteTeamFlagCommand extends AbstractZoneMakerCommand {
|
||||
public DeleteTeamFlagCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
Warzone zone;
|
||||
|
||||
if (this.args.length == 0) {
|
||||
return false;
|
||||
} else if (this.args.length == 2) {
|
||||
zone = Warzone.getZoneByName(this.args[0]);
|
||||
this.args[0] = this.args[1];
|
||||
} else if (this.args.length == 1) {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
zone = Warzone.getZoneByLocation((Player) this.getSender());
|
||||
if (zone == null) {
|
||||
ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender());
|
||||
if (lobby == null) {
|
||||
return false;
|
||||
}
|
||||
zone = lobby.getZone();
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Team teamFlagTeam = null;
|
||||
for (Team team : zone.getTeams()) {
|
||||
if (team.getName().startsWith(this.args[0].toLowerCase())) {
|
||||
teamFlagTeam = team;
|
||||
}
|
||||
}
|
||||
if (teamFlagTeam != null) {
|
||||
teamFlagTeam.deleteTeamFlag();
|
||||
|
||||
WarzoneYmlMapper.save(zone);
|
||||
this.msg(teamFlagTeam.getName() + " flag removed.");
|
||||
War.war.log(this.getSender().getName() + " deleted team " + teamFlagTeam.getName() + " flag in warzone " + zone.getName(), Level.INFO);
|
||||
} else {
|
||||
this.badMsg("No such team flag.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mapper.VolumeMapper;
|
||||
import com.tommytony.war.mapper.WarYmlMapper;
|
||||
import com.tommytony.war.structure.WarHub;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Deletes the warhub.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class DeleteWarhubCommand extends AbstractWarAdminCommand {
|
||||
public DeleteWarhubCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotWarAdminException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (this.args.length != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (War.war.getWarHub() != null) {
|
||||
// reset existing hub
|
||||
War.war.getWarHub().getVolume().resetBlocks();
|
||||
VolumeMapper.deleteSimpleVolume(War.war.getWarHub().getVolume());
|
||||
War.war.setWarHub((WarHub) null);
|
||||
for (Warzone zone : War.war.getWarzones()) {
|
||||
if (zone.getLobby() != null) {
|
||||
zone.getLobby().getVolume().resetBlocks();
|
||||
zone.getLobby().initialize();
|
||||
}
|
||||
}
|
||||
|
||||
this.msg("War hub removed.");
|
||||
War.war.log(this.getSender().getName() + " deleted warhub", Level.INFO);
|
||||
} else {
|
||||
this.badMsg("No War hub to delete.");
|
||||
}
|
||||
WarYmlMapper.save();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mapper.WarYmlMapper;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
import com.tommytony.war.structure.ZoneLobby;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Deletes a warzone.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class DeleteZoneCommand extends AbstractZoneMakerCommand {
|
||||
public DeleteZoneCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
public static void forceDeleteZone(Warzone zone, CommandSender sender) {
|
||||
War.war.getWarzones().remove(zone);
|
||||
WarYmlMapper.save();
|
||||
|
||||
WarzoneYmlMapper.delete(zone);
|
||||
|
||||
if (War.war.getWarHub() != null) { // warhub has to change
|
||||
War.war.getWarHub().getVolume().resetBlocks();
|
||||
War.war.getWarHub().initialize();
|
||||
}
|
||||
|
||||
String msg = "Warzone " + zone.getName() + " removed by " + sender.getName() + ".";
|
||||
War.war.log(msg, Level.INFO);
|
||||
War.war.msg(sender, msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
Warzone zone;
|
||||
|
||||
if (this.args.length == 1) {
|
||||
zone = Warzone.getZoneByName(this.args[0]);
|
||||
} else if (this.args.length == 0) {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
zone = Warzone.getZoneByLocation((Player) this.getSender());
|
||||
if (zone == null) {
|
||||
ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender());
|
||||
if (lobby == null) {
|
||||
return false;
|
||||
}
|
||||
zone = lobby.getZone();
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
forceDeleteZone(zone, getSender());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.config.TeamKind;
|
||||
import com.tommytony.war.config.WarzoneConfig;
|
||||
import com.tommytony.war.structure.ZoneLobby;
|
||||
|
||||
/**
|
||||
* Joins a team.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class JoinCommand extends AbstractWarCommand {
|
||||
public JoinCommand(WarCommandHandler handler, CommandSender sender, String[] args) {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("command.console");
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) this.getSender();
|
||||
|
||||
Warzone zone;
|
||||
TeamKind kind;
|
||||
boolean signup = false;
|
||||
if (this.args.length == 2) {
|
||||
// zone by name
|
||||
zone = Warzone.getZoneByName(this.args[0]);
|
||||
kind = TeamKind.teamKindFromString(this.args[1]);
|
||||
} else if (this.args.length == 3 && args[0].equals("delayed")) {
|
||||
signup = true;
|
||||
zone = Warzone.getZoneByName(this.args[1]);
|
||||
kind = TeamKind.teamKindFromString(this.args[2]);
|
||||
} else if (this.args.length == 1) {
|
||||
zone = Warzone.getZoneByLocation((Player) this.getSender());
|
||||
if (zone == null) {
|
||||
ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender());
|
||||
if (lobby == null) {
|
||||
return false;
|
||||
}
|
||||
zone = lobby.getZone();
|
||||
}
|
||||
kind = TeamKind.teamKindFromString(this.args[0]);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (zone == null) {
|
||||
return false;
|
||||
}
|
||||
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.DISABLED)) {
|
||||
this.badMsg("join.disabled");
|
||||
} else if (zone.isReinitializing()) {
|
||||
this.badMsg("join.disabled");
|
||||
} else if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.AUTOASSIGN)) {
|
||||
this.badMsg("join.aarequired");
|
||||
} else if (!zone.getWarzoneConfig().getBoolean(WarzoneConfig.JOINMIDBATTLE) && zone.isEnoughPlayers()) {
|
||||
this.badMsg("join.progress");
|
||||
} else {
|
||||
Team team = zone.getTeamByKind(kind);
|
||||
if (kind == null || team == null) {
|
||||
this.badMsg("join.team404");
|
||||
} else if (!War.war.canPlayWar(player, team)) {
|
||||
this.badMsg("join.permission.single");
|
||||
} else if (team.isFull()) {
|
||||
this.badMsg("join.full.single", team.getName());
|
||||
} else {
|
||||
Team previousTeam = Team.getTeamByPlayerName(player.getName());
|
||||
if (previousTeam != null) {
|
||||
if (previousTeam == team) {
|
||||
this.badMsg("join.selfteam");
|
||||
return true;
|
||||
}
|
||||
previousTeam.removePlayer(player);
|
||||
previousTeam.resetSign();
|
||||
}
|
||||
if (signup && !zone.testEnoughPlayers(kind, false)) {
|
||||
// player wants to automatically join the zone when everyone else is ready
|
||||
zone.signup(player, team);
|
||||
return true;
|
||||
}
|
||||
zone.assign(player, team);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.Warzone.LeaveCause;
|
||||
|
||||
/**
|
||||
* Leaves a game.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class LeaveCommand extends AbstractWarCommand {
|
||||
public LeaveCommand(WarCommandHandler handler, CommandSender sender, String[] args) {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("command.console");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.args.length != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Player player = (Player) this.getSender();
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
if (zone == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
zone.handlePlayerLeave(player, zone.getEndTeleport(LeaveCause.COMMAND), true);
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
|
||||
|
||||
/**
|
||||
* Loads war.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class LoadWarCommand extends AbstractWarAdminCommand {
|
||||
public LoadWarCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotWarAdminException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (this.args.length != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
War.war.loadWar();
|
||||
this.msg("War loaded.");
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.job.PartialZoneResetJob;
|
||||
import com.tommytony.war.structure.ZoneLobby;
|
||||
|
||||
|
||||
public class NextBattleCommand extends AbstractZoneMakerCommand {
|
||||
public NextBattleCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
Warzone zone;
|
||||
if (this.args.length == 1) {
|
||||
zone = Warzone.getZoneByName(this.args[0]);
|
||||
} else if (this.args.length == 0) {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
zone = Warzone.getZoneByLocation((Player) this.getSender());
|
||||
if (zone == null) {
|
||||
ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender());
|
||||
if (lobby == null) {
|
||||
return false;
|
||||
}
|
||||
zone = lobby.getZone();
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
zone.clearThieves();
|
||||
zone.broadcast("zone.battle.next", zone.getName());
|
||||
|
||||
PartialZoneResetJob.setSenderToNotify(zone, this.getSender());
|
||||
|
||||
zone.reinitialize();
|
||||
|
||||
War.war.log(this.getSender().getName() + " used nextbattle in warzone " + zone.getName(), Level.INFO);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
/**
|
||||
* NotZoneMakerException is thrown when a player is no zonemaker.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class NotWarAdminException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -5412011034665080340L;
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
/**
|
||||
* NotZoneMakerException is thrown when a player is no zonemaker.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class NotZoneMakerException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -5412011034665080340L;
|
||||
}
|
|
@ -0,0 +1,117 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.config.WarzoneConfig;
|
||||
import com.tommytony.war.mapper.WarYmlMapper;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
import com.tommytony.war.structure.ZoneLobby;
|
||||
|
||||
public class RenameZoneCommand extends AbstractZoneMakerCommand {
|
||||
public RenameZoneCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
Warzone zone;
|
||||
|
||||
if (this.args.length == 2) {
|
||||
zone = Warzone.getZoneByName(this.args[0]);
|
||||
this.args[0] = this.args[1];
|
||||
} else if (this.args.length == 1) {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
zone = Warzone.getZoneByLocation((Player) this.getSender());
|
||||
if (zone == null) {
|
||||
ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender());
|
||||
if (lobby == null) {
|
||||
return false;
|
||||
}
|
||||
zone = lobby.getZone();
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Kill old warzone, but use it to create the renamed copy
|
||||
zone.unload();
|
||||
zone.getVolume().resetBlocks(); // We're going to use the blocks to save the new copy, reset to base state.
|
||||
|
||||
String newName = this.args[0];
|
||||
String oldName = zone.getName();
|
||||
|
||||
// Update the name
|
||||
zone.setName(newName);
|
||||
zone.saveState(false); // Save new volume files. Don't clear anything, we already unloaded.
|
||||
WarzoneYmlMapper.save(zone); // Save new config files for warzone.
|
||||
|
||||
// Get rid of old unloaded zone instance
|
||||
War.war.getWarzones().remove(zone);
|
||||
|
||||
// Move old files
|
||||
(new File(War.war.getDataFolder().getPath() + "/temp/renamed/")).mkdir();
|
||||
(new File(War.war.getDataFolder().getPath() + "/warzone-" + oldName + ".yml")).renameTo(new File(War.war.getDataFolder().getPath() + "/temp/renamed/warzone-" + oldName + ".yml"));
|
||||
(new File(War.war.getDataFolder().getPath() + "/temp/renamed/dat/warzone-" + oldName)).mkdirs();
|
||||
|
||||
String oldPath = War.war.getDataFolder().getPath() + "/dat/warzone-" + oldName + "/";
|
||||
File oldZoneFolder = new File(oldPath);
|
||||
File[] oldZoneFiles = oldZoneFolder.listFiles();
|
||||
for (File file : oldZoneFiles) {
|
||||
file.renameTo(new File(War.war.getDataFolder().getPath() + "/temp/renamed/dat/warzone-" + oldName + "/" + file.getName()));
|
||||
}
|
||||
oldZoneFolder.delete();
|
||||
|
||||
// Load new warzone
|
||||
War.war.log("Loading zone " + newName + "...", Level.INFO);
|
||||
Warzone newZone = WarzoneYmlMapper.load(newName);
|
||||
War.war.getWarzones().add(newZone);
|
||||
try {
|
||||
newZone.getVolume().loadCorners();
|
||||
} catch (SQLException ex) {
|
||||
War.war.log("Failed to load warzone " + newZone.getName() + ": " + ex.getMessage(), Level.WARNING);
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
try {
|
||||
zone.getVolume().loadCorners();
|
||||
} catch (SQLException ex) {
|
||||
War.war.log("Failed to load warzone " + zone.getName() + ": " + ex.getMessage(), Level.WARNING);
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
if (zone.getLobby() != null) {
|
||||
zone.getLobby().getVolume().resetBlocks();
|
||||
}
|
||||
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.RESETONLOAD)) {
|
||||
zone.getVolume().resetBlocks();
|
||||
}
|
||||
|
||||
newZone.initializeZone();
|
||||
|
||||
// Update war config
|
||||
WarYmlMapper.save();
|
||||
|
||||
if (War.war.getWarHub() != null) { // warhub has to change
|
||||
War.war.getWarHub().getVolume().resetBlocks();
|
||||
War.war.getWarHub().initialize();
|
||||
}
|
||||
|
||||
War.war.log(this.getSender().getName() + " renamed warzone " + oldName + " to " + newName, Level.INFO);
|
||||
this.msg("Warzone " + oldName + " renamed to " + newName + ".");
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.Warzone.LeaveCause;
|
||||
import com.tommytony.war.job.PartialZoneResetJob;
|
||||
import com.tommytony.war.structure.ZoneLobby;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.logging.Level;
|
||||
|
||||
|
||||
public class ResetZoneCommand extends AbstractZoneMakerCommand {
|
||||
public ResetZoneCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
public static void forceResetZone(Warzone zone, CommandSender sender) {
|
||||
zone.clearThieves();
|
||||
for (Team team : zone.getTeams()) {
|
||||
team.teamcast("The war has ended. " + zone.getTeamInformation() + " Resetting warzone " + zone.getName() + " and teams...");
|
||||
for (Iterator<Player> it = team.getPlayers().iterator(); it.hasNext(); ) {
|
||||
Player p = it.next();
|
||||
it.remove();
|
||||
team.removePlayer(p);
|
||||
if (!zone.getReallyDeadFighters().contains(p.getName())) {
|
||||
p.teleport(zone.getEndTeleport(LeaveCause.RESET));
|
||||
}
|
||||
}
|
||||
team.resetPoints();
|
||||
team.getPlayers().clear();
|
||||
}
|
||||
|
||||
War.war.msg(sender, "Reloading warzone " + zone.getName() + ".");
|
||||
|
||||
PartialZoneResetJob.setSenderToNotify(zone, sender);
|
||||
|
||||
zone.reinitialize();
|
||||
|
||||
War.war.log(sender.getName() + " reset warzone " + zone.getName(), Level.INFO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
Warzone zone;
|
||||
if (this.args.length == 1) {
|
||||
zone = Warzone.getZoneByName(this.args[0]);
|
||||
} else if (this.args.length == 0) {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
zone = Warzone.getZoneByLocation((Player) this.getSender());
|
||||
if (zone == null) {
|
||||
ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender());
|
||||
if (lobby == null) {
|
||||
return false;
|
||||
}
|
||||
zone = lobby.getZone();
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
forceResetZone(zone, this.getSender());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,161 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.config.WarConfig;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
import com.tommytony.war.structure.ZoneLobby;
|
||||
|
||||
public class SaveZoneCommand extends AbstractZoneMakerCommand {
|
||||
|
||||
public SaveZoneCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
Warzone zone = null;
|
||||
CommandSender commandSender = this.getSender();
|
||||
boolean isFirstParamWarzone = false;
|
||||
|
||||
if (this.args.length > 0 && !this.args[0].contains(":")) {
|
||||
// warzone name maybe in first place
|
||||
Warzone zoneByName = Warzone.getZoneByName(this.args[0]);
|
||||
if (zoneByName != null) {
|
||||
zone = zoneByName;
|
||||
isFirstParamWarzone = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.getSender() instanceof Player) {
|
||||
Player player = (Player) commandSender;
|
||||
|
||||
Warzone zoneByLoc = Warzone.getZoneByLocation(player);
|
||||
ZoneLobby lobbyByLoc = ZoneLobby.getLobbyByLocation(player);
|
||||
if (zoneByLoc == null && lobbyByLoc != null) {
|
||||
zoneByLoc = lobbyByLoc.getZone();
|
||||
}
|
||||
if (zoneByLoc != null) {
|
||||
zone = zoneByLoc;
|
||||
}
|
||||
}
|
||||
|
||||
if (zone == null) {
|
||||
// No warzone found, whatever the mean, escape
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isFirstParamWarzone) {
|
||||
if (this.args.length > 1) {
|
||||
// More than one param: the arguments need to be shifted
|
||||
String[] newargs = new String[this.args.length - 1];
|
||||
for (int i = 1; i < this.args.length; i++) {
|
||||
newargs[i - 1] = this.args[i];
|
||||
}
|
||||
this.args = newargs;
|
||||
}
|
||||
}
|
||||
|
||||
// We have a warzone and indexed-from-0 arguments
|
||||
if (War.war.getWarConfig().getBoolean(WarConfig.KEEPOLDZONEVERSIONS)) {
|
||||
// Keep a copy of the old version, just in case. First, find the version number
|
||||
File oldVersionsFolder = new File(War.war.getDataFolder().getPath() + "/temp/oldversions/warzone-" + zone.getName());
|
||||
oldVersionsFolder.mkdirs();
|
||||
|
||||
File[] versionFolders = oldVersionsFolder.listFiles();
|
||||
int newVersion = versionFolders.length + 1;
|
||||
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
String newVersionString = format.format(new Date()) + "-" + newVersion;
|
||||
String newVersionPath = War.war.getDataFolder().getPath() + "/temp/oldversions/warzone-" + zone.getName() + "/" + newVersionString;
|
||||
File newVersionFolder = new File(newVersionPath);
|
||||
newVersionFolder.mkdir();
|
||||
|
||||
// Copy all warzone files to new version folder before they get overwritten
|
||||
try {
|
||||
copyFile(new File(War.war.getDataFolder().getPath() + "/warzone-" + zone.getName() + ".yml"), new File(newVersionPath + "/warzone-" + zone.getName() + ".yml"));
|
||||
(new File(newVersionPath + "/dat/warzone-" + zone.getName())).mkdirs();
|
||||
String oldPath = War.war.getDataFolder().getPath() + "/dat/warzone-" + zone.getName() + "/";
|
||||
File currentZoneFolder = new File(oldPath);
|
||||
|
||||
File[] currentZoneFiles = currentZoneFolder.listFiles();
|
||||
for (File file : currentZoneFiles) {
|
||||
copyFile(file, new File(newVersionPath + "/dat/warzone-" + zone.getName() + "/" + file.getName()));
|
||||
}
|
||||
} catch (IOException badCopy) {
|
||||
War.war.log("Failed to make backup copy version " + newVersion + " of warzone " + zone.getName(), Level.WARNING);
|
||||
}
|
||||
|
||||
int currentVersion = newVersion + 1;
|
||||
this.msg("Saving version " + currentVersion + " of warzone " + zone.getName());
|
||||
War.war.log(this.getSender().getName() + " is saving version " + currentVersion + " of warzone " + zone.getName(), Level.INFO);
|
||||
} else {
|
||||
this.msg("Saving new permanent version of warzone " + zone.getName());
|
||||
War.war.log(this.getSender().getName() + " is saving new permanent version of warzone " + zone.getName(), Level.INFO);
|
||||
}
|
||||
|
||||
// Let's save the new version update
|
||||
int savedBlocks = zone.saveState(true);
|
||||
|
||||
// changed settings: must reinitialize with new settings
|
||||
String namedParamResult = War.war.updateZoneFromNamedParams(zone, commandSender, this.args);
|
||||
WarzoneYmlMapper.save(zone);
|
||||
if (this.args.length > 0) {
|
||||
// the config may have changed, requiring a reset for spawn styles etc.
|
||||
zone.getVolume().resetBlocks();
|
||||
}
|
||||
if (zone.getLobby() != null) {
|
||||
zone.getLobby().getVolume().resetBlocks();
|
||||
}
|
||||
zone.initializeZone(); // bring back team spawns etc
|
||||
|
||||
if (War.war.getWarHub() != null) { // maybe the zone was disabled/enabled
|
||||
War.war.getWarHub().getVolume().resetBlocks();
|
||||
War.war.getWarHub().initialize();
|
||||
}
|
||||
|
||||
this.msg("Saved " + savedBlocks + " blocks in warzone " + zone.getName() + "." + namedParamResult);
|
||||
if (namedParamResult != null && namedParamResult.length() > 0) {
|
||||
War.war.log(this.getSender().getName() + " also updated warzone " + zone.getName() + " configuration." + namedParamResult, Level.INFO);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void copyFile(File sourceFile, File destFile) throws IOException {
|
||||
if(!destFile.exists()) {
|
||||
destFile.createNewFile();
|
||||
}
|
||||
|
||||
FileChannel source = null;
|
||||
FileChannel destination = null;
|
||||
|
||||
try {
|
||||
source = new FileInputStream(sourceFile).getChannel();
|
||||
destination = new FileOutputStream(destFile).getChannel();
|
||||
destination.transferFrom(source, 0, source.size());
|
||||
}
|
||||
finally {
|
||||
if(source != null) {
|
||||
source.close();
|
||||
}
|
||||
if(destination != null) {
|
||||
destination.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
import com.tommytony.war.structure.Bomb;
|
||||
|
||||
/**
|
||||
* Places a bomb
|
||||
*
|
||||
* @author tommytony
|
||||
*/
|
||||
public class SetBombCommand extends AbstractZoneMakerCommand {
|
||||
public SetBombCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("You can't do this if you are not in-game.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) this.getSender();
|
||||
|
||||
if (this.args.length != 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Warzone zone = Warzone.getZoneByLocation(player);
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.args[0].equals(zone.getName())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zone.hasBomb(this.args[0])) {
|
||||
// move the existing bomb
|
||||
Bomb bomb = zone.getBomb(this.args[0]);
|
||||
bomb.getVolume().resetBlocks();
|
||||
bomb.setLocation(player.getLocation());
|
||||
this.msg("Bomb " + bomb.getName() + " was moved.");
|
||||
War.war.log(this.getSender().getName() + " moved bomb " + bomb.getName() + " in warzone " + zone.getName(), Level.INFO);
|
||||
} else {
|
||||
// create a new bomb
|
||||
Bomb bomb = new Bomb(this.args[0], zone, player.getLocation());
|
||||
zone.getBombs().add(bomb);
|
||||
this.msg("Bomb " + bomb.getName() + " created.");
|
||||
War.war.log(this.getSender().getName() + " created bomb " + bomb.getName() + " in warzone " + zone.getName(), Level.INFO);
|
||||
}
|
||||
|
||||
WarzoneYmlMapper.save(zone);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
import com.tommytony.war.structure.Cake;
|
||||
|
||||
/**
|
||||
* Places a cake
|
||||
*
|
||||
* @author tommytony
|
||||
*/
|
||||
public class SetCakeCommand extends AbstractZoneMakerCommand {
|
||||
public SetCakeCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("You can't do this if you are not in-game.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) this.getSender();
|
||||
|
||||
if (this.args.length != 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Warzone zone = Warzone.getZoneByLocation(player);
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.args[0].equals(zone.getName())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zone.hasCake(this.args[0])) {
|
||||
// move the existing cake
|
||||
Cake cake = zone.getCake(this.args[0]);
|
||||
cake.getVolume().resetBlocks();
|
||||
cake.setLocation(player.getLocation());
|
||||
this.msg("Cake " + cake.getName() + " was moved.");
|
||||
War.war.log(this.getSender().getName() + " moved cake " + cake.getName() + " in warzone " + zone.getName(), Level.INFO);
|
||||
} else {
|
||||
// create a new cake
|
||||
Cake cake = new Cake(this.args[0], zone, player.getLocation());
|
||||
zone.getCakes().add(cake);
|
||||
this.msg("Cake " + cake.getName() + " created.");
|
||||
War.war.log(this.getSender().getName() + " created cake " + cake.getName() + " in warzone " + zone.getName(), Level.INFO);
|
||||
}
|
||||
|
||||
WarzoneYmlMapper.save(zone);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.config.TeamKind;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
import com.tommytony.war.structure.CapturePoint;
|
||||
import com.tommytony.war.structure.Monument;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Sets a capture point
|
||||
*
|
||||
* @author Connor Monahan
|
||||
*/
|
||||
public class SetCapturePointCommand extends AbstractZoneMakerCommand {
|
||||
public SetCapturePointCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("You can't do this if you are not in-game.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) this.getSender();
|
||||
|
||||
if (this.args.length < 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Warzone zone = Warzone.getZoneByLocation(player);
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.args[0].equals(zone.getName())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zone.hasCapturePoint(this.args[0])) {
|
||||
// move the existing capture point
|
||||
CapturePoint cp = zone.getCapturePoint(this.args[0]);
|
||||
cp.getVolume().resetBlocks();
|
||||
cp.setLocation(player.getLocation());
|
||||
this.msg("Capture point " + cp.getName() + " was moved.");
|
||||
War.war.log(this.getSender().getName() + " moved capture point " + cp.getName() + " in warzone " + zone.getName(), Level.INFO);
|
||||
} else {
|
||||
// create a new capture point
|
||||
TeamKind controller = null;
|
||||
int strength = 0;
|
||||
if (args.length > 1) {
|
||||
controller = TeamKind.teamKindFromString(args[1]);
|
||||
strength = 4;
|
||||
if (controller == null || zone.getTeamByKind(controller) == null) {
|
||||
this.badMsg("Failed to create capture point: team {0} does not exist", args[1]);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
CapturePoint cp = new CapturePoint(this.args[0], player.getLocation(), controller, strength, zone);
|
||||
zone.getCapturePoints().add(cp);
|
||||
War.war.log(this.getSender().getName() + " created capture point " + cp.getName() + " in warzone " + zone.getName(), Level.INFO);
|
||||
}
|
||||
|
||||
WarzoneYmlMapper.save(zone);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
import com.tommytony.war.structure.Monument;
|
||||
|
||||
/**
|
||||
* Places a monument
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class SetMonumentCommand extends AbstractZoneMakerCommand {
|
||||
public SetMonumentCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("You can't do this if you are not in-game.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) this.getSender();
|
||||
|
||||
if (this.args.length != 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Warzone zone = Warzone.getZoneByLocation(player);
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.args[0].equals(zone.getName())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zone.hasMonument(this.args[0])) {
|
||||
// move the existing monument
|
||||
Monument monument = zone.getMonument(this.args[0]);
|
||||
monument.getVolume().resetBlocks();
|
||||
monument.setLocation(player.getLocation());
|
||||
this.msg("Monument " + monument.getName() + " was moved.");
|
||||
War.war.log(this.getSender().getName() + " moved monument " + monument.getName() + " in warzone " + zone.getName(), Level.INFO);
|
||||
} else {
|
||||
// create a new monument
|
||||
Monument monument = new Monument(this.args[0], zone, player.getLocation());
|
||||
zone.getMonuments().add(monument);
|
||||
War.war.log(this.getSender().getName() + " created monument " + monument.getName() + " in warzone " + zone.getName(), Level.INFO);
|
||||
}
|
||||
|
||||
WarzoneYmlMapper.save(zone);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.config.TeamConfig;
|
||||
import com.tommytony.war.config.TeamKind;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
import java.util.Collections;
|
||||
import org.bukkit.Location;
|
||||
|
||||
/**
|
||||
* Places a soawn
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class SetTeamCommand extends AbstractZoneMakerCommand {
|
||||
public SetTeamCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("You can't do this if you are not in-game.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) this.getSender();
|
||||
|
||||
if (this.args.length != 1) {
|
||||
return false;
|
||||
}
|
||||
Warzone zone = Warzone.getZoneByLocation(player);
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
TeamKind teamKind = TeamKind.teamKindFromString(this.args[0]);
|
||||
|
||||
if (teamKind == null) {
|
||||
return false;
|
||||
} else {
|
||||
Team existingTeam = zone.getTeamByKind(teamKind);
|
||||
if (existingTeam != null) {
|
||||
// add additional spawn
|
||||
existingTeam.addTeamSpawn(player.getLocation());
|
||||
this.msg("Additional spawn added for team " + existingTeam.getName() + ". Use /deleteteam " + existingTeam.getName() + " to remove all spawns.");
|
||||
War.war.log(this.getSender().getName() + " moved team " + existingTeam.getName() + " in warzone " + zone.getName(), Level.INFO);
|
||||
} else {
|
||||
// new team (use default TeamKind name for now)
|
||||
Team newTeam = new Team(teamKind.toString(), teamKind, Collections.<Location>emptyList(), zone);
|
||||
newTeam.setRemainingLives(newTeam.getTeamConfig().resolveInt(TeamConfig.LIFEPOOL));
|
||||
zone.getTeams().add(newTeam);
|
||||
if (zone.getLobby() != null) {
|
||||
zone.getLobby().setLocation(zone.getTeleport());
|
||||
zone.getLobby().initialize();
|
||||
}
|
||||
newTeam.addTeamSpawn(player.getLocation());
|
||||
this.msg("Team " + newTeam.getName() + " created with spawn here.");
|
||||
War.war.log(this.getSender().getName() + " created team " + newTeam.getName() + " in warzone " + zone.getName(), Level.INFO);
|
||||
}
|
||||
}
|
||||
|
||||
WarzoneYmlMapper.save(zone);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,154 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.tommytony.war.config.TeamConfigBag;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.config.TeamKind;
|
||||
import com.tommytony.war.config.WarzoneConfig;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
import com.tommytony.war.structure.ZoneLobby;
|
||||
|
||||
public class SetTeamConfigCommand extends AbstractOptionalZoneMakerCommand {
|
||||
|
||||
public SetTeamConfigCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
Warzone zone = null;
|
||||
Player player = null;
|
||||
CommandSender commandSender = this.getSender();
|
||||
boolean isFirstParamWarzone = false;
|
||||
boolean wantsToPrint = false;
|
||||
|
||||
Team team = null;
|
||||
|
||||
if (this.args.length == 0) {
|
||||
return false;
|
||||
} else {
|
||||
if (!this.args[0].contains(":")) {
|
||||
// warzone name maybe in first place
|
||||
Warzone zoneByName = Warzone.getZoneByName(this.args[0]);
|
||||
if (zoneByName != null) {
|
||||
zone = zoneByName;
|
||||
isFirstParamWarzone = true;
|
||||
} else if (this.args[0].equals("-p") || this.args[0].equals("print")) {
|
||||
wantsToPrint = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.getSender() instanceof Player) {
|
||||
player = (Player) commandSender;
|
||||
|
||||
if (zone == null) {
|
||||
// zone not found, is he standing in it?
|
||||
Warzone zoneByLoc = Warzone.getZoneByLocation(player);
|
||||
ZoneLobby lobbyByLoc = ZoneLobby.getLobbyByLocation(player);
|
||||
if (zoneByLoc == null && lobbyByLoc != null) {
|
||||
zoneByLoc = lobbyByLoc.getZone();
|
||||
}
|
||||
if (zoneByLoc != null) {
|
||||
zone = zoneByLoc;
|
||||
}
|
||||
}
|
||||
|
||||
team = Team.getTeamByPlayerName(player.getName());
|
||||
}
|
||||
|
||||
if (zone == null) {
|
||||
// No warzone found, whatever the mean, escape
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isFirstParamWarzone) {
|
||||
if (this.args.length == 1) {
|
||||
// Only one param: the warzone name - pritn usage
|
||||
return false;
|
||||
}
|
||||
// More than one param: the arguments need to be shifted
|
||||
String[] newargs = new String[this.args.length - 1];
|
||||
for (int i = 1; i < this.args.length; i++) {
|
||||
newargs[i - 1] = this.args[i];
|
||||
}
|
||||
this.args = newargs;
|
||||
}
|
||||
|
||||
// args have been shifted if needed
|
||||
if (this.args.length > 0) {
|
||||
TeamKind kind = TeamKind.teamKindFromString(this.args[0]);
|
||||
Team teamByName = zone.getTeamByKind(kind);
|
||||
|
||||
if (team == null && teamByName == null) {
|
||||
// Team not found
|
||||
this.badMsg("No such team. Use /teams.");
|
||||
return true;
|
||||
} else if (this.args.length == 1 && teamByName != null) {
|
||||
// only team name, print config
|
||||
this.msg(War.war.printConfig(teamByName));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (teamByName != null) {
|
||||
// first param was team, shift again
|
||||
String[] newargs = new String[this.args.length - 1];
|
||||
for (int i = 1; i < this.args.length; i++) {
|
||||
newargs[i - 1] = this.args[i];
|
||||
}
|
||||
this.args = newargs;
|
||||
}
|
||||
|
||||
if (teamByName != null) {
|
||||
// Named team > player's team
|
||||
team = teamByName;
|
||||
}
|
||||
} else {
|
||||
// No team param, show usage
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.args.length > 0 && (this.args[0].equals("-p") || this.args[0].equals("print"))) {
|
||||
// only printing
|
||||
if (this.args.length == 1) {
|
||||
this.msg(War.war.printConfig(team));
|
||||
return true;
|
||||
} else {
|
||||
// first param was to print, shift again
|
||||
String[] newargs = new String[this.args.length - 1];
|
||||
for (int i = 1; i < this.args.length; i++) {
|
||||
newargs[i - 1] = this.args[i];
|
||||
}
|
||||
this.args = newargs;
|
||||
}
|
||||
wantsToPrint = true;
|
||||
}
|
||||
|
||||
if (!this.isSenderZoneMaker()) {
|
||||
War.war.badMsg(this.getSender(), "You can't do this if you are not a warzone maker (permission war.zonemaker).");
|
||||
return true;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// We have a warzone, a team and indexed-from-0 arguments, let's update
|
||||
String namedParamReturn = War.war.updateTeamFromNamedParams(team, player, this.args);
|
||||
if (!namedParamReturn.equals("") && !namedParamReturn.equals("PARSE-ERROR")) {
|
||||
TeamConfigBag.afterUpdate(team, player, namedParamReturn, wantsToPrint);
|
||||
} else if (namedParamReturn.equals("PARSE-ERROR")) {
|
||||
this.badMsg("Failed to read named parameter(s).");
|
||||
} else {
|
||||
// empty return means no param was parsed - print command usage
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.config.TeamKind;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
|
||||
/**
|
||||
* Places a teamflag
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class SetTeamFlagCommand extends AbstractZoneMakerCommand {
|
||||
public SetTeamFlagCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("You can't do this if you are not in-game.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) this.getSender();
|
||||
|
||||
if (this.args.length != 1) {
|
||||
return false;
|
||||
}
|
||||
Warzone zone = Warzone.getZoneByLocation(player);
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
TeamKind kind = TeamKind.teamKindFromString(this.args[0]);
|
||||
Team team = zone.getTeamByKind(kind);
|
||||
if (team == null) {
|
||||
// no such team yet
|
||||
this.msg("Place the team spawn first.");
|
||||
} else if (team.getFlagVolume() == null) {
|
||||
// new team flag
|
||||
team.setTeamFlag(player.getLocation());
|
||||
Location playerLoc = player.getLocation();
|
||||
player.teleport(new Location(playerLoc.getWorld(), playerLoc.getBlockX() + 1, playerLoc.getBlockY(), playerLoc.getBlockZ()));
|
||||
this.msg("Team " + team.getName() + " flag added here.");
|
||||
WarzoneYmlMapper.save(zone);
|
||||
War.war.log(this.getSender().getName() + " created team " + team.getName() + " flag in warzone " + zone.getName(), Level.INFO);
|
||||
} else {
|
||||
// relocate flag
|
||||
team.getFlagVolume().resetBlocks();
|
||||
team.setTeamFlag(player.getLocation());
|
||||
Location playerLoc = player.getLocation();
|
||||
player.teleport(new Location(playerLoc.getWorld(), playerLoc.getBlockX() + 1, playerLoc.getBlockY(), playerLoc.getBlockZ() + 1));
|
||||
this.msg("Team " + team.getName() + " flag moved.");
|
||||
WarzoneYmlMapper.save(zone);
|
||||
War.war.log(this.getSender().getName() + " moved team " + team.getName() + " flag in warzone " + zone.getName(), Level.INFO);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.tommytony.war.config.WarConfigBag;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.mapper.WarYmlMapper;
|
||||
|
||||
public class SetWarConfigCommand extends AbstractOptionalWarAdminCommand {
|
||||
|
||||
public SetWarConfigCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotWarAdminException {
|
||||
super(handler, sender, args, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
boolean wantsToPrint = false;
|
||||
if (this.args.length == 0) {
|
||||
return false;
|
||||
} else if (this.args.length == 1 && (this.args[0].equals("-p") || this.args[0].equals("print"))) {
|
||||
String config = War.war.printConfig();
|
||||
this.msg(config);
|
||||
return true;
|
||||
} else if (this.args.length > 1 && (this.args[0].equals("-p") || this.args[0].equals("print"))) {
|
||||
wantsToPrint = true;
|
||||
}
|
||||
|
||||
if (!this.isSenderWarAdmin()) {
|
||||
War.war.badMsg(this.getSender(), "You can't do this if you are not a War admin (permission war.admin).");
|
||||
return true;
|
||||
}
|
||||
|
||||
String namedParamReturn = War.war.updateFromNamedParams(this.getSender(), this.args);
|
||||
if (!namedParamReturn.equals("") && !namedParamReturn.equals("PARSE-ERROR")) {
|
||||
WarConfigBag.afterUpdate(this.getSender(), namedParamReturn, wantsToPrint);
|
||||
} else if (namedParamReturn.equals("PARSE-ERROR")) {
|
||||
this.msg("Failed to read named parameters.");
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mapper.WarYmlMapper;
|
||||
import com.tommytony.war.structure.WarHub;
|
||||
|
||||
/**
|
||||
* Places the warhub
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class SetWarHubCommand extends AbstractWarAdminCommand {
|
||||
public SetWarHubCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotWarAdminException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("command.console");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.args.length != 0) {
|
||||
return false;
|
||||
}
|
||||
Player player = (Player) this.getSender();
|
||||
|
||||
if (War.war.getWarzones().size() > 0) {
|
||||
if (War.war.getWarHub() != null) {
|
||||
// reset existing hub
|
||||
War.war.getWarHub().getVolume().resetBlocks();
|
||||
War.war.getWarHub().setLocation(player.getLocation());
|
||||
War.war.getWarHub().initialize();
|
||||
this.msg("War hub moved.");
|
||||
War.war.log(this.getSender().getName() + " moved the warhub", Level.INFO);
|
||||
} else {
|
||||
War.war.setWarHub(new WarHub(player.getLocation()));
|
||||
War.war.getWarHub().initialize();
|
||||
for (Warzone zone : War.war.getWarzones()) {
|
||||
if (zone.getLobby() != null) {
|
||||
zone.getLobby().getVolume().resetBlocks();
|
||||
zone.getLobby().initialize();
|
||||
}
|
||||
}
|
||||
this.msg("War hub created.");
|
||||
War.war.log(this.getSender().getName() + " created the warhub", Level.INFO);
|
||||
}
|
||||
WarYmlMapper.save();
|
||||
} else {
|
||||
this.msg("No warzones yet.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.utility.Compat;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
public class SetZoneCommand extends AbstractZoneMakerCommand {
|
||||
|
||||
public SetZoneCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("command.console");
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) this.getSender();
|
||||
|
||||
if (this.args.length == 0) {
|
||||
return false;
|
||||
} else if (this.args.length > 2) {
|
||||
return false;
|
||||
} else if (this.args.length == 1) {
|
||||
Compat.BlockPair pair = Compat.getWorldEditSelection(player);
|
||||
if (pair != null) {
|
||||
ZoneSetter setter = new ZoneSetter(player, this.args[0]);
|
||||
setter.placeCorner1(pair.getBlock1());
|
||||
setter.placeCorner2(pair.getBlock2());
|
||||
return true;
|
||||
}
|
||||
War.war.addWandBearer(player, this.args[0]);
|
||||
} else {
|
||||
if (!this.args[1].equals("southeast") && !this.args[1].equals("northwest") && !this.args[1].equals("se") && !this.args[1].equals("nw") && !this.args[1].equals("corner1") && !this.args[1].equals("corner2") && !this.args[1].equals("c1") && !this.args[1].equals("c2") && !this.args[1].equals("pos1") && !this.args[1].equals("pos2") && !this.args[1].equals("wand")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ZoneSetter setter = new ZoneSetter(player, this.args[0]);
|
||||
if (this.args[1].equals("northwest") || this.args[1].equals("nw")) {
|
||||
setter.placeNorthwest();
|
||||
} else if (this.args[1].equals("southeast") || this.args[1].equals("se")) {
|
||||
setter.placeSoutheast();
|
||||
} else if (this.args[1].equals("corner1") || this.args[1].equals("c1") || this.args[1].equals("pos1")) {
|
||||
setter.placeCorner1();
|
||||
} else if (this.args[1].equals("corner2") || this.args[1].equals("c2") || this.args[1].equals("pos2")) {
|
||||
setter.placeCorner2();
|
||||
} else if (this.args[1].equals("wand")) {
|
||||
War.war.addWandBearer(player, this.args[0]);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,115 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.tommytony.war.config.WarzoneConfigBag;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.config.WarzoneConfig;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
import com.tommytony.war.structure.ZoneLobby;
|
||||
|
||||
public class SetZoneConfigCommand extends AbstractOptionalZoneMakerCommand {
|
||||
|
||||
public SetZoneConfigCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
Warzone zone = null;
|
||||
Player player = null;
|
||||
CommandSender commandSender = this.getSender();
|
||||
boolean isFirstParamWarzone = false;
|
||||
boolean wantsToPrint = false;
|
||||
|
||||
if (this.args.length == 0) {
|
||||
return false;
|
||||
} else {
|
||||
if (!this.args[0].contains(":")) {
|
||||
// warzone name maybe in first place
|
||||
Warzone zoneByName = Warzone.getZoneByName(this.args[0]);
|
||||
if (zoneByName != null) {
|
||||
zone = zoneByName;
|
||||
isFirstParamWarzone = true;
|
||||
} else if (this.args[0].equals("-p") || this.args[0].equals("print")) {
|
||||
wantsToPrint = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.getSender() instanceof Player) {
|
||||
player = (Player) commandSender;
|
||||
if (zone == null) {
|
||||
// zone not found, is he standing in it?
|
||||
Warzone zoneByLoc = Warzone.getZoneByLocation(player);
|
||||
ZoneLobby lobbyByLoc = ZoneLobby.getLobbyByLocation(player);
|
||||
if (zoneByLoc == null && lobbyByLoc != null) {
|
||||
zoneByLoc = lobbyByLoc.getZone();
|
||||
}
|
||||
if (zoneByLoc != null) {
|
||||
zone = zoneByLoc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (zone == null) {
|
||||
// No warzone found, whatever the mean, escape
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isFirstParamWarzone) {
|
||||
if (this.args.length == 1) {
|
||||
// Only one param: the warzone name - default to usage
|
||||
return false;
|
||||
}
|
||||
// More than one param: the arguments need to be shifted
|
||||
String[] newargs = new String[this.args.length - 1];
|
||||
for (int i = 1; i < this.args.length; i++) {
|
||||
newargs[i - 1] = this.args[i];
|
||||
}
|
||||
this.args = newargs;
|
||||
}
|
||||
|
||||
// args have been shifted if needed
|
||||
if (this.args.length > 0 && (this.args[0].equals("-p") || this.args[0].equals("print"))) {
|
||||
// only printing
|
||||
if (this.args.length == 1) {
|
||||
this.msg(War.war.printConfig(zone));
|
||||
return true;
|
||||
} else {
|
||||
// first param was to print, shift again
|
||||
String[] newargs = new String[this.args.length - 1];
|
||||
for (int i = 1; i < this.args.length; i++) {
|
||||
newargs[i - 1] = this.args[i];
|
||||
}
|
||||
this.args = newargs;
|
||||
}
|
||||
wantsToPrint = true;
|
||||
}
|
||||
|
||||
if (!this.isSenderZoneMaker()) {
|
||||
War.war.badMsg(this.getSender(), "You can't do this if you are not a warzone maker (permission war.zonemaker).");
|
||||
return true;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// We have a warzone and indexed-from-0 arguments, let's update
|
||||
String namedParamReturn = War.war.updateZoneFromNamedParams(zone, player, this.args);
|
||||
if (!namedParamReturn.equals("") && !namedParamReturn.equals("PARSE-ERROR")) {
|
||||
WarzoneConfigBag.afterUpdate(zone, player, namedParamReturn, wantsToPrint);
|
||||
} else if (namedParamReturn.equals("PARSE-ERROR")) {
|
||||
this.badMsg("Failed to read named parameter(s).");
|
||||
} else {
|
||||
// empty return means no param was parsed - print command usage
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,129 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
import com.tommytony.war.structure.ZoneLobby;
|
||||
import com.tommytony.war.utility.Direction;
|
||||
|
||||
/**
|
||||
* Places the zonelobby
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class SetZoneLobbyCommand extends AbstractZoneMakerCommand {
|
||||
|
||||
public SetZoneLobbyCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("You can't do this if you are not in-game.");
|
||||
return true;
|
||||
}
|
||||
if (this.args.length != 1) {
|
||||
return false;
|
||||
}
|
||||
Player player = (Player) this.getSender();
|
||||
ZoneLobby origLobby = null;
|
||||
Warzone zone = Warzone.getZoneByLocation((Player) this.getSender());
|
||||
if (zone == null) {
|
||||
origLobby = ZoneLobby.getLobbyByLocation((Player) this.getSender());
|
||||
if (origLobby != null) {
|
||||
zone = origLobby.getZone();
|
||||
}
|
||||
}
|
||||
|
||||
if (zone == null) {
|
||||
// Zone not where player is standing, maybe player is detaching/relocating the lobby
|
||||
Warzone givenWarzone = Warzone.getZoneByName(this.args[0]);
|
||||
if (givenWarzone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(givenWarzone)) {
|
||||
return true;
|
||||
} else {
|
||||
// Move the warzone lobby
|
||||
ZoneLobby lobby = givenWarzone.getLobby();
|
||||
if (lobby != null) {
|
||||
// reset existing lobby and save new volume at new location
|
||||
lobby.setLocation(player.getLocation());
|
||||
lobby.initialize();
|
||||
this.msg("Warzone lobby moved to your location.");
|
||||
} else {
|
||||
// new lobby
|
||||
lobby = new ZoneLobby(givenWarzone, player.getLocation());
|
||||
givenWarzone.setLobby(lobby);
|
||||
lobby.initialize();
|
||||
if (War.war.getWarHub() != null) { // warhub has to change
|
||||
War.war.getWarHub().getVolume().resetBlocks();
|
||||
War.war.getWarHub().initialize();
|
||||
}
|
||||
this.msg("Warzone lobby moved to your location.");
|
||||
}
|
||||
WarzoneYmlMapper.save(givenWarzone);
|
||||
}
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
} else {
|
||||
// Inside a warzone: use the classic n/s/e/w mode
|
||||
if (!this.args[0].equals("north") && !this.args[0].equals("n") && !this.args[0].equals("east") && !this.args[0].equals("e") && !this.args[0].equals("south") && !this.args[0].equals("s") && !this.args[0].equals("west") && !this.args[0].equals("w")) {
|
||||
if (Warzone.getZoneByName(this.args[0]) == zone && origLobby != null) {
|
||||
origLobby.setLocation(player.getLocation());
|
||||
origLobby.initialize();
|
||||
this.msg("Warzone lobby moved to your location.");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
ZoneLobby lobby = zone.getLobby();
|
||||
|
||||
BlockFace wall = Direction.WEST();
|
||||
String wallStr = "";
|
||||
if (this.args[0].equals("north") || this.args[0].equals("n")) {
|
||||
wall = Direction.NORTH();
|
||||
wallStr = "north";
|
||||
} else if (this.args[0].equals("east") || this.args[0].equals("e")) {
|
||||
wall = Direction.EAST();
|
||||
wallStr = "east";
|
||||
} else if (this.args[0].equals("south") || this.args[0].equals("s")) {
|
||||
wall = Direction.SOUTH();
|
||||
wallStr = "south";
|
||||
} else if (this.args[0].equals("west") || this.args[0].equals("w")) {
|
||||
wall = Direction.WEST();
|
||||
wallStr = "west";
|
||||
}
|
||||
|
||||
if (lobby != null) {
|
||||
// reset existing lobby
|
||||
lobby.getVolume().resetBlocks();
|
||||
lobby.setWall(wall);
|
||||
lobby.initialize();
|
||||
this.msg("Warzone lobby moved to " + wallStr + " side of zone.");
|
||||
} else {
|
||||
// new lobby
|
||||
lobby = new ZoneLobby(zone, wall);
|
||||
zone.setLobby(lobby);
|
||||
lobby.initialize();
|
||||
if (War.war.getWarHub() != null) { // warhub has to change
|
||||
War.war.getWarHub().getVolume().resetBlocks();
|
||||
War.war.getWarHub().initialize();
|
||||
}
|
||||
this.msg("Warzone lobby created on " + wallStr + "side of zone.");
|
||||
}
|
||||
WarzoneYmlMapper.save(zone);
|
||||
War.war.log(player.getName() + " moved lobby of warzone " + zone.getName(), Level.INFO);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
|
||||
/**
|
||||
* Sends a message to all team-members
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class TeamCommand extends AbstractWarCommand {
|
||||
public TeamCommand(WarCommandHandler handler, CommandSender sender, String[] args) {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("command.console");
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) this.getSender();
|
||||
Team playerTeam = Team.getTeamByPlayerName(player.getName());
|
||||
if (playerTeam == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.args.length < 1) {
|
||||
if (playerTeam.isInTeamChat(player)) {
|
||||
playerTeam.removeTeamChatPlayer(player);
|
||||
this.msg("team.chat.disable");
|
||||
} else {
|
||||
playerTeam.addTeamChatPlayer(player);
|
||||
this.msg("team.chat.enable");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
StringBuilder teamMessage = new StringBuilder();
|
||||
for (String part : this.args) {
|
||||
teamMessage.append(part).append(' ');
|
||||
}
|
||||
playerTeam.sendTeamChatMessage(player, teamMessage.toString());
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.structure.ZoneLobby;
|
||||
|
||||
/**
|
||||
* Shows team information
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class TeamsCommand extends AbstractWarCommand {
|
||||
public TeamsCommand(WarCommandHandler handler, CommandSender sender, String[] args) {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
Warzone zone;
|
||||
if (this.args.length == 1) {
|
||||
zone = Warzone.getZoneByName(this.args[0]);
|
||||
} else if (this.args.length == 0) {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
zone = Warzone.getZoneByLocation((Player) this.getSender());
|
||||
if (zone == null) {
|
||||
ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender());
|
||||
if (lobby == null) {
|
||||
return false;
|
||||
}
|
||||
zone = lobby.getZone();
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (zone == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.msg(zone.getTeamInformation());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
|
||||
|
||||
/**
|
||||
* Unloads war.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class UnloadWarCommand extends AbstractWarAdminCommand {
|
||||
public UnloadWarCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotWarAdminException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (this.args.length != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
War.war.unloadWar();
|
||||
this.msg("War unloaded.");
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,149 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.ui.WarUI;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
|
||||
/**
|
||||
* Handles commands received by War
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
* @package bukkit.tommytony.war
|
||||
*/
|
||||
public class WarCommandHandler {
|
||||
|
||||
/**
|
||||
* Handles a command
|
||||
*
|
||||
* @param sender
|
||||
* The sender of the command
|
||||
* @param cmd
|
||||
* The command
|
||||
* @param args
|
||||
* The arguments
|
||||
* @return Success
|
||||
*/
|
||||
public boolean handle(CommandSender sender, Command cmd, String[] args) {
|
||||
String command = cmd.getName();
|
||||
String[] arguments = null;
|
||||
|
||||
// parse prefixed commands
|
||||
if ((command.equals("war") || command.equals("War")) && args.length > 0) {
|
||||
command = args[0];
|
||||
arguments = new String[args.length - 1];
|
||||
for (int i = 1; i <= arguments.length; i++) {
|
||||
arguments[i - 1] = args[i];
|
||||
}
|
||||
|
||||
if (arguments.length == 1 && (arguments[0].equals("help") || arguments[0].equals("h"))) {
|
||||
// show /war help
|
||||
War.war.badMsg(sender, cmd.getUsage());
|
||||
return true;
|
||||
}
|
||||
} else if (command.equals("war") || command.equals("War")) {
|
||||
if (sender instanceof Player) {
|
||||
War.war.getUIManager().assignUI((Player) sender, new WarUI());
|
||||
} else {
|
||||
War.war.badMsg(sender, "Use /war help for information.");
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
arguments = args;
|
||||
}
|
||||
|
||||
AbstractWarCommand commandObj = null;
|
||||
try {
|
||||
if (command.equals("warhub")) {
|
||||
commandObj = new WarhubCommand(this, sender, arguments);
|
||||
} else if (command.equals("zones") || command.equals("warzones")) {
|
||||
commandObj = new WarzonesCommand(this, sender, arguments);
|
||||
} else if (command.equals("zone") || command.equals("warzone")) {
|
||||
commandObj = new WarzoneCommand(this, sender, arguments);
|
||||
} else if (command.equals("teams")) {
|
||||
commandObj = new TeamsCommand(this, sender, arguments);
|
||||
} else if (command.equals("join")) {
|
||||
commandObj = new JoinCommand(this, sender, arguments);
|
||||
} else if (command.equals("leave")) {
|
||||
commandObj = new LeaveCommand(this, sender, arguments);
|
||||
} else if (command.equals("team")) {
|
||||
commandObj = new TeamCommand(this, sender, arguments);
|
||||
} else if (command.equals("setzone")) {
|
||||
commandObj = new SetZoneCommand(this, sender, arguments);
|
||||
} else if (command.equals("deletezone")) {
|
||||
commandObj = new DeleteZoneCommand(this, sender, arguments);
|
||||
} else if (command.equals("setzonelobby")) {
|
||||
commandObj = new SetZoneLobbyCommand(this, sender, arguments);
|
||||
} else if (command.equals("savezone")) {
|
||||
commandObj = new SaveZoneCommand(this, sender, arguments);
|
||||
} else if (command.equals("resetzone")) {
|
||||
commandObj = new ResetZoneCommand(this, sender, arguments);
|
||||
} else if (command.equals("nextbattle")) {
|
||||
commandObj = new NextBattleCommand(this, sender, arguments);
|
||||
} else if (command.equals("renamezone")) {
|
||||
commandObj = new RenameZoneCommand(this, sender, arguments);
|
||||
} else if (command.equals("setteam")) {
|
||||
commandObj = new SetTeamCommand(this, sender, arguments);
|
||||
} else if (command.equals("deleteteam")) {
|
||||
commandObj = new DeleteTeamCommand(this, sender, arguments);
|
||||
} else if (command.equals("setteamflag")) {
|
||||
commandObj = new SetTeamFlagCommand(this, sender, arguments);
|
||||
} else if (command.equals("deleteteamflag")) {
|
||||
commandObj = new DeleteTeamFlagCommand(this, sender, arguments);
|
||||
} else if (command.equals("setmonument")) {
|
||||
commandObj = new SetMonumentCommand(this, sender, arguments);
|
||||
} else if (command.equals("deletemonument")) {
|
||||
commandObj = new DeleteMonumentCommand(this, sender, arguments);
|
||||
} else if (command.equals("setcapturepoint")) {
|
||||
commandObj = new SetCapturePointCommand(this, sender, arguments);
|
||||
} else if (command.equals("deletecapturepoint")) {
|
||||
commandObj = new DeleteCapturePointCommand(this, sender, arguments);
|
||||
} else if (command.equals("setbomb")) {
|
||||
commandObj = new SetBombCommand(this, sender, arguments);
|
||||
} else if (command.equals("deletebomb")) {
|
||||
commandObj = new DeleteBombCommand(this, sender, arguments);
|
||||
} else if (command.equals("setcake")) {
|
||||
commandObj = new SetCakeCommand(this, sender, arguments);
|
||||
} else if (command.equals("deletecake")) {
|
||||
commandObj = new DeleteCakeCommand(this, sender, arguments);
|
||||
}else if (command.equals("setteamconfig") || command.equals("teamcfg")) {
|
||||
commandObj = new SetTeamConfigCommand(this, sender, arguments);
|
||||
} else if (command.equals("setzoneconfig") || command.equals("zonecfg")) {
|
||||
commandObj = new SetZoneConfigCommand(this, sender, arguments);
|
||||
} else if (command.equals("setwarhub")) {
|
||||
commandObj = new SetWarHubCommand(this, sender, arguments);
|
||||
} else if (command.equals("deletewarhub")) {
|
||||
commandObj = new DeleteWarhubCommand(this, sender, arguments);
|
||||
} else if (command.equals("loadwar")) {
|
||||
commandObj = new LoadWarCommand(this, sender, arguments);
|
||||
} else if (command.equals("unloadwar")) {
|
||||
commandObj = new UnloadWarCommand(this, sender, arguments);
|
||||
} else if (command.equals("setwarconfig") || command.equals("warcfg")) {
|
||||
commandObj = new SetWarConfigCommand(this, sender, arguments);
|
||||
} else if (command.equals("zonemaker") || command.equals("zm")) {
|
||||
commandObj = new ZoneMakerCommand(this, sender, arguments);
|
||||
}
|
||||
// we are not responsible for any other command
|
||||
} catch (NotWarAdminException e) {
|
||||
War.war.badMsg(sender, "war.notadmin");
|
||||
} catch (NotZoneMakerException e) {
|
||||
War.war.badMsg(sender, "war.notzm");
|
||||
} catch (Exception e) {
|
||||
War.war.log("An error occured while handling command " + cmd.getName() + ". Exception:" + e.getClass().toString() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if(commandObj != null) {
|
||||
boolean handled = commandObj.handle();
|
||||
if(!handled) {
|
||||
War.war.badMsg(sender, cmd.getUsage());
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import com.tommytony.war.config.WarConfig;
|
||||
import com.tommytony.war.job.TeleportPlayerJob;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
|
||||
/**
|
||||
* Warps the player to the warhub.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class WarhubCommand extends AbstractWarCommand {
|
||||
public WarhubCommand(WarCommandHandler handler, CommandSender sender, String[] args) {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("command.console");
|
||||
return true;
|
||||
}
|
||||
if (this.args.length != 0) {
|
||||
return false;
|
||||
}
|
||||
Player player = (Player) this.getSender();
|
||||
if (War.war.getWarHub() == null) {
|
||||
this.badMsg("warhub.none");
|
||||
} else if (!War.war.canWarp(player)) {
|
||||
this.badMsg("warhub.permission");
|
||||
} else {
|
||||
Warzone playerWarzone = Warzone.getZoneByPlayerName(player.getName());
|
||||
if (playerWarzone != null) { // was in zone
|
||||
playerWarzone.handlePlayerLeave(player, War.war.getWarHub().getLocation(), true);
|
||||
}
|
||||
int warmup = War.war.getWarConfig().getInt(WarConfig.TPWARMUP);
|
||||
if (warmup > 0 && !player.hasPermission("war.warmupexempt")) {
|
||||
final int TICKS_PER_SECOND = 20;
|
||||
TeleportPlayerJob job = new TeleportPlayerJob(player, War.war.getWarHub().getLocation());
|
||||
job.runTaskLater(War.war, warmup);
|
||||
this.msg("command.tp.init", warmup / TICKS_PER_SECOND);
|
||||
} else {
|
||||
player.teleport(War.war.getWarHub().getLocation());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import com.tommytony.war.config.WarConfig;
|
||||
import com.tommytony.war.job.TeleportPlayerJob;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
/**
|
||||
* Warps the player to the given warzone.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class WarzoneCommand extends AbstractWarCommand {
|
||||
public WarzoneCommand(WarCommandHandler handler, CommandSender sender, String[] args) {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("command.console");
|
||||
return true;
|
||||
}
|
||||
Player player = (Player) this.getSender();
|
||||
if (args.length == 1) {
|
||||
if (War.war.canWarp(player)) {
|
||||
Warzone warzone = Warzone.getZoneByName(args[0]);
|
||||
if (warzone != null && warzone.getTeleport() != null) {
|
||||
Warzone playerWarzone = Warzone.getZoneByPlayerName(player.getName());
|
||||
int warmup = War.war.getWarConfig().getInt(WarConfig.TPWARMUP);
|
||||
if (playerWarzone != null) {
|
||||
playerWarzone.handlePlayerLeave(player, warzone.getTeleport(), true);
|
||||
}
|
||||
if (warmup > 0 && !player.hasPermission("war.warmupexempt")) {
|
||||
final int TICKS_PER_SECOND = 20;
|
||||
TeleportPlayerJob job = new TeleportPlayerJob(player, warzone.getTeleport());
|
||||
job.runTaskLater(War.war, warmup);
|
||||
this.msg("command.tp.init", warmup / TICKS_PER_SECOND);
|
||||
} else {
|
||||
player.teleport(warzone.getTeleport());
|
||||
}
|
||||
} else {
|
||||
this.badMsg("zone.zone404");
|
||||
}
|
||||
} else {
|
||||
this.badMsg("zone.warp.permission");
|
||||
}
|
||||
return true;
|
||||
} else if (args.length == 2 && (args[1].equalsIgnoreCase("sb")
|
||||
|| args[1].equalsIgnoreCase("score")
|
||||
|| args[1].equalsIgnoreCase("scoreboard"))) {
|
||||
Warzone warzone = Warzone.getZoneByName(args[0]);
|
||||
if (warzone != null) {
|
||||
if (warzone.getScoreboard() != null) {
|
||||
if (warzone.getScoreboard() == player.getScoreboard()) {
|
||||
player.setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard());
|
||||
} else {
|
||||
player.setScoreboard(warzone.getScoreboard());
|
||||
}
|
||||
} else {
|
||||
this.badMsg("zone.score.board404");
|
||||
}
|
||||
} else {
|
||||
this.badMsg("zone.zone404");
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
|
||||
/**
|
||||
* Lists all warzones
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class WarzonesCommand extends AbstractWarCommand {
|
||||
public WarzonesCommand(WarCommandHandler handler, CommandSender sender, String[] args) {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (this.args.length != 0) {
|
||||
return false;
|
||||
}
|
||||
StringBuilder warzonesMessage = new StringBuilder(War.war.getString("zone.zoneinfo.prefix"));
|
||||
if (War.war.getWarzones().isEmpty()) {
|
||||
warzonesMessage.append(War.war.getString("zone.teaminfo.none"));
|
||||
} else {
|
||||
for (Warzone warzone : War.war.getWarzones()) {
|
||||
warzonesMessage.append('\n');
|
||||
warzonesMessage.append(MessageFormat.format(War.war.getString("zone.zoneinfo.format"),
|
||||
warzone.getName(), warzone.getTeams().size(), warzone.getPlayerCount()));
|
||||
}
|
||||
}
|
||||
|
||||
this.msg(warzonesMessage.toString() + ((this.getSender() instanceof Player) ? War.war.getString("zone.zoneinfo.teleport") : ""));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.mapper.WarYmlMapper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Makes a player zonemaker and other way round.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class ZoneMakerCommand extends AbstractWarCommand {
|
||||
|
||||
public ZoneMakerCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
|
||||
if (sender instanceof Player) { // i hate java for this.
|
||||
if (!War.war.isZoneMaker((Player) sender)) {
|
||||
for (OfflinePlayer offlinePlayer : War.war.getZoneMakersImpersonatingPlayers()) {
|
||||
if (offlinePlayer.isOnline() && sender.equals(offlinePlayer.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new NotZoneMakerException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("You can't do this if you are not in-game.");
|
||||
return true;
|
||||
}
|
||||
Player player = (Player) this.getSender();
|
||||
|
||||
if (War.war.isZoneMaker(player)) {
|
||||
if (this.args.length == 0) {
|
||||
War.war.getZoneMakersImpersonatingPlayers().add(player);
|
||||
this.msg("You are now impersonating a regular player. Type /zonemaker again to toggle back to war maker mode.");
|
||||
} else if (this.args.length == 1) {
|
||||
OfflinePlayer other = Bukkit.getOfflinePlayer(this.args[0]);
|
||||
// make someone zonemaker or remove the right
|
||||
if (War.war.getZoneMakerNames().contains(other)) {
|
||||
// kick
|
||||
War.war.getZoneMakerNames().remove(other);
|
||||
this.msg(this.args[0] + " is not a zone maker anymore.");
|
||||
if (other.isOnline()) {
|
||||
War.war.msg(other.getPlayer(), player.getName() + " took away your warzone maker priviledges.");
|
||||
War.war.log(player.getName() + " took away zonemaker rights from " + other.getName(), Level.INFO);
|
||||
}
|
||||
} else {
|
||||
// add
|
||||
War.war.getZoneMakerNames().add(other);
|
||||
this.msg(this.args[0] + " is now a zone maker.");
|
||||
if (other.isOnline()) {
|
||||
War.war.msg(other.getPlayer(), player.getName() + " made you warzone maker.");
|
||||
War.war.log(player.getName() + " made " + other.getName() + " a zonemaker", Level.INFO);
|
||||
}
|
||||
}
|
||||
WarYmlMapper.save();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (this.args.length != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
War.war.getZoneMakersImpersonatingPlayers().remove(player);
|
||||
this.msg("You are back as a zone maker.");
|
||||
WarYmlMapper.save();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,274 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.config.WarConfig;
|
||||
import com.tommytony.war.mapper.WarYmlMapper;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
import com.tommytony.war.structure.ZoneLobby;
|
||||
import com.tommytony.war.utility.Direction;
|
||||
import com.tommytony.war.volume.NotNorthwestException;
|
||||
import com.tommytony.war.volume.NotSoutheastException;
|
||||
import com.tommytony.war.volume.TooBigException;
|
||||
import com.tommytony.war.volume.TooSmallException;
|
||||
|
||||
public class ZoneSetter {
|
||||
|
||||
private final Player player;
|
||||
private final String zoneName;
|
||||
|
||||
public ZoneSetter(Player player, String zoneName) {
|
||||
this.player = player;
|
||||
this.zoneName = zoneName;
|
||||
}
|
||||
|
||||
public void placeNorthwest() {
|
||||
Warzone warzone = War.war.findWarzone(this.zoneName);
|
||||
Block northwestBlock = this.player.getLocation().getWorld().getBlockAt(this.player.getLocation());
|
||||
StringBuilder msgString = new StringBuilder();
|
||||
try {
|
||||
if (warzone == null && War.war.getWarzones().size() >= War.war.getWarConfig().getInt(WarConfig.MAXZONES)) {
|
||||
// max warzones reached
|
||||
War.war.badMsg(player, "Too many warzones already! To change the maximum, use /warcfg maxzone:20.");
|
||||
return;
|
||||
} else if (warzone == null) {
|
||||
// create the warzone
|
||||
warzone = new Warzone(this.player.getLocation().getWorld(), this.zoneName);
|
||||
warzone.addAuthor(player.getName());
|
||||
War.war.getIncompleteZones().add(warzone);
|
||||
warzone.getVolume().setNorthwest(northwestBlock.getLocation());
|
||||
War.war.msg(this.player, "Warzone " + warzone.getName() + " created. Northwesternmost point set to x:" + warzone.getVolume().getNorthwestX() + " z:" + warzone.getVolume().getNorthwestZ() + ". ");
|
||||
War.war.log(player.getName() + " created warzone " + zoneName + " by setting its nw corner", Level.INFO);
|
||||
} else if (!this.isPlayerAuthorOfZoneOrAdmin(warzone)) {
|
||||
return;
|
||||
} else {
|
||||
// change existing warzone
|
||||
this.resetWarzone(warzone, msgString);
|
||||
warzone.getVolume().setNorthwest(northwestBlock.getLocation());
|
||||
msgString.append("Warzone " + warzone.getName() + " modified. Northwesternmost point set to x:" + warzone.getVolume().getNorthwestX() + " z:" + warzone.getVolume().getNorthwestZ() + ". ");
|
||||
War.war.log(player.getName() + " updated warzone " + zoneName + " by setting its nw corner", Level.INFO);
|
||||
}
|
||||
this.saveIfReady(warzone, msgString);
|
||||
} catch (NotNorthwestException e) {
|
||||
War.war.badMsg(this.player, "The block you selected is not to the northwest of the existing southeasternmost block.");
|
||||
if (warzone.getVolume().isSaved()) {
|
||||
warzone.initializeZone(); // was reset before changing
|
||||
}
|
||||
} catch (TooSmallException e) {
|
||||
this.handleTooSmall();
|
||||
if (warzone.getVolume().isSaved()) {
|
||||
warzone.initializeZone();
|
||||
}
|
||||
} catch (TooBigException e) {
|
||||
this.handleTooBig();
|
||||
if (warzone.getVolume().isSaved()) {
|
||||
warzone.initializeZone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void placeSoutheast() {
|
||||
Warzone warzone = War.war.findWarzone(this.zoneName);
|
||||
Block southeastBlock = this.player.getLocation().getWorld().getBlockAt(this.player.getLocation());
|
||||
StringBuilder msgString = new StringBuilder();
|
||||
try {
|
||||
if (warzone == null && War.war.getWarzones().size() >= War.war.getWarConfig().getInt(WarConfig.MAXZONES)) {
|
||||
// max warzones reached
|
||||
War.war.badMsg(player, "Too many warzones already! To change the maximum, use /warcfg maxzone:20.");
|
||||
return;
|
||||
} else if (warzone == null) {
|
||||
// create the warzone
|
||||
warzone = new Warzone(this.player.getLocation().getWorld(), this.zoneName);
|
||||
warzone.addAuthor(player.getName());
|
||||
War.war.getIncompleteZones().add(warzone);
|
||||
warzone.getVolume().setSoutheast(southeastBlock.getLocation());
|
||||
War.war.msg(this.player, "Warzone " + warzone.getName() + " created. Southeasternmost point set to x:" + warzone.getVolume().getSoutheastX() + " z:" + warzone.getVolume().getSoutheastZ() + ". ");
|
||||
War.war.log(player.getName() + " created warzone " + zoneName + " by setting its se corner", Level.INFO);
|
||||
} else if (!this.isPlayerAuthorOfZoneOrAdmin(warzone)) {
|
||||
return;
|
||||
} else {
|
||||
// change existing warzone
|
||||
this.resetWarzone(warzone, msgString);
|
||||
warzone.getVolume().setSoutheast(southeastBlock.getLocation());
|
||||
msgString.append("Warzone " + warzone.getName() + " modified. Southeasternmost point set to x:" + warzone.getVolume().getSoutheastX() + " z:" + warzone.getVolume().getSoutheastZ() + ". ");
|
||||
War.war.log(player.getName() + " updated warzone " + zoneName + " by setting its se corner", Level.INFO);
|
||||
}
|
||||
this.saveIfReady(warzone, msgString);
|
||||
} catch (NotSoutheastException e) {
|
||||
War.war.badMsg(this.player, "The block you selected is not to the southeast of the existing northwestnmost block.");
|
||||
if (warzone.getVolume().isSaved()) {
|
||||
warzone.initializeZone(); // was reset before changing
|
||||
}
|
||||
} catch (TooSmallException e) {
|
||||
this.handleTooSmall();
|
||||
if (warzone.getVolume().isSaved()) {
|
||||
warzone.initializeZone();
|
||||
}
|
||||
} catch (TooBigException e) {
|
||||
this.handleTooBig();
|
||||
if (warzone.getVolume().isSaved()) {
|
||||
warzone.initializeZone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void placeCorner1() {
|
||||
Block corner1Block = this.player.getLocation().getWorld().getBlockAt(this.player.getLocation());
|
||||
this.placeCorner1(corner1Block);
|
||||
}
|
||||
|
||||
public void placeCorner1(Block corner1Block) {
|
||||
Warzone warzone = War.war.findWarzone(this.zoneName);
|
||||
StringBuilder msgString = new StringBuilder();
|
||||
try {
|
||||
if (warzone == null && War.war.getWarzones().size() >= War.war.getWarConfig().getInt(WarConfig.MAXZONES)) {
|
||||
// max warzones reached
|
||||
War.war.badMsg(player, "Too many warzones already! To change the maximum, use /warcfg maxzone:20.");
|
||||
return;
|
||||
} else if (warzone == null) {
|
||||
// create the warzone
|
||||
warzone = new Warzone(this.player.getLocation().getWorld(), this.zoneName);
|
||||
warzone.addAuthor(player.getName());
|
||||
War.war.getIncompleteZones().add(warzone);
|
||||
warzone.getVolume().setZoneCornerOne(corner1Block);
|
||||
War.war.msg(this.player, "Warzone " + warzone.getName() + " created. Corner 1 set to x:" + corner1Block.getX() + " y:" + corner1Block.getY() + " z:" + corner1Block.getZ() + ". ");
|
||||
War.war.log(player.getName() + " created warzone " + zoneName + " by setting its corner 1", Level.INFO);
|
||||
} else if (!this.isPlayerAuthorOfZoneOrAdmin(warzone)) {
|
||||
return;
|
||||
} else {
|
||||
// change existing warzone
|
||||
this.resetWarzone(warzone, msgString);
|
||||
warzone.getVolume().setZoneCornerOne(corner1Block);
|
||||
msgString.append("Warzone " + warzone.getName() + " modified. Corner 1 set to x:" + corner1Block.getX() + " y:" + corner1Block.getY() + " z:" + corner1Block.getZ() + ". ");
|
||||
War.war.log(player.getName() + " updated warzone " + zoneName + " by setting its corner 1", Level.INFO);
|
||||
}
|
||||
this.saveIfReady(warzone, msgString);
|
||||
} catch (TooSmallException e) {
|
||||
this.handleTooSmall();
|
||||
if (warzone.getVolume().isSaved()) {
|
||||
warzone.initializeZone();
|
||||
}
|
||||
} catch (TooBigException e) {
|
||||
this.handleTooBig();
|
||||
if (warzone.getVolume().isSaved()) {
|
||||
warzone.initializeZone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void placeCorner2() {
|
||||
Block corner2Block = this.player.getLocation().getWorld().getBlockAt(this.player.getLocation());
|
||||
this.placeCorner2(corner2Block);
|
||||
}
|
||||
|
||||
public void placeCorner2(Block corner2Block) {
|
||||
Warzone warzone = War.war.findWarzone(this.zoneName);
|
||||
StringBuilder msgString = new StringBuilder();
|
||||
try {
|
||||
if (warzone == null && War.war.getWarzones().size() >= War.war.getWarConfig().getInt(WarConfig.MAXZONES)) {
|
||||
// max warzones reached
|
||||
War.war.badMsg(player, "Too many warzones already! To change the maximum, use /warcfg maxzone:20.");
|
||||
return;
|
||||
} else if (warzone == null) {
|
||||
// create the warzone
|
||||
warzone = new Warzone(this.player.getLocation().getWorld(), this.zoneName);
|
||||
warzone.addAuthor(player.getName());
|
||||
War.war.getIncompleteZones().add(warzone);
|
||||
warzone.getVolume().setZoneCornerTwo(corner2Block);
|
||||
War.war.msg(this.player, "Warzone " + warzone.getName() + " created. Corner 2 set to x:" + corner2Block.getX() + " y:" + corner2Block.getY() + " z:" + corner2Block.getZ() + ". ");
|
||||
War.war.log(player.getName() + " created warzone " + zoneName + " by setting its corner 2", Level.INFO);
|
||||
} else if (!this.isPlayerAuthorOfZoneOrAdmin(warzone)) {
|
||||
return;
|
||||
} else {
|
||||
// change existing warzone
|
||||
this.resetWarzone(warzone, msgString);
|
||||
warzone.getVolume().setZoneCornerTwo(corner2Block);
|
||||
msgString.append("Warzone " + warzone.getName() + " modified. Corner 2 set to x:" + corner2Block.getX() + " y:" + corner2Block.getY() + " z:" + corner2Block.getZ() + ". ");
|
||||
War.war.log(player.getName() + " updated warzone " + zoneName + " by setting its corner 2", Level.INFO);
|
||||
}
|
||||
this.saveIfReady(warzone, msgString);
|
||||
} catch (TooSmallException e) {
|
||||
this.handleTooSmall();
|
||||
if (warzone.getVolume().isSaved()) {
|
||||
warzone.initializeZone();
|
||||
}
|
||||
} catch (TooBigException e) {
|
||||
this.handleTooBig();
|
||||
if (warzone.getVolume().isSaved()) {
|
||||
warzone.initializeZone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isPlayerAuthorOfZoneOrAdmin(Warzone warzone) {
|
||||
boolean isAuthor = warzone.isAuthor(player);
|
||||
boolean isAdmin = !War.war.isWarAdmin(player);
|
||||
if (!isAuthor && !isAdmin) {
|
||||
War.war.badMsg(player, "You can't do this because you are not an author of the " + warzone.getName() + " warzone." );
|
||||
}
|
||||
return isAuthor || isAdmin;
|
||||
}
|
||||
|
||||
private void resetWarzone(Warzone warzone, StringBuilder msgString) {
|
||||
if (warzone.getVolume().isSaved()) {
|
||||
War.war.msg(this.player, "Resetting " + warzone.getName() + " blocks.");
|
||||
if (warzone.getLobby() != null && warzone.getLobby().getVolume() != null) {
|
||||
warzone.getLobby().getVolume().resetBlocks();
|
||||
}
|
||||
warzone.getVolume().resetBlocks();
|
||||
msgString.append(warzone.getVolume().size() + " blocks reset. ");
|
||||
}
|
||||
}
|
||||
|
||||
private void handleTooSmall() {
|
||||
War.war.badMsg(this.player, "That would make the " + this.zoneName + " warzone too small. Sides must be at least 10 blocks and all existing structures (spawns, flags, etc) must fit inside.");
|
||||
}
|
||||
|
||||
private void handleTooBig() {
|
||||
War.war.badMsg(this.player, "That would make the " + this.zoneName + " warzone too big. Sides must be less than 750 blocks.");
|
||||
}
|
||||
|
||||
private void saveIfReady(Warzone warzone, StringBuilder msgString) {
|
||||
if (warzone.ready()) {
|
||||
if (!War.war.getWarzones().contains(warzone)) {
|
||||
War.war.addWarzone(warzone);
|
||||
}
|
||||
if (War.war.getIncompleteZones().contains(warzone)) {
|
||||
War.war.getIncompleteZones().remove(warzone);
|
||||
}
|
||||
WarYmlMapper.save();
|
||||
msgString.append("Saving new warzone blocks...");
|
||||
War.war.msg(this.player, msgString.toString());
|
||||
warzone.saveState(false); // we just changed the volume, cant reset walls
|
||||
|
||||
if (warzone.getLobby() == null) {
|
||||
// Set default lobby on south side
|
||||
ZoneLobby lobby = new ZoneLobby(warzone, Direction.SOUTH());
|
||||
warzone.setLobby(lobby);
|
||||
if (War.war.getWarHub() != null) { // warhub has to change
|
||||
War.war.getWarHub().getVolume().resetBlocks();
|
||||
War.war.getWarHub().initialize();
|
||||
}
|
||||
War.war.msg(this.player, "Default lobby created on south side of zone. Use /setzonelobby <n/s/e/w> to change its position.");
|
||||
}
|
||||
|
||||
warzone.initializeZone();
|
||||
WarzoneYmlMapper.save(warzone);
|
||||
War.war.msg(this.player, "Warzone saved.");
|
||||
War.war.log(this.player.getName() + " saved first version of warzone " + zoneName, Level.INFO);
|
||||
} else {
|
||||
if (warzone.getVolume().getCornerOne() == null) {
|
||||
msgString.append("Still missing corner 1.");
|
||||
} else if (warzone.getVolume().getCornerTwo() == null) {
|
||||
msgString.append("Still missing corner 2.");
|
||||
}
|
||||
War.war.msg(this.player, msgString.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.tommytony.war.config;
|
||||
|
||||
public enum FlagReturn {
|
||||
BOTH,
|
||||
FLAG,
|
||||
SPAWN;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString().toLowerCase();
|
||||
}
|
||||
|
||||
public static FlagReturn getFromString(String string) {
|
||||
for (FlagReturn flagMode : FlagReturn.values()) {
|
||||
if (string.toLowerCase().equals(flagMode.toString())) {
|
||||
return flagMode;
|
||||
}
|
||||
}
|
||||
|
||||
return FlagReturn.BOTH;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,153 @@
|
|||
package com.tommytony.war.config;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.utility.Loadout;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class InventoryBag {
|
||||
|
||||
private List<Loadout> loadouts = new ArrayList<Loadout>();
|
||||
private HashMap<Integer, ItemStack> reward = null;
|
||||
|
||||
private Warzone warzone;
|
||||
|
||||
public InventoryBag(Warzone warzone) {
|
||||
this.warzone = warzone;
|
||||
}
|
||||
|
||||
public InventoryBag() {
|
||||
this.warzone = null;
|
||||
}
|
||||
|
||||
public void addLoadout(String name, HashMap<Integer, ItemStack> loadout) {
|
||||
this.loadouts.add(new Loadout(name, loadout, null));
|
||||
}
|
||||
|
||||
public void addLoadout(Loadout loadout) {
|
||||
this.loadouts.add(loadout);
|
||||
}
|
||||
|
||||
public void removeLoadout(String name) {
|
||||
ArrayList<Loadout> loadoutsToRemove = new ArrayList<Loadout>();
|
||||
for (Loadout ldt : loadouts) {
|
||||
if (ldt.getName().equals(name)) {
|
||||
loadoutsToRemove.add(ldt);
|
||||
}
|
||||
}
|
||||
|
||||
// avoid concurrent modif exceptions
|
||||
for (Loadout loadoutToRemove : loadoutsToRemove) {
|
||||
this.removeLoadout(loadoutToRemove);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeLoadout(Loadout ldt) {
|
||||
this.loadouts.remove(ldt);
|
||||
}
|
||||
|
||||
public boolean hasLoadouts() {
|
||||
return loadouts.size() > 0;
|
||||
}
|
||||
|
||||
public HashMap<String, HashMap<Integer, ItemStack>> getLoadouts() {
|
||||
return Loadout.toLegacyFormat(loadouts);
|
||||
}
|
||||
|
||||
public List<Loadout> getNewLoadouts() {
|
||||
return loadouts;
|
||||
}
|
||||
|
||||
public void setLoadouts(List<Loadout> loadouts) {
|
||||
this.loadouts = loadouts;
|
||||
}
|
||||
|
||||
public HashMap<String, HashMap<Integer, ItemStack>> resolveLoadouts() {
|
||||
if (this.hasLoadouts()) {
|
||||
return this.getLoadouts();
|
||||
} else if (warzone != null && warzone.getDefaultInventories().hasLoadouts()) {
|
||||
return warzone.getDefaultInventories().resolveLoadouts();
|
||||
} else if (War.war.getDefaultInventories().hasLoadouts()) {
|
||||
return War.war.getDefaultInventories().resolveLoadouts();
|
||||
} else {
|
||||
return new HashMap<String, HashMap<Integer, ItemStack>>();
|
||||
}
|
||||
}
|
||||
|
||||
public List<Loadout> resolveNewLoadouts() {
|
||||
if (this.hasLoadouts()) {
|
||||
return this.getNewLoadouts();
|
||||
} else if (warzone != null && warzone.getDefaultInventories().hasLoadouts()) {
|
||||
return warzone.getDefaultInventories().resolveNewLoadouts();
|
||||
} else if (War.war.getDefaultInventories().hasLoadouts()) {
|
||||
return War.war.getDefaultInventories().resolveNewLoadouts();
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
public void setReward(HashMap<Integer, ItemStack> reward) {
|
||||
this.reward = reward;
|
||||
}
|
||||
|
||||
public boolean hasReward() {
|
||||
return reward != null;
|
||||
}
|
||||
|
||||
public HashMap<Integer, ItemStack> getReward() {
|
||||
return reward;
|
||||
}
|
||||
|
||||
public HashMap<Integer, ItemStack> resolveReward() {
|
||||
if (this.hasReward()) {
|
||||
return reward;
|
||||
} else if (warzone != null && warzone.getDefaultInventories().hasReward()) {
|
||||
return warzone.getDefaultInventories().resolveReward();
|
||||
} else {
|
||||
return War.war.getDefaultInventories().resolveReward();
|
||||
}
|
||||
}
|
||||
|
||||
public void clearLoadouts() {
|
||||
this.loadouts.clear();
|
||||
}
|
||||
|
||||
public HashMap<Integer, ItemStack> getLoadout(String loadoutName) {
|
||||
for (Loadout ldt : loadouts) {
|
||||
if (ldt.getName().equals(loadoutName)) {
|
||||
return ldt.getContents();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Loadout getNewLoadout(String loadoutName) {
|
||||
for (Loadout ldt : loadouts) {
|
||||
if (ldt.getName().equals(loadoutName)) {
|
||||
return ldt;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setLoadout(String name, HashMap<Integer, ItemStack> contents) {
|
||||
for (Loadout ldt : loadouts) {
|
||||
if (ldt.getName().equals(name)) {
|
||||
ldt.setContents(contents);
|
||||
return;
|
||||
}
|
||||
}
|
||||
loadouts.add(new Loadout(name, contents, null));
|
||||
}
|
||||
|
||||
public boolean containsLoadout(String name) {
|
||||
return this.getNewLoadout(name) != null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,155 @@
|
|||
package com.tommytony.war.config;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.MemoryConfiguration;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
/**
|
||||
* Manage rewards for certain killstreaks.
|
||||
*
|
||||
* @author cmastudios
|
||||
*/
|
||||
public class KillstreakReward {
|
||||
|
||||
private ConfigurationSection section;
|
||||
private Set<String> airstrikePlayers;
|
||||
|
||||
/**
|
||||
* Creates a new killstreak reward class with default options.
|
||||
*/
|
||||
public KillstreakReward() {
|
||||
this(new MemoryConfiguration());
|
||||
section.set("3.privmsg", "You have been rewarded with some health for your kills.");
|
||||
section.set("3.reward.health", 8);
|
||||
section.set("4.reward.xp", 3);
|
||||
section.set("5.message", "{0} is on a &ckillstreak&f! 5 kills this life.");
|
||||
section.set("5.privmsg", "You have received some items for your kills.");
|
||||
section.set("5.reward.points", 1);
|
||||
section.set("5.reward.airstrike", true);
|
||||
section.set("5.reward.items", ImmutableList.of(new ItemStack(Material.ARROW, 15), new ItemStack(Material.EGG)));
|
||||
section.set("5.reward.effect", Effect.GHAST_SHRIEK.name());
|
||||
ItemStack sword = new ItemStack(Material.WOODEN_SWORD);
|
||||
sword.addEnchantment(Enchantment.DAMAGE_ALL, 2);
|
||||
sword.addEnchantment(Enchantment.KNOCKBACK, 1);
|
||||
ItemMeta meta = sword.getItemMeta();
|
||||
meta.setDisplayName("The Breaker");
|
||||
meta.setLore(ImmutableList.of("Very slow speed"));
|
||||
sword.setItemMeta(meta);
|
||||
section.set("7.reward.items", ImmutableList.of(sword));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new killstreak reward class with options from the provided
|
||||
* config.
|
||||
*
|
||||
* @param section Section to load killstreak options from, such as
|
||||
* set.war.killstreak
|
||||
*/
|
||||
public KillstreakReward(ConfigurationSection section) {
|
||||
this.section = section;
|
||||
this.airstrikePlayers = new HashSet<String>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Rewards a player for their current killstreak. The player must be in a
|
||||
* warzone.
|
||||
*
|
||||
* @param player Player to reward
|
||||
* @param kills Amount of kills to reward for
|
||||
*/
|
||||
public void rewardPlayer(Player player, int kills) {
|
||||
if (section == null) {
|
||||
/*
|
||||
* Cancel the reward if there is no configuration for killstreaks.
|
||||
* This can occur if the server owner has an older War config with
|
||||
* no settings for killstreaks and have neglected to add any. Heck,
|
||||
* they shouldn't have enabled killstreaks in the warzone anyway.
|
||||
*/
|
||||
return;
|
||||
}
|
||||
final Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
final Team playerTeam = Team.getTeamByPlayerName(player.getName());
|
||||
Validate.notNull(zone, "Cannot reward player if they are not in a warzone");
|
||||
Validate.notNull(playerTeam, "Cannot reward player if they are not in a team");
|
||||
if (section.contains(Integer.toString(kills))) {
|
||||
ConfigurationSection killSection = section.getConfigurationSection(Integer.toString(kills));
|
||||
if (killSection.contains("message")) {
|
||||
final String playerName = playerTeam.getKind().getColor() + player.getName() + ChatColor.WHITE;
|
||||
final String message = ChatColor.translateAlternateColorCodes('&', MessageFormat.format(killSection.getString("message"), playerName));
|
||||
for (Team team : zone.getTeams()) {
|
||||
team.teamcast(message);
|
||||
}
|
||||
}
|
||||
if (killSection.contains("privmsg")) {
|
||||
War.war.msg(player, ChatColor.translateAlternateColorCodes('&', killSection.getString("privmsg")));
|
||||
}
|
||||
if (killSection.contains("reward.health")) {
|
||||
double health = player.getHealth() + killSection.getInt("reward.health");
|
||||
player.setHealth(health > 20 ? 20 : health); // Grant up to full health only
|
||||
}
|
||||
if (killSection.contains("reward.items")) {
|
||||
for (Object obj : killSection.getList("reward.items")) {
|
||||
if (obj instanceof ItemStack) {
|
||||
player.getInventory().addItem((ItemStack) obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (killSection.contains("reward.xp") && !playerTeam.getTeamConfig().resolveBoolean(TeamConfig.XPKILLMETER)) {
|
||||
// Will not work if XPKILLMETER is enabled
|
||||
player.setLevel(player.getLevel() + killSection.getInt("reward.xp"));
|
||||
}
|
||||
if (killSection.contains("reward.points")) {
|
||||
for (int i = 0; i < killSection.getInt("reward.points"); i++) {
|
||||
playerTeam.addPoint();
|
||||
}
|
||||
// Detect win conditions
|
||||
if (playerTeam.getPoints() >= playerTeam.getTeamConfig().resolveInt(TeamConfig.MAXSCORE)) {
|
||||
player.getServer().getScheduler().runTaskLater(War.war, new Runnable() {
|
||||
public void run() {
|
||||
zone.handleScoreCapReached(playerTeam.getName());
|
||||
}
|
||||
}, 1L);
|
||||
} else {
|
||||
// just added a point
|
||||
playerTeam.resetSign();
|
||||
zone.getLobby().resetTeamGateSign(playerTeam);
|
||||
}
|
||||
}
|
||||
if (killSection.getBoolean("reward.airstrike")) {
|
||||
this.airstrikePlayers.add(player.getName());
|
||||
}
|
||||
if (killSection.contains("reward.effect")) {
|
||||
Effect effect = Effect.valueOf(killSection.getString("reward.effect"));
|
||||
player.getWorld().playEffect(player.getLocation(), effect, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void saveTo(ConfigurationSection section) {
|
||||
Map<String, Object> values = this.section.getValues(true);
|
||||
for (Map.Entry<String, Object> entry : values.entrySet()) {
|
||||
section.set(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public Set<String> getAirstrikePlayers() {
|
||||
return airstrikePlayers;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
package com.tommytony.war.config;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Map;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.MemoryConfiguration;
|
||||
|
||||
/**
|
||||
* Storage class for MySQL configuration settings.
|
||||
*
|
||||
* @author cmastudios
|
||||
*/
|
||||
public class MySQLConfig {
|
||||
|
||||
private ConfigurationSection section;
|
||||
|
||||
/**
|
||||
* Load the values from the specified section into the MySQL config.
|
||||
*
|
||||
* @param section Section to load MySQL settings from.
|
||||
*/
|
||||
public MySQLConfig(ConfigurationSection section) {
|
||||
this.section = section;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new MySQL configuration section with default values.
|
||||
*/
|
||||
public MySQLConfig() {
|
||||
this(new MemoryConfiguration());
|
||||
section.set("enabled", false);
|
||||
section.set("host", "localhost");
|
||||
section.set("port", 3306);
|
||||
section.set("database", "war");
|
||||
section.set("username", "root");
|
||||
section.set("password", "meow");
|
||||
section.set("logging.enabled", false);
|
||||
section.set("logging.autoclear",
|
||||
"WHERE `date` < NOW() - INTERVAL 7 DAY");
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if MySQL support is enabled.
|
||||
*
|
||||
* @return true if MySQL support is enabled, false otherwise.
|
||||
*/
|
||||
public boolean isEnabled() {
|
||||
return section.getBoolean("enabled");
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if kill-death logging is enabled.
|
||||
*
|
||||
* @return true if kill-death logging is enabled, false otherwise.
|
||||
*/
|
||||
public boolean isLoggingEnabled() {
|
||||
return section.getBoolean("logging.enabled");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get WHERE clause for automatic deletion from database table.
|
||||
*
|
||||
* @return deletion WHERE clause or empty string.
|
||||
*/
|
||||
public String getLoggingDeleteClause() {
|
||||
return section.getString("logging.autoclear", "");
|
||||
}
|
||||
|
||||
private String getJDBCUrl() {
|
||||
return String.format("jdbc:mysql://%s:%d/%s?user=%s&password=%s",
|
||||
section.getString("host"), section.getInt("port"),
|
||||
section.getString("database"), section.getString("username"),
|
||||
section.getString("password"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a connection to the MySQL database represented by this configuration.
|
||||
*
|
||||
* @return connection to MySQL database.
|
||||
* @throws SQLException Error occured connecting to database.
|
||||
* @throws IllegalArgumentException MySQL support is not enabled.
|
||||
*/
|
||||
public Connection getConnection() throws SQLException {
|
||||
Validate.isTrue(this.isEnabled(), "MySQL support is not enabled");
|
||||
return DriverManager.getConnection(this.getJDBCUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy represented configuration into another configuration section.
|
||||
*
|
||||
* @param section Mutable section to write values in.
|
||||
*/
|
||||
public void saveTo(ConfigurationSection section) {
|
||||
Map<String, Object> values = this.section.getValues(true);
|
||||
for (Map.Entry<String, Object> entry : values.entrySet()) {
|
||||
section.set(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.tommytony.war.config;
|
||||
|
||||
public enum ScoreboardType {
|
||||
|
||||
NONE(null),
|
||||
POINTS("Points"),
|
||||
LIFEPOOL("Lifepool"),
|
||||
TOPKILLS("Top kills"),
|
||||
PLAYERCOUNT("Player count"),
|
||||
SWITCHING("Switching");
|
||||
private final String displayName;
|
||||
|
||||
ScoreboardType(String displayName) {
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
public static ScoreboardType getFromString(String string) {
|
||||
for (ScoreboardType boardMode : ScoreboardType.values()) {
|
||||
if (string.toLowerCase().equals(boardMode.toString())) {
|
||||
return boardMode;
|
||||
}
|
||||
}
|
||||
|
||||
return ScoreboardType.NONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString().toLowerCase();
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package com.tommytony.war.config;
|
||||
|
||||
|
||||
public enum TeamConfig {
|
||||
FLAGMUSTBEHOME (Boolean.class, "Flag Must Be Home", "If true, enemy flag cannot be captured if your flag is out"),
|
||||
FLAGPOINTSONLY (Boolean.class, null, null), // obsolete
|
||||
FLAGRETURN (FlagReturn.class, "Flag Return Destination", "Defines where the flag must be returned to capture\nOptions: spawn, flag, or both"),
|
||||
LIFEPOOL (Integer.class, "Lifepool", "Sets maximum team lives"),
|
||||
MAXSCORE (Integer.class, "Max Score", "Sets the point limit for when a team will win"),
|
||||
NOHUNGER (Boolean.class, "No Hunger", "If true, player hunger will not decrease"),
|
||||
PLAYERLOADOUTASDEFAULT (Boolean.class, "Player Loadout As Default", "If true, the default loadout will be the items the player brings into the zone"),
|
||||
RESPAWNTIMER (Integer.class, "Respawn Time", "Time, in seconds, required to wait after each death"),
|
||||
SATURATION (Integer.class, "Saturation", "Set player saturation to this level after each death"),
|
||||
SPAWNSTYLE (TeamSpawnStyle.class, "Spawn Style", "Sets the type spawn point\nOptions: small, big, flat, invisible"),
|
||||
TEAMSIZE (Integer.class, "Team Size", "Maximum players that may play on a team"),
|
||||
PERMISSION (String.class, "Required Permission", "Only allow players with a certain permission to join a team"),
|
||||
XPKILLMETER (Boolean.class, "XP Kill Meter", "Use the XP bar to count kills"),
|
||||
KILLSTREAK (Boolean.class, "Killstreak Rewards", "Reward players for kills based on war.yml configuration"),
|
||||
BLOCKWHITELIST (String.class, "Block Whitelist", "Comma-separated list of blocks players may break or place, 'all' removes this limit"),
|
||||
PLACEBLOCK (Boolean.class, "Place Blocks", "If true, players can place blocks"),
|
||||
APPLYPOTION(String.class, "Apply Potion Effect", "Give players a potion effect after each death, Format: EFFECT;DURATION;STRENGTH"),
|
||||
ECOREWARD(Double.class, "Economy Reward", "Give the winning team this much money, requires Vault plugin"),
|
||||
INVENTORYDROP(Boolean.class, "Drop Inventory", "If true, players will drop items on death"),
|
||||
BORDERDROP(Boolean.class, "Drop Near Border", "If true, players can drop items near the border\nUsually enabled to prevent duping");
|
||||
|
||||
private final Class<?> configType;
|
||||
private final String title;
|
||||
private final String description;
|
||||
|
||||
TeamConfig(Class<?> configType, String title, String description) {
|
||||
this.configType = configType;
|
||||
this.title = title;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public Class<?> getConfigType() {
|
||||
return configType;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public static TeamConfig teamConfigFromString(String str) {
|
||||
String lowered = str.toLowerCase();
|
||||
for (TeamConfig config : TeamConfig.values()) {
|
||||
if (config.toString().startsWith(lowered)) {
|
||||
return config;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String toStringWithValue(Object value) {
|
||||
return this.toString() + ":" + value.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString().toLowerCase();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,280 @@
|
|||
package com.tommytony.war.config;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class TeamConfigBag {
|
||||
|
||||
private EnumMap<TeamConfig, Object> bag = new EnumMap<TeamConfig, Object>(TeamConfig.class);
|
||||
private Warzone warzone;
|
||||
|
||||
public TeamConfigBag(Warzone warzone) {
|
||||
this.warzone = warzone;
|
||||
}
|
||||
|
||||
public TeamConfigBag() {
|
||||
this.warzone = null;
|
||||
}
|
||||
|
||||
public static void afterUpdate(Team team, CommandSender sender, String namedParamReturn, boolean wantsToPrint) {
|
||||
final Warzone zone = team.getZone();
|
||||
WarzoneYmlMapper.save(zone);
|
||||
|
||||
String zoneReset = "Some changes may require a /resetzone. ";
|
||||
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.RESETONCONFIGCHANGE)) {
|
||||
zone.reinitialize(); // bring back team spawns etc
|
||||
zoneReset = "Zone reset. ";
|
||||
}
|
||||
|
||||
if (wantsToPrint) {
|
||||
War.war.msg(sender, "Team config saved. " + zoneReset + namedParamReturn + " " + War.war.printConfig(team));
|
||||
} else {
|
||||
War.war.msg(sender, "Team config saved. " + zoneReset + namedParamReturn);
|
||||
}
|
||||
|
||||
War.war.log(sender.getName() + " updated team " + team.getName() + " configuration in warzone " + zone.getName() + "." + namedParamReturn, Level.INFO);
|
||||
|
||||
if (War.war.getWarHub() != null) { // maybe the zone was disabled/enabled
|
||||
War.war.getWarHub().getVolume().resetBlocks();
|
||||
War.war.getWarHub().initialize();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean contains(TeamConfig config) {
|
||||
return this.bag.containsKey(config);
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
this.bag.clear();
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return this.bag.keySet().size() == 0;
|
||||
}
|
||||
|
||||
public void put(TeamConfig config, Object value) {
|
||||
this.bag.put(config, value);
|
||||
}
|
||||
|
||||
public Object getValue(TeamConfig config) {
|
||||
if (this.contains(config)) {
|
||||
return this.bag.get(config);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Object resolveValue(TeamConfig config) {
|
||||
if (this.contains(config)) {
|
||||
return this.bag.get(config);
|
||||
} else if (this.warzone != null && this.warzone.getTeamDefaultConfig().contains(config)){
|
||||
// use Warzone default config
|
||||
return this.warzone.getTeamDefaultConfig().resolveValue(config);
|
||||
} else {
|
||||
// use War default config
|
||||
return War.war.getTeamDefaultConfig().resolveValue(config);
|
||||
}
|
||||
}
|
||||
|
||||
public Double getDouble(TeamConfig config) {
|
||||
if (this.contains(config)) {
|
||||
return (Double)this.bag.get(config);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Double resolveDouble(TeamConfig config) {
|
||||
if (this.contains(config)) {
|
||||
return (Double)this.bag.get(config);
|
||||
} else if (this.warzone != null && this.warzone.getTeamDefaultConfig().contains(config)){
|
||||
// use Warzone default config
|
||||
return this.warzone.getTeamDefaultConfig().resolveDouble(config);
|
||||
} else {
|
||||
// use War default config
|
||||
return War.war.getTeamDefaultConfig().resolveDouble(config);
|
||||
}
|
||||
}
|
||||
|
||||
public Integer getInt(TeamConfig config) {
|
||||
if (this.contains(config)) {
|
||||
return (Integer)this.bag.get(config);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Integer resolveInt(TeamConfig config) {
|
||||
if (this.contains(config)) {
|
||||
return (Integer) this.bag.get(config);
|
||||
} else if (this.warzone != null && this.warzone.getTeamDefaultConfig().contains(config)){
|
||||
// use Warzone default config
|
||||
return this.warzone.getTeamDefaultConfig().resolveInt(config);
|
||||
} else {
|
||||
// use War default config
|
||||
return War.war.getTeamDefaultConfig().resolveInt(config);
|
||||
}
|
||||
}
|
||||
|
||||
public Boolean getBoolean(TeamConfig config) {
|
||||
if (this.contains(config)) {
|
||||
return (Boolean)this.bag.get(config);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Boolean resolveBoolean(TeamConfig config) {
|
||||
if (this.contains(config)) {
|
||||
return (Boolean) this.bag.get(config);
|
||||
} else if (this.warzone != null && this.warzone.getTeamDefaultConfig().contains(config)){
|
||||
// use Warzone default config
|
||||
return this.warzone.getTeamDefaultConfig().resolveBoolean(config);
|
||||
} else {
|
||||
// use War default config
|
||||
return War.war.getTeamDefaultConfig().resolveBoolean(config);
|
||||
}
|
||||
}
|
||||
|
||||
public String getString(TeamConfig config) {
|
||||
if (this.contains(config)) {
|
||||
return (String)this.bag.get(config);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String resolveString(TeamConfig config) {
|
||||
if (this.contains(config)) {
|
||||
return (String) this.bag.get(config);
|
||||
} else if (this.warzone != null && this.warzone.getTeamDefaultConfig().contains(config)){
|
||||
// use Warzone default config
|
||||
return this.warzone.getTeamDefaultConfig().resolveString(config);
|
||||
} else {
|
||||
// use War default config
|
||||
return War.war.getTeamDefaultConfig().resolveString(config);
|
||||
}
|
||||
}
|
||||
|
||||
public FlagReturn resolveFlagReturn() {
|
||||
if (this.contains(TeamConfig.FLAGRETURN)) {
|
||||
return (FlagReturn) this.bag.get(TeamConfig.FLAGRETURN);
|
||||
} else if (this.warzone != null && this.warzone.getTeamDefaultConfig().contains(TeamConfig.FLAGRETURN)){
|
||||
// use Warzone default config
|
||||
return this.warzone.getTeamDefaultConfig().resolveFlagReturn();
|
||||
} else {
|
||||
// use War default config
|
||||
return War.war.getTeamDefaultConfig().resolveFlagReturn();
|
||||
}
|
||||
}
|
||||
|
||||
public FlagReturn getFlagReturn() {
|
||||
if (this.contains(TeamConfig.FLAGRETURN)) {
|
||||
return (FlagReturn) this.bag.get(TeamConfig.FLAGRETURN);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public TeamSpawnStyle resolveSpawnStyle() {
|
||||
if (this.contains(TeamConfig.SPAWNSTYLE)) {
|
||||
return (TeamSpawnStyle) this.bag.get(TeamConfig.SPAWNSTYLE);
|
||||
} else if (this.warzone != null && this.warzone.getTeamDefaultConfig().contains(TeamConfig.SPAWNSTYLE)){
|
||||
// use War default config
|
||||
return this.warzone.getTeamDefaultConfig().resolveSpawnStyle();
|
||||
} else {
|
||||
return War.war.getTeamDefaultConfig().resolveSpawnStyle();
|
||||
}
|
||||
}
|
||||
|
||||
public TeamSpawnStyle getSpawnStyle() {
|
||||
if (this.contains(TeamConfig.SPAWNSTYLE)) {
|
||||
return (TeamSpawnStyle) this.bag.get(TeamConfig.SPAWNSTYLE);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void loadFrom(ConfigurationSection teamConfigSection) {
|
||||
for (TeamConfig config : TeamConfig.values()) {
|
||||
if (teamConfigSection.contains(config.toString())) {
|
||||
if (config.getConfigType().equals(Integer.class)) {
|
||||
this.put(config, teamConfigSection.getInt(config.toString()));
|
||||
} else if (config.getConfigType().equals(Boolean.class)) {
|
||||
this.put(config, teamConfigSection.getBoolean(config.toString()));
|
||||
} else if (config.getConfigType().equals(String.class)) {
|
||||
this.put(config, teamConfigSection.getString(config.toString()));
|
||||
} else if (config.getConfigType().equals(Double.class)) {
|
||||
this.put(config, teamConfigSection.getDouble(config.toString()));
|
||||
} else if (config.getConfigType().equals(FlagReturn.class)) {
|
||||
String flagReturnStr = teamConfigSection.getString(config.toString());
|
||||
FlagReturn returnMode = FlagReturn.getFromString(flagReturnStr);
|
||||
if (returnMode != null) {
|
||||
this.put(config, returnMode);
|
||||
}
|
||||
} else if (config.getConfigType().equals(TeamSpawnStyle.class)) {
|
||||
String spawnStyleStr = teamConfigSection.getString(config.toString());
|
||||
TeamSpawnStyle style = TeamSpawnStyle.getStyleFromString(spawnStyleStr);
|
||||
if (style != null) {
|
||||
this.put(config, style);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void saveTo(ConfigurationSection teamConfigSection) {
|
||||
for (TeamConfig config : TeamConfig.values()) {
|
||||
if (this.contains(config)) {
|
||||
if (config.getConfigType().equals(Integer.class)
|
||||
|| config.getConfigType().equals(Boolean.class)
|
||||
|| config.getConfigType().equals(Double.class)) {
|
||||
teamConfigSection.set(config.toString(), this.bag.get(config));
|
||||
} else {
|
||||
teamConfigSection.set(config.toString(), this.bag.get(config).toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String updateFromNamedParams(Map<String, String> namedParams) {
|
||||
String returnMessage = "";
|
||||
for (String namedParam : namedParams.keySet()) {
|
||||
TeamConfig teamConfig = TeamConfig.teamConfigFromString(namedParam);
|
||||
if (teamConfig != null) {
|
||||
if (teamConfig.getConfigType().equals(Integer.class)) {
|
||||
int intValue = Integer.parseInt(namedParams.get(namedParam));
|
||||
this.bag.put(teamConfig, intValue);
|
||||
} else if (teamConfig.getConfigType().equals(Double.class)) {
|
||||
double doubleValue = Double.parseDouble(namedParams.get(namedParam));
|
||||
this.bag.put(teamConfig, doubleValue);
|
||||
} else if (teamConfig.getConfigType().equals(Boolean.class)) {
|
||||
String onOff = namedParams.get(namedParam);
|
||||
this.bag.put(teamConfig, onOff.equals("on") || onOff.equals("true"));
|
||||
} else if (teamConfig.getConfigType().equals(String.class)) {
|
||||
String str = namedParams.get(namedParam);
|
||||
this.bag.put(teamConfig, str);
|
||||
} else if (teamConfig.getConfigType().equals(FlagReturn.class)) {
|
||||
FlagReturn flagValue = FlagReturn.getFromString(namedParams.get(namedParam));
|
||||
this.bag.put(teamConfig, flagValue);
|
||||
} else if (teamConfig.getConfigType().equals(TeamSpawnStyle.class)) {
|
||||
TeamSpawnStyle spawnValue = TeamSpawnStyle.getStyleFromString(namedParams.get(namedParam));
|
||||
this.bag.put(teamConfig, spawnValue);
|
||||
}
|
||||
returnMessage += " " + teamConfig.toString() + " set to " + namedParams.get(namedParam);
|
||||
} else if (namedParam.equals("delete")) {
|
||||
String toDelete = namedParams.get(namedParam);
|
||||
teamConfig = TeamConfig.teamConfigFromString(toDelete);
|
||||
|
||||
// param delete (to restore inheritance)
|
||||
if (teamConfig != null) {
|
||||
this.bag.remove(teamConfig);
|
||||
returnMessage += " " + teamConfig.toString() + " removed";
|
||||
}
|
||||
}
|
||||
}
|
||||
return returnMessage;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,157 @@
|
|||
package com.tommytony.war.config;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
|
||||
public enum TeamKind {
|
||||
WHITE (DyeColor.WHITE, Material.WHITE_WOOL, ChatColor.WHITE, 450),
|
||||
ORANGE (DyeColor.ORANGE, Material.ORANGE_WOOL, ChatColor.GOLD, 51),
|
||||
MAGENTA (DyeColor.MAGENTA, Material.MAGENTA_WOOL, ChatColor.LIGHT_PURPLE, 353),
|
||||
BLUE (DyeColor.LIGHT_BLUE, Material.LIGHT_BLUE_WOOL, ChatColor.BLUE, 23),
|
||||
GOLD (DyeColor.YELLOW, Material.YELLOW_WOOL, ChatColor.YELLOW, 403), // yellow = gold
|
||||
GREEN (DyeColor.LIME, Material.LIME_WOOL, ChatColor.GREEN, 612),
|
||||
PINK (DyeColor.PINK, Material.PINK_WOOL, ChatColor.LIGHT_PURPLE, 929),
|
||||
GRAY (DyeColor.GRAY, Material.GRAY_WOOL, ChatColor.DARK_GRAY, 600),
|
||||
IRON (DyeColor.GRAY, Material.GRAY_WOOL, ChatColor.GRAY, 154), // lightgrey = iron
|
||||
DIAMOND (DyeColor.CYAN, Material.CYAN_WOOL, ChatColor.DARK_AQUA, 738), // cyan = diamond
|
||||
PURPLE (DyeColor.PURPLE, Material.PURPLE_WOOL, ChatColor.DARK_PURPLE, 153),
|
||||
NAVY (DyeColor.BLUE, Material.BLUE_WOOL, ChatColor.DARK_BLUE, 939),
|
||||
BROWN (DyeColor.BROWN, Material.BROWN_WOOL, ChatColor.DARK_RED, 908),
|
||||
DARKGREEN (DyeColor.GREEN, Material.GREEN_WOOL, ChatColor.DARK_GREEN, 612),
|
||||
RED (DyeColor.RED, Material.RED_WOOL, ChatColor.RED, 245),
|
||||
BLACK (DyeColor.BLACK, Material.BLACK_WOOL, ChatColor.BLACK, 0);
|
||||
|
||||
private final DyeColor dyeColor;
|
||||
private final ChatColor chatColor;
|
||||
private final Material material;
|
||||
private final int potionEffectColor;
|
||||
|
||||
TeamKind(DyeColor blockHeadColor, Material material, ChatColor color, int potionEffectColor) {
|
||||
this.dyeColor = blockHeadColor;
|
||||
this.material = material;
|
||||
this.chatColor = color;
|
||||
this.potionEffectColor = potionEffectColor;
|
||||
}
|
||||
|
||||
public static TeamKind teamKindFromString(String str) {
|
||||
String lowered = str.toLowerCase();
|
||||
for (TeamKind kind : TeamKind.values()) {
|
||||
if (kind.toString().startsWith(lowered)) {
|
||||
return kind;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static TeamKind getTeam(String teamName) {
|
||||
for (TeamKind team : TeamKind.values()) {
|
||||
if (team.toString().equalsIgnoreCase(teamName)) {
|
||||
return team;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get wool block data for the dye color.
|
||||
* @deprecated TODO remove all spout craft support
|
||||
* @return wool color data value
|
||||
*/
|
||||
public byte getData() {
|
||||
return this.dyeColor.getWoolData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the color of this team in chat messages.
|
||||
*
|
||||
* @return team chat color.
|
||||
*/
|
||||
public ChatColor getColor() {
|
||||
return this.chatColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the color of the wool block as a bukkit color.
|
||||
*
|
||||
* @return wool block color.
|
||||
*/
|
||||
public org.bukkit.Color getBukkitColor() {
|
||||
return this.dyeColor.getColor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get head block material.
|
||||
*
|
||||
* @return team head block material.
|
||||
*/
|
||||
public Material getMaterial() {
|
||||
return this.material;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString().toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get color of the team's potion effect, for thieves.
|
||||
*
|
||||
* @return potion effect color.
|
||||
*/
|
||||
public int getPotionEffectColor() {
|
||||
return this.potionEffectColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single item of this team's wool head block.
|
||||
*
|
||||
* @return single block head item.
|
||||
*/
|
||||
public ItemStack getBlockHead() {
|
||||
return new ItemStack(this.material, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a block is this team's color block.
|
||||
*
|
||||
* @param block Wool block to check.
|
||||
* @return true if block is this team's color.
|
||||
*/
|
||||
public boolean isTeamBlock(BlockState block) {
|
||||
return block.getType() == material;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an item is this team's color block.
|
||||
*
|
||||
* @param item Wool item to check.
|
||||
* @return true if item is this team's color.
|
||||
*/
|
||||
public boolean isTeamItem(ItemStack item) {
|
||||
return item.getType() == material;
|
||||
}
|
||||
|
||||
public String getFormattedName() {
|
||||
return this.getColor() + this.name().toLowerCase() + ChatColor.WHITE;
|
||||
}
|
||||
|
||||
public String getCapsName() {
|
||||
return String.valueOf(name().charAt(0)) + name().substring(1).toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a colored hat item for the team.
|
||||
* @return Hat item with the team's color.
|
||||
*/
|
||||
public ItemStack getHat() {
|
||||
ItemStack helmet = new ItemStack(Material.LEATHER_HELMET);
|
||||
LeatherArmorMeta meta = (LeatherArmorMeta) helmet.getItemMeta();
|
||||
meta.setColor(this.getBukkitColor());
|
||||
helmet.setItemMeta(meta);
|
||||
return helmet;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.tommytony.war.config;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
public enum TeamSpawnStyle {
|
||||
INVISIBLE,
|
||||
SMALL,
|
||||
FLAT,
|
||||
BIG;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString().toLowerCase();
|
||||
}
|
||||
|
||||
public static TeamSpawnStyle getStyleFromString(String string) {
|
||||
for (TeamSpawnStyle style : TeamSpawnStyle.values()) {
|
||||
if (string.toLowerCase().equals(style.toString())) {
|
||||
return style;
|
||||
}
|
||||
}
|
||||
|
||||
return TeamSpawnStyle.SMALL;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
package com.tommytony.war.config;
|
||||
|
||||
|
||||
public enum WarConfig {
|
||||
BUILDINZONESONLY (Boolean.class, "Build in zones only", "Allow building in zones only"),
|
||||
DISABLEBUILDMESSAGE (Boolean.class, "Disable build message", "Silently prevent building outside zones"),
|
||||
DISABLEPVPMESSAGE (Boolean.class, "Disable PVP message", "Silently prevent PVP"),
|
||||
KEEPOLDZONEVERSIONS (Boolean.class, "Keep old zone versions", "If true, archive the warzone on each save"),
|
||||
MAXZONES (Integer.class, "Max zones", "Limit on number of zones that can be created"),
|
||||
PVPINZONESONLY (Boolean.class, "PVP in zones only", "If true, limits PVP to warzones"),
|
||||
TNTINZONESONLY (Boolean.class, "TNT in zones only", "If true, limits TNT to warzones"),
|
||||
RESETSPEED (Integer.class, "Reset speed", "Number of blocks to reset per tick"),
|
||||
MAXSIZE (Integer.class, "Max size", "Maximum volume of a warzone"),
|
||||
LANGUAGE (String.class, "Language", "Preferred server language"),
|
||||
AUTOJOIN (String.class, "Auto-join", "Name of warzone to send players to upon join"),
|
||||
TPWARMUP(Integer.class, "TP warmup", "Amount of seconds a player must wait after requesting a teleport"),
|
||||
DISABLECOOLDOWN (Boolean.class, "Disable the 1.9 combat cooldown", "Disables the attack cooldown when swinging a weapon");
|
||||
|
||||
private final Class<?> configType;
|
||||
private final String title;
|
||||
private final String description;
|
||||
|
||||
WarConfig(Class<?> configType, String title, String description) {
|
||||
this.configType = configType;
|
||||
this.title = title;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public Class<?> getConfigType() {
|
||||
return configType;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public static WarConfig warConfigFromString(String str) {
|
||||
String lowered = str.toLowerCase();
|
||||
for (WarConfig config : WarConfig.values()) {
|
||||
if (config.toString().startsWith(lowered)) {
|
||||
return config;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String toStringWithValue(Object value) {
|
||||
return this.toString() + ":" + value.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString().toLowerCase();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
package com.tommytony.war.config;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.mapper.WarYmlMapper;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
public class WarConfigBag {
|
||||
|
||||
EnumMap<WarConfig, Object> bag = new EnumMap<WarConfig, Object>(WarConfig.class);
|
||||
|
||||
public void put(WarConfig config, Object value) {
|
||||
this.bag.put(config, value);
|
||||
}
|
||||
|
||||
public Object getValue(WarConfig config) {
|
||||
if (this.bag.containsKey(config)) {
|
||||
return this.bag.get(config);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Integer getInt(WarConfig config) {
|
||||
if (this.bag.containsKey(config)) {
|
||||
return (Integer)this.bag.get(config);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Boolean getBoolean(WarConfig config) {
|
||||
if (this.bag.containsKey(config)) {
|
||||
return (Boolean)this.bag.get(config);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String getString(WarConfig config) {
|
||||
if (this.bag.containsKey(config)) {
|
||||
return (String)this.bag.get(config);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void loadFrom(ConfigurationSection warConfigSection) {
|
||||
for (WarConfig config : WarConfig.values()) {
|
||||
if (warConfigSection.contains(config.toString())) {
|
||||
if (config.getConfigType().equals(Integer.class)) {
|
||||
this.put(config, warConfigSection.getInt(config.toString()));
|
||||
} else if (config.getConfigType().equals(Boolean.class)) {
|
||||
this.put(config, warConfigSection.getBoolean(config.toString()));
|
||||
} else if (config.getConfigType().equals(String.class)) {
|
||||
this.put(config, warConfigSection.getString(config.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void saveTo(ConfigurationSection warConfigSection) {
|
||||
for (WarConfig config : WarConfig.values()) {
|
||||
if (this.bag.containsKey(config)) {
|
||||
warConfigSection.set(config.toString(), this.bag.get(config));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String updateFromNamedParams(Map<String, String> namedParams) {
|
||||
String returnMessage = "";
|
||||
for (String namedParam : namedParams.keySet()) {
|
||||
WarConfig warConfig = WarConfig.warConfigFromString(namedParam);
|
||||
if (warConfig != null) {
|
||||
if (warConfig.getConfigType().equals(Integer.class)) {
|
||||
int intValue = Integer.parseInt(namedParams.get(namedParam));
|
||||
this.bag.put(warConfig, intValue);
|
||||
} else if (warConfig.getConfigType().equals(Boolean.class)) {
|
||||
String onOff = namedParams.get(namedParam);
|
||||
this.bag.put(warConfig, onOff.equals("on") || onOff.equals("true"));
|
||||
} else if (warConfig.getConfigType().equals(String.class)) {
|
||||
String str = namedParams.get(namedParam);
|
||||
this.bag.put(warConfig, str);
|
||||
}
|
||||
if (warConfig == WarConfig.LANGUAGE) {
|
||||
War.reloadLanguage();
|
||||
}
|
||||
returnMessage += warConfig.toString() + " set to " + namedParams.get(namedParam);
|
||||
}
|
||||
}
|
||||
return returnMessage;
|
||||
}
|
||||
|
||||
public static void afterUpdate(CommandSender sender, String namedParamReturn, boolean wantsToPrint) {
|
||||
WarYmlMapper.save();
|
||||
if (wantsToPrint) {
|
||||
String config = War.war.printConfig();
|
||||
War.war.msg(sender, "War config saved. " + namedParamReturn + " " + config);
|
||||
} else {
|
||||
War.war.msg(sender, "War config saved. " + namedParamReturn);
|
||||
}
|
||||
War.war.log(sender.getName() + " updated War configuration. " + namedParamReturn, Level.INFO);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
package com.tommytony.war.config;
|
||||
|
||||
public enum WarzoneConfig {
|
||||
AUTOASSIGN (Boolean.class, "Auto-Assign", "If true, distributes players across teams"),
|
||||
BLOCKHEADS (Boolean.class, "Team Helmets", "If true, players are given a team-colored hat"),
|
||||
DEATHMESSAGES (Boolean.class, "Death Notification", "If true, notify the zone when players are killed"),
|
||||
DISABLED (Boolean.class, "Disable Zone", "If true, prevent players from joining the zone"),
|
||||
FRIENDLYFIRE (Boolean.class, "Friendly Fire", "If true, players are allowed to injure teammates"),
|
||||
GLASSWALLS (Boolean.class, "Glass Walls", "If true, use magic glass walls to keep players in/out of zones"),
|
||||
INSTABREAK (Boolean.class, "Insta-Break", "If true, players break blocks instantly\nUseful for Spleef gamemodes"),
|
||||
MINTEAMS (Integer.class, "Minimum Teams", "Minimum number of active teams required to start the battle"),
|
||||
MINPLAYERS (Integer.class, "Minimum Players", "Minimum number of players required per team to start the battle"),
|
||||
MONUMENTHEAL (Integer.class, "Monument Heal", "Number of hearts given to players jumping on the monument"),
|
||||
NOCREATURES (Boolean.class, "No Mobs", "If true, prevent mob spawning"),
|
||||
NODROPS (Boolean.class, "No Drops", "If true, prevent players from dropping items"),
|
||||
PVPINZONE (Boolean.class, "PVP", "If true, PVP is enabled\nUseful for Spleef gamemodes"),
|
||||
REALDEATHS (Boolean.class, "Real Deaths", "If true, send players to the real Minecraft death screen"),
|
||||
RESETONEMPTY (Boolean.class, "Reset on Empty", "If true, reset the zone when all players leave"),
|
||||
RESETONCONFIGCHANGE (Boolean.class, "Reset on Config Change", "If true, reset every time the zone config is modified"),
|
||||
RESETONLOAD (Boolean.class, "Reset on Load", "If true, reset warzone when the server starts"),
|
||||
RESETONUNLOAD (Boolean.class, "Reset on Unload", "If true, reset warzone when the server stops"),
|
||||
UNBREAKABLE (Boolean.class, "Unbreakable Blocks", "If true, prevent block breaking"),
|
||||
JOINMIDBATTLE (Boolean.class, "Join Mid-Battle", "If true, players are allowed to join during a battle"),
|
||||
AUTOJOIN (Boolean.class, "Auto-Join", "If true, bypass the zone lobby and auto-assign the player a team"),
|
||||
SCOREBOARD (ScoreboardType.class, "Scoreboard Type", "Type of scoreboard for this zone\nOptions: none, points, lifepool, top kills"),
|
||||
SOUPHEALING (Boolean.class, "Soup Healing", "If true, allow players to heal by consuming soup"),
|
||||
ALLOWENDER (Boolean.class, "Allow Ender Chests", "If true, ender chests are allowed\nEnder chests are usually blocked to prevent item duplication"),
|
||||
RESETBLOCKS (Boolean.class, "Reset Blocks", "If true, reset warzone blocks each battle"),
|
||||
CAPTUREPOINTTIME (Integer.class, "Capture Control Time", "Time, in seconds, required to gain control of a capture point"),
|
||||
PREPTIME(Integer.class, "Preparation Time", "Time, in seconds, before players are allowed to fight");
|
||||
|
||||
|
||||
private final Class<?> configType;
|
||||
private final String title;
|
||||
private final String description;
|
||||
|
||||
WarzoneConfig(Class<?> configType, String title, String description) {
|
||||
this.configType = configType;
|
||||
this.title = title;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public Class<?> getConfigType() {
|
||||
return configType;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public static WarzoneConfig warzoneConfigFromString(String str) {
|
||||
String lowered = str.toLowerCase();
|
||||
for (WarzoneConfig config : WarzoneConfig.values()) {
|
||||
if (config.toString().startsWith(lowered)) {
|
||||
return config;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String toStringWithValue(Object value) {
|
||||
return this.toString() + ":" + value.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString().toLowerCase();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,165 @@
|
|||
package com.tommytony.war.config;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
|
||||
public class WarzoneConfigBag {
|
||||
|
||||
private final Warzone warzone;
|
||||
EnumMap<WarzoneConfig, Object> bag = new EnumMap<WarzoneConfig, Object>(WarzoneConfig.class);
|
||||
|
||||
public WarzoneConfigBag(Warzone warzone) {
|
||||
this.warzone = warzone;
|
||||
}
|
||||
|
||||
public WarzoneConfigBag() {
|
||||
// default zone settings (at War level) don't have a warzone
|
||||
this.warzone = null;
|
||||
}
|
||||
|
||||
public static void afterUpdate(Warzone zone, CommandSender sender, String namedParamReturn, boolean wantsToPrint) {
|
||||
WarzoneYmlMapper.save(zone);
|
||||
|
||||
String zoneReset = "Some changes may require a /resetzone. ";
|
||||
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.RESETONCONFIGCHANGE)) {
|
||||
zone.reinitialize(); // bring back team spawns etc
|
||||
zoneReset = "Zone reset. ";
|
||||
}
|
||||
|
||||
if (wantsToPrint) {
|
||||
War.war.msg(sender, "Warzone config saved. " + zoneReset + namedParamReturn + " " + War.war.printConfig(zone));
|
||||
} else {
|
||||
War.war.msg(sender, "Warzone config saved. " + zoneReset + namedParamReturn);
|
||||
}
|
||||
|
||||
War.war.log(sender.getName() + " updated warzone " + zone.getName() + " configuration." + namedParamReturn, Level.INFO);
|
||||
|
||||
if (War.war.getWarHub() != null) { // maybe the zone was disabled/enabled
|
||||
War.war.getWarHub().getVolume().resetBlocks();
|
||||
War.war.getWarHub().initialize();
|
||||
}
|
||||
}
|
||||
|
||||
public void put(WarzoneConfig config, Object value) {
|
||||
bag.put(config, value);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return bag.keySet().size() == 0;
|
||||
}
|
||||
|
||||
public Object getValue(WarzoneConfig config) {
|
||||
if (bag.containsKey(config)) {
|
||||
return bag.get(config);
|
||||
} else {
|
||||
// use War default config
|
||||
return War.war.getWarzoneDefaultConfig().getValue(config);
|
||||
}
|
||||
}
|
||||
|
||||
public Integer getInt(WarzoneConfig config) {
|
||||
if (bag.containsKey(config)) {
|
||||
return (Integer) bag.get(config);
|
||||
} else {
|
||||
// use War default config
|
||||
return War.war.getWarzoneDefaultConfig().getInt(config);
|
||||
}
|
||||
}
|
||||
|
||||
public Boolean getBoolean(WarzoneConfig config) {
|
||||
if (bag.containsKey(config)) {
|
||||
return (Boolean) bag.get(config);
|
||||
} else {
|
||||
// use War default config
|
||||
return War.war.getWarzoneDefaultConfig().getBoolean(config);
|
||||
}
|
||||
}
|
||||
|
||||
public ScoreboardType getScoreboardType(WarzoneConfig config) {
|
||||
if (bag.containsKey(config)) {
|
||||
return (ScoreboardType)bag.get(config);
|
||||
} else {
|
||||
// use War default config
|
||||
return War.war.getWarzoneDefaultConfig().getScoreboardType(config);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean contains(WarzoneConfig config) {
|
||||
return this.bag.containsKey(config);
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
this.bag.clear();
|
||||
}
|
||||
|
||||
public void loadFrom(ConfigurationSection warzoneConfigSection) {
|
||||
for (WarzoneConfig config : WarzoneConfig.values()) {
|
||||
if (warzoneConfigSection.contains(config.toString())) {
|
||||
if (config.getConfigType().equals(Integer.class)) {
|
||||
this.put(config, warzoneConfigSection.getInt(config.toString()));
|
||||
} else if (config.getConfigType().equals(Boolean.class)) {
|
||||
this.put(config, warzoneConfigSection.getBoolean(config.toString()));
|
||||
} else if (config.getConfigType().equals(ScoreboardType.class)) {
|
||||
this.put(config, ScoreboardType.getFromString(warzoneConfigSection.getString(config.toString())));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void saveTo(ConfigurationSection warzoneConfigSection) {
|
||||
for (WarzoneConfig config : WarzoneConfig.values()) {
|
||||
if (this.bag.containsKey(config)) {
|
||||
if (config.getConfigType().equals(Integer.class)
|
||||
|| config.getConfigType().equals(Boolean.class)) {
|
||||
warzoneConfigSection.set(config.toString(), this.bag.get(config));
|
||||
} else {
|
||||
warzoneConfigSection.set(config.toString(), this.bag.get(config).toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String updateFromNamedParams(Map<String, String> namedParams) {
|
||||
String returnMessage = "";
|
||||
for (String namedParam : namedParams.keySet()) {
|
||||
WarzoneConfig warzoneConfig = WarzoneConfig.warzoneConfigFromString(namedParam);
|
||||
|
||||
// param update
|
||||
if (warzoneConfig != null) {
|
||||
if (warzoneConfig.getConfigType().equals(Integer.class)) {
|
||||
int intValue = Integer.parseInt(namedParams.get(namedParam));
|
||||
this.bag.put(warzoneConfig, intValue);
|
||||
} else if (warzoneConfig.getConfigType().equals(Boolean.class)) {
|
||||
String onOff = namedParams.get(namedParam);
|
||||
this.bag.put(warzoneConfig, onOff.equals("on") || onOff.equals("true"));
|
||||
if (this.warzone != null && namedParam.equals(WarzoneConfig.AUTOASSIGN.toString())) {
|
||||
this.warzone.getLobby().setLocation(this.warzone.getTeleport());
|
||||
this.warzone.getLobby().initialize();
|
||||
}
|
||||
} else if (warzoneConfig.getConfigType().equals(ScoreboardType.class)) {
|
||||
String type = namedParams.get(namedParam);
|
||||
this.bag.put(warzoneConfig, ScoreboardType.getFromString(type));
|
||||
}
|
||||
returnMessage += " " + warzoneConfig.toString() + " set to " + namedParams.get(namedParam);
|
||||
} else if (namedParam.equals("delete")) {
|
||||
String toDelete = namedParams.get(namedParam);
|
||||
warzoneConfig = WarzoneConfig.warzoneConfigFromString(toDelete);
|
||||
|
||||
// param delete (to restore inheritance)
|
||||
if (warzoneConfig != null) {
|
||||
this.bag.remove(warzoneConfig);
|
||||
returnMessage += " " + warzoneConfig.toString() + " removed";
|
||||
}
|
||||
}
|
||||
}
|
||||
return returnMessage;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package com.tommytony.war.event;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.Warzone;
|
||||
|
||||
public class WarBattleWinEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private List<Team> winningTeams;
|
||||
private Warzone zone;
|
||||
|
||||
public WarBattleWinEvent(Warzone zone, List<Team> winningTeams) {
|
||||
this.zone = zone;
|
||||
this.winningTeams = winningTeams;
|
||||
}
|
||||
|
||||
public Warzone getZone() {
|
||||
return zone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public List<Team> getWinningTeams() {
|
||||
return winningTeams;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,407 @@
|
|||
package com.tommytony.war.event;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.config.TeamConfig;
|
||||
import com.tommytony.war.config.WarConfig;
|
||||
import com.tommytony.war.config.WarzoneConfig;
|
||||
import com.tommytony.war.structure.Bomb;
|
||||
import com.tommytony.war.structure.Cake;
|
||||
import com.tommytony.war.structure.Monument;
|
||||
import com.tommytony.war.utility.Compat;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.*;
|
||||
import org.bukkit.event.world.StructureGrowEvent;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
public class WarBlockListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onBlockPlace(final BlockPlaceEvent event) {
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
Block block = event.getBlock();
|
||||
if (player == null || block == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
Warzone zone = Warzone.getZoneByLocation(player);
|
||||
// Monument capturing
|
||||
if (team != null && zone != null && zone.isMonumentCenterBlock(block) && team.getKind().isTeamBlock(block.getState())) {
|
||||
Monument monument = zone.getMonumentFromCenterBlock(block);
|
||||
if (monument != null && !monument.hasOwner()) {
|
||||
monument.capture(team);
|
||||
zone.broadcast("zone.monument.capture", monument.getName(), team.getName());
|
||||
event.setCancelled(false);
|
||||
return; // important otherwise cancelled down a few line by isImportantblock
|
||||
} else {
|
||||
War.war.badMsg(player, "zone.monument.badblock");
|
||||
cancelAndKeepItem(event);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
boolean isZoneMaker = War.war.isZoneMaker(player);
|
||||
// prevent build in important parts
|
||||
if (zone != null && (zone.isImportantBlock(block) || zone.isOpponentSpawnPeripheryBlock(team, block)) && (!isZoneMaker || team != null)) {
|
||||
War.war.badMsg(player, "build.denied.location");
|
||||
cancelAndKeepItem(event);
|
||||
return;
|
||||
}
|
||||
|
||||
// protect warzone lobbies
|
||||
for (Warzone wz : War.war.getWarzones()) {
|
||||
if (wz.getLobby() != null && wz.getLobby().getVolume() != null && wz.getLobby().getVolume().contains(block)) {
|
||||
War.war.badMsg(player, "build.denied.location");
|
||||
cancelAndKeepItem(event);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// protect the hub
|
||||
if (War.war.getWarHub() != null && War.war.getWarHub().getVolume().contains(block)) {
|
||||
War.war.badMsg(player, "build.denied.location");
|
||||
cancelAndKeepItem(event);
|
||||
return;
|
||||
}
|
||||
|
||||
// buildInZonesOnly
|
||||
if (zone == null && War.war.getWarConfig().getBoolean(WarConfig.BUILDINZONESONLY) && !War.war.canBuildOutsideZone(player)) {
|
||||
if (!War.war.getWarConfig().getBoolean(WarConfig.DISABLEBUILDMESSAGE)) {
|
||||
War.war.badMsg(player, "build.denied.outside");
|
||||
}
|
||||
cancelAndKeepItem(event);
|
||||
return;
|
||||
}
|
||||
|
||||
// can't place a block of your team's color
|
||||
if (team != null && block.getType() == team.getKind().getMaterial()) {
|
||||
War.war.badMsg(player, "build.denied.teamblock");
|
||||
cancelAndKeepItem(event);
|
||||
return;
|
||||
}
|
||||
|
||||
// a flag thief can't drop his flag
|
||||
if (team != null && zone != null && zone.isFlagThief(player)) {
|
||||
War.war.badMsg(player, "drop.flag.disabled");
|
||||
cancelAndKeepItem(event);
|
||||
return;
|
||||
}
|
||||
|
||||
// a bomb thief can't drop his bomb
|
||||
if (team != null && zone != null && zone.isBombThief(player)) {
|
||||
War.war.badMsg(player, "drop.bomb.disabled");
|
||||
cancelAndKeepItem(event);
|
||||
return;
|
||||
}
|
||||
|
||||
// a cake thief can't drop his cake
|
||||
if (team != null && zone != null && zone.isCakeThief(player)) {
|
||||
War.war.badMsg(player, "drop.cake.disabled");
|
||||
cancelAndKeepItem(event);
|
||||
return;
|
||||
}
|
||||
|
||||
// unbreakableZoneBlocks
|
||||
if (zone != null && (zone.getWarzoneConfig().getBoolean(WarzoneConfig.UNBREAKABLE) || team != null && !team.getTeamConfig().resolveBoolean(TeamConfig.PLACEBLOCK)) && (!isZoneMaker || team != null)) {
|
||||
// if the zone is unbreakable, no one but zone makers can break blocks (even then, zone makers in a team can't break blocks)
|
||||
War.war.badMsg(player, "build.denied.zone.place");
|
||||
cancelAndKeepItem(event);
|
||||
return;
|
||||
}
|
||||
|
||||
if (team != null && !team.canModify(block.getType())) {
|
||||
War.war.badMsg(player, "build.denied.zone.type");
|
||||
cancelAndKeepItem(event);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void cancelAndKeepItem(BlockPlaceEvent event) {
|
||||
event.setCancelled(true);
|
||||
ItemStack inHand = event.getItemInHand();
|
||||
ItemStack newItemInHand;
|
||||
|
||||
if (inHand.getType() == Material.FIRE) {
|
||||
// Weird bukkit/mc behavior where item in hand is reported as fire while using flint & steel.
|
||||
// Just give the user his f&s back but almost broken (max durability is 8).
|
||||
newItemInHand = Compat.createDamagedIS(Material.FLINT_AND_STEEL, 1, 1);
|
||||
} else {
|
||||
newItemInHand = inHand.clone();
|
||||
}
|
||||
if (event.getHand() == EquipmentSlot.OFF_HAND) {
|
||||
event.getPlayer().getInventory().setItemInOffHand(newItemInHand);
|
||||
} else {
|
||||
event.getPlayer().getInventory().setItemInMainHand(newItemInHand);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
// Do not allow moving of block into or from important zones
|
||||
public void onBlockPistonExtend(final BlockPistonExtendEvent event) {
|
||||
Warzone zone = Warzone.getZoneByLocation(event.getBlock().getLocation());
|
||||
if (zone != null) {
|
||||
for (Block b : event.getBlocks()) {
|
||||
if (zone.isImportantBlock(b)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
//noinspection deprecation
|
||||
if (zone.isImportantBlock(event.getBlock().getRelative(event.getDirection(), event.getLength()+1))) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockPistonRetract(final BlockPistonRetractEvent event) {
|
||||
Warzone zone = Warzone.getZoneByLocation(event.getBlock().getLocation());
|
||||
if (zone!=null) {
|
||||
Block b = event.getBlock().getRelative(event.getDirection(), 2);
|
||||
if (zone.isImportantBlock(b)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBreak(final BlockBreakEvent event) {
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
Block block = event.getBlock();
|
||||
if (player != null && block != null) {
|
||||
this.handleBreakOrDamage(player, block, event);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockDamage(final BlockDamageEvent event) {
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
Block block = event.getBlock();
|
||||
Warzone playerZone = Warzone.getZoneByLocation(player);
|
||||
if (player != null && block != null && playerZone != null && playerZone.getWarzoneConfig().getBoolean(WarzoneConfig.INSTABREAK)) {
|
||||
Warzone blockZone = Warzone.getZoneByLocation(new Location(block.getWorld(), block.getX(), block.getY(), block.getZ()));
|
||||
if (blockZone != null && blockZone == playerZone && block.getType() != Material.BEDROCK) {
|
||||
event.setInstaBreak(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBurn(final BlockBurnEvent event) {
|
||||
Warzone zone = Warzone.getZoneByLocation(event.getBlock().getLocation());
|
||||
if (zone != null && zone.isImportantBlock(event.getBlock())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleBreakOrDamage(Player player, Block block, Cancellable event) {
|
||||
Warzone warzone = Warzone.getZoneByLocation(player);
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
boolean isZoneMaker = War.war.isZoneMaker(player);
|
||||
|
||||
if (warzone != null && team == null && !isZoneMaker) {
|
||||
// can't actually destroy blocks in a warzone if not part of a team
|
||||
War.war.badMsg(player, "build.denied.zone.outside");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
// monument's center is destroyed
|
||||
if (team != null && block != null && warzone != null && warzone.isMonumentCenterBlock(block)) {
|
||||
Monument monument = warzone.getMonumentFromCenterBlock(block);
|
||||
if (monument.hasOwner()) {
|
||||
Team ownerTeam = monument.getOwnerTeam();
|
||||
warzone.broadcast("zone.monument.lose", ownerTeam.getName(), monument.getName());
|
||||
monument.uncapture();
|
||||
}
|
||||
event.setCancelled(false);
|
||||
return;
|
||||
}
|
||||
// changes in parts of important areas
|
||||
if (warzone != null && warzone.isImportantBlock(block) && (!isZoneMaker || team != null)) {
|
||||
// breakage of spawn
|
||||
if (team.isSpawnLocation(block.getLocation())) {
|
||||
// let team members loot one block the spawn for monument captures
|
||||
if (player.getInventory().containsAtLeast(team.getKind().getBlockHead(), 1)) {
|
||||
War.war.badMsg(player, "build.denied.zone.multteam", team.getName());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
} else {
|
||||
event.setCancelled(false); // very important, otherwise could get cancelled but unbreakableZoneBlocks further down
|
||||
return;
|
||||
}
|
||||
}
|
||||
// stealing of flag
|
||||
if (warzone.isEnemyTeamFlagBlock(team, block)) {
|
||||
if (warzone.isFlagThief(player)) {
|
||||
// detect audacious thieves
|
||||
War.war.badMsg(player, "zone.stealextra.flag");
|
||||
} else if (warzone.isBombThief(player) || warzone.isCakeThief(player)) {
|
||||
War.war.badMsg(player, "zone.stealextra.other");
|
||||
} else {
|
||||
Team lostFlagTeam = warzone.getTeamForFlagBlock(block);
|
||||
if (lostFlagTeam.getPlayers().size() != 0) {
|
||||
// player just broke the flag block of other team: cancel to avoid drop, give player the block, set block to air
|
||||
ItemStack teamKindBlock = lostFlagTeam.getKind().getBlockHead();
|
||||
player.getInventory().clear();
|
||||
player.getInventory().addItem(teamKindBlock);
|
||||
warzone.addFlagThief(lostFlagTeam, player);
|
||||
block.setType(Material.AIR);
|
||||
for (Team t : warzone.getTeams()) {
|
||||
t.teamcast("zone.steal.flag.broadcast", team.getKind().getColor() + player.getName() + ChatColor.WHITE, lostFlagTeam.getName());
|
||||
if (t.getName().equals(lostFlagTeam.getName())) {
|
||||
t.teamcast("zone.steal.flag.prevent", team.getKind().getColor() + player.getName() + ChatColor.WHITE, team.getName());
|
||||
}
|
||||
}
|
||||
War.war.msg(player, "zone.steal.flag.notice", lostFlagTeam.getName());
|
||||
} else {
|
||||
War.war.msg(player, "zone.steal.flag.empty", lostFlagTeam.getName());
|
||||
}
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
} else if (warzone.isBombBlock(block)) {
|
||||
if (warzone.isBombThief(player)) {
|
||||
// detect audacious thieves
|
||||
War.war.badMsg(player, "zone.stealextra.bomb");
|
||||
} else if (warzone.isFlagThief(player) || warzone.isCakeThief(player)) {
|
||||
War.war.badMsg(player, "zone.stealextra.other");
|
||||
} else {
|
||||
Bomb bomb = warzone.getBombForBlock(block);
|
||||
// player just broke the bomb block: cancel to avoid drop, give player the block, set block to air
|
||||
ItemStack tntBlock = new ItemStack(Material.TNT);
|
||||
tntBlock.setDurability((short)8);
|
||||
player.getInventory().clear();
|
||||
player.getInventory().addItem(tntBlock);
|
||||
warzone.addBombThief(bomb, player);
|
||||
block.setType(Material.AIR);
|
||||
for (Team t : warzone.getTeams()) {
|
||||
t.teamcast("zone.steal.bomb.broadcast", team.getKind().getColor() + player.getName() + ChatColor.WHITE, ChatColor.GREEN + bomb.getName() + ChatColor.WHITE);
|
||||
t.teamcast("zone.steal.bomb.prevent", team.getKind().getColor() + player.getName() + ChatColor.WHITE);
|
||||
}
|
||||
War.war.msg(player, "zone.steal.bomb.notice", bomb.getName());
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
} else if (warzone.isCakeBlock(block)) {
|
||||
if (warzone.isCakeThief(player)) {
|
||||
// detect audacious thieves
|
||||
War.war.badMsg(player, "zone.stealextra.cake");
|
||||
} else if (warzone.isFlagThief(player) || warzone.isBombThief(player)) {
|
||||
War.war.badMsg(player, "zone.stealextra.other");
|
||||
} else {
|
||||
Cake cake = warzone.getCakeForBlock(block);
|
||||
// player just broke the cake block: cancel to avoid drop, give player the block, set block to air
|
||||
ItemStack cakeBlock = new ItemStack(Material.CAKE);
|
||||
cakeBlock.setDurability((short)8);
|
||||
player.getInventory().clear();
|
||||
player.getInventory().addItem(cakeBlock);
|
||||
warzone.addCakeThief(cake, player);
|
||||
block.setType(Material.AIR);
|
||||
for (Team t : warzone.getTeams()) {
|
||||
t.teamcast("zone.steal.cake.broadcast", team.getKind().getColor() + player.getName() + ChatColor.WHITE, ChatColor.GREEN + cake.getName() + ChatColor.WHITE);
|
||||
t.teamcast("zone.steal.cake.prevent", team.getKind().getColor() + player.getName() + ChatColor.WHITE);
|
||||
}
|
||||
War.war.msg(player, "zone.steal.cake.notice", cake.getName());
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
} else if (!warzone.isMonumentCenterBlock(block)) {
|
||||
War.war.badMsg(player, "build.denied.location");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// protect warzone lobbies
|
||||
if (block != null) {
|
||||
for (Warzone zone : War.war.getWarzones()) {
|
||||
if (zone.getLobby() != null && zone.getLobby().getVolume() != null && zone.getLobby().getVolume().contains(block)) {
|
||||
War.war.badMsg(player, "build.denied.location");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// protect the hub
|
||||
if (War.war.getWarHub() != null && War.war.getWarHub().getVolume().contains(block)) {
|
||||
War.war.badMsg(player, "build.denied.location");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// buildInZonesOnly
|
||||
Warzone blockZone = Warzone.getZoneByLocation(new Location(block.getWorld(), block.getX(), block.getY(), block.getZ()));
|
||||
if (blockZone == null && War.war.getWarConfig().getBoolean(WarConfig.BUILDINZONESONLY) && !War.war.canBuildOutsideZone(player)) {
|
||||
if (!War.war.getWarConfig().getBoolean(WarConfig.DISABLEBUILDMESSAGE)) {
|
||||
War.war.badMsg(player, "build.denied.outside");
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// unbreakableZoneBlocks
|
||||
if (blockZone != null && blockZone.getWarzoneConfig().getBoolean(WarzoneConfig.UNBREAKABLE) && (!isZoneMaker || (isZoneMaker && team != null))) {
|
||||
// if the zone is unbreakable, no one but zone makers can break blocks (even then, zone makers in a team can't break blocks
|
||||
War.war.badMsg(player, "build.denied.zone.break");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (team != null && !team.canModify(block.getType())) {
|
||||
War.war.badMsg(player, "build.denied.zone.type");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onStructureGrowth(final StructureGrowEvent event) {
|
||||
Warzone zone = Warzone.getZoneByLocation(event.getLocation());
|
||||
if (zone != null) {
|
||||
List<BlockState> canceledBlocks = new ArrayList<BlockState>();
|
||||
for (BlockState state : event.getBlocks()) {
|
||||
if (!zone.getVolume().contains(state.getLocation())
|
||||
|| zone.isImportantBlock(state.getBlock())) {
|
||||
canceledBlocks.add(state);
|
||||
}
|
||||
}
|
||||
for (BlockState state : canceledBlocks) {
|
||||
event.getBlocks().remove(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,551 @@
|
|||
package com.tommytony.war.event;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.*;
|
||||
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
|
||||
import org.bukkit.event.hanging.HangingPlaceEvent;
|
||||
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.projectiles.ProjectileSource;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.config.TeamConfig;
|
||||
import com.tommytony.war.config.WarConfig;
|
||||
import com.tommytony.war.config.WarzoneConfig;
|
||||
import com.tommytony.war.job.DeferredBlockResetsJob;
|
||||
import com.tommytony.war.structure.Bomb;
|
||||
import com.tommytony.war.utility.LoadoutSelection;
|
||||
|
||||
/**
|
||||
* Handles Entity-Events
|
||||
*
|
||||
* @author tommytony, Tim Düsterhus
|
||||
* @package com.tommytony.war.event
|
||||
*/
|
||||
public class WarEntityListener implements Listener {
|
||||
|
||||
/**
|
||||
* Handles PVP-Damage
|
||||
*
|
||||
* @param event
|
||||
* fired event
|
||||
*/
|
||||
private void handlerAttackDefend(EntityDamageByEntityEvent event) {
|
||||
Entity attacker = event.getDamager();
|
||||
Entity defender = event.getEntity();
|
||||
|
||||
// Maybe an arrow was thrown
|
||||
if (attacker != null && event.getDamager() instanceof Projectile && ((Projectile)event.getDamager()).getShooter() instanceof Player){
|
||||
attacker = ((Player)((Projectile)event.getDamager()).getShooter());
|
||||
}
|
||||
|
||||
if (attacker != null && defender != null && attacker instanceof Player && defender instanceof Player) {
|
||||
// only let adversaries (same warzone, different team) attack each other
|
||||
Player a = (Player) attacker;
|
||||
Player d = (Player) defender;
|
||||
Warzone attackerWarzone = Warzone.getZoneByPlayerName(a.getName());
|
||||
Team attackerTeam = Team.getTeamByPlayerName(a.getName());
|
||||
Warzone defenderWarzone = Warzone.getZoneByPlayerName(d.getName());
|
||||
Team defenderTeam = Team.getTeamByPlayerName(d.getName());
|
||||
|
||||
if ((attackerTeam != null && defenderTeam != null && attackerTeam != defenderTeam && attackerWarzone == defenderWarzone)
|
||||
|| (attackerTeam != null && defenderTeam != null && attacker.getEntityId() == defender.getEntityId())) {
|
||||
|
||||
LoadoutSelection defenderLoadoutState = defenderWarzone.getLoadoutSelections().get(d.getName());
|
||||
if (defenderLoadoutState != null && defenderLoadoutState.isStillInSpawn()) {
|
||||
War.war.badMsg(a, "pvp.target.spawn");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
LoadoutSelection attackerLoadoutState = attackerWarzone.getLoadoutSelections().get(a.getName());
|
||||
if (attackerLoadoutState != null && attackerLoadoutState.isStillInSpawn()) {
|
||||
War.war.badMsg(a, "pvp.self.spawn");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure none of them are locked in by respawn timer
|
||||
if (defenderWarzone.isRespawning(d)) {
|
||||
War.war.badMsg(a, "pvp.target.respawn");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
} else if (attackerWarzone.isRespawning(a)) {
|
||||
War.war.badMsg(a, "pvp.self.respawn");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!defenderWarzone.getPvpReady()) {
|
||||
//if the timer is still tickin we gotta handle defense! (there be notchz in virgina)
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!attackerWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.PVPINZONE)) {
|
||||
// spleef-like, non-pvp, zone
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Detect death, prevent it and respawn the player
|
||||
if (event.getDamage() >= d.getHealth()) {
|
||||
if (defenderWarzone.getReallyDeadFighters().contains(d.getName())) {
|
||||
// don't re-kill a dead person
|
||||
return;
|
||||
}
|
||||
WarPlayerDeathEvent event1 = new WarPlayerDeathEvent(defenderWarzone, d, a, event.getCause());
|
||||
War.war.getServer().getPluginManager().callEvent(event1);
|
||||
if (!defenderWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.REALDEATHS)) {
|
||||
// fast respawn, don't really die
|
||||
event.setCancelled(true);
|
||||
}
|
||||
if (d == a) {
|
||||
defenderWarzone.handleSuicide(d);
|
||||
} else {
|
||||
defenderWarzone.handleKill(a, d, event.getDamager());
|
||||
}
|
||||
} else if (defenderWarzone.isBombThief(d) && d.getLocation().distance(a.getLocation()) < 2) {
|
||||
// Close combat, close enough to detonate
|
||||
Bomb bomb = defenderWarzone.getBombForThief(d);
|
||||
|
||||
// Kill the bomber
|
||||
WarPlayerDeathEvent event1 = new WarPlayerDeathEvent(defenderWarzone, d, null, event.getCause());
|
||||
War.war.getServer().getPluginManager().callEvent(event1);
|
||||
defenderWarzone.handleDeath(d);
|
||||
|
||||
if (defenderWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.REALDEATHS)) {
|
||||
// and respawn him and remove from deadmen (cause realdeath + handleDeath means no respawn and getting queued up for onPlayerRespawn)
|
||||
defenderWarzone.getReallyDeadFighters().remove(d.getName());
|
||||
defenderWarzone.respawnPlayer(defenderTeam, d);
|
||||
}
|
||||
|
||||
// Blow up bomb
|
||||
if (!defenderWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.UNBREAKABLE)) {
|
||||
defenderWarzone.getWorld().createExplosion(a.getLocation(), 2F);
|
||||
}
|
||||
|
||||
// bring back tnt
|
||||
bomb.getVolume().resetBlocks();
|
||||
bomb.addBombBlocks();
|
||||
|
||||
// Notify everyone
|
||||
for (Team t : defenderWarzone.getTeams()) {
|
||||
t.sendAchievement(attackerTeam.getKind().getColor() + a.getName() + ChatColor.YELLOW + " made ",
|
||||
defenderTeam.getKind().getColor() + d.getName() + ChatColor.YELLOW + " blow up!", new ItemStack(Material.TNT), 10000);
|
||||
t.teamcast("pvp.kill.bomb", attackerTeam.getKind().getColor() + a.getName() + ChatColor.WHITE,
|
||||
defenderTeam.getKind().getColor() + d.getName() + ChatColor.WHITE);
|
||||
}
|
||||
}
|
||||
} else if (attackerTeam != null && defenderTeam != null && attackerTeam == defenderTeam && attackerWarzone == defenderWarzone && attacker.getEntityId() != defender.getEntityId()) {
|
||||
// same team, but not same person
|
||||
if (attackerWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.FRIENDLYFIRE)) {
|
||||
War.war.badMsg(a, "pvp.ff.enabled"); // if ff is on, let the attack go through
|
||||
} else {
|
||||
War.war.badMsg(a, "pvp.ff.disabled");
|
||||
event.setCancelled(true); // ff is off
|
||||
}
|
||||
} else if (attackerTeam == null && defenderTeam == null && War.war.canPvpOutsideZones(a)) {
|
||||
// let normal PVP through is its not turned off or if you have perms
|
||||
} else if (attackerTeam == null && defenderTeam == null && !War.war.canPvpOutsideZones(a)) {
|
||||
if (!War.war.getWarConfig().getBoolean(WarConfig.DISABLEPVPMESSAGE)) {
|
||||
War.war.badMsg(a, "pvp.outside.permission");
|
||||
}
|
||||
|
||||
event.setCancelled(true); // global pvp is off
|
||||
} else {
|
||||
if (attackerTeam == null) {
|
||||
War.war.badMsg(a, "pvp.self.notplaying");
|
||||
} else if (defenderTeam == null) {
|
||||
War.war.badMsg(a, "pvp.target.notplaying");
|
||||
} else if (attacker != null && defender != null && attacker.getEntityId() == defender.getEntityId()) {
|
||||
// You just hit yourself, probably with a bouncing arrow
|
||||
} else if (attackerTeam == defenderTeam) {
|
||||
War.war.badMsg(a, "pvp.ff.disabled");
|
||||
} else if (attackerWarzone != defenderWarzone) {
|
||||
War.war.badMsg(a, "pvp.target.otherzone");
|
||||
}
|
||||
|
||||
event.setCancelled(true); // can't attack someone inside a warzone if you're not in a team
|
||||
}
|
||||
} else if (defender instanceof Player) {
|
||||
// attacked by dispenser arrow most probably
|
||||
// Detect death, prevent it and respawn the player
|
||||
Player d = (Player) defender;
|
||||
Warzone defenderWarzone = Warzone.getZoneByPlayerName(d.getName());
|
||||
if (d != null && defenderWarzone != null && event.getDamage() >= d.getHealth()) {
|
||||
LoadoutSelection defenderLoadoutState = defenderWarzone.getLoadoutSelections().get(d.getName());
|
||||
if (defenderLoadoutState != null && defenderLoadoutState.isStillInSpawn()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (defenderWarzone.getReallyDeadFighters().contains(d.getName())) {
|
||||
// don't re-kill a dead person
|
||||
return;
|
||||
}
|
||||
|
||||
WarPlayerDeathEvent event1 = new WarPlayerDeathEvent(defenderWarzone, d, null, event.getCause());
|
||||
War.war.getServer().getPluginManager().callEvent(event1);
|
||||
if (!defenderWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.REALDEATHS)) {
|
||||
// fast respawn, don't really die
|
||||
event.setCancelled(true);
|
||||
}
|
||||
defenderWarzone.handleNaturalKill(d, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Protects important structures from explosions
|
||||
*
|
||||
* @see EntityListener.onEntityExplode()
|
||||
*/
|
||||
@EventHandler
|
||||
public void onEntityExplode(final EntityExplodeEvent event) {
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
// protect zones elements, lobbies and warhub from creepers and tnt
|
||||
List<Block> explodedBlocks = event.blockList();
|
||||
List<Block> dontExplode = new ArrayList<Block>();
|
||||
|
||||
boolean explosionInAWarzone = event.getEntity() != null && Warzone.getZoneByLocation(event.getEntity().getLocation()) != null;
|
||||
|
||||
if (!explosionInAWarzone && War.war.getWarConfig().getBoolean(WarConfig.TNTINZONESONLY) && event.getEntity() instanceof TNTPrimed) {
|
||||
// if tntinzonesonly:true, no tnt blows up outside zones
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
for (Block block : explodedBlocks) {
|
||||
if (block.getType() == Material.TNT) {
|
||||
continue; // don't restore TNT (failed to track down regression cause)
|
||||
}
|
||||
if (War.war.getWarHub() != null && War.war.getWarHub().getVolume().contains(block)) {
|
||||
dontExplode.add(block);
|
||||
} else {
|
||||
boolean inOneZone = false;
|
||||
for (Warzone zone : War.war.getWarzones()) {
|
||||
if (zone.isImportantBlock(block)) {
|
||||
dontExplode.add(block);
|
||||
if (zone.isBombBlock(block)) {
|
||||
// tnt doesn't get reset like normal blocks, gotta schedule a later reset just for the Bomb
|
||||
// structure's tnt block
|
||||
DeferredBlockResetsJob job = new DeferredBlockResetsJob();
|
||||
BlockState tnt = block.getState();
|
||||
tnt.setType(Material.TNT);
|
||||
job.add(tnt);
|
||||
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job, 10);
|
||||
}
|
||||
inOneZone = true;
|
||||
break;
|
||||
} else if (zone.getLobby() != null && zone.getLobby().getVolume().contains(block)) {
|
||||
dontExplode.add(block);
|
||||
inOneZone = true;
|
||||
break;
|
||||
} else if (zone.getVolume().contains(block)) {
|
||||
inOneZone = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!inOneZone && explosionInAWarzone) {
|
||||
// if the explosion originated in warzone, always rollback
|
||||
dontExplode.add(block);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int dontExplodeSize = dontExplode.size();
|
||||
if (dontExplode.size() > 0) {
|
||||
// Reset the exploded blocks that shouldn't have exploded (some of these are zone artifacts, if rollbackexplosion some may be outside-of-zone blocks
|
||||
DeferredBlockResetsJob job = new DeferredBlockResetsJob();
|
||||
for (Block dont : dontExplode) {
|
||||
job.add(dont.getState());
|
||||
}
|
||||
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job);
|
||||
|
||||
// Changed explosion yield following proportion of explosion prevention (makes drops less buggy too)
|
||||
int explodedSize = explodedBlocks.size();
|
||||
float middleYeild = (float)(explodedSize - dontExplodeSize) / (float)explodedSize;
|
||||
float newYeild = middleYeild * event.getYield();
|
||||
|
||||
event.setYield(newYeild);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles damage on Players
|
||||
*
|
||||
* @see EntityListener.onEntityDamage()
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onEntityDamage(final EntityDamageEvent event) {
|
||||
|
||||
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = event.getEntity();
|
||||
if (!(entity instanceof Player)) {
|
||||
|
||||
return;
|
||||
}
|
||||
Player player = (Player) entity;
|
||||
|
||||
// prevent godmode
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
if (zone != null) {
|
||||
event.setCancelled(false);
|
||||
}
|
||||
|
||||
// pass pvp-damage
|
||||
if (event instanceof EntityDamageByEntityEvent) {
|
||||
this.handlerAttackDefend((EntityDamageByEntityEvent) event);
|
||||
} else {
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
|
||||
if (zone != null && team != null) {
|
||||
LoadoutSelection playerLoadoutState = zone.getLoadoutSelections().get(player.getName());
|
||||
if (team.isSpawnLocation(player.getLocation())
|
||||
&& playerLoadoutState != null && playerLoadoutState.isStillInSpawn()) {
|
||||
// don't let a player still in spawn get damaged
|
||||
event.setCancelled(true);
|
||||
} else if (event.getDamage() >= player.getHealth()) {
|
||||
if (zone.getReallyDeadFighters().contains(player.getName())) {
|
||||
// don't re-count the death points of an already dead person
|
||||
return;
|
||||
}
|
||||
|
||||
// Detect death, prevent it and respawn the player
|
||||
WarPlayerDeathEvent event1 = new WarPlayerDeathEvent(zone, player, null, event.getCause());
|
||||
War.war.getServer().getPluginManager().callEvent(event1);
|
||||
if (!zone.getWarzoneConfig().getBoolean(WarzoneConfig.REALDEATHS)) {
|
||||
// fast respawn, don't really die
|
||||
event.setCancelled(true);
|
||||
}
|
||||
zone.handleNaturalKill(player, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents creatures from spawning in warzones if no creatures is active
|
||||
*
|
||||
* @see EntityListener.onCreatureSpawn()
|
||||
*/
|
||||
@EventHandler
|
||||
public void onCreatureSpawn(final CreatureSpawnEvent event) {
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Location location = event.getLocation();
|
||||
Warzone zone = Warzone.getZoneByLocation(location);
|
||||
if (zone != null && zone.getWarzoneConfig().getBoolean(WarzoneConfig.NOCREATURES)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents health regaining caused by peaceful mode
|
||||
*
|
||||
* @see EntityListener.onEntityRegainHealth()
|
||||
*/
|
||||
@EventHandler
|
||||
public void onEntityRegainHealth(final EntityRegainHealthEvent event) {
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = event.getEntity();
|
||||
if (!(entity instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) entity;
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
if (zone != null) {
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
if (event.getRegainReason() == RegainReason.SATIATED
|
||||
&& team.getTeamConfig().resolveBoolean(TeamConfig.NOHUNGER)) {
|
||||
// noHunger setting means you can't auto-heal with full hunger bar (use saturation instead to control how fast you get hungry)
|
||||
event.setCancelled(true);
|
||||
} else if (event.getRegainReason() == RegainReason.REGEN) {
|
||||
// disable peaceful mode regen
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onFoodLevelChange(final FoodLevelChangeEvent event) {
|
||||
if (!War.war.isLoaded() || !(event.getEntity() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) event.getEntity();
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
if (zone != null && team.getTeamConfig().resolveBoolean(TeamConfig.NOHUNGER)){
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerDeath(final PlayerDeathEvent event) {
|
||||
Player player = event.getEntity();
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
if (zone != null) {
|
||||
event.getDrops().clear();
|
||||
if (!zone.getWarzoneConfig().getBoolean(WarzoneConfig.REALDEATHS)) {
|
||||
// catch the odd death that gets away from us when usually intercepting and preventing deaths
|
||||
zone.handleDeath(player);
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.DEATHMESSAGES)) {
|
||||
zone.broadcast("pvp.death.other", team.getKind().getColor() + player.getName());
|
||||
}
|
||||
War.war.getLogger().log(Level.WARNING, "We missed the death of player {0} - something went wrong.", player.getName());
|
||||
} else {
|
||||
event.setDeathMessage("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onExplosionPrime(final ExplosionPrimeEvent event) {
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Location eventLocation = event.getEntity().getLocation();
|
||||
|
||||
for (Warzone zone : War.war.getWarzones()) {
|
||||
if (zone.isBombBlock(eventLocation.getBlock())) {
|
||||
// prevent the Bomb from exploding on its pedestral
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onProjectileHit(final ProjectileHitEvent event) {
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
if (event.getEntityType() == EntityType.EGG) {
|
||||
if (event.getEntity().hasMetadata("warAirstrike")) {
|
||||
Location loc = event.getEntity().getLocation();
|
||||
Warzone zone = Warzone.getZoneByLocation(loc);
|
||||
if (zone == null) {
|
||||
return;
|
||||
}
|
||||
Location tntPlace = new Location(loc.getWorld(), loc.getX(), Warzone.getZoneByLocation(loc).getVolume().getMaxY(), loc.getZ());
|
||||
loc.getWorld().spawnEntity(tntPlace, EntityType.PRIMED_TNT);
|
||||
loc.getWorld().spawnEntity(tntPlace.clone().add(new Vector(2, 0, 0)), EntityType.PRIMED_TNT);
|
||||
loc.getWorld().spawnEntity(tntPlace.clone().add(new Vector(-2, 0, 0)), EntityType.PRIMED_TNT);
|
||||
loc.getWorld().spawnEntity(tntPlace.clone().add(new Vector(0, 0, 2)), EntityType.PRIMED_TNT);
|
||||
loc.getWorld().spawnEntity(tntPlace.clone().add(new Vector(0, 0, -2)), EntityType.PRIMED_TNT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onProjectileLaunch(final ProjectileLaunchEvent event) {
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
if (event.getEntityType() == EntityType.EGG) {
|
||||
ProjectileSource shooter = event.getEntity().getShooter();
|
||||
if (shooter instanceof Player) {
|
||||
Player player = (Player) shooter;
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
if (zone != null) {
|
||||
if (War.war.getKillstreakReward().getAirstrikePlayers().remove(player.getName())) {
|
||||
event.getEntity().setMetadata("warAirstrike", new FixedMetadataValue(War.war, true));
|
||||
zone.broadcast("zone.airstrike", team.getKind().getColor() + player.getName() + ChatColor.WHITE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPaintingBreakByEntity(final HangingBreakByEntityEvent event) {
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
if (!(event.getRemover() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
Player player = (Player) event.getRemover();
|
||||
Warzone zone = Warzone.getZoneByLocation(event.getEntity().getLocation());
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
boolean isZoneMaker = War.war.isZoneMaker(player);
|
||||
if (team == null && isZoneMaker) {
|
||||
return;
|
||||
}
|
||||
if (zone != null && zone.getWarzoneConfig().getBoolean(WarzoneConfig.UNBREAKABLE)) {
|
||||
event.setCancelled(true);
|
||||
War.war.badMsg(player, "build.denied.zone.break");
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPaintingPlaceByEntity(final HangingPlaceEvent event) {
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
Warzone zone = Warzone.getZoneByLocation(event.getBlock().getLocation());
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
boolean isZoneMaker = War.war.isZoneMaker(player);
|
||||
if (team == null && isZoneMaker) {
|
||||
return;
|
||||
}
|
||||
if (zone != null && (zone.getWarzoneConfig().getBoolean(WarzoneConfig.UNBREAKABLE)
|
||||
|| (team != null && !team.getTeamConfig().resolveBoolean(TeamConfig.PLACEBLOCK)))) {
|
||||
event.setCancelled(true);
|
||||
War.war.badMsg(player, "build.denied.zone.place");
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityTeleport(final EntityTeleportEvent event) {
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
if (event.getEntityType() == EntityType.WOLF) {
|
||||
if (Warzone.getZoneByLocation(event.getTo()) != null) {
|
||||
// prevent wolves from teleporting to players in zones
|
||||
event.setCancelled(true);
|
||||
event.setTo(event.getFrom());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package com.tommytony.war.event;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
|
||||
import com.tommytony.war.Warzone;
|
||||
|
||||
public class WarPlayerDeathEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private Player victim;
|
||||
private Warzone zone;
|
||||
private Entity killer;
|
||||
private DamageCause cause;
|
||||
|
||||
public WarPlayerDeathEvent(Warzone zone, Player victim, Entity killer,
|
||||
DamageCause cause) {
|
||||
this.zone = zone;
|
||||
this.victim = victim;
|
||||
this.killer = killer;
|
||||
this.cause = cause;
|
||||
}
|
||||
|
||||
public Warzone getZone() {
|
||||
return zone;
|
||||
}
|
||||
|
||||
public Entity getKiller() {
|
||||
return killer;
|
||||
}
|
||||
|
||||
public DamageCause getCause() {
|
||||
return cause;
|
||||
}
|
||||
|
||||
public Player getVictim() {
|
||||
return victim;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.tommytony.war.event;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class WarPlayerLeaveEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private String player;
|
||||
|
||||
public WarPlayerLeaveEvent(String player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public String getQuitter() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,949 @@
|
|||
package com.tommytony.war.event;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.Warzone.LeaveCause;
|
||||
import com.tommytony.war.command.ZoneSetter;
|
||||
import com.tommytony.war.config.FlagReturn;
|
||||
import com.tommytony.war.config.TeamConfig;
|
||||
import com.tommytony.war.config.WarConfig;
|
||||
import com.tommytony.war.config.WarzoneConfig;
|
||||
import com.tommytony.war.structure.Bomb;
|
||||
import com.tommytony.war.structure.Cake;
|
||||
import com.tommytony.war.structure.WarHub;
|
||||
import com.tommytony.war.structure.ZoneLobby;
|
||||
import com.tommytony.war.utility.Direction;
|
||||
import com.tommytony.war.utility.Loadout;
|
||||
import com.tommytony.war.utility.LoadoutSelection;
|
||||
import com.tommytony.war.volume.Volume;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event.Result;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.entity.EntityPickupItemEvent;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* @author tommytony, Tim Düsterhus
|
||||
*/
|
||||
public class WarPlayerListener implements Listener {
|
||||
private java.util.Random random = new java.util.Random();
|
||||
private HashMap<String, Location> latestLocations = new HashMap<String, Location>();
|
||||
|
||||
/**
|
||||
* Correctly removes quitting players from warzones
|
||||
*
|
||||
* @see PlayerQuitEvent
|
||||
*/
|
||||
@EventHandler
|
||||
public void onPlayerQuit(final PlayerQuitEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
Player player = event.getPlayer();
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
if (zone != null) {
|
||||
zone.handlePlayerLeave(player, zone.getEndTeleport(LeaveCause.DISCONNECT), true);
|
||||
}
|
||||
|
||||
if (War.war.isWandBearer(player)) {
|
||||
War.war.removeWandBearer(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onPlayerJoin(final PlayerJoinEvent event) {
|
||||
String autojoinName = War.war.getWarConfig().getString(WarConfig.AUTOJOIN);
|
||||
boolean autojoinEnabled = !autojoinName.isEmpty();
|
||||
if (autojoinEnabled) { // Won't be able to find warzone if unset
|
||||
Warzone autojoinWarzone = Warzone.getZoneByNameExact(autojoinName);
|
||||
if (autojoinWarzone == null) {
|
||||
War.war.getLogger().log(Level.WARNING, "Failed to find autojoin warzone ''{0}''.", new Object[] {autojoinName});
|
||||
return;
|
||||
}
|
||||
if (autojoinWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.DISABLED) || autojoinWarzone.isReinitializing()) {
|
||||
War.war.badMsg(event.getPlayer(), "join.disabled");
|
||||
event.getPlayer().teleport(autojoinWarzone.getTeleport());
|
||||
} else if (!autojoinWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.JOINMIDBATTLE) && autojoinWarzone.isEnoughPlayers()) {
|
||||
War.war.badMsg(event.getPlayer(), "join.progress");
|
||||
event.getPlayer().teleport(autojoinWarzone.getTeleport());
|
||||
} else if (autojoinWarzone.isFull()) {
|
||||
War.war.badMsg(event.getPlayer(), "join.full.all");
|
||||
event.getPlayer().teleport(autojoinWarzone.getTeleport());
|
||||
} else if (autojoinWarzone.isFull(event.getPlayer())) {
|
||||
War.war.badMsg(event.getPlayer(), "join.permission.all");
|
||||
event.getPlayer().teleport(autojoinWarzone.getTeleport());
|
||||
} else { // Player will only ever be autoassigned to a team
|
||||
autojoinWarzone.autoAssign(event.getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDropItem(final PlayerDropItemEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
Player player = event.getPlayer();
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
if (team != null) {
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
|
||||
if (zone.isFlagThief(player)) {
|
||||
// a flag thief can't drop his flag
|
||||
War.war.badMsg(player, "drop.flag.disabled");
|
||||
event.setCancelled(true);
|
||||
} else if (zone.isBombThief(player)) {
|
||||
// a bomb thief can't drop his bomb
|
||||
War.war.badMsg(player, "drop.bomb.disabled");
|
||||
event.setCancelled(true);
|
||||
} else if (zone.isCakeThief(player)) {
|
||||
// a cake thief can't drop his cake
|
||||
War.war.badMsg(player, "drop.cake.disabled");
|
||||
event.setCancelled(true);
|
||||
} else if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.NODROPS)) {
|
||||
War.war.badMsg(player, "drop.item.disabled");
|
||||
event.setCancelled(true);
|
||||
} else {
|
||||
Item item = event.getItemDrop();
|
||||
if (item != null) {
|
||||
ItemStack itemStack = item.getItemStack();
|
||||
if (itemStack != null && team.getKind().isTeamItem(itemStack)) {
|
||||
// Can't drop your team's kind block
|
||||
War.war.badMsg(player, "drop.team", team.getName());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (zone.isNearWall(player.getLocation()) && itemStack != null
|
||||
&& !team.getTeamConfig().resolveBoolean(TeamConfig.BORDERDROP)) {
|
||||
War.war.badMsg(player, "drop.item.border");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (zone.getLoadoutSelections().keySet().contains(player.getName())
|
||||
&& zone.getLoadoutSelections().get(player.getName()).isStillInSpawn()) {
|
||||
// still at spawn
|
||||
War.war.badMsg(player, "drop.item.spawn");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (War.war.isWandBearer(player)) {
|
||||
Item item = event.getItemDrop();
|
||||
if (item.getItemStack().getType() == Material.WOODEN_SWORD) {
|
||||
String zoneName = War.war.getWandBearerZone(player);
|
||||
War.war.removeWandBearer(player);
|
||||
War.war.msg(player, "drop.wand", zoneName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final int MINIMUM_TEAM_BLOCKS = 1;
|
||||
@EventHandler
|
||||
public void onPlayerPickupItem(final EntityPickupItemEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
if (!(event.getEntity() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
Player player = (Player) event.getEntity();
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
if (team != null) {
|
||||
Warzone zone = team.getZone();
|
||||
|
||||
if (zone.isFlagThief(player)) {
|
||||
// a flag thief can't pick up anything
|
||||
event.setCancelled(true);
|
||||
} else {
|
||||
Item item = event.getItem();
|
||||
if (item != null) {
|
||||
ItemStack itemStack = item.getItemStack();
|
||||
if (itemStack != null && team.getKind().isTeamItem(itemStack) &&
|
||||
player.getInventory().containsAtLeast(team.getKind().getBlockHead(), MINIMUM_TEAM_BLOCKS)) {
|
||||
// Can't pick up a second precious block
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
Player player = event.getPlayer();
|
||||
Team talkingPlayerTeam = Team.getTeamByPlayerName(player.getName());
|
||||
if (talkingPlayerTeam != null) {
|
||||
String msg = event.getMessage();
|
||||
String[] split = msg.split(" ");
|
||||
if (!War.war.isWarAdmin(player) && split.length > 0 && split[0].startsWith("/")) {
|
||||
String command = split[0].substring(1);
|
||||
if (!command.equals("war") && !command.equals("zones") && !command.equals("warzones") && !command.equals("zone") && !command.equals("warzone") && !command.equals("teams") && !command.equals("join") && !command.equals("leave") && !command.equals("team") && !command.equals("warhub") && !command.equals("zonemaker")) {
|
||||
// allow white commands
|
||||
for (String whiteCommand : War.war.getCommandWhitelist()) {
|
||||
if (whiteCommand.equals(command)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
War.war.badMsg(player, "command.disabled");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerKick(final PlayerKickEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
Player player = event.getPlayer();
|
||||
Warzone warzone = Warzone.getZoneByLocation(player);
|
||||
|
||||
if (warzone != null) {
|
||||
// kick player from warzone as well
|
||||
warzone.handlePlayerLeave(player, warzone.getEndTeleport(LeaveCause.DISCONNECT), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
Player player = event.getPlayer();
|
||||
if (event.getItem() != null && event.getItem().getType() == Material.WOODEN_SWORD && War.war.isWandBearer(player)) {
|
||||
String zoneName = War.war.getWandBearerZone(player);
|
||||
ZoneSetter setter = new ZoneSetter(player, zoneName);
|
||||
if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_AIR) {
|
||||
War.war.badMsg(player, "wand.toofar");
|
||||
} else if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
|
||||
setter.placeCorner1(event.getClickedBlock());
|
||||
event.setUseItemInHand(Result.ALLOW);
|
||||
} else if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
setter.placeCorner2(event.getClickedBlock());
|
||||
event.setUseItemInHand(Result.ALLOW);
|
||||
}
|
||||
}
|
||||
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
if (zone != null && zone.getLoadoutSelections().containsKey(player.getName())
|
||||
&& zone.getLoadoutSelections().get(player.getName()).isStillInSpawn()) {
|
||||
event.setUseItemInHand(Result.DENY);
|
||||
event.setCancelled(true);
|
||||
// Replace message with sound to reduce spamminess.
|
||||
// Whenever a player dies in the middle of conflict they will
|
||||
// likely respawn still trying to use their items to attack
|
||||
// another player.
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 1, 0);
|
||||
}
|
||||
|
||||
if (zone != null && event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == Material.ENDER_CHEST && !zone.getWarzoneConfig().getBoolean(WarzoneConfig.ALLOWENDER)) {
|
||||
event.setCancelled(true);
|
||||
War.war.badMsg(player, "use.ender");
|
||||
}
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
if (zone != null && team != null && event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == Material.ENCHANTING_TABLE && team.getTeamConfig().resolveBoolean(TeamConfig.XPKILLMETER)) {
|
||||
event.setCancelled(true);
|
||||
War.war.badMsg(player, "use.enchant");
|
||||
if (zone.getAuthors().contains(player.getName())) {
|
||||
War.war.badMsg(player, "use.xpkillmeter");
|
||||
}
|
||||
}
|
||||
if (zone != null && team != null && event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == Material.ANVIL && team.getTeamConfig().resolveBoolean(TeamConfig.XPKILLMETER)) {
|
||||
event.setCancelled(true);
|
||||
War.war.badMsg(player, "use.anvil");
|
||||
if (zone.getAuthors().contains(player.getName())) {
|
||||
War.war.badMsg(player, "use.xpkillmeter");
|
||||
}
|
||||
}
|
||||
if (zone != null && team != null && event.getAction() == Action.RIGHT_CLICK_BLOCK
|
||||
&& event.getClickedBlock().getState() instanceof InventoryHolder
|
||||
&& zone.isFlagThief(player)) {
|
||||
event.setCancelled(true);
|
||||
War.war.badMsg(player, "drop.flag.disabled");
|
||||
}
|
||||
if (zone == null && event.getAction() == Action.RIGHT_CLICK_BLOCK
|
||||
&& (event.getClickedBlock().getType() == Material.CHEST || event.getClickedBlock().getType() == Material.TRAPPED_CHEST)
|
||||
&& Warzone.getZoneByLocation(event.getClickedBlock().getLocation()) != null
|
||||
&& !War.war.isZoneMaker(event.getPlayer())) {
|
||||
// prevent opening chests inside a warzone if a player is not a zone maker
|
||||
event.setCancelled(true);
|
||||
player.playSound(player.getLocation(), Sound.BLOCK_CHEST_LOCKED, 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK
|
||||
|| event.getAction() == Action.RIGHT_CLICK_AIR) {
|
||||
Player player = event.getPlayer();
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
if (zone != null && zone.getWarzoneConfig().getBoolean(WarzoneConfig.SOUPHEALING)) {
|
||||
ItemStack item = event.getItem();
|
||||
if ((item != null) && (item.getType() == Material.MUSHROOM_STEW)) {
|
||||
if (player.getHealth() < 20) {
|
||||
player.setHealth(Math.min(20, player.getHealth() + 7));
|
||||
item.setType(Material.BOWL);
|
||||
} else if (player.getFoodLevel() < 20) {
|
||||
player.setFoodLevel(Math.min(20, player.getFoodLevel() + 6));
|
||||
player.setSaturation(player.getSaturation() + 7.2f);
|
||||
item.setType(Material.BOWL);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMove(final PlayerMoveEvent event) {
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
Location playerLoc = event.getTo(); // Don't call again we need same result.
|
||||
|
||||
Location previousLocation = latestLocations.get(player.getName());
|
||||
if (previousLocation != null &&
|
||||
playerLoc.getBlockX() == previousLocation.getBlockX() &&
|
||||
playerLoc.getBlockY() == previousLocation.getBlockY() &&
|
||||
playerLoc.getBlockZ() == previousLocation.getBlockZ() &&
|
||||
playerLoc.getWorld() == previousLocation.getWorld()) {
|
||||
// we only care when people change location
|
||||
return;
|
||||
}
|
||||
latestLocations.put(player.getName(), playerLoc);
|
||||
|
||||
// Signs can automatically teleport you to specific or random warzones
|
||||
if (playerLoc.getBlock().getType() == Material.SIGN) {
|
||||
Sign sign = (Sign) playerLoc.getBlock().getState();
|
||||
if (sign.getLine(0).equals("[zone]")) {
|
||||
Warzone indicated = Warzone.getZoneByName(sign.getLine(1));
|
||||
if (indicated != null) {
|
||||
player.teleport(indicated.getTeleport());
|
||||
} else if (sign.getLine(1).equalsIgnoreCase("$random")) {
|
||||
List<Warzone> warzones = War.war.getEnabledWarzones();
|
||||
if (warzones.size() == 0) return;
|
||||
int zone = random.nextInt(warzones.size());
|
||||
Warzone random = warzones.get(zone);
|
||||
player.teleport(random.getTeleport());
|
||||
} else if (sign.getLine(1).equalsIgnoreCase("$active")) {
|
||||
List<Warzone> warzones = War.war.getActiveWarzones();
|
||||
if (warzones.size() == 0) warzones = War.war.getEnabledWarzones();
|
||||
if (warzones.size() == 0) return;
|
||||
int zone = random.nextInt(warzones.size());
|
||||
Warzone random = warzones.get(zone);
|
||||
player.teleport(random.getTeleport());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Warzone locZone = Warzone.getZoneByLocation(playerLoc);
|
||||
ZoneLobby locLobby = ZoneLobby.getLobbyByLocation(playerLoc);
|
||||
|
||||
boolean isMaker = War.war.isZoneMaker(player);
|
||||
|
||||
// Zone walls
|
||||
Team currentTeam = Team.getTeamByPlayerName(player.getName());
|
||||
Warzone playerWarzone = Warzone.getZoneByPlayerName(player.getName()); // this uses the teams, so it asks: get the player's team's warzone
|
||||
boolean protecting = false;
|
||||
if (currentTeam != null) {
|
||||
if (playerWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.GLASSWALLS)) {
|
||||
protecting = playerWarzone.protectZoneWallAgainstPlayer(player);
|
||||
}
|
||||
} else {
|
||||
Warzone nearbyZone = War.war.zoneOfZoneWallAtProximity(playerLoc);
|
||||
if (nearbyZone != null && nearbyZone.getWarzoneConfig().getBoolean(WarzoneConfig.GLASSWALLS) && !isMaker) {
|
||||
protecting = nearbyZone.protectZoneWallAgainstPlayer(player);
|
||||
}
|
||||
}
|
||||
|
||||
if (!protecting) {
|
||||
// zone makers still need to delete their walls
|
||||
// make sure to delete any wall guards as you leave
|
||||
for (Warzone zone : War.war.getWarzones()) {
|
||||
zone.dropZoneWallGuardIfAny(player);
|
||||
}
|
||||
}
|
||||
|
||||
// Warzone lobby gates
|
||||
if (locLobby != null && currentTeam == null && locLobby.isInAnyGate(playerLoc)) {
|
||||
Warzone zone = locLobby.getZone();
|
||||
Team locTeamGate = locLobby.getTeamGate(playerLoc);
|
||||
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.DISABLED) || zone.isReinitializing()) {
|
||||
War.war.badMsg(player, "join.disabled");
|
||||
event.setTo(zone.getTeleport());
|
||||
} else if (!zone.getWarzoneConfig().getBoolean(WarzoneConfig.JOINMIDBATTLE) && zone.isEnoughPlayers()) {
|
||||
War.war.badMsg(player, "join.progress");
|
||||
event.setTo(zone.getTeleport());
|
||||
} else if (zone.isFull()) {
|
||||
War.war.badMsg(player, "join.full.all");
|
||||
event.setTo(zone.getTeleport());
|
||||
} else if (zone.isFull(player)) {
|
||||
War.war.badMsg(player, "join.permission.all");
|
||||
event.setTo(zone.getTeleport());
|
||||
} else if (locTeamGate != null && locTeamGate.isFull()) {
|
||||
War.war.badMsg(player, "join.full.single", locTeamGate.getName());
|
||||
event.setTo(zone.getTeleport());
|
||||
} else if (locTeamGate != null && !War.war.canPlayWar(player, locTeamGate)) {
|
||||
War.war.badMsg(player, "join.permission.single", locTeamGate.getName());
|
||||
event.setTo(zone.getTeleport());
|
||||
} else if (zone.getLobby().isAutoAssignGate(playerLoc)) {
|
||||
zone.autoAssign(player);
|
||||
} else if (locTeamGate != null) {
|
||||
zone.assign(player, locTeamGate);
|
||||
}
|
||||
return;
|
||||
} else if (locLobby != null && currentTeam == null
|
||||
&& locLobby.isInWarHubLinkGate(playerLoc)
|
||||
&& War.war.getWarHub() != null) {
|
||||
War.war.msg(player, "warhub.teleport");
|
||||
event.setTo(War.war.getWarHub().getLocation());
|
||||
return;
|
||||
}
|
||||
|
||||
// Warhub zone gates
|
||||
WarHub hub = War.war.getWarHub();
|
||||
if (hub != null && hub.getVolume().contains(player.getLocation())) {
|
||||
Warzone zone = hub.getDestinationWarzoneForLocation(playerLoc);
|
||||
if (zone != null && zone.getTeleport() != null) {
|
||||
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.AUTOJOIN)
|
||||
&& zone.getTeams().size() >= 1 && currentTeam == null) {
|
||||
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.DISABLED) || zone.isReinitializing()) {
|
||||
War.war.badMsg(player, "join.disabled");
|
||||
event.setTo(hub.getLocation());
|
||||
} else if (!zone.getWarzoneConfig().getBoolean(WarzoneConfig.JOINMIDBATTLE) && zone.isEnoughPlayers()) {
|
||||
War.war.badMsg(player, "join.progress");
|
||||
event.setTo(hub.getLocation());
|
||||
} else if (zone.isFull()) {
|
||||
War.war.badMsg(player, "join.full.all");
|
||||
event.setTo(hub.getLocation());
|
||||
} else if (zone.isFull(player)) {
|
||||
War.war.badMsg(player, "join.permission.all");
|
||||
event.setTo(hub.getLocation());
|
||||
} else {
|
||||
zone.autoAssign(player);
|
||||
}
|
||||
return;
|
||||
}
|
||||
event.setTo(zone.getTeleport());
|
||||
War.war.msg(player, "zone.teleport", zone.getName());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
boolean isLeaving = playerWarzone != null && playerWarzone.getLobby().isLeavingZone(playerLoc);
|
||||
Team playerTeam = Team.getTeamByPlayerName(player.getName());
|
||||
if (isLeaving) { // already in a team and in warzone, leaving
|
||||
// same as leave
|
||||
if (playerTeam != null) {
|
||||
boolean atSpawnAlready = playerTeam.isSpawnLocation(playerLoc);
|
||||
if (!atSpawnAlready) {
|
||||
playerWarzone.handlePlayerLeave(player, playerWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.AUTOJOIN) ?
|
||||
War.war.getWarHub().getLocation() : playerWarzone.getTeleport(), event, true);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (playerWarzone != null) {
|
||||
// Player belongs to a warzone team but is outside: he snuck out or is at spawn and died
|
||||
if (locZone == null && playerTeam != null && playerWarzone.getLobby() != null && !playerWarzone.getLobby().getVolume().contains(playerLoc) && !isLeaving) {
|
||||
List<BlockFace> nearestWalls = playerWarzone.getNearestWalls(playerLoc);
|
||||
if (!playerWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.REALDEATHS)) {
|
||||
War.war.badMsg(player, "zone.leavenotice");
|
||||
}
|
||||
if(nearestWalls != null && nearestWalls.size() > 0) {
|
||||
// First, try to bump the player back in
|
||||
int northSouthMove = 0;
|
||||
int eastWestMove = 0;
|
||||
int upDownMove = 0;
|
||||
int moveDistance = 1;
|
||||
|
||||
if (nearestWalls.contains(Direction.NORTH())) {
|
||||
// move south
|
||||
northSouthMove += moveDistance;
|
||||
} else if (nearestWalls.contains(Direction.SOUTH())) {
|
||||
// move north
|
||||
northSouthMove -= moveDistance;
|
||||
}
|
||||
|
||||
if (nearestWalls.contains(Direction.EAST())) {
|
||||
// move west
|
||||
eastWestMove += moveDistance;
|
||||
} else if (nearestWalls.contains(Direction.WEST())) {
|
||||
// move east
|
||||
eastWestMove -= moveDistance;
|
||||
}
|
||||
|
||||
if (nearestWalls.contains(BlockFace.UP)) {
|
||||
upDownMove -= moveDistance;
|
||||
} else if (nearestWalls.contains(BlockFace.DOWN)) {
|
||||
// fell off the map, back to spawn (still need to drop objects)
|
||||
playerWarzone.dropAllStolenObjects(event.getPlayer(), false);
|
||||
playerWarzone.respawnPlayer(event, playerTeam, event.getPlayer());
|
||||
return;
|
||||
}
|
||||
|
||||
event.setTo(new Location(playerLoc.getWorld(),
|
||||
playerLoc.getX() + northSouthMove,
|
||||
playerLoc.getY() + upDownMove,
|
||||
playerLoc.getZ() + eastWestMove,
|
||||
playerLoc.getYaw(),
|
||||
playerLoc.getPitch()));
|
||||
return;
|
||||
|
||||
// Otherwise, send him to spawn (first make sure he drops his flag/cake/bomb to prevent auto-cap and as punishment)
|
||||
} else {
|
||||
playerWarzone.dropAllStolenObjects(event.getPlayer(), false);
|
||||
playerWarzone.respawnPlayer(event, playerTeam, event.getPlayer());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
LoadoutSelection loadoutSelectionState = playerWarzone.getLoadoutSelections().get(player.getName());
|
||||
FlagReturn flagReturn = playerTeam.getTeamConfig().resolveFlagReturn();
|
||||
if (!playerTeam.isSpawnLocation(playerLoc)) {
|
||||
if (!playerWarzone.isEnoughPlayers() && loadoutSelectionState != null && loadoutSelectionState.isStillInSpawn()) {
|
||||
// Be sure to keep only players that just respawned locked inside the spawn for minplayer/minteams restrictions - otherwise
|
||||
// this will conflict with the can't-renter-spawn bump just a few lines below
|
||||
War.war.badMsg(player, "zone.spawn.minplayers", playerWarzone.getWarzoneConfig().getInt(WarzoneConfig.MINPLAYERS),
|
||||
playerWarzone.getWarzoneConfig().getInt(WarzoneConfig.MINTEAMS));
|
||||
event.setTo(playerTeam.getRandomSpawn());
|
||||
return;
|
||||
}
|
||||
if (playerWarzone.isRespawning(player)) {
|
||||
int rt = playerTeam.getTeamConfig().resolveInt(TeamConfig.RESPAWNTIMER);
|
||||
War.war.badMsg(player, "zone.spawn.timer", rt);
|
||||
event.setTo(playerTeam.getRandomSpawn());
|
||||
return;
|
||||
}
|
||||
if (playerWarzone.isReinitializing()) {
|
||||
// don't let players wander about outside spawns during reset
|
||||
// (they could mess up the blocks that have already been reset
|
||||
// before the start of the new battle)
|
||||
War.war.msg(player, "zone.battle.reset");
|
||||
event.setTo(playerTeam.getRandomSpawn());
|
||||
return;
|
||||
}
|
||||
} else if (loadoutSelectionState != null && !loadoutSelectionState.isStillInSpawn()
|
||||
&& !playerWarzone.isCakeThief(player)
|
||||
&& (flagReturn.equals(FlagReturn.BOTH) || flagReturn.equals(FlagReturn.SPAWN))
|
||||
&& !playerWarzone.isFlagThief(player)) {
|
||||
|
||||
// player is in spawn, but has left already: he should NOT be let back in - kick him out gently
|
||||
// if he sticks around too long.
|
||||
// (also, be sure you aren't preventing the flag or cake from being captured)
|
||||
// if (!CantReEnterSpawnJob.getPlayersUnderSuspicion().contains(player.getName())) {
|
||||
// CantReEnterSpawnJob job = new CantReEnterSpawnJob(player, playerTeam);
|
||||
// War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job, 12);
|
||||
// }
|
||||
return;
|
||||
}
|
||||
|
||||
// Monuments
|
||||
if (playerTeam != null && playerWarzone.nearAnyOwnedMonument(playerLoc, playerTeam) && player.getHealth() < 20 && player.getHealth() > 0 // don't heal the dead
|
||||
&& this.random.nextInt(7) == 3) { // one chance out of many of getting healed
|
||||
int currentHp = (int) player.getHealth();
|
||||
int newHp = Math.min(20, currentHp + locZone.getWarzoneConfig().getInt(WarzoneConfig.MONUMENTHEAL));
|
||||
|
||||
player.setHealth(newHp);
|
||||
double heartNum = ((double) newHp - currentHp) / 2;
|
||||
War.war.msg(player, "zone.monument.voodoo", heartNum);
|
||||
return;
|
||||
}
|
||||
|
||||
// Flag capture
|
||||
if (playerWarzone.isFlagThief(player)) {
|
||||
|
||||
// smoky
|
||||
if (System.currentTimeMillis() % 13 == 0) {
|
||||
playerWarzone.getWorld().playEffect(player.getLocation(), Effect.POTION_BREAK, playerTeam.getKind().getPotionEffectColor());
|
||||
}
|
||||
|
||||
// Make sure game ends can't occur simultaneously.
|
||||
// See Warzone.handleDeath() for details.
|
||||
boolean inSpawn = playerTeam.isSpawnLocation(player.getLocation());
|
||||
boolean inFlag = (playerTeam.getFlagVolume() != null && playerTeam.getFlagVolume().contains(player.getLocation()));
|
||||
|
||||
if (playerTeam.getTeamConfig().resolveFlagReturn().equals(FlagReturn.BOTH)) {
|
||||
if (!inSpawn && !inFlag) {
|
||||
return;
|
||||
}
|
||||
} else if (playerTeam.getTeamConfig().resolveFlagReturn().equals(FlagReturn.SPAWN)) {
|
||||
if (inFlag) {
|
||||
War.war.badMsg(player, "zone.flagreturn.spawn");
|
||||
return;
|
||||
} else if (!inSpawn) {
|
||||
return;
|
||||
}
|
||||
} else if (playerTeam.getTeamConfig().resolveFlagReturn().equals(FlagReturn.FLAG)) {
|
||||
if (inSpawn) {
|
||||
War.war.badMsg(player, "zone.flagreturn.flag");
|
||||
return;
|
||||
} else if (!inFlag) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!playerTeam.getPlayers().contains(player)) {
|
||||
// Make sure player is still part of team, game may have ended while waiting)
|
||||
// Ignore the scorers that happened immediately after the game end.
|
||||
return;
|
||||
}
|
||||
|
||||
if (playerWarzone.isTeamFlagStolen(playerTeam) && playerTeam.getTeamConfig().resolveBoolean(TeamConfig.FLAGMUSTBEHOME)) {
|
||||
War.war.badMsg(player, "zone.flagreturn.deadlock");
|
||||
} else {
|
||||
// flags can be captured at own spawn or own flag pole
|
||||
if (playerWarzone.isReinitializing()) {
|
||||
// Battle already ended or interrupted
|
||||
playerWarzone.respawnPlayer(event, playerTeam, player);
|
||||
} else {
|
||||
// All good - proceed with scoring
|
||||
playerTeam.addPoint();
|
||||
Team victim = playerWarzone.getVictimTeamForFlagThief(player);
|
||||
|
||||
// Notify everyone
|
||||
for (Team t : playerWarzone.getTeams()) {
|
||||
t.teamcast("zone.flagcapture.broadcast", playerTeam.getKind().getColor() + player.getName() + ChatColor.WHITE,
|
||||
victim.getName(), playerTeam.getName());
|
||||
}
|
||||
|
||||
// Detect win conditions
|
||||
if (playerTeam.getPoints() >= playerTeam.getTeamConfig().resolveInt(TeamConfig.MAXSCORE)) {
|
||||
if (playerWarzone.hasPlayerState(player.getName())) {
|
||||
playerWarzone.restorePlayerState(player);
|
||||
}
|
||||
playerWarzone.handleScoreCapReached(playerTeam.getName());
|
||||
event.setTo(playerWarzone.getTeleport());
|
||||
} else {
|
||||
// just added a point
|
||||
victim.getFlagVolume().resetBlocks(); // bring back flag to team that lost it
|
||||
victim.initializeTeamFlag();
|
||||
|
||||
playerWarzone.respawnPlayer(event, playerTeam, player);
|
||||
playerTeam.resetSign();
|
||||
playerWarzone.getLobby().resetTeamGateSign(playerTeam);
|
||||
}
|
||||
}
|
||||
|
||||
playerWarzone.removeFlagThief(player);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Bomb detonation
|
||||
if (playerWarzone.isBombThief(player)) {
|
||||
// smoky
|
||||
playerWarzone.getWorld().playEffect(player.getLocation(), Effect.SMOKE, 0);
|
||||
|
||||
// Make sure game ends can't occur simultaneously.
|
||||
// Not thread safe. See Warzone.handleDeath() for details.
|
||||
boolean inEnemySpawn = false;
|
||||
Team victim = null;
|
||||
for (Team team : playerWarzone.getTeams()) {
|
||||
if (team != playerTeam
|
||||
&& team.isSpawnLocation(player.getLocation())
|
||||
&& team.getPlayers().size() > 0) {
|
||||
inEnemySpawn = true;
|
||||
victim = team;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (inEnemySpawn && playerTeam.getPlayers().contains(player)) {
|
||||
// Made sure player is still part of team, game may have ended while waiting.
|
||||
// Ignored the scorers that happened immediately after the game end.
|
||||
Bomb bomb = playerWarzone.getBombForThief(player);
|
||||
|
||||
// Boom!
|
||||
if (!playerWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.UNBREAKABLE)) {
|
||||
// Don't blow up if warzone is unbreakable
|
||||
playerWarzone.getWorld().createExplosion(player.getLocation(), 2F);
|
||||
}
|
||||
|
||||
if (playerWarzone.isReinitializing()) {
|
||||
// Battle already ended or interrupted
|
||||
playerWarzone.respawnPlayer(event, playerTeam, player);
|
||||
} else {
|
||||
// All good - proceed with scoring
|
||||
playerTeam.addPoint();
|
||||
|
||||
// Notify everyone
|
||||
for (Team t : playerWarzone.getTeams()) {
|
||||
t.teamcast("zone.bomb.broadcast", playerTeam.getKind().getColor() + player.getName() + ChatColor.WHITE,
|
||||
victim.getName(), playerTeam.getName());
|
||||
}
|
||||
|
||||
// Detect win conditions
|
||||
if (playerTeam.getPoints() >= playerTeam.getTeamConfig().resolveInt(TeamConfig.MAXSCORE)) {
|
||||
if (playerWarzone.hasPlayerState(player.getName())) {
|
||||
playerWarzone.restorePlayerState(player);
|
||||
}
|
||||
playerWarzone.handleScoreCapReached(playerTeam.getName());
|
||||
event.setTo(playerWarzone.getTeleport());
|
||||
} else {
|
||||
// just added a point
|
||||
|
||||
// restore bombed team's spawn
|
||||
for (Volume spawnVolume : victim.getSpawnVolumes().values()) {
|
||||
spawnVolume.resetBlocks();
|
||||
}
|
||||
victim.initializeTeamSpawns();
|
||||
|
||||
// bring back tnt
|
||||
bomb.getVolume().resetBlocks();
|
||||
bomb.addBombBlocks();
|
||||
|
||||
playerWarzone.respawnPlayer(event, playerTeam, player);
|
||||
playerTeam.resetSign();
|
||||
playerWarzone.getLobby().resetTeamGateSign(playerTeam);
|
||||
}
|
||||
}
|
||||
|
||||
playerWarzone.removeBombThief(player);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Cake retrieval
|
||||
if (playerWarzone.isCakeThief(player)) {
|
||||
// smoky
|
||||
if (System.currentTimeMillis() % 13 == 0) {
|
||||
playerWarzone.getWorld().playEffect(player.getLocation(), Effect.POTION_BREAK, playerTeam.getKind().getPotionEffectColor());
|
||||
}
|
||||
|
||||
// Make sure game ends can't occur simultaneously.
|
||||
// Not thread safe. See Warzone.handleDeath() for details.
|
||||
boolean inSpawn = playerTeam.isSpawnLocation(player.getLocation());
|
||||
|
||||
if (inSpawn && playerTeam.getPlayers().contains(player)) {
|
||||
// Made sure player is still part of team, game may have ended while waiting.
|
||||
// Ignored the scorers that happened immediately after the game end.
|
||||
boolean hasOpponent = false;
|
||||
for (Team t : playerWarzone.getTeams()) {
|
||||
if (t != playerTeam && t.getPlayers().size() > 0) {
|
||||
hasOpponent = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Don't let someone alone make points off cakes
|
||||
if (hasOpponent) {
|
||||
Cake cake = playerWarzone.getCakeForThief(player);
|
||||
|
||||
if (playerWarzone.isReinitializing()) {
|
||||
// Battle already ended or interrupted
|
||||
playerWarzone.respawnPlayer(event, playerTeam, player);
|
||||
} else {
|
||||
// All good - proceed with scoring
|
||||
// Woot! Cake effect: 1 pt + full lifepool
|
||||
playerTeam.addPoint();
|
||||
playerTeam.setRemainingLives(playerTeam.getTeamConfig().resolveInt(TeamConfig.LIFEPOOL));
|
||||
|
||||
// Notify everyone
|
||||
for (Team t : playerWarzone.getTeams()) {
|
||||
t.teamcast("zone.cake.broadcast", playerTeam.getKind().getColor() + player.getName() + ChatColor.WHITE,
|
||||
ChatColor.GREEN + cake.getName() + ChatColor.WHITE, playerTeam.getName());
|
||||
}
|
||||
|
||||
// Detect win conditions
|
||||
if (playerTeam.getPoints() >= playerTeam.getTeamConfig().resolveInt(TeamConfig.MAXSCORE)) {
|
||||
if (playerWarzone.hasPlayerState(player.getName())) {
|
||||
playerWarzone.restorePlayerState(player);
|
||||
}
|
||||
playerWarzone.handleScoreCapReached(playerTeam.getName());
|
||||
event.setTo(playerWarzone.getTeleport());
|
||||
} else {
|
||||
// just added a point
|
||||
|
||||
// bring back cake
|
||||
cake.getVolume().resetBlocks();
|
||||
cake.addCakeBlocks();
|
||||
|
||||
playerWarzone.respawnPlayer(event, playerTeam, player);
|
||||
playerTeam.resetSign();
|
||||
playerWarzone.getLobby().resetTeamGateSign(playerTeam);
|
||||
}
|
||||
}
|
||||
|
||||
playerWarzone.removeCakeThief(player);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Class selection lock
|
||||
if (!playerTeam.isSpawnLocation(player.getLocation()) &&
|
||||
playerWarzone.getLoadoutSelections().keySet().contains(player.getName())
|
||||
&& playerWarzone.getLoadoutSelections().get(player.getName()).isStillInSpawn()) {
|
||||
playerWarzone.getLoadoutSelections().get(player.getName()).setStillInSpawn(false);
|
||||
}
|
||||
|
||||
} else if (locZone != null && locZone.getLobby() != null && !locZone.getLobby().isLeavingZone(playerLoc) && !isMaker) {
|
||||
// player is not in any team, but inside warzone boundaries, get him out
|
||||
Warzone zone = Warzone.getZoneByLocation(playerLoc);
|
||||
event.setTo(zone.getTeleport());
|
||||
War.war.badMsg(player, "zone.noteamnotice");
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerToggleSneak(PlayerToggleSneakEvent event) {
|
||||
if (War.war.isLoaded() && event.isSneaking()) {
|
||||
Warzone playerWarzone = Warzone.getZoneByLocation(event.getPlayer());
|
||||
Team playerTeam = Team.getTeamByPlayerName(event.getPlayer().getName());
|
||||
if (playerWarzone != null && playerTeam != null && playerTeam.getInventories().resolveLoadouts().keySet().size() > 1 && playerTeam.isSpawnLocation(event.getPlayer().getLocation())) {
|
||||
if (playerWarzone.getLoadoutSelections().keySet().contains(event.getPlayer().getName())
|
||||
&& playerWarzone.getLoadoutSelections().get(event.getPlayer().getName()).isStillInSpawn()) {
|
||||
LoadoutSelection selection = playerWarzone.getLoadoutSelections().get(event.getPlayer().getName());
|
||||
List<Loadout> loadouts = new ArrayList<Loadout>(playerTeam.getInventories().resolveNewLoadouts());
|
||||
for (Iterator<Loadout> it = loadouts.iterator(); it.hasNext();) {
|
||||
Loadout ldt = it.next();
|
||||
if (ldt.getName().equals("first") ||
|
||||
(ldt.requiresPermission() && !event.getPlayer().hasPermission(ldt.getPermission()))) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
int currentIndex = (selection.getSelectedIndex() + 1) % loadouts.size();
|
||||
selection.setSelectedIndex(currentIndex);
|
||||
|
||||
playerWarzone.equipPlayerLoadoutSelection(event.getPlayer(), playerTeam, false, true);
|
||||
} else {
|
||||
War.war.badMsg(event.getPlayer(), "zone.loadout.reenter");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerRespawn(PlayerRespawnEvent event) {
|
||||
Warzone playingZone = Warzone.getZoneByPlayerName(event.getPlayer().getName());
|
||||
Warzone deadZone = Warzone.getZoneForDeadPlayer(event.getPlayer());
|
||||
if (playingZone == null && deadZone != null) {
|
||||
// Game ended while player was dead, so restore state
|
||||
deadZone.getReallyDeadFighters().remove(event.getPlayer().getName());
|
||||
if (deadZone.hasPlayerState(event.getPlayer().getName())) {
|
||||
deadZone.restorePlayerState(event.getPlayer());
|
||||
}
|
||||
event.setRespawnLocation(deadZone.getEndTeleport(LeaveCause.DISCONNECT));
|
||||
return;
|
||||
} else if (playingZone == null) {
|
||||
// Player not playing war
|
||||
return;
|
||||
} else if (deadZone == null) {
|
||||
// Player is not a 'really' dead player, nothing to do here
|
||||
return;
|
||||
}
|
||||
Team team = playingZone.getPlayerTeam(event.getPlayer().getName());
|
||||
Validate.notNull(team, String.format(
|
||||
"Failed to find a team for player %s in warzone %s on respawn.",
|
||||
event.getPlayer().getName(), playingZone.getName()));
|
||||
playingZone.getReallyDeadFighters().remove(event.getPlayer().getName());
|
||||
event.setRespawnLocation(team.getRandomSpawn());
|
||||
playingZone.respawnPlayer(team, event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerTeleport(final PlayerTeleportEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
Warzone playerWarzone = Warzone.getZoneByPlayerName(event.getPlayer().getName());
|
||||
Team playerTeam = Team.getTeamByPlayerName(event.getPlayer().getName());
|
||||
if (playerWarzone != null) {
|
||||
if (!playerWarzone.getVolume().contains(event.getTo())) {
|
||||
// Prevent teleporting out of the warzone
|
||||
if (!playerWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.REALDEATHS)) {
|
||||
War.war.badMsg(event.getPlayer(), "Use /leave (or /war leave) to exit the zone.");
|
||||
}
|
||||
playerWarzone.dropAllStolenObjects(event.getPlayer(), false);
|
||||
playerWarzone.respawnPlayer(event, playerTeam, event.getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerExpChange(PlayerExpChangeEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
Team team = Team.getTeamByPlayerName(event.getPlayer().getName());
|
||||
if (team != null && team.getTeamConfig().resolveBoolean(TeamConfig.XPKILLMETER)) {
|
||||
event.setAmount(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerChat(final AsyncPlayerChatEvent event) {
|
||||
Team team = Team.getTeamByPlayerName(event.getPlayer().getName());
|
||||
if (team != null && team.isInTeamChat(event.getPlayer())) {
|
||||
event.setCancelled(true);
|
||||
team.sendTeamChatMessage(event.getPlayer(), event.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(final InventoryClickEvent event) {
|
||||
if (!(event.getWhoClicked() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
if (zone == null) {
|
||||
return;
|
||||
}
|
||||
if (zone.isThief(player)) {
|
||||
// Prevent thieves from taking their bomb/wool/cake into a chest, etc.
|
||||
event.setCancelled(true);
|
||||
player.playSound(player.getLocation(), Sound.BLOCK_LAVA_EXTINGUISH, 10, 10);
|
||||
} else if (event.getSlotType() == InventoryType.SlotType.ARMOR && event.getSlot() == 39
|
||||
&& zone.getWarzoneConfig().getBoolean(WarzoneConfig.BLOCKHEADS)) {
|
||||
// Magically give player a wool block when they click their helmet
|
||||
ItemStack teamBlock = zone.getPlayerTeam(player.getName()).getKind().getBlockHead();
|
||||
player.getInventory().remove(teamBlock.getType());
|
||||
// Deprecated behavior cannot be removed as it is essential to this function
|
||||
//noinspection deprecation
|
||||
event.setCursor(teamBlock);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void purgeLatestPositions() {
|
||||
this.latestLocations.clear();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBucketEmpty(PlayerBucketEmptyEvent event) {
|
||||
Player player = (Player) event.getPlayer();
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
if (zone == null) {
|
||||
return;
|
||||
}
|
||||
if (zone.isImportantBlock(event.getBlockClicked())) {
|
||||
event.setCancelled(true);
|
||||
player.playSound(player.getLocation(), Sound.BLOCK_LAVA_EXTINGUISH, 10, 10);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.tommytony.war.event;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class WarPlayerThiefEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private Player player;
|
||||
private StolenObject type;
|
||||
|
||||
public WarPlayerThiefEvent(Player thief, StolenObject stolen) {
|
||||
this.player = thief;
|
||||
this.type = stolen;
|
||||
}
|
||||
|
||||
public Player getThief() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public StolenObject getStolenObject() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public enum StolenObject {
|
||||
FLAG,
|
||||
BOMB,
|
||||
CAKE
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.tommytony.war.event;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
|
||||
public class WarScoreCapEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private List<Team> winningTeams;
|
||||
|
||||
public List<Team> getWinningTeams() {
|
||||
return winningTeams;
|
||||
}
|
||||
|
||||
public WarScoreCapEvent(List<Team> winningTeams) {
|
||||
this.winningTeams = winningTeams;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.tommytony.war.job;
|
||||
|
||||
import com.tommytony.war.volume.Volume;
|
||||
|
||||
public class BlockResetJob implements Runnable {
|
||||
|
||||
private final Volume volume;
|
||||
|
||||
public BlockResetJob(Volume volume) {
|
||||
this.volume = volume;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
this.volume.resetBlocks();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,119 @@
|
|||
package com.tommytony.war.job;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.config.TeamConfig;
|
||||
import com.tommytony.war.structure.CapturePoint;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class CapturePointTimer extends BukkitRunnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Player player : War.war.getServer().getOnlinePlayers()) {
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
|
||||
if (zone == null || team == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (CapturePoint cp : zone.getCapturePoints()) {
|
||||
if (cp.getVolume().contains(player.getLocation())) {
|
||||
// player is maintaining or contesting capture point.
|
||||
if (cp.getController() == null) {
|
||||
// take control of unclaimed point
|
||||
incrementStrength(cp, player, zone, team);
|
||||
} else if (cp.getController() != team.getKind()) {
|
||||
// contest other team's point
|
||||
decrementStrength(cp, player, zone, team);
|
||||
} else if (cp.getController() == team.getKind()) {
|
||||
// maintain your team's point
|
||||
incrementStrength(cp, player, zone, team);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (Warzone zone : War.war.getWarzones()) {
|
||||
for (CapturePoint cp : zone.getCapturePoints()) {
|
||||
if (cp.getController() != null && cp.getController() != cp.getDefaultController()
|
||||
&& cp.getStrength() == cp.getMaxStrength()) {
|
||||
int controlTime = cp.getControlTime() + 1;
|
||||
cp.setControlTime(controlTime);
|
||||
if (controlTime % cp.getMaxStrength() == 0) {
|
||||
// give points for every control time which is a multiple of the time taken to capture
|
||||
Team team = zone.getTeamByKind(cp.getController());
|
||||
team.addPoint();
|
||||
zone.broadcast("zone.capturepoint.addpoint",
|
||||
cp.getController().getFormattedName(), cp.getName());
|
||||
// Detect win conditions
|
||||
if (team.getPoints() >= team.getTeamConfig().resolveInt(TeamConfig.MAXSCORE)) {
|
||||
zone.handleScoreCapReached(team.getName());
|
||||
} else {
|
||||
// just added a point
|
||||
team.resetSign();
|
||||
zone.getLobby().resetTeamGateSign(team);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void decrementStrength(CapturePoint cp, Player player, Warzone zone, Team team) {
|
||||
int strength = cp.getStrength();
|
||||
if (strength < 1) {
|
||||
// strength is already at minimum, ensure attributes are wiped
|
||||
cp.setController(null);
|
||||
cp.setStrength(0);
|
||||
return;
|
||||
}
|
||||
strength -= 1;
|
||||
if (strength == 0) {
|
||||
if (cp.antiChatSpam()) {
|
||||
zone.broadcast("zone.capturepoint.lose", cp.getController().getFormattedName(), cp.getName());
|
||||
}
|
||||
cp.setControlTime(0);
|
||||
cp.setController(null);
|
||||
} else if (strength == cp.getMaxStrength() - 1) {
|
||||
if (cp.antiChatSpam()) {
|
||||
zone.broadcast("zone.capturepoint.contest", cp.getName(),
|
||||
team.getKind().getColor() + player.getName() + ChatColor.WHITE);
|
||||
}
|
||||
}
|
||||
cp.setStrength(strength);
|
||||
}
|
||||
|
||||
private static void incrementStrength(CapturePoint cp, Player player, Warzone zone, Team team) {
|
||||
int strength = cp.getStrength();
|
||||
if (strength > cp.getMaxStrength()) {
|
||||
// cap strength at CapturePoint.MAX_STRENGTH
|
||||
cp.setStrength(cp.getMaxStrength());
|
||||
return;
|
||||
} else if (strength == cp.getMaxStrength()) {
|
||||
// do nothing
|
||||
return;
|
||||
}
|
||||
strength += 1;
|
||||
if (strength == cp.getMaxStrength()) {
|
||||
if (cp.antiChatSpam()) {
|
||||
zone.broadcast("zone.capturepoint.capture", cp.getController().getFormattedName(), cp.getName());
|
||||
}
|
||||
team.addPoint();
|
||||
} else if (strength == 1) {
|
||||
if (cp.antiChatSpam()) {
|
||||
zone.broadcast("zone.capturepoint.fortify", team.getKind().getFormattedName(), cp.getName());
|
||||
}
|
||||
cp.setController(team.getKind());
|
||||
}
|
||||
cp.setStrength(strength);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package com.tommytony.war.job;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Item;
|
||||
|
||||
import com.tommytony.war.utility.DeferredBlockReset;
|
||||
|
||||
public class DeferredBlockResetsJob implements Runnable {
|
||||
|
||||
List<BlockState> deferred = new ArrayList<BlockState>();
|
||||
|
||||
public DeferredBlockResetsJob() {
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public DeferredBlockResetsJob(World humor) {
|
||||
}
|
||||
|
||||
public void add(BlockState pleaseResetLater) {
|
||||
this.deferred.add(pleaseResetLater);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void add(DeferredBlockReset humor) {
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return this.deferred.isEmpty();
|
||||
}
|
||||
|
||||
public void run() {
|
||||
for (BlockState reset : this.deferred) {
|
||||
reset.update(true, false);
|
||||
for (Entity ent : reset.getWorld().getEntities()) {
|
||||
if (ent instanceof Item
|
||||
&& ent.getLocation().distance(reset.getLocation()) < 2) {
|
||||
ent.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
package com.tommytony.war.job;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.config.WarzoneConfig;
|
||||
|
||||
|
||||
/**
|
||||
* Sets the helmet again onto the players heads. Also limits the number of blocks being held.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class HelmetProtectionTask implements Runnable {
|
||||
|
||||
public void run() {
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
for (Warzone zone : War.war.getWarzones()) {
|
||||
for (Team team : zone.getTeams()) {
|
||||
for (Player player : team.getPlayers()) {
|
||||
PlayerInventory playerInv = player.getInventory();
|
||||
Material teamBlockMaterial;
|
||||
|
||||
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.BLOCKHEADS)) {
|
||||
teamBlockMaterial = team.getKind().getMaterial();
|
||||
// 1) Replace missing block head
|
||||
if (playerInv.getHelmet() == null || playerInv.getHelmet().getType() != Material.LEATHER_HELMET) {
|
||||
playerInv.setHelmet(team.getKind().getHat());
|
||||
}
|
||||
|
||||
// 2) Get rid of extra blocks in inventory: only keep one
|
||||
HashMap<Integer, ? extends ItemStack> blocks = playerInv.all(teamBlockMaterial);
|
||||
if (blocks.size() > 1 || (blocks.size() == 1 && blocks.get(blocks.keySet().iterator().next()).getAmount() > 1)) {
|
||||
int i = 0;
|
||||
int removed = 0;
|
||||
for (ItemStack item : playerInv.getContents()) {
|
||||
// remove only same colored wool
|
||||
if (item != null && item.getType() == teamBlockMaterial) {
|
||||
playerInv.clear(i);
|
||||
removed++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
int firstEmpty = playerInv.firstEmpty();
|
||||
if (firstEmpty > 0) {
|
||||
playerInv.setItem(firstEmpty, team.getKind().getBlockHead());
|
||||
}
|
||||
|
||||
if (removed > 1) {
|
||||
War.war.badMsg(player, "All that " + team.getName() + " wool must have been heavy!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check for thieves without their treasure in their hands
|
||||
if (zone.isFlagThief(player)) {
|
||||
Team victim = zone.getVictimTeamForFlagThief(player);
|
||||
player.getInventory().setItemInMainHand(null);
|
||||
player.getInventory().setItemInOffHand(null);
|
||||
player.getInventory().setHeldItemSlot(0);
|
||||
player.getInventory().addItem(new ItemStack(victim.getKind().getMaterial(), 2240));
|
||||
} else if (zone.isBombThief(player)) {
|
||||
player.getInventory().setItemInMainHand(null);
|
||||
player.getInventory().setItemInOffHand(null);
|
||||
player.getInventory().setHeldItemSlot(0);
|
||||
player.getInventory().addItem(new ItemStack(Material.TNT, 2240));
|
||||
} else if (zone.isCakeThief(player)) {
|
||||
player.getInventory().setItemInMainHand(null);
|
||||
player.getInventory().setItemInOffHand(null);
|
||||
player.getInventory().setHeldItemSlot(0);
|
||||
player.getInventory().addItem(new ItemStack(Material.CAKE, 2240));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.tommytony.war.job;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.Warzone;
|
||||
|
||||
public class InitZoneJob implements Runnable {
|
||||
|
||||
private final Warzone zone;
|
||||
private final Player respawnExempted;
|
||||
|
||||
public InitZoneJob(Warzone zone) {
|
||||
this.zone = zone;
|
||||
this.respawnExempted = null;
|
||||
}
|
||||
|
||||
public InitZoneJob(Warzone warzone, Player respawnExempted) {
|
||||
this.zone = warzone;
|
||||
this.respawnExempted = respawnExempted;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
this.zone.initializeZone(this.respawnExempted);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.tommytony.war.job;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.Warzone;
|
||||
|
||||
public class LoadoutResetJob implements Runnable {
|
||||
|
||||
private final Player player;
|
||||
private final Warzone zone;
|
||||
private final Team team;
|
||||
private final boolean isFirstRespawn;
|
||||
private final boolean isToggle;
|
||||
|
||||
public LoadoutResetJob(Warzone zone, Team team, Player player, boolean isFirstRespawn, boolean isToggle) {
|
||||
this.zone = zone;
|
||||
this.team = team;
|
||||
this.player = player;
|
||||
this.isFirstRespawn = isFirstRespawn;
|
||||
this.isToggle = isToggle;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
this.zone.equipPlayerLoadoutSelection(player, team, isFirstRespawn, isToggle);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
package com.tommytony.war.job;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.tommytony.war.War;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.logging.Level;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
/**
|
||||
* Job to insert kills and deaths information to MySQL database.
|
||||
*
|
||||
* @author cmastudios
|
||||
*/
|
||||
public class LogKillsDeathsJob extends BukkitRunnable {
|
||||
|
||||
private final ImmutableList<KillsDeathsRecord> records;
|
||||
|
||||
public LogKillsDeathsJob(final ImmutableList<KillsDeathsRecord> records) {
|
||||
this.records = records;
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Adds all #records to database at #databaseURL. Will attempt to open a
|
||||
* connection to the database at #databaseURL. This method is thread safe.
|
||||
*/
|
||||
public void run() {
|
||||
Connection conn = null;
|
||||
try {
|
||||
conn = War.war.getMysqlConfig().getConnection();
|
||||
Statement createStmt = conn.createStatement();
|
||||
createStmt.executeUpdate("CREATE TABLE IF NOT EXISTS `war_kills` (`date` datetime NOT NULL, `player` varchar(16) NOT NULL, `kills` int(11) NOT NULL, `deaths` int(11) NOT NULL, KEY `date` (`date`)) ENGINE=InnoDB DEFAULT CHARSET=latin1");
|
||||
createStmt.close();
|
||||
PreparedStatement stmt = conn.prepareStatement("INSERT INTO war_kills (date, player, kills, deaths) VALUES (NOW(), ?, ?, ?)");
|
||||
conn.setAutoCommit(false);
|
||||
for (KillsDeathsRecord kdr : records) {
|
||||
stmt.setString(1, kdr.getPlayer().getName());
|
||||
stmt.setInt(2, kdr.getKills());
|
||||
stmt.setInt(3, kdr.getDeaths());
|
||||
stmt.addBatch();
|
||||
}
|
||||
stmt.executeBatch();
|
||||
conn.commit();
|
||||
stmt.close();
|
||||
final String deleteClause =
|
||||
War.war.getMysqlConfig().getLoggingDeleteClause();
|
||||
if (!deleteClause.isEmpty()) {
|
||||
Statement deleteStmt = conn.createStatement();
|
||||
deleteStmt.executeUpdate(
|
||||
"DELETE FROM war_kills " + deleteClause);
|
||||
deleteStmt.close();
|
||||
conn.commit();
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
War.war.getLogger().log(Level.SEVERE,
|
||||
"Inserting kill-death logs into database", ex);
|
||||
} finally {
|
||||
if (conn != null) {
|
||||
try {
|
||||
conn.close();
|
||||
} catch (SQLException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final class KillsDeathsRecord {
|
||||
|
||||
private final OfflinePlayer player;
|
||||
private final int kills;
|
||||
private final int deaths;
|
||||
|
||||
public KillsDeathsRecord(OfflinePlayer player, int kills, int deaths) {
|
||||
this.player = player;
|
||||
this.kills = kills;
|
||||
this.deaths = deaths;
|
||||
}
|
||||
|
||||
public OfflinePlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public int getKills() {
|
||||
return kills;
|
||||
}
|
||||
|
||||
public int getDeaths() {
|
||||
return deaths;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.tommytony.war.job;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class LootDropperTask implements Runnable {
|
||||
|
||||
private final List<ItemStack> drop;
|
||||
private final Location location;
|
||||
|
||||
public LootDropperTask(Location location, List<ItemStack> drop) {
|
||||
this.location = location;
|
||||
this.drop = drop;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
for (ItemStack item : this.drop) {
|
||||
if (item != null) {
|
||||
this.location.getWorld().dropItemNaturally(this.location, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,171 @@
|
|||
package com.tommytony.war.job;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mapper.ZoneVolumeMapper;
|
||||
import com.tommytony.war.structure.ZoneLobby;
|
||||
import com.tommytony.war.volume.ZoneVolume;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.MessageFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class PartialZoneResetJob extends BukkitRunnable implements Cloneable {
|
||||
|
||||
// Watch out, this command sender's map is shared between all concurrent reset jobs on different warzones
|
||||
// - gotta make sure to notify the correct player that sent the command
|
||||
private static Map<Warzone, CommandSender> sendersToNotify = Collections.synchronizedMap(new HashMap<Warzone, CommandSender>());
|
||||
|
||||
private final Warzone zone;
|
||||
private final ZoneVolume volume;
|
||||
private final int speed;
|
||||
private final int total;
|
||||
private int completed = 0;
|
||||
private final long startTime = System.currentTimeMillis();
|
||||
private long messageCounter = System.currentTimeMillis();
|
||||
boolean[][][] changes;
|
||||
public static final long MESSAGE_INTERVAL = 7500;
|
||||
// Ticks between job runs
|
||||
public static final int JOB_INTERVAL = 1;
|
||||
private int totalChanges = 0;
|
||||
private NumberFormat formatter = new DecimalFormat("#0.00");
|
||||
private Connection conn;
|
||||
|
||||
/**
|
||||
* Reset a warzone's blocks at a certain speed.
|
||||
*
|
||||
* @param zone
|
||||
* Warzone to reset.
|
||||
* @param speed
|
||||
* Blocks to modify per #INTERVAL.
|
||||
*/
|
||||
public PartialZoneResetJob(Warzone zone, int speed) throws SQLException {
|
||||
this.zone = zone;
|
||||
this.volume = zone.getVolume();
|
||||
this.speed = speed;
|
||||
this.total = volume.getTotalSavedBlocks();
|
||||
this.changes = new boolean[volume.getSizeX()][volume.getSizeY()][volume.getSizeZ()];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (conn == null || conn.isClosed()) {
|
||||
conn = ZoneVolumeMapper.getZoneConnection(volume, zone.getName());
|
||||
}
|
||||
if (completed >= total) {
|
||||
int airChanges = 0;
|
||||
int minX = volume.getMinX(), minY = volume.getMinY(), minZ = volume.getMinZ();
|
||||
air: for (int x = volume.getMinX(); x <= volume.getMaxX(); x++) {
|
||||
for (int y = volume.getMinY(); y <= volume.getMaxY(); y++) {
|
||||
for (int z = volume.getMinZ(); z <= volume.getMaxZ(); z++) {
|
||||
int xi = x - minX, yi = y - minY, zi = z - minZ;
|
||||
if (!changes[xi][yi][zi]) {
|
||||
changes[xi][yi][zi] = true;
|
||||
airChanges++;
|
||||
BlockState state = volume.getWorld().getBlockAt(x, y, z).getState();
|
||||
if (state.getType() != Material.AIR) {
|
||||
state.setType(Material.AIR);
|
||||
state.update(true, false);
|
||||
}
|
||||
if (airChanges >= speed) {
|
||||
this.displayStatusMessage();
|
||||
break air;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
totalChanges += airChanges;
|
||||
if (this.doneAir()) {
|
||||
volume.resetEntities(conn);
|
||||
String secondsAsText = formatter.format(((double)(System.currentTimeMillis() - startTime)) / 1000);
|
||||
String message = MessageFormat.format(
|
||||
War.war.getString("zone.battle.resetcomplete"), secondsAsText);
|
||||
this.sendMessageToAllWarzonePlayers(message);
|
||||
PartialZoneResetJob.setSenderToNotify(zone, null); // stop notifying for this zone
|
||||
zone.initializeZone();
|
||||
War.war.getLogger().log(Level.INFO, "Finished reset cycle for warzone {0} (took {1} seconds)",
|
||||
new Object[]{volume.getName(), secondsAsText});
|
||||
conn.close();
|
||||
} else {
|
||||
War.war.getServer().getScheduler().runTaskLater(War.war, (Runnable) this.clone(), JOB_INTERVAL);
|
||||
}
|
||||
} else {
|
||||
int solidChanges = volume.resetSection(conn, completed, speed, changes);
|
||||
completed += solidChanges;
|
||||
totalChanges += solidChanges;
|
||||
this.displayStatusMessage();
|
||||
War.war.getServer().getScheduler().runTaskLater(War.war, (Runnable) this.clone(), JOB_INTERVAL);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
War.war.getLogger().log(Level.WARNING, "Failed to load zone during reset loop", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void sendMessageToAllWarzonePlayers(String message) {
|
||||
for (Player player : War.war.getServer().getOnlinePlayers()) {
|
||||
ZoneLobby lobby = ZoneLobby.getLobbyByLocation(player);
|
||||
if (player != PartialZoneResetJob.sendersToNotify.get(zone)
|
||||
&& (zone.getPlayers().contains(player)
|
||||
|| (lobby != null && lobby.getZone() == zone))) {
|
||||
War.war.msg(player, message);
|
||||
}
|
||||
}
|
||||
|
||||
if (PartialZoneResetJob.sendersToNotify.get(zone) != null) {
|
||||
War.war.msg(PartialZoneResetJob.sendersToNotify.get(zone), message);
|
||||
}
|
||||
}
|
||||
|
||||
private void displayStatusMessage() {
|
||||
if (System.currentTimeMillis() - messageCounter > MESSAGE_INTERVAL) {
|
||||
String secondsAsText = formatter.format(((double)(System.currentTimeMillis() - startTime)) / 1000);
|
||||
messageCounter = System.currentTimeMillis();
|
||||
int percent = (int) (((double) totalChanges / (double) volume.size()) * 100);
|
||||
String message = MessageFormat.format(
|
||||
War.war.getString("zone.battle.resetprogress"),
|
||||
percent, secondsAsText);
|
||||
this.sendMessageToAllWarzonePlayers(message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PartialZoneResetJob clone() {
|
||||
try {
|
||||
return (PartialZoneResetJob) super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
throw new Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setSenderToNotify(Warzone warzone, CommandSender sender) {
|
||||
PartialZoneResetJob.sendersToNotify.put(warzone, sender);
|
||||
}
|
||||
|
||||
private boolean doneAir() {
|
||||
int minX = volume.getMinX(), minY = volume.getMinY(), minZ = volume.getMinZ();
|
||||
for (int x = volume.getMinX(); x <= volume.getMaxX(); x++) {
|
||||
for (int y = volume.getMinY(); y <= volume.getMaxY(); y++) {
|
||||
for (int z = volume.getMinZ(); z <= volume.getMaxZ(); z++) {
|
||||
int xi = x - minX, yi = y - minY, zi = z - minZ;
|
||||
if (!changes[xi][yi][zi]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
package com.tommytony.war.job;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mapper.VolumeMapper;
|
||||
import com.tommytony.war.structure.WarHub;
|
||||
import com.tommytony.war.volume.Volume;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class RestoreYmlWarhubJob implements Runnable {
|
||||
|
||||
private final ConfigurationSection warhubConfig;
|
||||
|
||||
public RestoreYmlWarhubJob(ConfigurationSection warhubConfig) {
|
||||
this.warhubConfig = warhubConfig;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
int hubX = warhubConfig.getInt("x");
|
||||
int hubY = warhubConfig.getInt("y");
|
||||
int hubZ = warhubConfig.getInt("z");
|
||||
|
||||
String worldName = warhubConfig.getString("world");
|
||||
String hubOrientation = warhubConfig.getString("orientation");
|
||||
|
||||
// materials
|
||||
if (warhubConfig.isItemStack("materials.floor")) {
|
||||
War.war.getWarhubMaterials().setFloorBlock(
|
||||
warhubConfig.getItemStack("materials.floor"));
|
||||
}
|
||||
if (warhubConfig.isItemStack("materials.outline")) {
|
||||
War.war.getWarhubMaterials().setOutlineBlock(
|
||||
warhubConfig.getItemStack("materials.outline"));
|
||||
}
|
||||
if (warhubConfig.isItemStack("materials.gate")) {
|
||||
War.war.getWarhubMaterials().setGateBlock(
|
||||
warhubConfig.getItemStack("materials.gate"));
|
||||
}
|
||||
if (warhubConfig.isItemStack("materials.light")) {
|
||||
War.war.getWarhubMaterials().setLightBlock(
|
||||
warhubConfig.getItemStack("materials.light"));
|
||||
}
|
||||
World world = War.war.getServer().getWorld(worldName);
|
||||
if (world != null) {
|
||||
Location hubLocation = new Location(world, hubX, hubY, hubZ);
|
||||
WarHub hub = new WarHub(hubLocation, hubOrientation);
|
||||
War.war.setWarHub(hub);
|
||||
Volume vol;
|
||||
try {
|
||||
vol = VolumeMapper.loadSimpleVolume("warhub", world);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
hub.setVolume(vol);
|
||||
hub.getVolume().resetBlocks();
|
||||
hub.initialize();
|
||||
|
||||
// In the previous job started by the mapper, warzones were created, but their lobbies are missing the war hub gate (because it didn't exist yet)
|
||||
for (Warzone zone : War.war.getWarzones()) {
|
||||
if (zone.getLobby() != null) {
|
||||
zone.getLobby().getVolume().resetBlocks();
|
||||
zone.getLobby().initialize();
|
||||
}
|
||||
}
|
||||
War.war.log("Warhub ready.", Level.INFO);
|
||||
} else {
|
||||
War.war.log("Failed to restore warhub. The specified world (name: " + worldName + ") does not exist!", Level.WARNING);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,100 @@
|
|||
package com.tommytony.war.job;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.config.WarzoneConfig;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.mcstats.Metrics;
|
||||
import org.mcstats.Metrics.Graph;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class RestoreYmlWarzonesJob implements Runnable {
|
||||
|
||||
private final List<String> warzones;
|
||||
|
||||
public RestoreYmlWarzonesJob(List<String> warzones) {
|
||||
this.warzones = warzones;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
War.war.getWarzones().clear();
|
||||
if (this.warzones != null) {
|
||||
for (String warzoneName : this.warzones) {
|
||||
if (warzoneName != null && !warzoneName.equals("")) {
|
||||
War.war.log("Loading zone " + warzoneName + "...", Level.INFO);
|
||||
Warzone zone = WarzoneYmlMapper.load(warzoneName);
|
||||
if (zone != null) { // could have failed, would've been logged already
|
||||
War.war.getWarzones().add(zone);
|
||||
try {
|
||||
zone.getVolume().loadCorners();
|
||||
} catch (SQLException ex) {
|
||||
War.war.log("Failed to load warzone " + warzoneName + ": " + ex.getMessage(), Level.WARNING);
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
if (zone.getLobby() != null) {
|
||||
zone.getLobby().getVolume().resetBlocks();
|
||||
}
|
||||
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.RESETONLOAD)) {
|
||||
zone.getVolume().resetBlocks();
|
||||
}
|
||||
zone.initializeZone();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (War.war.getWarzones().size() > 0) {
|
||||
War.war.log("Warzones ready.", Level.INFO);
|
||||
final int zones = War.war.getWarzones().size();
|
||||
try {
|
||||
Metrics metrics = new Metrics(War.war);
|
||||
Graph warzoneCount = metrics.createGraph("Warzones");
|
||||
warzoneCount.addPlotter(new FixedPlotter("Count", zones));
|
||||
Graph language = metrics.createGraph("Language");
|
||||
String langName = War.war.getLoadedLocale().getDisplayLanguage(Locale.ENGLISH);
|
||||
if (langName.isEmpty()) {
|
||||
langName = "English";
|
||||
}
|
||||
language.addPlotter(new PlotterEnabled(langName));
|
||||
Graph plugins = metrics.createGraph("Extensions");
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("WorldEdit")) {
|
||||
plugins.addPlotter(new PlotterEnabled("WorldEdit"));
|
||||
}
|
||||
plugins.addPlotter(new PlotterEnabled("War")); // of course
|
||||
metrics.start();
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class FixedPlotter extends Metrics.Plotter {
|
||||
|
||||
private final int value;
|
||||
|
||||
public FixedPlotter(final String name, final int value) {
|
||||
super(name);
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
private static class PlotterEnabled extends Metrics.Plotter {
|
||||
|
||||
public PlotterEnabled(final String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getValue() {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package com.tommytony.war.job;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.config.ScoreboardType;
|
||||
import com.tommytony.war.config.WarzoneConfig;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
/**
|
||||
* Switches scoreboards periodically
|
||||
* Github #790
|
||||
*/
|
||||
public class ScoreboardSwitchTimer extends BukkitRunnable {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
for (Warzone zone : War.war.getEnabledWarzones()) {
|
||||
if (zone.getWarzoneConfig().getScoreboardType(WarzoneConfig.SCOREBOARD) == ScoreboardType.SWITCHING) {
|
||||
switch (zone.getScoreboardType()) {
|
||||
case SWITCHING:
|
||||
zone.setScoreboardType(ScoreboardType.POINTS);
|
||||
break;
|
||||
case POINTS:
|
||||
zone.setScoreboardType(ScoreboardType.LIFEPOOL);
|
||||
break;
|
||||
case LIFEPOOL:
|
||||
zone.setScoreboardType(ScoreboardType.TOPKILLS);
|
||||
break;
|
||||
case TOPKILLS:
|
||||
zone.setScoreboardType(ScoreboardType.PLAYERCOUNT);
|
||||
break;
|
||||
case PLAYERCOUNT:
|
||||
zone.setScoreboardType(ScoreboardType.POINTS);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
zone.updateScoreboard();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package com.tommytony.war.job;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class TeleportPlayerJob extends BukkitRunnable {
|
||||
private final Player player;
|
||||
private final Location location;
|
||||
private final Location originalLocation;
|
||||
private final double originalHealth;
|
||||
|
||||
public TeleportPlayerJob(Player player, Location location) {
|
||||
this.player = player;
|
||||
this.location = location;
|
||||
this.originalLocation = player.getLocation().clone();
|
||||
this.originalHealth = player.getHealth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!player.isOnline()) {
|
||||
} else if (hasPlayerMoved()) {
|
||||
War.war.badMsg(player, "command.tp.moved");
|
||||
} else if (hasPlayerTakenDamage()) {
|
||||
War.war.badMsg(player, "command.tp.damaged");
|
||||
} else {
|
||||
player.teleport(location, PlayerTeleportEvent.TeleportCause.COMMAND);
|
||||
War.war.msg(player, "command.tp.success");
|
||||
}
|
||||
}
|
||||
|
||||
boolean hasPlayerMoved() {
|
||||
final double MAX_MOVE_TOLERANCE = 1.5;
|
||||
return distance3D(player.getLocation(), originalLocation) > MAX_MOVE_TOLERANCE;
|
||||
}
|
||||
|
||||
boolean hasPlayerTakenDamage() {
|
||||
final double MAX_DAMAGE_TOLERANCE = 2;
|
||||
return Math.abs(originalHealth - player.getHealth()) > MAX_DAMAGE_TOLERANCE;
|
||||
}
|
||||
|
||||
double distance3D(Location pos1, Location pos2) {
|
||||
double distX = pos2.getX() - pos1.getX();
|
||||
double distY = pos2.getY() - pos1.getY();
|
||||
double distZ = pos2.getZ() - pos1.getZ();
|
||||
return Math.sqrt(Math.pow(distX, 2) + Math.pow(distY, 2) + Math.pow(distZ, 2));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.tommytony.war.job;
|
||||
|
||||
import com.tommytony.war.Warzone;
|
||||
|
||||
/**
|
||||
* @author grinning
|
||||
*/
|
||||
public class ZoneTimeJob implements Runnable {
|
||||
|
||||
private Warzone zone;
|
||||
|
||||
public ZoneTimeJob(Warzone zone) {
|
||||
this.zone = zone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
zone.setPvpReady(true);
|
||||
}
|
||||
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue