Compare commits

...
100 Commits
Author SHA1 Message Date
wizjany 1d984198ce [maven-release-plugin] prepare release 5.7.2 2013-03-15 16:01:02 -04:00
wizjany f2ca980771 Update changelog to 5.7.2 2013-03-15 15:44:48 -04:00
wizjany b826697aea Add flag check to smelting/mining xp handling 2013-03-15 15:44:34 -04:00
wizjany 89430c13ec Handle TNT Minecarts with tnt flag/settings. 2013-03-15 15:32:57 -04:00
Wizjany f07acea3e1 Updated to MC 1.5 2013-03-15 14:42:20 -04:00
wizjany e9402c55e6 Fixed a bunch of small bugs 2013-03-14 18:45:05 -04:00
wizjany 2eb6c76da8 Fix stack issue. 2013-03-13 14:38:28 -04:00
Wizjany a34e48a145 Added unit test for entry and exit flags to put the matter to rest.
Also cleaned up a few other things regarding tests.
2013-03-01 22:20:16 -05:00
Wizjany 2d50659b48 Apply exp flag and config setting to xp bottles.
"Workaround" for not being able to blacklist exp bottles at the moment.
Although I supposed I could have just fixed that instead, this allows more flexibility.
2013-02-21 10:20:47 -05:00
Wizjany 327ae2b807 Apply crop trampling setting to all entities. 2013-02-21 10:13:17 -05:00
Wizjany dfb6114584 Fix a few wolf issues 2013-01-31 08:23:38 -05:00
Wizjany 5085841d9d [maven-release-plugin] prepare for next development iteration 2013-01-30 16:26:26 -05:00
Wizjany 7a98944469 [maven-release-plugin] prepare release 5.7.1 2013-01-30 16:26:20 -05:00
Wizjany 3d2b455cda Update changelog for 5.7.1 2013-01-30 16:21:55 -05:00
Wizjany 460d5d0691 Made wolves respect pvp stuff. Removed some extraneous code. 2013-01-30 15:27:52 -05:00
Wizjany b5f80351ec Allow a lot of commands to be sent from the console.
Examples:
 /rg addmem <id> <player> -w <worldname>
 /rg flag <id> <flag> -w <worldname> <flagvalue>
 /rg remove <id> -w <worldname>
Command blocks are currently untested.
List of commands: flag, priority, parent, remove,
 addmember, removemember, addowner, removeowner
2013-01-30 14:45:29 -05:00
Wizjany 72a9472a57 Add vine growth flag and config option. 2013-01-30 14:02:45 -05:00
Wizjany 7eb820c688 Fixed bug where players could place beds on the borders of regions without permissions 2013-01-30 13:47:48 -05:00
Wizjany 886b279da6 Bugfixes for bonemeal and minecarts. 2013-01-27 22:43:29 -05:00
Wizjany f2d7135fc5 Check shooter of projectile when one hits a hanging entity 2013-01-25 21:07:11 -05:00
Wizjany d214a859c3 Check the block that the item frame will end in, not the block the player clicked. 2013-01-21 04:08:17 -05:00
Wizjany d1e221c2b7 Don't cancel explosion if we only want to clear blocklist. May potentially cause issues with multiple settings overlapping. 2013-01-19 08:46:51 -05:00
Dark Arc e0e4207a4d Apply a cap to the health and hunger flags to prevent possible exceptions
If a player's health or hunger is set to higher than its respective maximum CraftBukkit will throw exceptions.
2013-01-16 14:48:39 -05:00
Wizjany 4398c781c5 Wither skulls should be handled separately from fireballs 2013-01-15 18:23:53 -05:00
Wizjany 3e06000fd9 Workaround for CraftBukkit bug with slab placement 2013-01-15 16:06:42 -05:00
Wizjany 833795ebe1 Add enderchest and anvil to blacklist inventories. 2013-01-14 13:31:54 -05:00
Wizjany 6e270d5ec3 Setting summary-on-start to false reduces much more clutter now 2013-01-13 17:21:51 -05:00
Wizjany 09a9bea3a7 Move enderchest to use flag 2013-01-13 16:10:06 -05:00
Wizjany 035ccee2a6 Fixed placing stuff in flower pots. (derp) 2013-01-13 13:44:54 -05:00
Wizjany 17aa2a4153 Fix region teleport permission 2013-01-13 06:13:41 -05:00
Wizjany f5bc5c0b47 That was not in there 2013-01-13 03:48:11 -05:00
Wizjany e7a4afde7d [maven-release-plugin] prepare for next development iteration 2013-01-13 03:08:17 -05:00
Wizjany 8758c9b940 [maven-release-plugin] prepare release 5.7 2013-01-13 03:08:13 -05:00
Wizjany a569d20779 Remove max players flag for now.
There are currently too many unhandled circumstances
which can easily break this flag such as players
entering region in weird ways (teleporting, falling,
logging in) and states changing. It is also horribly
inefficient at the moment.
2013-01-13 02:34:34 -05:00
Wizjany 88e01fa083 Fix enderpearl flag properly 2013-01-12 11:39:59 -05:00
Wizjany 7b435f9283 Added changelog for 5.7. Incremented version in pom.xml. 2013-01-12 00:25:55 -05:00
Wizjany a240e5d128 Added config option to block zombies from breaking down doors 2013-01-12 00:25:55 -05:00
Wizjany 0d0ba31d3a Fixes for tripwire, flower pots, wooden buttons, ender chests, and sneaking 2013-01-12 00:25:54 -05:00
Wizjany e79bb3533d Fireball flag should block blaze fireball ignition too now 2013-01-12 00:25:54 -05:00
Wizjany f94c4ec831 Mob damage setting/flag blocks poison DoT 2013-01-12 00:25:54 -05:00
Wizjany d5afb76105 Added config setting and flag to block explosions by plugins. 2013-01-12 00:25:53 -05:00
Wizjany dd7e9ba05e Add enderpearl flag to prevent players from teleporting to/from regions with enderpearls 2013-01-11 18:21:20 -05:00
Wizjany ee54698fdb Fix players being able to plant cocoa beans in protected areas 2013-01-11 17:54:29 -05:00
Wizjany 955b0e991c Added MAX_PLAYER and MAX_PLAYER_MESSAGE flags
Allows setting maximum number of players in a region
and sends a message if a region is at capacity.
2013-01-11 17:09:15 -05:00
Dilandau c1b98b9e40 Decrease call to PluginManager in WGBukkit
If WorldGuard is already found we bypass the call to
the PluginManager and use a cached version.
2013-01-11 16:16:49 -05:00
Dark Arc d6939b7916 Allow EnderPearls to damage the player who threw them in no-pvp areas 2013-01-02 19:46:41 -05:00
Dark Arc 5f0ca37879 Add support for blocking sub commands 2013-01-02 19:03:22 -05:00
Wizjany 548bdb7eb5 Attempt to fix item frame issues 2012-12-31 17:03:14 -05:00
Wizjany 5c85f39228 Block snowballs in pvp regions again. Reverts 671fd58568 2012-12-30 15:11:19 -05:00
Wizjany 85b2cbc03a Null check for entity explosions without an entity. 2012-12-29 11:46:24 -05:00
Wizjany cc78011da6 Build on latest Bukkit snapshot. Closes WORLDGUARD-2381
Fixes EntityChangeBlockEvent errors. Note that 1.4.5-R0.3-SNAPSHOT means build 2505+ and that there ARE 0.3 snapshots below 2505. Thus, this should be treated as temporary and changed on the next Bukkit Beta.
2012-12-29 11:46:14 -05:00
Dark Arc d016da1895 Resolves WORLDGUARD-2316 TNT still lethal when its damage is disabled 2012-11-24 02:42:28 -05:00
Dark Arc 8593f1c80a Resolves WORLDGUARD-2352 Anvils usable despite the use flag 2012-11-24 02:25:59 -05:00
Dark Arc 0b3c40dc3e Implements WORLDGUARD-2315 Enderdragon portal blocking 2012-11-24 02:17:34 -05:00
sk89q 2e7ecc59c0 Fixed typo where BEACON was COMMAND_BLOCK instead. 2012-11-11 19:08:31 -08:00
sk89q 942ce95dbf Fixed #WORLDGUARD-2297, Beacons are not protected in regions. 2012-11-11 18:45:55 -08:00
sk89q 03f77d5ab7 Fixed #WORLDGUARD-2296, Recent fix for dragon eggs in regions not working for left click. 2012-11-11 18:43:34 -08:00
sk89q 8dec32fa6a Added workaround for #WORLDGUARD-2299, java.lang.IllegalArgumentException: Instant potions cannot be extended. 2012-11-11 18:41:18 -08:00
sk89q 8f409d47d9 Fixed #WORLDGUARD-2289, FlagStateManager is not thread synced with the main thread. 2012-11-11 18:36:08 -08:00
sk89q 93f062d4e3 Hey, we have a mailing list now! Subscribe! https://groups.google.com/d/forum/sk-dev-discuss 2012-11-07 13:00:44 -08:00
Dark Arc b8f9ceafbb Resolves comma issue relating to flag listing
This stops commas from being added when a player types in an invalid flag and the player does not have permission to use one or more of the flag that are listed.
2012-11-07 14:20:44 -05:00
sk89q 75d07b6dad [maven-release-plugin] prepare for next development iteration 2012-11-07 09:19:50 -08:00
sk89q 6060a0a430 [maven-release-plugin] prepare release 5.6.5 2012-11-07 09:19:35 -08:00
sk89q 647ba1572c Updated CHANGELOG.txt for 5.6.5. 2012-11-07 09:10:20 -08:00
sk89q 051e0cb811 Fixed regression bug cause item frames and paintings to not be protected. 2012-11-07 09:07:38 -08:00
sk89q b8c9e78910 [maven-release-plugin] prepare for next development iteration 2012-11-06 20:39:09 -08:00
sk89q 2d7d9c6093 [maven-release-plugin] prepare release 5.6.4 2012-11-06 20:38:50 -08:00
sk89q 0f32f56208 Updated CHANGELOG.txt for 5.6.4. 2012-11-06 20:35:18 -08:00
sk89q 5addfd8975 Added security.deop-everyone-on-join and security.block-in-game-op-command. 2012-11-06 20:32:15 -08:00
sk89q 7f108ce8f0 Changed dragon eggs to be checked like it is a broken block in regions. 2012-11-06 20:19:16 -08:00
sk89q 8c883e1ca8 WGBukkit is not supposed to be there. Now in com.sk89q.worldguard.bukkit. 2012-11-06 19:26:05 -08:00
sk89q d18fe6ffa0 Worked around bug with water potions causing errors. 2012-11-06 19:21:12 -08:00
sk89q 80a8ac9e98 Added mobs.block-above-ground-slimes to block slimes spawning naturally above ground (in swamps). 2012-11-06 18:49:32 -08:00
Dark Arc 671fd58568 Stop snowball blocking 2012-11-06 18:59:08 -05:00
Dark Arc c4ea3b59f0 Resolve WORLDGUARD-2281, for Dispensers 2012-11-06 18:44:36 -05:00
Dark Arc 5d5def206d Actually corrected Javadoc 2012-11-06 18:07:26 -05:00
Dark Arc b2ebbb9b55 Corrected Javadoc 2012-11-06 18:04:22 -05:00
Dark Arc 3734c071bf Fixes WORLDGUARD-2281, NPE on Water Potion Drinking
This resolves the issue where WorldGuard would throw a NullPointerException when a player drank a potion of water while potion blocking was enabled.
2012-11-06 18:01:13 -05:00
sk89q b1a419f2a2 [maven-release-plugin] prepare for next development iteration 2012-11-05 12:40:01 -08:00
sk89q bf5e292160 [maven-release-plugin] prepare release 5.6.3 2012-11-05 12:39:46 -08:00
sk89q df57d91270 Possibly fixed the ladder setting. 2012-11-05 12:28:40 -08:00
sk89q 4da1741578 kekekeke forgot static in WGBukkit's methods. 2012-11-05 12:22:04 -08:00
sk89q 7a3774e730 Updated CHANGELOG.txt for 5.6.3. 2012-11-05 12:20:13 -08:00
sk89q e6e21caeea Added helper WGBukkit class to get references to WorldGuard in other Bukkit plugins. 2012-11-05 12:12:25 -08:00
sk89q 200d47ab09 Added physics.vine-like-rope-ladders to make ladders work like vines. 2012-11-05 11:32:40 -08:00
sk89q ab274151d4 Potential fix for WORLDGUARD-2263, mobs.block-{item-frame,painting}-destroy not working. 2012-11-05 11:27:35 -08:00
sk89q aec1e3a529 Fixed NPE in PlayerInteractEvent due to potion blocking. Fixes WORLDGUARD-2269. 2012-11-05 11:09:14 -08:00
sk89q 916caa1eb2 [maven-release-plugin] prepare for next development iteration 2012-11-04 14:49:50 -08:00
sk89q 50b29f8ad6 [maven-release-plugin] prepare release 5.6.2 2012-11-04 14:49:35 -08:00
sk89q 88d662cf27 Updated CHANGELOG.txt for 5.6.2. 2012-11-04 14:48:30 -08:00
sk89q 5316130ae8 Better handle potion blocking with dispensers/splash potions. 2012-11-04 14:46:36 -08:00
sk89q 4f36dbc636 [maven-release-plugin] prepare for next development iteration 2012-11-04 13:48:25 -08:00
sk89q 230a8697bf [maven-release-plugin] prepare release 5.6.1 2012-11-04 13:48:08 -08:00
sk89q 121449b230 Updated changelog for 5.6.1. 2012-11-04 13:44:52 -08:00
sk89q fede549b51 Added gameplay.block-potions. 2012-11-04 13:42:55 -08:00
sk89q 1bdd7f9a6b Fixed a tab issue with WorldGuardBlockListener due to the mycelium commit. 2012-11-04 13:12:06 -08:00
sk89q b3f9da67b7 Changed version to 5.6.1-SNAPSHOT. 2012-11-04 13:06:35 -08:00
sk89q 1ba7d623b4 Adds null check in EntityExplodeEvent's handler, fixing WORLDGUARD-2267. 2012-11-04 13:05:25 -08:00
Gabriel Harris-Rouquette 47902e1177 Added mycelium-spread flags. 2012-11-03 15:31:16 -07:00
sk89q a035bcc671 [maven-release-plugin] prepare for next development iteration 2012-11-03 12:38:06 -07:00
23 changed files with 1663 additions and 597 deletions

No files matched your search

