Compare commits

...
44 Commits
Author SHA1 Message Date
sk89q c75b9c2328 [maven-release-plugin] prepare release 5.2.2 2011-06-27 12:09:47 -07:00
sk89q 0863db8cf0 Changed configuration saving so empty lists will be added to the configuration files. 2011-06-27 12:09:03 -07:00
sk89q 53d6a272e6 [maven-release-plugin] prepare for next development iteration 2011-06-27 11:47:48 -07:00
sk89q 71467a7ae7 [maven-release-plugin] prepare release 5.2.1 2011-06-27 11:47:37 -07:00
sk89q 56fa3458ab Updated CHANGELOG.txt for 5.2.1. 2011-06-27 11:37:22 -07:00
sk89q 82e04ac4e5 Changed /region {add|rem}{member|owner} to allow putting owners/members on the global region. 2011-06-27 11:23:33 -07:00
sk89q 564d4442fc Added a bunch of unit tests for regions. 2011-06-27 11:10:20 -07:00
sk89q df8fdd086b Fixed some flag algorithm issues, added the possibility of owners and members on the global region in order to affect build. 2011-06-27 11:10:20 -07:00
sk89q a31476251e Fixed DefaultDomain.size() not counting players. 2011-06-27 11:10:19 -07:00
sk89q 360a655627 Added the ability to add owners/members to the global region for handling guest groups. 2011-06-27 11:10:19 -07:00
sk89q 3b871b9c00 Added more region unit tests. 2011-06-27 11:10:19 -07:00
sk89q 65834a2087 Undeprecated ApplicableRegionSet.allows(StateFlag) 2011-06-27 11:10:19 -07:00
e9d85da691 Merge pull request #107 from Moo0/infobounds
Add region bounds to "/region info"
2011-06-27 09:31:02 -07:00
sk89q cfa78af654 [maven-release-plugin] prepare for next development iteration 2011-06-27 00:00:47 -07:00
sk89q 45d9119150 [maven-release-plugin] prepare release 5.2 2011-06-27 00:00:38 -07:00
sk89q ea487eb6a4 Fixed the %online% macro requiring a player. 2011-06-26 23:41:30 -07:00
sk89q 4e295ea1eb Updated for 5.2. 2011-06-26 23:20:43 -07:00
sk89q 32265414bd Added Javadocs, cleaned up comments. 2011-06-26 23:19:49 -07:00
sk89q 80e706e962 Improved the API. 2011-06-26 22:50:21 -07:00
sk89q 110838715b Gave the ability to use color colors and macros in greeting and farewell messages. 2011-06-26 21:49:34 -07:00
sk89q b90334c8a8 Made WorldGuard catch setHeader() not being yet defined. 2011-06-26 21:49:33 -07:00
sk89q 3ce0530d5f Updated for 5.2. 2011-06-26 21:49:33 -07:00
sk89q 7eaa84d5b1 Added disable-ice-melting, disable-snow-formation, disable-mushroom-spread, disable-snow-melting, disable-ice-formation. 2011-06-26 21:49:32 -07:00
sk89q ad325dfedb Added paintings to blacklist support. 2011-06-26 21:49:32 -07:00
sk89q 5bb7eb6f01 Added default.disable-health-regain. 2011-06-26 21:49:32 -07:00
sk89q 342cfc0801 Added auto-invincible-permission setting, which lets you use the permission 'worldguard.auto-invincible' to become invincible. 2011-06-26 21:49:31 -07:00
sk89q f5c6a9f507 Flames won't appear if you are /god'ed now. 2011-06-26 21:49:31 -07:00
e843ff372e Merge pull request #113 from Moo0/limitoverride
Region limit override permission.
2011-06-26 19:35:40 -07:00
sk89q ed27ffed65 Updated the blacklist with a new ignore-perms option. No more groups! Use permissions! 2011-06-26 18:36:06 -07:00
sk89q 7995ecd867 Updated CHANGELOG.txt. 2011-06-26 17:33:59 -07:00
sk89q fcef6679c4 Updated README.html. 2011-06-26 16:48:51 -07:00
sk89q 742b6a2e27 Made negative healing possible. 2011-06-26 16:39:41 -07:00
sk89q 258fbc8870 Improved the entry/exit flags so that it's harder to break it. Thanks to Siriuo. 2011-06-26 16:29:28 -07:00
sk89q 0fa43ee287 Added a warning about modifying region database files manually. 2011-06-26 15:11:05 -07:00
sk89q fb39261dc7 Fixed floating point inaccuracy in onPlayerMove(). 2011-06-26 14:38:56 -07:00
sk89q 7fce4bf53e Added exit flag to deny exiting a region. 2011-06-26 14:11:11 -07:00
sk89q 13840cf61b Changed the configuration header messages to be more helpful to new users. 2011-06-26 12:59:20 -07:00
sk89q e26f6b5e8d Added 'entry' flag to deny entry. 2011-06-26 12:32:01 -07:00
sk89q 767c49f9fa Added region command whitelisting and the bypass for command checks. 2011-06-26 10:45:12 -07:00
sk89q c9178da608 Added command blocking. 2011-06-26 10:40:08 -07:00
sk89q 855bc59a53 [maven-release-plugin] prepare for next development iteration 2011-06-26 03:15:25 -07:00
Moo0 3b4c58b721 Add region limit override permission. 2011-06-20 17:22:33 +01:00
Moo0 69af41f1e5 Remove permission. 2011-05-24 16:25:45 +01:00
Moo0 7074963fb1 Add region bounds to "/region info" 2011-05-23 19:48:02 +01:00
31 changed files with 1709 additions and 388 deletions

No files matched your search

