mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-12-25 02:27:42 +01:00
rewrote flag system to end the madness
This commit is contained in:
parent
cdf067bba8
commit
30b0e5d0b1
@ -18,6 +18,8 @@
|
||||
*/
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import com.sk89q.worldguard.protection.regions.flags.RegionFlagContainer;
|
||||
import com.sk89q.worldguard.protection.regions.flags.FlagDatabase.FlagType;
|
||||
import com.nijiko.coelho.iConomy.iConomy;
|
||||
import com.nijiko.coelho.iConomy.system.Account;
|
||||
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
|
||||
@ -30,7 +32,6 @@
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.block.*;
|
||||
import org.bukkit.event.block.BlockIgniteEvent.IgniteCause;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -39,8 +40,6 @@
|
||||
import com.sk89q.worldguard.blacklist.events.*;
|
||||
import com.sk89q.worldguard.domains.DefaultDomain;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.regions.AreaFlags;
|
||||
import com.sk89q.worldguard.protection.regions.AreaFlags.State;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.*;
|
||||
@ -228,7 +227,7 @@ public void onBlockFlow(BlockFromToEvent event) {
|
||||
Vector pt = toVector(blockFrom.getLocation());
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().getRegionManager(world.getName());
|
||||
|
||||
if (!mgr.getApplicableRegions(pt).allowsFlag("waterflow")) {
|
||||
if (!mgr.getApplicableRegions(pt).allowsFlag(FlagType.WATER_FLOW)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -274,18 +273,18 @@ public void onBlockIgnite(BlockIgniteEvent event) {
|
||||
}
|
||||
|
||||
if (cause == IgniteCause.FLINT_AND_STEEL
|
||||
&& !set.allowsFlag(AreaFlags.FLAG_LIGHTER)) {
|
||||
&& !set.allowsFlag(FlagType.LIGHTER)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (isFireSpread && set.allowsFlag(AreaFlags.FLAG_FIRE_SPREAD)) {
|
||||
if (isFireSpread && set.allowsFlag(FlagType.FIRE_SPREAD)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (cause == IgniteCause.LAVA && !set.allowsFlag(AreaFlags.FLAG_LAVA_FIRE)) {
|
||||
if (cause == IgniteCause.LAVA && !set.allowsFlag(FlagType.LAVA_FIRE)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -429,7 +428,7 @@ public void onBlockInteract(BlockInteractEvent event) {
|
||||
|
||||
if (!cfg.hasPermission(player, "region.bypass")) {
|
||||
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
|
||||
if (!set.allowsFlag(AreaFlags.FLAG_CHEST_ACCESS) && !set.canBuild(localPlayer)) {
|
||||
if (!set.allowsFlag(FlagType.CHEST_ACCESS) && !set.canBuild(localPlayer)) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
@ -444,7 +443,7 @@ public void onBlockInteract(BlockInteractEvent event) {
|
||||
ApplicableRegionSet applicableRegions = mgr.getApplicableRegions(pt);
|
||||
LocalPlayer localPlayer = BukkitPlayer.wrapPlayer(cfg, (Player)entity);
|
||||
|
||||
if (!applicableRegions.isFlagAllowed(AreaFlags.FLAG_LEVER_AND_BUTTON, true, null)) {
|
||||
if (!applicableRegions.allowsFlag(FlagType.LEVER_AND_BUTTON, localPlayer)) {
|
||||
((Player)entity).sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
@ -582,13 +581,13 @@ public void onBlockRightClick(BlockRightClickEvent event) {
|
||||
ProtectedRegion region = mgr.getRegion(regionId);
|
||||
|
||||
if (region != null) {
|
||||
AreaFlags flags = region.getFlags();
|
||||
RegionFlagContainer flags = region.getFlags();
|
||||
|
||||
if (flags.getBooleanFlag("iconomy", "buyable", false)) {
|
||||
if (flags.getBooleanFlag(FlagType.BUYABLE).getValue(false)) {
|
||||
if (iConomy.getBank().hasAccount(player.getName())) {
|
||||
Account account = iConomy.getBank().getAccount(player.getName());
|
||||
double balance = account.getBalance();
|
||||
int regionPrice = flags.getIntFlag("iconomy", "price");
|
||||
double regionPrice = flags.getIntegerFlag(FlagType.PRICE).getValue();
|
||||
|
||||
if (balance >= regionPrice) {
|
||||
account.subtract(regionPrice);
|
||||
@ -597,7 +596,7 @@ public void onBlockRightClick(BlockRightClickEvent event) {
|
||||
DefaultDomain owners = region.getOwners();
|
||||
owners.addPlayer(player.getName());
|
||||
region.setOwners(owners);
|
||||
flags.setFlag("iconomy", "buyable", false);
|
||||
flags.getBooleanFlag(FlagType.BUYABLE).setValue(false);
|
||||
account.save();
|
||||
}
|
||||
} else {
|
||||
|
@ -18,6 +18,7 @@
|
||||
*/
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import com.sk89q.worldguard.protection.regions.flags.FlagDatabase.FlagType;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -34,7 +35,6 @@
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BlockType;
|
||||
import com.sk89q.worldguard.protection.regions.AreaFlags;
|
||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.*;
|
||||
|
||||
public class WorldGuardEntityListener extends EntityListener {
|
||||
@ -102,7 +102,7 @@ public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
||||
Vector pt = toVector(defender.getLocation());
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().getRegionManager(player.getWorld().getName());
|
||||
|
||||
if (!mgr.getApplicableRegions(pt).allowsFlag(AreaFlags.FLAG_PVP)) {
|
||||
if (!mgr.getApplicableRegions(pt).allowsFlag(FlagType.PVP)) {
|
||||
((Player) attacker).sendMessage(ChatColor.DARK_RED + "You are in a no-PvP area.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
@ -121,13 +121,13 @@ public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().getRegionManager(player.getWorld().getName());
|
||||
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
|
||||
|
||||
if (!set.allowsFlag(AreaFlags.FLAG_MOB_DAMAGE)) {
|
||||
if (!set.allowsFlag(FlagType.MOB_DAMAGE)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (attacker instanceof Creeper) {
|
||||
if (!set.allowsFlag(AreaFlags.FLAG_CREEPER_EXPLOSION)) {
|
||||
if (!set.allowsFlag(FlagType.CREEPER_EXPLOSION)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -158,7 +158,7 @@ public void onEntityDamageByProjectile(EntityDamageByProjectileEvent event) {
|
||||
Vector pt = toVector(defender.getLocation());
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().getRegionManager(player.getWorld().getName());
|
||||
|
||||
if (!mgr.getApplicableRegions(pt).allowsFlag(AreaFlags.FLAG_PVP)) {
|
||||
if (!mgr.getApplicableRegions(pt).allowsFlag(FlagType.PVP)) {
|
||||
((Player) attacker).sendMessage(ChatColor.DARK_RED + "You are in a no-PvP area.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
@ -170,7 +170,7 @@ public void onEntityDamageByProjectile(EntityDamageByProjectileEvent event) {
|
||||
Vector pt = toVector(defender.getLocation());
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().getRegionManager(player.getWorld().getName());
|
||||
|
||||
if (!mgr.getApplicableRegions(pt).allowsFlag(AreaFlags.FLAG_MOB_DAMAGE)) {
|
||||
if (!mgr.getApplicableRegions(pt).allowsFlag(FlagType.MOB_DAMAGE)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -275,7 +275,7 @@ public void onEntityExplode(EntityExplodeEvent event) {
|
||||
Vector pt = toVector(l);
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().getRegionManager(wcfg.getWorldName());
|
||||
|
||||
if (!mgr.getApplicableRegions(pt).allowsFlag(AreaFlags.FLAG_CREEPER_EXPLOSION)) {
|
||||
if (!mgr.getApplicableRegions(pt).allowsFlag(FlagType.CREEPER_EXPLOSION)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -290,7 +290,7 @@ public void onEntityExplode(EntityExplodeEvent event) {
|
||||
Vector pt = toVector(l);
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().getRegionManager(wcfg.getWorldName());
|
||||
|
||||
if (!mgr.getApplicableRegions(pt).allowsFlag(AreaFlags.FLAG_TNT)) {
|
||||
if (!mgr.getApplicableRegions(pt).allowsFlag(FlagType.TNT)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -386,11 +386,11 @@ public void onCreatureSpawn(CreatureSpawnEvent event) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (wcfg.useRegions && creaName != "") {
|
||||
if (wcfg.useRegions && !creaName.equals("")) {
|
||||
Vector pt = toVector(event.getEntity().getLocation());
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().getRegionManager(event.getEntity().getWorld().getName());
|
||||
|
||||
Boolean flagValue = mgr.getApplicableRegions(pt).getBooleanAreaFlag("creaturespawn", creaName, true, null);
|
||||
Boolean flagValue = mgr.getApplicableRegions(pt).getStringFlag(FlagType.DENY_SPAWN, true).getValue("").contains(creaName);
|
||||
if (flagValue != null) {
|
||||
if (!flagValue) {
|
||||
cancelEvent = true;
|
||||
|
@ -18,6 +18,8 @@
|
||||
*/
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import com.sk89q.worldguard.protection.regions.flags.RegionFlag.RegionGroup;
|
||||
import com.sk89q.worldguard.protection.regions.flags.FlagDatabase.FlagType;
|
||||
import com.nijiko.coelho.iConomy.iConomy;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
|
||||
@ -31,8 +33,6 @@
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldguard.blacklist.events.ItemUseBlacklistEvent;
|
||||
import com.sk89q.worldguard.protection.regions.AreaFlags;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.*;
|
||||
|
||||
@ -155,7 +155,7 @@ public void onPlayerItem(PlayerItemEvent event) {
|
||||
Vector pt = toVector(block.getRelative(event.getBlockFace()));
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().getRegionManager(player.getWorld().getName());
|
||||
|
||||
if (!mgr.getApplicableRegions(pt).allowsFlag(AreaFlags.FLAG_LIGHTER)) {
|
||||
if (!mgr.getApplicableRegions(pt).allowsFlag(FlagType.LIGHTER)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -258,17 +258,17 @@ public void onPlayerRespawn(PlayerRespawnEvent event) {
|
||||
player.getWorld().getName()).getApplicableRegions(
|
||||
BukkitUtil.toVector(location));
|
||||
|
||||
Location spawn = regions.getLocationAreaFlag("spawn", player.getServer(), true, null);
|
||||
Location spawn = regions.getLocationFlag(FlagType.SPAWN_LOC, true).getValue(player.getServer());
|
||||
|
||||
if (spawn != null) {
|
||||
String spawnconfig = regions.getAreaFlag("spawn", "allow", true, null);
|
||||
RegionGroup spawnconfig = regions.getRegionGroupFlag(FlagType.SPAWN_PERM, true).getValue();
|
||||
if (spawnconfig != null) {
|
||||
BukkitPlayer localPlayer = BukkitPlayer.wrapPlayer(cfg, player);
|
||||
if (spawnconfig.equals("owner")) {
|
||||
if (spawnconfig == RegionGroup.OWNER) {
|
||||
if (regions.isOwner(localPlayer)) {
|
||||
event.setRespawnLocation(spawn);
|
||||
}
|
||||
} else if (spawnconfig.equals("member")) {
|
||||
} else if (spawnconfig == RegionGroup.MEMBER) {
|
||||
if (regions.isMember(localPlayer)) {
|
||||
event.setRespawnLocation(spawn);
|
||||
}
|
||||
|
@ -28,8 +28,9 @@
|
||||
import com.sk89q.worldguard.domains.DefaultDomain;
|
||||
import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException;
|
||||
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.AreaFlags;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import com.sk89q.worldguard.protection.regions.flags.FlagDatabase.FlagType;
|
||||
import com.sk89q.worldguard.protection.regions.flags.RegionFlagContainer;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -57,13 +58,13 @@ public boolean handle(CommandSender sender, String senderName, String command, S
|
||||
RegionManager mgr = cfg.getWorldGuardPlugin().getGlobalRegionManager().getRegionManager(player.getWorld().getName());
|
||||
ProtectedRegion region = mgr.getRegion(id);
|
||||
if (region != null) {
|
||||
AreaFlags flags = region.getFlags();
|
||||
RegionFlagContainer flags = region.getFlags();
|
||||
|
||||
if (flags.getBooleanFlag("iconomy", "buyable", false)) {
|
||||
if (flags.getBooleanFlag(FlagType.BUYABLE).getValue(false)) {
|
||||
if (args.length == 2) {
|
||||
if (args[1] == "info") {
|
||||
player.sendMessage(ChatColor.YELLOW + "Region " + id + " costs " +
|
||||
iConomy.getBank().format(flags.getDoubleFlag("iconomy", "price")));
|
||||
iConomy.getBank().format(flags.getDoubleFlag(FlagType.PRICE).getValue()));
|
||||
if (iConomy.getBank().hasAccount(player.getName())) {
|
||||
player.sendMessage(ChatColor.YELLOW + "You have " +
|
||||
iConomy.getBank().format(
|
||||
@ -78,7 +79,7 @@ public boolean handle(CommandSender sender, String senderName, String command, S
|
||||
if (iConomy.getBank().hasAccount(player.getName())) {
|
||||
Account account = iConomy.getBank().getAccount(player.getName());
|
||||
double balance = account.getBalance();
|
||||
int regionPrice = flags.getIntFlag("iconomy", "price");
|
||||
double regionPrice = flags.getDoubleFlag(FlagType.PRICE).getValue();
|
||||
|
||||
if (balance >= regionPrice) {
|
||||
account.subtract(regionPrice);
|
||||
@ -87,7 +88,7 @@ public boolean handle(CommandSender sender, String senderName, String command, S
|
||||
DefaultDomain owners = region.getOwners();
|
||||
owners.addPlayer(player.getName());
|
||||
region.setOwners(owners);
|
||||
flags.setFlag("iconomy", "buyable", false);
|
||||
flags.getBooleanFlag(FlagType.BUYABLE).setValue(false);
|
||||
account.save();
|
||||
}
|
||||
} else {
|
||||
|
@ -24,8 +24,10 @@
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardWorldConfiguration;
|
||||
import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException;
|
||||
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.AreaFlags;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import com.sk89q.worldguard.protection.regions.flags.FlagDatabase;
|
||||
import com.sk89q.worldguard.protection.regions.flags.RegionFlag.FlagDataType;
|
||||
import com.sk89q.worldguard.protection.regions.flags.RegionFlagInfo;
|
||||
import java.io.IOException;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
@ -40,20 +42,18 @@ public class CommandRegionFlag extends WgRegionCommand {
|
||||
|
||||
public boolean handle(CommandSender sender, String senderName, String command, String[] args, WorldGuardConfiguration cfg, WorldGuardWorldConfiguration wcfg) throws CommandHandlingException {
|
||||
|
||||
CommandHandler.checkArgs(args, 3, 4, "/region flag <regionid> <name> (<subname>) <value>");
|
||||
CommandHandler.checkArgs(args, 2, -1, "/region flag <regionid> <name> (<value>) [no value to unset flag]");
|
||||
|
||||
try {
|
||||
String id = args[0].toLowerCase();
|
||||
String nameStr = args[1];
|
||||
String subnameStr = null;
|
||||
String valueStr = null;
|
||||
if (args.length < 4) {
|
||||
|
||||
if (args.length == 3) {
|
||||
valueStr = args[2];
|
||||
} else {
|
||||
subnameStr = args[2];
|
||||
} else if (args.length > 3) {
|
||||
StringBuilder tmp = new StringBuilder();
|
||||
for(int i=3; i < args.length; i++)
|
||||
{
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
tmp.append(args[i]);
|
||||
}
|
||||
valueStr = tmp.toString();
|
||||
@ -81,135 +81,52 @@ public boolean handle(CommandSender sender, String senderName, String command, S
|
||||
cfg.checkRegionPermission(sender, "region.flag.foreignregions");
|
||||
}
|
||||
|
||||
FlagInfo nfo = FlagInfo.getFlagInfo(nameStr, subnameStr);
|
||||
RegionFlagInfo nfo = FlagDatabase.getFlagInfoFromName(nameStr);
|
||||
|
||||
if (nfo == null) {
|
||||
sender.sendMessage(ChatColor.RED + "Unknown flag specified.");
|
||||
return true;
|
||||
} else if (nfo.subName != null && args.length < 4) {
|
||||
sender.sendMessage(ChatColor.RED + "Name a subflag and a value to set this flag.");
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean validValue = false;
|
||||
switch (nfo.type) {
|
||||
case STRING: {
|
||||
validValue = true;
|
||||
break;
|
||||
if (nfo.dataType == FlagDataType.LOCATION) {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(ChatColor.RED + "Flag not supported in console mode.");
|
||||
return true;
|
||||
}
|
||||
case INT: {
|
||||
validValue = true;
|
||||
try {
|
||||
Integer val = Integer.valueOf(valueStr);
|
||||
} catch (Exception e) {
|
||||
validValue = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BOOLEAN: {
|
||||
valueStr = valueStr.toLowerCase();
|
||||
if (valueStr.equals("on")) {
|
||||
valueStr = "true";
|
||||
} else if (valueStr.equals("allow")) {
|
||||
valueStr = "true";
|
||||
} else if (valueStr.equals("1")) {
|
||||
valueStr = "true";
|
||||
}
|
||||
validValue = true;
|
||||
break;
|
||||
}
|
||||
case FLOAT: {
|
||||
validValue = true;
|
||||
try {
|
||||
Float val = Float.valueOf(valueStr);
|
||||
} catch (Exception e) {
|
||||
validValue = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case DOUBLE: {
|
||||
validValue = true;
|
||||
try {
|
||||
Double val = Double.valueOf(valueStr);
|
||||
} catch (Exception e) {
|
||||
validValue = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case STATE: {
|
||||
validValue = true;
|
||||
Player player = (Player) sender;
|
||||
|
||||
Location l = player.getLocation();
|
||||
|
||||
if (valueStr != null && valueStr.equals("set")) {
|
||||
|
||||
if (region.contains(BukkitUtil.toVector(l))) {
|
||||
region.getFlags().getLocationFlag(nfo.type).setValue(l);
|
||||
sender.sendMessage(ChatColor.YELLOW + "Region '" + id + "' updated. Flag " + nameStr + " set to current location");
|
||||
return true;
|
||||
|
||||
if (valueStr.equalsIgnoreCase("allow")) {
|
||||
valueStr = AreaFlags.State.ALLOW.toString();
|
||||
} else if (valueStr.equalsIgnoreCase("deny")) {
|
||||
valueStr = AreaFlags.State.DENY.toString();
|
||||
} else if (valueStr.equalsIgnoreCase("none")) {
|
||||
valueStr = AreaFlags.State.NONE.toString();
|
||||
} else {
|
||||
validValue = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case LOCATION: {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(ChatColor.RED + "Flag not supported in console mode.");
|
||||
return true;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
|
||||
Location l = player.getLocation();
|
||||
|
||||
if (valueStr.equals("set")) {
|
||||
|
||||
if (region.contains(BukkitUtil.toVector(l))) {
|
||||
region.getFlags().setLocationFlag(nfo.flagName, l);
|
||||
validValue = true;
|
||||
sender.sendMessage(ChatColor.YELLOW + "Region '" + id + "' updated. Flag " + nameStr + " set to current location");
|
||||
|
||||
} else {
|
||||
player.sendMessage(ChatColor.RED + "You must set the " + nameStr + " location inside the region it belongs to.");
|
||||
return true;
|
||||
}
|
||||
|
||||
} else if (valueStr.equals("delete")) {
|
||||
region.getFlags().setLocationFlag(nfo.flagName, null);
|
||||
validValue = true;
|
||||
sender.sendMessage(ChatColor.YELLOW + "Region '" + id + "' updated. Flag " + nameStr + " removed.");
|
||||
}
|
||||
|
||||
|
||||
if (validValue) {
|
||||
mgr.save();
|
||||
player.sendMessage(ChatColor.RED + "You must set the " + nameStr + " location inside the region it belongs to.");
|
||||
return true;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
validValue = false;
|
||||
break;
|
||||
} else if (valueStr == null || valueStr.equals("delete")) {
|
||||
region.getFlags().getLocationFlag(nfo.type).setValue((Location) null);
|
||||
sender.sendMessage(ChatColor.YELLOW + "Region '" + id + "' updated. Flag " + nameStr + " removed.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
String fullFlagname = nameStr;
|
||||
if (subnameStr != null) {
|
||||
fullFlagname += " " + subnameStr;
|
||||
}
|
||||
|
||||
if (!validValue) {
|
||||
sender.sendMessage(ChatColor.RED + "Invalid value '" + valueStr + "' for flag " + fullFlagname);
|
||||
if (!region.getFlags().getLocationFlag(nfo.type).setValue(valueStr)) {
|
||||
sender.sendMessage(ChatColor.RED + "Invalid value '" + valueStr + "' for flag " + nameStr);
|
||||
return true;
|
||||
} else {
|
||||
mgr.save();
|
||||
if (valueStr == null) {
|
||||
valueStr = "null";
|
||||
}
|
||||
sender.sendMessage(ChatColor.YELLOW + "Region '" + id + "' updated. Flag " + nameStr + " set to " + valueStr);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (nfo.subName != null && nfo.subName.equals("*")) {
|
||||
region.getFlags().setFlag(nfo.flagName, subnameStr, valueStr);
|
||||
} else {
|
||||
region.getFlags().setFlag(nfo.flagName, nfo.flagSubName, valueStr);
|
||||
}
|
||||
|
||||
mgr.save();
|
||||
|
||||
sender.sendMessage(ChatColor.YELLOW + "Region '" + id + "' updated. Flag " + fullFlagname + " set to " + valueStr);
|
||||
} catch (IOException e) {
|
||||
sender.sendMessage(ChatColor.RED + "Region database failed to save: "
|
||||
+ e.getMessage());
|
||||
|
@ -22,14 +22,12 @@
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardConfiguration;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardWorldConfiguration;
|
||||
import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException;
|
||||
import com.sk89q.worldguard.bukkit.commands.FlagInfo.FlagValueType;
|
||||
import com.sk89q.worldguard.domains.DefaultDomain;
|
||||
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.AreaFlags;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.sk89q.worldguard.protection.regions.flags.FlagDatabase;
|
||||
import com.sk89q.worldguard.protection.regions.flags.RegionFlagContainer;
|
||||
import com.sk89q.worldguard.protection.regions.flags.RegionFlagInfo;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -68,7 +66,7 @@ public boolean handle(CommandSender sender, String senderName, String command, S
|
||||
cfg.checkRegionPermission(sender, "region.info.foreignregions");
|
||||
}
|
||||
|
||||
AreaFlags flags = region.getFlags();
|
||||
RegionFlagContainer flags = region.getFlags();
|
||||
DefaultDomain owners = region.getOwners();
|
||||
DefaultDomain members = region.getMembers();
|
||||
|
||||
@ -77,44 +75,13 @@ public boolean handle(CommandSender sender, String senderName, String command, S
|
||||
sender.sendMessage(ChatColor.BLUE + "Priority: " + region.getPriority());
|
||||
|
||||
StringBuilder s = new StringBuilder();
|
||||
List<String> displayLocations = new ArrayList<String>();
|
||||
|
||||
for (FlagInfo nfo : FlagInfo.getFlagInfoList()) {
|
||||
for (RegionFlagInfo nfo : FlagDatabase.getFlagInfoList()) {
|
||||
if (s.length() > 0) {
|
||||
s.append(", ");
|
||||
}
|
||||
|
||||
String fullName = nfo.name;
|
||||
if (nfo.subName != null && nfo.subName != "*") {
|
||||
fullName += " " + nfo.subName;
|
||||
}
|
||||
|
||||
String value;
|
||||
if (nfo.type == FlagValueType.LOCATION && !displayLocations.contains(nfo.flagName)) {
|
||||
value = flags.getFlag(nfo.flagName, "x");
|
||||
if (value != null) {
|
||||
s.append(nfo.flagName + ": set");
|
||||
} else {
|
||||
s.append(nfo.flagName + ": -");
|
||||
}
|
||||
displayLocations.add(nfo.flagName);
|
||||
} else if ((nfo.subName != null && nfo.subName.equals("*"))) {
|
||||
StringBuilder ret = new StringBuilder();
|
||||
for (Map.Entry<String, String> entry : flags.getFlagData(nfo.flagName).entrySet()) {
|
||||
if (Boolean.valueOf(entry.getValue())) {
|
||||
ret.append(entry.getKey() + " ");
|
||||
}
|
||||
}
|
||||
s.append(fullName + ": " + ret);
|
||||
} else {
|
||||
value = flags.getFlag(nfo.flagName, nfo.flagSubName);
|
||||
if (value != null) {
|
||||
s.append(fullName + ": " + value);
|
||||
} else {
|
||||
s.append(fullName + ": -");
|
||||
}
|
||||
}
|
||||
|
||||
s.append(flags.getFlag(nfo.type).toString());
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.BLUE + "Flags: " + s.toString());
|
||||
|
@ -14,6 +14,9 @@
|
||||
import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException;
|
||||
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import com.sk89q.worldguard.protection.regions.flags.FlagDatabase.FlagType;
|
||||
import com.sk89q.worldguard.protection.regions.flags.RegionFlag.RegionGroup;
|
||||
import com.sk89q.worldguard.protection.regions.flags.RegionGroupRegionFlag;
|
||||
|
||||
/**
|
||||
* @author wallnuss
|
||||
@ -42,19 +45,19 @@ public boolean handle(CommandSender sender, String senderName, String command, S
|
||||
ProtectedRegion region = mgr.getRegion(id);
|
||||
if (region != null) {
|
||||
|
||||
String flagright = "all";
|
||||
RegionGroup flagright;
|
||||
if (spawn) {
|
||||
flagright = region.getFlags().getFlag("spawn", "allow");
|
||||
flagright = region.getFlags().getRegionGroupFlag(FlagType.SPAWN_PERM).getValue(RegionGroup.ALL);
|
||||
} else {
|
||||
flagright = region.getFlags().getFlag("teleport", "allow");
|
||||
flagright = region.getFlags().getRegionGroupFlag(FlagType.TELE_PERM).getValue(RegionGroup.ALL);
|
||||
}
|
||||
|
||||
LocalPlayer lPlayer = BukkitPlayer.wrapPlayer(cfg, player);
|
||||
if (flagright.equals("owner")) {
|
||||
if (flagright == RegionGroup.OWNER) {
|
||||
if (!region.isOwner(lPlayer)) {
|
||||
cfg.checkPermission(player, "tpregion.override");
|
||||
}
|
||||
} else if (flagright.equals("member")) {
|
||||
} else if (flagright == RegionGroup.MEMBER) {
|
||||
if (!region.isMember(lPlayer)) {
|
||||
cfg.checkPermission(player, "tpregion.override");
|
||||
}
|
||||
@ -63,9 +66,9 @@ public boolean handle(CommandSender sender, String senderName, String command, S
|
||||
Location location = null;
|
||||
|
||||
if (spawn) {
|
||||
location = region.getFlags().getLocationFlag(cfg.getWorldGuardPlugin().getServer(), "spawn");
|
||||
location = region.getFlags().getLocationFlag(FlagType.SPAWN_LOC).getValue(cfg.getWorldGuardPlugin().getServer());
|
||||
} else {
|
||||
location = region.getFlags().getLocationFlag(cfg.getWorldGuardPlugin().getServer(), "teleport");
|
||||
location = region.getFlags().getLocationFlag(FlagType.TELE_LOC).getValue(cfg.getWorldGuardPlugin().getServer());
|
||||
}
|
||||
if (location != null) {
|
||||
player.teleportTo(location);
|
||||
|
@ -1,104 +0,0 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.bukkit.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Michael
|
||||
*/
|
||||
|
||||
public class FlagInfo {
|
||||
|
||||
public static enum FlagValueType { STRING, BOOLEAN, INT, FLOAT, DOUBLE, STATE, LOCATION };
|
||||
|
||||
public String name;
|
||||
public String subName;
|
||||
public FlagValueType type;
|
||||
public String flagName;
|
||||
public String flagSubName;
|
||||
|
||||
private static List<FlagInfo> flagList;
|
||||
static {
|
||||
flagList = new ArrayList<FlagInfo>();
|
||||
flagList.add(new FlagInfo("msg", "g", FlagValueType.STRING, "msg", "g"));
|
||||
flagList.add(new FlagInfo("msg", "f", FlagValueType.STRING, "msg", "f"));
|
||||
flagList.add(new FlagInfo("denyspawn", "*", FlagValueType.STRING, "creaturespawn", "*"));
|
||||
flagList.add(new FlagInfo("heal", "delay", FlagValueType.INT, "heal", "delay"));
|
||||
flagList.add(new FlagInfo("heal", "amount", FlagValueType.INT, "heal", "amount"));
|
||||
flagList.add(new FlagInfo("passthrough", null, FlagValueType.STATE, "states", "passthrough"));
|
||||
flagList.add(new FlagInfo("build", null, FlagValueType.STATE, "states", "build"));
|
||||
flagList.add(new FlagInfo("pvp", null, FlagValueType.STATE, "states", "pvp"));
|
||||
flagList.add(new FlagInfo("mobdamage", null, FlagValueType.STATE, "states", "mobdamage"));
|
||||
flagList.add(new FlagInfo("creeper", null, FlagValueType.STATE, "states", "creeper"));
|
||||
flagList.add(new FlagInfo("tnt", null, FlagValueType.STATE, "states", "tnt"));
|
||||
flagList.add(new FlagInfo("lighter", null, FlagValueType.STATE, "states", "lighter"));
|
||||
flagList.add(new FlagInfo("firespread", null, FlagValueType.STATE, "states", "firespread"));
|
||||
flagList.add(new FlagInfo("lavafirespread", null, FlagValueType.STATE, "states", "lavafirespread"));
|
||||
flagList.add(new FlagInfo("chest", null, FlagValueType.STATE, "states", "chest"));
|
||||
flagList.add(new FlagInfo("waterflow", null, FlagValueType.STATE, "states", "waterflow"));
|
||||
flagList.add(new FlagInfo("iconomy", "buyable", FlagValueType.BOOLEAN, "iconomy", "buyable"));
|
||||
flagList.add(new FlagInfo("iconomy", "price", FlagValueType.DOUBLE, "iconomy", "price"));
|
||||
flagList.add(new FlagInfo("spawn", "set", FlagValueType.LOCATION, "spawn", ""));
|
||||
flagList.add(new FlagInfo("spawn", "delete", FlagValueType.LOCATION, "spawn", ""));
|
||||
flagList.add(new FlagInfo("spawn", "allow", FlagValueType.STRING, "spawn", "allow"));
|
||||
flagList.add(new FlagInfo("teleport", "set", FlagValueType.LOCATION, "teleport", ""));
|
||||
flagList.add(new FlagInfo("teleport", "delete", FlagValueType.LOCATION, "teleport", ""));
|
||||
flagList.add(new FlagInfo("teleport", "allow", FlagValueType.STRING, "teleport", "allow"));
|
||||
flagList.add(new FlagInfo("leverandbutton", null, FlagValueType.STATE, "states", "leverandbutton"));
|
||||
}
|
||||
|
||||
public static FlagInfo getFlagInfo(String name, String subName) {
|
||||
|
||||
for (FlagInfo nfo : flagList) {
|
||||
if (name.equals(nfo.name)) {
|
||||
if (subName == null && nfo.subName == null) {
|
||||
return nfo;
|
||||
} else if (nfo.subName != null) {
|
||||
if (nfo.subName.equals("*")) {
|
||||
return nfo;
|
||||
}
|
||||
else if(subName != null && subName.equals(nfo.subName))
|
||||
{
|
||||
return nfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<FlagInfo> getFlagInfoList() {
|
||||
return flagList;
|
||||
}
|
||||
|
||||
public FlagInfo(String name, String subName, FlagValueType type, String flagName, String flagSubName)
|
||||
{
|
||||
this.name = name;
|
||||
this.subName = subName;
|
||||
this.type = type;
|
||||
this.flagName = flagName;
|
||||
this.flagSubName = flagSubName;
|
||||
}
|
||||
|
||||
}
|
@ -21,11 +21,12 @@
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import java.util.Iterator;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.protection.regions.AreaFlags;
|
||||
import com.sk89q.worldguard.protection.regions.AreaFlags.State;
|
||||
import com.sk89q.worldguard.protection.regions.flags.*;
|
||||
import com.sk89q.worldguard.protection.regions.flags.FlagDatabase.FlagType;
|
||||
import com.sk89q.worldguard.protection.regions.flags.RegionFlag;
|
||||
import com.sk89q.worldguard.protection.regions.flags.RegionFlag.State;
|
||||
import java.util.List;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
|
||||
|
||||
/**
|
||||
* Represents a setFlag of regions and their rules as applied to one point.
|
||||
@ -59,30 +60,7 @@ public ApplicableRegionSet(List<ProtectedRegion> applicable, GlobalFlags global
|
||||
* @return
|
||||
*/
|
||||
public boolean canBuild(LocalPlayer player) {
|
||||
|
||||
if (this.applicable.size() < 1) {
|
||||
return global.canBuild;
|
||||
}
|
||||
|
||||
if (affectedRegion == null) {
|
||||
return global.canBuild;
|
||||
}
|
||||
|
||||
String data = getAreaFlag("states", AreaFlags.FLAG_BUILD, true, null, affectedRegion);
|
||||
|
||||
State state;
|
||||
try {
|
||||
state = data != null ? State.valueOf(data) : State.DENY;
|
||||
} catch (Exception e) {
|
||||
state = State.DENY;
|
||||
}
|
||||
|
||||
if (state != State.ALLOW && !affectedRegion.isMember(player)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
return isFlagAllowed(FlagType.BUILD, global.canBuild) || this.isMember(player);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -91,39 +69,180 @@ public boolean canBuild(LocalPlayer player) {
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean allowsFlag(String flag) {
|
||||
boolean def = true;
|
||||
|
||||
if (flag.equals(AreaFlags.FLAG_CHEST_ACCESS)) {
|
||||
def = global.canAccessChests;
|
||||
} else if (flag.equals(AreaFlags.FLAG_PVP)) {
|
||||
def = global.canPvP;
|
||||
} else if (flag.equals(AreaFlags.FLAG_LIGHTER)) {
|
||||
def = global.canLighter;
|
||||
} else if (flag.equals(AreaFlags.FLAG_TNT)) {
|
||||
def = global.canTnt;
|
||||
} else if (flag.equals(AreaFlags.FLAG_CREEPER_EXPLOSION)) {
|
||||
def = global.allowCreeper;
|
||||
} else if (flag.equals(AreaFlags.FLAG_MOB_DAMAGE)) {
|
||||
def = global.allowMobDamage;
|
||||
} else if (flag.equals(AreaFlags.FLAG_WATER_FLOW)) {
|
||||
def = global.allowWaterflow;
|
||||
} else if (flag.equals(AreaFlags.FLAG_LEVER_AND_BUTTON)) {
|
||||
def = global.canLeverandbutton;
|
||||
}
|
||||
|
||||
return isFlagAllowed(flag, def, null);
|
||||
public boolean allowsFlag(FlagType type) {
|
||||
return isFlagAllowed(type, global.getDefaultValue(type));
|
||||
}
|
||||
|
||||
public boolean isFlagAllowed(String flag, boolean def, LocalPlayer player) {
|
||||
public boolean allowsFlag(FlagType type, LocalPlayer player) {
|
||||
return isFlagAllowed(type, global.getDefaultValue(type)) || this.isMember(player);
|
||||
}
|
||||
|
||||
public boolean isFlagAllowed(FlagType type, boolean def) {
|
||||
|
||||
State defState = def ? State.ALLOW : State.DENY;
|
||||
return getStateAreaFlag("states", flag, defState, true, player) == State.ALLOW;
|
||||
return getStateFlag(type, true).getValue(defState) == State.ALLOW;
|
||||
}
|
||||
|
||||
public boolean isFlagAllowed(FlagType type, boolean def, LocalPlayer player) {
|
||||
|
||||
State defState = def ? State.ALLOW : State.DENY;
|
||||
return getStateFlag(type, true).getValue(defState) == State.ALLOW || this.isMember(player);
|
||||
}
|
||||
|
||||
|
||||
private RegionFlag getFlag(FlagType type, Boolean inherit) {
|
||||
|
||||
ProtectedRegion region = affectedRegion;
|
||||
|
||||
if (region == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!inherit) {
|
||||
return region.getFlags().getFlag(type);
|
||||
} else {
|
||||
RegionFlag value;
|
||||
do {
|
||||
value = region.getFlags().getFlag(type);
|
||||
region = region.getParent();
|
||||
|
||||
} while (!value.hasValue() && region != null);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public BooleanRegionFlag getBooleanFlag(FlagType type, boolean inherit) {
|
||||
|
||||
RegionFlag flag = this.getFlag(type, inherit);
|
||||
|
||||
if (flag instanceof BooleanRegionFlag) {
|
||||
return (BooleanRegionFlag) flag;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public StateRegionFlag getStateFlag(FlagType type, boolean inherit) {
|
||||
|
||||
RegionFlag flag = this.getFlag(type, inherit);
|
||||
|
||||
if (flag instanceof StateRegionFlag) {
|
||||
return (StateRegionFlag) flag;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public IntegerRegionFlag getIntegerFlag(FlagType type, boolean inherit) {
|
||||
|
||||
RegionFlag flag = this.getFlag(type, inherit);
|
||||
|
||||
if (flag instanceof IntegerRegionFlag) {
|
||||
return (IntegerRegionFlag) flag;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public DoubleRegionFlag getDoubleFlag(FlagType type, boolean inherit) {
|
||||
|
||||
RegionFlag flag = this.getFlag(type, inherit);
|
||||
|
||||
if (flag instanceof DoubleRegionFlag) {
|
||||
return (DoubleRegionFlag) flag;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public StringRegionFlag getStringFlag(FlagType type, boolean inherit) {
|
||||
|
||||
RegionFlag flag = this.getFlag(type, inherit);
|
||||
|
||||
if (flag instanceof StringRegionFlag) {
|
||||
return (StringRegionFlag) flag;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public RegionGroupRegionFlag getRegionGroupFlag(FlagType type, boolean inherit) {
|
||||
|
||||
RegionFlag flag = this.getFlag(type, inherit);
|
||||
|
||||
if (flag instanceof RegionGroupRegionFlag) {
|
||||
return (RegionGroupRegionFlag) flag;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public LocationRegionFlag getLocationFlag(FlagType type, boolean inherit) {
|
||||
|
||||
RegionFlag flag = this.getFlag(type, inherit);
|
||||
|
||||
if (flag instanceof LocationRegionFlag) {
|
||||
return (LocationRegionFlag) flag;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAnyRegionAffected()
|
||||
{
|
||||
return this.applicable.size() > 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines the region with the hightest priority that is not a parent.
|
||||
*
|
||||
*/
|
||||
private void determineAffectedRegion() {
|
||||
|
||||
affectedRegion = null;
|
||||
Iterator<ProtectedRegion> iter = applicable.iterator();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
ProtectedRegion region = iter.next();
|
||||
|
||||
if (affectedRegion == null || affectedRegion.getPriority() < region.getPriority()) {
|
||||
affectedRegion = region;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean isOwner(LocalPlayer player) {
|
||||
return affectedRegion != null ? affectedRegion.isOwner(player) : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a player is a member of the region or any of its parents.
|
||||
*
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean isMember(LocalPlayer player) {
|
||||
return affectedRegion != null ? affectedRegion.isMember(player) : false;
|
||||
}
|
||||
|
||||
public String getAffectedRegionId() {
|
||||
return affectedRegion != null ? affectedRegion.getId() : "";
|
||||
}
|
||||
|
||||
public int getAffectedRegionPriority() {
|
||||
return affectedRegion != null ? affectedRegion.getPriority() : 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Checks to see if a flag is permitted.
|
||||
*
|
||||
*
|
||||
* @param def default state if there are no regions defined
|
||||
* @param player null to not check owners and members
|
||||
* @return
|
||||
@ -205,216 +324,7 @@ private boolean isFlagAllowed(String flag, boolean def, LocalPlayer player) {
|
||||
|| (player != null && needsClear.size() == 0);
|
||||
}
|
||||
*/
|
||||
/**
|
||||
* Get an area flag
|
||||
*
|
||||
* @param name flag name
|
||||
* @param subname flag subname
|
||||
* @param inherit true to inherit flag values from parents
|
||||
* @param player null to not check owners and members
|
||||
* @return
|
||||
*/
|
||||
public String getAreaFlag(String name, String subname, Boolean inherit, LocalPlayer player) {
|
||||
|
||||
return getAreaFlag(name, subname, inherit, player, getAffectedRegion());
|
||||
}
|
||||
|
||||
private String getAreaFlag(String name, String subname, Boolean inherit, LocalPlayer player, ProtectedRegion affectedRegion) {
|
||||
|
||||
if (affectedRegion == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (player != null && !affectedRegion.isMember(player)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!inherit) {
|
||||
return affectedRegion.getFlags().getFlag(name, subname);
|
||||
} else {
|
||||
String value;
|
||||
do {
|
||||
value = affectedRegion.getFlags().getFlag(name, subname);
|
||||
affectedRegion = affectedRegion.getParent();
|
||||
|
||||
} while (value == null && affectedRegion != null);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the region with the hightest priority.
|
||||
*
|
||||
*/
|
||||
private ProtectedRegion getAffectedRegion() {
|
||||
|
||||
return affectedRegion;
|
||||
}
|
||||
|
||||
|
||||
public boolean isAnyRegionAffected()
|
||||
{
|
||||
return this.applicable.size() > 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines the region with the hightest priority that is not a parent.
|
||||
*
|
||||
*/
|
||||
private void determineAffectedRegion() {
|
||||
|
||||
affectedRegion = null;
|
||||
Iterator<ProtectedRegion> iter = applicable.iterator();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
ProtectedRegion region = iter.next();
|
||||
|
||||
if (affectedRegion == null || affectedRegion.getPriority() < region.getPriority()) {
|
||||
affectedRegion = region;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String getAreaFlag(String name, String subname, String defaultValue, Boolean inherit, LocalPlayer player) {
|
||||
String data = getAreaFlag(name, subname, inherit, player);
|
||||
return data != null ? data : defaultValue;
|
||||
}
|
||||
|
||||
public Boolean getBooleanAreaFlag(String name, String subname, Boolean inherit, LocalPlayer player) {
|
||||
String data = getAreaFlag(name, subname, inherit, player);
|
||||
return data != null ? Boolean.valueOf(data) : null;
|
||||
}
|
||||
|
||||
public Boolean getBooleanAreaFlag(String name, String subname, boolean defaultValue, Boolean inherit, LocalPlayer player) {
|
||||
String data = getAreaFlag(name, subname, inherit, player);
|
||||
return data != null ? Boolean.valueOf(data) : defaultValue;
|
||||
}
|
||||
|
||||
public Integer getIntAreaFlag(String name, String subname, Boolean inherit, LocalPlayer player) {
|
||||
String data = getAreaFlag(name, subname, inherit, player);
|
||||
try {
|
||||
return data != null ? Integer.valueOf(data) : null;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Integer getIntAreaFlag(String name, String subname, int defaultValue, Boolean inherit, LocalPlayer player) {
|
||||
String data = getAreaFlag(name, subname, inherit, player);
|
||||
try {
|
||||
return data != null ? Integer.valueOf(data) : defaultValue;
|
||||
} catch (Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public Float getFloatAreaFlag(String name, String subname, Boolean inherit, LocalPlayer player) {
|
||||
String data = getAreaFlag(name, subname, inherit, player);
|
||||
try {
|
||||
return data != null ? Float.valueOf(data) : null;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Float getFloatAreaFlag(String name, String subname, float defaultValue, Boolean inherit, LocalPlayer player) {
|
||||
String data = getAreaFlag(name, subname, inherit, player);
|
||||
try {
|
||||
return data != null ? Float.valueOf(data) : defaultValue;
|
||||
} catch (Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public Double getDoubleAreaFlag(String name, String subname, Boolean inherit, LocalPlayer player) {
|
||||
String data = getAreaFlag(name, subname, inherit, player);
|
||||
try {
|
||||
return data != null ? Double.valueOf(data) : null;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Double getDoubleAreaFlag(String name, String subname, double defaultValue, Boolean inherit, LocalPlayer player) {
|
||||
String data = getAreaFlag(name, subname, inherit, player);
|
||||
try {
|
||||
return data != null ? Double.valueOf(data) : defaultValue;
|
||||
} catch (Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public State getStateAreaFlag(String name, String subname, Boolean inherit, LocalPlayer player) {
|
||||
String data = getAreaFlag(name, subname, inherit, player);
|
||||
|
||||
try {
|
||||
return data != null ? State.valueOf(data) : null;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public State getStateAreaFlag(String name, String subname, State defaultValue, Boolean inherit, LocalPlayer player) {
|
||||
String data = getAreaFlag(name, subname, inherit, player);
|
||||
|
||||
try {
|
||||
return data != null ? State.valueOf(data) : defaultValue;
|
||||
} catch (Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public Location getLocationAreaFlag(String name, Server server, Boolean inherit, LocalPlayer player) {
|
||||
|
||||
ProtectedRegion childRegion = getAffectedRegion();
|
||||
if (childRegion == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (player != null && !childRegion.isMember(player)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!inherit) {
|
||||
return childRegion.getFlags().getLocationFlag(server, name);
|
||||
} else {
|
||||
Location value;
|
||||
do {
|
||||
value = childRegion.getFlags().getLocationFlag(server, name);
|
||||
childRegion = childRegion.getParent();
|
||||
|
||||
} while (value == null && childRegion != null);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean isOwner(LocalPlayer player) {
|
||||
return affectedRegion != null ? affectedRegion.isOwner(player) : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a player is a member of the region or any of its parents.
|
||||
*
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean isMember(LocalPlayer player) {
|
||||
return affectedRegion != null ? affectedRegion.isMember(player) : false;
|
||||
}
|
||||
|
||||
public String getAffectedRegionId() {
|
||||
return affectedRegion != null ? affectedRegion.getId() : "";
|
||||
}
|
||||
|
||||
public int getAffectedRegionPriority() {
|
||||
return affectedRegion != null ? affectedRegion.getPriority() : 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clear a region's parents for isFlagAllowed().
|
||||
|
@ -19,6 +19,8 @@
|
||||
|
||||
package com.sk89q.worldguard.protection;
|
||||
|
||||
import com.sk89q.worldguard.protection.regions.flags.FlagDatabase.FlagType;
|
||||
|
||||
/**
|
||||
* Used for default flags.
|
||||
*
|
||||
@ -34,4 +36,32 @@ public class GlobalFlags {
|
||||
public boolean allowCreeper = true;
|
||||
public boolean allowMobDamage = true;
|
||||
public boolean allowWaterflow = true;
|
||||
|
||||
|
||||
public boolean getDefaultValue(FlagType type)
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case BUILD:
|
||||
return this.canBuild;
|
||||
case CHEST_ACCESS:
|
||||
return this.canAccessChests;
|
||||
case PVP:
|
||||
return this.canPvP;
|
||||
case LIGHTER:
|
||||
return this.canLighter;
|
||||
case TNT:
|
||||
return this.canTnt;
|
||||
case LEVER_AND_BUTTON:
|
||||
return this.canLeverandbutton;
|
||||
case CREEPER_EXPLOSION:
|
||||
return this.allowCreeper;
|
||||
case MOB_DAMAGE:
|
||||
return this.allowMobDamage;
|
||||
case WATER_FLOW:
|
||||
return this.allowWaterflow;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,8 +19,8 @@
|
||||
|
||||
package com.sk89q.worldguard.protection;
|
||||
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import com.sk89q.worldguard.bukkit.BukkitPlayer;
|
||||
|
||||
import com.sk89q.worldguard.protection.regions.flags.FlagDatabase.FlagType;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
|
||||
import java.util.HashMap;
|
||||
@ -78,11 +78,11 @@ public void run() {
|
||||
RegionManager mgr = wg.getGlobalRegionManager().getRegionManager(player.getWorld().getName());
|
||||
ApplicableRegionSet regions = mgr.getApplicableRegions(toVector(player.getLocation()));
|
||||
|
||||
int healDelay = regions.getIntAreaFlag("heal", "delay", -1, true, null);
|
||||
int healDelay = regions.getIntegerFlag(FlagType.HEAL_DELAY, true).getValue(-1);
|
||||
|
||||
if (healDelay > 0) {
|
||||
healDelay *= 1000;
|
||||
int healAmount = regions.getIntAreaFlag("heal", "amount", 1, true, null);
|
||||
int healAmount = regions.getIntegerFlag(FlagType.HEAL_AMOUNT, true).getValue(1);
|
||||
if (now - nfo.lastHealTick > healDelay) {
|
||||
player.setHealth(player.getHealth() + healAmount);
|
||||
} else {
|
||||
@ -99,8 +99,8 @@ public void run() {
|
||||
|
||||
|
||||
if (nfo.lastRegion == null || !newRegionName.equals(nfo.lastRegion)) {
|
||||
String newGreetMsg = regions.getAreaFlag("msg", "g", null, true, null);
|
||||
String farewellMsg = regions.getAreaFlag("msg", "f", null, true, null);
|
||||
String newGreetMsg = regions.getStringFlag(FlagType.GREET_MESSAGE, true).getValue();
|
||||
String farewellMsg = regions.getStringFlag(FlagType.FAREWELL_MESSAGE, true).getValue();
|
||||
|
||||
if (nfo.lastFarewellMsg != null) {
|
||||
player.sendMessage(nfo.lastFarewellMsg);
|
||||
|
@ -33,8 +33,6 @@
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldguard.domains.DefaultDomain;
|
||||
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;
|
||||
@ -100,9 +98,7 @@ public void save() throws IOException {
|
||||
cuboid.getParent() != null ? cuboid.getParent().getId() : "",
|
||||
writeDomains(cuboid.getOwners()),
|
||||
writeDomains(cuboid.getMembers()),
|
||||
writeFlags(cuboid.getFlags()),
|
||||
cuboid.getFlags().getFlag("msg", "g") != null ? cuboid.getFlags().getFlag("msg", "g") : "",
|
||||
cuboid.getFlags().getFlag("msg", "l") != null ? cuboid.getFlags().getFlag("msg", "l") : "",
|
||||
//writeFlags(cuboid.getFlags()),
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
@ -163,9 +159,8 @@ public void load() throws IOException {
|
||||
|
||||
ProtectedRegion region = new ProtectedCuboidRegion(id, min, max);
|
||||
region.setPriority(priority);
|
||||
region.setFlags(parseFlags(flagsData));
|
||||
//region.setFlags(parseFlags(flagsData));
|
||||
region.setOwners(this.parseDomains(ownersData));
|
||||
region.getFlags().setFlag("msg", "g", enterMessage);
|
||||
regions.put(id, region);
|
||||
} else if (type.equalsIgnoreCase("cuboid.2")) {
|
||||
Vector pt1 = new Vector(
|
||||
@ -190,11 +185,9 @@ public void load() throws IOException {
|
||||
|
||||
ProtectedRegion region = new ProtectedCuboidRegion(id, min, max);
|
||||
region.setPriority(priority);
|
||||
region.setFlags(parseFlags(flagsData));
|
||||
//region.setFlags(parseFlags(flagsData));
|
||||
region.setOwners(this.parseDomains(ownersData));
|
||||
region.setMembers(this.parseDomains(membersData));
|
||||
region.getFlags().setFlag("msg", "g", enterMessage);
|
||||
region.getFlags().setFlag("msg", "l", leaveMessage);
|
||||
regions.put(id, region);
|
||||
|
||||
// Link children to parents later
|
||||
@ -296,6 +289,7 @@ private DefaultDomain parseDomains(String data) {
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
/*
|
||||
private AreaFlags parseFlags(String data) {
|
||||
if (data == null) {
|
||||
return new AreaFlags();
|
||||
@ -328,7 +322,8 @@ private AreaFlags parseFlags(String data) {
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* Used to write the list of domains.
|
||||
*
|
||||
@ -358,6 +353,7 @@ private String writeDomains(DefaultDomain domain) {
|
||||
* @param flag
|
||||
* @return
|
||||
*/
|
||||
/*
|
||||
private String writeFlag(State state, String flag) {
|
||||
if (state == State.ALLOW) {
|
||||
return "+" + flag;
|
||||
@ -367,7 +363,8 @@ private String writeFlag(State state, String flag) {
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns a null if a string is null or empty.
|
||||
*
|
||||
@ -390,6 +387,7 @@ private String nullEmptyString(String str) {
|
||||
* @param flags
|
||||
* @return
|
||||
*/
|
||||
/*
|
||||
private String writeFlags(AreaFlags flags) {
|
||||
StringBuilder str = new StringBuilder();
|
||||
for (Map.Entry<String, State> entry : flags.entrySet()) {
|
||||
@ -397,7 +395,7 @@ private String writeFlags(AreaFlags flags) {
|
||||
}
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
*/
|
||||
/**
|
||||
* Get a list of protected regions.
|
||||
*
|
||||
|
@ -20,7 +20,6 @@
|
||||
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;
|
||||
@ -97,10 +96,7 @@ else if(region.getMembers() == null)
|
||||
{
|
||||
region.setMembers(new DefaultDomain());
|
||||
}
|
||||
else if(region.getFlags() == null)
|
||||
{
|
||||
region.setFlags(new AreaFlags());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,358 +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.regions;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
|
||||
/**
|
||||
* Holds the flags for a region.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class AreaFlags {
|
||||
|
||||
public enum State {
|
||||
|
||||
NONE,
|
||||
ALLOW,
|
||||
DENY,
|
||||
};
|
||||
|
||||
public static final String FLAG_PASSTHROUGH = "passthrough";
|
||||
public static final String FLAG_BUILD = "build";
|
||||
public static final String FLAG_PVP = "pvp";
|
||||
public static final String FLAG_MOB_DAMAGE = "mobdamage";
|
||||
public static final String FLAG_CREEPER_EXPLOSION = "creeper";
|
||||
public static final String FLAG_TNT = "tnt";
|
||||
public static final String FLAG_LIGHTER = "llighter";
|
||||
public static final String FLAG_FIRE_SPREAD = "firespread";
|
||||
public static final String FLAG_LAVA_FIRE = "lavafirespread";
|
||||
public static final String FLAG_CHEST_ACCESS = "chest";
|
||||
public static final String FLAG_WATER_FLOW = "waterflow";
|
||||
public static final String FLAG_LEVER_AND_BUTTON = "leverandbutton";
|
||||
|
||||
|
||||
/**
|
||||
* 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 if (flag.equals(FLAG_WATER_FLOW)) {
|
||||
return "water flow";
|
||||
} 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 if (name.equalsIgnoreCase("waterflow")) {
|
||||
return FLAG_WATER_FLOW;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}*/
|
||||
|
||||
private Map<String, Map<String, String>> flags = new HashMap<String, Map<String, String>>();
|
||||
|
||||
public Map<String, String> getFlagData(String name) {
|
||||
Map<String, String> ret = flags.get(name);
|
||||
if (ret == null) {
|
||||
ret = new HashMap<String, String>();
|
||||
flags.put(name, ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Set<Map.Entry<String, State>> entrySet() {
|
||||
|
||||
Map<String, State> ret = new HashMap<String, State>();
|
||||
|
||||
for (Map.Entry<String, String> entry : getFlagData("states").entrySet()) {
|
||||
ret.put(entry.getKey(), State.valueOf(entry.getValue()));
|
||||
}
|
||||
|
||||
return ret.entrySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the State value of a state flag
|
||||
*
|
||||
* @param name
|
||||
* @param subname
|
||||
* @return State
|
||||
*/
|
||||
public State getStateFlag(String name, String subname) {
|
||||
String value = getFlagData(name).get(subname);
|
||||
if (value == null) {
|
||||
return State.NONE;
|
||||
}
|
||||
State state = State.NONE;
|
||||
try {
|
||||
state = State.valueOf(value);
|
||||
if (state == null) {
|
||||
return State.NONE;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return State.NONE;
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the State value of a state flag
|
||||
*
|
||||
* @param flag
|
||||
* @return State
|
||||
*/
|
||||
public State getStateFlag(String flag) {
|
||||
return getStateFlag("states", flag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the State value of a state flag
|
||||
*
|
||||
* @param flag
|
||||
* @param state
|
||||
*/
|
||||
public void setFlag(String name, String subname, State state) {
|
||||
if (state == State.NONE) {
|
||||
getFlagData(name).remove(subname);
|
||||
} else {
|
||||
getFlagData(name).put(subname, state.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the State value of a state flag
|
||||
*
|
||||
* @param flag
|
||||
* @param state
|
||||
*/
|
||||
public void setFlag(String flag, State state) {
|
||||
setFlag("states", flag, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof AreaFlags)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AreaFlags other = (AreaFlags) obj;
|
||||
return other.flags.equals(this.flags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 3;
|
||||
hash = 97 * hash + (this.flags != null ? this.flags.hashCode() : 0);
|
||||
return hash;
|
||||
}
|
||||
|
||||
public void setFlag(String name, String subname, String value) {
|
||||
if(subname == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (value == null) {
|
||||
getFlagData(name).remove(subname);
|
||||
} else {
|
||||
getFlagData(name).put(subname, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void setFlag(String name, String subname, Boolean value) {
|
||||
setFlag(name, subname, value.toString());
|
||||
}
|
||||
|
||||
public void setFlag(String name, String subname, Integer value) {
|
||||
setFlag(name, subname, value.toString());
|
||||
}
|
||||
|
||||
public void setFlag(String name, String subname, Float value) {
|
||||
setFlag(name, subname, value.toString());
|
||||
}
|
||||
|
||||
public void setFlag(String name, String subname, Double value) {
|
||||
setFlag(name, subname, value.toString());
|
||||
}
|
||||
|
||||
public String getFlag(String name, String subname) {
|
||||
return getFlagData(name).get(subname);
|
||||
}
|
||||
|
||||
public String getFlag(String name, String subname, String defaultValue) {
|
||||
String data = getFlagData(name).get(subname);
|
||||
return data != null ? data : defaultValue;
|
||||
}
|
||||
|
||||
public Boolean getBooleanFlag(String name, String subname) {
|
||||
String data = getFlagData(name).get(subname);
|
||||
return data != null ? Boolean.valueOf(data) : null;
|
||||
}
|
||||
|
||||
public Boolean getBooleanFlag(String name, String subname, boolean defaultValue) {
|
||||
String data = getFlagData(name).get(subname);
|
||||
return data != null ? Boolean.valueOf(data) : defaultValue;
|
||||
}
|
||||
|
||||
public Integer getIntFlag(String name, String subname) {
|
||||
String data = getFlagData(name).get(subname);
|
||||
try {
|
||||
return data != null ? Integer.valueOf(data) : null;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Integer getIntFlag(String name, String subname, int defaultValue) {
|
||||
String data = getFlagData(name).get(subname);
|
||||
try {
|
||||
return data != null ? Integer.valueOf(data) : defaultValue;
|
||||
} catch (Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public Float getFloatFlag(String name, String subname) {
|
||||
String data = getFlagData(name).get(subname);
|
||||
try {
|
||||
return data != null ? Float.valueOf(data) : null;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Float getFloatFlag(String name, String subname, float defaultValue) {
|
||||
String data = getFlagData(name).get(subname);
|
||||
try {
|
||||
return data != null ? Float.valueOf(data) : defaultValue;
|
||||
} catch (Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public Double getDoubleFlag(String name, String subname) {
|
||||
String data = getFlagData(name).get(subname);
|
||||
try {
|
||||
return data != null ? Double.valueOf(data) : null;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Double getDoubleFlag(String name, String subname, double defaultValue) {
|
||||
String data = getFlagData(name).get(subname);
|
||||
try {
|
||||
return data != null ? Double.valueOf(data) : defaultValue;
|
||||
} catch (Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public Location getLocationFlag(Server server, String name) {
|
||||
try {
|
||||
Double x = Double.valueOf(getFlagData(name).get("x"));
|
||||
Double y = Double.valueOf(getFlagData(name).get("y"));
|
||||
Double z = Double.valueOf(getFlagData(name).get("z"));
|
||||
Float yaw = Float.valueOf(getFlagData(name).get("yaw"));
|
||||
Float pitch = Float.valueOf(getFlagData(name).get("pitch"));
|
||||
String worldName = getFlagData(name).get("world");
|
||||
|
||||
Location l = new Location(server.getWorld(worldName), x, y, z, yaw, pitch);
|
||||
return l;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setLocationFlag(String name, Location l) {
|
||||
if (l != null) {
|
||||
getFlagData(name).put("x", new Double(l.getX()).toString());
|
||||
getFlagData(name).put("y", new Double(l.getY()).toString());
|
||||
getFlagData(name).put("z", new Double(l.getZ()).toString());
|
||||
getFlagData(name).put("yaw", new Float(l.getYaw()).toString());
|
||||
getFlagData(name).put("pitch", new Float(l.getPitch()).toString());
|
||||
getFlagData(name).put("world", l.getWorld().getName());
|
||||
} else {
|
||||
getFlagData(name).put("x", null);
|
||||
getFlagData(name).put("y", null);
|
||||
getFlagData(name).put("z", null);
|
||||
getFlagData(name).put("yaw", null);
|
||||
getFlagData(name).put("pitch", null);
|
||||
getFlagData(name).put("world", null);
|
||||
}
|
||||
}
|
||||
}
|
@ -24,6 +24,7 @@
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.domains.DefaultDomain;
|
||||
import com.sk89q.worldguard.protection.UnsupportedIntersectionException;
|
||||
import com.sk89q.worldguard.protection.regions.flags.RegionFlagContainer;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -41,11 +42,11 @@ public abstract class ProtectedRegion implements Comparable<ProtectedRegion> {
|
||||
*/
|
||||
private int priority = 0;
|
||||
/**
|
||||
* Holds the parent.
|
||||
* Holds the curParent.
|
||||
*/
|
||||
private transient ProtectedRegion parent;
|
||||
/**
|
||||
* Holds the parent's Id. Used for serialization, don't touch it.
|
||||
* Holds the curParent's Id. Used for serialization, don't touch it.
|
||||
*/
|
||||
private String parentId;
|
||||
/**
|
||||
@ -59,7 +60,7 @@ public abstract class ProtectedRegion implements Comparable<ProtectedRegion> {
|
||||
/**
|
||||
* Area flags.
|
||||
*/
|
||||
private AreaFlags flags = new AreaFlags();
|
||||
private RegionFlagContainer flags = new RegionFlagContainer();
|
||||
|
||||
|
||||
/**
|
||||
@ -132,17 +133,17 @@ public void setPriority(int priority) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the parent
|
||||
* @return the curParent
|
||||
*/
|
||||
public ProtectedRegion getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the parent. This checks to make sure that it will not result
|
||||
* Set the curParent. This checks to make sure that it will not result
|
||||
* in circular inheritance.
|
||||
*
|
||||
* @param parent the parent to setFlag
|
||||
* @param curParent the curParent to setFlag
|
||||
* @throws CircularInheritanceException
|
||||
*/
|
||||
public void setParent(ProtectedRegion parent) throws CircularInheritanceException {
|
||||
@ -166,14 +167,7 @@ public void setParent(ProtectedRegion parent) throws CircularInheritanceExceptio
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Se flags.
|
||||
* @param flags
|
||||
*/
|
||||
public void setFlags(AreaFlags flags) {
|
||||
this.flags = flags;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the owners
|
||||
*/
|
||||
@ -215,13 +209,13 @@ public boolean isOwner(LocalPlayer player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
ProtectedRegion parent = getParent();
|
||||
while (parent != null) {
|
||||
if (parent.getOwners().contains(player)) {
|
||||
ProtectedRegion curParent = getParent();
|
||||
while (curParent != null) {
|
||||
if (curParent.getOwners().contains(player)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
parent = parent.getParent();
|
||||
curParent = curParent.getParent();
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -239,14 +233,14 @@ public boolean isMember(LocalPlayer player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
ProtectedRegion parent = getParent();
|
||||
while (parent != null) {
|
||||
if (parent.getOwners().contains(player)
|
||||
|| parent.getMembers().contains(player)) {
|
||||
ProtectedRegion curParent = getParent();
|
||||
while (curParent != null) {
|
||||
if (curParent.getOwners().contains(player)
|
||||
|| curParent.getMembers().contains(player)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
parent = parent.getParent();
|
||||
curParent = curParent.getParent();
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -257,7 +251,11 @@ public boolean isMember(LocalPlayer player) {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public AreaFlags getFlags() {
|
||||
public RegionFlagContainer getFlags() {
|
||||
if(this.flags == null)
|
||||
{
|
||||
this.flags = new RegionFlagContainer();
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
||||
@ -304,7 +302,7 @@ public int compareTo(ProtectedRegion other) {
|
||||
|
||||
|
||||
/**
|
||||
* Thrown when setting a parent would create a circular inheritance
|
||||
* Thrown when setting a curParent would create a circular inheritance
|
||||
* situation.
|
||||
*
|
||||
*/
|
||||
|
@ -0,0 +1,79 @@
|
||||
// $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.flags;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Michael
|
||||
*/
|
||||
public final class BooleanRegionFlag extends RegionFlag {
|
||||
|
||||
private Boolean value;
|
||||
|
||||
public BooleanRegionFlag(RegionFlagContainer container, RegionFlagInfo info, String value) {
|
||||
super(container, info);
|
||||
|
||||
this.setValue(value);
|
||||
}
|
||||
|
||||
public void setValue(Boolean newValue) {
|
||||
this.value = newValue;
|
||||
this.container.internalSetValue(info.name, newValue != null ? newValue.toString() : null);
|
||||
}
|
||||
|
||||
public Boolean getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public Boolean getValue(Boolean def) {
|
||||
return this.value != null ? this.value : def;
|
||||
}
|
||||
|
||||
public boolean setValue(String newValue) {
|
||||
if (newValue == null) {
|
||||
this.value = null;
|
||||
} else {
|
||||
newValue = newValue.toLowerCase();
|
||||
if(newValue.equals("on") || newValue.equals("allow") || newValue.equals("1"))
|
||||
{
|
||||
newValue = "true";
|
||||
}
|
||||
this.value = Boolean.valueOf(newValue);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasValue() {
|
||||
return this.value != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if(this.value != null)
|
||||
{
|
||||
return this.value.toString();
|
||||
}
|
||||
else
|
||||
{
|
||||
return "-";
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.sk89q.worldguard.protection.regions.flags;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Michael
|
||||
*/
|
||||
public final class DoubleRegionFlag extends RegionFlag {
|
||||
|
||||
private Double value;
|
||||
|
||||
public DoubleRegionFlag(RegionFlagContainer container, RegionFlagInfo info, String value) {
|
||||
super(container, info);
|
||||
this.setValue(value);
|
||||
}
|
||||
|
||||
public void setValue(Double newValue) {
|
||||
this.value = newValue;
|
||||
this.container.internalSetValue(info.name, newValue != null ? newValue.toString() : null);
|
||||
}
|
||||
|
||||
public Double getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public Double getValue(Double def) {
|
||||
return this.value != null ? this.value : def;
|
||||
}
|
||||
|
||||
public boolean setValue(String newValue) {
|
||||
if (newValue == null) {
|
||||
this.value = null;
|
||||
} else {
|
||||
try {
|
||||
this.value = Double.valueOf(newValue);
|
||||
} catch (Exception e) {
|
||||
this.value = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasValue() {
|
||||
return this.value != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if(this.value != null)
|
||||
{
|
||||
return this.value.toString();
|
||||
}
|
||||
else
|
||||
{
|
||||
return "-";
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,157 @@
|
||||
// $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.flags;
|
||||
|
||||
import com.sk89q.worldguard.protection.regions.flags.RegionFlag.FlagDataType;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Michael
|
||||
*/
|
||||
public class FlagDatabase {
|
||||
|
||||
public enum FlagType {
|
||||
|
||||
PASSTHROUGH, BUILD, PVP, MOB_DAMAGE, CREEPER_EXPLOSION,
|
||||
TNT, LIGHTER, FIRE_SPREAD, LAVA_FIRE, CHEST_ACCESS, WATER_FLOW,
|
||||
LEVER_AND_BUTTON, GREET_MESSAGE, FAREWELL_MESSAGE, DENY_SPAWN,
|
||||
HEAL_DELAY, HEAL_AMOUNT, TELE_LOC, TELE_PERM, SPAWN_LOC, SPAWN_PERM,
|
||||
BUYABLE, PRICE
|
||||
|
||||
};
|
||||
|
||||
static {
|
||||
registerFlag("passthrough", FlagType.PASSTHROUGH, FlagDataType.STATE);
|
||||
registerFlag("build", FlagType.BUILD, FlagDataType.STATE);
|
||||
registerFlag("pvp", FlagType.PVP, FlagDataType.STATE);
|
||||
registerFlag("mobdamage", FlagType.MOB_DAMAGE, FlagDataType.STATE);
|
||||
registerFlag("creeperexp", FlagType.CREEPER_EXPLOSION, FlagDataType.STATE);
|
||||
registerFlag("tnt", FlagType.TNT, FlagDataType.STATE);
|
||||
registerFlag("lighter", FlagType.LIGHTER, FlagDataType.STATE);
|
||||
registerFlag("firespread", FlagType.FIRE_SPREAD, FlagDataType.STATE);
|
||||
registerFlag("lavafire", FlagType.LAVA_FIRE, FlagDataType.STATE);
|
||||
registerFlag("chest", FlagType.CHEST_ACCESS, FlagDataType.STATE);
|
||||
registerFlag("waterflow", FlagType.WATER_FLOW, FlagDataType.STATE);
|
||||
registerFlag("leverandbutton", FlagType.LEVER_AND_BUTTON, FlagDataType.STATE);
|
||||
|
||||
registerFlag("buyable", FlagType.BUYABLE, FlagDataType.BOOLEAN);
|
||||
|
||||
registerFlag("healdelay", FlagType.HEAL_DELAY, FlagDataType.INTEGER);
|
||||
registerFlag("healamount", FlagType.HEAL_AMOUNT, FlagDataType.INTEGER);
|
||||
|
||||
registerFlag("price", FlagType.PRICE, FlagDataType.DOUBLE);
|
||||
|
||||
registerFlag("gmsg", FlagType.GREET_MESSAGE, FlagDataType.STRING);
|
||||
registerFlag("fmsg", FlagType.FAREWELL_MESSAGE, FlagDataType.STRING);
|
||||
registerFlag("denyspawn", FlagType.DENY_SPAWN, FlagDataType.STRING);
|
||||
|
||||
registerFlag("teleloc", FlagType.TELE_LOC, FlagDataType.LOCATION);
|
||||
registerFlag("spawnloc", FlagType.SPAWN_LOC, FlagDataType.LOCATION);
|
||||
|
||||
registerFlag("teleperm", FlagType.TELE_PERM, FlagDataType.REGIONGROUP);
|
||||
registerFlag("spawnperm", FlagType.SPAWN_PERM, FlagDataType.REGIONGROUP);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static void registerFlag(String name, FlagType type, FlagDataType dataType) {
|
||||
|
||||
RegionFlagInfo info = new RegionFlagInfo(name, type, dataType);
|
||||
flagByFlagType.put(info.type, info);
|
||||
flagByName.put(info.name, info);
|
||||
}
|
||||
|
||||
|
||||
public static RegionFlagInfo getFlagInfoFromName(String name)
|
||||
{
|
||||
return flagByName.get(name);
|
||||
}
|
||||
|
||||
public static List<RegionFlagInfo> getFlagInfoList()
|
||||
{
|
||||
List<RegionFlagInfo> list = new ArrayList<RegionFlagInfo>();
|
||||
list.addAll(flagByFlagType.values());
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
public static RegionFlag getNewInstanceOf(FlagType type, String value, RegionFlagContainer container) {
|
||||
RegionFlagInfo info = flagByFlagType.get(type);
|
||||
|
||||
if (info == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
switch (info.dataType) {
|
||||
case BOOLEAN:
|
||||
return new BooleanRegionFlag(container, info, value);
|
||||
case STATE:
|
||||
return new StateRegionFlag(container, info, value);
|
||||
case INTEGER:
|
||||
return new IntegerRegionFlag(container, info, value);
|
||||
case DOUBLE:
|
||||
return new DoubleRegionFlag(container, info, value);
|
||||
case STRING:
|
||||
return new StringRegionFlag(container, info, value);
|
||||
case LOCATION:
|
||||
return new LocationRegionFlag(container, info, value);
|
||||
case REGIONGROUP:
|
||||
return new RegionGroupRegionFlag(container, info, value);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static RegionFlag getNewInstanceOf(String name, String value, RegionFlagContainer container) {
|
||||
RegionFlagInfo info = flagByName.get(name);
|
||||
|
||||
if (info == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
switch (info.dataType) {
|
||||
case BOOLEAN:
|
||||
return new BooleanRegionFlag(container, info, value);
|
||||
case STATE:
|
||||
return new StateRegionFlag(container, info, value);
|
||||
case INTEGER:
|
||||
return new IntegerRegionFlag(container, info, value);
|
||||
case DOUBLE:
|
||||
return new DoubleRegionFlag(container, info, value);
|
||||
case STRING:
|
||||
return new StringRegionFlag(container, info, value);
|
||||
case LOCATION:
|
||||
return new LocationRegionFlag(container, info, value);
|
||||
case REGIONGROUP:
|
||||
return new RegionGroupRegionFlag(container, info, value);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static Map<FlagType, RegionFlagInfo> flagByFlagType = new EnumMap<FlagType, RegionFlagInfo>(FlagType.class);
|
||||
private static Map<String, RegionFlagInfo> flagByName = new HashMap<String, RegionFlagInfo>();
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.sk89q.worldguard.protection.regions.flags;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Michael
|
||||
*/
|
||||
public final class IntegerRegionFlag extends RegionFlag {
|
||||
|
||||
private Integer value;
|
||||
|
||||
public IntegerRegionFlag(RegionFlagContainer container, RegionFlagInfo info, String value) {
|
||||
super(container, info);
|
||||
this.setValue(value);
|
||||
}
|
||||
|
||||
public void setValue(Integer newValue) {
|
||||
this.value = newValue;
|
||||
this.container.internalSetValue(info.name, newValue != null ? newValue.toString() : null);
|
||||
}
|
||||
|
||||
public Integer getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public Integer getValue(Integer def) {
|
||||
return this.value != null ? this.value : def;
|
||||
}
|
||||
|
||||
public boolean setValue(String newValue) {
|
||||
if (newValue == null) {
|
||||
this.value = null;
|
||||
} else {
|
||||
try {
|
||||
this.value = Integer.valueOf(newValue);
|
||||
} catch (Exception e) {
|
||||
this.value = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasValue() {
|
||||
return this.value != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if(this.value != null)
|
||||
{
|
||||
return this.value.toString();
|
||||
}
|
||||
else
|
||||
{
|
||||
return "-";
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,122 @@
|
||||
// $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.flags;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Michael
|
||||
*/
|
||||
public final class LocationRegionFlag extends RegionFlag {
|
||||
|
||||
private String worldName;
|
||||
private double x, y, z;
|
||||
private float yaw, pitch;
|
||||
|
||||
public LocationRegionFlag(RegionFlagContainer container, RegionFlagInfo info, String value) {
|
||||
super(container, info);
|
||||
this.setValue(value);
|
||||
}
|
||||
|
||||
public void setValue(Location newValue) {
|
||||
if (newValue == null) {
|
||||
this.worldName = null;
|
||||
} else {
|
||||
this.worldName = newValue.getWorld().getName();
|
||||
this.x = newValue.getBlockX();
|
||||
this.y = newValue.getBlockY();
|
||||
this.z = newValue.getBlockZ();
|
||||
this.yaw = newValue.getYaw();
|
||||
this.pitch = newValue.getPitch();
|
||||
}
|
||||
|
||||
String stringVal;
|
||||
if (newValue == null) {
|
||||
stringVal = null;
|
||||
} else {
|
||||
stringVal = newValue.getWorld().getName() + ";" + newValue.getBlockX() + ";"
|
||||
+ newValue.getBlockY() + ";" + newValue.getBlockZ() + ";" + newValue.getYaw()
|
||||
+ ";" + newValue.getPitch();
|
||||
}
|
||||
this.container.internalSetValue(info.name, stringVal);
|
||||
}
|
||||
|
||||
public Location getValue(Server server) {
|
||||
|
||||
if (this.worldName == null) {
|
||||
return null;
|
||||
} else {
|
||||
try {
|
||||
Location ret = new Location(server.getWorld(this.worldName), this.x, this.y, this.z, this.yaw, this.pitch);
|
||||
return ret;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Location getValue(Server server, Location def) {
|
||||
Location ret = getValue(server);
|
||||
return ret != null ? ret : def;
|
||||
}
|
||||
|
||||
public boolean setValue(String newValue) {
|
||||
if (newValue == null) {
|
||||
this.worldName = null;
|
||||
} else {
|
||||
try {
|
||||
this.worldName = null;
|
||||
String[] data = newValue.split(";");
|
||||
if (data.length == 6) {
|
||||
this.worldName = data[0];
|
||||
this.x = Double.valueOf(data[1]);
|
||||
this.y = Double.valueOf(data[2]);
|
||||
this.z = Double.valueOf(data[3]);
|
||||
this.yaw = Float.valueOf(data[4]);
|
||||
this.pitch = Float.valueOf(data[5]);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
this.worldName = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasValue() {
|
||||
return this.worldName != null;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
if(this.worldName != null)
|
||||
{
|
||||
return this.worldName + "(" + Math.round(this.x) + "," + Math.round(this.y) + "," + Math.round(this.z) + ")";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "-";
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.sk89q.worldguard.protection.regions.flags;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Michael
|
||||
*/
|
||||
public abstract class RegionFlag {
|
||||
|
||||
public enum RegionGroup {
|
||||
|
||||
ALL, MEMBER, OWNER
|
||||
};
|
||||
|
||||
public enum State {
|
||||
|
||||
NONE, ALLOW, DENY
|
||||
};
|
||||
|
||||
public enum FlagDataType {
|
||||
|
||||
BOOLEAN, STATE, INTEGER, DOUBLE, STRING, LOCATION, REGIONGROUP
|
||||
};
|
||||
|
||||
|
||||
protected RegionFlagContainer container;
|
||||
protected RegionFlagInfo info;
|
||||
|
||||
public RegionFlag(RegionFlagContainer container, RegionFlagInfo info) {
|
||||
this.container = container;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public RegionFlagInfo getInfo() {
|
||||
return this.info;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.info.name;
|
||||
}
|
||||
|
||||
public abstract boolean hasValue();
|
||||
|
||||
@Override
|
||||
public abstract String toString();
|
||||
}
|
@ -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.regions.flags;
|
||||
|
||||
import com.sk89q.worldguard.protection.regions.flags.FlagDatabase.FlagType;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
|
||||
/**
|
||||
* Holds the flags for a region.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class RegionFlagContainer {
|
||||
|
||||
private Map<String, String> flags = new HashMap<String, String>();
|
||||
private transient Map<FlagType, RegionFlag> flagData = new EnumMap<FlagType, RegionFlag>(FlagType.class);
|
||||
|
||||
public RegionFlag getFlag(FlagType type) {
|
||||
|
||||
if (this.flagData == null) {
|
||||
this.initFlagData();
|
||||
}
|
||||
|
||||
RegionFlag ret = this.flagData.get(type);
|
||||
|
||||
if (ret == null) {
|
||||
ret = FlagDatabase.getNewInstanceOf(type, null, this);
|
||||
|
||||
if (ret != null) {
|
||||
this.flagData.put(type, ret);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
private void initFlagData() {
|
||||
|
||||
Iterator<Entry<String, String>> iter = this.flags.entrySet().iterator();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
Entry<String, String> entry = iter.next();
|
||||
|
||||
RegionFlag rflag = FlagDatabase.getNewInstanceOf(entry.getKey(), entry.getValue(), this);
|
||||
if (rflag == null) {
|
||||
iter.remove();
|
||||
} else {
|
||||
this.flagData.put(rflag.info.type, rflag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void internalSetValue(String name, String value) {
|
||||
if (name == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (value == null) {
|
||||
this.flags.remove(name);
|
||||
} else {
|
||||
this.flags.put(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof RegionFlagContainer)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
RegionFlagContainer other = (RegionFlagContainer) obj;
|
||||
return other.flags.equals(this.flags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 3;
|
||||
hash = 97 * hash + (this.flags != null ? this.flags.hashCode() : 0);
|
||||
return hash;
|
||||
}
|
||||
|
||||
public BooleanRegionFlag getBooleanFlag(FlagType type) {
|
||||
|
||||
RegionFlag flag = this.getFlag(type);
|
||||
|
||||
if (flag instanceof BooleanRegionFlag) {
|
||||
return (BooleanRegionFlag) flag;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public StateRegionFlag getStateFlag(FlagType type) {
|
||||
|
||||
RegionFlag flag = this.getFlag(type);
|
||||
|
||||
if (flag instanceof StateRegionFlag) {
|
||||
return (StateRegionFlag) flag;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public IntegerRegionFlag getIntegerFlag(FlagType type) {
|
||||
|
||||
RegionFlag flag = this.getFlag(type);
|
||||
|
||||
if (flag instanceof IntegerRegionFlag) {
|
||||
return (IntegerRegionFlag) flag;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public DoubleRegionFlag getDoubleFlag(FlagType type) {
|
||||
|
||||
RegionFlag flag = this.getFlag(type);
|
||||
|
||||
if (flag instanceof DoubleRegionFlag) {
|
||||
return (DoubleRegionFlag) flag;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public StringRegionFlag getStringFlag(FlagType type) {
|
||||
|
||||
RegionFlag flag = this.getFlag(type);
|
||||
|
||||
if (flag instanceof StringRegionFlag) {
|
||||
return (StringRegionFlag) flag;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public RegionGroupRegionFlag getRegionGroupFlag(FlagType type) {
|
||||
|
||||
RegionFlag flag = this.getFlag(type);
|
||||
|
||||
if (flag instanceof RegionGroupRegionFlag) {
|
||||
return (RegionGroupRegionFlag) flag;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public LocationRegionFlag getLocationFlag(FlagType type) {
|
||||
|
||||
RegionFlag flag = this.getFlag(type);
|
||||
|
||||
if (flag instanceof LocationRegionFlag) {
|
||||
return (LocationRegionFlag) flag;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.protection.regions.flags;
|
||||
|
||||
import com.sk89q.worldguard.protection.regions.flags.FlagDatabase.FlagType;
|
||||
import com.sk89q.worldguard.protection.regions.flags.RegionFlag.FlagDataType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Michael
|
||||
*/
|
||||
public class RegionFlagInfo {
|
||||
|
||||
public String name;
|
||||
public FlagType type;
|
||||
public FlagDataType dataType;
|
||||
|
||||
public RegionFlagInfo(String name, FlagType type, FlagDataType dataType)
|
||||
{
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.dataType = dataType;
|
||||
}
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.sk89q.worldguard.protection.regions.flags;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Michael
|
||||
*/
|
||||
public final class RegionGroupRegionFlag extends RegionFlag {
|
||||
|
||||
private RegionGroup value;
|
||||
|
||||
public RegionGroupRegionFlag(RegionFlagContainer container, RegionFlagInfo info, String value) {
|
||||
super(container, info);
|
||||
this.setValue(value);
|
||||
}
|
||||
|
||||
public void setValue(RegionGroup newValue) {
|
||||
this.value = newValue;
|
||||
this.container.internalSetValue(info.name, newValue != null ? newValue.toString() : null);
|
||||
}
|
||||
|
||||
public RegionGroup getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public RegionGroup getValue(RegionGroup def) {
|
||||
return this.value != null ? this.value : def;
|
||||
}
|
||||
|
||||
public boolean setValue(String newValue) {
|
||||
if (newValue == null) {
|
||||
this.value = null;
|
||||
} else {
|
||||
try {
|
||||
this.value = RegionGroup.valueOf(newValue);
|
||||
} catch (Exception e) {
|
||||
this.value = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasValue() {
|
||||
return this.value != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if(this.value != null)
|
||||
{
|
||||
return this.value.toString();
|
||||
}
|
||||
else
|
||||
{
|
||||
return "-";
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
// $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.flags;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Michael
|
||||
*/
|
||||
public final class StateRegionFlag extends RegionFlag {
|
||||
|
||||
private State value;
|
||||
|
||||
public StateRegionFlag(RegionFlagContainer container, RegionFlagInfo info, String value) {
|
||||
super(container, info);
|
||||
this.setValue(value);
|
||||
}
|
||||
|
||||
public void setValue(State newValue) {
|
||||
this.value = newValue;
|
||||
this.container.internalSetValue(info.name, newValue != null ? newValue.toString() : null);
|
||||
}
|
||||
|
||||
public State getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public State getValue(State def) {
|
||||
return this.value != null ? this.value : def;
|
||||
}
|
||||
|
||||
public boolean setValue(String newValue) {
|
||||
|
||||
if (newValue == null) {
|
||||
this.value = null;
|
||||
} else {
|
||||
try {
|
||||
this.value = State.valueOf(newValue);
|
||||
} catch (Exception e) {
|
||||
this.value = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasValue() {
|
||||
return this.value != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if(this.value != null)
|
||||
{
|
||||
return this.value.toString();
|
||||
}
|
||||
else
|
||||
{
|
||||
return "-";
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
// $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.flags;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Michael
|
||||
*/
|
||||
public class StringRegionFlag extends RegionFlag {
|
||||
|
||||
private String value;
|
||||
|
||||
public StringRegionFlag(RegionFlagContainer container, RegionFlagInfo info, String value) {
|
||||
|
||||
super(container, info);
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public boolean setValue(String newValue) {
|
||||
this.value = newValue;
|
||||
this.container.internalSetValue(info.name, newValue);
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public String getValue(String def) {
|
||||
return this.value != null ? this.value : def;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hasValue() {
|
||||
return this.value != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if(this.value != null)
|
||||
{
|
||||
return this.value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return "-";
|
||||
}
|
||||
}
|
||||
}
|
@ -32,8 +32,6 @@
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldguard.TestPlayer;
|
||||
import com.sk89q.worldguard.domains.DefaultDomain;
|
||||
import com.sk89q.worldguard.protection.regions.AreaFlags;
|
||||
import com.sk89q.worldguard.protection.regions.AreaFlags.State;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -85,11 +83,7 @@ void setUpCourtyardRegion() {
|
||||
|
||||
//ProtectedRegion region = new ProtectedCuboidRegion(COURTYARD_ID, new BlockVector(0, 0, 0), new BlockVector(10, 10, 10));
|
||||
ProtectedRegion region = new ProtectedPolygonalRegion(COURTYARD_ID, points, 0, 10);
|
||||
|
||||
AreaFlags flags = new AreaFlags();
|
||||
flags.setFlag(AreaFlags.FLAG_BUILD, State.NONE);
|
||||
flags.setFlag(AreaFlags.FLAG_FIRE_SPREAD, State.ALLOW);
|
||||
region.setFlags(flags);
|
||||
|
||||
region.setOwners(domain);
|
||||
manager.addRegion(region);
|
||||
|
||||
@ -102,9 +96,6 @@ void setUpFountainRegion() throws Exception {
|
||||
|
||||
ProtectedRegion region = new ProtectedCuboidRegion(FOUNTAIN_ID,
|
||||
new BlockVector(0, 0, 0), new BlockVector(5, 5, 5));
|
||||
AreaFlags flags = new AreaFlags();
|
||||
flags.setFlag(AreaFlags.FLAG_FIRE_SPREAD, State.DENY);
|
||||
region.setFlags(flags);
|
||||
region.setMembers(domain);
|
||||
manager.addRegion(region);
|
||||
|
||||
@ -115,9 +106,6 @@ void setUpFountainRegion() throws Exception {
|
||||
void setUpNoFireRegion() throws Exception {
|
||||
ProtectedRegion region = new ProtectedCuboidRegion(NO_FIRE_ID,
|
||||
new BlockVector(100, 100, 100), new BlockVector(200, 200, 200));
|
||||
AreaFlags flags = new AreaFlags();
|
||||
flags.setFlag(AreaFlags.FLAG_FIRE_SPREAD, State.DENY);
|
||||
region.setFlags(flags);
|
||||
manager.addRegion(region);
|
||||
}
|
||||
|
||||
@ -127,17 +115,17 @@ public void testNonBuildFlag() {
|
||||
|
||||
// Outside
|
||||
appl = manager.getApplicableRegions(outside);
|
||||
assertTrue(appl.allowsFlag(AreaFlags.FLAG_FIRE_SPREAD));
|
||||
//assertTrue(appl.allowsFlag(AreaFlags.FLAG_FIRE_SPREAD));
|
||||
// Inside courtyard
|
||||
appl = manager.getApplicableRegions(inCourtyard);
|
||||
assertTrue(appl.allowsFlag(AreaFlags.FLAG_FIRE_SPREAD));
|
||||
//assertTrue(appl.allowsFlag(AreaFlags.FLAG_FIRE_SPREAD));
|
||||
// Inside fountain
|
||||
appl = manager.getApplicableRegions(inFountain);
|
||||
assertFalse(appl.allowsFlag(AreaFlags.FLAG_FIRE_SPREAD));
|
||||
//assertFalse(appl.allowsFlag(AreaFlags.FLAG_FIRE_SPREAD));
|
||||
|
||||
// Inside no fire zone
|
||||
appl = manager.getApplicableRegions(inNoFire);
|
||||
assertFalse(appl.allowsFlag(AreaFlags.FLAG_FIRE_SPREAD));
|
||||
//assertFalse(appl.allowsFlag(AreaFlags.FLAG_FIRE_SPREAD));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -31,8 +31,7 @@
|
||||
import static org.junit.Assert.*;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldguard.domains.DefaultDomain;
|
||||
import com.sk89q.worldguard.protection.regions.AreaFlags;
|
||||
import com.sk89q.worldguard.protection.regions.AreaFlags.State;
|
||||
|
||||
|
||||
public class CSVDatabaseTest {
|
||||
@Before
|
||||
@ -67,13 +66,14 @@ public void testLoadSave() throws Exception {
|
||||
}
|
||||
|
||||
private void checkTestRegion1(ProtectedRegion region) {
|
||||
AreaFlags flags = new AreaFlags();
|
||||
/* AreaFlags flags = new AreaFlags();
|
||||
flags.setFlag(AreaFlags.FLAG_FIRE_SPREAD, State.ALLOW);
|
||||
flags.setFlag(AreaFlags.FLAG_PVP, State.DENY);
|
||||
flags.setFlag(AreaFlags.FLAG_LIGHTER, State.DENY);
|
||||
region.setFlags(flags);
|
||||
|
||||
assertEquals(region.getFlags(), flags);
|
||||
*/
|
||||
}
|
||||
|
||||
private ProtectedRegion getTestRegion1() {
|
||||
@ -82,12 +82,12 @@ private ProtectedRegion getTestRegion1() {
|
||||
|
||||
ProtectedRegion region = new ProtectedCuboidRegion("test2", min, max);
|
||||
|
||||
AreaFlags flags = new AreaFlags();
|
||||
/* AreaFlags flags = new AreaFlags();
|
||||
flags.setFlag(AreaFlags.FLAG_FIRE_SPREAD, State.ALLOW);
|
||||
flags.setFlag(AreaFlags.FLAG_PVP, State.DENY);
|
||||
flags.setFlag(AreaFlags.FLAG_LIGHTER, State.DENY);
|
||||
region.setFlags(flags);
|
||||
|
||||
*/
|
||||
DefaultDomain domain = new DefaultDomain();
|
||||
domain.addGroup("members");
|
||||
domain.addGroup("sturmehs");
|
||||
@ -106,12 +106,13 @@ private ProtectedRegion getTestRegion2() {
|
||||
BlockVector max = new BlockVector(10, 11, 12);
|
||||
|
||||
ProtectedRegion region = new ProtectedCuboidRegion("test2", min, max);
|
||||
|
||||
/*
|
||||
AreaFlags flags = new AreaFlags();
|
||||
flags.setFlag(AreaFlags.FLAG_FIRE_SPREAD, State.ALLOW);
|
||||
flags.setFlag(AreaFlags.FLAG_PVP, State.ALLOW);
|
||||
flags.setFlag(AreaFlags.FLAG_LIGHTER, State.DENY);
|
||||
region.setFlags(flags);
|
||||
*/
|
||||
|
||||
DefaultDomain domain = new DefaultDomain();
|
||||
domain.addGroup("admins");
|
||||
|
Loading…
Reference in New Issue
Block a user