+92 -1
View File
@@ -1,3 +1,94 @@
5.7.2:
- Updated to MineCraft 1.5.
- Added TNT Minecart support. They are handled with the same flags/settings as TNT.
- Added mining and smelting xp handling to the xp drops flag and setting.
- Fixed a few edge cases for placing items on region borders.
- Legacy: Fixed issue with //stack not respecting item metadata.
5.7.1:
- Added a vine growth config option and flag.
- Added support for many commands to be used from console.
Usage is with -w flag and a world name e.g.
/rg addmem <id> <player> -w <worldname>
/rg flag <id> <flag> -w <worldname> <flagvalue>
- Fixed bug that blocks placing plants in flower pots.
- Fixed permissions check for /rg tp
- Fixed enderchests not being accessible (they are now part of the USE flag)
- Fixed an issue with slabs being placable in protected regions. This was
also fixed in CraftBukkit but has been left in for users running other versions.
- Fixed wither skulls being handled with other fireballs, despite having their own settings.
- Fixed item frames being placable on region borders.
- Fixed a bug that made explosions more ineffective than they should have been.
- Fixed bonemeal usage in protected regions.
- Fixed special minecarts being placable in protected regions.
- Fixed bugs being placable on region borders.
- Fixed wolves bypassing pvp flags.
5.7:
- Fixed thread sync issue with FlagStateManager.
- Fixed dragon egg region protection not working in certain cases.
- Added beacon and anvil usage protection in regions.
- Add mobs.block-enderdragon-portal-creation to stop enderdragons
from making portals on death.
- Fix TNT being lethal in some case when damage was disabled.
- Fix snowballs and enderpearls being able to knock players back in
pvp deny regions.
- Add subcommand support for allowed and blocked command flags.
- Add max-players-allowed and max-players-reject-message flags to
limit the numbers of players in a region.
- Fix players being able to plant cocoa beans in protected areas.
- Add an enderpearl flag to prevent players from teleporting to and
from regions.
- Added mobs.block-other-explosions config setting and other-explosion
flag to block explosions caused by uncovered things, such as other
plugins. (It doesn't actually have to be a mob)
- Fix mob damage setting and flag not blocking the DoT wither effect.
- Ghast fireball flag will not block blaze fireballs from lighting things
on fire.
- Fixed players without region permissions being able to trigger tripwires,
use enderchests, use wooden buttons, and put plants in flower pots.
- Added mobs.block-zombie-door-destruction setting to stop zombies from
breaking down doors while difficulty is set to hard.
Thank you to thvortex, Dilandau, tophathacker, and Dark_arc for their contributions this release.
5.6.5:
- Fixed a regression that caused paintings and item frames to no longer be properly
protected.
5.6.4:
- Added mobs.block-above-ground-slimes to block slimes spawning naturally above ground.
- Added security.deop-everyone-on-join to de-op all players when they join.
- Added security.block-in-game-op-command to prevent usage of /op from in-game.
- Fixed a NullPointerException in PlayerInteract involving water potions and
potion blocking.
- Fixed an issue with snowballs being blocked in regions.
- Changed dragon eggs to be checked like it is a broken block in regions.
- Moved developer's WGBukkit class to package com.sk89q.worldguard.bukkit.
5.6.3:
- Added helper WGBukkit class to get references to WorldGuard from other plugins.
- Added physics.vine-like-rope-ladders to make ladders work like vines. As long as the
top ladder block is present, ladder blocks will hold even if they have no block
behind them, like a rope ladder.
- Fixed NullPointerException in PlayerInteractEvent caused by potion blocking.
- Fixed mobs.block-{item-frame,painting}-destroy not working.
Thank you to def for testing the above fixes and features.
5.6.2:
- Fixed potion blocking not working well for splash potions.
5.6.1:
- Added a mycelium-spread region flag.
- Added a dynamics.disable-mycelium-spread configuration setting.
- Added new gameplay.block-potions option. For example:
gameplay:
block-potions: [invisibility, speed]
- Fixed a bug in the entity explosion event handler that caused a NullPointerException.
Thank you for gabizou for his contribution in this release.
5.6:
- Added official support for Minecraft 1.4. Support for 1.3.2 (and below) is still
provided in this release.
@@ -456,4 +547,4 @@ EduardBaer, TomyLobo, and halvors
- Added block lag fix.
1.0
- Initial release.
- Initial release.
+3
View File
@@ -26,9 +26,12 @@ must be licensed under the GNU General Public License v3.
Please read CONTRIBUTING.md for important guidelines to follow.
We recommend following our [mailing list](https://groups.google.com/d/forum/sk-dev-discuss), especially if you have some big ideas that you want to implement.
Links
-----
* [Mailing list](https://groups.google.com/d/forum/sk-dev-discuss)
* [IRC channel](http://skq.me/irc/irc.esper.net/sk89q/) (#sk89q on irc.esper.net)
* [Issue tracker](http://youtrack.sk89q.com/issues/WORLDGUARD)
* [Continuous integration](http://build.sk89q.com) [![Build Status](https://secure.travis-ci.org/sk89q/worldguard.png)](http://travis-ci.org/sk89q/worldguard)
+3 -3
View File
@@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.sk89q</groupId>
<artifactId>worldguard</artifactId>
<version>5.6</version>
<version>5.7.2</version>
<name>WorldGuard</name>
<description>WorldGuard protects your Minecraft servers.</description>
<licenses>
@@ -40,13 +40,13 @@
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>worldedit</artifactId>
<version>5.4.4</version>
<version>5.5.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.4.2-R0.2-SNAPSHOT</version>
<version>1.5-R0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
@@ -31,7 +31,6 @@ 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 {
@@ -143,6 +142,27 @@ public class BukkitUtil {
return id == 8 || id == 9;
}
/**
* Checks if the given potion is a vial of water.
*
* @param item the item to check
* @return true if it's a water vial
*/
public static boolean isWaterPotion(ItemStack item) {
return (item.getDurability() & 0x3F) == 0;
}
/**
* Get just the potion effect bits. This is to work around bugs with potion
* parsing.
*
* @param item item
* @return new bits
*/
public static int getPotionEffectBits(ItemStack item) {
return item.getDurability() & 0x3F;
}
/**
* Find a position for the player to stand that is not inside a block.
* Blocks above the player will be iteratively tested until there is
@@ -18,6 +18,15 @@
*/
package com.sk89q.worldguard.bukkit;
import com.sk89q.commandbook.CommandBook;
import com.sk89q.commandbook.GodComponent;
import com.sk89q.util.yaml.YAMLFormat;
import com.sk89q.util.yaml.YAMLProcessor;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.blacklist.Blacklist;
import org.bukkit.World;
import org.bukkit.entity.Player;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
@@ -27,16 +36,6 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import com.sk89q.commandbook.CommandBook;
import com.sk89q.commandbook.GodComponent;
import com.sk89q.util.yaml.YAMLFormat;
import com.sk89q.util.yaml.YAMLProcessor;
import org.bukkit.World;
import org.bukkit.entity.Player;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.blacklist.Blacklist;
/**
* Represents the global configuration and also delegates configuration
* for individual worlds.
@@ -100,6 +99,8 @@ public class ConfigurationManager {
public boolean activityHaltToggle = false;
public boolean autoGodMode;
public boolean usePlayerMove;
public boolean deopOnJoin;
public boolean blockInGameOp;
public Map<String, String> hostKeys = new HashMap<String, String>();
/**
@@ -138,15 +139,14 @@ public class ConfigurationManager {
}
config.removeProperty("suppress-tick-sync-warnings");
useRegionsScheduler = config.getBoolean(
"regions.use-scheduler", true);
useRegionsCreatureSpawnEvent = config.getBoolean(
"regions.use-creature-spawn-event", true);
autoGodMode = config.getBoolean(
"auto-invincible", config.getBoolean("auto-invincible-permission", false));
useRegionsScheduler = config.getBoolean("regions.use-scheduler", true);
useRegionsCreatureSpawnEvent = config.getBoolean("regions.use-creature-spawn-event", true);
autoGodMode = config.getBoolean("auto-invincible", config.getBoolean("auto-invincible-permission", false));
config.removeProperty("auto-invincible-permission");
usePlayerMove = config.getBoolean(
"use-player-move-event", true);
usePlayerMove = config.getBoolean("use-player-move-event", true);
deopOnJoin = config.getBoolean("security.deop-everyone-on-join", false);
blockInGameOp = config.getBoolean("security.block-in-game-op-command", false);
hostKeys = new HashMap<String, String>();
Object hostKeysRaw = config.getProperty("host-keys");
@@ -19,19 +19,18 @@
package com.sk89q.worldguard.bukkit;
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.GameMode;
import org.bukkit.World;
import org.bukkit.entity.Player;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;
import org.bukkit.GameMode;
import org.bukkit.World;
import org.bukkit.entity.Player;
import java.util.HashMap;
import java.util.Map;
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
/**
* This processes per-player state information and is also meant to be used
@@ -83,10 +82,8 @@ public class FlagStateManager implements Runnable {
}
Vector playerLocation = toVector(player.getLocation());
RegionManager regionManager = plugin.getGlobalRegionManager()
.get(player.getWorld());
ApplicableRegionSet applicable = regionManager
.getApplicableRegions(playerLocation);
RegionManager regionManager = plugin.getGlobalRegionManager().get(player.getWorld());
ApplicableRegionSet applicable = regionManager.getApplicableRegions(playerLocation);
if (!RegionQueryUtil.isInvincible(plugin, player, applicable)
&& !plugin.getGlobalStateManager().hasGodMode(player)
@@ -124,6 +121,10 @@ public class FlagStateManager implements Runnable {
if (minHealth == null) minHealth = 0;
if (maxHealth == null) maxHealth = 20;
// Apply a cap to prevent possible exceptions
minHealth = Math.min(player.getMaxHealth(), minHealth);
maxHealth = Math.min(player.getMaxHealth(), maxHealth);
if (player.getHealth() >= maxHealth && healAmount > 0) {
return;
}
@@ -161,6 +162,10 @@ public class FlagStateManager implements Runnable {
if (minHunger == null) minHunger = 0;
if (maxHunger == null) maxHunger = 20;
// Apply a cap to prevent possible exceptions
minHunger = Math.min(20, minHunger);
maxHunger = Math.min(20, maxHunger);
if (player.getFoodLevel() >= maxHunger && feedAmount > 0) {
return;
}
@@ -0,0 +1,73 @@
// $Id$
/*
* This file is a part of WorldGuard.
* Copyright (c) sk89q <http://www.sk89q.com>
* Copyright (c) the WorldGuard team and contributors
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit;
import org.bukkit.Bukkit;
import org.bukkit.World;
import com.sk89q.worldguard.protection.managers.RegionManager;
/**
* Helper class to get a reference to WorldGuard and its components.
*/
public class WGBukkit {
private static WorldGuardPlugin cachedPlugin = null;
private WGBukkit() {
}
/**
* Get the WorldGuard plugin. If WorldGuard isn't loaded yet, then this will
* return null.
* <p>
* If you are depending on WorldGuard in your plugin, you should place
* <code>softdepend: [WorldGuard]</code> or <code>depend: [WorldGuard]</code>
* in your plugin.yml so that this won't return null for you.
*
* @return the WorldGuard plugin or null
*/
public static WorldGuardPlugin getPlugin() {
if (cachedPlugin == null) {
cachedPlugin = (WorldGuardPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldGuard");
}
return cachedPlugin;
}
/**
* Set cache to null for reload WorldGuardPlugin
*/
public static void cleanCache() {
cachedPlugin = null;
}
/**
* Returns the region manager for a given world. May return null if WorldGuard
* is not loaded or region protection is not enabled for the given world.
*
* @param world world
* @return a region manager or null
*/
public static RegionManager getRegionManager(World world) {
if (getPlugin() == null) {
return null;
}
return cachedPlugin.getRegionManager(world);
}
}
@@ -19,6 +19,22 @@
package com.sk89q.worldguard.bukkit;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import org.bukkit.block.Block;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffectType;
import com.sk89q.util.yaml.YAMLFormat;
import com.sk89q.util.yaml.YAMLProcessor;
import com.sk89q.worldguard.blacklist.Blacklist;
@@ -28,15 +44,6 @@ 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 org.bukkit.block.Block;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.*;
import java.util.logging.Level;
/**
* Holds the configuration for individual worlds.
@@ -68,16 +75,20 @@ public class WorldConfiguration {
private ChestProtection chestProtection = new SignChestProtection();
/* Configuration data start */
public boolean summaryOnStart;
public boolean opPermissions;
public boolean fireSpreadDisableToggle;
public boolean itemDurability;
public boolean simulateSponge;
public int spongeRadius;
public boolean disableExpDrops;
public Set<PotionEffectType> blockPotions;
public boolean blockPotionsAlways;
public boolean pumpkinScuba;
public boolean redstoneSponges;
public boolean noPhysicsGravel;
public boolean noPhysicsSand;
public boolean ropeLadders;
public boolean allowPortalAnywhere;
public Set<Integer> preventWaterDamage;
public boolean blockLighter;
@@ -94,11 +105,15 @@ public class WorldConfiguration {
public boolean blockWitherSkullExplosions;
public boolean blockWitherSkullBlockDamage;
public boolean blockEnderDragonBlockDamage;
public boolean blockEnderDragonPortalCreation;
public boolean blockFireballExplosions;
public boolean blockFireballBlockDamage;
public boolean blockOtherExplosions;
public boolean blockEntityPaintingDestroy;
public boolean blockEntityItemFrameDestroy;
public boolean blockPluginSpawning;
public boolean blockGroundSlimes;
public boolean blockZombieDoorDestruction;
public boolean disableContactDamage;
public boolean disableFallDamage;
public boolean disableLavaDamage;
@@ -143,6 +158,8 @@ public class WorldConfiguration {
public boolean disableIceFormation;
public boolean disableLeafDecay;
public boolean disableGrassGrowth;
public boolean disableMyceliumSpread;
public boolean disableVineGrowth;
public boolean disableEndermanGriefing;
public boolean regionInvinciblityRemovesMobs;
public boolean disableDeathMessages;
@@ -174,7 +191,9 @@ public class WorldConfiguration {
config = new YAMLProcessor(configFile, true, YAMLFormat.EXTENDED);
loadConfiguration();
plugin.getLogger().info("Loaded configuration for world '" + worldName + "'");
if (summaryOnStart) {
plugin.getLogger().info("Loaded configuration for world '" + worldName + "'");
}
}
private boolean getBoolean(String node, boolean def) {
@@ -280,6 +299,7 @@ public class WorldConfiguration {
e.printStackTrace();
}
summaryOnStart = getBoolean("summary-on-start", true);
opPermissions = getBoolean("op-permissions", true);
itemDurability = getBoolean("protection.item-durability", true);
@@ -287,6 +307,18 @@ public class WorldConfiguration {
disableExpDrops = getBoolean("protection.disable-xp-orb-drops", false);
disableObsidianGenerators = getBoolean("protection.disable-obsidian-generators", false);
blockPotions = new HashSet<PotionEffectType>();
for (String potionName : getStringList("gameplay.block-potions", null)) {
PotionEffectType effect = PotionEffectType.getByName(potionName);
if (effect == null) {
plugin.getLogger().warning("Unknown potion effect type '" + potionName + "'");
} else {
blockPotions.add(effect);
}
}
blockPotionsAlways = getBoolean("gameplay.block-potions-overly-reliably", false);
simulateSponge = getBoolean("simulation.sponge.enable", true);
spongeRadius = Math.max(1, getInt("simulation.sponge.radius", 3)) - 1;
redstoneSponges = getBoolean("simulation.sponge.redstone", false);
@@ -296,6 +328,7 @@ public class WorldConfiguration {
noPhysicsGravel = getBoolean("physics.no-physics-gravel", false);
noPhysicsSand = getBoolean("physics.no-physics-sand", false);
ropeLadders = getBoolean("physics.vine-like-rope-ladders", false);
allowPortalAnywhere = getBoolean("physics.allow-portal-anywhere", false);
preventWaterDamage = new HashSet<Integer>(getIntList("physics.disable-water-damage-blocks", null));
@@ -315,6 +348,7 @@ public class WorldConfiguration {
blockWitherSkullExplosions = getBoolean("mobs.block-wither-skull-explosions", false);
blockWitherSkullBlockDamage = getBoolean("mobs.block-wither-skull-block-damage", false);
blockEnderDragonBlockDamage = getBoolean("mobs.block-enderdragon-block-damage", false);
blockEnderDragonPortalCreation = getBoolean("mobs.block-enderdragon-portal-creation", false);
blockFireballExplosions = getBoolean("mobs.block-fireball-explosions", false);
blockFireballBlockDamage = getBoolean("mobs.block-fireball-block-damage", false);
antiWolfDumbness = getBoolean("mobs.anti-wolf-dumbness", false);
@@ -322,6 +356,9 @@ public class WorldConfiguration {
blockEntityPaintingDestroy = getBoolean("mobs.block-painting-destroy", false);
blockEntityItemFrameDestroy = getBoolean("mobs.block-item-frame-destroy", false);
blockPluginSpawning = getBoolean("mobs.block-plugin-spawning", true);
blockGroundSlimes = getBoolean("mobs.block-above-ground-slimes", false);
blockOtherExplosions = getBoolean("mobs.block-other-explosions", false);
blockZombieDoorDestruction = getBoolean("mobs.block-zombie-door-destruction", false);
disableFallDamage = getBoolean("player-damage.disable-fall-damage", false);
disableLavaDamage = getBoolean("player-damage.disable-lava-damage", false);
@@ -359,6 +396,8 @@ public class WorldConfiguration {
disableIceFormation = getBoolean("dynamics.disable-ice-formation", false);
disableLeafDecay = getBoolean("dynamics.disable-leaf-decay", false);
disableGrassGrowth = getBoolean("dynamics.disable-grass-growth", false);
disableMyceliumSpread = getBoolean("dynamics.disable-mycelium-spread", false);
disableVineGrowth = getBoolean("dynamics.disable-vine-growth", false);
useRegions = getBoolean("regions.enable", true);
regionInvinciblityRemovesMobs = getBoolean("regions.invincibility-removes-mobs", false);
@@ -431,7 +470,9 @@ public class WorldConfiguration {
this.blacklist = null;
} else {
this.blacklist = blist;
plugin.getLogger().log(Level.INFO, "Blacklist loaded.");
if (summaryOnStart) {
plugin.getLogger().log(Level.INFO, "Blacklist loaded.");
}
BlacklistLogger blacklistLogger = blist.getLogger();
@@ -457,7 +498,7 @@ public class WorldConfiguration {
}
// Print an overview of settings
if (getBoolean("summary-on-start", true)) {
if (summaryOnStart) {
plugin.getLogger().log(Level.INFO, blockTNTExplosions
? "(" + worldName + ") TNT ignition is blocked."
: "(" + worldName + ") TNT ignition is PERMITTED.");
@@ -22,6 +22,7 @@ import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
@@ -31,10 +32,13 @@ 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.BlockExpEvent;
import org.bukkit.event.block.BlockFadeEvent;
import org.bukkit.event.block.BlockFormEvent;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.block.BlockIgniteEvent.IgniteCause;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
@@ -43,12 +47,14 @@ import org.bukkit.event.block.BlockRedstoneEvent;
import org.bukkit.event.block.BlockSpreadEvent;
import org.bukkit.event.block.LeavesDecayEvent;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.block.BlockIgniteEvent.IgniteCause;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.Potion;
import org.bukkit.potion.PotionEffect;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.blocks.BlockType;
import com.sk89q.worldedit.blocks.ItemType;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.blacklist.events.BlockBreakBlacklistEvent;
import com.sk89q.worldguard.blacklist.events.BlockPlaceBlacklistEvent;
@@ -134,7 +140,7 @@ public class WorldGuardBlockListener implements Listener {
if (held.getTypeId() > 0
&& !(ItemType.usesDamageValue(held.getTypeId())
|| BlockType.usesData(held.getTypeId()))) {
held.setDurability((short) -1);
held.setDurability(Material.getMaterial(held.getTypeId()).getMaxDurability());
player.setItemInHand(held);
}
}
@@ -358,6 +364,14 @@ public class WorldGuardBlockListener implements Listener {
return;
}
if (cause == IgniteCause.FIREBALL && event.getPlayer() == null) {
// wtf bukkit, FIREBALL is supposed to be reserved to players
if (!set.allows(DefaultFlag.GHAST_FIREBALL)) {
event.setCancelled(true);
return;
}
}
if (cause == IgniteCause.LIGHTNING && !set.allows(DefaultFlag.LIGHTNING)) {
event.setCancelled(true);
return;
@@ -467,6 +481,13 @@ public class WorldGuardBlockListener implements Listener {
event.setCancelled(true);
return;
}
if (wcfg.ropeLadders && event.getBlock().getType() == Material.LADDER) {
if (event.getBlock().getRelative(0, 1, 0).getType() == Material.LADDER) {
event.setCancelled(true);
return;
}
}
}
/*
@@ -726,6 +747,34 @@ public class WorldGuardBlockListener implements Listener {
return;
}
}
if (fromType == BlockID.MYCELIUM) {
if (wcfg.disableMyceliumSpread) {
event.setCancelled(true);
return;
}
if (wcfg.useRegions
&& !plugin.getGlobalRegionManager().allows(
DefaultFlag.MYCELIUM_SPREAD, event.getBlock().getLocation())) {
event.setCancelled(true);
return;
}
}
if (fromType == BlockID.VINE) {
if (wcfg.disableVineGrowth) {
event.setCancelled(true);
return;
}
if (wcfg.useRegions
&& !plugin.getGlobalRegionManager().allows(
DefaultFlag.VINE_GROWTH, event.getBlock().getLocation())) {
event.setCancelled(true);
return;
}
}
}
/*
@@ -802,4 +851,40 @@ public class WorldGuardBlockListener implements Listener {
}
}
}
/*
* Called when a block is damaged.
*/
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockDispense(BlockDispenseEvent event) {
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
if (wcfg.blockPotions.size() > 0) {
ItemStack item = event.getItem();
if (item.getType() == Material.POTION && !BukkitUtil.isWaterPotion(item)) {
Potion potion = Potion.fromDamage(BukkitUtil.getPotionEffectBits(item));
for (PotionEffect effect : potion.getEffects()) {
if (potion.isSplash() && wcfg.blockPotions.contains(effect.getType())) {
event.setCancelled(true);
return;
}
}
}
}
}
/*
* Called when a block yields exp
*/
@EventHandler(priority = EventPriority.HIGH)
public void onBlockExp(BlockExpEvent event) {
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
if (wcfg.disableExpDrops || !plugin.getGlobalRegionManager().allows(DefaultFlag.EXP_DROPS,
event.getBlock().getLocation())) {
event.setExpToDrop(0);
}
}
}
@@ -24,7 +24,6 @@ import java.util.Set;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Creature;
@@ -36,18 +35,26 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Fireball;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Minecart;
import org.bukkit.entity.MinecartTNT;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.ThrownPotion;
import org.bukkit.entity.Wither;
import org.bukkit.entity.WitherSkull;
import org.bukkit.entity.Wolf;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.event.entity.CreeperPowerEvent;
import org.bukkit.event.entity.EntityBreakDoorEvent;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityCombustEvent;
import org.bukkit.event.entity.EntityCreatePortalEvent;
import org.bukkit.event.entity.EntityDamageByBlockEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
@@ -56,12 +63,14 @@ import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityInteractEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.event.entity.ExpBottleEvent;
import org.bukkit.event.entity.ExplosionPrimeEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.entity.PigZapEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.entity.PotionSplashEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BlockID;
@@ -81,9 +90,6 @@ import com.sk89q.worldguard.protection.managers.RegionManager;
public class WorldGuardEntityListener implements Listener {
private WorldGuardPlugin plugin;
private EntityType fireballType;
private EntityType witherType;
private EntityType witherSkullType;
/**
* Construct the object;
@@ -92,10 +98,6 @@ public class WorldGuardEntityListener implements Listener {
*/
public WorldGuardEntityListener(WorldGuardPlugin plugin) {
this.plugin = plugin;
fireballType = BukkitUtil.tryEnum(EntityType.class, "LARGE_FIREBALL", "FIREBALL");
witherType = BukkitUtil.tryEnum(EntityType.class, "WITHER");
witherSkullType = BukkitUtil.tryEnum(EntityType.class, "WITHER_SKULL");
}
/**
@@ -114,12 +116,24 @@ public class WorldGuardEntityListener implements Listener {
WorldConfiguration wcfg = cfg.get(entity.getWorld());
if (block.getTypeId() == BlockID.SOIL) {
if (entity instanceof Creature && wcfg.disableCreatureCropTrampling) {
if (/* entity instanceof Creature && // catch for any entity (not thrown for players) */
wcfg.disableCreatureCropTrampling) {
event.setCancelled(true);
}
}
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onExpBottle(ExpBottleEvent event) {
WorldConfiguration wcfg = plugin.getGlobalStateManager().get(event.getEntity().getWorld());
if (wcfg.disableExpDrops || !plugin.getGlobalRegionManager().allows(DefaultFlag.EXP_DROPS,
event.getEntity().getLocation())) {
event.setExperience(0);
// event.setShowEffect(false); // don't want to cancel the bottle entirely I suppose, just the exp
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onEntityDeath(EntityDeathEvent event) {
WorldConfiguration wcfg = plugin.getGlobalStateManager().get(event.getEntity().getWorld());
@@ -236,97 +250,123 @@ public class WorldGuardEntityListener implements Listener {
return;
}
if (wcfg.disableExplosionDamage && event.getCause() == DamageCause.ENTITY_EXPLOSION) {
event.setCancelled(true);
return;
if (wcfg.disableExplosionDamage) {
switch (event.getCause()) {
case BLOCK_EXPLOSION:
case ENTITY_EXPLOSION:
event.setCancelled(true);
return;
}
}
if (attacker != null && attacker instanceof Player) {
if (wcfg.useRegions) {
Vector pt = toVector(defender.getLocation());
Vector pt2 = toVector(attacker.getLocation());
RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld());
if (attacker != null) {
if (attacker instanceof Player) {
if (wcfg.useRegions) {
Vector pt = toVector(defender.getLocation());
Vector pt2 = toVector(attacker.getLocation());
RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld());
if (!mgr.getApplicableRegions(pt2).allows(DefaultFlag.PVP, plugin.wrapPlayer((Player) attacker))) {
tryCancelPVPEvent((Player) attacker, player, event, true);
} else if (!mgr.getApplicableRegions(pt).allows(DefaultFlag.PVP ,localPlayer)) {
tryCancelPVPEvent((Player) attacker, player, event, false);
if (!mgr.getApplicableRegions(pt2).allows(DefaultFlag.PVP, plugin.wrapPlayer((Player) attacker))) {
tryCancelPVPEvent((Player) attacker, player, event, true);
} else if (!mgr.getApplicableRegions(pt).allows(DefaultFlag.PVP ,localPlayer)) {
tryCancelPVPEvent((Player) attacker, player, event, false);
}
}
}
}
if (attacker != null && attacker instanceof TNTPrimed) {
if (wcfg.blockTNTExplosions) {
event.setCancelled(true);
return;
}
if (wcfg.useRegions) {
Vector pt = toVector(defender.getLocation());
RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld());
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
if (!set.allows(DefaultFlag.TNT, localPlayer)) {
if (attacker instanceof TNTPrimed || attacker instanceof MinecartTNT) {
// The check for explosion damage should be handled already... But... What ever...
if (wcfg.blockTNTExplosions) {
event.setCancelled(true);
return;
}
}
}
if (attacker != null && attacker instanceof Fireball) {
if (wcfg.blockFireballExplosions) {
event.setCancelled(true);
return;
}
if (wcfg.useRegions) {
Fireball fireball = (Fireball) attacker;
Vector pt = toVector(defender.getLocation());
RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld());
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
if (fireball.getShooter() instanceof Player) {
Vector pt2 = toVector(fireball.getShooter().getLocation());
if (!mgr.getApplicableRegions(pt2).allows(DefaultFlag.PVP, plugin.wrapPlayer((Player) fireball.getShooter()))) {
tryCancelPVPEvent((Player) fireball.getShooter(), player, event, true);
} else if (!set.allows(DefaultFlag.PVP, localPlayer)) {
tryCancelPVPEvent((Player) fireball.getShooter(), player, event, false);
}
} else {
if (!set.allows(DefaultFlag.GHAST_FIREBALL, localPlayer)) {
event.setCancelled(true);
return;
}
}
}
}
if (attacker != 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, localPlayer)) {
event.setCancelled(true);
return;
}
if (attacker instanceof Creeper) {
if (!set.allows(DefaultFlag.CREEPER_EXPLOSION, localPlayer)) {
if (wcfg.useRegions) {
Vector pt = toVector(defender.getLocation());
RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld());
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
if (!set.allows(DefaultFlag.TNT, localPlayer)) {
event.setCancelled(true);
return;
}
}
}
if (attacker instanceof Fireball) {
if (wcfg.blockFireballExplosions) {
event.setCancelled(true);
return;
}
if (wcfg.useRegions) {
Fireball fireball = (Fireball) attacker;
Vector pt = toVector(defender.getLocation());
RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld());
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
if (fireball.getShooter() instanceof Player) {
Vector pt2 = toVector(fireball.getShooter().getLocation());
if (!mgr.getApplicableRegions(pt2).allows(DefaultFlag.PVP, plugin.wrapPlayer((Player) fireball.getShooter()))) {
tryCancelPVPEvent((Player) fireball.getShooter(), player, event, true);
} else if (!set.allows(DefaultFlag.PVP, localPlayer)) {
tryCancelPVPEvent((Player) fireball.getShooter(), player, event, false);
}
} else {
if (!set.allows(DefaultFlag.GHAST_FIREBALL, localPlayer)) {
event.setCancelled(true);
return;
}
}
}
}
if (attacker instanceof LivingEntity && !(attacker instanceof Player)) {
if (attacker instanceof Creeper && wcfg.blockCreeperExplosions) {
event.setCancelled(true);
return;
}
if (wcfg.disableMobDamage) {
event.setCancelled(true);
return;
}
if (wcfg.useRegions) {
Vector pt = toVector(defender.getLocation());
RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld());
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
if (!set.allows(DefaultFlag.MOB_DAMAGE, localPlayer) && !(attacker instanceof Tameable)) {
event.setCancelled(true);
return;
}
if (attacker instanceof Creeper) {
if (!set.allows(DefaultFlag.CREEPER_EXPLOSION, localPlayer)) {
event.setCancelled(true);
return;
}
}
if (attacker instanceof Tameable) {
if (((Tameable) attacker).getOwner() == null) {
if (!set.allows(DefaultFlag.MOB_DAMAGE, localPlayer)) {
event.setCancelled(true);
return;
}
}
if (!(((Tameable) attacker).getOwner() instanceof Player)) {
return;
}
Player beastMaster = (Player) ((Tameable) attacker).getOwner();
Vector pt2 = toVector(attacker.getLocation());
if (!mgr.getApplicableRegions(pt2).allows(DefaultFlag.PVP, plugin.wrapPlayer(beastMaster))) {
tryCancelPVPEvent(beastMaster, player, event, true);
} else if (!set.allows(DefaultFlag.PVP, localPlayer)) {
tryCancelPVPEvent(beastMaster, player, event, false);
}
}
}
}
}
}
}
@@ -366,8 +406,9 @@ public class WorldGuardEntityListener implements Listener {
}
// Check Player
if (event.getDamager() instanceof EnderPearl) return;
// if (event.getDamager() instanceof EnderPearl || event.getDamager() instanceof Snowball) return;
if (attacker != null && attacker instanceof Player) {
if (event.getDamager() instanceof EnderPearl && attacker == player) return;
if (wcfg.useRegions) {
Vector pt = toVector(defender.getLocation());
Vector pt2 = toVector(attacker.getLocation());
@@ -415,6 +456,25 @@ public class WorldGuardEntityListener implements Listener {
return;
}
if (type == DamageCause.WITHER) {
// wither boss DoT tick
if (wcfg.disableMobDamage) {
event.setCancelled(true);
return;
}
if (wcfg.useRegions) {
Vector pt = toVector(defender.getLocation());
RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld());
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
if (!set.allows(DefaultFlag.MOB_DAMAGE, plugin.wrapPlayer(player))) {
event.setCancelled(true);
return;
}
}
}
if (type == DamageCause.DROWNING && cfg.hasAmphibiousMode(player)) {
player.setRemainingAir(player.getMaximumAir());
event.setCancelled(true);
@@ -491,35 +551,13 @@ public class WorldGuardEntityListener implements Listener {
Entity ent = event.getEntity();
if (cfg.activityHaltToggle) {
ent.remove();
if (ent != null) {
ent.remove();
}
event.setCancelled(true);
return;
}
if (ent.getType() == witherType) {
if (wcfg.blockWitherBlockDamage) {
event.blockList().clear();
return;
}
if (wcfg.blockWitherExplosions) {
event.setCancelled(true);
return;
}
}
if (ent.getType() == witherSkullType) {
if (wcfg.blockWitherSkullBlockDamage) {
event.blockList().clear();
return;
}
if (wcfg.blockWitherSkullExplosions) {
event.setCancelled(true);
return;
}
}
if (ent instanceof Creeper) {
if (wcfg.blockCreeperBlockDamage) {
event.blockList().clear();
@@ -538,6 +576,7 @@ public class WorldGuardEntityListener implements Listener {
for (Block block : event.blockList()) {
if (!mgr.getApplicableRegions(toVector(block)).allows(DefaultFlag.CREEPER_EXPLOSION)) {
event.blockList().clear();
event.setCancelled(true);
return;
}
}
@@ -546,6 +585,7 @@ public class WorldGuardEntityListener implements Listener {
} else if (ent instanceof EnderDragon) {
if (wcfg.blockEnderDragonBlockDamage) {
event.blockList().clear();
event.setCancelled(true);
return;
}
@@ -555,11 +595,12 @@ public class WorldGuardEntityListener implements Listener {
for (Block block : event.blockList()) {
if (!mgr.getApplicableRegions(toVector(block)).allows(DefaultFlag.ENDERDRAGON_BLOCK_DAMAGE)) {
event.blockList().clear();
event.setCancelled(true);
return;
}
}
}
} else if (ent instanceof TNTPrimed) {
} else if (ent instanceof TNTPrimed || ent instanceof MinecartTNT) {
if (wcfg.blockTNTBlockDamage) {
event.blockList().clear();
return;
@@ -576,26 +617,66 @@ public class WorldGuardEntityListener implements Listener {
for (Block block : event.blockList()) {
if (!mgr.getApplicableRegions(toVector(block)).allows(DefaultFlag.TNT)) {
event.blockList().clear();
event.setCancelled(true);
return;
}
}
}
} else if (ent instanceof Fireball) {
if (wcfg.blockFireballBlockDamage) {
event.blockList().clear();
return;
}
if (ent instanceof WitherSkull) {
if (wcfg.blockWitherSkullBlockDamage) {
event.blockList().clear();
return;
}
if (wcfg.blockFireballExplosions) {
event.setCancelled(true);
return;
}
if (wcfg.blockWitherSkullExplosions) {
event.setCancelled(true);
return;
}
} else {
if (wcfg.blockFireballBlockDamage) {
event.blockList().clear();
return;
}
if (wcfg.blockFireballExplosions) {
event.setCancelled(true);
return;
}
}
// allow wither skull blocking since there is no dedicated flag atm
if (wcfg.useRegions) {
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
for (Block block : event.blockList()) {
if (!mgr.getApplicableRegions(toVector(block)).allows(DefaultFlag.GHAST_FIREBALL)) {
event.blockList().clear();
event.setCancelled(true);
return;
}
}
}
} else if (ent instanceof Wither) {
if (wcfg.blockWitherBlockDamage) {
event.blockList().clear();
return;
}
if (wcfg.blockWitherExplosions) {
event.setCancelled(true);
return;
}
} else {
// unhandled entity
if (wcfg.blockOtherExplosions) {
event.blockList().clear();
event.setCancelled(true);
return;
}
if (wcfg.useRegions) {
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
for (Block block : event.blockList()) {
if (!mgr.getApplicableRegions(toVector(block)).allows(DefaultFlag.OTHER_EXPLOSION)) {
event.blockList().clear();
return;
}
@@ -603,6 +684,7 @@ public class WorldGuardEntityListener implements Listener {
}
}
if (wcfg.signChestProtection) {
for (Block block : event.blockList()) {
if (wcfg.isChestProtected(block)) {
@@ -628,32 +710,28 @@ public class WorldGuardEntityListener implements Listener {
event.setCancelled(true);
return;
}
if (event.getEntityType() == witherType) {
if (event.getEntityType() == EntityType.WITHER) {
if (wcfg.blockWitherExplosions) {
event.setCancelled(true);
return;
}
}
else if (event.getEntityType() == witherSkullType) {
} else if (event.getEntityType() == EntityType.WITHER_SKULL) {
if (wcfg.blockWitherSkullExplosions) {
event.setCancelled(true);
return;
}
}
else if (event.getEntityType() == fireballType) {
} else if (event.getEntityType() == EntityType.FIREBALL) {
if (wcfg.blockFireballExplosions) {
event.setCancelled(true);
return;
}
}
else if (event.getEntityType() == EntityType.CREEPER) {
} else if (event.getEntityType() == EntityType.CREEPER) {
if (wcfg.blockCreeperExplosions) {
event.setCancelled(true);
return;
}
}
else if (event.getEntityType() == EntityType.PRIMED_TNT) {
} else if (event.getEntityType() == EntityType.PRIMED_TNT) {
if (wcfg.blockTNTExplosions) {
event.setCancelled(true);
return;
@@ -703,6 +781,25 @@ public class WorldGuardEntityListener implements Listener {
return;
}
}
if (wcfg.blockGroundSlimes && entityType == EntityType.SLIME
&& eventLoc.getY() >= 60
&& event.getSpawnReason() == SpawnReason.NATURAL) {
event.setCancelled(true);
return;
}
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onCreatePortal(EntityCreatePortalEvent event) {
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(event.getEntity().getWorld());
switch (event.getEntityType()) {
case ENDER_DRAGON:
if (wcfg.blockEnderDragonPortalCreation) event.setCancelled(true);
break;
}
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
@@ -741,58 +838,40 @@ public class WorldGuardEntityListener implements Listener {
}
/**
* Called when an enderman picks up or puts down a block and some other cases.
* Called when an entity changes a block somehow
*
* @param event Relevant event details
*/
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onEndermanPickup(EntityChangeBlockEvent event) {
public void onEntityChangeBlock(EntityChangeBlockEvent event) {
Entity ent = event.getEntity();
Block block = event.getBlock();
Location location = block.getLocation();
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(ent.getWorld());
if (ent instanceof Enderman) {
if (event.getTo() == Material.AIR) {
// pickup
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(ent.getWorld());
if (wcfg.disableEndermanGriefing) {
event.setCancelled(true);
return;
}
if (wcfg.disableEndermanGriefing) {
if (wcfg.useRegions) {
if (!plugin.getGlobalRegionManager().allows(DefaultFlag.ENDER_BUILD, location)) {
event.setCancelled(true);
return;
}
if (wcfg.useRegions) {
if (!plugin.getGlobalRegionManager().allows(DefaultFlag.ENDER_BUILD, location)) {
event.setCancelled(true);
return;
}
}
} else {
// place
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(ent.getWorld());
if (wcfg.disableEndermanGriefing) {
event.setCancelled(true);
return;
}
if (wcfg.useRegions) {
if (!plugin.getGlobalRegionManager().allows(DefaultFlag.ENDER_BUILD, location)) {
event.setCancelled(true);
return;
}
}
}
} else if (ent.getType() == witherType) {
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(ent.getWorld());
} else if (ent.getType() == EntityType.WITHER) {
if (wcfg.blockWitherBlockDamage || wcfg.blockWitherExplosions) {
event.setCancelled(true);
return;
}
} else if (/*ent instanceof Zombie && */event instanceof EntityBreakDoorEvent) {
if (wcfg.blockZombieDoorDestruction) {
event.setCancelled(true);
return;
}
}
}
@@ -808,14 +887,39 @@ public class WorldGuardEntityListener implements Listener {
@EventHandler(ignoreCancelled = true)
public void onPotionSplash(PotionSplashEvent event) {
GlobalRegionManager global = plugin.getGlobalRegionManager();
Entity entity = event.getEntity();
ThrownPotion potion = event.getPotion();
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(entity.getWorld());
if (wcfg.blockPotionsAlways && wcfg.blockPotions.size() > 0) {
boolean blocked = false;
for (PotionEffect effect : potion.getEffects()) {
if (wcfg.blockPotions.contains(effect.getType())) {
blocked = true;
break;
}
}
if (blocked) {
event.setCancelled(true);
return;
}
}
GlobalRegionManager regionMan = plugin.getGlobalRegionManager();
int blockedEntities = 0;
for (LivingEntity e : event.getAffectedEntities()) {
if (!global.allows(DefaultFlag.POTION_SPLASH, e.getLocation(), e instanceof Player ? plugin.wrapPlayer((Player) e) : null)) {
if (!regionMan.allows(DefaultFlag.POTION_SPLASH, e.getLocation(),
e instanceof Player ? plugin.wrapPlayer((Player) e) : null)) {
event.setIntensity(e, 0);
++blockedEntities;
}
}
if (blockedEntities == event.getAffectedEntities().size()) {
event.setCancelled(true);
}
@@ -30,11 +30,13 @@ import org.bukkit.entity.Hanging;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Painting;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.event.hanging.HangingBreakEvent;
import org.bukkit.event.hanging.HangingBreakEvent.RemoveCause;
import org.bukkit.event.hanging.HangingPlaceEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
@@ -69,64 +71,77 @@ public class WorldGuardHangingListener implements Listener {
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onHangingingBreak(HangingBreakEvent breakEvent) {
if (!(breakEvent instanceof HangingBreakByEntityEvent)) {
return;
}
HangingBreakByEntityEvent event = (HangingBreakByEntityEvent) breakEvent;
public void onHangingingBreak(HangingBreakEvent event) {
Hanging hanging = event.getEntity();
World world = hanging.getWorld();
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(world);
if (event.getRemover() instanceof Player) {
Player player = (Player) event.getRemover();
if (wcfg.getBlacklist() != null) {
if (hanging instanceof Painting
&& !wcfg.getBlacklist().check(
new BlockBreakBlacklistEvent(plugin.wrapPlayer(player),
toVector(player.getLocation()), ItemID.PAINTING), false, false)) {
event.setCancelled(true);
return;
} else if (hanging instanceof ItemFrame
&& !wcfg.getBlacklist().check(
new BlockBreakBlacklistEvent(plugin.wrapPlayer(player),
toVector(player.getLocation()), ItemID.ITEM_FRAME), false, false)) {
event.setCancelled(true);
return;
}
if (event instanceof HangingBreakByEntityEvent) {
HangingBreakByEntityEvent entityEvent = (HangingBreakByEntityEvent) event;
Entity removerEntity = entityEvent.getRemover();
if (removerEntity instanceof Projectile) {
Projectile projectile = (Projectile) removerEntity;
removerEntity = projectile.getShooter() != null ? projectile.getShooter() : removerEntity;
}
if (wcfg.useRegions) {
if (!plugin.getGlobalRegionManager().canBuild(player, hanging.getLocation())) {
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
if (removerEntity instanceof Player) {
Player player = (Player) removerEntity;
if (wcfg.getBlacklist() != null) {
if (hanging instanceof Painting
&& !wcfg.getBlacklist().check(
new BlockBreakBlacklistEvent(plugin.wrapPlayer(player),
toVector(player.getLocation()), ItemID.PAINTING), false, false)) {
event.setCancelled(true);
return;
} else if (hanging instanceof ItemFrame
&& !wcfg.getBlacklist().check(
new BlockBreakBlacklistEvent(plugin.wrapPlayer(player),
toVector(player.getLocation()), ItemID.ITEM_FRAME), false, false)) {
event.setCancelled(true);
return;
}
}
if (wcfg.useRegions) {
if (!plugin.getGlobalRegionManager().canBuild(player, hanging.getLocation())) {
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
event.setCancelled(true);
return;
}
}
} else {
if (removerEntity instanceof Creeper) {
if (wcfg.blockCreeperBlockDamage || wcfg.blockCreeperExplosions) {
event.setCancelled(true);
return;
}
if (wcfg.useRegions && !plugin.getGlobalRegionManager().allows(DefaultFlag.CREEPER_EXPLOSION, hanging.getLocation())) {
event.setCancelled(true);
return;
}
}
if (hanging instanceof Painting
&& (wcfg.blockEntityPaintingDestroy
|| (wcfg.useRegions
&& !plugin.getGlobalRegionManager().allows(DefaultFlag.ENTITY_PAINTING_DESTROY, hanging.getLocation())))) {
event.setCancelled(true);
} else if (hanging instanceof ItemFrame
&& (wcfg.blockEntityItemFrameDestroy
|| (wcfg.useRegions
&& !plugin.getGlobalRegionManager().allows(DefaultFlag.ENTITY_ITEM_FRAME_DESTROY, hanging.getLocation())))) {
event.setCancelled(true);
return;
}
}
} else {
if (event.getRemover() instanceof Creeper) {
if (wcfg.blockCreeperBlockDamage || wcfg.blockCreeperExplosions) {
event.setCancelled(true);
return;
}
if (wcfg.useRegions && !plugin.getGlobalRegionManager().allows(DefaultFlag.CREEPER_EXPLOSION, hanging.getLocation())) {
event.setCancelled(true);
return;
}
}
if (hanging instanceof Painting
&& (wcfg.blockEntityPaintingDestroy
|| (wcfg.useRegions
&& !plugin.getGlobalRegionManager().allows(DefaultFlag.ENTITY_PAINTING_DESTROY, hanging.getLocation())))) {
// Explosions from mobs are not covered by HangingBreakByEntity
if (hanging instanceof Painting && wcfg.blockEntityPaintingDestroy
&& event.getCause() == RemoveCause.EXPLOSION) {
event.setCancelled(true);
} else if (hanging instanceof ItemFrame
&& (wcfg.blockEntityItemFrameDestroy
|| (wcfg.useRegions
&& !plugin.getGlobalRegionManager().allows(DefaultFlag.ENTITY_ITEM_FRAME_DESTROY, hanging.getLocation())))) {
} else if (hanging instanceof ItemFrame && wcfg.blockEntityItemFrameDestroy
&& event.getCause() == RemoveCause.EXPLOSION) {
event.setCancelled(true);
}
}
@@ -159,7 +174,7 @@ public class WorldGuardHangingListener implements Listener {
}
if (wcfg.useRegions) {
if (!plugin.getGlobalRegionManager().canBuild(player, placedOn.getLocation())) {
if (!plugin.getGlobalRegionManager().canBuild(player, placedOn.getRelative(event.getBlockFace()))) {
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
event.setCancelled(true);
return;
@@ -181,16 +196,16 @@ public class WorldGuardHangingListener implements Listener {
event.setCancelled(true);
return;
}
if (entity instanceof ItemFrame
&& ((!plugin.getGlobalRegionManager().allows(
DefaultFlag.ENTITY_ITEM_FRAME_DESTROY, entity.getLocation())))) {
event.setCancelled(true);
} else if (entity instanceof Painting
&& ((!plugin.getGlobalRegionManager().allows(
DefaultFlag.ENTITY_PAINTING_DESTROY, entity.getLocation())))) {
event.setCancelled(true);
}
// if (entity instanceof ItemFrame
// && ((!plugin.getGlobalRegionManager().allows(
// DefaultFlag.ENTITY_ITEM_FRAME_DESTROY, entity.getLocation())))) {
// event.setCancelled(true);
// } else if (entity instanceof Painting
// && ((!plugin.getGlobalRegionManager().allows(
// DefaultFlag.ENTITY_PAINTING_DESTROY, entity.getLocation())))) {
// event.setCancelled(true);
// }
}
}
}
@@ -22,13 +22,15 @@ import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
import java.util.Iterator;
import java.util.Set;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.blocks.ItemID;
import java.util.regex.Pattern;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
@@ -52,11 +54,17 @@ import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.PluginManager;
import org.bukkit.potion.Potion;
import org.bukkit.potion.PotionEffect;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.blocks.BlockType;
import com.sk89q.worldedit.blocks.ItemID;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.blacklist.events.BlockBreakBlacklistEvent;
import com.sk89q.worldguard.blacklist.events.BlockInteractBlacklistEvent;
@@ -75,6 +83,7 @@ import com.sk89q.worldguard.protection.regions.ProtectedRegion;
*/
public class WorldGuardPlayerListener implements Listener {
private Pattern opPattern = Pattern.compile("^/op(?:\\s.*)?$", Pattern.CASE_INSENSITIVE);
private WorldGuardPlugin plugin;
/**
@@ -107,7 +116,9 @@ public class WorldGuardPlayerListener implements Listener {
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(world);
if (player.getVehicle() != null) return; // handled in vehicle listener
if (player.getVehicle() != null) {
return; // handled in vehicle listener
}
if (wcfg.useRegions) {
// Did we move a block?
if (event.getFrom().getBlockX() != event.getTo().getBlockX()
@@ -128,9 +139,49 @@ public class WorldGuardPlayerListener implements Listener {
Vector pt = new Vector(event.getTo().getBlockX(), event.getTo().getBlockY(), event.getTo().getBlockZ());
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
/*
// check if region is full
// get the lowest number of allowed members in any region
boolean regionFull = false;
String maxPlayerMessage = null;
if (!hasBypass) {
for (ProtectedRegion region : set) {
if (region instanceof GlobalProtectedRegion) {
continue; // global region can't have a max
}
// get the max for just this region
Integer maxPlayers = region.getFlag(DefaultFlag.MAX_PLAYERS);
if (maxPlayers == null) {
continue;
}
int occupantCount = 0;
for(Player occupant : world.getPlayers()) {
// each player in this region counts as one toward the max of just this region
// A person with bypass doesn't count as an occupant of the region
if (!occupant.equals(player) && !plugin.getGlobalRegionManager().hasBypass(occupant, world)) {
if (region.contains(BukkitUtil.toVector(occupant.getLocation()))) {
if (++occupantCount >= maxPlayers) {
regionFull = true;
maxPlayerMessage = region.getFlag(DefaultFlag.MAX_PLAYERS_MESSAGE);
// At least one region in the set is full, we are going to use this message because it
// was the first one we detected as full. In reality we should check them all and then
// resolve the message from full regions, but that is probably a lot laggier (and this
// is already pretty laggy. In practice, we can't really control which one we get first
// right here.
break;
}
}
}
}
}
}
*/
boolean entryAllowed = set.allows(DefaultFlag.ENTRY, localPlayer);
if (!hasBypass && !entryAllowed) {
player.sendMessage(ChatColor.DARK_RED + "You are not permitted to enter this area.");
if (!hasBypass && (!entryAllowed /*|| regionFull*/)) {
String message = /*maxPlayerMessage != null ? maxPlayerMessage :*/ "You are not permitted to enter this area.";
player.sendMessage(ChatColor.DARK_RED + message);
Location newLoc = event.getFrom();
newLoc.setX(newLoc.getBlockX() + 0.5);
@@ -234,7 +285,7 @@ public class WorldGuardPlayerListener implements Listener {
}
}
}
}
}
@EventHandler
public void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
@@ -347,6 +398,10 @@ public class WorldGuardPlayerListener implements Listener {
return;
}
}
if (cfg.deopOnJoin) {
player.setOp(false);
}
}
@EventHandler
@@ -420,6 +475,40 @@ public class WorldGuardPlayerListener implements Listener {
player.sendMessage(ChatColor.RED + "Infinite stack removed.");
}
}
if (wcfg.blockPotions.size() > 0) {
ItemStack item = event.getItem();
if (item != null && item.getType() == Material.POTION && !BukkitUtil.isWaterPotion(item)) {
PotionEffect blockedEffect = null;
Potion potion = Potion.fromDamage(BukkitUtil.getPotionEffectBits(item));
for (PotionEffect effect : potion.getEffects()) {
if (wcfg.blockPotions.contains(effect.getType())) {
blockedEffect = effect;
break;
}
}
if (blockedEffect != null) {
if (plugin.hasPermission(player, "worldguard.override.potions")) {
if (potion.isSplash() && wcfg.blockPotionsAlways) {
player.sendMessage(ChatColor.RED + "Sorry, potions with " +
blockedEffect.getType().getName() + " can't be thrown, " +
"even if you have a permission to bypass it, " +
"due to limitations (and because overly-reliable potion blocking is on).");
event.setUseItemInHand(Result.DENY);
return;
}
} else {
player.sendMessage(ChatColor.RED + "Sorry, potions with "
+ blockedEffect.getType().getName() + " are presently disabled.");
event.setUseItemInHand(Result.DENY);
return;
}
}
}
}
}
/**
@@ -454,7 +543,7 @@ public class WorldGuardPlayerListener implements Listener {
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
LocalPlayer localPlayer = plugin.wrapPlayer(player);
if (type == BlockID.STONE_BUTTON
/*if (type == BlockID.STONE_BUTTON
|| type == BlockID.LEVER
|| type == BlockID.WOODEN_DOOR
|| type == BlockID.TRAP_DOOR
@@ -467,11 +556,22 @@ public class WorldGuardPlayerListener implements Listener {
event.setCancelled(true);
return;
}
}*/
if (type == BlockID.DRAGON_EGG) {
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
&& !set.canBuild(localPlayer)) {
player.sendMessage(ChatColor.DARK_RED + "You're not allowed to move dragon eggs here!");
event.setUseInteractedBlock(Result.DENY);
event.setCancelled(true);
return;
}
}
if (block.getRelative(event.getBlockFace()).getTypeId() == BlockID.FIRE) {
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
&& !set.canBuild(localPlayer)) {
&& !mgr.getApplicableRegions(block.getRelative(event.getBlockFace())
.getLocation()).canBuild(localPlayer)) {
event.setUseInteractedBlock(Result.DENY);
event.setCancelled(true);
return;
@@ -550,8 +650,7 @@ public class WorldGuardPlayerListener implements Listener {
|| type == BlockID.FURNACE
|| type == BlockID.BURNING_FURNACE
|| type == BlockID.BREWING_STAND
|| type == BlockID.ENCHANTMENT_TABLE
|| type == BlockID.CAULDRON)
|| type == BlockID.ENCHANTMENT_TABLE)
&& wcfg.removeInfiniteStacks
&& !plugin.hasPermission(player, "worldguard.override.infinite-stack")) {
for (int slot = 0; slot < 40; slot++) {
@@ -566,7 +665,9 @@ public class WorldGuardPlayerListener implements Listener {
if (wcfg.useRegions) {
Vector pt = toVector(block);
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
Block placedIn = block.getRelative(event.getBlockFace());
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
ApplicableRegionSet placedInSet = mgr.getApplicableRegions(placedIn.getLocation());
LocalPlayer localPlayer = plugin.wrapPlayer(player);
if (item.getTypeId() == wcfg.regionWand && plugin.hasPermission(player, "worldguard.region.wand")) {
@@ -592,23 +693,157 @@ public class WorldGuardPlayerListener implements Listener {
}
if (item.getTypeId() == BlockID.TNT) {
Block placedOn = block.getRelative(event.getBlockFace());
// workaround for a bug that allowed tnt to trigger instantly if placed
// next to redstone, without plugins getting the block place event
// (not sure if this actually still happens)
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
&& !plugin.getGlobalRegionManager().allows(
DefaultFlag.TNT, placedOn.getLocation(), localPlayer)) {
&& !placedInSet.allows(DefaultFlag.TNT, localPlayer)) {
event.setUseItemInHand(Result.DENY);
event.setCancelled(true);
}
}
if (item.getTypeId() == ItemID.INK_SACK
&& item.getData() != null
&& item.getData().getData() == 15 // bonemeal
&& type == BlockID.GRASS) {
// hacky workaround for craftbukkit bug
// has since been fixed, but leaving for legacy
if (item.getTypeId() == BlockID.STEP
|| item.getTypeId() == BlockID.WOODEN_STEP) {
if (!plugin.getGlobalRegionManager().hasBypass(localPlayer, world)) {
boolean cancel = false;
if ((block.getTypeId() == item.getTypeId())
&& !set.canBuild(localPlayer)) {
// if we are on a step already, the new block will end up in the same block as the interact
cancel = true;
} else if (!placedInSet.canBuild(localPlayer)) {
// if we are on another block, the half-slab in hand will be pushed to the adjacent block
cancel = true;
}
if (cancel) {
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
event.setCancelled(true);
return;
}
}
}
if (item.getTypeId() == ItemID.BED_ITEM) {
// this is mojang-level code, it had better give us the right direction
double yaw = (player.getLocation().getYaw() * 4.0F / 360.0F) + 0.5D;
int i = (int) yaw;
int i1 = (yaw < i ? i - 1 : i) & 3;
byte b0 = 0;
byte b1 = 0;
if (i1 == 0) {
b1 = 1;
}
if (i1 == 1) {
b0 = -1;
}
if (i1 == 2) {
b1 = -1;
}
if (i1 == 3) {
b0 = 1;
}
// end mojang-level code
Location headLoc = placedIn.getRelative(b0, 0, b1).getLocation();
if (!plugin.getGlobalRegionManager().hasBypass(localPlayer, world)
&& !mgr.getApplicableRegions(headLoc).canBuild(localPlayer)) {
// note that normal block placement is handled later, this is just a workaround
// for the location of the head block of the bed
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
event.setCancelled(true);
return;
}
}
if (block.getTypeId() == BlockID.PISTON_MOVING_PIECE) {
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
&& !set.canBuild(localPlayer)) {
event.setUseInteractedBlock(Result.DENY);
}
}
if (item.getTypeId() == ItemID.WOODEN_DOOR_ITEM || item.getTypeId() == ItemID.IRON_DOOR_ITEM) {
if (!plugin.getGlobalRegionManager().hasBypass(localPlayer, world)
&& !placedInSet.canBuild(localPlayer)) {
// note that normal block placement is handled later, this is just a workaround
// for the location of the top block of the door
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
event.setCancelled(true);
return;
}
}
if (item.getTypeId() == ItemID.FIRE_CHARGE || item.getTypeId() == ItemID.FLINT_AND_TINDER) {
if (!plugin.getGlobalRegionManager().hasBypass(localPlayer, world)
&& !placedInSet.canBuild(localPlayer)) {
event.setCancelled(true);
event.setUseItemInHand(Result.DENY);
player.sendMessage(ChatColor.DARK_RED + "You're not allowed to use that here.");
return;
}
}
if (item.getTypeId() == ItemID.EYE_OF_ENDER && block.getTypeId() == BlockID.END_PORTAL_FRAME) {
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
&& !set.canBuild(localPlayer)) {
event.setCancelled(true);
event.setUseItemInHand(Result.DENY);
player.sendMessage(ChatColor.DARK_RED + "You're not allowed to use that here.");
return;
}
}
if (item.getTypeId() == ItemID.INK_SACK
&& item.getData() != null) {
if (item.getData().getData() == 15 // bonemeal
&& (type == BlockID.GRASS
|| type == BlockID.SAPLING
|| type == BlockID.CROPS
|| type == BlockID.BROWN_MUSHROOM
|| type == BlockID.RED_MUSHROOM
|| type == BlockID.PUMPKIN_STEM
|| type == BlockID.MELON_STEM
|| type == BlockID.POTATOES
|| type == BlockID.CARROTS
|| type == BlockID.COCOA_PLANT)) {
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
&& !set.canBuild(localPlayer)) {
event.setCancelled(true);
event.setUseItemInHand(Result.DENY);
player.sendMessage(ChatColor.DARK_RED + "You're not allowed to use that here.");
return;
}
} else if (item.getData().getData() == 3) { // cocoa beans
// craftbukkit doesn't throw a block place for this, so workaround
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
&& !set.canBuild(localPlayer)) {
if (!(event.getBlockFace() == BlockFace.DOWN || event.getBlockFace() == BlockFace.UP)) {
event.setCancelled(true);
event.setUseItemInHand(Result.DENY);
player.sendMessage(ChatColor.DARK_RED + "You're not allowed to plant that here.");
return;
}
}
}
}
if (type == BlockID.FLOWER_POT) { // no api for this atm
if (item.getTypeId() == BlockID.RED_FLOWER
|| item.getTypeId() == BlockID.YELLOW_FLOWER
|| item.getTypeId() == BlockID.SAPLING
|| item.getTypeId() == BlockID.RED_MUSHROOM
|| item.getTypeId() == BlockID.BROWN_MUSHROOM
|| item.getTypeId() == BlockID.CACTUS
|| item.getTypeId() == BlockID.LONG_GRASS
|| item.getTypeId() == BlockID.DEAD_BUSH) {
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
&& !set.canBuild(localPlayer)) {
event.setUseItemInHand(Result.DENY);
event.setCancelled(true);
player.sendMessage(ChatColor.DARK_RED + "You're not allowed to plant that here.");
return;
}
}
}
@@ -627,7 +862,10 @@ public class WorldGuardPlayerListener implements Listener {
|| type == BlockID.DISPENSER
|| type == BlockID.FURNACE
|| type == BlockID.BURNING_FURNACE
|| type == BlockID.BREWING_STAND) {
|| type == BlockID.BREWING_STAND
|| type == BlockID.TRAPPED_CHEST
|| type == BlockID.HOPPER
|| type == BlockID.DROPPER) {
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
&& !set.canBuild(localPlayer)
&& !set.allows(DefaultFlag.CHEST_ACCESS, localPlayer)) {
@@ -638,8 +876,19 @@ public class WorldGuardPlayerListener implements Listener {
}
}
if (type == BlockID.DRAGON_EGG) {
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
&& !set.canBuild(localPlayer)) {
player.sendMessage(ChatColor.DARK_RED + "You're not allowed to move dragon eggs here!");
event.setUseInteractedBlock(Result.DENY);
event.setCancelled(true);
return;
}
}
if (type == BlockID.LEVER
|| type == BlockID.STONE_BUTTON
|| type == BlockID.WOODEN_BUTTON
|| type == BlockID.NOTE_BLOCK
|| type == BlockID.REDSTONE_REPEATER_OFF
|| type == BlockID.REDSTONE_REPEATER_ON
@@ -654,7 +903,11 @@ public class WorldGuardPlayerListener implements Listener {
|| type == BlockID.BREWING_STAND
|| type == BlockID.ENCHANTMENT_TABLE
|| type == BlockID.CAULDRON
|| type == BlockID.DRAGON_EGG) {
|| type == BlockID.ENDER_CHEST // blah
|| type == BlockID.BEACON
|| type == BlockID.ANVIL
|| type == BlockID.HOPPER
|| type == BlockID.DROPPER) {
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
&& !set.canBuild(localPlayer)
&& !set.allows(DefaultFlag.USE, localPlayer)) {
@@ -665,6 +918,20 @@ public class WorldGuardPlayerListener implements Listener {
}
}
if (type == BlockID.REDSTONE_REPEATER_OFF
|| type == BlockID.REDSTONE_REPEATER_ON
|| type == BlockID.COMPARATOR_OFF
|| type == BlockID.COMPARATOR_ON) {
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
&& !set.canBuild(localPlayer)) {
// using build and not use because it can potentially damage a circuit and use is more general-purposed
player.sendMessage(ChatColor.DARK_RED + "You don't have permission to use that in this area.");
event.setUseInteractedBlock(Result.DENY);
event.setCancelled(true);
return;
}
}
if (type == BlockID.CAKE_BLOCK) {
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
&& !set.canBuild(localPlayer)
@@ -676,10 +943,15 @@ public class WorldGuardPlayerListener implements Listener {
}
}
if (BlockType.isRailBlock(type) && item.getTypeId() == ItemID.MINECART) {
if (BlockType.isRailBlock(type)
&& (item.getTypeId() == ItemID.MINECART
|| item.getTypeId() == ItemID.POWERED_MINECART
|| item.getTypeId() == ItemID.STORAGE_MINECART
|| item.getTypeId() == ItemID.TNT_MINECART
|| item.getTypeId() == ItemID.HOPPER_MINECART)) {
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
&& !set.canBuild(localPlayer)
&& !set.allows(DefaultFlag.PLACE_VEHICLE, localPlayer)) {
&& !placedInSet.canBuild(localPlayer)
&& !placedInSet.allows(DefaultFlag.PLACE_VEHICLE, localPlayer)) {
player.sendMessage(ChatColor.DARK_RED + "You don't have permission to place vehicles here.");
event.setUseItemInHand(Result.DENY);
event.setCancelled(true);
@@ -689,8 +961,8 @@ public class WorldGuardPlayerListener implements Listener {
if (item.getTypeId() == ItemID.WOOD_BOAT) {
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
&& !set.canBuild(localPlayer)
&& !set.allows(DefaultFlag.PLACE_VEHICLE, localPlayer)) {
&& !placedInSet.canBuild(localPlayer)
&& !placedInSet.allows(DefaultFlag.PLACE_VEHICLE, localPlayer)) {
player.sendMessage(ChatColor.DARK_RED + "You don't have permission to place vehicles here.");
event.setUseItemInHand(Result.DENY);
event.setCancelled(true);
@@ -700,13 +972,18 @@ public class WorldGuardPlayerListener implements Listener {
}
if (wcfg.getBlacklist() != null) {
if(type != BlockID.CHEST
if (player.isSneaking() // sneak + right clicking no longer opens guis as of some recent version
|| (type != BlockID.CHEST
&& type != BlockID.DISPENSER
&& type != BlockID.FURNACE
&& type != BlockID.BURNING_FURNACE
&& type != BlockID.BREWING_STAND
&& type != BlockID.ENCHANTMENT_TABLE
&& type != BlockID.CAULDRON) {
&& type != BlockID.ANVIL
&& type != BlockID.ENDER_CHEST
&& type != BlockID.TRAPPED_CHEST
&& type != BlockID.HOPPER
&& type != BlockID.DROPPER)) {
if (!wcfg.getBlacklist().check(
new ItemUseBlacklistEvent(plugin.wrapPlayer(player), toVector(block),
item.getTypeId()), false, false)) {
@@ -742,7 +1019,10 @@ public class WorldGuardPlayerListener implements Listener {
|| type == BlockID.FURNACE
|| type == BlockID.BURNING_FURNACE
|| type == BlockID.ENCHANTMENT_TABLE
|| type == BlockID.BREWING_STAND)) {
|| type == BlockID.BREWING_STAND
|| type == BlockID.TRAPPED_CHEST
|| type == BlockID.HOPPER
|| type == BlockID.DROPPER)) {
if (wcfg.isChestProtected(block, player)) {
player.sendMessage(ChatColor.DARK_RED + "The chest is protected.");
@@ -829,7 +1109,9 @@ public class WorldGuardPlayerListener implements Listener {
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
LocalPlayer localPlayer = plugin.wrapPlayer(player);
if (type == BlockID.STONE_PRESSURE_PLATE || type == BlockID.WOODEN_PRESSURE_PLATE) {
if (type == BlockID.STONE_PRESSURE_PLATE || type == BlockID.WOODEN_PRESSURE_PLATE
|| type == BlockID.TRIPWIRE || type == BlockID.PRESSURE_PLATE_LIGHT
|| type == BlockID.PRESSURE_PLATE_HEAVY) {
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
&& !set.canBuild(localPlayer)
&& !set.allows(DefaultFlag.USE, localPlayer)) {
@@ -1063,6 +1345,39 @@ public class WorldGuardPlayerListener implements Listener {
}
}
@EventHandler(priority= EventPriority.LOW, ignoreCancelled = true)
public void onPlayerTeleport(PlayerTeleportEvent event) {
World world = event.getFrom().getWorld();
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(world);
if (wcfg.useRegions) {
if (event.getCause() == TeleportCause.ENDER_PEARL) {
RegionManager mgr = plugin.getGlobalRegionManager().get(event.getFrom().getWorld());
Vector pt = new Vector(event.getTo().getBlockX(), event.getTo().getBlockY(), event.getTo().getBlockZ());
Vector ptFrom = new Vector(event.getFrom().getBlockX(), event.getFrom().getBlockY(), event.getFrom().getBlockZ());
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
ApplicableRegionSet setFrom = mgr.getApplicableRegions(ptFrom);
LocalPlayer localPlayer = plugin.wrapPlayer(event.getPlayer());
if (!plugin.getGlobalRegionManager().hasBypass(localPlayer, world)
&& !(set.allows(DefaultFlag.ENTRY, localPlayer)
&& setFrom.allows(DefaultFlag.EXIT, localPlayer))) {
event.getPlayer().sendMessage(ChatColor.DARK_RED + "You're not allowed to go there.");
event.setCancelled(true);
return;
}
if (!plugin.getGlobalRegionManager().hasBypass(localPlayer, world)
&& !(set.allows(DefaultFlag.ENDERPEARL, localPlayer)
&& setFrom.allows(DefaultFlag.ENDERPEARL, localPlayer))) {
event.getPlayer().sendMessage(ChatColor.DARK_RED + "You're not allowed to go there.");
event.setCancelled(true);
return;
}
}
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
Player player = event.getPlayer();
@@ -1076,22 +1391,40 @@ public class WorldGuardPlayerListener implements Listener {
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
String[] parts = event.getMessage().split(" ");
String lowerCommand = parts[0].toLowerCase();
String lowerCommand = event.getMessage().toLowerCase();
Set<String> allowedCommands = set.getFlag(DefaultFlag.ALLOWED_CMDS, localPlayer);
Set<String> blockedCommands = set.getFlag(DefaultFlag.BLOCKED_CMDS, localPlayer);
if (allowedCommands != null && !allowedCommands.contains(lowerCommand)
&& (blockedCommands == null || blockedCommands.contains(lowerCommand))) {
player.sendMessage(ChatColor.RED + lowerCommand + " is not allowed in this area.");
String blockedCommand = "";
if (blockedCommands != null){
for (String aCommand : blockedCommands) {
if (lowerCommand.startsWith(aCommand)) {
blockedCommand = aCommand;
break;
}
}
}
if (allowedCommands != null) {
if (blockedCommand.isEmpty()) blockedCommand = lowerCommand.split(" ")[0];
for (String aCommand : allowedCommands) {
if (lowerCommand.startsWith(aCommand)) {
blockedCommand = "";
break;
}
}
}
if (!blockedCommand.isEmpty()) {
player.sendMessage(ChatColor.RED + blockedCommand + " is not allowed in this area.");
event.setCancelled(true);
return;
}
}
if (blockedCommands != null && blockedCommands.contains(lowerCommand)
&& (allowedCommands == null || !allowedCommands.contains(lowerCommand))) {
player.sendMessage(ChatColor.RED + lowerCommand + " is blocked in this area.");
if (cfg.blockInGameOp) {
if (opPattern.matcher(event.getMessage()).matches()) {
player.sendMessage(ChatColor.RED + "/op can only be used in console (as set by a WG setting).");
event.setCancelled(true);
return;
}
@@ -34,9 +34,6 @@ import java.util.Set;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;
import com.sk89q.bukkit.util.CommandsManagerRegistration;
import com.sk89q.minecraft.util.commands.*;
import com.sk89q.wepif.PermissionsResolverManager;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
@@ -50,6 +47,15 @@ import org.bukkit.permissions.Permissible;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import com.sk89q.bukkit.util.CommandsManagerRegistration;
import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.minecraft.util.commands.CommandPermissionsException;
import com.sk89q.minecraft.util.commands.CommandUsageException;
import com.sk89q.minecraft.util.commands.CommandsManager;
import com.sk89q.minecraft.util.commands.MissingNestedCommandException;
import com.sk89q.minecraft.util.commands.SimpleInjector;
import com.sk89q.minecraft.util.commands.WrappedCommandException;
import com.sk89q.wepif.PermissionsResolverManager;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.bukkit.commands.GeneralCommands;
@@ -108,6 +114,7 @@ public class WorldGuardPlugin extends JavaPlugin {
/**
* Called on plugin enable.
*/
@Override
@SuppressWarnings("deprecation")
public void onEnable() {
@@ -137,12 +144,12 @@ public class WorldGuardPlugin extends JavaPlugin {
LegacyWorldGuardMigration.migrateBlacklist(this);
try {
// Load the configuration
configuration.load();
globalRegionManager.preload();
// Load the configuration
configuration.load();
globalRegionManager.preload();
} catch (FatalConfigurationLoadingException e) {
e.printStackTrace();
getServer().shutdown();
e.printStackTrace();
getServer().shutdown();
}
// Migrate regions after the regions were loaded because
@@ -152,7 +159,8 @@ public class WorldGuardPlugin extends JavaPlugin {
flagStateManager = new FlagStateManager(this);
if (configuration.useRegionsScheduler) {
getServer().getScheduler().scheduleAsyncRepeatingTask(this, flagStateManager, FlagStateManager.RUN_DELAY, FlagStateManager.RUN_DELAY);
getServer().getScheduler().scheduleSyncRepeatingTask(this, flagStateManager,
FlagStateManager.RUN_DELAY, FlagStateManager.RUN_DELAY);
}
// Register events
@@ -194,6 +202,7 @@ public class WorldGuardPlugin extends JavaPlugin {
/**
* Called on plugin disable.
*/
@Override
public void onDisable() {
globalRegionManager.unload();
configuration.unload();
@@ -275,7 +275,9 @@ public class GeneralCommands {
if (item2.getTypeId() == item.getTypeId() &&
((!ItemType.usesDamageValue(item.getTypeId()) && ignoreDamaged)
|| item.getDurability() == item2.getDurability()) &&
item.getEnchantments().equals(item2.getEnchantments())) {
((item.getItemMeta() == null && item2.getItemMeta() == null)
|| (item.getItemMeta() != null &&
item.getItemMeta().equals(item2.getItemMeta())))) {
// This stack won't fit in the parent stack
if (item2.getAmount() > needed) {
item.setAmount(max);
@@ -19,7 +19,23 @@
package com.sk89q.worldguard.bukkit.commands;
import com.sk89q.minecraft.util.commands.*;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
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.minecraft.util.commands.CommandPermissions;
import com.sk89q.minecraft.util.commands.CommandPermissionsException;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.Location;
import com.sk89q.worldedit.Vector;
@@ -38,60 +54,57 @@ import com.sk89q.worldguard.protection.databases.RegionDBUtil;
import com.sk89q.worldguard.protection.databases.migrators.AbstractDatabaseMigrator;
import com.sk89q.worldguard.protection.databases.migrators.MigrationException;
import com.sk89q.worldguard.protection.databases.migrators.MigratorKey;
import com.sk89q.worldguard.protection.flags.*;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.InvalidFlagFormat;
import com.sk89q.worldguard.protection.flags.RegionGroup;
import com.sk89q.worldguard.protection.flags.RegionGroupFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.GlobalProtectedRegion;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion.CircularInheritanceException;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
public class RegionCommands {
private final WorldGuardPlugin plugin;
private MigratorKey migrateDBRequest;
private Date migrateDBRequestDate;
public RegionCommands(WorldGuardPlugin plugin) {
this.plugin = plugin;
}
@Command(aliases = {"define", "def", "d"}, usage = "<id> [<owner1> [<owner2> [<owners...>]]]",
desc = "Defines a region", min = 1)
@CommandPermissions({"worldguard.region.define"})
public void define(CommandContext args, CommandSender sender) throws CommandException {
Player player = plugin.checkPlayer(sender);
WorldEditPlugin worldEdit = plugin.getWorldEdit();
String id = args.getString(0);
if (!ProtectedRegion.isValidId(id)) {
throw new CommandException("Invalid region ID specified!");
}
if (id.equalsIgnoreCase("__global__")) {
throw new CommandException("A region cannot be named __global__");
}
// Attempt to get the player's selection from WorldEdit
Selection sel = worldEdit.getSelection(player);
if (sel == null) {
throw new CommandException("Select a region with WorldEdit first.");
}
RegionManager mgr = plugin.getGlobalRegionManager().get(sel.getWorld());
if (mgr.hasRegion(id)) {
throw new CommandException("That region is already defined. Use redefine instead.");
}
ProtectedRegion region;
// Detect the type of region from WorldEdit
@@ -113,9 +126,9 @@ public class RegionCommands {
if (args.argsLength() > 1) {
region.setOwners(RegionDBUtil.parseDomainString(args.getSlice(1), 1));
}
mgr.addRegion(region);
try {
mgr.save();
sender.sendMessage(ChatColor.YELLOW + "Region saved as " + id + ".");
@@ -124,17 +137,17 @@ public class RegionCommands {
+ e.getMessage());
}
}
@Command(aliases = {"redefine", "update", "move"}, usage = "<id>",
desc = "Re-defines the shape of a region", min = 1, max = 1)
public void redefine(CommandContext args, CommandSender sender) throws CommandException {
Player player = plugin.checkPlayer(sender);
World world = player.getWorld();
WorldEditPlugin worldEdit = plugin.getWorldEdit();
LocalPlayer localPlayer = plugin.wrapPlayer(player);
String id = args.getString(0);
if (id.equalsIgnoreCase("__global__")) {
throw new CommandException("The region cannot be named __global__");
}
@@ -153,16 +166,16 @@ public class RegionCommands {
} else {
plugin.checkPermission(sender, "worldguard.region.redefine");
}
// Attempt to get the player's selection from WorldEdit
Selection sel = worldEdit.getSelection(player);
if (sel == null) {
throw new CommandException("Select a region with WorldEdit first.");
}
ProtectedRegion region;
// Detect the type of region from WorldEdit
if (sel instanceof Polygonal2DSelection) {
Polygonal2DSelection polySel = (Polygonal2DSelection) sel;
@@ -186,11 +199,11 @@ public class RegionCommands {
region.setParent(existing.getParent());
} catch (CircularInheritanceException ignore) {
}
mgr.addRegion(region);
sender.sendMessage(ChatColor.YELLOW + "Region updated with new area.");
try {
mgr.save();
} catch (ProtectionDatabaseException e) {
@@ -198,38 +211,38 @@ public class RegionCommands {
+ e.getMessage());
}
}
@Command(aliases = {"claim"}, usage = "<id> [<owner1> [<owner2> [<owners...>]]]",
desc = "Claim a region", min = 1)
@CommandPermissions({"worldguard.region.claim"})
public void claim(CommandContext args, CommandSender sender) throws CommandException {
Player player = plugin.checkPlayer(sender);
LocalPlayer localPlayer = plugin.wrapPlayer(player);
WorldEditPlugin worldEdit = plugin.getWorldEdit();
String id = args.getString(0);
if (!ProtectedRegion.isValidId(id)) {
throw new CommandException("Invalid region ID specified!");
}
if (id.equalsIgnoreCase("__global__")) {
throw new CommandException("A region cannot be named __global__");
}
// Attempt to get the player's selection from WorldEdit
Selection sel = worldEdit.getSelection(player);
if (sel == null) {
throw new CommandException("Select a region with WorldEdit first.");
}
RegionManager mgr = plugin.getGlobalRegionManager().get(sel.getWorld());
if (mgr.hasRegion(id)) {
throw new CommandException("That region already exists. Please choose a different name.");
}
ProtectedRegion region;
// Detect the type of region from WorldEdit
@@ -253,7 +266,7 @@ public class RegionCommands {
}
WorldConfiguration wcfg = plugin.getGlobalStateManager().get(player.getWorld());
if (!plugin.hasPermission(sender, "worldguard.region.unlimited")) {
// Check whether the player has created too many regions
int maxRegionCount = wcfg.getMaxRegionCount(player);
@@ -271,9 +284,9 @@ public class RegionCommands {
throw new CommandException("This region already exists and you don't own it.");
}
}
ApplicableRegionSet regions = mgr.getApplicableRegions(region);
// Check if this region overlaps any other region
if (regions.size() > 0) {
if (!regions.isOwnerOfAll(localPlayer)) {
@@ -320,7 +333,7 @@ public class RegionCommands {
region.getOwners().addPlayer(player.getName());
mgr.addRegion(region);
try {
mgr.save();
sender.sendMessage(ChatColor.YELLOW + "Region saved as " + id + ".");
@@ -389,7 +402,7 @@ public class RegionCommands {
world, poly2d.getPoints(),
poly2d.getMinimumPoint().getBlockY(),
poly2d.getMaximumPoint().getBlockY()
);
);
worldEdit.setSelection(player, selection);
player.sendMessage(ChatColor.YELLOW + "Region selected as a polygon.");
} else if (region instanceof GlobalProtectedRegion) {
@@ -524,7 +537,7 @@ public class RegionCommands {
sender.sendMessage(ChatColor.LIGHT_PURPLE + "Bounds:"
+ " (" + min.getBlockX() + "," + min.getBlockY() + "," + min.getBlockZ() + ")"
+ " (" + max.getBlockX() + "," + max.getBlockY() + "," + max.getBlockZ() + ")"
);
);
}
public class RegionEntry implements Comparable<RegionEntry>{
@@ -649,14 +662,21 @@ public class RegionCommands {
}
}
@Command(aliases = {"flag", "f"}, usage = "<id> <flag> [-g group] [value]", flags = "g:",
@Command(aliases = {"flag", "f"}, usage = "<id> <flag> [-g group] [value]", flags = "g:w:",
desc = "Set flags", min = 2)
public void flag(CommandContext args, CommandSender sender) throws CommandException {
Player player = plugin.checkPlayer(sender);
World world = player.getWorld();
LocalPlayer localPlayer = plugin.wrapPlayer(player);
final World world;
Player player;
LocalPlayer localPlayer = null;
if (args.hasFlag('w')) {
world = plugin.matchWorld(sender, args.getFlag('w'));
} else {
player = plugin.checkPlayer(sender);
localPlayer = plugin.wrapPlayer(player);
world = player.getWorld();
}
String id = args.getString(0);
String flagName = args.getString(1);
String value = null;
@@ -680,20 +700,24 @@ public class RegionCommands {
// @TODO deprecate "flag.[own./member./blank]"
boolean hasPerm = false;
if (region.isOwner(localPlayer)) {
if (plugin.hasPermission(sender, "worldguard.region.flag.own." + id.toLowerCase())) hasPerm = true;
else if (plugin.hasPermission(sender, "worldguard.region.flag.regions.own." + id.toLowerCase())) hasPerm = true;
} else if (region.isMember(localPlayer)) {
if (plugin.hasPermission(sender, "worldguard.region.flag.member." + id.toLowerCase())) hasPerm = true;
else if (plugin.hasPermission(sender, "worldguard.region.flag.regions.member." + id.toLowerCase())) hasPerm = true;
if (localPlayer == null) {
hasPerm = true;
} else {
if (plugin.hasPermission(sender, "worldguard.region.flag." + id.toLowerCase())) hasPerm = true;
else if (plugin.hasPermission(sender, "worldguard.region.flag.regions." + id.toLowerCase())) hasPerm = true;
if (region.isOwner(localPlayer)) {
if (plugin.hasPermission(sender, "worldguard.region.flag.own." + id.toLowerCase())) hasPerm = true;
else if (plugin.hasPermission(sender, "worldguard.region.flag.regions.own." + id.toLowerCase())) hasPerm = true;
} else if (region.isMember(localPlayer)) {
if (plugin.hasPermission(sender, "worldguard.region.flag.member." + id.toLowerCase())) hasPerm = true;
else if (plugin.hasPermission(sender, "worldguard.region.flag.regions.member." + id.toLowerCase())) hasPerm = true;
} else {
if (plugin.hasPermission(sender, "worldguard.region.flag." + id.toLowerCase())) hasPerm = true;
else if (plugin.hasPermission(sender, "worldguard.region.flag.regions." + id.toLowerCase())) hasPerm = true;
}
}
if (!hasPerm) throw new CommandPermissionsException();
Flag<?> foundFlag = null;
// Now time to find the flag!
for (Flag<?> flag : DefaultFlag.getFlags()) {
// Try to detect the flag
@@ -702,53 +726,57 @@ public class RegionCommands {
break;
}
}
if (foundFlag == null) {
StringBuilder list = new StringBuilder();
// Need to build a list
for (Flag<?> flag : DefaultFlag.getFlags()) {
// @TODO deprecate inconsistant "owner" permission
if (localPlayer != null) {
if (region.isOwner(localPlayer)) {
if (!plugin.hasPermission(sender, "worldguard.region.flag.flags."
+ flag.getName() + ".owner." + id.toLowerCase())
&& !plugin.hasPermission(sender, "worldguard.region.flag.flags."
+ flag.getName() + ".own." + id.toLowerCase())) {
continue;
}
} else if (region.isMember(localPlayer)) {
if (!plugin.hasPermission(sender, "worldguard.region.flag.flags."
+ flag.getName() + ".member." + id.toLowerCase())) {
continue;
}
} else {
if (!plugin.hasPermission(sender, "worldguard.region.flag.flags."
+ flag.getName() + "." + id.toLowerCase())) {
continue;
}
}
}
if (list.length() > 0) {
list.append(", ");
}
// @TODO deprecate inconsistant "owner" permission
if (region.isOwner(localPlayer)) {
if (!plugin.hasPermission(sender, "worldguard.region.flag.flags."
+ flag.getName() + ".owner." + id.toLowerCase())
&& !plugin.hasPermission(sender, "worldguard.region.flag.flags."
+ flag.getName() + ".own." + id.toLowerCase())) {
continue;
}
} else if (region.isMember(localPlayer)) {
if (!plugin.hasPermission(sender, "worldguard.region.flag.flags."
+ flag.getName() + ".member." + id.toLowerCase())) {
continue;
}
} else {
if (!plugin.hasPermission(sender, "worldguard.region.flag.flags."
+ flag.getName() + "." + id.toLowerCase())) {
continue;
}
}
list.append(flag.getName());
}
player.sendMessage(ChatColor.RED + "Unknown flag specified: " + flagName);
player.sendMessage(ChatColor.RED + "Available flags: " + list);
sender.sendMessage(ChatColor.RED + "Unknown flag specified: " + flagName);
sender.sendMessage(ChatColor.RED + "Available flags: " + list);
return;
}
if (region.isOwner(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.flag.flags."
+ foundFlag.getName() + ".owner." + id.toLowerCase());
} else if (region.isMember(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.flag.flags."
+ foundFlag.getName() + ".member." + id.toLowerCase());
} else {
plugin.checkPermission(sender, "worldguard.region.flag.flags."
+ foundFlag.getName() + "." + id.toLowerCase());
if (localPlayer != null) {
if (region.isOwner(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.flag.flags."
+ foundFlag.getName() + ".owner." + id.toLowerCase());
} else if (region.isMember(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.flag.flags."
+ foundFlag.getName() + ".member." + id.toLowerCase());
} else {
plugin.checkPermission(sender, "worldguard.region.flag.flags."
+ foundFlag.getName() + "." + id.toLowerCase());
}
}
if (args.hasFlag('g')) {
@@ -817,27 +845,37 @@ public class RegionCommands {
+ e.getMessage());
}
}
public <V> void setFlag(ProtectedRegion region,
Flag<V> flag, CommandSender sender, String value)
throws InvalidFlagFormat {
throws InvalidFlagFormat {
region.setFlag(flag, flag.parseInput(plugin, sender, value));
}
@Command(aliases = {"setpriority", "priority", "pri"}, usage = "<id> <priority>",
desc = "Set the priority of a region", min = 2, max = 2)
@Command(aliases = {"setpriority", "priority", "pri"},
usage = "<id> <priority>",
flags = "w:",
desc = "Set the priority of a region",
min = 2, max = 2)
public void setPriority(CommandContext args, CommandSender sender) throws CommandException {
Player player = plugin.checkPlayer(sender);
World world = player.getWorld();
LocalPlayer localPlayer = plugin.wrapPlayer(player);
final World world;
Player player;
LocalPlayer localPlayer = null;
if (args.hasFlag('w')) {
world = plugin.matchWorld(sender, args.getFlag('w'));
} else {
player = plugin.checkPlayer(sender);
localPlayer = plugin.wrapPlayer(player);
world = player.getWorld();
}
String id = args.getString(0);
int priority = args.getInteger(1);
if (id.equalsIgnoreCase("__global__")) {
throw new CommandException("The region cannot be named __global__");
}
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
ProtectedRegion region = mgr.getRegion(id);
if (region == null) {
@@ -846,20 +884,22 @@ public class RegionCommands {
id = region.getId();
if (region.isOwner(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.setpriority.own." + id.toLowerCase());
} else if (region.isMember(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.setpriority.member." + id.toLowerCase());
} else {
plugin.checkPermission(sender, "worldguard.region.setpriority." + id.toLowerCase());
}
if (localPlayer != null) {
if (region.isOwner(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.setpriority.own." + id.toLowerCase());
} else if (region.isMember(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.setpriority.member." + id.toLowerCase());
} else {
plugin.checkPermission(sender, "worldguard.region.setpriority." + id.toLowerCase());
}
}
region.setPriority(priority);
sender.sendMessage(ChatColor.YELLOW
+ "Priority of '" + region.getId() + "' set to "
+ priority + ".");
try {
mgr.save();
} catch (ProtectionDatabaseException e) {
@@ -867,20 +907,30 @@ public class RegionCommands {
+ e.getMessage());
}
}
@Command(aliases = {"setparent", "parent", "par"}, usage = "<id> [parent-id]",
desc = "Set the parent of a region", min = 1, max = 2)
@Command(aliases = {"setparent", "parent", "par"},
usage = "<id> [parent-id]",
flags = "w:",
desc = "Set the parent of a region",
min = 1, max = 2)
public void setParent(CommandContext args, CommandSender sender) throws CommandException {
Player player = plugin.checkPlayer(sender);
World world = player.getWorld();
LocalPlayer localPlayer = plugin.wrapPlayer(player);
final World world;
Player player;
LocalPlayer localPlayer = null;
if (args.hasFlag('w')) {
world = plugin.matchWorld(sender, args.getFlag('w'));
} else {
player = plugin.checkPlayer(sender);
localPlayer = plugin.wrapPlayer(player);
world = player.getWorld();
}
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);
if (region == null) {
@@ -894,44 +944,45 @@ public class RegionCommands {
region.setParent(null);
} catch (CircularInheritanceException ignore) {
}
sender.sendMessage(ChatColor.YELLOW
+ "Parent of '" + region.getId() + "' cleared.");
} else {
String parentId = args.getString(1);
ProtectedRegion parent = mgr.getRegion(parentId);
if (parent == null) {
throw new CommandException("Could not find the parent region by that ID.");
}
if (region.isOwner(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.setparent.own." + id.toLowerCase());
} else if (region.isMember(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.setparent.member." + id.toLowerCase());
} else {
plugin.checkPermission(sender, "worldguard.region.setparent." + id.toLowerCase());
}
if (parent.isOwner(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.setparent.own." + parentId.toLowerCase());
} else if (parent.isMember(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.setparent.member." + parentId.toLowerCase());
} else {
plugin.checkPermission(sender, "worldguard.region.setparent." + parentId.toLowerCase());
if (localPlayer != null) {
if (region.isOwner(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.setparent.own." + id.toLowerCase());
} else if (region.isMember(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.setparent.member." + id.toLowerCase());
} else {
plugin.checkPermission(sender, "worldguard.region.setparent." + id.toLowerCase());
}
if (parent.isOwner(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.setparent.own." + parentId.toLowerCase());
} else if (parent.isMember(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.setparent.member." + parentId.toLowerCase());
} else {
plugin.checkPermission(sender, "worldguard.region.setparent." + parentId.toLowerCase());
}
}
try {
region.setParent(parent);
} catch (CircularInheritanceException e) {
throw new CommandException("Circular inheritance detected!");
}
sender.sendMessage(ChatColor.YELLOW
+ "Parent of '" + region.getId() + "' set to '"
+ parent.getId() + "'.");
}
try {
mgr.save();
} catch (ProtectionDatabaseException e) {
@@ -939,15 +990,24 @@ public class RegionCommands {
+ e.getMessage());
}
}
@Command(aliases = {"remove", "delete", "del", "rem"}, usage = "<id>",
desc = "Remove a region", min = 1, max = 1)
@Command(aliases = {"remove", "delete", "del", "rem"},
usage = "<id>",
flags = "w:",
desc = "Remove a region",
min = 1, max = 1)
public void remove(CommandContext args, CommandSender sender) throws CommandException {
Player player = plugin.checkPlayer(sender);
World world = player.getWorld();
LocalPlayer localPlayer = plugin.wrapPlayer(player);
final World world;
Player player;
LocalPlayer localPlayer = null;
if (args.hasFlag('w')) {
world = plugin.matchWorld(sender, args.getFlag('w'));
} else {
player = plugin.checkPlayer(sender);
localPlayer = plugin.wrapPlayer(player);
world = player.getWorld();
}
String id = args.getString(0);
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
@@ -956,20 +1016,22 @@ public class RegionCommands {
if (region == null) {
throw new CommandException("Could not find a region by that ID.");
}
if (region.isOwner(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.remove.own." + id.toLowerCase());
} else if (region.isMember(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.remove.member." + id.toLowerCase());
} else {
plugin.checkPermission(sender, "worldguard.region.remove." + id.toLowerCase());
if (localPlayer != null) {
if (region.isOwner(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.remove.own." + id.toLowerCase());
} else if (region.isMember(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.remove.member." + id.toLowerCase());
} else {
plugin.checkPermission(sender, "worldguard.region.remove." + id.toLowerCase());
}
}
mgr.removeRegion(id);
sender.sendMessage(ChatColor.YELLOW
+ "Region '" + id + "' removed.");
try {
mgr.save();
} catch (ProtectionDatabaseException e) {
@@ -977,21 +1039,21 @@ public class RegionCommands {
+ e.getMessage());
}
}
@Command(aliases = {"load", "reload"}, usage = "[world]",
desc = "Reload regions from file", max = 1)
@CommandPermissions({"worldguard.region.load"})
public void load(CommandContext args, CommandSender sender) throws CommandException {
World world = null;
if (args.argsLength() > 0) {
world = plugin.matchWorld(sender, args.getString(0));
}
if (world != null) {
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
try {
mgr.load();
sender.sendMessage(ChatColor.YELLOW
@@ -1003,7 +1065,7 @@ public class RegionCommands {
} else {
for (World w : plugin.getServer().getWorlds()) {
RegionManager mgr = plugin.getGlobalRegionManager().get(w);
try {
mgr.load();
} catch (ProtectionDatabaseException e) {
@@ -1011,26 +1073,26 @@ public class RegionCommands {
+ e.getMessage());
}
}
sender.sendMessage(ChatColor.YELLOW
+ "Region databases loaded.");
}
}
@Command(aliases = {"save", "write"}, usage = "[world]",
desc = "Re-save regions to file", max = 1)
@CommandPermissions({"worldguard.region.save"})
public void save(CommandContext args, CommandSender sender) throws CommandException {
World world = null;
if (args.argsLength() > 0) {
world = plugin.matchWorld(sender, args.getString(0));
}
if (world != null) {
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
try {
mgr.save();
sender.sendMessage(ChatColor.YELLOW
@@ -1042,7 +1104,7 @@ public class RegionCommands {
} else {
for (World w : plugin.getServer().getWorlds()) {
RegionManager mgr = plugin.getGlobalRegionManager().get(w);
try {
mgr.save();
} catch (ProtectionDatabaseException e) {
@@ -1050,7 +1112,7 @@ public class RegionCommands {
+ e.getMessage());
}
}
sender.sendMessage(ChatColor.YELLOW
+ "Region databases saved.");
}
@@ -1108,7 +1170,6 @@ public class RegionCommands {
@Command(aliases = {"teleport", "tp"}, usage = "<id>", flags = "s",
desc = "Teleports you to the location associated with the region.", min = 1, max = 1)
@CommandPermissions({"worldguard.region.teleport"})
public void teleport(CommandContext args, CommandSender sender) throws CommandException {
final Player player = plugin.checkPlayer(sender);
@@ -30,11 +30,11 @@ import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.domains.DefaultDomain;
import com.sk89q.worldguard.protection.databases.ProtectionDatabaseException;
import com.sk89q.worldguard.protection.databases.RegionDBUtil;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.protection.databases.ProtectionDatabaseException;
import com.sk89q.worldguard.protection.databases.RegionDBUtil;
// @TODO: A lot of code duplication here! Need to fix.
@@ -44,15 +44,24 @@ public class RegionMemberCommands {
public RegionMemberCommands(WorldGuardPlugin plugin) {
this.plugin = plugin;
}
@Command(aliases = {"addmember", "addmember"}, usage = "<id> <members...>",
desc = "Add a member to a region", min = 2)
@Command(aliases = {"addmember", "addmember"},
usage = "<id> <members...>",
flags = "w:",
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);
final World world;
Player player;
LocalPlayer localPlayer = null;
if (args.hasFlag('w')) {
world = plugin.matchWorld(sender, args.getFlag('w'));
} else {
player = plugin.checkPlayer(sender);
localPlayer = plugin.wrapPlayer(player);
world = player.getWorld();
}
String id = args.getString(0);
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
@@ -64,19 +73,21 @@ public class RegionMemberCommands {
id = region.getId();
if (region.isOwner(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.addmember.own." + id.toLowerCase());
} else if (region.isMember(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.addmember.member." + id.toLowerCase());
} else {
plugin.checkPermission(sender, "worldguard.region.addmember." + id.toLowerCase());
if (localPlayer != null) {
if (region.isOwner(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.addmember.own." + id.toLowerCase());
} else if (region.isMember(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.addmember.member." + id.toLowerCase());
} else {
plugin.checkPermission(sender, "worldguard.region.addmember." + id.toLowerCase());
}
}
RegionDBUtil.addToDomain(region.getMembers(), args.getPaddedSlice(2, 0), 0);
sender.sendMessage(ChatColor.YELLOW
+ "Region '" + id + "' updated.");
try {
mgr.save();
} catch (ProtectionDatabaseException e) {
@@ -84,15 +95,24 @@ public class RegionMemberCommands {
+ e.getMessage());
}
}
@Command(aliases = {"addowner", "addowner"}, usage = "<id> <owners...>",
desc = "Add an owner to a region", min = 2)
@Command(aliases = {"addowner", "addowner"},
usage = "<id> <owners...>",
flags = "w:",
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);
final World world;
Player player = null;
LocalPlayer localPlayer = null;
if (args.hasFlag('w')) {
world = plugin.matchWorld(sender, args.getFlag('w'));
} else {
player = plugin.checkPlayer(sender);
localPlayer = plugin.wrapPlayer(player);
world = player.getWorld();
}
String id = args.getString(0);
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
@@ -106,22 +126,24 @@ public class RegionMemberCommands {
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.");
if (localPlayer != null) {
if (flag != null && flag && owners != null && owners.size() == 0) {
if (!plugin.hasPermission(player, "worldguard.region.unlimited")) {
int maxRegionCount = plugin.getGlobalStateManager().get(world).getMaxRegionCount(player);
if (maxRegionCount >= 0 && mgr.getRegionCountOfPlayer(localPlayer)
>= maxRegionCount) {
throw new CommandException("You already own the maximum allowed amount of regions.");
}
}
}
plugin.checkPermission(sender, "worldguard.region.addowner.unclaimed." + id.toLowerCase());
} else {
if (region.isOwner(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.addowner.own." + id.toLowerCase());
} else if (region.isMember(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.addowner.member." + id.toLowerCase());
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());
}
}
}
@@ -129,7 +151,7 @@ public class RegionMemberCommands {
sender.sendMessage(ChatColor.YELLOW
+ "Region '" + id + "' updated.");
try {
mgr.save();
} catch (ProtectionDatabaseException e) {
@@ -137,15 +159,24 @@ public class RegionMemberCommands {
+ e.getMessage());
}
}
@Command(aliases = {"removemember", "remmember", "removemem", "remmem"}, usage = "<id> <owners...>",
desc = "Remove an owner to a region", min = 2)
@Command(aliases = {"removemember", "remmember", "removemem", "remmem"},
usage = "<id> <owners...>",
flags = "w:",
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);
final World world;
Player player;
LocalPlayer localPlayer = null;
if (args.hasFlag('w')) {
world = plugin.matchWorld(sender, args.getFlag('w'));
} else {
player = plugin.checkPlayer(sender);
localPlayer = plugin.wrapPlayer(player);
world = player.getWorld();
}
String id = args.getString(0);
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
@@ -157,19 +188,21 @@ public class RegionMemberCommands {
id = region.getId();
if (region.isOwner(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.removemember.own." + id.toLowerCase());
} else if (region.isMember(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.removemember.member." + id.toLowerCase());
} else {
plugin.checkPermission(sender, "worldguard.region.removemember." + id.toLowerCase());
if (localPlayer != null) {
if (region.isOwner(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.removemember.own." + id.toLowerCase());
} else if (region.isMember(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.removemember.member." + id.toLowerCase());
} else {
plugin.checkPermission(sender, "worldguard.region.removemember." + id.toLowerCase());
}
}
RegionDBUtil.removeFromDomain(region.getMembers(), args.getPaddedSlice(2, 0), 0);
sender.sendMessage(ChatColor.YELLOW
+ "Region '" + id + "' updated.");
try {
mgr.save();
} catch (ProtectionDatabaseException e) {
@@ -177,16 +210,25 @@ public class RegionMemberCommands {
+ e.getMessage());
}
}
@Command(aliases = {"removeowner", "remowner"}, usage = "<id> <owners...>",
desc = "Remove an owner to a region", min = 2)
@Command(aliases = {"removeowner", "remowner"},
usage = "<id> <owners...>",
flags = "w:",
desc = "Remove an owner to a region",
min = 2)
public void removeOwner(CommandContext args,
CommandSender sender) throws CommandException {
Player player = plugin.checkPlayer(sender);
World world = player.getWorld();
LocalPlayer localPlayer = plugin.wrapPlayer(player);
final World world;
Player player;
LocalPlayer localPlayer = null;
if (args.hasFlag('w')) {
world = plugin.matchWorld(sender, args.getFlag('w'));
} else {
player = plugin.checkPlayer(sender);
localPlayer = plugin.wrapPlayer(player);
world = player.getWorld();
}
String id = args.getString(0);
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
@@ -198,19 +240,21 @@ public class RegionMemberCommands {
id = region.getId();
if (region.isOwner(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.removeowner.own." + id.toLowerCase());
} else if (region.isMember(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.removeowner.member." + id.toLowerCase());
} else {
plugin.checkPermission(sender, "worldguard.region.removeowner." + id.toLowerCase());
if (localPlayer != null) {
if (region.isOwner(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.removeowner.own." + id.toLowerCase());
} else if (region.isMember(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.removeowner.member." + id.toLowerCase());
} else {
plugin.checkPermission(sender, "worldguard.region.removeowner." + id.toLowerCase());
}
}
RegionDBUtil.removeFromDomain(region.getOwners(), args.getPaddedSlice(2, 0), 0);
sender.sendMessage(ChatColor.YELLOW
+ "Region '" + id + "' updated.");
try {
mgr.save();
} catch (ProtectionDatabaseException e) {
@@ -34,6 +34,7 @@ import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.worldguard.bukkit.LoggerToChatHandler;
import com.sk89q.worldguard.bukkit.ReportWriter;
import com.sk89q.worldguard.bukkit.WGBukkit;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.util.PastebinPoster;
import com.sk89q.worldguard.util.PastebinPoster.PasteCallback;
@@ -72,6 +73,7 @@ public class WorldGuardCommands {
plugin.getGlobalRegionManager().unload();
plugin.getGlobalStateManager().load();
plugin.getGlobalRegionManager().preload();
WGBukkit.cleanCache();
sender.sendMessage("WorldGuard configuration reloaded.");
} catch (Throwable t) {
sender.sendMessage("Error while reloading: "
@@ -36,12 +36,11 @@ import com.sk89q.worldguard.bukkit.BukkitUtil;
import com.sk89q.worldguard.bukkit.ConfigurationManager;
import com.sk89q.worldguard.bukkit.WorldConfiguration;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.databases.ProtectionDatabaseException;
import com.sk89q.worldguard.protection.databases.ProtectionDatabase;
import com.sk89q.worldguard.protection.databases.YAMLDatabase;
import com.sk89q.worldguard.protection.databases.MySQLDatabase;
import com.sk89q.worldguard.protection.databases.ProtectionDatabase;
import com.sk89q.worldguard.protection.databases.ProtectionDatabaseException;
import com.sk89q.worldguard.protection.databases.YAMLDatabase;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.managers.FlatRegionManager;
import com.sk89q.worldguard.protection.managers.PRTreeRegionManager;
import com.sk89q.worldguard.protection.managers.RegionManager;
@@ -160,8 +159,10 @@ public class GlobalRegionManager {
RegionManager manager = new PRTreeRegionManager(database);
manager.load();
plugin.getLogger().info(manager.getRegions().size()
+ " regions loaded for '" + name + "'");
if (plugin.getGlobalStateManager().get(world).summaryOnStart) {
plugin.getLogger().info(manager.getRegions().size()
+ " regions loaded for '" + name + "'");
}
return manager;
} catch (ProtectionDatabaseException e) {
@@ -37,6 +37,7 @@ public final class DefaultFlag {
public static final StateFlag CREEPER_EXPLOSION = new StateFlag("creeper-explosion", true, RegionGroup.ALL);
public static final StateFlag ENDERDRAGON_BLOCK_DAMAGE = new StateFlag("enderdragon-block-damage", true);
public static final StateFlag GHAST_FIREBALL = new StateFlag("ghast-fireball", true, RegionGroup.ALL);
public static final StateFlag OTHER_EXPLOSION = new StateFlag("other-explosion", true);
public static final StateFlag SLEEP = new StateFlag("sleep", true);
public static final StateFlag TNT = new StateFlag("tnt", true, RegionGroup.ALL);
public static final StateFlag LIGHTER = new StateFlag("lighter", true, RegionGroup.ALL);
@@ -57,6 +58,8 @@ public final class DefaultFlag {
public static final StateFlag MUSHROOMS = new StateFlag("mushroom-growth", true);
public static final StateFlag LEAF_DECAY = new StateFlag("leaf-decay", true);
public static final StateFlag GRASS_SPREAD = new StateFlag("grass-growth", true);
public static final StateFlag MYCELIUM_SPREAD = new StateFlag("mycelium-spread", true);
public static final StateFlag VINE_GROWTH = new StateFlag("vine-growth", true);
public static final StateFlag ENDER_BUILD = new StateFlag("enderman-grief", true);
public static final StateFlag INVINCIBILITY = new StateFlag("invincible", false, RegionGroup.ALL);
public static final StateFlag EXP_DROPS = new StateFlag("exp-drops", true, RegionGroup.ALL);
@@ -65,6 +68,7 @@ public final class DefaultFlag {
public static final StateFlag ENTRY = new StateFlag("entry", true);
public static final StateFlag EXIT = new StateFlag("exit", true);
public static final StateFlag ITEM_DROP = new StateFlag("item-drop", true);
public static final StateFlag ENDERPEARL = new StateFlag("enderpearl", true);
public static final StateFlag ENTITY_PAINTING_DESTROY = new StateFlag("entity-painting-destroy", true);
public static final StateFlag ENTITY_ITEM_FRAME_DESTROY = new StateFlag("entity-item-frame-destroy", true);
public static final StateFlag POTION_SPLASH = new StateFlag("potion-splash", true);
@@ -82,8 +86,11 @@ public final class DefaultFlag {
public static final IntegerFlag FEED_AMOUNT = new IntegerFlag("feed-amount", RegionGroup.ALL);
public static final IntegerFlag MIN_FOOD = new IntegerFlag("feed-min-hunger", RegionGroup.ALL);
public static final IntegerFlag MAX_FOOD = new IntegerFlag("feed-max-hunger", RegionGroup.ALL);
// public static final IntegerFlag MAX_PLAYERS = new IntegerFlag("max-players-allowed", RegionGroup.ALL);
// public static final StringFlag MAX_PLAYERS_MESSAGE = new StringFlag("max-players-reject-message", RegionGroup.ALL);
public static final LocationFlag TELE_LOC = new LocationFlag("teleport", RegionGroup.MEMBERS);
public static final LocationFlag SPAWN_LOC = new LocationFlag("spawn", RegionGroup.MEMBERS);
public static final StateFlag ENABLE_SHOP = new StateFlag("allow-shop", false);
public static final BooleanFlag BUYABLE = new BooleanFlag("buyable");
public static final DoubleFlag PRICE = new DoubleFlag("price");
public static final SetFlag<String> BLOCKED_CMDS = new SetFlag<String>("blocked-cmds", RegionGroup.ALL, new CommandStringFlag(null));
@@ -93,20 +100,19 @@ public final class DefaultFlag {
PASSTHROUGH, BUILD, CONSTRUCT, PVP, CHEST_ACCESS, PISTONS,
TNT, LIGHTER, USE, PLACE_VEHICLE, DESTROY_VEHICLE, SLEEP,
MOB_DAMAGE, MOB_SPAWNING, DENY_SPAWN, INVINCIBILITY, EXP_DROPS,
CREEPER_EXPLOSION, ENDERDRAGON_BLOCK_DAMAGE, GHAST_FIREBALL, ENDER_BUILD,
CREEPER_EXPLOSION, OTHER_EXPLOSION, ENDERDRAGON_BLOCK_DAMAGE, GHAST_FIREBALL, ENDER_BUILD,
GREET_MESSAGE, FAREWELL_MESSAGE, NOTIFY_ENTER, NOTIFY_LEAVE,
EXIT, ENTRY, LIGHTNING, ENTITY_PAINTING_DESTROY,
ENTITY_ITEM_FRAME_DESTROY, ITEM_DROP,
EXIT, ENTRY, LIGHTNING, ENTITY_PAINTING_DESTROY, ENDERPEARL,
ENTITY_ITEM_FRAME_DESTROY, ITEM_DROP, /*MAX_PLAYERS, MAX_PLAYERS_MESSAGE,*/
HEAL_AMOUNT, HEAL_DELAY, MIN_HEAL, MAX_HEAL,
FEED_DELAY, FEED_AMOUNT, MIN_FOOD, MAX_FOOD,
SNOW_FALL, SNOW_MELT, ICE_FORM, ICE_MELT, GAME_MODE,
MUSHROOMS, LEAF_DECAY, GRASS_SPREAD, SEND_CHAT, RECEIVE_CHAT,
FIRE_SPREAD, LAVA_FIRE, LAVA_FLOW, WATER_FLOW,
MUSHROOMS, LEAF_DECAY, GRASS_SPREAD, MYCELIUM_SPREAD, VINE_GROWTH,
SEND_CHAT, RECEIVE_CHAT, FIRE_SPREAD, LAVA_FIRE, LAVA_FLOW, WATER_FLOW,
TELE_LOC, SPAWN_LOC, POTION_SPLASH,
BLOCKED_CMDS, ALLOWED_CMDS, PRICE, BUYABLE,
BLOCKED_CMDS, ALLOWED_CMDS, PRICE, BUYABLE, ENABLE_SHOP
};
private DefaultFlag() {
}
@@ -19,10 +19,10 @@
package com.sk89q.worldguard;
import java.util.Set;
import java.util.HashSet;
import java.util.Set;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.LocalPlayer;
@org.junit.Ignore
public class TestPlayer extends LocalPlayer {
@@ -49,32 +49,27 @@ public class TestPlayer extends LocalPlayer {
@Override
public Vector getPosition() {
// TODO Auto-generated method stub
return null;
return new Vector(0, 0, 0);
}
@Override
public void kick(String msg) {
// TODO Auto-generated method stub
System.out.println("TestPlayer{" + this.name + "} kicked!");
}
@Override
public void ban(String msg) {
// TODO Auto-generated method stub
System.out.println("TestPlayer{" + this.name + "} banned!");
}
@Override
public void printRaw(String msg) {
// TODO Auto-generated method stub
System.out.println("-> TestPlayer{" + this.name + "}: " + msg);
}
@Override
public String[] getGroups() {
// TODO Auto-generated method stub
return null;
return groups.toArray(new String[groups.size()]);
}
@Override
@@ -0,0 +1,30 @@
// $Id$
/*
* WorldGuard
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.protection;
import com.sk89q.worldguard.protection.managers.PRTreeRegionManager;
import com.sk89q.worldguard.protection.managers.RegionManager;
public class PRTreeRegionEntryExitTest extends RegionEntryExitTest {
@Override
protected RegionManager createRegionManager() throws Exception {
return new PRTreeRegionManager(null);
}
}
@@ -0,0 +1,146 @@
// $Id$
/*
* WorldGuard
* Copyright (C) 2013 sk89q <http://www.sk89q.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.protection;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.TestPlayer;
import com.sk89q.worldguard.domains.DefaultDomain;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.flags.RegionGroup;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.GlobalProtectedRegion;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
public abstract class RegionEntryExitTest {
static String ENTRY_ID = "entry_rg";
static String EXIT_ID = "exit_rg";
static String BUILDER_GROUP = "builder";
static String VIP_GROUP = "vip";
Vector inEntry = new Vector(5, 64, 5);
Vector inExit = new Vector(-5, 65, -5);
RegionManager manager;
ProtectedRegion globalRegion;
ProtectedRegion entryRegion;
ProtectedRegion exitRegion;
TestPlayer vip_player;
TestPlayer builder_player;
protected abstract RegionManager createRegionManager() throws Exception;
@Before
public void setUp() throws Exception {
setUpGlobalRegion();
manager = createRegionManager();
setUpPlayers();
setUpEntryRegion();
setUpExitRegion();
}
void setUpPlayers() {
vip_player = new TestPlayer("dudu");
vip_player.addGroup(VIP_GROUP);
builder_player = new TestPlayer("esskay");
builder_player.addGroup(BUILDER_GROUP);
// @Test
// assertFalse(builderPlayer.wuvs(vip_player)); // causes test to fail
}
void setUpGlobalRegion() {
globalRegion = new GlobalProtectedRegion("__global__");
}
void setUpEntryRegion() {
DefaultDomain domain = new DefaultDomain();
domain.addGroup(VIP_GROUP);
ProtectedRegion region = new ProtectedCuboidRegion(ENTRY_ID, new BlockVector(1, 0, 1), new BlockVector(10, 255, 10));
region.setMembers(domain);
manager.addRegion(region);
entryRegion = region;
// this is the way it's supposed to work
// whatever the group flag is set to is the group that the flag APPLIES to
// in this case, non members (esskay) should be DENIED entry
entryRegion.setFlag(DefaultFlag.ENTRY, StateFlag.State.DENY);
entryRegion.setFlag(DefaultFlag.ENTRY.getRegionGroupFlag(), RegionGroup.NON_MEMBERS);
}
void setUpExitRegion() throws Exception {
DefaultDomain domain = new DefaultDomain();
domain.addGroup(BUILDER_GROUP);
ProtectedRegion region = new ProtectedCuboidRegion(EXIT_ID, new BlockVector(-1, 0, -1), new BlockVector(-10, 255, -10));
region.setOwners(domain);
manager.addRegion(region);
entryRegion = region;
// same as above
entryRegion.setFlag(DefaultFlag.EXIT, StateFlag.State.DENY);
entryRegion.setFlag(DefaultFlag.EXIT.getRegionGroupFlag(), RegionGroup.NON_OWNERS);
}
@Test
public void testEntry() throws Exception {
ApplicableRegionSet appl;
appl = manager.getApplicableRegions(inEntry);
// ProtectedRegion rg = appl.iterator().next();
// System.out.println("rg " + rg.getId());
// System.out.println("mem " + rg.getMembers().toGroupsString());
// System.out.println("flag " + appl.getFlag(DefaultFlag.ENTRY));
// System.out.println("grp " + appl.getFlag(DefaultFlag.ENTRY.getRegionGroupFlag()));
// System.out.println("===");
assertTrue("Allowed Entry", appl.allows(DefaultFlag.ENTRY, vip_player));
assertFalse("Forbidden Entry", appl.allows(DefaultFlag.ENTRY, builder_player));
}
@Test
public void testExit() throws Exception {
ApplicableRegionSet appl;
appl = manager.getApplicableRegions(inExit);
// ProtectedRegion rg = appl.iterator().next();
// System.out.println("rg " + rg.getId());
// System.out.println("own " + rg.getOwners().toGroupsString());
// System.out.println("flag " + appl.getFlag(DefaultFlag.EXIT));
// System.out.println("grp " + appl.getFlag(DefaultFlag.EXIT.getRegionGroupFlag()));
// System.out.println("===");
assertTrue("Allowed Exit", appl.allows(DefaultFlag.EXIT, builder_player));
assertFalse("Forbidden Exit", appl.allows(DefaultFlag.EXIT, vip_player));
}
}
@@ -19,6 +19,15 @@
package com.sk89q.worldguard.protection;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.HashSet;
import org.junit.Before;
import org.junit.Test;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.BlockVector2D;
import com.sk89q.worldedit.Vector;
@@ -26,19 +35,11 @@ import com.sk89q.worldguard.TestPlayer;
import com.sk89q.worldguard.domains.DefaultDomain;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.managers.FlatRegionManager;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.GlobalProtectedRegion;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
import java.util.HashSet;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public abstract class RegionOverlapTest {
static String COURTYARD_ID = "courtyard";
@@ -166,7 +167,6 @@ public abstract class RegionOverlapTest {
HashSet<ProtectedRegion> test = new HashSet<ProtectedRegion>();
test.add(courtyard);
test.add(fountain);
System.out.println(test);
// Outside
appl = manager.getApplicableRegions(outside);