+34
View File
@@ -1,3 +1,37 @@
5.2.2:
- Changed configuration saving so empty lists will be added to
the configuration files.
5.2.1:
- Add region bounds to /region info
- Added the ability to add owners/members to the global region for
handling guest groups. Now if there's owners or members on the global
region, then those that are not on the list cannot build.
- Fixed some flag algorithm issues.
- API: Fixed DefaultDomain.size() not counting players.
- API: Undeprecated ApplicableRegionSet.allows(StateFlag).
5.2:
- Gave the ability to use color colors and macros in greeting
and farewell messages.
- Added disable-ice-melting, disable-snow-formation, disable-mushroom-spread,
disable-snow-melting, disable-ice-formation.
- Added paintings to blacklist support.
- Added default.disable-health-regain.
- Added auto-invincible-permission setting, which lets you use the permission
'worldguard.auto-invincible' to become invincible on join automatically.
- Flames won't appear if you are /god'ed now.
- Added blocked-cmds region flag to block commands.
- Added allowed-cmds region flag to whitelist commands.
- Added entry region flag to block entry. Use entry-group to determine who
this affects.
- Added exit region flag to block exit. Use exit-group to determine who
this affects.
- Made negative healing possible via the healing flag.
- Changed the configuration header messages to be more helpful to new users.
- Added a warning about modifying region files by hand.
- Improved the API for plugin developers.
5.1:
- A lot of changes.
+4 -4
View File
@@ -76,7 +76,7 @@ h2 {
<h1>WorldGuard ${version}</h1>
<p>Thanks for choosing WorldGuard!</p>
<h2>First Steps</h2>
<h2>Getting Started</h2>
<p>Now, to begin, you want to:</p>
<ol>
@@ -90,18 +90,18 @@ h2 {
Use <em>/wg reload</em> in the console to reload the configuration.
<li><strong>Learn how to use WorldGuard:</strong> Check <a href="http://wiki.sk89q.com/wiki/WorldGuard">out the wiki</a> to learn how to disable things like fire and to protect regions.</li>
</ol>
<p class="warning"><strong>Note:</strong> Be sure you install <a href="http://www.sk89q.com/projects/worldedit/">WorldEdit</a>. If you don't want WorldEdit, just put WorldEdit.jar into your Bukkit root folder (outside of plugins/). Note that region protection requires WorldEdit in plugins/.</p>
<p class="warning"><strong>Note:</strong> <a href="http://www.sk89q.com/projects/worldedit/">WorldEdit</a> must be installed, but if you do not want it, put WorldEdit.jar into your Bukkit root folder (outside of plugins/). Note that region protection requires WorldEdit in plugins/.</p>
<p>Be sure to:</p>
<ul>
<li>Subscribe to <a href="http://minecraftnews.sk89q.com/">SK's Minecraft blog</a> for news about WorldGuard</li>
<li>Submit bug reports and suggestions to the <a href="http://redmine.sk89q.com/projects/worldguard/issues">issue tracker</a></li>
<li>Check out the <a href="http://wiki.sk89q.com/wiki/WorldGuard">WorldGuard wiki</a></li>
<li>Idle with us in IRC at <a href="http://skq.me/irc/irc.esper.net/worldguard">irc.esper.net in #worldguard</a></li>
</ul>
<h2>Getting Help</h2>
<p>If you need help, the best two ways to ask are:</p>
<ul>
<li><a href="http://forum.sk89q.com/">Visit the WorldGuard forum</a></li>
<li>Ask in IRC chat on <a href="http://skq.me/irc/irc.esper.net/worldguard">irc.esper.net in #worldguard</a> (idle with us!)</li>
<li>Submit bug reports and suggestions to the <a href="http://redmine.sk89q.com/projects/worldguard/issues">issue tracker</a></li>
</ul>
<h2>Contributing</h2>
<p>WorldGuard is entirely open source! You can download all of the plugin code to learn from it, modify it for your own self, or even contribute back!</p>
+15 -2
View File
@@ -7,7 +7,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.sk89q</groupId>
<artifactId>worldguard</artifactId>
<version>5.1.1</version>
<version>5.2.2</version>
<name>WorldGuard</name>
<description>WorldGuard protects your Minecraft servers</description>
@@ -88,7 +88,6 @@
</resource>
</resources>
<!-- Plugins -->
<plugins>
<!-- Compile plugin -->
<plugin>
@@ -170,4 +169,18 @@
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<!-- Javadocs -->
<!-- TODO: Get Doclava working -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8</version>
<configuration>
</configuration>
</plugin>
</plugins>
</reporting>
</project>
@@ -205,6 +205,8 @@ public abstract class Blacklist {
for (BlacklistEntry entry : currentEntries) {
if (parts[0].equalsIgnoreCase("ignore-groups")) {
entry.setIgnoreGroups(parts[1].split(","));
} else if (parts[0].equalsIgnoreCase("ignore-perms")) {
entry.setIgnorePermissions(parts[1].split(","));
} else if (parts[0].equalsIgnoreCase("on-break")) {
entry.setBreakActions(parts[1].split(","));
} else if (parts[0].equalsIgnoreCase("on-destroy-with")) {
@@ -42,10 +42,16 @@ public class BlacklistEntry {
* Parent blacklist entry.
*/
private Blacklist blacklist;
/**
* List of groups to not affect.
*/
private Set<String> ignoreGroups;
/**
* List of permissions to not affect.
*/
private Set<String> ignorePermissions;
private String[] breakActions;
private String[] destroyWithActions;
@@ -74,6 +80,13 @@ public class BlacklistEntry {
return ignoreGroups.toArray(new String[ignoreGroups.size()]);
}
/**
* @return the ignoreGroups
*/
public String[] getIgnorePermissions() {
return ignorePermissions.toArray(new String[ignorePermissions.size()]);
}
/**
* @param ignoreGroups the ignoreGroups to set
*/
@@ -85,6 +98,17 @@ public class BlacklistEntry {
this.ignoreGroups = ignoreGroupsSet;
}
/**
* @param ignorePermissions the ignorePermissions to set
*/
public void setIgnorePermissions(String[] ignorePermissions) {
Set<String> ignorePermissionsSet = new HashSet<String>();
for (String perm : ignorePermissions) {
ignorePermissionsSet.add(perm);
}
this.ignorePermissions = ignorePermissionsSet;
}
/**
* @return
*/
@@ -218,12 +242,19 @@ public class BlacklistEntry {
* @return
*/
public boolean shouldIgnore(LocalPlayer player) {
if (ignoreGroups == null) {
return false;
if (ignoreGroups != null) {
for (String group : player.getGroups()) {
if (ignoreGroups.contains(group.toLowerCase())) {
return true;
}
}
}
for (String group : player.getGroups()) {
if (ignoreGroups.contains(group.toLowerCase())) {
return true;
if (ignorePermissions != null) {
for (String perm : ignorePermissions) {
if (player.hasPermission(perm)) {
return true;
}
}
}
@@ -20,13 +20,12 @@
package com.sk89q.worldguard.bukkit;
import java.util.List;
import com.sk89q.worldedit.blocks.BlockType;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.World;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.Vector;
@@ -139,4 +138,85 @@ public class BukkitUtil {
}
}
/**
* Find a position for the player to stand that is not inside a block.
* Blocks above the player will be iteratively tested until there is
* a series of two free blocks. The player will be teleported to
* that free position.
*
* @param player
*/
public static void findFreePosition(Player player) {
Location loc = player.getLocation();
int x = loc.getBlockX();
int y = Math.max(0, loc.getBlockY());
int origY = y;
int z = loc.getBlockZ();
World world = player.getWorld();
byte free = 0;
while (y <= 129) {
if (BlockType.canPassThrough(world.getBlockTypeIdAt(x, y, z))) {
free++;
} else {
free = 0;
}
if (free == 2) {
if (y - 1 != origY || y == 1) {
loc.setX(x + 0.5);
loc.setY(y);
loc.setZ(z + 0.5);
if (y <= 2 && world.getBlockAt(x,0,z).getType() == Material.AIR) {
world.getBlockAt(x,0,z).setTypeId(20);
loc.setY(2);
}
player.setFallDistance(0F);
player.teleport(loc);
}
return;
}
y++;
}
}
/**
* Replace color macros in a string. The macros are in the form of `[char]
* where char represents the color. R is for red, Y is for yellow,
* G is for green, C is for cyan, B is for blue, and P is for purple.
* The uppercase versions of those are the darker shades, while the
* lowercase versions are the lighter shades. For white, it's 'w', and
* 0-2 are black, dark grey, and grey, respectively.
*
* @param str
* @return color-coded string
*/
public static String replaceColorMacros(String str) {
str = str.replace("&r", ChatColor.RED.toString());
str = str.replace("&R", ChatColor.DARK_RED.toString());
str = str.replace("&y", ChatColor.YELLOW.toString());
str = str.replace("&Y", ChatColor.GOLD.toString());
str = str.replace("&g", ChatColor.GREEN.toString());
str = str.replace("&G", ChatColor.DARK_GREEN.toString());
str = str.replace("&c", ChatColor.AQUA.toString());
str = str.replace("&C", ChatColor.DARK_AQUA.toString());
str = str.replace("&b", ChatColor.BLUE.toString());
str = str.replace("&B", ChatColor.DARK_BLUE.toString());
str = str.replace("&p", ChatColor.LIGHT_PURPLE.toString());
str = str.replace("&P", ChatColor.DARK_PURPLE.toString());
str = str.replace("&0", ChatColor.BLACK.toString());
str = str.replace("&1", ChatColor.DARK_GRAY.toString());
str = str.replace("&2", ChatColor.GRAY.toString());
str = str.replace("&w", ChatColor.WHITE.toString());
return str;
}
}
@@ -38,8 +38,12 @@ import org.bukkit.util.config.Configuration;
*/
public class ConfigurationManager {
public static final String CONFIG_HEADER = "#\r\n" +
"# WorldGuard's configuration file\r\n" +
private static final String CONFIG_HEADER = "#\r\n" +
"# WorldGuard's main configuration file\r\n" +
"#\r\n" +
"# This is the global configuration file. Anything placed into here will\r\n" +
"# be applied to all worlds. However, each world has its own configuration\r\n" +
"# file to allow you to replace any setting in here for that world only.\r\n" +
"#\r\n" +
"# About editing this file:\r\n" +
"# - DO NOT USE TABS. You MUST use spaces or Bukkit will complain. If\r\n" +
@@ -78,6 +82,7 @@ public class ConfigurationManager {
public boolean suppressTickSyncWarnings;
public boolean useRegionsScheduler;
public boolean activityHaltToggle = false;
public boolean autoGodMode;
/**
* Construct the object.
@@ -104,13 +109,19 @@ public class ConfigurationManager {
"suppress-tick-sync-warnings", false);
useRegionsScheduler = config.getBoolean(
"regions.use-scheduler", true);
autoGodMode = config.getBoolean(
"auto-invincible-permission", false);
// Load configurations for each world
for (World world : plugin.getServer().getWorlds()) {
get(world);
}
config.setHeader(CONFIG_HEADER);
try {
config.setHeader(CONFIG_HEADER);
} catch (Throwable t) {
}
config.save();
}
@@ -22,6 +22,7 @@ package com.sk89q.worldguard.bukkit;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.entity.Player;
import org.bukkit.World;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
@@ -97,7 +98,7 @@ public class FlagStateManager implements Runnable {
private void processHeal(ApplicableRegionSet applicable, Player player,
PlayerFlagState state) {
if (player.getHealth() >= 20 || player.getHealth() <= 0) {
if (player.getHealth() <= 0) {
return;
}
@@ -106,15 +107,19 @@ public class FlagStateManager implements Runnable {
Integer healAmount = applicable.getFlag(DefaultFlag.HEAL_AMOUNT);
Integer healDelay = applicable.getFlag(DefaultFlag.HEAL_DELAY);
if (healAmount == null || healDelay == null || healAmount < 1 || healDelay < 0) {
if (healAmount == null || healDelay == null || healAmount == 0 || healDelay < 0) {
return;
}
if (player.getHealth() >= 20 && healAmount > 0) {
return;
}
if (healDelay <= 0) {
if (healDelay <= 0 && healAmount > 0) {
player.setHealth(20);
state.lastHeal = now;
} else if (now - state.lastHeal > healDelay * 1000) {
player.setHealth(Math.min(20, player.getHealth() + healAmount));
player.setHealth(Math.min(20, Math.max(0, player.getHealth() + healAmount)));
state.lastHeal = now;
}
}
@@ -152,8 +157,13 @@ public class FlagStateManager implements Runnable {
public long lastHeal;
public String lastGreeting;
public String lastFarewell;
public Boolean notifiedForEnter = false;
public Boolean lastExitAllowed = null;
public Boolean notifiedForLeave = false;
public Boolean notifiedForEnter = false;
public World lastWorld;
public int lastBlockX;
public int lastBlockY;
public int lastBlockZ;
}
}
@@ -29,6 +29,7 @@ import com.sk89q.worldguard.chest.SignChestProtection;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -48,23 +49,14 @@ import org.bukkit.util.config.Configuration;
public class WorldConfiguration {
public static final String CONFIG_HEADER = "#\r\n" +
"# WorldGuard's configuration file.\r\n" +
"# WorldGuard's world configuration file\r\n" +
"#\r\n" +
"# This is the a per-world configuration file. It only affects one\r\n" +
"# corresponding world.\r\n" +
"# This is a world configuration file. Anything placed into here will only\r\n" +
"# affect this world. If you don't put anything in this file, then the\r\n" +
"# settings will be inherited from the main configuration file.\r\n" +
"#\r\n" +
"# About editing this file:\r\n" +
"# - DO NOT USE TABS. You MUST use spaces or Bukkit will complain. If\r\n" +
"# you use an editor like Notepad++ (recommended for Windows users), you\r\n" +
"# must configure it to \"replace tabs with spaces.\" In Notepad++, this can\r\n" +
"# be changed in Settings > Preferences > Language Menu.\r\n" +
"# - Don't get rid of the indents. They are indented so some entries are\r\n" +
"# in categories (like \"enforce-single-session\" is in the \"protection\"\r\n" +
"# category.\r\n" +
"# - If you want to check the format of this file before putting it\r\n" +
"# into WorldGuard, paste it into http://yaml-online-parser.appspot.com/\r\n" +
"# and see if it gives \"ERROR:\".\r\n" +
"# - Lines starting with # are comments and so they are ignored.\r\n" +
"# If you see {} below, that means that there are NO entries in this file.\r\n" +
"# Remove the {} and add your own entries.\r\n" +
"#\r\n";
private static final Logger logger = Logger
@@ -143,6 +135,13 @@ public class WorldConfiguration {
public boolean alwaysThundering;
public boolean disablePigZap;
public boolean disableCreeperPower;
public boolean disableHealthRegain;
public boolean disableMushroomSpread;
public boolean disableIceMelting;
public boolean disableSnowMelting;
public boolean disableSnowFormation;
public boolean disableIceFormation;
public boolean disableLeafDecay;
/* Configuration data end */
@@ -203,19 +202,35 @@ public class WorldConfiguration {
}
private List<Integer> getIntList(String node, List<Integer> def) {
List<Integer> res;
if (config.getProperty(node) != null) {
return config.getIntList(node, def);
res = config.getIntList(node, def);
} else {
return parentConfig.getIntList(node, def);
res = parentConfig.getIntList(node, def);
}
if (res == null || res.size() == 0) {
parentConfig.setProperty(node, new ArrayList<Integer>());
}
return res;
}
private List<String> getStringList(String node, List<String> def) {
List<String> res;
if (config.getProperty(node) != null) {
return config.getStringList(node, def);
res = config.getStringList(node, def);
} else {
return parentConfig.getStringList(node, def);
res = parentConfig.getStringList(node, def);
}
if (res == null || res.size() == 0) {
parentConfig.setProperty(node, new ArrayList<String>());
}
return res;
}
/**
@@ -237,6 +252,8 @@ public class WorldConfiguration {
pumpkinScuba = getBoolean("pumpkin-scuba", false);
disableHealthRegain = getBoolean("default.disable-health-regain", false);
noPhysicsGravel = getBoolean("physics.no-physics-gravel", false);
noPhysicsSand = getBoolean("physics.no-physics-sand", false);
allowPortalAnywhere = getBoolean("physics.allow-portal-anywhere", false);
@@ -287,6 +304,13 @@ public class WorldConfiguration {
alwaysRaining = getBoolean("weather.always-raining", false);
alwaysThundering = getBoolean("weather.always-thundering", false);
disableMushroomSpread = getBoolean("dynamics.disable-mushroom-spread", false);
disableIceMelting = getBoolean("dynamics.disable-ice-melting", false);
disableSnowMelting = getBoolean("dynamics.disable-snow-melting", false);
disableSnowFormation = getBoolean("dynamics.disable-snow-formation", false);
disableIceFormation = getBoolean("dynamics.disable-ice-formation", false);
disableLeafDecay = getBoolean("dynamics.disable-leaf-decay", false);
useRegions = getBoolean("regions.enable", true);
highFreqFlags = getBoolean("regions.high-frequency-flags", false);
regionWand = getInt("regions.wand", 287);
@@ -397,7 +421,11 @@ public class WorldConfiguration {
}
}
config.setHeader(CONFIG_HEADER);
try {
config.setHeader(CONFIG_HEADER);
} catch (Throwable t) {
}
config.save();
}
@@ -83,6 +83,7 @@ public class WorldGuardBlockListener extends BlockListener {
registerEvent("LEAVES_DECAY", Priority.High);
registerEvent("BLOCK_FORM", Priority.High);
registerEvent("BLOCK_SPREAD", Priority.High);
registerEvent("BLOCK_FADE", Priority.High);
}
/**
@@ -652,15 +653,23 @@ public class WorldGuardBlockListener extends BlockListener {
}
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
if (cfg.activityHaltToggle) {
event.setCancelled(true);
return;
}
if (!plugin.getGlobalRegionManager().allows(DefaultFlag.SNOW_FALL,
event.getBlock().getLocation())) {
if (wcfg.disableSnowFormation) {
event.setCancelled(true);
return;
}
if (wcfg.useRegions) {
if (!plugin.getGlobalRegionManager().allows(DefaultFlag.SNOW_FALL,
event.getBlock().getLocation())) {
event.setCancelled(true);
}
}
}
@@ -671,14 +680,23 @@ public class WorldGuardBlockListener extends BlockListener {
}
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
if (cfg.activityHaltToggle) {
event.setCancelled(true);
return;
}
if (!plugin.getGlobalRegionManager().allows(DefaultFlag.LEAF_DECAY, event.getBlock().getLocation())) {
if (wcfg.disableLeafDecay) {
event.setCancelled(true);
return;
}
if (wcfg.useRegions) {
if (!plugin.getGlobalRegionManager().allows(DefaultFlag.LEAF_DECAY,
event.getBlock().getLocation())) {
event.setCancelled(true);
}
}
}
@@ -686,23 +704,77 @@ public class WorldGuardBlockListener extends BlockListener {
* Called when a block is formed based on world conditions.
*/
public void onBlockForm(BlockFormEvent event) {
if (event.isCancelled()) {
return;
}
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
if (cfg.activityHaltToggle) {
event.setCancelled(true);
return;
}
Material type = event.getNewState().getType();
if (wcfg.disableIceFormation && type == Material.ICE) {
event.setCancelled(true);
return;
}
if (wcfg.disableSnowFormation && type == Material.SNOW) {
event.setCancelled(true);
return;
}
}
/**
* Called when a block spreads based on world conditions.
*/
public void onBlockSpread(BlockSpreadEvent event) {
if (event.isCancelled()) {
return;
}
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
if (cfg.activityHaltToggle) {
event.setCancelled(true);
return;
}
Material fromType = event.getSource().getType();
if (wcfg.disableMushroomSpread && (fromType == Material.RED_MUSHROOM
|| fromType == Material.BROWN_MUSHROOM)) {
event.setCancelled(true);
return;
}
}
/**
* Called when a block fades.
*/
public void onBlockFade(BlockFadeEvent event) {
if (event.isCancelled()) {
return;
}
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
Material type = event.getBlock().getType();
if (wcfg.disableIceMelting && type == Material.ICE) {
event.setCancelled(true);
return;
}
if (wcfg.disableSnowMelting && type == Material.SNOW) {
event.setCancelled(true);
return;
}
}
}
@@ -19,6 +19,8 @@
package com.sk89q.worldguard.bukkit;
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
import com.sk89q.worldguard.blacklist.events.BlockBreakBlacklistEvent;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
@@ -35,7 +37,6 @@ import org.bukkit.event.painting.PaintingPlaceEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.PluginManager;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BlockType;
import com.sk89q.worldguard.blacklist.events.ItemUseBlacklistEvent;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
@@ -73,6 +74,7 @@ public class WorldGuardEntityListener extends EntityListener {
PluginManager pm = plugin.getServer().getPluginManager();
registerEvent("ENTITY_DAMAGE", Priority.High);
registerEvent("ENTITY_COMBUST", Priority.High);
registerEvent("ENTITY_EXPLODE", Priority.High);
registerEvent("CREATURE_SPAWN", Priority.High);
registerEvent("ENTITY_INTERACT", Priority.High);
@@ -80,6 +82,7 @@ public class WorldGuardEntityListener extends EntityListener {
registerEvent("PIG_ZAP", Priority.High);
registerEvent("PAINTING_BREAK", Priority.High);
registerEvent("PAINTING_PLACE", Priority.High);
registerEvent("ENTITY_REGAIN_HEALTH", Priority.High);
}
/**
@@ -154,7 +157,7 @@ public class WorldGuardEntityListener extends EntityListener {
}
if (wcfg.teleportOnVoid && type == DamageCause.VOID) {
findFreePosition(player);
BukkitUtil.findFreePosition(player);
event.setCancelled(true);
return;
}
@@ -391,7 +394,7 @@ public class WorldGuardEntityListener extends EntityListener {
}
if (wcfg.teleportOnSuffocation && type == DamageCause.SUFFOCATION) {
findFreePosition(player);
BukkitUtil.findFreePosition(player);
event.setCancelled(true);
return;
}
@@ -403,6 +406,29 @@ public class WorldGuardEntityListener extends EntityListener {
}
}
/**
* Called on entity combust.
*/
@Override
public void onEntityCombust(EntityCombustEvent event) {
if (event.isCancelled()) {
return;
}
Entity entity = event.getEntity();
ConfigurationManager cfg = plugin.getGlobalStateManager();
if (entity instanceof Player) {
Player player = (Player) entity;
if (cfg.hasGodMode(player)) {
event.setCancelled(true);
return;
}
}
}
/**
* Called on entity explode.
*/
@@ -597,6 +623,15 @@ public class WorldGuardEntityListener extends EntityListener {
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(world);
if (wcfg.getBlacklist() != null) {
if (!wcfg.getBlacklist().check(
new BlockBreakBlacklistEvent(plugin.wrapPlayer(player),
toVector(player.getLocation()), 321), false, false)) {
event.setCancelled(true);
return;
}
}
if (wcfg.useRegions) {
if (!plugin.getGlobalRegionManager().canBuild(player, painting.getLocation())) {
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
@@ -618,6 +653,15 @@ public class WorldGuardEntityListener extends EntityListener {
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(world);
if (wcfg.getBlacklist() != null) {
if (!wcfg.getBlacklist().check(
new ItemUseBlacklistEvent(plugin.wrapPlayer(player),
toVector(player.getLocation()), 321), false, false)) {
event.setCancelled(true);
return;
}
}
if (wcfg.useRegions) {
if (!plugin.getGlobalRegionManager().canBuild(player, placedOn.getLocation())) {
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
@@ -626,48 +670,21 @@ public class WorldGuardEntityListener extends EntityListener {
}
}
}
/**
* Find a position for the player to stand that is not inside a block.
* Blocks above the player will be iteratively tested until there is
* a series of two free blocks. The player will be teleported to
* that free position.
*
* @param player
* Called on entity health regain.
*/
public void findFreePosition(Player player) {
Location loc = player.getLocation();
int x = loc.getBlockX();
int y = Math.max(0, loc.getBlockY());
int origY = y;
int z = loc.getBlockZ();
World world = player.getWorld();
public void onEntityRegainHealth(EntityRegainHealthEvent event) {
Entity ent = event.getEntity();
World world = ent.getWorld();
byte free = 0;
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(world);
while (y <= 129) {
if (BlockType.canPassThrough(world.getBlockTypeIdAt(x, y, z))) {
free++;
} else {
free = 0;
}
if (free == 2) {
if (y - 1 != origY || y == 1) {
loc.setX(x + 0.5);
loc.setY(y);
loc.setZ(z + 0.5);
if (y <= 2 && world.getBlockAt(x,0,z).getType() == Material.AIR) {
world.getBlockAt(x,0,z).setTypeId(20);
loc.setY(2);
}
player.setFallDistance(0F);
player.teleport(loc);
}
return;
}
y++;
if (wcfg.disableHealthRegain) {
event.setCancelled(true);
return;
}
}
}
@@ -20,8 +20,11 @@ package com.sk89q.worldguard.bukkit;
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
import java.util.Iterator;
import java.util.Set;
import java.util.logging.Logger;
import com.sk89q.worldedit.blocks.BlockType;
import com.sk89q.worldguard.protection.flags.RegionGroupFlag;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
@@ -84,6 +87,7 @@ public class WorldGuardPlayerListener extends PlayerListener {
registerEvent("PLAYER_ITEM_HELD", Priority.High);
registerEvent("PLAYER_BED_ENTER", Priority.High);
registerEvent("PLAYER_MOVE", Priority.High);
registerEvent("PLAYER_COMMAND_PREPROCESS", Priority.High);
}
/**
@@ -129,6 +133,7 @@ public class WorldGuardPlayerListener extends PlayerListener {
@Override
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
World world = player.getWorld();
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(player.getWorld());
@@ -160,13 +165,23 @@ public class WorldGuardPlayerListener extends PlayerListener {
+ "Fire spread is currently globally disabled for this world.");
}
if (plugin.inGroup(player, "wg-invincible")) {
if (plugin.inGroup(player, "wg-invincible")
|| (cfg.autoGodMode && plugin.hasPermission(player, "worldguard.auto-invincible"))) {
cfg.enableGodMode(player);
}
if (plugin.inGroup(player, "wg-amphibious")) {
cfg.enableAmphibiousMode(player);
}
if (wcfg.useRegions) {
PlayerFlagState state = plugin.getFlagStateManager().getState(player);
Location loc = player.getLocation();
state.lastWorld = loc.getWorld();
state.lastBlockX = loc.getBlockX();
state.lastBlockY = loc.getBlockY();
state.lastBlockZ = loc.getBlockZ();
}
}
/**
@@ -175,8 +190,41 @@ public class WorldGuardPlayerListener extends PlayerListener {
@Override
public void onPlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();
World world = player.getWorld();
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(world);
// This is to make the enter/exit flags accurate -- move events are not
// sent constantly, so it is possible to move just a little enough to
// not trigger the event and then rejoin so that you are then considered
// outside the border. This should work around that.
if (wcfg.useRegions) {
boolean hasBypass = plugin.getGlobalRegionManager().hasBypass(player, world);
PlayerFlagState state = plugin.getFlagStateManager().getState(player);
if (state.lastWorld != null && !hasBypass) {
LocalPlayer localPlayer = plugin.wrapPlayer(player);
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
Location loc = player.getLocation();
Vector pt = new Vector(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
if (state.lastExitAllowed == null) {
state.lastExitAllowed = set.allows(DefaultFlag.EXIT, localPlayer);
}
if (!state.lastExitAllowed || !set.allows(DefaultFlag.ENTRY, localPlayer)) {
// Only if we have the last location cached
if (state.lastWorld.equals(world)) {
Location newLoc = new Location(world, state.lastBlockX + 0.5,
state.lastBlockY, state.lastBlockZ + 0.5);
player.teleport(newLoc);
}
}
}
}
cfg.forgetPlayer(plugin.wrapPlayer(player));
plugin.forgetPlayer(player);
}
@@ -234,10 +282,43 @@ public class WorldGuardPlayerListener extends PlayerListener {
|| event.getFrom().getBlockY() != event.getTo().getBlockY()
|| event.getFrom().getBlockZ() != event.getTo().getBlockZ()) {
PlayerFlagState state = plugin.getFlagStateManager().getState(player);
LocalPlayer localPlayer = plugin.wrapPlayer(player);
boolean hasBypass = plugin.getGlobalRegionManager().hasBypass(player, world);
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
Vector pt = toVector(event.getTo());
Vector pt = new Vector(event.getTo().getBlockX(), event.getTo().getBlockY(), event.getTo().getBlockZ());
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
boolean entryAllowed = set.allows(DefaultFlag.ENTRY, localPlayer);
if (!hasBypass && !entryAllowed) {
player.sendMessage(ChatColor.DARK_RED + "You are not permitted to enter this area.");
Location newLoc = event.getFrom();
newLoc.setX(newLoc.getBlockX() + 0.5);
newLoc.setY(newLoc.getBlockY());
newLoc.setZ(newLoc.getBlockZ() + 0.5);
event.setTo(newLoc);
return;
}
// Have to set this state
if (state.lastExitAllowed == null) {
state.lastExitAllowed = mgr.getApplicableRegions(toVector(event.getFrom()))
.allows(DefaultFlag.EXIT, localPlayer);
}
boolean exitAllowed = set.allows(DefaultFlag.EXIT, localPlayer);
if (!hasBypass && exitAllowed && !state.lastExitAllowed) {
player.sendMessage(ChatColor.DARK_RED + "You are not permitted to leave this area.");
Location newLoc = event.getFrom();
newLoc.setX(newLoc.getBlockX() + 0.5);
newLoc.setY(newLoc.getBlockY());
newLoc.setZ(newLoc.getBlockZ() + 0.5);
event.setTo(newLoc);
return;
}
String greeting = set.getFlag(DefaultFlag.GREET_MESSAGE);
String farewell = set.getFlag(DefaultFlag.FAREWELL_MESSAGE);
Boolean notifyEnter = set.getFlag(DefaultFlag.NOTIFY_ENTER);
@@ -245,12 +326,16 @@ public class WorldGuardPlayerListener extends PlayerListener {
if (state.lastFarewell != null && (farewell == null
|| !state.lastFarewell.equals(farewell))) {
player.sendMessage(ChatColor.AQUA + " ** " + state.lastFarewell);
String replacedFarewell = plugin.replaceMacros(
player, BukkitUtil.replaceColorMacros(state.lastFarewell));
player.sendMessage(ChatColor.AQUA + " ** " + replacedFarewell);
}
if (greeting != null && (state.lastGreeting == null
|| !state.lastGreeting.equals(greeting))) {
player.sendMessage(ChatColor.AQUA + " ** " + greeting);
String replacedGreeting = plugin.replaceMacros(
player, BukkitUtil.replaceColorMacros(greeting));
player.sendMessage(ChatColor.AQUA + " ** " + replacedGreeting);
}
if ((notifyLeave == null || !notifyLeave)
@@ -282,6 +367,11 @@ public class WorldGuardPlayerListener extends PlayerListener {
state.lastFarewell = farewell;
state.notifiedForEnter = notifyEnter;
state.notifiedForLeave = notifyLeave;
state.lastExitAllowed = exitAllowed;
state.lastWorld = event.getTo().getWorld();
state.lastBlockX = event.getTo().getBlockX();
state.lastBlockY = event.getTo().getBlockY();
state.lastBlockZ = event.getTo().getBlockZ();
}
}
}
@@ -819,15 +909,9 @@ public class WorldGuardPlayerListener extends PlayerListener {
if (group != null) {
LocalPlayer localPlayer = plugin.wrapPlayer(player);
if (group == RegionGroup.OWNERS) {
if (set.isOwnerOfAll(localPlayer)) {
event.setRespawnLocation(spawnLoc);
}
} else if (group == RegionGroup.MEMBERS) {
if (set.isMemberOfAll(localPlayer)) {
event.setRespawnLocation(spawnLoc);
}
if (RegionGroupFlag.isMember(set, group, localPlayer)) {
event.setRespawnLocation(spawnLoc);
}
} else {
event.setRespawnLocation(spawnLoc);
@@ -885,4 +969,37 @@ public class WorldGuardPlayerListener extends PlayerListener {
}
}
}
/**
* Called on command run.
*/
@Override
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
Player player = event.getPlayer();
World world = player.getWorld();
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(world);
if (wcfg.useRegions && !plugin.getGlobalRegionManager().hasBypass(player, world)) {
Vector pt = toVector(player.getLocation());
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
String[] parts = event.getMessage().split(" ");
Set<String> allowedCommands = set.getFlag(DefaultFlag.ALLOWED_CMDS);
if (allowedCommands != null && !allowedCommands.contains(parts[0].toLowerCase())) {
player.sendMessage(ChatColor.RED + parts[0].toLowerCase() + " is not allowed in this area.");
event.setCancelled(true);
return;
}
Set<String> blockedCommands = set.getFlag(DefaultFlag.BLOCKED_CMDS);
if (blockedCommands != null && blockedCommands.contains(parts[0].toLowerCase())) {
player.sendMessage(ChatColor.RED + parts[0].toLowerCase() + " is blocked in this area.");
event.setCancelled(true);
return;
}
}
}
}
@@ -19,6 +19,7 @@
package com.sk89q.worldguard.bukkit;
import com.sk89q.worldguard.protection.managers.RegionManager;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
@@ -735,4 +736,43 @@ public class WorldGuardPlugin extends JavaPlugin {
public boolean canBuild(Player player, Block block) {
return getGlobalRegionManager().canBuild(player, block);
}
/**
* Gets the region manager for a world.
*
* @param world world to get the region manager for
* @return the region manager or null if regions are not enabled
*/
public RegionManager getRegionManager(World world) {
if (!getGlobalStateManager().get(world).useRegions) {
return null;
}
return getGlobalRegionManager().get(world);
}
/**
* Replace macros in the text.
*
* @param sender
* @param message
* @return
*/
public String replaceMacros(CommandSender sender, String message) {
Player[] online = getServer().getOnlinePlayers();
message = message.replace("%name%", toName(sender));
message = message.replace("%id%", toUniqueName(sender));
message = message.replace("%online%", String.valueOf(online.length));
if (sender instanceof Player) {
Player player = (Player) sender;
World world = player.getWorld();
message = message.replace("%world%", world.getName());
message = message.replace("%health%", String.valueOf(player.getHealth()));
}
return message;
}
}
@@ -237,10 +237,12 @@ public class RegionCommands {
WorldConfiguration wcfg = plugin.getGlobalStateManager().get(player.getWorld());
RegionManager mgr = plugin.getGlobalRegionManager().get(sel.getWorld());
// Check whether the player has created too many regions
if (wcfg.maxRegionCountPerPlayer >= 0
&& mgr.getRegionCountOfPlayer(localPlayer) >= wcfg.maxRegionCountPerPlayer) {
throw new CommandException("You own too many regions, delete one first to claim a new one.");
if (!plugin.hasPermission(sender, "worldguard.region.unlimited")) {
// Check whether the player has created too many regions
if (wcfg.maxRegionCountPerPlayer >= 0
&& mgr.getRegionCountOfPlayer(localPlayer) >= wcfg.maxRegionCountPerPlayer) {
throw new CommandException("You own too many regions, delete one first to claim a new one.");
}
}
ProtectedRegion existing = mgr.getRegion(id);
@@ -289,11 +291,13 @@ public class RegionCommands {
}
}*/
if (region.volume() > wcfg.maxClaimVolume) {
player.sendMessage(ChatColor.RED + "This region is to large to claim.");
player.sendMessage(ChatColor.RED +
"Max. volume: " + wcfg.maxClaimVolume + ", your volume: " + region.volume());
return;
if (!plugin.hasPermission(sender, "worldguard.region.unlimited")) {
if (region.volume() > wcfg.maxClaimVolume) {
player.sendMessage(ChatColor.RED + "This region is too large to claim.");
player.sendMessage(ChatColor.RED +
"Max. volume: " + wcfg.maxClaimVolume + ", your volume: " + region.volume());
return;
}
}
region.getOwners().addPlayer(player.getName());
@@ -434,6 +438,11 @@ public class RegionCommands {
+ owners.toUserFriendlyString());
sender.sendMessage(ChatColor.LIGHT_PURPLE + "Members: "
+ members.toUserFriendlyString());
BlockVector min = region.getMinimumPoint();
BlockVector max = region.getMaximumPoint();
String c = "(" + min.getBlockX() + "," + min.getBlockY() + "," + min.getBlockZ() + ")";
c += " (" +max.getBlockX() + "," + max.getBlockY() + "," + max.getBlockZ() + ")";
sender.sendMessage(ChatColor.LIGHT_PURPLE + "Bounds: " + c);
}
@Command(aliases = {"list"},
@@ -49,10 +49,6 @@ public class RegionMemberCommands {
LocalPlayer localPlayer = plugin.wrapPlayer(player);
String id = args.getString(0);
if (id.equalsIgnoreCase("__global__")) {
throw new CommandException("The region cannot be named __global__");
}
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
ProtectedRegion region = mgr.getRegion(id);
@@ -94,10 +90,6 @@ public class RegionMemberCommands {
LocalPlayer localPlayer = plugin.wrapPlayer(player);
String id = args.getString(0);
if (id.equalsIgnoreCase("__global__")) {
throw new CommandException("The region cannot be named __global__");
}
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
ProtectedRegion region = mgr.getRegion(id);
@@ -139,10 +131,6 @@ public class RegionMemberCommands {
LocalPlayer localPlayer = plugin.wrapPlayer(player);
String id = args.getString(0);
if (id.equalsIgnoreCase("__global__")) {
throw new CommandException("The region cannot be named __global__");
}
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
ProtectedRegion region = mgr.getRegion(id);
@@ -184,10 +172,6 @@ public class RegionMemberCommands {
LocalPlayer localPlayer = plugin.wrapPlayer(player);
String id = args.getString(0);
if (id.equalsIgnoreCase("__global__")) {
throw new CommandException("The region cannot be named __global__");
}
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
ProtectedRegion region = mgr.getRegion(id);
@@ -81,7 +81,7 @@ public class DefaultDomain implements Domain {
}
public int size() {
return groups.size();
return groups.size() + players.size();
}
public String toPlayersString() {
@@ -31,8 +31,12 @@ import java.util.Set;
import com.sk89q.worldguard.LocalPlayer;
/**
* Represents a setFlag of regions and their rules as applied to one point or
* region.
* Represents a set of regions for a particular point or area and the rules
* that are represented by that set. An instance of this can be used to
* query the value of a flag or check if a player can build in the respective
* region or point. This object contains the list of applicable regions and so
* the expensive search of regions that are in the desired area has already
* been completed.
*
* @author sk89q
*/
@@ -57,37 +61,57 @@ public class ApplicableRegionSet implements Iterable<ProtectedRegion> {
* Checks if a player can build in an area.
*
* @param player
* @return
* @return build ability
*/
public boolean canBuild(LocalPlayer player) {
return internalGetState(DefaultFlag.BUILD, player);
return internalGetState(DefaultFlag.BUILD, player, null, null);
}
/**
* Checks if a player can build in an area.
* Checks if a player can use buttons and such in an area.
*
* @param player
* @return
* @return able to use items
*/
public boolean canUse(LocalPlayer player) {
return internalGetState(DefaultFlag.USE, player);
return !allows(DefaultFlag.USE, player)
&& !canBuild(player);
}
/**
* Gets the state of a state flag. This cannot be used for the build flag.
*
* @param flag flag to check
* @return whether it is allowed
* @throws IllegalArgumentException if the build flag is given
*/
public boolean allows(StateFlag flag) {
if (flag == DefaultFlag.BUILD) {
throw new IllegalArgumentException("Can't use build flag with allows()");
}
return internalGetState(flag, null, null, null);
}
/**
* Gets the state of a state flag. This cannot be used for the build flag.
*
* @param flag
* @return
* @param flag flag to check
* @param player player (used by some flags)
* @return whether the state is allows for it
* @throws IllegalArgumentException if the build flag is given
*/
public boolean allows(StateFlag flag) {
return internalGetState(flag, null);
public boolean allows(StateFlag flag, LocalPlayer player) {
if (flag == DefaultFlag.BUILD) {
throw new IllegalArgumentException("Can't use build flag with allows()");
}
return internalGetState(flag, null, flag.getGroupFlag(), player);
}
/**
* Indicates whether a player is an owner of all regions in this set.
*
* @param player
* @return
* @param player player
* @return whether the player is an owner of all regions
*/
public boolean isOwnerOfAll(LocalPlayer player) {
for (ProtectedRegion region : applicable) {
@@ -103,8 +127,8 @@ public class ApplicableRegionSet implements Iterable<ProtectedRegion> {
* Indicates whether a player is an owner or member of all regions in
* this set.
*
* @param player
* @return
* @param player player
* @return whether the player is a member of all regions
*/
public boolean isMemberOfAll(LocalPlayer player) {
for (ProtectedRegion region : applicable) {
@@ -119,24 +143,37 @@ public class ApplicableRegionSet implements Iterable<ProtectedRegion> {
/**
* Checks to see if a flag is permitted.
*
* @param def
* default state if there are no regions defined
* @param player
* null to not check owners and members
* @param flag flag to check
* @param player null to not check owners and members
* @param groupFlag group flag to check
* @param groupPlayer player to use for the group flag check
* @return
*/
private boolean internalGetState(StateFlag flag, LocalPlayer player) {
private boolean internalGetState(StateFlag flag, LocalPlayer player,
RegionGroupFlag groupFlag,
LocalPlayer groupPlayer) {
boolean found = false;
boolean hasFlagDefined = false;
boolean allowed = false; // Used for ALLOW override
boolean def = flag.getDefault();
// Handle defaults
if (globalRegion != null) {
State globalState = globalRegion.getFlag(flag);
// The global region has this flag set
if (globalState != null) {
def = (globalState == State.ALLOW);
// Build flag is very special
if (player != null && globalRegion.hasMembersOrOwners()) {
def = globalRegion.isMember(player) && (globalState == State.ALLOW);
} else {
def = (globalState == State.ALLOW);
}
} else {
// Build flag is very special
if (player != null && globalRegion.hasMembersOrOwners()) {
def = globalRegion.isMember(player);
}
}
}
@@ -175,7 +212,7 @@ public class ApplicableRegionSet implements Iterable<ProtectedRegion> {
ProtectedRegion region = it.next();
// Ignore lower priority regions
if (found && region.getPriority() < lastPriority) {
if (hasFlagDefined && region.getPriority() < lastPriority) {
break;
}
@@ -186,6 +223,17 @@ public class ApplicableRegionSet implements Iterable<ProtectedRegion> {
&& region.getFlag(DefaultFlag.PASSTHROUGH) == State.ALLOW) {
continue;
}
// Check group permissions
if (groupPlayer != null && groupFlag != null) {
RegionGroupFlag.RegionGroup group = region.getFlag(groupFlag);
if (group == null) {
group = groupFlag.getDefault();
}
if (!RegionGroupFlag.isMember(region, group, groupPlayer)) {
continue;
}
}
State v = region.getFlag(flag);
@@ -199,6 +247,7 @@ public class ApplicableRegionSet implements Iterable<ProtectedRegion> {
if (v == State.ALLOW) {
allowed = true;
found = true;
hasFlagDefined = true;
continue;
}
@@ -206,6 +255,8 @@ public class ApplicableRegionSet implements Iterable<ProtectedRegion> {
// on membership, so we have to check for parent-child
// relationships
if (player != null) {
hasFlagDefined = true;
if (hasCleared.contains(region)) {
// Already cleared, so do nothing
} else {
@@ -246,14 +297,18 @@ public class ApplicableRegionSet implements Iterable<ProtectedRegion> {
}
/**
* Gets the value of a flag. Do not use this for state flags.
* Gets the value of a flag. Do not use this for state flags
* (use {@link #allows(StateFlag, LocalPlayer)} for that).
*
* @param flag
* @param <T>
* @param <V>
* @return
* @param flag flag to check
* @return value of the flag
* @throws IllegalArgumentException if a StateFlag is given
*/
public <T extends Flag<V>, V> V getFlag(T flag) {
if (flag instanceof StateFlag) {
throw new IllegalArgumentException("Cannot use StateFlag with getFlag()");
}
int lastPriority = 0;
boolean found = false;
@@ -276,9 +331,10 @@ public class ApplicableRegionSet implements Iterable<ProtectedRegion> {
clearParents(needsClear, hasCleared, region);
needsClear.put(region, region.getFlag(flag));
found = true;
}
found = true;
lastPriority = region.getPriority();
}
@@ -208,6 +208,18 @@ public class GlobalRegionManager {
return manager;
}
/**
* Returns whether the player can bypass.
*
* @param player
* @param world
* @return
*/
public boolean hasBypass(LocalPlayer player, World world) {
return player.hasPermission("worldguard.region.bypass."
+ world.getName());
}
/**
* Returns whether the player can bypass.
@@ -225,6 +225,17 @@ public class YAMLDatabase extends AbstractProtectionDatabase {
}
}
config.setHeader("#\r\n" +
"# WorldGuard regions file\r\n" +
"#\r\n" +
"# WARNING: THIS FILE IS AUTOMATICALLY GENERATED. If you modify this file by\r\n" +
"# hand, be aware that A SINGLE MISTYPED CHARACTER CAN CORRUPT THE FILE. If\r\n" +
"# WorldGuard is unable to parse the file, your regions will FAIL TO LOAD and\r\n" +
"# the contents of this file will reset. Please use a YAML validator such as\r\n" +
"# http://yaml-online-parser.appspot.com (for smaller files).\r\n" +
"#\r\n" +
"# REMEMBER TO KEEP PERIODICAL BACKUPS.\r\n" +
"#");
config.save();
}
@@ -0,0 +1,62 @@
// $Id$
/*
* WorldGuard
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.protection.flags;
import org.bukkit.command.CommandSender;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
/**
*
* @author sk89q
*/
public class CommandStringFlag extends Flag<String> {
public CommandStringFlag(String name, char legacyCode) {
super(name, legacyCode);
}
public CommandStringFlag(String name) {
super(name);
}
@Override
public String parseInput(WorldGuardPlugin plugin, CommandSender sender,
String input) throws InvalidFlagFormat {
input = input.trim();
if (!input.startsWith("/")) {
input = "/" + input;
}
return input.toLowerCase();
}
@Override
public String unmarshal(Object o) {
if (o instanceof String) {
return (String) o;
} else {
return null;
}
}
@Override
public Object marshal(String o) {
return o;
}
}
@@ -21,8 +21,6 @@ package com.sk89q.worldguard.protection.flags;
import org.bukkit.entity.CreatureType;
import java.util.Set;
/**
*
* @author sk89q
@@ -49,6 +47,10 @@ public final class DefaultFlag {
public static final StateFlag PLACE_VEHICLE = new StateFlag("vehicle-place", false);
public static final StateFlag SNOW_FALL = new StateFlag("snow-fall", true);
public static final StateFlag LEAF_DECAY = new StateFlag("leaf-decay", true);
public static final StateFlag ENTRY = new StateFlag("entry", true);
public static final RegionGroupFlag ENTRY_PERM = new RegionGroupFlag("entry-group", RegionGroupFlag.RegionGroup.NON_MEMBERS);
public static final StateFlag EXIT = new StateFlag("exit", true);
public static final RegionGroupFlag EXIT_PERM = new RegionGroupFlag("exit-group", RegionGroupFlag.RegionGroup.NON_MEMBERS);
public static final StringFlag GREET_MESSAGE = new StringFlag("greeting");
public static final StringFlag FAREWELL_MESSAGE = new StringFlag("farewell");
public static final BooleanFlag NOTIFY_ENTER = new BooleanFlag("notify-enter");
@@ -57,11 +59,13 @@ public final class DefaultFlag {
public static final IntegerFlag HEAL_DELAY = new IntegerFlag("heal-delay");
public static final IntegerFlag HEAL_AMOUNT = new IntegerFlag("heal-amount");
public static final VectorFlag TELE_LOC = new VectorFlag("teleport");
public static final RegionGroupFlag TELE_PERM = new RegionGroupFlag("teleport-group");
public static final RegionGroupFlag TELE_PERM = new RegionGroupFlag("teleport-group", RegionGroupFlag.RegionGroup.MEMBERS);
public static final VectorFlag SPAWN_LOC = new VectorFlag("spawn");
public static final RegionGroupFlag SPAWN_PERM = new RegionGroupFlag("spawn-group");
public static final RegionGroupFlag SPAWN_PERM = new RegionGroupFlag("spawn-group", RegionGroupFlag.RegionGroup.MEMBERS);
public static final BooleanFlag BUYABLE = new BooleanFlag("buyable");
public static final DoubleFlag PRICE = new DoubleFlag("price");
public static final SetFlag<String> BLOCKED_CMDS = new SetFlag<String>("blocked-cmds", new CommandStringFlag(null));
public static final SetFlag<String> ALLOWED_CMDS = new SetFlag<String>("allowed-cmds", new CommandStringFlag(null));
public static final Flag<?>[] flagsList = new Flag<?>[] {
PASSTHROUGH, BUILD, PVP, MOB_DAMAGE, MOB_SPAWNING, CREEPER_EXPLOSION, SLEEP,
@@ -69,8 +73,13 @@ public final class DefaultFlag {
USE, PLACE_VEHICLE, GREET_MESSAGE, FAREWELL_MESSAGE, NOTIFY_ENTER,
NOTIFY_LEAVE, DENY_SPAWN, HEAL_DELAY, HEAL_AMOUNT, TELE_LOC,
TELE_PERM, SPAWN_LOC, SPAWN_PERM, BUYABLE, PRICE, SNOW_FALL, LEAF_DECAY,
GHAST_FIREBALL
GHAST_FIREBALL, BLOCKED_CMDS, ALLOWED_CMDS, ENTRY, ENTRY_PERM, EXIT, EXIT_PERM
};
static {
ENTRY.setGroupFlag(ENTRY_PERM);
EXIT.setGroupFlag(EXIT_PERM);
}
private DefaultFlag() {
}
@@ -18,6 +18,9 @@
*/
package com.sk89q.worldguard.protection.flags;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import org.bukkit.command.CommandSender;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
@@ -26,18 +29,28 @@ import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
* @author sk89q
*/
public class RegionGroupFlag extends Flag<RegionGroupFlag.RegionGroup> {
public static enum RegionGroup {
MEMBERS,
OWNERS
}
public RegionGroupFlag(String name, char legacyCode) {
super(name, legacyCode);
OWNERS,
NON_MEMBERS,
NON_OWNERS
}
public RegionGroupFlag(String name) {
private RegionGroup def;
public RegionGroupFlag(String name, char legacyCode, RegionGroup def) {
super(name, legacyCode);
this.def = def;
}
public RegionGroupFlag(String name, RegionGroup def) {
super(name);
this.def = def;
}
public RegionGroup getDefault() {
return def;
}
@Override
@@ -49,6 +62,10 @@ public class RegionGroupFlag extends Flag<RegionGroupFlag.RegionGroup> {
return RegionGroup.MEMBERS;
} else if (input.equalsIgnoreCase("owners") || input.equalsIgnoreCase("owner")) {
return RegionGroup.OWNERS;
} else if (input.equalsIgnoreCase("nonowners") || input.equalsIgnoreCase("nonowner")) {
return RegionGroup.NON_OWNERS;
} else if (input.equalsIgnoreCase("nonmembers") || input.equalsIgnoreCase("nonmember")) {
return RegionGroup.NON_MEMBERS;
} else if (input.equalsIgnoreCase("everyone") || input.equalsIgnoreCase("anyone")) {
return null;
} else {
@@ -63,6 +80,10 @@ public class RegionGroupFlag extends Flag<RegionGroupFlag.RegionGroup> {
return RegionGroup.MEMBERS;
} else if (str.equalsIgnoreCase("owners")) {
return RegionGroup.OWNERS;
} else if (str.equalsIgnoreCase("nonmembers")) {
return RegionGroup.NON_MEMBERS;
} else if (str.equalsIgnoreCase("nonowners")) {
return RegionGroup.NON_OWNERS;
} else {
return null;
}
@@ -74,9 +95,58 @@ public class RegionGroupFlag extends Flag<RegionGroupFlag.RegionGroup> {
return "members";
} else if (o == RegionGroup.OWNERS) {
return "owners";
} else if (o == RegionGroup.NON_MEMBERS) {
return "nonmembers";
} else if (o == RegionGroup.NON_OWNERS) {
return "nonowners";
} else {
return null;
}
}
public static boolean isMember(ProtectedRegion region, RegionGroup group, LocalPlayer player) {
if (group == RegionGroupFlag.RegionGroup.OWNERS) {
if (region.isOwner(player)) {
return true;
}
} else if (group == RegionGroupFlag.RegionGroup.MEMBERS) {
if (region.isMember(player)) {
return true;
}
} else if (group == RegionGroupFlag.RegionGroup.NON_OWNERS) {
if (!region.isOwner(player)) {
return true;
}
} else if (group == RegionGroupFlag.RegionGroup.NON_MEMBERS) {
if (!region.isMember(player)) {
return true;
}
}
return false;
}
public static boolean isMember(ApplicableRegionSet set,
RegionGroup group, LocalPlayer player) {
if (group == RegionGroupFlag.RegionGroup.OWNERS) {
if (set.isOwnerOfAll(player)) {
return true;
}
} else if (group == RegionGroupFlag.RegionGroup.MEMBERS) {
if (set.isMemberOfAll(player)) {
return true;
}
} else if (group == RegionGroupFlag.RegionGroup.NON_OWNERS) {
if (!set.isOwnerOfAll(player)) {
return true;
}
} else if (group == RegionGroupFlag.RegionGroup.NON_MEMBERS) {
if (!set.isMemberOfAll(player)) {
return true;
}
}
return false;
}
}
@@ -33,6 +33,7 @@ public class StateFlag extends Flag<StateFlag.State> {
}
private boolean def;
private RegionGroupFlag groupFlag;
public StateFlag(String name, char legacyCode, boolean def) {
super(name, legacyCode);
@@ -48,6 +49,14 @@ public class StateFlag extends Flag<StateFlag.State> {
return def;
}
public RegionGroupFlag getGroupFlag() {
return groupFlag;
}
public void setGroupFlag(RegionGroupFlag groupFlag) {
this.groupFlag = groupFlag;
}
@Override
public State parseInput(WorldGuardPlugin plugin, CommandSender sender,
String input) throws InvalidFlagFormat {
@@ -50,9 +50,10 @@ public abstract class RegionManager {
}
/**
* Load the list of regions.
* Load the list of regions. If the regions do not load properly, then
* the existing list should be used (as stored previously).
*
* @throws IOException
* @throws IOException thrown on load error
*/
public void load() throws IOException {
loader.load(this);
@@ -61,78 +62,86 @@ public abstract class RegionManager {
/**
* Save the list of regions.
*
* @throws IOException
* @throws IOException thrown on save eIf checking multiple flags for a single locationror
*/
public void save() throws IOException {
loader.save(this);
}
/**
* Get a list of protected regions.
* Get a map of protected regions. Use one of the region manager methods
* if possible if working with regions.
*
* @return
* @return map of regions, with keys being region IDs (lowercase)
*/
public abstract Map<String, ProtectedRegion> getRegions();
/**
* Set a list of protected regions.
* Set a list of protected regions. Keys should be lowercase in the given
* map fo regions.
*
* @param regions
* @param regions map of regions
*/
public abstract void setRegions(Map<String, ProtectedRegion> regions);
/**
* Adds a region.
* Adds a region. If a region by the given name already exists, then
* the existing region will be replaced.
*
* @param region
* @param region region to add
*/
public abstract void addRegion(ProtectedRegion region);
/**
* Return whether a region exists by an ID.
*
* @param id
* @return
* @param id id of the region, can be mixed-case
* @return whether the region exists
*/
public abstract boolean hasRegion(String id);
/**
* Get a region by its ID.
*
* @param id
* @return
* @param id id of the region, can be mixed-case
* @return region or null if it doesn't exist
*/
public abstract ProtectedRegion getRegion(String id);
/**
* Removes a region, including inheriting children.
*
* @param id
* @param id id of the region, can be mixed-case
*/
public abstract void removeRegion(String id);
/**
* Get an object for a point for rules to be applied with.
* Get an object for a point for rules to be applied with. Use this
* in order to query for flag data or membership data for a given
* point.
*
* @param pt
* @return
* @param pt point
* @return applicable region set
*/
public abstract ApplicableRegionSet getApplicableRegions(Vector pt);
/**
* Get an object for a point for rules to be applied with.
*
* @param region
* @return
* Get an object for a point for rules to be applied with. This gets
* a set for the given reason.
*
* @deprecated not yet fully supported
* @param region region
* @return regino set
*/
@Deprecated
public abstract ApplicableRegionSet getApplicableRegions(
ProtectedRegion region);
/**
* Get a list of region IDs that contain a point.
*
* @param pt
* @return
* @param pt point
* @return list of region Ids
*/
public abstract List<String> getApplicableRegionsIDs(Vector pt);
@@ -140,25 +149,25 @@ public abstract class RegionManager {
* Returns true if the provided region overlaps with any other region that
* is not owned by the player.
*
* @param region
* @param player
* @return
* @param region region to check
* @param player player to check against
* @return whether there is an overlap
*/
public abstract boolean overlapsUnownedRegion(ProtectedRegion region,
LocalPlayer player);
/**
* Get the number of regions.
*
* @return
*
* @return number of regions
*/
public abstract int size();
/**
* Get the number of regions for a player.
*
* @param player
* @return
*
* @param player player
* @return name number of regions that a player owns
*/
public abstract int getRegionCountOfPlayer(LocalPlayer player);
}
@@ -168,7 +168,6 @@ public abstract class ProtectedRegion implements Comparable<ProtectedRegion> {
* @return the members
*/
public DefaultDomain getMembers() {
return members;
}
@@ -178,12 +177,21 @@ public abstract class ProtectedRegion implements Comparable<ProtectedRegion> {
public void setMembers(DefaultDomain members) {
this.members = members;
}
/**
* Checks whether a region has members or owners.
*
* @return whether there are members or owners
*/
public boolean hasMembersOrOwners() {
return owners.size() > 0 || members.size() > 0;
}
/**
* Checks whether a player is an owner of region or any of its parents.
*
* @param player
* @return
* @param player player to check
* @return whether an owner
*/
public boolean isOwner(LocalPlayer player) {
if (owners.contains(player)) {
@@ -202,12 +210,12 @@ public abstract class ProtectedRegion implements Comparable<ProtectedRegion> {
return false;
}
/**
* Checks whether a player is a member of the region or any of its parents.
* Checks whether a player is a member OR OWNER of the region
* or any of its parents.
*
* @param player
* @return
* @param player player to check
* @return whether an owner or member
*/
public boolean isMember(LocalPlayer player) {
if (owners.contains(player) || members.contains(player)) {
@@ -226,6 +234,30 @@ public abstract class ProtectedRegion implements Comparable<ProtectedRegion> {
return false;
}
/**
* Checks whether a player is a member of the region
* or any of its parents.
*
* @param player player to check
* @return whether an member
*/
public boolean isMemberOnly(LocalPlayer player) {
if (members.contains(player)) {
return true;
}
ProtectedRegion curParent = getParent();
while (curParent != null) {
if (curParent.getMembers().contains(player)) {
return true;
}
curParent = curParent.getParent();
}
return false;
}
/**
* Get a flag's value.
@@ -70,6 +70,7 @@ import org.yaml.snakeyaml.representer.Representer;
public class Configuration extends ConfigurationNode {
private Yaml yaml;
private File file;
private String header = null;
public Configuration(File file) {
super(new HashMap<String, Object>());
@@ -105,31 +106,79 @@ public class Configuration extends ConfigurationNode {
}
}
}
/**
* Saves the configuration to disk.
*
* @throws IOException
* Set the header for the file as a series of lines that are terminated
* by a new line sequence.
*
* @param headerLines header lines to prepend
*/
public void save() throws IOException {
public void setHeader(String... headerLines) {
StringBuilder header = new StringBuilder();
for (String line : headerLines) {
if (header.length() > 0) {
header.append("\r\n");
}
header.append(line);
}
setHeader(header.toString());
}
/**
* Set the header for the file. A header can be provided to prepend the
* YAML data output on configuration save. The header is
* printed raw and so must be manually commented if used. A new line will
* be appended after the header, however, if a header is provided.
*
* @param header header to prepend
*/
public void setHeader(String header) {
this.header = header;
}
/**
* Return the set header.
*
* @return
*/
public String getHeader() {
return header;
}
/**
* Saves the configuration to disk. All errors are clobbered.
*
* @return true if it was successful
*/
public boolean save() {
FileOutputStream stream = null;
File parent = file.getParentFile();
if (parent != null) {
parent.mkdirs();
}
try {
stream = new FileOutputStream(file);
yaml.dump(root, new OutputStreamWriter(stream, "UTF-8"));
} finally {
OutputStreamWriter writer = new OutputStreamWriter(stream, "UTF-8");
if (header != null) {
writer.append(header);
writer.append("\r\n");
}
yaml.dump(root, writer);
return true;
} catch (IOException e) {} finally {
try {
if (stream != null) {
stream.close();
}
} catch (IOException e) {
}
} catch (IOException e) {}
}
return false;
}
@SuppressWarnings("unchecked")
+17 -43
View File
@@ -1,33 +1,17 @@
#
# This is the blacklist for WorldGuard. The blacklist allows you to perform
# actions depending on an item or block ID. Comments start with # and they
# are ignored so you can put your own notes.
# WorldGuard blacklist
#
# --------------------------------------------------------------------------
# The blacklist lets you block actions, blocks, and items from being used.
# You choose a set of "items to affect" and a list of "actions to perform."
#
# WARNING:
# Remember to check the compatibility spreadsheet for WorldGuard to see
# if any events or actions are currently broken in your version of Bukkit.
#
# --------------------------------------------------------------------------
#
# Format:
# [item1,item2]
# option1=options
# event1=whatToDo1,whatToDo2,whatToDo3
# event2=whatToDo1,whatToDo2
###############################################################################
#
# Example to block some ore mining and placement:
# [coalore,goldore,ironore]
# on-break=deny,log,kick
# on-place=deny,tell
#
# Options:
# - ignore-groups (comma-separated list of groups to not affect)
# - comment (message for yourself that is printed with 'log' and 'notify')
# - message (optional message to show the user instead; %s is the item name)
#
# Events:
# Events that you can detect:
# - on-break (when a block of this type is about to be broken)
# - on-destroy-with (the item/block held by the user while destroying)
# - on-place (a block is being placed)
@@ -39,43 +23,33 @@
# Actions (for events):
# - deny (deny completely, used blacklist mode)
# - allow (used in whitelist mode)
# - notify (notify admins)
# - notify (notify admins with the 'worldguard.notify' permission)
# - log (log to console/file/database)
# - tell (tell a player that that's not allowed)
# - kick (kick player)
# - ban (ban player)
#
# Users with the /worldguardnotify permission will receive notifications.
# Options:
# - ignore-groups (comma-separated list of groups to not affect)
# - ignore-perms (comma-separated list of permissions to not affect - make up
# your very own permissions!)
# - comment (message for yourself that is printed with 'log' and 'notify')
# - message (optional message to show the user instead; %s is the item name)
#
# -------------
###############################################################################
#
# You can have the same block or item used in two different sections and
# they will both apply:
# For more information, see:
# http://wiki.sk89q.com/wiki/WorldGuard/Blacklist
#
# [goldblock]
# ignore-groups=vip
# on-break=deny
# [goldblock]
# ignore-groups=admins
# on-break=tell
#
# However, some events override others. For example, if you disable both
# usage of the diamond pickaxe (with the on-destroy-with event) and
# destruction of gold blocks (with the on-break event) and a player tries
# to destroy a gold block with a diamond pickaxe, because the
# on-destroy-with event comes first, the rules for the gold block
# will not be applied (but the player will be denied nevertheless).
#
# --------------------------------------------------------------------------
###############################################################################
#
# Some examples follow.
#
# REMEMBER: If a line has # in front, it will be ignored.
#
# --------------------------------------------------------------------------
# Deny lava buckets
#[lavabucket]
#ignore-perms=my.own.madeup.permission
#ignore-groups=admins,mods
#on-use=deny,tell
@@ -19,8 +19,10 @@
package com.sk89q.worldguard.protection;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.flags.StringFlag;
import com.sk89q.worldguard.protection.managers.FlatRegionManager;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.GlobalProtectedRegion;
@@ -39,140 +41,459 @@ import java.util.ArrayList;
import java.util.HashSet;
public class ApplicableRegionSetTest {
static String COURTYARD_ID = "courtyard";
static String FOUNTAIN_ID = "fountain";
static String NO_FIRE_ID = "nofire";
static String MEMBER_GROUP = "member";
static String COURTYARD_GROUP = "courtyard";
Vector inFountain = new Vector(2, 2, 2);
Vector inCourtyard = new Vector(7, 7, 7);
Vector outside = new Vector(15, 15, 15);
Vector inNoFire = new Vector(150, 150, 150);
RegionManager manager;
ProtectedRegion globalRegion;
ProtectedRegion courtyard;
ProtectedRegion fountain;
TestPlayer player1;
TestPlayer player2;
@Before
public void setUp() throws Exception {
setUpGlobalRegion();
manager = new FlatRegionManager(null);
setUpPlayers();
setUpCourtyardRegion();
setUpFountainRegion();
setUpNoFireRegion();
}
void setUpPlayers() {
player1 = new TestPlayer("tetsu");
player1.addGroup(MEMBER_GROUP);
player1.addGroup(COURTYARD_GROUP);
player2 = new TestPlayer("alex");
player2.addGroup(MEMBER_GROUP);
}
void setUpGlobalRegion() {
globalRegion = new GlobalProtectedRegion("__global__");
}
void setUpCourtyardRegion() {
DefaultDomain domain = new DefaultDomain();
domain.addGroup(COURTYARD_GROUP);
ArrayList<BlockVector2D> points = new ArrayList<BlockVector2D>();
points.add(new BlockVector2D(0, 0));
points.add(new BlockVector2D(10, 0));
points.add(new BlockVector2D(10, 10));
points.add(new BlockVector2D(0, 10));
//ProtectedRegion region = new ProtectedCuboidRegion(COURTYARD_ID, new BlockVector(0, 0, 0), new BlockVector(10, 10, 10));
ProtectedRegion region = new ProtectedPolygonalRegion(COURTYARD_ID, points, 0, 10);
region.setOwners(domain);
manager.addRegion(region);
courtyard = region;
}
void setUpFountainRegion() throws Exception {
DefaultDomain domain = new DefaultDomain();
domain.addGroup(MEMBER_GROUP);
ProtectedRegion region = new ProtectedCuboidRegion(FOUNTAIN_ID,
new BlockVector(0, 0, 0), new BlockVector(5, 5, 5));
region.setMembers(domain);
manager.addRegion(region);
fountain = region;
fountain.setParent(courtyard);
fountain.setFlag(DefaultFlag.FIRE_SPREAD, StateFlag.State.DENY);
}
void setUpNoFireRegion() throws Exception {
ProtectedRegion region = new ProtectedCuboidRegion(NO_FIRE_ID,
new BlockVector(100, 100, 100), new BlockVector(200, 200, 200));
manager.addRegion(region);
region.setFlag(DefaultFlag.FIRE_SPREAD, StateFlag.State.DENY);
}
@Test
public void testNonBuildFlag() {
ApplicableRegionSet appl;
// Outside
appl = manager.getApplicableRegions(outside);
assertTrue(appl.allows(DefaultFlag.FIRE_SPREAD));
// Inside courtyard
appl = manager.getApplicableRegions(inCourtyard);
assertTrue(appl.allows(DefaultFlag.FIRE_SPREAD));
// Inside fountain
appl = manager.getApplicableRegions(inFountain);
assertFalse(appl.allows(DefaultFlag.FIRE_SPREAD));
public void testStateFlagPriorityFallThrough() {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
ProtectedRegion region;
// Inside no fire zone
appl = manager.getApplicableRegions(inNoFire);
assertFalse(appl.allows(DefaultFlag.FIRE_SPREAD));
StateFlag STATE1 = new StateFlag(null, false);
StateFlag STATE2 = new StateFlag(null, false);
StateFlag STATE3 = new StateFlag(null, false);
region = mock.add(0);
region.setFlag(STATE1, StateFlag.State.ALLOW);
region.setFlag(STATE2, StateFlag.State.DENY);
region = mock.add(1);
region.setFlag(STATE1, StateFlag.State.DENY);
region.setFlag(STATE3, StateFlag.State.ALLOW);
ApplicableRegionSet set = mock.getApplicableSet();
assertFalse(set.allows(STATE1));
assertFalse(set.allows(STATE2));
assertTrue(set.allows(STATE3));
}
@Test
public void testPlayer1BuildAccess() {
ApplicableRegionSet appl;
// Outside
appl = manager.getApplicableRegions(outside);
assertTrue(appl.canBuild(player1));
// Inside courtyard
appl = manager.getApplicableRegions(inCourtyard);
assertTrue(appl.canBuild(player1));
// Inside fountain
appl = manager.getApplicableRegions(inFountain);
assertTrue(appl.canBuild(player1));
public void testNonStateFlagPriorityFallThrough() {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
ProtectedRegion region;
StringFlag STRING1 = new StringFlag(null);
StringFlag STRING2 = new StringFlag(null);
StringFlag STRING3 = new StringFlag(null);
StringFlag STRING4 = new StringFlag(null);
region = mock.add(0);
region.setFlag(STRING1, "Beans");
region.setFlag(STRING2, "Apples");
region = mock.add(1);
region.setFlag(STRING1, "Cats");
region.setFlag(STRING3, "Bananas");
ApplicableRegionSet set = mock.getApplicableSet();
assertEquals(set.getFlag(STRING1), "Cats");
assertEquals(set.getFlag(STRING2), "Apples");
assertEquals(set.getFlag(STRING3), "Bananas");
assertEquals(set.getFlag(STRING4), null);
}
@Test
public void testPlayer2BuildAccess() {
ApplicableRegionSet appl;
HashSet<ProtectedRegion> test = new HashSet<ProtectedRegion>();
test.add(courtyard);
test.add(fountain);
System.out.println(test);
// Outside
appl = manager.getApplicableRegions(outside);
assertTrue(appl.canBuild(player2));
// Inside courtyard
appl = manager.getApplicableRegions(inCourtyard);
assertFalse(appl.canBuild(player2));
// Inside fountain
appl = manager.getApplicableRegions(inFountain);
assertTrue(appl.canBuild(player2));
public void testStateFlagMultiplePriorityFallThrough() {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
ProtectedRegion region;
StringFlag STRING1 = new StringFlag(null);
StringFlag STRING2 = new StringFlag(null);
StringFlag STRING3 = new StringFlag(null);
StringFlag STRING4 = new StringFlag(null);
region = mock.add(0);
region.setFlag(STRING1, "Beans");
region.setFlag(STRING2, "Apples");
region.setFlag(STRING3, "Dogs");
region = mock.add(1);
region.setFlag(STRING1, "Cats");
region.setFlag(STRING3, "Bananas");
region = mock.add(10);
region.setFlag(STRING3, "Strings");
ApplicableRegionSet set = mock.getApplicableSet();
assertEquals(set.getFlag(STRING1), "Cats");
assertEquals(set.getFlag(STRING2), "Apples");
assertEquals(set.getFlag(STRING3), "Strings");
assertEquals(set.getFlag(STRING4), null);
}
@Test
public void testStateGlobalDefault() {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
ProtectedRegion region;
StateFlag STATE1 = new StateFlag(null, false);
StateFlag STATE2 = new StateFlag(null, false);
StateFlag STATE3 = new StateFlag(null, false);
StateFlag STATE4 = new StateFlag(null, true);
StateFlag STATE5 = new StateFlag(null, true);
StateFlag STATE6 = new StateFlag(null, true);
region = mock.global();
region.setFlag(STATE1, StateFlag.State.ALLOW);
region.setFlag(STATE2, StateFlag.State.DENY);
region.setFlag(STATE4, StateFlag.State.ALLOW);
region.setFlag(STATE5, StateFlag.State.DENY);
ApplicableRegionSet set = mock.getApplicableSet();
assertTrue(set.allows(STATE1));
assertFalse(set.allows(STATE2));
assertFalse(set.allows(STATE3));
assertTrue(set.allows(STATE4));
assertFalse(set.allows(STATE5));
assertTrue(set.allows(STATE6));
}
@Test
public void testStateGlobalWithRegionsDefault() {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
ProtectedRegion region;
StateFlag STATE1 = new StateFlag(null, false);
StateFlag STATE2 = new StateFlag(null, false);
StateFlag STATE3 = new StateFlag(null, false);
StateFlag STATE4 = new StateFlag(null, true);
StateFlag STATE5 = new StateFlag(null, true);
StateFlag STATE6 = new StateFlag(null, true);
region = mock.global();
region.setFlag(STATE1, StateFlag.State.ALLOW);
region.setFlag(STATE2, StateFlag.State.DENY);
region.setFlag(STATE4, StateFlag.State.ALLOW);
region.setFlag(STATE5, StateFlag.State.DENY);
region = mock.add(0);
region.setFlag(STATE1, StateFlag.State.DENY);
region.setFlag(STATE2, StateFlag.State.DENY);
region.setFlag(STATE4, StateFlag.State.DENY);
region.setFlag(STATE5, StateFlag.State.DENY);
region = mock.add(1);
region.setFlag(STATE5, StateFlag.State.ALLOW);
ApplicableRegionSet set = mock.getApplicableSet();
assertFalse(set.allows(STATE1));
assertFalse(set.allows(STATE2));
assertFalse(set.allows(STATE3));
assertFalse(set.allows(STATE4));
assertTrue(set.allows(STATE5));
assertTrue(set.allows(STATE6));
}
@Test
public void testBuildAccess() {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
ProtectedRegion region;
LocalPlayer member = mock.createPlayer();
LocalPlayer nonMember = mock.createPlayer();
region = mock.add(0);
region.getOwners().addPlayer(member);
ApplicableRegionSet set = mock.getApplicableSet();
assertTrue(set.canBuild(member));
assertFalse(set.canBuild(nonMember));
}
@Test
public void testBuildRegionPriorities() {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
ProtectedRegion region;
LocalPlayer upperMember = mock.createPlayer();
LocalPlayer lowerMember = mock.createPlayer();
LocalPlayer nonMember = mock.createPlayer();
region = mock.add(0);
region.getOwners().addPlayer(lowerMember);
region = mock.add(1);
region.getOwners().addPlayer(upperMember);
ApplicableRegionSet set = mock.getApplicableSet();
assertTrue(set.canBuild(upperMember));
assertFalse(set.canBuild(lowerMember));
assertFalse(set.canBuild(nonMember));
}
@Test
public void testBuildDenyFlag() {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
ProtectedRegion region;
LocalPlayer member = mock.createPlayer();
LocalPlayer nonMember = mock.createPlayer();
region = mock.add(0);
region.getOwners().addPlayer(member);
region.setFlag(DefaultFlag.BUILD, StateFlag.State.DENY);
ApplicableRegionSet set = mock.getApplicableSet();
assertFalse(set.canBuild(member));
assertFalse(set.canBuild(nonMember));
}
@Test
public void testBuildAllowFlag() {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
ProtectedRegion region;
LocalPlayer member = mock.createPlayer();
LocalPlayer nonMember = mock.createPlayer();
region = mock.add(0);
region.getOwners().addPlayer(member);
region.setFlag(DefaultFlag.BUILD, StateFlag.State.ALLOW);
ApplicableRegionSet set = mock.getApplicableSet();
assertTrue(set.canBuild(member));
assertTrue(set.canBuild(nonMember));
}
@Test
public void testHigherPriorityOverrideBuildDenyFlag() {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
ProtectedRegion region;
LocalPlayer member = mock.createPlayer();
LocalPlayer nonMember = mock.createPlayer();
region = mock.add(0);
region.getOwners().addPlayer(member);
region.setFlag(DefaultFlag.BUILD, StateFlag.State.DENY);
region = mock.add(1);
region.setFlag(DefaultFlag.BUILD, StateFlag.State.ALLOW);
ApplicableRegionSet set = mock.getApplicableSet();
assertTrue(set.canBuild(member));
assertTrue(set.canBuild(nonMember));
}
@Test
public void testHigherPriorityUnsetBuildDenyFlag() {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
ProtectedRegion region;
LocalPlayer member = mock.createPlayer();
LocalPlayer nonMember = mock.createPlayer();
region = mock.add(0);
region.getOwners().addPlayer(member);
region.setFlag(DefaultFlag.BUILD, StateFlag.State.DENY);
region = mock.add(1);
ApplicableRegionSet set = mock.getApplicableSet();
assertFalse(set.canBuild(member));
assertFalse(set.canBuild(nonMember));
}
@Test
public void testPriorityDisjointBuildDenyFlagAndMembership() {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
ProtectedRegion region;
LocalPlayer member = mock.createPlayer();
LocalPlayer nonMember = mock.createPlayer();
region = mock.add(0);
region.setFlag(DefaultFlag.BUILD, StateFlag.State.DENY);
region = mock.add(1);
region.getOwners().addPlayer(member);
ApplicableRegionSet set = mock.getApplicableSet();
assertTrue(set.canBuild(member));
assertFalse(set.canBuild(nonMember));
}
@Test
public void testPriorityDisjointBuildDenyFlagAndRegion() {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
ProtectedRegion region;
LocalPlayer member = mock.createPlayer();
LocalPlayer nonMember = mock.createPlayer();
region = mock.add(0);
region.setFlag(DefaultFlag.BUILD, StateFlag.State.DENY);
region = mock.add(1);
ApplicableRegionSet set = mock.getApplicableSet();
assertFalse(set.canBuild(member));
assertFalse(set.canBuild(nonMember));
}
@Test
public void testPriorityDisjointMembershipAndBuildDenyFlag() {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
ProtectedRegion region;
LocalPlayer member = mock.createPlayer();
LocalPlayer nonMember = mock.createPlayer();
region = mock.add(0);
region.getOwners().addPlayer(member);
region = mock.add(1);
region.setFlag(DefaultFlag.BUILD, StateFlag.State.DENY);
ApplicableRegionSet set = mock.getApplicableSet();
assertFalse(set.canBuild(member));
assertFalse(set.canBuild(nonMember));
}
@Test
public void testNoGlobalRegionDefaultBuild() {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
ProtectedRegion region;
LocalPlayer member = mock.createPlayer();
LocalPlayer nonMember = mock.createPlayer();
ApplicableRegionSet set = mock.getApplicableSet();
assertTrue(set.canBuild(member));
assertTrue(set.canBuild(nonMember));
}
@Test
public void testGlobalRegionDefaultBuild() {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
ProtectedRegion region;
region = mock.global();
LocalPlayer member = mock.createPlayer();
LocalPlayer nonMember = mock.createPlayer();
ApplicableRegionSet set = mock.getApplicableSet();
assertTrue(set.canBuild(member));
assertTrue(set.canBuild(nonMember));
}
@Test
public void testGlobalRegionBuildFlagAllow() {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
ProtectedRegion region;
region = mock.global();
region.setFlag(DefaultFlag.BUILD, StateFlag.State.ALLOW);
LocalPlayer member = mock.createPlayer();
LocalPlayer nonMember = mock.createPlayer();
ApplicableRegionSet set = mock.getApplicableSet();
assertTrue(set.canBuild(member));
assertTrue(set.canBuild(nonMember));
}
@Test
public void testGlobalRegionBuildFlagDeny() {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
ProtectedRegion region;
region = mock.global();
region.setFlag(DefaultFlag.BUILD, StateFlag.State.DENY);
LocalPlayer member = mock.createPlayer();
LocalPlayer nonMember = mock.createPlayer();
ApplicableRegionSet set = mock.getApplicableSet();
assertFalse(set.canBuild(member));
assertFalse(set.canBuild(nonMember));
}
@Test
public void testGlobalRegionBuildFlagAllowWithRegion() {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
ProtectedRegion region;
LocalPlayer member = mock.createPlayer();
LocalPlayer nonMember = mock.createPlayer();
region = mock.global();
region.setFlag(DefaultFlag.BUILD, StateFlag.State.ALLOW);
region = mock.add(0);
region.getOwners().addPlayer(member);
ApplicableRegionSet set = mock.getApplicableSet();
assertTrue(set.canBuild(member));
assertFalse(set.canBuild(nonMember));
}
@Test
public void testGlobalRegionBuildFlagDenyWithRegion() {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
ProtectedRegion region;
LocalPlayer member = mock.createPlayer();
LocalPlayer nonMember = mock.createPlayer();
region = mock.global();
region.setFlag(DefaultFlag.BUILD, StateFlag.State.DENY);
region = mock.add(0);
region.getOwners().addPlayer(member);
ApplicableRegionSet set = mock.getApplicableSet();
assertTrue(set.canBuild(member));
assertFalse(set.canBuild(nonMember));
}
@Test
public void testGlobalRegionHavingOwnershipBuildFlagUnset() {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
ProtectedRegion region;
LocalPlayer member = mock.createPlayer();
LocalPlayer nonMember = mock.createPlayer();
region = mock.global();
region.getOwners().addPlayer(member);
ApplicableRegionSet set = mock.getApplicableSet();
assertTrue(set.canBuild(member));
assertFalse(set.canBuild(nonMember));
}
@Test
public void testGlobalRegionHavingOwnershipBuildFlagAllow() {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
ProtectedRegion region;
LocalPlayer member = mock.createPlayer();
LocalPlayer nonMember = mock.createPlayer();
region = mock.global();
region.setFlag(DefaultFlag.BUILD, StateFlag.State.ALLOW);
region.getOwners().addPlayer(member);
ApplicableRegionSet set = mock.getApplicableSet();
assertTrue(set.canBuild(member));
assertFalse(set.canBuild(nonMember));
}
@Test
public void testGlobalRegionHavingOwnershipBuildFlagDeny() {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
ProtectedRegion region;
LocalPlayer member = mock.createPlayer();
LocalPlayer nonMember = mock.createPlayer();
region = mock.global();
region.setFlag(DefaultFlag.BUILD, StateFlag.State.DENY);
region.getOwners().addPlayer(member);
ApplicableRegionSet set = mock.getApplicableSet();
assertFalse(set.canBuild(member));
assertFalse(set.canBuild(nonMember));
}
}
@@ -0,0 +1,80 @@
// $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.worldedit.BlockVector;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.TestPlayer;
import com.sk89q.worldguard.protection.regions.GlobalProtectedRegion;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import java.util.TreeSet;
public class MockApplicableRegionSet {
private TreeSet<ProtectedRegion> regions = new TreeSet<ProtectedRegion>();
private ProtectedRegion global;
private int id = 0;
private int playerIndex = 0;
public void add(ProtectedRegion region) {
regions.add(region);
}
public LocalPlayer createPlayer() {
playerIndex++;
LocalPlayer player = new TestPlayer("#PLAYER_" + playerIndex);
return player;
}
public ProtectedRegion global() {
global = new GlobalProtectedRegion("__global__");
return global;
}
public ProtectedRegion add(int priority) {
ProtectedRegion region = new ProtectedCuboidRegion(getNextId(),
new BlockVector(0, 0, 0), new BlockVector(1, 1, 1));
region.setPriority(priority);
add(region);
return region;
}
public ProtectedRegion add(int priority, ProtectedRegion parent)
throws ProtectedRegion.CircularInheritanceException {
ProtectedRegion region = new ProtectedCuboidRegion(getNextId(),
new BlockVector(0, 0, 0), new BlockVector(1, 1, 1));
region.setPriority(priority);
region.setParent(parent);
add(region);
return region;
}
public ApplicableRegionSet getApplicableSet() {
return new ApplicableRegionSet(regions, global);
}
private String getNextId() {
id++;
return "#REGION_" + id;
}
}
@@ -0,0 +1,179 @@
// $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.worldedit.BlockVector;
import com.sk89q.worldedit.BlockVector2D;
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.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 class RegionOverlapTest {
static String COURTYARD_ID = "courtyard";
static String FOUNTAIN_ID = "fountain";
static String NO_FIRE_ID = "nofire";
static String MEMBER_GROUP = "member";
static String COURTYARD_GROUP = "courtyard";
Vector inFountain = new Vector(2, 2, 2);
Vector inCourtyard = new Vector(7, 7, 7);
Vector outside = new Vector(15, 15, 15);
Vector inNoFire = new Vector(150, 150, 150);
RegionManager manager;
ProtectedRegion globalRegion;
ProtectedRegion courtyard;
ProtectedRegion fountain;
TestPlayer player1;
TestPlayer player2;
@Before
public void setUp() throws Exception {
setUpGlobalRegion();
manager = new FlatRegionManager(null);
setUpPlayers();
setUpCourtyardRegion();
setUpFountainRegion();
setUpNoFireRegion();
}
void setUpPlayers() {
player1 = new TestPlayer("tetsu");
player1.addGroup(MEMBER_GROUP);
player1.addGroup(COURTYARD_GROUP);
player2 = new TestPlayer("alex");
player2.addGroup(MEMBER_GROUP);
}
void setUpGlobalRegion() {
globalRegion = new GlobalProtectedRegion("__global__");
}
void setUpCourtyardRegion() {
DefaultDomain domain = new DefaultDomain();
domain.addGroup(COURTYARD_GROUP);
ArrayList<BlockVector2D> points = new ArrayList<BlockVector2D>();
points.add(new BlockVector2D(0, 0));
points.add(new BlockVector2D(10, 0));
points.add(new BlockVector2D(10, 10));
points.add(new BlockVector2D(0, 10));
//ProtectedRegion region = new ProtectedCuboidRegion(COURTYARD_ID, new BlockVector(0, 0, 0), new BlockVector(10, 10, 10));
ProtectedRegion region = new ProtectedPolygonalRegion(COURTYARD_ID, points, 0, 10);
region.setOwners(domain);
manager.addRegion(region);
courtyard = region;
}
void setUpFountainRegion() throws Exception {
DefaultDomain domain = new DefaultDomain();
domain.addGroup(MEMBER_GROUP);
ProtectedRegion region = new ProtectedCuboidRegion(FOUNTAIN_ID,
new BlockVector(0, 0, 0), new BlockVector(5, 5, 5));
region.setMembers(domain);
manager.addRegion(region);
fountain = region;
fountain.setParent(courtyard);
fountain.setFlag(DefaultFlag.FIRE_SPREAD, StateFlag.State.DENY);
}
void setUpNoFireRegion() throws Exception {
ProtectedRegion region = new ProtectedCuboidRegion(NO_FIRE_ID,
new BlockVector(100, 100, 100), new BlockVector(200, 200, 200));
manager.addRegion(region);
region.setFlag(DefaultFlag.FIRE_SPREAD, StateFlag.State.DENY);
}
@Test
public void testNonBuildFlag() {
ApplicableRegionSet appl;
// Outside
appl = manager.getApplicableRegions(outside);
assertTrue(appl.allows(DefaultFlag.FIRE_SPREAD));
// Inside courtyard
appl = manager.getApplicableRegions(inCourtyard);
assertTrue(appl.allows(DefaultFlag.FIRE_SPREAD));
// Inside fountain
appl = manager.getApplicableRegions(inFountain);
assertFalse(appl.allows(DefaultFlag.FIRE_SPREAD));
// Inside no fire zone
appl = manager.getApplicableRegions(inNoFire);
assertFalse(appl.allows(DefaultFlag.FIRE_SPREAD));
}
@Test
public void testPlayer1BuildAccess() {
ApplicableRegionSet appl;
// Outside
appl = manager.getApplicableRegions(outside);
assertTrue(appl.canBuild(player1));
// Inside courtyard
appl = manager.getApplicableRegions(inCourtyard);
assertTrue(appl.canBuild(player1));
// Inside fountain
appl = manager.getApplicableRegions(inFountain);
assertTrue(appl.canBuild(player1));
}
@Test
public void testPlayer2BuildAccess() {
ApplicableRegionSet appl;
HashSet<ProtectedRegion> test = new HashSet<ProtectedRegion>();
test.add(courtyard);
test.add(fountain);
System.out.println(test);
// Outside
appl = manager.getApplicableRegions(outside);
assertTrue(appl.canBuild(player2));
// Inside courtyard
appl = manager.getApplicableRegions(inCourtyard);
assertFalse(appl.canBuild(player2));
// Inside fountain
appl = manager.getApplicableRegions(inFountain);
assertTrue(appl.canBuild(player2));
}
}
@@ -135,7 +135,7 @@ public class RegionPriorityTest {
appl = manager.getApplicableRegions(inCourtyard);
assertTrue(appl.allows(DefaultFlag.FIRE_SPREAD));
appl = manager.getApplicableRegions(inFountain);
assertTrue(appl.allows(DefaultFlag.FIRE_SPREAD));
assertFalse(appl.allows(DefaultFlag.FIRE_SPREAD));
}
@Test