Compare commits
431
Commits
5.1
...
feature/six
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ee2ed762c2 | ||
|
|
a0dceaa713 | ||
|
|
4b15855b2f | ||
|
|
7acfb3586c | ||
|
|
a841aa7215 | ||
|
|
f752c305d7 | ||
|
|
840700b719 | ||
|
|
8f73a15ba3 | ||
|
|
4e008f6c52 | ||
|
|
df54d4de91 | ||
|
|
0768e08e71 | ||
|
|
040e35f65b | ||
|
|
919c03a57b | ||
|
|
a13f556c7b | ||
|
|
5bfb9e48f4 | ||
|
|
ff209abb8c | ||
|
|
7987258fe2 | ||
|
|
4cba9d01ec | ||
|
|
e703999c8f | ||
|
|
bfc8691118 | ||
|
|
061b303faa | ||
|
|
3b985f7eab | ||
|
|
a027721f37 | ||
|
|
129412ba79 | ||
|
|
e0ab79bd36 | ||
|
|
28a1f225ee | ||
|
|
355168a3ac | ||
|
|
27c6819df9 | ||
|
|
122c1aa003 | ||
|
|
644d6ee512 | ||
|
|
58cc4392c8 | ||
|
|
e228315dfd | ||
|
|
8a308cd521 | ||
|
|
c3d3c1812f | ||
|
|
cc5958bc2f | ||
|
|
2d8911c9ce | ||
|
|
c6a0c61028 | ||
|
|
0c0cbcc1b0 | ||
|
|
5882e30357 | ||
|
|
4faf0a9b2e | ||
|
|
2e4093e953 | ||
|
|
1a9a3274a6 | ||
|
|
8671fbc396 | ||
|
|
50c4b3c738 | ||
|
|
23f0791231 | ||
|
|
fa11dd6d62 | ||
|
|
58fa6d1c0b | ||
|
|
723f17b782 | ||
|
|
fe2e399451 | ||
|
|
6fa7faad12 | ||
|
|
c864a1c252 | ||
|
|
386288b89a | ||
|
|
b3425b2630 | ||
|
|
f8105c3de0 | ||
|
|
bcf35085ed | ||
|
|
b7064cb102 | ||
|
|
6c282cfe0a | ||
|
|
f8e0410d23 | ||
|
|
e8274e76ca | ||
|
|
393b15ac7a | ||
|
|
38f40908ee | ||
|
|
caee1df596 | ||
|
|
d9d655b6b2 | ||
|
|
cc9bbec1c9 | ||
|
|
2a504ffbde | ||
|
|
5f11c5710b | ||
|
|
5d3409be57 | ||
|
|
ad921a2111 | ||
|
|
50ec8e5875 | ||
|
|
fc9e28ddb9 | ||
|
|
35e02459ea | ||
|
|
0781ebc289 | ||
|
|
915e332a6b | ||
|
|
19859164ab | ||
|
|
bb7f972897 | ||
|
|
e355bb0055 | ||
|
|
9b1b665da7 | ||
|
|
6daf80229d | ||
|
|
dc1f3f54b1 | ||
|
|
579143a5dd | ||
|
|
f4e52f5cd7 | ||
|
|
abea9689cb | ||
|
|
2c7767f89f | ||
|
|
5e75bf36c3 | ||
|
|
a5814c4b32 | ||
|
|
70ae1c46a2 | ||
|
|
fc5c59ec85 | ||
|
|
2d9a28b0e6 | ||
|
|
cbcc524798 | ||
|
|
69940f2fac | ||
|
|
35628d09be | ||
|
|
ef43ba2700 | ||
|
|
2c2484b026 | ||
|
|
b181bfc914 | ||
|
|
7fcf686d8d | ||
|
|
4f5a751519 | ||
|
|
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 | ||
|
|
3b4c58b721 | ||
|
|
69af41f1e5 | ||
|
|
7074963fb1 |
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
|
||||
+227
@@ -1,3 +1,230 @@
|
||||
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.
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
+204
-88
@@ -1,116 +1,232 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>WorldGuard ${version}</title>
|
||||
<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: 20px;
|
||||
background: #efefef;
|
||||
color: #333;
|
||||
margin: 0;
|
||||
padding: 3em 1em;
|
||||
background: #efefef;
|
||||
color: #333;
|
||||
line-height: 1.5;
|
||||
}
|
||||
#wrapper {
|
||||
margin: 20px auto 20px auto;
|
||||
width: 600px;
|
||||
background: #fff;
|
||||
padding: 40px;
|
||||
border: 1px solid #fff;
|
||||
border-radius: 10px;
|
||||
-moz-border-radius: 10px;
|
||||
-webkit-border-radius: 10px;
|
||||
box-shadow: 0 0 2px #999;
|
||||
-webkit-box-shadow: 0 0 3px #999;
|
||||
}
|
||||
a img {
|
||||
border: 0;
|
||||
width: 600px;
|
||||
margin: auto;
|
||||
}
|
||||
body, th, td, input {
|
||||
font: 13px/17px "Lucida Grande", "Lucida Sans Unicode", Arial, Verdana, sans-serif;
|
||||
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: #00688f;
|
||||
text-decoration: underline;
|
||||
color: #0004b2;
|
||||
text-decoration: none;
|
||||
}
|
||||
a:hover, a:active {
|
||||
color: #000;
|
||||
border: 0;
|
||||
a:hover {
|
||||
color: #ac0000;
|
||||
text-decoration: none;
|
||||
border-bottom: 1px solid #999;
|
||||
}
|
||||
h1 {
|
||||
font: 170% "Trebuchet MS", Georgia, serif;
|
||||
font-weight: bold;
|
||||
color: #b90000;
|
||||
margin: 15px 0 5px 0;
|
||||
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: 130% "Trebuchet MS", Georgia, serif;
|
||||
font-weight: bold;
|
||||
color: #6a45ac;
|
||||
margin: 50px 0 5px 0;
|
||||
padding: 0 0 3px 0;
|
||||
border-bottom: 1px solid #ccc;
|
||||
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;
|
||||
}
|
||||
.warning {
|
||||
background: #fffedf;
|
||||
padding: 8px;
|
||||
border: 1px dashed #ccc;
|
||||
border-radius: 4px;
|
||||
-moz-border-radius: 4px;
|
||||
-webkit-border-radius: 4px;
|
||||
font-size: 90%;
|
||||
h3 {
|
||||
text-transform: uppercase;
|
||||
font-weight: bold;
|
||||
}
|
||||
.subtle {
|
||||
color: #999;
|
||||
h2 + * {
|
||||
clear: both;
|
||||
}
|
||||
.optional {
|
||||
background: none repeat scroll 0 0 #FFE081;
|
||||
border-radius: 3px 3px 3px 3px;
|
||||
font-size: 80%;
|
||||
font-weight: normal;
|
||||
padding: 1px 4px;
|
||||
@media (max-width: 650px) {
|
||||
#wrapper {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="wrapper">
|
||||
|
||||
<h1>WorldGuard ${version}</h1>
|
||||
<p>Thanks for choosing WorldGuard!</p>
|
||||
<h2>First Steps</h2>
|
||||
|
||||
<p>Now, to begin, you want to:</p>
|
||||
<ol>
|
||||
<li><strong>Install the plugin:</strong> Copy WorldGuard.jar into your Bukkit server's "plugins" directory.</li>
|
||||
<li><strong>Change the configuration:</strong> Run your server once (with WorldGuard) to generate the default configuration files. There are <em>two</em> types of configuration files:
|
||||
<ul>
|
||||
<li>The main config.yml file inside "plugins/WorldGuard" is the main configuration. </li>
|
||||
<li>Each world has a configuration file in "plugins/WorldGuard/worlds" that you can use to override any setting in the main configuration file for that specific world.</li>
|
||||
</ul>
|
||||
</li>
|
||||
Use <em>/wg reload</em> in the console to reload the configuration.
|
||||
<li><strong>Learn how to use WorldGuard:</strong> Check <a href="http://wiki.sk89q.com/wiki/WorldGuard">out the wiki</a> to learn how to disable things like fire and to protect regions.</li>
|
||||
</ol>
|
||||
<p class="warning"><strong>Note:</strong> Be sure you install <a href="http://www.sk89q.com/projects/worldedit/">WorldEdit</a>. If you don't want WorldEdit, just put WorldEdit.jar into your Bukkit root folder (outside of plugins/). Note that region protection requires WorldEdit in plugins/.</p>
|
||||
<p>Be sure to:</p>
|
||||
<ul>
|
||||
<li>Subscribe to <a href="http://minecraftnews.sk89q.com/">SK's Minecraft blog</a> for news about WorldGuard</li>
|
||||
<li>Submit bug reports and suggestions to the <a href="http://redmine.sk89q.com/projects/worldguard/issues">issue tracker</a></li>
|
||||
<li>Check out the <a href="http://wiki.sk89q.com/wiki/WorldGuard">WorldGuard wiki</a></li>
|
||||
</ul>
|
||||
<h2>Getting Help</h2>
|
||||
<p>If you need help, the best two ways to ask are:</p>
|
||||
<ul>
|
||||
<li><a href="http://forum.sk89q.com/">Visit the WorldGuard forum</a></li>
|
||||
<li>Ask in IRC chat on <a href="http://skq.me/irc/irc.esper.net/worldguard">irc.esper.net in #worldguard</a> (idle with us!)</li>
|
||||
</ul>
|
||||
<h2>Contributing</h2>
|
||||
<p>WorldGuard is entirely open source! You can download all of the plugin code to learn from it, modify it for your own self, or even contribute back!</p>
|
||||
<ul>
|
||||
<li><a href="https://github.com/sk89q/worldguard">Download WorldGuard code from GitHub</a></li>
|
||||
<li>You can also <a href="http://www.sk89q.com/donate/">donate</a></li>
|
||||
</ul>
|
||||
<p>The code is covered under the GNU General Public License v3.</p>
|
||||
<p class="subtle">Maven information: ${groupId}/${artifactId}/${version}</p>
|
||||
<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>
|
||||
@@ -1,25 +1,35 @@
|
||||
WorldGuard
|
||||

|
||||
==========
|
||||
|
||||
WorldGuard protects your Minecraft server. As Minecraft's oldest surviving world protection mod, you know you're in safe hands.
|
||||
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
|
||||
---------
|
||||
|
||||
You need to have Maven installed (http://maven.apache.org). Once installed,
|
||||
simply run:
|
||||
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).
|
||||
|
||||
mvn clean install
|
||||
|
||||
Maven will automatically download dependencies for you. Note: For that to work,
|
||||
be sure to add Maven to your "PATH".
|
||||
Dependencies are automatically handled by Maven.
|
||||
|
||||
Contributing
|
||||
------------
|
||||
|
||||
We happily accept contributions. The best way to do this is to fork WorldGuard
|
||||
on GitHub, add your changes, and then submit a pull request. We'll look at it,
|
||||
make comments, and merge it into WorldGuard if everything works out.
|
||||
We happily accept contributions, especially through pull requests on GitHub. Submissions
|
||||
must be licensed under the GNU General Public License v3.
|
||||
|
||||
By submitting code, you agree to place to license your code under the
|
||||
GNU General Public License v3.
|
||||
Please read CONTRIBUTING.md for important guidelines to follow.
|
||||
|
||||
Links
|
||||
-----
|
||||
|
||||
* [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)
|
||||
@@ -1,24 +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,
|
||||
`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
|
||||
|
||||
-- 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
|
||||
@@ -1,173 +1,274 @@
|
||||
<!--
|
||||
Maven build file for WorldGuard
|
||||
Copyright (c) 2011 sk89q <http://www.sk89q.com>
|
||||
CommandBook is available under the GNU General Public License v3
|
||||
-->
|
||||
<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.1</version>
|
||||
<name>WorldGuard</name>
|
||||
<description>WorldGuard protects your Minecraft servers</description>
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:git://github.com/sk89q/worldguard.git</connection>
|
||||
<url>https://github.com/sk89q/worldguard</url>
|
||||
<developerConnection>scm:git:git@github.com:sk89q/worldguard.git</developerConnection>
|
||||
</scm>
|
||||
|
||||
<repositories>
|
||||
<!-- Repository for other dependencies of SK's -->
|
||||
<repository>
|
||||
<id>sk89q-mvn2</id>
|
||||
<url>http://mvn2.sk89q.com/repo</url>
|
||||
</repository>
|
||||
<!-- Repository for Bukkit -->
|
||||
<repository>
|
||||
<id>bukkit-repo</id>
|
||||
<url>http://repo.bukkit.org/artifactory/repo</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<!-- Required component -->
|
||||
<dependency>
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>worldedit</artifactId>
|
||||
<version>4.4.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Bukkit -->
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Additional libraries -->
|
||||
<dependency>
|
||||
<groupId>com.nijikokun</groupId>
|
||||
<artifactId>iconomy</artifactId>
|
||||
<version>5.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.khelekore</groupId>
|
||||
<artifactId>prtree</artifactId>
|
||||
<version>1.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sf.opencsv</groupId>
|
||||
<artifactId>opencsv</artifactId>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
|
||||
|
||||
<!-- Resources -->
|
||||
<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 -->
|
||||
<plugins>
|
||||
<!-- Compile plugin -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
</plugin>
|
||||
|
||||
<!-- JAR creation 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>WorldEdit.jar WorldGuard/WorldEdit.jar lib/WorldEdit.jar ../lib/WorldEdit.jar ../WorldEdit.jar</Class-Path>
|
||||
</manifestEntries>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<!-- Shade -->
|
||||
<!-- We want to bundle in some dependencies -->
|
||||
<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>
|
||||
<!-- We want to bundle in the modified CSV library -->
|
||||
<includes>
|
||||
<include>net.sf.opencsv:opencsv</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<!-- Assembly -->
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>2.2.1</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>
|
||||
|
||||
<!-- Release -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-release-plugin</artifactId>
|
||||
<version>2.1</version>
|
||||
<configuration>
|
||||
<preparationGoals>assembly:assembly</preparationGoals>
|
||||
<goals>assembly:assembly</goals>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
<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-SNAPSHOT</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>com.sk89q</groupId>
|
||||
<artifactId>rebar</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.4.2-R0.2-SNAPSHOT</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>
|
||||
<dependency>
|
||||
<groupId>commons-lang</groupId>
|
||||
<artifactId>commons-lang</artifactId>
|
||||
<version>2.3</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jolbox</groupId>
|
||||
<artifactId>bonecp</artifactId>
|
||||
<version>0.7.1.RELEASE</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-all</artifactId>
|
||||
<version>1.9.5</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>blacklist.txt</include>
|
||||
<include>builtin_rules.yml</include>
|
||||
<include>rulelist.yml</include>
|
||||
</includes>
|
||||
</resource>
|
||||
<resource>
|
||||
<targetPath></targetPath>
|
||||
<filtering>false</filtering>
|
||||
<directory>${basedir}/src/main/resources/</directory>
|
||||
<includes>
|
||||
<include>models/</include>
|
||||
<include>sql/</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>
|
||||
<include>com.sk89q:rebar</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>
|
||||
@@ -28,7 +28,10 @@
|
||||
<includes>
|
||||
<include>LICENSE.txt</include>
|
||||
<include>NOTICE.txt</include>
|
||||
<include>blacklist_table.sql</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>
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
// $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.rulelists;
|
||||
|
||||
/**
|
||||
* An action that will be performed if the conditions are matched of the rule.
|
||||
*
|
||||
* @param <T> implementation-specific context object
|
||||
*/
|
||||
public interface Action<T extends Context> {
|
||||
|
||||
/**
|
||||
* Apply the action.
|
||||
*
|
||||
* @param context implementation-specific context object
|
||||
*/
|
||||
void apply(T context);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
// $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.rulelists;
|
||||
|
||||
/**
|
||||
* An attachment is analogous to an event.
|
||||
*/
|
||||
public final class Attachment {
|
||||
|
||||
private static int NEXT_ID = 0;
|
||||
|
||||
private final int id;
|
||||
private final String alias;
|
||||
|
||||
/**
|
||||
* Create a new attachment with the given alias. The alias is used in rule list
|
||||
* files.
|
||||
*
|
||||
* @param alias alias name
|
||||
*/
|
||||
public Attachment(String alias) {
|
||||
this.alias = alias;
|
||||
|
||||
// No internal ID
|
||||
id = -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new attachment with the given alias. The alias is used in rule list
|
||||
* files.
|
||||
*
|
||||
* @param alias alias name
|
||||
* @param isInternal true to assign this attachment a standard internal ID
|
||||
*/
|
||||
Attachment(String alias, boolean isInternal) {
|
||||
this.alias = alias;
|
||||
|
||||
id = isInternal ? NEXT_ID++ : -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the internal ID.
|
||||
*
|
||||
* @return ID number, possibly -1 for no internal ID
|
||||
*/
|
||||
int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the alias used inside rule list files.
|
||||
*
|
||||
* @return alias
|
||||
*/
|
||||
public String getAlias() {
|
||||
return alias;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
// $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.rulelists;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.sk89q.rebar.config.Loader;
|
||||
import com.sk89q.rebar.config.LoaderBuilderException;
|
||||
|
||||
/**
|
||||
* A database of valid attachments.
|
||||
*/
|
||||
public final class AttachmentManager implements Loader<Attachment> {
|
||||
|
||||
private Set<Attachment> attachments = new HashSet<Attachment>();
|
||||
private Map<String, Attachment> aliasMap = new HashMap<String, Attachment>();
|
||||
|
||||
public AttachmentManager() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an attachment.
|
||||
*
|
||||
* @param attachment the attachment
|
||||
*/
|
||||
public synchronized void register(Attachment attachment) {
|
||||
if (attachments.contains(attachment)
|
||||
|| aliasMap.containsKey(attachment.getAlias().toLowerCase())) {
|
||||
throw new IllegalArgumentException("Attachment '" + attachment + "' already registered.");
|
||||
}
|
||||
|
||||
attachments.add(attachment);
|
||||
aliasMap.put(attachment.getAlias().toLowerCase(), attachment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an attachment by its alias.
|
||||
*
|
||||
* @param alias alias, case in-sensitive
|
||||
* @return an attachment or null
|
||||
*/
|
||||
public synchronized Attachment lookup(String alias) {
|
||||
return aliasMap.get(alias.toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Attachment read(Object value) throws LoaderBuilderException {
|
||||
String id = String.valueOf(value);
|
||||
|
||||
Attachment attachment = lookup(id);
|
||||
if (attachment == null) {
|
||||
throw new LoaderBuilderException("Unknown RuleList attachment: " + id);
|
||||
}
|
||||
|
||||
return attachment;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
// $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.rulelists;
|
||||
|
||||
/**
|
||||
* A context has some shared variables that may be used by a number of different
|
||||
* events. Because the context contains common information, criteria and
|
||||
* actions do not have to be custom tailored to specific implementation-specific
|
||||
* events, and can refer to the the properties set on the context. The place
|
||||
* where the information is known as to what is considered the proper valid
|
||||
* value of a common property is during the initial handling of
|
||||
* the event in the implementation.
|
||||
* </p>
|
||||
* Implementations need to have custom contexts that can carry more
|
||||
* information than offered in this abstract implementation. Criteria and
|
||||
* actions can be implement-specific by tailoring themselves to one of these
|
||||
* implementation-specific contexts.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public abstract class Context {
|
||||
|
||||
private boolean matches = false;
|
||||
private boolean cancelled = false;
|
||||
|
||||
/**
|
||||
* Gets whether the event associated with this context has been set to
|
||||
* be cancelled.
|
||||
*
|
||||
* @return true if the event is set to be cancelled
|
||||
*/
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the event associated with this context to be cancelled, if possible.
|
||||
*/
|
||||
public void cancel() {
|
||||
setCancelled(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the event associated with this context to be cancelled, if possible.
|
||||
*
|
||||
* @param cancelled true to cancel
|
||||
*/
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set as to whether all the conditions associated with this context have
|
||||
* evaluated to being true.
|
||||
*
|
||||
* @param matches match state
|
||||
*/
|
||||
void setMatches(boolean matches) {
|
||||
this.matches = matches;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether all the conditions associated with this context
|
||||
* have been evaluated to true.
|
||||
*
|
||||
* @return true if all the conditions have been true
|
||||
*/
|
||||
public boolean matches() {
|
||||
return matches;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// $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.rulelists;
|
||||
|
||||
/**
|
||||
* A criteria that is evaluated to decide whether the rule should undergo
|
||||
* further processing.
|
||||
*
|
||||
* @param <T> an implementation-specific context
|
||||
*/
|
||||
public interface Criteria<T extends Context> {
|
||||
|
||||
/**
|
||||
* Returns whether the current event / context matches this criteria.
|
||||
*
|
||||
* @param context context to verify
|
||||
* @return true if it matches
|
||||
*/
|
||||
boolean matches(T context);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
// $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.rulelists;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
/**
|
||||
* Contains names of standard attachments.
|
||||
*/
|
||||
public final class DefaultAttachments {
|
||||
|
||||
public final static Attachment BLOCK_BREAK = new Attachment("block-break", true);
|
||||
public final static Attachment BLOCK_PLACE = new Attachment("block-place", true);
|
||||
public final static Attachment BLOCK_SPREAD = new Attachment("block-spread", true);
|
||||
public final static Attachment BLOCK_PHYSICS = new Attachment("block-physics", true);
|
||||
public final static Attachment BLOCK_INTERACT = new Attachment("block-interact", true);
|
||||
public final static Attachment BLOCK_FADE = new Attachment("block-fade", true);
|
||||
public final static Attachment BLOCK_FORM = new Attachment("block-form", true);
|
||||
public final static Attachment PLAYER_JOIN = new Attachment("player-join", true);
|
||||
public final static Attachment PLAYER_RESPAWN = new Attachment("player-respawn", true);
|
||||
public final static Attachment PLAYER_QUIT = new Attachment("player-quit", true);
|
||||
public final static Attachment ENTITY_EXPLODE = new Attachment("entity-explode", true);
|
||||
public final static Attachment ENTITY_DAMAGE = new Attachment("entity-damage", true);
|
||||
public final static Attachment ENTITY_DEATH = new Attachment("entity-death", true);
|
||||
public final static Attachment ENTITY_IGNITE = new Attachment("entity-ignite", true);
|
||||
public final static Attachment ENTITY_SPAWN = new Attachment("entity-spawn", true);
|
||||
public final static Attachment ENTITY_STRIKE = new Attachment("entity-strike", true);
|
||||
public final static Attachment ENTITY_INTERACT = new Attachment("entity-interact", true);
|
||||
public final static Attachment CHAT = new Attachment("chat", true);
|
||||
public final static Attachment ITEM_DROP = new Attachment("item-drop", true);
|
||||
public final static Attachment ITEM_PICKUP = new Attachment("item-pickup", true);
|
||||
public final static Attachment ITEM_USE = new Attachment("item-use", true);
|
||||
public final static Attachment WEATHER_PHENOMENON = new Attachment("weather-phenomenon", true);
|
||||
public final static Attachment WEATHER_TRANSITION = new Attachment("weather-transition", true);
|
||||
public final static Attachment WORLD_LOAD = new Attachment("world-load", true);
|
||||
public final static Attachment WORLD_UNLOAD = new Attachment("world-unload", true);
|
||||
public final static Attachment WORLD_SAVE = new Attachment("world-save", true);
|
||||
|
||||
private DefaultAttachments() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the attachments in this class with the given manager.
|
||||
*
|
||||
* @param manager the manager
|
||||
*/
|
||||
public static void registerWith(AttachmentManager manager) {
|
||||
for (Field field : DefaultAttachments.class.getFields()) {
|
||||
if (Modifier.isStatic(field.getModifiers())
|
||||
&& Attachment.class.isAssignableFrom(field.getType())) {
|
||||
try {
|
||||
manager.register((Attachment) field.get(null));
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new RuntimeException("Failed to register default attachment", e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException("Failed to register default attachment", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
// $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.rulelists;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* A {@link Rule} implementation with a list of {@link Criteria} and
|
||||
* {@link Action}s.
|
||||
*
|
||||
* @param <T> underlying implementation-specific context
|
||||
*/
|
||||
public class DefinedRule<T extends Context> implements Rule<T> {
|
||||
|
||||
private static Logger logger = Logger.getLogger(Rule.class.getCanonicalName());
|
||||
|
||||
private final List<Criteria<T>> criterion = new LinkedList<Criteria<T>>();
|
||||
private final List<Action<T>> actions = new LinkedList<Action<T>>();
|
||||
|
||||
/**
|
||||
* Add a criteria to this rule.
|
||||
*
|
||||
* @param criteria the criteria
|
||||
*/
|
||||
public void add(Criteria<T> criteria) {
|
||||
criterion.add(criteria);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an action to this rule.
|
||||
*
|
||||
* @param action the action
|
||||
*/
|
||||
public void add(Action<T> action) {
|
||||
actions.add(action);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether criteria are defined.
|
||||
*
|
||||
* @return true if there are criteria
|
||||
*/
|
||||
public boolean hasCriterion() {
|
||||
return criterion.size() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether actions are defined.
|
||||
*
|
||||
* @return true if there are actions
|
||||
*/
|
||||
public boolean hasActions() {
|
||||
return actions.size() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(T context) {
|
||||
for (Criteria<T> criteria : criterion) {
|
||||
if (!criteria.matches(context)) {
|
||||
context.setMatches(false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
context.setMatches(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(T context) {
|
||||
for (Action<T> action : actions) {
|
||||
try {
|
||||
action.apply(context);
|
||||
} catch (Throwable t) {
|
||||
logger.log(Level.WARNING, "Failed to apply action of rule", t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// $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.rulelists;
|
||||
|
||||
import com.sk89q.rebar.config.LoaderBuilderException;
|
||||
|
||||
public class DefinitionException extends LoaderBuilderException {
|
||||
|
||||
private static final long serialVersionUID = -5429457695711163632L;
|
||||
|
||||
public DefinitionException() {
|
||||
}
|
||||
|
||||
public DefinitionException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public DefinitionException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public DefinitionException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// $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.rulelists;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class DefinitionInitializeEvent extends Event {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private final RuleListsManager ruleListsManager;
|
||||
|
||||
public DefinitionInitializeEvent(RuleListsManager ruleListsManager) {
|
||||
this.ruleListsManager = ruleListsManager;
|
||||
}
|
||||
|
||||
public RuleListsManager getManager() {
|
||||
return ruleListsManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
// $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.rulelists;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.sk89q.rebar.config.ConfigurationNode;
|
||||
import com.sk89q.rebar.config.ConfigurationValue;
|
||||
import com.sk89q.rebar.config.Loader;
|
||||
|
||||
/**
|
||||
* Manages loaders for definitions of the given generic type.
|
||||
*
|
||||
* @author sk89q
|
||||
* @param <V> type to create
|
||||
*/
|
||||
public class DefinitionManager<V> {
|
||||
|
||||
/**
|
||||
* Map of factories.
|
||||
*/
|
||||
private Map<String, Loader<? extends V>> factories = new HashMap<String, Loader<? extends V>>();
|
||||
|
||||
/**
|
||||
* Register a loader.
|
||||
*
|
||||
* @param id ID, case does not matter
|
||||
* @param factory factory
|
||||
*/
|
||||
public void register(String id, Loader<? extends V> factory) {
|
||||
factories.put(id.toLowerCase(), factory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param id type
|
||||
* @param node configuration node
|
||||
* @param value short-hand value, possibly null
|
||||
* @return an object
|
||||
* @throws DefinitionException thrown on error when parsing or instantiating
|
||||
*/
|
||||
V newInstance(String id, ConfigurationNode node, ConfigurationValue value) throws DefinitionException {
|
||||
Loader<? extends V> factory;
|
||||
|
||||
if (value != null) {
|
||||
node = node.clone();
|
||||
node.set("_", value.get());
|
||||
}
|
||||
|
||||
if ((factory = factories.get(id)) != null) {
|
||||
return factory.read(node);
|
||||
}
|
||||
|
||||
throw new DefinitionException("Don't know what '" + id
|
||||
+ "' is (typo? criteria/action doesn't exist?)");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// $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.rulelists;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ExpressionParser {
|
||||
|
||||
private static final char COLOR_CHAR = '\u00A7';
|
||||
private static final Pattern classicColors = Pattern.compile("&[A-Fa-z0-9klmnor]");
|
||||
|
||||
public String format(Context context, String string) {
|
||||
Matcher m = classicColors.matcher(string);
|
||||
string = m.replaceAll(COLOR_CHAR + "$1");
|
||||
return string;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
// $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.rulelists;
|
||||
|
||||
/**
|
||||
* A criteria wrapper that inverts the condition.
|
||||
*
|
||||
* @author sk89q
|
||||
* @param <T> underlying criteria
|
||||
*/
|
||||
public class InvertedCriteria<T extends Context> implements Criteria<T> {
|
||||
|
||||
private final Criteria<T> criteria;
|
||||
|
||||
public InvertedCriteria(Criteria<T> criteria) {
|
||||
this.criteria = criteria;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(T context) {
|
||||
return !criteria.matches(context);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// $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.rulelists;
|
||||
|
||||
/**
|
||||
* Attempts to resolve the requested object from other objects. For
|
||||
* example, a block place event can have multiple 'relevant' blocks, such as
|
||||
* the target block or the source block. A resolver is used to figure out
|
||||
* which block is requested, and then the resolver would return the object
|
||||
* requested by accessing it through a given context.
|
||||
*/
|
||||
public interface Resolver {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
// $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.rulelists;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ResolverManager {
|
||||
|
||||
private final Map<Class<? extends Resolver>, Map<String, Resolver>> resolvers
|
||||
= new HashMap<Class<? extends Resolver>, Map<String, Resolver>>();
|
||||
private final Map<Resolver, String> reverse = new HashMap<Resolver, String>();
|
||||
|
||||
public <T extends Resolver> void register(Class<T> clazz, String id, T resolver) {
|
||||
Map<String, Resolver> map = resolvers.get(clazz);
|
||||
if (map == null) {
|
||||
map = new HashMap<String, Resolver>();
|
||||
resolvers.put(clazz, map);
|
||||
}
|
||||
|
||||
reverse.put(resolver, id);
|
||||
|
||||
map.put(id.toLowerCase(), resolver);
|
||||
}
|
||||
|
||||
public String getId(Object object) {
|
||||
return reverse.get(object);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Resolver> T get(Class<T> clazz, String id) throws DefinitionException {
|
||||
Map<String, Resolver> map = resolvers.get(clazz);
|
||||
if (map == null) {
|
||||
throw new DefinitionException("Don't know how to resolve "
|
||||
+ clazz.getCanonicalName());
|
||||
}
|
||||
|
||||
Resolver resolver = map.get(id);
|
||||
if (resolver == null) {
|
||||
throw new DefinitionException("Don't know how to resolve "
|
||||
+ clazz.getCanonicalName());
|
||||
}
|
||||
|
||||
return (T) resolver;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// $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.rulelists;
|
||||
|
||||
/**
|
||||
* A rule that may match a number of events and can be applied in
|
||||
* a situation. See {@link DefinedRule} for a rule implementation that
|
||||
* consists of constituent {@link Criteria}s and {@link Action}s.
|
||||
*
|
||||
* @author sk89q
|
||||
* @param <T> implementation-specific context
|
||||
*/
|
||||
public interface Rule<T extends Context> {
|
||||
|
||||
boolean matches(T context);
|
||||
|
||||
void apply(T context);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
// $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.rulelists;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A pair of attachments and a rule.
|
||||
*/
|
||||
public class RuleEntry {
|
||||
|
||||
private final List<Attachment> attachments;
|
||||
private final Rule<?> rule;
|
||||
|
||||
/**
|
||||
* Construct the rule entry with the list of attachments and rules.
|
||||
*
|
||||
* @param attachments attachment names
|
||||
* @param rule rules
|
||||
*/
|
||||
public RuleEntry(List<Attachment> attachments, Rule<?> rule) {
|
||||
this.attachments = attachments;
|
||||
this.rule = rule;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of attachments.
|
||||
*
|
||||
* @return attachment
|
||||
*/
|
||||
public List<Attachment> getAttachments() {
|
||||
return attachments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rule.
|
||||
*
|
||||
* @return rule
|
||||
*/
|
||||
public Rule<?> getRule() {
|
||||
return rule;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
// $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.rulelists;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.sk89q.rebar.config.AbstractNodeLoader;
|
||||
import com.sk89q.rebar.config.ConfigurationNode;
|
||||
import com.sk89q.rebar.config.ConfigurationValue;
|
||||
import com.sk89q.rebar.config.LoaderBuilderException;
|
||||
import com.sk89q.rebar.util.LoggerUtils;
|
||||
|
||||
/**
|
||||
* A loader that will load rule definitions for the RuleLists.
|
||||
*/
|
||||
public class RuleEntryLoader extends AbstractNodeLoader<RuleEntry> {
|
||||
|
||||
public static final String INLINE = "_";
|
||||
|
||||
private static final Logger logger = LoggerUtils.getLogger(RuleEntryLoader.class);
|
||||
|
||||
private final AttachmentManager attachmentManager;
|
||||
private final DefinitionLoader<Criteria<?>> criteriaLoader;
|
||||
private final DefinitionLoader<Action<?>> actionLoader;
|
||||
|
||||
/**
|
||||
* Construct the loader.
|
||||
*
|
||||
* @param ruleListsManager the action lists manager
|
||||
*/
|
||||
public RuleEntryLoader(RuleListsManager ruleListsManager) {
|
||||
attachmentManager = ruleListsManager.getAttachments();
|
||||
criteriaLoader = new DefinitionLoader<Criteria<?>>(ruleListsManager.getCriterion(), true);
|
||||
actionLoader = new DefinitionLoader<Action<?>>(ruleListsManager.getActions(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public RuleEntry read(ConfigurationNode node) {
|
||||
if (node.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<Attachment> when = node.listOf("when", attachmentManager);
|
||||
|
||||
// Check to see if the rule has any events defined
|
||||
if (when.size() == 0) {
|
||||
logger.warning("A rule has missing 'when' clause:\n" + node.toString());
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
DefinedRule rule = new DefinedRule();
|
||||
|
||||
// Get criterion from the 'if' subnode
|
||||
for (Criteria criteria : node.listOf("if", criteriaLoader)) {
|
||||
rule.add(criteria);
|
||||
}
|
||||
|
||||
// Get actions from the 'then' subnode
|
||||
for (Action action : node.listOf("then", actionLoader)) {
|
||||
rule.add(action);
|
||||
}
|
||||
|
||||
// A rule needs actions!
|
||||
if (rule.hasActions()) {
|
||||
return new RuleEntry(when, rule);
|
||||
} else {
|
||||
logger.warning("The following rule has no actions in:\n" + node.toString());
|
||||
return null;
|
||||
}
|
||||
} catch (LoaderBuilderException e) {
|
||||
logger.warning("A rule had the error '" + e.getMessage() + ", and the rule is:\n" + node.toString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inverts an criteria, wrapping it in a {@link InvertedCriteria}.
|
||||
*
|
||||
* @param criteria to invert
|
||||
* @param inverted true to invert (false to not)
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
private static <V> V invertCriteria(V object, boolean inverted) {
|
||||
if (object instanceof Criteria && inverted) {
|
||||
return (V) new InvertedCriteria((Criteria<?>) object);
|
||||
}
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads specific definitions (criterion or actions) defined.
|
||||
*
|
||||
* @param <T> type of definition ({@link Action} or {@link Criteria})
|
||||
*/
|
||||
private class DefinitionLoader<T> extends AbstractNodeLoader<T> {
|
||||
|
||||
private final DefinitionManager<T> manager;
|
||||
private final boolean strict;
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param manager the definition manager
|
||||
* @param strict true to throw exceptions on error
|
||||
*/
|
||||
public DefinitionLoader(DefinitionManager<T> manager, boolean strict) {
|
||||
this.manager = manager;
|
||||
this.strict = strict;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T read(ConfigurationNode node) {
|
||||
String id = node.getString("?");
|
||||
boolean inverted = node.getBoolean("negate", false);
|
||||
|
||||
try {
|
||||
// Check for long hand notation (?: class)
|
||||
if (id != null) {
|
||||
return invertCriteria(manager.newInstance(id, node, null), inverted);
|
||||
}
|
||||
|
||||
// Check for short-hand notation (?class: value)
|
||||
for (String key : node.getKeys(ConfigurationNode.ROOT)) {
|
||||
if (key.startsWith("?")) {
|
||||
id = key;
|
||||
|
||||
Object value = node.get(key);
|
||||
return invertCriteria(
|
||||
manager.newInstance(key.substring(1), node, new ConfigurationValue(value)), inverted);
|
||||
}
|
||||
}
|
||||
|
||||
// No class defined!
|
||||
logger.warning("RuleList: Missing '?' parameter in definition " +
|
||||
"(to define what kind of criteria/action it is)");
|
||||
|
||||
return null;
|
||||
} catch (DefinitionException e) {
|
||||
logger.warning("RuleList: Invalid definition " +
|
||||
"identified by type '" + id + "': " + e.getMessage());
|
||||
|
||||
// Throw an exception in strict mode
|
||||
if (strict) {
|
||||
throw new LoaderBuilderException("RuleList: Invalid definition " +
|
||||
"identified by type '" + id + "': " + e.getMessage());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
// $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.rulelists;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Holds all the rules.
|
||||
*/
|
||||
public class RuleList {
|
||||
|
||||
private Map<Attachment, RuleSet> collections = new HashMap<Attachment, RuleSet>();
|
||||
|
||||
/**
|
||||
* Build a new instance.
|
||||
*/
|
||||
public RuleList() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a rule set for a given attachment. A rule set is guaranteed to be
|
||||
* returned for all given attachments.
|
||||
*
|
||||
* @param attachment the attachment
|
||||
* @return the rule set
|
||||
*/
|
||||
public synchronized RuleSet get(Attachment attachment) {
|
||||
RuleSet collection = collections.get(attachment);
|
||||
if (collection == null) {
|
||||
collection = new RuleSet();
|
||||
collections.put(attachment, collection);
|
||||
}
|
||||
return collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a rule with this rule list.
|
||||
*
|
||||
* @param entry entry
|
||||
*/
|
||||
public void learn(RuleEntry entry) {
|
||||
Rule<?> rule = entry.getRule();
|
||||
|
||||
for (Attachment attachment : entry.getAttachments()) {
|
||||
learn(attachment, rule);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a rule with this rule list.
|
||||
*
|
||||
* @param attachment the attachment for the rule
|
||||
* @param rule the rule itself
|
||||
*/
|
||||
public void learn(Attachment attachment, Rule<?> rule) {
|
||||
get(attachment).learn(rule);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forget all rules.
|
||||
*/
|
||||
public void clear() {
|
||||
collections.clear();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
// $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.rulelists;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.sk89q.rebar.config.ConfigurationNode;
|
||||
|
||||
/**
|
||||
* RuleList-related utility methods.
|
||||
*/
|
||||
public class RuleListUtils {
|
||||
|
||||
private RuleListUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Warn of unknown directives in a rule list block.
|
||||
*
|
||||
* @param node node
|
||||
* @param logger the logger to send to
|
||||
* @param expected expected keys
|
||||
*/
|
||||
public static void warnUnknown(ConfigurationNode node, Logger logger, String ... expected) {
|
||||
List<String> keys = node.getKeys(ConfigurationNode.ROOT);
|
||||
|
||||
for (String key : keys) {
|
||||
boolean found = false;
|
||||
|
||||
if (key.equals("?")) continue;
|
||||
if (key.equals("negate")) continue;
|
||||
if (key.equals("_")) continue;
|
||||
if (key.length() > 0 && key.charAt(0) == '?') continue;
|
||||
|
||||
for (String expect : expected) {
|
||||
if (expect.equals(key)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
logger.warning("[WorldGuard] RuleList: Unexpected parameter of '" + key + "' in " + node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
// $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.rulelists;
|
||||
|
||||
/**
|
||||
* Manages action lists and details relevant to them.
|
||||
*/
|
||||
public class RuleListsManager {
|
||||
|
||||
private final AttachmentManager attachments = new AttachmentManager();
|
||||
private final DefinitionManager<Criteria<?>> criterion = new DefinitionManager<Criteria<?>>();
|
||||
private final DefinitionManager<Action<?>> actions = new DefinitionManager<Action<?>>();
|
||||
private final ResolverManager subjectResolvers = new ResolverManager();
|
||||
private final ExpressionParser exprParser = new ExpressionParser();
|
||||
|
||||
/**
|
||||
* Get the attachment manager.
|
||||
*
|
||||
* @return the attachment manager
|
||||
*/
|
||||
public AttachmentManager getAttachments() {
|
||||
return attachments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the criterion manager.
|
||||
*
|
||||
* @return criterion manager
|
||||
*/
|
||||
public DefinitionManager<Criteria<?>> getCriterion() {
|
||||
return criterion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the actions manager.
|
||||
*
|
||||
* @return actions manager
|
||||
*/
|
||||
public DefinitionManager<Action<?>> getActions() {
|
||||
return actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the subject resolvers manager.
|
||||
*
|
||||
* @return the subject resolvers manager
|
||||
*/
|
||||
public ResolverManager getResolvers() {
|
||||
return subjectResolvers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the expression parser.
|
||||
*
|
||||
* @return the expression parser
|
||||
*/
|
||||
public ExpressionParser getParser() {
|
||||
return exprParser;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
// $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.rulelists;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Holds a collection of rules that can be applied to a context.
|
||||
*
|
||||
* @see RuleList
|
||||
*/
|
||||
public class RuleSet {
|
||||
|
||||
private List<Rule<?>> rules = new LinkedList<Rule<?>>();
|
||||
|
||||
RuleSet() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the given rule to this set.
|
||||
*
|
||||
* @param rule the rule
|
||||
*/
|
||||
public synchronized void learn(Rule<?> rule) {
|
||||
rules.add(rule);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forget all rules.
|
||||
*/
|
||||
public synchronized void clear() {
|
||||
rules.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether this set has rules.
|
||||
*
|
||||
* @return true if there are rules
|
||||
*/
|
||||
public synchronized boolean hasRules() {
|
||||
return rules.size() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of rules. The returned list cannot be modified.
|
||||
*
|
||||
* @return rule list
|
||||
*/
|
||||
public synchronized List<Rule<?>> getRules() {
|
||||
return Collections.unmodifiableList(rules);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply this rule set onto the given context. Only one thread should call
|
||||
* this method at a given time.
|
||||
*
|
||||
* @param context the context
|
||||
* @return true if the event has been cancelled
|
||||
*/
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public boolean process(Context context) {
|
||||
if (context.isCancelled()) {
|
||||
return true; // Ignore cancelled events for now
|
||||
}
|
||||
|
||||
for (Rule rule : rules) {
|
||||
if (rule.matches(context)) {
|
||||
rule.apply(context);
|
||||
}
|
||||
}
|
||||
|
||||
return context.isCancelled();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
// $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.rulelists;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.sk89q.rebar.config.AbstractNodeLoader;
|
||||
import com.sk89q.rebar.config.ConfigurationNode;
|
||||
import com.sk89q.rebar.config.LoaderBuilderException;
|
||||
import com.sk89q.rebar.config.types.StringLoaderBuilder;
|
||||
|
||||
/**
|
||||
* A loader that will load the built-in rules used. It handles a slightly different
|
||||
* format that also stores parameter information and other goodies.
|
||||
*/
|
||||
public class RuleTemplateEntryLoader extends AbstractNodeLoader<List<RuleEntry>> {
|
||||
|
||||
private static final StringLoaderBuilder stringLoader = new StringLoaderBuilder();
|
||||
|
||||
private final ConfigurationNode config;
|
||||
private final RuleEntryLoader entryLoader;
|
||||
|
||||
/**
|
||||
* Construct the loader with the given rule lists manager.
|
||||
*
|
||||
* @param manager the manager
|
||||
* @param config the configuration node to read settings from
|
||||
*/
|
||||
public RuleTemplateEntryLoader(RuleListsManager manager, ConfigurationNode config) {
|
||||
entryLoader = new RuleEntryLoader(manager);
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RuleEntry> read(ConfigurationNode node) throws LoaderBuilderException {
|
||||
List<RuleEntry> rules = new ArrayList<RuleEntry>();
|
||||
|
||||
List<String> settings = node.listOf("setting", stringLoader);
|
||||
if (settings.size() == 0) {
|
||||
throw new LoaderBuilderException("No 'setting' value in:\n" + node.toString());
|
||||
}
|
||||
|
||||
String selectedSetting = settings.get(0);
|
||||
String type = node.getString("type", "boolean");
|
||||
|
||||
if (settings.size() > 1) {
|
||||
boolean migrate = false;
|
||||
boolean found = false;
|
||||
Object value = null;
|
||||
|
||||
for (String setting : settings) {
|
||||
if (config.contains(setting)) {
|
||||
value = config.get(setting);
|
||||
found = true;
|
||||
break;
|
||||
} else {
|
||||
migrate = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (found && migrate) {
|
||||
config.set(settings.get(0), value);
|
||||
|
||||
int i = 0;
|
||||
for (String setting : settings) {
|
||||
if (i++ != 0) {
|
||||
config.remove(setting);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean active = false;
|
||||
|
||||
// See if the setting is active
|
||||
if (type.equals("boolean")) {
|
||||
boolean negate = node.getBoolean("negate", false);
|
||||
boolean enabled = config.getBoolean(selectedSetting, negate);
|
||||
|
||||
if (negate) {
|
||||
enabled = !enabled;
|
||||
}
|
||||
|
||||
if (enabled) {
|
||||
active = true;
|
||||
}
|
||||
} else if (type.equals("list")) {
|
||||
Object val = config.get(selectedSetting);
|
||||
|
||||
if (val == null) {
|
||||
config.set(selectedSetting, new ArrayList<Object>());
|
||||
} else if (val instanceof List<?> && ((List<?>) val).size() > 0) {
|
||||
active = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Load the setting
|
||||
if (active) {
|
||||
List<String> paramPaths = node.getStringList("parameters.target", new ArrayList<String>());
|
||||
if (paramPaths.size() > 0) {
|
||||
Object val = config.get(selectedSetting);
|
||||
for (String path : paramPaths) {
|
||||
node.set(path, val);
|
||||
}
|
||||
}
|
||||
|
||||
for (RuleEntry rule : node.listOf("rules", entryLoader)) {
|
||||
rules.add(rule);
|
||||
}
|
||||
}
|
||||
|
||||
return rules;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// $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
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser 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;
|
||||
|
||||
/**
|
||||
* A user, group, or other object that describes a set of users.
|
||||
*/
|
||||
public interface Classifier {
|
||||
|
||||
}
|
||||
@@ -25,68 +25,66 @@ public abstract class LocalPlayer {
|
||||
/**
|
||||
* Get a player's name.
|
||||
*
|
||||
* @return
|
||||
* @return The player's name
|
||||
*/
|
||||
public abstract String getName();
|
||||
|
||||
/**
|
||||
* Returns true if the player is inside a group.
|
||||
*
|
||||
* @param group
|
||||
* @return
|
||||
* @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
|
||||
* @return The player's position
|
||||
*/
|
||||
public abstract Vector getPosition();
|
||||
|
||||
/**
|
||||
* Kick the player.
|
||||
*
|
||||
* @param msg
|
||||
* @param msg The message to kick the player with
|
||||
*/
|
||||
public abstract void kick(String msg);
|
||||
|
||||
/**
|
||||
* Ban the player.
|
||||
*
|
||||
* @param msg
|
||||
* @param msg The message to ban the player with
|
||||
*/
|
||||
public abstract void ban(String msg);
|
||||
|
||||
/**
|
||||
* Send the player a message;
|
||||
*
|
||||
* @param msg
|
||||
* @param msg The message to send to the player
|
||||
*/
|
||||
public abstract void printRaw(String msg);
|
||||
|
||||
/**
|
||||
* Get the player's list of groups.
|
||||
*
|
||||
* @return
|
||||
* @return The groups this player is in
|
||||
*/
|
||||
public abstract String[] getGroups();
|
||||
|
||||
/**
|
||||
* Returns whether a player has permission.
|
||||
*
|
||||
* @param perm
|
||||
* @return
|
||||
* @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) {
|
||||
if (!(obj instanceof LocalPlayer)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ((LocalPlayer)obj).getName().equals(getName());
|
||||
|
||||
return obj instanceof LocalPlayer && ((LocalPlayer) obj).getName().equals(getName());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,35 +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/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard;
|
||||
|
||||
import java.util.logging.Filter;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
||||
|
||||
public class TickSyncDelayLoggerFilter implements Filter {
|
||||
public boolean isLoggable(LogRecord record) {
|
||||
if (record.getLevel() == Level.WARNING
|
||||
&& record.getMessage().equals("Can't keep up! Did the system time change, or is the server overloaded?")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -19,14 +19,19 @@
|
||||
|
||||
package com.sk89q.worldguard.blacklist;
|
||||
|
||||
import java.util.Map;
|
||||
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;
|
||||
@@ -36,11 +41,7 @@ import com.sk89q.worldguard.blacklist.events.BlacklistEvent;
|
||||
* @author sk89q
|
||||
*/
|
||||
public abstract class Blacklist {
|
||||
/**
|
||||
* Logger.
|
||||
*/
|
||||
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
||||
|
||||
|
||||
/**
|
||||
* List of entries by block ID.
|
||||
*/
|
||||
@@ -60,18 +61,19 @@ public abstract class Blacklist {
|
||||
Map<String,BlacklistTrackedEvent> lastAffected =
|
||||
new HashMap<String,BlacklistTrackedEvent>();
|
||||
|
||||
|
||||
private boolean useAsWhitelist;
|
||||
|
||||
public Blacklist(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();
|
||||
@@ -79,36 +81,36 @@ public abstract class Blacklist {
|
||||
|
||||
/**
|
||||
* Get the entries for an item or list.
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*
|
||||
* @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
|
||||
*
|
||||
* @return The number of items in the blacklist
|
||||
*/
|
||||
public int getItemCount() {
|
||||
return blacklist.size();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns whether the blacklist is used as a whitelist.
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @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;
|
||||
@@ -116,11 +118,11 @@ public abstract class Blacklist {
|
||||
|
||||
/**
|
||||
* Method to handle the event.
|
||||
*
|
||||
* @param event
|
||||
* @param forceRepeat
|
||||
* @param silent
|
||||
* @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 check(BlacklistEvent event, boolean forceRepeat, boolean silent) {
|
||||
List<BlacklistEntry> entries = getEntries(event.getType());
|
||||
@@ -139,8 +141,8 @@ public abstract class Blacklist {
|
||||
/**
|
||||
* Load the blacklist.
|
||||
*
|
||||
* @param file
|
||||
* @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;
|
||||
@@ -168,14 +170,14 @@ public abstract 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 = getItemID(item.trim());
|
||||
if (id == 0) {
|
||||
logger.log(Level.WARNING, "WorldGuard: Unknown block name: "
|
||||
logger.log(Level.WARNING, "Unknown block name: "
|
||||
+ item);
|
||||
break;
|
||||
}
|
||||
@@ -205,6 +207,8 @@ public abstract class Blacklist {
|
||||
for (BlacklistEntry entry : currentEntries) {
|
||||
if (parts[0].equalsIgnoreCase("ignore-groups")) {
|
||||
entry.setIgnoreGroups(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-destroy-with")) {
|
||||
@@ -244,48 +248,48 @@ public abstract class Blacklist {
|
||||
if (input != null) {
|
||||
input.close();
|
||||
}
|
||||
} catch (IOException e2) {
|
||||
} catch (IOException ignore) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the last event.
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @return The last event
|
||||
*/
|
||||
public BlacklistEvent getLastEvent() {
|
||||
return lastEvent;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notify administrators.
|
||||
*
|
||||
* @param event
|
||||
* @param comment
|
||||
*
|
||||
* @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: "
|
||||
|
||||
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
|
||||
*
|
||||
* @param msg The message to broadcast
|
||||
*/
|
||||
public abstract void broadcastNotification(String msg);
|
||||
|
||||
/**
|
||||
* Forget a player.
|
||||
*
|
||||
* @param player
|
||||
* @param player The player to forget
|
||||
*/
|
||||
public void forgetPlayer(LocalPlayer player) {
|
||||
lastAffected.remove(player.getName());
|
||||
@@ -300,8 +304,9 @@ public abstract class Blacklist {
|
||||
|
||||
/**
|
||||
* Get an item's ID from its name.
|
||||
*
|
||||
* @param 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);
|
||||
@@ -314,8 +319,9 @@ public abstract class Blacklist {
|
||||
|
||||
/**
|
||||
* Get an item's friendly name with its ID.
|
||||
*
|
||||
* @param 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);
|
||||
|
||||
@@ -19,9 +19,12 @@
|
||||
|
||||
package com.sk89q.worldguard.blacklist;
|
||||
|
||||
import java.util.Set;
|
||||
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;
|
||||
@@ -42,11 +45,17 @@ 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;
|
||||
@@ -54,14 +63,14 @@ public class BlacklistEntry {
|
||||
private String[] useActions;
|
||||
private String[] dropActions;
|
||||
private String[] acquireActions;
|
||||
|
||||
|
||||
private String message;
|
||||
private String comment;
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param blacklist
|
||||
*
|
||||
* @param blacklist The blacklist that contains this entry
|
||||
*/
|
||||
public BlacklistEntry(Blacklist blacklist) {
|
||||
this.blacklist = blacklist;
|
||||
@@ -74,6 +83,13 @@ public class BlacklistEntry {
|
||||
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
|
||||
*/
|
||||
@@ -86,98 +102,107 @@ public class BlacklistEntry {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @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
|
||||
* @param actions The actions to occur when breaking
|
||||
*/
|
||||
public void setBreakActions(String[] actions) {
|
||||
this.breakActions = actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @return The actions that occur when destroying with a specific item
|
||||
*/
|
||||
public String[] getDestroyWithActions() {
|
||||
return destroyWithActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param actions
|
||||
* @param actions The actions to occur when destroying with an item
|
||||
*/
|
||||
public void setDestroyWithActions(String[] actions) {
|
||||
this.destroyWithActions = actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @return The actions that will occur when placing
|
||||
*/
|
||||
public String[] getPlaceActions() {
|
||||
return placeActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param actions
|
||||
* @param actions The actions to occur when placing
|
||||
*/
|
||||
public void setPlaceActions(String[] actions) {
|
||||
this.placeActions = actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @return The actions that will occur when interacting
|
||||
*/
|
||||
public String[] getInteractActions() {
|
||||
return interactActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param actions
|
||||
* @param actions The actions to occur when interacting
|
||||
*/
|
||||
public void setInteractActions(String[] actions) {
|
||||
this.interactActions = actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @return The actions that will occur when using
|
||||
*/
|
||||
public String[] getUseActions() {
|
||||
return useActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param actions
|
||||
* @param actions The actions to occur when using
|
||||
*/
|
||||
public void setUseActions(String[] actions) {
|
||||
this.useActions = actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @return The actions that will occur when dropping
|
||||
*/
|
||||
public String[] getDropActions() {
|
||||
return dropActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param actions
|
||||
* @param actions The actions to occur when dropping
|
||||
*/
|
||||
public void setDropActions(String[] actions) {
|
||||
this.dropActions = actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @return The actions that will occur when acquiring
|
||||
*/
|
||||
public String[] getAcquireActions() {
|
||||
return acquireActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param actions
|
||||
* @param actions The actions to occur when acquiring
|
||||
*/
|
||||
public void setAcquireActions(String[] actions) {
|
||||
this.acquireActions = actions;
|
||||
@@ -214,50 +239,57 @@ public class BlacklistEntry {
|
||||
/**
|
||||
* Returns true if this player should be ignored.
|
||||
*
|
||||
* @param player
|
||||
* @return
|
||||
* @param player The player to check
|
||||
* @return whether this player should be ignored for blacklist blocking
|
||||
*/
|
||||
public boolean shouldIgnore(LocalPlayer player) {
|
||||
if (ignoreGroups == null) {
|
||||
return false;
|
||||
if (ignoreGroups != null) {
|
||||
for (String group : player.getGroups()) {
|
||||
if (ignoreGroups.contains(group.toLowerCase())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
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
|
||||
* @return
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
@@ -265,16 +297,16 @@ public class BlacklistEntry {
|
||||
|
||||
/**
|
||||
* Method to handle the event.
|
||||
*
|
||||
* @param useAsWhitelist
|
||||
* @param event
|
||||
* @param forceRepeat
|
||||
* @param silent
|
||||
* @return
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
@@ -295,21 +327,21 @@ public class BlacklistEntry {
|
||||
|
||||
String actions[] = getActions(event);
|
||||
|
||||
|
||||
boolean ret = useAsWhitelist ? false : true;
|
||||
|
||||
|
||||
boolean ret = !useAsWhitelist;
|
||||
|
||||
// Nothing to do
|
||||
if (actions == null) {
|
||||
return useAsWhitelist ? false : true;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
for (String action : actions) {
|
||||
// Deny
|
||||
if (action.equalsIgnoreCase("deny")) {
|
||||
if (silent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
ret = false;
|
||||
|
||||
// Allow
|
||||
@@ -325,7 +357,7 @@ public class BlacklistEntry {
|
||||
if (silent) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (this.message != null) {
|
||||
player.kick(String.format(this.message,
|
||||
getFriendlyItemName(event.getType())));
|
||||
@@ -339,7 +371,7 @@ public class BlacklistEntry {
|
||||
if (silent) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (this.message != null) {
|
||||
player.ban("Banned: " + String.format(this.message,
|
||||
getFriendlyItemName(event.getType())));
|
||||
@@ -348,12 +380,12 @@ public class BlacklistEntry {
|
||||
+ 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);
|
||||
@@ -378,8 +410,8 @@ public class BlacklistEntry {
|
||||
|
||||
/**
|
||||
* Get an item's friendly name with its ID.
|
||||
*
|
||||
* @param id
|
||||
*
|
||||
* @param id The id to get a name for
|
||||
*/
|
||||
private static String getFriendlyItemName(int id) {
|
||||
ItemType type = ItemType.fromID(id);
|
||||
|
||||
@@ -19,8 +19,9 @@
|
||||
|
||||
package com.sk89q.worldguard.blacklist;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.sk89q.worldguard.blacklist.events.BlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.loggers.BlacklistLoggerHandler;
|
||||
|
||||
@@ -38,16 +39,16 @@ public class BlacklistLogger implements BlacklistLoggerHandler {
|
||||
/**
|
||||
* Add a handler.
|
||||
*
|
||||
* @param handler
|
||||
* @param handler The handler to add
|
||||
*/
|
||||
public void addHandler(BlacklistLoggerHandler handler) {
|
||||
handlers.add(handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a handler.
|
||||
* Remove a handler.
|
||||
*
|
||||
* @param handler
|
||||
* @param handler The handler to remove
|
||||
*/
|
||||
public void removeHandler(BlacklistLoggerHandler handler) {
|
||||
handlers.remove(handler);
|
||||
@@ -59,11 +60,11 @@ public class BlacklistLogger implements BlacklistLoggerHandler {
|
||||
public void clearHandlers() {
|
||||
handlers.clear();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Log an event.
|
||||
*
|
||||
* @param event
|
||||
* @param event The event to log
|
||||
*/
|
||||
public void logEvent(BlacklistEvent event, String comment) {
|
||||
for (BlacklistLoggerHandler handler : handlers) {
|
||||
|
||||
@@ -31,9 +31,9 @@ public class BlacklistTrackedEvent {
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param event
|
||||
* @param time
|
||||
*
|
||||
* @param event The event tracked
|
||||
* @param time The time at which the event occurred
|
||||
*/
|
||||
public BlacklistTrackedEvent(BlacklistEvent event, long time) {
|
||||
this.event = event;
|
||||
|
||||
@@ -39,9 +39,9 @@ public abstract class BlacklistEvent {
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param player
|
||||
* @param pos
|
||||
* @param type
|
||||
* @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;
|
||||
@@ -51,8 +51,8 @@ public abstract class BlacklistEvent {
|
||||
|
||||
/**
|
||||
* Get the player.
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @return The player associated with this event
|
||||
*/
|
||||
public LocalPlayer getPlayer() {
|
||||
return player;
|
||||
@@ -61,16 +61,16 @@ public abstract class BlacklistEvent {
|
||||
/**
|
||||
* Get the position.
|
||||
*
|
||||
* @return
|
||||
* @return The position of this event
|
||||
*/
|
||||
public Vector getPosition() {
|
||||
return pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type.
|
||||
* Get the item type.
|
||||
*
|
||||
* @return
|
||||
* @return The type associated with this event
|
||||
*/
|
||||
public int getType() {
|
||||
return type;
|
||||
@@ -79,7 +79,7 @@ public abstract class BlacklistEvent {
|
||||
/**
|
||||
* Get a short description such as "break" or "destroy with."
|
||||
*
|
||||
* @return
|
||||
* @return The event description
|
||||
*/
|
||||
public abstract String getDescription();
|
||||
}
|
||||
@@ -26,12 +26,7 @@ public class BlockBreakBlacklistEvent extends BlockBlacklistEvent {
|
||||
public BlockBreakBlacklistEvent(LocalPlayer player, Vector pos, int type) {
|
||||
super(player, pos, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a short description such as "break" or "destroy with."
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "break";
|
||||
|
||||
+1
-6
@@ -26,12 +26,7 @@ public class BlockInteractBlacklistEvent extends BlockBlacklistEvent {
|
||||
public BlockInteractBlacklistEvent(LocalPlayer player, Vector pos, int type) {
|
||||
super(player, pos, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a short description such as "break" or "destroy with."
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "interact with";
|
||||
|
||||
@@ -26,12 +26,7 @@ public class BlockPlaceBlacklistEvent extends BlockBlacklistEvent {
|
||||
public BlockPlaceBlacklistEvent(LocalPlayer player, Vector pos, int type) {
|
||||
super(player, pos, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a short description such as "break" or "destroy with."
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "place";
|
||||
|
||||
@@ -26,12 +26,7 @@ public class DestroyWithBlacklistEvent extends BlacklistEvent {
|
||||
public DestroyWithBlacklistEvent(LocalPlayer player, Vector pos, int type) {
|
||||
super(player, pos, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a short description such as "break" or "destroy with."
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "destroy with";
|
||||
|
||||
@@ -26,12 +26,7 @@ public class ItemAcquireBlacklistEvent extends ItemBlacklistEvent {
|
||||
public ItemAcquireBlacklistEvent(LocalPlayer player, Vector pos, int type) {
|
||||
super(player, pos, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a short description such as "break" or "destroy with."
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "acquire";
|
||||
|
||||
@@ -26,12 +26,7 @@ public class ItemDropBlacklistEvent extends ItemBlacklistEvent {
|
||||
public ItemDropBlacklistEvent(LocalPlayer player, Vector pos, int type) {
|
||||
super(player, pos, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a short description such as "break" or "destroy with."
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "drop";
|
||||
|
||||
@@ -26,12 +26,7 @@ public class ItemUseBlacklistEvent extends ItemBlacklistEvent {
|
||||
public ItemUseBlacklistEvent(LocalPlayer player, Vector pos, int type) {
|
||||
super(player, pos, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a short description such as "break" or "destroy with."
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "use";
|
||||
|
||||
@@ -34,7 +34,7 @@ public interface BlacklistLoggerHandler {
|
||||
* @param comment
|
||||
*/
|
||||
public void logEvent(BlacklistEvent event, String comment);
|
||||
|
||||
|
||||
/**
|
||||
* Close the logger.
|
||||
*/
|
||||
|
||||
@@ -19,102 +19,104 @@
|
||||
|
||||
package com.sk89q.worldguard.blacklist.loggers;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.sk89q.worldedit.blocks.ItemType;
|
||||
import com.sk89q.worldguard.blacklist.events.*;
|
||||
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 {
|
||||
/**
|
||||
* Logger.
|
||||
*/
|
||||
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
||||
|
||||
|
||||
|
||||
|
||||
private String worldName;
|
||||
|
||||
public ConsoleLoggerHandler(String worldName)
|
||||
{
|
||||
this.worldName = worldName;
|
||||
|
||||
private final Logger logger;
|
||||
|
||||
public ConsoleLoggerHandler(String worldName, Logger logger) {
|
||||
this.worldName = worldName;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log an event.
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
public void logEvent(BlacklistEvent event, String comment) {
|
||||
// Block break
|
||||
if (event instanceof BlockBreakBlacklistEvent) {
|
||||
BlockBreakBlacklistEvent evt = (BlockBreakBlacklistEvent)event;
|
||||
logger.log(Level.INFO, "WorldGuard: [" + worldName + "] " + event.getPlayer().getName()
|
||||
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, "WorldGuard: [" + worldName + "] " + event.getPlayer().getName()
|
||||
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, "WorldGuard: [" + worldName + "] " + event.getPlayer().getName()
|
||||
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, "WorldGuard: [" + worldName + "] " + event.getPlayer().getName()
|
||||
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, "WorldGuard: [" + worldName + "] " + event.getPlayer().getName()
|
||||
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, "WorldGuard: [" + worldName + "] " + event.getPlayer().getName()
|
||||
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, "WorldGuard: [" + worldName + "] " + event.getPlayer().getName()
|
||||
logger.log(Level.INFO, "[" + worldName + "] " + event.getPlayer().getName()
|
||||
+ " tried to use " + getFriendlyItemName(evt.getType())
|
||||
+ (comment != null ? " (" + comment + ")" : ""));
|
||||
|
||||
|
||||
// Unknown
|
||||
} else {
|
||||
logger.log(Level.INFO, "WorldGuard: [" + worldName + "] " + event.getPlayer().getName()
|
||||
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
|
||||
*
|
||||
* @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 + "";
|
||||
return "#" + id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,17 +19,19 @@
|
||||
|
||||
package com.sk89q.worldguard.blacklist.loggers;
|
||||
|
||||
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;
|
||||
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;
|
||||
@@ -40,58 +42,58 @@ import com.sk89q.worldguard.blacklist.events.ItemUseBlacklistEvent;
|
||||
* @author sk89q
|
||||
*/
|
||||
public class DatabaseLoggerHandler implements BlacklistLoggerHandler {
|
||||
/**
|
||||
* Logger.
|
||||
*/
|
||||
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
||||
|
||||
/**
|
||||
* DSN.
|
||||
*/
|
||||
private String dsn;
|
||||
private final String dsn;
|
||||
/**
|
||||
* Username.
|
||||
*/
|
||||
private String user;
|
||||
private final String user;
|
||||
/**
|
||||
* Password.
|
||||
*/
|
||||
private String pass;
|
||||
private final String pass;
|
||||
/**
|
||||
* Table.
|
||||
*/
|
||||
private String table;
|
||||
private final String table;
|
||||
/**
|
||||
* World name.
|
||||
*/
|
||||
private String worldName;
|
||||
private final String worldName;
|
||||
/**
|
||||
* Database connection.
|
||||
*/
|
||||
private Connection conn;
|
||||
|
||||
private final Logger logger;
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param dsn
|
||||
* @param user
|
||||
* @param pass
|
||||
* @param table
|
||||
* @param worldName
|
||||
*
|
||||
* @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) {
|
||||
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
|
||||
* @throws SQLException
|
||||
*
|
||||
* @return The database connection
|
||||
* @throws SQLException when the connection cannot be created
|
||||
*/
|
||||
private Connection getConnection() throws SQLException {
|
||||
if (conn == null || conn.isClosed()) {
|
||||
@@ -102,14 +104,12 @@ public class DatabaseLoggerHandler implements BlacklistLoggerHandler {
|
||||
|
||||
/**
|
||||
* Log an event to the database.
|
||||
*
|
||||
* @param event
|
||||
* @param name
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @param item
|
||||
* @param comment
|
||||
*
|
||||
* @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) {
|
||||
@@ -134,11 +134,11 @@ public class DatabaseLoggerHandler implements BlacklistLoggerHandler {
|
||||
+ e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Log an event.
|
||||
*
|
||||
* @param event
|
||||
* @param event The event to log
|
||||
*/
|
||||
public void logEvent(BlacklistEvent event, String comment) {
|
||||
// Block break
|
||||
@@ -146,43 +146,43 @@ public class DatabaseLoggerHandler implements BlacklistLoggerHandler {
|
||||
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 BlockPlaceBlacklistEvent) {
|
||||
BlockPlaceBlacklistEvent evt = (BlockPlaceBlacklistEvent)event;
|
||||
} 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(),
|
||||
@@ -198,8 +198,8 @@ public class DatabaseLoggerHandler implements BlacklistLoggerHandler {
|
||||
if (conn != null && !conn.isClosed()) {
|
||||
conn.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
|
||||
} catch (SQLException ignore) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,26 +19,32 @@
|
||||
|
||||
package com.sk89q.worldguard.blacklist.loggers;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
import java.util.logging.Level;
|
||||
import java.io.*;
|
||||
import java.util.regex.*;
|
||||
import java.util.*;
|
||||
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.*;
|
||||
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.
|
||||
*/
|
||||
@@ -66,38 +72,45 @@ public class FileLoggerHandler implements BlacklistLoggerHandler {
|
||||
*/
|
||||
private TreeMap<String,FileLoggerWriter> writers =
|
||||
new TreeMap<String,FileLoggerWriter>();
|
||||
|
||||
private final Logger logger;
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param pathPattern
|
||||
* @param worldName
|
||||
* @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, String worldName) {
|
||||
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 worldName
|
||||
* @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, String worldName) {
|
||||
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();
|
||||
@@ -142,20 +155,21 @@ 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(LocalPlayer player, String message, String comment) {
|
||||
String path = buildPath(player.getName());
|
||||
@@ -163,7 +177,7 @@ public class FileLoggerHandler implements BlacklistLoggerHandler {
|
||||
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!
|
||||
@@ -185,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);
|
||||
@@ -203,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();
|
||||
|
||||
@@ -222,71 +236,33 @@ public class FileLoggerHandler implements BlacklistLoggerHandler {
|
||||
|
||||
/**
|
||||
* Gets the coordinates in text form for the log.
|
||||
*
|
||||
* @param pos
|
||||
* @return
|
||||
*
|
||||
* @param pos The position to get coordinates for
|
||||
* @return The position's coordinates in human-readable form
|
||||
*/
|
||||
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 an event.
|
||||
*
|
||||
* @param 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(event, "break", evt.getType(), evt.getPosition(), comment);
|
||||
|
||||
// Block place
|
||||
} else if (event instanceof BlockPlaceBlacklistEvent) {
|
||||
BlockPlaceBlacklistEvent evt = (BlockPlaceBlacklistEvent)event;
|
||||
logEvent(event, "place", evt.getType(), evt.getPosition(), comment);
|
||||
|
||||
// Block interact
|
||||
} else if (event instanceof BlockInteractBlacklistEvent) {
|
||||
BlockInteractBlacklistEvent evt = (BlockInteractBlacklistEvent)event;
|
||||
logEvent(event, "interact with", evt.getType(), evt.getPosition(), comment);
|
||||
|
||||
// Destroy with
|
||||
} else if (event instanceof DestroyWithBlacklistEvent) {
|
||||
DestroyWithBlacklistEvent evt = (DestroyWithBlacklistEvent)event;
|
||||
logEvent(event, "destroy with", evt.getType(), evt.getPosition(), comment);
|
||||
|
||||
// Acquire
|
||||
} else if (event instanceof ItemAcquireBlacklistEvent) {
|
||||
ItemAcquireBlacklistEvent evt = (ItemAcquireBlacklistEvent)event;
|
||||
logEvent(event, "acquire", evt.getType(), evt.getPosition(), comment);
|
||||
|
||||
// Drop
|
||||
} else if (event instanceof ItemDropBlacklistEvent) {
|
||||
ItemDropBlacklistEvent evt = (ItemDropBlacklistEvent)event;
|
||||
logEvent(event, "drop", evt.getType(), evt.getPosition(), comment);
|
||||
|
||||
// Use
|
||||
} else if (event instanceof ItemUseBlacklistEvent) {
|
||||
ItemUseBlacklistEvent evt = (ItemUseBlacklistEvent)event;
|
||||
logEvent(event, "use", evt.getType(), evt.getPosition(), comment);
|
||||
|
||||
// Unknown
|
||||
} else {
|
||||
log(event.getPlayer(), "Unknown event: "
|
||||
+ event.getClass().getCanonicalName(), 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) {
|
||||
ItemType type = ItemType.fromID(id);
|
||||
@@ -304,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) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
package com.sk89q.worldguard.blacklist.loggers;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.BufferedWriter;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -41,9 +41,9 @@ public class FileLoggerWriter implements Comparable<FileLoggerWriter> {
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param path
|
||||
* @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;
|
||||
@@ -53,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;
|
||||
@@ -73,7 +73,7 @@ public class FileLoggerWriter implements Comparable<FileLoggerWriter> {
|
||||
public long getLastUse() {
|
||||
return lastUse;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update last use time.
|
||||
*/
|
||||
@@ -81,12 +81,6 @@ public class FileLoggerWriter implements Comparable<FileLoggerWriter> {
|
||||
lastUse = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
/**
|
||||
* Comparison function.
|
||||
*
|
||||
* @param other
|
||||
* @return
|
||||
*/
|
||||
public int compareTo(FileLoggerWriter other) {
|
||||
if (lastUse > other.lastUse) {
|
||||
return 1;
|
||||
|
||||
@@ -25,7 +25,7 @@ public class BukkitBlacklist extends Blacklist {
|
||||
private WorldGuardPlugin plugin;
|
||||
|
||||
public BukkitBlacklist(Boolean useAsWhitelist, WorldGuardPlugin plugin) {
|
||||
super(useAsWhitelist);
|
||||
super(useAsWhitelist, plugin.getLogger());
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@@ -33,5 +33,4 @@ public class BukkitBlacklist extends Blacklist {
|
||||
public void broadcastNotification(String msg) {
|
||||
plugin.broadcastNotification(msg);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,238 @@
|
||||
// $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.block.BlockState;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.sk89q.rulelists.Context;
|
||||
import com.sk89q.worldguard.region.ApplicableRegionSet;
|
||||
|
||||
/**
|
||||
* An implementation of a {@link Context} for Bukkit. This object is thread-safe, but
|
||||
* the underlying objects returned by this class may not be.
|
||||
*
|
||||
* @see Context
|
||||
*/
|
||||
public class BukkitContext extends Context {
|
||||
|
||||
private final RegionQueryCache regionCache;
|
||||
private final Event event;
|
||||
private RegionQuery regionQuery;
|
||||
private String message;
|
||||
private Entity sourceEntity;
|
||||
private Entity targetEntity;
|
||||
private ItemStack item;
|
||||
private BlockState sourceBlock;
|
||||
private BlockState targetBlock;
|
||||
private BlockState replacedTargetBlock;
|
||||
private ApplicableRegionSet lastApplRegionSet;
|
||||
|
||||
/**
|
||||
* Construct a context linked to the given event.
|
||||
*
|
||||
* @param plugin the WorldGuard plugin
|
||||
* @param event the event
|
||||
*/
|
||||
BukkitContext(WorldGuardPlugin plugin, Event event) {
|
||||
this.regionCache = plugin.getRegionCache();
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message attribute of this context.
|
||||
*
|
||||
* @return message or null
|
||||
*/
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the message attribute of this context.
|
||||
*
|
||||
* @param message or null
|
||||
*/
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the source entity for this context. The source entity is the 'cause' of
|
||||
* this context, if it is available.
|
||||
*
|
||||
* @return entity or null
|
||||
*/
|
||||
public Entity getSourceEntity() {
|
||||
return sourceEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the source entity for this context. The source entity is the 'cause' of
|
||||
* this context, if it is available.
|
||||
*
|
||||
* @param sourceEntity entity or null
|
||||
*/
|
||||
public void setSourceEntity(Entity sourceEntity) {
|
||||
this.sourceEntity = sourceEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the target entity for this context. The target entity is the 'subject'
|
||||
* of this context, if it is available.
|
||||
*
|
||||
* @return entity or null
|
||||
*/
|
||||
public Entity getTargetEntity() {
|
||||
return targetEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the target entity for this context. The target entity is the 'subject'
|
||||
* of this context, if it is available.
|
||||
*
|
||||
* @param targetEntity entity or null
|
||||
*/
|
||||
public void setTargetEntity(Entity targetEntity) {
|
||||
this.targetEntity = targetEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the primary item related to this context. Only events that are oriented
|
||||
* around an item have this property set.
|
||||
*
|
||||
* @return item or null
|
||||
*/
|
||||
public ItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the primary item related to this context. Only events that are oriented
|
||||
* around an item have this property set.
|
||||
*
|
||||
* @param item item or null
|
||||
*/
|
||||
public void setItem(ItemStack item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the source block for this context. The source block is the 'cause'
|
||||
* of this context, if it is available.
|
||||
*
|
||||
* @return block or null
|
||||
*/
|
||||
public BlockState getSourceBlock() {
|
||||
return sourceBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the source block for this context. The source block is the 'cause'
|
||||
* of this context, if it is available.
|
||||
*
|
||||
* @param block block or null
|
||||
*/
|
||||
public void setSourceBlock(BlockState block) {
|
||||
this.sourceBlock = block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a target block for this context. The target block is the 'subject' of
|
||||
* this context, if it is available.
|
||||
*
|
||||
* @return block or null
|
||||
*/
|
||||
public BlockState getTargetBlock() {
|
||||
return targetBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a target block for this context. The target block is the 'subject' of
|
||||
* this context, if it is available.
|
||||
*
|
||||
* @param targetBlock block or null
|
||||
*/
|
||||
public void setTargetBlock(BlockState targetBlock) {
|
||||
this.targetBlock = targetBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the placed block for this context. The placed block is the 'new' block
|
||||
* that will replace the existing block in this context, if it is available.
|
||||
*
|
||||
* @return block or null
|
||||
*/
|
||||
public BlockState getPlacedBlock() {
|
||||
return replacedTargetBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the placed block for this context. The placed block is the 'new' block
|
||||
* that will replace the existing block in this context, if it is available.
|
||||
*
|
||||
* @param replacedTargetBlock block or null
|
||||
*/
|
||||
public void setPlacedBlock(BlockState replacedTargetBlock) {
|
||||
this.replacedTargetBlock = replacedTargetBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last {@link ApplicableRegionSet}. This can be set by a rule and used
|
||||
* within one, but it cannot be guaranteed to exist across rules.
|
||||
*
|
||||
* @return an {@link ApplicableRegionSet} or null
|
||||
*/
|
||||
public ApplicableRegionSet getApplicableRegionSet() {
|
||||
return lastApplRegionSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the last {@link ApplicableRegionSet}.
|
||||
*
|
||||
* @param set an {@link ApplicableRegionSet} or null
|
||||
*/
|
||||
public void setApplicableRegionSet(ApplicableRegionSet set) {
|
||||
this.lastApplRegionSet = set;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying event object.
|
||||
*
|
||||
* @return event object
|
||||
*/
|
||||
public Event getEvent() {
|
||||
return event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the region query object.
|
||||
*
|
||||
* @return region query object
|
||||
*/
|
||||
public synchronized RegionQuery getRegionQuery() {
|
||||
if (regionQuery == null) {
|
||||
regionQuery = regionCache.against(event);
|
||||
}
|
||||
return regionQuery;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,6 +21,7 @@ package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
|
||||
@@ -56,6 +57,7 @@ public class BukkitPlayer extends LocalPlayer {
|
||||
|
||||
@Override
|
||||
public void ban(String msg) {
|
||||
player.setBanned(true);
|
||||
player.kickPlayer(msg);
|
||||
}
|
||||
|
||||
@@ -73,5 +75,4 @@ public class BukkitPlayer extends LocalPlayer {
|
||||
public boolean hasPermission(String perm) {
|
||||
return plugin.hasPermission(player, perm);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,48 +19,52 @@
|
||||
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import java.util.List;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
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
|
||||
* @return
|
||||
*
|
||||
* @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
|
||||
* @return
|
||||
*
|
||||
* @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
|
||||
* @return
|
||||
*
|
||||
* @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());
|
||||
@@ -68,22 +72,24 @@ public class BukkitUtil {
|
||||
|
||||
/**
|
||||
* Converts a WorldEdit vector to a Bukkit location.
|
||||
*
|
||||
* @param world
|
||||
* @param vec
|
||||
* @return
|
||||
*
|
||||
* @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
|
||||
* @param name
|
||||
* @return
|
||||
*
|
||||
* @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) {
|
||||
@@ -91,22 +97,24 @@ public class BukkitUtil {
|
||||
}
|
||||
return players.get(0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Drops a sign item and removes a sign.
|
||||
*
|
||||
* @param block
|
||||
*
|
||||
* @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(Material.SIGN));
|
||||
new ItemStack(ItemID.SIGN, 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the given block to fluid water.
|
||||
* Used by addSpongeWater()
|
||||
*
|
||||
*
|
||||
* @param world
|
||||
* @param ox
|
||||
* @param oy
|
||||
@@ -122,21 +130,146 @@ public class BukkitUtil {
|
||||
|
||||
/**
|
||||
* Checks if the given block is water
|
||||
*
|
||||
* @param world
|
||||
* @param ox
|
||||
* @param oy
|
||||
* @param oz
|
||||
* @return
|
||||
*
|
||||
* @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();
|
||||
if (id == 8 || id == 9) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
return id == 8 || id == 9;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 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;
|
||||
}
|
||||
|
||||
static 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);
|
||||
}
|
||||
}
|
||||
|
||||
static 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);
|
||||
}
|
||||
}
|
||||
@@ -18,100 +18,147 @@
|
||||
*/
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.blacklist.Blacklist;
|
||||
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;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.config.Configuration;
|
||||
import org.yaml.snakeyaml.DumperOptions.FlowStyle;
|
||||
|
||||
import com.sk89q.commandbook.CommandBook;
|
||||
import com.sk89q.commandbook.GodComponent;
|
||||
import com.sk89q.rebar.config.ConfigurationException;
|
||||
import com.sk89q.rebar.config.PairedKeyValueLoaderBuilder;
|
||||
import com.sk89q.rebar.config.YamlConfigurationFile;
|
||||
import com.sk89q.rebar.config.YamlStyle;
|
||||
import com.sk89q.rebar.config.types.LowercaseStringLoaderBuilder;
|
||||
import com.sk89q.rebar.config.types.StringLoaderBuilder;
|
||||
import com.sk89q.rebar.util.LoggerUtils;
|
||||
import com.sk89q.rulelists.RuleEntryLoader;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.blacklist.Blacklist;
|
||||
|
||||
/**
|
||||
* Represents the global configuration and also delegates configuration
|
||||
* for individual worlds.
|
||||
*
|
||||
* @author sk89q
|
||||
* @author Michael
|
||||
*/
|
||||
public class ConfigurationManager {
|
||||
|
||||
public static final String CONFIG_HEADER = "#\r\n" +
|
||||
"# WorldGuard's configuration file\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 static Logger logger = LoggerUtils.getLogger(RuleEntryLoader.class, "[WorldGuard] ");
|
||||
|
||||
private static final String DEFAULT_RULELIST_PATH = "rulelist.yml";
|
||||
private static final String DEFAULT_BLACKLIST_PATH = "worlds/%world%/blacklist.txt";
|
||||
private static final String DEFAULT_WORLD_CONFIG_PATH = "worlds/%world%/config.yml";
|
||||
|
||||
static final YamlStyle YAML_STYLE = new YamlStyle(FlowStyle.BLOCK);
|
||||
|
||||
private WorldGuardPlugin plugin;
|
||||
|
||||
/**
|
||||
* Holds configurations for different worlds.
|
||||
*/
|
||||
private Map<String, WorldConfiguration> worlds;
|
||||
|
||||
/**
|
||||
* List of people with god mode.
|
||||
*/
|
||||
private ConcurrentMap<String, WorldConfiguration> worlds;
|
||||
private YamlConfigurationFile config;
|
||||
|
||||
private Map<String, String> ruleLists = new HashMap<String, String>();
|
||||
private Map<String, String> blacklists = new HashMap<String, String>();
|
||||
private Map<String, String> worldConfigs = new HashMap<String, String>();
|
||||
|
||||
@Deprecated
|
||||
private Set<String> hasGodMode = new HashSet<String>();
|
||||
|
||||
/**
|
||||
* List of people who can breathe underwater.
|
||||
*/
|
||||
private Set<String> hasAmphibious = new HashSet<String>();
|
||||
|
||||
public boolean suppressTickSyncWarnings;
|
||||
|
||||
private boolean hasCommandBookGodMode = false;
|
||||
|
||||
/* Configuration data start */
|
||||
public boolean useRegionsScheduler;
|
||||
public boolean activityHaltToggle = false;
|
||||
public boolean useRegionsCreatureSpawnEvent;
|
||||
public boolean usePlayerMove;
|
||||
public Map<String, String> hostKeys = new HashMap<String, String>();
|
||||
|
||||
public boolean useSqlDatabase = false;
|
||||
public String sqlDsn;
|
||||
public String sqlUsername;
|
||||
public String sqlPassword;
|
||||
/* Configuration data end */
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param plugin
|
||||
*
|
||||
* @param plugin the plugin instance
|
||||
*/
|
||||
public ConfigurationManager(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.worlds = new HashMap<String, WorldConfiguration>();
|
||||
this.worlds = new ConcurrentHashMap<String, WorldConfiguration>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the configuration.
|
||||
*/
|
||||
public void load() {
|
||||
// Create the default configuration file
|
||||
WorldGuardPlugin.createDefaultConfiguration(
|
||||
new File(plugin.getDataFolder(), "config.yml"), "config.yml");
|
||||
|
||||
Configuration config = plugin.getConfiguration();
|
||||
config.load();
|
||||
loadConfig();
|
||||
|
||||
suppressTickSyncWarnings = config.getBoolean(
|
||||
"suppress-tick-sync-warnings", false);
|
||||
useRegionsScheduler = config.getBoolean(
|
||||
"regions.use-scheduler", true);
|
||||
// Regions settings
|
||||
useRegionsScheduler = config.getBoolean("regions.use-scheduler", true);
|
||||
useRegionsCreatureSpawnEvent = config.getBoolean("regions.use-creature-spawn-event", true);
|
||||
|
||||
// Regions SQL settings
|
||||
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");
|
||||
|
||||
// Other settings
|
||||
usePlayerMove = config.getBoolean("use-player-move-event", true);
|
||||
|
||||
// Load host keys
|
||||
hostKeys = config.mapOf("host-keys",
|
||||
PairedKeyValueLoaderBuilder.build(
|
||||
new LowercaseStringLoaderBuilder(), new StringLoaderBuilder()));
|
||||
|
||||
// Load rule list filenames
|
||||
if (config.contains("rulelists")) {
|
||||
ruleLists = config.mapOf("rulelists",
|
||||
PairedKeyValueLoaderBuilder.build(
|
||||
new LowercaseStringLoaderBuilder(), new StringLoaderBuilder()));
|
||||
} else {
|
||||
config.setNode("rulelists").set("__default__", DEFAULT_RULELIST_PATH);
|
||||
ruleLists = new HashMap<String, String>();
|
||||
ruleLists.put("__default__", DEFAULT_RULELIST_PATH);
|
||||
}
|
||||
|
||||
// Load blacklist filenames
|
||||
if (config.contains("blacklists")) {
|
||||
blacklists = config.mapOf("blacklists",
|
||||
PairedKeyValueLoaderBuilder.build(
|
||||
new LowercaseStringLoaderBuilder(), new StringLoaderBuilder()));
|
||||
} else {
|
||||
config.setNode("blacklists").set("__default__", DEFAULT_BLACKLIST_PATH);
|
||||
blacklists = new HashMap<String, String>();
|
||||
blacklists.put("__default__", DEFAULT_BLACKLIST_PATH);
|
||||
}
|
||||
|
||||
// Load world config filenames
|
||||
if (config.contains("world-configs")) {
|
||||
worldConfigs = config.mapOf("world-configs",
|
||||
PairedKeyValueLoaderBuilder.build(
|
||||
new LowercaseStringLoaderBuilder(), new StringLoaderBuilder()));
|
||||
} else {
|
||||
config.setNode("world-configs").set("__default__", DEFAULT_WORLD_CONFIG_PATH);
|
||||
worldConfigs = new HashMap<String, String>();
|
||||
worldConfigs.put("__default__", DEFAULT_WORLD_CONFIG_PATH);
|
||||
}
|
||||
|
||||
// Load configurations for each world
|
||||
for (World world : plugin.getServer().getWorlds()) {
|
||||
get(world);
|
||||
}
|
||||
|
||||
config.setHeader(CONFIG_HEADER);
|
||||
config.save();
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,97 +168,246 @@ public class ConfigurationManager {
|
||||
worlds.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the configuration from file.
|
||||
*/
|
||||
private void loadConfig() {
|
||||
config = new YamlConfigurationFile(new File(plugin.getDataFolder(), "config.yml"), YAML_STYLE);
|
||||
|
||||
try {
|
||||
config.load();
|
||||
} catch (IOException e) {
|
||||
logger.log(Level.SEVERE, "Error reading config.yml for global config", e);
|
||||
} catch (ConfigurationException e) {
|
||||
logger.log(Level.SEVERE, "Error reading config.yml for global config", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the configuration to file.
|
||||
*/
|
||||
private void saveConfig() {
|
||||
config.setHeader(
|
||||
"# GLOBAL CONFIGURATION FILE\r\n" +
|
||||
"#\r\n" +
|
||||
"# Everything in here applies to all worlds. For world-specific settings, edit \r\n" +
|
||||
"# the files in plugins/WorldGuard/worlds/WORLD_NAME_HERE/config.yml\r\n" +
|
||||
"#\r\n" +
|
||||
"# The official format of this file is called YAML. If you've never had to\r\n" +
|
||||
"# edit one before, you should REALLY read http://wiki.sk89q.com/wiki/Editing_YAML\r\n");
|
||||
|
||||
try {
|
||||
config.save();
|
||||
} catch (IOException e) {
|
||||
logger.log(Level.SEVERE, "Failed to save configuration", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the configuration for a world.
|
||||
*
|
||||
* @param world
|
||||
* @return
|
||||
*
|
||||
* @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);
|
||||
|
||||
if (config == null) {
|
||||
config = new WorldConfiguration(plugin, worldName);
|
||||
worlds.put(worldName, config);
|
||||
WorldConfiguration newConfig = null;
|
||||
|
||||
while (config == null) {
|
||||
if (newConfig == null) {
|
||||
newConfig = new WorldConfiguration(plugin, worldName, this, this.config);
|
||||
}
|
||||
worlds.putIfAbsent(world.getName(), newConfig);
|
||||
config = worlds.get(world.getName());
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forget a player.
|
||||
*
|
||||
* @param player
|
||||
* Get the RuleList file for the given world.
|
||||
*
|
||||
* @param worldName world
|
||||
* @return file (which may or may not exist)
|
||||
*/
|
||||
public void forgetPlayer(LocalPlayer player) {
|
||||
File getRuleListFile(String worldName) {
|
||||
String path = ruleLists.get(worldName.toLowerCase());
|
||||
|
||||
if (path == null) {
|
||||
path = ruleLists.get("__default__");
|
||||
}
|
||||
|
||||
if (path == null) {
|
||||
path = DEFAULT_RULELIST_PATH;
|
||||
}
|
||||
|
||||
path = path.replace("%world%", worldName);
|
||||
File file = new File(plugin.getDataFolder(), path);
|
||||
|
||||
if (!file.exists()) {
|
||||
plugin.createDefaultConfiguration(file, "rulelist.yml");
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the blacklist file for the given world.
|
||||
*
|
||||
* @param worldName world
|
||||
* @return file (which may or may not exist)
|
||||
*/
|
||||
File getBlacklistFile(String worldName) {
|
||||
String path = blacklists.get(worldName.toLowerCase());
|
||||
File file;
|
||||
|
||||
if (path == null) {
|
||||
path = blacklists.get("__default__");
|
||||
}
|
||||
|
||||
if (path == null) {
|
||||
path = DEFAULT_BLACKLIST_PATH;
|
||||
}
|
||||
|
||||
path = path.replace("%world%", worldName);
|
||||
file = new File(plugin.getDataFolder(), path);
|
||||
|
||||
if (!file.exists()) {
|
||||
plugin.createDefaultConfiguration(file, "blacklist.txt");
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the world configuration file for the given world.
|
||||
*
|
||||
* @param worldName world
|
||||
* @return file (which may or may not exist)
|
||||
*/
|
||||
File getWorldConfigFile(String worldName) {
|
||||
String path = worldConfigs.get(worldName.toLowerCase());
|
||||
File file;
|
||||
|
||||
if (path == null) {
|
||||
path = worldConfigs.get("__default__");
|
||||
}
|
||||
|
||||
if (path == null) {
|
||||
path = DEFAULT_WORLD_CONFIG_PATH;
|
||||
}
|
||||
|
||||
path = path.replace("%world%", worldName);
|
||||
file = new File(plugin.getDataFolder(), path);
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forget a player.
|
||||
*
|
||||
* @param player The player to forget about
|
||||
*/
|
||||
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
|
||||
*
|
||||
* @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
|
||||
*
|
||||
* @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
|
||||
* @return
|
||||
*
|
||||
* @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
|
||||
*
|
||||
* @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
|
||||
*
|
||||
* @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
|
||||
* @return
|
||||
* 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());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check and store whether CommandBook is installed.
|
||||
*/
|
||||
void updateCommandBookGodMode() {
|
||||
try {
|
||||
if (plugin.getServer().getPluginManager().isPluginEnabled("CommandBook")) {
|
||||
Class.forName("com.sk89q.commandbook.GodComponent");
|
||||
hasCommandBookGodMode = true;
|
||||
return;
|
||||
}
|
||||
} catch (ClassNotFoundException ignore) {}
|
||||
hasCommandBookGodMode = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether CommandBook is available for God mode usage.
|
||||
*
|
||||
* @return true if it available
|
||||
*/
|
||||
boolean hasCommandBookGodMode() {
|
||||
return hasCommandBookGodMode;
|
||||
}
|
||||
}
|
||||
@@ -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.bukkit;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,159 +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/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
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.managers.RegionManager;
|
||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.*;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
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);
|
||||
|
||||
processHeal(applicable, player, state);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process healing for a player.
|
||||
*
|
||||
* @param applicable
|
||||
* @param player
|
||||
* @param state
|
||||
*/
|
||||
private void processHeal(ApplicableRegionSet applicable, Player player,
|
||||
PlayerFlagState state) {
|
||||
|
||||
if (player.getHealth() >= 20 || player.getHealth() <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
Integer healAmount = applicable.getFlag(DefaultFlag.HEAL_AMOUNT);
|
||||
Integer healDelay = applicable.getFlag(DefaultFlag.HEAL_DELAY);
|
||||
|
||||
if (healAmount == null || healDelay == null || healAmount < 1 || healDelay < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (healDelay <= 0) {
|
||||
player.setHealth(20);
|
||||
state.lastHeal = now;
|
||||
} else if (now - state.lastHeal > healDelay * 1000) {
|
||||
player.setHealth(Math.min(20, player.getHealth() + healAmount));
|
||||
state.lastHeal = now;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Forget a player.
|
||||
*
|
||||
* @param player
|
||||
*/
|
||||
public synchronized void forget(Player player) {
|
||||
states.remove(player.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a player's flag state.
|
||||
*
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
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 String lastGreeting;
|
||||
public String lastFarewell;
|
||||
public Boolean notifiedForEnter = false;
|
||||
public Boolean notifiedForLeave = false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,305 @@
|
||||
// $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 java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Animals;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.ExperienceOrb;
|
||||
import org.bukkit.entity.FallingBlock;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBurnEvent;
|
||||
import org.bukkit.event.block.BlockFormEvent;
|
||||
import org.bukkit.event.block.BlockFromToEvent;
|
||||
import org.bukkit.event.block.BlockIgniteEvent;
|
||||
import org.bukkit.event.block.BlockPhysicsEvent;
|
||||
import org.bukkit.event.block.BlockSpreadEvent;
|
||||
import org.bukkit.event.block.LeavesDecayEvent;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.entity.ExplosionPrimeEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.world.ChunkLoadEvent;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
import com.sk89q.rebar.util.LoggerUtils;
|
||||
|
||||
/**
|
||||
* Handles the "stop lag" mode.
|
||||
*/
|
||||
public class LagStopMode implements Listener {
|
||||
|
||||
private static final Logger logger = LoggerUtils.getLogger(LagStopMode.class,
|
||||
"[WorldGuard] Lag Stop Mode: ");
|
||||
|
||||
private final WorldGuardPlugin plugin;
|
||||
private boolean enabled = false;
|
||||
private boolean removeAnimals = true;
|
||||
|
||||
LagStopMode(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this class's events.
|
||||
*/
|
||||
void registerEvents() {
|
||||
PluginManager pm = plugin.getServer().getPluginManager();
|
||||
pm.registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether the lag stop mode is enabled.
|
||||
*
|
||||
* @return true if it's enabled
|
||||
*/
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the lag stop mode. This will start the process and emit messages.
|
||||
*
|
||||
* @param unloadChunks true to unload chunks
|
||||
*/
|
||||
public void enable(boolean unloadChunks) {
|
||||
if (!enabled) {
|
||||
Server server = plugin.getServer();
|
||||
|
||||
server.broadcastMessage(ChatColor.GRAY
|
||||
+ "(WorldGuard's 'lag stop' mode has been enabled. Some parts of the game may be 'frozen'. Keep calm and carry on.)");
|
||||
|
||||
// Remove entities
|
||||
server.broadcastMessage(ChatColor.GRAY + "(Please wait... removing entities...)");
|
||||
for (World world : server.getWorlds()) {
|
||||
freeUp(world);
|
||||
}
|
||||
|
||||
// Unloading chunks
|
||||
if (unloadChunks) {
|
||||
server.broadcastMessage(ChatColor.GRAY + "(Please wait... garbage collecting chunks...)");
|
||||
for (World world : server.getWorlds()) {
|
||||
Chunk[] chunks = world.getLoadedChunks();
|
||||
|
||||
for (Chunk chunk : chunks) {
|
||||
chunk.unload(true, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
server.broadcastMessage(ChatColor.GRAY + "(Completed. Lag stop mode is still enabled.)");
|
||||
}
|
||||
|
||||
this.enabled = true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the lag stop mode.
|
||||
*/
|
||||
public void disable() {
|
||||
if (enabled) {
|
||||
Server server = plugin.getServer();
|
||||
server.broadcastMessage(ChatColor.GRAY
|
||||
+ "(WorldGuard's 'lag stop' mode is now off. Everything should proceed to start working again.)");
|
||||
}
|
||||
|
||||
this.enabled = false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether animals are being removed.
|
||||
*
|
||||
* @return true if animals are being removed
|
||||
*/
|
||||
public boolean isRemovingAnimals() {
|
||||
return removeAnimals;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether animals should be removed.
|
||||
*
|
||||
* @param removeAnimals true to remove animals
|
||||
*/
|
||||
public void setRemoveAnimals(boolean removeAnimals) {
|
||||
this.removeAnimals = removeAnimals;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove items and other things within the chunk.
|
||||
*
|
||||
* @param plugin the plugin
|
||||
* @param chunk the chunk to halt
|
||||
*/
|
||||
private void freeUp(Chunk chunk) {
|
||||
int removed = 0;
|
||||
|
||||
for (Entity entity : chunk.getEntities()) {
|
||||
if (shouldRemove(entity)) {
|
||||
entity.remove();
|
||||
removed++;
|
||||
}
|
||||
}
|
||||
|
||||
if (removed > 50) {
|
||||
logger.info(removed + " entities (>50) auto-removed from " + chunk.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove items and other things within the world.
|
||||
*
|
||||
* @param plugin the plugin
|
||||
* @param world the world to halt
|
||||
*/
|
||||
private void freeUp(World world) {
|
||||
int removed = 0;
|
||||
|
||||
for (Entity entity : world.getEntities()) {
|
||||
if (shouldRemove(entity)) {
|
||||
entity.remove();
|
||||
removed++;
|
||||
}
|
||||
}
|
||||
|
||||
if (removed > 50) {
|
||||
logger.info(removed + " entities (>50) auto-removed from " + world.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether an entity should be removed.
|
||||
*
|
||||
* @param entity the entity to check
|
||||
* @return true if it should be removed
|
||||
*/
|
||||
private boolean shouldRemove(Entity entity) {
|
||||
return entity instanceof Item
|
||||
|| entity instanceof TNTPrimed
|
||||
|| entity instanceof ExperienceOrb
|
||||
|| entity instanceof FallingBlock
|
||||
|| (entity instanceof LivingEntity
|
||||
&& !(entity instanceof Tameable)
|
||||
&& !(entity instanceof Player)
|
||||
&& (removeAnimals || !(entity instanceof Animals)));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
World world = player.getWorld();
|
||||
|
||||
if (enabled) {
|
||||
player.sendMessage(ChatColor.GRAY
|
||||
+ "WorldGuard's 'lag stop' mode has been enabled. Some parts of the game may be 'frozen'.");
|
||||
freeUp(world);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onBlockFromTo(BlockFromToEvent event) {
|
||||
if (enabled) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onBlockIgnite(BlockIgniteEvent event) {
|
||||
if (enabled) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onBlockBurn(BlockBurnEvent event) {
|
||||
if (enabled) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onBlockPhysics(BlockPhysicsEvent event) {
|
||||
if (enabled) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onBlockForm(BlockFormEvent event) {
|
||||
if (enabled) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onLeavesDecay(LeavesDecayEvent event) {
|
||||
if (enabled) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onBlockSpread(BlockSpreadEvent event) {
|
||||
if (enabled) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onEntityExplode(EntityExplodeEvent event) {
|
||||
if (enabled) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onExplosionPrime(ExplosionPrimeEvent event) {
|
||||
if (enabled) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onCreatureSpawn(CreatureSpawnEvent event) {
|
||||
if (enabled) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onChunkLoad(ChunkLoadEvent event) {
|
||||
if (enabled) {
|
||||
freeUp(event.getChunk());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,152 +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/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.World;
|
||||
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 {
|
||||
/**
|
||||
* Logger for messages.
|
||||
*/
|
||||
protected static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
||||
|
||||
/**
|
||||
* Port over the blacklist.
|
||||
*
|
||||
* @param plugin
|
||||
*/
|
||||
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()) {
|
||||
logger.warning("WorldGuard: 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 {
|
||||
logger.warning("WorldGuard: blacklist.txt has been converted " +
|
||||
"for the main world at " + newPath + "");
|
||||
logger.warning("WorldGuard: Your other worlds currently have no " +
|
||||
"blacklist defined!");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrate region settings.
|
||||
*
|
||||
* @param plugin
|
||||
*/
|
||||
public static void migrateRegions(WorldGuardPlugin plugin) {
|
||||
try {
|
||||
File oldDatabase = new File(plugin.getDataFolder(), "regions.txt");
|
||||
if (!oldDatabase.exists()) return;
|
||||
|
||||
logger.info("WorldGuard: The regions database has changed in 4.x. "
|
||||
+ "Your old regions database will be converted to the new format "
|
||||
+ "and set as your primarily 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);
|
||||
db.load();
|
||||
|
||||
// Then save the new database
|
||||
mgr.setRegions(db.getRegions());
|
||||
mgr.save();
|
||||
|
||||
oldDatabase.renameTo(new File(plugin.getDataFolder(), "regions.txt.old"));
|
||||
|
||||
logger.info("WorldGuard: Regions database converted!");
|
||||
} catch (FileNotFoundException e) {
|
||||
} catch (IOException e) {
|
||||
logger.warning("WorldGuard: Failed to load regions: "
|
||||
+ e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies a file.
|
||||
*
|
||||
* @param from
|
||||
* @param to
|
||||
* @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 ex) {
|
||||
} catch (IOException e) {
|
||||
} finally {
|
||||
if (in != null) {
|
||||
try {
|
||||
in.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
|
||||
if (out != null) {
|
||||
try {
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -20,14 +20,14 @@
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.Level;
|
||||
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 {
|
||||
/**
|
||||
@@ -37,7 +37,7 @@ public class LoggerToChatHandler extends Handler {
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
*
|
||||
* @param player
|
||||
*/
|
||||
public LoggerToChatHandler(CommandSender player) {
|
||||
@@ -63,7 +63,12 @@ public class LoggerToChatHandler extends Handler {
|
||||
*/
|
||||
@Override
|
||||
public void publish(LogRecord record) {
|
||||
player.sendMessage(ChatColor.GRAY + record.getLevel().getName() + ": "
|
||||
+ ChatColor.WHITE + record.getMessage());
|
||||
if (record.getLevel().intValue() >= Level.WARNING.intValue()) {
|
||||
player.sendMessage(ChatColor.RED + record.getLevel().getName() + ": "
|
||||
+ ChatColor.YELLOW + record.getMessage());
|
||||
} else {
|
||||
player.sendMessage(ChatColor.GRAY + record.getLevel().getName() + ": "
|
||||
+ ChatColor.WHITE + record.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
// $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.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldguard.region.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.region.RegionManager;
|
||||
import com.sk89q.worldguard.region.RegionQueryCacheEntry;
|
||||
|
||||
/**
|
||||
* A class that will cache all region queries. Instances of this class are created
|
||||
* via an instance of {@link RegionQueryCache} and represent a point in time.
|
||||
*/
|
||||
public final class RegionQuery {
|
||||
|
||||
private final WorldGuardPlugin plugin;
|
||||
private final RegionQueryCacheEntry entry;
|
||||
|
||||
/**
|
||||
* Construct the instance with the underlying cache entry.
|
||||
*
|
||||
* @param entry
|
||||
*/
|
||||
RegionQuery(WorldGuardPlugin plugin, RegionQueryCacheEntry entry) {
|
||||
this.plugin = plugin;
|
||||
this.entry = entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an {@link ApplicableRegionSet} for a given location. The result may have been
|
||||
* temporarily cached for the given event, or null if region protection has
|
||||
* been disabled for the the world of the given location.
|
||||
*
|
||||
* @param location the location to check
|
||||
* @return the set, or null if region protection is disabled for the given location
|
||||
*/
|
||||
public ApplicableRegionSet lookup(Location location) {
|
||||
World world = location.getWorld();
|
||||
Vector vector = BukkitUtil.toVector(location);
|
||||
|
||||
ConfigurationManager config = plugin.getGlobalStateManager();
|
||||
WorldConfiguration worldConfig = config.get(world);
|
||||
RegionManager regionManager = plugin.getGlobalRegionManager();
|
||||
|
||||
if (!worldConfig.useRegions) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return entry.lookup(regionManager.get(world), vector);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an {@link ApplicableRegionSet} for a given block. The result may have been
|
||||
* temporarily cached for the given event, or null if region protection has
|
||||
* been disabled for the the world of the given block.
|
||||
*
|
||||
* @param block the block to check
|
||||
* @return the set, or null if region protection is disabled for the given block
|
||||
*/
|
||||
public ApplicableRegionSet lookup(Block block) {
|
||||
return lookup(block.getLocation());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an {@link ApplicableRegionSet} for a given entity. The result may have been
|
||||
* temporarily cached for the given event, or null if region protection has
|
||||
* been disabled for the the world of the given entity.
|
||||
*
|
||||
* @param entity the entity to check
|
||||
* @return the set, or null if region protection is disabled for the given entity
|
||||
*/
|
||||
public ApplicableRegionSet lookup(Entity entity) {
|
||||
return lookup(entity.getLocation());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
// $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.event.Event;
|
||||
|
||||
import com.sk89q.worldguard.region.AbstractRegionQueryCache;
|
||||
|
||||
/**
|
||||
* An implementation of {@link AbstractRegionQueryCache} for Bukkit. This implementation
|
||||
* is thread-safe.
|
||||
*/
|
||||
public final class RegionQueryCache extends AbstractRegionQueryCache {
|
||||
|
||||
private final WorldGuardPlugin plugin;
|
||||
|
||||
/**
|
||||
* Construct the cache with the given plugin instance.
|
||||
*
|
||||
* @param plugin plugin instance
|
||||
*/
|
||||
public RegionQueryCache(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a {@link RegionQuery} object that can cache region queries. The object
|
||||
* returned by this method does not need to be cached. It is merely a proxy class.
|
||||
*
|
||||
* @param event the event to cache against
|
||||
* @return an object to perform lookups against
|
||||
*/
|
||||
public RegionQuery against(Event event) {
|
||||
return new RegionQuery(plugin, get(event));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,32 +23,29 @@ import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.*;
|
||||
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.region.RegionManager;
|
||||
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());
|
||||
@@ -61,38 +58,38 @@ public class ReportWriter {
|
||||
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);
|
||||
@@ -102,7 +99,7 @@ public class ReportWriter {
|
||||
output.append("\r\n");
|
||||
appendln();
|
||||
}
|
||||
|
||||
|
||||
private void appendReportHeader(WorldGuardPlugin plugin) {
|
||||
appendln("WorldGuard Configuration Report");
|
||||
appendln("Generated " + dateFmt.format(date));
|
||||
@@ -110,33 +107,34 @@ public class ReportWriter {
|
||||
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 e) {
|
||||
} 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)",
|
||||
@@ -161,23 +159,23 @@ public class ReportWriter {
|
||||
append(log);
|
||||
appendln();
|
||||
}
|
||||
|
||||
|
||||
private void appendPluginInformation(Plugin[] plugins) {
|
||||
appendHeader("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())
|
||||
@@ -188,42 +186,42 @@ public class ReportWriter {
|
||||
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("ID", world.getId());
|
||||
|
||||
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()) {
|
||||
@@ -232,18 +230,18 @@ public class ReportWriter {
|
||||
entry.getValue(),
|
||||
(float) (entry.getValue() / (double) loadedChunkCount));
|
||||
}
|
||||
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
append(log);
|
||||
appendln();
|
||||
}
|
||||
|
||||
|
||||
private void appendWorldConfigurations(WorldGuardPlugin plugin, List<World> worlds,
|
||||
GlobalRegionManager regionMgr, ConfigurationManager mgr) {
|
||||
RegionManager regionMgr, ConfigurationManager mgr) {
|
||||
appendHeader("World Configurations");
|
||||
|
||||
|
||||
LogListBlock log = new LogListBlock();
|
||||
|
||||
int i = 0;
|
||||
@@ -261,9 +259,9 @@ public class ReportWriter {
|
||||
+ 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 {
|
||||
@@ -271,10 +269,10 @@ public class ReportWriter {
|
||||
configLog.put(field.getName(), String.valueOf(val));
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
} catch (IllegalAccessException ignore) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (config.getBlacklist() == null) {
|
||||
blacklistLog.put("State", "DISABLED");
|
||||
} else {
|
||||
@@ -285,13 +283,13 @@ public class ReportWriter {
|
||||
config.getBlacklist().isWhitelist());
|
||||
}
|
||||
|
||||
RegionManager worldRegions = regionMgr.get(world);
|
||||
/*RegionIndex 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__");
|
||||
|
||||
Region globalRegion = worldRegions.getRegion("__global__");
|
||||
if (globalRegion == null) {
|
||||
globalRegionLog.put("Status", "UNDEFINED");
|
||||
} else {
|
||||
@@ -301,17 +299,17 @@ public class ReportWriter {
|
||||
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);
|
||||
@@ -321,15 +319,14 @@ public class ReportWriter {
|
||||
if (writer != null) {
|
||||
try {
|
||||
writer.close();
|
||||
} catch (IOException e) {
|
||||
} catch (IOException ignore) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
// $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.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import com.sk89q.worldedit.blocks.BlockID;
|
||||
|
||||
/**
|
||||
* An applicator of the sponge feature.
|
||||
*/
|
||||
class SpongeApplicator {
|
||||
|
||||
private final int spongeRadius;
|
||||
private final boolean useRedstone;
|
||||
private final boolean refillArea;
|
||||
|
||||
/**
|
||||
* Construct a new applicator.
|
||||
*
|
||||
* @param spongeRadius the radius of the sponge's effect
|
||||
* @param useRedstone use Redstone
|
||||
* @param refillArea refill the area if a sponge is removed
|
||||
*/
|
||||
public SpongeApplicator(int spongeRadius, boolean useRedstone, boolean refillArea) {
|
||||
this.spongeRadius = spongeRadius;
|
||||
this.useRedstone = useRedstone;
|
||||
this.refillArea = refillArea;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the block at the given position is water.
|
||||
*
|
||||
* @param world world
|
||||
* @param x x
|
||||
* @param y y
|
||||
* @param z z
|
||||
* @return true if it's water
|
||||
*/
|
||||
private static boolean isWater(World world, int x, int y, int z) {
|
||||
int type = world.getBlockTypeIdAt(x, y, z);
|
||||
return type == BlockID.WATER || type == BlockID.STATIONARY_WATER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the given sponge is an active sponge.
|
||||
*
|
||||
* @param block block to check
|
||||
* @return true if it's active
|
||||
*/
|
||||
public boolean isActiveSponge(Block block) {
|
||||
return block.getType() == Material.SPONGE
|
||||
&& (!useRedstone || !block.isBlockIndirectlyPowered());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if a given block near an active sponge.
|
||||
*
|
||||
* @param blockTo location of the block
|
||||
* @return true if it's near a sponge (and water should be cancelled)
|
||||
*/
|
||||
public boolean isNearSponge(Block blockTo) {
|
||||
World world = blockTo.getWorld();
|
||||
int ox = blockTo.getX();
|
||||
int oy = blockTo.getY();
|
||||
int oz = blockTo.getZ();
|
||||
|
||||
for (int cx = -spongeRadius; cx <= spongeRadius; cx++) {
|
||||
for (int cy = -spongeRadius; cy <= spongeRadius; cy++) {
|
||||
for (int cz = -spongeRadius; cz <= spongeRadius; cz++) {
|
||||
Block sponge = world.getBlockAt(ox + cx, oy + cy, oz + cz);
|
||||
if (isActiveSponge(sponge)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove water due to a sponge from the given position.
|
||||
*
|
||||
* @param block the block
|
||||
*/
|
||||
public void clearWater(Block block) {
|
||||
World world = block.getWorld();
|
||||
int ox = block.getX();
|
||||
int oy = block.getY();
|
||||
int oz = block.getZ();
|
||||
|
||||
for (int cx = -spongeRadius; cx <= spongeRadius; cx++) {
|
||||
for (int cy = -spongeRadius; cy <= spongeRadius; cy++) {
|
||||
for (int cz = -spongeRadius; cz <= spongeRadius; cz++) {
|
||||
if (isWater(world, ox + cx, oy + cy, oz + cz)) {
|
||||
world.getBlockAt(ox + cx, oy + cy, oz + cz).setTypeId(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add water due to a sponge from the given position.
|
||||
*
|
||||
* @param block the block
|
||||
*/
|
||||
public void placeWater(Block block) {
|
||||
if (!refillArea) return;
|
||||
|
||||
World world = block.getWorld();
|
||||
int ox = block.getX();
|
||||
int oy = block.getY();
|
||||
int oz = block.getZ();
|
||||
|
||||
// The negative x edge
|
||||
int cx = ox - spongeRadius - 1;
|
||||
for (int cy = oy - spongeRadius - 1; cy <= oy + spongeRadius + 1; cy++) {
|
||||
for (int cz = oz - spongeRadius - 1; cz <= oz + spongeRadius + 1; cz++) {
|
||||
if (isWater(world, cx, cy, cz)) {
|
||||
world.getBlockAt(cx + 1, cy, cz).setType(Material.STATIONARY_WATER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The positive x edge
|
||||
cx = ox + spongeRadius + 1;
|
||||
for (int cy = oy - spongeRadius - 1; cy <= oy + spongeRadius + 1; cy++) {
|
||||
for (int cz = oz - spongeRadius - 1; cz <= oz + spongeRadius + 1; cz++) {
|
||||
if (isWater(world, cx, cy, cz)) {
|
||||
world.getBlockAt(cx - 1, cy, cz).setType(Material.STATIONARY_WATER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The negative y edge
|
||||
int cy = oy - spongeRadius - 1;
|
||||
for (cx = ox - spongeRadius - 1; cx <= ox + spongeRadius + 1; cx++) {
|
||||
for (int cz = oz - spongeRadius - 1; cz <= oz + spongeRadius + 1; cz++) {
|
||||
if (isWater(world, cx, cy, cz)) {
|
||||
world.getBlockAt(cx, cy + 1, cz).setType(Material.STATIONARY_WATER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The positive y edge
|
||||
cy = oy + spongeRadius + 1;
|
||||
for (cx = ox - spongeRadius - 1; cx <= ox + spongeRadius + 1; cx++) {
|
||||
for (int cz = oz - spongeRadius - 1; cz <= oz + spongeRadius + 1; cz++) {
|
||||
if (isWater(world, cx, cy, cz)) {
|
||||
world.getBlockAt(cx, cy - 1, cz).setType(Material.STATIONARY_WATER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The negative z edge
|
||||
int cz = oz - spongeRadius - 1;
|
||||
for (cx = ox - spongeRadius - 1; cx <= ox + spongeRadius + 1; cx++) {
|
||||
for (cy = oy - spongeRadius - 1; cy <= oy + spongeRadius + 1; cy++) {
|
||||
if (isWater(world, cx, cy, cz)) {
|
||||
world.getBlockAt(cx, cy, cz + 1).setType(Material.STATIONARY_WATER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The positive z edge
|
||||
cz = oz + spongeRadius + 1;
|
||||
for (cx = ox - spongeRadius - 1; cx <= ox + spongeRadius + 1; cx++) {
|
||||
for (cy = oy - spongeRadius - 1; cy <= oy + spongeRadius + 1; cy++) {
|
||||
if (isWater(world, cx, cy, cz)) {
|
||||
world.getBlockAt(cx, cy, cz - 1).setType(Material.STATIONARY_WATER);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,124 +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/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.*;
|
||||
import org.bukkit.World;
|
||||
|
||||
public class SpongeUtil {
|
||||
|
||||
/**
|
||||
* Remove water around a sponge.
|
||||
*
|
||||
* @param plugin
|
||||
* @param world
|
||||
* @param ox
|
||||
* @param oy
|
||||
* @param oz
|
||||
*/
|
||||
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
|
||||
* @param world
|
||||
* @param ox
|
||||
* @param oy
|
||||
* @param oz
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,438 +19,416 @@
|
||||
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.sk89q.rebar.config.ConfigurationException;
|
||||
import com.sk89q.rebar.config.ConfigurationNode;
|
||||
import com.sk89q.rebar.config.YamlConfiguration;
|
||||
import com.sk89q.rebar.config.YamlConfigurationFile;
|
||||
import com.sk89q.rebar.config.YamlConfigurationResource;
|
||||
import com.sk89q.rebar.config.YamlStyle;
|
||||
import com.sk89q.rebar.util.LoggerUtils;
|
||||
import com.sk89q.rulelists.RuleList;
|
||||
import com.sk89q.rulelists.RuleEntry;
|
||||
import com.sk89q.rulelists.RuleEntryLoader;
|
||||
import com.sk89q.rulelists.RuleTemplateEntryLoader;
|
||||
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;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.CreatureType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.config.Configuration;
|
||||
|
||||
/**
|
||||
* Holds the configuration for individual worlds.
|
||||
*
|
||||
* @author sk89q
|
||||
* @author Michael
|
||||
*/
|
||||
public class WorldConfiguration {
|
||||
|
||||
public static final String CONFIG_HEADER = "#\r\n" +
|
||||
"# WorldGuard's configuration file.\r\n" +
|
||||
"#\r\n" +
|
||||
"# This is the a per-world configuration file. It only affects one\r\n" +
|
||||
"# corresponding world.\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";
|
||||
private static Logger logger = LoggerUtils.getLogger(WorldConfiguration.class, "[WorldGuard] ");
|
||||
|
||||
private static final Logger logger = Logger
|
||||
.getLogger("Minecraft.WorldGuard");
|
||||
|
||||
private WorldGuardPlugin plugin;
|
||||
|
||||
private String worldName;
|
||||
private Configuration parentConfig;
|
||||
private Configuration config;
|
||||
private File configFile;
|
||||
private File blacklistFile;
|
||||
private final WorldGuardPlugin plugin;
|
||||
private final ConfigurationManager configMan;
|
||||
private final YamlConfigurationFile config;
|
||||
private final String worldName;
|
||||
|
||||
private Blacklist blacklist;
|
||||
private ChestProtection chestProtection = new SignChestProtection();
|
||||
private RuleList ruleList = new RuleList();
|
||||
private SpongeApplicator spongeApplicator = null;
|
||||
|
||||
/* Configuration data start */
|
||||
public boolean opPermissions;
|
||||
public boolean fireSpreadDisableToggle;
|
||||
public boolean enforceOneSession;
|
||||
public boolean itemDurability;
|
||||
public boolean classicWater;
|
||||
public boolean simulateSponge;
|
||||
public int spongeRadius;
|
||||
public boolean pumpkinScuba;
|
||||
public boolean redstoneSponges;
|
||||
public boolean noPhysicsGravel;
|
||||
public boolean noPhysicsSand;
|
||||
public boolean allowPortalAnywhere;
|
||||
public Set<Integer> preventWaterDamage;
|
||||
public boolean blockTNT;
|
||||
public boolean blockLighter;
|
||||
public boolean disableFireSpread;
|
||||
public Set<Integer> disableFireSpreadBlocks;
|
||||
public boolean preventLavaFire;
|
||||
public Set<Integer> allowedLavaSpreadOver;
|
||||
public boolean blockCreeperExplosions;
|
||||
public boolean blockCreeperBlockDamage;
|
||||
public int loginProtection;
|
||||
public int spawnProtection;
|
||||
public boolean kickOnDeath;
|
||||
public boolean exactRespawn;
|
||||
public boolean teleportToHome;
|
||||
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 = 287;
|
||||
public Set<CreatureType> blockCreatureSpawn;
|
||||
public boolean useiConomy;
|
||||
public boolean buyOnClaim;
|
||||
public double buyOnClaimPrice;
|
||||
public int regionWand;
|
||||
public boolean regionInvinciblityRemovesMobs;
|
||||
// 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 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 disableSignChestProtectionCheck;
|
||||
private Map<String, Integer> maxRegionCounts;
|
||||
public boolean fireSpreadDisableToggle;
|
||||
/* Configuration data end */
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param plugin
|
||||
* @param worldName
|
||||
* @param plugin the plugin instance
|
||||
* @param worldName name of the world that this object is for
|
||||
* @param configMan configuration manager
|
||||
* @param parentConfig parent configuration
|
||||
*/
|
||||
public WorldConfiguration(WorldGuardPlugin plugin, String worldName) {
|
||||
File baseFolder = new File(plugin.getDataFolder(), "worlds/" + worldName);
|
||||
configFile = new File(baseFolder, "config.yml");
|
||||
blacklistFile = new File(baseFolder, "blacklist.txt");
|
||||
|
||||
public WorldConfiguration(WorldGuardPlugin plugin, String worldName,
|
||||
ConfigurationManager configMan, ConfigurationNode parentConfig) {
|
||||
this.plugin = plugin;
|
||||
this.worldName = worldName;
|
||||
this.parentConfig = plugin.getConfiguration();
|
||||
this.configMan = configMan;
|
||||
|
||||
WorldGuardPlugin.createDefaultConfiguration(configFile, "config_world.yml");
|
||||
WorldGuardPlugin.createDefaultConfiguration(blacklistFile, "blacklist.txt");
|
||||
File file = configMan.getWorldConfigFile(worldName);
|
||||
config = new YamlConfigurationFile(file, ConfigurationManager.YAML_STYLE);
|
||||
config.setParent(parentConfig);
|
||||
|
||||
config = new Configuration(this.configFile);
|
||||
loadConfiguration();
|
||||
|
||||
logger.info("WorldGuard: Loaded configuration for world '" + worldName + '"');
|
||||
}
|
||||
|
||||
private boolean getBoolean(String node, boolean def) {
|
||||
if (config.getProperty(node) != null) {
|
||||
return config.getBoolean(node, def);
|
||||
} else {
|
||||
return parentConfig.getBoolean(node, def);
|
||||
}
|
||||
}
|
||||
|
||||
private String getString(String node, String def) {
|
||||
if (config.getProperty(node) != null) {
|
||||
return config.getString(node, def);
|
||||
} else {
|
||||
return parentConfig.getString(node, def);
|
||||
}
|
||||
}
|
||||
|
||||
private int getInt(String node, int def) {
|
||||
if (config.getProperty(node) != null) {
|
||||
return config.getInt(node, def);
|
||||
} else {
|
||||
return parentConfig.getInt(node, def);
|
||||
}
|
||||
}
|
||||
|
||||
private double getDouble(String node, double def) {
|
||||
if (config.getProperty(node) != null) {
|
||||
return config.getDouble(node, def);
|
||||
} else {
|
||||
return parentConfig.getDouble(node, def);
|
||||
}
|
||||
}
|
||||
|
||||
private List<Integer> getIntList(String node, List<Integer> def) {
|
||||
if (config.getProperty(node) != null) {
|
||||
return config.getIntList(node, def);
|
||||
} else {
|
||||
return parentConfig.getIntList(node, def);
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> getStringList(String node, List<String> def) {
|
||||
if (config.getProperty(node) != null) {
|
||||
return config.getStringList(node, def);
|
||||
} else {
|
||||
return parentConfig.getStringList(node, def);
|
||||
}
|
||||
load();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the configuration.
|
||||
*/
|
||||
private void loadConfiguration() {
|
||||
config.load();
|
||||
private void load() {
|
||||
logger.info("Loading configuration for '" + worldName + "'...");
|
||||
|
||||
opPermissions = getBoolean("op-permissions", true);
|
||||
loadConfig();
|
||||
|
||||
enforceOneSession = getBoolean("protection.enforce-single-session", true);
|
||||
itemDurability = getBoolean("protection.item-durability", true);
|
||||
removeInfiniteStacks = getBoolean("protection.remove-infinite-stacks", false);
|
||||
// Load rule lists
|
||||
ruleList.clear();
|
||||
loadBuiltInRules();
|
||||
loadUserRules();
|
||||
loadBlacklist();
|
||||
loadSettings();
|
||||
|
||||
classicWater = getBoolean("simulation.classic-water", false);
|
||||
simulateSponge = getBoolean("simulation.sponge.enable", true);
|
||||
spongeRadius = Math.max(1, getInt("simulation.sponge.radius", 3)) - 1;
|
||||
redstoneSponges = getBoolean("simulation.sponge.redstone", false);
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
pumpkinScuba = getBoolean("pumpkin-scuba", false);
|
||||
|
||||
noPhysicsGravel = getBoolean("physics.no-physics-gravel", false);
|
||||
noPhysicsSand = getBoolean("physics.no-physics-sand", false);
|
||||
allowPortalAnywhere = getBoolean("physics.allow-portal-anywhere", false);
|
||||
preventWaterDamage = new HashSet<Integer>(getIntList("physics.disable-water-damage-blocks", null));
|
||||
|
||||
blockTNT = getBoolean("ignition.block-tnt", 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);
|
||||
antiWolfDumbness = getBoolean("mobs.anti-wolf-dumbness", false);
|
||||
|
||||
loginProtection = getInt("spawn.login-protection", 3);
|
||||
spawnProtection = getInt("spawn.spawn-protection", 0);
|
||||
kickOnDeath = getBoolean("spawn.kick-on-death", false);
|
||||
exactRespawn = getBoolean("spawn.exact-respawn", false);
|
||||
teleportToHome = getBoolean("spawn.teleport-to-home-on-death", 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);
|
||||
|
||||
signChestProtection = getBoolean("chest-protection.enable", 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);
|
||||
|
||||
useRegions = getBoolean("regions.enable", true);
|
||||
highFreqFlags = getBoolean("regions.high-frequency-flags", false);
|
||||
regionWand = getInt("regions.wand", 287);
|
||||
maxClaimVolume = getInt("regions.max-claim-volume", 30000);
|
||||
claimOnlyInsideExistingRegions = getBoolean("regions.claim-only-inside-existing-regions", false);
|
||||
maxRegionCountPerPlayer = getInt("regions.max-region-count-per-player", 7);
|
||||
|
||||
useiConomy = getBoolean("iconomy.enable", false);
|
||||
buyOnClaim = getBoolean("iconomy.buy-on-claim", false);
|
||||
buyOnClaimPrice = getDouble("iconomy.buy-on-claim-price", 1.0);
|
||||
|
||||
blockCreatureSpawn = new HashSet<CreatureType>();
|
||||
for (String creatureName : getStringList("mobs.block-creature-spawn", null)) {
|
||||
CreatureType creature = CreatureType.fromName(creatureName);
|
||||
|
||||
if (creature == null) {
|
||||
logger.warning("WorldGuard: Unknown mob type '" + creatureName + "'");
|
||||
} 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
|
||||
/**
|
||||
* Load the configuration from file.
|
||||
*/
|
||||
private void loadConfig() {
|
||||
try {
|
||||
config.load();
|
||||
} catch (IOException e) {
|
||||
logger.log(Level.SEVERE, "Error reading configuration for world " + worldName, e);
|
||||
} catch (ConfigurationException e) {
|
||||
logger.log(Level.SEVERE, "Error reading configuration for world " + worldName, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the configuration to file.
|
||||
*/
|
||||
private void saveConfig() {
|
||||
config.setHeader(
|
||||
"# CONFIGURATION FILE FOR ONLY THIS WORLD\r\n" +
|
||||
"#\r\n" +
|
||||
"# Everything in here applies to ONLY this world. For global settings, edit \r\n" +
|
||||
"# the file in plugins/WorldGuard/config.yml\r\n" +
|
||||
"#\r\n" +
|
||||
"# How do you use this file? Copy potions of the global configuration file into this file.\r\n" +
|
||||
"#\r\n" +
|
||||
"# EXAMPLE (remove the # in front):\r\n" +
|
||||
"#physics:\r\n" +
|
||||
"# block-tnt-damage: false");
|
||||
|
||||
try {
|
||||
config.save();
|
||||
} catch (IOException e) {
|
||||
logger.log(Level.SEVERE, "Failed to save configuration", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the built-in rules.
|
||||
*/
|
||||
private void loadBuiltInRules() {
|
||||
try {
|
||||
RuleTemplateEntryLoader loader = new RuleTemplateEntryLoader(
|
||||
plugin.getRulesListManager(), config);
|
||||
|
||||
for (List<RuleEntry> entries : plugin.getBuiltInRules().listOf("", loader)) {
|
||||
for (RuleEntry entry : entries) {
|
||||
ruleList.learn(entry);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.log(Level.SEVERE, "Failed to load the built-in rules", e);
|
||||
} catch (ConfigurationException e) {
|
||||
logger.log(Level.SEVERE, "Failed to load the built-in rules", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the user rules.
|
||||
*/
|
||||
private void loadUserRules() {
|
||||
File rulesFile = configMan.getRuleListFile(worldName);
|
||||
RuleEntryLoader entryLoader = new RuleEntryLoader(plugin.getRulesListManager());
|
||||
YamlConfigurationFile rulesConfig = new YamlConfigurationFile(rulesFile,
|
||||
ConfigurationManager.YAML_STYLE, false);
|
||||
|
||||
try {
|
||||
rulesConfig.load();
|
||||
|
||||
for (RuleEntry entry : rulesConfig.listOf(ConfigurationNode.ROOT, entryLoader)) {
|
||||
ruleList.learn(entry);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.log(Level.SEVERE, "Failed to load " + rulesFile.getAbsolutePath(), e);
|
||||
} catch (ConfigurationException e) {
|
||||
logger.log(Level.SEVERE, "Failed to load " + rulesFile.getAbsolutePath(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the blacklist.
|
||||
*/
|
||||
private void loadBlacklist() {
|
||||
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);
|
||||
File blacklistFile = configMan.getBlacklistFile(worldName);
|
||||
|
||||
// If the blacklist is empty, then set the field to null
|
||||
// and save some resources
|
||||
if (blist.isEmpty()) {
|
||||
// Load blacklist settings
|
||||
boolean useBlacklistAsWhitelist = config.getBoolean("blacklist.use-as-whitelist", false);
|
||||
boolean logConsole = config.getBoolean("blacklist.logging.console.enable", true);
|
||||
boolean logDatabase = config.getBoolean("blacklist.logging.database.enable", false);
|
||||
String dsn = config.getString("blacklist.logging.database.dsn", "jdbc:mysql://localhost:3306/minecraft");
|
||||
String user = config.getString("blacklist.logging.database.user", "root");
|
||||
String pass = config.getString("blacklist.logging.database.pass", "");
|
||||
String table = config.getString("blacklist.logging.database.table", "blacklist_events");
|
||||
boolean logFile = config.getBoolean("blacklist.logging.file.enable", false);
|
||||
String logFilePattern = config.getString("blacklist.logging.file.path", "worldguard/logs/%Y-%m-%d.log");
|
||||
int logFileCacheSize = Math.max(1, config.getInt("blacklist.logging.file.open-files", 10));
|
||||
|
||||
Blacklist newBlacklist = new BukkitBlacklist(useBlacklistAsWhitelist, plugin);
|
||||
newBlacklist.load(blacklistFile);
|
||||
|
||||
// If the blacklist is empty, then set the field to null and save some resources
|
||||
if (newBlacklist.isEmpty()) {
|
||||
this.blacklist = null;
|
||||
} else {
|
||||
this.blacklist = blist;
|
||||
logger.log(Level.INFO, "WorldGuard: Blacklist loaded.");
|
||||
this.blacklist = newBlacklist;
|
||||
logger.log(Level.INFO, "Blacklist loaded.");
|
||||
|
||||
BlacklistLogger blacklistLogger = blist.getLogger();
|
||||
BlacklistLogger blacklistLogger = newBlacklist.getLogger();
|
||||
|
||||
if (logDatabase) {
|
||||
blacklistLogger.addHandler(new DatabaseLoggerHandler(dsn, user, pass, table, worldName));
|
||||
}
|
||||
if (logDatabase)
|
||||
blacklistLogger.addHandler(new DatabaseLoggerHandler(dsn, user,
|
||||
pass, table, worldName, logger));
|
||||
|
||||
if (logConsole) {
|
||||
blacklistLogger.addHandler(new ConsoleLoggerHandler(worldName));
|
||||
}
|
||||
if (logConsole)
|
||||
blacklistLogger.addHandler(new ConsoleLoggerHandler(worldName,
|
||||
logger));
|
||||
|
||||
if (logFile) {
|
||||
FileLoggerHandler handler =
|
||||
new FileLoggerHandler(logFilePattern, logFileCacheSize, worldName);
|
||||
FileLoggerHandler handler = new FileLoggerHandler(logFilePattern,
|
||||
logFileCacheSize, worldName, logger);
|
||||
blacklistLogger.addHandler(handler);
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
logger.log(Level.WARNING, "WorldGuard blacklist does not exist.");
|
||||
logger.log(Level.WARNING, "WorldGuard blacklist does not exist", e);
|
||||
} catch (IOException e) {
|
||||
logger.log(Level.WARNING, "Could not load WorldGuard blacklist: "
|
||||
+ e.getMessage());
|
||||
logger.log(Level.WARNING, "Could not load blacklist", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the settings.
|
||||
*/
|
||||
private void loadSettings() {
|
||||
opPermissions = config.getBoolean("op-permissions", true);
|
||||
|
||||
boolean simulateSponge = config.getBoolean("simulation.sponge.enable", true);
|
||||
int spongeRadius = Math.max(1, config.getInt("simulation.sponge.radius", 3)) - 1;
|
||||
boolean redstoneSponges = config.getBoolean("simulation.sponge.redstone", false);
|
||||
boolean refillArea = config.getBoolean("simulation.sponge.refill-area", false);
|
||||
if (simulateSponge) {
|
||||
spongeApplicator = new SpongeApplicator(spongeRadius, redstoneSponges, refillArea);
|
||||
}
|
||||
|
||||
// Print an overview of settings
|
||||
if (getBoolean("summary-on-start", true)) {
|
||||
logger.log(Level.INFO, enforceOneSession
|
||||
? "WorldGuard: (" + worldName + ") Single session is enforced."
|
||||
: "WorldGuard: (" + worldName + ") Single session is NOT ENFORCED.");
|
||||
logger.log(Level.INFO, blockTNT
|
||||
? "WorldGuard: (" + worldName + ") TNT ignition is blocked."
|
||||
: "WorldGuard: (" + worldName + ") TNT ignition is PERMITTED.");
|
||||
logger.log(Level.INFO, blockLighter
|
||||
? "WorldGuard: (" + worldName + ") Lighters are blocked."
|
||||
: "WorldGuard: (" + worldName + ") Lighters are PERMITTED.");
|
||||
logger.log(Level.INFO, preventLavaFire
|
||||
? "WorldGuard: (" + worldName + ") Lava fire is blocked."
|
||||
: "WorldGuard: (" + worldName + ") Lava fire is PERMITTED.");
|
||||
signChestProtection = config.getBoolean("chest-protection.enable", false);
|
||||
disableSignChestProtectionCheck = config.getBoolean("chest-protection.disable-off-check", false);
|
||||
|
||||
if (disableFireSpread) {
|
||||
logger.log(Level.INFO, "WorldGuard: (" + worldName + ") All fire spread is disabled.");
|
||||
} else {
|
||||
if (disableFireSpreadBlocks.size() > 0) {
|
||||
logger.log(Level.INFO, "WorldGuard: (" + worldName
|
||||
+ ") Fire spread is limited to "
|
||||
+ disableFireSpreadBlocks.size() + " block types.");
|
||||
} else {
|
||||
logger.log(Level.INFO, "WorldGuard: (" + worldName
|
||||
+ ") Fire spread is UNRESTRICTED.");
|
||||
useRegions = config.getBoolean("regions.enable", true);
|
||||
regionInvinciblityRemovesMobs = config.getBoolean("regions.invincibility-removes-mobs", false);
|
||||
highFreqFlags = config.getBoolean("regions.high-frequency-flags", false);
|
||||
regionWand = config.getInt("regions.wand", 287);
|
||||
maxClaimVolume = config.getInt("regions.max-claim-volume", 30000);
|
||||
claimOnlyInsideExistingRegions = config.getBoolean("regions.claim-only-inside-existing-regions", false);
|
||||
|
||||
maxRegionCountPerPlayer = config.getInt("regions.max-region-count-per-player.default", 7);
|
||||
maxRegionCounts = new HashMap<String, Integer>();
|
||||
maxRegionCounts.put(null, maxRegionCountPerPlayer);
|
||||
|
||||
for (String key : config.getKeys("regions.max-region-count-per-player")) {
|
||||
if (!key.equalsIgnoreCase("default")) {
|
||||
Object val = config.get("regions.max-region-count-per-player." + key);
|
||||
if (val != null && val instanceof Number) {
|
||||
maxRegionCounts.put(key, ((Number) val).intValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
config.setHeader(CONFIG_HEADER);
|
||||
config.save();
|
||||
// Very important part for protection!
|
||||
if (useRegions) {
|
||||
loadRegionModels();
|
||||
}
|
||||
|
||||
// useiConomy = getBoolean("iconomy.enable", false);
|
||||
// buyOnClaim = getBoolean("iconomy.buy-on-claim", false);
|
||||
// buyOnClaimPrice = getDouble("iconomy.buy-on-claim-price", 1.0);
|
||||
}
|
||||
|
||||
public Blacklist getBlacklist() {
|
||||
return this.blacklist;
|
||||
/**
|
||||
* Load region protection model.
|
||||
*/
|
||||
private void loadRegionModels() {
|
||||
List<String> filenames;
|
||||
RuleEntryLoader entryLoader = new RuleEntryLoader(plugin.getRulesListManager());
|
||||
|
||||
// Make a default protection model list
|
||||
List<String> defaultProtectionModels = new ArrayList<String>();
|
||||
defaultProtectionModels.add("minimal");
|
||||
|
||||
// Load protection model
|
||||
filenames = config.getStringList("regions.protection-models", defaultProtectionModels);
|
||||
for (YamlConfiguration config : readFiles(filenames, "/models/protection/",
|
||||
new File(plugin.getDataFolder(), "models/protection"))) {
|
||||
for (RuleEntry entry : config.listOf(ConfigurationNode.ROOT, entryLoader)) {
|
||||
ruleList.learn(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the blacklist.
|
||||
*
|
||||
* @return the blacklist
|
||||
*/
|
||||
Blacklist getBlacklist() {
|
||||
return blacklist;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the RuleList.
|
||||
*
|
||||
* @return the rule list
|
||||
*/
|
||||
RuleList getRuleList() {
|
||||
return ruleList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the sponge applicator.
|
||||
*
|
||||
* @return sponge applicator
|
||||
*/
|
||||
SpongeApplicator getSpongeApplicator() {
|
||||
return spongeApplicator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the world name of this configuration.
|
||||
*
|
||||
* @return the world name
|
||||
*/
|
||||
public String getWorldName() {
|
||||
return this.worldName;
|
||||
}
|
||||
|
||||
public boolean isChestProtected(Block block, Player player) {
|
||||
if (!signChestProtection) {
|
||||
return false;
|
||||
|
||||
/**
|
||||
* Get the maximum region count for a given player.
|
||||
*
|
||||
* @param player player
|
||||
* @return number of regions
|
||||
*/
|
||||
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 (plugin.hasPermission(player, "worldguard.chest-protection.override")
|
||||
|| plugin.hasPermission(player, "worldguard.override.chest-protection")) {
|
||||
return false;
|
||||
if (max <= -1) {
|
||||
max = maxRegionCountPerPlayer;
|
||||
}
|
||||
return chestProtection.isProtected(block, player);
|
||||
}
|
||||
|
||||
public boolean isChestProtected(Block block) {
|
||||
if (!signChestProtection) {
|
||||
return false;
|
||||
}
|
||||
return 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);
|
||||
return max;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
/**
|
||||
* Read a list of files, either from the .jar (preferred) or from disk.
|
||||
*
|
||||
* @param filenames list of filenames
|
||||
* @param internalDir the base path for the JAR files
|
||||
* @param externalDir the base dir for the disk files
|
||||
* @return a list of {@link YamlConfiguration}s
|
||||
*/
|
||||
private static List<YamlConfiguration> readFiles(Collection<String> filenames,
|
||||
String internalDir, File externalDir) {
|
||||
List<YamlConfiguration> configs = new ArrayList<YamlConfiguration>();
|
||||
|
||||
public ChestProtection getChestProtection() {
|
||||
return chestProtection;
|
||||
for (String filename : filenames) {
|
||||
YamlConfiguration config;
|
||||
|
||||
// External file path
|
||||
File file = new File(externalDir, filename);
|
||||
file.getParentFile().mkdirs();
|
||||
|
||||
// Try loading from the .jar first
|
||||
String path = internalDir + filename + ".yml";
|
||||
config = new YamlConfigurationResource(WorldGuardPlugin.class, path);
|
||||
try {
|
||||
config.load();
|
||||
configs.add(config);
|
||||
continue; // Found!
|
||||
} catch (FileNotFoundException e) {
|
||||
// Do nothing
|
||||
} catch (IOException e) {
|
||||
logger.log(Level.SEVERE, "Failed to internal path " + path, e);
|
||||
} catch (ConfigurationException e) {
|
||||
logger.log(Level.SEVERE, "Failed to internal path " + path, e);
|
||||
}
|
||||
|
||||
// Try loading from disk
|
||||
config = new YamlConfigurationFile(file, new YamlStyle(), false);
|
||||
try {
|
||||
config.load();
|
||||
configs.add(config);
|
||||
continue; // Found!
|
||||
} catch (FileNotFoundException e) {
|
||||
logger.log(Level.SEVERE, "Failed to load " + file.getAbsolutePath());
|
||||
} catch (IOException e) {
|
||||
logger.log(Level.SEVERE, "Failed to load " + file.getAbsolutePath(), e);
|
||||
} catch (ConfigurationException e) {
|
||||
logger.log(Level.SEVERE, "Failed to load " + file.getAbsolutePath(), e);
|
||||
}
|
||||
}
|
||||
|
||||
return configs;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,585 +16,330 @@
|
||||
* 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.protection.flags.DefaultFlag;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import org.bukkit.event.Event.Priority;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.block.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
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.inventory.ItemStack;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BlockType;
|
||||
import com.sk89q.worldedit.blocks.ItemType;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.blacklist.events.*;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import org.bukkit.event.block.BlockPhysicsEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.block.BlockSpreadEvent;
|
||||
import org.bukkit.event.block.LeavesDecayEvent;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.*;
|
||||
import com.sk89q.rulelists.DefaultAttachments;
|
||||
import com.sk89q.rulelists.RuleSet;
|
||||
import com.sk89q.worldedit.blocks.BlockID;
|
||||
|
||||
/**
|
||||
* The listener for block events.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class WorldGuardBlockListener extends BlockListener {
|
||||
/**
|
||||
* Logger for messages.
|
||||
*/
|
||||
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
||||
class WorldGuardBlockListener implements Listener {
|
||||
|
||||
private WorldGuardPlugin plugin;
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param plugin
|
||||
* Construct the listener.
|
||||
*
|
||||
* @param plugin WorldGuard plugin
|
||||
*/
|
||||
public WorldGuardBlockListener(WorldGuardPlugin plugin) {
|
||||
WorldGuardBlockListener(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register events.
|
||||
* Register the events.
|
||||
*/
|
||||
public void registerEvents() {
|
||||
PluginManager pm = plugin.getServer().getPluginManager();
|
||||
|
||||
registerEvent("BLOCK_DAMAGE", Priority.High);
|
||||
registerEvent("BLOCK_BREAK", Priority.High);
|
||||
registerEvent("BLOCK_FROMTO", Priority.Normal);
|
||||
registerEvent("BLOCK_IGNITE", Priority.High);
|
||||
registerEvent("BLOCK_PHYSICS", Priority.Normal);
|
||||
registerEvent("BLOCK_PLACE", Priority.High);
|
||||
registerEvent("BLOCK_BURN", Priority.High);
|
||||
registerEvent("SIGN_CHANGE", Priority.High);
|
||||
registerEvent("REDSTONE_CHANGE", Priority.High);
|
||||
registerEvent("SNOW_FORM", Priority.High);
|
||||
registerEvent("LEAVES_DECAY", Priority.High);
|
||||
registerEvent("BLOCK_FORM", Priority.High);
|
||||
registerEvent("BLOCK_SPREAD", Priority.High);
|
||||
void registerEvents() {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an event, but not failing if the event is not implemented.
|
||||
*
|
||||
* @param typeName
|
||||
* @param priority
|
||||
*/
|
||||
private void registerEvent(String typeName, Priority priority) {
|
||||
try {
|
||||
Event.Type type = Event.Type.valueOf(typeName);
|
||||
PluginManager pm = plugin.getServer().getPluginManager();
|
||||
pm.registerEvent(type, this, priority, plugin);
|
||||
} catch (IllegalArgumentException e) {
|
||||
logger.info("WorldGuard: Unable to register missing event type " + typeName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the world configuration given a world.
|
||||
*
|
||||
* @param world
|
||||
* @return
|
||||
*/
|
||||
protected WorldConfiguration getWorldConfig(World world) {
|
||||
return plugin.getGlobalStateManager().get(world);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the world configuration given a player.
|
||||
*
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
protected WorldConfiguration getWorldConfig(Player player) {
|
||||
return plugin.getGlobalStateManager().get(player.getWorld());
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a block is damaged.
|
||||
*/
|
||||
@Override
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onBlockDamage(BlockDamageEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
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.getType() == Material.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.
|
||||
*/
|
||||
@Override
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
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())) {
|
||||
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.
|
||||
*/
|
||||
@Override
|
||||
public void onBlockFromTo(BlockFromToEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
|
||||
|
||||
if (cfg.activityHaltToggle) {
|
||||
// Cake are damaged and not broken when they are eaten, so we must
|
||||
// handle them a bit separately
|
||||
if (blockDamaged.getTypeId() == BlockID.CAKE_BLOCK) {
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.BLOCK_INTERACT);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setSourceEntity(player);
|
||||
context.setTargetBlock(event.getBlock().getState());
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Block block = event.getBlock();
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.BLOCK_BREAK);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setSourceEntity(player);
|
||||
context.setTargetBlock(event.getBlock().getState());
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.simulateSponge && isWater) {
|
||||
int ox = blockTo.getX();
|
||||
int oy = blockTo.getY();
|
||||
int oz = blockTo.getZ();
|
||||
/* --- No short-circuit returns below this line --- */
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Sponges
|
||||
SpongeApplicator spongeAppl = wcfg.getSpongeApplicator();
|
||||
if (spongeAppl != null && block.getType() == Material.SPONGE) {
|
||||
if (spongeAppl.isActiveSponge(block)) {
|
||||
spongeAppl.placeWater(block);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*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;
|
||||
}
|
||||
}*/
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBlockFromTo(BlockFromToEvent event) {
|
||||
Block blockFrom = event.getBlock();
|
||||
Block blockTo = event.getToBlock();
|
||||
|
||||
// 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 ((blockFrom.getTypeId() == 0 || isWater) &&
|
||||
wcfg.preventWaterDamage.contains(targetId)) {
|
||||
boolean isWater = blockFrom.getTypeId() == 8 || blockFrom.getTypeId() == 9;
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
|
||||
|
||||
// Sponges
|
||||
SpongeApplicator spongeAppl = wcfg.getSpongeApplicator();
|
||||
if (spongeAppl != null && isWater) {
|
||||
if (spongeAppl.isNearSponge(blockTo)) {
|
||||
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())) {
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.BLOCK_SPREAD);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setSourceBlock(event.getBlock().getState());
|
||||
context.setTargetBlock(event.getToBlock().getState());
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a block gets ignited.
|
||||
*/
|
||||
@Override
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onBlockIgnite(BlockIgniteEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
IgniteCause cause = event.getCause();
|
||||
Block block = event.getBlock();
|
||||
World world = block.getWorld();
|
||||
boolean isFireSpread = cause == IgniteCause.SPREAD;
|
||||
|
||||
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
|
||||
&& event.getPlayer() != null
|
||||
&& !plugin.hasPermission(event.getPlayer(), "worldguard.override.lighter")) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Fire stop toggle
|
||||
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();
|
||||
// RuleLists
|
||||
RuleSet rules;
|
||||
BukkitContext context;
|
||||
BlockState placedState;
|
||||
|
||||
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))) {
|
||||
switch (event.getCause()) {
|
||||
case FLINT_AND_STEEL:
|
||||
// Consider flint and steel as an item use
|
||||
rules = wcfg.getRuleList().get(DefaultAttachments.ITEM_USE);
|
||||
context = new BukkitContext(plugin, event);
|
||||
context.setSourceEntity(event.getPlayer());
|
||||
context.setTargetBlock(event.getBlock().getState());
|
||||
context.setItem(event.getPlayer().getItemInHand()); // Should be flint and steel
|
||||
|
||||
// Make a virtual new state
|
||||
placedState = event.getBlock().getState();
|
||||
placedState.setType(Material.FIRE);
|
||||
context.setPlacedBlock(placedState);
|
||||
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case LAVA:
|
||||
case SPREAD:
|
||||
// Consider everything else as a block spread
|
||||
rules = wcfg.getRuleList().get(DefaultAttachments.BLOCK_SPREAD);
|
||||
context = new BukkitContext(plugin, event);
|
||||
context.setTargetBlock(event.getBlock().getState());
|
||||
|
||||
// Make a virtual source state
|
||||
BlockState sourceState = event.getBlock().getState();
|
||||
sourceState.setType(event.getCause() == IgniteCause.LAVA ? Material.LAVA : Material.FIRE);
|
||||
context.setSourceBlock(sourceState);
|
||||
|
||||
// Make a virtual new state
|
||||
placedState = event.getBlock().getState();
|
||||
placedState.setType(Material.FIRE);
|
||||
context.setPlacedBlock(placedState);
|
||||
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case FIREBALL:
|
||||
case LIGHTNING:
|
||||
// Consider everything else as a block spread
|
||||
rules = wcfg.getRuleList().get(DefaultAttachments.BLOCK_PLACE);
|
||||
context = new BukkitContext(plugin, event);
|
||||
context.setTargetBlock(event.getBlock().getState());
|
||||
|
||||
// Make a virtual new state
|
||||
placedState = event.getBlock().getState();
|
||||
placedState.setType(Material.FIRE);
|
||||
context.setPlacedBlock(placedState);
|
||||
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
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) {
|
||||
if (!set.canBuild(localPlayer)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (!set.allows(DefaultFlag.LIGHTER)
|
||||
&& !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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a block is destroyed from burning.
|
||||
*/
|
||||
@Override
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onBlockBurn(BlockBurnEvent event) {
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// Fire stop toggle
|
||||
if (wcfg.fireSpreadDisableToggle) {
|
||||
Block block = event.getBlock();
|
||||
event.setCancelled(true);
|
||||
BukkitUtil.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);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (wcfg.isChestProtected(event.getBlock())) {
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.BLOCK_BREAK);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
BlockState virtualFireState = event.getBlock().getState();
|
||||
virtualFireState.setType(Material.FIRE);
|
||||
context.setSourceBlock(virtualFireState);
|
||||
context.setTargetBlock(event.getBlock().getState());
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.useRegions) {
|
||||
Block block = event.getBlock();
|
||||
Vector pt = toVector(block);
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(block.getWorld());
|
||||
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
|
||||
|
||||
if (!set.allows(DefaultFlag.FIRE_SPREAD)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when block physics occurs.
|
||||
*/
|
||||
@Override
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBlockPhysics(BlockPhysicsEvent event) {
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
Block block = event.getBlock();
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
|
||||
|
||||
if (cfg.activityHaltToggle) {
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.BLOCK_PHYSICS);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setTargetBlock(event.getBlock().getState());
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
int id = event.getChangedTypeId();
|
||||
/* --- No short-circuit returns below this line --- */
|
||||
|
||||
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;
|
||||
// Sponges
|
||||
SpongeApplicator spongeAppl = wcfg.getSpongeApplicator();
|
||||
if (spongeAppl != null && block.getType() == Material.SPONGE) {
|
||||
if (spongeAppl.isActiveSponge(block)) {
|
||||
spongeAppl.placeWater(block);
|
||||
} else {
|
||||
spongeAppl.clearWater(block);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player places a block.
|
||||
*/
|
||||
@Override
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Block blockPlaced = event.getBlock();
|
||||
Player player = event.getPlayer();
|
||||
World world = blockPlaced.getWorld();
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(world);
|
||||
|
||||
if (wcfg.useRegions) {
|
||||
if (!plugin.getGlobalRegionManager().canBuild(player, blockPlaced.getLocation())) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
// Sponges
|
||||
SpongeApplicator spongeAppl = wcfg.getSpongeApplicator();
|
||||
if (spongeAppl != null && spongeAppl.isActiveSponge(blockPlaced)) {
|
||||
spongeAppl.clearWater(blockPlaced);
|
||||
}
|
||||
|
||||
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.getType())) {
|
||||
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.
|
||||
*/
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.BLOCK_PLACE);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setSourceEntity(event.getPlayer());
|
||||
context.setTargetBlock(event.getBlock().getState());
|
||||
context.setPlacedBlock(event.getBlockReplacedState());
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a sign is changed.
|
||||
*/
|
||||
@Override
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onSignChange(SignChangeEvent event) {
|
||||
|
||||
Player player = event.getPlayer();
|
||||
WorldConfiguration wcfg = getWorldConfig(player);
|
||||
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(player.getWorld());
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.BLOCK_INTERACT);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setTargetBlock(event.getBlock().getState());
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Chest protection
|
||||
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.");
|
||||
dropSign(event.getBlock());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getBlock().getType() != Material.SIGN_POST) {
|
||||
if (event.getBlock().getTypeId() != BlockID.SIGN_POST) {
|
||||
player.sendMessage(ChatColor.RED
|
||||
+ "The [Lock] sign must be a sign post, not a wall sign.");
|
||||
|
||||
dropSign(event.getBlock());
|
||||
event.getBlock().breakNaturally();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@@ -603,104 +348,114 @@ public class WorldGuardBlockListener extends BlockListener {
|
||||
player.sendMessage(ChatColor.RED
|
||||
+ "The first owner line must be your name.");
|
||||
|
||||
dropSign(event.getBlock());
|
||||
event.getBlock().breakNaturally();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
Material below = event.getBlock().getRelative(0, -1, 0).getType();
|
||||
|
||||
if (below == Material.TNT || below == Material.SAND
|
||||
|| below == Material.GRAVEL || below == Material.SIGN_POST) {
|
||||
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.");
|
||||
|
||||
dropSign(event.getBlock());
|
||||
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 {
|
||||
} else if (!wcfg.disableSignChestProtectionCheck) {
|
||||
if (event.getLine(0).equalsIgnoreCase("[Lock]")) {
|
||||
player.sendMessage(ChatColor.RED
|
||||
+ "WorldGuard's sign chest protection is disabled.");
|
||||
|
||||
dropSign(event.getBlock());
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when snow is formed.
|
||||
*/
|
||||
@Override
|
||||
public void onSnowForm(SnowFormEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
|
||||
if (cfg.activityHaltToggle) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!plugin.getGlobalRegionManager().allows(DefaultFlag.SNOW_FALL,
|
||||
event.getBlock().getLocation())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onLeavesDecay(LeavesDecayEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
|
||||
|
||||
if (cfg.activityHaltToggle) {
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.BLOCK_FADE);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setTargetBlock(event.getBlock().getState());
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
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) {
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.BLOCK_FORM);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setTargetBlock(event.getBlock().getState());
|
||||
context.setPlacedBlock(event.getNewState());
|
||||
if (rules.process(context)) {
|
||||
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) {
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.BLOCK_SPREAD);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setSourceBlock(event.getSource().getState());
|
||||
context.setTargetBlock(event.getBlock().getState());
|
||||
context.setPlacedBlock(event.getNewState());
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onBlockFade(BlockFadeEvent event) {
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.BLOCK_FADE);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setTargetBlock(event.getBlock().getState());
|
||||
context.setPlacedBlock(event.getNewState());
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onBlockDispense(BlockDispenseEvent event) {
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.ITEM_DROP);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setSourceBlock(event.getBlock().getState());
|
||||
context.setItem(event.getItem());
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -18,656 +18,297 @@
|
||||
*/
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
|
||||
import org.bukkit.ChatColor;
|
||||
import java.util.Iterator;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.Event.Priority;
|
||||
import org.bukkit.event.entity.*;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.event.painting.PaintingBreakByEntityEvent;
|
||||
import org.bukkit.event.painting.PaintingBreakEvent;
|
||||
import org.bukkit.event.painting.PaintingPlaceEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BlockType;
|
||||
import com.sk89q.worldguard.blacklist.events.ItemUseBlacklistEvent;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
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.CreeperPowerEvent;
|
||||
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||
import org.bukkit.event.entity.EntityCombustEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByBlockEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.entity.EntityInteractEvent;
|
||||
import org.bukkit.event.entity.ExplosionPrimeEvent;
|
||||
import org.bukkit.event.entity.PigZapEvent;
|
||||
import org.bukkit.event.entity.PotionSplashEvent;
|
||||
import com.sk89q.rulelists.DefaultAttachments;
|
||||
import com.sk89q.rulelists.RuleSet;
|
||||
import com.sk89q.worldguard.region.RegionManager;
|
||||
import com.sk89q.worldguard.region.flags.DefaultFlag;
|
||||
|
||||
/**
|
||||
* Listener for entity related events.
|
||||
*
|
||||
* @author sk89q
|
||||
* The listener for entity events.
|
||||
*/
|
||||
public class WorldGuardEntityListener extends EntityListener {
|
||||
/**
|
||||
* Logger for messages.
|
||||
*/
|
||||
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
||||
class WorldGuardEntityListener implements Listener {
|
||||
|
||||
private WorldGuardPlugin plugin;
|
||||
|
||||
/**
|
||||
* Construct the object;
|
||||
*
|
||||
* @param plugin
|
||||
* Construct the listener.
|
||||
*
|
||||
* @param plugin WorldGuard plugin
|
||||
*/
|
||||
public WorldGuardEntityListener(WorldGuardPlugin plugin) {
|
||||
WorldGuardEntityListener(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register events.
|
||||
* Register the events.
|
||||
*/
|
||||
public void registerEvents() {
|
||||
PluginManager pm = plugin.getServer().getPluginManager();
|
||||
|
||||
registerEvent("ENTITY_DAMAGE", Priority.High);
|
||||
registerEvent("ENTITY_EXPLODE", Priority.High);
|
||||
registerEvent("CREATURE_SPAWN", Priority.High);
|
||||
registerEvent("ENTITY_INTERACT", Priority.High);
|
||||
registerEvent("CREEPER_POWER", Priority.High);
|
||||
registerEvent("PIG_ZAP", Priority.High);
|
||||
registerEvent("PAINTING_BREAK", Priority.High);
|
||||
registerEvent("PAINTING_PLACE", Priority.High);
|
||||
void registerEvents() {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an event, but not failing if the event is not implemented.
|
||||
*
|
||||
* @param typeName
|
||||
* @param priority
|
||||
*/
|
||||
private void registerEvent(String typeName, Priority priority) {
|
||||
try {
|
||||
Event.Type type = Event.Type.valueOf(typeName);
|
||||
PluginManager pm = plugin.getServer().getPluginManager();
|
||||
pm.registerEvent(type, this, priority, plugin);
|
||||
} catch (IllegalArgumentException e) {
|
||||
logger.info("WorldGuard: Unable to register missing event type " + typeName);
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onEntityInteract(EntityInteractEvent event) {
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(event.getEntity().getWorld());
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.BLOCK_INTERACT);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setSourceEntity(event.getEntity());
|
||||
context.setTargetBlock(event.getBlock().getState());
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when an entity interacts with another object.
|
||||
*/
|
||||
@Override
|
||||
public void onEntityInteract(EntityInteractEvent event) {
|
||||
//bukkit doesn't actually throw this event yet, someone add a ticket to leaky
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onEntityDeath(EntityDeathEvent event) {
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(event.getEntity().getWorld());
|
||||
|
||||
/* --- No short-circuit returns below this line --- */
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.ENTITY_DEATH);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setTargetEntity(event.getEntity());
|
||||
|
||||
// Set a message if it's a death from a player
|
||||
if (event instanceof PlayerDeathEvent) {
|
||||
context.setMessage(((PlayerDeathEvent) event).getDeathMessage());
|
||||
}
|
||||
|
||||
rules.process(context);
|
||||
|
||||
// Set the message back
|
||||
if (event instanceof PlayerDeathEvent) {
|
||||
((PlayerDeathEvent) event).setDeathMessage(context.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onEntityDamage(EntityDamageEvent event) {
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(event.getEntity().getWorld());
|
||||
|
||||
// Redirect damage done by an entity
|
||||
if (event instanceof EntityDamageByEntityEvent) {
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.ENTITY_DAMAGE);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setSourceEntity(((EntityDamageByEntityEvent) event).getDamager());
|
||||
context.setTargetEntity(event.getEntity());
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Redirect damage done by blocks
|
||||
} else if (event instanceof EntityDamageByBlockEvent) {
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.ENTITY_DAMAGE);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
Block damager = ((EntityDamageByBlockEvent) event).getDamager();
|
||||
if (damager != null) { // Should NOT be null!
|
||||
context.setSourceBlock(damager.getState());
|
||||
}
|
||||
context.setTargetEntity(event.getEntity());
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Other damage
|
||||
} else {
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.ENTITY_DAMAGE);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setTargetEntity(event.getEntity());
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onEntityCombust(EntityCombustEvent event) {
|
||||
Entity entity = event.getEntity();
|
||||
Block block = event.getBlock();
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(entity.getWorld());
|
||||
|
||||
if (block.getType() == Material.SOIL) {
|
||||
if (entity instanceof Creature && wcfg.disableCreatureCropTrampling) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on entity damage by a block.
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
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 (cfg.hasGodMode(player)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.disableLavaDamage && type == DamageCause.LAVA) {
|
||||
event.setCancelled(true);
|
||||
if (cfg.hasGodMode(player)) player.setFireTicks(0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.disableContactDamage && type == DamageCause.CONTACT) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.teleportOnVoid && type == DamageCause.VOID) {
|
||||
findFreePosition(player);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.disableVoidDamage && type == DamageCause.VOID) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.disableExplosionDamage && event.getCause() == DamageCause.BLOCK_EXPLOSION) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on entity damage by an entity.
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
private void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
||||
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;
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(player.getWorld());
|
||||
|
||||
if (cfg.hasGodMode(player)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.disableLightningDamage && event.getCause() == DamageCause.LIGHTNING) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.disableExplosionDamage && event.getCause() == DamageCause.ENTITY_EXPLOSION) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (attacker != null && attacker instanceof Player) {
|
||||
if (wcfg.useRegions) {
|
||||
Vector pt = toVector(defender.getLocation());
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld());
|
||||
|
||||
if (!mgr.getApplicableRegions(pt).allows(DefaultFlag.PVP)) {
|
||||
((Player) attacker).sendMessage(ChatColor.DARK_RED + "You are in a no-PvP area.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (attacker != null && 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)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (attacker instanceof Creeper) {
|
||||
if (!set.allows(DefaultFlag.CREEPER_EXPLOSION)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on entity damage by a projectile.
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
private void onEntityDamageByProjectile(EntityDamageByProjectileEvent event) {
|
||||
Entity defender = event.getEntity();
|
||||
Entity attacker = event.getDamager();
|
||||
|
||||
if (defender instanceof Player) {
|
||||
Player player = (Player) defender;
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(player.getWorld());
|
||||
|
||||
if (cfg.hasGodMode(player)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (attacker != null && attacker instanceof Player) {
|
||||
if (wcfg.useRegions) {
|
||||
Vector pt = toVector(defender.getLocation());
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld());
|
||||
|
||||
if (!mgr.getApplicableRegions(pt).allows(DefaultFlag.PVP)) {
|
||||
((Player) attacker).sendMessage(ChatColor.DARK_RED + "You are in a no-PvP area.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (attacker != null && attacker instanceof Skeleton) {
|
||||
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)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on entity damage.
|
||||
*/
|
||||
@Override
|
||||
public void onEntityDamage(EntityDamageEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.ENTITY_IGNITE);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setTargetEntity(entity);
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event instanceof EntityDamageByProjectileEvent) {
|
||||
this.onEntityDamageByProjectile((EntityDamageByProjectileEvent) event);
|
||||
return;
|
||||
} else 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 (cfg.hasGodMode(player)) {
|
||||
event.setCancelled(true);
|
||||
player.setFireTicks(0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (type == DamageCause.DROWNING && cfg.hasAmphibiousMode(player)) {
|
||||
player.setRemainingAir(player.getMaximumAir());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (type == DamageCause.DROWNING && wcfg.pumpkinScuba
|
||||
&& (player.getInventory().getHelmet().getType() == Material.PUMPKIN
|
||||
|| player.getInventory().getHelmet().getType() == Material.JACK_O_LANTERN)) {
|
||||
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) {
|
||||
findFreePosition(player);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.disableSuffocationDamage && type == DamageCause.SUFFOCATION) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on entity explode.
|
||||
*/
|
||||
@Override
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onEntityExplode(EntityExplodeEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
Location l = event.getLocation();
|
||||
World world = l.getWorld();
|
||||
WorldConfiguration wcfg = cfg.get(world);
|
||||
Entity ent = event.getEntity();
|
||||
|
||||
if (ent instanceof LivingEntity) {
|
||||
if (wcfg.blockCreeperBlockDamage) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.blockCreeperExplosions) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.useRegions) {
|
||||
Vector pt = toVector(l);
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||
|
||||
if (!mgr.getApplicableRegions(pt).allows(DefaultFlag.CREEPER_EXPLOSION)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if (ent instanceof Fireball) {
|
||||
if (wcfg.useRegions) {
|
||||
Vector pt = toVector(l);
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||
|
||||
if (!mgr.getApplicableRegions(pt).allows(DefaultFlag.GHAST_FIREBALL)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if (ent instanceof TNTPrimed) {
|
||||
if (cfg.activityHaltToggle) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.blockTNT) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.useRegions) {
|
||||
Vector pt = toVector(l);
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||
|
||||
if (!mgr.getApplicableRegions(pt).allows(DefaultFlag.TNT)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (wcfg.signChestProtection) {
|
||||
for (Block block : event.blockList()) {
|
||||
if (wcfg.isChestProtected(block)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.ENTITY_EXPLODE);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setTargetEntity(event.getEntity());
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.useRegions) {
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||
/* --- No short-circuit returns below this line --- */
|
||||
|
||||
// Whoo, for each block
|
||||
for (Block block : event.blockList()) {
|
||||
Vector pt = toVector(block);
|
||||
// Now apply RuleLists for each block
|
||||
Iterator<Block> iter = event.blockList().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Block block = iter.next();
|
||||
|
||||
if (!mgr.getApplicableRegions(pt).allows(DefaultFlag.TNT)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
rules = wcfg.getRuleList().get(DefaultAttachments.BLOCK_BREAK);
|
||||
context = new BukkitContext(plugin, event);
|
||||
context.setSourceEntity(event.getEntity());
|
||||
context.setTargetBlock(block.getState());
|
||||
rules.process(context);
|
||||
if (context.isCancelled()) {
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on creature spawn.
|
||||
*/
|
||||
@Override
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onExplosionPrime(ExplosionPrimeEvent event) {
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(event.getEntity().getWorld());
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.ENTITY_EXPLODE);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setTargetEntity(event.getEntity());
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onCreatureSpawn(CreatureSpawnEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
|
||||
if (cfg.activityHaltToggle) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
WorldConfiguration wcfg = cfg.get(event.getEntity().getWorld());
|
||||
CreatureType creaType = event.getCreatureType();
|
||||
|
||||
if (wcfg.blockCreatureSpawn.contains(creaType)) {
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.ENTITY_SPAWN);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setTargetEntity(event.getEntity());
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
Location eventLoc = event.getLocation();
|
||||
|
||||
if (wcfg.useRegions) {
|
||||
Vector pt = toVector(eventLoc);
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(eventLoc.getWorld());
|
||||
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
|
||||
|
||||
if (!set.allows(DefaultFlag.MOB_SPAWNING)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
Set<CreatureType> blockTypes = set.getFlag(DefaultFlag.DENY_SPAWN);
|
||||
if (blockTypes != null && blockTypes.contains(creaType)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on pig zap.
|
||||
*/
|
||||
@Override
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onPigZap(PigZapEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(event.getEntity().getWorld());
|
||||
|
||||
if (wcfg.disablePigZap) {
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.ENTITY_STRIKE);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setTargetEntity(event.getEntity());
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on creeper power.
|
||||
*/
|
||||
@Override
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onCreeperPower(CreeperPowerEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(event.getEntity().getWorld());
|
||||
|
||||
if (wcfg.disableCreeperPower) {
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.ENTITY_STRIKE);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setTargetEntity(event.getEntity());
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a painting is removed.
|
||||
*/
|
||||
@Override
|
||||
public void onPaintingBreak(PaintingBreakEvent breakEvent) {
|
||||
if (breakEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(breakEvent instanceof PaintingBreakByEntityEvent)) {
|
||||
return;
|
||||
}
|
||||
|
||||
PaintingBreakByEntityEvent event = (PaintingBreakByEntityEvent) breakEvent;
|
||||
if (!(event.getRemover() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Painting painting= event.getPainting();
|
||||
Player player = (Player) event.getRemover();
|
||||
World world = painting.getWorld();
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onEntityChangeBlock(EntityChangeBlockEvent event) {
|
||||
Entity entity = event.getEntity();
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(world);
|
||||
WorldConfiguration wcfg = cfg.get(entity.getWorld());
|
||||
|
||||
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;
|
||||
}
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(event.getTo() == Material.AIR ?
|
||||
DefaultAttachments.BLOCK_BREAK : DefaultAttachments.BLOCK_PLACE);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setSourceEntity(entity);
|
||||
BlockState newState = event.getBlock().getState(); // This event is lame
|
||||
newState.setType(event.getTo()); // Need to construct our own BlockState
|
||||
context.setTargetBlock(event.getBlock().getState());
|
||||
context.setPlacedBlock(newState);
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on painting place.
|
||||
*/
|
||||
@Override
|
||||
public void onPaintingPlace(PaintingPlaceEvent event) {
|
||||
Block placedOn = event.getBlock();
|
||||
Player player = event.getPlayer();
|
||||
World world = placedOn.getWorld();
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPotionSplash(PotionSplashEvent event) {
|
||||
RegionManager global = plugin.getGlobalRegionManager();
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(world);
|
||||
/* --- No short-circuit returns below this line --- */
|
||||
|
||||
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;
|
||||
int blockedEntities = 0;
|
||||
|
||||
for (LivingEntity e : event.getAffectedEntities()) {
|
||||
if (!global.allows(DefaultFlag.POTION_SPLASH, e.getLocation(),
|
||||
e instanceof Player ? plugin.wrapPlayer((Player) e) : null)) {
|
||||
event.setIntensity(e, 0);
|
||||
++blockedEntities;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 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 <= 129) {
|
||||
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).getType() == Material.AIR) {
|
||||
world.getBlockAt(x,0,z).setTypeId(20);
|
||||
loc.setY(2);
|
||||
}
|
||||
player.setFallDistance(0F);
|
||||
player.teleport(loc);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
y++;
|
||||
if (blockedEntities == event.getAffectedEntities().size()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
// $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.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Hanging;
|
||||
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.HangingPlaceEvent;
|
||||
import com.sk89q.rulelists.DefaultAttachments;
|
||||
import com.sk89q.rulelists.RuleSet;
|
||||
|
||||
/**
|
||||
* Listener for hanging entity events.
|
||||
*/
|
||||
class WorldGuardHangingListener implements Listener {
|
||||
|
||||
private WorldGuardPlugin plugin;
|
||||
|
||||
/**
|
||||
* Construct the listener.
|
||||
*
|
||||
* @param plugin WorldGuard plugin
|
||||
*/
|
||||
WorldGuardHangingListener(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register events.
|
||||
*/
|
||||
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);
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.ENTITY_DAMAGE);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
if (event instanceof HangingBreakByEntityEvent) {
|
||||
context.setSourceEntity(((HangingBreakByEntityEvent) event).getRemover());
|
||||
}
|
||||
context.setTargetEntity(event.getEntity());
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onHangingPlace(HangingPlaceEvent event) {
|
||||
Block placedOn = event.getBlock();
|
||||
World world = placedOn.getWorld();
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(world);
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.ENTITY_SPAWN);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setSourceEntity(event.getPlayer());
|
||||
context.setTargetEntity(event.getEntity());
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
// $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.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Painting;
|
||||
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 com.sk89q.rulelists.DefaultAttachments;
|
||||
import com.sk89q.rulelists.RuleSet;
|
||||
|
||||
/**
|
||||
* Listener for painting related events. This event is deprecated and it is provided for
|
||||
* compatibility with older versions of Bukkit.
|
||||
*/
|
||||
@Deprecated
|
||||
public class WorldGuardPaintingListener implements Listener {
|
||||
|
||||
private WorldGuardPlugin plugin;
|
||||
|
||||
/**
|
||||
* Construct the listener.
|
||||
*
|
||||
* @param plugin WorldGuard plugin
|
||||
*/
|
||||
WorldGuardPaintingListener(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register events.
|
||||
*/
|
||||
void registerEvents() {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onPaintingBreak(PaintingBreakEvent event) {
|
||||
Painting painting = event.getPainting();
|
||||
World world = painting.getWorld();
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(world);
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.ENTITY_DAMAGE);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
if (event instanceof PaintingBreakByEntityEvent) {
|
||||
context.setSourceEntity(((PaintingBreakByEntityEvent) event).getRemover());
|
||||
}
|
||||
context.setTargetEntity(event.getPainting());
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onPaintingPlace(PaintingPlaceEvent event) {
|
||||
Block placedOn = event.getBlock();
|
||||
World world = placedOn.getWorld();
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(world);
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.ENTITY_SPAWN);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setSourceEntity(event.getPlayer());
|
||||
context.setTargetEntity(event.getPainting());
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,48 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* Listener for server events.
|
||||
*/
|
||||
class WorldGuardServerListener implements Listener {
|
||||
|
||||
private final WorldGuardPlugin plugin;
|
||||
|
||||
/**
|
||||
* Construct the listener.
|
||||
*
|
||||
* @param plugin WorldGuard plugin
|
||||
*/
|
||||
WorldGuardServerListener(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register events.
|
||||
*/
|
||||
void registerEvents() {
|
||||
PluginManager pm = plugin.getServer().getPluginManager();
|
||||
pm.registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPluginEnable(PluginEnableEvent event) {
|
||||
// Legacy god mode
|
||||
if (event.getPlugin().getDescription().getName().equalsIgnoreCase("CommandBook")) {
|
||||
plugin.getGlobalStateManager().updateCommandBookGodMode();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPluginDisable(PluginDisableEvent event) {
|
||||
// Legacy god mode
|
||||
if (event.getPlugin().getDescription().getName().equalsIgnoreCase("CommandBook")) {
|
||||
plugin.getGlobalStateManager().updateCommandBookGodMode();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
// $Id$
|
||||
/*
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
* All rights reserved.
|
||||
*/
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Vehicle;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.vehicle.VehicleDestroyEvent;
|
||||
import com.sk89q.rulelists.DefaultAttachments;
|
||||
import com.sk89q.rulelists.RuleSet;
|
||||
|
||||
/**
|
||||
* Listener for vehicle events.
|
||||
*/
|
||||
class WorldGuardVehicleListener implements Listener {
|
||||
|
||||
private WorldGuardPlugin plugin;
|
||||
|
||||
/**
|
||||
* Construct the listener.
|
||||
*
|
||||
* @param plugin WorldGuard plugin
|
||||
*/
|
||||
WorldGuardVehicleListener(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the events.
|
||||
*/
|
||||
void registerEvents() {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onVehicleDestroy(VehicleDestroyEvent event) {
|
||||
Vehicle vehicle = event.getVehicle();
|
||||
Entity destroyer = event.getAttacker();
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(vehicle.getWorld());
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.ENTITY_DAMAGE);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setSourceEntity(destroyer);
|
||||
context.setTargetEntity(vehicle);
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,132 +18,82 @@
|
||||
*/
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.Event.Priority;
|
||||
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 org.bukkit.event.weather.WeatherListener;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
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 java.util.logging.Logger;
|
||||
import com.sk89q.rulelists.DefaultAttachments;
|
||||
import com.sk89q.rulelists.RuleSet;
|
||||
|
||||
public class WorldGuardWeatherListener extends WeatherListener {
|
||||
/**
|
||||
* Listener for weather events.
|
||||
*/
|
||||
class WorldGuardWeatherListener implements Listener {
|
||||
|
||||
/**
|
||||
* Logger for messages.
|
||||
*/
|
||||
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
||||
|
||||
/**
|
||||
* Plugin.
|
||||
*/
|
||||
private WorldGuardPlugin plugin;
|
||||
|
||||
/**
|
||||
* Construct the object;
|
||||
* Construct the listener.
|
||||
*
|
||||
* @param plugin
|
||||
* @param plugin WorldGuard plugin
|
||||
*/
|
||||
public WorldGuardWeatherListener(WorldGuardPlugin plugin) {
|
||||
WorldGuardWeatherListener(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void registerEvents() {
|
||||
PluginManager pm = plugin.getServer().getPluginManager();
|
||||
|
||||
registerEvent("LIGHTNING_STRIKE", Priority.High);
|
||||
registerEvent("THUNDER_CHANGE", Priority.High);
|
||||
registerEvent("WEATHER_CHANGE", Priority.High);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an event, but not failing if the event is not implemented.
|
||||
*
|
||||
* @param typeName
|
||||
* @param priority
|
||||
* Register the events.
|
||||
*/
|
||||
private void registerEvent(String typeName, Priority priority) {
|
||||
try {
|
||||
Event.Type type = Event.Type.valueOf(typeName);
|
||||
PluginManager pm = plugin.getServer().getPluginManager();
|
||||
pm.registerEvent(type, this, priority, plugin);
|
||||
} catch (IllegalArgumentException e) {
|
||||
logger.info("WorldGuard: Unable to register missing event type " + typeName);
|
||||
}
|
||||
void registerEvents() {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onWeatherChange(WeatherChangeEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
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);
|
||||
}
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.WEATHER_TRANSITION);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onThunderChange(ThunderChangeEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.WEATHER_TRANSITION);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onLightningStrike(LightningStrikeEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
Location loc = event.getLightning().getLocation();
|
||||
|
||||
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);
|
||||
}
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.WEATHER_PHENOMENON);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setTargetBlock(loc.getBlock().getState());
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,80 +5,75 @@
|
||||
*/
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.world.ChunkLoadEvent;
|
||||
import org.bukkit.event.world.WorldListener;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.world.WorldLoadEvent;
|
||||
import org.bukkit.event.world.WorldSaveEvent;
|
||||
import org.bukkit.event.world.WorldUnloadEvent;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
import com.sk89q.rulelists.DefaultAttachments;
|
||||
import com.sk89q.rulelists.RuleSet;
|
||||
|
||||
public class WorldGuardWorldListener extends WorldListener {
|
||||
|
||||
/**
|
||||
* Logger for messages.
|
||||
*/
|
||||
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
||||
/**
|
||||
* Listener for world events.
|
||||
*/
|
||||
public class WorldGuardWorldListener implements Listener {
|
||||
|
||||
private WorldGuardPlugin plugin;
|
||||
|
||||
/**
|
||||
* Construct the object;
|
||||
* Construct the listener.
|
||||
*
|
||||
* @param plugin
|
||||
* @param plugin WorldGuard plugin
|
||||
*/
|
||||
public WorldGuardWorldListener(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register events.
|
||||
* Register the events.
|
||||
*/
|
||||
public void registerEvents() {
|
||||
PluginManager pm = plugin.getServer().getPluginManager();
|
||||
|
||||
registerEvent("CHUNK_LOAD", Event.Priority.Normal);
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an event, but not failing if the event is not implemented.
|
||||
*
|
||||
* @param typeName
|
||||
* @param priority
|
||||
*/
|
||||
private void registerEvent(String typeName, Event.Priority priority) {
|
||||
try {
|
||||
Event.Type type = Event.Type.valueOf(typeName);
|
||||
PluginManager pm = plugin.getServer().getPluginManager();
|
||||
pm.registerEvent(type, this, priority, plugin);
|
||||
} catch (IllegalArgumentException e) {
|
||||
logger.info("WorldGuard: Unable to register missing event type " + typeName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a chunk is loaded.
|
||||
*/
|
||||
public void onChunkLoad(ChunkLoadEvent event) {
|
||||
@EventHandler
|
||||
public void onWorldLoad(WorldLoadEvent event) {
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(event.getWorld());
|
||||
|
||||
if (cfg.activityHaltToggle) {
|
||||
int removed = 0;
|
||||
/* --- No short-circuit returns below this line --- */
|
||||
|
||||
for (Entity entity : event.getChunk().getEntities()) {
|
||||
if (entity instanceof Item
|
||||
|| (entity instanceof LivingEntity
|
||||
&& !(entity instanceof Tameable)
|
||||
&& !(entity instanceof Player))) {
|
||||
entity.remove();
|
||||
removed++;
|
||||
}
|
||||
}
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.WORLD_LOAD);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
rules.process(context);
|
||||
}
|
||||
|
||||
if (removed > 50) {
|
||||
logger.info("WG Halt-Act: " + removed + " entities (>50) auto-removed from "
|
||||
+ event.getChunk().toString());
|
||||
}
|
||||
@EventHandler
|
||||
public void onWorldLoad(WorldUnloadEvent event) {
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(event.getWorld());
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.WORLD_UNLOAD);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onWorldSave(WorldSaveEvent event) {
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(event.getWorld());
|
||||
|
||||
/* --- No short-circuit returns below this line --- */
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(DefaultAttachments.WORLD_SAVE);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
rules.process(context);
|
||||
}
|
||||
}
|
||||
@@ -23,22 +23,26 @@ 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;
|
||||
import com.sk89q.worldedit.blocks.ItemType;
|
||||
|
||||
public class GeneralCommands {
|
||||
private final WorldGuardPlugin plugin;
|
||||
|
||||
public GeneralCommands(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Command(aliases = {"god"},
|
||||
usage = "[player]",
|
||||
desc = "Enable godmode on a player",
|
||||
flags = "s", min = 0, max = 1)
|
||||
public static void god(CommandContext args, WorldGuardPlugin plugin,
|
||||
CommandSender sender) throws CommandException {
|
||||
@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;
|
||||
@@ -81,12 +85,10 @@ public class GeneralCommands {
|
||||
}
|
||||
}
|
||||
|
||||
@Command(aliases = {"ungod"},
|
||||
usage = "[player]",
|
||||
desc = "Disable godmode on a player",
|
||||
flags = "s", min = 0, max = 1)
|
||||
public static void ungod(CommandContext args, WorldGuardPlugin plugin,
|
||||
CommandSender sender) throws CommandException {
|
||||
@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;
|
||||
@@ -128,12 +130,8 @@ public class GeneralCommands {
|
||||
}
|
||||
}
|
||||
|
||||
@Command(aliases = {"heal"},
|
||||
usage = "[player]",
|
||||
desc = "Heal a player",
|
||||
flags = "s", min = 0, max = 1)
|
||||
public static void heal(CommandContext args, WorldGuardPlugin plugin,
|
||||
CommandSender sender) throws CommandException {
|
||||
@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;
|
||||
@@ -153,6 +151,7 @@ public class GeneralCommands {
|
||||
|
||||
for (Player player : targets) {
|
||||
player.setHealth(20);
|
||||
player.setFoodLevel(20);
|
||||
|
||||
// Tell the user
|
||||
if (player.equals(sender)) {
|
||||
@@ -174,12 +173,8 @@ public class GeneralCommands {
|
||||
}
|
||||
}
|
||||
|
||||
@Command(aliases = {"slay"},
|
||||
usage = "[player]",
|
||||
desc = "Slay a player",
|
||||
flags = "s", min = 0, max = 1)
|
||||
public static void slay(CommandContext args, WorldGuardPlugin plugin,
|
||||
CommandSender sender) throws CommandException {
|
||||
@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;
|
||||
@@ -220,13 +215,9 @@ public class GeneralCommands {
|
||||
}
|
||||
}
|
||||
|
||||
@Command(aliases = {"locate"},
|
||||
usage = "[player]",
|
||||
desc = "Locate a player",
|
||||
flags = "", min = 0, max = 1)
|
||||
@Command(aliases = {"locate"}, usage = "[player]", desc = "Locate a player", max = 1)
|
||||
@CommandPermissions({"worldguard.locate"})
|
||||
public static void locate(CommandContext args, WorldGuardPlugin plugin,
|
||||
CommandSender sender) throws CommandException {
|
||||
public void locate(CommandContext args, CommandSender sender) throws CommandException {
|
||||
|
||||
Player player = plugin.checkPlayer(sender);
|
||||
|
||||
@@ -242,15 +233,13 @@ public class GeneralCommands {
|
||||
}
|
||||
}
|
||||
|
||||
@Command(aliases = {"stack"},
|
||||
usage = "",
|
||||
desc = "Stack items",
|
||||
flags = "", min = 0, max = 0)
|
||||
@Command(aliases = {"stack", ";"}, usage = "", desc = "Stack items", max = 0)
|
||||
@CommandPermissions({"worldguard.stack"})
|
||||
public static void stack(CommandContext args, WorldGuardPlugin plugin,
|
||||
CommandSender sender) throws CommandException {
|
||||
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;
|
||||
@@ -262,17 +251,14 @@ public class GeneralCommands {
|
||||
|
||||
// Avoid infinite stacks and stacks with durability
|
||||
if (item == null || item.getAmount() <= 0
|
||||
|| ItemType.shouldNotStack(item.getTypeId())) {
|
||||
|| (!ignoreMax && item.getMaxStackSize() == 1)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ignore buckets
|
||||
if (item.getTypeId() >= 325 && item.getTypeId() <= 327) {
|
||||
continue;
|
||||
}
|
||||
int max = ignoreMax ? 64 : item.getMaxStackSize();
|
||||
|
||||
if (item.getAmount() < 64) {
|
||||
int needed = 64 - item.getAmount(); // Number of needed items until 64
|
||||
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++) {
|
||||
@@ -280,25 +266,26 @@ public class GeneralCommands {
|
||||
|
||||
// Avoid infinite stacks and stacks with durability
|
||||
if (item2 == null || item2.getAmount() <= 0
|
||||
|| ItemType.shouldNotStack(item.getTypeId())) {
|
||||
|| (!ignoreMax && item.getMaxStackSize() == 1)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Same type?
|
||||
// Blocks store their color in the damage value
|
||||
if (item2.getTypeId() == item.getTypeId() &&
|
||||
(!ItemType.usesDamageValue(item.getTypeId())
|
||||
|| item.getDurability() == item2.getDurability())) {
|
||||
((!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(64);
|
||||
item.setAmount(max);
|
||||
item2.setAmount(item2.getAmount() - needed);
|
||||
break;
|
||||
// This stack will
|
||||
} else {
|
||||
items[j] = null;
|
||||
item.setAmount(item.getAmount() + item2.getAmount());
|
||||
needed = 64 - item.getAmount();
|
||||
needed = max - item.getAmount();
|
||||
}
|
||||
|
||||
affected++;
|
||||
|
||||
@@ -20,21 +20,25 @@
|
||||
package com.sk89q.worldguard.bukkit.commands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import com.sk89q.minecraft.util.commands.*;
|
||||
|
||||
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 {
|
||||
@Command(aliases = {"region"},
|
||||
desc = "Region management commands")
|
||||
@NestedCommand({RegionCommands.class, RegionMemberCommands.class})
|
||||
public static void region(CommandContext args, WorldGuardPlugin plugin,
|
||||
CommandSender sender) throws CommandException {
|
||||
@SuppressWarnings("unused")
|
||||
private final WorldGuardPlugin plugin;
|
||||
|
||||
public ProtectionCommands(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Command(aliases = {"worldguard"},
|
||||
desc = "WorldGuard commands")
|
||||
@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 static void worldGuard(CommandContext args, WorldGuardPlugin plugin,
|
||||
CommandSender sender) throws CommandException {
|
||||
}
|
||||
public void worldGuard(CommandContext args, CommandSender sender) {}
|
||||
}
|
||||
Executable → Regular
+533
-480
File diff suppressed because it is too large.
Load diff
@@ -19,48 +19,51 @@
|
||||
|
||||
package com.sk89q.worldguard.bukkit.commands;
|
||||
|
||||
import java.io.IOException;
|
||||
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.protection.managers.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import com.sk89q.worldguard.util.RegionUtil;
|
||||
import com.sk89q.worldguard.domains.DefaultDomain;
|
||||
import com.sk89q.worldguard.region.Region;
|
||||
import com.sk89q.worldguard.region.flags.DefaultFlag;
|
||||
import com.sk89q.worldguard.region.indices.RegionIndex;
|
||||
import com.sk89q.worldguard.region.stores.ProtectionDatabaseException;
|
||||
import com.sk89q.worldguard.region.stores.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",
|
||||
flags = "", min = 2, max = -1)
|
||||
public static void addMember(CommandContext args, WorldGuardPlugin plugin,
|
||||
CommandSender sender) throws CommandException {
|
||||
@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);
|
||||
|
||||
if (id.equalsIgnoreCase("__global__")) {
|
||||
throw new CommandException("The region cannot be named __global__");
|
||||
}
|
||||
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||
ProtectedRegion region = mgr.getRegion(id);
|
||||
RegionIndex mgr = plugin.getGlobalRegionManager().get(world);
|
||||
Region 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)) {
|
||||
@@ -69,88 +72,91 @@ public class RegionMemberCommands {
|
||||
plugin.checkPermission(sender, "worldguard.region.addmember." + id.toLowerCase());
|
||||
}
|
||||
|
||||
RegionUtil.addToDomain(region.getMembers(), args.getPaddedSlice(2, 0), 0);
|
||||
RegionDBUtil.addToDomain(region.getMembers(), args.getPaddedSlice(2, 0), 0);
|
||||
|
||||
sender.sendMessage(ChatColor.YELLOW
|
||||
+ "Region '" + id + "' updated.");
|
||||
|
||||
try {
|
||||
mgr.save();
|
||||
} catch (IOException e) {
|
||||
throw new CommandException("Failed to write regions file: "
|
||||
} 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",
|
||||
flags = "", min = 2, max = -1)
|
||||
public static void addOwner(CommandContext args, WorldGuardPlugin plugin,
|
||||
CommandSender sender) throws CommandException {
|
||||
@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);
|
||||
|
||||
if (id.equalsIgnoreCase("__global__")) {
|
||||
throw new CommandException("The region cannot be named __global__");
|
||||
}
|
||||
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||
ProtectedRegion region = mgr.getRegion(id);
|
||||
RegionIndex mgr = plugin.getGlobalRegionManager().get(world);
|
||||
Region region = mgr.getRegion(id);
|
||||
|
||||
if (region == null) {
|
||||
throw new CommandException("Could not find a region by that ID.");
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
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 {
|
||||
plugin.checkPermission(sender, "worldguard.region.addowner." + id.toLowerCase());
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
RegionUtil.addToDomain(region.getOwners(), args.getPaddedSlice(2, 0), 0);
|
||||
RegionDBUtil.addToDomain(region.getOwners(), args.getPaddedSlice(2, 0), 0);
|
||||
|
||||
sender.sendMessage(ChatColor.YELLOW
|
||||
+ "Region '" + id + "' updated.");
|
||||
|
||||
try {
|
||||
mgr.save();
|
||||
} catch (IOException e) {
|
||||
throw new CommandException("Failed to write regions file: "
|
||||
} 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",
|
||||
flags = "", min = 2, max = -1)
|
||||
public static void removeMember(CommandContext args, WorldGuardPlugin plugin,
|
||||
CommandSender sender) throws CommandException {
|
||||
@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);
|
||||
|
||||
if (id.equalsIgnoreCase("__global__")) {
|
||||
throw new CommandException("The region cannot be named __global__");
|
||||
}
|
||||
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||
ProtectedRegion region = mgr.getRegion(id);
|
||||
RegionIndex mgr = plugin.getGlobalRegionManager().get(world);
|
||||
Region 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)) {
|
||||
@@ -159,24 +165,22 @@ public class RegionMemberCommands {
|
||||
plugin.checkPermission(sender, "worldguard.region.removemember." + id.toLowerCase());
|
||||
}
|
||||
|
||||
RegionUtil.removeFromDomain(region.getMembers(), args.getPaddedSlice(2, 0), 0);
|
||||
RegionDBUtil.removeFromDomain(region.getMembers(), args.getPaddedSlice(2, 0), 0);
|
||||
|
||||
sender.sendMessage(ChatColor.YELLOW
|
||||
+ "Region '" + id + "' updated.");
|
||||
|
||||
try {
|
||||
mgr.save();
|
||||
} catch (IOException e) {
|
||||
throw new CommandException("Failed to write regions file: "
|
||||
} 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",
|
||||
flags = "", min = 2, max = -1)
|
||||
public static void removeOwner(CommandContext args, WorldGuardPlugin plugin,
|
||||
@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);
|
||||
@@ -184,18 +188,16 @@ public class RegionMemberCommands {
|
||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||
|
||||
String id = args.getString(0);
|
||||
|
||||
if (id.equalsIgnoreCase("__global__")) {
|
||||
throw new CommandException("The region cannot be named __global__");
|
||||
}
|
||||
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||
ProtectedRegion region = mgr.getRegion(id);
|
||||
RegionIndex mgr = plugin.getGlobalRegionManager().get(world);
|
||||
Region 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)) {
|
||||
@@ -204,15 +206,15 @@ public class RegionMemberCommands {
|
||||
plugin.checkPermission(sender, "worldguard.region.removeowner." + id.toLowerCase());
|
||||
}
|
||||
|
||||
RegionUtil.removeFromDomain(region.getOwners(), args.getPaddedSlice(2, 0), 0);
|
||||
RegionDBUtil.removeFromDomain(region.getOwners(), args.getPaddedSlice(2, 0), 0);
|
||||
|
||||
sender.sendMessage(ChatColor.YELLOW
|
||||
+ "Region '" + id + "' updated.");
|
||||
|
||||
try {
|
||||
mgr.save();
|
||||
} catch (IOException e) {
|
||||
throw new CommandException("Failed to write regions file: "
|
||||
} catch (ProtectionDatabaseException e) {
|
||||
throw new CommandException("Failed to write regions: "
|
||||
+ e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,32 +19,37 @@
|
||||
|
||||
package com.sk89q.worldguard.bukkit.commands;
|
||||
|
||||
import com.sk89q.worldguard.bukkit.ConfigurationManager;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import com.sk89q.minecraft.util.commands.*;
|
||||
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.LagStopMode;
|
||||
import com.sk89q.worldguard.bukkit.WorldConfiguration;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import org.bukkit.entity.*;
|
||||
|
||||
public class ToggleCommands {
|
||||
private final WorldGuardPlugin plugin;
|
||||
|
||||
@Command(aliases = {"stopfire"},
|
||||
usage = "[<world>]", desc = "Disables all fire spread temporarily",
|
||||
flags = "", min = 0, max = 1)
|
||||
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 static void stopFire(CommandContext args, WorldGuardPlugin plugin,
|
||||
CommandSender sender) throws CommandException {
|
||||
|
||||
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) {
|
||||
@@ -61,21 +66,18 @@ public class ToggleCommands {
|
||||
wcfg.fireSpreadDisableToggle = true;
|
||||
}
|
||||
|
||||
@Command(aliases = {"allowfire"},
|
||||
usage = "[<world>]", desc = "Allows all fire spread temporarily",
|
||||
flags = "", min = 0, max = 1)
|
||||
@Command(aliases = {"allowfire"}, usage = "[<world>]",
|
||||
desc = "Allows all fire spread temporarily", max = 1)
|
||||
@CommandPermissions({"worldguard.fire-toggle.stop"})
|
||||
public static void allowFire(CommandContext args, WorldGuardPlugin plugin,
|
||||
CommandSender sender) throws CommandException {
|
||||
|
||||
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) {
|
||||
@@ -90,54 +92,21 @@ public class ToggleCommands {
|
||||
wcfg.fireSpreadDisableToggle = false;
|
||||
}
|
||||
|
||||
@Command(aliases = {"halt-activity"},
|
||||
usage = "", desc = "Attempts to cease as much activity in order to stop lag",
|
||||
flags = "c", min = 0, max = 0)
|
||||
@Command(aliases = {"halt-activity", "stoplag", "haltactivity"},
|
||||
desc = "Attempts to cease as much activity in order to stop lag", flags = "cag", max = 0)
|
||||
@CommandPermissions({"worldguard.halt-activity"})
|
||||
public static void stopLag(CommandContext args, WorldGuardPlugin plugin,
|
||||
CommandSender sender) throws CommandException {
|
||||
public void stopLag(CommandContext args, CommandSender sender) throws CommandException {
|
||||
LagStopMode lagStopper = plugin.getLagStopMode();
|
||||
|
||||
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 (entity instanceof Item
|
||||
|| (entity instanceof LivingEntity
|
||||
&& !(entity instanceof Tameable)
|
||||
&& !(entity instanceof Player))) {
|
||||
entity.remove();
|
||||
removed++;
|
||||
}
|
||||
}
|
||||
|
||||
if (removed > 10) {
|
||||
sender.sendMessage("" + removed + " entities (>10) auto-removed from "
|
||||
+ world.toString());
|
||||
}
|
||||
}
|
||||
lagStopper.setRemoveAnimals(!args.hasFlag('c'));
|
||||
|
||||
if (!args.hasFlag('c')) {
|
||||
sender.sendMessage(ChatColor.YELLOW + "Enabling lag stop mode...");
|
||||
lagStopper.enable(!args.hasFlag('g'));
|
||||
} 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.");
|
||||
sender.sendMessage(ChatColor.YELLOW + "Disabling lag stop mode...");
|
||||
lagStopper.disable();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -23,13 +23,16 @@ 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.rebar.util.MaterialDatabase;
|
||||
import com.sk89q.worldguard.bukkit.LoggerToChatHandler;
|
||||
import com.sk89q.worldguard.bukkit.ReportWriter;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
@@ -37,38 +40,36 @@ import com.sk89q.worldguard.util.PastebinPoster;
|
||||
import com.sk89q.worldguard.util.PastebinPoster.PasteCallback;
|
||||
|
||||
public class WorldGuardCommands {
|
||||
private final WorldGuardPlugin plugin;
|
||||
|
||||
@Command(aliases = {"version"},
|
||||
usage = "",
|
||||
desc = "Get the WorldGuard version",
|
||||
flags = "", min = 0, max = 0)
|
||||
public static void version(CommandContext args, WorldGuardPlugin plugin,
|
||||
CommandSender sender) throws CommandException {
|
||||
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"},
|
||||
usage = "",
|
||||
desc = "Reload WorldGuard configuration",
|
||||
flags = "", min = 0, max = 0)
|
||||
@Command(aliases = {"reload"}, desc = "Reload WorldGuard configuration", max = 0)
|
||||
@CommandPermissions({"worldguard.reload"})
|
||||
public static void relload(CommandContext args, WorldGuardPlugin plugin,
|
||||
CommandSender sender) throws CommandException {
|
||||
|
||||
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 = Logger.getLogger("");
|
||||
minecraftLogger.addHandler(handler);
|
||||
}
|
||||
|
||||
try {
|
||||
MaterialDatabase.reload();
|
||||
plugin.getGlobalStateManager().unload();
|
||||
plugin.getGlobalRegionManager().unload();
|
||||
plugin.getGlobalStateManager().load();
|
||||
@@ -82,19 +83,17 @@ public class WorldGuardCommands {
|
||||
minecraftLogger.removeHandler(handler);
|
||||
}
|
||||
}
|
||||
|
||||
plugin.simulateWorldLoad();
|
||||
}
|
||||
|
||||
@Command(aliases = {"report"},
|
||||
usage = "",
|
||||
desc = "Writes a report on WorldGuard",
|
||||
flags = "p", min = 0, max = 0)
|
||||
|
||||
@Command(aliases = {"report"}, desc = "Writes a report on WorldGuard", flags = "p", max = 0)
|
||||
@CommandPermissions({"worldguard.report"})
|
||||
public static void report(CommandContext args, WorldGuardPlugin plugin,
|
||||
final CommandSender sender) throws CommandException {
|
||||
|
||||
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 "
|
||||
@@ -102,18 +101,20 @@ public class WorldGuardCommands {
|
||||
} 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() {
|
||||
|
||||
|
||||
@Override
|
||||
public void handleSuccess(String url) {
|
||||
// Hope we don't have a thread safety issue here
|
||||
sender.sendMessage(ChatColor.YELLOW + "WorldGuard report (1 hour): " + url);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleError(String err) {
|
||||
// Hope we don't have a thread safety issue here
|
||||
sender.sendMessage(ChatColor.YELLOW + "WorldGuard report pastebin error: " + err);
|
||||
@@ -122,4 +123,21 @@ public class WorldGuardCommands {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@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,117 @@
|
||||
// $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.definitions;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
|
||||
import com.sk89q.rebar.util.MaterialPattern;
|
||||
import com.sk89q.rulelists.Criteria;
|
||||
import com.sk89q.worldguard.bukkit.BukkitContext;
|
||||
import com.sk89q.worldguard.bukkit.resolvers.BlockResolver;
|
||||
|
||||
public class BlockCriteria implements Criteria<BukkitContext> {
|
||||
|
||||
public enum Direction {
|
||||
AT,
|
||||
ABOVE,
|
||||
BELOW,
|
||||
AROUND
|
||||
}
|
||||
|
||||
private final BlockResolver resolver;
|
||||
private Direction direction;
|
||||
private MaterialPattern[] patterns = new MaterialPattern[0];
|
||||
|
||||
public BlockCriteria(BlockResolver resolver) {
|
||||
this.resolver = resolver;
|
||||
}
|
||||
|
||||
public MaterialPattern[] getPatterns() {
|
||||
return patterns;
|
||||
}
|
||||
|
||||
public void setPatterns(MaterialPattern[] patterns) {
|
||||
this.patterns = patterns;
|
||||
}
|
||||
|
||||
public void setPatterns(List<MaterialPattern> patterns) {
|
||||
MaterialPattern[] arr = new MaterialPattern[patterns.size()];
|
||||
patterns.toArray(arr);
|
||||
this.patterns = arr;
|
||||
}
|
||||
|
||||
public Direction getDirection() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
public void setDirection(Direction direction) {
|
||||
this.direction = direction;
|
||||
}
|
||||
|
||||
private boolean matches(BlockState block) {
|
||||
for (MaterialPattern pattern : patterns) {
|
||||
if (pattern.matches(block.getTypeId(), block.getRawData())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean matches(Block block) {
|
||||
for (MaterialPattern pattern : patterns) {
|
||||
if (pattern.matches(block.getTypeId(), block.getData())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(BukkitContext context) {
|
||||
BlockState block = resolver.resolve(context);
|
||||
|
||||
if (block == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (getDirection()) {
|
||||
case AT:
|
||||
return matches(block);
|
||||
case ABOVE:
|
||||
return matches(block.getBlock().getRelative(0, 1, 0));
|
||||
case BELOW:
|
||||
return matches(block.getBlock().getRelative(0, -1, 0));
|
||||
case AROUND:
|
||||
return matches(block.getBlock().getRelative(0, -1, 0)) ||
|
||||
matches(block.getBlock().getRelative(0, 1, 0)) ||
|
||||
matches(block.getBlock().getRelative(-1, 0, 0)) ||
|
||||
matches(block.getBlock().getRelative(1, 0, 0)) ||
|
||||
matches(block.getBlock().getRelative(0, 0, -1)) ||
|
||||
matches(block.getBlock().getRelative(0, 0, 1));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
// $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.definitions;
|
||||
|
||||
import static com.sk89q.rulelists.RuleEntryLoader.INLINE;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.sk89q.rebar.config.AbstractNodeLoader;
|
||||
import com.sk89q.rebar.config.ConfigurationNode;
|
||||
import com.sk89q.rebar.config.LoaderBuilderException;
|
||||
import com.sk89q.rebar.config.types.EnumLoaderBuilder;
|
||||
import com.sk89q.rebar.config.types.MaterialPatternLoaderBuilder;
|
||||
import com.sk89q.rebar.util.LoggerUtils;
|
||||
import com.sk89q.rebar.util.MaterialPattern;
|
||||
import com.sk89q.rulelists.DefinitionException;
|
||||
import com.sk89q.rulelists.RuleListUtils;
|
||||
import com.sk89q.rulelists.RuleListsManager;
|
||||
import com.sk89q.worldguard.bukkit.definitions.BlockCriteria.Direction;
|
||||
import com.sk89q.worldguard.bukkit.resolvers.BlockResolver;
|
||||
|
||||
public class BlockCriteriaLoader extends AbstractNodeLoader<BlockCriteria> {
|
||||
|
||||
private final RuleListsManager manager;
|
||||
private MaterialPatternLoaderBuilder materialLoader = new MaterialPatternLoaderBuilder();
|
||||
private EnumLoaderBuilder<Direction> dirLoader = new EnumLoaderBuilder<Direction>(Direction.class);
|
||||
|
||||
public BlockCriteriaLoader(RuleListsManager manager) {
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockCriteria read(ConfigurationNode node)
|
||||
throws DefinitionException {
|
||||
BlockResolver resolver = manager.getResolvers()
|
||||
.get(BlockResolver.class, node.getString("block", BlockResolver.DEFAULT));
|
||||
|
||||
// Load patterns
|
||||
List<MaterialPattern> patterns = node.contains(INLINE) ?
|
||||
node.listOf(INLINE, materialLoader) : node.listOf("material", materialLoader);
|
||||
if (patterns.size() == 0) {
|
||||
throw new LoaderBuilderException("No block materials specified");
|
||||
}
|
||||
|
||||
// Load direction
|
||||
Direction direction = node.getOf("relative", dirLoader, Direction.AT);
|
||||
|
||||
BlockCriteria criteria = new BlockCriteria(resolver);
|
||||
criteria.setPatterns(patterns);
|
||||
criteria.setDirection(direction);
|
||||
|
||||
RuleListUtils.warnUnknown(node, LoggerUtils.getLogger(getClass()),
|
||||
"block", "material", "relative");
|
||||
|
||||
return criteria;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// $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.definitions;
|
||||
|
||||
import com.sk89q.rulelists.Action;
|
||||
import com.sk89q.rulelists.Context;
|
||||
|
||||
public class CancelAction implements Action<Context> {
|
||||
|
||||
@Override
|
||||
public void apply(Context context) {
|
||||
context.cancel();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
// $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.definitions;
|
||||
|
||||
import com.sk89q.rebar.config.AbstractNodeLoader;
|
||||
import com.sk89q.rebar.config.ConfigurationNode;
|
||||
import com.sk89q.rebar.util.LoggerUtils;
|
||||
import com.sk89q.rulelists.DefinitionException;
|
||||
import com.sk89q.rulelists.RuleListUtils;
|
||||
|
||||
public class CancelActionLoader extends AbstractNodeLoader<CancelAction> {
|
||||
|
||||
private final CancelAction instance = new CancelAction();
|
||||
|
||||
@Override
|
||||
public CancelAction read(ConfigurationNode node)
|
||||
throws DefinitionException {
|
||||
RuleListUtils.warnUnknown(node, LoggerUtils.getLogger(getClass()));
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
// $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.definitions;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
|
||||
import com.sk89q.rulelists.Criteria;
|
||||
import com.sk89q.worldguard.bukkit.BukkitContext;
|
||||
|
||||
public class DamageCriteria implements Criteria<BukkitContext> {
|
||||
|
||||
private Set<DamageCause> causes = new HashSet<DamageCause>();
|
||||
|
||||
public DamageCriteria(Set<DamageCause> causes) {
|
||||
this.causes = causes;
|
||||
}
|
||||
|
||||
public Set<DamageCause> getCauses() {
|
||||
return causes;
|
||||
}
|
||||
|
||||
public void setCauses(Set<DamageCause> causes) {
|
||||
this.causes = causes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(BukkitContext context) {
|
||||
Event event = context.getEvent();
|
||||
|
||||
if (event instanceof EntityDamageEvent) {
|
||||
return causes.contains(((EntityDamageEvent) event).getCause());
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
// $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.definitions;
|
||||
|
||||
import static com.sk89q.rulelists.RuleEntryLoader.INLINE;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
|
||||
import com.sk89q.rebar.config.AbstractNodeLoader;
|
||||
import com.sk89q.rebar.config.ConfigurationNode;
|
||||
import com.sk89q.rebar.config.types.EnumLoaderBuilder;
|
||||
import com.sk89q.rebar.util.LoggerUtils;
|
||||
import com.sk89q.rulelists.DefinitionException;
|
||||
import com.sk89q.rulelists.RuleListUtils;
|
||||
|
||||
public class DamageCriteriaLoader extends AbstractNodeLoader<DamageCriteria> {
|
||||
|
||||
private EnumLoaderBuilder<DamageCause> typeLoader =
|
||||
new EnumLoaderBuilder<DamageCause>(DamageCause.class);
|
||||
|
||||
@Override
|
||||
public DamageCriteria read(ConfigurationNode node) throws DefinitionException {
|
||||
Set<DamageCause> types = node.contains(INLINE) ?
|
||||
node.setOf(INLINE, typeLoader) :
|
||||
node.setOf("type", typeLoader);
|
||||
|
||||
DamageCriteria criteria = new DamageCriteria(types);
|
||||
|
||||
RuleListUtils.warnUnknown(node, LoggerUtils.getLogger(getClass()),
|
||||
"type");
|
||||
|
||||
return criteria;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
// $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.definitions;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.event.block.BlockIgniteEvent;
|
||||
import org.bukkit.event.block.BlockIgniteEvent.IgniteCause;
|
||||
|
||||
import com.sk89q.rulelists.Criteria;
|
||||
import com.sk89q.worldguard.bukkit.BukkitContext;
|
||||
import com.sk89q.worldguard.bukkit.BukkitUtil;
|
||||
import com.sk89q.worldguard.bukkit.resolvers.EntityResolver;
|
||||
import com.sk89q.worldguard.bukkit.resolvers.SourceEntityResolver;
|
||||
|
||||
public class EntityCriteria implements Criteria<BukkitContext> {
|
||||
|
||||
private final EntityResolver entityResolver;
|
||||
private Set<EntityType> types = new HashSet<EntityType>();
|
||||
private Class<?>[] ofTypes = new Class<?>[0];
|
||||
private Boolean isTamed = null;
|
||||
|
||||
// Counteract 1.3->1.4 breaking change
|
||||
private EntityType fireballType =
|
||||
BukkitUtil.tryEnum(EntityType.class, "FIREBALL", "LARGE_FIREBALL");
|
||||
|
||||
public EntityCriteria(EntityResolver entityResolver) {
|
||||
this.entityResolver = entityResolver;
|
||||
}
|
||||
|
||||
public Class<?>[] getOfTypes() {
|
||||
return ofTypes;
|
||||
}
|
||||
|
||||
public void setOfTypes(Class<?>[] ofTypes) {
|
||||
this.ofTypes = ofTypes;
|
||||
}
|
||||
|
||||
public Set<EntityType> getTypes() {
|
||||
return types;
|
||||
}
|
||||
|
||||
public void setTypes(Set<EntityType> types) {
|
||||
this.types = types;
|
||||
}
|
||||
|
||||
public Boolean getIsTamed() {
|
||||
return isTamed;
|
||||
}
|
||||
|
||||
public void setIsTamed(Boolean isTamed) {
|
||||
this.isTamed = isTamed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(BukkitContext context) {
|
||||
Entity entity = entityResolver.resolve(context);
|
||||
boolean matched = false;
|
||||
|
||||
// Hack because BlockIgniteEvent doesn't give an entity
|
||||
if (context.getEvent() instanceof BlockIgniteEvent && entityResolver instanceof SourceEntityResolver) {
|
||||
BlockIgniteEvent igniteEvent = (BlockIgniteEvent) context.getEvent();
|
||||
|
||||
if (igniteEvent.getCause() == IgniteCause.FIREBALL) {
|
||||
if (types.contains(fireballType)) {
|
||||
matched = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (igniteEvent.getCause() == IgniteCause.LIGHTNING) {
|
||||
if (types.contains(EntityType.LIGHTNING)) {
|
||||
matched = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (entity == null) {
|
||||
return matched;
|
||||
}
|
||||
|
||||
if (ofTypes.length != 0) {
|
||||
Class<?> cls = entity.getClass();
|
||||
|
||||
for (Class<?> type : ofTypes) {
|
||||
if (type.isAssignableFrom(cls)) {
|
||||
matched = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!matched) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (isTamed != null) {
|
||||
if (entity instanceof Tameable && ((Tameable) entity).isTamed() == isTamed) {
|
||||
matched = true;
|
||||
}
|
||||
|
||||
if (!matched) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (types.size() != 0) {
|
||||
matched = types.contains(entity.getType());
|
||||
|
||||
if (!matched) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return matched;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
// $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.definitions;
|
||||
|
||||
import static com.sk89q.rulelists.RuleEntryLoader.INLINE;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.entity.Animals;
|
||||
import org.bukkit.entity.Creature;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Monster;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Tameable;
|
||||
|
||||
import com.sk89q.rebar.config.AbstractNodeLoader;
|
||||
import com.sk89q.rebar.config.ConfigurationNode;
|
||||
import com.sk89q.rebar.config.types.EnumLoaderBuilder;
|
||||
import com.sk89q.rebar.util.LoggerUtils;
|
||||
import com.sk89q.rulelists.DefinitionException;
|
||||
import com.sk89q.rulelists.RuleListUtils;
|
||||
import com.sk89q.rulelists.RuleListsManager;
|
||||
import com.sk89q.worldguard.bukkit.resolvers.EntityResolver;
|
||||
|
||||
public class EntityCriteriaLoader extends AbstractNodeLoader<EntityCriteria> {
|
||||
|
||||
private final RuleListsManager manager;
|
||||
private EnumLoaderBuilder<EntityType> typeLoader =
|
||||
new EnumLoaderBuilder<EntityType>(EntityType.class);
|
||||
|
||||
public EntityCriteriaLoader(RuleListsManager manager) {
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityCriteria read(ConfigurationNode node) throws DefinitionException {
|
||||
EntityResolver entityResolver = manager.getResolvers()
|
||||
.get(EntityResolver.class, node.getString("entity", EntityResolver.DEFAULT));
|
||||
|
||||
Set<EntityType> types = node.contains(INLINE) ?
|
||||
node.setOf(INLINE, typeLoader) :
|
||||
node.setOf("type", typeLoader);
|
||||
|
||||
EntityCriteria criteria = new EntityCriteria(entityResolver);
|
||||
|
||||
List<Class<?>> ofTypes = new ArrayList<Class<?>>();
|
||||
|
||||
if (node.getBoolean("is-animal", false))
|
||||
ofTypes.add(Animals.class);
|
||||
if (node.getBoolean("is-monster", false))
|
||||
ofTypes.add(Monster.class);
|
||||
if (node.getBoolean("is-creature", false))
|
||||
ofTypes.add(Creature.class);
|
||||
if (node.getBoolean("is-living", false))
|
||||
ofTypes.add(LivingEntity.class);
|
||||
if (node.getBoolean("is-player", false))
|
||||
ofTypes.add(Player.class);
|
||||
if (node.getBoolean("is-tameable", false))
|
||||
ofTypes.add(Tameable.class);
|
||||
|
||||
criteria.setTypes(types);
|
||||
criteria.setOfTypes(ofTypes.toArray(new Class<?>[ofTypes.size()]));
|
||||
criteria.setIsTamed(node.getBoolean("is-tamed"));
|
||||
|
||||
RuleListUtils.warnUnknown(node, LoggerUtils.getLogger(getClass()),
|
||||
"entity", "type", "is-animal", "is-monster", "is-creature",
|
||||
"is-living", "is-player", "is-tameable", "is-tamed");
|
||||
|
||||
return criteria;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
// $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.definitions;
|
||||
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.sk89q.rulelists.Criteria;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.bukkit.BukkitContext;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.bukkit.resolvers.BlockResolver;
|
||||
import com.sk89q.worldguard.bukkit.resolvers.EntityResolver;
|
||||
import com.sk89q.worldguard.region.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.region.flags.DefaultFlag;
|
||||
import com.sk89q.worldguard.region.flags.StateFlag;
|
||||
|
||||
public class FlagCriteria implements Criteria<BukkitContext> {
|
||||
|
||||
private final WorldGuardPlugin plugin;
|
||||
private final StateFlag flag;
|
||||
private BlockResolver blockResolver;
|
||||
private EntityResolver entityResolver;
|
||||
|
||||
public FlagCriteria(WorldGuardPlugin plugin, StateFlag flag) {
|
||||
this.plugin = plugin;
|
||||
this.flag = flag;
|
||||
}
|
||||
|
||||
public BlockResolver getBlockResolver() {
|
||||
return blockResolver;
|
||||
}
|
||||
|
||||
public void setBlockResolver(BlockResolver blockResolver) {
|
||||
this.blockResolver = blockResolver;
|
||||
}
|
||||
|
||||
public EntityResolver getEntityResolver() {
|
||||
return entityResolver;
|
||||
}
|
||||
|
||||
public void setEntityResolver(EntityResolver entityResolver) {
|
||||
this.entityResolver = entityResolver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(BukkitContext context) {
|
||||
boolean matches = false;
|
||||
|
||||
ApplicableRegionSet set = context.getApplicableRegionSet();
|
||||
|
||||
if (set == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (blockResolver != null) {
|
||||
BlockState block = blockResolver.resolve(context);
|
||||
|
||||
if (block == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (flag == DefaultFlag.BUILD) {
|
||||
matches = false;
|
||||
} else {
|
||||
matches = set.allows(flag);
|
||||
}
|
||||
|
||||
if (!matches) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (entityResolver != null) {
|
||||
Entity entity = entityResolver.resolve(context);
|
||||
|
||||
if (entity == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
LocalPlayer localPlayer = null;
|
||||
if (entity instanceof Player) {
|
||||
localPlayer = plugin.wrapPlayer((Player) entity);
|
||||
}
|
||||
|
||||
if (flag == DefaultFlag.BUILD) {
|
||||
matches = localPlayer != null && set.canBuild(localPlayer);
|
||||
} else {
|
||||
matches = set.allows(flag, localPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
return matches;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
// $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.definitions;
|
||||
|
||||
import com.sk89q.rebar.config.AbstractNodeLoader;
|
||||
import com.sk89q.rebar.config.ConfigurationNode;
|
||||
import com.sk89q.rebar.config.LoaderBuilderException;
|
||||
import com.sk89q.rebar.config.types.StaticFieldLoaderBuilder;
|
||||
import com.sk89q.rebar.util.LoggerUtils;
|
||||
import com.sk89q.rulelists.DefinitionException;
|
||||
import com.sk89q.rulelists.RuleListUtils;
|
||||
import com.sk89q.rulelists.RuleListsManager;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.bukkit.resolvers.BlockResolver;
|
||||
import com.sk89q.worldguard.bukkit.resolvers.EntityResolver;
|
||||
import com.sk89q.worldguard.region.flags.DefaultFlag;
|
||||
import com.sk89q.worldguard.region.flags.StateFlag;
|
||||
|
||||
public class FlagCriteriaLoader extends AbstractNodeLoader<FlagCriteria> {
|
||||
|
||||
private final WorldGuardPlugin plugin;
|
||||
private final RuleListsManager manager;
|
||||
private final StaticFieldLoaderBuilder<StateFlag> stateFlagLoader =
|
||||
new StaticFieldLoaderBuilder<StateFlag>(DefaultFlag.class, StateFlag.class);
|
||||
|
||||
public FlagCriteriaLoader(WorldGuardPlugin plugin, RuleListsManager manager) {
|
||||
this.plugin = plugin;
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FlagCriteria read(ConfigurationNode node)
|
||||
throws DefinitionException {
|
||||
BlockResolver blockResolver = null;
|
||||
EntityResolver entityResolver = null;
|
||||
|
||||
String entity = node.getString("entity");
|
||||
String block = node.getString("block");
|
||||
|
||||
if (block != null) {
|
||||
blockResolver = manager.getResolvers().get(BlockResolver.class, block);
|
||||
}
|
||||
|
||||
if (entity != null) {
|
||||
entityResolver = manager.getResolvers().get(EntityResolver.class, entity);
|
||||
}
|
||||
|
||||
if (block == null && entity == null) {
|
||||
throw new LoaderBuilderException("Flag criteria needs either a block resolver or an entity resolver");
|
||||
}
|
||||
|
||||
StateFlag flag = node.getOf("flag", stateFlagLoader);
|
||||
if (flag == null) {
|
||||
throw new LoaderBuilderException("A flag must be specified");
|
||||
}
|
||||
|
||||
FlagCriteria criteria = new FlagCriteria(plugin, flag);
|
||||
criteria.setBlockResolver(blockResolver);
|
||||
criteria.setEntityResolver(entityResolver);
|
||||
|
||||
RuleListUtils.warnUnknown(node, LoggerUtils.getLogger(getClass()),
|
||||
"flag", "block", "entity");
|
||||
|
||||
return criteria;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
// $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.definitions;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.Potion;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import com.sk89q.rebar.util.MaterialPattern;
|
||||
import com.sk89q.rulelists.Criteria;
|
||||
import com.sk89q.worldguard.bukkit.BukkitContext;
|
||||
import com.sk89q.worldguard.bukkit.resolvers.EntityResolver;
|
||||
import com.sk89q.worldguard.bukkit.resolvers.ItemStackSlotResolver;
|
||||
|
||||
public class ItemCriteria implements Criteria<BukkitContext> {
|
||||
|
||||
private final EntityResolver entityResolver;
|
||||
private final ItemStackSlotResolver itemResolver;
|
||||
private MaterialPattern[] patterns = new MaterialPattern[0];
|
||||
private Set<PotionEffectType> potionEffects = null;
|
||||
private Boolean hasData = false;
|
||||
|
||||
public ItemCriteria(EntityResolver entityResolver, ItemStackSlotResolver itemResolver) {
|
||||
this.entityResolver = entityResolver;
|
||||
this.itemResolver = itemResolver;
|
||||
}
|
||||
|
||||
public Boolean hasDataCheck() {
|
||||
return hasData;
|
||||
}
|
||||
|
||||
public void setDataCheck(Boolean hasData) {
|
||||
this.hasData = hasData;
|
||||
}
|
||||
|
||||
public MaterialPattern[] getPatterns() {
|
||||
return patterns;
|
||||
}
|
||||
|
||||
public void setPatterns(MaterialPattern[] patterns) {
|
||||
this.patterns = patterns;
|
||||
}
|
||||
|
||||
public void setPatterns(List<MaterialPattern> patterns) {
|
||||
MaterialPattern[] arr = new MaterialPattern[patterns.size()];
|
||||
patterns.toArray(arr);
|
||||
this.patterns = arr;
|
||||
}
|
||||
|
||||
public Set<PotionEffectType> getPotionEffects() {
|
||||
return potionEffects;
|
||||
}
|
||||
|
||||
public void setPotionEffects(Set<PotionEffectType> effects) {
|
||||
this.potionEffects = effects;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(BukkitContext context) {
|
||||
ItemStack item;
|
||||
boolean matched = false;
|
||||
|
||||
if (entityResolver == null) {
|
||||
item = context.getItem();
|
||||
} else {
|
||||
Entity entity = entityResolver.resolve(context);
|
||||
|
||||
if (entity == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
item = itemResolver.resolve(entity).get();
|
||||
}
|
||||
|
||||
if (item == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (hasData != null) {
|
||||
matched = hasData == (item.getDurability() != 0);
|
||||
if (!matched) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (item.getType() == Material.POTION && potionEffects.size() > 0) {
|
||||
for (PotionEffect effect : Potion.fromItemStack(item).getEffects()) {
|
||||
if (potionEffects.contains(effect.getType())) {
|
||||
matched = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!matched) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for (MaterialPattern pattern : patterns) {
|
||||
if (pattern.matches(item.getTypeId(), item.getDurability())) {
|
||||
matched = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return matched;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
// $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.definitions;
|
||||
|
||||
import static com.sk89q.rulelists.RuleEntryLoader.INLINE;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import com.sk89q.rebar.config.AbstractNodeLoader;
|
||||
import com.sk89q.rebar.config.ConfigurationNode;
|
||||
import com.sk89q.rebar.config.LoaderBuilderException;
|
||||
import com.sk89q.rebar.config.types.MaterialPatternLoaderBuilder;
|
||||
import com.sk89q.rebar.config.types.StaticFieldLoaderBuilder;
|
||||
import com.sk89q.rebar.util.LoggerUtils;
|
||||
import com.sk89q.rebar.util.MaterialPattern;
|
||||
import com.sk89q.rulelists.DefinitionException;
|
||||
import com.sk89q.rulelists.RuleListUtils;
|
||||
import com.sk89q.rulelists.RuleListsManager;
|
||||
import com.sk89q.worldguard.bukkit.resolvers.EntityResolver;
|
||||
import com.sk89q.worldguard.bukkit.resolvers.ItemStackSlotResolver;
|
||||
|
||||
public class ItemCriteriaLoader extends AbstractNodeLoader<ItemCriteria> {
|
||||
|
||||
private final RuleListsManager manager;
|
||||
private MaterialPatternLoaderBuilder materialLoader = new MaterialPatternLoaderBuilder();
|
||||
private StaticFieldLoaderBuilder<PotionEffectType> effectLoader =
|
||||
new StaticFieldLoaderBuilder<PotionEffectType>(PotionEffectType.class);
|
||||
|
||||
public ItemCriteriaLoader(RuleListsManager manager) {
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemCriteria read(ConfigurationNode node) throws DefinitionException {
|
||||
String entity = node.getString("entity");
|
||||
EntityResolver entityResolver = null;
|
||||
ItemStackSlotResolver resolver = null;
|
||||
|
||||
if (entity != null) {
|
||||
entityResolver = manager.getResolvers()
|
||||
.get(EntityResolver.class, entity);
|
||||
resolver = manager.getResolvers()
|
||||
.get(ItemStackSlotResolver.class, node.getString("item", ItemStackSlotResolver.DEFAULT));
|
||||
}
|
||||
|
||||
// has-data
|
||||
Boolean hasData = null;
|
||||
if (node.contains("has-data")) {
|
||||
hasData = node.getBoolean("has-data", false);
|
||||
}
|
||||
|
||||
// Patterns
|
||||
List<MaterialPattern> patterns = node.contains(INLINE) ? node.listOf(INLINE,
|
||||
materialLoader) : node.listOf("material", materialLoader);
|
||||
if (patterns.size() == 0 && hasData == null) {
|
||||
throw new LoaderBuilderException("No block materials specified");
|
||||
}
|
||||
|
||||
// Potion effects
|
||||
Set<PotionEffectType> effects = node.setOf("potion-effect", effectLoader);
|
||||
|
||||
ItemCriteria criteria = new ItemCriteria(entityResolver, resolver);
|
||||
criteria.setPatterns(patterns);
|
||||
criteria.setDataCheck(hasData);
|
||||
criteria.setPotionEffects(effects);
|
||||
|
||||
RuleListUtils.warnUnknown(node, LoggerUtils.getLogger(getClass()),
|
||||
"item", "entity", "has-data", "material", "potion-effect");
|
||||
|
||||
return criteria;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
// $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.definitions;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.sk89q.rulelists.Criteria;
|
||||
import com.sk89q.worldguard.bukkit.BukkitContext;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.bukkit.resolvers.EntityResolver;
|
||||
|
||||
public class PermissionCriteria implements Criteria<BukkitContext> {
|
||||
|
||||
private final WorldGuardPlugin wg;
|
||||
private final EntityResolver entityResolver;
|
||||
private String permission;
|
||||
|
||||
public PermissionCriteria(WorldGuardPlugin wg, EntityResolver entityResolver) {
|
||||
this.wg = wg;
|
||||
this.entityResolver = entityResolver;
|
||||
}
|
||||
|
||||
public String getPermission() {
|
||||
return permission;
|
||||
}
|
||||
|
||||
public void setPermission(String permission) {
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(BukkitContext context) {
|
||||
Entity entity = entityResolver.resolve(context);
|
||||
|
||||
if (entity == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (entity instanceof Player) {
|
||||
return wg.hasPermission((Player) entity, permission);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
// $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.definitions;
|
||||
|
||||
import static com.sk89q.rulelists.RuleEntryLoader.INLINE;
|
||||
|
||||
import com.sk89q.rebar.config.AbstractNodeLoader;
|
||||
import com.sk89q.rebar.config.ConfigurationNode;
|
||||
import com.sk89q.rebar.util.LoggerUtils;
|
||||
import com.sk89q.rulelists.DefinitionException;
|
||||
import com.sk89q.rulelists.RuleListUtils;
|
||||
import com.sk89q.rulelists.RuleListsManager;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.bukkit.resolvers.EntityResolver;
|
||||
|
||||
public class PermissionCriteriaLoader extends AbstractNodeLoader<PermissionCriteria> {
|
||||
|
||||
private final WorldGuardPlugin wg;
|
||||
private final RuleListsManager manager;
|
||||
|
||||
public PermissionCriteriaLoader(WorldGuardPlugin wg, RuleListsManager manager) {
|
||||
this.wg = wg;
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionCriteria read(ConfigurationNode node) throws DefinitionException {
|
||||
EntityResolver entityResolver = manager.getResolvers()
|
||||
.get(EntityResolver.class, node.getString("entity", EntityResolver.DEFAULT));
|
||||
|
||||
String permission = node.contains(INLINE) ?
|
||||
node.getString(INLINE, "") :
|
||||
node.getString("permission", "");
|
||||
|
||||
PermissionCriteria criteria = new PermissionCriteria(wg, entityResolver);
|
||||
criteria.setPermission(permission);
|
||||
|
||||
RuleListUtils.warnUnknown(node, LoggerUtils.getLogger(getClass()),
|
||||
"entity", "permission");
|
||||
|
||||
return criteria;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
// $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.definitions;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.weather.LightningStrikeEvent;
|
||||
|
||||
import com.sk89q.rulelists.Criteria;
|
||||
import com.sk89q.worldguard.bukkit.BukkitContext;
|
||||
|
||||
public class PhenomenonCriteria implements Criteria<BukkitContext> {
|
||||
|
||||
private Boolean isLightning = null;
|
||||
|
||||
public PhenomenonCriteria(Boolean isLightning) {
|
||||
}
|
||||
|
||||
public Boolean getIsLightning() {
|
||||
return isLightning;
|
||||
}
|
||||
|
||||
public void setIsLightning(Boolean isLightning) {
|
||||
this.isLightning = isLightning;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(BukkitContext context) {
|
||||
Event event = context.getEvent();
|
||||
|
||||
if (isLightning != null && isLightning && event instanceof LightningStrikeEvent) {
|
||||
return true;
|
||||
} else {
|
||||
return isLightning == null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
// $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.definitions;
|
||||
|
||||
import static com.sk89q.rulelists.RuleEntryLoader.INLINE;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import com.sk89q.rebar.config.AbstractNodeLoader;
|
||||
import com.sk89q.rebar.config.ConfigurationNode;
|
||||
import com.sk89q.rebar.config.types.EnumLoaderBuilder;
|
||||
import com.sk89q.rebar.util.LoggerUtils;
|
||||
import com.sk89q.rulelists.DefinitionException;
|
||||
import com.sk89q.rulelists.RuleListUtils;
|
||||
|
||||
public class PhenomenonCriteriaLoader extends AbstractNodeLoader<PhenomenonCriteria> {
|
||||
|
||||
public enum Phenomenon {
|
||||
LIGHTNING;
|
||||
}
|
||||
|
||||
private EnumLoaderBuilder<Phenomenon> typeLoader =
|
||||
new EnumLoaderBuilder<Phenomenon>(Phenomenon.class);
|
||||
|
||||
@Override
|
||||
public PhenomenonCriteria read(ConfigurationNode node) throws DefinitionException {
|
||||
Set<Phenomenon> types = node.contains(INLINE) ?
|
||||
node.setOf(INLINE, typeLoader) :
|
||||
node.setOf("type", typeLoader);
|
||||
|
||||
PhenomenonCriteria criteria = new PhenomenonCriteria(types.contains(Phenomenon.LIGHTNING));
|
||||
|
||||
RuleListUtils.warnUnknown(node, LoggerUtils.getLogger(getClass()),
|
||||
"type");
|
||||
|
||||
return criteria;
|
||||
}
|
||||
|
||||
}
|
||||
Loaded 100 of 225 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user