added multiworld support for regions and json region database

This commit is contained in:
Redecouverte 2011-02-24 11:19:35 +01:00
parent 4505bb6f4e
commit f61a9ab5cc
26 changed files with 1909 additions and 1333 deletions

View File

@ -14,7 +14,7 @@
<include name="Bukkit.jar" />
<include name="WorldEdit.jar" />
<include name="prtree.jar" />
<include name="json-simple-1.1.jar" />
<include name="gson-1.7-SNAPSHOT.jar" />
</fileset>
<target name="init">
@ -47,7 +47,7 @@
<copy tofile="${build.dir}/defaults/blacklist.txt" file="blacklist.txt"/>
<jar jarfile="${dist.dir}/WorldGuard.jar" basedir="${build.dir}" manifest="manifest.mf">
<zipgroupfileset dir="lib" includes="prtree.jar" />
<zipgroupfileset dir="lib" includes="json-simple-1.1.jar" />
<zipgroupfileset dir="lib" includes="gson-1.7-SNAPSHOT.jar" />
</jar>
</target>

BIN
lib/gson-1.7-SNAPSHOT.jar Normal file

Binary file not shown.

Binary file not shown.

View File

@ -27,7 +27,7 @@ dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath=
excludes=
file.reference.Bukkit.jar=lib/Bukkit.jar
file.reference.json-simple-1.1.jar=lib\\json-simple-1.1.jar
file.reference.gson-1.7-SNAPSHOT.jar=lib\\gson-1.7-SNAPSHOT.jar
file.reference.prtree.jar=lib/prtree.jar
file.reference.truezip.jar=lib/truezip.jar
file.reference.WorldEdit.jar=lib/WorldEdit.jar
@ -38,7 +38,7 @@ javac.classpath=\
${file.reference.prtree.jar}:\
${file.reference.truezip.jar}:\
${file.reference.WorldEdit.jar}:\
${file.reference.json-simple-1.1.jar}
${file.reference.gson-1.7-SNAPSHOT.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false

View File

@ -19,6 +19,7 @@
package com.sk89q.worldguard.bukkit;
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
import java.util.Iterator;
import java.util.List;
import org.bukkit.block.Block;
@ -35,7 +36,7 @@
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.blacklist.events.*;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.AreaFlags;
import com.sk89q.worldguard.protection.regions.AreaFlags;
import static com.sk89q.worldguard.bukkit.BukkitUtil.*;
public class WorldGuardBlockListener extends BlockListener {
@ -70,10 +71,8 @@ public void onBlockDamage(BlockDamageEvent event) {
if (plugin.useRegions && blockDamaged.getType() == Material.CAKE_BLOCK) {
Vector pt = toVector(blockDamaged);
LocalPlayer localPlayer = plugin.wrapPlayer(player);
if (!plugin.hasPermission(player, "/regionbypass")
&& !plugin.regionManager.getApplicableRegions(pt).canBuild(localPlayer)) {
if (!plugin.canBuild(player, pt)) {
player.sendMessage(ChatColor.DARK_RED + "You're not invited to this tea party!");
event.setCancelled(true);
@ -105,10 +104,8 @@ public void onBlockBreak(BlockBreakEvent event) {
if (plugin.useRegions) {
Vector pt = BukkitUtil.toVector(event.getBlock());
LocalPlayer localPlayer = plugin.wrapPlayer(player);
if (!plugin.hasPermission(player, "/regionbypass")
&& !plugin.regionManager.getApplicableRegions(pt).canBuild(localPlayer)) {
if (!plugin.canBuild(player, pt)) {
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
event.setCancelled(true);
return;
@ -274,26 +271,26 @@ public void onBlockIgnite(BlockIgniteEvent event) {
LocalPlayer localPlayer = plugin.wrapPlayer(player);
if (cause == IgniteCause.FLINT_AND_STEEL
&& !plugin.regionManager.getApplicableRegions(pt).canBuild(localPlayer)) {
&& !plugin.globalRegionManager.getApplicableRegions(pt).canBuild(localPlayer)) {
event.setCancelled(true);
return;
}
if (cause == IgniteCause.FLINT_AND_STEEL
&& !plugin.regionManager.getApplicableRegions(pt)
&& !plugin.globalRegionManager.getApplicableRegions(pt)
.allowsFlag(AreaFlags.FLAG_LIGHTER)) {
event.setCancelled(true);
return;
}
}
f (isFireSpread && !plugin.regionManager.getApplicableRegions(pt)
f (isFireSpread && !plugin.globalRegionManager.getApplicableRegions(pt)
.allowsFlag(AreaFlags.FLAG_FIRE_SPREAD)) {
event.setCancelled(true);
return;
}
if (cause == IgniteCause.LAVA && !plugin.regionManager.getApplicableRegions(pt)
if (cause == IgniteCause.LAVA && !plugin.globalRegionManager.getApplicableRegions(pt)
.allowsFlag(AreaFlags.FLAG_LAVA_FIRE)) {
event.setCancelled(true);
return;
@ -391,10 +388,11 @@ public void onBlockInteract(BlockInteractEvent event) {
if (plugin.useRegions) {
Vector pt = toVector(block);
LocalPlayer localPlayer = plugin.wrapPlayer(player);
RegionManager mgr = plugin.getGlobalRegionManager().getRegionmanager(player.getWorld().getName());
if (!plugin.hasPermission(player, "/regionbypass")
&& !plugin.regionManager.getApplicableRegions(pt).allowsFlag(AreaFlags.FLAG_CHEST_ACCESS)
&& !plugin.regionManager.getApplicableRegions(pt).canBuild(localPlayer)) {
&& !mgr.getApplicableRegions(pt).allowsFlag(AreaFlags.FLAG_CHEST_ACCESS)
&& !mgr.getApplicableRegions(pt).canBuild(localPlayer)) {
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
event.setCancelled(true);
return;
@ -433,10 +431,8 @@ public void onBlockPlace(BlockPlaceEvent event) {
if (plugin.useRegions) {
Vector pt = toVector(blockPlaced);
LocalPlayer localPlayer = plugin.wrapPlayer(player);
if (!plugin.hasPermission(player, "/regionbypass")
&& !plugin.regionManager.getApplicableRegions(pt).canBuild(localPlayer)) {
if (!plugin.canBuild(player, pt)) {
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
event.setCancelled(true);
return;
@ -478,8 +474,10 @@ public void onBlockRightClick(BlockRightClickEvent event) {
if (plugin.useRegions && event.getItemInHand().getTypeId() == plugin.regionWand) {
Vector pt = toVector(blockClicked);
ApplicableRegionSet app = plugin.regionManager.getApplicableRegions(pt);
List<String> regions = plugin.regionManager.getApplicableRegionsIDs(pt);
RegionManager mgr = plugin.getGlobalRegionManager().getRegionmanager(player.getWorld().getName());
ApplicableRegionSet app = mgr.getApplicableRegions(pt);
List<String> regions = mgr.getApplicableRegionsIDs(pt);
if (regions.size() > 0) {
player.sendMessage(ChatColor.YELLOW + "Can you build? "
@ -504,10 +502,8 @@ public void onBlockRightClick(BlockRightClickEvent event) {
if (plugin.useRegions && type == Material.CAKE_BLOCK) {
Vector pt = toVector(blockClicked);
LocalPlayer localPlayer = plugin.wrapPlayer(player);
if (!plugin.hasPermission(player, "/regionbypass")
&& !plugin.regionManager.getApplicableRegions(pt).canBuild(localPlayer)) {
if (!plugin.canBuild(player, pt)) {
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
byte newData = (byte) (blockClicked.getData() - 1);

View File

@ -19,6 +19,7 @@
package com.sk89q.worldguard.bukkit;
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
@ -32,7 +33,7 @@
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BlockType;
import com.sk89q.worldguard.protection.AreaFlags;
import com.sk89q.worldguard.protection.regions.AreaFlags;
import static com.sk89q.worldguard.bukkit.BukkitUtil.*;
public class WorldGuardEntityListener extends EntityListener {
@ -91,8 +92,9 @@ public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
if (attacker != null && attacker instanceof Player) {
if (plugin.useRegions) {
Vector pt = toVector(defender.getLocation());
if (!plugin.regionManager.getApplicableRegions(pt)
RegionManager mgr = plugin.getGlobalRegionManager().getRegionmanager(player.getWorld().getName());
if (!mgr.getApplicableRegions(pt)
.allowsFlag(AreaFlags.FLAG_PVP)) {
((Player)attacker).sendMessage(ChatColor.DARK_RED + "You are in a no-PvP area.");
event.setCancelled(true);
@ -109,15 +111,16 @@ public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
if (plugin.useRegions) {
Vector pt = toVector(defender.getLocation());
if (!plugin.regionManager.getApplicableRegions(pt)
RegionManager mgr = plugin.getGlobalRegionManager().getRegionmanager(player.getWorld().getName());
if (!mgr.getApplicableRegions(pt)
.allowsFlag(AreaFlags.FLAG_MOB_DAMAGE)) {
event.setCancelled(true);
return;
}
if (attacker instanceof Creeper) {
if (!plugin.regionManager.getApplicableRegions(pt)
if (!mgr.getApplicableRegions(pt)
.allowsFlag(AreaFlags.FLAG_CREEPER_EXPLOSION)) {
event.setCancelled(true);
return;
@ -144,8 +147,9 @@ public void onEntityDamageByProjectile(EntityDamageByProjectileEvent event) {
if (attacker != null && attacker instanceof Player) {
if (plugin.useRegions) {
Vector pt = toVector(defender.getLocation());
if (!plugin.regionManager.getApplicableRegions(pt)
RegionManager mgr = plugin.getGlobalRegionManager().getRegionmanager(player.getWorld().getName());
if (!mgr.getApplicableRegions(pt)
.allowsFlag(AreaFlags.FLAG_PVP)) {
((Player)attacker).sendMessage(ChatColor.DARK_RED + "You are in a no-PvP area.");
event.setCancelled(true);
@ -156,8 +160,9 @@ public void onEntityDamageByProjectile(EntityDamageByProjectileEvent event) {
if (attacker != null && attacker instanceof Skeleton) {
if (plugin.useRegions) {
Vector pt = toVector(defender.getLocation());
if (!plugin.regionManager.getApplicableRegions(pt)
RegionManager mgr = plugin.getGlobalRegionManager().getRegionmanager(player.getWorld().getName());
if (!mgr.getApplicableRegions(pt)
.allowsFlag(AreaFlags.FLAG_MOB_DAMAGE)) {
event.setCancelled(true);
return;
@ -254,8 +259,9 @@ public void onEntityExplode(EntityExplodeEvent event) {
if (plugin.useRegions) {
Vector pt = toVector(event.getEntity().getLocation());
RegionManager mgr = plugin.getGlobalRegionManager().getRegionmanager(event.getEntity().getWorld().getName());
if (!plugin.regionManager.getApplicableRegions(pt)
if (!mgr.getApplicableRegions(pt)
.allowsFlag(AreaFlags.FLAG_CREEPER_EXPLOSION)) {
event.setCancelled(true);
return;
@ -269,8 +275,9 @@ public void onEntityExplode(EntityExplodeEvent event) {
if (plugin.useRegions && event.getEntity() != null) {
Vector pt = toVector(event.getEntity().getLocation());
if (!plugin.regionManager.getApplicableRegions(pt)
RegionManager mgr = plugin.getGlobalRegionManager().getRegionmanager(event.getEntity().getWorld().getName());
if (!mgr.getApplicableRegions(pt)
.allowsFlag(AreaFlags.FLAG_TNT)) {
event.setCancelled(true);
return;

View File

@ -19,6 +19,7 @@
package com.sk89q.worldguard.bukkit;
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
import com.sk89q.worldguard.blacklist.events.ItemAcquireBlacklistEvent;
import org.bukkit.entity.Item;
import com.sk89q.worldguard.blacklist.events.ItemDropBlacklistEvent;
@ -30,7 +31,7 @@
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.*;
import com.sk89q.worldguard.blacklist.events.ItemUseBlacklistEvent;
import com.sk89q.worldguard.protection.AreaFlags;
import com.sk89q.worldguard.protection.regions.AreaFlags;
import static com.sk89q.worldguard.bukkit.BukkitUtil.*;
/**
@ -116,10 +117,8 @@ public void onPlayerItem(PlayerItemEvent event) {
if (plugin.useRegions && !event.isBlock() && block != null) {
Vector pt = toVector(block.getRelative(event.getBlockFace()));
LocalPlayer localPlayer = plugin.wrapPlayer(player);
if (!plugin.hasPermission(player, "/regionbypass")
&& !plugin.regionManager.getApplicableRegions(pt).canBuild(localPlayer)) {
if (!plugin.canBuild(player, pt)) {
player.sendMessage(ChatColor.DARK_RED
+ "You don't have permission for this area.");
event.setCancelled(true);
@ -139,8 +138,9 @@ public void onPlayerItem(PlayerItemEvent event) {
if (plugin.useRegions && item != null && block != null && item.getTypeId() == 259) {
Vector pt = toVector(block.getRelative(event.getBlockFace()));
if (!plugin.regionManager.getApplicableRegions(pt)
RegionManager mgr = plugin.getGlobalRegionManager().getRegionmanager(player.getWorld().getName());
if (!mgr.getApplicableRegions(pt)
.allowsFlag(AreaFlags.FLAG_LIGHTER)) {
event.setCancelled(true);
return;

View File

@ -19,8 +19,11 @@
package com.sk89q.worldguard.bukkit;
import com.sk89q.worldguard.protection.dbs.CSVDatabase;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
import static com.sk89q.worldguard.bukkit.BukkitUtil.matchSinglePlayer;
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
import java.io.*;
import java.util.*;
import java.util.logging.*;
@ -31,14 +34,12 @@
import org.bukkit.entity.Player;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginLoader;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.config.Configuration;
import com.sk89q.bukkit.migration.PermissionsResolverManager;
@ -49,7 +50,6 @@
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.ItemType;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.bukkit.WorldEditAPI;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldguard.LocalPlayer;
@ -58,8 +58,12 @@
import com.sk89q.worldguard.blacklist.loggers.*;
import com.sk89q.worldguard.domains.DefaultDomain;
import com.sk89q.worldguard.protection.*;
import com.sk89q.worldguard.protection.AreaFlags.State;
import com.sk89q.worldguard.protection.ProtectedRegion.CircularInheritanceException;
import com.sk89q.worldguard.protection.regionmanager.GlobalRegionManager;
import com.sk89q.worldguard.protection.regions.AreaFlags;
import com.sk89q.worldguard.protection.regions.AreaFlags.State;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion.CircularInheritanceException;
import org.bukkit.World;
/**
* Plugin for Bukkit.
@ -81,12 +85,10 @@ public class WorldGuardPlugin extends JavaPlugin {
private PermissionsResolverServerListener permsListener;
private PermissionsResolverManager perms;
Blacklist blacklist;
GlobalFlags globalFlags = new GlobalFlags();
RegionManager regionManager = new FlatRegionManager(globalFlags);
ProtectionDatabase regionLoader;
GlobalRegionManager globalRegionManager;
Set<String> invinciblePlayers = new HashSet<String>();
Set<String> amphibiousPlayers = new HashSet<String>();
@ -158,7 +160,8 @@ public void onEnable() {
createDefaultConfiguration("config.yml");
createDefaultConfiguration("blacklist.txt");
regionLoader = new CSVDatabase(new File(folder, "regions.txt"));
globalRegionManager = new GlobalRegionManager(this);
perms = new PermissionsResolverManager(getConfiguration(), getServer(),
"WorldGuard", logger);
permsListener = new PermissionsResolverServerListener(perms);
@ -316,6 +319,8 @@ public void loadConfiguration() {
useRegions = config.getBoolean("regions.enable", true);
regionWand = config.getInt("regions.wand", 287);
GlobalFlags globalFlags = new GlobalFlags();
globalFlags.canBuild = config.getBoolean("regions.default.build", true);
globalFlags.canAccessChests = config.getBoolean("regions.default.chest-access", false);
globalFlags.canPvP = config.getBoolean("regions.default.pvp", true);
@ -323,16 +328,35 @@ public void loadConfiguration() {
globalFlags.canTnt = config.getBoolean("regions.default.tnt", true);
globalFlags.allowCreeper = config.getBoolean("regions.default.creeper", true);
globalFlags.allowMobDamage = config.getBoolean("regions.default.mobdamage", true);
globalRegionManager.setGlobalFlags(globalFlags);
try {
regionLoader.load();
regionManager.setRegions(regionLoader.getRegions());
File CSVfile = new File(this.getDataFolder(), "regions.txt");
if (CSVfile.exists()) {
logger.info("WorldGuard: Converting old regions.txt to new format....");
World w = this.getServer().getWorlds().get(0);
RegionManager mgr = globalRegionManager.getRegionmanager(w.getName());
CSVDatabase db = new CSVDatabase(CSVfile);
db.load();
for (Map.Entry<String, ProtectedRegion> entry : db.getRegions().entrySet()) {
mgr.addRegion(entry.getValue());
}
mgr.save();
CSVfile.renameTo(new File(this.getDataFolder(), "region.txt.old"));
logger.info("WorldGuard: Done.");
}
} catch (FileNotFoundException e) {
} catch (IOException e) {
logger.warning("WorldGuard: Failed to load regions: "
+ e.getMessage());
}
// Console log configuration
boolean logConsole = config.getBoolean("blacklist.logging.console.enable", true);
@ -780,9 +804,10 @@ private boolean handleRegionCommand(Player player, String action, String[] args)
String id = args[0].toLowerCase();
WorldEditPlugin worldEdit = (WorldEditPlugin)wePlugin;
World w = player.getWorld();
LocalSession session = worldEdit.getSession(player);
Region weRegion = session.getSelection(new BukkitWorld(player.getWorld()));
Region weRegion = session.getSelection(new BukkitWorld(w));
BlockVector min = weRegion.getMinimumPoint().toBlockVector();
BlockVector max = weRegion.getMaximumPoint().toBlockVector();
@ -791,8 +816,9 @@ private boolean handleRegionCommand(Player player, String action, String[] args)
if (args.length >= 2) {
region.setOwners(parseDomainString(args, 1));
}
regionManager.addRegion(region);
regionLoader.save(regionManager);
RegionManager mgr = globalRegionManager.getRegionmanager(w.getName());
mgr.addRegion(region);
mgr.save();
player.sendMessage(ChatColor.YELLOW + "Region saved as " + id + ".");
} catch (IncompleteRegionException e) {
player.sendMessage(ChatColor.RED + "You must first define an area in WorldEdit.");
@ -810,8 +836,9 @@ private boolean handleRegionCommand(Player player, String action, String[] args)
try {
String id = args[0].toLowerCase();
RegionManager mgr = globalRegionManager.getRegionmanager(player.getWorld().getName());
ProtectedRegion existing = regionManager.getRegion(id);
ProtectedRegion existing = mgr.getRegion(id);
if (existing != null) {
if (!existing.getOwners().contains(wrapPlayer(player))) {
@ -830,15 +857,15 @@ private boolean handleRegionCommand(Player player, String action, String[] args)
ProtectedRegion region = new ProtectedCuboidRegion(id, min, max);
if (regionManager.overlapsUnownedRegion(region, wrapPlayer(player))) {
if (mgr.overlapsUnownedRegion(region, wrapPlayer(player))) {
player.sendMessage(ChatColor.RED + "This region overlaps with someone else's region.");
return true;
}
region.getOwners().addPlayer(player.getName());
regionManager.addRegion(region);
regionLoader.save(regionManager);
mgr.addRegion(region);
mgr.save();
player.sendMessage(ChatColor.YELLOW + "Region saved as " + id + ".");
} catch (IncompleteRegionException e) {
player.sendMessage(ChatColor.RED + "You must first define an area in WorldEdit.");
@ -858,7 +885,8 @@ private boolean handleRegionCommand(Player player, String action, String[] args)
String id = args[0].toLowerCase();
String flagStr = args[1];
String stateStr = args[2];
ProtectedRegion region = regionManager.getRegion(id);
RegionManager mgr = globalRegionManager.getRegionmanager(player.getWorld().getName());
ProtectedRegion region = mgr.getRegion(id);
if (region == null) {
player.sendMessage(ChatColor.RED + "Could not find a region by that ID.");
@ -893,7 +921,7 @@ private boolean handleRegionCommand(Player player, String action, String[] args)
AreaFlags flags = region.getFlags();
flags.set(flagStr, state);
regionLoader.save(regionManager);
mgr.save();
player.sendMessage(ChatColor.YELLOW + "Region '" + id + "' updated.");
} catch (IOException e) {
player.sendMessage(ChatColor.RED + "Region database failed to save: "
@ -911,8 +939,9 @@ private boolean handleRegionCommand(Player player, String action, String[] args)
String id = args[0].toLowerCase();
String parentId = args.length > 1 ? args[1].toLowerCase() : null;
ProtectedRegion region = regionManager.getRegion(id);
RegionManager mgr = globalRegionManager.getRegionmanager(player.getWorld().getName());
ProtectedRegion region = mgr.getRegion(id);
if (region == null) {
player.sendMessage(ChatColor.RED + "Could not find a region with ID: " + id);
@ -929,7 +958,7 @@ private boolean handleRegionCommand(Player player, String action, String[] args)
// Set a parent
if (parentId != null) {
parent = regionManager.getRegion(parentId);
parent = mgr.getRegion(parentId);
if (parent == null) {
player.sendMessage(ChatColor.RED + "Could not find a region with ID: " + parentId);
@ -946,7 +975,7 @@ private boolean handleRegionCommand(Player player, String action, String[] args)
try {
region.setParent(parent);
regionLoader.save(regionManager);
mgr.save();
player.sendMessage(ChatColor.YELLOW + "Region '" + id + "' updated.");
} catch (CircularInheritanceException e) {
player.sendMessage(ChatColor.RED + "Circular inheritance detected. The operation failed.");
@ -961,15 +990,16 @@ private boolean handleRegionCommand(Player player, String action, String[] args)
if (action.equalsIgnoreCase("info")) {
checkRegionPermission(player, "/regioninfo");
checkArgs(args, 1, 1, "/region info <id>");
RegionManager mgr = globalRegionManager.getRegionmanager(player.getWorld().getName());
String id = args[0].toLowerCase();
if (!regionManager.hasRegion(id)) {
if (!mgr.hasRegion(id)) {
player.sendMessage(ChatColor.RED + "A region with ID '"
+ id + "' doesn't exist.");
return true;
}
ProtectedRegion region = regionManager.getRegion(id);
ProtectedRegion region = mgr.getRegion(id);
AreaFlags flags = region.getFlags();
DefaultDomain owners = region.getOwners();
DefaultDomain members = region.getMembers();
@ -1010,15 +1040,16 @@ private boolean handleRegionCommand(Player player, String action, String[] args)
checkArgs(args, 2, -1, "/region add[member|owner] <id> [player1 [group1 [players/groups...]]]");
boolean isOwner = action.equalsIgnoreCase("addowner");
RegionManager mgr = globalRegionManager.getRegionmanager(player.getWorld().getName());
String id = args[0].toLowerCase();
if (!regionManager.hasRegion(id)) {
if (!mgr.hasRegion(id)) {
player.sendMessage(ChatColor.RED + "A region with ID '"
+ id + "' doesn't exist.");
return true;
}
ProtectedRegion existing = regionManager.getRegion(id);
ProtectedRegion existing = mgr.getRegion(id);
if (!canUseRegionCommand(player, "/regiondefine")
&& !existing.isOwner(wrapPlayer(player))) {
@ -1033,7 +1064,7 @@ private boolean handleRegionCommand(Player player, String action, String[] args)
}
try {
regionLoader.save(regionManager);
mgr.save();
player.sendMessage(ChatColor.YELLOW + "Region updated!");
player.sendMessage(ChatColor.GRAY + "Current owners: "
+ existing.getOwners().toUserFriendlyString());
@ -1054,15 +1085,16 @@ private boolean handleRegionCommand(Player player, String action, String[] args)
checkArgs(args, 2, -1, "/region removeowner <id> [owner1 [owner2 [owners...]]]");
boolean isOwner = action.equalsIgnoreCase("removeowner");
RegionManager mgr = globalRegionManager.getRegionmanager(player.getWorld().getName());
String id = args[0].toLowerCase();
if (!regionManager.hasRegion(id)) {
if (!mgr.hasRegion(id)) {
player.sendMessage(ChatColor.RED + "A region with ID '"
+ id + "' doesn't exist.");
return true;
}
ProtectedRegion existing = regionManager.getRegion(id);
ProtectedRegion existing = mgr.getRegion(id);
if (!canUseRegionCommand(player, "/regiondefine")
&& !existing.isOwner(wrapPlayer(player))) {
@ -1077,7 +1109,7 @@ private boolean handleRegionCommand(Player player, String action, String[] args)
}
try {
regionLoader.save(regionManager);
mgr.save();
player.sendMessage(ChatColor.YELLOW + "Region updated!");
player.sendMessage(ChatColor.GRAY + "Current owners: "
+ existing.getOwners().toUserFriendlyString());
@ -1104,8 +1136,9 @@ private boolean handleRegionCommand(Player player, String action, String[] args)
page = 0;
}
}
Map<String,ProtectedRegion> regions = regionManager.getRegions();
RegionManager mgr = globalRegionManager.getRegionmanager(player.getWorld().getName());
Map<String,ProtectedRegion> regions = mgr.getRegions();
int size = regions.size();
int pages = (int)Math.ceil(size / (float)CMD_LIST_SIZE);
@ -1139,13 +1172,15 @@ private boolean handleRegionCommand(Player player, String action, String[] args)
try {
String id = args[0].toLowerCase();
if (!regionManager.hasRegion(id)) {
RegionManager mgr = globalRegionManager.getRegionmanager(player.getWorld().getName());
if (!mgr.hasRegion(id)) {
player.sendMessage(ChatColor.RED + "A region with ID '"
+ id + "' doesn't exist.");
return true;
}
ProtectedRegion existing = regionManager.getRegion(id);
ProtectedRegion existing = mgr.getRegion(id);
if (!canUseRegionCommand(player, "/regiondelete")
&& !existing.isOwner(wrapPlayer(player))) {
@ -1153,8 +1188,8 @@ private boolean handleRegionCommand(Player player, String action, String[] args)
return true;
}
regionManager.removeRegion(id);
regionLoader.save(regionManager);
mgr.removeRegion(id);
mgr.save();
player.sendMessage(ChatColor.YELLOW + "Region removed!");
} catch (IOException e) {
player.sendMessage(ChatColor.RED + "Region database failed to save: "
@ -1169,7 +1204,8 @@ private boolean handleRegionCommand(Player player, String action, String[] args)
checkArgs(args, 0, 0, "/region save");
try {
regionLoader.save(regionManager);
RegionManager mgr = globalRegionManager.getRegionmanager(player.getWorld().getName());
mgr.save();
player.sendMessage(ChatColor.YELLOW + "Region database saved to file!");
} catch (IOException e) {
player.sendMessage(ChatColor.RED + "Region database failed to save: "
@ -1184,7 +1220,8 @@ private boolean handleRegionCommand(Player player, String action, String[] args)
checkArgs(args, 0, 0, "/region load");
try {
regionLoader.load(regionManager);
RegionManager mgr = globalRegionManager.getRegionmanager(player.getWorld().getName());
mgr.load();
player.sendMessage(ChatColor.YELLOW + "Region database loaded from file!");
} catch (IOException e) {
player.sendMessage(ChatColor.RED + "Region database failed to load: "
@ -1341,35 +1378,49 @@ private void checkArgs(String[] args, int min, int max, String help)
*
* @return
*/
public RegionManager getRegionManager() {
return regionManager;
}
/**
* Get the region loader.
*
* @return
*/
public ProtectionDatabase getRegionLoader() {
return regionLoader;
public GlobalRegionManager getGlobalRegionManager() {
return globalRegionManager;
}
public boolean canBuild(Player player, int x, int y, int z) {
if (useRegions) {
Vector pt = new Vector(x, y, z);
LocalPlayer localPlayer = wrapPlayer(player);
if (!hasPermission(player, "/regionbypass")
&& !regionManager.getApplicableRegions(pt).canBuild(localPlayer)) {
return false;
if (!hasPermission(player, "/regionbypass")) {
RegionManager mgr = globalRegionManager.getRegionmanager(player.getWorld().getName());
if (!mgr.getApplicableRegions(pt).canBuild(localPlayer)) {
return false;
}
}
return true;
} else {
return true;
}
}
public boolean canBuild(Player player, Vector pt) {
if (useRegions) {
LocalPlayer localPlayer = wrapPlayer(player);
if (!hasPermission(player, "/regionbypass")) {
RegionManager mgr = globalRegionManager.getRegionmanager(player.getWorld().getName());
if (!mgr.getApplicableRegions(pt).canBuild(localPlayer)) {
return false;
}
}
return true;
} else {
return true;
}
}
boolean inGroup(Player player, String group) {
try {
return perms.inGroup(player.getName(), group);

View File

@ -19,13 +19,15 @@
package com.sk89q.worldguard.protection;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.protection.AreaFlags.State;
import com.sk89q.worldguard.protection.regions.AreaFlags;
import com.sk89q.worldguard.protection.regions.AreaFlags.State;
/**
* Represents a set of regions and their rules as applied to one point.

View File

@ -19,6 +19,7 @@
package com.sk89q.worldguard.protection;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import java.util.Comparator;
class DescendingPriorityComparator implements Comparator<ProtectedRegion> {

View File

@ -1,112 +0,0 @@
// $Id$
/*
* WorldGuard
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.protection;
import java.util.List;
import java.util.Map;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.LocalPlayer;
/**
* An interface for getting, setting, and looking up regions. The most
* simple implementation uses a flat list and iterates through the entire
* list to look for applicable regions, but a more complicated (and more
* efficient) implementation may use space partitioning techniques.
*
* @author sk89q
*/
public interface RegionManager {
/**
* Get a list of protected regions.
*
* @return
*/
public Map<String, ProtectedRegion> getRegions();
/**
* Set a list of protected regions.
*
* @return
*/
public void setRegions(Map<String,ProtectedRegion> regions);
/**
* Adds a region.
*
* @param id
* @param region
*/
public void addRegion(ProtectedRegion region);
/**
* Return whether a region exists by an ID.
*
* @param id
* @return
*/
public boolean hasRegion(String id);
/**
* Get a region by its ID.
*
* @param id
*/
public ProtectedRegion getRegion(String id);
/**
* Removes a region, including inheriting children.
*
* @param id
*/
public void removeRegion(String id);
/**
* Get an object for a point for rules to be applied with.
*
* @param pt
* @return
*/
public ApplicableRegionSet getApplicableRegions(Vector pt);
/**
* Get a list of region IDs that contain a point.
*
* @param pt
* @return
*/
public List<String> getApplicableRegionsIDs(Vector pt);
/**
* Returns true if the provided region overlaps with any other region that
* is not owned by the player.
*
* @param region
* @param player
* @return
*/
public boolean overlapsUnownedRegion(ProtectedRegion region, LocalPlayer player);
/**
* Get the number of regions.
*
* @return
*/
public int size();
}

View File

@ -17,8 +17,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.protection;
package com.sk89q.worldguard.protection.dbs;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
@ -31,8 +33,10 @@
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.domains.DefaultDomain;
import com.sk89q.worldguard.protection.AreaFlags.State;
import com.sk89q.worldguard.protection.ProtectedRegion.CircularInheritanceException;
import com.sk89q.worldguard.protection.regions.AreaFlags;
import com.sk89q.worldguard.protection.regions.AreaFlags.State;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion.CircularInheritanceException;
import com.sk89q.worldguard.util.ArrayReader;
/**

View File

@ -0,0 +1,109 @@
// $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.dbs;
import com.sk89q.worldguard.domains.DefaultDomain;
import com.sk89q.worldguard.protection.regions.AreaFlags;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion.CircularInheritanceException;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
/**
*
* @author Redecouverte
*/
public class JSONContainer {
private static Logger logger = Logger.getLogger("Minecraft.WorldGuard");
private HashMap<String,ProtectedCuboidRegion> cRegions;
private HashMap<String,ProtectedPolygonalRegion> pRegions;
public JSONContainer(Map<String,ProtectedRegion> regions)
{
this.cRegions = new HashMap<String,ProtectedCuboidRegion>();
this.pRegions = new HashMap<String,ProtectedPolygonalRegion>();
for (Map.Entry<String,ProtectedRegion> entry : regions.entrySet()) {
String id = entry.getKey();
ProtectedRegion region = entry.getValue();
region.setParentId();
if(region instanceof ProtectedCuboidRegion)
{
cRegions.put(id, (ProtectedCuboidRegion)region);
}
else if(region instanceof ProtectedPolygonalRegion)
{
pRegions.put(id, (ProtectedPolygonalRegion)region);
}
else
{
logger.info("regions of type '" + region.getClass().toString() + "' are not supported for saving, yet.");
}
}
}
public Map<String, ProtectedRegion> getRegions() {
HashMap<String, ProtectedRegion> ret = new HashMap<String, ProtectedRegion>();
ret.putAll(this.cRegions);
ret.putAll(this.pRegions);
for (Map.Entry<String, ProtectedRegion> entry : ret.entrySet()) {
String id = entry.getKey();
ProtectedRegion region = entry.getValue();
String parentId = region.getParentId();
if (parentId != null) {
try {
region.setParent(ret.get(parentId));
} catch (CircularInheritanceException ex) {
}
} else {
try {
region.setParent(null);
} catch (CircularInheritanceException ex) {
}
}
if(region.getOwners() == null)
{
region.setOwners(new DefaultDomain());
}
else if(region.getMembers() == null)
{
region.setMembers(new DefaultDomain());
}
else if(region.getFlags() == null)
{
region.setFlags(new AreaFlags());
}
}
return ret;
}
}

View File

@ -0,0 +1,168 @@
// $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.dbs;
import com.sk89q.worldguard.protection.dbs.ProtectionDatabase;
import com.sk89q.worldguard.protection.dbs.JSONContainer;
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.String;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
/**
* Represents a protected area database that uses JSON files.
*
* @author Redecouverte
*/
public class JSONDatabase implements ProtectionDatabase {
private static Logger logger = Logger.getLogger("Minecraft.WorldGuard");
/**
* References the json db folder.
*/
private File file;
/**
* Holds the list of regions.
*/
private Map<String,ProtectedRegion> regions;
/**
* Construct the database with a path to a file. No file is read or
* written at this time.
*
* @param file
*/
public JSONDatabase(File file) {
this.file = file;
}
/**
* Helper function to read a file into a String
*/
private static String readFileAsString(File file) throws java.io.IOException {
byte[] buffer = new byte[(int) file.length()];
BufferedInputStream f = null;
try {
f = new BufferedInputStream(new FileInputStream(file.getAbsolutePath()));
f.read(buffer);
} finally {
if (f != null) {
try {
f.close();
} catch (IOException ignored) {
}
}
}
return new String(buffer);
}
/**
* Load the database from file.
*/
public void load() throws IOException {
Gson gson = new Gson();
JSONContainer jContainer = gson.fromJson(readFileAsString(file), JSONContainer.class);
this.regions = jContainer.getRegions();
}
/**
* Saves the database.
*/
public void save() throws IOException {
Gson gson = new Gson();
String jsonData = gson.toJson(new JSONContainer(this.regions), JSONContainer.class);
writeStringToFile(jsonData, this.file);
}
/**
* Writes a String to a file.
*
* @throws IOException
*/
public static void writeStringToFile(String string, File file) throws IOException {
FileWriter writer = null;
try {
writer = new FileWriter(file);
writer.write(string);
} finally {
try {
if (writer != null) {
writer.close();
}
} catch (IOException e) {
}
}
}
/**
* Load the list of regions into a region manager.
*
* @throws IOException
*/
public void load(RegionManager manager) throws IOException {
load();
manager.setRegions(regions);
}
/**
* Save the list of regions from a region manager.
*
* @throws IOException
*/
public void save(RegionManager manager) throws IOException {
regions = manager.getRegions();
save();
}
/**
* Get a list of protected regions.
*
* @return
*/
public Map<String,ProtectedRegion> getRegions() {
return regions;
}
/**
* Get a list of protected regions.
*
* @return
*/
public void setRegions(Map<String,ProtectedRegion> regions) {
this.regions = regions;
}
}

View File

@ -1,68 +1,70 @@
// $Id$
/*
* WorldGuard
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.protection;
import java.io.IOException;
import java.util.Map;
/**
* Represents a database to read and write lists of regions from and to.
*
* @author sk89q
*/
public interface ProtectionDatabase {
/**
* Load the list of regions. The method should not modify the list returned
* by getRegions() unless the load finishes successfully.
*
* @throws IOException
*/
public void load() throws IOException;
/**
* Save the list of regions.
*
* @throws IOException
*/
public void save() throws IOException;
/**
* Load the list of regions into a region manager.
*
* @throws IOException
*/
public void load(RegionManager manager) throws IOException;
/**
* Save the list of regions from a region manager.
*
* @throws IOException
*/
public void save(RegionManager manager) throws IOException;
/**
* Get a list of regions.
*
* @return
*/
public Map<String,ProtectedRegion> getRegions();
/**
* Set the list of regions.
*
* @param regions
*/
public void setRegions(Map<String,ProtectedRegion> regions);
}
// $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.dbs;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
import java.io.IOException;
import java.util.Map;
/**
* Represents a database to read and write lists of regions from and to.
*
* @author sk89q
*/
public interface ProtectionDatabase {
/**
* Load the list of regions. The method should not modify the list returned
* by getRegions() unless the load finishes successfully.
*
* @throws IOException
*/
public void load() throws IOException;
/**
* Save the list of regions.
*
* @throws IOException
*/
public void save() throws IOException;
/**
* Load the list of regions into a region manager.
*
* @throws IOException
*/
public void load(RegionManager manager) throws IOException;
/**
* Save the list of regions from a region manager.
*
* @throws IOException
*/
public void save(RegionManager manager) throws IOException;
/**
* Get a list of regions.
*
* @return
*/
public Map<String,ProtectedRegion> getRegions();
/**
* Set the list of regions.
*
* @param regions
*/
public void setRegions(Map<String,ProtectedRegion> regions);
}

View File

@ -1,183 +1,208 @@
// $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 java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.LocalPlayer;
/**
* A very simple implementation of the region manager that uses a flat list
* and iterates through the list to identify applicable regions. This method
* is not very efficient.
*
* @author sk89q
*/
public class FlatRegionManager implements RegionManager {
/**
* List of protected regions.
*/
private Map<String,ProtectedRegion> regions;
/**
* Global flags.
*/
private GlobalFlags global;
/**
* Construct the manager.
*/
public FlatRegionManager(GlobalFlags global) {
regions = new TreeMap<String,ProtectedRegion>();
this.global = global;
}
/**
* Get a list of protected regions.
*
* @return
*/
public Map<String,ProtectedRegion> getRegions() {
return regions;
}
/**
* Set a list of protected regions.
*
* @return
*/
public void setRegions(Map<String,ProtectedRegion> regions) {
this.regions = new TreeMap<String,ProtectedRegion>(regions);
}
/**
* Adds a region.
*
* @param id
* @param region
*/
public void addRegion(ProtectedRegion region) {
regions.put(region.getId(), region);
}
/**
* Removes a region and its children.
*
* @param id
*/
public void removeRegion(String id) {
ProtectedRegion region = regions.get(id);
regions.remove(id);
if (region != null) {
for (Map.Entry<String, ProtectedRegion> entry : regions.entrySet()) {
if (entry.getValue().getParent() == region) {
removeRegion(entry.getKey());
}
}
}
}
/**
* Return whether a region exists by an ID.
*
* @param id
* @return
*/
public boolean hasRegion(String id) {
return regions.containsKey(id);
}
/**
* Get a region by its ID.
*
* @param id
*/
public ProtectedRegion getRegion(String id) {
return regions.get(id);
}
/**
* Get an object for a point for rules to be applied with.
*
* @param pt
* @return
*/
public ApplicableRegionSet getApplicableRegions(Vector pt) {
return new ApplicableRegionSet(pt, regions.values().iterator(), global);
}
/**
* Get a list of region IDs that contain a point.
*
* @param pt
* @return
*/
public List<String> getApplicableRegionsIDs(Vector pt) {
List<String> applicable = new ArrayList<String>();
for (Map.Entry<String,ProtectedRegion> entry : regions.entrySet()) {
if (entry.getValue().contains(pt)) {
applicable.add(entry.getKey());
}
}
return applicable;
}
/**
* Returns true if the provided region overlaps with any other region that
* is not owned by the player.
*
* @param region
* @param player
* @return
*/
public boolean overlapsUnownedRegion(ProtectedRegion region, LocalPlayer player) {
for (ProtectedRegion other : regions.values()) {
if (other.getOwners().contains(player)) {
continue;
}
try {
if (ProtectedRegion.intersects(region, other)) {
return true;
}
} catch (UnsupportedIntersectionException e) {
// TODO: Maybe do something here
}
}
return false;
}
/**
* Get the number of regions.
*
* @return
*/
public int size() {
return regions.size();
}
}
// $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.regionmanager;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.GlobalFlags;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.protection.UnsupportedIntersectionException;
import com.sk89q.worldguard.protection.dbs.ProtectionDatabase;
import java.io.FileNotFoundException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* A very simple implementation of the region manager that uses a flat list
* and iterates through the list to identify applicable regions. This method
* is not very efficient.
*
* @author sk89q
*/
public class FlatRegionManager extends RegionManager {
/**
* List of protected regions.
*/
private Map<String,ProtectedRegion> regions;
/**
* Construct the manager.
*/
public FlatRegionManager(GlobalFlags global, ProtectionDatabase regionloader) throws IOException {
super(global, regionloader);
regions = new TreeMap<String,ProtectedRegion>();
this.load();
}
/**
* Get a list of protected regions.
*
* @return
*/
public Map<String,ProtectedRegion> getRegions() {
return regions;
}
/**
* Set a list of protected regions.
*
* @return
*/
public void setRegions(Map<String,ProtectedRegion> regions) {
this.regions = new TreeMap<String,ProtectedRegion>(regions);
}
/**
* Adds a region.
*
* @param id
* @param region
*/
public void addRegion(ProtectedRegion region) {
regions.put(region.getId(), region);
}
/**
* Removes a region and its children.
*
* @param id
*/
public void removeRegion(String id) {
ProtectedRegion region = regions.get(id);
regions.remove(id);
if (region != null) {
for (Map.Entry<String, ProtectedRegion> entry : regions.entrySet()) {
if (entry.getValue().getParent() == region) {
removeRegion(entry.getKey());
}
}
}
}
/**
* Return whether a region exists by an ID.
*
* @param id
* @return
*/
public boolean hasRegion(String id) {
return regions.containsKey(id);
}
/**
* Get a region by its ID.
*
* @param id
*/
public ProtectedRegion getRegion(String id) {
return regions.get(id);
}
/**
* Get an object for a point for rules to be applied with.
*
* @param pt
* @return
*/
public ApplicableRegionSet getApplicableRegions(Vector pt) {
return new ApplicableRegionSet(pt, regions.values().iterator(), global);
}
/**
* Get a list of region IDs that contain a point.
*
* @param pt
* @return
*/
public List<String> getApplicableRegionsIDs(Vector pt) {
List<String> applicable = new ArrayList<String>();
for (Map.Entry<String,ProtectedRegion> entry : regions.entrySet()) {
if (entry.getValue().contains(pt)) {
applicable.add(entry.getKey());
}
}
return applicable;
}
/**
* Returns true if the provided region overlaps with any other region that
* is not owned by the player.
*
* @param region
* @param player
* @return
*/
public boolean overlapsUnownedRegion(ProtectedRegion region, LocalPlayer player) {
for (ProtectedRegion other : regions.values()) {
if (other.getOwners().contains(player)) {
continue;
}
try {
if (ProtectedRegion.intersects(region, other)) {
return true;
}
} catch (UnsupportedIntersectionException e) {
// TODO: Maybe do something here
}
}
return false;
}
/**
* Get the number of regions.
*
* @return
*/
public int size() {
return regions.size();
}
/**
* Save the list of regions.
*
* @throws IOException
*/
public void save() throws IOException
{
if(this.regionloader == null)
{
return;
}
regionloader.save(this);
}
}

View File

@ -0,0 +1,89 @@
// $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.regionmanager;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.GlobalFlags;
import com.sk89q.worldguard.protection.dbs.JSONDatabase;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
import org.bukkit.World;
/**
*
* @author Redecouverte
*/
public class GlobalRegionManager {
private WorldGuardPlugin wg;
private HashMap<String, RegionManager> managers;
private GlobalFlags globalFlags;
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
public GlobalRegionManager(WorldGuardPlugin wg) {
this.wg = wg;
this.managers = new HashMap<String, RegionManager>();
this.globalFlags = new GlobalFlags();
for (World w : wg.getServer().getWorlds()) {
loadWorld(w.getName());
}
}
private void loadWorld(String name) {
String filename = name + ".regions.json";
try {
managers.put(name, new FlatRegionManager(globalFlags, new JSONDatabase(new File(wg.getDataFolder(), filename))));
} catch (FileNotFoundException e) {
} catch (IOException e) {
logger.warning("WorldGuard: Failed to load regions from file " + filename + " : "
+ e.getMessage());
}
}
public RegionManager getRegionmanager(String worldName) {
RegionManager ret = this.managers.get(worldName);
if (ret == null) {
if (wg.getServer().getWorld(worldName) != null) {
loadWorld(worldName);
}
}
return ret;
}
public void setGlobalFlags(GlobalFlags globalflags) {
if (globalflags != null) {
this.globalFlags = globalflags;
for (Map.Entry<String, RegionManager> entry : managers.entrySet()) {
entry.getValue().setGlobalFlags(globalflags);
}
}
}
}

View File

@ -1,203 +1,218 @@
// $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 java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import org.khelekore.prtree.MBRConverter;
import org.khelekore.prtree.PRTree;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.LocalPlayer;
public class PRTreeRegionManager implements RegionManager {
private static final int BRANCH_FACTOR = 30;
/**
* List of protected regions.
*/
private Map<String,ProtectedRegion> regions;
/**
* Global flags.
*/
private GlobalFlags global;
/**
* Converter to get coordinates of the tree.
*/
private MBRConverter<ProtectedRegion> converter
= new ProtectedRegionMBRConverter();
/**
* Priority R-tree.
*/
private PRTree<ProtectedRegion> tree;
/**
* Construct the manager.
*/
public PRTreeRegionManager(GlobalFlags global) {
regions = new TreeMap<String,ProtectedRegion>();
tree = new PRTree<ProtectedRegion>(converter, BRANCH_FACTOR);
this.global = global;
}
/**
* Get a list of protected regions.
*
* @return
*/
public Map<String,ProtectedRegion> getRegions() {
return regions;
}
/**
* Set a list of protected regions.
*
* @return
*/
public void setRegions(Map<String,ProtectedRegion> regions) {
this.regions = new TreeMap<String,ProtectedRegion>(regions);
tree = new PRTree<ProtectedRegion>(converter, BRANCH_FACTOR);
tree.load(regions.values());
}
/**
* Adds a region.
*
* @param id
* @param region
*/
public void addRegion(ProtectedRegion region) {
regions.put(region.getId(), region);
tree = new PRTree<ProtectedRegion>(converter, BRANCH_FACTOR);
tree.load(regions.values());
}
/**
* Return whether a region exists by an ID.
*
* @param id
* @return
*/
public boolean hasRegion(String id) {
return regions.containsKey(id);
}
/**
* Get a region by its ID.
*
* @param id
*/
public ProtectedRegion getRegion(String id) {
return regions.get(id);
}
/**
* Removes a region and its children.
*
* @param id
*/
public void removeRegion(String id) {
ProtectedRegion region = regions.get(id);
regions.remove(id);
if (region != null) {
for (Map.Entry<String, ProtectedRegion> entry : regions.entrySet()) {
if (entry.getValue().getParent() == region) {
removeRegion(entry.getKey());
}
}
}
tree = new PRTree<ProtectedRegion>(converter, BRANCH_FACTOR);
tree.load(regions.values());
}
/**
* Get an object for a point for rules to be applied with.
*
* @param pt
* @return
*/
public ApplicableRegionSet getApplicableRegions(Vector pt) {
return new ApplicableRegionSet(pt, regions.values().iterator(), global);
}
/**
* Get a list of region IDs that contain a point.
*
* @param pt
* @return
*/
public List<String> getApplicableRegionsIDs(Vector pt) {
List<String> applicable = new ArrayList<String>();
int x = pt.getBlockX();
int z = pt.getBlockZ();
for (ProtectedRegion region : tree.find(x, z, x, z)) {
if (region.contains(pt)) {
applicable.add(region.getId());
}
}
return applicable;
}
/**
* Returns true if the provided region overlaps with any other region that
* is not owned by the player.
*
* @param region
* @param player
* @return
*/
public boolean overlapsUnownedRegion(ProtectedRegion region, LocalPlayer player) {
for (ProtectedRegion other : regions.values()) {
if (other.getOwners().contains(player)) {
continue;
}
try {
if (ProtectedRegion.intersects(region, other)) {
return true;
}
} catch (UnsupportedIntersectionException e) {
// TODO: Maybe do something here
}
}
return false;
}
/**
* Get the number of regions.
*
* @return
*/
public int size() {
return regions.size();
}
}
// $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.regionmanager;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import org.khelekore.prtree.MBRConverter;
import org.khelekore.prtree.PRTree;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.GlobalFlags;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegionMBRConverter;
import com.sk89q.worldguard.protection.UnsupportedIntersectionException;
import com.sk89q.worldguard.protection.dbs.ProtectionDatabase;
import java.io.IOException;
import java.util.HashMap;
public class PRTreeRegionManager extends RegionManager {
private static final int BRANCH_FACTOR = 30;
/**
* List of protected regions.
*/
private Map<String,ProtectedRegion> regions;
/**
* Converter to get coordinates of the tree.
*/
private MBRConverter<ProtectedRegion> converter
= new ProtectedRegionMBRConverter();
/**
* Priority R-tree.
*/
private PRTree<ProtectedRegion> tree;
/**
* Construct the manager.
*/
public PRTreeRegionManager(GlobalFlags global, ProtectionDatabase regionloader) throws IOException {
super(global, regionloader);
regions = new TreeMap<String,ProtectedRegion>();
tree = new PRTree<ProtectedRegion>(converter, BRANCH_FACTOR);
this.load();
}
/**
* Get a list of protected regions.
*
* @return
*/
public Map<String,ProtectedRegion> getRegions() {
return regions;
}
/**
* Set a list of protected regions.
*
* @return
*/
public void setRegions(Map<String,ProtectedRegion> regions) {
this.regions = new TreeMap<String,ProtectedRegion>(regions);
tree = new PRTree<ProtectedRegion>(converter, BRANCH_FACTOR);
tree.load(regions.values());
}
/**
* Adds a region.
*
* @param id
* @param region
*/
public void addRegion(ProtectedRegion region) {
regions.put(region.getId(), region);
tree = new PRTree<ProtectedRegion>(converter, BRANCH_FACTOR);
tree.load(regions.values());
}
/**
* Return whether a region exists by an ID.
*
* @param id
* @return
*/
public boolean hasRegion(String id) {
return regions.containsKey(id);
}
/**
* Get a region by its ID.
*
* @param id
*/
public ProtectedRegion getRegion(String id) {
return regions.get(id);
}
/**
* Removes a region and its children.
*
* @param id
*/
public void removeRegion(String id) {
ProtectedRegion region = regions.get(id);
regions.remove(id);
if (region != null) {
for (Map.Entry<String, ProtectedRegion> entry : regions.entrySet()) {
if (entry.getValue().getParent() == region) {
removeRegion(entry.getKey());
}
}
}
tree = new PRTree<ProtectedRegion>(converter, BRANCH_FACTOR);
tree.load(regions.values());
}
/**
* Get an object for a point for rules to be applied with.
*
* @param pt
* @return
*/
public ApplicableRegionSet getApplicableRegions(Vector pt) {
return new ApplicableRegionSet(pt, regions.values().iterator(), global);
}
/**
* Get a list of region IDs that contain a point.
*
* @param pt
* @return
*/
public List<String> getApplicableRegionsIDs(Vector pt) {
List<String> applicable = new ArrayList<String>();
int x = pt.getBlockX();
int z = pt.getBlockZ();
for (ProtectedRegion region : tree.find(x, z, x, z)) {
if (region.contains(pt)) {
applicable.add(region.getId());
}
}
return applicable;
}
/**
* Returns true if the provided region overlaps with any other region that
* is not owned by the player.
*
* @param region
* @param player
* @return
*/
public boolean overlapsUnownedRegion(ProtectedRegion region, LocalPlayer player) {
for (ProtectedRegion other : regions.values()) {
if (other.getOwners().contains(player)) {
continue;
}
try {
if (ProtectedRegion.intersects(region, other)) {
return true;
}
} catch (UnsupportedIntersectionException e) {
// TODO: Maybe do something here
}
}
return false;
}
/**
* Get the number of regions.
*
* @return
*/
public int size() {
return regions.size();
}
/**
* Save the list of regions.
*
* @throws IOException
*/
public void save() throws IOException
{
regionloader.save(this);
}
}

View File

@ -0,0 +1,181 @@
// $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.regionmanager;
import java.util.List;
import java.util.Map;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.GlobalFlags;
import com.sk89q.worldguard.protection.dbs.ProtectionDatabase;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.logging.Logger;
/**
* An abstract class for getting, setting, and looking up regions. The most
* simple implementation uses a flat list and iterates through the entire
* list to look for applicable regions, but a more complicated (and more
* efficient) implementation may use space partitioning techniques.
*
* @author sk89q
*/
public abstract class RegionManager {
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
/**
* Global flags.
*/
protected GlobalFlags global;
protected ProtectionDatabase regionloader;
public RegionManager(GlobalFlags global, ProtectionDatabase regionloader)
{
this.global = global;
this.regionloader = regionloader;
}
/**
* Load the list of regions.
*
* @throws IOException
*/
public void load() throws IOException
{
if(this.regionloader == null)
{
return;
}
try {
this.regionloader.load();
this.setRegions(this.regionloader.getRegions());
} catch (FileNotFoundException e) {
} catch (IOException e) {
logger.warning("WorldGuard: Failed to load regions: "
+ e.getMessage());
}
}
/**
* Save the list of regions.
*
* @throws IOException
*/
public abstract void save() throws IOException;
/**
* Get a list of protected regions.
*
* @return
*/
public abstract Map<String, ProtectedRegion> getRegions();
/**
* Set a list of protected regions.
*
* @return
*/
public abstract void setRegions(Map<String,ProtectedRegion> regions);
/**
* Adds a region.
*
* @param id
* @param region
*/
public abstract void addRegion(ProtectedRegion region);
/**
* Return whether a region exists by an ID.
*
* @param id
* @return
*/
public abstract boolean hasRegion(String id);
/**
* Get a region by its ID.
*
* @param id
*/
public abstract ProtectedRegion getRegion(String id);
/**
* Removes a region, including inheriting children.
*
* @param id
*/
public abstract void removeRegion(String id);
/**
* Get an object for a point for rules to be applied with.
*
* @param pt
* @return
*/
public abstract ApplicableRegionSet getApplicableRegions(Vector pt);
/**
* Get a list of region IDs that contain a point.
*
* @param pt
* @return
*/
public abstract List<String> getApplicableRegionsIDs(Vector pt);
/**
* Returns true if the provided region overlaps with any other region that
* is not owned by the player.
*
* @param region
* @param player
* @return
*/
public abstract boolean overlapsUnownedRegion(ProtectedRegion region, LocalPlayer player);
/**
* Get the number of regions.
*
* @return
*/
public abstract int size();
/**
* Sets the global flags.
*
* @return
*/
public void setGlobalFlags(GlobalFlags globalflags)
{
global = globalflags;
}
}

View File

@ -1,145 +1,145 @@
// $Id$
/*
* WorldGuard
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.protection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/**
* Holds the flags for a region.
*
* @author sk89q
*/
public class AreaFlags {
public enum State {
NONE,
ALLOW,
DENY,
};
public static final String FLAG_PASSTHROUGH = "z";
public static final String FLAG_BUILD = "b";
public static final String FLAG_PVP = "p";
public static final String FLAG_MOB_DAMAGE = "m";
public static final String FLAG_CREEPER_EXPLOSION = "c";
public static final String FLAG_TNT = "t";
public static final String FLAG_LIGHTER = "l";
public static final String FLAG_FIRE_SPREAD = "f";
public static final String FLAG_LAVA_FIRE = "F";
public static final String FLAG_CHEST_ACCESS = "C";
/**
* Get the user-friendly name of a flag. If a name isn't known, then
* the flag is returned unchanged.
*
* @param flag
* @return
*/
public static String getFlagName(String flag) {
if (flag.equals(FLAG_PASSTHROUGH)) {
return "passthrough";
} else if (flag.equals(FLAG_BUILD)) {
return "build";
} else if (flag.equals(FLAG_PVP)) {
return "PvP";
} else if (flag.equals(FLAG_MOB_DAMAGE)) {
return "mob damage";
} else if (flag.equals(FLAG_CREEPER_EXPLOSION)) {
return "creeper explosion";
} else if (flag.equals(FLAG_TNT)) {
return "TNT";
} else if (flag.equals(FLAG_LIGHTER)) {
return "lighter";
} else if (flag.equals(FLAG_FIRE_SPREAD)) {
return "fire spread";
} else if (flag.equals(FLAG_LAVA_FIRE)) {
return "lava fire spread";
} else if (flag.equals(FLAG_CHEST_ACCESS)) {
return "chest access";
} else {
return flag;
}
}
/**
* Gets a flag from an alias. May return null.
*
* @param name
* @return
*/
public static String fromAlias(String name) {
if (name.equalsIgnoreCase("passthrough")) {
return FLAG_PASSTHROUGH;
} else if (name.equalsIgnoreCase("build")) {
return FLAG_BUILD;
} else if (name.equalsIgnoreCase("pvp")) {
return FLAG_PVP;
} else if (name.equalsIgnoreCase("mobdamage")) {
return FLAG_MOB_DAMAGE;
} else if (name.equalsIgnoreCase("creeper")) {
return FLAG_CREEPER_EXPLOSION;
} else if (name.equalsIgnoreCase("tnt")) {
return FLAG_TNT;
} else if (name.equalsIgnoreCase("lighter")) {
return FLAG_LIGHTER;
} else if (name.equalsIgnoreCase("firespread")) {
return FLAG_FIRE_SPREAD;
} else if (name.equalsIgnoreCase("lavafirespread")) {
return FLAG_LAVA_FIRE;
} else if (name.equalsIgnoreCase("chest")) {
return FLAG_CHEST_ACCESS;
} else {
return null;
}
}
private Map<String, State> states = new HashMap<String, State>();
public State get(String flag) {
State state = states.get(flag);
if (state == null) {
return State.NONE;
}
return state;
}
public void set(String flag, State state) {
if (state == State.NONE) {
states.remove(flag);
} else {
states.put(flag, state);
}
}
public Set<Map.Entry<String, State>> entrySet() {
return states.entrySet();
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof AreaFlags)) {
return false;
}
AreaFlags other = (AreaFlags)obj;
return other.states.equals(this);
}
}
// $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.regions;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/**
* Holds the flags for a region.
*
* @author sk89q
*/
public class AreaFlags {
public enum State {
NONE,
ALLOW,
DENY,
};
public static final String FLAG_PASSTHROUGH = "z";
public static final String FLAG_BUILD = "b";
public static final String FLAG_PVP = "p";
public static final String FLAG_MOB_DAMAGE = "m";
public static final String FLAG_CREEPER_EXPLOSION = "c";
public static final String FLAG_TNT = "t";
public static final String FLAG_LIGHTER = "l";
public static final String FLAG_FIRE_SPREAD = "f";
public static final String FLAG_LAVA_FIRE = "F";
public static final String FLAG_CHEST_ACCESS = "C";
/**
* Get the user-friendly name of a flag. If a name isn't known, then
* the flag is returned unchanged.
*
* @param flag
* @return
*/
public static String getFlagName(String flag) {
if (flag.equals(FLAG_PASSTHROUGH)) {
return "passthrough";
} else if (flag.equals(FLAG_BUILD)) {
return "build";
} else if (flag.equals(FLAG_PVP)) {
return "PvP";
} else if (flag.equals(FLAG_MOB_DAMAGE)) {
return "mob damage";
} else if (flag.equals(FLAG_CREEPER_EXPLOSION)) {
return "creeper explosion";
} else if (flag.equals(FLAG_TNT)) {
return "TNT";
} else if (flag.equals(FLAG_LIGHTER)) {
return "lighter";
} else if (flag.equals(FLAG_FIRE_SPREAD)) {
return "fire spread";
} else if (flag.equals(FLAG_LAVA_FIRE)) {
return "lava fire spread";
} else if (flag.equals(FLAG_CHEST_ACCESS)) {
return "chest access";
} else {
return flag;
}
}
/**
* Gets a flag from an alias. May return null.
*
* @param name
* @return
*/
public static String fromAlias(String name) {
if (name.equalsIgnoreCase("passthrough")) {
return FLAG_PASSTHROUGH;
} else if (name.equalsIgnoreCase("build")) {
return FLAG_BUILD;
} else if (name.equalsIgnoreCase("pvp")) {
return FLAG_PVP;
} else if (name.equalsIgnoreCase("mobdamage")) {
return FLAG_MOB_DAMAGE;
} else if (name.equalsIgnoreCase("creeper")) {
return FLAG_CREEPER_EXPLOSION;
} else if (name.equalsIgnoreCase("tnt")) {
return FLAG_TNT;
} else if (name.equalsIgnoreCase("lighter")) {
return FLAG_LIGHTER;
} else if (name.equalsIgnoreCase("firespread")) {
return FLAG_FIRE_SPREAD;
} else if (name.equalsIgnoreCase("lavafirespread")) {
return FLAG_LAVA_FIRE;
} else if (name.equalsIgnoreCase("chest")) {
return FLAG_CHEST_ACCESS;
} else {
return null;
}
}
private Map<String, State> states = new HashMap<String, State>();
public State get(String flag) {
State state = states.get(flag);
if (state == null) {
return State.NONE;
}
return state;
}
public void set(String flag, State state) {
if (state == State.NONE) {
states.remove(flag);
} else {
states.put(flag, state);
}
}
public Set<Map.Entry<String, State>> entrySet() {
return states.entrySet();
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof AreaFlags)) {
return false;
}
AreaFlags other = (AreaFlags)obj;
return other.states.equals(this);
}
}

View File

@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.protection;
package com.sk89q.worldguard.protection.regions;
import com.sk89q.worldedit.*;

View File

@ -1,132 +1,132 @@
// $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 java.util.List;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.BlockVector2D;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.Vector2D;
public class ProtectedPolygonalRegion extends ProtectedRegion {
protected List<BlockVector2D> points;
protected int minY;
protected int maxY;
private BlockVector min;
private BlockVector max;
public ProtectedPolygonalRegion(String id, List<BlockVector2D> points, int minY, int maxY) {
super(id);
this.points = points;
this.minY = minY;
this.maxY = maxY;
int minX = points.get(0).getBlockX();
int minZ = points.get(0).getBlockZ();
int maxX = points.get(0).getBlockX();
int maxZ = points.get(0).getBlockZ();
for (BlockVector2D v : points) {
int x = v.getBlockX();
int z = v.getBlockZ();
if (x < minX) minX = x;
if (z < minZ) minZ = z;
if (x > maxX) maxX = x;
if (z > maxZ) maxZ = z;
}
min = new BlockVector(minX, minY, minZ);
max = new BlockVector(maxX, maxY, maxZ);
}
@Override
public BlockVector getMinimumPoint() {
return min;
}
@Override
public BlockVector getMaximumPoint() {
return max;
}
/**
* Checks to see if a point is inside this region.
*/
@Override
public boolean contains(Vector pt) {
int targetX = pt.getBlockX(); //wide
int targetY = pt.getBlockY(); //height
int targetZ = pt.getBlockZ(); //depth
if (targetY < minY || targetY > maxY) {
return false;
}
//Quick and dirty check.
if(targetX < min.getBlockX() || targetX > max.getBlockX() || targetZ < min.getBlockZ() || targetZ > max.getBlockZ()){
return false;
}
boolean inside = false;
int npoints = points.size();
int xNew, zNew;
int xOld, zOld;
int x1, z1;
int x2, z2;
int i;
xOld = points.get(npoints - 1).getBlockX();
zOld = points.get(npoints - 1).getBlockZ();
for (i = 0; i < npoints; i++) {
xNew = points.get(i).getBlockX();
zNew = points.get(i).getBlockZ();
if (xNew > xOld) {
x1 = xOld;
x2 = xNew;
z1 = zOld;
z2 = zNew;
} else {
x1 = xNew;
x2 = xOld;
z1 = zNew;
z2 = zOld;
}
if ((xNew < targetX) == (targetX <= xOld)
&& ((long) targetZ - (long) z1) * (long) (x2 - x1) <= ((long) z2 - (long) z1)
* (long) (targetX - x1)) {
inside = !inside;
}
xOld = xNew;
zOld = zNew;
}
return inside;
}
/**
* Return the type of region as a user-friendly name.
*
* @return type of region
*/
@Override
public String getTypeName() {
return "polygon";
}
}
// $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.regions;
import java.util.List;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.BlockVector2D;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.Vector2D;
public class ProtectedPolygonalRegion extends ProtectedRegion {
protected List<BlockVector2D> points;
protected int minY;
protected int maxY;
private BlockVector min;
private BlockVector max;
public ProtectedPolygonalRegion(String id, List<BlockVector2D> points, int minY, int maxY) {
super(id);
this.points = points;
this.minY = minY;
this.maxY = maxY;
int minX = points.get(0).getBlockX();
int minZ = points.get(0).getBlockZ();
int maxX = points.get(0).getBlockX();
int maxZ = points.get(0).getBlockZ();
for (BlockVector2D v : points) {
int x = v.getBlockX();
int z = v.getBlockZ();
if (x < minX) minX = x;
if (z < minZ) minZ = z;
if (x > maxX) maxX = x;
if (z > maxZ) maxZ = z;
}
min = new BlockVector(minX, minY, minZ);
max = new BlockVector(maxX, maxY, maxZ);
}
@Override
public BlockVector getMinimumPoint() {
return min;
}
@Override
public BlockVector getMaximumPoint() {
return max;
}
/**
* Checks to see if a point is inside this region.
*/
@Override
public boolean contains(Vector pt) {
int targetX = pt.getBlockX(); //wide
int targetY = pt.getBlockY(); //height
int targetZ = pt.getBlockZ(); //depth
if (targetY < minY || targetY > maxY) {
return false;
}
//Quick and dirty check.
if(targetX < min.getBlockX() || targetX > max.getBlockX() || targetZ < min.getBlockZ() || targetZ > max.getBlockZ()){
return false;
}
boolean inside = false;
int npoints = points.size();
int xNew, zNew;
int xOld, zOld;
int x1, z1;
int x2, z2;
int i;
xOld = points.get(npoints - 1).getBlockX();
zOld = points.get(npoints - 1).getBlockZ();
for (i = 0; i < npoints; i++) {
xNew = points.get(i).getBlockX();
zNew = points.get(i).getBlockZ();
if (xNew > xOld) {
x1 = xOld;
x2 = xNew;
z1 = zOld;
z2 = zNew;
} else {
x1 = xNew;
x2 = xOld;
z1 = zNew;
z2 = zOld;
}
if ((xNew < targetX) == (targetX <= xOld)
&& ((long) targetZ - (long) z1) * (long) (x2 - x1) <= ((long) z2 - (long) z1)
* (long) (targetX - x1)) {
inside = !inside;
}
xOld = xNew;
zOld = zNew;
}
return inside;
}
/**
* Return the type of region as a user-friendly name.
*
* @return type of region
*/
@Override
public String getTypeName() {
return "polygon";
}
}

View File

@ -1,334 +1,361 @@
// $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.Vector;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.domains.DefaultDomain;
/**
* Represents a region of any shape and size that can be protected.
*
* @author sk89q
*/
public abstract class ProtectedRegion implements Comparable<ProtectedRegion> {
/**
* Holds the region's ID.
*/
private String id;
/**
* Priority.
*/
private int priority = 0;
/**
* Parent region.
*/
private ProtectedRegion parent;
/**
* List of owners.
*/
private DefaultDomain owners = new DefaultDomain();
/**
* List of members.
*/
private DefaultDomain members = new DefaultDomain();
/**
* Area flags.
*/
private AreaFlags flags = new AreaFlags();
/**
* Area message.
*/
private String enterMessage;
/**
* Area message.
*/
private String leaveMessage;
/**
* Construct a new instance of this region.
*
* @param id
*/
public ProtectedRegion(String id) {
this.id = id;
}
/**
* @return the id
*/
public String getId() {
return id;
}
/**
* Get the lower point of the cuboid.
*
* @return min point
*/
public abstract BlockVector getMinimumPoint();
/**
* Get the upper point of the cuboid.
*
* @return max point
*/
public abstract BlockVector getMaximumPoint();
/**
* @return the priority
*/
public int getPriority() {
return priority;
}
/**
* @param priority the priority to set
*/
public void setPriority(int priority) {
this.priority = priority;
}
/**
* @return the parent
*/
public ProtectedRegion getParent() {
return parent;
}
/**
* Set the parent. This checks to make sure that it will not result
* in circular inheritance.
*
* @param parent the parent to set
* @throws CircularInheritanceException
*/
public void setParent(ProtectedRegion parent) throws CircularInheritanceException {
if (parent == null) {
this.parent = null;
return;
}
if (parent == this) {
throw new CircularInheritanceException();
}
ProtectedRegion p = parent.getParent();
while (p != null) {
if (p == this) {
throw new CircularInheritanceException();
}
p = p.getParent();
}
this.parent = parent;
}
/**
* Se flags.
* @param flags
*/
public void setFlags(AreaFlags flags) {
this.flags = flags;
}
/**
* @return the enterMessage
*/
public String getEnterMessage() {
return enterMessage;
}
/**
* @param enterMessage the enterMessage to set
*/
public void setEnterMessage(String enterMessage) {
this.enterMessage = enterMessage;
}
/**
* @return the leaveMessage
*/
public String getLeaveMessage() {
return leaveMessage;
}
/**
* @param leaveMessage the leaveMessage to set
*/
public void setLeaveMessage(String leaveMessage) {
this.leaveMessage = leaveMessage;
}
/**
* @return the owners
*/
public DefaultDomain getOwners() {
return owners;
}
/**
* @param owners the owners to set
*/
public void setOwners(DefaultDomain owners) {
this.owners = owners;
}
/**
* @return the members
*/
public DefaultDomain getMembers() {
return members;
}
/**
* @param owners the owners to set
*/
public void setMembers(DefaultDomain members) {
this.members = members;
}
/**
* Checks whether a player is an owner of region or any of its parents.
*
* @param player
* @return
*/
public boolean isOwner(LocalPlayer player) {
if (owners.contains(player)) {
return true;
}
ProtectedRegion parent = getParent();
while (parent != null) {
if (parent.getOwners().contains(player)) {
return true;
}
parent = parent.getParent();
}
return false;
}
/**
* Checks whether a player is a member of the region or any of its parents.
*
* @param player
* @return
*/
public boolean isMember(LocalPlayer player) {
if (owners.contains(player) || members.contains(player)) {
return true;
}
ProtectedRegion parent = getParent();
while (parent != null) {
if (parent.getOwners().contains(player)
|| parent.getMembers().contains(player)) {
return true;
}
parent = parent.getParent();
}
return false;
}
/**
* Get flags.
*
* @return
*/
public AreaFlags getFlags() {
return flags;
}
/**
* Check to see if a point is inside this region.
*
* @param pt
* @return
*/
public abstract boolean contains(Vector pt);
/**
* Compares to another region.
*
* @param other
* @return
*/
public int compareTo(ProtectedRegion other) {
if (priority == other.priority) {
return 0;
} else if (priority > other.priority) {
return -1;
} else {
return 1;
}
}
/**
* Return the type of region as a user-friendly, lowercase name.
*
* @return type of region
*/
public abstract String getTypeName();
/**
* Checks if two region intersects.
*
* @param region1
* @param region2
* @throws UnsupportedIntersectionException
* @return
*/
public static boolean intersects(ProtectedRegion region1, ProtectedRegion region2)
throws UnsupportedIntersectionException {
if (region1 instanceof ProtectedCuboidRegion
&& region2 instanceof ProtectedCuboidRegion) {
ProtectedCuboidRegion r1 = (ProtectedCuboidRegion)region1;
ProtectedCuboidRegion r2 = (ProtectedCuboidRegion)region2;
BlockVector min1 = r1.getMinimumPoint();
BlockVector max1 = r1.getMaximumPoint();
BlockVector min2 = r2.getMinimumPoint();
BlockVector max2 = r2.getMaximumPoint();
return !(min1.getBlockX() > max2.getBlockX()
|| min1.getBlockY() > max2.getBlockY()
|| min1.getBlockZ() > max2.getBlockZ()
|| max1.getBlockX() < min2.getBlockX()
|| max1.getBlockY() < min2.getBlockY()
|| max1.getBlockZ() < min2.getBlockZ());
} else {
throw new UnsupportedIntersectionException();
}
}
/**
* Thrown when setting a parent would create a circular inheritance
* situation.
*
*/
public static class CircularInheritanceException extends Exception {
private static final long serialVersionUID = 7479613488496776022L;
}
}
// $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.regions;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.domains.DefaultDomain;
import com.sk89q.worldguard.protection.UnsupportedIntersectionException;
/**
* Represents a region of any shape and size that can be protected.
*
* @author sk89q
*/
public abstract class ProtectedRegion implements Comparable<ProtectedRegion> {
/**
* Holds the region's ID.
*/
private String id;
/**
* Priority.
*/
private int priority = 0;
/**
* Holds the parent.
*/
private transient ProtectedRegion parent;
/**
* Holds the parent's Id. Used for serialization, don't touch it.
*/
private String parentId;
/**
* List of owners.
*/
private DefaultDomain owners = new DefaultDomain();
/**
* List of members.
*/
private DefaultDomain members = new DefaultDomain();
/**
* Area flags.
*/
private AreaFlags flags = new AreaFlags();
/**
* Area message.
*/
private String enterMessage;
/**
* Area message.
*/
private String leaveMessage;
/**
* Construct a new instance of this region.
*
* @param id
*/
public ProtectedRegion(String id) {
this.id = id;
}
/**
* @return the id
*/
public String getId() {
return id;
}
/**
* @return the parentId.
*/
public String getParentId() {
this.setParentId();
return parentId;
}
/**
* @set the parentId. Used for serialization, don't touch it.
*/
public void setParentId() {
if (this.parent != null) {
this.parentId = parent.getId();
} else {
this.parentId = null;
}
}
/**
* Get the lower point of the cuboid.
*
* @return min point
*/
public abstract BlockVector getMinimumPoint();
/**
* Get the upper point of the cuboid.
*
* @return max point
*/
public abstract BlockVector getMaximumPoint();
/**
* @return the priority
*/
public int getPriority() {
return priority;
}
/**
* @param priority the priority to set
*/
public void setPriority(int priority) {
this.priority = priority;
}
/**
* @return the parent
*/
public ProtectedRegion getParent() {
return parent;
}
/**
* Set the parent. This checks to make sure that it will not result
* in circular inheritance.
*
* @param parent the parent to set
* @throws CircularInheritanceException
*/
public void setParent(ProtectedRegion parent) throws CircularInheritanceException {
if (parent == null) {
this.parent = null;
return;
}
if (parent == this) {
throw new CircularInheritanceException();
}
ProtectedRegion p = parent.getParent();
while (p != null) {
if (p == this) {
throw new CircularInheritanceException();
}
p = p.getParent();
}
this.parent = parent;
}
/**
* Se flags.
* @param flags
*/
public void setFlags(AreaFlags flags) {
this.flags = flags;
}
/**
* @return the enterMessage
*/
public String getEnterMessage() {
return enterMessage;
}
/**
* @param enterMessage the enterMessage to set
*/
public void setEnterMessage(String enterMessage) {
this.enterMessage = enterMessage;
}
/**
* @return the leaveMessage
*/
public String getLeaveMessage() {
return leaveMessage;
}
/**
* @param leaveMessage the leaveMessage to set
*/
public void setLeaveMessage(String leaveMessage) {
this.leaveMessage = leaveMessage;
}
/**
* @return the owners
*/
public DefaultDomain getOwners() {
return owners;
}
/**
* @param owners the owners to set
*/
public void setOwners(DefaultDomain owners) {
this.owners = owners;
}
/**
* @return the members
*/
public DefaultDomain getMembers() {
return members;
}
/**
* @param owners the owners to set
*/
public void setMembers(DefaultDomain members) {
this.members = members;
}
/**
* Checks whether a player is an owner of region or any of its parents.
*
* @param player
* @return
*/
public boolean isOwner(LocalPlayer player) {
if (owners.contains(player)) {
return true;
}
ProtectedRegion parent = getParent();
while (parent != null) {
if (parent.getOwners().contains(player)) {
return true;
}
parent = parent.getParent();
}
return false;
}
/**
* Checks whether a player is a member of the region or any of its parents.
*
* @param player
* @return
*/
public boolean isMember(LocalPlayer player) {
if (owners.contains(player) || members.contains(player)) {
return true;
}
ProtectedRegion parent = getParent();
while (parent != null) {
if (parent.getOwners().contains(player)
|| parent.getMembers().contains(player)) {
return true;
}
parent = parent.getParent();
}
return false;
}
/**
* Get flags.
*
* @return
*/
public AreaFlags getFlags() {
return flags;
}
/**
* Check to see if a point is inside this region.
*
* @param pt
* @return
*/
public abstract boolean contains(Vector pt);
/**
* Compares to another region.
*
* @param other
* @return
*/
public int compareTo(ProtectedRegion other) {
if (priority == other.priority) {
return 0;
} else if (priority > other.priority) {
return -1;
} else {
return 1;
}
}
/**
* Return the type of region as a user-friendly, lowercase name.
*
* @return type of region
*/
public abstract String getTypeName();
/**
* Checks if two region intersects.
*
* @param region1
* @param region2
* @throws UnsupportedIntersectionException
* @return
*/
public static boolean intersects(ProtectedRegion region1, ProtectedRegion region2)
throws UnsupportedIntersectionException {
if (region1 instanceof ProtectedCuboidRegion
&& region2 instanceof ProtectedCuboidRegion) {
ProtectedCuboidRegion r1 = (ProtectedCuboidRegion)region1;
ProtectedCuboidRegion r2 = (ProtectedCuboidRegion)region2;
BlockVector min1 = r1.getMinimumPoint();
BlockVector max1 = r1.getMaximumPoint();
BlockVector min2 = r2.getMinimumPoint();
BlockVector max2 = r2.getMaximumPoint();
return !(min1.getBlockX() > max2.getBlockX()
|| min1.getBlockY() > max2.getBlockY()
|| min1.getBlockZ() > max2.getBlockZ()
|| max1.getBlockX() < min2.getBlockX()
|| max1.getBlockY() < min2.getBlockY()
|| max1.getBlockZ() < min2.getBlockZ());
} else {
throw new UnsupportedIntersectionException();
}
}
/**
* Thrown when setting a parent would create a circular inheritance
* situation.
*
*/
public static class CircularInheritanceException extends Exception {
private static final long serialVersionUID = 7479613488496776022L;
}
}

View File

@ -1,41 +1,42 @@
// $Id$
/*
* WorldGuard
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.protection;
import org.khelekore.prtree.MBRConverter;
public class ProtectedRegionMBRConverter implements MBRConverter<ProtectedRegion> {
public double getMinX(ProtectedRegion t) {
return t.getMinimumPoint().getBlockX();
}
public double getMinY(ProtectedRegion t) {
return t.getMinimumPoint().getBlockZ();
}
public double getMaxX(ProtectedRegion t) {
return t.getMaximumPoint().getBlockX();
}
public double getMaxY(ProtectedRegion t) {
return t.getMaximumPoint().getBlockZ();
}
}
// $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.regions;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import org.khelekore.prtree.MBRConverter;
public class ProtectedRegionMBRConverter implements MBRConverter<ProtectedRegion> {
public double getMinX(ProtectedRegion t) {
return t.getMinimumPoint().getBlockX();
}
public double getMinY(ProtectedRegion t) {
return t.getMinimumPoint().getBlockZ();
}
public double getMaxX(ProtectedRegion t) {
return t.getMaximumPoint().getBlockX();
}
public double getMaxY(ProtectedRegion t) {
return t.getMaximumPoint().getBlockZ();
}
}

View File

@ -19,6 +19,11 @@
package com.sk89q.worldguard.protection;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
import com.sk89q.worldguard.protection.regionmanager.FlatRegionManager;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
@ -27,7 +32,8 @@
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.TestPlayer;
import com.sk89q.worldguard.domains.DefaultDomain;
import com.sk89q.worldguard.protection.AreaFlags.State;
import com.sk89q.worldguard.protection.regions.AreaFlags;
import com.sk89q.worldguard.protection.regions.AreaFlags.State;
import java.util.ArrayList;
import java.util.List;
@ -50,7 +56,7 @@ public class ApplicableRegionSetTest {
@Before
public void setUp() throws Exception {
manager = new FlatRegionManager(new GlobalFlags());
manager = new FlatRegionManager(new GlobalFlags(), null);
setUpPlayers();
setUpCourtyardRegion();

View File

@ -19,6 +19,9 @@
package com.sk89q.worldguard.protection;
import com.sk89q.worldguard.protection.dbs.CSVDatabase;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import java.io.*;
import java.util.Map;
import java.util.HashMap;
@ -28,7 +31,8 @@
import static org.junit.Assert.*;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldguard.domains.DefaultDomain;
import com.sk89q.worldguard.protection.AreaFlags.State;
import com.sk89q.worldguard.protection.regions.AreaFlags;
import com.sk89q.worldguard.protection.regions.AreaFlags.State;
public class CSVDatabaseTest {
@Before