Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8758c9b940 | ||
|
|
a569d20779 | ||
|
|
88e01fa083 | ||
|
|
7b435f9283 | ||
|
|
a240e5d128 | ||
|
|
0d0ba31d3a | ||
|
|
e79bb3533d | ||
|
|
f94c4ec831 | ||
|
|
d5afb76105 | ||
|
|
dd7e9ba05e | ||
|
|
ee54698fdb | ||
|
|
955b0e991c | ||
|
|
c1b98b9e40 | ||
|
|
d6939b7916 | ||
|
|
5f0ca37879 | ||
|
|
548bdb7eb5 | ||
|
|
5c85f39228 | ||
|
|
85b2cbc03a | ||
|
|
cc78011da6 | ||
|
|
d016da1895 | ||
|
|
8593f1c80a | ||
|
|
0b3c40dc3e | ||
|
|
2e7ecc59c0 | ||
|
|
942ce95dbf | ||
|
|
03f77d5ab7 | ||
|
|
8dec32fa6a | ||
|
|
8f409d47d9 | ||
|
|
93f062d4e3 | ||
|
|
b8f9ceafbb | ||
|
|
75d07b6dad | ||
|
|
6060a0a430 | ||
|
|
647ba1572c | ||
|
|
051e0cb811 | ||
|
|
b8c9e78910 | ||
|
|
2d7d9c6093 | ||
|
|
0f32f56208 | ||
|
|
5addfd8975 | ||
|
|
7f108ce8f0 | ||
|
|
8c883e1ca8 | ||
|
|
d18fe6ffa0 | ||
|
|
80a8ac9e98 | ||
|
|
671fd58568 | ||
|
|
c4ea3b59f0 | ||
|
|
5d5def206d | ||
|
|
b2ebbb9b55 | ||
|
|
3734c071bf | ||
|
|
b1a419f2a2 | ||
|
|
bf5e292160 | ||
|
|
df57d91270 | ||
|
|
4da1741578 | ||
|
|
7a3774e730 | ||
|
|
e6e21caeea | ||
|
|
200d47ab09 | ||
|
|
ab274151d4 | ||
|
|
aec1e3a529 | ||
|
|
916caa1eb2 | ||
|
|
50b29f8ad6 | ||
|
|
88d662cf27 | ||
|
|
5316130ae8 | ||
|
|
4f36dbc636 | ||
|
|
230a8697bf | ||
|
|
121449b230 | ||
|
|
fede549b51 | ||
|
|
1bdd7f9a6b | ||
|
|
b3f9da67b7 | ||
|
|
1ba7d623b4 | ||
|
|
47902e1177 | ||
|
|
a035bcc671 | ||
|
|
9bcc6b9605 | ||
|
|
282c3a864e | ||
|
|
eb083a8934 | ||
|
|
0fc71ff79e | ||
|
|
68a7455496 | ||
|
|
fcfc3acbb8 | ||
|
|
aa53c0aa6a | ||
|
|
f098905a92 | ||
|
|
eec78092b5 | ||
|
|
34fa5eceb8 | ||
|
|
c32d2dd6f8 | ||
|
|
da80d3536a | ||
|
|
e9361022d2 | ||
|
|
dd0c1a5ab5 | ||
|
|
bb9dff7b8c | ||
|
|
7e419c116e | ||
|
|
2cbc2f5226 | ||
|
|
68b5e3e0a8 | ||
|
|
1502ec12a9 | ||
|
|
6d09b18479 | ||
|
|
08ce207636 | ||
|
|
f199b977eb | ||
|
|
5715e2c835 | ||
|
|
b8642b7ca3 | ||
|
|
2c4d4708d8 | ||
|
|
0edb6e6157 | ||
|
|
4f394b5668 | ||
|
|
9834c30e3a | ||
|
|
f3f1b0870f | ||
|
|
915d314c18 | ||
|
|
02b3ae6aa5 | ||
|
|
f725e73653 | ||
|
|
c5858ef202 | ||
|
|
ba2fd2ca2e | ||
|
|
1075d36748 | ||
|
|
3ee3799e55 | ||
|
|
6654b0a67a | ||
|
|
9577c93edb | ||
|
|
7cd67281bc | ||
|
|
d21c226183 | ||
|
|
4322236b9e | ||
|
|
05e408ee65 | ||
|
|
3d1012ba94 | ||
|
|
94937e41ef | ||
|
|
3957aa83fc | ||
|
|
8aa79d1c4c | ||
|
|
578eeff0e1 | ||
|
|
5f2f1c67f5 | ||
|
|
c92b9c3d97 | ||
|
|
0951d00da3 | ||
|
|
6df9c3660b | ||
|
|
19be2bf96e | ||
|
|
e10ed6ac7a | ||
|
|
479ebf4d89 | ||
|
|
1f1e36e9f7 | ||
|
|
27e634ae03 | ||
|
|
e60b20b37b | ||
|
|
684214ff6a | ||
|
|
ba5be6071f | ||
|
|
6c8d13690e | ||
|
|
3e0b2ef3e4 | ||
|
|
c5304d2775 | ||
|
|
ca95ae04a5 | ||
|
|
1ab9f85ca6 | ||
|
|
01ff1b2f8f | ||
|
|
9b17fe68e7 | ||
|
|
0fed35a80f | ||
|
|
25280c9fa9 | ||
|
|
a98ebfdb21 | ||
|
|
acb1d18654 | ||
|
|
18b5a4e106 | ||
|
|
bab420a359 | ||
|
|
4f14f1f736 | ||
|
|
166831447c | ||
|
|
f2bd5961d0 | ||
|
|
2cc990a530 | ||
|
|
f0e6008563 | ||
|
|
93f19cca0a | ||
|
|
1cbe508f82 | ||
|
|
0c178c3155 | ||
|
|
e67304389d | ||
|
|
ad5b1cdcba | ||
|
|
fe1e09289f | ||
|
|
583ea76e4b | ||
|
|
a7d198893e | ||
|
|
fe62c8d0c5 | ||
|
|
16ce56c1ad | ||
|
|
15f0bfb9db | ||
|
|
22db589742 | ||
|
|
69119e6db7 | ||
|
|
690da2332b | ||
|
|
f2fead1444 | ||
|
|
c4f6267921 | ||
|
|
0dc65d083f | ||
|
|
40c1d93f02 | ||
|
|
2024a93126 | ||
|
|
88d79a42e6 | ||
|
|
b01b2cce9b | ||
|
|
c5b1089c96 | ||
|
|
679e43758b | ||
|
|
90e6e5a96c | ||
|
|
4fb003c4df | ||
|
|
9d5f349a04 | ||
|
|
f4f4a47a7f | ||
|
|
6a3e987668 | ||
|
|
83f943965f | ||
|
|
c9fdff169f | ||
|
|
5454832918 | ||
|
|
3d6d774b17 | ||
|
|
1463547af4 | ||
|
|
0bcf4b3597 | ||
|
|
824e8dcb4b | ||
|
|
4b2f0c8020 | ||
|
|
7fd424cf65 | ||
|
|
5ff2855eb0 | ||
|
|
8c8c162a54 | ||
|
|
37d52f3688 | ||
|
|
f361cbfa71 | ||
|
|
ddefbfe2cf | ||
|
|
10296cb736 | ||
|
|
49dc0599c9 | ||
|
|
14348e170b | ||
|
|
59d1f0d817 | ||
|
|
e024f134a4 | ||
|
|
cf5a5b5b47 | ||
|
|
e957f92496 | ||
|
|
9484bb9941 | ||
|
|
d781f9822f | ||
|
|
7845ef2de4 | ||
|
|
a9d4ecf33d | ||
|
|
6f4a62c7a3 | ||
|
|
6b4f872742 | ||
|
|
ef4f00f8f5 | ||
|
|
a27deb3936 | ||
|
|
18814c7373 | ||
|
|
1d9908e1f6 | ||
|
|
29529e4a06 | ||
|
|
74b1003c4c | ||
|
|
27ffdec323 | ||
|
|
d9e5fc2b60 | ||
|
|
646b3e3064 | ||
|
|
d3475208ef | ||
|
|
7246da472d | ||
|
|
e1f917894a | ||
|
|
c14d25f860 | ||
|
|
57ed91cd28 | ||
|
|
47c84beb43 | ||
|
|
1e3032bdce | ||
|
|
ed69684843 | ||
|
|
2eea5c7bf7 | ||
|
|
16da53ae4e | ||
|
|
f45464b0d9 | ||
|
|
2351ade6fe | ||
|
|
c19ccf9278 | ||
|
|
5c92762ba9 | ||
|
|
e665f966e6 | ||
|
|
7dcca7e505 | ||
|
|
e25049b1d6 | ||
|
|
da9bc4a138 | ||
|
|
1224d3b443 | ||
|
|
d33be37694 | ||
|
|
551ff26a65 | ||
|
|
74082f9c68 | ||
|
|
b93331e184 | ||
|
|
d5d26168b3 | ||
|
|
9d848e222b | ||
|
|
46a2510e85 | ||
|
|
0789a453a2 | ||
|
|
b30f7fe9c7 | ||
|
|
525bd199b2 | ||
|
|
dffd8b59f5 | ||
|
|
df206724bd | ||
|
|
41f31250a9 | ||
|
|
b29007275f | ||
|
|
35f268319e | ||
|
|
6e8a185b63 | ||
|
|
120fff1fc4 | ||
|
|
f879bd5e3a | ||
|
|
01f9fd561d | ||
|
|
6802a7d747 | ||
|
|
b918b29014 | ||
|
|
4895a3313b | ||
|
|
59673c9e66 | ||
|
|
b126255be7 | ||
|
|
606c9f3fd8 | ||
|
|
aa306a8df7 | ||
|
|
b1256eedcf | ||
|
|
4454df341f | ||
|
|
5bcac17f1c | ||
|
|
875b9f326c | ||
|
|
a0d27c6f86 | ||
|
|
1d47d12189 | ||
|
|
67f78ae8b5 | ||
|
|
5948855da7 | ||
|
|
f6ec46cdf6 | ||
|
|
ebd2755eb2 | ||
|
|
78f5827d3d | ||
|
|
0829070c67 | ||
|
|
8b4332e842 | ||
|
|
f904c91443 | ||
|
|
944539453e | ||
|
|
5856b002df | ||
|
|
12f68bc227 | ||
|
|
de6e20d60a | ||
|
|
35e6ef5cd8 | ||
|
|
27251dda2e | ||
|
|
4bb967ab4a | ||
|
|
7c1f878610 | ||
|
|
e8c4c9b218 | ||
|
|
bc37d365ab | ||
|
|
d9ae1bbd9f | ||
|
|
e492b30178 | ||
|
|
920860c298 | ||
|
|
5f8a6e3423 | ||
|
|
3e7a5056d5 | ||
|
|
2ec6f04763 | ||
|
|
ecef9c9792 | ||
|
|
810501a508 | ||
|
|
6285a66d76 | ||
|
|
72e4922e8e | ||
|
|
c1f1885633 | ||
|
|
56e514a500 | ||
|
|
5ede100d56 | ||
|
|
f1456b8101 | ||
|
|
ef8eb76b16 | ||
|
|
b4f2188f72 | ||
|
|
38c30f5ecd | ||
|
|
94c794de6f | ||
|
|
fb535e620c | ||
|
|
5a42980d78 | ||
|
|
299d2a1f01 | ||
|
|
164ff5ea9a | ||
|
|
6c89ef908a | ||
|
|
3441ae11f2 | ||
|
|
c028331ef9 | ||
|
|
9343c300cd | ||
|
|
63693cc529 | ||
|
|
e6de06aae8 | ||
|
|
89ce7312d1 | ||
|
|
b884787377 | ||
|
|
a1427e7743 | ||
|
|
0c02190e19 | ||
|
|
1f7cce9535 | ||
|
|
9fea677b60 | ||
|
|
6b9a3aff58 | ||
|
|
b938271b4d | ||
|
|
297e06ba71 | ||
|
|
a521ab76a5 | ||
|
|
b1c8fc82c4 | ||
|
|
d4ba90c21d | ||
|
|
14dc868d45 | ||
|
|
61a60ecdd6 | ||
|
|
2b56247e21 | ||
|
|
e0066e6173 | ||
|
|
b5b92f91dc | ||
|
|
7b12510182 | ||
|
|
e2fc6a3ff0 | ||
|
|
5acd3a7f6c | ||
|
|
ce49ca0998 | ||
|
|
eacce487ed | ||
|
|
602b1d8a27 | ||
|
|
dec469caef | ||
|
|
4194b2ca86 | ||
|
|
17741822c1 | ||
|
|
3757056e46 | ||
|
|
0eb68ef864 | ||
|
|
3f77a9b721 | ||
|
|
321b3acf0a | ||
|
|
dfbbeeb473 | ||
|
|
31d3f2e7c6 | ||
|
|
40a66b9be4 | ||
|
|
049a1fb2ed | ||
|
|
3fc68af05f | ||
|
|
c3f0c8a7a1 | ||
|
|
cba1a95838 | ||
|
|
345f4a2e0e | ||
|
|
162d53b66e | ||
|
|
bed6782a00 | ||
|
|
d90b960597 | ||
|
|
3325feb1cb | ||
|
|
62d181eb81 | ||
|
|
1e24e9c128 | ||
|
|
cfffba25cf | ||
|
|
671b4fe2db | ||
|
|
5b300bc5d1 | ||
|
|
a5332c2166 | ||
|
|
141d5ccd25 | ||
|
|
c75b9c2328 | ||
|
|
0863db8cf0 | ||
|
|
53d6a272e6 | ||
|
|
71467a7ae7 | ||
|
|
56fa3458ab | ||
|
|
82e04ac4e5 | ||
|
|
564d4442fc | ||
|
|
df8fdd086b | ||
|
|
a31476251e | ||
|
|
360a655627 | ||
|
|
3b871b9c00 | ||
|
|
65834a2087 | ||
|
|
e9d85da691 | ||
|
|
cfa78af654 | ||
|
|
45d9119150 | ||
|
|
ea487eb6a4 | ||
|
|
4e295ea1eb | ||
|
|
32265414bd | ||
|
|
80e706e962 | ||
|
|
110838715b | ||
|
|
b90334c8a8 | ||
|
|
3ce0530d5f | ||
|
|
7eaa84d5b1 | ||
|
|
ad325dfedb | ||
|
|
5bb7eb6f01 | ||
|
|
342cfc0801 | ||
|
|
f5c6a9f507 | ||
|
|
e843ff372e | ||
|
|
ed27ffed65 | ||
|
|
7995ecd867 | ||
|
|
fcef6679c4 | ||
|
|
742b6a2e27 | ||
|
|
258fbc8870 | ||
|
|
0fa43ee287 | ||
|
|
fb39261dc7 | ||
|
|
7fce4bf53e | ||
|
|
13840cf61b | ||
|
|
e26f6b5e8d | ||
|
|
767c49f9fa | ||
|
|
c9178da608 | ||
|
|
855bc59a53 | ||
|
|
798c22e94b | ||
|
|
ea3be11294 | ||
|
|
335073b3b0 | ||
|
|
2b6ee344b7 | ||
|
|
8f55b82e2f | ||
|
|
ba9cd1f3e2 | ||
|
|
e0e7ae98e7 | ||
|
|
b05e439da9 | ||
|
|
fb5dbbdf58 | ||
|
|
9cb9dd0a58 | ||
|
|
276d42561e | ||
|
|
44b98165ba | ||
|
|
b5088340fd | ||
|
|
b7dd63ebd9 | ||
|
|
ba376a6326 | ||
|
|
87a43e8e8f | ||
|
|
b62ada53c3 | ||
|
|
4f3198b1bd | ||
|
|
c9f99e0903 | ||
|
|
3b4c58b721 | ||
|
|
6496bbd87f | ||
|
|
4ad8d362f7 | ||
|
|
d9aeb6afaa | ||
|
|
d971389746 | ||
|
|
233a2bdbe7 | ||
|
|
2277183330 | ||
|
|
b2cd3d31fd | ||
|
|
02f6b3be42 | ||
|
|
22e84321fc | ||
|
|
c472dc89ad | ||
|
|
b89d9d44b0 | ||
|
|
a2c21f8ceb | ||
|
|
e35596b0fa | ||
|
|
b95a7f063b | ||
|
|
e4bbd36d47 | ||
|
|
9790ab29a2 | ||
|
|
24cc2d3b36 | ||
|
|
12779699e3 | ||
|
|
2188690d20 | ||
|
|
7059fdfd9e | ||
|
|
9e1bde4b00 | ||
|
|
45790b60b0 | ||
|
|
c5f3a27d6b | ||
|
|
d9136aa407 | ||
|
|
183f48a998 | ||
|
|
3c5bc507a5 | ||
|
|
548dd0365c | ||
|
|
4591fc603f | ||
|
|
26946feecc | ||
|
|
dd14f3c469 | ||
|
|
69af41f1e5 | ||
|
|
474562455d | ||
|
|
c75d612541 | ||
|
|
8de6ce9868 | ||
|
|
97bde50708 | ||
|
|
b23e35cf26 | ||
|
|
b58e04707d | ||
|
|
846cf63268 | ||
|
|
4850bdefdf | ||
|
|
424b580eb9 | ||
|
|
7f8ad468ca | ||
|
|
e07e2bd7d1 | ||
|
|
7074963fb1 | ||
|
|
88acbe655d | ||
|
|
903ebc68a4 | ||
|
|
49bdccf020 | ||
|
|
ba3818884d | ||
|
|
64ce904ec1 | ||
|
|
8c5f7ef020 | ||
|
|
98426f6dcc | ||
|
|
f3ec873ac2 | ||
|
|
30961483e1 | ||
|
|
33e0750959 | ||
|
|
e59a07e232 | ||
|
|
3b05b9be11 | ||
|
|
943bbd9889 | ||
|
|
763cf8dbda | ||
|
|
5117518d8f | ||
|
|
936996da17 | ||
|
|
019a7e59b7 | ||
|
|
428a47f889 | ||
|
|
2be2cb19b2 | ||
|
|
66ee09d050 | ||
|
|
906dab28c1 | ||
|
|
6db8e1d842 | ||
|
|
a665e86096 | ||
|
|
b7481dbd2e | ||
|
|
b1e509c6f8 | ||
|
|
1f69622a34 | ||
|
|
215b2b5f75 | ||
|
|
1e8c91e92f | ||
|
|
19d447d67d | ||
|
|
925fa2ee1b | ||
|
|
1cedf0e9a0 | ||
|
|
ca8bb7f5f0 | ||
|
|
9e15a4a557 | ||
|
|
af5d0c4b0e | ||
|
|
08ab359534 | ||
|
|
28c44e0b2f | ||
|
|
7038f49a1a | ||
|
|
af25c15286 | ||
|
|
ffc5281d59 | ||
|
|
ad659cd32e | ||
|
|
afd3cbd311 | ||
|
|
a5a5f7e24a | ||
|
|
1e203b58c3 | ||
|
|
104b7c2cf2 | ||
|
|
355c89ecab | ||
|
|
1241e18f9c | ||
|
|
6566acf7eb | ||
|
|
4332ed92f2 | ||
|
|
2e7f96aab0 | ||
|
|
3cb9b90ef0 | ||
|
|
21a04cc8c8 | ||
|
|
dcc1b59627 | ||
|
|
e8fb3e6d24 | ||
|
|
93d084d5ba | ||
|
|
e45ecf9c86 | ||
|
|
beb10e22f2 | ||
|
|
64b12f8497 | ||
|
|
0821a08df2 | ||
|
|
50870a9b32 | ||
|
|
b823446e28 | ||
|
|
48b00874e5 | ||
|
|
deba6c79f3 | ||
|
|
c0be10ad94 | ||
|
|
5010d35ff3 | ||
|
|
42d26a1f4f | ||
|
|
92c25d2df4 | ||
|
|
5b5349fc34 | ||
|
|
cc6ac93b7a | ||
|
|
1b843b3586 | ||
|
|
3b9a426547 | ||
|
|
989ba0103d | ||
|
|
b584b996a3 | ||
|
|
896c7fc467 | ||
|
|
bd2393342f | ||
|
|
762b10cb17 | ||
|
|
9322eedb4e | ||
|
|
4e2a902b75 | ||
|
|
d3b8bd6f39 | ||
|
|
0fa64dad7f | ||
|
|
792e8663e6 | ||
|
|
4dc999b0d9 | ||
|
|
7c15c2de41 | ||
|
|
43137c3e53 | ||
|
|
521ecd438e | ||
|
|
949c6599b3 | ||
|
|
ea79efe693 | ||
|
|
b4a89462f8 | ||
|
|
70bd3d0e9a | ||
|
|
c33474e0f9 | ||
|
|
3d0ebe5c91 | ||
|
|
a9ab0702e0 | ||
|
|
9272741a3c | ||
|
|
2b72a99608 | ||
|
|
4c38e10fe1 | ||
|
|
7806b48d34 | ||
|
|
9803d6b731 | ||
|
|
649db3aca2 | ||
|
|
b75ab68e7a | ||
|
|
8ffc42d349 | ||
|
|
145c9750cd | ||
|
|
12647c3a6c | ||
|
|
056f8a57c7 | ||
|
|
94f0acf9f3 | ||
|
|
40bf65d56a | ||
|
|
726e3a5c20 | ||
|
|
d1cab0da7f | ||
|
|
ede4873c6a | ||
|
|
fd8c827bf1 | ||
|
|
20afbdf264 | ||
|
|
0dd92e5189 | ||
|
|
4b1ba5acb0 | ||
|
|
edc94594eb | ||
|
|
837efb75d1 | ||
|
|
252208a479 | ||
|
|
2641cb7d4f | ||
|
|
9c91f06c5d | ||
|
|
7fab4144ae | ||
|
|
81eb2cad1a | ||
|
|
eda7db7aca | ||
|
|
45a7653dcd | ||
|
|
36fef995e4 | ||
|
|
af2e862ca2 | ||
|
|
7f48ce06be | ||
|
|
1c5ae9ef67 | ||
|
|
3bf18c41bb | ||
|
|
7ab49f1909 | ||
|
|
44b5e5548d | ||
|
|
50ca9d129b | ||
|
|
7b725d655c | ||
|
|
3e9c7aa74b | ||
|
|
916ed2652e | ||
|
|
59a1726e8c | ||
|
|
20f91b5258 | ||
|
|
353ce7e825 | ||
|
|
94be4ab18e | ||
|
|
df7409607f | ||
|
|
79b937e8d2 | ||
|
|
83c6c9c743 | ||
|
|
6a2affc0f9 | ||
|
|
8ad713c183 | ||
|
|
f8fb746f64 | ||
|
|
c6b3507bf4 | ||
|
|
2dc95da6e0 | ||
|
|
8f9bfcf474 | ||
|
|
a8b54757e9 | ||
|
|
19cfd9edc6 | ||
|
|
03d0f962e5 | ||
|
|
0ff24627ca | ||
|
|
4d8cd430b7 | ||
|
|
30b0e5d0b1 | ||
|
|
cdf067bba8 | ||
|
|
e4d05e14ac | ||
|
|
82dc78523f | ||
|
|
676e744c02 | ||
|
|
0d80265ff2 | ||
|
|
442521a73c | ||
|
|
dcef083e30 | ||
|
|
162cd20f80 | ||
|
|
c74433422a | ||
|
|
f338650b24 | ||
|
|
65c0d77d3e | ||
|
|
09a150b6e9 | ||
|
|
06173a446a | ||
|
|
d6adea447e | ||
|
|
d042b785ed | ||
|
|
881846d301 | ||
|
|
2092cc43b3 | ||
|
|
dc637d0f2b | ||
|
|
987a20b33c | ||
|
|
dbf65f798f | ||
|
|
97aa259b2d | ||
|
|
770a108bad | ||
|
|
71aaa574b2 | ||
|
|
a02fe633e2 | ||
|
|
0669bab563 | ||
|
|
a258400443 | ||
|
|
d02c5057c6 | ||
|
|
a473f47235 | ||
|
|
7bedf6bb15 | ||
|
|
9d813290c6 | ||
|
|
05239bccb0 | ||
|
|
1d5c28f37f | ||
|
|
16fb6b4f9d | ||
|
|
97b09aab34 | ||
|
|
55210caceb | ||
|
|
8127e56603 | ||
|
|
e61b496ca4 | ||
|
|
3ed8eb76c2 | ||
|
|
a5c3b8a245 | ||
|
|
3f5d52f901 | ||
|
|
46e0607a26 | ||
|
|
23fa7a89ad | ||
|
|
dcd379bce7 | ||
|
|
40238a9d25 | ||
|
|
44db374e09 | ||
|
|
d960d543ff | ||
|
|
0a45292587 | ||
|
|
9b4a7c705b | ||
|
|
71a6d8ab44 | ||
|
|
91f9acb633 | ||
|
|
0e45dc5a3f | ||
|
|
3341574e02 | ||
|
|
881dc38a18 | ||
|
|
e54b201aa5 | ||
|
|
2d06a40127 | ||
|
|
f7e68798fa | ||
|
|
b9fe5d2afc | ||
|
|
5f12d99e73 | ||
|
|
933987ac0a | ||
|
|
3a10a0969a | ||
|
|
ba4907e67b | ||
|
|
99b37147d3 | ||
|
|
92a03ab7d6 | ||
|
|
68a0c67769 | ||
|
|
17e9105b9c | ||
|
|
5411a294e7 | ||
|
|
f821e277de | ||
|
|
18c2164049 | ||
|
|
c9688a9c58 | ||
|
|
cd599849b2 | ||
|
|
423f0199d0 | ||
|
|
40299eeea4 | ||
|
|
38077275bc | ||
|
|
23aa6dc743 | ||
|
|
b90fb6a2b0 | ||
|
|
17c8ed9ebc | ||
|
|
a091a32c26 | ||
|
|
23970a4e36 | ||
|
|
f61a9ab5cc | ||
|
|
4505bb6f4e | ||
|
|
bb836aea57 | ||
|
|
d584fba31c | ||
|
|
feacf3af7b | ||
|
|
8c428bb399 | ||
|
|
8edb6976fb | ||
|
|
edd2f460a0 | ||
|
|
8810647bb8 | ||
|
|
2204bd67a7 | ||
|
|
c9c747693d | ||
|
|
135d92303d | ||
|
|
c707434155 | ||
|
|
4b72805a69 | ||
|
|
d5a9b0c65f | ||
|
|
2015604fe2 | ||
|
|
96a290b153 | ||
|
|
912fcfe88a | ||
|
|
4dcf7489fa | ||
|
|
7f1552dff8 | ||
|
|
d2ca8bffc4 | ||
|
|
e15b01bac5 | ||
|
|
dcd3cb80b8 | ||
|
|
d0ddc7c271 | ||
|
|
2b55f3407c | ||
|
|
e84afb4808 | ||
|
|
10c47eff7e | ||
|
|
aee81f918e | ||
|
|
95b2d9419f | ||
|
|
feb9ce6633 | ||
|
|
43489ca087 | ||
|
|
ce1a15e6ea | ||
|
|
cc72d370ea | ||
|
|
d042185660 | ||
|
|
e78b639018 | ||
|
|
e8ea562b09 | ||
|
|
3b5a729ef3 | ||
|
|
ef7d487ec5 | ||
|
|
b379b8f022 | ||
|
|
a31378c2c8 | ||
|
|
0d2c2121bb | ||
|
|
21040b306a | ||
|
|
541b1dbc44 | ||
|
|
005ac41820 | ||
|
|
dd93772233 | ||
|
|
428fc7e5f6 | ||
|
|
5cf38cc885 | ||
|
|
2f6b51e811 | ||
|
|
2f12da6bc6 | ||
|
|
3985e157d9 | ||
|
|
3034eb5c12 | ||
|
|
f666f1baa9 | ||
|
|
3bbffa7b55 | ||
|
|
bc774e2596 | ||
|
|
65a0e5c188 | ||
|
|
772d2cb580 | ||
|
|
edc6825f83 | ||
|
|
7b2f9e0c86 | ||
|
|
0fa4fa1862 | ||
|
|
5be31ebb5c | ||
|
|
962394b2ba | ||
|
|
7cf7c5f44c | ||
|
|
5b494a09ec | ||
|
|
5cfac5da4a | ||
|
|
203004951b | ||
|
|
765d7402fa | ||
|
|
151b5fc561 | ||
|
|
b489da7fe4 | ||
|
|
786a0f6f2b | ||
|
|
e2a940e01b | ||
|
|
518c3be478 | ||
|
|
6f3eaac008 | ||
|
|
31633e9466 | ||
|
|
02913780ec | ||
|
|
f03a2263d8 | ||
|
|
a8cd832c28 | ||
|
|
abbced0530 | ||
|
|
200e07023f | ||
|
|
5fdd26b53f | ||
|
|
61896ea760 | ||
|
|
b43881c299 | ||
|
|
6046f4defc | ||
|
|
69ccb9f12b | ||
|
|
430f2f57e9 | ||
|
|
c3f0bbb41c | ||
|
|
7e481e6a9a | ||
|
|
627de1aebd | ||
|
|
194108336b | ||
|
|
eade612981 | ||
|
|
733163cc4c | ||
|
|
86a917ddd1 | ||
|
|
e8503aa0b9 | ||
|
|
01bf9e8406 | ||
|
|
0bdadf63b3 | ||
|
|
5b1c35bf06 | ||
|
|
c467acdfac | ||
|
|
22167a0a07 | ||
|
|
251647c7a2 | ||
|
|
80e9799579 | ||
|
|
95f49f34d0 | ||
|
|
b01b67f64c | ||
|
|
603fb5d2b8 | ||
|
|
22f7c347ab | ||
|
|
08229ed4f9 | ||
|
|
a942fd08f5 | ||
|
|
c96d534c26 | ||
|
|
789a9a9bb4 | ||
|
|
d2435a8026 | ||
|
|
36db436fa3 | ||
|
|
30d9978412 | ||
|
|
5db7f124ac | ||
|
|
c82ee055e7 | ||
|
|
cb1c1efc35 | ||
|
|
0037a4e83f | ||
|
|
c369b3c62a | ||
|
|
0934a12205 | ||
|
|
d19db5f86f | ||
|
|
5657ee6c90 | ||
|
|
41a71d6185 | ||
|
|
11592cd742 | ||
|
|
43d83d8855 | ||
|
|
d1cb628473 | ||
|
|
44fc802e8b | ||
|
|
bfa1734d23 | ||
|
|
66139dacac | ||
|
|
714c24445d | ||
|
|
79f55a02cb | ||
|
|
484fe22e9e | ||
|
|
119d8b1a81 | ||
|
|
953d1f0aed | ||
|
|
2e225a9452 | ||
|
|
960dc2cd48 | ||
|
|
345ac35649 | ||
|
|
802114c605 | ||
|
|
16bbd30209 | ||
|
|
0021e789bc | ||
|
|
41daebb629 | ||
|
|
b496e88557 | ||
|
|
7c0e10d058 | ||
|
|
1d72447096 | ||
|
|
01e93a642e | ||
|
|
696ae7c967 | ||
|
|
b28202f1cb | ||
|
|
601e15db5a | ||
|
|
f30b413b46 | ||
|
|
a9c4a81abe | ||
|
|
d619ed5798 | ||
|
|
e94a9bf68f | ||
|
|
257c12e727 | ||
|
|
8b3eaa70fb | ||
|
|
c96bb890b4 | ||
|
|
8192a1962a | ||
|
|
80df9c6aa4 | ||
|
|
8073089da4 | ||
|
|
23e7d4a8bb | ||
|
|
0e1e92df13 | ||
|
|
d13f0b9191 | ||
|
|
aa2bffbd00 | ||
|
|
a456d67528 | ||
|
|
95f074342c | ||
|
|
74016bf93e | ||
|
|
3f8bac582c | ||
|
|
6b57e58d63 | ||
|
|
19aa20537d | ||
|
|
cf31df35ec | ||
|
|
6d39ce7240 | ||
|
|
0f3c1b94d7 | ||
|
|
13cc6736e2 | ||
|
|
64629bd878 | ||
|
|
e42be555b1 | ||
|
|
c62c5f5cae | ||
|
|
313bdbd8bf | ||
|
|
765b606e18 | ||
|
|
c0be685846 | ||
|
|
133e4c2c78 | ||
|
|
b7e91ac6d0 |
No files matched your search
@@ -0,0 +1,2 @@
|
||||
*.java diff=java
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
.classpath
|
||||
.project
|
||||
.settings
|
||||
target
|
||||
|
||||
.DS_Store
|
||||
@@ -0,0 +1,7 @@
|
||||
language: java
|
||||
jdk:
|
||||
- oraclejdk7
|
||||
- openjdk7
|
||||
- openjdk6
|
||||
notifications:
|
||||
email: false
|
||||
+426
@@ -1,3 +1,429 @@
|
||||
5.7:
|
||||
- Fixed thread sync issue with FlagStateManager.
|
||||
- Fixed dragon egg region protection not working in certain cases.
|
||||
- Added beacon and anvil usage protection in regions.
|
||||
- Add mobs.block-enderdragon-portal-creation to stop enderdragons
|
||||
from making portals on death.
|
||||
- Fix TNT being lethal in some case when damage was disabled.
|
||||
- Fix snowballs and enderpearls being able to knock players back in
|
||||
pvp deny regions.
|
||||
- Add subcommand support for allowed and blocked command flags.
|
||||
- Add max-players-allowed and max-players-reject-message flags to
|
||||
limit the numbers of players in a region.
|
||||
- Fix players being able to plant cocoa beans in protected areas.
|
||||
- Add an enderpearl flag to prevent players from teleporting to and
|
||||
from regions.
|
||||
- Added mobs.block-other-explosions config setting and other-explosion
|
||||
flag to block explosions caused by uncovered things, such as other
|
||||
plugins. (It doesn't actually have to be a mob)
|
||||
- Fix mob damage setting and flag not blocking the DoT wither effect.
|
||||
- Ghast fireball flag will not block blaze fireballs from lighting things
|
||||
on fire.
|
||||
- Fixed players without region permissions being able to trigger tripwires,
|
||||
use enderchests, use wooden buttons, and put plants in flower pots.
|
||||
- Added mobs.block-zombie-door-destruction setting to stop zombies from
|
||||
breaking down doors while difficulty is set to hard.
|
||||
- Added a texture-pack flag that sends players a texture pack url when in
|
||||
certain regions.
|
||||
|
||||
Thank you to thvortex, Dilandau, tophathacker, and Dark_arc for their contributions this release.
|
||||
|
||||
5.6.5:
|
||||
- Fixed a regression that caused paintings and item frames to no longer be properly
|
||||
protected.
|
||||
|
||||
5.6.4:
|
||||
- Added mobs.block-above-ground-slimes to block slimes spawning naturally above ground.
|
||||
- Added security.deop-everyone-on-join to de-op all players when they join.
|
||||
- Added security.block-in-game-op-command to prevent usage of /op from in-game.
|
||||
- Fixed a NullPointerException in PlayerInteract involving water potions and
|
||||
potion blocking.
|
||||
- Fixed an issue with snowballs being blocked in regions.
|
||||
- Changed dragon eggs to be checked like it is a broken block in regions.
|
||||
- Moved developer's WGBukkit class to package com.sk89q.worldguard.bukkit.
|
||||
|
||||
5.6.3:
|
||||
- Added helper WGBukkit class to get references to WorldGuard from other plugins.
|
||||
- Added physics.vine-like-rope-ladders to make ladders work like vines. As long as the
|
||||
top ladder block is present, ladder blocks will hold even if they have no block
|
||||
behind them, like a rope ladder.
|
||||
- Fixed NullPointerException in PlayerInteractEvent caused by potion blocking.
|
||||
- Fixed mobs.block-{item-frame,painting}-destroy not working.
|
||||
|
||||
Thank you to def for testing the above fixes and features.
|
||||
|
||||
5.6.2:
|
||||
- Fixed potion blocking not working well for splash potions.
|
||||
|
||||
5.6.1:
|
||||
- Added a mycelium-spread region flag.
|
||||
- Added a dynamics.disable-mycelium-spread configuration setting.
|
||||
- Added new gameplay.block-potions option. For example:
|
||||
gameplay:
|
||||
block-potions: [invisibility, speed]
|
||||
- Fixed a bug in the entity explosion event handler that caused a NullPointerException.
|
||||
|
||||
Thank you for gabizou for his contribution in this release.
|
||||
|
||||
5.6:
|
||||
- Added official support for Minecraft 1.4. Support for 1.3.2 (and below) is still
|
||||
provided in this release.
|
||||
- Added support for new and existing explosion types.
|
||||
- Added support for blocking withers with the following settings:
|
||||
mobs:
|
||||
block-wither-explosions: false
|
||||
block-wither-block-damage: false
|
||||
block-wither-skull-explosions: false
|
||||
block-wither-skull-block-damage: true
|
||||
- Added support for blocking item frames (and their use) in protected regions.
|
||||
- Added item frame destruction region flags (if you wish to disable item frame
|
||||
destruction completely).
|
||||
- (Re-)added support for priority R-tree region indexes. This means quicker region lookup,
|
||||
and better support for servers with thousands of regions.
|
||||
- Improved /region info output for -g group flags.
|
||||
- Allowed removing of -g group flags with /region flag.
|
||||
- Allowed /region flag to set group and value at once.
|
||||
- Deleting a region flag now also deletes group flag.
|
||||
- Fixed detection of attack by projectiles to be more accurate.
|
||||
- Fixed support for saving non-string flags in the MySQL region support.
|
||||
- Fixed spurious comma in "Flags:" /region info output.
|
||||
- Fixed players who are not in god mode not receiving damage in PVP areas from
|
||||
enderpearls.
|
||||
- Players will now be told that they are in a no-PvP area if they are in one and
|
||||
attempting to attack someone, or that the player they are attacking is in a
|
||||
no-PvP area, if that is the case instead.
|
||||
- Fixed an issue where region.getId() was lowercase'd each pass of a for loop in
|
||||
MySQLDatabase.updatePoly2dPoints().
|
||||
- Fixed mob damage from projectiles not being properly blocked in regions where
|
||||
applicable.
|
||||
- Changed default region wand to leather (#334).
|
||||
|
||||
Thank you to the following individuals for their contribution:
|
||||
thvortex, Rutr, Glitchfinder, and DarthAndroid.
|
||||
|
||||
5.5.4:
|
||||
- Minecraft 1.3 support.
|
||||
- Fixed /stack dupe bugs.
|
||||
- Added regions.use-creature-spawn-event.
|
||||
- Update for Async chat issue.
|
||||
- Add use flag to cakes.
|
||||
- Report number of plugins loaded in report writer.
|
||||
- Updated fireblal item blocking.
|
||||
- Fixed permissions for /region reload.
|
||||
|
||||
5.5.3:
|
||||
- Added game mode flag.
|
||||
- Added item drop pickup flag to regions.
|
||||
- Added support for fireball item blocking (385).
|
||||
- Added configuration option to allow creature spawns from plugins.
|
||||
- Added host key check.
|
||||
- Added a new line split feature to region greetings.
|
||||
- Prevented commands in the allow commands list from being blocked and
|
||||
vice versa.
|
||||
|
||||
5.5.2:
|
||||
- Added potion-splash flag to block splash potions
|
||||
- Add entity-painting-destroy which can be used to prevent entities from destroying
|
||||
paintings (skeletons firing arrows)
|
||||
- Added send-chat and receive-chat flags
|
||||
- Fixed having regions in multiple worlds with the same name not working with MySQL
|
||||
- A cancellable event is now fired if WorldGuard disallows PvP. (for developers!)
|
||||
- Made /region setparent check worldguard.region.setparent.own/member.<parent> instead
|
||||
of worldguard.region.setparent.own/member.<child>.
|
||||
- Allowed passing #<index> in place of a region ID, where <index> is the index as
|
||||
displayed by /region list.
|
||||
- Fixed an error that occured when clearing a non-existant region's parent.
|
||||
- Added a -s flag to /region teleport, which sends you to the spawn point instead of the
|
||||
teleport point of a region.
|
||||
- Added region/role-based permissions to /region teleport.
|
||||
- BREAKING CHANGE: Added a LocationFlag class and made the teleport and spawn flags
|
||||
use it.
|
||||
- /region info -s now selects the region being queried.
|
||||
- Added /region teleport <id>.
|
||||
- Vector flags can now be set to the current location with the value "here" and to a
|
||||
specific position with x,y,z.
|
||||
- Made /region info show the region you're in if you don't specify an id explicitly.
|
||||
- Prevent block ignition from lightning strikes if lightning is blocked in region. Fixes
|
||||
#1175
|
||||
- Correctly check both WEPIF and superperms in WorldGurdPlugin.broadcastNotification()
|
||||
- Destroy fire blocks when fire-spread is disallowed
|
||||
- Added a construct flag that can be used to restrict block placing/destroying in zones
|
||||
to certain roles.
|
||||
- Added FallingSand to list of intensive entities to be removed with /halt-activiy.
|
||||
- Replaced all usage of CreatureType by EntityType.
|
||||
- Updated to support Bukkit 1.2-R0.3 and newer
|
||||
- Made auto-god-mode disabled by default again.
|
||||
- Added sign protection check disable.
|
||||
- Cleaned up javadoc, deprecated duplicate methods, other cleanup
|
||||
- Added a RegionGroupFlag to evey region flag Using the /region flag command with -g,
|
||||
the region group that the region flag applies to can be set.
|
||||
|
||||
5.5.1:
|
||||
- Fixed attacking with arrows from non-PVP to PVP areas
|
||||
- Compatibility with Bukkit 1.1-R5
|
||||
- Removed broken suppress-tick-sync-warnings config option. See bukkit.yml's setings.warn-on-overload option instead.
|
||||
- Add region and 'can build' information to CommandBook's /whois
|
||||
|
||||
Contributions thanks to: NolanSyKinsley
|
||||
|
||||
5.5:
|
||||
- Removed WorldEdit.jar from the classpath to stop conflicts with Bukkit's plugin loader
|
||||
- Now using Bukkit's tagged logging
|
||||
- Updated to new event system
|
||||
- Flush player flag state cache on world change
|
||||
- Improved compatibility with versions of CommandBook without GodComponent and updated pom dep for 2.0
|
||||
- Added MySQL region storage method.
|
||||
- Made explosions display their animations even when the event was blocked.
|
||||
- Added fallback support for those who don't have a version of CommandBook with GodComponent
|
||||
- Added LIGHTNING flag to DefaultFlag's flagsList Fixes #1026
|
||||
- Removed /god, /heal, /locate, and /stack from WorldGuard to CommandBook. CommandBook is now checked to see whether a player is godded.
|
||||
- Removed remaining usages of org.bukkit.util.config.Configuration
|
||||
- Removed some unused configuration options
|
||||
- Added permission worldguard.region.wand to the region wand
|
||||
- Fixed ProtectedRegion.compareTo.
|
||||
- Fixed FlatRegionManager.getApplicableRegions to return parent regions as well.
|
||||
- Added exp-drops flag to disable experience drops per-region.
|
||||
- Fixed some warnings.
|
||||
- Updated dependency version for WorldGuard from 5.0 to 5.1-SNAPSHOT.
|
||||
- Added support for fireballs shot by players being blocked by the PVP flag.
|
||||
- Now using dynamic command registration
|
||||
- Split off ender dragon block damage from creeper block damage.
|
||||
|
||||
Contributions thanks to: narthollis, DarkArc, Wolvereness, and skeight
|
||||
|
||||
5.4:
|
||||
- Fixed configuration generation on Windows
|
||||
- Fixed intersection calculation for regions
|
||||
- Fixed timer and feeding delay for food flags
|
||||
- Fixed region managers not being created properly (This caused errors related to CREATURE_SPAWN)
|
||||
- Added support for Minecraft 1.0.1 blocks
|
||||
- Added support for enchantments and tool damage (worldguard.stack.damaged is the node) with /stack
|
||||
- Made being in the wg-invincible group respect the configuration's auto-invincible setting
|
||||
- Added per-group region claim limit maximum
|
||||
- Added worldguard.region.addowner.unclaimed.* permission for non-economy region 'buying'
|
||||
- Checking allowed/blocked commands now occurs earlier to override more plugins
|
||||
- Made PVP flag check whether either player is in a pvp deny region for blocking
|
||||
|
||||
Contributions thanks to: epuidokas, wizjany, Turtle9598, and DerFlash
|
||||
|
||||
5.3:
|
||||
- Added new config options and flags to better handle explosions of all types
|
||||
- Added config options and flags for snow, ice, mushroom spread, grass spread,
|
||||
and leaf decay
|
||||
- Added min and max health flags to clamp the values for the existing healing
|
||||
flags
|
||||
- Added hunger flags similar to the existing healing flags
|
||||
- Added an option to disable the use of the move event. This can boost
|
||||
performance on large servers but will disable the greeting/farewell
|
||||
and entry/exit flags
|
||||
- Added flag to prevent pistons (including those that are outside the
|
||||
region, but would affect blocks inside the region)
|
||||
- Added a /wg flushstates [player] command to free players stuck in a
|
||||
region that was exit-deny but no longer exists or the flag was removed
|
||||
- Added a config option to disable xp orb dropping
|
||||
- Added config option to disable redstone wire obsidian generators
|
||||
- Added a vehicle-destroy flag
|
||||
- Added enderman protection config and flag
|
||||
- Allowed and blocked command flags will now fall back to the global region
|
||||
- The worldguard.region.flag.own/member permissions are now
|
||||
worldguard.region.flag.regions.own/member! Please change your permissions
|
||||
accordingly.
|
||||
- Made //stack respect max stack sizes unless the player has the
|
||||
worldguard.stack.illegitimate permission
|
||||
- Setting invincibility flag to deny will override god mode unless the player
|
||||
has worldguard.god.override-regions
|
||||
- The sleep flag will now prevent beds in the nether from
|
||||
exploding if set to deny
|
||||
- Existing regions can no longer be accidentally overwritten.
|
||||
Use /region redefine to move an existing region.
|
||||
- The info command will now sort players alphabetically
|
||||
- Priming TNT by punching it with flint and steal should throw a blacklist
|
||||
event (consistent with old Minecraft versions)
|
||||
- The /stoplag command will now remove xp orbs
|
||||
- Permissions system will use per-world permissions if the provider supports it
|
||||
- Players in vehicles are now subject to entry/exit and greeting/farewell flags
|
||||
- Fixed interact blacklist event not logging correctly
|
||||
- Fixed heal flag taking effect half a block northeast of the region
|
||||
- Fixed a infinite sign dropping bug
|
||||
- Fixed players being able to douse fire by punching it in regions they
|
||||
couldn't build it
|
||||
- Fixed players being able to eat protected cake
|
||||
- Fence gate usage can be blocked with the use flag
|
||||
- Fixed chests being unprotected when they should be in 1.8
|
||||
- Fixed weather config settings not applying when a world was loaded
|
||||
- Fixed explosion handling in certain cases
|
||||
- Fixed arrows working in non-pvp zones
|
||||
- Fixed buckets working on the border of protected regions in certain cases
|
||||
Contributions thanks to:
|
||||
wizjany, zml2008, imjake9, Droolio, epuidokas,
|
||||
EduardBaer, TomyLobo, and halvors
|
||||
|
||||
5.2.2:
|
||||
- Changed configuration saving so empty lists will be added to
|
||||
the configuration files.
|
||||
|
||||
5.2.1:
|
||||
- Add region bounds to /region info
|
||||
- Added the ability to add owners/members to the global region for
|
||||
handling guest groups. Now if there's owners or members on the global
|
||||
region, then those that are not on the list cannot build.
|
||||
- Fixed some flag algorithm issues.
|
||||
- API: Fixed DefaultDomain.size() not counting players.
|
||||
- API: Undeprecated ApplicableRegionSet.allows(StateFlag).
|
||||
|
||||
5.2:
|
||||
- Gave the ability to use color colors and macros in greeting
|
||||
and farewell messages.
|
||||
- Added disable-ice-melting, disable-snow-formation, disable-mushroom-spread,
|
||||
disable-snow-melting, disable-ice-formation.
|
||||
- Added paintings to blacklist support.
|
||||
- Added default.disable-health-regain.
|
||||
- Added auto-invincible-permission setting, which lets you use the permission
|
||||
'worldguard.auto-invincible' to become invincible on join automatically.
|
||||
- Flames won't appear if you are /god'ed now.
|
||||
- Added blocked-cmds region flag to block commands.
|
||||
- Added allowed-cmds region flag to whitelist commands.
|
||||
- Added entry region flag to block entry. Use entry-group to determine who
|
||||
this affects.
|
||||
- Added exit region flag to block exit. Use exit-group to determine who
|
||||
this affects.
|
||||
- Made negative healing possible via the healing flag.
|
||||
- Changed the configuration header messages to be more helpful to new users.
|
||||
- Added a warning about modifying region files by hand.
|
||||
- Improved the API for plugin developers.
|
||||
|
||||
5.1:
|
||||
- A lot of changes.
|
||||
|
||||
4.0-alpha1:
|
||||
- This release is only to fix WorldGuard for Bukkit. Ignore the 4.0
|
||||
label. Just move along. Nothing to see.
|
||||
|
||||
3.2.2:
|
||||
- Changed disable-water-damage to disable-drowning-damage.
|
||||
- Fixed suffocation disable option.
|
||||
- Fixed fire spread blocking.
|
||||
- stopfire and allowfire now work in server console, just like in hMod.
|
||||
|
||||
3.2.1:
|
||||
- Updated for recent Bukkit ItemStack change.
|
||||
|
||||
3.2:
|
||||
- Added regions.default.pvp to control default PvP setting.
|
||||
- Updated WorldGuard for the newer builds of Bukkit.
|
||||
- Fixed creeper explosion blocking.
|
||||
- Added redstone support to sponges, removed classic water.
|
||||
- Fixed item durability disable for hoes.
|
||||
|
||||
|
||||
3.1.2:
|
||||
- Increased the priority of WorldGuard's event handling.
|
||||
|
||||
3.1.1:
|
||||
- Fixed creeper and chest flag conflicting.
|
||||
|
||||
3.1:
|
||||
- Added ability to disable chest protection. New configuration setting
|
||||
(regions.build.chest-access) and new chest flag.
|
||||
- Possibly fixed projectile blocking in no-PvP zones.
|
||||
- Added /regionmembership permission that lets people only change
|
||||
the owners and members of regions they own.
|
||||
|
||||
3.0b2:
|
||||
- Fixed issue where built-in permissions were not (re)loaded.
|
||||
- Fixed /god not working for others.
|
||||
|
||||
3.0b1:
|
||||
- Added parent-child relationships to regions.
|
||||
- Added global build flag.
|
||||
- Improved flag support.
|
||||
- Fixed no-PvP zone messages being sent to the wrong person.
|
||||
- Fixed commands so that they work in a recent version of Bukkit.
|
||||
- Fixed NullPointerException in explode hook.
|
||||
|
||||
2.3.1:
|
||||
- Fixed various cast exceptions with the blacklist loggers.
|
||||
- Added checks for unchecked exceptions when resolving permissions.
|
||||
- Fixed the item durability disable setting changing the damage value on
|
||||
an empty hand.
|
||||
|
||||
2.3:
|
||||
- /god now works very well.
|
||||
- Item (TNT, flint and steel, etc.) blocking should now work.
|
||||
- The TNT blocking configuration variable should now work.
|
||||
- Re-added /heal (not sure where that went), added /slay.
|
||||
- Implemented contact damage disable toggle.
|
||||
- Made all player damage disabling configuration parameters work.
|
||||
- Fixed teleport-on-suffocation setting.
|
||||
- Added /locate <name>, /locate <x> <y> <z>, and /locate that lets you
|
||||
program/change your compass bearing to point to a player's position
|
||||
(not yet live), a position, or back to spawn.
|
||||
- Fixed CSVDatabase spitting an error if the owners list was empty.
|
||||
|
||||
2.2:
|
||||
- Now supports GroupUsers.
|
||||
- Added support for blocking creeper explosions.
|
||||
- Fixed a bug where a player's groups were not being loaded correctly,
|
||||
causing the blacklist group ignore option to not work.
|
||||
|
||||
2.1.1:
|
||||
- Fixed fire spread disable preventing flint and steel too.
|
||||
- Fixed NullPointerException related to the player item event.
|
||||
- Made setup simpler.
|
||||
|
||||
2.1:
|
||||
- Improved Bukkit support.
|
||||
|
||||
2.0beta3:
|
||||
- Fixed NullPointerException inside the ignite hook.
|
||||
|
||||
2.0beta2:
|
||||
- Fixed a NullPointerException in the damage hook.
|
||||
|
||||
2.0beta1:
|
||||
- Added area protection. Use /region or /rg to define regions.
|
||||
|
||||
1.8.1
|
||||
- Fixed NullPointerException.
|
||||
|
||||
1.8
|
||||
- Updated for Minecraft beta.
|
||||
- Blacklist hooks have CHANGED. The new hooks are work better. on-create has
|
||||
been replaced with on-place (for block placement) and on-use
|
||||
(for item usage, light buckets and lighters). The old on-use is now
|
||||
on-right-click although it currently does nothing.
|
||||
- Added coordinates to blacklist file logger.
|
||||
- Added suffocation damage prevention.
|
||||
|
||||
1.7.1
|
||||
- Updated for v0.2.8.
|
||||
|
||||
1.7
|
||||
- Updated for v0.2.6_02 and hMod b129.
|
||||
- Added option to prevent water from damaging particular blocks
|
||||
(Redstone wire, Minecart tracks, etc.). See disable-water-damage-blocks.
|
||||
- /reload WorldGuard should now reload WorldGuard's configuration.
|
||||
- Added wg-invincible and wg-amphibious groups that let you give certain
|
||||
players invincibility or underwater breathing.
|
||||
- Added the ability to disable fall, water, lava, and/or fire damage.
|
||||
- Water/lava bucket blocking should now be more reliable.
|
||||
- Added /stack (alias /;) commands to stack items in your inventory into
|
||||
piles up to 64 items in size. Even unstackable items like signs can be
|
||||
stacked.
|
||||
- /god mode should now let you gain health.
|
||||
- /god mode should now work more reliably.
|
||||
- Caught an error message for when the configuration file does not exist.
|
||||
|
||||
1.6
|
||||
- Added spawn protection that prevents damage when a player spawns.
|
||||
- Added login protection that prevents damage when a player joins.
|
||||
- Added /god. /god can be used on others, provided that the /godother
|
||||
permission is set for the command's user.
|
||||
|
||||
1.5.1
|
||||
- Removed the 'java.lang.NoSuchMethodError: Item.setDamage(I)V' error
|
||||
generated.
|
||||
|
||||
1.5
|
||||
- Removed the block lag fix.
|
||||
- WorldGuard now conditionally loads features so you can use any up-to-date
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
Contributing
|
||||
============
|
||||
|
||||
Thank you for your interest in contributing to WorldGuard! We appreciate your
|
||||
effort, but to make sure that the inclusion of your patch is a smooth process, we
|
||||
ask that you make note of the following guidelines.
|
||||
|
||||
* **Follow the [Oracle coding conventions](http://www.oracle.com/technetwork/java/codeconv-138413.html).**
|
||||
We can't stress this enough; if your code has notable issues, it may delay
|
||||
the process significantly.
|
||||
* **Target Java 6 for source and compilation.** Make sure to mark methods with
|
||||
` @Override` that override methods of parent classes, or that implement
|
||||
methods of interfaces (Java 6+).
|
||||
* **Use only spaces for indentation.** Our indents are 4-spaces long, and tabs
|
||||
are unacceptable.
|
||||
* **Wrap code to a 89 column limit.** We do this to make side by side diffs
|
||||
and other such tasks easier. Ignore this guideline if it makes the code
|
||||
too unreadable.
|
||||
* **Write complete Javadocs.** Do so only for public methods, and make sure
|
||||
that your `@param` and `@return` fields are not just blank.
|
||||
* **Don't tag classes with @author.** Some legacy classes may have this tag,
|
||||
but we are phasing it out.
|
||||
* **Make sure the code is efficient.** One way you can achieve this is to spend
|
||||
around ten minutes to think about what the code is doing and whether it
|
||||
seems awfully roundabout. If you had to copy the same large piece of
|
||||
code in several places, that's bad.
|
||||
* **Keep commit summaries under 70 characters.** For more details, place two
|
||||
new lines after the summary line and write away!
|
||||
* **Test your code.** We're not interested in broken code, for the obvious reasons.
|
||||
* **Write unit tests.** While this is strictly optional, we recommend it for
|
||||
complicated algorithms.
|
||||
|
||||
|
||||
Checklist
|
||||
---------
|
||||
|
||||
Ready to submit? Perform the checklist below:
|
||||
|
||||
1. Have all tabs been replaced into four spaces? Are indentations 4-space wide?
|
||||
2. Have I written proper Javadocs for my public methods? Are the @param and
|
||||
@return fields actually filled out?
|
||||
3. Have I `git rebase`d my pull request to the latest commit of the target
|
||||
branch?
|
||||
4. Have I combined my commits into a reasonably small number (if not one)
|
||||
commit using `git rebase`?
|
||||
5. Have I made my pull request too large? Pull requests should introduce
|
||||
small sets of changes at a time. Major changes should be discussed with
|
||||
the team prior to starting work.
|
||||
6. Are my commit messages descriptive?
|
||||
|
||||
You should be aware of [`git rebase`](http://learn.github.com/p/rebasing.html).
|
||||
It allows you to modify existing commit messages, and combine, break apart, or
|
||||
adjust past changes.
|
||||
|
||||
Example
|
||||
-------
|
||||
|
||||
This is **GOOD:**
|
||||
|
||||
if (var.func(param1, param2)) {
|
||||
// do things
|
||||
}
|
||||
|
||||
This is **EXTREMELY BAD:**
|
||||
|
||||
if(var.func( param1, param2 ))
|
||||
{
|
||||
// do things
|
||||
}
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
Installation
|
||||
------------
|
||||
|
||||
This plugin requires Hey0's server modification.
|
||||
|
||||
1. Create a "plugins" folder inside your "bin" folder.
|
||||
|
||||
2. Copy WorldGuard.jar into "plugins".
|
||||
|
||||
3. Add "WorldGuard" to the "plugins" line of your server.properties file.
|
||||
If it's not already there, add the line. The line should look like this:
|
||||
|
||||
plugins=WorldGuard
|
||||
|
||||
If you have multiple plugins, separate plugin names with commas.
|
||||
+39
-1
@@ -1,3 +1,7 @@
|
||||
----------------------------------------------------------------------------
|
||||
WorldGuard License
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
@@ -162,4 +166,38 @@ General Public License ever published by the Free Software Foundation.
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
||||
Library.
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
PRTree License
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2008-2010 Robert Olofsson.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the authors nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGE.
|
||||
+232
@@ -0,0 +1,232 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>${project.name} ${version}</title>
|
||||
<link href="http://fonts.googleapis.com/css?family=Source+Sans+Pro:400,700|Ropa+Sans" rel="stylesheet" type="text/css">
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 3em 1em;
|
||||
background: #efefef;
|
||||
color: #333;
|
||||
line-height: 1.5;
|
||||
}
|
||||
#wrapper {
|
||||
width: 600px;
|
||||
margin: auto;
|
||||
}
|
||||
body, th, td, input {
|
||||
font: 14px 'Source Sans Pro', Arial, sans-serifsans-serif;
|
||||
}
|
||||
.section {
|
||||
background: #fff;
|
||||
position: relative;
|
||||
padding: 2em 2.4em;
|
||||
margin: 3em auto 4em auto;
|
||||
width: 80%;
|
||||
-webkit-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
|
||||
-moz-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
|
||||
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
.section:before, .section:after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
z-index: -2;
|
||||
}
|
||||
.section {
|
||||
-moz-border-radius: 4px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.section:before, .section:after {
|
||||
bottom: 15px;
|
||||
left: 10px;
|
||||
width: 50%;
|
||||
height: 20%;
|
||||
max-width: 300px;
|
||||
max-height: 100px;
|
||||
-webkit-box-shadow: 0 15px 10px rgba(0, 0, 0, 0.5);
|
||||
-moz-box-shadow: 0 15px 10px rgba(0, 0, 0, 0.5);
|
||||
box-shadow: 0 15px 10px rgba(0, 0, 0, 0.5);
|
||||
-webkit-transform: rotate(-1deg);
|
||||
-moz-transform: rotate(-1deg);
|
||||
-ms-transform: rotate(-1deg);
|
||||
-o-transform: rotate(-1deg);
|
||||
transform: rotate(-1deg);
|
||||
}
|
||||
.section:after {
|
||||
right: 10px;
|
||||
left: auto;
|
||||
-webkit-transform: rotate(1deg);
|
||||
-moz-transform: rotate(1deg);
|
||||
-ms-transform: rotate(1deg);
|
||||
-o-transform: rotate(1deg);
|
||||
transform: rotate(1deg);
|
||||
}
|
||||
a:link, a:visited {
|
||||
color: #0004b2;
|
||||
text-decoration: none;
|
||||
}
|
||||
a:hover {
|
||||
color: #ac0000;
|
||||
text-decoration: none;
|
||||
border-bottom: 1px solid #999;
|
||||
}
|
||||
h1 {
|
||||
font: 2.7em 'Ropa Sans', 'Trebuchet MS', Helvetica, Arial, sans-serif;
|
||||
color: #000;
|
||||
margin: 0 0;
|
||||
padding: 0 0 0.2em 0;
|
||||
font-weight: normal;
|
||||
text-align: center;
|
||||
text-shadow: 2px 2px #FFF;
|
||||
}
|
||||
h2 {
|
||||
font-size: 1.3em;
|
||||
color: #FFF;
|
||||
margin: -2.5em 0 0.8em 0;
|
||||
float: left;
|
||||
background: #0049FF;
|
||||
padding: 0.4em 0.8em;
|
||||
border-radius: 0.2em;
|
||||
font-weight: normal;
|
||||
text-align: center;
|
||||
}
|
||||
h3 {
|
||||
text-transform: uppercase;
|
||||
font-weight: bold;
|
||||
}
|
||||
h2 + * {
|
||||
clear: both;
|
||||
}
|
||||
@media (max-width: 650px) {
|
||||
#wrapper {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="wrapper">
|
||||
<h1>${project.name} ${version}</h1>
|
||||
<div class="section">
|
||||
<h2>Getting Started</h2>
|
||||
<p>
|
||||
Thanks for choosing ${project.name}! When you first install ${project.name},
|
||||
nothing will be enabled, so you will need to switch on the features
|
||||
that you need to use, whenever it is convenient for you.
|
||||
</p>
|
||||
<ul>
|
||||
<li><a href="http://wiki.sk89q.com/wiki/${project.name}/Installation">How do I install ${project.name}?</a></li>
|
||||
<li><a href="http://wiki.sk89q.com/wiki/${project.name}/Upgrading">How do I update ${project.name}?</a></li>
|
||||
<li><a href="http://wiki.sk89q.com/wiki/${project.name}#Usage">How do I use ${project.name}?</a></li>
|
||||
</ul>
|
||||
<p>
|
||||
Need help?
|
||||
<a href="http://wiki.sk89q.com/wiki/${project.name}/Support">See the ways that you can get assistance</a>.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2>Common Issues</h2>
|
||||
|
||||
<h3>What are the other files that come with the download?</h3>
|
||||
<p>
|
||||
Inside the folder "contrib" of the download are the following files:
|
||||
</p>
|
||||
<ul>
|
||||
<li>blacklist_table.sql is for using a database with the
|
||||
<a href="http://wiki.sk89q.com/wiki/${project.name}/Blacklist">blacklist feature</a>.</li>
|
||||
<li>region_storage.sql is for using a database with the
|
||||
<a href="http://wiki.sk89q.com/wiki/${project.name}/Regions">region protection feature</a>.</li>
|
||||
<li>region_storage_update_20110325.sql is for updating your region protection
|
||||
database (if you're using it) if your database was made before March 25, 2011.</li>
|
||||
</ul>
|
||||
|
||||
<h3>${project.name} doesn't seem to work.</h3>
|
||||
<p>
|
||||
Two common mistakes include forgetting to install WorldEdit
|
||||
(${project.name} needs it), or making
|
||||
a syntax error in one of ${project.name}'s configuration files (this is very
|
||||
fatal unfortunately, and can be caused by a single character typed in the wrong place). Try
|
||||
<a href="http://wiki.sk89q.com/wiki/${project.name}/Support">asking in IRC</a>
|
||||
to see whether anyone can help you.
|
||||
</p>
|
||||
|
||||
<h3>How do I protect my spawn, or another area?</h3>
|
||||
<p>
|
||||
Read the <a href="http://wiki.sk89q.com/wiki/${project.name}/Regions/Tutorial">area protection tutorial</a>
|
||||
on our wiki. For more detailed information, be sure to read about
|
||||
<a href="http://wiki.sk89q.com/wiki/WorldGuard/Regions">region protection on the wiki</a>. Note
|
||||
that if you can't build in spawn, don't forget that Minecraft comes with its own
|
||||
limited spawn protection that you have to disable (see below).
|
||||
</p>
|
||||
|
||||
<h3>I or others don't have permission to build.</h3>
|
||||
<p>
|
||||
Unless you copied configuration files from an older installation of
|
||||
${project.name}, your problem is either caused by another plugin, or by not
|
||||
disabling the built-in spawn protection of the Minecraft server.
|
||||
</p>
|
||||
|
||||
<h3>No one can build in a region I made!</h3>
|
||||
<p>
|
||||
Make sure that:
|
||||
</p>
|
||||
<ul>
|
||||
<li>You didn't change the 'build' flag, because protection is on by default
|
||||
when a new region is made. Setting the build flag to 'deny' means that
|
||||
no one can modify the things inside the region.</li>
|
||||
<li>That you added the player as an owner or member of the region. If you are using
|
||||
a group (g:groupName), you may have to give the group the permission of
|
||||
group.groupName for ${project.name} to recognize it.</li>
|
||||
<li>That you disabled spawn protection. The Minecraft server has an automatic
|
||||
spawn protection feature where only 'ops' can build in a definable
|
||||
radius around spawn (by default, it is 16 blocks). If you are on Minecraft
|
||||
1.4 or newer, edit "spawn-protection" in server.properties; otherwise, modify bukkit.yml
|
||||
and change the spawn-radius setting.</li>
|
||||
<li>That it's not another plugin causing you trouble. The error messages of ${project.name} are of
|
||||
a dark red shade. If the color of the "no permission" message is not
|
||||
that color, it is not ${project.name}.</li>
|
||||
</ul>
|
||||
|
||||
<h3>Everyone can build in a region I made!</h3>
|
||||
<p>
|
||||
Make sure that:
|
||||
</p>
|
||||
<ul>
|
||||
<li>You didn't change the 'build' flag, because protection is on by default
|
||||
when a new region is made. Setting the build flag to 'allow' means that
|
||||
anyone can modify the things inside the region.</li>
|
||||
<li>That it's not caused by another plugin. If players are getting a dark red
|
||||
permission denied message, but they can still build, another plugin
|
||||
is likely causing the conflict.</li>
|
||||
</ul>
|
||||
|
||||
<h3>Where do I report bugs or suggest ideas?</h3>
|
||||
<p>
|
||||
Make sure you are using the latest version of ${project.name}, try asking in
|
||||
IRC first (see "Need help?" above) if it's a problem, and if you think you've
|
||||
found a bug or have a great suggestion to provide, please
|
||||
report it to <a href="http://youtrack.sk89q.com/issues/WORLDGUARD">our issue tracker</a>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Still need help?
|
||||
<a href="http://wiki.sk89q.com/wiki/${project.name}/Support">See the ways that you can get assistance</a>.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2>Contributing</h2>
|
||||
<p>
|
||||
Did you know that ${project.name} is open source? That means that you can
|
||||
read the code and learn from it, as well as modify it and submit back
|
||||
changes to help the community!
|
||||
</p>
|
||||
<ul>
|
||||
<li><a href="https://github.com/sk89q/worldguard">View the source code</a></li>
|
||||
<li><a href="http://wiki.sk89q.com/wiki/${project.name}/Development">More information</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,38 @@
|
||||

|
||||
==========
|
||||
|
||||
WorldGuard is a toolbox of various functions, useful for multiplayer servers, that lets you:
|
||||
|
||||
* Protect your server from a number of problems.
|
||||
* Block fire spread, lava spread, endermen, and more.
|
||||
* Flag areas as "no PVP" or "no TNT."
|
||||
* Assign ownership to areas so only selected individuals can build.
|
||||
* Use a number of useful commands.
|
||||
|
||||
WorldGuard is open source and is available under the GNU General Public License v3.
|
||||
|
||||
Compiling
|
||||
---------
|
||||
|
||||
The project is written for Java 6 and our build process makes use of [Maven](http://maven.apache.org). Detailed compilation information [can be found on the wiki](http://wiki.sk89q.com/wiki/WorldGuard/Development#Compiling).
|
||||
|
||||
Dependencies are automatically handled by Maven.
|
||||
|
||||
Contributing
|
||||
------------
|
||||
|
||||
We happily accept contributions, especially through pull requests on GitHub. Submissions
|
||||
must be licensed under the GNU General Public License v3.
|
||||
|
||||
Please read CONTRIBUTING.md for important guidelines to follow.
|
||||
|
||||
We recommend following our [mailing list](https://groups.google.com/d/forum/sk-dev-discuss), especially if you have some big ideas that you want to implement.
|
||||
|
||||
Links
|
||||
-----
|
||||
|
||||
* [Mailing list](https://groups.google.com/d/forum/sk-dev-discuss)
|
||||
* [IRC channel](http://skq.me/irc/irc.esper.net/sk89q/) (#sk89q on irc.esper.net)
|
||||
* [Issue tracker](http://youtrack.sk89q.com/issues/WORLDGUARD)
|
||||
* [Continuous integration](http://build.sk89q.com) [](http://travis-ci.org/sk89q/worldguard)
|
||||
* [End-user documentation](http://wiki.sk89q.com/wiki/WorldGuard)
|
||||
-213
@@ -1,213 +0,0 @@
|
||||
WorldGuard
|
||||
Copyright (c) 2010 sk89q <http://www.sk89q.com>
|
||||
Licensed under the GNU Lesser General Public License v3
|
||||
|
||||
Introduction
|
||||
------------
|
||||
|
||||
WorldGuard has a number of features, any of which you can choose to
|
||||
use or not:
|
||||
|
||||
- Enforce only one session for a player on a server (can't login twice).
|
||||
- Block creeper explosions.
|
||||
- Block TNT explosions.
|
||||
- Block lighters from setting fires.
|
||||
- Block all fires.
|
||||
- Allow fire but prevent it from burning certain blocks.
|
||||
- Prevent lava from starting fires.
|
||||
- Restrict lava spreading to only some block types.
|
||||
- Simulate classic-esque water by letting water infinitely expand in
|
||||
area (only if there is a block underneath).
|
||||
- Simulate the function of the sponge from Minecraft Classic.
|
||||
- Notify admins, block, log, kick or ban for the use of certain block types
|
||||
or items.
|
||||
- Temporarily stop fire globally with some commands.
|
||||
- Destroy tools on drop to alleviate the durability cheat.
|
||||
- OR just fix the durability bug. *Requires special version of hMod
|
||||
- Prevent gravel and sand from falling. *Requires special version of hMod
|
||||
- Allow portal blocks to be placed anywhere.
|
||||
*Requires special version of hMod
|
||||
|
||||
hMod is required as WorldGuard is a plugin for hMod.
|
||||
|
||||
Configuration
|
||||
-------------
|
||||
|
||||
A "worldguard.properties" will be created the first the time that you load
|
||||
WorldGuard on your server. You can either restart your server or use
|
||||
/reloadplugin WorldGuard to reload the configuraton file after editing it.
|
||||
|
||||
NOTE: Some features may require a custom version of hMod. When the server
|
||||
is loaded with the plugin, WorldGuard will tell you the features
|
||||
unsupported by your version of hMod.
|
||||
|
||||
- summary-on-start (def. true)
|
||||
Print a summary of WorldGuard's protection settings at-a-glance when
|
||||
the plugin is loaded.
|
||||
|
||||
- item-durability (def. false)
|
||||
**Requires special version of hMod
|
||||
Enables item durability.
|
||||
|
||||
- classic-water (def. false)
|
||||
Toggle use of classic water. Be foreward that your world may be
|
||||
flooded if you are not careful. If you have WorldEdit, you can use
|
||||
//drain in such an event, although that will drain the entire pool
|
||||
as well. This classic-esque water will only spread infinitely over
|
||||
ground, but if there are air blocks underneath, the water will not
|
||||
spread (preventing waterfalls from becoming tsunamis).
|
||||
|
||||
- simulate-sponge (def. true)
|
||||
Toggle simulation of the sponge from Classic. It blocks water from
|
||||
flowing near the sponge.
|
||||
|
||||
- sponge-radius (def. 3)
|
||||
The radius of the sponge's effect. The default is that of Classic,
|
||||
creating a 5x5x5 cuboid free of water. Increasing the number will
|
||||
increase server load exponentially, although 3-5 has fairly low impact.
|
||||
|
||||
- no-physics-gravel (def. false)
|
||||
**Requires special version of hMod
|
||||
Prevents gravel from falling due to gravity.
|
||||
|
||||
- no-physics-sand (def. false)
|
||||
**Requires special version of hMod
|
||||
Prevents sand from falling due to gravity.
|
||||
|
||||
- allow-portal-anywhere (def. false)
|
||||
**Requires special version of hMod
|
||||
Allows you to place portal blocks anywhere.
|
||||
|
||||
- enforce-single-session (def. true)
|
||||
Enforce single sessions. If the player is already found to be on
|
||||
the server when s/he logs in, the other player will be kicked with
|
||||
an informative message. The inventory will have been saved before
|
||||
the new session starts.
|
||||
|
||||
- block-tnt (def. false)
|
||||
Block TNT explosions. TNT will still explode client-side but the blocks
|
||||
will be "restored" in a few seconds afterwards.
|
||||
|
||||
- block-lighter (def. false)
|
||||
Block flint and steel fires. Those with access to the commands
|
||||
/uselighter or /lighter can bypass this. /uselighter is not a real
|
||||
command; it is only used for permissions.
|
||||
|
||||
- block-creepers (def. false)
|
||||
Block creeper explosions from destroying terrain (and possibly from
|
||||
causing damage).
|
||||
|
||||
- disable-lava-fire (def. true)
|
||||
Prevent lava from starting fires.
|
||||
|
||||
- allowed-lava-spread-blocks (no default)
|
||||
List of block names/IDs to allow lava to spread to. Leave blank
|
||||
to disable this feature.
|
||||
|
||||
- disable-all-fire-spread (def. false)
|
||||
Disable all fire from spreading.
|
||||
|
||||
- disallowed-fire-spread-blocks (no default)
|
||||
List of block names/IDs to prevent fire from spreading to. Leave blank
|
||||
to disable this feature. Enabling disable-all-fire-spread will
|
||||
override this function.
|
||||
|
||||
- item-drop-blacklist (no default)
|
||||
List of block names/IDs to destroy on drop. This can alleviate the
|
||||
durability cheat that allows you to drop your tools to fix their
|
||||
durability. You can also enforce this with the blacklist but
|
||||
this is an easier way to do it (this way also prints a more
|
||||
friendly message than if you used the 'tell' action of the blacklist).
|
||||
|
||||
- log-console (def. true)
|
||||
For blacklist log actions, print to console.
|
||||
|
||||
- log-file (def. false)
|
||||
For blacklist log actions, log to file.
|
||||
|
||||
- log-file-path (def. "worldguard/logs/%Y-%m-%d.log")
|
||||
Log blacklist events to file. You can use these patterns in the path:
|
||||
%Y the year (YYYY)
|
||||
%m the month (MM)
|
||||
%d the day (DD)
|
||||
%W the week of the year (00-52)
|
||||
%H 24-hour time (HH)
|
||||
%h 12-hour time (HH)
|
||||
%i the minute (mm)
|
||||
%s the second (ss)
|
||||
%u the user's name
|
||||
%% translates to a single percent sign "%"
|
||||
The files are not automatically rotated if they get large so you should
|
||||
perhaps put a week in the filename at least.
|
||||
|
||||
Escape backslashes with another backslash, like so:
|
||||
C:\path\to\log.txt -> C:\\path\\to\\log.txt
|
||||
|
||||
- log-file-open-files (def. 10)
|
||||
The number of log files to keep open at once. Unless you use dynamic
|
||||
patterns in the path, the value of this variable won't matter. However,
|
||||
if, for example, you use a player's username in the filename and you
|
||||
have many users who cause logged events to occur, files would have
|
||||
to be opened for each user and this parameter would matter.
|
||||
|
||||
- log-database (def. false)
|
||||
Log blacklist events to database.
|
||||
|
||||
- log-database-dsn (def. "jdbc:mysql://localhost:3306/minecraft")
|
||||
Connection string. A string to use for MySQL would be:
|
||||
jdbc:mysql://localhost:3306/minecraft
|
||||
The "minecraft" part at the end is the database name.
|
||||
|
||||
Escape colons with a backslash, like so:
|
||||
jdbc:mysql://localhost:3306/minecraft
|
||||
->
|
||||
jdbc\:mysql\://localhost\:3306/minecraft
|
||||
|
||||
- log-database-user (def. "root")
|
||||
Database username.
|
||||
|
||||
- log-database-pass (def. "")
|
||||
Database password.
|
||||
|
||||
- log-database-table (def. "blacklist_events")
|
||||
Database table to use.
|
||||
|
||||
Commands
|
||||
--------
|
||||
|
||||
- /stopfire and /allowfire
|
||||
Disables and enables fire spread globally. Both commands require the
|
||||
permission to use only "/stopfire. Re-enabling fire spread with this
|
||||
command will not override other fire spread control features of
|
||||
WorldGuard. Note that disabling fire does not disable fire damage
|
||||
but fire at least won't spread.
|
||||
|
||||
Server Commands
|
||||
---------------
|
||||
|
||||
- fire-stop and fire-allow
|
||||
Disables and enables fire spread globally. Re-enabling fire spread
|
||||
with this command will not override other fire spread control features
|
||||
of WorldGuard. Note that disabling fire does not disable fire damage
|
||||
but fire at least won't spread.
|
||||
|
||||
Blacklists
|
||||
----------
|
||||
|
||||
Blacklists let you control the use of blocks and items. You can have
|
||||
certain rules apply to only some groups.
|
||||
|
||||
Edit the included worldguard-blacklist.txt file and follow the
|
||||
instructions inside. The file comes with the download for WorldGuard.
|
||||
|
||||
Thanks
|
||||
------
|
||||
|
||||
While I would like to thank everyone for their support, I would like to
|
||||
say thanks to the following individuals for their direct
|
||||
contributions to WorldGuard:
|
||||
|
||||
- Sturmeh, for contributing the original durability workaround
|
||||
- Meaglin, for changing the on flow hook at my request
|
||||
- Dinnerbone, for implementing the on item pick up hook at my request,
|
||||
and also for figuring out the durability bug in the process
|
||||
@@ -1,21 +1,24 @@
|
||||
-- Blacklist table for MySQL.
|
||||
-- You must still configure WorldGuard to use your database.
|
||||
-- If you do not plan on using a database for logging blacklist events,
|
||||
-- you do not need to do anything with this file.
|
||||
|
||||
CREATE TABLE `blacklist_events` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`event` varchar(25) NOT NULL,
|
||||
`player` varchar(16) NOT NULL,
|
||||
`x` int(11) NOT NULL,
|
||||
`y` int(11) NOT NULL,
|
||||
`z` int(11) NOT NULL,
|
||||
`item` int(11) NOT NULL,
|
||||
`time` int(11) NOT NULL,
|
||||
`comment` varchar(255) NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
|
||||
-- Required update if you have an older version of the table:
|
||||
|
||||
ALTER TABLE `blacklist_events` ADD `comment` VARCHAR( 255 ) NULL
|
||||
-- Blacklist table for MySQL.
|
||||
-- You must still configure WorldGuard to use your database.
|
||||
-- If you do not plan on using a database for logging blacklist events,
|
||||
-- you do not need to do anything with this file.
|
||||
|
||||
CREATE TABLE `blacklist_events` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`event` varchar(25) NOT NULL,
|
||||
`world` varchar(32) NOT NULL,
|
||||
`player` varchar(16) NOT NULL,
|
||||
`x` int(11) NOT NULL,
|
||||
`y` int(11) NOT NULL,
|
||||
`z` int(11) NOT NULL,
|
||||
`item` int(11) NOT NULL,
|
||||
`time` int(11) NOT NULL,
|
||||
`comment` varchar(255) NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
|
||||
-- Required update if you have an older version of the table:
|
||||
|
||||
ALTER TABLE `blacklist_events` ADD `comment` VARCHAR( 255 ) NULL
|
||||
|
||||
ALTER TABLE `blacklist_events` ADD `world` VARCHAR( 32 ) NOT NULL
|
||||
@@ -0,0 +1,217 @@
|
||||
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
|
||||
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
|
||||
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `group`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `group` (
|
||||
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT ,
|
||||
`name` VARCHAR(64) CHARACTER SET 'utf8' COLLATE 'utf8_bin' NOT NULL ,
|
||||
PRIMARY KEY (`id`) ,
|
||||
UNIQUE INDEX `name` (`name` ASC) )
|
||||
ENGINE = InnoDB
|
||||
AUTO_INCREMENT = 5
|
||||
DEFAULT CHARACTER SET = utf8
|
||||
COLLATE = utf8_bin;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `world`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `world` (
|
||||
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT ,
|
||||
`name` VARCHAR(128) CHARACTER SET 'utf8' COLLATE 'utf8_bin' NOT NULL ,
|
||||
PRIMARY KEY (`id`) ,
|
||||
UNIQUE INDEX `name` (`name` ASC) )
|
||||
ENGINE = InnoDB
|
||||
AUTO_INCREMENT = 9
|
||||
DEFAULT CHARACTER SET = utf8
|
||||
COLLATE = utf8_bin;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `region`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `region` (
|
||||
`id` VARCHAR(128) CHARACTER SET 'utf8' COLLATE 'utf8_bin' NOT NULL ,
|
||||
`world_id` INT(10) UNSIGNED NOT NULL ,
|
||||
`type` ENUM('cuboid','poly2d','global') CHARACTER SET 'utf8' COLLATE 'utf8_bin' NOT NULL ,
|
||||
`priority` SMALLINT(6) NOT NULL DEFAULT '0' ,
|
||||
`parent` VARCHAR(128) CHARACTER SET 'utf8' COLLATE 'utf8_bin' NULL DEFAULT NULL ,
|
||||
PRIMARY KEY (`id`, `world_id`) ,
|
||||
INDEX `fk_region_world` (`world_id` ASC) ,
|
||||
INDEX `parent` (`parent` ASC) ,
|
||||
CONSTRAINT `fk_region_world1`
|
||||
FOREIGN KEY (`world_id` )
|
||||
REFERENCES `world` (`id` )
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE,
|
||||
CONSTRAINT `parent`
|
||||
FOREIGN KEY (`parent` )
|
||||
REFERENCES `region` (`id` )
|
||||
ON DELETE SET NULL
|
||||
ON UPDATE CASCADE)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = utf8
|
||||
COLLATE = utf8_bin;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `region_cuboid`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `region_cuboid` (
|
||||
`region_id` VARCHAR(128) CHARACTER SET 'utf8' COLLATE 'utf8_bin' NOT NULL ,
|
||||
`world_id` INT(10) UNSIGNED NOT NULL ,
|
||||
`min_x` BIGINT(20) NOT NULL ,
|
||||
`min_y` BIGINT(20) NOT NULL ,
|
||||
`min_z` BIGINT(20) NOT NULL ,
|
||||
`max_x` BIGINT(20) NOT NULL ,
|
||||
`max_y` BIGINT(20) NOT NULL ,
|
||||
`max_z` BIGINT(20) NOT NULL ,
|
||||
PRIMARY KEY (`region_id`, `world_id`) ,
|
||||
INDEX `fk_region_cuboid_region` (`region_id` ASC) ,
|
||||
CONSTRAINT `fk_region_cuboid_region`
|
||||
FOREIGN KEY (`region_id` , `world_id` )
|
||||
REFERENCES `region` (`id` , `world_id` )
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = utf8
|
||||
COLLATE = utf8_bin;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `region_flag`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `region_flag` (
|
||||
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT ,
|
||||
`region_id` VARCHAR(128) CHARACTER SET 'utf8' COLLATE 'utf8_bin' NOT NULL ,
|
||||
`world_id` INT(10) UNSIGNED NOT NULL ,
|
||||
`flag` VARCHAR(45) CHARACTER SET 'utf8' COLLATE 'utf8_bin' NOT NULL ,
|
||||
`value` VARCHAR(256) CHARACTER SET 'utf8' COLLATE 'utf8_bin' NOT NULL ,
|
||||
PRIMARY KEY (`id`) ,
|
||||
INDEX `fk_flags_region` (`region_id` ASC, `world_id` ASC) ,
|
||||
CONSTRAINT `fk_flags_region`
|
||||
FOREIGN KEY (`region_id` , `world_id` )
|
||||
REFERENCES `region` (`id` , `world_id` )
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE)
|
||||
ENGINE = InnoDB
|
||||
AUTO_INCREMENT = 3246
|
||||
DEFAULT CHARACTER SET = utf8
|
||||
COLLATE = utf8_bin;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `region_groups`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `region_groups` (
|
||||
`region_id` VARCHAR(128) CHARACTER SET 'utf8' COLLATE 'utf8_bin' NOT NULL ,
|
||||
`world_id` INT(10) UNSIGNED NOT NULL ,
|
||||
`group_id` INT(10) UNSIGNED NOT NULL ,
|
||||
`owner` TINYINT(1) NOT NULL ,
|
||||
PRIMARY KEY (`region_id`, `world_id`, `group_id`) ,
|
||||
INDEX `fk_region_groups_region` (`region_id` ASC) ,
|
||||
INDEX `fk_region_groups_group` (`group_id` ASC) ,
|
||||
CONSTRAINT `fk_region_groups_group`
|
||||
FOREIGN KEY (`group_id` )
|
||||
REFERENCES `group` (`id` )
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_region_groups_region`
|
||||
FOREIGN KEY (`region_id` , `world_id` )
|
||||
REFERENCES `region` (`id` , `world_id` )
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = utf8
|
||||
COLLATE = utf8_bin;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `user`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `user` (
|
||||
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT ,
|
||||
`name` VARCHAR(64) CHARACTER SET 'utf8' COLLATE 'utf8_bin' NOT NULL ,
|
||||
PRIMARY KEY (`id`) ,
|
||||
UNIQUE INDEX `name` (`name` ASC) )
|
||||
ENGINE = InnoDB
|
||||
AUTO_INCREMENT = 82
|
||||
DEFAULT CHARACTER SET = utf8
|
||||
COLLATE = utf8_bin;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `region_players`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `region_players` (
|
||||
`region_id` VARCHAR(128) CHARACTER SET 'utf8' COLLATE 'utf8_bin' NOT NULL ,
|
||||
`world_id` INT(10) UNSIGNED NOT NULL ,
|
||||
`user_id` INT(10) UNSIGNED NOT NULL ,
|
||||
`owner` TINYINT(1) NOT NULL ,
|
||||
PRIMARY KEY (`region_id`, `world_id`, `user_id`) ,
|
||||
INDEX `fk_region_players_region` (`region_id` ASC) ,
|
||||
INDEX `fk_region_users_user` (`user_id` ASC) ,
|
||||
CONSTRAINT `fk_region_users_region`
|
||||
FOREIGN KEY (`region_id` , `world_id` )
|
||||
REFERENCES `region` (`id` , `world_id` )
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_region_users_user`
|
||||
FOREIGN KEY (`user_id` )
|
||||
REFERENCES `user` (`id` )
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = utf8
|
||||
COLLATE = utf8_bin;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `region_poly2d`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `region_poly2d` (
|
||||
`region_id` VARCHAR(128) CHARACTER SET 'utf8' COLLATE 'utf8_bin' NOT NULL ,
|
||||
`world_id` INT(10) UNSIGNED NOT NULL ,
|
||||
`min_y` INT(11) NOT NULL ,
|
||||
`max_y` INT(11) NOT NULL ,
|
||||
PRIMARY KEY (`region_id`, `world_id`) ,
|
||||
INDEX `fk_region_poly2d_region` (`region_id` ASC) ,
|
||||
CONSTRAINT `fk_region_poly2d_region`
|
||||
FOREIGN KEY (`region_id` , `world_id` )
|
||||
REFERENCES `region` (`id` , `world_id` )
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = utf8
|
||||
COLLATE = utf8_bin;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `region_poly2d_point`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `region_poly2d_point` (
|
||||
`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT ,
|
||||
`region_id` VARCHAR(128) CHARACTER SET 'utf8' COLLATE 'utf8_bin' NOT NULL ,
|
||||
`world_id` INT(10) UNSIGNED NOT NULL ,
|
||||
`x` BIGINT(20) NOT NULL ,
|
||||
`z` BIGINT(20) NOT NULL ,
|
||||
PRIMARY KEY (`id`) ,
|
||||
INDEX `fk_region_poly2d_point_region_poly2d` (`region_id` ASC, `world_id` ASC) ,
|
||||
CONSTRAINT `fk_region_poly2d_point_region_poly2d`
|
||||
FOREIGN KEY (`region_id` , `world_id` )
|
||||
REFERENCES `region_poly2d` (`region_id` , `world_id` )
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE)
|
||||
ENGINE = InnoDB
|
||||
AUTO_INCREMENT = 15
|
||||
DEFAULT CHARACTER SET = utf8
|
||||
COLLATE = utf8_bin;
|
||||
|
||||
|
||||
|
||||
SET SQL_MODE=@OLD_SQL_MODE;
|
||||
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
|
||||
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
|
||||
@@ -0,0 +1,106 @@
|
||||
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
|
||||
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
|
||||
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';
|
||||
|
||||
ALTER TABLE `region_cuboid` DROP FOREIGN KEY `fk_region_cuboid_region` ;
|
||||
|
||||
ALTER TABLE `region_flag` DROP FOREIGN KEY `fk_flags_region1` ;
|
||||
|
||||
ALTER TABLE `region_groups` DROP FOREIGN KEY `fk_region_groups_region` ;
|
||||
|
||||
ALTER TABLE `region_players` DROP FOREIGN KEY `fk_region_players_user` , DROP FOREIGN KEY `fk_region_players_region` ;
|
||||
|
||||
ALTER TABLE `region_poly2d` DROP FOREIGN KEY `fk_region_poly2d_region` ;
|
||||
|
||||
ALTER TABLE `region_poly2d_point` DROP FOREIGN KEY `fk_region_poly2d_point_region_poly2d` ;
|
||||
|
||||
ALTER TABLE `group` COLLATE = utf8_bin ;
|
||||
|
||||
ALTER TABLE `region_cuboid` COLLATE = utf8_bin , ADD COLUMN `world_id` INT(10) UNSIGNED NOT NULL AFTER `region_id` , CHANGE COLUMN `min_x` `min_x` BIGINT(20) NOT NULL AFTER `world_id` , CHANGE COLUMN `min_y` `min_y` BIGINT(20) NOT NULL AFTER `min_x` , CHANGE COLUMN `max_x` `max_x` BIGINT(20) NOT NULL AFTER `min_z` , CHANGE COLUMN `max_y` `max_y` BIGINT(20) NOT NULL AFTER `max_x` ,
|
||||
ADD CONSTRAINT `fk_region_cuboid_region`
|
||||
FOREIGN KEY (`region_id` , `world_id` )
|
||||
REFERENCES `region` (`id` , `world_id` )
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE
|
||||
, DROP PRIMARY KEY
|
||||
, ADD PRIMARY KEY (`region_id`, `world_id`) ;
|
||||
|
||||
ALTER TABLE `region_flag` COLLATE = utf8_bin , ADD COLUMN `world_id` INT(10) UNSIGNED NOT NULL AFTER `region_id` , CHANGE COLUMN `flag` `flag` VARCHAR(45) CHARACTER SET 'utf8' COLLATE 'utf8_bin' NOT NULL ,
|
||||
ADD CONSTRAINT `fk_flags_region`
|
||||
FOREIGN KEY (`region_id` , `world_id` )
|
||||
REFERENCES `region` (`id` , `world_id` )
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE
|
||||
, DROP INDEX `fk_flags_region`
|
||||
, ADD INDEX `fk_flags_region` (`region_id` ASC, `world_id` ASC) ;
|
||||
|
||||
ALTER TABLE `region_groups` COLLATE = utf8_bin , ADD COLUMN `world_id` INT(10) UNSIGNED NOT NULL AFTER `region_id` , DROP FOREIGN KEY `fk_region_groups_group` ;
|
||||
|
||||
ALTER TABLE `region_groups`
|
||||
ADD CONSTRAINT `fk_region_groups_group`
|
||||
FOREIGN KEY (`group_id` )
|
||||
REFERENCES `group` (`id` )
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE,
|
||||
ADD CONSTRAINT `fk_region_groups_region`
|
||||
FOREIGN KEY (`region_id` , `world_id` )
|
||||
REFERENCES `region` (`id` , `world_id` )
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE
|
||||
, DROP PRIMARY KEY
|
||||
, ADD PRIMARY KEY (`region_id`, `world_id`, `group_id`) ;
|
||||
|
||||
ALTER TABLE `region_players` COLLATE = utf8_bin , ADD COLUMN `world_id` INT(10) UNSIGNED NOT NULL AFTER `region_id` ,
|
||||
ADD CONSTRAINT `fk_region_users_region`
|
||||
FOREIGN KEY (`region_id` , `world_id` )
|
||||
REFERENCES `region` (`id` , `world_id` )
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE,
|
||||
ADD CONSTRAINT `fk_region_users_user`
|
||||
FOREIGN KEY (`user_id` )
|
||||
REFERENCES `user` (`id` )
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE
|
||||
, DROP PRIMARY KEY
|
||||
, ADD PRIMARY KEY (`region_id`, `world_id`, `user_id`)
|
||||
, ADD INDEX `fk_region_users_user` (`user_id` ASC)
|
||||
, DROP INDEX `fk_region_players_user` ;
|
||||
|
||||
ALTER TABLE `region_poly2d` COLLATE = utf8_bin , ADD COLUMN `world_id` INT(10) UNSIGNED NOT NULL AFTER `region_id` , CHANGE COLUMN `min_y` `min_y` INT(11) NOT NULL AFTER `world_id` ,
|
||||
ADD CONSTRAINT `fk_region_poly2d_region`
|
||||
FOREIGN KEY (`region_id` , `world_id` )
|
||||
REFERENCES `region` (`id` , `world_id` )
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE
|
||||
, DROP PRIMARY KEY
|
||||
, ADD PRIMARY KEY (`region_id`, `world_id`) ;
|
||||
|
||||
ALTER TABLE `region_poly2d_point` COLLATE = utf8_bin , ADD COLUMN `world_id` INT(10) UNSIGNED NOT NULL AFTER `region_id` , CHANGE COLUMN `x` `x` BIGINT(20) NOT NULL AFTER `world_id` ,
|
||||
ADD CONSTRAINT `fk_region_poly2d_point_region_poly2d`
|
||||
FOREIGN KEY (`region_id` , `world_id` )
|
||||
REFERENCES `region_poly2d` (`region_id` , `world_id` )
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE
|
||||
, DROP INDEX `fk_region_poly2d_point_region_poly2d`
|
||||
, ADD INDEX `fk_region_poly2d_point_region_poly2d` (`region_id` ASC, `world_id` ASC) ;
|
||||
|
||||
ALTER TABLE `user` COLLATE = utf8_bin ;
|
||||
|
||||
ALTER TABLE `world` COLLATE = utf8_bin ;
|
||||
|
||||
|
||||
UPDATE `region_cuboid` AS c SET c.`world_id` = (SELECT p.`world_id` FROM `region` AS p WHERE p.`id` = c.`region_id`);
|
||||
|
||||
UPDATE `region_flag` AS c SET c.`world_id` = (SELECT p.`world_id` FROM `region` AS p WHERE p.`id` = c.`region_id`);
|
||||
|
||||
UPDATE `region_groups` AS c SET c.`world_id` = (SELECT p.`world_id` FROM `region` AS p WHERE p.`id` = c.`region_id`);
|
||||
|
||||
UPDATE `region_players` AS c SET c.`world_id` = (SELECT p.`world_id` FROM `region` AS p WHERE p.`id` = c.`region_id`);
|
||||
|
||||
UPDATE `region_poly2d` AS c SET c.`world_id` = (SELECT p.`world_id` FROM `region` AS p WHERE p.`id` = c.`region_id`);
|
||||
|
||||
UPDATE `region_poly2d_point` AS c SET c.`world_id` = (SELECT p.`world_id` FROM `region` AS p WHERE p.`id` = c.`region_id`);
|
||||
|
||||
SET SQL_MODE=@OLD_SQL_MODE;
|
||||
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
|
||||
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
|
||||
@@ -1,2 +0,0 @@
|
||||
Manifest-Version: 1.0
|
||||
WorldGuard-Version: 1.5
|
||||
@@ -0,0 +1,240 @@
|
||||
<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.sk89q</groupId>
|
||||
<artifactId>worldguard</artifactId>
|
||||
<version>5.7</version>
|
||||
<name>WorldGuard</name>
|
||||
<description>WorldGuard protects your Minecraft servers.</description>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>GNU General Public License 2.0</name>
|
||||
<url>LICENSE.txt</url>
|
||||
<distribution>repo</distribution>
|
||||
<comments>License on all contributions</comments>
|
||||
</license>
|
||||
</licenses>
|
||||
<scm>
|
||||
<connection>scm:git:git://github.com/sk89q/worldguard.git</connection>
|
||||
<url>https://github.com/sk89q/worldguard</url>
|
||||
<tag>master</tag>
|
||||
<developerConnection>scm:git:git@github.com:sk89q/worldguard.git</developerConnection>
|
||||
</scm>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>sk89q-repo</id>
|
||||
<url>http://maven.sk89q.com/repo/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>zml-repo</id>
|
||||
<url>http://files.zachsthings.com/repo</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>bukkit-repo</id>
|
||||
<url>http://repo.bukkit.org/content/groups/public</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>worldedit</artifactId>
|
||||
<version>5.4.4</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.4.5-R1.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>commandbook</artifactId>
|
||||
<version>2.1</version>
|
||||
<scope>compile</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.zachsthings.libcomponents</groupId>
|
||||
<artifactId>libcomponents-bukkit</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.spout</groupId>
|
||||
<artifactId>spoutapi</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.nijikokun</groupId>
|
||||
<artifactId>iconomy</artifactId>
|
||||
<version>5.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.khelekore</groupId>
|
||||
<artifactId>prtree</artifactId>
|
||||
<version>1.5.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sf.opencsv</groupId>
|
||||
<artifactId>opencsv</artifactId>
|
||||
<version>2.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<distributionManagement>
|
||||
<site>
|
||||
<id>sk89q-docs-upload</id>
|
||||
<url>ftp://sk89q-maven-deploy/worldguard/</url>
|
||||
</site>
|
||||
</distributionManagement>
|
||||
<build>
|
||||
<defaultGoal>install</defaultGoal>
|
||||
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
|
||||
|
||||
<extensions>
|
||||
<extension>
|
||||
<groupId>org.apache.maven.wagon</groupId>
|
||||
<artifactId>wagon-ftp</artifactId>
|
||||
<version>1.0-beta-6</version>
|
||||
</extension>
|
||||
</extensions>
|
||||
|
||||
<resources>
|
||||
<resource>
|
||||
<targetPath>.</targetPath>
|
||||
<filtering>true</filtering>
|
||||
<directory>${basedir}/src/main/resources/</directory>
|
||||
<includes>
|
||||
<include>plugin.yml</include>
|
||||
</includes>
|
||||
</resource>
|
||||
<resource>
|
||||
<targetPath>defaults/</targetPath>
|
||||
<filtering>true</filtering>
|
||||
<directory>${basedir}/src/main/resources/</directory>
|
||||
<includes>
|
||||
<include>config.yml</include>
|
||||
<include>config_world.yml</include>
|
||||
<include>blacklist.txt</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.3.1</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<addMavenDescriptor>true</addMavenDescriptor>
|
||||
<manifest>
|
||||
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
|
||||
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
|
||||
</manifest>
|
||||
<manifestEntries>
|
||||
<Class-Path>WorldGuard/WorldEdit.jar lib/WorldEdit.jar ../lib/WorldEdit.jar ../WorldEdit.jar</Class-Path>
|
||||
</manifestEntries>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>1.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>net.sf.opencsv:opencsv</include>
|
||||
<include>org.khelekore:prtree</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>2.2-beta-2</version>
|
||||
<configuration>
|
||||
<descriptor>${basedir}/src/main/assembly/default.xml</descriptor>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>release</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-release-plugin</artifactId>
|
||||
<version>2.2.2</version>
|
||||
<configuration>
|
||||
<preparationGoals>assembly:assembly</preparationGoals>
|
||||
<goals>assembly:assembly</goals>
|
||||
<tagNameFormat>@{project.version}</tagNameFormat>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-site-plugin</artifactId>
|
||||
<version>3.1</version>
|
||||
<configuration>
|
||||
<reportPlugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||
<version>2.5</version>
|
||||
<reportSets>
|
||||
<reportSet>
|
||||
<reports>
|
||||
<report>license</report>
|
||||
<report>index</report>
|
||||
</reports>
|
||||
</reportSet>
|
||||
</reportSets>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>2.8.1</version>
|
||||
</plugin>
|
||||
</reportPlugins>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -1,694 +0,0 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import java.util.logging.Logger;
|
||||
import java.util.logging.Level;
|
||||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class BlacklistEntry {
|
||||
/**
|
||||
* Used to prevent spamming.
|
||||
*/
|
||||
private static Map<String,BlacklistTrackedEvent> lastAffected =
|
||||
new HashMap<String,BlacklistTrackedEvent>();
|
||||
/**
|
||||
* Parent blacklist entry.
|
||||
*/
|
||||
private Blacklist blacklist;
|
||||
/**
|
||||
* List of groups to not affect.
|
||||
*/
|
||||
private Set<String> ignoreGroups;
|
||||
/**
|
||||
* List of actions to perform on destruction.
|
||||
*/
|
||||
private String[] destroyActions;
|
||||
/**
|
||||
* List of actions to perform on break.
|
||||
*/
|
||||
private String[] breakActions;
|
||||
/**
|
||||
* List of actions to perform on left click.
|
||||
*/
|
||||
private String[] destroyWithActions;
|
||||
/**
|
||||
* List of actions to perform on right click.
|
||||
*/
|
||||
private String[] createActions;
|
||||
/**
|
||||
* List of actions to perform on right click upon.
|
||||
*/
|
||||
private String[] useActions;
|
||||
/**
|
||||
* List of actions to perform on drop.
|
||||
*/
|
||||
private String[] dropActions;
|
||||
/**
|
||||
* List of actions to perform on drop.
|
||||
*/
|
||||
private String[] acquireActions;
|
||||
/**
|
||||
* Message for users.
|
||||
*/
|
||||
private String message;
|
||||
/**
|
||||
* Comment for administrators.
|
||||
*/
|
||||
private String comment;
|
||||
|
||||
/**
|
||||
* Used to ignore messages.
|
||||
*/
|
||||
private static ActionHandler silentHandler = new ActionHandler() {
|
||||
public void log(String itemName) {}
|
||||
public void kick(String itemName) {}
|
||||
public void ban(String itemName) {}
|
||||
public void notifyAdmins(String itemName) {}
|
||||
public void tell(String itemName) {}
|
||||
};
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param blacklist
|
||||
*/
|
||||
public BlacklistEntry(Blacklist blacklist) {
|
||||
this.blacklist = blacklist;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the ignoreGroups
|
||||
*/
|
||||
public String[] getIgnoreGroups() {
|
||||
return ignoreGroups.toArray(new String[ignoreGroups.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ignoreGroups the ignoreGroups to set
|
||||
*/
|
||||
public void setIgnoreGroups(String[] ignoreGroups) {
|
||||
Set<String> ignoreGroupsSet = new HashSet<String>();
|
||||
for (String group : ignoreGroups) {
|
||||
ignoreGroupsSet.add(group.toLowerCase());
|
||||
}
|
||||
this.ignoreGroups = ignoreGroupsSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String[] getDestroyActions() {
|
||||
return destroyActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param actions
|
||||
*/
|
||||
public void setDestroyActions(String[] actions) {
|
||||
this.destroyActions = actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String[] getBreakActions() {
|
||||
return breakActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param actions
|
||||
*/
|
||||
public void setBreakActions(String[] actions) {
|
||||
this.breakActions = actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String[] getDestroyWithActions() {
|
||||
return destroyWithActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param action
|
||||
*/
|
||||
public void setDestroyWithActions(String[] actions) {
|
||||
this.destroyWithActions = actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the rightClickActions
|
||||
*/
|
||||
public String[] getCreateActions() {
|
||||
return createActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param actions
|
||||
*/
|
||||
public void setCreateActions(String[] actions) {
|
||||
this.createActions = actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String[] getUseActions() {
|
||||
return useActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param actions
|
||||
*/
|
||||
public void setUseActions(String[] actions) {
|
||||
this.useActions = actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String[] getDropActions() {
|
||||
return dropActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param actions
|
||||
*/
|
||||
public void setDropActions(String[] actions) {
|
||||
this.dropActions = actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String[] getAcquireActions() {
|
||||
return acquireActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param actions
|
||||
*/
|
||||
public void setAcquireActions(String[] actions) {
|
||||
this.acquireActions = actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the message
|
||||
*/
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message the message to set
|
||||
*/
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the comment
|
||||
*/
|
||||
public String getComment() {
|
||||
return comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param comment the comment to set
|
||||
*/
|
||||
public void setComment(String comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this player should be ignored.
|
||||
*
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean shouldIgnore(Player player) {
|
||||
if (ignoreGroups == null) {
|
||||
return false;
|
||||
}
|
||||
for (String group : player.getGroups()) {
|
||||
if (ignoreGroups.contains(group.toLowerCase())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Announces a message to all administrators.
|
||||
*
|
||||
* @param str
|
||||
*/
|
||||
public void notifyAdmins(String str) {
|
||||
for (Player player : etc.getServer().getPlayerList()) {
|
||||
if (player.canUseCommand("/wprotectalerts")
|
||||
|| player.canUseCommand("/worldguardnotify")) {
|
||||
player.sendMessage(Colors.LightGray + "WG: " + str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ban a player.
|
||||
*
|
||||
* @param player
|
||||
* @param msg
|
||||
*/
|
||||
public void banPlayer(Player player, String msg) {
|
||||
etc.getServer().ban(player.getName());
|
||||
etc.getLoader().callHook(PluginLoader.Hook.BAN, new Object[]{
|
||||
player.getUser(), player.getUser(), msg
|
||||
});
|
||||
player.kick(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on block destruction. Returns true to let the action pass
|
||||
* through.
|
||||
*
|
||||
* @param block
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean onDestroy(final Block block, final Player player) {
|
||||
if (destroyActions == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final BlacklistEntry entry = this;
|
||||
|
||||
ActionHandler handler = new ActionHandler() {
|
||||
public void log(String itemName) {
|
||||
blacklist.getLogger().logDestroyAttempt(player, block, comment);
|
||||
}
|
||||
public void kick(String itemName) {
|
||||
player.kick("You are not allowed to destroy " + itemName);
|
||||
}
|
||||
public void ban(String itemName) {
|
||||
entry.banPlayer(player, "Banned: You are not allowed to destroy " + itemName);
|
||||
}
|
||||
public void notifyAdmins(String itemName) {
|
||||
entry.notifyAdmins(player.getName() + " (destroy) " + itemName
|
||||
+ (comment != null ? " (" + comment + ")" : "") + ".");
|
||||
}
|
||||
public void tell(String itemName) {
|
||||
player.sendMessage(Colors.Yellow + "You are not allowed to destroy " + itemName + ".");
|
||||
}
|
||||
};
|
||||
|
||||
return process(block.getType(), player, destroyActions, handler, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on block break. Returns true to let the action pass
|
||||
* through.
|
||||
*
|
||||
* @param block
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean onBreak(final Block block, final Player player) {
|
||||
if (breakActions == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final BlacklistEntry entry = this;
|
||||
|
||||
ActionHandler handler = new ActionHandler() {
|
||||
public void log(String itemName) {
|
||||
blacklist.getLogger().logBreakAttempt(player, block, comment);
|
||||
}
|
||||
public void kick(String itemName) {
|
||||
player.kick("You are not allowed to break " + itemName);
|
||||
}
|
||||
public void ban(String itemName) {
|
||||
entry.banPlayer(player, "Banned: You are not allowed to break " + itemName);
|
||||
}
|
||||
public void notifyAdmins(String itemName) {
|
||||
entry.notifyAdmins(player.getName() + " (break) " + itemName
|
||||
+ (comment != null ? " (" + comment + ")" : "") + ".");
|
||||
}
|
||||
public void tell(String itemName) {
|
||||
player.sendMessage(Colors.Yellow + "You are not allowed to break " + itemName + ".");
|
||||
}
|
||||
};
|
||||
|
||||
return process(block.getType(), player, breakActions, handler, true, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on left click. Returns true to let the action pass through.
|
||||
*
|
||||
* @param item
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean onDestroyWith(final int item, final Player player) {
|
||||
if (destroyWithActions == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final BlacklistEntry entry = this;
|
||||
|
||||
ActionHandler handler = new ActionHandler() {
|
||||
public void log(String itemName) {
|
||||
blacklist.getLogger().logDestroyWithAttempt(player, item, comment);
|
||||
}
|
||||
public void kick(String itemName) {
|
||||
player.kick("You can't destroy with " + itemName);
|
||||
}
|
||||
public void ban(String itemName) {
|
||||
entry.banPlayer(player, "Banned: You can't destroy with " + itemName);
|
||||
}
|
||||
public void notifyAdmins(String itemName) {
|
||||
entry.notifyAdmins(player.getName() + " (destroy w/) " + itemName
|
||||
+ (comment != null ? " (" + comment + ")" : "") + ".");
|
||||
}
|
||||
public void tell(String itemName) {
|
||||
player.sendMessage(Colors.Yellow + "You can't destroy with " + itemName + ".");
|
||||
}
|
||||
};
|
||||
|
||||
return process(item, player, destroyWithActions, handler, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on right click. Returns true to let the action pass through.
|
||||
*
|
||||
* @param item
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean onCreate(final int item, final Player player) {
|
||||
if (createActions == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final BlacklistEntry entry = this;
|
||||
|
||||
ActionHandler handler = new ActionHandler() {
|
||||
public void log(String itemName) {
|
||||
blacklist.getLogger().logCreateAttempt(player, item, comment);
|
||||
}
|
||||
public void kick(String itemName) {
|
||||
player.kick("You can't place " + itemName);
|
||||
}
|
||||
public void ban(String itemName) {
|
||||
entry.banPlayer(player, "Banned: You can't place " + itemName);
|
||||
}
|
||||
public void notifyAdmins(String itemName) {
|
||||
entry.notifyAdmins(player.getName() + " (place) " + itemName
|
||||
+ (comment != null ? " (" + comment + ")" : "") + ".");
|
||||
}
|
||||
public void tell(String itemName) {
|
||||
player.sendMessage(Colors.Yellow + "You can't place " + itemName + ".");
|
||||
}
|
||||
};
|
||||
|
||||
return process(item, player, createActions, handler, true, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on right click upon. Returns true to let the action pass through.
|
||||
*
|
||||
* @param item
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean onUse(final Block block, final Player player) {
|
||||
if (useActions == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final BlacklistEntry entry = this;
|
||||
|
||||
ActionHandler handler = new ActionHandler() {
|
||||
public void log(String itemName) {
|
||||
blacklist.getLogger().logUseAttempt(player, block, comment);
|
||||
}
|
||||
public void kick(String itemName) {
|
||||
player.kick("You can't use " + itemName);
|
||||
}
|
||||
public void ban(String itemName) {
|
||||
entry.banPlayer(player, "Banned: You can't use " + itemName);
|
||||
}
|
||||
public void notifyAdmins(String itemName) {
|
||||
entry.notifyAdmins(player.getName() + " (use) " + itemName
|
||||
+ (comment != null ? " (" + comment + ")" : "") + ".");
|
||||
}
|
||||
public void tell(String itemName) {
|
||||
player.sendMessage(Colors.Yellow + "You're not allowed to use " + itemName + ".");
|
||||
}
|
||||
};
|
||||
|
||||
return process(block.getType(), player, useActions, handler, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on right click upon. Returns true to let the action pass through.
|
||||
*
|
||||
* @param item
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean onSilentUse(final Block block, final Player player) {
|
||||
if (useActions == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return process(block.getType(), player, useActions, silentHandler, false, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on item drop. Returns true to let the action pass through.
|
||||
*
|
||||
* @param item
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean onDrop(final int item, final Player player) {
|
||||
if (dropActions == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final BlacklistEntry entry = this;
|
||||
|
||||
ActionHandler handler = new ActionHandler() {
|
||||
public void log(String itemName) {
|
||||
blacklist.getLogger().logDropAttempt(player, item, comment);
|
||||
}
|
||||
public void kick(String itemName) {
|
||||
player.kick("You can't drop " + itemName);
|
||||
}
|
||||
public void ban(String itemName) {
|
||||
entry.banPlayer(player, "Banned: You can't drop " + itemName);
|
||||
}
|
||||
public void notifyAdmins(String itemName) {
|
||||
entry.notifyAdmins(player.getName() + " (drop) " + itemName
|
||||
+ (comment != null ? " (" + comment + ")" : "") + ".");
|
||||
}
|
||||
public void tell(String itemName) {
|
||||
player.sendMessage(Colors.Yellow + "You're not allowed to drop " + itemName + ".");
|
||||
}
|
||||
};
|
||||
|
||||
return process(item, player, dropActions, handler, true, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on item acquire. Returns true to let the action pass through.
|
||||
*
|
||||
* @param item
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean onAcquire(final int item, final Player player) {
|
||||
if (acquireActions == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final BlacklistEntry entry = this;
|
||||
|
||||
ActionHandler handler = new ActionHandler() {
|
||||
public void log(String itemName) {
|
||||
blacklist.getLogger().logAcquireAttempt(player, item, comment);
|
||||
}
|
||||
public void kick(String itemName) {
|
||||
player.kick("You can't acquire " + itemName);
|
||||
}
|
||||
public void ban(String itemName) {
|
||||
entry.banPlayer(player, "Banned: You can't acquire " + itemName);
|
||||
}
|
||||
public void notifyAdmins(String itemName) {
|
||||
entry.notifyAdmins(player.getName() + " (acquire) " + itemName
|
||||
+ (comment != null ? " (" + comment + ")" : "") + ".");
|
||||
}
|
||||
public void tell(String itemName) {
|
||||
player.sendMessage(Colors.Yellow + "You're not allowed to acquire " + itemName + ".");
|
||||
}
|
||||
};
|
||||
|
||||
return process(item, player, acquireActions, handler, true, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on item acquire. Returns true to let the action pass through.
|
||||
*
|
||||
* @param item
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean onSilentAcquire(final int item, final Player player) {
|
||||
if (acquireActions == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return process(item, player, acquireActions, silentHandler, false, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal method to handle the actions.
|
||||
*
|
||||
* @param id
|
||||
* @param player
|
||||
* @param actions
|
||||
* @param handler
|
||||
* @param allowRepeat
|
||||
* @param silent
|
||||
* @return
|
||||
*/
|
||||
private boolean process(int id, Player player, String[] actions,
|
||||
ActionHandler handler, boolean allowRepeat, boolean silent) {
|
||||
|
||||
if (shouldIgnore(player)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String name = player.getName();
|
||||
long now = System.currentTimeMillis();
|
||||
boolean repeating = false;
|
||||
|
||||
// Check to see whether this event is being repeated
|
||||
BlacklistTrackedEvent tracked = lastAffected.get(name);
|
||||
if (tracked != null) {
|
||||
if (tracked.getId() == id && tracked.getTime() > now - 3000) {
|
||||
repeating = true;
|
||||
} else {
|
||||
tracked.setTime(now);
|
||||
tracked.setId(id);
|
||||
}
|
||||
} else {
|
||||
lastAffected.put(name, new BlacklistTrackedEvent(id, now));
|
||||
}
|
||||
|
||||
boolean ret = true;
|
||||
|
||||
for (String action : actions) {
|
||||
// Deny
|
||||
if (action.equalsIgnoreCase("deny")) {
|
||||
if (silent) {
|
||||
return false;
|
||||
}
|
||||
ret = false;
|
||||
|
||||
// Kick
|
||||
} else if (action.equalsIgnoreCase("kick")) {
|
||||
if (this.message != null) {
|
||||
player.kick(String.format(this.message,
|
||||
etc.getDataSource().getItem(id)));
|
||||
} else {
|
||||
handler.kick(etc.getDataSource().getItem(id));
|
||||
}
|
||||
|
||||
// Ban
|
||||
} else if (action.equalsIgnoreCase("ban")) {
|
||||
handler.ban(etc.getDataSource().getItem(id));
|
||||
if (this.message != null) {
|
||||
banPlayer(player, "Banned: " + String.format(this.message,
|
||||
etc.getDataSource().getItem(id)));
|
||||
} else {
|
||||
handler.ban(etc.getDataSource().getItem(id));
|
||||
}
|
||||
|
||||
} else if (!repeating || allowRepeat) {
|
||||
// Notify
|
||||
if (action.equalsIgnoreCase("notify")) {
|
||||
handler.notifyAdmins(etc.getDataSource().getItem(id));
|
||||
|
||||
// Log
|
||||
} else if (action.equalsIgnoreCase("log")) {
|
||||
handler.log(etc.getDataSource().getItem(id));
|
||||
|
||||
// Tell
|
||||
} else if (action.equalsIgnoreCase("tell")) {
|
||||
if (this.message != null) {
|
||||
player.sendMessage(Colors.Yellow +
|
||||
String.format(message, etc.getDataSource().getItem(id))
|
||||
+ ".");
|
||||
} else {
|
||||
handler.tell(etc.getDataSource().getItem(id));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forget a player.
|
||||
*
|
||||
* @param player
|
||||
*/
|
||||
public static void forgetPlayer(Player player) {
|
||||
lastAffected.remove(player.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Forget all players.
|
||||
*
|
||||
* @param player
|
||||
*/
|
||||
public static void forgetAllPlayers() {
|
||||
lastAffected.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets called for actions.
|
||||
*/
|
||||
private static interface ActionHandler {
|
||||
public void log(String itemName);
|
||||
public void kick(String itemName);
|
||||
public void ban(String itemName);
|
||||
public void notifyAdmins(String itemName);
|
||||
public void tell(String itemName);
|
||||
}
|
||||
}
|
||||
@@ -1,153 +0,0 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class BlacklistLogger implements BlacklistLoggerHandler {
|
||||
/**
|
||||
* List of logger handlers.
|
||||
*/
|
||||
private Set<BlacklistLoggerHandler> handlers
|
||||
= new HashSet<BlacklistLoggerHandler>();
|
||||
|
||||
/**
|
||||
* Add a handler.
|
||||
*
|
||||
* @param handler
|
||||
*/
|
||||
public void addHandler(BlacklistLoggerHandler handler) {
|
||||
handlers.add(handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a handler.
|
||||
*
|
||||
* @param handler
|
||||
*/
|
||||
public void removeHandler(BlacklistLoggerHandler handler) {
|
||||
handlers.remove(handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a handler.
|
||||
*
|
||||
* @param handler
|
||||
*/
|
||||
public void clearHandlers() {
|
||||
handlers.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a block destroy attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param block
|
||||
*/
|
||||
public void logDestroyAttempt(Player player, Block block, String comment) {
|
||||
for (BlacklistLoggerHandler handler : handlers) {
|
||||
handler.logDestroyAttempt(player, block, comment);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a block break attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param block
|
||||
*/
|
||||
public void logBreakAttempt(Player player, Block block, String comment) {
|
||||
for (BlacklistLoggerHandler handler : handlers) {
|
||||
handler.logBreakAttempt(player, block, comment);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a right click on attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param block
|
||||
*/
|
||||
public void logUseAttempt(Player player, Block block, String comment) {
|
||||
for (BlacklistLoggerHandler handler : handlers) {
|
||||
handler.logUseAttempt(player, block, comment);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Right a left click attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logDestroyWithAttempt(Player player, int item, String comment) {
|
||||
for (BlacklistLoggerHandler handler : handlers) {
|
||||
handler.logDestroyWithAttempt(player, item, comment);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a right click attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logCreateAttempt(Player player, int item, String comment) {
|
||||
for (BlacklistLoggerHandler handler : handlers) {
|
||||
handler.logCreateAttempt(player, item, comment);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a drop attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logDropAttempt(Player player, int item, String comment) {
|
||||
for (BlacklistLoggerHandler handler : handlers) {
|
||||
handler.logDropAttempt(player, item, comment);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log an acquire attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logAcquireAttempt(Player player, int item, String comment) {
|
||||
for (BlacklistLoggerHandler handler : handlers) {
|
||||
handler.logAcquireAttempt(player, item, comment);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the connection.
|
||||
*/
|
||||
public void close() {
|
||||
for (BlacklistLoggerHandler handler : handlers) {
|
||||
handler.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Interface for loggers for the blacklist.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public interface BlacklistLoggerHandler {
|
||||
/**
|
||||
* Log a block destroy attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param block
|
||||
*/
|
||||
public void logDestroyAttempt(Player player, Block block, String comment);
|
||||
/**
|
||||
* Log a block break attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param block
|
||||
*/
|
||||
public void logBreakAttempt(Player player, Block block, String comment);
|
||||
/**
|
||||
* Log a right click on attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param block
|
||||
*/
|
||||
public void logUseAttempt(Player player, Block block, String comment);
|
||||
/**
|
||||
* Right a left click attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logDestroyWithAttempt(Player player, int item, String comment);
|
||||
/**
|
||||
* Log a right click attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logCreateAttempt(Player player, int item, String comment);
|
||||
/**
|
||||
* Log a drop attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logDropAttempt(Player player, int item, String comment);
|
||||
/**
|
||||
* Log an acquire attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logAcquireAttempt(Player player, int item, String comment);
|
||||
/**
|
||||
* Close the logger.
|
||||
*/
|
||||
public void close();
|
||||
}
|
||||
@@ -1,131 +0,0 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import java.util.logging.Logger;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class ConsoleLoggerHandler implements BlacklistLoggerHandler {
|
||||
/**
|
||||
* Logger.
|
||||
*/
|
||||
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
||||
|
||||
/**
|
||||
* Log a block destroy attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param block
|
||||
*/
|
||||
public void logDestroyAttempt(Player player, Block block, String comment) {
|
||||
logger.log(Level.INFO, "WorldGuard: " + player.getName()
|
||||
+ " tried to destroy " + getFriendlyItemName(block.getType())
|
||||
+ (comment != null ? " (" + comment + ")" : ""));
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a block break attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param block
|
||||
*/
|
||||
public void logBreakAttempt(Player player, Block block, String comment) {
|
||||
logger.log(Level.INFO, "WorldGuard: " + player.getName()
|
||||
+ " tried to break " + getFriendlyItemName(block.getType())
|
||||
+ (comment != null ? " (" + comment + ")" : ""));
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a right click on attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param block
|
||||
*/
|
||||
public void logUseAttempt(Player player, Block block, String comment) {
|
||||
logger.log(Level.INFO, "WorldGuard: " + player.getName()
|
||||
+ " tried to use " + getFriendlyItemName(block.getType())
|
||||
+ (comment != null ? " (" + comment + ")" : ""));
|
||||
}
|
||||
|
||||
/**
|
||||
* Log an attempt to destroy with an item.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logDestroyWithAttempt(Player player, int item, String comment) {
|
||||
logger.log(Level.INFO, "WorldGuard: " + player.getName()
|
||||
+ " tried to destroy with " + getFriendlyItemName(item)
|
||||
+ (comment != null ? " (" + comment + ")" : ""));
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a block creation attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logCreateAttempt(Player player, int item, String comment) {
|
||||
logger.log(Level.INFO, "WorldGuard: " + player.getName()
|
||||
+ " tried to create " + getFriendlyItemName(item)
|
||||
+ (comment != null ? " (" + comment + ")" : ""));
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a drop attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logDropAttempt(Player player, int item, String comment) {
|
||||
logger.log(Level.INFO, "WorldGuard: " + player.getName()
|
||||
+ " tried to drop " + getFriendlyItemName(item)
|
||||
+ (comment != null ? " (" + comment + ")" : ""));
|
||||
}
|
||||
|
||||
/**
|
||||
* Log an acquire attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logAcquireAttempt(Player player, int item, String comment) {
|
||||
logger.log(Level.INFO, "WorldGuard: " + player.getName()
|
||||
+ " tried to acquire " + getFriendlyItemName(item)
|
||||
+ (comment != null ? " (" + comment + ")" : ""));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an item's friendly name with its ID.
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
private static String getFriendlyItemName(int id) {
|
||||
return etc.getDataSource().getItem(id) + " (#" + id + ")";
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the connection.
|
||||
*/
|
||||
public void close() {
|
||||
}
|
||||
}
|
||||
@@ -1,215 +0,0 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import java.util.logging.Logger;
|
||||
import java.util.logging.Level;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.PreparedStatement;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class DatabaseLoggerHandler implements BlacklistLoggerHandler {
|
||||
/**
|
||||
* Logger.
|
||||
*/
|
||||
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
||||
|
||||
/**
|
||||
* DSN.
|
||||
*/
|
||||
private String dsn;
|
||||
/**
|
||||
* Username.
|
||||
*/
|
||||
private String user;
|
||||
/**
|
||||
* Password.
|
||||
*/
|
||||
private String pass;
|
||||
/**
|
||||
* Table.
|
||||
*/
|
||||
private String table;
|
||||
/**
|
||||
* Database connection.
|
||||
*/
|
||||
private Connection conn;
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param dsn
|
||||
* @param user
|
||||
* @param pass
|
||||
*/
|
||||
public DatabaseLoggerHandler(String dsn, String user, String pass, String table) {
|
||||
this.dsn = dsn;
|
||||
this.user = user;
|
||||
this.pass = pass;
|
||||
this.table = table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the database connection.
|
||||
*
|
||||
* @return
|
||||
* @throws SQLException
|
||||
*/
|
||||
private Connection getConnection() throws SQLException {
|
||||
if (conn == null || conn.isClosed()) {
|
||||
conn = DriverManager.getConnection(dsn, user, pass);
|
||||
}
|
||||
return conn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log an event to the database.
|
||||
*
|
||||
* @param event
|
||||
* @param name
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @param item
|
||||
* @param comment
|
||||
*/
|
||||
private void logEvent(String event, String name, int x, int y, int z, int item,
|
||||
String comment) {
|
||||
try {
|
||||
Connection conn = getConnection();
|
||||
PreparedStatement stmt = conn.prepareStatement(
|
||||
"INSERT INTO " + table
|
||||
+ "(event, player, x, y, z, item, time, comment) VALUES "
|
||||
+ "(?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
stmt.setString(1, event);
|
||||
stmt.setString(2, name);
|
||||
stmt.setInt(3, x);
|
||||
stmt.setInt(4, y);
|
||||
stmt.setInt(5, z);
|
||||
stmt.setInt(6, item);
|
||||
stmt.setInt(7, (int)(System.currentTimeMillis() / 1000));
|
||||
stmt.setString(8, comment);
|
||||
stmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
logger.log(Level.SEVERE, "Failed to log blacklist event to database: "
|
||||
+ e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a block destroy attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param block
|
||||
*/
|
||||
public void logDestroyAttempt(Player player, Block block, String comment) {
|
||||
logEvent("DESTROY", player.getName(),
|
||||
block.getX(), block.getY(), block.getZ(), block.getType(),
|
||||
comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a block break attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param block
|
||||
*/
|
||||
public void logBreakAttempt(Player player, Block block, String comment) {
|
||||
logEvent("BREAK", player.getName(),
|
||||
block.getX(), block.getY(), block.getZ(), block.getType(),
|
||||
comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a right click on attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param block
|
||||
*/
|
||||
public void logUseAttempt(Player player, Block block, String comment) {
|
||||
logEvent("USE", player.getName(),
|
||||
block.getX(), block.getY(), block.getZ(), block.getType(),
|
||||
comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Right a left click attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logDestroyWithAttempt(Player player, int item, String comment) {
|
||||
logEvent("DESTROY_WITH", player.getName(),
|
||||
(int)Math.floor(player.getX()), (int)Math.floor(player.getY()),
|
||||
(int)Math.floor(player.getZ()), item, comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a right click attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logCreateAttempt(Player player, int item, String comment) {
|
||||
logEvent("CREATE", player.getName(),
|
||||
(int)Math.floor(player.getX()), (int)Math.floor(player.getY()),
|
||||
(int)Math.floor(player.getZ()), item, comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a drop attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logDropAttempt(Player player, int item, String comment) {
|
||||
logEvent("DROP", player.getName(),
|
||||
(int)Math.floor(player.getX()), (int)Math.floor(player.getY()),
|
||||
(int)Math.floor(player.getZ()), item, comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log an aquire attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logAcquireAttempt(Player player, int item, String comment) {
|
||||
logEvent("AQUIRE", player.getName(),
|
||||
(int)Math.floor(player.getX()), (int)Math.floor(player.getY()),
|
||||
(int)Math.floor(player.getZ()), item, comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the connection.
|
||||
*/
|
||||
public void close() {
|
||||
try {
|
||||
if (conn != null && !conn.isClosed()) {
|
||||
conn.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,207 +0,0 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import java.util.logging.Logger;
|
||||
import java.util.logging.Level;
|
||||
import java.util.jar.Manifest;
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.net.URL;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.*;
|
||||
|
||||
/**
|
||||
* Entry point for the plugin for hey0's mod.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class WorldGuard extends Plugin {
|
||||
/**
|
||||
* Logger.
|
||||
*/
|
||||
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
||||
/**
|
||||
* Listener for the plugin system.
|
||||
*/
|
||||
private WorldGuardListener listener;
|
||||
|
||||
/**
|
||||
* Initialize the plugin.
|
||||
*/
|
||||
public WorldGuard() {
|
||||
listener = new WorldGuardListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the plugin.
|
||||
*/
|
||||
@Override
|
||||
public void initialize() {
|
||||
PluginLoader loader = etc.getLoader();
|
||||
|
||||
List<String> missingFeatures = new ArrayList<String>();
|
||||
|
||||
registerHook("COMMAND", PluginListener.Priority.MEDIUM);
|
||||
registerHook("SERVERCOMMAND", PluginListener.Priority.MEDIUM);
|
||||
if (!registerHook("EXPLODE", PluginListener.Priority.HIGH)) {
|
||||
missingFeatures.add("disabling TNT or creeper explosions");
|
||||
}
|
||||
if (!registerHook("IGNITE", PluginListener.Priority.HIGH)) {
|
||||
missingFeatures.add("disabling fire or lava fire");
|
||||
}
|
||||
if (!registerHook("FLOW", PluginListener.Priority.HIGH)) {
|
||||
missingFeatures.add("controlling lava flow");
|
||||
missingFeatures.add("sponge simulation");
|
||||
}
|
||||
registerHook("LOGINCHECK", PluginListener.Priority.HIGH);
|
||||
registerHook("LOGIN", PluginListener.Priority.MEDIUM);
|
||||
registerHook("BLOCK_CREATED", PluginListener.Priority.HIGH);
|
||||
registerHook("BLOCK_DESTROYED", PluginListener.Priority.CRITICAL);
|
||||
registerHook("BLOCK_BROKEN", PluginListener.Priority.HIGH);
|
||||
registerHook("DISCONNECT", PluginListener.Priority.HIGH);
|
||||
registerHook("ITEM_DROP", PluginListener.Priority.HIGH);
|
||||
if (!registerHook("ITEM_PICK_UP", PluginListener.Priority.HIGH)) {
|
||||
missingFeatures.add("denying item pickups");
|
||||
missingFeatures.add("the item durability fix");
|
||||
} else {
|
||||
try {
|
||||
Method method =
|
||||
Item.class.getDeclaredMethod("setDamage", new Class[]{ Integer.class });
|
||||
if (method == null) {
|
||||
missingFeatures.add("the item durability fix");
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
missingFeatures.add("the item durability fix");
|
||||
}
|
||||
}
|
||||
registerHook("COMPLEX_BLOCK_CHANGE", PluginListener.Priority.HIGH);
|
||||
registerHook("COMPLEX_BLOCK_SEND", PluginListener.Priority.HIGH);
|
||||
registerHook("INVENTORY_CHANGE", PluginListener.Priority.HIGH);
|
||||
if (!registerHook("BLOCK_PHYSICS", PluginListener.Priority.MEDIUM)) {
|
||||
missingFeatures.add("controlling the physics of gravel, sand, or portal blocks");
|
||||
}
|
||||
|
||||
if (missingFeatures.size() > 0) {
|
||||
logger.log(Level.WARNING, "WorldGuard: Your version of hMod does not support "
|
||||
+ concatMissingFeatures(missingFeatures) + ".");
|
||||
} else {
|
||||
logger.log(Level.INFO, "WorldGuard: Your version of hMod appears to"
|
||||
+ " support all features.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Conditionally registers a hook.
|
||||
*
|
||||
* @param name
|
||||
* @param priority
|
||||
* @return where the hook was registered correctly
|
||||
*/
|
||||
public boolean registerHook(String name, PluginListener.Priority priority) {
|
||||
try {
|
||||
PluginLoader.Hook hook = PluginLoader.Hook.valueOf(name);
|
||||
etc.getLoader().addListener(hook, listener, this, priority);
|
||||
return true;
|
||||
} catch (IllegalArgumentException e) {
|
||||
//logger.log(Level.WARNING, "WorldGuard: Missing hook " + name + "!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables the plugin.
|
||||
*/
|
||||
@Override
|
||||
public void enable() {
|
||||
logger.log(Level.INFO, "WorldGuard version " + getVersion() + " loaded");
|
||||
listener.loadConfiguration();
|
||||
|
||||
etc.getInstance().addCommand("/stopfire", "Globally stop fire spread");
|
||||
etc.getInstance().addCommand("/allowfire", "Globally re-enable fire spread");
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables the plugin.
|
||||
*/
|
||||
@Override
|
||||
public void disable() {
|
||||
try {
|
||||
listener.disable();
|
||||
BlacklistEntry.forgetAllPlayers();
|
||||
} catch (Throwable t) {
|
||||
}
|
||||
|
||||
etc.getInstance().removeCommand("/stopfire");
|
||||
etc.getInstance().removeCommand("/allowfire");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the WorldGuard version.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private String getVersion() {
|
||||
try {
|
||||
String classContainer = WorldGuard.class.getProtectionDomain()
|
||||
.getCodeSource().getLocation().toString();
|
||||
URL manifestUrl = new URL("jar:" + classContainer + "!/META-INF/MANIFEST.MF");
|
||||
Manifest manifest = new Manifest(manifestUrl.openStream());
|
||||
Attributes attrib = manifest.getMainAttributes();
|
||||
String ver = (String)attrib.getValue("WorldGuard-Version");
|
||||
return ver != null ? ver : "(unavailable)";
|
||||
} catch (IOException e) {
|
||||
return "(unknown)";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Joins a string from an array of strings.
|
||||
*
|
||||
* @param str
|
||||
* @param delimiter
|
||||
* @return
|
||||
*/
|
||||
private static String concatMissingFeatures(List<String> str) {
|
||||
if (str.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
|
||||
int size = str.size();
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
buffer.append("(1) ");
|
||||
buffer.append(str.get(0));
|
||||
for (int i = 1; i < size; i++) {
|
||||
if (i == size - 1) {
|
||||
buffer.append(" or ");
|
||||
buffer.append("(");
|
||||
buffer.append(i + 1);
|
||||
buffer.append(") ");
|
||||
buffer.append(str.get(i));
|
||||
} else {
|
||||
buffer.append(", ");
|
||||
buffer.append("(");
|
||||
buffer.append(i + 1);
|
||||
buffer.append(") ");
|
||||
buffer.append(str.get(i));
|
||||
}
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
||||
@@ -1,767 +0,0 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.logging.Level;
|
||||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
import java.util.Random;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* Event listener for Hey0's server mod.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class WorldGuardListener extends PluginListener {
|
||||
/**
|
||||
* Logger.
|
||||
*/
|
||||
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
||||
/**
|
||||
* Timer for threading.
|
||||
*/
|
||||
private static final Timer timer = new Timer();
|
||||
/**
|
||||
* Random number generator.
|
||||
*/
|
||||
private static Random rand = new Random();
|
||||
|
||||
/**
|
||||
* Plugin host.
|
||||
*/
|
||||
private WorldGuard plugin;
|
||||
/**
|
||||
* Properties file for WorldGuard.
|
||||
*/
|
||||
private PropertiesFile properties = new PropertiesFile("worldguard.properties");
|
||||
|
||||
/**
|
||||
* Stop fire spread mode.
|
||||
*/
|
||||
private boolean stopFireSpread = false;
|
||||
|
||||
private boolean enforceOneSession;
|
||||
private boolean blockCreepers;
|
||||
private boolean blockTNT;
|
||||
private boolean blockLighter;
|
||||
private boolean preventLavaFire;
|
||||
private boolean disableAllFire;
|
||||
private boolean simulateSponge;
|
||||
private int spongeRadius;
|
||||
private boolean itemDurability;
|
||||
private Set<Integer> fireNoSpreadBlocks;
|
||||
private Set<Integer> allowedLavaSpreadOver;
|
||||
private Set<Integer> itemDropBlacklist;
|
||||
private boolean classicWater;
|
||||
private boolean noPhysicsGravel;
|
||||
private boolean noPhysicsSand;
|
||||
private boolean allowPortalAnywhere;
|
||||
private Blacklist blacklist;
|
||||
|
||||
/**
|
||||
* Construct the listener.
|
||||
*
|
||||
* @param plugin
|
||||
*/
|
||||
public WorldGuardListener(WorldGuard plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a comma-delimited list to a set of integers.
|
||||
*
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
private static Set<Integer> toBlockIDSet(String str) {
|
||||
if (str.trim().length() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String[] items = str.split(",");
|
||||
Set<Integer> result = new HashSet<Integer>();
|
||||
|
||||
for (String item : items) {
|
||||
try {
|
||||
result.add(Integer.parseInt(item.trim()));
|
||||
} catch (NumberFormatException e) {
|
||||
int id = etc.getDataSource().getItem(item.trim());
|
||||
if (id != 0) {
|
||||
result.add(id);
|
||||
} else {
|
||||
logger.log(Level.WARNING, "WorldGuard: Unknown block name: "
|
||||
+ item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the configuration
|
||||
*/
|
||||
public void loadConfiguration() {
|
||||
properties.load();
|
||||
|
||||
// Load basic options
|
||||
enforceOneSession = properties.getBoolean("enforce-single-session", true);
|
||||
blockCreepers = properties.getBoolean("block-creepers", false);
|
||||
blockTNT = properties.getBoolean("block-tnt", false);
|
||||
blockLighter = properties.getBoolean("block-lighter", false);
|
||||
preventLavaFire = properties.getBoolean("disable-lava-fire", true);
|
||||
disableAllFire = properties.getBoolean("disable-all-fire-spread", false);
|
||||
itemDropBlacklist = toBlockIDSet(properties.getString("item-drop-blacklist", ""));
|
||||
fireNoSpreadBlocks = toBlockIDSet(properties.getString("disallowed-fire-spread-blocks", ""));
|
||||
allowedLavaSpreadOver = toBlockIDSet(properties.getString("allowed-lava-spread-blocks", ""));
|
||||
classicWater = properties.getBoolean("classic-water", false);
|
||||
simulateSponge = properties.getBoolean("simulate-sponge", true);
|
||||
spongeRadius = Math.max(1, properties.getInt("sponge-radius", 3)) - 1;
|
||||
itemDurability = properties.getBoolean("item-durability", false);
|
||||
noPhysicsGravel = properties.getBoolean("no-physics-gravel", false);
|
||||
noPhysicsSand = properties.getBoolean("no-physics-sand", false);
|
||||
allowPortalAnywhere = properties.getBoolean("allow-portal-anywhere", false);
|
||||
|
||||
// Console log configuration
|
||||
boolean logConsole = properties.getBoolean("log-console", true);
|
||||
|
||||
// Database log configuration
|
||||
boolean logDatabase = properties.getBoolean("log-database", false);
|
||||
String dsn = properties.getString("log-database-dsn", "jdbc:mysql://localhost:3306/minecraft");
|
||||
String user = properties.getString("log-database-user", "root");
|
||||
String pass = properties.getString("log-database-pass", "");
|
||||
String table = properties.getString("log-database-table", "blacklist_events");
|
||||
|
||||
// File log configuration
|
||||
boolean logFile = properties.getBoolean("log-file", false);
|
||||
String logFilePattern = properties.getString("log-file-path", "worldguard/logs/%Y-%m-%d.log");
|
||||
int logFileCacheSize = Math.max(1, properties.getInt("log-file-open-files", 10));
|
||||
|
||||
// Load the blacklist
|
||||
try {
|
||||
// If there was an existing blacklist, close loggers
|
||||
if (blacklist != null) {
|
||||
blacklist.getLogger().close();
|
||||
}
|
||||
|
||||
// First load the blacklist data from worldguard-blacklist.txt
|
||||
Blacklist blist = new Blacklist();
|
||||
blist.load(new File("worldguard-blacklist.txt"));
|
||||
|
||||
// If the blacklist is empty, then set the field to null
|
||||
// and save some resources
|
||||
if (blist.isEmpty()) {
|
||||
this.blacklist = null;
|
||||
} else {
|
||||
this.blacklist = blist;
|
||||
logger.log(Level.INFO, "WorldGuard: Blacklist loaded.");
|
||||
|
||||
BlacklistLogger blacklistLogger = blist.getLogger();
|
||||
|
||||
if (logDatabase) {
|
||||
blacklistLogger.addHandler(new DatabaseLoggerHandler(dsn, user, pass, table));
|
||||
}
|
||||
|
||||
if (logConsole) {
|
||||
blacklistLogger.addHandler(new ConsoleLoggerHandler());
|
||||
}
|
||||
|
||||
if (logFile) {
|
||||
FileLoggerHandler handler =
|
||||
new FileLoggerHandler(logFilePattern, logFileCacheSize);
|
||||
blacklistLogger.addHandler(handler);
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
logger.log(Level.WARNING, "WorldGuard blacklist does not exist.");
|
||||
} catch (IOException e) {
|
||||
logger.log(Level.WARNING, "Could not load WorldGuard blacklist: "
|
||||
+ e.getMessage());
|
||||
}
|
||||
|
||||
// Print an overview of settings
|
||||
if (properties.getBoolean("summary-on-start", true)) {
|
||||
logger.log(Level.INFO, enforceOneSession ? "WorldGuard: Single session is enforced."
|
||||
: "WorldGuard: Single session is NOT ENFORCED.");
|
||||
logger.log(Level.INFO, blockTNT ? "WorldGuard: TNT ignition is blocked."
|
||||
: "WorldGuard: TNT ignition is PERMITTED.");
|
||||
logger.log(Level.INFO, blockLighter ? "WorldGuard: Lighters are blocked."
|
||||
: "WorldGuard: Lighters are PERMITTED.");
|
||||
logger.log(Level.INFO, preventLavaFire ? "WorldGuard: Lava fire is blocked."
|
||||
: "WorldGuard: Lava fire is PERMITTED.");
|
||||
if (disableAllFire) {
|
||||
logger.log(Level.INFO, "WorldGuard: All fire spread is disabled.");
|
||||
} else {
|
||||
if (fireNoSpreadBlocks != null) {
|
||||
logger.log(Level.INFO, "WorldGuard: Fire spread is limited to "
|
||||
+ fireNoSpreadBlocks.size() + " block types.");
|
||||
} else {
|
||||
logger.log(Level.INFO, "WorldGuard: Fire spread is UNRESTRICTED.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called during the early login process to check whether or not to kick the
|
||||
* player
|
||||
*
|
||||
* @param user
|
||||
* @return kick reason. null if you don't want to kick the player.
|
||||
*/
|
||||
@Override
|
||||
public String onLoginChecks(String user) {
|
||||
if (enforceOneSession) {
|
||||
for (Player player : etc.getServer().getPlayerList()) {
|
||||
if (player.getName().equalsIgnoreCase(user)) {
|
||||
player.kick("Logged in from another location.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called during the later login process
|
||||
*
|
||||
* @param player
|
||||
*/
|
||||
@Override
|
||||
public void onLogin(Player player) {
|
||||
if (stopFireSpread) {
|
||||
player.sendMessage(Colors.Yellow + "Fire spread is currently globally disabled.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called before the command is parsed. Return true if you don't want the
|
||||
* command to be parsed.
|
||||
*
|
||||
* @param player
|
||||
* @param split
|
||||
* @return false if you want the command to be parsed.
|
||||
*/
|
||||
@Override
|
||||
public boolean onCommand(Player player, String[] split) {
|
||||
if (split[0].equalsIgnoreCase("/stopfire") &&
|
||||
player.canUseCommand("/stopfire")) {
|
||||
if (!stopFireSpread) {
|
||||
etc.getServer().messageAll(Colors.Yellow
|
||||
+ "Fire spread has been globally disabled by " + player.getName() + ".");
|
||||
} else {
|
||||
player.sendMessage(Colors.Yellow + "Fire spread was already globally disabled.");
|
||||
}
|
||||
stopFireSpread = true;
|
||||
return true;
|
||||
} else if (split[0].equalsIgnoreCase("/allowfire")
|
||||
&& player.canUseCommand("/stopfire")) {
|
||||
if (stopFireSpread) {
|
||||
etc.getServer().messageAll(Colors.Yellow
|
||||
+ "Fire spread has been globally re-enabled by " + player.getName() + ".");
|
||||
} else {
|
||||
player.sendMessage(Colors.Yellow + "Fire spread was already globally enabled.");
|
||||
}
|
||||
stopFireSpread = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called before the console command is parsed. Return true if you don't
|
||||
* want the server command to be parsed by the server.
|
||||
*
|
||||
* @param split
|
||||
* @return false if you want the command to be parsed.
|
||||
*/
|
||||
@Override
|
||||
public boolean onConsoleCommand(String[] split) {
|
||||
if (split[0].equalsIgnoreCase("fire-stop")) {
|
||||
if (!stopFireSpread) {
|
||||
etc.getServer().messageAll(Colors.Yellow
|
||||
+ "Fire spread has been globally disabled by server console.");
|
||||
logger.log(Level.INFO, "Fire spread is now globally disabled.");
|
||||
} else {
|
||||
logger.log(Level.INFO, "Fire spread was already globally disabled.");
|
||||
}
|
||||
stopFireSpread = true;
|
||||
return true;
|
||||
} else if (split[0].equalsIgnoreCase("fire-allow")) {
|
||||
if (stopFireSpread) {
|
||||
etc.getServer().messageAll(Colors.Yellow
|
||||
+ "Fire spread has been globally re-enabled by server console.");
|
||||
logger.log(Level.INFO, "Fire spread is now globally enabled.");
|
||||
} else {
|
||||
logger.log(Level.INFO, "Fire spread was already globally enabled.");
|
||||
}
|
||||
stopFireSpread = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player drops an item.
|
||||
*
|
||||
* @param player
|
||||
* player who dropped the item
|
||||
* @param item
|
||||
* item that was dropped
|
||||
* @return true if you don't want the dropped item to be spawned in the
|
||||
* world
|
||||
*/
|
||||
@Override
|
||||
public boolean onItemDrop(Player player, Item item) {
|
||||
if (itemDropBlacklist != null) {
|
||||
int n = item.getItemId();
|
||||
if (itemDropBlacklist.contains(n)) {
|
||||
player.sendMessage(Colors.Rose + "Item was destroyed!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (blacklist != null) {
|
||||
if (!blacklist.onDrop(item.getItemId(), player)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!itemDurability) {
|
||||
try {
|
||||
item.setDamage(0);
|
||||
} catch (java.lang.NoSuchMethodError e) {
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player picks up an item.
|
||||
*
|
||||
* @param player
|
||||
* player who picked up the item
|
||||
* @param item
|
||||
* item that was picked up
|
||||
* @return true if you want to leave the item where it was
|
||||
*/
|
||||
@Override
|
||||
public boolean onItemPickUp(Player player, Item item) {
|
||||
if (blacklist != null && blacklist.hasOnAcquire()) {
|
||||
if (!blacklist.onSilentAcquire(item.getItemId(), player)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player's inventory is modified.
|
||||
*
|
||||
* @param player
|
||||
* player who's inventory was modified
|
||||
* @return true if you want any changes to be reverted
|
||||
*/
|
||||
@Override
|
||||
public boolean onInventoryChange(Player player) {
|
||||
if (blacklist != null && blacklist.hasOnAcquire()) {
|
||||
hl[] items = player.getInventory().getArray();
|
||||
boolean needUpdate = false;
|
||||
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
if (items[i] != null) {
|
||||
if (!blacklist.onAcquire(items[i].c, player)) {
|
||||
items[i] = null;
|
||||
needUpdate = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (needUpdate) {
|
||||
player.getInventory().updateInventory();
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when someone presses right click. If they right clicked with a
|
||||
* block you can return true to cancel that. You can intercept this to add
|
||||
* your own right click actions to different item types (see itemInHand)
|
||||
*
|
||||
* @param player
|
||||
* @param blockPlaced
|
||||
* @param blockClicked
|
||||
* @param itemInHand
|
||||
* @return false if you want the action to go through
|
||||
*/
|
||||
@Override
|
||||
public boolean onBlockCreate(Player player, Block blockPlaced, Block blockClicked,
|
||||
int itemInHand) {
|
||||
if (blacklist != null) {
|
||||
if (!blacklist.onCreate(itemInHand, player)) {
|
||||
// Water/lava bucket fix
|
||||
if (itemInHand == 326 || itemInHand == 327) {
|
||||
final int x = blockPlaced.getX();
|
||||
final int y = blockPlaced.getY();
|
||||
final int z = blockPlaced.getZ();
|
||||
final int existingID = etc.getServer().getBlockIdAt(x, y, z);
|
||||
|
||||
// This is REALLY BAD, but there's no other choice
|
||||
// at the moment that is as reliable
|
||||
timer.schedule(new TimerTask() {
|
||||
public void run() {
|
||||
try {
|
||||
etc.getServer().setBlockAt(existingID, x, y, z);
|
||||
} catch (Throwable t) {}
|
||||
}
|
||||
}, 200); // Just in case
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!blacklist.onUse(blockClicked, player)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (simulateSponge && blockPlaced.getType() == 19) {
|
||||
int ox = blockPlaced.getX();
|
||||
int oy = blockPlaced.getY();
|
||||
int oz = blockPlaced.getZ();
|
||||
|
||||
Server server = etc.getServer();
|
||||
|
||||
for (int cx = -spongeRadius; cx <= spongeRadius; cx++) {
|
||||
for (int cy = -spongeRadius; cy <= spongeRadius; cy++) {
|
||||
for (int cz = -spongeRadius; cz <= spongeRadius; cz++) {
|
||||
int id = server.getBlockIdAt(ox + cx, oy + cy, oz + cz);
|
||||
if (id == 8 || id == 9) {
|
||||
server.setBlockAt(0, ox + cx, oy + cy, oz + cz);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a person left clicks a block.
|
||||
*
|
||||
* @param player
|
||||
* @param block
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean onBlockDestroy(Player player, Block block) {
|
||||
int type = block.getType();
|
||||
|
||||
if (blacklist != null) {
|
||||
if (!blacklist.onDestroyWith(player.getItemInHand(), player)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!blacklist.onDestroy(block, player)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a person actually breaks the block.
|
||||
*
|
||||
* @param player
|
||||
* @param block
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean onBlockBreak(Player player, Block block) {
|
||||
if (blacklist != null) {
|
||||
if (!blacklist.onBreak(block, player)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when either a sign, chest or furnace is changed.
|
||||
*
|
||||
* @param player
|
||||
* player who changed it
|
||||
* @param complexBlock
|
||||
* complex block that changed
|
||||
* @return true if you want any changes to be reverted
|
||||
*/
|
||||
@Override
|
||||
public boolean onComplexBlockChange(Player player, ComplexBlock complexBlock) {
|
||||
if (blacklist != null) {
|
||||
if (complexBlock instanceof Chest) {
|
||||
Block block = new Block(54, complexBlock.getX(),
|
||||
complexBlock.getY(), complexBlock.getZ());
|
||||
|
||||
if (!blacklist.onSilentUse(block, player)) {
|
||||
return true;
|
||||
}
|
||||
} else if (complexBlock instanceof Furnace) {
|
||||
int id = etc.getServer().getBlockIdAt(complexBlock.getX(),
|
||||
complexBlock.getY(), complexBlock.getZ());
|
||||
Block block = new Block(id, complexBlock.getX(),
|
||||
complexBlock.getY(), complexBlock.getZ());
|
||||
|
||||
if (!blacklist.onSilentUse(block, player)) {
|
||||
return true;
|
||||
}
|
||||
} else if (complexBlock instanceof Sign) {
|
||||
int id = etc.getServer().getBlockIdAt(complexBlock.getX(),
|
||||
complexBlock.getY(), complexBlock.getZ());
|
||||
Block block = new Block(id, complexBlock.getX(),
|
||||
complexBlock.getY(), complexBlock.getZ());
|
||||
|
||||
if (!blacklist.onSilentUse(block, player)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when either a sign, chest or furnace is sent to a player
|
||||
*
|
||||
* @param player
|
||||
* player who the block is being sent to
|
||||
* @param complexBlock
|
||||
* complex block that's being sent
|
||||
* @return true if you want the chest, furnace or sign to be empty
|
||||
*/
|
||||
@Override
|
||||
public boolean onSendComplexBlock(Player player, ComplexBlock complexBlock) {
|
||||
if (blacklist != null) {
|
||||
if (complexBlock instanceof Chest) {
|
||||
Block block = new Block(54, complexBlock.getX(),
|
||||
complexBlock.getY(), complexBlock.getZ());
|
||||
|
||||
if (!blacklist.onSilentUse(block, player)) {
|
||||
return true;
|
||||
}
|
||||
} else if (complexBlock instanceof Furnace) {
|
||||
int id = etc.getServer().getBlockIdAt(complexBlock.getX(),
|
||||
complexBlock.getY(), complexBlock.getZ());
|
||||
Block block = new Block(id, complexBlock.getX(),
|
||||
complexBlock.getY(), complexBlock.getZ());
|
||||
|
||||
if (!blacklist.onSilentUse(block, player)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Called when either a lava block or a lighter tryes to light something on fire.
|
||||
* block status depends on the light source:
|
||||
* 1 = lava.
|
||||
* 2 = lighter (flint + steel).
|
||||
* 3 = spread (dynamic spreading of fire).
|
||||
* @param block
|
||||
* block that the fire wants to spawn in.
|
||||
*
|
||||
* @return true if you dont want the fire to ignite.
|
||||
*/
|
||||
@Override
|
||||
public boolean onIgnite(Block block, Player player) {
|
||||
if (preventLavaFire && block.getStatus() == 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (blockLighter && block.getStatus() == 2) {
|
||||
return !player.canUseCommand("/uselighter")
|
||||
&& !player.canUseCommand("/lighter");
|
||||
}
|
||||
|
||||
if (stopFireSpread && block.getStatus() == 3) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (disableAllFire && block.getStatus() == 3) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (fireNoSpreadBlocks != null && block.getStatus() == 3) {
|
||||
int x = block.getX();
|
||||
int y = block.getY();
|
||||
int z = block.getZ();
|
||||
if (fireNoSpreadBlocks.contains(etc.getServer().getBlockIdAt(x, y - 1, z))
|
||||
|| fireNoSpreadBlocks.contains(etc.getServer().getBlockIdAt(x + 1, y, z))
|
||||
|| fireNoSpreadBlocks.contains(etc.getServer().getBlockIdAt(x - 1, y, z))
|
||||
|| fireNoSpreadBlocks.contains(etc.getServer().getBlockIdAt(x, y, z - 1))
|
||||
|| fireNoSpreadBlocks.contains(etc.getServer().getBlockIdAt(x, y, z + 1))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Called when a dynamite block or a creeper is triggerd.
|
||||
* block status depends on explosive compound:
|
||||
* 1 = dynamite.
|
||||
* 2 = creeper.
|
||||
* @param block
|
||||
* dynamite block/creeper location block.
|
||||
*
|
||||
* @return true if you dont the block to explode.
|
||||
*/
|
||||
@Override
|
||||
public boolean onExplode(Block block) {
|
||||
if (blockCreepers && block.getStatus() == 2) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (blockTNT && block.getStatus() == 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Called when fluid wants to flow to a certain block.
|
||||
* (10 & 11 for lava and 8 & 9 for water)
|
||||
*
|
||||
* @param blockFrom
|
||||
* the block where the fluid came from.
|
||||
* (blocktype = fluid type)
|
||||
* @param blockTo
|
||||
* the block where fluid wants to flow to.
|
||||
*
|
||||
*
|
||||
* @return true if you dont want the substance to flow.
|
||||
*/
|
||||
@Override
|
||||
public boolean onFlow(Block blockFrom, Block blockTo) {
|
||||
int x = blockFrom.getX();
|
||||
int y = blockFrom.getY();
|
||||
int z = blockFrom.getZ();
|
||||
|
||||
boolean isWater = blockFrom.getType() == 8 || blockFrom.getType() == 9;
|
||||
boolean isLava = blockFrom.getType() == 10 || blockFrom.getType() == 11;
|
||||
|
||||
if (simulateSponge && isWater) {
|
||||
int ox = blockTo.getX();
|
||||
int oy = blockTo.getY();
|
||||
int oz = blockTo.getZ();
|
||||
|
||||
Server server = etc.getServer();
|
||||
|
||||
for (int cx = -spongeRadius; cx <= spongeRadius; cx++) {
|
||||
for (int cy = -spongeRadius; cy <= spongeRadius; cy++) {
|
||||
for (int cz = -spongeRadius; cz <= spongeRadius; cz++) {
|
||||
if (server.getBlockIdAt(ox + cx, oy + cy, oz + cz) == 19) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (classicWater && isWater) {
|
||||
int blockBelow = etc.getServer().getBlockIdAt(blockFrom.getX(), blockFrom.getY() - 1, blockFrom.getZ());
|
||||
if (blockBelow != 0 && blockBelow != 8 && blockBelow != 9) {
|
||||
etc.getServer().setBlockAt(9, blockFrom.getX(), blockFrom.getY(), blockFrom.getZ());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (allowedLavaSpreadOver != null && isLava) {
|
||||
int targetId = etc.getServer().getBlockIdAt(
|
||||
blockTo.getX(), blockTo.getY() - 1, blockTo.getZ());
|
||||
if (!allowedLavaSpreadOver.contains(targetId)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the game is checking the physics for a certain block.
|
||||
* This method is called frequently whenever a nearby block is changed,
|
||||
* or if the block has just been placed.
|
||||
* Currently the only supported blocks are sand, gravel and portals.
|
||||
*
|
||||
* @param block Block which requires special physics
|
||||
* @param boolean true if this block has just been placed
|
||||
* @return true if you do want to stop the default physics for this block
|
||||
*/
|
||||
public boolean onBlockPhysics(Block block, boolean placed) {
|
||||
int id = block.getType();
|
||||
|
||||
if (id == 13 && noPhysicsGravel) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (id == 12 && noPhysicsSand) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (id == 90 && allowPortalAnywhere) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on player disconnect
|
||||
*
|
||||
* @param player
|
||||
*/
|
||||
@Override
|
||||
public void onDisconnect(Player player) {
|
||||
BlacklistEntry.forgetPlayer(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call to disable the plugin.
|
||||
*/
|
||||
public void disable() {
|
||||
if (blacklist != null) {
|
||||
blacklist.getLogger().close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<assembly
|
||||
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
|
||||
<includeBaseDirectory>false</includeBaseDirectory>
|
||||
<formats>
|
||||
<format>tar.gz</format>
|
||||
<format>tar.bz2</format>
|
||||
<format>zip</format>
|
||||
</formats>
|
||||
<files>
|
||||
<file>
|
||||
<source>${project.build.directory}/${artifactId}-${project.version}.jar</source>
|
||||
<destName>WorldGuard.jar</destName>
|
||||
<outputDirectory>/</outputDirectory>
|
||||
<filtered>false</filtered>
|
||||
</file>
|
||||
<file>
|
||||
<source>README.html</source>
|
||||
<outputDirectory>/</outputDirectory>
|
||||
<filtered>true</filtered>
|
||||
</file>
|
||||
</files>
|
||||
<fileSets>
|
||||
<fileSet>
|
||||
<includes>
|
||||
<include>LICENSE.txt</include>
|
||||
<include>NOTICE.txt</include>
|
||||
<include>CHANGELOG.txt</include>
|
||||
<include>contrib/blacklist_table.sql</include>
|
||||
<include>contrib/region_storage.sql</include>
|
||||
<include>contrib/region_storage_update_20110325.sql</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</assembly>
|
||||
@@ -0,0 +1,94 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
|
||||
public abstract class LocalPlayer {
|
||||
/**
|
||||
* Get a player's name.
|
||||
*
|
||||
* @return The player's name
|
||||
*/
|
||||
public abstract String getName();
|
||||
|
||||
/**
|
||||
* Returns true if the player is inside a group.
|
||||
*
|
||||
* @param group The group to check
|
||||
* @return Whether this player is in {@code group}
|
||||
*/
|
||||
public abstract boolean hasGroup(String group);
|
||||
|
||||
/**
|
||||
* Get the player's position.
|
||||
*
|
||||
* @return The player's position
|
||||
*/
|
||||
public abstract Vector getPosition();
|
||||
|
||||
/**
|
||||
* Kick the player.
|
||||
*
|
||||
* @param msg The message to kick the player with
|
||||
*/
|
||||
public abstract void kick(String msg);
|
||||
|
||||
/**
|
||||
* Ban the player.
|
||||
*
|
||||
* @param msg The message to ban the player with
|
||||
*/
|
||||
public abstract void ban(String msg);
|
||||
|
||||
/**
|
||||
* Send the player a message;
|
||||
*
|
||||
* @param msg The message to send to the player
|
||||
*/
|
||||
public abstract void printRaw(String msg);
|
||||
|
||||
/**
|
||||
* Get the player's list of groups.
|
||||
*
|
||||
* @return The groups this player is in
|
||||
*/
|
||||
public abstract String[] getGroups();
|
||||
|
||||
/**
|
||||
* Returns whether a player has permission.
|
||||
*
|
||||
* @param perm The permission to check
|
||||
* @return Whether this player has {@code perm}
|
||||
*/
|
||||
public abstract boolean hasPermission(String perm);
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
|
||||
return obj instanceof LocalPlayer && ((LocalPlayer) obj).getName().equals(getName());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getName().hashCode();
|
||||
}
|
||||
}
|
||||
+156
-219
@@ -17,24 +17,31 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import java.util.Map;
|
||||
package com.sk89q.worldguard.blacklist;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.io.*;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import com.sk89q.worldedit.blocks.ItemType;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.blacklist.events.BlacklistEvent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class Blacklist {
|
||||
/**
|
||||
* Logger.
|
||||
*/
|
||||
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
||||
|
||||
public abstract class Blacklist {
|
||||
|
||||
/**
|
||||
* List of entries by block ID.
|
||||
*/
|
||||
@@ -44,16 +51,29 @@ public class Blacklist {
|
||||
* Logger.
|
||||
*/
|
||||
private BlacklistLogger blacklistLogger = new BlacklistLogger();
|
||||
|
||||
/**
|
||||
* Blacklist contains on-acquire events.
|
||||
* Last event.
|
||||
*/
|
||||
private boolean hasOnAcquire;
|
||||
private BlacklistEvent lastEvent;
|
||||
/**
|
||||
* Used to prevent flooding.
|
||||
*/
|
||||
Map<String,BlacklistTrackedEvent> lastAffected =
|
||||
new HashMap<String,BlacklistTrackedEvent>();
|
||||
|
||||
private boolean useAsWhitelist;
|
||||
|
||||
private final Logger logger;
|
||||
|
||||
public Blacklist(Boolean useAsWhitelist, Logger logger) {
|
||||
this.useAsWhitelist = useAsWhitelist;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the list is empty.
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @return whether the blacklist is empty
|
||||
*/
|
||||
public boolean isEmpty() {
|
||||
return blacklist.isEmpty();
|
||||
@@ -61,205 +81,57 @@ public class Blacklist {
|
||||
|
||||
/**
|
||||
* Get the entries for an item or list.
|
||||
*
|
||||
* @param id The item id to get blacklist information for
|
||||
* @return The blacklist entries for {@code id}
|
||||
*/
|
||||
public List<BlacklistEntry> getEntries(int id) {
|
||||
return blacklist.get(id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the number of individual items that have blacklist entries.
|
||||
*
|
||||
* @return The number of items in the blacklist
|
||||
*/
|
||||
public int getItemCount() {
|
||||
return blacklist.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the blacklist is used as a whitelist.
|
||||
*
|
||||
* @return whether the blacklist is be used as a whitelist
|
||||
*/
|
||||
public boolean isWhitelist() {
|
||||
return useAsWhitelist;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the logger.
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @return The logger used in this blacklist
|
||||
*/
|
||||
public BlacklistLogger getLogger() {
|
||||
return blacklistLogger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on block destruction. Returns true to let the action pass
|
||||
* through.
|
||||
* Method to handle the event.
|
||||
*
|
||||
* @param block
|
||||
* @param player
|
||||
* @return
|
||||
* @param event The event to check
|
||||
* @param forceRepeat Whether to force quickly repeating notifications
|
||||
* @param silent Whether to force-deny notifications
|
||||
* @return Whether the event is allowed
|
||||
*/
|
||||
public boolean onDestroy(final Block block, final Player player) {
|
||||
List<BlacklistEntry> entries = getEntries(block.getType());
|
||||
public boolean check(BlacklistEvent event, boolean forceRepeat, boolean silent) {
|
||||
List<BlacklistEntry> entries = getEntries(event.getType());
|
||||
if (entries == null) {
|
||||
return true;
|
||||
}
|
||||
boolean ret = true;
|
||||
for (BlacklistEntry entry : entries) {
|
||||
if (!entry.onDestroy(block, player)) {
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on block break. Returns true to let the action pass
|
||||
* through.
|
||||
*
|
||||
* @param block
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean onBreak(final Block block, final Player player) {
|
||||
List<BlacklistEntry> entries = getEntries(block.getType());
|
||||
if (entries == null) {
|
||||
return true;
|
||||
}
|
||||
boolean ret = true;
|
||||
for (BlacklistEntry entry : entries) {
|
||||
if (!entry.onBreak(block, player)) {
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on left click. Returns true to let the action pass through.
|
||||
*
|
||||
* @param item
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean onDestroyWith(int item, Player player) {
|
||||
List<BlacklistEntry> entries = getEntries(item);
|
||||
if (entries == null) {
|
||||
return true;
|
||||
}
|
||||
boolean ret = true;
|
||||
for (BlacklistEntry entry : entries) {
|
||||
if (!entry.onDestroyWith(item, player)) {
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on right click. Returns true to let the action pass through.
|
||||
*
|
||||
* @param item
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean onCreate(int item, Player player) {
|
||||
List<BlacklistEntry> entries = getEntries(item);
|
||||
if (entries == null) {
|
||||
return true;
|
||||
}
|
||||
boolean ret = true;
|
||||
for (BlacklistEntry entry : entries) {
|
||||
if (!entry.onCreate(item, player)) {
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on right click upon. Returns true to let the action pass through.
|
||||
*
|
||||
* @param item
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean onUse(Block block, Player player) {
|
||||
List<BlacklistEntry> entries = getEntries(block.getType());
|
||||
if (entries == null) {
|
||||
return true;
|
||||
}
|
||||
boolean ret = true;
|
||||
for (BlacklistEntry entry : entries) {
|
||||
if (!entry.onUse(block, player)) {
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on right click upon. Returns true to let the action pass through.
|
||||
*
|
||||
* @param item
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean onSilentUse(Block block, Player player) {
|
||||
List<BlacklistEntry> entries = getEntries(block.getType());
|
||||
if (entries == null) {
|
||||
return true;
|
||||
}
|
||||
boolean ret = true;
|
||||
for (BlacklistEntry entry : entries) {
|
||||
if (!entry.onSilentUse(block, player)) {
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on drop. Returns true to let the action pass through.
|
||||
*
|
||||
* @param item
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean onDrop(int item, Player player) {
|
||||
List<BlacklistEntry> entries = getEntries(item);
|
||||
if (entries == null) {
|
||||
return true;
|
||||
}
|
||||
boolean ret = true;
|
||||
for (BlacklistEntry entry : entries) {
|
||||
if (!entry.onDrop(item, player)) {
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on acquire. Returns true to let the action pass through.
|
||||
*
|
||||
* @param item
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean onAcquire(int item, Player player) {
|
||||
List<BlacklistEntry> entries = getEntries(item);
|
||||
if (entries == null) {
|
||||
return true;
|
||||
}
|
||||
boolean ret = true;
|
||||
for (BlacklistEntry entry : entries) {
|
||||
if (!entry.onAcquire(item, player)) {
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on acquire. Returns true to let the action pass through.
|
||||
*
|
||||
* @param item
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean onSilentAcquire(int item, Player player) {
|
||||
List<BlacklistEntry> entries = getEntries(item);
|
||||
if (entries == null) {
|
||||
return true;
|
||||
}
|
||||
boolean ret = true;
|
||||
for (BlacklistEntry entry : entries) {
|
||||
if (!entry.onSilentAcquire(item, player)) {
|
||||
if (!entry.check(useAsWhitelist, event, forceRepeat, silent)) {
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
@@ -269,9 +141,8 @@ public class Blacklist {
|
||||
/**
|
||||
* Load the blacklist.
|
||||
*
|
||||
* @param file
|
||||
* @return
|
||||
* @throws IOException
|
||||
* @param file The file to load from
|
||||
* @throws IOException if an error occurred reading from the file
|
||||
*/
|
||||
public void load(File file) throws IOException {
|
||||
FileReader input = null;
|
||||
@@ -282,8 +153,6 @@ public class Blacklist {
|
||||
input = new FileReader(file);
|
||||
BufferedReader buff = new BufferedReader(input);
|
||||
|
||||
hasOnAcquire = false;
|
||||
|
||||
String line;
|
||||
List<BlacklistEntry> currentEntries = null;
|
||||
while ((line = buff.readLine()) != null) {
|
||||
@@ -301,14 +170,14 @@ public class Blacklist {
|
||||
currentEntries = new ArrayList<BlacklistEntry>();
|
||||
|
||||
for (String item : items) {
|
||||
int id = 0;
|
||||
int id;
|
||||
|
||||
try {
|
||||
id = Integer.parseInt(item.trim());
|
||||
} catch (NumberFormatException e) {
|
||||
id = etc.getDataSource().getItem(item.trim());
|
||||
id = getItemID(item.trim());
|
||||
if (id == 0) {
|
||||
logger.log(Level.WARNING, "WorldGuard: Unknown block name: "
|
||||
logger.log(Level.WARNING, "Unknown block name: "
|
||||
+ item);
|
||||
break;
|
||||
}
|
||||
@@ -338,23 +207,21 @@ public class Blacklist {
|
||||
for (BlacklistEntry entry : currentEntries) {
|
||||
if (parts[0].equalsIgnoreCase("ignore-groups")) {
|
||||
entry.setIgnoreGroups(parts[1].split(","));
|
||||
} else if (parts[0].equalsIgnoreCase("on-destroy")) {
|
||||
entry.setDestroyActions(parts[1].split(","));
|
||||
} else if (parts[0].equalsIgnoreCase("ignore-perms")) {
|
||||
entry.setIgnorePermissions(parts[1].split(","));
|
||||
} else if (parts[0].equalsIgnoreCase("on-break")) {
|
||||
entry.setBreakActions(parts[1].split(","));
|
||||
} else if (parts[0].equalsIgnoreCase("on-left")
|
||||
|| parts[0].equalsIgnoreCase("on-destroy-with")) {
|
||||
} else if (parts[0].equalsIgnoreCase("on-destroy-with")) {
|
||||
entry.setDestroyWithActions(parts[1].split(","));
|
||||
} else if (parts[0].equalsIgnoreCase("on-right")
|
||||
|| parts[0].equalsIgnoreCase("on-create")) {
|
||||
entry.setCreateActions(parts[1].split(","));
|
||||
} else if (parts[0].equalsIgnoreCase("on-right-on")
|
||||
|| parts[0].equalsIgnoreCase("on-use")) {
|
||||
} else if (parts[0].equalsIgnoreCase("on-place")) {
|
||||
entry.setPlaceActions(parts[1].split(","));
|
||||
} else if (parts[0].equalsIgnoreCase("on-interact")) {
|
||||
entry.setInteractActions(parts[1].split(","));
|
||||
} else if (parts[0].equalsIgnoreCase("on-use")) {
|
||||
entry.setUseActions(parts[1].split(","));
|
||||
} else if (parts[0].equalsIgnoreCase("on-drop")) {
|
||||
entry.setDropActions(parts[1].split(","));
|
||||
} else if (parts[0].equalsIgnoreCase("on-acquire")) {
|
||||
hasOnAcquire = true;
|
||||
entry.setAcquireActions(parts[1].split(","));
|
||||
} else if (parts[0].equalsIgnoreCase("message")) {
|
||||
entry.setMessage(parts[1].trim());
|
||||
@@ -381,17 +248,87 @@ public class Blacklist {
|
||||
if (input != null) {
|
||||
input.close();
|
||||
}
|
||||
} catch (IOException e2) {
|
||||
} catch (IOException ignore) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Blacklist contains on-acquire events.
|
||||
*
|
||||
* @return
|
||||
* Get the last event.
|
||||
*
|
||||
* @return The last event
|
||||
*/
|
||||
public boolean hasOnAcquire() {
|
||||
return hasOnAcquire;
|
||||
public BlacklistEvent getLastEvent() {
|
||||
return lastEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify administrators.
|
||||
*
|
||||
* @param event The event to notify about
|
||||
* @param comment The comment to notify with
|
||||
*/
|
||||
public void notify(BlacklistEvent event, String comment) {
|
||||
lastEvent = event;
|
||||
|
||||
broadcastNotification(ChatColor.GRAY + "WG: "
|
||||
+ ChatColor.LIGHT_PURPLE + event.getPlayer().getName()
|
||||
+ ChatColor.GOLD + " (" + event.getDescription() + ") "
|
||||
+ ChatColor.WHITE
|
||||
+ getFriendlyItemName(event.getType())
|
||||
+ (comment != null ? " (" + comment + ")" : "") + ".");
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a notification to all subscribing users.
|
||||
*
|
||||
* @param msg The message to broadcast
|
||||
*/
|
||||
public abstract void broadcastNotification(String msg);
|
||||
|
||||
/**
|
||||
* Forget a player.
|
||||
*
|
||||
* @param player The player to forget
|
||||
*/
|
||||
public void forgetPlayer(LocalPlayer player) {
|
||||
lastAffected.remove(player.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Forget all players.
|
||||
*/
|
||||
public void forgetAllPlayers() {
|
||||
lastAffected.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an item's ID from its name.
|
||||
*
|
||||
* @param name the name of the item to look up
|
||||
* @return the id for name if contained in ItemId, else -1
|
||||
*/
|
||||
private static int getItemID(String name) {
|
||||
ItemType type = ItemType.lookup(name);
|
||||
if (type != null) {
|
||||
return type.getID();
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an item's friendly name with its ID.
|
||||
*
|
||||
* @param id The id to look up
|
||||
* @return The item's friendly name
|
||||
*/
|
||||
private static String getFriendlyItemName(int id) {
|
||||
ItemType type = ItemType.fromID(id);
|
||||
if (type != null) {
|
||||
return type.getName() + " (#" + id + ")";
|
||||
} else {
|
||||
return "#" + id + "";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,424 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.blacklist;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import com.sk89q.worldedit.blocks.ItemType;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.blacklist.events.BlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.events.BlockBreakBlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.events.BlockInteractBlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.events.BlockPlaceBlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.events.DestroyWithBlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.events.ItemAcquireBlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.events.ItemDropBlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.events.ItemUseBlacklistEvent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class BlacklistEntry {
|
||||
/**
|
||||
* Parent blacklist entry.
|
||||
*/
|
||||
private Blacklist blacklist;
|
||||
|
||||
/**
|
||||
* List of groups to not affect.
|
||||
*/
|
||||
private Set<String> ignoreGroups;
|
||||
|
||||
/**
|
||||
* List of permissions to not affect.
|
||||
*/
|
||||
private Set<String> ignorePermissions;
|
||||
|
||||
private String[] breakActions;
|
||||
private String[] destroyWithActions;
|
||||
private String[] placeActions;
|
||||
private String[] interactActions;
|
||||
private String[] useActions;
|
||||
private String[] dropActions;
|
||||
private String[] acquireActions;
|
||||
|
||||
private String message;
|
||||
private String comment;
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param blacklist The blacklist that contains this entry
|
||||
*/
|
||||
public BlacklistEntry(Blacklist blacklist) {
|
||||
this.blacklist = blacklist;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the ignoreGroups
|
||||
*/
|
||||
public String[] getIgnoreGroups() {
|
||||
return ignoreGroups.toArray(new String[ignoreGroups.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the ignoreGroups
|
||||
*/
|
||||
public String[] getIgnorePermissions() {
|
||||
return ignorePermissions.toArray(new String[ignorePermissions.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ignoreGroups the ignoreGroups to set
|
||||
*/
|
||||
public void setIgnoreGroups(String[] ignoreGroups) {
|
||||
Set<String> ignoreGroupsSet = new HashSet<String>();
|
||||
for (String group : ignoreGroups) {
|
||||
ignoreGroupsSet.add(group.toLowerCase());
|
||||
}
|
||||
this.ignoreGroups = ignoreGroupsSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ignorePermissions the ignorePermissions to set
|
||||
*/
|
||||
public void setIgnorePermissions(String[] ignorePermissions) {
|
||||
Set<String> ignorePermissionsSet = new HashSet<String>();
|
||||
Collections.addAll(ignorePermissionsSet, ignorePermissions);
|
||||
this.ignorePermissions = ignorePermissionsSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The actions that occur when breaking
|
||||
*/
|
||||
public String[] getBreakActions() {
|
||||
return breakActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param actions The actions to occur when breaking
|
||||
*/
|
||||
public void setBreakActions(String[] actions) {
|
||||
this.breakActions = actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The actions that occur when destroying with a specific item
|
||||
*/
|
||||
public String[] getDestroyWithActions() {
|
||||
return destroyWithActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param actions The actions to occur when destroying with an item
|
||||
*/
|
||||
public void setDestroyWithActions(String[] actions) {
|
||||
this.destroyWithActions = actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The actions that will occur when placing
|
||||
*/
|
||||
public String[] getPlaceActions() {
|
||||
return placeActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param actions The actions to occur when placing
|
||||
*/
|
||||
public void setPlaceActions(String[] actions) {
|
||||
this.placeActions = actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The actions that will occur when interacting
|
||||
*/
|
||||
public String[] getInteractActions() {
|
||||
return interactActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param actions The actions to occur when interacting
|
||||
*/
|
||||
public void setInteractActions(String[] actions) {
|
||||
this.interactActions = actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The actions that will occur when using
|
||||
*/
|
||||
public String[] getUseActions() {
|
||||
return useActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param actions The actions to occur when using
|
||||
*/
|
||||
public void setUseActions(String[] actions) {
|
||||
this.useActions = actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The actions that will occur when dropping
|
||||
*/
|
||||
public String[] getDropActions() {
|
||||
return dropActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param actions The actions to occur when dropping
|
||||
*/
|
||||
public void setDropActions(String[] actions) {
|
||||
this.dropActions = actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The actions that will occur when acquiring
|
||||
*/
|
||||
public String[] getAcquireActions() {
|
||||
return acquireActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param actions The actions to occur when acquiring
|
||||
*/
|
||||
public void setAcquireActions(String[] actions) {
|
||||
this.acquireActions = actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the message
|
||||
*/
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message the message to set
|
||||
*/
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the comment
|
||||
*/
|
||||
public String getComment() {
|
||||
return comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param comment the comment to set
|
||||
*/
|
||||
public void setComment(String comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this player should be ignored.
|
||||
*
|
||||
* @param player The player to check
|
||||
* @return whether this player should be ignored for blacklist blocking
|
||||
*/
|
||||
public boolean shouldIgnore(LocalPlayer player) {
|
||||
if (ignoreGroups != null) {
|
||||
for (String group : player.getGroups()) {
|
||||
if (ignoreGroups.contains(group.toLowerCase())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ignorePermissions != null) {
|
||||
for (String perm : ignorePermissions) {
|
||||
if (player.hasPermission(perm)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the associated actions with an event.
|
||||
*
|
||||
* @param event The event to check
|
||||
* @return The actions for the given event
|
||||
*/
|
||||
private String[] getActions(BlacklistEvent event) {
|
||||
if (event instanceof BlockBreakBlacklistEvent) {
|
||||
return breakActions;
|
||||
|
||||
} else if (event instanceof BlockPlaceBlacklistEvent) {
|
||||
return placeActions;
|
||||
|
||||
} else if (event instanceof BlockInteractBlacklistEvent) {
|
||||
return interactActions;
|
||||
|
||||
} else if (event instanceof DestroyWithBlacklistEvent) {
|
||||
return destroyWithActions;
|
||||
|
||||
} else if (event instanceof ItemAcquireBlacklistEvent) {
|
||||
return acquireActions;
|
||||
|
||||
} else if (event instanceof ItemDropBlacklistEvent) {
|
||||
return dropActions;
|
||||
|
||||
} else if (event instanceof ItemUseBlacklistEvent) {
|
||||
return useActions;
|
||||
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to handle the event.
|
||||
*
|
||||
* @param useAsWhitelist Whether this entry is buing used in a whitelist
|
||||
* @param event The event to check
|
||||
* @param forceRepeat Whether to force repeating notifications even within the delay limit
|
||||
* @param silent Whether to prevent notifications from happening
|
||||
* @return Whether the action was allowed
|
||||
*/
|
||||
public boolean check(boolean useAsWhitelist, BlacklistEvent event, boolean forceRepeat, boolean silent) {
|
||||
LocalPlayer player = event.getPlayer();
|
||||
|
||||
if (shouldIgnore(player)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String name = player.getName();
|
||||
long now = System.currentTimeMillis();
|
||||
boolean repeating = false;
|
||||
|
||||
// Check to see whether this event is being repeated
|
||||
BlacklistTrackedEvent tracked = blacklist.lastAffected.get(name);
|
||||
if (tracked != null) {
|
||||
if (tracked.matches(event, now)) {
|
||||
repeating = true;
|
||||
}
|
||||
} else {
|
||||
blacklist.lastAffected.put(name, new BlacklistTrackedEvent(event, now));
|
||||
}
|
||||
|
||||
String actions[] = getActions(event);
|
||||
|
||||
|
||||
boolean ret = !useAsWhitelist;
|
||||
|
||||
// Nothing to do
|
||||
if (actions == null) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
for (String action : actions) {
|
||||
// Deny
|
||||
if (action.equalsIgnoreCase("deny")) {
|
||||
if (silent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = false;
|
||||
|
||||
// Allow
|
||||
} else if (action.equalsIgnoreCase("allow")) {
|
||||
if (silent) {
|
||||
return true;
|
||||
}
|
||||
|
||||
ret = true;
|
||||
|
||||
// Kick
|
||||
} else if (action.equalsIgnoreCase("kick")) {
|
||||
if (silent) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (this.message != null) {
|
||||
player.kick(String.format(this.message,
|
||||
getFriendlyItemName(event.getType())));
|
||||
} else {
|
||||
player.kick("You can't " + event.getDescription() + " "
|
||||
+ getFriendlyItemName(event.getType()));
|
||||
}
|
||||
|
||||
// Ban
|
||||
} else if (action.equalsIgnoreCase("ban")) {
|
||||
if (silent) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (this.message != null) {
|
||||
player.ban("Banned: " + String.format(this.message,
|
||||
getFriendlyItemName(event.getType())));
|
||||
} else {
|
||||
player.ban("Banned: You can't "
|
||||
+ event.getDescription() + " "
|
||||
+ getFriendlyItemName(event.getType()));
|
||||
}
|
||||
|
||||
} else if (!silent && (!repeating || forceRepeat)) {
|
||||
// Notify
|
||||
if (action.equalsIgnoreCase("notify")) {
|
||||
blacklist.notify(event, comment);
|
||||
|
||||
// Log
|
||||
} else if (action.equalsIgnoreCase("log")) {
|
||||
blacklist.getLogger().logEvent(event, comment);
|
||||
|
||||
// Tell
|
||||
} else if (action.equalsIgnoreCase("tell")) {
|
||||
if (this.message != null) {
|
||||
player.printRaw(ChatColor.YELLOW +
|
||||
String.format(message, getFriendlyItemName(event.getType()))
|
||||
+ ".");
|
||||
} else {
|
||||
player.printRaw(ChatColor.YELLOW + "You're not allowed to "
|
||||
+ event.getDescription() + " "
|
||||
+ getFriendlyItemName(event.getType()) + ".");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an item's friendly name with its ID.
|
||||
*
|
||||
* @param id The id to get a name for
|
||||
*/
|
||||
private static String getFriendlyItemName(int id) {
|
||||
ItemType type = ItemType.fromID(id);
|
||||
if (type != null) {
|
||||
return type.getName() + " (#" + id + ")";
|
||||
} else {
|
||||
return "#" + id + "";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.blacklist;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.sk89q.worldguard.blacklist.events.BlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.loggers.BlacklistLoggerHandler;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class BlacklistLogger implements BlacklistLoggerHandler {
|
||||
/**
|
||||
* List of logger handlers.
|
||||
*/
|
||||
private Set<BlacklistLoggerHandler> handlers
|
||||
= new HashSet<BlacklistLoggerHandler>();
|
||||
|
||||
/**
|
||||
* Add a handler.
|
||||
*
|
||||
* @param handler The handler to add
|
||||
*/
|
||||
public void addHandler(BlacklistLoggerHandler handler) {
|
||||
handlers.add(handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a handler.
|
||||
*
|
||||
* @param handler The handler to remove
|
||||
*/
|
||||
public void removeHandler(BlacklistLoggerHandler handler) {
|
||||
handlers.remove(handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a handler.
|
||||
*/
|
||||
public void clearHandlers() {
|
||||
handlers.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Log an event.
|
||||
*
|
||||
* @param event The event to log
|
||||
*/
|
||||
public void logEvent(BlacklistEvent event, String comment) {
|
||||
for (BlacklistLoggerHandler handler : handlers) {
|
||||
handler.logEvent(event, comment);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the connection.
|
||||
*/
|
||||
public void close() {
|
||||
for (BlacklistLoggerHandler handler : handlers) {
|
||||
handler.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
-32
@@ -17,50 +17,32 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.blacklist;
|
||||
|
||||
import com.sk89q.worldguard.blacklist.events.BlacklistEvent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class BlacklistTrackedEvent {
|
||||
private int id;
|
||||
private BlacklistEvent event;
|
||||
private long time;
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param id
|
||||
* @param time
|
||||
*
|
||||
* @param event The event tracked
|
||||
* @param time The time at which the event occurred
|
||||
*/
|
||||
public BlacklistTrackedEvent(int id, long time) {
|
||||
this.id = id;
|
||||
public BlacklistTrackedEvent(BlacklistEvent event, long time) {
|
||||
this.event = event;
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id the id to set
|
||||
*/
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the time
|
||||
*/
|
||||
public long getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param time the time to set
|
||||
*/
|
||||
public void setTime(long time) {
|
||||
this.time = time;
|
||||
public boolean matches(BlacklistEvent other, long now) {
|
||||
return other.getType() == event.getType()
|
||||
&& time > now - 3000
|
||||
&& other.getClass() == event.getClass();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.blacklist.events;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
|
||||
/**
|
||||
* Represents a blacklist event.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public abstract class BlacklistEvent {
|
||||
private Vector pos;
|
||||
private int type;
|
||||
|
||||
/**
|
||||
* Holds the player that triggered the event.
|
||||
*/
|
||||
private LocalPlayer player;
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param player The player associated with this event
|
||||
* @param pos The position the event occurred at
|
||||
* @param type The type of item used
|
||||
*/
|
||||
public BlacklistEvent(LocalPlayer player, Vector pos, int type) {
|
||||
this.player = player;
|
||||
this.pos = pos;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the player.
|
||||
*
|
||||
* @return The player associated with this event
|
||||
*/
|
||||
public LocalPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the position.
|
||||
*
|
||||
* @return The position of this event
|
||||
*/
|
||||
public Vector getPosition() {
|
||||
return pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the item type.
|
||||
*
|
||||
* @return The type associated with this event
|
||||
*/
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a short description such as "break" or "destroy with."
|
||||
*
|
||||
* @return The event description
|
||||
*/
|
||||
public abstract String getDescription();
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.blacklist.events;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
|
||||
public abstract class BlockBlacklistEvent extends BlacklistEvent {
|
||||
public BlockBlacklistEvent(LocalPlayer player, Vector pos, int type) {
|
||||
super(player, pos, type);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.blacklist.events;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
|
||||
public class BlockBreakBlacklistEvent extends BlockBlacklistEvent {
|
||||
public BlockBreakBlacklistEvent(LocalPlayer player, Vector pos, int type) {
|
||||
super(player, pos, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "break";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.blacklist.events;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
|
||||
public class BlockInteractBlacklistEvent extends BlockBlacklistEvent {
|
||||
public BlockInteractBlacklistEvent(LocalPlayer player, Vector pos, int type) {
|
||||
super(player, pos, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "interact with";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.blacklist.events;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
|
||||
public class BlockPlaceBlacklistEvent extends BlockBlacklistEvent {
|
||||
public BlockPlaceBlacklistEvent(LocalPlayer player, Vector pos, int type) {
|
||||
super(player, pos, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "place";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.blacklist.events;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
|
||||
public class DestroyWithBlacklistEvent extends BlacklistEvent {
|
||||
public DestroyWithBlacklistEvent(LocalPlayer player, Vector pos, int type) {
|
||||
super(player, pos, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "destroy with";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.blacklist.events;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
|
||||
public class ItemAcquireBlacklistEvent extends ItemBlacklistEvent {
|
||||
public ItemAcquireBlacklistEvent(LocalPlayer player, Vector pos, int type) {
|
||||
super(player, pos, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "acquire";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.blacklist.events;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
|
||||
public abstract class ItemBlacklistEvent extends BlacklistEvent {
|
||||
public ItemBlacklistEvent(LocalPlayer player, Vector pos, int type) {
|
||||
super(player, pos, type);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.blacklist.events;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
|
||||
public class ItemDropBlacklistEvent extends ItemBlacklistEvent {
|
||||
public ItemDropBlacklistEvent(LocalPlayer player, Vector pos, int type) {
|
||||
super(player, pos, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "drop";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.blacklist.events;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
|
||||
public class ItemUseBlacklistEvent extends ItemBlacklistEvent {
|
||||
public ItemUseBlacklistEvent(LocalPlayer player, Vector pos, int type) {
|
||||
super(player, pos, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "use";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.blacklist.loggers;
|
||||
|
||||
import com.sk89q.worldguard.blacklist.events.BlacklistEvent;
|
||||
|
||||
/**
|
||||
* Interface for loggers for the blacklist.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public interface BlacklistLoggerHandler {
|
||||
/**
|
||||
* Log an event.
|
||||
*
|
||||
* @param event
|
||||
* @param comment
|
||||
*/
|
||||
public void logEvent(BlacklistEvent event, String comment);
|
||||
|
||||
/**
|
||||
* Close the logger.
|
||||
*/
|
||||
public void close();
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.blacklist.loggers;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.sk89q.worldedit.blocks.ItemType;
|
||||
import com.sk89q.worldguard.blacklist.events.BlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.events.BlockBreakBlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.events.BlockInteractBlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.events.BlockPlaceBlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.events.DestroyWithBlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.events.ItemAcquireBlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.events.ItemDropBlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.events.ItemUseBlacklistEvent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class ConsoleLoggerHandler implements BlacklistLoggerHandler {
|
||||
|
||||
|
||||
private String worldName;
|
||||
|
||||
private final Logger logger;
|
||||
|
||||
public ConsoleLoggerHandler(String worldName, Logger logger) {
|
||||
this.worldName = worldName;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public void logEvent(BlacklistEvent event, String comment) {
|
||||
// Block break
|
||||
if (event instanceof BlockBreakBlacklistEvent) {
|
||||
BlockBreakBlacklistEvent evt = (BlockBreakBlacklistEvent)event;
|
||||
logger.log(Level.INFO, "[" + worldName + "] " + event.getPlayer().getName()
|
||||
+ " tried to break " + getFriendlyItemName(evt.getType())
|
||||
+ (comment != null ? " (" + comment + ")" : ""));
|
||||
|
||||
// Block place
|
||||
} else if (event instanceof BlockPlaceBlacklistEvent) {
|
||||
BlockPlaceBlacklistEvent evt = (BlockPlaceBlacklistEvent)event;
|
||||
logger.log(Level.INFO, "[" + worldName + "] " + event.getPlayer().getName()
|
||||
+ " tried to place " + getFriendlyItemName(evt.getType())
|
||||
+ (comment != null ? " (" + comment + ")" : ""));
|
||||
|
||||
// Block interact
|
||||
} else if (event instanceof BlockInteractBlacklistEvent) {
|
||||
BlockInteractBlacklistEvent evt = (BlockInteractBlacklistEvent)event;
|
||||
logger.log(Level.INFO, "[" + worldName + "] " + event.getPlayer().getName()
|
||||
+ " tried to interact with " + getFriendlyItemName(evt.getType())
|
||||
+ (comment != null ? " (" + comment + ")" : ""));
|
||||
|
||||
// Destroy with
|
||||
} else if (event instanceof DestroyWithBlacklistEvent) {
|
||||
DestroyWithBlacklistEvent evt = (DestroyWithBlacklistEvent)event;
|
||||
logger.log(Level.INFO, "[" + worldName + "] " + event.getPlayer().getName()
|
||||
+ " tried to destroy with " + getFriendlyItemName(evt.getType())
|
||||
+ (comment != null ? " (" + comment + ")" : ""));
|
||||
|
||||
// Acquire
|
||||
} else if (event instanceof ItemAcquireBlacklistEvent) {
|
||||
ItemAcquireBlacklistEvent evt = (ItemAcquireBlacklistEvent)event;
|
||||
logger.log(Level.INFO, "[" + worldName + "] " + event.getPlayer().getName()
|
||||
+ " tried to acquire " + getFriendlyItemName(evt.getType())
|
||||
+ (comment != null ? " (" + comment + ")" : ""));
|
||||
|
||||
// Drop
|
||||
} else if (event instanceof ItemDropBlacklistEvent) {
|
||||
ItemDropBlacklistEvent evt = (ItemDropBlacklistEvent)event;
|
||||
logger.log(Level.INFO, "[" + worldName + "] " + event.getPlayer().getName()
|
||||
+ " tried to drop " + getFriendlyItemName(evt.getType())
|
||||
+ (comment != null ? " (" + comment + ")" : ""));
|
||||
|
||||
// Use
|
||||
} else if (event instanceof ItemUseBlacklistEvent) {
|
||||
ItemUseBlacklistEvent evt = (ItemUseBlacklistEvent)event;
|
||||
logger.log(Level.INFO, "[" + worldName + "] " + event.getPlayer().getName()
|
||||
+ " tried to use " + getFriendlyItemName(evt.getType())
|
||||
+ (comment != null ? " (" + comment + ")" : ""));
|
||||
|
||||
// Unknown
|
||||
} else {
|
||||
logger.log(Level.INFO, "[" + worldName + "] " + event.getPlayer().getName()
|
||||
+ " caught unknown event: " + event.getClass().getCanonicalName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an item's friendly name with its ID.
|
||||
*
|
||||
* @param id The item id
|
||||
* @return The friendly name of the item
|
||||
*/
|
||||
private static String getFriendlyItemName(int id) {
|
||||
ItemType type = ItemType.fromID(id);
|
||||
if (type != null) {
|
||||
return type.getName() + " (#" + id + ")";
|
||||
} else {
|
||||
return "#" + id;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the connection.
|
||||
*/
|
||||
public void close() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.blacklist.loggers;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.blacklist.events.BlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.events.BlockBreakBlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.events.BlockPlaceBlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.events.BlockInteractBlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.events.DestroyWithBlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.events.ItemAcquireBlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.events.ItemDropBlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.events.ItemUseBlacklistEvent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class DatabaseLoggerHandler implements BlacklistLoggerHandler {
|
||||
|
||||
/**
|
||||
* DSN.
|
||||
*/
|
||||
private final String dsn;
|
||||
/**
|
||||
* Username.
|
||||
*/
|
||||
private final String user;
|
||||
/**
|
||||
* Password.
|
||||
*/
|
||||
private final String pass;
|
||||
/**
|
||||
* Table.
|
||||
*/
|
||||
private final String table;
|
||||
/**
|
||||
* World name.
|
||||
*/
|
||||
private final String worldName;
|
||||
/**
|
||||
* Database connection.
|
||||
*/
|
||||
private Connection conn;
|
||||
|
||||
private final Logger logger;
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param dsn The DSN for the connection
|
||||
* @param user The username to connect with
|
||||
* @param pass The password to connect with
|
||||
* @param table The table to log to
|
||||
* @param worldName The name of the world to log
|
||||
* @param logger The logger to log errors to
|
||||
*/
|
||||
public DatabaseLoggerHandler(String dsn, String user, String pass, String table, String worldName, Logger logger) {
|
||||
this.dsn = dsn;
|
||||
this.user = user;
|
||||
this.pass = pass;
|
||||
this.table = table;
|
||||
this.worldName = worldName;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the database connection.
|
||||
*
|
||||
* @return The database connection
|
||||
* @throws SQLException when the connection cannot be created
|
||||
*/
|
||||
private Connection getConnection() throws SQLException {
|
||||
if (conn == null || conn.isClosed()) {
|
||||
conn = DriverManager.getConnection(dsn, user, pass);
|
||||
}
|
||||
return conn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log an event to the database.
|
||||
*
|
||||
* @param event The event to log
|
||||
* @param player The player associated with the event
|
||||
* @param pos The location of the event
|
||||
* @param item The item used
|
||||
* @param comment The comment associated with the event
|
||||
*/
|
||||
private void logEvent(String event, LocalPlayer player, Vector pos, int item,
|
||||
String comment) {
|
||||
try {
|
||||
Connection conn = getConnection();
|
||||
PreparedStatement stmt = conn.prepareStatement(
|
||||
"INSERT INTO " + table
|
||||
+ "(event, world, player, x, y, z, item, time, comment) VALUES "
|
||||
+ "(?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
stmt.setString(1, event);
|
||||
stmt.setString(2, worldName);
|
||||
stmt.setString(3, player.getName());
|
||||
stmt.setInt(4, pos.getBlockX());
|
||||
stmt.setInt(5, pos.getBlockY());
|
||||
stmt.setInt(6, pos.getBlockZ());
|
||||
stmt.setInt(7, item);
|
||||
stmt.setInt(8, (int)(System.currentTimeMillis() / 1000));
|
||||
stmt.setString(9, comment);
|
||||
stmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
logger.log(Level.SEVERE, "Failed to log blacklist event to database: "
|
||||
+ e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log an event.
|
||||
*
|
||||
* @param event The event to log
|
||||
*/
|
||||
public void logEvent(BlacklistEvent event, String comment) {
|
||||
// Block break
|
||||
if (event instanceof BlockBreakBlacklistEvent) {
|
||||
BlockBreakBlacklistEvent evt = (BlockBreakBlacklistEvent)event;
|
||||
logEvent("BREAK", evt.getPlayer(), evt.getPosition(),
|
||||
evt.getType(), comment);
|
||||
|
||||
// Block place
|
||||
} else if (event instanceof BlockPlaceBlacklistEvent) {
|
||||
BlockPlaceBlacklistEvent evt = (BlockPlaceBlacklistEvent)event;
|
||||
logEvent("PLACE", evt.getPlayer(), evt.getPosition(),
|
||||
evt.getType(), comment);
|
||||
|
||||
// Block interact
|
||||
} else if (event instanceof BlockInteractBlacklistEvent) {
|
||||
BlockInteractBlacklistEvent evt = (BlockInteractBlacklistEvent)event;
|
||||
logEvent("INTERACT", evt.getPlayer(), evt.getPosition(),
|
||||
evt.getType(), comment);
|
||||
|
||||
// Destroy with
|
||||
} else if (event instanceof DestroyWithBlacklistEvent) {
|
||||
DestroyWithBlacklistEvent evt = (DestroyWithBlacklistEvent)event;
|
||||
logEvent("DESTROY_WITH", evt.getPlayer(), evt.getPosition(),
|
||||
evt.getType(), comment);
|
||||
|
||||
// Acquire
|
||||
} else if (event instanceof ItemAcquireBlacklistEvent) {
|
||||
ItemAcquireBlacklistEvent evt = (ItemAcquireBlacklistEvent)event;
|
||||
logEvent("ACQUIRE", evt.getPlayer(), evt.getPlayer().getPosition(),
|
||||
evt.getType(), comment);
|
||||
|
||||
// Drop
|
||||
} else if (event instanceof ItemDropBlacklistEvent) {
|
||||
ItemDropBlacklistEvent evt = (ItemDropBlacklistEvent)event;
|
||||
logEvent("DROP", evt.getPlayer(), evt.getPlayer().getPosition(),
|
||||
evt.getType(), comment);
|
||||
|
||||
// Use
|
||||
} else if (event instanceof ItemUseBlacklistEvent) {
|
||||
ItemUseBlacklistEvent evt = (ItemUseBlacklistEvent)event;
|
||||
logEvent("USE", evt.getPlayer(), evt.getPlayer().getPosition(),
|
||||
evt.getType(), comment);
|
||||
|
||||
// Unknown
|
||||
} else {
|
||||
logEvent("UNKNOWN", event.getPlayer(), event.getPlayer().getPosition(),
|
||||
-1, comment);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the connection.
|
||||
*/
|
||||
public void close() {
|
||||
try {
|
||||
if (conn != null && !conn.isClosed()) {
|
||||
conn.close();
|
||||
}
|
||||
} catch (SQLException ignore) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+83
-98
@@ -17,27 +17,34 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import java.util.logging.Logger;
|
||||
import java.util.logging.Level;
|
||||
import java.io.*;
|
||||
import java.util.regex.*;
|
||||
import java.util.Map;
|
||||
import java.util.Date;
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.TreeMap;
|
||||
import java.util.Iterator;
|
||||
package com.sk89q.worldguard.blacklist.loggers;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.ItemType;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.blacklist.events.BlacklistEvent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class FileLoggerHandler implements BlacklistLoggerHandler {
|
||||
/**
|
||||
* Logger.
|
||||
*/
|
||||
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
||||
/**
|
||||
* Regex for patterns in the path.
|
||||
*/
|
||||
@@ -56,45 +63,59 @@ public class FileLoggerHandler implements BlacklistLoggerHandler {
|
||||
* Path pattern.
|
||||
*/
|
||||
private String pathPattern;
|
||||
/**
|
||||
* World name.
|
||||
*/
|
||||
private String worldName;
|
||||
/**
|
||||
* Cache of writers.
|
||||
*/
|
||||
private TreeMap<String,FileLoggerWriter> writers =
|
||||
new TreeMap<String,FileLoggerWriter>();
|
||||
|
||||
private final Logger logger;
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param pathPattern
|
||||
* @param pathPattern The pattern for the logflie path
|
||||
* @param worldName The name of the world
|
||||
* @param logger The logger used to log errors
|
||||
*/
|
||||
public FileLoggerHandler(String pathPattern) {
|
||||
public FileLoggerHandler(String pathPattern, String worldName, Logger logger) {
|
||||
this.pathPattern = pathPattern;
|
||||
this.worldName = worldName;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param pathPattern
|
||||
* @param cacheSize
|
||||
* @param pathPattern The pattern for logfile paths
|
||||
* @param cacheSize The size of the file cache
|
||||
* @param worldName The name of the associated world
|
||||
* @param logger The logger to log errors with
|
||||
*/
|
||||
public FileLoggerHandler(String pathPattern, int cacheSize) {
|
||||
public FileLoggerHandler(String pathPattern, int cacheSize, String worldName, Logger logger) {
|
||||
if (cacheSize < 1) {
|
||||
throw new IllegalArgumentException("Cache size cannot be less than 1");
|
||||
}
|
||||
this.pathPattern = pathPattern;
|
||||
this.cacheSize = cacheSize;
|
||||
this.worldName = worldName;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the path.
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @param playerName The name of the playername
|
||||
* @return The path for the logfile
|
||||
*/
|
||||
private String buildPath(String playerName) {
|
||||
GregorianCalendar calendar = new GregorianCalendar();
|
||||
|
||||
Pattern p = Pattern.compile("%.");
|
||||
Matcher m = p.matcher(pathPattern);
|
||||
Matcher m = pattern.matcher(pathPattern);
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
|
||||
// Pattern replacements
|
||||
@@ -110,6 +131,12 @@ public class FileLoggerHandler implements BlacklistLoggerHandler {
|
||||
rep = rep.substring(0, 32);
|
||||
}
|
||||
|
||||
}else if (group.matches("%w")) {
|
||||
rep = worldName.toLowerCase().replaceAll("[^A-Za-z0-9_]", "_");
|
||||
if (rep.length() > 32) { // Actual max length is 16
|
||||
rep = rep.substring(0, 32);
|
||||
}
|
||||
|
||||
// Date and time
|
||||
} else if (group.matches("%Y")) {
|
||||
rep = String.valueOf(calendar.get(Calendar.YEAR));
|
||||
@@ -128,28 +155,29 @@ public class FileLoggerHandler implements BlacklistLoggerHandler {
|
||||
} else if (group.matches("%s")) {
|
||||
rep = String.format("%02d", calendar.get(Calendar.SECOND));
|
||||
}
|
||||
|
||||
|
||||
m.appendReplacement(buffer, rep);
|
||||
}
|
||||
|
||||
m.appendTail(buffer);
|
||||
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message.
|
||||
*
|
||||
* @param player
|
||||
* @param message
|
||||
*
|
||||
* @param player The player to log
|
||||
* @param message The message to log
|
||||
* @param comment The comment associated with the logged event
|
||||
*/
|
||||
private void log(Player player, String message, String comment) {
|
||||
private void log(LocalPlayer player, String message, String comment) {
|
||||
String path = buildPath(player.getName());
|
||||
try {
|
||||
String date = dateFormat.format(new Date());
|
||||
String line = "[" + date + "] " + player.getName() + ": " + message
|
||||
+ (comment != null ? " (" + comment + ")" : "") + "\r\n";
|
||||
|
||||
|
||||
FileLoggerWriter writer = writers.get(path);
|
||||
|
||||
// Writer already exists!
|
||||
@@ -171,7 +199,7 @@ public class FileLoggerHandler implements BlacklistLoggerHandler {
|
||||
if (parent != null && !parent.exists()) {
|
||||
parent.mkdirs();
|
||||
}
|
||||
|
||||
|
||||
FileWriter stream = new FileWriter(path, true);
|
||||
BufferedWriter out = new BufferedWriter(stream);
|
||||
out.write(line);
|
||||
@@ -189,7 +217,7 @@ public class FileLoggerHandler implements BlacklistLoggerHandler {
|
||||
Map.Entry<String,FileLoggerWriter> entry = it.next();
|
||||
try {
|
||||
entry.getValue().getWriter().close();
|
||||
} catch (IOException e) {
|
||||
} catch (IOException ignore) {
|
||||
}
|
||||
it.remove();
|
||||
|
||||
@@ -207,85 +235,42 @@ public class FileLoggerHandler implements BlacklistLoggerHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a block destroy attempt.
|
||||
* Gets the coordinates in text form for the log.
|
||||
*
|
||||
* @param player
|
||||
* @param block
|
||||
* @param pos The position to get coordinates for
|
||||
* @return The position's coordinates in human-readable form
|
||||
*/
|
||||
public void logDestroyAttempt(Player player, Block block, String comment) {
|
||||
log(player, "Tried to destroy " + getFriendlyItemName(block.getType()),
|
||||
comment);
|
||||
private String getCoordinates(Vector pos) {
|
||||
return "@" + pos.getBlockX() + "," + pos.getBlockY() + "," + pos.getBlockZ();
|
||||
}
|
||||
|
||||
private void logEvent(BlacklistEvent event, String text, int id, Vector pos, String comment) {
|
||||
log(event.getPlayer(), "Tried to " + text + " " + getFriendlyItemName(id)
|
||||
+ " " + getCoordinates(pos), comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a block break attempt.
|
||||
* Log an event.
|
||||
*
|
||||
* @param player
|
||||
* @param block
|
||||
* @param event The event to log
|
||||
*/
|
||||
public void logBreakAttempt(Player player, Block block, String comment) {
|
||||
log(player, "Tried to break " + getFriendlyItemName(block.getType()),
|
||||
comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a right click on attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param block
|
||||
*/
|
||||
public void logUseAttempt(Player player, Block block, String comment) {
|
||||
log(player, "Tried to use " + getFriendlyItemName(block.getType()),
|
||||
comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log an attempt to destroy with an item.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logDestroyWithAttempt(Player player, int item, String comment) {
|
||||
log(player, "Tried to destroy with " + getFriendlyItemName(item), comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a block creation attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logCreateAttempt(Player player, int item, String comment) {
|
||||
log(player, "Tried to create " + getFriendlyItemName(item), comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a drop attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logDropAttempt(Player player, int item, String comment) {
|
||||
log(player, "Tried to drop " + getFriendlyItemName(item), comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log an acquire attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logAcquireAttempt(Player player, int item, String comment) {
|
||||
log(player, "Tried to acquire " + getFriendlyItemName(item), comment);
|
||||
public void logEvent(BlacklistEvent event, String comment) {
|
||||
logEvent(event, event.getDescription(), event.getType(), event.getPosition(), comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an item's friendly name with its ID.
|
||||
*
|
||||
* @param id
|
||||
* @param id The id to get a friendly name for
|
||||
* @return The friendly name
|
||||
*/
|
||||
private static String getFriendlyItemName(int id) {
|
||||
return etc.getDataSource().getItem(id) + " (#" + id + ")";
|
||||
ItemType type = ItemType.fromID(id);
|
||||
if (type != null) {
|
||||
return type.getName() + " (#" + id + ")";
|
||||
} else {
|
||||
return "#" + id + "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -295,7 +280,7 @@ public class FileLoggerHandler implements BlacklistLoggerHandler {
|
||||
for (Map.Entry<String,FileLoggerWriter> entry : writers.entrySet()) {
|
||||
try {
|
||||
entry.getValue().getWriter().close();
|
||||
} catch (IOException e) {
|
||||
} catch (IOException ignore) {
|
||||
}
|
||||
}
|
||||
|
||||
+10
-15
@@ -17,7 +17,9 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
package com.sk89q.worldguard.blacklist.loggers;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -39,8 +41,9 @@ public class FileLoggerWriter implements Comparable<FileLoggerWriter> {
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param writer
|
||||
*
|
||||
* @param path The path to write to
|
||||
* @param writer The writer for the file
|
||||
*/
|
||||
public FileLoggerWriter(String path, BufferedWriter writer) {
|
||||
this.path = path;
|
||||
@@ -50,15 +53,15 @@ public class FileLoggerWriter implements Comparable<FileLoggerWriter> {
|
||||
|
||||
/**
|
||||
* File path.
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @return The path the logger is logging to
|
||||
*/
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the writer
|
||||
* @return the writer being logged to
|
||||
*/
|
||||
public BufferedWriter getWriter() {
|
||||
return writer;
|
||||
@@ -70,22 +73,14 @@ public class FileLoggerWriter implements Comparable<FileLoggerWriter> {
|
||||
public long getLastUse() {
|
||||
return lastUse;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update last use time.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public void updateLastUse() {
|
||||
lastUse = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
/**
|
||||
* Comparison function.
|
||||
*
|
||||
* @param other
|
||||
* @return
|
||||
*/
|
||||
public int compareTo(FileLoggerWriter other) {
|
||||
if (lastUse > other.lastUse) {
|
||||
return 1;
|
||||
@@ -0,0 +1,36 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import com.sk89q.worldguard.blacklist.Blacklist;
|
||||
|
||||
public class BukkitBlacklist extends Blacklist {
|
||||
private WorldGuardPlugin plugin;
|
||||
|
||||
public BukkitBlacklist(Boolean useAsWhitelist, WorldGuardPlugin plugin) {
|
||||
super(useAsWhitelist, plugin.getLogger());
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void broadcastNotification(String msg) {
|
||||
plugin.broadcastNotification(msg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
|
||||
public class BukkitPlayer extends LocalPlayer {
|
||||
private Player player;
|
||||
private WorldGuardPlugin plugin;
|
||||
|
||||
public BukkitPlayer(WorldGuardPlugin plugin, Player player) {
|
||||
this.plugin = plugin;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasGroup(String group) {
|
||||
return plugin.inGroup(player, group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector getPosition() {
|
||||
Location loc = player.getLocation();
|
||||
return new Vector(loc.getX(), loc.getY(), loc.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void kick(String msg) {
|
||||
player.kickPlayer(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ban(String msg) {
|
||||
player.setBanned(true);
|
||||
player.kickPlayer(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getGroups() {
|
||||
return plugin.getGroups(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printRaw(String msg) {
|
||||
player.sendMessage(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String perm) {
|
||||
return plugin.hasPermission(player, perm);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,296 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BlockID;
|
||||
import com.sk89q.worldedit.blocks.BlockType;
|
||||
import com.sk89q.worldedit.blocks.ItemID;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import java.util.List;
|
||||
|
||||
public class BukkitUtil {
|
||||
|
||||
private BukkitUtil() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the location of a Bukkit block to a WorldEdit vector.
|
||||
*
|
||||
* @param block The block to convert
|
||||
* @return The block's location as a BlockVector
|
||||
*/
|
||||
public static BlockVector toVector(Block block) {
|
||||
return new BlockVector(block.getX(), block.getY(), block.getZ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Bukkit location to a WorldEdit vector.
|
||||
*
|
||||
* @param loc A Bukkit Location
|
||||
* @return A Vector with the location's x, y, and z values
|
||||
*/
|
||||
public static Vector toVector(Location loc) {
|
||||
return new Vector(loc.getX(), loc.getY(), loc.getZ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Bukkit vector to a WorldEdit vector.
|
||||
*
|
||||
* @param vector The Bukkit vector
|
||||
* @return A WorldEdit vector with the same values as the Bukkit vector.
|
||||
*/
|
||||
public static Vector toVector(org.bukkit.util.Vector vector) {
|
||||
return new Vector(vector.getX(), vector.getY(), vector.getZ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a WorldEdit vector to a Bukkit location.
|
||||
*
|
||||
* @param world The World to create the new Location with
|
||||
* @param vec The vector to use for coordinates
|
||||
* @return The Vector as a location with a World of world
|
||||
*/
|
||||
public static Location toLocation(World world, Vector vec) {
|
||||
return new Location(world, vec.getX(), vec.getY(), vec.getZ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches one player based on name.
|
||||
*
|
||||
* @param server The server to check
|
||||
* @param name The name to attempt to match
|
||||
* @deprecated see {@link WorldGuardPlugin#matchSinglePlayer(org.bukkit.command.CommandSender, String)}
|
||||
* @return The matched player if any, otherwise null
|
||||
*/
|
||||
@Deprecated
|
||||
public static Player matchSinglePlayer(Server server, String name) {
|
||||
List<Player> players = server.matchPlayer(name);
|
||||
if (players.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
return players.get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Drops a sign item and removes a sign.
|
||||
*
|
||||
* @param block The block
|
||||
* @deprecated see {@link org.bukkit.block.Block#breakNaturally()}
|
||||
*/
|
||||
@Deprecated
|
||||
public static void dropSign(Block block) {
|
||||
block.setTypeId(0);
|
||||
block.getWorld().dropItemNaturally(block.getLocation(),
|
||||
new ItemStack(ItemID.SIGN, 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the given block to fluid water.
|
||||
* Used by addSpongeWater()
|
||||
*
|
||||
* @param world
|
||||
* @param ox
|
||||
* @param oy
|
||||
* @param oz
|
||||
*/
|
||||
public static void setBlockToWater(World world, int ox, int oy, int oz) {
|
||||
Block block = world.getBlockAt(ox, oy, oz);
|
||||
int id = block.getTypeId();
|
||||
if (id == 0) {
|
||||
block.setTypeId(8);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given block is water
|
||||
*
|
||||
* @param world the world
|
||||
* @param ox x
|
||||
* @param oy y
|
||||
* @param oz z
|
||||
* @return true if it's water
|
||||
*/
|
||||
public static boolean isBlockWater(World world, int ox, int oy, int oz) {
|
||||
Block block = world.getBlockAt(ox, oy, oz);
|
||||
int id = block.getTypeId();
|
||||
return id == 8 || id == 9;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given potion is a vial of water.
|
||||
*
|
||||
* @param item the item to check
|
||||
* @return true if it's a water vial
|
||||
*/
|
||||
public static boolean isWaterPotion(ItemStack item) {
|
||||
return (item.getDurability() & 0x3F) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get just the potion effect bits. This is to work around bugs with potion
|
||||
* parsing.
|
||||
*
|
||||
* @param item item
|
||||
* @return new bits
|
||||
*/
|
||||
public static int getPotionEffectBits(ItemStack item) {
|
||||
return item.getDurability() & 0x3F;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a position for the player to stand that is not inside a block.
|
||||
* Blocks above the player will be iteratively tested until there is
|
||||
* a series of two free blocks. The player will be teleported to
|
||||
* that free position.
|
||||
*
|
||||
* @param player
|
||||
*/
|
||||
public static void findFreePosition(Player player) {
|
||||
Location loc = player.getLocation();
|
||||
int x = loc.getBlockX();
|
||||
int y = Math.max(0, loc.getBlockY());
|
||||
int origY = y;
|
||||
int z = loc.getBlockZ();
|
||||
World world = player.getWorld();
|
||||
|
||||
byte free = 0;
|
||||
|
||||
while (y <= world.getMaxHeight() + 1) {
|
||||
if (BlockType.canPassThrough(world.getBlockTypeIdAt(x, y, z))) {
|
||||
free++;
|
||||
} else {
|
||||
free = 0;
|
||||
}
|
||||
|
||||
if (free == 2) {
|
||||
if (y - 1 != origY || y == 1) {
|
||||
loc.setX(x + 0.5);
|
||||
loc.setY(y);
|
||||
loc.setZ(z + 0.5);
|
||||
if (y <= 2 && world.getBlockAt(x,0,z).getTypeId() == BlockID.AIR) {
|
||||
world.getBlockAt(x,0,z).setTypeId(20);
|
||||
loc.setY(2);
|
||||
}
|
||||
player.setFallDistance(0F);
|
||||
player.teleport(loc);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
y++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace color macros in a string. The macros are in the form of `[char]
|
||||
* where char represents the color. R is for red, Y is for yellow,
|
||||
* G is for green, C is for cyan, B is for blue, and P is for purple.
|
||||
* The uppercase versions of those are the darker shades, while the
|
||||
* lowercase versions are the lighter shades. For white, it's 'w', and
|
||||
* 0-2 are black, dark grey, and grey, respectively.
|
||||
*
|
||||
* @param str
|
||||
* @return color-coded string
|
||||
*/
|
||||
public static String replaceColorMacros(String str) {
|
||||
str = str.replace("&r", ChatColor.RED.toString());
|
||||
str = str.replace("&R", ChatColor.DARK_RED.toString());
|
||||
|
||||
str = str.replace("&y", ChatColor.YELLOW.toString());
|
||||
str = str.replace("&Y", ChatColor.GOLD.toString());
|
||||
|
||||
str = str.replace("&g", ChatColor.GREEN.toString());
|
||||
str = str.replace("&G", ChatColor.DARK_GREEN.toString());
|
||||
|
||||
str = str.replace("&c", ChatColor.AQUA.toString());
|
||||
str = str.replace("&C", ChatColor.DARK_AQUA.toString());
|
||||
|
||||
str = str.replace("&b", ChatColor.BLUE.toString());
|
||||
str = str.replace("&B", ChatColor.DARK_BLUE.toString());
|
||||
|
||||
str = str.replace("&p", ChatColor.LIGHT_PURPLE.toString());
|
||||
str = str.replace("&P", ChatColor.DARK_PURPLE.toString());
|
||||
|
||||
str = str.replace("&0", ChatColor.BLACK.toString());
|
||||
str = str.replace("&1", ChatColor.DARK_GRAY.toString());
|
||||
str = str.replace("&2", ChatColor.GRAY.toString());
|
||||
str = str.replace("&w", ChatColor.WHITE.toString());
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether an entity should be removed for the halt activity mode.
|
||||
*
|
||||
* @param entity
|
||||
* @return true if it's to be removed
|
||||
*/
|
||||
public static boolean isIntensiveEntity(Entity entity) {
|
||||
return entity instanceof Item
|
||||
|| entity instanceof TNTPrimed
|
||||
|| entity instanceof ExperienceOrb
|
||||
|| entity instanceof FallingSand
|
||||
|| (entity instanceof LivingEntity
|
||||
&& !(entity instanceof Tameable)
|
||||
&& !(entity instanceof Player));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether our running CraftBukkit already supports
|
||||
* the HangingEvent instead of the PaintingEvent
|
||||
*
|
||||
* @return true if the hanging event is supported
|
||||
*/
|
||||
public static boolean hasHangingEvent() {
|
||||
Class<?> tmp = null;
|
||||
try {
|
||||
tmp = Class.forName("org.bukkit.event.hanging.HangingEvent");
|
||||
} catch (ClassNotFoundException ignored) { }
|
||||
return (tmp != null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search an enum for a value, and return the first one found. Return null if the
|
||||
* enum entry is not found.
|
||||
*
|
||||
* @param enumType enum class
|
||||
* @param values values to test
|
||||
* @return a value in the enum or null
|
||||
*/
|
||||
public static <T extends Enum<T>> T tryEnum(Class<T> enumType, String ... values) {
|
||||
for (String val : values) {
|
||||
try {
|
||||
return Enum.valueOf(enumType, val);
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,310 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import com.sk89q.commandbook.CommandBook;
|
||||
import com.sk89q.commandbook.GodComponent;
|
||||
import com.sk89q.util.yaml.YAMLFormat;
|
||||
import com.sk89q.util.yaml.YAMLProcessor;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.blacklist.Blacklist;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
/**
|
||||
* Represents the global configuration and also delegates configuration
|
||||
* for individual worlds.
|
||||
*
|
||||
* @author sk89q
|
||||
* @author Michael
|
||||
*/
|
||||
public class ConfigurationManager {
|
||||
|
||||
private static final String CONFIG_HEADER = "#\r\n" +
|
||||
"# WorldGuard's main configuration file\r\n" +
|
||||
"#\r\n" +
|
||||
"# This is the global configuration file. Anything placed into here will\r\n" +
|
||||
"# be applied to all worlds. However, each world has its own configuration\r\n" +
|
||||
"# file to allow you to replace most settings in here for that world only.\r\n" +
|
||||
"#\r\n" +
|
||||
"# About editing this file:\r\n" +
|
||||
"# - DO NOT USE TABS. You MUST use spaces or Bukkit will complain. If\r\n" +
|
||||
"# you use an editor like Notepad++ (recommended for Windows users), you\r\n" +
|
||||
"# must configure it to \"replace tabs with spaces.\" In Notepad++, this can\r\n" +
|
||||
"# be changed in Settings > Preferences > Language Menu.\r\n" +
|
||||
"# - Don't get rid of the indents. They are indented so some entries are\r\n" +
|
||||
"# in categories (like \"enforce-single-session\" is in the \"protection\"\r\n" +
|
||||
"# category.\r\n" +
|
||||
"# - If you want to check the format of this file before putting it\r\n" +
|
||||
"# into WorldGuard, paste it into http://yaml-online-parser.appspot.com/\r\n" +
|
||||
"# and see if it gives \"ERROR:\".\r\n" +
|
||||
"# - Lines starting with # are comments and so they are ignored.\r\n" +
|
||||
"#\r\n";
|
||||
|
||||
/**
|
||||
* Reference to the plugin.
|
||||
*/
|
||||
private WorldGuardPlugin plugin;
|
||||
|
||||
/**
|
||||
* Holds configurations for different worlds.
|
||||
*/
|
||||
private ConcurrentMap<String, WorldConfiguration> worlds;
|
||||
|
||||
/**
|
||||
* The global configuration for use when loading worlds
|
||||
*/
|
||||
private YAMLProcessor config;
|
||||
|
||||
/**
|
||||
* List of people with god mode.
|
||||
*/
|
||||
@Deprecated
|
||||
private Set<String> hasGodMode = new HashSet<String>();
|
||||
|
||||
/**
|
||||
* List of people who can breathe underwater.
|
||||
*/
|
||||
private Set<String> hasAmphibious = new HashSet<String>();
|
||||
|
||||
private boolean hasCommandBookGodMode = false;
|
||||
|
||||
public boolean useRegionsScheduler;
|
||||
public boolean useRegionsCreatureSpawnEvent;
|
||||
public boolean activityHaltToggle = false;
|
||||
public boolean autoGodMode;
|
||||
public boolean usePlayerMove;
|
||||
public boolean deopOnJoin;
|
||||
public boolean blockInGameOp;
|
||||
public Map<String, String> hostKeys = new HashMap<String, String>();
|
||||
|
||||
/**
|
||||
* Region Storage Configuration method, and config values
|
||||
*/
|
||||
public boolean useSqlDatabase = false;
|
||||
public String sqlDsn;
|
||||
public String sqlUsername;
|
||||
public String sqlPassword;
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param plugin The plugin instance
|
||||
*/
|
||||
public ConfigurationManager(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.worlds = new ConcurrentHashMap<String, WorldConfiguration>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the configuration.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void load() {
|
||||
// Create the default configuration file
|
||||
plugin.createDefaultConfiguration(
|
||||
new File(plugin.getDataFolder(), "config.yml"), "config.yml");
|
||||
|
||||
config = new YAMLProcessor(new File(plugin.getDataFolder(), "config.yml"), true, YAMLFormat.EXTENDED);
|
||||
try {
|
||||
config.load();
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().severe("Error reading configuration for global config: ");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
config.removeProperty("suppress-tick-sync-warnings");
|
||||
useRegionsScheduler = config.getBoolean("regions.use-scheduler", true);
|
||||
useRegionsCreatureSpawnEvent = config.getBoolean("regions.use-creature-spawn-event", true);
|
||||
autoGodMode = config.getBoolean("auto-invincible", config.getBoolean("auto-invincible-permission", false));
|
||||
config.removeProperty("auto-invincible-permission");
|
||||
usePlayerMove = config.getBoolean("use-player-move-event", true);
|
||||
|
||||
deopOnJoin = config.getBoolean("security.deop-everyone-on-join", false);
|
||||
blockInGameOp = config.getBoolean("security.block-in-game-op-command", false);
|
||||
|
||||
hostKeys = new HashMap<String, String>();
|
||||
Object hostKeysRaw = config.getProperty("host-keys");
|
||||
if (hostKeysRaw == null || !(hostKeysRaw instanceof Map)) {
|
||||
config.setProperty("host-keys", new HashMap<String, String>());
|
||||
} else {
|
||||
for (Map.Entry<Object, Object> entry : ((Map<Object, Object>) hostKeysRaw).entrySet()) {
|
||||
String key = String.valueOf(entry.getKey());
|
||||
String value = String.valueOf(entry.getValue());
|
||||
hostKeys.put(key.toLowerCase(), value);
|
||||
}
|
||||
}
|
||||
|
||||
useSqlDatabase = config.getBoolean(
|
||||
"regions.sql.use", false);
|
||||
|
||||
sqlDsn = config.getString("regions.sql.dsn", "jdbc:mysql://localhost/worldguard");
|
||||
sqlUsername = config.getString("regions.sql.username", "worldguard");
|
||||
sqlPassword = config.getString("regions.sql.password", "worldguard");
|
||||
|
||||
// Load configurations for each world
|
||||
for (World world : plugin.getServer().getWorlds()) {
|
||||
get(world);
|
||||
}
|
||||
|
||||
config.setHeader(CONFIG_HEADER);
|
||||
|
||||
if (!config.save()) {
|
||||
plugin.getLogger().severe("Error saving configuration!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unload the configuration.
|
||||
*/
|
||||
public void unload() {
|
||||
worlds.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the configuration for a world.
|
||||
*
|
||||
* @param world The world to get the configuration for
|
||||
* @return {@code world}'s configuration
|
||||
*/
|
||||
public WorldConfiguration get(World world) {
|
||||
String worldName = world.getName();
|
||||
WorldConfiguration config = worlds.get(worldName);
|
||||
WorldConfiguration newConfig = null;
|
||||
|
||||
while (config == null) {
|
||||
if (newConfig == null) {
|
||||
newConfig = new WorldConfiguration(plugin, worldName, this.config);
|
||||
}
|
||||
worlds.putIfAbsent(world.getName(), newConfig);
|
||||
config = worlds.get(world.getName());
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forget a player.
|
||||
*
|
||||
* @param player The player to forget about
|
||||
*/
|
||||
public void forgetPlayer(LocalPlayer player) {
|
||||
for (Map.Entry<String, WorldConfiguration> entry
|
||||
: worlds.entrySet()) {
|
||||
|
||||
// The blacklist needs to forget players
|
||||
Blacklist bl = entry.getValue().getBlacklist();
|
||||
if (bl != null) {
|
||||
bl.forgetPlayer(player);
|
||||
}
|
||||
}
|
||||
|
||||
hasGodMode.remove(player.getName());
|
||||
hasAmphibious.remove(player.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable god mode for a player.
|
||||
*
|
||||
* @param player The player to enable god mode for.
|
||||
*/
|
||||
@Deprecated
|
||||
public void enableGodMode(Player player) {
|
||||
|
||||
hasGodMode.add(player.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable god mode for a player.
|
||||
*
|
||||
* @param player The player to disable godmode for
|
||||
*/
|
||||
@Deprecated
|
||||
public void disableGodMode(Player player) {
|
||||
hasGodMode.remove(player.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if god mode is enabled for a player.
|
||||
*
|
||||
* @param player The player to check
|
||||
* @return Whether the player has godmode through WorldGuard or CommandBook
|
||||
*/
|
||||
public boolean hasGodMode(Player player) {
|
||||
if (hasCommandBookGodMode) {
|
||||
GodComponent god = CommandBook.inst().getComponentManager().getComponent(GodComponent.class);
|
||||
if (god != null) {
|
||||
return god.hasGodMode(player);
|
||||
}
|
||||
}
|
||||
return hasGodMode.contains(player.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable amphibious mode for a player.
|
||||
*
|
||||
* @param player The player to enable amphibious mode for
|
||||
*/
|
||||
public void enableAmphibiousMode(Player player) {
|
||||
hasAmphibious.add(player.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable amphibious mode for a player.
|
||||
*
|
||||
* @param player The player to disable amphibious mode for
|
||||
*/
|
||||
public void disableAmphibiousMode(Player player) {
|
||||
hasAmphibious.remove(player.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if amphibious mode is enabled for a player.
|
||||
*
|
||||
* @param player The player to check
|
||||
* @return Whether {@code player} has amphibious mode
|
||||
*/
|
||||
public boolean hasAmphibiousMode(Player player) {
|
||||
return hasAmphibious.contains(player.getName());
|
||||
}
|
||||
|
||||
public void updateCommandBookGodMode() {
|
||||
try {
|
||||
if (plugin.getServer().getPluginManager().isPluginEnabled("CommandBook")) {
|
||||
Class.forName("com.sk89q.commandbook.GodComponent");
|
||||
hasCommandBookGodMode = true;
|
||||
return;
|
||||
}
|
||||
} catch (ClassNotFoundException ignore) {}
|
||||
hasCommandBookGodMode = false;
|
||||
}
|
||||
|
||||
public boolean hasCommandBookGodMode() {
|
||||
return hasCommandBookGodMode;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,233 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
|
||||
|
||||
/**
|
||||
* This processes per-player state information and is also meant to be used
|
||||
* as a scheduled task.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class FlagStateManager implements Runnable {
|
||||
|
||||
public static final int RUN_DELAY = 20;
|
||||
|
||||
private WorldGuardPlugin plugin;
|
||||
private Map<String, PlayerFlagState> states;
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param plugin The plugin instance
|
||||
*/
|
||||
public FlagStateManager(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
states = new HashMap<String, PlayerFlagState>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the task.
|
||||
*/
|
||||
public void run() {
|
||||
Player[] players = plugin.getServer().getOnlinePlayers();
|
||||
ConfigurationManager config = plugin.getGlobalStateManager();
|
||||
|
||||
for (Player player : players) {
|
||||
WorldConfiguration worldConfig = config.get(player.getWorld());
|
||||
|
||||
if (!worldConfig.useRegions) {
|
||||
continue;
|
||||
}
|
||||
|
||||
PlayerFlagState state;
|
||||
|
||||
synchronized (this) {
|
||||
state = states.get(player.getName());
|
||||
|
||||
if (state == null) {
|
||||
state = new PlayerFlagState();
|
||||
states.put(player.getName(), state);
|
||||
}
|
||||
}
|
||||
|
||||
Vector playerLocation = toVector(player.getLocation());
|
||||
RegionManager regionManager = plugin.getGlobalRegionManager().get(player.getWorld());
|
||||
ApplicableRegionSet applicable = regionManager.getApplicableRegions(playerLocation);
|
||||
|
||||
if (!RegionQueryUtil.isInvincible(plugin, player, applicable)
|
||||
&& !plugin.getGlobalStateManager().hasGodMode(player)
|
||||
&& !(player.getGameMode() == GameMode.CREATIVE)) {
|
||||
processHeal(applicable, player, state);
|
||||
processFeed(applicable, player, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process healing for a player.
|
||||
*
|
||||
* @param applicable The set of applicable regions
|
||||
* @param player The player to process healing flags on
|
||||
* @param state The player's state
|
||||
*/
|
||||
private void processHeal(ApplicableRegionSet applicable, Player player,
|
||||
PlayerFlagState state) {
|
||||
|
||||
if (player.getHealth() <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
Integer healAmount = applicable.getFlag(DefaultFlag.HEAL_AMOUNT);
|
||||
Integer healDelay = applicable.getFlag(DefaultFlag.HEAL_DELAY);
|
||||
Integer minHealth = applicable.getFlag(DefaultFlag.MIN_HEAL);
|
||||
Integer maxHealth = applicable.getFlag(DefaultFlag.MAX_HEAL);
|
||||
|
||||
if (healAmount == null || healDelay == null || healAmount == 0 || healDelay < 0) {
|
||||
return;
|
||||
}
|
||||
if (minHealth == null) minHealth = 0;
|
||||
if (maxHealth == null) maxHealth = 20;
|
||||
|
||||
if (player.getHealth() >= maxHealth && healAmount > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (healDelay <= 0) {
|
||||
player.setHealth(healAmount > 0 ? maxHealth : minHealth); // this will insta-kill if the flag is unset
|
||||
state.lastHeal = now;
|
||||
} else if (now - state.lastHeal > healDelay * 1000) {
|
||||
// clamp health between minimum and maximum
|
||||
player.setHealth(Math.min(maxHealth, Math.max(minHealth, player.getHealth() + healAmount)));
|
||||
state.lastHeal = now;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process restoring hunger for a player.
|
||||
*
|
||||
* @param applicable The set of applicable regions
|
||||
* @param player The player to process hunger flags on
|
||||
* @param state The player's state
|
||||
*/
|
||||
private void processFeed(ApplicableRegionSet applicable, Player player,
|
||||
PlayerFlagState state) {
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
Integer feedAmount = applicable.getFlag(DefaultFlag.FEED_AMOUNT);
|
||||
Integer feedDelay = applicable.getFlag(DefaultFlag.FEED_DELAY);
|
||||
Integer minHunger = applicable.getFlag(DefaultFlag.MIN_FOOD);
|
||||
Integer maxHunger = applicable.getFlag(DefaultFlag.MAX_FOOD);
|
||||
|
||||
if (feedAmount == null || feedDelay == null || feedAmount == 0 || feedDelay < 0) {
|
||||
return;
|
||||
}
|
||||
if (minHunger == null) minHunger = 0;
|
||||
if (maxHunger == null) maxHunger = 20;
|
||||
|
||||
if (player.getFoodLevel() >= maxHunger && feedAmount > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (feedDelay <= 0) {
|
||||
player.setFoodLevel(feedAmount > 0 ? maxHunger : minHunger);
|
||||
state.lastFeed = now;
|
||||
} else if (now - state.lastFeed > feedDelay * 1000) {
|
||||
// clamp health between minimum and maximum
|
||||
player.setFoodLevel(Math.min(maxHunger, Math.max(minHunger, player.getFoodLevel() + feedAmount)));
|
||||
state.lastFeed = now;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Forget a player.
|
||||
*
|
||||
* @param player The player to forget
|
||||
*/
|
||||
public synchronized void forget(Player player) {
|
||||
states.remove(player.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Forget all managed players. Use with caution.
|
||||
*/
|
||||
public synchronized void forgetAll() {
|
||||
states.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a player's flag state. A new state will be created if there is no existing
|
||||
* state for the player.
|
||||
*
|
||||
* @param player The player to get a state for
|
||||
* @return The {@code player}'s state
|
||||
*/
|
||||
public synchronized PlayerFlagState getState(Player player) {
|
||||
PlayerFlagState state = states.get(player.getName());
|
||||
|
||||
if (state == null) {
|
||||
state = new PlayerFlagState();
|
||||
states.put(player.getName(), state);
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Keeps state per player.
|
||||
*/
|
||||
public static class PlayerFlagState {
|
||||
public long lastHeal;
|
||||
public long lastFeed;
|
||||
public String lastGreeting;
|
||||
public String lastFarewell;
|
||||
public Boolean lastExitAllowed = null;
|
||||
public Boolean notifiedForLeave = false;
|
||||
public Boolean notifiedForEnter = false;
|
||||
public GameMode lastGameMode;
|
||||
public World lastWorld;
|
||||
public int lastBlockX;
|
||||
public int lastBlockY;
|
||||
public int lastBlockZ;
|
||||
|
||||
/* Used to cache invincibility status */
|
||||
public World lastInvincibleWorld;
|
||||
public int lastInvincibleX;
|
||||
public int lastInvincibleY;
|
||||
public int lastInvincibleZ;
|
||||
public boolean wasInvincible;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import org.bukkit.World;
|
||||
|
||||
import com.sk89q.worldguard.protection.databases.ProtectionDatabaseException;
|
||||
import com.sk89q.worldguard.protection.databases.CSVDatabase;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
|
||||
/**
|
||||
* Utility methods for porting from legacy versions.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class LegacyWorldGuardMigration {
|
||||
|
||||
/**
|
||||
* Port over the blacklist.
|
||||
*
|
||||
* @param plugin The plugin instance
|
||||
*/
|
||||
public static void migrateBlacklist(WorldGuardPlugin plugin) {
|
||||
World mainWorld = plugin.getServer().getWorlds().get(0);
|
||||
String mainWorldName = mainWorld.getName();
|
||||
String newPath = "worlds/" + mainWorldName + "/blacklist.txt";
|
||||
|
||||
File oldFile = new File(plugin.getDataFolder(), "blacklist.txt");
|
||||
File newFile = new File(plugin.getDataFolder(), newPath);
|
||||
|
||||
if (!newFile.exists() && oldFile.exists()) {
|
||||
plugin.getLogger().warning("WorldGuard will now update your blacklist "
|
||||
+ "from an older version of WorldGuard.");
|
||||
|
||||
// Need to make root directories
|
||||
newFile.getParentFile().mkdirs();
|
||||
|
||||
if (copyFile(oldFile, newFile)) {
|
||||
oldFile.renameTo(new File(plugin.getDataFolder(),
|
||||
"blacklist.txt.old"));
|
||||
} else {
|
||||
plugin.getLogger().warning("blacklist.txt has been converted " +
|
||||
"for the main world at " + newPath + "");
|
||||
plugin.getLogger().warning("Your other worlds currently have no " +
|
||||
"blacklist defined!");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrate region settings.
|
||||
*
|
||||
* @param plugin The plugin instance
|
||||
*/
|
||||
public static void migrateRegions(WorldGuardPlugin plugin) {
|
||||
try {
|
||||
File oldDatabase = new File(plugin.getDataFolder(), "regions.txt");
|
||||
if (!oldDatabase.exists()) return;
|
||||
|
||||
plugin.getLogger().info("The regions database has changed in 5.x. "
|
||||
+ "Your old regions database will be converted to the new format "
|
||||
+ "and set as your primary world's database.");
|
||||
|
||||
World w = plugin.getServer().getWorlds().get(0);
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(w);
|
||||
|
||||
// First load up the old database using the CSV loader
|
||||
CSVDatabase db = new CSVDatabase(oldDatabase, plugin.getLogger());
|
||||
db.load();
|
||||
|
||||
// Then save the new database
|
||||
mgr.setRegions(db.getRegions());
|
||||
mgr.save();
|
||||
|
||||
oldDatabase.renameTo(new File(plugin.getDataFolder(), "regions.txt.old"));
|
||||
|
||||
plugin.getLogger().info("Regions database converted!");
|
||||
} catch (ProtectionDatabaseException e) {
|
||||
plugin.getLogger().warning("Failed to load regions: "
|
||||
+ e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies a file.
|
||||
*
|
||||
* @param from The source file
|
||||
* @param to The destination file
|
||||
* @return true if successful
|
||||
*/
|
||||
private static boolean copyFile(File from, File to) {
|
||||
InputStream in = null;
|
||||
OutputStream out = null;
|
||||
|
||||
try {
|
||||
in = new FileInputStream(from);
|
||||
out = new FileOutputStream(to);
|
||||
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
while ((len = in.read(buf)) > 0) {
|
||||
out.write(buf, 0, len);
|
||||
}
|
||||
|
||||
in.close();
|
||||
out.close();
|
||||
|
||||
return true;
|
||||
} catch (FileNotFoundException ignore) {
|
||||
} catch (IOException ignore) {
|
||||
} finally {
|
||||
if (in != null) {
|
||||
try {
|
||||
in.close();
|
||||
} catch (IOException ignore) {
|
||||
}
|
||||
}
|
||||
|
||||
if (out != null) {
|
||||
try {
|
||||
out.close();
|
||||
} catch (IOException ignore) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.LogRecord;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* Sends all logger messages to a player.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class LoggerToChatHandler extends Handler {
|
||||
/**
|
||||
* Player.
|
||||
*/
|
||||
private CommandSender player;
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param player
|
||||
*/
|
||||
public LoggerToChatHandler(CommandSender player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the handler.
|
||||
*/
|
||||
@Override
|
||||
public void close() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush the output.
|
||||
*/
|
||||
@Override
|
||||
public void flush() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Publish a log record.
|
||||
*/
|
||||
@Override
|
||||
public void publish(LogRecord record) {
|
||||
player.sendMessage(ChatColor.GRAY + record.getLevel().getName() + ": "
|
||||
+ ChatColor.WHITE + record.getMessage());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
|
||||
public class RegionQueryUtil {
|
||||
|
||||
public static boolean isInvincible(WorldGuardPlugin plugin, Player player) {
|
||||
return isInvincible(plugin, player, null);
|
||||
}
|
||||
|
||||
public static boolean isInvincible(WorldGuardPlugin plugin, Player player,
|
||||
ApplicableRegionSet set) {
|
||||
Location loc = player.getLocation();
|
||||
World world = player.getWorld();
|
||||
|
||||
FlagStateManager.PlayerFlagState state = plugin.getFlagStateManager().getState(player);
|
||||
|
||||
if (state.lastInvincibleWorld == null ||
|
||||
!state.lastInvincibleWorld.equals(world) ||
|
||||
state.lastInvincibleX != loc.getBlockX() ||
|
||||
state.lastInvincibleY != loc.getBlockY() ||
|
||||
state.lastInvincibleZ != loc.getBlockZ()) {
|
||||
state.lastInvincibleX = loc.getBlockX();
|
||||
state.lastInvincibleY = loc.getBlockY();
|
||||
state.lastInvincibleZ = loc.getBlockZ();
|
||||
state.lastInvincibleWorld = world;
|
||||
|
||||
if (set == null) {
|
||||
Vector vec = new Vector(state.lastInvincibleX,
|
||||
state.lastInvincibleY, state.lastInvincibleZ);
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||
set = mgr.getApplicableRegions(vec);
|
||||
}
|
||||
|
||||
state.wasInvincible = set.allows(DefaultFlag.INVINCIBILITY, plugin.wrapPlayer(player));
|
||||
}
|
||||
|
||||
return state.wasInvincible;
|
||||
}
|
||||
|
||||
public static Boolean isAllowedInvinciblity(WorldGuardPlugin plugin, Player player) {
|
||||
World world = player.getWorld();
|
||||
FlagStateManager.PlayerFlagState state = plugin.getFlagStateManager().getState(player);
|
||||
Vector vec = new Vector(state.lastInvincibleX, state.lastInvincibleY, state.lastInvincibleZ);
|
||||
|
||||
StateFlag.State regionState = plugin.getGlobalRegionManager().get(world).
|
||||
getApplicableRegions(vec).getFlag(DefaultFlag.INVINCIBILITY, plugin.wrapPlayer(player));
|
||||
if (regionState == StateFlag.State.ALLOW) {
|
||||
return Boolean.TRUE;
|
||||
} else if (regionState == StateFlag.State.DENY) {
|
||||
return Boolean.FALSE;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,337 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.sk89q.worldguard.protection.GlobalRegionManager;
|
||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import com.sk89q.worldguard.util.LogListBlock;
|
||||
|
||||
public class ReportWriter {
|
||||
|
||||
private static final SimpleDateFormat dateFmt =
|
||||
new SimpleDateFormat("yyyy-MM-dd kk:mm Z");
|
||||
|
||||
private Date date = new Date();
|
||||
private StringBuilder output = new StringBuilder();
|
||||
|
||||
public ReportWriter(WorldGuardPlugin plugin) {
|
||||
appendReportHeader(plugin);
|
||||
appendServerInformation(plugin.getServer());
|
||||
appendPluginInformation(plugin.getServer().getPluginManager().getPlugins());
|
||||
appendWorldInformation(plugin.getServer().getWorlds());
|
||||
appendGlobalConfiguration(plugin.getGlobalStateManager());
|
||||
appendWorldConfigurations(plugin, plugin.getServer().getWorlds(),
|
||||
plugin.getGlobalRegionManager(), plugin.getGlobalStateManager());
|
||||
appendln("-------------");
|
||||
appendln("END OF REPORT");
|
||||
appendln();
|
||||
}
|
||||
|
||||
protected static String repeat(String str, int n) {
|
||||
if(str == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < n; i++) {
|
||||
sb.append(str);
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
protected void appendln(String text) {
|
||||
output.append(text);
|
||||
output.append("\r\n");
|
||||
}
|
||||
|
||||
protected void appendln(String text, Object ... args) {
|
||||
output.append(String.format(text, args));
|
||||
output.append("\r\n");
|
||||
}
|
||||
|
||||
protected void append(LogListBlock log) {
|
||||
output.append(log.toString());
|
||||
}
|
||||
|
||||
protected void appendln() {
|
||||
output.append("\r\n");
|
||||
}
|
||||
|
||||
protected void appendHeader(String text) {
|
||||
String rule = repeat("-", text.length());
|
||||
output.append(rule);
|
||||
output.append("\r\n");
|
||||
appendln(text);
|
||||
output.append(rule);
|
||||
output.append("\r\n");
|
||||
appendln();
|
||||
}
|
||||
|
||||
private void appendReportHeader(WorldGuardPlugin plugin) {
|
||||
appendln("WorldGuard Configuration Report");
|
||||
appendln("Generated " + dateFmt.format(date));
|
||||
appendln();
|
||||
appendln("Version: " + plugin.getDescription().getVersion());
|
||||
appendln();
|
||||
}
|
||||
|
||||
private void appendGlobalConfiguration(ConfigurationManager config) {
|
||||
appendHeader("Global Configuration");
|
||||
|
||||
LogListBlock log = new LogListBlock();
|
||||
LogListBlock configLog = log.putChild("Configuration");
|
||||
|
||||
Class<? extends ConfigurationManager> cls = config.getClass();
|
||||
for (Field field : cls.getFields()) {
|
||||
try {
|
||||
if (field.getName().equalsIgnoreCase("CONFIG_HEADER")) continue;
|
||||
Object val = field.get(config);
|
||||
configLog.put(field.getName(), val);
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException ignore) {
|
||||
}
|
||||
}
|
||||
|
||||
append(log);
|
||||
appendln();
|
||||
}
|
||||
|
||||
private void appendServerInformation(Server server) {
|
||||
appendHeader("Server Information");
|
||||
|
||||
LogListBlock log = new LogListBlock();
|
||||
|
||||
Runtime runtime = Runtime.getRuntime();
|
||||
|
||||
log.put("Java", "%s %s (%s)",
|
||||
System.getProperty("java.vendor"),
|
||||
System.getProperty("java.version"),
|
||||
System.getProperty("java.vendor.url"));
|
||||
log.put("Operating system", "%s %s (%s)",
|
||||
System.getProperty("os.name"),
|
||||
System.getProperty("os.version"),
|
||||
System.getProperty("os.arch"));
|
||||
log.put("Available processors", runtime.availableProcessors());
|
||||
log.put("Free memory", runtime.freeMemory() / 1024 / 1024 + " MB");
|
||||
log.put("Max memory", runtime.maxMemory() / 1024 / 1024 + " MB");
|
||||
log.put("Total memory", runtime.totalMemory() / 1024 / 1024 + " MB");
|
||||
log.put("Server ID", server.getServerId());
|
||||
log.put("Server name", server.getServerName());
|
||||
log.put("Implementation", server.getVersion());
|
||||
//log.put("Address", server.getIp(), server.getPort());
|
||||
log.put("Player count", "%d/%d",
|
||||
server.getOnlinePlayers().length, server.getMaxPlayers());
|
||||
|
||||
append(log);
|
||||
appendln();
|
||||
}
|
||||
|
||||
private void appendPluginInformation(Plugin[] plugins) {
|
||||
appendHeader("Plugins (" + plugins.length + ")");
|
||||
|
||||
LogListBlock log = new LogListBlock();
|
||||
|
||||
for (Plugin plugin : plugins) {
|
||||
log.put(plugin.getDescription().getName(), plugin.getDescription().getVersion());
|
||||
}
|
||||
|
||||
append(log);
|
||||
appendln();
|
||||
|
||||
/*appendHeader("Plugin Information");
|
||||
|
||||
log = new LogListBlock();
|
||||
|
||||
for (Plugin plugin : plugins) {
|
||||
log.putChild(plugin.getDescription().getName())
|
||||
.put("Data folder", plugin.getDataFolder())
|
||||
.put("Website", plugin.getDescription().getWebsite())
|
||||
.put("Entry point", plugin.getDescription().getMain());
|
||||
}
|
||||
|
||||
append(log);
|
||||
appendln();*/
|
||||
}
|
||||
|
||||
private void appendWorldInformation(List<World> worlds) {
|
||||
appendHeader("Worlds");
|
||||
|
||||
LogListBlock log = new LogListBlock();
|
||||
|
||||
int i = 0;
|
||||
for (World world : worlds) {
|
||||
int loadedChunkCount = world.getLoadedChunks().length;
|
||||
|
||||
LogListBlock worldLog = log.putChild(world.getName() + " (" + i + ")");
|
||||
LogListBlock infoLog = worldLog.putChild("Information");
|
||||
LogListBlock entitiesLog = worldLog.putChild("Entities");
|
||||
|
||||
infoLog.put("Seed", world.getSeed());
|
||||
infoLog.put("Environment", world.getEnvironment().toString());
|
||||
infoLog.put("Player count", world.getPlayers().size());
|
||||
infoLog.put("Entity count", world.getEntities().size());
|
||||
infoLog.put("Loaded chunk count", loadedChunkCount);
|
||||
infoLog.put("Spawn location", world.getSpawnLocation());
|
||||
infoLog.put("Raw time", world.getFullTime());
|
||||
|
||||
Map<Class<? extends Entity>, Integer> entityCounts =
|
||||
new HashMap<Class<? extends Entity>, Integer>();
|
||||
|
||||
// Collect entities
|
||||
for (Entity entity : world.getEntities()) {
|
||||
Class<? extends Entity> cls = entity.getClass();
|
||||
|
||||
if (entityCounts.containsKey(cls)) {
|
||||
entityCounts.put(cls, entityCounts.get(cls) + 1);
|
||||
} else {
|
||||
entityCounts.put(cls, 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Print entities
|
||||
for (Map.Entry<Class<? extends Entity>, Integer> entry
|
||||
: entityCounts.entrySet()) {
|
||||
entitiesLog.put(entry.getKey().getSimpleName(),
|
||||
"%d [%f]",
|
||||
entry.getValue(),
|
||||
(float) (entry.getValue() / (double) loadedChunkCount));
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
append(log);
|
||||
appendln();
|
||||
}
|
||||
|
||||
private void appendWorldConfigurations(WorldGuardPlugin plugin, List<World> worlds,
|
||||
GlobalRegionManager regionMgr, ConfigurationManager mgr) {
|
||||
appendHeader("World Configurations");
|
||||
|
||||
LogListBlock log = new LogListBlock();
|
||||
|
||||
int i = 0;
|
||||
for (World world : worlds) {
|
||||
LogListBlock worldLog = log.putChild(world.getName() + " (" + i + ")");
|
||||
LogListBlock infoLog = worldLog.putChild("Information");
|
||||
LogListBlock configLog = worldLog.putChild("Configuration");
|
||||
LogListBlock blacklistLog = worldLog.putChild("Blacklist");
|
||||
LogListBlock regionsLog = worldLog.putChild("Region manager");
|
||||
|
||||
infoLog.put("Configuration file", (new File(plugin.getDataFolder(), "worlds/"
|
||||
+ world.getName() + "/config.yml")).getAbsoluteFile());
|
||||
|
||||
infoLog.put("Blacklist file", (new File(plugin.getDataFolder(), "worlds/"
|
||||
+ world.getName() + "/blacklist.txt")).getAbsoluteFile());
|
||||
infoLog.put("Regions file", (new File(plugin.getDataFolder(), "worlds/"
|
||||
+ world.getName() + "/regions.yml")).getAbsoluteFile());
|
||||
|
||||
WorldConfiguration config = mgr.get(world);
|
||||
|
||||
Class<? extends WorldConfiguration> cls = config.getClass();
|
||||
for (Field field : cls.getFields()) {
|
||||
try {
|
||||
Object val = field.get(config);
|
||||
configLog.put(field.getName(), String.valueOf(val));
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException ignore) {
|
||||
}
|
||||
}
|
||||
|
||||
if (config.getBlacklist() == null) {
|
||||
blacklistLog.put("State", "DISABLED");
|
||||
} else {
|
||||
blacklistLog.put("State", "Enabled");
|
||||
blacklistLog.put("Number of items",
|
||||
config.getBlacklist().getItemCount());
|
||||
blacklistLog.put("Is whitelist",
|
||||
config.getBlacklist().isWhitelist());
|
||||
}
|
||||
|
||||
RegionManager worldRegions = regionMgr.get(world);
|
||||
|
||||
regionsLog.put("Type", worldRegions.getClass().getCanonicalName());
|
||||
regionsLog.put("Number of regions", worldRegions.getRegions().size());
|
||||
LogListBlock globalRegionLog = regionsLog.putChild("Global region");
|
||||
|
||||
ProtectedRegion globalRegion = worldRegions.getRegion("__global__");
|
||||
if (globalRegion == null) {
|
||||
globalRegionLog.put("Status", "UNDEFINED");
|
||||
} else {
|
||||
for (Flag<?> flag : DefaultFlag.getFlags()) {
|
||||
if (flag instanceof StateFlag) {
|
||||
globalRegionLog.put(flag.getName(),
|
||||
globalRegion.getFlag(flag));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
append(log);
|
||||
appendln();
|
||||
}
|
||||
|
||||
public void write(File file) throws IOException {
|
||||
FileWriter writer = null;
|
||||
BufferedWriter out;
|
||||
|
||||
try {
|
||||
writer = new FileWriter(file);
|
||||
out = new BufferedWriter(writer);
|
||||
out.write(output.toString());
|
||||
out.close();
|
||||
} finally {
|
||||
if (writer != null) {
|
||||
try {
|
||||
writer.close();
|
||||
} catch (IOException ignore) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return output.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.isBlockWater;
|
||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.setBlockToWater;
|
||||
|
||||
import org.bukkit.World;
|
||||
|
||||
public class SpongeUtil {
|
||||
|
||||
/**
|
||||
* Remove water around a sponge.
|
||||
*
|
||||
* @param plugin The plugin instace
|
||||
* @param world The world the sponge isin
|
||||
* @param ox The x coordinate of the 'sponge' block
|
||||
* @param oy The y coordinate of the 'sponge' block
|
||||
* @param oz The z coordinate of the 'sponge' block
|
||||
*/
|
||||
public static void clearSpongeWater(WorldGuardPlugin plugin, World world, int ox, int oy, int oz) {
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(world);
|
||||
|
||||
for (int cx = -wcfg.spongeRadius; cx <= wcfg.spongeRadius; cx++) {
|
||||
for (int cy = -wcfg.spongeRadius; cy <= wcfg.spongeRadius; cy++) {
|
||||
for (int cz = -wcfg.spongeRadius; cz <= wcfg.spongeRadius; cz++) {
|
||||
if (isBlockWater(world, ox + cx, oy + cy, oz + cz)) {
|
||||
world.getBlockAt(ox + cx, oy + cy, oz + cz).setTypeId(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add water around a sponge.
|
||||
*
|
||||
* @param plugin The plugin instance
|
||||
* @param world The world the sponge is located in
|
||||
* @param ox The x coordinate of the 'sponge' block
|
||||
* @param oy The y coordinate of the 'sponge' block
|
||||
* @param oz The z coordinate of the 'sponge' block
|
||||
*/
|
||||
public static void addSpongeWater(WorldGuardPlugin plugin, World world, int ox, int oy, int oz) {
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(world);
|
||||
|
||||
// The negative x edge
|
||||
int cx = ox - wcfg.spongeRadius - 1;
|
||||
for (int cy = oy - wcfg.spongeRadius - 1; cy <= oy + wcfg.spongeRadius + 1; cy++) {
|
||||
for (int cz = oz - wcfg.spongeRadius - 1; cz <= oz + wcfg.spongeRadius + 1; cz++) {
|
||||
if (isBlockWater(world, cx, cy, cz)) {
|
||||
setBlockToWater(world, cx + 1, cy, cz);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The positive x edge
|
||||
cx = ox + wcfg.spongeRadius + 1;
|
||||
for (int cy = oy - wcfg.spongeRadius - 1; cy <= oy + wcfg.spongeRadius + 1; cy++) {
|
||||
for (int cz = oz - wcfg.spongeRadius - 1; cz <= oz + wcfg.spongeRadius + 1; cz++) {
|
||||
if (isBlockWater(world, cx, cy, cz)) {
|
||||
setBlockToWater(world, cx - 1, cy, cz);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The negative y edge
|
||||
int cy = oy - wcfg.spongeRadius - 1;
|
||||
for (cx = ox - wcfg.spongeRadius - 1; cx <= ox + wcfg.spongeRadius + 1; cx++) {
|
||||
for (int cz = oz - wcfg.spongeRadius - 1; cz <= oz + wcfg.spongeRadius + 1; cz++) {
|
||||
if (isBlockWater(world, cx, cy, cz)) {
|
||||
setBlockToWater(world, cx, cy + 1, cz);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The positive y edge
|
||||
cy = oy + wcfg.spongeRadius + 1;
|
||||
for (cx = ox - wcfg.spongeRadius - 1; cx <= ox + wcfg.spongeRadius + 1; cx++) {
|
||||
for (int cz = oz - wcfg.spongeRadius - 1; cz <= oz + wcfg.spongeRadius + 1; cz++) {
|
||||
if (isBlockWater(world, cx, cy, cz)) {
|
||||
setBlockToWater(world, cx, cy - 1, cz);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The negative z edge
|
||||
int cz = oz - wcfg.spongeRadius - 1;
|
||||
for (cx = ox - wcfg.spongeRadius - 1; cx <= ox + wcfg.spongeRadius + 1; cx++) {
|
||||
for (cy = oy - wcfg.spongeRadius - 1; cy <= oy + wcfg.spongeRadius + 1; cy++) {
|
||||
if (isBlockWater(world, cx, cy, cz)) {
|
||||
setBlockToWater(world, cx, cy, cz + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The positive z edge
|
||||
cz = oz + wcfg.spongeRadius + 1;
|
||||
for (cx = ox - wcfg.spongeRadius - 1; cx <= ox + wcfg.spongeRadius + 1; cx++) {
|
||||
for (cy = oy - wcfg.spongeRadius - 1; cy <= oy + wcfg.spongeRadius + 1; cy++) {
|
||||
if (isBlockWater(world, cx, cy, cz)) {
|
||||
setBlockToWater(world, cx, cy, cz - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
// $Id$
|
||||
/*
|
||||
* This file is a part of WorldGuard.
|
||||
* Copyright (c) sk89q <http://www.sk89q.com>
|
||||
* Copyright (c) the WorldGuard team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
|
||||
/**
|
||||
* Helper class to get a reference to WorldGuard and its components.
|
||||
*/
|
||||
public class WGBukkit {
|
||||
private static WorldGuardPlugin cachedPlugin = null;
|
||||
|
||||
private WGBukkit() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the WorldGuard plugin. If WorldGuard isn't loaded yet, then this will
|
||||
* return null.
|
||||
* <p>
|
||||
* If you are depending on WorldGuard in your plugin, you should place
|
||||
* <code>softdepend: [WorldGuard]</code> or <code>depend: [WorldGuard]</code>
|
||||
* in your plugin.yml so that this won't return null for you.
|
||||
*
|
||||
* @return the WorldGuard plugin or null
|
||||
*/
|
||||
public static WorldGuardPlugin getPlugin() {
|
||||
if (cachedPlugin == null) {
|
||||
cachedPlugin = (WorldGuardPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldGuard");
|
||||
}
|
||||
return cachedPlugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set cache to null for reload WorldGuardPlugin
|
||||
*/
|
||||
public static void cleanCache() {
|
||||
cachedPlugin = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the region manager for a given world. May return null if WorldGuard
|
||||
* is not loaded or region protection is not enabled for the given world.
|
||||
*
|
||||
* @param world world
|
||||
* @return a region manager or null
|
||||
*/
|
||||
public static RegionManager getRegionManager(World world) {
|
||||
if (getPlugin() == null) {
|
||||
return null;
|
||||
}
|
||||
return cachedPlugin.getRegionManager(world);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,586 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import com.sk89q.util.yaml.YAMLFormat;
|
||||
import com.sk89q.util.yaml.YAMLProcessor;
|
||||
import com.sk89q.worldguard.blacklist.Blacklist;
|
||||
import com.sk89q.worldguard.blacklist.BlacklistLogger;
|
||||
import com.sk89q.worldguard.blacklist.loggers.ConsoleLoggerHandler;
|
||||
import com.sk89q.worldguard.blacklist.loggers.DatabaseLoggerHandler;
|
||||
import com.sk89q.worldguard.blacklist.loggers.FileLoggerHandler;
|
||||
import com.sk89q.worldguard.chest.ChestProtection;
|
||||
import com.sk89q.worldguard.chest.SignChestProtection;
|
||||
|
||||
/**
|
||||
* Holds the configuration for individual worlds.
|
||||
*
|
||||
* @author sk89q
|
||||
* @author Michael
|
||||
*/
|
||||
public class WorldConfiguration {
|
||||
|
||||
public static final String CONFIG_HEADER = "#\r\n" +
|
||||
"# WorldGuard's world configuration file\r\n" +
|
||||
"#\r\n" +
|
||||
"# This is a world configuration file. Anything placed into here will only\r\n" +
|
||||
"# affect this world. If you don't put anything in this file, then the\r\n" +
|
||||
"# settings will be inherited from the main configuration file.\r\n" +
|
||||
"#\r\n" +
|
||||
"# If you see {} below, that means that there are NO entries in this file.\r\n" +
|
||||
"# Remove the {} and add your own entries.\r\n" +
|
||||
"#\r\n";
|
||||
|
||||
private WorldGuardPlugin plugin;
|
||||
|
||||
private String worldName;
|
||||
private YAMLProcessor parentConfig;
|
||||
private YAMLProcessor config;
|
||||
private File blacklistFile;
|
||||
|
||||
private Blacklist blacklist;
|
||||
private ChestProtection chestProtection = new SignChestProtection();
|
||||
|
||||
/* Configuration data start */
|
||||
public boolean opPermissions;
|
||||
public boolean fireSpreadDisableToggle;
|
||||
public boolean itemDurability;
|
||||
public boolean simulateSponge;
|
||||
public int spongeRadius;
|
||||
public boolean disableExpDrops;
|
||||
public Set<PotionEffectType> blockPotions;
|
||||
public boolean blockPotionsAlways;
|
||||
public boolean pumpkinScuba;
|
||||
public boolean redstoneSponges;
|
||||
public boolean noPhysicsGravel;
|
||||
public boolean noPhysicsSand;
|
||||
public boolean ropeLadders;
|
||||
public boolean allowPortalAnywhere;
|
||||
public Set<Integer> preventWaterDamage;
|
||||
public boolean blockLighter;
|
||||
public boolean disableFireSpread;
|
||||
public Set<Integer> disableFireSpreadBlocks;
|
||||
public boolean preventLavaFire;
|
||||
public Set<Integer> allowedLavaSpreadOver;
|
||||
public boolean blockTNTExplosions;
|
||||
public boolean blockTNTBlockDamage;
|
||||
public boolean blockCreeperExplosions;
|
||||
public boolean blockCreeperBlockDamage;
|
||||
public boolean blockWitherExplosions;
|
||||
public boolean blockWitherBlockDamage;
|
||||
public boolean blockWitherSkullExplosions;
|
||||
public boolean blockWitherSkullBlockDamage;
|
||||
public boolean blockEnderDragonBlockDamage;
|
||||
public boolean blockEnderDragonPortalCreation;
|
||||
public boolean blockFireballExplosions;
|
||||
public boolean blockFireballBlockDamage;
|
||||
public boolean blockOtherExplosions;
|
||||
public boolean blockEntityPaintingDestroy;
|
||||
public boolean blockEntityItemFrameDestroy;
|
||||
public boolean blockPluginSpawning;
|
||||
public boolean blockGroundSlimes;
|
||||
public boolean blockZombieDoorDestruction;
|
||||
public boolean disableContactDamage;
|
||||
public boolean disableFallDamage;
|
||||
public boolean disableLavaDamage;
|
||||
public boolean disableFireDamage;
|
||||
public boolean disableLightningDamage;
|
||||
public boolean disableDrowningDamage;
|
||||
public boolean disableSuffocationDamage;
|
||||
public boolean teleportOnSuffocation;
|
||||
public boolean disableVoidDamage;
|
||||
public boolean teleportOnVoid;
|
||||
public boolean disableExplosionDamage;
|
||||
public boolean disableMobDamage;
|
||||
public boolean useRegions;
|
||||
public boolean highFreqFlags;
|
||||
public int regionWand;
|
||||
public Set<EntityType> blockCreatureSpawn;
|
||||
// public boolean useiConomy;
|
||||
// public boolean buyOnClaim;
|
||||
// public double buyOnClaimPrice;
|
||||
public int maxClaimVolume;
|
||||
public boolean claimOnlyInsideExistingRegions;
|
||||
public int maxRegionCountPerPlayer;
|
||||
public boolean antiWolfDumbness;
|
||||
public boolean signChestProtection;
|
||||
public boolean disableSignChestProtectionCheck;
|
||||
public boolean removeInfiniteStacks;
|
||||
public boolean disableCreatureCropTrampling;
|
||||
public boolean disablePlayerCropTrampling;
|
||||
public boolean preventLightningFire;
|
||||
public Set<Integer> disallowedLightningBlocks;
|
||||
public boolean disableThunder;
|
||||
public boolean disableWeather;
|
||||
public boolean alwaysRaining;
|
||||
public boolean alwaysThundering;
|
||||
public boolean disablePigZap;
|
||||
public boolean disableCreeperPower;
|
||||
public boolean disableHealthRegain;
|
||||
public boolean disableMushroomSpread;
|
||||
public boolean disableIceMelting;
|
||||
public boolean disableSnowMelting;
|
||||
public boolean disableSnowFormation;
|
||||
public boolean disableIceFormation;
|
||||
public boolean disableLeafDecay;
|
||||
public boolean disableGrassGrowth;
|
||||
public boolean disableMyceliumSpread;
|
||||
public boolean disableEndermanGriefing;
|
||||
public boolean regionInvinciblityRemovesMobs;
|
||||
public boolean disableDeathMessages;
|
||||
public boolean disableObsidianGenerators;
|
||||
|
||||
private Map<String, Integer> maxRegionCounts;
|
||||
|
||||
/* Configuration data end */
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param plugin The WorldGuardPlugin instance
|
||||
* @param worldName The world name that this WorldConfiguration is for.
|
||||
* @param parentConfig The parent configuration to read defaults from
|
||||
*/
|
||||
public WorldConfiguration(WorldGuardPlugin plugin, String worldName, YAMLProcessor parentConfig) {
|
||||
File baseFolder = new File(plugin.getDataFolder(), "worlds/" + worldName);
|
||||
File configFile = new File(baseFolder, "config.yml");
|
||||
blacklistFile = new File(baseFolder, "blacklist.txt");
|
||||
|
||||
this.plugin = plugin;
|
||||
this.worldName = worldName;
|
||||
this.parentConfig = parentConfig;
|
||||
|
||||
plugin.createDefaultConfiguration(configFile, "config_world.yml");
|
||||
plugin.createDefaultConfiguration(blacklistFile, "blacklist.txt");
|
||||
|
||||
config = new YAMLProcessor(configFile, true, YAMLFormat.EXTENDED);
|
||||
loadConfiguration();
|
||||
|
||||
plugin.getLogger().info("Loaded configuration for world '" + worldName + "'");
|
||||
}
|
||||
|
||||
private boolean getBoolean(String node, boolean def) {
|
||||
boolean val = parentConfig.getBoolean(node, def);
|
||||
|
||||
if (config.getProperty(node) != null) {
|
||||
return config.getBoolean(node, def);
|
||||
} else {
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
private String getString(String node, String def) {
|
||||
String val = parentConfig.getString(node, def);
|
||||
|
||||
if (config.getProperty(node) != null) {
|
||||
return config.getString(node, def);
|
||||
} else {
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
private int getInt(String node, int def) {
|
||||
int val = parentConfig.getInt(node, def);
|
||||
|
||||
if (config.getProperty(node) != null) {
|
||||
return config.getInt(node, def);
|
||||
} else {
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private double getDouble(String node, double def) {
|
||||
double val = parentConfig.getDouble(node, def);
|
||||
|
||||
if (config.getProperty(node) != null) {
|
||||
return config.getDouble(node, def);
|
||||
} else {
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
private List<Integer> getIntList(String node, List<Integer> def) {
|
||||
List<Integer> res = parentConfig.getIntList(node, def);
|
||||
|
||||
if (res == null || res.size() == 0) {
|
||||
parentConfig.setProperty(node, new ArrayList<Integer>());
|
||||
}
|
||||
|
||||
if (config.getProperty(node) != null) {
|
||||
res = config.getIntList(node, def);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
private List<String> getStringList(String node, List<String> def) {
|
||||
List<String> res = parentConfig.getStringList(node, def);
|
||||
|
||||
if (res == null || res.size() == 0) {
|
||||
parentConfig.setProperty(node, new ArrayList<String>());
|
||||
}
|
||||
|
||||
if (config.getProperty(node) != null) {
|
||||
res = config.getStringList(node, def);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
private List<String> getKeys(String node) {
|
||||
List<String> res = parentConfig.getKeys(node);
|
||||
|
||||
if (res == null || res.size() == 0) {
|
||||
res = config.getKeys(node);
|
||||
}
|
||||
if (res == null) {
|
||||
res = new ArrayList<String>();
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
private Object getProperty(String node) {
|
||||
Object res = parentConfig.getProperty(node);
|
||||
|
||||
if (config.getProperty(node) != null) {
|
||||
res = config.getProperty(node);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the configuration.
|
||||
*/
|
||||
private void loadConfiguration() {
|
||||
try {
|
||||
config.load();
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().severe("Error reading configuration for world " + worldName + ": ");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
opPermissions = getBoolean("op-permissions", true);
|
||||
|
||||
itemDurability = getBoolean("protection.item-durability", true);
|
||||
removeInfiniteStacks = getBoolean("protection.remove-infinite-stacks", false);
|
||||
disableExpDrops = getBoolean("protection.disable-xp-orb-drops", false);
|
||||
disableObsidianGenerators = getBoolean("protection.disable-obsidian-generators", false);
|
||||
|
||||
blockPotions = new HashSet<PotionEffectType>();
|
||||
for (String potionName : getStringList("gameplay.block-potions", null)) {
|
||||
PotionEffectType effect = PotionEffectType.getByName(potionName);
|
||||
|
||||
if (effect == null) {
|
||||
plugin.getLogger().warning("Unknown potion effect type '" + potionName + "'");
|
||||
} else {
|
||||
blockPotions.add(effect);
|
||||
}
|
||||
}
|
||||
blockPotionsAlways = getBoolean("gameplay.block-potions-overly-reliably", false);
|
||||
|
||||
simulateSponge = getBoolean("simulation.sponge.enable", true);
|
||||
spongeRadius = Math.max(1, getInt("simulation.sponge.radius", 3)) - 1;
|
||||
redstoneSponges = getBoolean("simulation.sponge.redstone", false);
|
||||
|
||||
pumpkinScuba = getBoolean("default.pumpkin-scuba", false);
|
||||
disableHealthRegain = getBoolean("default.disable-health-regain", false);
|
||||
|
||||
noPhysicsGravel = getBoolean("physics.no-physics-gravel", false);
|
||||
noPhysicsSand = getBoolean("physics.no-physics-sand", false);
|
||||
ropeLadders = getBoolean("physics.vine-like-rope-ladders", false);
|
||||
allowPortalAnywhere = getBoolean("physics.allow-portal-anywhere", false);
|
||||
preventWaterDamage = new HashSet<Integer>(getIntList("physics.disable-water-damage-blocks", null));
|
||||
|
||||
blockTNTExplosions = getBoolean("ignition.block-tnt", false);
|
||||
blockTNTBlockDamage = getBoolean("ignition.block-tnt-block-damage", false);
|
||||
blockLighter = getBoolean("ignition.block-lighter", false);
|
||||
|
||||
preventLavaFire = getBoolean("fire.disable-lava-fire-spread", true);
|
||||
disableFireSpread = getBoolean("fire.disable-all-fire-spread", false);
|
||||
disableFireSpreadBlocks = new HashSet<Integer>(getIntList("fire.disable-fire-spread-blocks", null));
|
||||
allowedLavaSpreadOver = new HashSet<Integer>(getIntList("fire.lava-spread-blocks", null));
|
||||
|
||||
blockCreeperExplosions = getBoolean("mobs.block-creeper-explosions", false);
|
||||
blockCreeperBlockDamage = getBoolean("mobs.block-creeper-block-damage", false);
|
||||
blockWitherExplosions = getBoolean("mobs.block-wither-explosions", false);
|
||||
blockWitherBlockDamage = getBoolean("mobs.block-wither-block-damage", false);
|
||||
blockWitherSkullExplosions = getBoolean("mobs.block-wither-skull-explosions", false);
|
||||
blockWitherSkullBlockDamage = getBoolean("mobs.block-wither-skull-block-damage", false);
|
||||
blockEnderDragonBlockDamage = getBoolean("mobs.block-enderdragon-block-damage", false);
|
||||
blockEnderDragonPortalCreation = getBoolean("mobs.block-enderdragon-portal-creation", false);
|
||||
blockFireballExplosions = getBoolean("mobs.block-fireball-explosions", false);
|
||||
blockFireballBlockDamage = getBoolean("mobs.block-fireball-block-damage", false);
|
||||
antiWolfDumbness = getBoolean("mobs.anti-wolf-dumbness", false);
|
||||
disableEndermanGriefing = getBoolean("mobs.disable-enderman-griefing", false);
|
||||
blockEntityPaintingDestroy = getBoolean("mobs.block-painting-destroy", false);
|
||||
blockEntityItemFrameDestroy = getBoolean("mobs.block-item-frame-destroy", false);
|
||||
blockPluginSpawning = getBoolean("mobs.block-plugin-spawning", true);
|
||||
blockGroundSlimes = getBoolean("mobs.block-above-ground-slimes", false);
|
||||
blockOtherExplosions = getBoolean("mobs.block-other-explosions", false);
|
||||
blockZombieDoorDestruction = getBoolean("mobs.block-zombie-door-destruction", false);
|
||||
|
||||
disableFallDamage = getBoolean("player-damage.disable-fall-damage", false);
|
||||
disableLavaDamage = getBoolean("player-damage.disable-lava-damage", false);
|
||||
disableFireDamage = getBoolean("player-damage.disable-fire-damage", false);
|
||||
disableLightningDamage = getBoolean("player-damage.disable-lightning-damage", false);
|
||||
disableDrowningDamage = getBoolean("player-damage.disable-drowning-damage", false);
|
||||
disableSuffocationDamage = getBoolean("player-damage.disable-suffocation-damage", false);
|
||||
disableContactDamage = getBoolean("player-damage.disable-contact-damage", false);
|
||||
teleportOnSuffocation = getBoolean("player-damage.teleport-on-suffocation", false);
|
||||
disableVoidDamage = getBoolean("player-damage.disable-void-damage", false);
|
||||
teleportOnVoid = getBoolean("player-damage.teleport-on-void-falling", false);
|
||||
disableExplosionDamage = getBoolean("player-damage.disable-explosion-damage", false);
|
||||
disableMobDamage = getBoolean("player-damage.disable-mob-damage", false);
|
||||
disableDeathMessages = getBoolean("player-damage.disable-death-messages", false);
|
||||
|
||||
signChestProtection = getBoolean("chest-protection.enable", false);
|
||||
disableSignChestProtectionCheck = getBoolean("chest-protection.disable-off-check", false);
|
||||
|
||||
disableCreatureCropTrampling = getBoolean("crops.disable-creature-trampling", false);
|
||||
disablePlayerCropTrampling = getBoolean("crops.disable-player-trampling", false);
|
||||
|
||||
disallowedLightningBlocks = new HashSet<Integer>(getIntList("weather.prevent-lightning-strike-blocks", null));
|
||||
preventLightningFire = getBoolean("weather.disable-lightning-strike-fire", false);
|
||||
disableThunder = getBoolean("weather.disable-thunderstorm", false);
|
||||
disableWeather = getBoolean("weather.disable-weather", false);
|
||||
disablePigZap = getBoolean("weather.disable-pig-zombification", false);
|
||||
disableCreeperPower = getBoolean("weather.disable-powered-creepers", false);
|
||||
alwaysRaining = getBoolean("weather.always-raining", false);
|
||||
alwaysThundering = getBoolean("weather.always-thundering", false);
|
||||
|
||||
disableMushroomSpread = getBoolean("dynamics.disable-mushroom-spread", false);
|
||||
disableIceMelting = getBoolean("dynamics.disable-ice-melting", false);
|
||||
disableSnowMelting = getBoolean("dynamics.disable-snow-melting", false);
|
||||
disableSnowFormation = getBoolean("dynamics.disable-snow-formation", false);
|
||||
disableIceFormation = getBoolean("dynamics.disable-ice-formation", false);
|
||||
disableLeafDecay = getBoolean("dynamics.disable-leaf-decay", false);
|
||||
disableGrassGrowth = getBoolean("dynamics.disable-grass-growth", false);
|
||||
disableMyceliumSpread = getBoolean("dynamics.disable-mycelium-spread", false);
|
||||
|
||||
useRegions = getBoolean("regions.enable", true);
|
||||
regionInvinciblityRemovesMobs = getBoolean("regions.invincibility-removes-mobs", false);
|
||||
highFreqFlags = getBoolean("regions.high-frequency-flags", false);
|
||||
regionWand = getInt("regions.wand", 334);
|
||||
maxClaimVolume = getInt("regions.max-claim-volume", 30000);
|
||||
claimOnlyInsideExistingRegions = getBoolean("regions.claim-only-inside-existing-regions", false);
|
||||
|
||||
maxRegionCountPerPlayer = getInt("regions.max-region-count-per-player.default", 7);
|
||||
maxRegionCounts = new HashMap<String, Integer>();
|
||||
maxRegionCounts.put(null, maxRegionCountPerPlayer);
|
||||
|
||||
for (String key : getKeys("regions.max-region-count-per-player")) {
|
||||
if (!key.equalsIgnoreCase("default")) {
|
||||
Object val = getProperty("regions.max-region-count-per-player." + key);
|
||||
if (val != null && val instanceof Number) {
|
||||
maxRegionCounts.put(key, ((Number) val).intValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// useiConomy = getBoolean("iconomy.enable", false);
|
||||
// buyOnClaim = getBoolean("iconomy.buy-on-claim", false);
|
||||
// buyOnClaimPrice = getDouble("iconomy.buy-on-claim-price", 1.0);
|
||||
|
||||
blockCreatureSpawn = new HashSet<EntityType>();
|
||||
for (String creatureName : getStringList("mobs.block-creature-spawn", null)) {
|
||||
EntityType creature = EntityType.fromName(creatureName);
|
||||
|
||||
if (creature == null) {
|
||||
plugin.getLogger().warning("Unknown mob type '" + creatureName + "'");
|
||||
} else if (!creature.isAlive()) {
|
||||
plugin.getLogger().warning("Entity type '" + creatureName + "' is not a creature");
|
||||
} else {
|
||||
blockCreatureSpawn.add(creature);
|
||||
}
|
||||
}
|
||||
|
||||
boolean useBlacklistAsWhitelist = getBoolean("blacklist.use-as-whitelist", false);
|
||||
|
||||
// Console log configuration
|
||||
boolean logConsole = getBoolean("blacklist.logging.console.enable", true);
|
||||
|
||||
// Database log configuration
|
||||
boolean logDatabase = getBoolean("blacklist.logging.database.enable", false);
|
||||
String dsn = getString("blacklist.logging.database.dsn", "jdbc:mysql://localhost:3306/minecraft");
|
||||
String user = getString("blacklist.logging.database.user", "root");
|
||||
String pass = getString("blacklist.logging.database.pass", "");
|
||||
String table = getString("blacklist.logging.database.table", "blacklist_events");
|
||||
|
||||
// File log configuration
|
||||
boolean logFile = getBoolean("blacklist.logging.file.enable", false);
|
||||
String logFilePattern = getString("blacklist.logging.file.path", "worldguard/logs/%Y-%m-%d.log");
|
||||
int logFileCacheSize = Math.max(1, getInt("blacklist.logging.file.open-files", 10));
|
||||
|
||||
// Load the blacklist
|
||||
try {
|
||||
// If there was an existing blacklist, close loggers
|
||||
if (blacklist != null) {
|
||||
blacklist.getLogger().close();
|
||||
}
|
||||
|
||||
// First load the blacklist data from worldguard-blacklist.txt
|
||||
Blacklist blist = new BukkitBlacklist(useBlacklistAsWhitelist, plugin);
|
||||
blist.load(blacklistFile);
|
||||
|
||||
// If the blacklist is empty, then set the field to null
|
||||
// and save some resources
|
||||
if (blist.isEmpty()) {
|
||||
this.blacklist = null;
|
||||
} else {
|
||||
this.blacklist = blist;
|
||||
plugin.getLogger().log(Level.INFO, "Blacklist loaded.");
|
||||
|
||||
BlacklistLogger blacklistLogger = blist.getLogger();
|
||||
|
||||
if (logDatabase) {
|
||||
blacklistLogger.addHandler(new DatabaseLoggerHandler(dsn, user, pass, table, worldName, plugin.getLogger()));
|
||||
}
|
||||
|
||||
if (logConsole) {
|
||||
blacklistLogger.addHandler(new ConsoleLoggerHandler(worldName, plugin.getLogger()));
|
||||
}
|
||||
|
||||
if (logFile) {
|
||||
FileLoggerHandler handler =
|
||||
new FileLoggerHandler(logFilePattern, logFileCacheSize, worldName, plugin.getLogger());
|
||||
blacklistLogger.addHandler(handler);
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
plugin.getLogger().log(Level.WARNING, "WorldGuard blacklist does not exist.");
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().log(Level.WARNING, "Could not load WorldGuard blacklist: "
|
||||
+ e.getMessage());
|
||||
}
|
||||
|
||||
// Print an overview of settings
|
||||
if (getBoolean("summary-on-start", true)) {
|
||||
plugin.getLogger().log(Level.INFO, blockTNTExplosions
|
||||
? "(" + worldName + ") TNT ignition is blocked."
|
||||
: "(" + worldName + ") TNT ignition is PERMITTED.");
|
||||
plugin.getLogger().log(Level.INFO, blockLighter
|
||||
? "(" + worldName + ") Lighters are blocked."
|
||||
: "(" + worldName + ") Lighters are PERMITTED.");
|
||||
plugin.getLogger().log(Level.INFO, preventLavaFire
|
||||
? "(" + worldName + ") Lava fire is blocked."
|
||||
: "(" + worldName + ") Lava fire is PERMITTED.");
|
||||
|
||||
if (disableFireSpread) {
|
||||
plugin.getLogger().log(Level.INFO, "(" + worldName + ") All fire spread is disabled.");
|
||||
} else {
|
||||
if (disableFireSpreadBlocks.size() > 0) {
|
||||
plugin.getLogger().log(Level.INFO, "(" + worldName
|
||||
+ ") Fire spread is limited to "
|
||||
+ disableFireSpreadBlocks.size() + " block types.");
|
||||
} else {
|
||||
plugin.getLogger().log(Level.INFO, "(" + worldName
|
||||
+ ") Fire spread is UNRESTRICTED.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
config.setHeader(CONFIG_HEADER);
|
||||
|
||||
config.save();
|
||||
}
|
||||
|
||||
public Blacklist getBlacklist() {
|
||||
return this.blacklist;
|
||||
}
|
||||
|
||||
public String getWorldName() {
|
||||
return this.worldName;
|
||||
}
|
||||
|
||||
public boolean isChestProtected(Block block, Player player) {
|
||||
if (!signChestProtection) {
|
||||
return false;
|
||||
}
|
||||
if (plugin.hasPermission(player, "worldguard.chest-protection.override")
|
||||
|| plugin.hasPermission(player, "worldguard.override.chest-protection")) {
|
||||
return false;
|
||||
}
|
||||
return chestProtection.isProtected(block, player);
|
||||
}
|
||||
|
||||
public boolean isChestProtected(Block block) {
|
||||
|
||||
return signChestProtection && chestProtection.isProtected(block, null);
|
||||
}
|
||||
|
||||
public boolean isChestProtectedPlacement(Block block, Player player) {
|
||||
if (!signChestProtection) {
|
||||
return false;
|
||||
}
|
||||
if (plugin.hasPermission(player, "worldguard.chest-protection.override")
|
||||
|| plugin.hasPermission(player, "worldguard.override.chest-protection")) {
|
||||
return false;
|
||||
}
|
||||
return chestProtection.isProtectedPlacement(block, player);
|
||||
}
|
||||
|
||||
public boolean isAdjacentChestProtected(Block block, Player player) {
|
||||
if (!signChestProtection) {
|
||||
return false;
|
||||
}
|
||||
if (plugin.hasPermission(player, "worldguard.chest-protection.override")
|
||||
|| plugin.hasPermission(player, "worldguard.override.chest-protection")) {
|
||||
return false;
|
||||
}
|
||||
return chestProtection.isAdjacentChestProtected(block, player);
|
||||
}
|
||||
|
||||
public ChestProtection getChestProtection() {
|
||||
return chestProtection;
|
||||
}
|
||||
|
||||
public int getMaxRegionCount(Player player) {
|
||||
int max = -1;
|
||||
for (String group : plugin.getGroups(player)) {
|
||||
if (maxRegionCounts.containsKey(group)) {
|
||||
int groupMax = maxRegionCounts.get(group);
|
||||
if (max < groupMax) max = groupMax;
|
||||
}
|
||||
}
|
||||
if (max <= -1) {
|
||||
max = maxRegionCountPerPlayer;
|
||||
}
|
||||
return max;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,861 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockBurnEvent;
|
||||
import org.bukkit.event.block.BlockDamageEvent;
|
||||
import org.bukkit.event.block.BlockDispenseEvent;
|
||||
import org.bukkit.event.block.BlockFadeEvent;
|
||||
import org.bukkit.event.block.BlockFormEvent;
|
||||
import org.bukkit.event.block.BlockFromToEvent;
|
||||
import org.bukkit.event.block.BlockIgniteEvent;
|
||||
import org.bukkit.event.block.BlockIgniteEvent.IgniteCause;
|
||||
import org.bukkit.event.block.BlockPhysicsEvent;
|
||||
import org.bukkit.event.block.BlockPistonExtendEvent;
|
||||
import org.bukkit.event.block.BlockPistonRetractEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.block.BlockRedstoneEvent;
|
||||
import org.bukkit.event.block.BlockSpreadEvent;
|
||||
import org.bukkit.event.block.LeavesDecayEvent;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.Potion;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BlockID;
|
||||
import com.sk89q.worldedit.blocks.BlockType;
|
||||
import com.sk89q.worldedit.blocks.ItemType;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.blacklist.events.BlockBreakBlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.events.BlockPlaceBlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.events.DestroyWithBlacklistEvent;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
|
||||
/**
|
||||
* The listener for block events.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class WorldGuardBlockListener implements Listener {
|
||||
|
||||
private WorldGuardPlugin plugin;
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param plugin The plugin instance
|
||||
*/
|
||||
public WorldGuardBlockListener(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register events.
|
||||
*/
|
||||
public void registerEvents() {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the world configuration given a world.
|
||||
*
|
||||
* @param world The world to get the configuration for.
|
||||
* @return The configuration for {@code world}
|
||||
*/
|
||||
protected WorldConfiguration getWorldConfig(World world) {
|
||||
return plugin.getGlobalStateManager().get(world);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the world configuration given a player.
|
||||
*
|
||||
* @param player The player to get the wold from
|
||||
* @return The {@link WorldConfiguration} for the player's world
|
||||
*/
|
||||
protected WorldConfiguration getWorldConfig(Player player) {
|
||||
return getWorldConfig(player.getWorld());
|
||||
}
|
||||
|
||||
/*
|
||||
* Called when a block is damaged.
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onBlockDamage(BlockDamageEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Block blockDamaged = event.getBlock();
|
||||
|
||||
// Cake are damaged and not broken when they are eaten, so we must
|
||||
// handle them a bit separately
|
||||
if (blockDamaged.getTypeId() == BlockID.CAKE_BLOCK) {
|
||||
if (!plugin.getGlobalRegionManager().canBuild(player, blockDamaged)) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You're not invited to this tea party!");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Called when a block is broken.
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
WorldConfiguration wcfg = getWorldConfig(player);
|
||||
|
||||
if (!wcfg.itemDurability) {
|
||||
ItemStack held = player.getItemInHand();
|
||||
if (held.getTypeId() > 0
|
||||
&& !(ItemType.usesDamageValue(held.getTypeId())
|
||||
|| BlockType.usesData(held.getTypeId()))) {
|
||||
held.setDurability((short) -1);
|
||||
player.setItemInHand(held);
|
||||
}
|
||||
}
|
||||
|
||||
if (!plugin.getGlobalRegionManager().canBuild(player, event.getBlock())
|
||||
|| !plugin.getGlobalRegionManager().canConstruct(player, event.getBlock())) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.getBlacklist() != null) {
|
||||
if (!wcfg.getBlacklist().check(
|
||||
new BlockBreakBlacklistEvent(plugin.wrapPlayer(player),
|
||||
toVector(event.getBlock()),
|
||||
event.getBlock().getTypeId()), false, false)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!wcfg.getBlacklist().check(
|
||||
new DestroyWithBlacklistEvent(plugin.wrapPlayer(player),
|
||||
toVector(event.getBlock()),
|
||||
player.getItemInHand().getTypeId()), false, false)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (wcfg.isChestProtected(event.getBlock(), player)) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "The chest is protected.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Called when fluids flow.
|
||||
*/
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBlockFromTo(BlockFromToEvent event) {
|
||||
World world = event.getBlock().getWorld();
|
||||
Block blockFrom = event.getBlock();
|
||||
Block blockTo = event.getToBlock();
|
||||
|
||||
boolean isWater = blockFrom.getTypeId() == 8 || blockFrom.getTypeId() == 9;
|
||||
boolean isLava = blockFrom.getTypeId() == 10 || blockFrom.getTypeId() == 11;
|
||||
boolean isAir = blockFrom.getTypeId() == 0;
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
|
||||
|
||||
if (cfg.activityHaltToggle) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.simulateSponge && isWater) {
|
||||
int ox = blockTo.getX();
|
||||
int oy = blockTo.getY();
|
||||
int oz = blockTo.getZ();
|
||||
|
||||
for (int cx = -wcfg.spongeRadius; cx <= wcfg.spongeRadius; cx++) {
|
||||
for (int cy = -wcfg.spongeRadius; cy <= wcfg.spongeRadius; cy++) {
|
||||
for (int cz = -wcfg.spongeRadius; cz <= wcfg.spongeRadius; cz++) {
|
||||
Block sponge = world.getBlockAt(ox + cx, oy + cy, oz + cz);
|
||||
if (sponge.getTypeId() == 19
|
||||
&& (!wcfg.redstoneSponges || !sponge.isBlockIndirectlyPowered())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*if (plugin.classicWater && isWater) {
|
||||
int blockBelow = blockFrom.getRelative(0, -1, 0).getTypeId();
|
||||
if (blockBelow != 0 && blockBelow != 8 && blockBelow != 9) {
|
||||
blockFrom.setTypeId(9);
|
||||
if (blockTo.getTypeId() == 0) {
|
||||
blockTo.setTypeId(9);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}*/
|
||||
|
||||
// Check the fluid block (from) whether it is air.
|
||||
// If so and the target block is protected, cancel the event
|
||||
if (wcfg.preventWaterDamage.size() > 0) {
|
||||
int targetId = blockTo.getTypeId();
|
||||
|
||||
if ((isAir || isWater) &&
|
||||
wcfg.preventWaterDamage.contains(targetId)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (wcfg.allowedLavaSpreadOver.size() > 0 && isLava) {
|
||||
int targetId = blockTo.getRelative(0, -1, 0).getTypeId();
|
||||
|
||||
if (!wcfg.allowedLavaSpreadOver.contains(targetId)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (wcfg.highFreqFlags && isWater
|
||||
&& !plugin.getGlobalRegionManager().allows(DefaultFlag.WATER_FLOW,
|
||||
blockFrom.getLocation())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.highFreqFlags && isLava
|
||||
&& !plugin.getGlobalRegionManager().allows(DefaultFlag.LAVA_FLOW,
|
||||
blockFrom.getLocation())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.disableObsidianGenerators && (isAir || isLava)
|
||||
&& blockTo.getTypeId() == 55) {
|
||||
blockTo.setTypeId(0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Called when a block gets ignited.
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onBlockIgnite(BlockIgniteEvent event) {
|
||||
IgniteCause cause = event.getCause();
|
||||
Block block = event.getBlock();
|
||||
World world = block.getWorld();
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(world);
|
||||
|
||||
if (cfg.activityHaltToggle) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
boolean isFireSpread = cause == IgniteCause.SPREAD;
|
||||
|
||||
if (wcfg.preventLightningFire && cause == IgniteCause.LIGHTNING) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.preventLavaFire && cause == IgniteCause.LAVA) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.disableFireSpread && isFireSpread) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.blockLighter && (cause == IgniteCause.FLINT_AND_STEEL || cause == IgniteCause.FIREBALL)
|
||||
&& event.getPlayer() != null
|
||||
&& !plugin.hasPermission(event.getPlayer(), "worldguard.override.lighter")) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.fireSpreadDisableToggle && isFireSpread) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.disableFireSpreadBlocks.size() > 0 && isFireSpread) {
|
||||
int x = block.getX();
|
||||
int y = block.getY();
|
||||
int z = block.getZ();
|
||||
|
||||
if (wcfg.disableFireSpreadBlocks.contains(world.getBlockTypeIdAt(x, y - 1, z))
|
||||
|| wcfg.disableFireSpreadBlocks.contains(world.getBlockTypeIdAt(x + 1, y, z))
|
||||
|| wcfg.disableFireSpreadBlocks.contains(world.getBlockTypeIdAt(x - 1, y, z))
|
||||
|| wcfg.disableFireSpreadBlocks.contains(world.getBlockTypeIdAt(x, y, z - 1))
|
||||
|| wcfg.disableFireSpreadBlocks.contains(world.getBlockTypeIdAt(x, y, z + 1))) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (wcfg.useRegions) {
|
||||
Vector pt = toVector(block);
|
||||
Player player = event.getPlayer();
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
|
||||
|
||||
if (player != null && !plugin.getGlobalRegionManager().hasBypass(player, world)) {
|
||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||
|
||||
if (cause == IgniteCause.FLINT_AND_STEEL || cause == IgniteCause.FIREBALL) {
|
||||
if (!set.canBuild(localPlayer)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (!set.allows(DefaultFlag.LIGHTER, localPlayer)
|
||||
&& !plugin.hasPermission(player, "worldguard.override.lighter")) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (wcfg.highFreqFlags && isFireSpread
|
||||
&& !set.allows(DefaultFlag.FIRE_SPREAD)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.highFreqFlags && cause == IgniteCause.LAVA
|
||||
&& !set.allows(DefaultFlag.LAVA_FIRE)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (cause == IgniteCause.FIREBALL && event.getPlayer() == null) {
|
||||
// wtf bukkit, FIREBALL is supposed to be reserved to players
|
||||
if (!set.allows(DefaultFlag.GHAST_FIREBALL)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (cause == IgniteCause.LIGHTNING && !set.allows(DefaultFlag.LIGHTNING)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Called when a block is destroyed from burning.
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onBlockBurn(BlockBurnEvent event) {
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
|
||||
|
||||
if (cfg.activityHaltToggle) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.disableFireSpread) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.fireSpreadDisableToggle) {
|
||||
Block block = event.getBlock();
|
||||
event.setCancelled(true);
|
||||
checkAndDestroyAround(block.getWorld(), block.getX(), block.getY(), block.getZ(), BlockID.FIRE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.disableFireSpreadBlocks.size() > 0) {
|
||||
Block block = event.getBlock();
|
||||
|
||||
if (wcfg.disableFireSpreadBlocks.contains(block.getTypeId())) {
|
||||
event.setCancelled(true);
|
||||
checkAndDestroyAround(block.getWorld(), block.getX(), block.getY(), block.getZ(), BlockID.FIRE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (wcfg.isChestProtected(event.getBlock())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.useRegions) {
|
||||
Block block = event.getBlock();
|
||||
int x = block.getX();
|
||||
int y = block.getY();
|
||||
int z = block.getZ();
|
||||
Vector pt = toVector(block);
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(block.getWorld());
|
||||
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
|
||||
|
||||
if (!set.allows(DefaultFlag.FIRE_SPREAD)) {
|
||||
checkAndDestroyAround(block.getWorld(), x, y, z, BlockID.FIRE);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void checkAndDestroyAround(World world, int x, int y, int z, int required) {
|
||||
checkAndDestroy(world, x, y, z + 1, required);
|
||||
checkAndDestroy(world, x, y, z - 1, required);
|
||||
checkAndDestroy(world, x, y + 1, z, required);
|
||||
checkAndDestroy(world, x, y - 1, z, required);
|
||||
checkAndDestroy(world, x + 1, y, z, required);
|
||||
checkAndDestroy(world, x - 1, y, z, required);
|
||||
}
|
||||
|
||||
private void checkAndDestroy(World world, int x, int y, int z, int required) {
|
||||
if (world.getBlockTypeIdAt(x, y, z) == required) {
|
||||
world.getBlockAt(x, y, z).setTypeId(BlockID.AIR);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Called when block physics occurs.
|
||||
*/
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBlockPhysics(BlockPhysicsEvent event) {
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
|
||||
|
||||
if (cfg.activityHaltToggle) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
int id = event.getChangedTypeId();
|
||||
|
||||
if (id == 13 && wcfg.noPhysicsGravel) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (id == 12 && wcfg.noPhysicsSand) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (id == 90 && wcfg.allowPortalAnywhere) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.ropeLadders && event.getBlock().getType() == Material.LADDER) {
|
||||
if (event.getBlock().getRelative(0, 1, 0).getType() == Material.LADDER) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Called when a player places a block.
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
Block blockPlaced = event.getBlock();
|
||||
Player player = event.getPlayer();
|
||||
World world = blockPlaced.getWorld();
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(world);
|
||||
|
||||
if (wcfg.useRegions) {
|
||||
final Location location = blockPlaced.getLocation();
|
||||
if (!plugin.getGlobalRegionManager().canBuild(player, location)
|
||||
|| !plugin.getGlobalRegionManager().canConstruct(player, location)) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (wcfg.getBlacklist() != null) {
|
||||
if (!wcfg.getBlacklist().check(
|
||||
new BlockPlaceBlacklistEvent(plugin.wrapPlayer(player), toVector(blockPlaced),
|
||||
blockPlaced.getTypeId()), false, false)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (wcfg.signChestProtection && wcfg.getChestProtection().isChest(blockPlaced.getTypeId())) {
|
||||
if (wcfg.isAdjacentChestProtected(event.getBlock(), player)) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "This spot is for a chest that you don't have permission for.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (wcfg.simulateSponge && blockPlaced.getTypeId() == 19) {
|
||||
if (wcfg.redstoneSponges && blockPlaced.isBlockIndirectlyPowered()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int ox = blockPlaced.getX();
|
||||
int oy = blockPlaced.getY();
|
||||
int oz = blockPlaced.getZ();
|
||||
|
||||
SpongeUtil.clearSpongeWater(plugin, world, ox, oy, oz);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Called when redstone changes.
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onBlockRedstoneChange(BlockRedstoneEvent event) {
|
||||
Block blockTo = event.getBlock();
|
||||
World world = blockTo.getWorld();
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(world);
|
||||
|
||||
if (wcfg.simulateSponge && wcfg.redstoneSponges) {
|
||||
int ox = blockTo.getX();
|
||||
int oy = blockTo.getY();
|
||||
int oz = blockTo.getZ();
|
||||
|
||||
for (int cx = -1; cx <= 1; cx++) {
|
||||
for (int cy = -1; cy <= 1; cy++) {
|
||||
for (int cz = -1; cz <= 1; cz++) {
|
||||
Block sponge = world.getBlockAt(ox + cx, oy + cy, oz + cz);
|
||||
if (sponge.getTypeId() == 19
|
||||
&& sponge.isBlockIndirectlyPowered()) {
|
||||
SpongeUtil.clearSpongeWater(plugin, world, ox + cx, oy + cy, oz + cz);
|
||||
} else if (sponge.getTypeId() == 19
|
||||
&& !sponge.isBlockIndirectlyPowered()) {
|
||||
SpongeUtil.addSpongeWater(plugin, world, ox + cx, oy + cy, oz + cz);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Called when a sign is changed.
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onSignChange(SignChangeEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
WorldConfiguration wcfg = getWorldConfig(player);
|
||||
|
||||
if (wcfg.signChestProtection) {
|
||||
if (event.getLine(0).equalsIgnoreCase("[Lock]")) {
|
||||
if (wcfg.isChestProtectedPlacement(event.getBlock(), player)) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You do not own the adjacent chest.");
|
||||
event.getBlock().breakNaturally();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getBlock().getTypeId() != BlockID.SIGN_POST) {
|
||||
player.sendMessage(ChatColor.RED
|
||||
+ "The [Lock] sign must be a sign post, not a wall sign.");
|
||||
|
||||
event.getBlock().breakNaturally();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!event.getLine(1).equalsIgnoreCase(player.getName())) {
|
||||
player.sendMessage(ChatColor.RED
|
||||
+ "The first owner line must be your name.");
|
||||
|
||||
event.getBlock().breakNaturally();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
int below = event.getBlock().getRelative(0, -1, 0).getTypeId();
|
||||
|
||||
if (below == BlockID.TNT || below == BlockID.SAND
|
||||
|| below == BlockID.GRAVEL || below == BlockID.SIGN_POST) {
|
||||
player.sendMessage(ChatColor.RED
|
||||
+ "That is not a safe block that you're putting this sign on.");
|
||||
|
||||
event.getBlock().breakNaturally();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
event.setLine(0, "[Lock]");
|
||||
player.sendMessage(ChatColor.YELLOW
|
||||
+ "A chest or double chest above is now protected.");
|
||||
}
|
||||
} else if (!wcfg.disableSignChestProtectionCheck) {
|
||||
if (event.getLine(0).equalsIgnoreCase("[Lock]")) {
|
||||
player.sendMessage(ChatColor.RED
|
||||
+ "WorldGuard's sign chest protection is disabled.");
|
||||
|
||||
event.getBlock().breakNaturally();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!plugin.getGlobalRegionManager().canBuild(player, event.getBlock())) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onLeavesDecay(LeavesDecayEvent event) {
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
|
||||
|
||||
if (cfg.activityHaltToggle) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.disableLeafDecay) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.useRegions) {
|
||||
if (!plugin.getGlobalRegionManager().allows(DefaultFlag.LEAF_DECAY,
|
||||
event.getBlock().getLocation())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Called when a block is formed based on world conditions.
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onBlockForm(BlockFormEvent event) {
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
|
||||
|
||||
if (cfg.activityHaltToggle) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
int type = event.getNewState().getTypeId();
|
||||
|
||||
if (type == BlockID.ICE) {
|
||||
if (wcfg.disableIceFormation) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (wcfg.useRegions && !plugin.getGlobalRegionManager().allows(
|
||||
DefaultFlag.ICE_FORM, event.getBlock().getLocation())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (type == BlockID.SNOW) {
|
||||
if (wcfg.disableSnowFormation) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (wcfg.useRegions && !plugin.getGlobalRegionManager().allows(
|
||||
DefaultFlag.SNOW_FALL, event.getBlock().getLocation())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Called when a block spreads based on world conditions.
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onBlockSpread(BlockSpreadEvent event) {
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
|
||||
|
||||
if (cfg.activityHaltToggle) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
int fromType = event.getSource().getTypeId();
|
||||
|
||||
if (fromType == BlockID.RED_MUSHROOM || fromType == BlockID.BROWN_MUSHROOM) {
|
||||
if (wcfg.disableMushroomSpread) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (wcfg.useRegions && !plugin.getGlobalRegionManager().allows(
|
||||
DefaultFlag.MUSHROOMS, event.getBlock().getLocation())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (fromType == BlockID.GRASS) {
|
||||
if (wcfg.disableGrassGrowth) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (wcfg.useRegions && !plugin.getGlobalRegionManager().allows(
|
||||
DefaultFlag.GRASS_SPREAD, event.getBlock().getLocation())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (fromType == BlockID.MYCELIUM) {
|
||||
if (wcfg.disableMyceliumSpread) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.useRegions
|
||||
&& !plugin.getGlobalRegionManager().allows(
|
||||
DefaultFlag.MYCELIUM_SPREAD, event.getBlock().getLocation())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Called when a block fades.
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onBlockFade(BlockFadeEvent event) {
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
|
||||
|
||||
int type = event.getBlock().getTypeId();
|
||||
|
||||
if (type == BlockID.ICE) {
|
||||
if (wcfg.disableIceMelting) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (wcfg.useRegions && !plugin.getGlobalRegionManager().allows(
|
||||
DefaultFlag.ICE_MELT, event.getBlock().getLocation())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (type == BlockID.SNOW) {
|
||||
if (wcfg.disableSnowMelting) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (wcfg.useRegions && !plugin.getGlobalRegionManager().allows(
|
||||
DefaultFlag.SNOW_MELT, event.getBlock().getLocation())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Called when a piston extends
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
|
||||
|
||||
if (wcfg.useRegions) {
|
||||
if (!plugin.getGlobalRegionManager().allows(DefaultFlag.PISTONS, event.getBlock().getLocation())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
for (Block block : event.getBlocks()) {
|
||||
if (!plugin.getGlobalRegionManager().allows(DefaultFlag.PISTONS, block.getLocation())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Called when a piston retracts
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onBlockPistonRetract(BlockPistonRetractEvent event) {
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
|
||||
|
||||
if (wcfg.useRegions && event.isSticky()) {
|
||||
if (!(plugin.getGlobalRegionManager().allows(DefaultFlag.PISTONS, event.getRetractLocation()))
|
||||
|| !(plugin.getGlobalRegionManager().allows(DefaultFlag.PISTONS, event.getBlock().getLocation()))) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Called when a block is damaged.
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onBlockDispense(BlockDispenseEvent event) {
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
|
||||
|
||||
if (wcfg.blockPotions.size() > 0) {
|
||||
ItemStack item = event.getItem();
|
||||
if (item.getType() == Material.POTION && !BukkitUtil.isWaterPotion(item)) {
|
||||
Potion potion = Potion.fromDamage(BukkitUtil.getPotionEffectBits(item));
|
||||
for (PotionEffect effect : potion.getEffects()) {
|
||||
if (potion.isSplash() && wcfg.blockPotions.contains(effect.getType())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2012 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import com.sk89q.commandbook.InfoComponent;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
/**
|
||||
* @author zml2008
|
||||
*/
|
||||
public class WorldGuardCommandBookListener implements Listener {
|
||||
private final WorldGuardPlugin plugin;
|
||||
|
||||
public WorldGuardCommandBookListener(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerWhois(InfoComponent.PlayerWhoisEvent event) {
|
||||
if (event.getPlayer() instanceof Player) {
|
||||
Player player = (Player) event.getPlayer();
|
||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||
if (plugin.getGlobalStateManager().get(player.getWorld()).useRegions) {
|
||||
ApplicableRegionSet regions = plugin.getGlobalRegionManager()
|
||||
.get(player.getWorld()).getApplicableRegions(player.getLocation());
|
||||
|
||||
// Current regions
|
||||
StringBuilder regionStr = new StringBuilder();
|
||||
boolean first = true;
|
||||
|
||||
for (ProtectedRegion region : regions) {
|
||||
if (!first) {
|
||||
regionStr.append(", ");
|
||||
}
|
||||
|
||||
if (region.isOwner(localPlayer)) {
|
||||
regionStr.append("+");
|
||||
} else if (region.isMemberOnly(localPlayer)) {
|
||||
regionStr.append("-");
|
||||
}
|
||||
|
||||
regionStr.append(region.getId());
|
||||
|
||||
first = false;
|
||||
}
|
||||
|
||||
if (regions.size() > 0) {
|
||||
event.addWhoisInformation("Current Regions", regionStr);
|
||||
}
|
||||
event.addWhoisInformation("Can build", regions.canBuild(localPlayer));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,981 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Creature;
|
||||
import org.bukkit.entity.Creeper;
|
||||
import org.bukkit.entity.EnderDragon;
|
||||
import org.bukkit.entity.EnderPearl;
|
||||
import org.bukkit.entity.Enderman;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Fireball;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.entity.ThrownPotion;
|
||||
import org.bukkit.entity.Wolf;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
|
||||
import org.bukkit.event.entity.CreeperPowerEvent;
|
||||
import org.bukkit.event.entity.EntityBreakDoorEvent;
|
||||
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||
import org.bukkit.event.entity.EntityCombustEvent;
|
||||
import org.bukkit.event.entity.EntityCreatePortalEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByBlockEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.entity.EntityInteractEvent;
|
||||
import org.bukkit.event.entity.EntityRegainHealthEvent;
|
||||
import org.bukkit.event.entity.ExplosionPrimeEvent;
|
||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||
import org.bukkit.event.entity.PigZapEvent;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.entity.PotionSplashEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BlockID;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.blacklist.events.ItemUseBlacklistEvent;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.GlobalRegionManager;
|
||||
import com.sk89q.worldguard.protection.events.DisallowedPVPEvent;
|
||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
|
||||
/**
|
||||
* Listener for entity related events.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class WorldGuardEntityListener implements Listener {
|
||||
|
||||
private WorldGuardPlugin plugin;
|
||||
private EntityType fireballType;
|
||||
private EntityType witherType;
|
||||
private EntityType witherSkullType;
|
||||
|
||||
/**
|
||||
* Construct the object;
|
||||
*
|
||||
* @param plugin The plugin instance
|
||||
*/
|
||||
public WorldGuardEntityListener(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
fireballType = BukkitUtil.tryEnum(EntityType.class, "LARGE_FIREBALL", "FIREBALL");
|
||||
witherType = BukkitUtil.tryEnum(EntityType.class, "WITHER");
|
||||
witherSkullType = BukkitUtil.tryEnum(EntityType.class, "WITHER_SKULL");
|
||||
}
|
||||
|
||||
/**
|
||||
* Register events.
|
||||
*/
|
||||
public void registerEvents() {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onEntityInteract(EntityInteractEvent event) {
|
||||
Entity entity = event.getEntity();
|
||||
Block block = event.getBlock();
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(entity.getWorld());
|
||||
|
||||
if (block.getTypeId() == BlockID.SOIL) {
|
||||
if (entity instanceof Creature && wcfg.disableCreatureCropTrampling) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onEntityDeath(EntityDeathEvent event) {
|
||||
WorldConfiguration wcfg = plugin.getGlobalStateManager().get(event.getEntity().getWorld());
|
||||
|
||||
if (wcfg.disableExpDrops || !plugin.getGlobalRegionManager().allows(DefaultFlag.EXP_DROPS,
|
||||
event.getEntity().getLocation())) {
|
||||
event.setDroppedExp(0);
|
||||
}
|
||||
|
||||
if (event instanceof PlayerDeathEvent && wcfg.disableDeathMessages) {
|
||||
((PlayerDeathEvent) event).setDeathMessage("");
|
||||
}
|
||||
}
|
||||
|
||||
private void onEntityDamageByBlock(EntityDamageByBlockEvent event) {
|
||||
Entity defender = event.getEntity();
|
||||
DamageCause type = event.getCause();
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(defender.getWorld());
|
||||
|
||||
if (defender instanceof Wolf && ((Wolf) defender).isTamed()) {
|
||||
if (wcfg.antiWolfDumbness && !(type == DamageCause.VOID)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
} else if (defender instanceof Player) {
|
||||
Player player = (Player) defender;
|
||||
|
||||
if (isInvincible(player)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.disableLavaDamage && type == DamageCause.LAVA) {
|
||||
event.setCancelled(true);
|
||||
player.setFireTicks(0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.disableContactDamage && type == DamageCause.CONTACT) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.teleportOnVoid && type == DamageCause.VOID) {
|
||||
BukkitUtil.findFreePosition(player);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.disableVoidDamage && type == DamageCause.VOID) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.disableExplosionDamage && type == DamageCause.BLOCK_EXPLOSION) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
||||
|
||||
if (event.getDamager() instanceof Projectile) {
|
||||
onEntityDamageByProjectile(event);
|
||||
return;
|
||||
}
|
||||
|
||||
Entity attacker = event.getDamager();
|
||||
Entity defender = event.getEntity();
|
||||
|
||||
if (attacker instanceof Player) {
|
||||
Player player = (Player) attacker;
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(player.getWorld());
|
||||
|
||||
ItemStack held = player.getInventory().getItemInHand();
|
||||
|
||||
if (held != null) {
|
||||
if (wcfg.getBlacklist() != null) {
|
||||
if (!wcfg.getBlacklist().check(
|
||||
new ItemUseBlacklistEvent(plugin.wrapPlayer(player),
|
||||
toVector(player.getLocation()), held.getTypeId()), false, false)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (defender instanceof Player) {
|
||||
Player player = (Player) defender;
|
||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(player.getWorld());
|
||||
|
||||
if (isInvincible(player)) {
|
||||
if (wcfg.regionInvinciblityRemovesMobs
|
||||
&& attacker instanceof LivingEntity && !(attacker instanceof Player)
|
||||
&& !(attacker instanceof Tameable && ((Tameable) attacker).isTamed())) {
|
||||
attacker.remove();
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.disableLightningDamage && event.getCause() == DamageCause.LIGHTNING) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.disableExplosionDamage) {
|
||||
switch (event.getCause()) {
|
||||
case BLOCK_EXPLOSION:
|
||||
case ENTITY_EXPLOSION:
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (attacker != null) {
|
||||
if (attacker instanceof Player) {
|
||||
if (wcfg.useRegions) {
|
||||
Vector pt = toVector(defender.getLocation());
|
||||
Vector pt2 = toVector(attacker.getLocation());
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld());
|
||||
|
||||
if (!mgr.getApplicableRegions(pt2).allows(DefaultFlag.PVP, plugin.wrapPlayer((Player) attacker))) {
|
||||
tryCancelPVPEvent((Player) attacker, player, event, true);
|
||||
} else if (!mgr.getApplicableRegions(pt).allows(DefaultFlag.PVP ,localPlayer)) {
|
||||
tryCancelPVPEvent((Player) attacker, player, event, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (attacker instanceof TNTPrimed) {
|
||||
|
||||
// The check for explosion damage should be handled already... But... What ever...
|
||||
if (wcfg.blockTNTExplosions) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (wcfg.useRegions) {
|
||||
Vector pt = toVector(defender.getLocation());
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld());
|
||||
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
|
||||
if (!set.allows(DefaultFlag.TNT, localPlayer)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (attacker instanceof Fireball) {
|
||||
if (wcfg.blockFireballExplosions) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (wcfg.useRegions) {
|
||||
Fireball fireball = (Fireball) attacker;
|
||||
Vector pt = toVector(defender.getLocation());
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld());
|
||||
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
|
||||
if (fireball.getShooter() instanceof Player) {
|
||||
Vector pt2 = toVector(fireball.getShooter().getLocation());
|
||||
if (!mgr.getApplicableRegions(pt2).allows(DefaultFlag.PVP, plugin.wrapPlayer((Player) fireball.getShooter()))) {
|
||||
tryCancelPVPEvent((Player) fireball.getShooter(), player, event, true);
|
||||
} else if (!set.allows(DefaultFlag.PVP, localPlayer)) {
|
||||
tryCancelPVPEvent((Player) fireball.getShooter(), player, event, false);
|
||||
}
|
||||
} else {
|
||||
if (!set.allows(DefaultFlag.GHAST_FIREBALL, localPlayer)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (attacker instanceof LivingEntity && !(attacker instanceof Player)) {
|
||||
if (attacker instanceof Creeper && wcfg.blockCreeperExplosions) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.disableMobDamage) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.useRegions) {
|
||||
Vector pt = toVector(defender.getLocation());
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld());
|
||||
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
|
||||
|
||||
if (!set.allows(DefaultFlag.MOB_DAMAGE, localPlayer)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (attacker instanceof Creeper) {
|
||||
if (!set.allows(DefaultFlag.CREEPER_EXPLOSION, localPlayer)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void onEntityDamageByProjectile(EntityDamageByEntityEvent event) {
|
||||
Entity defender = event.getEntity();
|
||||
Entity attacker = ((Projectile) event.getDamager()).getShooter();
|
||||
|
||||
if (defender instanceof Player) {
|
||||
Player player = (Player) defender;
|
||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(player.getWorld());
|
||||
|
||||
// Check Invincible
|
||||
if (isInvincible(player)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check Mob
|
||||
if (attacker != null && attacker instanceof LivingEntity && !(attacker instanceof Player)) {
|
||||
if (wcfg.disableMobDamage) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (wcfg.useRegions) {
|
||||
Vector pt = toVector(defender.getLocation());
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld());
|
||||
|
||||
if (!mgr.getApplicableRegions(pt).allows(DefaultFlag.MOB_DAMAGE, localPlayer)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check Player
|
||||
// if (event.getDamager() instanceof EnderPearl || event.getDamager() instanceof Snowball) return;
|
||||
if (attacker != null && attacker instanceof Player) {
|
||||
if (event.getDamager() instanceof EnderPearl && attacker == player) return;
|
||||
if (wcfg.useRegions) {
|
||||
Vector pt = toVector(defender.getLocation());
|
||||
Vector pt2 = toVector(attacker.getLocation());
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld());
|
||||
|
||||
if (!mgr.getApplicableRegions(pt2).allows(DefaultFlag.PVP, plugin.wrapPlayer((Player) attacker))) {
|
||||
tryCancelPVPEvent((Player) attacker, player, event, true);
|
||||
} else if (!mgr.getApplicableRegions(pt).allows(DefaultFlag.PVP, localPlayer)) {
|
||||
tryCancelPVPEvent((Player) attacker, player, event, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onEntityDamage(EntityDamageEvent event) {
|
||||
|
||||
if (event instanceof EntityDamageByEntityEvent) {
|
||||
this.onEntityDamageByEntity((EntityDamageByEntityEvent) event);
|
||||
return;
|
||||
} else if (event instanceof EntityDamageByBlockEvent) {
|
||||
this.onEntityDamageByBlock((EntityDamageByBlockEvent) event);
|
||||
return;
|
||||
}
|
||||
|
||||
Entity defender = event.getEntity();
|
||||
DamageCause type = event.getCause();
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(defender.getWorld());
|
||||
|
||||
if (defender instanceof Wolf && ((Wolf) defender).isTamed()) {
|
||||
if (wcfg.antiWolfDumbness) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
} else if (defender instanceof Player) {
|
||||
Player player = (Player) defender;
|
||||
|
||||
if (isInvincible(player)) {
|
||||
event.setCancelled(true);
|
||||
player.setFireTicks(0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (type == DamageCause.WITHER) {
|
||||
// wither boss DoT tick
|
||||
if (wcfg.disableMobDamage) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.useRegions) {
|
||||
Vector pt = toVector(defender.getLocation());
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld());
|
||||
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
|
||||
|
||||
if (!set.allows(DefaultFlag.MOB_DAMAGE, plugin.wrapPlayer(player))) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (type == DamageCause.DROWNING && cfg.hasAmphibiousMode(player)) {
|
||||
player.setRemainingAir(player.getMaximumAir());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack helmet = player.getInventory().getHelmet();
|
||||
|
||||
if (type == DamageCause.DROWNING && wcfg.pumpkinScuba
|
||||
&& helmet != null
|
||||
&& (helmet.getTypeId() == BlockID.PUMPKIN
|
||||
|| helmet.getTypeId() == BlockID.JACKOLANTERN)) {
|
||||
player.setRemainingAir(player.getMaximumAir());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.disableFallDamage && type == DamageCause.FALL) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.disableFireDamage && (type == DamageCause.FIRE
|
||||
|| type == DamageCause.FIRE_TICK)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.disableDrowningDamage && type == DamageCause.DROWNING) {
|
||||
player.setRemainingAir(player.getMaximumAir());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.teleportOnSuffocation && type == DamageCause.SUFFOCATION) {
|
||||
BukkitUtil.findFreePosition(player);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.disableSuffocationDamage && type == DamageCause.SUFFOCATION) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onEntityCombust(EntityCombustEvent event) {
|
||||
Entity entity = event.getEntity();
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(entity.getWorld());
|
||||
|
||||
if (entity instanceof Player) {
|
||||
Player player = (Player) entity;
|
||||
|
||||
if (cfg.hasGodMode(player) || (wcfg.useRegions && RegionQueryUtil.isInvincible(plugin, player))) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Called on entity explode.
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onEntityExplode(EntityExplodeEvent event) {
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
Location l = event.getLocation();
|
||||
World world = l.getWorld();
|
||||
WorldConfiguration wcfg = cfg.get(world);
|
||||
Entity ent = event.getEntity();
|
||||
|
||||
if (cfg.activityHaltToggle) {
|
||||
if (ent != null) {
|
||||
ent.remove();
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Not all explosions come from an entity
|
||||
if (ent != null) {
|
||||
if (ent.getType() == witherType) {
|
||||
if (wcfg.blockWitherBlockDamage) {
|
||||
event.blockList().clear();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.blockWitherExplosions) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (ent.getType() == witherSkullType) {
|
||||
if (wcfg.blockWitherSkullBlockDamage) {
|
||||
event.blockList().clear();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.blockWitherSkullExplosions) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (ent instanceof Creeper) {
|
||||
if (wcfg.blockCreeperBlockDamage) {
|
||||
event.blockList().clear();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.blockCreeperExplosions) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.useRegions) {
|
||||
if (wcfg.useRegions) {
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||
|
||||
for (Block block : event.blockList()) {
|
||||
if (!mgr.getApplicableRegions(toVector(block)).allows(DefaultFlag.CREEPER_EXPLOSION)) {
|
||||
event.blockList().clear();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (ent instanceof EnderDragon) {
|
||||
if (wcfg.blockEnderDragonBlockDamage) {
|
||||
event.blockList().clear();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.useRegions) {
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||
|
||||
for (Block block : event.blockList()) {
|
||||
if (!mgr.getApplicableRegions(toVector(block)).allows(DefaultFlag.ENDERDRAGON_BLOCK_DAMAGE)) {
|
||||
event.blockList().clear();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (ent instanceof TNTPrimed) {
|
||||
if (wcfg.blockTNTBlockDamage) {
|
||||
event.blockList().clear();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.blockTNTExplosions) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.useRegions) {
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||
|
||||
for (Block block : event.blockList()) {
|
||||
if (!mgr.getApplicableRegions(toVector(block)).allows(DefaultFlag.TNT)) {
|
||||
event.blockList().clear();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (ent instanceof Fireball) {
|
||||
if (wcfg.blockFireballBlockDamage) {
|
||||
event.blockList().clear();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.blockFireballExplosions) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.useRegions) {
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||
|
||||
for (Block block : event.blockList()) {
|
||||
if (!mgr.getApplicableRegions(toVector(block)).allows(DefaultFlag.GHAST_FIREBALL)) {
|
||||
event.blockList().clear();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// null entity, caused by another plugin or so
|
||||
if (wcfg.blockOtherExplosions) {
|
||||
event.blockList().clear();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (wcfg.useRegions) {
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||
for (Block block : event.blockList()) {
|
||||
if (!mgr.getApplicableRegions(toVector(block)).allows(DefaultFlag.OTHER_EXPLOSION)) {
|
||||
event.blockList().clear();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (wcfg.signChestProtection) {
|
||||
for (Block block : event.blockList()) {
|
||||
if (wcfg.isChestProtected(block)) {
|
||||
event.blockList().clear();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Called on explosion prime
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onExplosionPrime(ExplosionPrimeEvent event) {
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(event.getEntity().getWorld());
|
||||
Entity ent = event.getEntity();
|
||||
|
||||
if (cfg.activityHaltToggle) {
|
||||
ent.remove();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getEntityType() == witherType) {
|
||||
if (wcfg.blockWitherExplosions) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (event.getEntityType() == witherSkullType) {
|
||||
if (wcfg.blockWitherSkullExplosions) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (event.getEntityType() == fireballType) {
|
||||
if (wcfg.blockFireballExplosions) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (event.getEntityType() == EntityType.CREEPER) {
|
||||
if (wcfg.blockCreeperExplosions) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (event.getEntityType() == EntityType.PRIMED_TNT) {
|
||||
if (wcfg.blockTNTExplosions) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onCreatureSpawn(CreatureSpawnEvent event) {
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
|
||||
if (cfg.activityHaltToggle) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
WorldConfiguration wcfg = cfg.get(event.getEntity().getWorld());
|
||||
|
||||
// allow spawning of creatures from plugins
|
||||
if (!wcfg.blockPluginSpawning && event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.CUSTOM)
|
||||
return;
|
||||
|
||||
EntityType entityType = event.getEntityType();
|
||||
|
||||
if (wcfg.blockCreatureSpawn.contains(entityType)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
Location eventLoc = event.getLocation();
|
||||
|
||||
if (wcfg.useRegions && cfg.useRegionsCreatureSpawnEvent) {
|
||||
Vector pt = toVector(eventLoc);
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(eventLoc.getWorld());
|
||||
// @TODO get victims' stacktraces and find out why it's null anyway
|
||||
if (mgr == null) return;
|
||||
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
|
||||
|
||||
if (!set.allows(DefaultFlag.MOB_SPAWNING)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
Set<EntityType> entityTypes = set.getFlag(DefaultFlag.DENY_SPAWN);
|
||||
if (entityTypes != null && entityTypes.contains(entityType)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (wcfg.blockGroundSlimes && entityType == EntityType.SLIME
|
||||
&& eventLoc.getY() >= 60
|
||||
&& event.getSpawnReason() == SpawnReason.NATURAL) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onCreatePortal(EntityCreatePortalEvent event) {
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(event.getEntity().getWorld());
|
||||
|
||||
switch (event.getEntityType()) {
|
||||
case ENDER_DRAGON:
|
||||
if (wcfg.blockEnderDragonBlockDamage) event.setCancelled(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onPigZap(PigZapEvent event) {
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(event.getEntity().getWorld());
|
||||
|
||||
if (wcfg.disablePigZap) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onCreeperPower(CreeperPowerEvent event) {
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(event.getEntity().getWorld());
|
||||
|
||||
if (wcfg.disableCreeperPower) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onEntityRegainHealth(EntityRegainHealthEvent event) {
|
||||
|
||||
Entity ent = event.getEntity();
|
||||
World world = ent.getWorld();
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(world);
|
||||
|
||||
if (wcfg.disableHealthRegain) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when an entity changes a block somehow
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onEndermanPickup(EntityChangeBlockEvent event) {
|
||||
Entity ent = event.getEntity();
|
||||
Block block = event.getBlock();
|
||||
Location location = block.getLocation();
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(ent.getWorld());
|
||||
if (ent instanceof Enderman) {
|
||||
if (event.getTo() == Material.AIR) {
|
||||
// pickup
|
||||
|
||||
if (wcfg.disableEndermanGriefing) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.useRegions) {
|
||||
if (!plugin.getGlobalRegionManager().allows(DefaultFlag.ENDER_BUILD, location)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// place
|
||||
|
||||
if (wcfg.disableEndermanGriefing) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.useRegions) {
|
||||
if (!plugin.getGlobalRegionManager().allows(DefaultFlag.ENDER_BUILD, location)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (ent.getType() == witherType) {
|
||||
|
||||
if (wcfg.blockWitherBlockDamage || wcfg.blockWitherExplosions) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
} else if (/*ent instanceof Zombie && */event instanceof EntityBreakDoorEvent) {
|
||||
if (wcfg.blockZombieDoorDestruction) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onFoodLevelChange(FoodLevelChangeEvent event) {
|
||||
if (event.getEntity() instanceof Player) {
|
||||
Player player = (Player) event.getEntity();
|
||||
if (event.getFoodLevel() < player.getFoodLevel() && isInvincible(player)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPotionSplash(PotionSplashEvent event) {
|
||||
Entity entity = event.getEntity();
|
||||
ThrownPotion potion = event.getPotion();
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(entity.getWorld());
|
||||
|
||||
if (wcfg.blockPotionsAlways && wcfg.blockPotions.size() > 0) {
|
||||
boolean blocked = false;
|
||||
|
||||
for (PotionEffect effect : potion.getEffects()) {
|
||||
if (wcfg.blockPotions.contains(effect.getType())) {
|
||||
blocked = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (blocked) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
GlobalRegionManager regionMan = plugin.getGlobalRegionManager();
|
||||
|
||||
int blockedEntities = 0;
|
||||
for (LivingEntity e : event.getAffectedEntities()) {
|
||||
if (!regionMan.allows(DefaultFlag.POTION_SPLASH, e.getLocation(),
|
||||
e instanceof Player ? plugin.wrapPlayer((Player) e) : null)) {
|
||||
event.setIntensity(e, 0);
|
||||
++blockedEntities;
|
||||
}
|
||||
}
|
||||
|
||||
if (blockedEntities == event.getAffectedEntities().size()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a player is invincible, via either god mode or region flag. If
|
||||
* the region denies invincibility, the player must have an extra permission
|
||||
* to override it. (worldguard.god.override-regions)
|
||||
*
|
||||
* @param player The player to check
|
||||
* @return Whether {@code player} is invincible
|
||||
*/
|
||||
private boolean isInvincible(Player player) {
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(player.getWorld());
|
||||
|
||||
boolean god = cfg.hasGodMode(player);
|
||||
if (wcfg.useRegions) {
|
||||
Boolean flag = RegionQueryUtil.isAllowedInvinciblity(plugin, player);
|
||||
boolean allowed = flag == null || flag;
|
||||
boolean invincible = RegionQueryUtil.isInvincible(plugin, player);
|
||||
|
||||
if (allowed) {
|
||||
return god || invincible;
|
||||
} else {
|
||||
return (god && plugin.hasPermission(player, "worldguard.god.override-regions"))
|
||||
|| invincible;
|
||||
}
|
||||
} else {
|
||||
return god;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Using a DisallowedPVPEvent, notifies other plugins that WorldGuard
|
||||
* wants to cancel a PvP damage event.<br />
|
||||
* If this event is not cancelled, the attacking player is notified that
|
||||
* PvP is disabled and WorldGuard cancels the damage event.
|
||||
*
|
||||
* @param attackingPlayer The attacker
|
||||
* @param defendingPlayer The defender
|
||||
* @param event The event that caused WorldGuard to act
|
||||
*/
|
||||
public void tryCancelPVPEvent(final Player attackingPlayer, final Player defendingPlayer, EntityDamageByEntityEvent event, boolean aggressorTriggered) {
|
||||
final DisallowedPVPEvent disallowedPVPEvent = new DisallowedPVPEvent(attackingPlayer, defendingPlayer, event);
|
||||
plugin.getServer().getPluginManager().callEvent(disallowedPVPEvent);
|
||||
if (!disallowedPVPEvent.isCancelled()) {
|
||||
if (aggressorTriggered) attackingPlayer.sendMessage(ChatColor.DARK_RED + "You are in a no-PvP area.");
|
||||
else attackingPlayer.sendMessage(ChatColor.DARK_RED + "That player is in a no-PvP area.");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Creeper;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Hanging;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.entity.Painting;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
|
||||
import org.bukkit.event.hanging.HangingBreakEvent;
|
||||
import org.bukkit.event.hanging.HangingBreakEvent.RemoveCause;
|
||||
import org.bukkit.event.hanging.HangingPlaceEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
|
||||
import com.sk89q.worldedit.blocks.ItemID;
|
||||
import com.sk89q.worldguard.blacklist.events.BlockBreakBlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.events.ItemUseBlacklistEvent;
|
||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||
|
||||
/**
|
||||
* Listener for painting related events.
|
||||
*
|
||||
* @author BangL <henno.rickowski@gmail.com>
|
||||
*/
|
||||
public class WorldGuardHangingListener implements Listener {
|
||||
|
||||
private WorldGuardPlugin plugin;
|
||||
|
||||
/**
|
||||
* Construct the object;
|
||||
*
|
||||
* @param plugin The plugin instance
|
||||
*/
|
||||
public WorldGuardHangingListener(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register events.
|
||||
*/
|
||||
public void registerEvents() {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onHangingingBreak(HangingBreakEvent event) {
|
||||
Hanging hanging = event.getEntity();
|
||||
World world = hanging.getWorld();
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(world);
|
||||
|
||||
if (event instanceof HangingBreakByEntityEvent) {
|
||||
HangingBreakByEntityEvent entityEvent = (HangingBreakByEntityEvent) event;
|
||||
Entity removerEntity = entityEvent.getRemover();
|
||||
|
||||
if (removerEntity instanceof Player) {
|
||||
Player player = (Player) removerEntity;
|
||||
|
||||
if (wcfg.getBlacklist() != null) {
|
||||
if (hanging instanceof Painting
|
||||
&& !wcfg.getBlacklist().check(
|
||||
new BlockBreakBlacklistEvent(plugin.wrapPlayer(player),
|
||||
toVector(player.getLocation()), ItemID.PAINTING), false, false)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
} else if (hanging instanceof ItemFrame
|
||||
&& !wcfg.getBlacklist().check(
|
||||
new BlockBreakBlacklistEvent(plugin.wrapPlayer(player),
|
||||
toVector(player.getLocation()), ItemID.ITEM_FRAME), false, false)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (wcfg.useRegions) {
|
||||
if (!plugin.getGlobalRegionManager().canBuild(player, hanging.getLocation())) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (removerEntity instanceof Creeper) {
|
||||
if (wcfg.blockCreeperBlockDamage || wcfg.blockCreeperExplosions) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (wcfg.useRegions && !plugin.getGlobalRegionManager().allows(DefaultFlag.CREEPER_EXPLOSION, hanging.getLocation())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (hanging instanceof Painting
|
||||
&& (wcfg.blockEntityPaintingDestroy
|
||||
|| (wcfg.useRegions
|
||||
&& !plugin.getGlobalRegionManager().allows(DefaultFlag.ENTITY_PAINTING_DESTROY, hanging.getLocation())))) {
|
||||
event.setCancelled(true);
|
||||
} else if (hanging instanceof ItemFrame
|
||||
&& (wcfg.blockEntityItemFrameDestroy
|
||||
|| (wcfg.useRegions
|
||||
&& !plugin.getGlobalRegionManager().allows(DefaultFlag.ENTITY_ITEM_FRAME_DESTROY, hanging.getLocation())))) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Explosions from mobs are not covered by HangingBreakByEntity
|
||||
if (hanging instanceof Painting && wcfg.blockEntityPaintingDestroy
|
||||
&& event.getCause() == RemoveCause.EXPLOSION) {
|
||||
event.setCancelled(true);
|
||||
} else if (hanging instanceof ItemFrame && wcfg.blockEntityItemFrameDestroy
|
||||
&& event.getCause() == RemoveCause.EXPLOSION) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onHangingPlace(HangingPlaceEvent event) {
|
||||
Block placedOn = event.getBlock();
|
||||
Player player = event.getPlayer();
|
||||
World world = placedOn.getWorld();
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(world);
|
||||
|
||||
if (wcfg.getBlacklist() != null) {
|
||||
|
||||
if (event.getEntity() instanceof Painting
|
||||
&& !wcfg.getBlacklist().check(
|
||||
new ItemUseBlacklistEvent(plugin.wrapPlayer(player),
|
||||
toVector(player.getLocation()), ItemID.PAINTING), false, false)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
} else if (event.getEntity() instanceof ItemFrame
|
||||
&& !wcfg.getBlacklist().check(
|
||||
new ItemUseBlacklistEvent(plugin.wrapPlayer(player),
|
||||
toVector(player.getLocation()), ItemID.ITEM_FRAME), false, false)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (wcfg.useRegions) {
|
||||
if (!plugin.getGlobalRegionManager().canBuild(player, placedOn.getLocation())) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onEntityInteract(PlayerInteractEntityEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Entity entity = event.getRightClicked();
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(entity.getWorld());
|
||||
|
||||
if (wcfg.useRegions && (entity instanceof ItemFrame || entity instanceof Painting)) {
|
||||
if (!plugin.getGlobalRegionManager().canBuild(player, entity.getLocation())) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// if (entity instanceof ItemFrame
|
||||
// && ((!plugin.getGlobalRegionManager().allows(
|
||||
// DefaultFlag.ENTITY_ITEM_FRAME_DESTROY, entity.getLocation())))) {
|
||||
// event.setCancelled(true);
|
||||
// } else if (entity instanceof Painting
|
||||
// && ((!plugin.getGlobalRegionManager().allows(
|
||||
// DefaultFlag.ENTITY_PAINTING_DESTROY, entity.getLocation())))) {
|
||||
// event.setCancelled(true);
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Warning;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Creeper;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Painting;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.painting.PaintingBreakByEntityEvent;
|
||||
import org.bukkit.event.painting.PaintingBreakEvent;
|
||||
import org.bukkit.event.painting.PaintingPlaceEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
|
||||
import com.sk89q.worldedit.blocks.ItemID;
|
||||
import com.sk89q.worldguard.blacklist.events.BlockBreakBlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.events.ItemUseBlacklistEvent;
|
||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||
|
||||
/**
|
||||
* Listener for painting related events.
|
||||
*
|
||||
* @author sk89q
|
||||
* @deprecated Use {@link com.sk89q.worldguard.bukkit.WorldGuardHangingListener} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@Warning(reason="This listener has been replaced by WorldGuardHangingListener")
|
||||
public class WorldGuardPaintingListener implements Listener {
|
||||
|
||||
private WorldGuardPlugin plugin;
|
||||
|
||||
/**
|
||||
* Construct the object;
|
||||
*
|
||||
* @param plugin The plugin instance
|
||||
*/
|
||||
public WorldGuardPaintingListener(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register events.
|
||||
*/
|
||||
public void registerEvents() {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onPaintingBreak(PaintingBreakEvent breakEvent) {
|
||||
if (!(breakEvent instanceof PaintingBreakByEntityEvent)) {
|
||||
return;
|
||||
}
|
||||
|
||||
PaintingBreakByEntityEvent event = (PaintingBreakByEntityEvent) breakEvent;
|
||||
Painting painting = event.getPainting();
|
||||
World world = painting.getWorld();
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(world);
|
||||
|
||||
if (event.getRemover() instanceof Player) {
|
||||
Player player = (Player) event.getRemover();
|
||||
|
||||
if (wcfg.getBlacklist() != null) {
|
||||
if (!wcfg.getBlacklist().check(
|
||||
new BlockBreakBlacklistEvent(plugin.wrapPlayer(player),
|
||||
toVector(player.getLocation()), ItemID.PAINTING), false, false)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (wcfg.useRegions) {
|
||||
if (!plugin.getGlobalRegionManager().canBuild(player, painting.getLocation())) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (event.getRemover() instanceof Creeper) {
|
||||
if (wcfg.blockCreeperBlockDamage || wcfg.blockCreeperExplosions) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (wcfg.useRegions && !plugin.getGlobalRegionManager().allows(DefaultFlag.CREEPER_EXPLOSION, painting.getLocation())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (wcfg.blockEntityPaintingDestroy
|
||||
|| (wcfg.useRegions
|
||||
&& !plugin.getGlobalRegionManager().allows(DefaultFlag.ENTITY_PAINTING_DESTROY, painting.getLocation()))) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onPaintingPlace(PaintingPlaceEvent event) {
|
||||
Block placedOn = event.getBlock();
|
||||
Player player = event.getPlayer();
|
||||
World world = placedOn.getWorld();
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(world);
|
||||
|
||||
if (wcfg.getBlacklist() != null) {
|
||||
|
||||
if (!wcfg.getBlacklist().check(
|
||||
new ItemUseBlacklistEvent(plugin.wrapPlayer(player),
|
||||
toVector(player.getLocation()), ItemID.PAINTING), false, false)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (wcfg.useRegions) {
|
||||
if (!plugin.getGlobalRegionManager().canBuild(player, placedOn.getLocation())) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onEntityInteract(PlayerInteractEntityEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Entity entity = event.getRightClicked();
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(entity.getWorld());
|
||||
|
||||
if (wcfg.useRegions && entity instanceof Painting) {
|
||||
if (!plugin.getGlobalRegionManager().canBuild(player, entity.getLocation())) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (entity instanceof Painting
|
||||
&& ((!plugin.getGlobalRegionManager().allows(
|
||||
DefaultFlag.ENTITY_PAINTING_DESTROY, entity.getLocation())))) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,861 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.hasHangingEvent;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.zip.ZipEntry;
|
||||
|
||||
import com.sk89q.bukkit.util.CommandsManagerRegistration;
|
||||
import com.sk89q.minecraft.util.commands.*;
|
||||
import com.sk89q.wepif.PermissionsResolverManager;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permissible;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.bukkit.commands.GeneralCommands;
|
||||
import com.sk89q.worldguard.bukkit.commands.ProtectionCommands;
|
||||
import com.sk89q.worldguard.bukkit.commands.ToggleCommands;
|
||||
import com.sk89q.worldguard.protection.GlobalRegionManager;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import com.sk89q.worldguard.util.FatalConfigurationLoadingException;
|
||||
|
||||
/**
|
||||
* The main class for WorldGuard as a Bukkit plugin.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class WorldGuardPlugin extends JavaPlugin {
|
||||
|
||||
/**
|
||||
* Manager for commands. This automatically handles nested commands,
|
||||
* permissions checking, and a number of other fancy command things.
|
||||
* We just set it up and register commands against it.
|
||||
*/
|
||||
private final CommandsManager<CommandSender> commands;
|
||||
|
||||
/**
|
||||
* Handles the region databases for all worlds.
|
||||
*/
|
||||
private final GlobalRegionManager globalRegionManager;
|
||||
|
||||
/**
|
||||
* Handles all configuration.
|
||||
*/
|
||||
private final ConfigurationManager configuration;
|
||||
|
||||
/**
|
||||
* Used for scheduling flags.
|
||||
*/
|
||||
private FlagStateManager flagStateManager;
|
||||
|
||||
/**
|
||||
* Construct objects. Actual loading occurs when the plugin is enabled, so
|
||||
* this merely instantiates the objects.
|
||||
*/
|
||||
public WorldGuardPlugin() {
|
||||
configuration = new ConfigurationManager(this);
|
||||
globalRegionManager = new GlobalRegionManager(this);
|
||||
|
||||
final WorldGuardPlugin plugin = this;
|
||||
commands = new CommandsManager<CommandSender>() {
|
||||
@Override
|
||||
public boolean hasPermission(CommandSender player, String perm) {
|
||||
return plugin.hasPermission(player, perm);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on plugin enable.
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public void onEnable() {
|
||||
|
||||
// Set the proper command injector
|
||||
commands.setInjector(new SimpleInjector(this));
|
||||
|
||||
// Register command classes
|
||||
final CommandsManagerRegistration reg = new CommandsManagerRegistration(this, commands);
|
||||
reg.register(ToggleCommands.class);
|
||||
reg.register(ProtectionCommands.class);
|
||||
|
||||
getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!getGlobalStateManager().hasCommandBookGodMode()) {
|
||||
reg.register(GeneralCommands.class);
|
||||
}
|
||||
}
|
||||
}, 0L);
|
||||
|
||||
// Need to create the plugins/WorldGuard folder
|
||||
getDataFolder().mkdirs();
|
||||
|
||||
PermissionsResolverManager.initialize(this);
|
||||
|
||||
// This must be done before configuration is loaded
|
||||
LegacyWorldGuardMigration.migrateBlacklist(this);
|
||||
|
||||
try {
|
||||
// Load the configuration
|
||||
configuration.load();
|
||||
globalRegionManager.preload();
|
||||
} catch (FatalConfigurationLoadingException e) {
|
||||
e.printStackTrace();
|
||||
getServer().shutdown();
|
||||
}
|
||||
|
||||
// Migrate regions after the regions were loaded because
|
||||
// the migration code reuses the loaded region managers
|
||||
LegacyWorldGuardMigration.migrateRegions(this);
|
||||
|
||||
flagStateManager = new FlagStateManager(this);
|
||||
|
||||
if (configuration.useRegionsScheduler) {
|
||||
getServer().getScheduler().scheduleSyncRepeatingTask(this, flagStateManager,
|
||||
FlagStateManager.RUN_DELAY, FlagStateManager.RUN_DELAY);
|
||||
}
|
||||
|
||||
// Register events
|
||||
(new WorldGuardPlayerListener(this)).registerEvents();
|
||||
(new WorldGuardBlockListener(this)).registerEvents();
|
||||
(new WorldGuardEntityListener(this)).registerEvents();
|
||||
(new WorldGuardWeatherListener(this)).registerEvents();
|
||||
(new WorldGuardVehicleListener(this)).registerEvents();
|
||||
(new WorldGuardServerListener(this)).registerEvents();
|
||||
if (hasHangingEvent()) {
|
||||
(new WorldGuardHangingListener(this)).registerEvents();
|
||||
} else {
|
||||
(new WorldGuardPaintingListener(this)).registerEvents();
|
||||
}
|
||||
configuration.updateCommandBookGodMode();
|
||||
|
||||
if (getServer().getPluginManager().isPluginEnabled("CommandBook")) {
|
||||
getServer().getPluginManager().registerEvents(new WorldGuardCommandBookListener(this), this);
|
||||
}
|
||||
|
||||
// handle worlds separately to initialize already loaded worlds
|
||||
WorldGuardWorldListener worldListener = (new WorldGuardWorldListener(this));
|
||||
for (World world : getServer().getWorlds()) {
|
||||
worldListener.initWorld(world);
|
||||
}
|
||||
worldListener.registerEvents();
|
||||
|
||||
if (!configuration.hasCommandBookGodMode()) {
|
||||
// Check god mode for existing players, if any
|
||||
for (Player player : getServer().getOnlinePlayers()) {
|
||||
if (inGroup(player, "wg-invincible") ||
|
||||
(configuration.autoGodMode && hasPermission(player, "worldguard.auto-invincible"))) {
|
||||
configuration.enableGodMode(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on plugin disable.
|
||||
*/
|
||||
@Override
|
||||
public void onDisable() {
|
||||
globalRegionManager.unload();
|
||||
configuration.unload();
|
||||
this.getServer().getScheduler().cancelTasks(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a command.
|
||||
*/
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label,
|
||||
String[] args) {
|
||||
try {
|
||||
commands.execute(cmd.getName(), args, sender, sender);
|
||||
} catch (CommandPermissionsException e) {
|
||||
sender.sendMessage(ChatColor.RED + "You don't have permission.");
|
||||
} catch (MissingNestedCommandException e) {
|
||||
sender.sendMessage(ChatColor.RED + e.getUsage());
|
||||
} catch (CommandUsageException e) {
|
||||
sender.sendMessage(ChatColor.RED + e.getMessage());
|
||||
sender.sendMessage(ChatColor.RED + e.getUsage());
|
||||
} catch (WrappedCommandException e) {
|
||||
if (e.getCause() instanceof NumberFormatException) {
|
||||
sender.sendMessage(ChatColor.RED + "Number expected, string received instead.");
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "An error has occurred. See console.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (CommandException e) {
|
||||
sender.sendMessage(ChatColor.RED + e.getMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the GlobalRegionManager.
|
||||
*
|
||||
* @return The plugin's global region manager
|
||||
*/
|
||||
public GlobalRegionManager getGlobalRegionManager() {
|
||||
return globalRegionManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the WorldGuard Configuration.
|
||||
*
|
||||
* @return ConfigurationManager
|
||||
* @deprecated Use {@link #getGlobalStateManager()} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public ConfigurationManager getGlobalConfiguration() {
|
||||
return getGlobalStateManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the flag state manager.
|
||||
*
|
||||
* @return The flag state manager
|
||||
*/
|
||||
public FlagStateManager getFlagStateManager() {
|
||||
return flagStateManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the global ConfigurationManager.
|
||||
* USe this to access global configuration values and per-world configuration values.
|
||||
* @return The global ConfigurationManager
|
||||
*/
|
||||
public ConfigurationManager getGlobalStateManager() {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a player is in a group.
|
||||
* This calls the corresponding method in PermissionsResolverManager
|
||||
*
|
||||
* @param player The player to check
|
||||
* @param group The group
|
||||
* @return whether {@code player} is in {@code group}
|
||||
*/
|
||||
public boolean inGroup(Player player, String group) {
|
||||
try {
|
||||
return PermissionsResolverManager.getInstance().inGroup(player, group);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the groups of a player.
|
||||
* This calls the corresponding method in PermissionsResolverManager.
|
||||
* @param player The player to check
|
||||
* @return The names of each group the playe is in.
|
||||
*/
|
||||
public String[] getGroups(Player player) {
|
||||
try {
|
||||
return PermissionsResolverManager.getInstance().getGroups(player);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
return new String[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of a command sender. This is a unique name and this
|
||||
* method should never return a "display name".
|
||||
*
|
||||
* @param sender The sender to get the name of
|
||||
* @return The unique name of the sender.
|
||||
*/
|
||||
public String toUniqueName(CommandSender sender) {
|
||||
if (sender instanceof ConsoleCommandSender) {
|
||||
return "*Console*";
|
||||
} else {
|
||||
return sender.getName();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of a command sender. This play be a display name.
|
||||
*
|
||||
* @param sender The CommandSender to get the name of.
|
||||
* @return The name of the given sender
|
||||
*/
|
||||
public String toName(CommandSender sender) {
|
||||
if (sender instanceof ConsoleCommandSender) {
|
||||
return "*Console*";
|
||||
} else if (sender instanceof Player) {
|
||||
return ((Player) sender).getDisplayName();
|
||||
} else {
|
||||
return sender.getName();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks permissions.
|
||||
*
|
||||
* @param sender The sender to check the permission on.
|
||||
* @param perm The permission to check the permission on.
|
||||
* @return whether {@code sender} has {@code perm}
|
||||
*/
|
||||
public boolean hasPermission(CommandSender sender, String perm) {
|
||||
if (sender.isOp()) {
|
||||
if (sender instanceof Player) {
|
||||
if (this.getGlobalStateManager().get(((Player) sender).
|
||||
getWorld()).opPermissions) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Invoke the permissions resolver
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
return PermissionsResolverManager.getInstance().hasPermission(player.getWorld().getName(), player.getName(), perm);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks permissions and throws an exception if permission is not met.
|
||||
*
|
||||
* @param sender The sender to check the permission on.
|
||||
* @param perm The permission to check the permission on.
|
||||
* @throws CommandPermissionsException if {@code sender} doesn't have {@code perm}
|
||||
*/
|
||||
public void checkPermission(CommandSender sender, String perm)
|
||||
throws CommandPermissionsException {
|
||||
if (!hasPermission(sender, perm)) {
|
||||
throw new CommandPermissionsException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if the sender is a player, otherwise throw an exception.
|
||||
*
|
||||
* @param sender The {@link CommandSender} to check
|
||||
* @return {@code sender} casted to a player
|
||||
* @throws CommandException if {@code sender} isn't a {@link Player}
|
||||
*/
|
||||
public Player checkPlayer(CommandSender sender)
|
||||
throws CommandException {
|
||||
if (sender instanceof Player) {
|
||||
return (Player) sender;
|
||||
} else {
|
||||
throw new CommandException("A player is expected.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Match player names.
|
||||
*
|
||||
* The filter string uses the following format:
|
||||
* @[name] looks up all players with the exact {@code name}
|
||||
* *[name] matches any player whose name contains {@code name}
|
||||
* [name] matches any player whose name starts with {@code name}
|
||||
*
|
||||
* @param filter The filter string to check.
|
||||
* @return A {@link List} of players who match {@code filter}
|
||||
*/
|
||||
public List<Player> matchPlayerNames(String filter) {
|
||||
Player[] players = getServer().getOnlinePlayers();
|
||||
|
||||
filter = filter.toLowerCase();
|
||||
|
||||
// Allow exact name matching
|
||||
if (filter.charAt(0) == '@' && filter.length() >= 2) {
|
||||
filter = filter.substring(1);
|
||||
|
||||
for (Player player : players) {
|
||||
if (player.getName().equalsIgnoreCase(filter)) {
|
||||
List<Player> list = new ArrayList<Player>();
|
||||
list.add(player);
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
return new ArrayList<Player>();
|
||||
// Allow partial name matching
|
||||
} else if (filter.charAt(0) == '*' && filter.length() >= 2) {
|
||||
filter = filter.substring(1);
|
||||
|
||||
List<Player> list = new ArrayList<Player>();
|
||||
|
||||
for (Player player : players) {
|
||||
if (player.getName().toLowerCase().contains(filter)) {
|
||||
list.add(player);
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
|
||||
// Start with name matching
|
||||
} else {
|
||||
List<Player> list = new ArrayList<Player>();
|
||||
|
||||
for (Player player : players) {
|
||||
if (player.getName().toLowerCase().startsWith(filter)) {
|
||||
list.add(player);
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given list of players is greater than size 0, otherwise
|
||||
* throw an exception.
|
||||
*
|
||||
* @param players The {@link List} to check
|
||||
* @return {@code players} as an {@link Iterable}
|
||||
* @throws CommandException If {@code players} is empty
|
||||
*/
|
||||
protected Iterable<Player> checkPlayerMatch(List<Player> players)
|
||||
throws CommandException {
|
||||
// Check to see if there were any matches
|
||||
if (players.size() == 0) {
|
||||
throw new CommandException("No players matched query.");
|
||||
}
|
||||
|
||||
return players;
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches players based on the specified filter string
|
||||
*
|
||||
* The filter string format is as follows:
|
||||
* * returns all the players currently online
|
||||
* If {@code sender} is a {@link Player}:
|
||||
* #world returns all players in the world that {@code sender} is in
|
||||
* #near reaturns all players within 30 blocks of {@code sender}'s location
|
||||
* Otherwise, the format is as specified in {@link #matchPlayerNames(String)}
|
||||
*
|
||||
* @param source The CommandSender who is trying to find a player
|
||||
* @param filter The filter string for players
|
||||
* @return iterator for players
|
||||
* @throws CommandException if no matches are found
|
||||
*/
|
||||
public Iterable<Player> matchPlayers(CommandSender source, String filter)
|
||||
throws CommandException {
|
||||
|
||||
if (getServer().getOnlinePlayers().length == 0) {
|
||||
throw new CommandException("No players matched query.");
|
||||
}
|
||||
|
||||
if (filter.equals("*")) {
|
||||
return checkPlayerMatch(Arrays.asList(getServer().getOnlinePlayers()));
|
||||
}
|
||||
|
||||
// Handle special hash tag groups
|
||||
if (filter.charAt(0) == '#') {
|
||||
// Handle #world, which matches player of the same world as the
|
||||
// calling source
|
||||
if (filter.equalsIgnoreCase("#world")) {
|
||||
List<Player> players = new ArrayList<Player>();
|
||||
Player sourcePlayer = checkPlayer(source);
|
||||
World sourceWorld = sourcePlayer.getWorld();
|
||||
|
||||
for (Player player : getServer().getOnlinePlayers()) {
|
||||
if (player.getWorld().equals(sourceWorld)) {
|
||||
players.add(player);
|
||||
}
|
||||
}
|
||||
|
||||
return checkPlayerMatch(players);
|
||||
|
||||
// Handle #near, which is for nearby players.
|
||||
} else if (filter.equalsIgnoreCase("#near")) {
|
||||
List<Player> players = new ArrayList<Player>();
|
||||
Player sourcePlayer = checkPlayer(source);
|
||||
World sourceWorld = sourcePlayer.getWorld();
|
||||
org.bukkit.util.Vector sourceVector
|
||||
= sourcePlayer.getLocation().toVector();
|
||||
|
||||
for (Player player : getServer().getOnlinePlayers()) {
|
||||
if (player.getWorld().equals(sourceWorld)
|
||||
&& player.getLocation().toVector().distanceSquared(
|
||||
sourceVector) < 900) {
|
||||
players.add(player);
|
||||
}
|
||||
}
|
||||
|
||||
return checkPlayerMatch(players);
|
||||
|
||||
} else {
|
||||
throw new CommandException("Invalid group '" + filter + "'.");
|
||||
}
|
||||
}
|
||||
|
||||
List<Player> players = matchPlayerNames(filter);
|
||||
|
||||
return checkPlayerMatch(players);
|
||||
}
|
||||
|
||||
/**
|
||||
* Match only a single player.
|
||||
*
|
||||
* @param sender The {@link CommandSender} who is requesting a player match
|
||||
* @param filter The filter string.
|
||||
* @see #matchPlayers(org.bukkit.entity.Player) for filter string syntax
|
||||
* @return The single player
|
||||
* @throws CommandException If more than one player match was found
|
||||
*/
|
||||
public Player matchSinglePlayer(CommandSender sender, String filter)
|
||||
throws CommandException {
|
||||
// This will throw an exception if there are no matches
|
||||
Iterator<Player> players = matchPlayers(sender, filter).iterator();
|
||||
|
||||
Player match = players.next();
|
||||
|
||||
// We don't want to match the wrong person, so fail if if multiple
|
||||
// players were found (we don't want to just pick off the first one,
|
||||
// as that may be the wrong player)
|
||||
if (players.hasNext()) {
|
||||
throw new CommandException("More than one player found! " +
|
||||
"Use @<name> for exact matching.");
|
||||
}
|
||||
|
||||
return match;
|
||||
}
|
||||
|
||||
/**
|
||||
* Match only a single player or console.
|
||||
*
|
||||
* The filter string syntax is as follows:
|
||||
* #console, *console, or ! return the server console
|
||||
* All syntax from {@link #matchSinglePlayer(org.bukkit.command.CommandSender, String)}
|
||||
* @param sender The sender trying to match a CommandSender
|
||||
* @param filter The filter string
|
||||
* @return The resulting CommandSender
|
||||
* @throws CommandException if either zero or more than one player matched.
|
||||
*/
|
||||
public CommandSender matchPlayerOrConsole(CommandSender sender, String filter)
|
||||
throws CommandException {
|
||||
|
||||
// Let's see if console is wanted
|
||||
if (filter.equalsIgnoreCase("#console")
|
||||
|| filter.equalsIgnoreCase("*console*")
|
||||
|| filter.equalsIgnoreCase("!")) {
|
||||
return getServer().getConsoleSender();
|
||||
}
|
||||
|
||||
return matchSinglePlayer(sender, filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single player as an iterator for players.
|
||||
*
|
||||
* @param player The player to return in an Iterable
|
||||
* @return iterator for player
|
||||
*/
|
||||
public Iterable<Player> matchPlayers(Player player) {
|
||||
return Arrays.asList(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Match a world.
|
||||
*
|
||||
* The filter string syntax is as follows:
|
||||
* #main returns the main world
|
||||
* #normal returns the first world with a normal environment
|
||||
* #nether return the first world with a nether environment
|
||||
* #player:[name] returns the world that a player named {@code name} is located in, if the player is online.
|
||||
* [name] A world with the name {@code name}
|
||||
*
|
||||
* @param sender The sender requesting a match
|
||||
* @param filter The filter string
|
||||
* @return The resulting world
|
||||
* @throws CommandException if no world matches
|
||||
*/
|
||||
public World matchWorld(CommandSender sender, String filter) throws CommandException {
|
||||
List<World> worlds = getServer().getWorlds();
|
||||
|
||||
// Handle special hash tag groups
|
||||
if (filter.charAt(0) == '#') {
|
||||
// #main for the main world
|
||||
if (filter.equalsIgnoreCase("#main")) {
|
||||
return worlds.get(0);
|
||||
|
||||
// #normal for the first normal world
|
||||
} else if (filter.equalsIgnoreCase("#normal")) {
|
||||
for (World world : worlds) {
|
||||
if (world.getEnvironment() == Environment.NORMAL) {
|
||||
return world;
|
||||
}
|
||||
}
|
||||
|
||||
throw new CommandException("No normal world found.");
|
||||
|
||||
// #nether for the first nether world
|
||||
} else if (filter.equalsIgnoreCase("#nether")) {
|
||||
for (World world : worlds) {
|
||||
if (world.getEnvironment() == Environment.NETHER) {
|
||||
return world;
|
||||
}
|
||||
}
|
||||
|
||||
throw new CommandException("No nether world found.");
|
||||
|
||||
// Handle getting a world from a player
|
||||
} else if (filter.matches("^#player$")) {
|
||||
String parts[] = filter.split(":", 2);
|
||||
|
||||
// They didn't specify an argument for the player!
|
||||
if (parts.length == 1) {
|
||||
throw new CommandException("Argument expected for #player.");
|
||||
}
|
||||
|
||||
return matchPlayers(sender, parts[1]).iterator().next().getWorld();
|
||||
} else {
|
||||
throw new CommandException("Invalid identifier '" + filter + "'.");
|
||||
}
|
||||
}
|
||||
|
||||
for (World world : worlds) {
|
||||
if (world.getName().equals(filter)) {
|
||||
return world;
|
||||
}
|
||||
}
|
||||
|
||||
throw new CommandException("No world by that exact name found.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a copy of the WorldEdit plugin.
|
||||
*
|
||||
* @return The WorldEditPlugin instance
|
||||
* @throws CommandException If there is no WorldEditPlugin available
|
||||
*/
|
||||
public WorldEditPlugin getWorldEdit() throws CommandException {
|
||||
Plugin worldEdit = getServer().getPluginManager().getPlugin("WorldEdit");
|
||||
if (worldEdit == null) {
|
||||
throw new CommandException("WorldEdit does not appear to be installed.");
|
||||
}
|
||||
|
||||
if (worldEdit instanceof WorldEditPlugin) {
|
||||
return (WorldEditPlugin) worldEdit;
|
||||
} else {
|
||||
throw new CommandException("WorldEdit detection failed (report error).");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap a player as a LocalPlayer.
|
||||
*
|
||||
* @param player The player to wrap
|
||||
* @return The wrapped player
|
||||
*/
|
||||
public LocalPlayer wrapPlayer(Player player) {
|
||||
return new BukkitPlayer(this, player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a default configuration file from the .jar.
|
||||
*
|
||||
* @param actual The destination file
|
||||
* @param defaultName The name of the file inside the jar's defaults folder
|
||||
*/
|
||||
public void createDefaultConfiguration(File actual,
|
||||
String defaultName) {
|
||||
|
||||
// Make parent directories
|
||||
File parent = actual.getParentFile();
|
||||
if (!parent.exists()) {
|
||||
parent.mkdirs();
|
||||
}
|
||||
|
||||
if (actual.exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
InputStream input =
|
||||
null;
|
||||
try {
|
||||
JarFile file = new JarFile(getFile());
|
||||
ZipEntry copy = file.getEntry("defaults/" + defaultName);
|
||||
if (copy == null) throw new FileNotFoundException();
|
||||
input = file.getInputStream(copy);
|
||||
} catch (IOException e) {
|
||||
getLogger().severe("Unable to read default configuration: " + defaultName);
|
||||
}
|
||||
|
||||
if (input != null) {
|
||||
FileOutputStream output = null;
|
||||
|
||||
try {
|
||||
output = new FileOutputStream(actual);
|
||||
byte[] buf = new byte[8192];
|
||||
int length = 0;
|
||||
while ((length = input.read(buf)) > 0) {
|
||||
output.write(buf, 0, length);
|
||||
}
|
||||
|
||||
getLogger().info("Default configuration file written: "
|
||||
+ actual.getAbsolutePath());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (input != null) {
|
||||
input.close();
|
||||
}
|
||||
} catch (IOException ignore) {
|
||||
}
|
||||
|
||||
try {
|
||||
if (output != null) {
|
||||
output.close();
|
||||
}
|
||||
} catch (IOException ignore) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies all with the worldguard.notify permission.
|
||||
* This will check both superperms and WEPIF,
|
||||
* but makes sure WEPIF checks don't result in duplicate notifications
|
||||
*
|
||||
* @param msg The notification to broadcast
|
||||
*/
|
||||
public void broadcastNotification(String msg) {
|
||||
getServer().broadcast(msg, "worldguard.notify");
|
||||
Set<Permissible> subs = getServer().getPluginManager().getPermissionSubscriptions("worldguard.notify");
|
||||
for (Player player : getServer().getOnlinePlayers()) {
|
||||
if (!(subs.contains(player) && player.hasPermission("worldguard.notify")) &&
|
||||
hasPermission(player, "worldguard.notify")) { // Make sure the player wasn't already broadcasted to.
|
||||
player.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
getLogger().info(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forgets a player.
|
||||
*
|
||||
* @param player The player to remove state information for
|
||||
*/
|
||||
public void forgetPlayer(Player player) {
|
||||
flagStateManager.forget(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if a player can build at a location. This will return
|
||||
* true if region protection is disabled.
|
||||
*
|
||||
* @param player The player to check.
|
||||
* @param loc The location to check at.
|
||||
* @see GlobalRegionManager#canBuild(org.bukkit.entity.Player, org.bukkit.Location)
|
||||
* @return whether {@code player} can build at {@code loc}
|
||||
*/
|
||||
public boolean canBuild(Player player, Location loc) {
|
||||
return getGlobalRegionManager().canBuild(player, loc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if a player can build at a location. This will return
|
||||
* true if region protection is disabled.
|
||||
*
|
||||
* @param player The player to check
|
||||
* @param block The block to check at.
|
||||
* @see GlobalRegionManager#canBuild(org.bukkit.entity.Player, org.bukkit.block.Block)
|
||||
* @return whether {@code player} can build at {@code block}'s location
|
||||
*/
|
||||
public boolean canBuild(Player player, Block block) {
|
||||
return getGlobalRegionManager().canBuild(player, block);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the region manager for a world.
|
||||
*
|
||||
* @param world world to get the region manager for
|
||||
* @return the region manager or null if regions are not enabled
|
||||
*/
|
||||
public RegionManager getRegionManager(World world) {
|
||||
if (!getGlobalStateManager().get(world).useRegions) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return getGlobalRegionManager().get(world);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace macros in the text.
|
||||
*
|
||||
* The macros replaced are as follows:
|
||||
* %name%: The name of {@code sender}. See {@link #toName(org.bukkit.command.CommandSender)}
|
||||
* %id%: The unique name of the sender. See {@link #toUniqueName(org.bukkit.command.CommandSender)}
|
||||
* %online%: The number of players currently online on the server
|
||||
* If {@code sender} is a Player:
|
||||
* %world%: The name of the world {@code sender} is located in
|
||||
* %health%: The health of {@code sender}. See {@link org.bukkit.entity.Player#getHealth()}
|
||||
*
|
||||
* @param sender The sender to check
|
||||
* @param message The message to replace macros in
|
||||
* @return The message with macros replaced
|
||||
*/
|
||||
public String replaceMacros(CommandSender sender, String message) {
|
||||
Player[] online = getServer().getOnlinePlayers();
|
||||
|
||||
message = message.replace("%name%", toName(sender));
|
||||
message = message.replace("%id%", toUniqueName(sender));
|
||||
message = message.replace("%online%", String.valueOf(online.length));
|
||||
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
World world = player.getWorld();
|
||||
|
||||
message = message.replace("%world%", world.getName());
|
||||
message = message.replace("%health%", String.valueOf(player.getHealth()));
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.PluginDisableEvent;
|
||||
import org.bukkit.event.server.PluginEnableEvent;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
/**
|
||||
* @author zml2008
|
||||
*/
|
||||
public class WorldGuardServerListener implements Listener {
|
||||
|
||||
private final WorldGuardPlugin plugin;
|
||||
|
||||
public WorldGuardServerListener(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void registerEvents() {
|
||||
PluginManager pm = plugin.getServer().getPluginManager();
|
||||
pm.registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPluginEnable(PluginEnableEvent event) {
|
||||
if (event.getPlugin().getDescription().getName().equalsIgnoreCase("CommandBook")) {
|
||||
plugin.getGlobalStateManager().updateCommandBookGodMode();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPluginDisable(PluginDisableEvent event) {
|
||||
if (event.getPlugin().getDescription().getName().equalsIgnoreCase("CommandBook")) {
|
||||
plugin.getGlobalStateManager().updateCommandBookGodMode();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
// $Id$
|
||||
/*
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
* All rights reserved.
|
||||
*/
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Vehicle;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.vehicle.VehicleDestroyEvent;
|
||||
import org.bukkit.event.vehicle.VehicleMoveEvent;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.bukkit.FlagStateManager.PlayerFlagState;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
public class WorldGuardVehicleListener implements Listener {
|
||||
|
||||
private WorldGuardPlugin plugin;
|
||||
|
||||
/**
|
||||
* Construct the object;
|
||||
*
|
||||
* @param plugin
|
||||
*/
|
||||
public WorldGuardVehicleListener(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register events.
|
||||
*/
|
||||
public void registerEvents() {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onVehicleDestroy(VehicleDestroyEvent event) {
|
||||
Vehicle vehicle = event.getVehicle();
|
||||
Entity destroyer = event.getAttacker();
|
||||
|
||||
if (!(destroyer instanceof Player)) return; // don't care
|
||||
Player player = (Player) destroyer;
|
||||
World world = vehicle.getWorld();
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(world);
|
||||
|
||||
if (wcfg.useRegions) {
|
||||
Vector pt = toVector(vehicle.getLocation());
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
|
||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||
|
||||
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
|
||||
&& !set.canBuild(localPlayer)
|
||||
&& !set.allows(DefaultFlag.DESTROY_VEHICLE, localPlayer)) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You don't have permission to destroy vehicles here.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onVehicleMove(VehicleMoveEvent event) {
|
||||
Vehicle vehicle = event.getVehicle();
|
||||
if (vehicle.getPassenger() == null
|
||||
|| !(vehicle.getPassenger() instanceof Player)) return;
|
||||
Player player = (Player) vehicle.getPassenger();
|
||||
World world = vehicle.getWorld();
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(world);
|
||||
|
||||
// unfortunate code duplication
|
||||
if (wcfg.useRegions) {
|
||||
// Did we move a block?
|
||||
if (event.getFrom().getBlockX() != event.getTo().getBlockX()
|
||||
|| event.getFrom().getBlockY() != event.getTo().getBlockY()
|
||||
|| event.getFrom().getBlockZ() != event.getTo().getBlockZ()) {
|
||||
PlayerFlagState state = plugin.getFlagStateManager().getState(player);
|
||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||
boolean hasBypass = plugin.getGlobalRegionManager().hasBypass(player, world);
|
||||
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||
Vector pt = new Vector(event.getTo().getBlockX(), event.getTo().getBlockY(), event.getTo().getBlockZ());
|
||||
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
|
||||
|
||||
boolean entryAllowed = set.allows(DefaultFlag.ENTRY, localPlayer);
|
||||
if (!hasBypass && !entryAllowed) {
|
||||
|
||||
vehicle.setVelocity(new org.bukkit.util.Vector(0,0,0));
|
||||
vehicle.teleport(event.getFrom());
|
||||
return;
|
||||
}
|
||||
|
||||
// Have to set this state
|
||||
if (state.lastExitAllowed == null) {
|
||||
state.lastExitAllowed = mgr.getApplicableRegions(toVector(event.getFrom()))
|
||||
.allows(DefaultFlag.EXIT, localPlayer);
|
||||
}
|
||||
|
||||
boolean exitAllowed = set.allows(DefaultFlag.EXIT, localPlayer);
|
||||
if (!hasBypass && exitAllowed && !state.lastExitAllowed) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You are not permitted to leave this area.");
|
||||
|
||||
vehicle.setVelocity(new org.bukkit.util.Vector(0,0,0));
|
||||
vehicle.teleport(event.getFrom());
|
||||
return;
|
||||
}
|
||||
|
||||
String greeting = set.getFlag(DefaultFlag.GREET_MESSAGE, localPlayer);
|
||||
String farewell = set.getFlag(DefaultFlag.FAREWELL_MESSAGE, localPlayer);
|
||||
Boolean notifyEnter = set.getFlag(DefaultFlag.NOTIFY_ENTER, localPlayer);
|
||||
Boolean notifyLeave = set.getFlag(DefaultFlag.NOTIFY_LEAVE, localPlayer);
|
||||
|
||||
if (state.lastFarewell != null && (farewell == null
|
||||
|| !state.lastFarewell.equals(farewell))) {
|
||||
String replacedFarewell = plugin.replaceMacros(
|
||||
player, BukkitUtil.replaceColorMacros(state.lastFarewell));
|
||||
player.sendMessage(ChatColor.AQUA + " ** " + replacedFarewell);
|
||||
}
|
||||
|
||||
if (greeting != null && (state.lastGreeting == null
|
||||
|| !state.lastGreeting.equals(greeting))) {
|
||||
String replacedGreeting = plugin.replaceMacros(
|
||||
player, BukkitUtil.replaceColorMacros(greeting));
|
||||
player.sendMessage(ChatColor.AQUA + " ** " + replacedGreeting);
|
||||
}
|
||||
|
||||
if ((notifyLeave == null || !notifyLeave)
|
||||
&& state.notifiedForLeave != null && state.notifiedForLeave) {
|
||||
plugin.broadcastNotification(ChatColor.GRAY + "WG: "
|
||||
+ ChatColor.LIGHT_PURPLE + player.getName()
|
||||
+ ChatColor.GOLD + " left NOTIFY region");
|
||||
}
|
||||
|
||||
if (notifyEnter != null && notifyEnter && (state.notifiedForEnter == null
|
||||
|| !state.notifiedForEnter)) {
|
||||
StringBuilder regionList = new StringBuilder();
|
||||
|
||||
for (ProtectedRegion region : set) {
|
||||
if (regionList.length() != 0) {
|
||||
regionList.append(", ");
|
||||
}
|
||||
regionList.append(region.getId());
|
||||
}
|
||||
|
||||
plugin.broadcastNotification(ChatColor.GRAY + "WG: "
|
||||
+ ChatColor.LIGHT_PURPLE + player.getName()
|
||||
+ ChatColor.GOLD + " entered NOTIFY region: "
|
||||
+ ChatColor.WHITE
|
||||
+ regionList);
|
||||
}
|
||||
|
||||
state.lastGreeting = greeting;
|
||||
state.lastFarewell = farewell;
|
||||
state.notifiedForEnter = notifyEnter;
|
||||
state.notifiedForLeave = notifyLeave;
|
||||
state.lastExitAllowed = exitAllowed;
|
||||
state.lastWorld = event.getTo().getWorld();
|
||||
state.lastBlockX = event.getTo().getBlockX();
|
||||
state.lastBlockY = event.getTo().getBlockY();
|
||||
state.lastBlockZ = event.getTo().getBlockZ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.weather.LightningStrikeEvent;
|
||||
import org.bukkit.event.weather.ThunderChangeEvent;
|
||||
import org.bukkit.event.weather.WeatherChangeEvent;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
|
||||
public class WorldGuardWeatherListener implements Listener {
|
||||
|
||||
/**
|
||||
* Plugin.
|
||||
*/
|
||||
private WorldGuardPlugin plugin;
|
||||
|
||||
/**
|
||||
* Construct the object;
|
||||
*
|
||||
* @param plugin The plugin instance
|
||||
*/
|
||||
public WorldGuardWeatherListener(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void registerEvents() {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onWeatherChange(WeatherChangeEvent event) {
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(event.getWorld());
|
||||
|
||||
if (event.toWeatherState()) {
|
||||
if (wcfg.disableWeather) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else {
|
||||
if (!wcfg.disableWeather && wcfg.alwaysRaining) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onThunderChange(ThunderChangeEvent event) {
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(event.getWorld());
|
||||
|
||||
if (event.toThunderState()) {
|
||||
if (wcfg.disableThunder) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else {
|
||||
if (!wcfg.disableWeather && wcfg.alwaysThundering) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onLightningStrike(LightningStrikeEvent event) {
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(event.getWorld());
|
||||
|
||||
if (wcfg.disallowedLightningBlocks.size() > 0) {
|
||||
int targetId = event.getLightning().getLocation().getBlock().getTypeId();
|
||||
if (wcfg.disallowedLightningBlocks.contains(targetId)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
Location loc = event.getLightning().getLocation();
|
||||
if (wcfg.useRegions) {
|
||||
Vector pt = toVector(loc);
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(loc.getWorld());
|
||||
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
|
||||
|
||||
if (!set.allows(DefaultFlag.LIGHTNING)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
// $Id$
|
||||
/*
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
* All rights reserved.
|
||||
*/
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.world.ChunkLoadEvent;
|
||||
import org.bukkit.event.world.WorldLoadEvent;
|
||||
|
||||
public class WorldGuardWorldListener implements Listener {
|
||||
|
||||
private WorldGuardPlugin plugin;
|
||||
|
||||
/**
|
||||
* Construct the object;
|
||||
*
|
||||
* @param plugin The plugin instance
|
||||
*/
|
||||
public WorldGuardWorldListener(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register events.
|
||||
*/
|
||||
public void registerEvents() {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onChunkLoad(ChunkLoadEvent event) {
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
|
||||
if (cfg.activityHaltToggle) {
|
||||
int removed = 0;
|
||||
|
||||
for (Entity entity : event.getChunk().getEntities()) {
|
||||
if (BukkitUtil.isIntensiveEntity(entity)) {
|
||||
entity.remove();
|
||||
removed++;
|
||||
}
|
||||
}
|
||||
|
||||
if (removed > 50) {
|
||||
plugin.getLogger().info("Halt-Act: " + removed + " entities (>50) auto-removed from "
|
||||
+ event.getChunk().toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onWorldLoad(WorldLoadEvent event) {
|
||||
initWorld(event.getWorld());
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the settings for the specified world
|
||||
* @see WorldConfiguration#alwaysRaining
|
||||
* @see WorldConfiguration#disableWeather
|
||||
* @see WorldConfiguration#alwaysThundering
|
||||
* @see WorldConfiguration#disableThunder
|
||||
* @param world The specified world
|
||||
*/
|
||||
public void initWorld(World world) {
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(world);
|
||||
if (wcfg.alwaysRaining && !wcfg.disableWeather) {
|
||||
world.setStorm(true);
|
||||
} else if (wcfg.disableWeather && !wcfg.alwaysRaining) {
|
||||
world.setStorm(false);
|
||||
}
|
||||
if (wcfg.alwaysThundering && !wcfg.disableThunder) {
|
||||
world.setThundering(true);
|
||||
} else if (wcfg.disableThunder && !wcfg.alwaysThundering) {
|
||||
world.setStorm(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,303 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.bukkit.commands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.worldedit.blocks.ItemType;
|
||||
import com.sk89q.worldguard.bukkit.ConfigurationManager;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
|
||||
public class GeneralCommands {
|
||||
private final WorldGuardPlugin plugin;
|
||||
|
||||
public GeneralCommands(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Command(aliases = {"god"}, usage = "[player]",
|
||||
desc = "Enable godmode on a player", flags = "s", max = 1)
|
||||
public void god(CommandContext args, CommandSender sender) throws CommandException {
|
||||
ConfigurationManager config = plugin.getGlobalStateManager();
|
||||
|
||||
Iterable<Player> targets = null;
|
||||
boolean included = false;
|
||||
|
||||
// Detect arguments based on the number of arguments provided
|
||||
if (args.argsLength() == 0) {
|
||||
targets = plugin.matchPlayers(plugin.checkPlayer(sender));
|
||||
|
||||
// Check permissions!
|
||||
plugin.checkPermission(sender, "worldguard.god");
|
||||
} else if (args.argsLength() == 1) {
|
||||
targets = plugin.matchPlayers(sender, args.getString(0));
|
||||
|
||||
// Check permissions!
|
||||
plugin.checkPermission(sender, "worldguard.god.other");
|
||||
}
|
||||
|
||||
for (Player player : targets) {
|
||||
config.enableGodMode(player);
|
||||
player.setFireTicks(0);
|
||||
|
||||
// Tell the user
|
||||
if (player.equals(sender)) {
|
||||
player.sendMessage(ChatColor.YELLOW + "God mode enabled! Use /ungod to disable.");
|
||||
|
||||
// Keep track of this
|
||||
included = true;
|
||||
} else {
|
||||
player.sendMessage(ChatColor.YELLOW + "God enabled by "
|
||||
+ plugin.toName(sender) + ".");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// The player didn't receive any items, then we need to send the
|
||||
// user a message so s/he know that something is indeed working
|
||||
if (!included && args.hasFlag('s')) {
|
||||
sender.sendMessage(ChatColor.YELLOW.toString() + "Players now have god mode.");
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Command(aliases = {"ungod"}, usage = "[player]",
|
||||
desc = "Disable godmode on a player", flags = "s", max = 1)
|
||||
public void ungod(CommandContext args, CommandSender sender) throws CommandException {
|
||||
ConfigurationManager config = plugin.getGlobalStateManager();
|
||||
|
||||
Iterable<Player> targets = null;
|
||||
boolean included = false;
|
||||
|
||||
// Detect arguments based on the number of arguments provided
|
||||
if (args.argsLength() == 0) {
|
||||
targets = plugin.matchPlayers(plugin.checkPlayer(sender));
|
||||
|
||||
// Check permissions!
|
||||
plugin.checkPermission(sender, "worldguard.god");
|
||||
} else if (args.argsLength() == 1) {
|
||||
targets = plugin.matchPlayers(sender, args.getString(0));
|
||||
|
||||
// Check permissions!
|
||||
plugin.checkPermission(sender, "worldguard.god.other");
|
||||
}
|
||||
|
||||
for (Player player : targets) {
|
||||
config.disableGodMode(player);
|
||||
|
||||
// Tell the user
|
||||
if (player.equals(sender)) {
|
||||
player.sendMessage(ChatColor.YELLOW + "God mode disabled!");
|
||||
|
||||
// Keep track of this
|
||||
included = true;
|
||||
} else {
|
||||
player.sendMessage(ChatColor.YELLOW + "God disabled by "
|
||||
+ plugin.toName(sender) + ".");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// The player didn't receive any items, then we need to send the
|
||||
// user a message so s/he know that something is indeed working
|
||||
if (!included && args.hasFlag('s')) {
|
||||
sender.sendMessage(ChatColor.YELLOW.toString() + "Players no longer have god mode.");
|
||||
}
|
||||
}
|
||||
|
||||
@Command(aliases = {"heal"}, usage = "[player]", desc = "Heal a player", flags = "s", max = 1)
|
||||
public void heal(CommandContext args,CommandSender sender) throws CommandException {
|
||||
|
||||
Iterable<Player> targets = null;
|
||||
boolean included = false;
|
||||
|
||||
// Detect arguments based on the number of arguments provided
|
||||
if (args.argsLength() == 0) {
|
||||
targets = plugin.matchPlayers(plugin.checkPlayer(sender));
|
||||
|
||||
// Check permissions!
|
||||
plugin.checkPermission(sender, "worldguard.heal");
|
||||
} else if (args.argsLength() == 1) {
|
||||
targets = plugin.matchPlayers(sender, args.getString(0));
|
||||
|
||||
// Check permissions!
|
||||
plugin.checkPermission(sender, "worldguard.heal.other");
|
||||
}
|
||||
|
||||
for (Player player : targets) {
|
||||
player.setHealth(20);
|
||||
player.setFoodLevel(20);
|
||||
|
||||
// Tell the user
|
||||
if (player.equals(sender)) {
|
||||
player.sendMessage(ChatColor.YELLOW + "Healed!");
|
||||
|
||||
// Keep track of this
|
||||
included = true;
|
||||
} else {
|
||||
player.sendMessage(ChatColor.YELLOW + "Healed by "
|
||||
+ plugin.toName(sender) + ".");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// The player didn't receive any items, then we need to send the
|
||||
// user a message so s/he know that something is indeed working
|
||||
if (!included && args.hasFlag('s')) {
|
||||
sender.sendMessage(ChatColor.YELLOW.toString() + "Players healed.");
|
||||
}
|
||||
}
|
||||
|
||||
@Command(aliases = {"slay"}, usage = "[player]", desc = "Slay a player", flags = "s", max = 1)
|
||||
public void slay(CommandContext args, CommandSender sender) throws CommandException {
|
||||
|
||||
Iterable<Player> targets = null;
|
||||
boolean included = false;
|
||||
|
||||
// Detect arguments based on the number of arguments provided
|
||||
if (args.argsLength() == 0) {
|
||||
targets = plugin.matchPlayers(plugin.checkPlayer(sender));
|
||||
|
||||
// Check permissions!
|
||||
plugin.checkPermission(sender, "worldguard.slay");
|
||||
} else if (args.argsLength() == 1) {
|
||||
targets = plugin.matchPlayers(sender, args.getString(0));
|
||||
|
||||
// Check permissions!
|
||||
plugin.checkPermission(sender, "worldguard.slay.other");
|
||||
}
|
||||
|
||||
for (Player player : targets) {
|
||||
player.setHealth(0);
|
||||
|
||||
// Tell the user
|
||||
if (player.equals(sender)) {
|
||||
player.sendMessage(ChatColor.YELLOW + "Slain!");
|
||||
|
||||
// Keep track of this
|
||||
included = true;
|
||||
} else {
|
||||
player.sendMessage(ChatColor.YELLOW + "Slain by "
|
||||
+ plugin.toName(sender) + ".");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// The player didn't receive any items, then we need to send the
|
||||
// user a message so s/he know that something is indeed working
|
||||
if (!included && args.hasFlag('s')) {
|
||||
sender.sendMessage(ChatColor.YELLOW.toString() + "Players slain.");
|
||||
}
|
||||
}
|
||||
|
||||
@Command(aliases = {"locate"}, usage = "[player]", desc = "Locate a player", max = 1)
|
||||
@CommandPermissions({"worldguard.locate"})
|
||||
public void locate(CommandContext args, CommandSender sender) throws CommandException {
|
||||
|
||||
Player player = plugin.checkPlayer(sender);
|
||||
|
||||
if (args.argsLength() == 0) {
|
||||
player.setCompassTarget(player.getWorld().getSpawnLocation());
|
||||
|
||||
sender.sendMessage(ChatColor.YELLOW.toString() + "Compass reset to spawn.");
|
||||
} else {
|
||||
Player target = plugin.matchSinglePlayer(sender, args.getString(0));
|
||||
player.setCompassTarget(target.getLocation());
|
||||
|
||||
sender.sendMessage(ChatColor.YELLOW.toString() + "Compass repointed.");
|
||||
}
|
||||
}
|
||||
|
||||
@Command(aliases = {"stack", ";"}, usage = "", desc = "Stack items", max = 0)
|
||||
@CommandPermissions({"worldguard.stack"})
|
||||
public void stack(CommandContext args, CommandSender sender) throws CommandException {
|
||||
|
||||
Player player = plugin.checkPlayer(sender);
|
||||
boolean ignoreMax = plugin.hasPermission(player, "worldguard.stack.illegitimate");
|
||||
boolean ignoreDamaged = plugin.hasPermission(player, "worldguard.stack.damaged");
|
||||
|
||||
ItemStack[] items = player.getInventory().getContents();
|
||||
int len = items.length;
|
||||
|
||||
int affected = 0;
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
ItemStack item = items[i];
|
||||
|
||||
// Avoid infinite stacks and stacks with durability
|
||||
if (item == null || item.getAmount() <= 0
|
||||
|| (!ignoreMax && item.getMaxStackSize() == 1)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int max = ignoreMax ? 64 : item.getMaxStackSize();
|
||||
|
||||
if (item.getAmount() < max) {
|
||||
int needed = max - item.getAmount(); // Number of needed items until max
|
||||
|
||||
// Find another stack of the same type
|
||||
for (int j = i + 1; j < len; j++) {
|
||||
ItemStack item2 = items[j];
|
||||
|
||||
// Avoid infinite stacks and stacks with durability
|
||||
if (item2 == null || item2.getAmount() <= 0
|
||||
|| (!ignoreMax && item.getMaxStackSize() == 1)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Same type?
|
||||
// Blocks store their color in the damage value
|
||||
if (item2.getTypeId() == item.getTypeId() &&
|
||||
((!ItemType.usesDamageValue(item.getTypeId()) && ignoreDamaged)
|
||||
|| item.getDurability() == item2.getDurability()) &&
|
||||
item.getEnchantments().equals(item2.getEnchantments())) {
|
||||
// This stack won't fit in the parent stack
|
||||
if (item2.getAmount() > needed) {
|
||||
item.setAmount(max);
|
||||
item2.setAmount(item2.getAmount() - needed);
|
||||
break;
|
||||
// This stack will
|
||||
} else {
|
||||
items[j] = null;
|
||||
item.setAmount(item.getAmount() + item2.getAmount());
|
||||
needed = max - item.getAmount();
|
||||
}
|
||||
|
||||
affected++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (affected > 0) {
|
||||
player.getInventory().setContents(items);
|
||||
}
|
||||
|
||||
player.sendMessage(ChatColor.YELLOW + "Items compacted into stacks!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.bukkit.commands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.NestedCommand;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
|
||||
public class ProtectionCommands {
|
||||
@SuppressWarnings("unused")
|
||||
private final WorldGuardPlugin plugin;
|
||||
|
||||
public ProtectionCommands(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Command(aliases = {"region", "regions", "rg"}, desc = "Region management commands")
|
||||
@NestedCommand({RegionCommands.class, RegionMemberCommands.class})
|
||||
public void region(CommandContext args, CommandSender sender) {}
|
||||
|
||||
@Command(aliases = {"worldguard", "wg"}, desc = "WorldGuard commands")
|
||||
@NestedCommand({WorldGuardCommands.class})
|
||||
public void worldGuard(CommandContext args, CommandSender sender) {}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,221 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.bukkit.commands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.domains.DefaultDomain;
|
||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import com.sk89q.worldguard.protection.databases.ProtectionDatabaseException;
|
||||
import com.sk89q.worldguard.protection.databases.RegionDBUtil;
|
||||
|
||||
// @TODO: A lot of code duplication here! Need to fix.
|
||||
|
||||
public class RegionMemberCommands {
|
||||
private final WorldGuardPlugin plugin;
|
||||
|
||||
public RegionMemberCommands(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Command(aliases = {"addmember", "addmember"}, usage = "<id> <members...>",
|
||||
desc = "Add a member to a region", min = 2)
|
||||
public void addMember(CommandContext args, CommandSender sender) throws CommandException {
|
||||
|
||||
Player player = plugin.checkPlayer(sender);
|
||||
World world = player.getWorld();
|
||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||
|
||||
String id = args.getString(0);
|
||||
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||
ProtectedRegion region = mgr.getRegion(id);
|
||||
|
||||
if (region == null) {
|
||||
throw new CommandException("Could not find a region by that ID.");
|
||||
}
|
||||
|
||||
id = region.getId();
|
||||
|
||||
if (region.isOwner(localPlayer)) {
|
||||
plugin.checkPermission(sender, "worldguard.region.addmember.own." + id.toLowerCase());
|
||||
} else if (region.isMember(localPlayer)) {
|
||||
plugin.checkPermission(sender, "worldguard.region.addmember.member." + id.toLowerCase());
|
||||
} else {
|
||||
plugin.checkPermission(sender, "worldguard.region.addmember." + id.toLowerCase());
|
||||
}
|
||||
|
||||
RegionDBUtil.addToDomain(region.getMembers(), args.getPaddedSlice(2, 0), 0);
|
||||
|
||||
sender.sendMessage(ChatColor.YELLOW
|
||||
+ "Region '" + id + "' updated.");
|
||||
|
||||
try {
|
||||
mgr.save();
|
||||
} catch (ProtectionDatabaseException e) {
|
||||
throw new CommandException("Failed to write regions: "
|
||||
+ e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Command(aliases = {"addowner", "addowner"}, usage = "<id> <owners...>",
|
||||
desc = "Add an owner to a region", min = 2)
|
||||
public void addOwner(CommandContext args, CommandSender sender) throws CommandException {
|
||||
|
||||
Player player = plugin.checkPlayer(sender);
|
||||
World world = player.getWorld();
|
||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||
|
||||
String id = args.getString(0);
|
||||
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||
ProtectedRegion region = mgr.getRegion(id);
|
||||
|
||||
if (region == null) {
|
||||
throw new CommandException("Could not find a region by that ID.");
|
||||
}
|
||||
|
||||
id = region.getId();
|
||||
|
||||
Boolean flag = region.getFlag(DefaultFlag.BUYABLE);
|
||||
DefaultDomain owners = region.getOwners();
|
||||
if (flag != null && flag && owners != null && owners.size() == 0) {
|
||||
if (!plugin.hasPermission(player, "worldguard.region.unlimited")) {
|
||||
int maxRegionCount = plugin.getGlobalStateManager().get(world).getMaxRegionCount(player);
|
||||
if (maxRegionCount >= 0 && mgr.getRegionCountOfPlayer(localPlayer)
|
||||
>= maxRegionCount) {
|
||||
throw new CommandException("You already own the maximum allowed amount of regions.");
|
||||
}
|
||||
}
|
||||
plugin.checkPermission(sender, "worldguard.region.addowner.unclaimed." + id.toLowerCase());
|
||||
} else {
|
||||
if (region.isOwner(localPlayer)) {
|
||||
plugin.checkPermission(sender, "worldguard.region.addowner.own." + id.toLowerCase());
|
||||
} else if (region.isMember(localPlayer)) {
|
||||
plugin.checkPermission(sender, "worldguard.region.addowner.member." + id.toLowerCase());
|
||||
} else {
|
||||
plugin.checkPermission(sender, "worldguard.region.addowner." + id.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
RegionDBUtil.addToDomain(region.getOwners(), args.getPaddedSlice(2, 0), 0);
|
||||
|
||||
sender.sendMessage(ChatColor.YELLOW
|
||||
+ "Region '" + id + "' updated.");
|
||||
|
||||
try {
|
||||
mgr.save();
|
||||
} catch (ProtectionDatabaseException e) {
|
||||
throw new CommandException("Failed to write regions: "
|
||||
+ e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Command(aliases = {"removemember", "remmember", "removemem", "remmem"}, usage = "<id> <owners...>",
|
||||
desc = "Remove an owner to a region", min = 2)
|
||||
public void removeMember(CommandContext args, CommandSender sender) throws CommandException {
|
||||
|
||||
Player player = plugin.checkPlayer(sender);
|
||||
World world = player.getWorld();
|
||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||
|
||||
String id = args.getString(0);
|
||||
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||
ProtectedRegion region = mgr.getRegion(id);
|
||||
|
||||
if (region == null) {
|
||||
throw new CommandException("Could not find a region by that ID.");
|
||||
}
|
||||
|
||||
id = region.getId();
|
||||
|
||||
if (region.isOwner(localPlayer)) {
|
||||
plugin.checkPermission(sender, "worldguard.region.removemember.own." + id.toLowerCase());
|
||||
} else if (region.isMember(localPlayer)) {
|
||||
plugin.checkPermission(sender, "worldguard.region.removemember.member." + id.toLowerCase());
|
||||
} else {
|
||||
plugin.checkPermission(sender, "worldguard.region.removemember." + id.toLowerCase());
|
||||
}
|
||||
|
||||
RegionDBUtil.removeFromDomain(region.getMembers(), args.getPaddedSlice(2, 0), 0);
|
||||
|
||||
sender.sendMessage(ChatColor.YELLOW
|
||||
+ "Region '" + id + "' updated.");
|
||||
|
||||
try {
|
||||
mgr.save();
|
||||
} catch (ProtectionDatabaseException e) {
|
||||
throw new CommandException("Failed to write regions: "
|
||||
+ e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Command(aliases = {"removeowner", "remowner"}, usage = "<id> <owners...>",
|
||||
desc = "Remove an owner to a region", min = 2)
|
||||
public void removeOwner(CommandContext args,
|
||||
CommandSender sender) throws CommandException {
|
||||
|
||||
Player player = plugin.checkPlayer(sender);
|
||||
World world = player.getWorld();
|
||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||
|
||||
String id = args.getString(0);
|
||||
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||
ProtectedRegion region = mgr.getRegion(id);
|
||||
|
||||
if (region == null) {
|
||||
throw new CommandException("Could not find a region by that ID.");
|
||||
}
|
||||
|
||||
id = region.getId();
|
||||
|
||||
if (region.isOwner(localPlayer)) {
|
||||
plugin.checkPermission(sender, "worldguard.region.removeowner.own." + id.toLowerCase());
|
||||
} else if (region.isMember(localPlayer)) {
|
||||
plugin.checkPermission(sender, "worldguard.region.removeowner.member." + id.toLowerCase());
|
||||
} else {
|
||||
plugin.checkPermission(sender, "worldguard.region.removeowner." + id.toLowerCase());
|
||||
}
|
||||
|
||||
RegionDBUtil.removeFromDomain(region.getOwners(), args.getPaddedSlice(2, 0), 0);
|
||||
|
||||
sender.sendMessage(ChatColor.YELLOW
|
||||
+ "Region '" + id + "' updated.");
|
||||
|
||||
try {
|
||||
mgr.save();
|
||||
} catch (ProtectionDatabaseException e) {
|
||||
throw new CommandException("Failed to write regions: "
|
||||
+ e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.bukkit.commands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.worldguard.bukkit.BukkitUtil;
|
||||
import com.sk89q.worldguard.bukkit.ConfigurationManager;
|
||||
import com.sk89q.worldguard.bukkit.WorldConfiguration;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
|
||||
public class ToggleCommands {
|
||||
private final WorldGuardPlugin plugin;
|
||||
|
||||
public ToggleCommands(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Command(aliases = {"stopfire"}, usage = "[<world>]",
|
||||
desc = "Disables all fire spread temporarily", max = 1)
|
||||
@CommandPermissions({"worldguard.fire-toggle.stop"})
|
||||
public void stopFire(CommandContext args, CommandSender sender) throws CommandException {
|
||||
|
||||
World world;
|
||||
|
||||
if (args.argsLength() == 0) {
|
||||
world = plugin.checkPlayer(sender).getWorld();
|
||||
} else {
|
||||
world = plugin.matchWorld(sender, args.getString(0));
|
||||
}
|
||||
|
||||
WorldConfiguration wcfg = plugin.getGlobalStateManager().get(world);
|
||||
|
||||
if (!wcfg.fireSpreadDisableToggle) {
|
||||
plugin.getServer().broadcastMessage(
|
||||
ChatColor.YELLOW
|
||||
+ "Fire spread has been globally disabled for '" + world.getName() + "' by "
|
||||
+ plugin.toName(sender) + ".");
|
||||
} else {
|
||||
sender.sendMessage(
|
||||
ChatColor.YELLOW
|
||||
+ "Fire spread was already globally disabled.");
|
||||
}
|
||||
|
||||
wcfg.fireSpreadDisableToggle = true;
|
||||
}
|
||||
|
||||
@Command(aliases = {"allowfire"}, usage = "[<world>]",
|
||||
desc = "Allows all fire spread temporarily", max = 1)
|
||||
@CommandPermissions({"worldguard.fire-toggle.stop"})
|
||||
public void allowFire(CommandContext args, CommandSender sender) throws CommandException {
|
||||
|
||||
World world;
|
||||
|
||||
if (args.argsLength() == 0) {
|
||||
world = plugin.checkPlayer(sender).getWorld();
|
||||
} else {
|
||||
world = plugin.matchWorld(sender, args.getString(0));
|
||||
}
|
||||
|
||||
WorldConfiguration wcfg = plugin.getGlobalStateManager().get(world);
|
||||
|
||||
if (wcfg.fireSpreadDisableToggle) {
|
||||
plugin.getServer().broadcastMessage(ChatColor.YELLOW
|
||||
+ "Fire spread has been globally for '" + world.getName() + "' re-enabled by "
|
||||
+ plugin.toName(sender) + ".");
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.YELLOW
|
||||
+ "Fire spread was already globally enabled.");
|
||||
}
|
||||
|
||||
wcfg.fireSpreadDisableToggle = false;
|
||||
}
|
||||
|
||||
@Command(aliases = {"halt-activity", "stoplag", "haltactivity"},
|
||||
desc = "Attempts to cease as much activity in order to stop lag", flags = "c", max = 0)
|
||||
@CommandPermissions({"worldguard.halt-activity"})
|
||||
public void stopLag(CommandContext args, CommandSender sender) throws CommandException {
|
||||
|
||||
ConfigurationManager configManager = plugin.getGlobalStateManager();
|
||||
|
||||
configManager.activityHaltToggle = !args.hasFlag('c');
|
||||
|
||||
if (configManager.activityHaltToggle) {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(ChatColor.YELLOW
|
||||
+ "ALL intensive server activity halted.");
|
||||
}
|
||||
|
||||
plugin.getServer().broadcastMessage(ChatColor.YELLOW
|
||||
+ "ALL intensive server activity halted by "
|
||||
+ plugin.toName(sender) + ".");
|
||||
|
||||
for (World world : plugin.getServer().getWorlds()) {
|
||||
int removed = 0;
|
||||
|
||||
for (Entity entity : world.getEntities()) {
|
||||
if (BukkitUtil.isIntensiveEntity(entity)) {
|
||||
entity.remove();
|
||||
removed++;
|
||||
}
|
||||
}
|
||||
|
||||
if (removed > 10) {
|
||||
sender.sendMessage("" + removed + " entities (>10) auto-removed from "
|
||||
+ world.toString());
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(ChatColor.YELLOW
|
||||
+ "ALL intensive server activity no longer halted.");
|
||||
}
|
||||
|
||||
plugin.getServer().broadcastMessage(ChatColor.YELLOW
|
||||
+ "ALL intensive server activity is now allowed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.bukkit.commands;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.worldguard.bukkit.LoggerToChatHandler;
|
||||
import com.sk89q.worldguard.bukkit.ReportWriter;
|
||||
import com.sk89q.worldguard.bukkit.WGBukkit;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.util.PastebinPoster;
|
||||
import com.sk89q.worldguard.util.PastebinPoster.PasteCallback;
|
||||
|
||||
public class WorldGuardCommands {
|
||||
private final WorldGuardPlugin plugin;
|
||||
|
||||
public WorldGuardCommands(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Command(aliases = {"version"}, desc = "Get the WorldGuard version", max = 0)
|
||||
public void version(CommandContext args, CommandSender sender) throws CommandException {
|
||||
sender.sendMessage(ChatColor.YELLOW
|
||||
+ "WorldGuard " + plugin.getDescription().getVersion());
|
||||
sender.sendMessage(ChatColor.YELLOW
|
||||
+ "http://www.sk89q.com");
|
||||
}
|
||||
|
||||
@Command(aliases = {"reload"}, desc = "Reload WorldGuard configuration", max = 0)
|
||||
@CommandPermissions({"worldguard.reload"})
|
||||
public void reload(CommandContext args, CommandSender sender) throws CommandException {
|
||||
|
||||
LoggerToChatHandler handler = null;
|
||||
Logger minecraftLogger = null;
|
||||
|
||||
if (sender instanceof Player) {
|
||||
handler = new LoggerToChatHandler(sender);
|
||||
handler.setLevel(Level.ALL);
|
||||
minecraftLogger = Logger.getLogger("Minecraft");
|
||||
minecraftLogger.addHandler(handler);
|
||||
}
|
||||
|
||||
try {
|
||||
plugin.getGlobalStateManager().unload();
|
||||
plugin.getGlobalRegionManager().unload();
|
||||
plugin.getGlobalStateManager().load();
|
||||
plugin.getGlobalRegionManager().preload();
|
||||
WGBukkit.cleanCache();
|
||||
sender.sendMessage("WorldGuard configuration reloaded.");
|
||||
} catch (Throwable t) {
|
||||
sender.sendMessage("Error while reloading: "
|
||||
+ t.getMessage());
|
||||
} finally {
|
||||
if (minecraftLogger != null) {
|
||||
minecraftLogger.removeHandler(handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Command(aliases = {"report"}, desc = "Writes a report on WorldGuard", flags = "p", max = 0)
|
||||
@CommandPermissions({"worldguard.report"})
|
||||
public void report(CommandContext args, final CommandSender sender) throws CommandException {
|
||||
|
||||
File dest = new File(plugin.getDataFolder(), "report.txt");
|
||||
ReportWriter report = new ReportWriter(plugin);
|
||||
|
||||
try {
|
||||
report.write(dest);
|
||||
sender.sendMessage(ChatColor.YELLOW + "WorldGuard report written to "
|
||||
+ dest.getAbsolutePath());
|
||||
} catch (IOException e) {
|
||||
throw new CommandException("Failed to write report: " + e.getMessage());
|
||||
}
|
||||
|
||||
if (args.hasFlag('p')) {
|
||||
plugin.checkPermission(sender, "worldguard.report.pastebin");
|
||||
|
||||
sender.sendMessage(ChatColor.YELLOW + "Now uploading to Pastebin...");
|
||||
PastebinPoster.paste(report.toString(), new PasteCallback() {
|
||||
|
||||
public void handleSuccess(String url) {
|
||||
// Hope we don't have a thread safety issue here
|
||||
sender.sendMessage(ChatColor.YELLOW + "WorldGuard report (1 hour): " + url);
|
||||
}
|
||||
|
||||
public void handleError(String err) {
|
||||
// Hope we don't have a thread safety issue here
|
||||
sender.sendMessage(ChatColor.YELLOW + "WorldGuard report pastebin error: " + err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Command(aliases = {"flushstates", "clearstates"},
|
||||
usage = "[player]", desc = "Flush the state manager", max = 1)
|
||||
@CommandPermissions("worldguard.flushstates")
|
||||
public void flushStates(CommandContext args, CommandSender sender) throws CommandException {
|
||||
if (args.argsLength() == 0) {
|
||||
plugin.getFlagStateManager().forgetAll();
|
||||
sender.sendMessage("Cleared all states.");
|
||||
} else {
|
||||
Player player = plugin.getServer().getPlayer(args.getString(0));
|
||||
if (player != null) {
|
||||
plugin.getFlagStateManager().forget(player);
|
||||
sender.sendMessage("Cleared states for player \"" + player.getName() + "\".");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.chest;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Interface for chest protection.
|
||||
*/
|
||||
public interface ChestProtection {
|
||||
|
||||
/**
|
||||
* Returns whether a block is protected.
|
||||
*
|
||||
* @param block The block to check
|
||||
* @param player The player to check
|
||||
* @return Whether the block is protected for player
|
||||
*/
|
||||
public boolean isProtected(Block block, Player player);
|
||||
|
||||
/**
|
||||
* Returns whether a location where a chest block is trying to be created
|
||||
* is protected.
|
||||
*
|
||||
* @param block The block to check
|
||||
* @param player The player to check
|
||||
* @return Whether {@code player} can place a block at the specified block
|
||||
*/
|
||||
public boolean isProtectedPlacement(Block block, Player player);
|
||||
|
||||
/**
|
||||
* Returns whether an adjacent chest is protected.
|
||||
*
|
||||
* @param searchBlock The block to check
|
||||
* @param player The player to check
|
||||
* @return Whether {@code searchBlock} is protected from access by {@code player}
|
||||
*/
|
||||
public boolean isAdjacentChestProtected(Block searchBlock, Player player);
|
||||
|
||||
/**
|
||||
* Returns whether a material is a chest.
|
||||
*
|
||||
* @param material The material to check
|
||||
* @deprecated see {@link #isChest(int)}
|
||||
* @return {@link #isChest(int)}
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean isChest(Material material);
|
||||
|
||||
/**
|
||||
* Returns whether a material is a chest.
|
||||
*
|
||||
* @param type The type to check
|
||||
* @return Whether type is a 'chest' (block that can be protected)
|
||||
*/
|
||||
public boolean isChest(int type);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.chest;
|
||||
|
||||
import com.sk89q.worldedit.blocks.BlockID;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Sign-based chest protection.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class SignChestProtection implements ChestProtection {
|
||||
|
||||
public boolean isProtected(Block block, Player player) {
|
||||
if (isChest(block.getTypeId())) {
|
||||
Block below = block.getRelative(0, -1, 0);
|
||||
return isProtectedSignAround(below, player);
|
||||
} else if (block.getTypeId() == BlockID.SIGN_POST) {
|
||||
return isProtectedSignAndChestBinary(block, player);
|
||||
} else {
|
||||
Block above = block.getRelative(0, 1, 0);
|
||||
Boolean res = isProtectedSign(above, player);
|
||||
if (res != null) return res;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isProtectedPlacement(Block block, Player player) {
|
||||
return isProtectedSignAround(block, player);
|
||||
}
|
||||
|
||||
private boolean isProtectedSignAround(Block searchBlock, Player player) {
|
||||
Block side;
|
||||
Boolean res;
|
||||
|
||||
side = searchBlock;
|
||||
res = isProtectedSign(side, player);
|
||||
if (res != null && res) return res;
|
||||
|
||||
side = searchBlock.getRelative(-1, 0, 0);
|
||||
res = isProtectedSignAndChest(side, player);
|
||||
if (res != null && res) return res;
|
||||
|
||||
side = searchBlock.getRelative(1, 0, 0);
|
||||
res = isProtectedSignAndChest(side, player);
|
||||
if (res != null && res) return res;
|
||||
|
||||
side = searchBlock.getRelative(0, 0, -1);
|
||||
res = isProtectedSignAndChest(side, player);
|
||||
if (res != null && res) return res;
|
||||
|
||||
side = searchBlock.getRelative(0, 0, 1);
|
||||
res = isProtectedSignAndChest(side, player);
|
||||
if (res != null && res) return res;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private Boolean isProtectedSign(Sign sign, Player player) {
|
||||
if (sign.getLine(0).equalsIgnoreCase("[Lock]")) {
|
||||
if (player == null) { // No player, no access
|
||||
return true;
|
||||
}
|
||||
|
||||
String name = player.getName();
|
||||
if (name.equalsIgnoreCase(sign.getLine(1).trim())
|
||||
|| name.equalsIgnoreCase(sign.getLine(2).trim())
|
||||
|| name.equalsIgnoreCase(sign.getLine(3).trim())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// No access!
|
||||
return true;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Boolean isProtectedSign(Block block, Player player) {
|
||||
BlockState state = block.getState();
|
||||
if (state == null || !(state instanceof Sign)) {
|
||||
return null;
|
||||
}
|
||||
return isProtectedSign((Sign) state, player);
|
||||
}
|
||||
|
||||
private Boolean isProtectedSignAndChest(Block block, Player player) {
|
||||
if (!isChest(block.getRelative(0, 1, 0).getTypeId())) {
|
||||
return null;
|
||||
}
|
||||
return isProtectedSign(block, player);
|
||||
}
|
||||
|
||||
private boolean isProtectedSignAndChestBinary(Block block, Player player) {
|
||||
Boolean res = isProtectedSignAndChest(block, player);
|
||||
return !(res == null || !res);
|
||||
}
|
||||
|
||||
public boolean isAdjacentChestProtected(Block searchBlock, Player player) {
|
||||
Block side;
|
||||
Boolean res;
|
||||
|
||||
side = searchBlock;
|
||||
res = isProtected(side, player);
|
||||
if (res != null && res) return res;
|
||||
|
||||
side = searchBlock.getRelative(-1, 0, 0);
|
||||
res = isProtected(side, player);
|
||||
if (res != null && res) return res;
|
||||
|
||||
side = searchBlock.getRelative(1, 0, 0);
|
||||
res = isProtected(side, player);
|
||||
if (res != null && res) return res;
|
||||
|
||||
side = searchBlock.getRelative(0, 0, -1);
|
||||
res = isProtected(side, player);
|
||||
if (res != null && res) return res;
|
||||
|
||||
side = searchBlock.getRelative(0, 0, 1);
|
||||
res = isProtected(side, player);
|
||||
if (res != null && res) return res;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean isChest(Material material) {
|
||||
return isChest(material.getId());
|
||||
}
|
||||
|
||||
public boolean isChest(int type) {
|
||||
return type == BlockID.CHEST
|
||||
|| type == BlockID.DISPENSER
|
||||
|| type == BlockID.FURNACE
|
||||
|| type == BlockID.BURNING_FURNACE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.domains;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
|
||||
public class DefaultDomain implements Domain {
|
||||
private Set<String> groups;
|
||||
private Set<String> players;
|
||||
|
||||
public DefaultDomain() {
|
||||
this.groups = new LinkedHashSet<String>();
|
||||
this.players = new HashSet<String>();
|
||||
}
|
||||
|
||||
public void addPlayer(String name) {
|
||||
players.add(name.toLowerCase());
|
||||
}
|
||||
|
||||
public void addPlayer(LocalPlayer player) {
|
||||
players.add(player.getName().toLowerCase());
|
||||
}
|
||||
|
||||
public void removePlayer(String name) {
|
||||
players.remove(name.toLowerCase());
|
||||
}
|
||||
|
||||
public void removePlayer(LocalPlayer player) {
|
||||
players.remove(player.getName().toLowerCase());
|
||||
}
|
||||
|
||||
public void addGroup(String name) {
|
||||
groups.add(name.toLowerCase());
|
||||
}
|
||||
|
||||
public void removeGroup(String name) {
|
||||
groups.remove(name.toLowerCase());
|
||||
}
|
||||
|
||||
public Set<String> getGroups() {
|
||||
return groups;
|
||||
}
|
||||
|
||||
public Set<String> getPlayers() {
|
||||
return players;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(LocalPlayer player) {
|
||||
if (contains(player.getName())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (String group : groups) {
|
||||
if (player.hasGroup(group)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(String playerName) {
|
||||
return players.contains(playerName.toLowerCase());
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return groups.size() + players.size();
|
||||
}
|
||||
|
||||
public String toPlayersString() {
|
||||
StringBuilder str = new StringBuilder();
|
||||
List<String> output = new ArrayList<String>(players);
|
||||
Collections.sort(output, String.CASE_INSENSITIVE_ORDER);
|
||||
for (Iterator<String> it = output.iterator(); it.hasNext();) {
|
||||
str.append(it.next());
|
||||
if (it.hasNext()) {
|
||||
str.append(", ");
|
||||
}
|
||||
}
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
public String toGroupsString() {
|
||||
StringBuilder str = new StringBuilder();
|
||||
for (Iterator<String> it = groups.iterator(); it.hasNext(); ) {
|
||||
str.append("*");
|
||||
str.append(it.next());
|
||||
if (it.hasNext()) {
|
||||
str.append(", ");
|
||||
}
|
||||
}
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
public String toUserFriendlyString() {
|
||||
StringBuilder str = new StringBuilder();
|
||||
if (players.size() > 0) {
|
||||
str.append(toPlayersString());
|
||||
}
|
||||
|
||||
if (groups.size() > 0) {
|
||||
if (str.length() > 0) {
|
||||
str.append("; ");
|
||||
}
|
||||
|
||||
str.append(toGroupsString());
|
||||
}
|
||||
|
||||
return str.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.sk89q.worldguard.domains;
|
||||
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
|
||||
public interface Domain {
|
||||
/**
|
||||
* Returns true if a domain contains a player.
|
||||
*
|
||||
* @param player The player to check
|
||||
* @return whether this domain contains {@code player}
|
||||
*/
|
||||
boolean contains(LocalPlayer player);
|
||||
|
||||
/**
|
||||
* Returns true if a domain contains a player.<br />
|
||||
* This method doesn't check for groups!
|
||||
*
|
||||
* @param playerName The name of the player to check
|
||||
* @return whether this domain contains a player by that name
|
||||
*/
|
||||
boolean contains(String playerName);
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.domains;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
|
||||
public class DomainCollection implements Domain {
|
||||
private Set<Domain> domains;
|
||||
|
||||
public DomainCollection() {
|
||||
domains = new LinkedHashSet<Domain>();
|
||||
}
|
||||
|
||||
public void add(Domain domain) {
|
||||
domains.add(domain);
|
||||
}
|
||||
|
||||
public void remove(Domain domain) {
|
||||
domains.remove(domain);
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return domains.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(LocalPlayer player) {
|
||||
for (Domain domain : domains) {
|
||||
if (domain.contains(player)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(String playerName) {
|
||||
for (Domain domain : domains) {
|
||||
if (domain.contains(playerName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.domains;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
|
||||
public class GroupDomain implements Domain {
|
||||
private Set<String> groups;
|
||||
|
||||
public GroupDomain() {
|
||||
this.groups = new LinkedHashSet<String>();
|
||||
}
|
||||
|
||||
public GroupDomain(String[] groups) {
|
||||
this.groups = new LinkedHashSet<String>(Arrays.asList(groups));
|
||||
}
|
||||
|
||||
public void addGroup(String name) {
|
||||
groups.add(name);
|
||||
}
|
||||
|
||||
public boolean contains(LocalPlayer player) {
|
||||
for (String group : groups) {
|
||||
if (player.hasGroup(group)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(String playerName) {
|
||||
return false; // GroupDomains can't contain player names.
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return groups.size();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.domains;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
|
||||
public class PlayerDomain implements Domain {
|
||||
private Set<String> players;
|
||||
|
||||
public PlayerDomain() {
|
||||
this.players = new HashSet<String>();
|
||||
}
|
||||
|
||||
public PlayerDomain(String[] players) {
|
||||
this.players = new HashSet<String>();
|
||||
|
||||
for (String name : players) {
|
||||
this.players.add(name.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
public void addPlayer(String name) {
|
||||
players.add(name.toLowerCase());
|
||||
}
|
||||
|
||||
public boolean contains(LocalPlayer player) {
|
||||
return contains(player.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(String playerName) {
|
||||
return players.contains(playerName.toLowerCase());
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return players.size();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,402 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.sk89q.worldguard.protection;
|
||||
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.protection.flags.*;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag.State;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Represents a set of regions for a particular point or area and the rules
|
||||
* that are represented by that set. An instance of this can be used to
|
||||
* query the value of a flag or check if a player can build in the respective
|
||||
* region or point. This object contains the list of applicable regions and so
|
||||
* the expensive search of regions that are in the desired area has already
|
||||
* been completed.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class ApplicableRegionSet implements Iterable<ProtectedRegion> {
|
||||
|
||||
private Collection<ProtectedRegion> applicable;
|
||||
private ProtectedRegion globalRegion;
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param applicable The regions contained in this set
|
||||
* @param globalRegion The global region, set aside for special handling.
|
||||
*/
|
||||
public ApplicableRegionSet(Collection<ProtectedRegion> applicable,
|
||||
ProtectedRegion globalRegion) {
|
||||
this.applicable = applicable;
|
||||
this.globalRegion = globalRegion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a player can build in an area.
|
||||
*
|
||||
* @param player The player to chec
|
||||
* @return build ability
|
||||
*/
|
||||
public boolean canBuild(LocalPlayer player) {
|
||||
return internalGetState(DefaultFlag.BUILD, player, null);
|
||||
}
|
||||
|
||||
public boolean canConstruct(LocalPlayer player) {
|
||||
final RegionGroup flag = getFlag(DefaultFlag.CONSTRUCT, player);
|
||||
return RegionGroupFlag.isMember(this, flag, player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a player can use buttons and such in an area.
|
||||
*
|
||||
* @param player The player to check
|
||||
* @return able to use items
|
||||
* @deprecated This method seems to be the opposite of its name
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean canUse(LocalPlayer player) {
|
||||
return !allows(DefaultFlag.USE, player)
|
||||
&& !canBuild(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the state of a state flag. This cannot be used for the build flag.
|
||||
*
|
||||
* @param flag flag to check
|
||||
* @return whether it is allowed
|
||||
* @throws IllegalArgumentException if the build flag is given
|
||||
*/
|
||||
public boolean allows(StateFlag flag) {
|
||||
if (flag == DefaultFlag.BUILD) {
|
||||
throw new IllegalArgumentException("Can't use build flag with allows()");
|
||||
}
|
||||
return internalGetState(flag, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the state of a state flag. This cannot be used for the build flag.
|
||||
*
|
||||
* @param flag flag to check
|
||||
* @param player player (used by some flags)
|
||||
* @return whether the state is allows for it
|
||||
* @throws IllegalArgumentException if the build flag is given
|
||||
*/
|
||||
public boolean allows(StateFlag flag, LocalPlayer player) {
|
||||
if (flag == DefaultFlag.BUILD) {
|
||||
throw new IllegalArgumentException("Can't use build flag with allows()");
|
||||
}
|
||||
return internalGetState(flag, null, player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether a player is an owner of all regions in this set.
|
||||
*
|
||||
* @param player player
|
||||
* @return whether the player is an owner of all regions
|
||||
*/
|
||||
public boolean isOwnerOfAll(LocalPlayer player) {
|
||||
for (ProtectedRegion region : applicable) {
|
||||
if (!region.isOwner(player)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether a player is an owner or member of all regions in
|
||||
* this set.
|
||||
*
|
||||
* @param player player
|
||||
* @return whether the player is a member of all regions
|
||||
*/
|
||||
public boolean isMemberOfAll(LocalPlayer player) {
|
||||
for (ProtectedRegion region : applicable) {
|
||||
if (!region.isMember(player)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if a flag is permitted.
|
||||
*
|
||||
* @param flag flag to check
|
||||
* @param player null to not check owners and members
|
||||
* @param groupPlayer player to use for the group flag check
|
||||
* @return the allow/deny state for the flag
|
||||
*/
|
||||
private boolean internalGetState(StateFlag flag, LocalPlayer player,
|
||||
LocalPlayer groupPlayer) {
|
||||
boolean found = false;
|
||||
boolean hasFlagDefined = false;
|
||||
boolean allowed = false; // Used for ALLOW override
|
||||
boolean def = flag.getDefault();
|
||||
|
||||
// Handle defaults
|
||||
if (globalRegion != null) {
|
||||
State globalState = globalRegion.getFlag(flag);
|
||||
|
||||
// The global region has this flag set
|
||||
if (globalState != null) {
|
||||
// Build flag is very special
|
||||
if (player != null && globalRegion.hasMembersOrOwners()) {
|
||||
def = globalRegion.isMember(player) && (globalState == State.ALLOW);
|
||||
} else {
|
||||
def = (globalState == State.ALLOW);
|
||||
}
|
||||
} else {
|
||||
// Build flag is very special
|
||||
if (player != null && globalRegion.hasMembersOrOwners()) {
|
||||
def = globalRegion.isMember(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The player argument is used if and only if the flag is the build
|
||||
// flag -- in which case, if there are any regions in this area, we
|
||||
// default to FALSE, otherwise true if there are no defined regions.
|
||||
// However, other flags are different -- if there are regions defined,
|
||||
// we default to the global region value.
|
||||
if (player == null) {
|
||||
allowed = def;
|
||||
}
|
||||
|
||||
int lastPriority = Integer.MIN_VALUE;
|
||||
|
||||
// The algorithm is as follows:
|
||||
// While iterating through the list of regions, if an entry disallows
|
||||
// the flag, then put it into the needsClear set. If an entry allows
|
||||
// the flag and it has a parent, then its parent is put into hasCleared.
|
||||
// In the situation that the child is reached before the parent, upon
|
||||
// the parent being reached, even if the parent disallows, because the
|
||||
// parent will be in hasCleared, permission will be allowed. In the
|
||||
// other case, where the parent is reached first, if it does not allow
|
||||
// permissions, it will be placed into needsClear. If a child of
|
||||
// the parent is reached later, the parent will be removed from
|
||||
// needsClear. At the end, if needsClear is not empty, that means that
|
||||
// permission should not be given. If a parent has multiple children
|
||||
// and one child does not allow permissions, then it will be placed into
|
||||
// needsClear just like as if was a parent.
|
||||
|
||||
Set<ProtectedRegion> needsClear = new HashSet<ProtectedRegion>();
|
||||
Set<ProtectedRegion> hasCleared = new HashSet<ProtectedRegion>();
|
||||
|
||||
for (ProtectedRegion region : applicable) {
|
||||
// Ignore lower priority regions
|
||||
if (hasFlagDefined && region.getPriority() < lastPriority) {
|
||||
break;
|
||||
}
|
||||
|
||||
lastPriority = region.getPriority();
|
||||
|
||||
// Ignore non-build regions
|
||||
if (player != null
|
||||
&& region.getFlag(DefaultFlag.PASSTHROUGH) == State.ALLOW) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check group permissions
|
||||
if (groupPlayer != null && flag.getRegionGroupFlag() != null) {
|
||||
RegionGroup group = region.getFlag(flag.getRegionGroupFlag());
|
||||
if (group == null) {
|
||||
group = flag.getRegionGroupFlag().getDefault();
|
||||
}
|
||||
if (!RegionGroupFlag.isMember(region, group, groupPlayer)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
State v = region.getFlag(flag);
|
||||
|
||||
// Allow DENY to override everything
|
||||
if (v == State.DENY) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Forget about regions that allow it, although make sure the
|
||||
// default state is now to allow
|
||||
if (v == State.ALLOW) {
|
||||
allowed = true;
|
||||
found = true;
|
||||
hasFlagDefined = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
// For the build flag, the flags are conditional and are based
|
||||
// on membership, so we have to check for parent-child
|
||||
// relationships
|
||||
if (player != null) {
|
||||
hasFlagDefined = true;
|
||||
|
||||
if (hasCleared.contains(region)) {
|
||||
// Already cleared, so do nothing
|
||||
} else {
|
||||
if (!region.isMember(player)) {
|
||||
needsClear.add(region);
|
||||
} else {
|
||||
// Need to clear all parents
|
||||
clearParents(needsClear, hasCleared, region);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
found = true;
|
||||
}
|
||||
|
||||
return !found ? def :
|
||||
(allowed || (player != null && needsClear.size() == 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear a region's parents for isFlagAllowed().
|
||||
*
|
||||
* @param needsClear The regions that should be cleared
|
||||
* @param hasCleared The regions already cleared
|
||||
* @param region The region to start from
|
||||
*/
|
||||
private void clearParents(Set<ProtectedRegion> needsClear,
|
||||
Set<ProtectedRegion> hasCleared, ProtectedRegion region) {
|
||||
ProtectedRegion parent = region.getParent();
|
||||
|
||||
while (parent != null) {
|
||||
if (!needsClear.remove(parent)) {
|
||||
hasCleared.add(parent);
|
||||
}
|
||||
|
||||
parent = parent.getParent();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #getFlag(com.sk89q.worldguard.protection.flags.Flag, com.sk89q.worldguard.LocalPlayer)
|
||||
* @param flag flag to check
|
||||
* @return value of the flag
|
||||
*/
|
||||
public <T extends Flag<V>, V> V getFlag(T flag) {
|
||||
return getFlag(flag, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of a flag. Do not use this for state flags
|
||||
* (use {@link #allows(StateFlag, LocalPlayer)} for that).
|
||||
*
|
||||
* @param flag flag to check
|
||||
* @param groupPlayer player to check {@link RegionGroup}s against
|
||||
* @return value of the flag
|
||||
* @throws IllegalArgumentException if a StateFlag is given
|
||||
*/
|
||||
public <T extends Flag<V>, V> V getFlag(T flag, LocalPlayer groupPlayer) {
|
||||
/*
|
||||
if (flag instanceof StateFlag) {
|
||||
throw new IllegalArgumentException("Cannot use StateFlag with getFlag()");
|
||||
}
|
||||
*/
|
||||
|
||||
int lastPriority = 0;
|
||||
boolean found = false;
|
||||
|
||||
Map<ProtectedRegion, V> needsClear = new HashMap<ProtectedRegion, V>();
|
||||
Set<ProtectedRegion> hasCleared = new HashSet<ProtectedRegion>();
|
||||
|
||||
for (ProtectedRegion region : applicable) {
|
||||
// Ignore lower priority regions
|
||||
if (found && region.getPriority() < lastPriority) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Check group permissions
|
||||
if (groupPlayer != null && flag.getRegionGroupFlag() != null) {
|
||||
RegionGroup group = region.getFlag(flag.getRegionGroupFlag());
|
||||
if (group == null) {
|
||||
group = flag.getRegionGroupFlag().getDefault();
|
||||
}
|
||||
if (!RegionGroupFlag.isMember(region, group, groupPlayer)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasCleared.contains(region)) {
|
||||
// Already cleared, so do nothing
|
||||
} else if (region.getFlag(flag) != null) {
|
||||
clearParents(needsClear, hasCleared, region);
|
||||
|
||||
needsClear.put(region, region.getFlag(flag));
|
||||
|
||||
found = true;
|
||||
}
|
||||
|
||||
lastPriority = region.getPriority();
|
||||
}
|
||||
|
||||
try {
|
||||
return needsClear.values().iterator().next();
|
||||
} catch (NoSuchElementException e) {
|
||||
if (globalRegion != null) {
|
||||
V gFlag = globalRegion.getFlag(flag);
|
||||
if (gFlag != null) return gFlag;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear a region's parents for getFlag().
|
||||
*
|
||||
* @param needsClear The regions that should be cleared
|
||||
* @param hasCleared The regions already cleared
|
||||
* @param region The region to start from
|
||||
*/
|
||||
private void clearParents(Map<ProtectedRegion, ?> needsClear,
|
||||
Set<ProtectedRegion> hasCleared, ProtectedRegion region) {
|
||||
ProtectedRegion parent = region.getParent();
|
||||
|
||||
while (parent != null) {
|
||||
if (needsClear.remove(parent) == null) {
|
||||
hasCleared.add(parent);
|
||||
}
|
||||
|
||||
parent = parent.getParent();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of regions that are included.
|
||||
*
|
||||
* @return the size of this ApplicbleRegionSet
|
||||
*/
|
||||
public int size() {
|
||||
return applicable.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an iterator of affected regions.
|
||||
*/
|
||||
public Iterator<ProtectedRegion> iterator() {
|
||||
return applicable.iterator();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,371 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.sk89q.worldguard.protection;
|
||||
|
||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.bukkit.BukkitUtil;
|
||||
import com.sk89q.worldguard.bukkit.ConfigurationManager;
|
||||
import com.sk89q.worldguard.bukkit.WorldConfiguration;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.protection.databases.ProtectionDatabaseException;
|
||||
import com.sk89q.worldguard.protection.databases.ProtectionDatabase;
|
||||
import com.sk89q.worldguard.protection.databases.YAMLDatabase;
|
||||
import com.sk89q.worldguard.protection.databases.MySQLDatabase;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
import com.sk89q.worldguard.protection.managers.FlatRegionManager;
|
||||
import com.sk89q.worldguard.protection.managers.PRTreeRegionManager;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
|
||||
/**
|
||||
* This class keeps track of region information for every world. It loads
|
||||
* world region information as needed.
|
||||
*
|
||||
* @author sk89q
|
||||
* @author Redecouverte
|
||||
*/
|
||||
public class GlobalRegionManager {
|
||||
|
||||
/**
|
||||
* Reference to the plugin.
|
||||
*/
|
||||
private WorldGuardPlugin plugin;
|
||||
|
||||
/**
|
||||
* Reference to the global configuration.
|
||||
*/
|
||||
private ConfigurationManager config;
|
||||
|
||||
/**
|
||||
* Map of managers per-world.
|
||||
*/
|
||||
private ConcurrentHashMap<String, RegionManager> managers;
|
||||
|
||||
/**
|
||||
* Stores the list of modification dates for the world files. This allows
|
||||
* WorldGuard to reload files as needed.
|
||||
*/
|
||||
private HashMap<String, Long> lastModified;
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param plugin The plugin instance
|
||||
*/
|
||||
public GlobalRegionManager(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
config = plugin.getGlobalStateManager();
|
||||
managers = new ConcurrentHashMap<String, RegionManager>();
|
||||
lastModified = new HashMap<String, Long>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unload region information.
|
||||
*/
|
||||
public void unload() {
|
||||
managers.clear();
|
||||
lastModified.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path for a world's regions file.
|
||||
*
|
||||
* @param name The name of the world
|
||||
* @return The region file path for a world's region file
|
||||
*/
|
||||
protected File getPath(String name) {
|
||||
return new File(plugin.getDataFolder(),
|
||||
"worlds" + File.separator + name + File.separator + "regions.yml");
|
||||
}
|
||||
|
||||
/**
|
||||
* Unload region information for a world.
|
||||
*
|
||||
* @param name The name of the world to unload
|
||||
*/
|
||||
public void unload(String name) {
|
||||
RegionManager manager = managers.remove(name);
|
||||
|
||||
if (manager != null) {
|
||||
lastModified.remove(name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unload all region information.
|
||||
*/
|
||||
public void unloadAll() {
|
||||
managers.clear();
|
||||
lastModified.clear();
|
||||
}
|
||||
|
||||
public RegionManager load(World world) {
|
||||
RegionManager manager = create(world);
|
||||
managers.put(world.getName(), manager);
|
||||
return manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load region information for a world.
|
||||
*
|
||||
* @param world The world to load a RegionManager for
|
||||
* @return the loaded RegionManager
|
||||
*/
|
||||
public RegionManager create(World world) {
|
||||
String name = world.getName();
|
||||
boolean sql = config.useSqlDatabase;
|
||||
ProtectionDatabase database;
|
||||
File file = null;
|
||||
|
||||
try {
|
||||
if (!sql) {
|
||||
file = getPath(name);
|
||||
database = new YAMLDatabase(file, plugin.getLogger());
|
||||
|
||||
// Store the last modification date so we can track changes
|
||||
lastModified.put(name, file.lastModified());
|
||||
} else {
|
||||
database = new MySQLDatabase(config, name, plugin.getLogger());
|
||||
}
|
||||
|
||||
// Create a manager
|
||||
RegionManager manager = new PRTreeRegionManager(database);
|
||||
manager.load();
|
||||
|
||||
plugin.getLogger().info(manager.getRegions().size()
|
||||
+ " regions loaded for '" + name + "'");
|
||||
|
||||
return manager;
|
||||
} catch (ProtectionDatabaseException e) {
|
||||
String logStr = "Failed to load regions from ";
|
||||
if (sql) {
|
||||
logStr += "SQL Database <" + config.sqlDsn + "> ";
|
||||
} else {
|
||||
logStr += "file \"" + file + "\" ";
|
||||
}
|
||||
|
||||
plugin.getLogger().log(Level.SEVERE, logStr + " : " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
} catch (FileNotFoundException e) {
|
||||
plugin.getLogger().log(Level.SEVERE, "Error loading regions for world \""
|
||||
+ name + "\": " + e.toString() + "\n\t" + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// @TODO: THIS CREATES PROBLEMS!!one!!1!!eleven!!1!!!
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Preloads region managers for all worlds.
|
||||
*/
|
||||
public void preload() {
|
||||
// Load regions
|
||||
for (World world : plugin.getServer().getWorlds()) {
|
||||
load(world);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads the region information from file when region databases
|
||||
* have changed.
|
||||
*/
|
||||
public void reloadChanged() {
|
||||
if (config.useSqlDatabase) return;
|
||||
|
||||
for (String name : managers.keySet()) {
|
||||
File file = getPath(name);
|
||||
|
||||
Long oldDate = lastModified.get(name);
|
||||
|
||||
if (oldDate == null) {
|
||||
oldDate = 0L;
|
||||
}
|
||||
|
||||
try {
|
||||
if (file.lastModified() > oldDate) {
|
||||
World world = plugin.getServer().getWorld(name);
|
||||
|
||||
if (world != null) {
|
||||
load(world);
|
||||
}
|
||||
}
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the region manager for a particular world.
|
||||
*
|
||||
* @param world The world to get a RegionManager for
|
||||
* @return The region manager.
|
||||
*/
|
||||
public RegionManager get(World world) {
|
||||
RegionManager manager = managers.get(world.getName());
|
||||
RegionManager newManager = null;
|
||||
|
||||
while (manager == null) {
|
||||
if (newManager == null) {
|
||||
newManager = create(world);
|
||||
}
|
||||
managers.putIfAbsent(world.getName(), newManager);
|
||||
manager = managers.get(world.getName());
|
||||
}
|
||||
|
||||
return manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the player can bypass.
|
||||
*
|
||||
* @param player The player to check
|
||||
* @param world The world to check for
|
||||
* @return Whether {@code player} has bypass permission for {@code world}
|
||||
*/
|
||||
public boolean hasBypass(LocalPlayer player, World world) {
|
||||
return player.hasPermission("worldguard.region.bypass."
|
||||
+ world.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the player can bypass.
|
||||
*
|
||||
* @param player The player to check
|
||||
* @param world The world to check
|
||||
* @return Whether {@code player} has bypass permission for {@code world}
|
||||
*/
|
||||
public boolean hasBypass(Player player, World world) {
|
||||
return plugin.hasPermission(player, "worldguard.region.bypass."
|
||||
+ world.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a player has permission to build at a block.
|
||||
*
|
||||
* @param player The player to check
|
||||
* @param block The block to check at
|
||||
* @return Whether {@code player} can build at {@code block}'s location
|
||||
*/
|
||||
public boolean canBuild(Player player, Block block) {
|
||||
return canBuild(player, block.getLocation());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a player has permission to build at a location.
|
||||
*
|
||||
* @param player The player to check
|
||||
* @param loc The location to check
|
||||
* @return Whether {@code player} can build at {@code loc}
|
||||
*/
|
||||
public boolean canBuild(Player player, Location loc) {
|
||||
World world = loc.getWorld();
|
||||
WorldConfiguration worldConfig = config.get(world);
|
||||
|
||||
if (!worldConfig.useRegions) {
|
||||
return true;
|
||||
}
|
||||
|
||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||
|
||||
if (!hasBypass(player, world)) {
|
||||
RegionManager mgr = get(world);
|
||||
|
||||
if (!mgr.getApplicableRegions(BukkitUtil.toVector(loc))
|
||||
.canBuild(localPlayer)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean canConstruct(Player player, Block block) {
|
||||
return canConstruct(player, block.getLocation());
|
||||
}
|
||||
|
||||
public boolean canConstruct(Player player, Location loc) {
|
||||
World world = loc.getWorld();
|
||||
WorldConfiguration worldConfig = config.get(world);
|
||||
|
||||
if (!worldConfig.useRegions) {
|
||||
return true;
|
||||
}
|
||||
|
||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||
|
||||
if (!hasBypass(player, world)) {
|
||||
RegionManager mgr = get(world);
|
||||
|
||||
final ApplicableRegionSet applicableRegions = mgr.getApplicableRegions(BukkitUtil.toVector(loc));
|
||||
if (!applicableRegions.canBuild(localPlayer)) {
|
||||
return false;
|
||||
}
|
||||
if (!applicableRegions.canConstruct(localPlayer)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see whether a flag is allowed.
|
||||
*
|
||||
* @see #allows(com.sk89q.worldguard.protection.flags.StateFlag, org.bukkit.Location, com.sk89q.worldguard.LocalPlayer)
|
||||
* @param flag The flag to check
|
||||
* @param loc The location to check the flag at
|
||||
* @return Whether the flag is allowed
|
||||
*/
|
||||
public boolean allows(StateFlag flag, Location loc) {
|
||||
return allows(flag, loc, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see whether a flag is allowed.
|
||||
*
|
||||
* @param flag The flag to check
|
||||
* @param loc The location to check the flag at
|
||||
* @param player The player to check for the flag's {@link com.sk89q.worldguard.protection.flags.RegionGroup}
|
||||
* @return Whether the flag is allowed
|
||||
*/
|
||||
public boolean allows(StateFlag flag, Location loc, LocalPlayer player) {
|
||||
World world = loc.getWorld();
|
||||
WorldConfiguration worldConfig = config.get(world);
|
||||
|
||||
if (!worldConfig.useRegions) {
|
||||
return true;
|
||||
}
|
||||
|
||||
RegionManager mgr = get(world);
|
||||
return mgr.getApplicableRegions(toVector(loc)).allows(flag, player);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.protection;
|
||||
|
||||
public class UnsupportedIntersectionException extends Exception {
|
||||
private static final long serialVersionUID = 6423189392345575148L;
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.protection.databases;
|
||||
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
|
||||
public abstract class AbstractProtectionDatabase implements ProtectionDatabase {
|
||||
|
||||
/**
|
||||
* Load the list of regions into a region manager.
|
||||
*
|
||||
* @throws ProtectionDatabaseException
|
||||
*/
|
||||
public void load(RegionManager manager) throws ProtectionDatabaseException {
|
||||
load();
|
||||
manager.setRegions(getRegions());
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the list of regions from a region manager.
|
||||
*
|
||||
* @throws ProtectionDatabaseException
|
||||
*/
|
||||
public void save(RegionManager manager) throws ProtectionDatabaseException {
|
||||
setRegions(manager.getRegions());
|
||||
save();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,357 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.protection.databases;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import au.com.bytecode.opencsv.CSVReader;
|
||||
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldguard.domains.DefaultDomain;
|
||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag.State;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion.CircularInheritanceException;
|
||||
import com.sk89q.worldguard.util.ArrayReader;
|
||||
|
||||
/**
|
||||
* Represents a protected area database that uses CSV files.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class CSVDatabase extends AbstractProtectionDatabase {
|
||||
|
||||
private static final Map<String, StateFlag> legacyFlagCodes = new HashMap<String, StateFlag>();
|
||||
static {
|
||||
legacyFlagCodes.put("z", DefaultFlag.PASSTHROUGH);
|
||||
legacyFlagCodes.put("b", DefaultFlag.BUILD);
|
||||
legacyFlagCodes.put("p", DefaultFlag.PVP);
|
||||
legacyFlagCodes.put("m", DefaultFlag.MOB_DAMAGE);
|
||||
legacyFlagCodes.put("c", DefaultFlag.CREEPER_EXPLOSION);
|
||||
legacyFlagCodes.put("t", DefaultFlag.TNT);
|
||||
legacyFlagCodes.put("l", DefaultFlag.LIGHTER);
|
||||
legacyFlagCodes.put("f", DefaultFlag.FIRE_SPREAD);
|
||||
legacyFlagCodes.put("F", DefaultFlag.LAVA_FIRE);
|
||||
legacyFlagCodes.put("C", DefaultFlag.CHEST_ACCESS);
|
||||
}
|
||||
|
||||
private final Logger logger;
|
||||
|
||||
/**
|
||||
* References the CSV file.
|
||||
*/
|
||||
private final File file;
|
||||
/**
|
||||
* Holds the list of regions.
|
||||
*/
|
||||
private Map<String,ProtectedRegion> regions;
|
||||
|
||||
/**
|
||||
* Construct the database with a path to a file. No file is read or
|
||||
* written at this time.
|
||||
*
|
||||
* @param file The file in CSV format containing the region database
|
||||
* @param logger The logger to log errors to
|
||||
*/
|
||||
public CSVDatabase(File file, Logger logger) {
|
||||
this.file = file;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the database.
|
||||
*/
|
||||
public void save() throws ProtectionDatabaseException {
|
||||
throw new UnsupportedOperationException("CSV format is no longer implemented");
|
||||
}
|
||||
|
||||
public void load() throws ProtectionDatabaseException {
|
||||
Map<String,ProtectedRegion> regions =
|
||||
new HashMap<String,ProtectedRegion>();
|
||||
Map<ProtectedRegion,String> parentSets =
|
||||
new LinkedHashMap<ProtectedRegion, String>();
|
||||
|
||||
CSVReader reader = null;
|
||||
try {
|
||||
reader = new CSVReader(new FileReader(file));
|
||||
|
||||
String[] line;
|
||||
|
||||
while ((line = reader.readNext()) != null) {
|
||||
if (line.length < 2) {
|
||||
logger.warning("Invalid region definition: " + line);
|
||||
continue;
|
||||
}
|
||||
|
||||
String id = line[0].toLowerCase().replace(".", "");
|
||||
String type = line[1];
|
||||
ArrayReader<String> entries = new ArrayReader<String>(line);
|
||||
|
||||
if (type.equalsIgnoreCase("cuboid")) {
|
||||
if (line.length < 8) {
|
||||
logger.warning("Invalid region definition: " + line);
|
||||
continue;
|
||||
}
|
||||
|
||||
Vector pt1 = new Vector(
|
||||
Integer.parseInt(line[2]),
|
||||
Integer.parseInt(line[3]),
|
||||
Integer.parseInt(line[4]));
|
||||
Vector pt2 = new Vector(
|
||||
Integer.parseInt(line[5]),
|
||||
Integer.parseInt(line[6]),
|
||||
Integer.parseInt(line[7]));
|
||||
|
||||
BlockVector min = Vector.getMinimum(pt1, pt2).toBlockVector();
|
||||
BlockVector max = Vector.getMaximum(pt1, pt2).toBlockVector();
|
||||
|
||||
int priority = entries.get(8) == null ? 0 : Integer.parseInt(entries.get(8));
|
||||
String ownersData = entries.get(9);
|
||||
String flagsData = entries.get(10);
|
||||
//String enterMessage = nullEmptyString(entries.get(11));
|
||||
|
||||
ProtectedRegion region = new ProtectedCuboidRegion(id, min, max);
|
||||
region.setPriority(priority);
|
||||
parseFlags(region, flagsData);
|
||||
region.setOwners(this.parseDomains(ownersData));
|
||||
regions.put(id, region);
|
||||
} else if (type.equalsIgnoreCase("cuboid.2")) {
|
||||
Vector pt1 = new Vector(
|
||||
Integer.parseInt(line[2]),
|
||||
Integer.parseInt(line[3]),
|
||||
Integer.parseInt(line[4]));
|
||||
Vector pt2 = new Vector(
|
||||
Integer.parseInt(line[5]),
|
||||
Integer.parseInt(line[6]),
|
||||
Integer.parseInt(line[7]));
|
||||
|
||||
BlockVector min = Vector.getMinimum(pt1, pt2).toBlockVector();
|
||||
BlockVector max = Vector.getMaximum(pt1, pt2).toBlockVector();
|
||||
|
||||
int priority = entries.get(8) == null ? 0 : Integer.parseInt(entries.get(8));
|
||||
String parentId = entries.get(9);
|
||||
String ownersData = entries.get(10);
|
||||
String membersData = entries.get(11);
|
||||
String flagsData = entries.get(12);
|
||||
//String enterMessage = nullEmptyString(entries.get(13));
|
||||
//String leaveMessage = nullEmptyString(entries.get(14));
|
||||
|
||||
ProtectedRegion region = new ProtectedCuboidRegion(id, min, max);
|
||||
region.setPriority(priority);
|
||||
parseFlags(region, flagsData);
|
||||
region.setOwners(this.parseDomains(ownersData));
|
||||
region.setMembers(this.parseDomains(membersData));
|
||||
regions.put(id, region);
|
||||
|
||||
// Link children to parents later
|
||||
if (parentId.length() > 0) {
|
||||
parentSets.put(region, parentId);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ProtectionDatabaseException(e);
|
||||
} finally {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
for (Map.Entry<ProtectedRegion, String> entry : parentSets.entrySet()) {
|
||||
ProtectedRegion parent = regions.get(entry.getValue());
|
||||
if (parent != null) {
|
||||
try {
|
||||
entry.getKey().setParent(parent);
|
||||
} catch (CircularInheritanceException e) {
|
||||
logger.warning("Circular inheritance detect with '"
|
||||
+ entry.getValue() + "' detected as a parent");
|
||||
}
|
||||
} else {
|
||||
logger.warning("Unknown region parent: " + entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
this.regions = regions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to parse the specified domain in the CSV file.
|
||||
*
|
||||
* @param data The domain data as a string
|
||||
* @return The domain data as a DefaultDomain
|
||||
*/
|
||||
private DefaultDomain parseDomains(String data) {
|
||||
if (data == null) {
|
||||
return new DefaultDomain();
|
||||
}
|
||||
|
||||
DefaultDomain domain = new DefaultDomain();
|
||||
Pattern pattern = Pattern.compile("^([A-Za-z]):(.*)$");
|
||||
|
||||
String[] parts = data.split(",");
|
||||
|
||||
for (String part : parts) {
|
||||
if (part.trim().length() == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Matcher matcher = pattern.matcher(part);
|
||||
|
||||
if (!matcher.matches()) {
|
||||
logger.warning("Invalid owner specification: " + part);
|
||||
continue;
|
||||
}
|
||||
|
||||
String type = matcher.group(1);
|
||||
String id = matcher.group(2);
|
||||
|
||||
if (type.equals("u")) {
|
||||
domain.addPlayer(id);
|
||||
} else if (type.equals("g")) {
|
||||
domain.addGroup(id);
|
||||
} else {
|
||||
logger.warning("Unknown owner specification: " + type);
|
||||
}
|
||||
}
|
||||
|
||||
return domain;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to parse the list of flags.
|
||||
*
|
||||
* @param data The flag data in string format
|
||||
*/
|
||||
private void parseFlags(ProtectedRegion region, String data) {
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
State curState = State.ALLOW;
|
||||
|
||||
for (int i = 0; i < data.length(); i++) {
|
||||
char k = data.charAt(i);
|
||||
if (k == '+') {
|
||||
curState = State.ALLOW;
|
||||
} else if (k == '-') {
|
||||
curState = State.DENY;
|
||||
} else {
|
||||
String flagStr;
|
||||
if (k == '_') {
|
||||
if (i == data.length() - 1) {
|
||||
logger.warning("_ read ahead fail");
|
||||
break;
|
||||
}
|
||||
flagStr = "_" + data.charAt(i + 1);
|
||||
i++;
|
||||
|
||||
logger.warning("_? custom flags are no longer supported");
|
||||
continue;
|
||||
} else {
|
||||
flagStr = String.valueOf(k);
|
||||
}
|
||||
|
||||
StateFlag flag = legacyFlagCodes.get(flagStr);
|
||||
if (flag != null) {
|
||||
region.setFlag(flag, curState);
|
||||
} else {
|
||||
logger.warning("Legacy flag '" + flagStr + "' is unsupported");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to write the list of domains.
|
||||
*
|
||||
* @param domain
|
||||
* @return
|
||||
*/
|
||||
/* private String writeDomains(DefaultDomain domain) {
|
||||
StringBuilder str = new StringBuilder();
|
||||
|
||||
for (String player : domain.getPlayers()) {
|
||||
str.append("u:" + player + ",");
|
||||
}
|
||||
|
||||
for (String group : domain.getGroups()) {
|
||||
str.append("g:" + group + ",");
|
||||
}
|
||||
|
||||
return str.length() > 0 ?
|
||||
str.toString().substring(0, str.length() - 1) : "";
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Helper method to prepend '+' or '-' in front of a flag according
|
||||
* to the flag's state.
|
||||
*
|
||||
* @param state
|
||||
* @param flag
|
||||
* @return
|
||||
*/
|
||||
/*
|
||||
private String writeFlag(State state, String flag) {
|
||||
if (state == State.ALLOW) {
|
||||
return "+" + flag;
|
||||
} else if (state == State.DENY) {
|
||||
return "-" + flag;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns a null if a string is null or empty.
|
||||
*
|
||||
* @param str The string to format
|
||||
* @return null if the string is empty or null, otherwise the provided string
|
||||
*/
|
||||
protected String nullEmptyString(String str) {
|
||||
if (str == null) {
|
||||
return null;
|
||||
} else if (str.length() == 0) {
|
||||
return null;
|
||||
} else {
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String,ProtectedRegion> getRegions() {
|
||||
return regions;
|
||||
}
|
||||
|
||||
public void setRegions(Map<String,ProtectedRegion> regions) {
|
||||
this.regions = regions;
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package com.sk89q.worldguard.protection.databases;
|
||||
|
||||
import com.sk89q.worldguard.util.FatalConfigurationLoadingException;
|
||||
|
||||
public class InvalidTableFormatException extends FatalConfigurationLoadingException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
protected String updateFile;
|
||||
|
||||
public InvalidTableFormatException(String updateFile) {
|
||||
super();
|
||||
|
||||
this.updateFile = updateFile;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "You need to update your database to the latest version.\n" +
|
||||
"\t\tPlease see " + this.updateFile;
|
||||
}
|
||||
}
|
||||
+1040
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,72 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.protection.databases;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
/**
|
||||
* Represents a database to read and write lists of regions from and to.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public interface ProtectionDatabase {
|
||||
/**
|
||||
* Load the list of regions. The method should not modify the list returned
|
||||
* by getRegions() unless the load finishes successfully.
|
||||
*
|
||||
* @throws ProtectionDatabaseException when an error occurs
|
||||
*/
|
||||
public void load() throws ProtectionDatabaseException;
|
||||
/**
|
||||
* Save the list of regions.
|
||||
*
|
||||
* @throws ProtectionDatabaseException when an error occurs
|
||||
*/
|
||||
public void save() throws ProtectionDatabaseException;
|
||||
/**
|
||||
* Load the list of regions into a region manager.
|
||||
*
|
||||
* @param manager The manager to load regions into
|
||||
* @throws ProtectionDatabaseException when an error occurs
|
||||
*/
|
||||
public void load(RegionManager manager) throws ProtectionDatabaseException;
|
||||
/**
|
||||
* Save the list of regions from a region manager.
|
||||
*
|
||||
* @param manager The manager to load regions into
|
||||
* @throws ProtectionDatabaseException when an error occurs
|
||||
*/
|
||||
public void save(RegionManager manager) throws ProtectionDatabaseException;
|
||||
/**
|
||||
* Get a list of regions.
|
||||
*
|
||||
* @return the regions loaded by this ProtectionDatabase
|
||||
*/
|
||||
public Map<String,ProtectedRegion> getRegions();
|
||||
/**
|
||||
* Set the list of regions.
|
||||
*
|
||||
* @param regions The regions to be applied to this ProtectionDatabase
|
||||
*/
|
||||
public void setRegions(Map<String,ProtectedRegion> regions);
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard ProtectionDatabaseException
|
||||
* Copyright (C) 2011 Nicholas Steicke <http://narthollis.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.protection.databases;
|
||||
|
||||
import java.lang.Exception;
|
||||
|
||||
public class ProtectionDatabaseException extends Exception {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public ProtectionDatabaseException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ProtectionDatabaseException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ProtectionDatabaseException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public ProtectionDatabaseException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.protection.databases;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.sk89q.worldguard.domains.DefaultDomain;
|
||||
|
||||
/**
|
||||
* Various utility functions for parsing region databases.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class RegionDBUtil {
|
||||
private static Pattern groupPattern = Pattern.compile("(?i)^[G]:(.+)$");
|
||||
|
||||
private RegionDBUtil() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the given names to {@code domain}
|
||||
*
|
||||
* @param domain The domain to add to
|
||||
* @param split The {@link String[]} containing names to add to {@code domain}
|
||||
* @param startIndex The beginning index in the array
|
||||
*/
|
||||
public static void addToDomain(DefaultDomain domain, String[] split,
|
||||
int startIndex) {
|
||||
for (int i = startIndex; i < split.length; i++) {
|
||||
String s = split[i];
|
||||
Matcher m = groupPattern.matcher(s);
|
||||
if (m.matches()) {
|
||||
domain.addGroup(m.group(1));
|
||||
} else {
|
||||
domain.addPlayer(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the given names from {@code domain}
|
||||
*
|
||||
* @param domain The domain to remove from
|
||||
* @param split The {@link String[]} containing names to remove from {@code domain}
|
||||
* @param startIndex The beginning index in the array
|
||||
*/
|
||||
public static void removeFromDomain(DefaultDomain domain, String[] split,
|
||||
int startIndex) {
|
||||
for (int i = startIndex; i < split.length; i++) {
|
||||
String s = split[i];
|
||||
Matcher m = groupPattern.matcher(s);
|
||||
if (m.matches()) {
|
||||
domain.removeGroup(m.group(1));
|
||||
} else {
|
||||
domain.removePlayer(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a group/player DefaultDomain specification for areas.
|
||||
*
|
||||
* @param split The array of names to add
|
||||
* @param startIndex The beginning index in the array
|
||||
* @return The resulting DefaultDomain
|
||||
*/
|
||||
public static DefaultDomain parseDomainString(String[] split, int startIndex) {
|
||||
DefaultDomain domain = new DefaultDomain();
|
||||
|
||||
for (int i = startIndex; i < split.length; i++) {
|
||||
String s = split[i];
|
||||
Matcher m = groupPattern.matcher(s);
|
||||
if (m.matches()) {
|
||||
domain.addGroup(m.group(1));
|
||||
} else {
|
||||
domain.addPlayer(s);
|
||||
}
|
||||
}
|
||||
|
||||
return domain;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a comma separated list of PreparedStatement place holders
|
||||
*
|
||||
* @param length The number of wildcards to create
|
||||
* @return A string with {@code length} wildcards for usage in a PreparedStatement
|
||||
*/
|
||||
public static String preparePlaceHolders(int length) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < length;) {
|
||||
builder.append("?");
|
||||
if (++i < length) {
|
||||
builder.append(",");
|
||||
}
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds all of the parsed values to the PreparedStatement
|
||||
*
|
||||
* @param preparedStatement The preparedStanement to add to
|
||||
* @param values The values to set
|
||||
* @throws SQLException see {@link PreparedStatement#setString(int, String)}
|
||||
*/
|
||||
public static void setValues(PreparedStatement preparedStatement, String... values) throws SQLException {
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
preparedStatement.setString(i + 1, values[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,315 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.protection.databases;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.sk89q.util.yaml.YAMLFormat;
|
||||
import com.sk89q.util.yaml.YAMLNode;
|
||||
import com.sk89q.util.yaml.YAMLProcessor;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.BlockVector2D;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldguard.domains.DefaultDomain;
|
||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
import com.sk89q.worldguard.protection.regions.GlobalProtectedRegion;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion.CircularInheritanceException;
|
||||
|
||||
public class YAMLDatabase extends AbstractProtectionDatabase {
|
||||
|
||||
private YAMLProcessor config;
|
||||
private Map<String, ProtectedRegion> regions;
|
||||
private final Logger logger;
|
||||
|
||||
public YAMLDatabase(File file, Logger logger) throws ProtectionDatabaseException, FileNotFoundException {
|
||||
this.logger = logger;
|
||||
if (!file.exists()) { // shouldn't be necessary, but check anyways
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (IOException e) {
|
||||
throw new FileNotFoundException(file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
config = new YAMLProcessor(file, false, YAMLFormat.COMPACT);
|
||||
}
|
||||
|
||||
public void load() throws ProtectionDatabaseException {
|
||||
try {
|
||||
config.load();
|
||||
} catch (IOException e) {
|
||||
throw new ProtectionDatabaseException(e);
|
||||
}
|
||||
|
||||
Map<String, YAMLNode> regionData = config.getNodes("regions");
|
||||
|
||||
// No regions are even configured
|
||||
if (regionData == null) {
|
||||
this.regions = new HashMap<String, ProtectedRegion>();
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String,ProtectedRegion> regions =
|
||||
new HashMap<String,ProtectedRegion>();
|
||||
Map<ProtectedRegion,String> parentSets =
|
||||
new LinkedHashMap<ProtectedRegion, String>();
|
||||
|
||||
for (Map.Entry<String, YAMLNode> entry : regionData.entrySet()) {
|
||||
String id = entry.getKey().toLowerCase().replace(".", "");
|
||||
YAMLNode node = entry.getValue();
|
||||
|
||||
String type = node.getString("type");
|
||||
ProtectedRegion region;
|
||||
|
||||
try {
|
||||
if (type == null) {
|
||||
logger.warning("Undefined region type for region '" + id + '"');
|
||||
continue;
|
||||
} else if (type.equals("cuboid")) {
|
||||
Vector pt1 = checkNonNull(node.getVector("min"));
|
||||
Vector pt2 = checkNonNull(node.getVector("max"));
|
||||
BlockVector min = Vector.getMinimum(pt1, pt2).toBlockVector();
|
||||
BlockVector max = Vector.getMaximum(pt1, pt2).toBlockVector();
|
||||
region = new ProtectedCuboidRegion(id, min, max);
|
||||
} else if (type.equals("poly2d")) {
|
||||
Integer minY = checkNonNull(node.getInt("min-y"));
|
||||
Integer maxY = checkNonNull(node.getInt("max-y"));
|
||||
List<BlockVector2D> points = node.getBlockVector2dList("points", null);
|
||||
region = new ProtectedPolygonalRegion(id, points, minY, maxY);
|
||||
} else if (type.equals("global")) {
|
||||
region = new GlobalProtectedRegion(id);
|
||||
} else {
|
||||
logger.warning("Unknown region type for region '" + id + '"');
|
||||
continue;
|
||||
}
|
||||
|
||||
Integer priority = checkNonNull(node.getInt("priority"));
|
||||
region.setPriority(priority);
|
||||
setFlags(region, node.getNode("flags"));
|
||||
region.setOwners(parseDomain(node.getNode("owners")));
|
||||
region.setMembers(parseDomain(node.getNode("members")));
|
||||
regions.put(id, region);
|
||||
|
||||
String parentId = node.getString("parent");
|
||||
if (parentId != null) {
|
||||
parentSets.put(region, parentId);
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
logger.warning("Missing data for region '" + id + '"');
|
||||
}
|
||||
}
|
||||
|
||||
// Relink parents
|
||||
for (Map.Entry<ProtectedRegion, String> entry : parentSets.entrySet()) {
|
||||
ProtectedRegion parent = regions.get(entry.getValue());
|
||||
if (parent != null) {
|
||||
try {
|
||||
entry.getKey().setParent(parent);
|
||||
} catch (CircularInheritanceException e) {
|
||||
logger.warning("Circular inheritance detect with '"
|
||||
+ entry.getValue() + "' detected as a parent");
|
||||
}
|
||||
} else {
|
||||
logger.warning("Unknown region parent: " + entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
this.regions = regions;
|
||||
}
|
||||
|
||||
private <V> V checkNonNull(V val) throws NullPointerException {
|
||||
if (val == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
private void setFlags(ProtectedRegion region, YAMLNode flagsData) {
|
||||
if (flagsData == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// @TODO: Make this better
|
||||
for (Flag<?> flag : DefaultFlag.getFlags()) {
|
||||
Object o = flagsData.getProperty(flag.getName());
|
||||
if (o != null) {
|
||||
setFlag(region, flag, o);
|
||||
}
|
||||
|
||||
if (flag.getRegionGroupFlag() != null) {
|
||||
Object o2 = flagsData.getProperty(flag.getRegionGroupFlag().getName());
|
||||
if (o2 != null) {
|
||||
setFlag(region, flag.getRegionGroupFlag(), o2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private <T> void setFlag(ProtectedRegion region, Flag<T> flag, Object rawValue) {
|
||||
T val = flag.unmarshal(rawValue);
|
||||
if (val == null) {
|
||||
logger.warning("Failed to parse flag '" + flag.getName()
|
||||
+ "' with value '" + rawValue.toString() + "'");
|
||||
return;
|
||||
}
|
||||
region.setFlag(flag, val);
|
||||
}
|
||||
|
||||
private DefaultDomain parseDomain(YAMLNode node) {
|
||||
if (node == null) {
|
||||
return new DefaultDomain();
|
||||
}
|
||||
|
||||
DefaultDomain domain = new DefaultDomain();
|
||||
|
||||
for (String name : node.getStringList("players", null)) {
|
||||
domain.addPlayer(name);
|
||||
}
|
||||
|
||||
for (String name : node.getStringList("groups", null)) {
|
||||
domain.addGroup(name);
|
||||
}
|
||||
|
||||
return domain;
|
||||
}
|
||||
|
||||
public void save() throws ProtectionDatabaseException {
|
||||
config.clear();
|
||||
|
||||
for (Map.Entry<String, ProtectedRegion> entry : regions.entrySet()) {
|
||||
ProtectedRegion region = entry.getValue();
|
||||
YAMLNode node = config.addNode("regions." + entry.getKey());
|
||||
|
||||
if (region instanceof ProtectedCuboidRegion) {
|
||||
ProtectedCuboidRegion cuboid = (ProtectedCuboidRegion) region;
|
||||
node.setProperty("type", "cuboid");
|
||||
node.setProperty("min", cuboid.getMinimumPoint());
|
||||
node.setProperty("max", cuboid.getMaximumPoint());
|
||||
} else if (region instanceof ProtectedPolygonalRegion) {
|
||||
ProtectedPolygonalRegion poly = (ProtectedPolygonalRegion) region;
|
||||
node.setProperty("type", "poly2d");
|
||||
node.setProperty("min-y", poly.getMinimumPoint().getBlockY());
|
||||
node.setProperty("max-y", poly.getMaximumPoint().getBlockY());
|
||||
|
||||
List<Map<String, Object>> points = new ArrayList<Map<String,Object>>();
|
||||
for (BlockVector2D point : poly.getPoints()) {
|
||||
Map<String, Object> data = new HashMap<String, Object>();
|
||||
data.put("x", point.getBlockX());
|
||||
data.put("z", point.getBlockZ());
|
||||
points.add(data);
|
||||
}
|
||||
|
||||
node.setProperty("points", points);
|
||||
} else if (region instanceof GlobalProtectedRegion) {
|
||||
node.setProperty("type", "global");
|
||||
} else {
|
||||
node.setProperty("type", region.getClass().getCanonicalName());
|
||||
}
|
||||
|
||||
node.setProperty("priority", region.getPriority());
|
||||
node.setProperty("flags", getFlagData(region));
|
||||
node.setProperty("owners", getDomainData(region.getOwners()));
|
||||
node.setProperty("members", getDomainData(region.getMembers()));
|
||||
ProtectedRegion parent = region.getParent();
|
||||
if (parent != null) {
|
||||
node.setProperty("parent", parent.getId());
|
||||
}
|
||||
}
|
||||
|
||||
config.setHeader("#\r\n" +
|
||||
"# WorldGuard regions file\r\n" +
|
||||
"#\r\n" +
|
||||
"# WARNING: THIS FILE IS AUTOMATICALLY GENERATED. If you modify this file by\r\n" +
|
||||
"# hand, be aware that A SINGLE MISTYPED CHARACTER CAN CORRUPT THE FILE. If\r\n" +
|
||||
"# WorldGuard is unable to parse the file, your regions will FAIL TO LOAD and\r\n" +
|
||||
"# the contents of this file will reset. Please use a YAML validator such as\r\n" +
|
||||
"# http://yaml-online-parser.appspot.com (for smaller files).\r\n" +
|
||||
"#\r\n" +
|
||||
"# REMEMBER TO KEEP PERIODICAL BACKUPS.\r\n" +
|
||||
"#");
|
||||
config.save();
|
||||
}
|
||||
|
||||
private Map<String, Object> getFlagData(ProtectedRegion region) {
|
||||
Map<String, Object> flagData = new HashMap<String, Object>();
|
||||
|
||||
for (Map.Entry<Flag<?>, Object> entry : region.getFlags().entrySet()) {
|
||||
Flag<?> flag = entry.getKey();
|
||||
addMarshalledFlag(flagData, flag, entry.getValue());
|
||||
}
|
||||
|
||||
return flagData;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <V> void addMarshalledFlag(Map<String, Object> flagData,
|
||||
Flag<V> flag, Object val) {
|
||||
if (val == null) {
|
||||
return;
|
||||
}
|
||||
flagData.put(flag.getName(), flag.marshal((V) val));
|
||||
}
|
||||
|
||||
private Map<String, Object> getDomainData(DefaultDomain domain) {
|
||||
Map<String, Object> domainData = new HashMap<String, Object>();
|
||||
|
||||
setDomainData(domainData, "players", domain.getPlayers());
|
||||
setDomainData(domainData, "groups", domain.getGroups());
|
||||
|
||||
return domainData;
|
||||
}
|
||||
|
||||
private void setDomainData(Map<String, Object> domainData,
|
||||
String key, Set<String> domain) {
|
||||
if (domain.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> list = new ArrayList<String>();
|
||||
|
||||
for (String str : domain) {
|
||||
list.add(str);
|
||||
}
|
||||
|
||||
domainData.put(key, list);
|
||||
}
|
||||
|
||||
public Map<String, ProtectedRegion> getRegions() {
|
||||
return regions;
|
||||
}
|
||||
|
||||
public void setRegions(Map<String, ProtectedRegion> regions) {
|
||||
this.regions = regions;
|
||||
}
|
||||
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
// $Id$
|
||||
/*
|
||||
* MySQL WordGuard Region Database
|
||||
* Copyright (C) 2011 Nicholas Steicke <http://narthollis.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.protection.databases.migrators;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.sk89q.worldguard.protection.databases.ProtectionDatabase;
|
||||
import com.sk89q.worldguard.protection.databases.ProtectionDatabaseException;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
public abstract class AbstractDatabaseMigrator implements DatabaseMigrator {
|
||||
|
||||
private static HashMap<MigratorKey, Class<? extends AbstractDatabaseMigrator>> migrators =
|
||||
new HashMap<MigratorKey, Class<? extends AbstractDatabaseMigrator>>();
|
||||
|
||||
public static Map<MigratorKey, Class<? extends AbstractDatabaseMigrator>> getMigrators() {
|
||||
if (!migrators.isEmpty()) return migrators;
|
||||
|
||||
AbstractDatabaseMigrator.migrators.put(new MigratorKey("mysql", "yaml"), MySQLToYAMLMigrator.class);
|
||||
AbstractDatabaseMigrator.migrators.put(new MigratorKey("yaml", "mysql"), YAMLToMySQLMigrator.class);
|
||||
|
||||
return migrators;
|
||||
}
|
||||
|
||||
protected abstract Set<String> getWorldsFromOld() throws MigrationException;
|
||||
|
||||
protected abstract Map<String, ProtectedRegion> getRegionsForWorldFromOld(String world) throws MigrationException;
|
||||
|
||||
protected abstract ProtectionDatabase getNewWorldStorage(String world) throws MigrationException;
|
||||
|
||||
public void migrate() throws MigrationException {
|
||||
for (String world : this.getWorldsFromOld()) {
|
||||
ProtectionDatabase database = this.getNewWorldStorage(world);
|
||||
database.setRegions(this.getRegionsForWorldFromOld(world));
|
||||
|
||||
try {
|
||||
database.save();
|
||||
} catch (ProtectionDatabaseException e) {
|
||||
throw new MigrationException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
// $Id$
|
||||
/*
|
||||
* MySQL WordGuard Region Database
|
||||
* Copyright (C) 2011 Nicholas Steicke <http://narthollis.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.protection.databases.migrators;
|
||||
|
||||
/**
|
||||
* Represents a method of converting from one database to another.
|
||||
*
|
||||
* @author Nicholas Steicke
|
||||
*/
|
||||
public interface DatabaseMigrator {
|
||||
|
||||
public void migrate() throws MigrationException;
|
||||
}
|
||||
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
// $Id$
|
||||
/*
|
||||
* MySQL WordGuard Region Database
|
||||
* Copyright (C) 2011 Nicholas Steicke <http://narthollis.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.protection.databases.migrators;
|
||||
|
||||
public class MigrationException extends Exception {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public MigrationException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public MigrationException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public MigrationException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public MigrationException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
// $Id$
|
||||
/*
|
||||
* MySQL WordGuard Region Database
|
||||
* Copyright (C) 2011 Nicholas Steicke <http://narthollis.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.protection.databases.migrators;
|
||||
|
||||
public class MigratorKey {
|
||||
public final String from;
|
||||
public final String to;
|
||||
|
||||
public MigratorKey(String from, String to) {
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
MigratorKey other = (MigratorKey) o;
|
||||
|
||||
return other.from.equals(this.from) && other.to.equals(this.to);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int hash = 17;
|
||||
hash = hash * 31 + this.from.hashCode();
|
||||
hash = hash * 31 + this.to.hashCode();
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
// $Id$
|
||||
/*
|
||||
* MySQL WordGuard Region Database
|
||||
* Copyright (C) 2011 Nicholas Steicke <http://narthollis.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.protection.databases.migrators;
|
||||
|
||||
import com.sk89q.worldguard.bukkit.ConfigurationManager;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.protection.databases.MySQLDatabase;
|
||||
import com.sk89q.worldguard.protection.databases.ProtectionDatabase;
|
||||
import com.sk89q.worldguard.protection.databases.ProtectionDatabaseException;
|
||||
import com.sk89q.worldguard.protection.databases.YAMLDatabase;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class MySQLToYAMLMigrator extends AbstractDatabaseMigrator {
|
||||
|
||||
private WorldGuardPlugin plugin;
|
||||
private Set<String> worlds;
|
||||
|
||||
public MySQLToYAMLMigrator(WorldGuardPlugin plugin) throws MigrationException {
|
||||
this.plugin = plugin;
|
||||
this.worlds = new HashSet<String>();
|
||||
|
||||
ConfigurationManager config = plugin.getGlobalStateManager();
|
||||
|
||||
try {
|
||||
Connection conn = DriverManager.getConnection(config.sqlDsn, config.sqlUsername, config.sqlPassword);
|
||||
|
||||
ResultSet worlds = conn.prepareStatement("SELECT `name` FROM `world`;").executeQuery();
|
||||
|
||||
while(worlds.next()) {
|
||||
this.worlds.add(worlds.getString(1));
|
||||
}
|
||||
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
throw new MigrationException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<String> getWorldsFromOld() {
|
||||
return this.worlds;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, ProtectedRegion> getRegionsForWorldFromOld(String world) throws MigrationException {
|
||||
ProtectionDatabase oldDatabase;
|
||||
try {
|
||||
oldDatabase = new MySQLDatabase(plugin.getGlobalStateManager(), world, plugin.getLogger());
|
||||
oldDatabase.load();
|
||||
} catch (ProtectionDatabaseException e) {
|
||||
throw new MigrationException(e);
|
||||
}
|
||||
|
||||
return oldDatabase.getRegions();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ProtectionDatabase getNewWorldStorage(String world) throws MigrationException {
|
||||
try {
|
||||
File file = new File(plugin.getDataFolder(),
|
||||
"worlds" + File.separator + world + File.separator + "regions.yml");
|
||||
|
||||
return new YAMLDatabase(file, plugin.getLogger());
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new MigrationException(e);
|
||||
} catch (ProtectionDatabaseException e) {
|
||||
throw new MigrationException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
// $Id$
|
||||
/*
|
||||
* MySQL WordGuard Region Database
|
||||
* Copyright (C) 2011 Nicholas Steicke <http://narthollis.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.protection.databases.migrators;
|
||||
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.protection.databases.MySQLDatabase;
|
||||
import com.sk89q.worldguard.protection.databases.ProtectionDatabase;
|
||||
import com.sk89q.worldguard.protection.databases.ProtectionDatabaseException;
|
||||
import com.sk89q.worldguard.protection.databases.YAMLDatabase;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class YAMLToMySQLMigrator extends AbstractDatabaseMigrator {
|
||||
|
||||
private WorldGuardPlugin plugin;
|
||||
private HashMap<String,File> regionYamlFiles;
|
||||
|
||||
public YAMLToMySQLMigrator(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
this.regionYamlFiles = new HashMap<String,File>();
|
||||
|
||||
File files[] = new File(plugin.getDataFolder(), "worlds" + File.separator).listFiles();
|
||||
for (File item : files) {
|
||||
if (item.isDirectory()) {
|
||||
for (File subItem : item.listFiles()) {
|
||||
if (subItem.getName().equals("regions.yml")) {
|
||||
this.regionYamlFiles.put(item.getName(), subItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<String> getWorldsFromOld() {
|
||||
return this.regionYamlFiles.keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, ProtectedRegion> getRegionsForWorldFromOld(String world) throws MigrationException {
|
||||
ProtectionDatabase oldDatabase;
|
||||
try {
|
||||
oldDatabase = new YAMLDatabase(this.regionYamlFiles.get(world), plugin.getLogger());
|
||||
oldDatabase.load();
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new MigrationException(e);
|
||||
} catch (ProtectionDatabaseException e) {
|
||||
throw new MigrationException(e);
|
||||
}
|
||||
|
||||
return oldDatabase.getRegions();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ProtectionDatabase getNewWorldStorage(String world) throws MigrationException {
|
||||
try {
|
||||
return new MySQLDatabase(plugin.getGlobalStateManager(), world, plugin.getLogger());
|
||||
} catch (ProtectionDatabaseException e) {
|
||||
throw new MigrationException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.protection.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
|
||||
/**
|
||||
* This event is fired when PVP is disallowed between players due to a "pvp deny" flag.
|
||||
* Cancelling this event allows the PVP in spite of this.
|
||||
*
|
||||
* @author Score_Under
|
||||
*/
|
||||
public class DisallowedPVPEvent extends Event implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private boolean cancelled = false;
|
||||
private final Player attacker;
|
||||
private final Player defender;
|
||||
private final EntityDamageByEntityEvent event;
|
||||
|
||||
public DisallowedPVPEvent(final Player attacker, final Player defender, EntityDamageByEntityEvent event) {
|
||||
this.attacker = attacker;
|
||||
this.defender = defender;
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the attacking player.
|
||||
*/
|
||||
public Player getAttacker() {
|
||||
return attacker;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the defending player.
|
||||
*/
|
||||
public Player getDefender() {
|
||||
return defender;
|
||||
}
|
||||
|
||||
public EntityDamageByEntityEvent getCause() {
|
||||
return event;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.sk89q.worldguard.protection.flags;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class BooleanFlag extends Flag<Boolean> {
|
||||
|
||||
public BooleanFlag(String name, RegionGroup defaultGroup) {
|
||||
super(name, defaultGroup);
|
||||
}
|
||||
|
||||
public BooleanFlag(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean parseInput(WorldGuardPlugin plugin, CommandSender sender,
|
||||
String input) throws InvalidFlagFormat {
|
||||
input = input.trim();
|
||||
|
||||
if (input.equalsIgnoreCase("true") || input.equalsIgnoreCase("yes")
|
||||
|| input.equalsIgnoreCase("on")
|
||||
|| input.equalsIgnoreCase("1")) {
|
||||
return true;
|
||||
} else if (input.equalsIgnoreCase("false") || input.equalsIgnoreCase("no")
|
||||
|| input.equalsIgnoreCase("off")
|
||||
|| input.equalsIgnoreCase("0")) {
|
||||
return false;
|
||||
} else {
|
||||
throw new InvalidFlagFormat("Not a yes/no value: " + input);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean unmarshal(Object o) {
|
||||
if (o instanceof Boolean) {
|
||||
return (Boolean) o;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object marshal(Boolean o) {
|
||||
return o;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.sk89q.worldguard.protection.flags;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class CommandStringFlag extends Flag<String> {
|
||||
|
||||
public CommandStringFlag(String name, RegionGroup defaultGroup) {
|
||||
super(name, defaultGroup);
|
||||
}
|
||||
|
||||
public CommandStringFlag(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String parseInput(WorldGuardPlugin plugin, CommandSender sender,
|
||||
String input) throws InvalidFlagFormat {
|
||||
input = input.trim();
|
||||
if (!input.startsWith("/")) {
|
||||
input = "/" + input;
|
||||
}
|
||||
return input.toLowerCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String unmarshal(Object o) {
|
||||
if (o instanceof String) {
|
||||
return (String) o;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object marshal(String o) {
|
||||
return o;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.protection.flags;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public final class DefaultFlag {
|
||||
|
||||
public static final StateFlag PASSTHROUGH = new StateFlag("passthrough", false, RegionGroup.ALL);
|
||||
public static final StateFlag BUILD = new StateFlag("build", true, RegionGroup.NON_MEMBERS);
|
||||
public static final RegionGroupFlag CONSTRUCT = new RegionGroupFlag("construct", RegionGroup.MEMBERS);
|
||||
public static final StateFlag PVP = new StateFlag("pvp", true, RegionGroup.ALL);
|
||||
public static final StateFlag MOB_DAMAGE = new StateFlag("mob-damage", true, RegionGroup.ALL);
|
||||
public static final StateFlag MOB_SPAWNING = new StateFlag("mob-spawning", true, RegionGroup.ALL);
|
||||
public static final StateFlag CREEPER_EXPLOSION = new StateFlag("creeper-explosion", true, RegionGroup.ALL);
|
||||
public static final StateFlag ENDERDRAGON_BLOCK_DAMAGE = new StateFlag("enderdragon-block-damage", true);
|
||||
public static final StateFlag GHAST_FIREBALL = new StateFlag("ghast-fireball", true, RegionGroup.ALL);
|
||||
public static final StateFlag OTHER_EXPLOSION = new StateFlag("other-explosion", true);
|
||||
public static final StateFlag SLEEP = new StateFlag("sleep", true);
|
||||
public static final StateFlag TNT = new StateFlag("tnt", true, RegionGroup.ALL);
|
||||
public static final StateFlag LIGHTER = new StateFlag("lighter", true, RegionGroup.ALL);
|
||||
public static final StateFlag FIRE_SPREAD = new StateFlag("fire-spread", true);
|
||||
public static final StateFlag LAVA_FIRE = new StateFlag("lava-fire", true);
|
||||
public static final StateFlag LIGHTNING = new StateFlag("lightning", true);
|
||||
public static final StateFlag CHEST_ACCESS = new StateFlag("chest-access", false);
|
||||
public static final StateFlag WATER_FLOW = new StateFlag("water-flow", true);
|
||||
public static final StateFlag LAVA_FLOW = new StateFlag("lava-flow", true);
|
||||
public static final StateFlag USE = new StateFlag("use", true);
|
||||
public static final StateFlag PLACE_VEHICLE = new StateFlag("vehicle-place", false);
|
||||
public static final StateFlag DESTROY_VEHICLE = new StateFlag("vehicle-destroy", false);
|
||||
public static final StateFlag PISTONS = new StateFlag("pistons", true);
|
||||
public static final StateFlag SNOW_FALL = new StateFlag("snow-fall", true);
|
||||
public static final StateFlag SNOW_MELT = new StateFlag("snow-melt", true);
|
||||
public static final StateFlag ICE_FORM = new StateFlag("ice-form", true);
|
||||
public static final StateFlag ICE_MELT = new StateFlag("ice-melt", true);
|
||||
public static final StateFlag MUSHROOMS = new StateFlag("mushroom-growth", true);
|
||||
public static final StateFlag LEAF_DECAY = new StateFlag("leaf-decay", true);
|
||||
public static final StateFlag GRASS_SPREAD = new StateFlag("grass-growth", true);
|
||||
public static final StateFlag MYCELIUM_SPREAD = new StateFlag("mycelium-spread", true);
|
||||
public static final StateFlag ENDER_BUILD = new StateFlag("enderman-grief", true);
|
||||
public static final StateFlag INVINCIBILITY = new StateFlag("invincible", false, RegionGroup.ALL);
|
||||
public static final StateFlag EXP_DROPS = new StateFlag("exp-drops", true, RegionGroup.ALL);
|
||||
public static final StateFlag SEND_CHAT = new StateFlag("send-chat", true);
|
||||
public static final StateFlag RECEIVE_CHAT = new StateFlag("receive-chat", true);
|
||||
public static final StateFlag ENTRY = new StateFlag("entry", true);
|
||||
public static final StateFlag EXIT = new StateFlag("exit", true);
|
||||
public static final StateFlag ITEM_DROP = new StateFlag("item-drop", true);
|
||||
public static final StateFlag ENDERPEARL = new StateFlag("enderpearl", true);
|
||||
public static final StateFlag ENTITY_PAINTING_DESTROY = new StateFlag("entity-painting-destroy", true);
|
||||
public static final StateFlag ENTITY_ITEM_FRAME_DESTROY = new StateFlag("entity-item-frame-destroy", true);
|
||||
public static final StateFlag POTION_SPLASH = new StateFlag("potion-splash", true);
|
||||
public static final StringFlag GREET_MESSAGE = new StringFlag("greeting", RegionGroup.ALL);
|
||||
public static final StringFlag FAREWELL_MESSAGE = new StringFlag("farewell", RegionGroup.ALL);
|
||||
public static final BooleanFlag NOTIFY_ENTER = new BooleanFlag("notify-enter", RegionGroup.ALL);
|
||||
public static final BooleanFlag NOTIFY_LEAVE = new BooleanFlag("notify-leave", RegionGroup.ALL);
|
||||
public static final SetFlag<EntityType> DENY_SPAWN = new SetFlag<EntityType>("deny-spawn", RegionGroup.ALL, new EntityTypeFlag(null));
|
||||
public static final EnumFlag<GameMode> GAME_MODE = new EnumFlag<GameMode>("game-mode", GameMode.class, RegionGroup.ALL);
|
||||
public static final IntegerFlag HEAL_DELAY = new IntegerFlag("heal-delay", RegionGroup.ALL);
|
||||
public static final IntegerFlag HEAL_AMOUNT = new IntegerFlag("heal-amount", RegionGroup.ALL);
|
||||
public static final IntegerFlag MIN_HEAL = new IntegerFlag("heal-min-health", RegionGroup.ALL);
|
||||
public static final IntegerFlag MAX_HEAL = new IntegerFlag("heal-max-health", RegionGroup.ALL);
|
||||
public static final IntegerFlag FEED_DELAY = new IntegerFlag("feed-delay", RegionGroup.ALL);
|
||||
public static final IntegerFlag FEED_AMOUNT = new IntegerFlag("feed-amount", RegionGroup.ALL);
|
||||
public static final IntegerFlag MIN_FOOD = new IntegerFlag("feed-min-hunger", RegionGroup.ALL);
|
||||
public static final IntegerFlag MAX_FOOD = new IntegerFlag("feed-max-hunger", RegionGroup.ALL);
|
||||
// public static final IntegerFlag MAX_PLAYERS = new IntegerFlag("max-players-allowed", RegionGroup.ALL);
|
||||
// public static final StringFlag MAX_PLAYERS_MESSAGE = new StringFlag("max-players-reject-message", RegionGroup.ALL);
|
||||
public static final LocationFlag TELE_LOC = new LocationFlag("teleport", RegionGroup.MEMBERS);
|
||||
public static final LocationFlag SPAWN_LOC = new LocationFlag("spawn", RegionGroup.MEMBERS);
|
||||
public static final BooleanFlag BUYABLE = new BooleanFlag("buyable");
|
||||
public static final DoubleFlag PRICE = new DoubleFlag("price");
|
||||
public static final SetFlag<String> BLOCKED_CMDS = new SetFlag<String>("blocked-cmds", RegionGroup.ALL, new CommandStringFlag(null));
|
||||
public static final SetFlag<String> ALLOWED_CMDS = new SetFlag<String>("allowed-cmds", RegionGroup.ALL, new CommandStringFlag(null));
|
||||
|
||||
public static final Flag<?>[] flagsList = new Flag<?>[] {
|
||||
PASSTHROUGH, BUILD, CONSTRUCT, PVP, CHEST_ACCESS, PISTONS,
|
||||
TNT, LIGHTER, USE, PLACE_VEHICLE, DESTROY_VEHICLE, SLEEP,
|
||||
MOB_DAMAGE, MOB_SPAWNING, DENY_SPAWN, INVINCIBILITY, EXP_DROPS,
|
||||
CREEPER_EXPLOSION, OTHER_EXPLOSION, ENDERDRAGON_BLOCK_DAMAGE, GHAST_FIREBALL, ENDER_BUILD,
|
||||
GREET_MESSAGE, FAREWELL_MESSAGE, NOTIFY_ENTER, NOTIFY_LEAVE,
|
||||
EXIT, ENTRY, LIGHTNING, ENTITY_PAINTING_DESTROY, ENDERPEARL,
|
||||
ENTITY_ITEM_FRAME_DESTROY, ITEM_DROP, /*MAX_PLAYERS, MAX_PLAYERS_MESSAGE,*/
|
||||
HEAL_AMOUNT, HEAL_DELAY, MIN_HEAL, MAX_HEAL,
|
||||
FEED_DELAY, FEED_AMOUNT, MIN_FOOD, MAX_FOOD,
|
||||
SNOW_FALL, SNOW_MELT, ICE_FORM, ICE_MELT, GAME_MODE,
|
||||
MUSHROOMS, LEAF_DECAY, GRASS_SPREAD, MYCELIUM_SPREAD, SEND_CHAT,
|
||||
RECEIVE_CHAT, FIRE_SPREAD, LAVA_FIRE, LAVA_FLOW, WATER_FLOW,
|
||||
TELE_LOC, SPAWN_LOC, POTION_SPLASH,
|
||||
BLOCKED_CMDS, ALLOWED_CMDS, PRICE, BUYABLE,
|
||||
};
|
||||
|
||||
|
||||
private DefaultFlag() {
|
||||
}
|
||||
|
||||
public static Flag<?>[] getFlags() {
|
||||
return flagsList;
|
||||
}
|
||||
}
|
||||
Loaded 100 of 144 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user