From 20afbdf264ece324da615d7cb38f7520659e28fa Mon Sep 17 00:00:00 2001 From: sk89q Date: Sat, 26 Mar 2011 19:33:29 -0700 Subject: [PATCH] More is working! DO NOT USE THIS YET or I will have to personally slap you. --- .../worldguard/bukkit/WorldConfiguration.java | 14 -- .../bukkit/WorldGuardBlockListener.java | 31 ++- .../bukkit/WorldGuardEntityListener.java | 24 ++- .../bukkit/WorldGuardPlayerListener.java | 11 +- .../worldguard/bukkit/WorldGuardPlugin.java | 3 - .../bukkit/WorldGuardVehicleListener.java | 2 +- .../bukkit/commands/CommandBuyRegion.java | 115 ----------- .../bukkit/commands/CommandHandler.java | 194 ----------------- .../commands/CommandRegionAddMember.java | 108 ---------- .../bukkit/commands/CommandRegionDelete.java | 80 ------- .../bukkit/commands/CommandRegionFlag.java | 143 ------------- .../bukkit/commands/CommandRegionInfo.java | 101 --------- .../bukkit/commands/CommandRegionList.java | 85 -------- .../bukkit/commands/CommandRegionLoad.java | 57 ----- .../commands/CommandRegionPriority.java | 93 --------- .../commands/CommandRegionRemoveMember.java | 109 ---------- .../bukkit/commands/CommandRegionSave.java | 58 ------ .../commands/CommandRegionSetParent.java | 110 ---------- .../bukkit/commands/CommandReloadWG.java | 70 ------- .../bukkit/commands/CommandTpRegion.java | 89 -------- .../bukkit/commands/RegionCommands.java | 19 +- .../protection/ApplicableRegionSet.java | 195 +++++++++++------- .../protection/TimedFlagsTimer.java | 95 +++++---- .../protection/flags/BooleanFlag.java | 35 ++++ .../protection/flags/DefaultFlag.java | 65 +++--- .../protection/flags/DoubleFlag.java | 4 +- .../worldguard/protection/flags/Flag.java | 2 - .../protection/flags/IntegerFlag.java | 4 +- .../protection/flags/LocationFlag.java | 5 +- .../protection/flags/RegionGroupFlag.java | 4 +- .../protection/flags/StateFlag.java | 16 +- .../protection/flags/StringFlag.java | 2 +- .../managers/FlatRegionManager.java | 13 +- .../managers/GlobalRegionManager.java | 185 ----------------- .../managers/PRTreeRegionManager.java | 13 +- .../protection/managers/RegionManager.java | 4 +- .../regions/GlobalProtectedRegion.java | 66 ++++++ .../protection/regions/ProtectedRegion.java | 12 +- .../protection/ApplicableRegionSetTest.java | 15 +- .../protection/CSVDatabaseTest.java | 1 - 40 files changed, 400 insertions(+), 1852 deletions(-) delete mode 100644 src/com/sk89q/worldguard/bukkit/commands/CommandBuyRegion.java delete mode 100644 src/com/sk89q/worldguard/bukkit/commands/CommandHandler.java delete mode 100644 src/com/sk89q/worldguard/bukkit/commands/CommandRegionAddMember.java delete mode 100644 src/com/sk89q/worldguard/bukkit/commands/CommandRegionDelete.java delete mode 100644 src/com/sk89q/worldguard/bukkit/commands/CommandRegionFlag.java delete mode 100644 src/com/sk89q/worldguard/bukkit/commands/CommandRegionInfo.java delete mode 100644 src/com/sk89q/worldguard/bukkit/commands/CommandRegionList.java delete mode 100644 src/com/sk89q/worldguard/bukkit/commands/CommandRegionLoad.java delete mode 100644 src/com/sk89q/worldguard/bukkit/commands/CommandRegionPriority.java delete mode 100644 src/com/sk89q/worldguard/bukkit/commands/CommandRegionRemoveMember.java delete mode 100644 src/com/sk89q/worldguard/bukkit/commands/CommandRegionSave.java delete mode 100644 src/com/sk89q/worldguard/bukkit/commands/CommandRegionSetParent.java delete mode 100644 src/com/sk89q/worldguard/bukkit/commands/CommandReloadWG.java delete mode 100644 src/com/sk89q/worldguard/bukkit/commands/CommandTpRegion.java create mode 100644 src/com/sk89q/worldguard/protection/flags/BooleanFlag.java delete mode 100644 src/com/sk89q/worldguard/protection/managers/GlobalRegionManager.java create mode 100644 src/com/sk89q/worldguard/protection/regions/GlobalProtectedRegion.java diff --git a/src/com/sk89q/worldguard/bukkit/WorldConfiguration.java b/src/com/sk89q/worldguard/bukkit/WorldConfiguration.java index d56c219d..5ad5023a 100644 --- a/src/com/sk89q/worldguard/bukkit/WorldConfiguration.java +++ b/src/com/sk89q/worldguard/bukkit/WorldConfiguration.java @@ -24,7 +24,6 @@ import com.sk89q.worldguard.blacklist.loggers.ConsoleLoggerHandler; import com.sk89q.worldguard.blacklist.loggers.DatabaseLoggerHandler; import com.sk89q.worldguard.blacklist.loggers.FileLoggerHandler; -import com.sk89q.worldguard.protection.GlobalFlags; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; @@ -175,19 +174,6 @@ private void loadConfiguration() { } } - GlobalFlags globalFlags = new GlobalFlags(); - globalFlags.canBuild = config.getBoolean("regions.default.build", true); - globalFlags.canAccessChests = config.getBoolean("regions.default.chest-access", false); - globalFlags.canPvP = config.getBoolean("regions.default.pvp", true); - globalFlags.canLighter = config.getBoolean("regions.default.lighter", true); - globalFlags.canTnt = config.getBoolean("regions.default.tnt", true); - globalFlags.allowCreeper = config.getBoolean("regions.default.creeper", true); - globalFlags.allowMobDamage = config.getBoolean("regions.default.mobdamage", true); - globalFlags.canLeverandbutton = config.getBoolean("regions.default.leverandbutton", true); - globalFlags.canPlaceVehicle = config.getBoolean("regions.default.placevehicle", true); - globalFlags.allowWaterflow = config.getBoolean("regions.default.waterflow", true); - plugin.getGlobalRegionManager().setGlobalFlags(worldName, globalFlags); - boolean useBlacklistAsWhitelist = config.getBoolean("blacklist.use-as-whitelist", false); // Console log configuration diff --git a/src/com/sk89q/worldguard/bukkit/WorldGuardBlockListener.java b/src/com/sk89q/worldguard/bukkit/WorldGuardBlockListener.java index 5b5bf46e..499b2f89 100644 --- a/src/com/sk89q/worldguard/bukkit/WorldGuardBlockListener.java +++ b/src/com/sk89q/worldguard/bukkit/WorldGuardBlockListener.java @@ -19,7 +19,6 @@ package com.sk89q.worldguard.bukkit; import com.sk89q.worldguard.protection.flags.DefaultFlag; -import com.sk89q.worldguard.protection.flags.RegionFlags; import com.sk89q.worldguard.protection.managers.RegionManager; import org.bukkit.event.Event.Priority; import org.bukkit.event.Event; @@ -68,14 +67,14 @@ public void registerEvents() { PluginManager pm = plugin.getServer().getPluginManager(); - pm.registerEvent(Event.Type.BLOCK_DAMAGED, this, Priority.High, plugin); + pm.registerEvent(Event.Type.BLOCK_DAMAGE, this, Priority.High, plugin); pm.registerEvent(Event.Type.BLOCK_BREAK, this, Priority.High, plugin); - pm.registerEvent(Event.Type.BLOCK_FLOW, this, Priority.Normal, plugin); + pm.registerEvent(Event.Type.BLOCK_FROMTO, this, Priority.Normal, plugin); pm.registerEvent(Event.Type.BLOCK_IGNITE, this, Priority.High, plugin); pm.registerEvent(Event.Type.BLOCK_PHYSICS, this, Priority.Normal, plugin); - pm.registerEvent(Event.Type.BLOCK_INTERACT, this, Priority.High, plugin); - pm.registerEvent(Event.Type.BLOCK_PLACED, this, Priority.High, plugin); - pm.registerEvent(Event.Type.BLOCK_RIGHTCLICKED, this, Priority.High, plugin); + //pm.registerEvent(Event.Type.BLOCK_INTERACT, this, Priority.High, plugin); + pm.registerEvent(Event.Type.BLOCK_PLACE, this, Priority.High, plugin); + //pm.registerEvent(Event.Type.BLOCK_RIGHTCLICK, this, Priority.High, plugin); pm.registerEvent(Event.Type.BLOCK_BURN, this, Priority.High, plugin); pm.registerEvent(Event.Type.REDSTONE_CHANGE, this, Priority.High, plugin); } @@ -247,7 +246,7 @@ public void onBlockFlow(BlockFromToEvent event) { Vector pt = toVector(blockFrom.getLocation()); RegionManager mgr = plugin.getGlobalRegionManager().get(world.getName()); - if (!mgr.getApplicableRegions(pt).isStateFlagAllowed(DefaultFlag.WATER_FLOW)) { + if (!mgr.getApplicableRegions(pt).allows(DefaultFlag.WATER_FLOW)) { event.setCancelled(true); return; } @@ -293,18 +292,18 @@ public void onBlockIgnite(BlockIgniteEvent event) { } if (cause == IgniteCause.FLINT_AND_STEEL - && !set.isStateFlagAllowed(DefaultFlag.LIGHTER)) { + && !set.allows(DefaultFlag.LIGHTER)) { event.setCancelled(true); return; } } - if (isFireSpread && set.isStateFlagAllowed(DefaultFlag.FIRE_SPREAD)) { + if (isFireSpread && set.allows(DefaultFlag.FIRE_SPREAD)) { event.setCancelled(true); return; } - if (cause == IgniteCause.LAVA && !set.isStateFlagAllowed(DefaultFlag.LAVA_FIRE)) { + if (cause == IgniteCause.LAVA && !set.allows(DefaultFlag.LAVA_FIRE)) { event.setCancelled(true); return; } @@ -419,7 +418,7 @@ public void onBlockPhysics(BlockPhysicsEvent event) { * Called when a block is interacted with * * @param event Relevant event details - */ + *//* @Override public void onBlockInteract(BlockInteractEvent event) { @@ -448,7 +447,7 @@ public void onBlockInteract(BlockInteractEvent event) { if (!plugin.hasPermission(player, "region.bypass")) { ApplicableRegionSet set = mgr.getApplicableRegions(pt); - if (!set.isStateFlagAllowed(DefaultFlag.CHEST_ACCESS) && !set.canBuild(localPlayer)) { + if (!set.allows(DefaultFlag.CHEST_ACCESS) && !set.canBuild(localPlayer)) { player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area."); event.setCancelled(true); return; @@ -463,7 +462,7 @@ public void onBlockInteract(BlockInteractEvent event) { ApplicableRegionSet applicableRegions = mgr.getApplicableRegions(pt); LocalPlayer localPlayer = plugin.wrapPlayer((Player)entity); - if (!applicableRegions.isStateFlagAllowed(DefaultFlag.LEVER_AND_BUTTON, localPlayer)) { + if (!applicableRegions.canUse(localPlayer)) { ((Player)entity).sendMessage(ChatColor.DARK_RED + "You don't have permission for this area."); event.setCancelled(true); return; @@ -480,7 +479,7 @@ public void onBlockInteract(BlockInteractEvent event) { return; } } - } + }*/ /** * Called when a player places a block @@ -538,9 +537,9 @@ public void onBlockPlace(BlockPlaceEvent event) { * * @param event Relevant event details */ + /* @Override public void onBlockRightClick(BlockRightClickEvent event) { - Player player = event.getPlayer(); Block blockClicked = event.getBlock(); @@ -639,7 +638,7 @@ public void onBlockRightClick(BlockRightClickEvent event) { } } } - } + }*/ /** * Called when redstone changes diff --git a/src/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java b/src/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java index b85ab2aa..9aff8555 100644 --- a/src/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java +++ b/src/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java @@ -60,7 +60,7 @@ public void registerEvents() { PluginManager pm = plugin.getServer().getPluginManager(); - pm.registerEvent(Event.Type.ENTITY_DAMAGED, this, Priority.High, plugin); + pm.registerEvent(Event.Type.ENTITY_DAMAGE, this, Priority.High, plugin); pm.registerEvent(Event.Type.ENTITY_EXPLODE, this, Priority.High, plugin); pm.registerEvent(Event.Type.CREATURE_SPAWN, this, Priority.High, plugin); } @@ -115,7 +115,7 @@ public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { Vector pt = toVector(defender.getLocation()); RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld().getName()); - if (!mgr.getApplicableRegions(pt).isStateFlagAllowed(DefaultFlag.PVP)) { + if (!mgr.getApplicableRegions(pt).allows(DefaultFlag.PVP)) { ((Player) attacker).sendMessage(ChatColor.DARK_RED + "You are in a no-PvP area."); event.setCancelled(true); return; @@ -134,13 +134,13 @@ public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld().getName()); ApplicableRegionSet set = mgr.getApplicableRegions(pt); - if (!set.isStateFlagAllowed(DefaultFlag.MOB_DAMAGE)) { + if (!set.allows(DefaultFlag.MOB_DAMAGE)) { event.setCancelled(true); return; } if (attacker instanceof Creeper) { - if (!set.isStateFlagAllowed(DefaultFlag.CREEPER_EXPLOSION)) { + if (!set.allows(DefaultFlag.CREEPER_EXPLOSION)) { event.setCancelled(true); return; } @@ -171,7 +171,7 @@ public void onEntityDamageByProjectile(EntityDamageByProjectileEvent event) { Vector pt = toVector(defender.getLocation()); RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld().getName()); - if (!mgr.getApplicableRegions(pt).isStateFlagAllowed(DefaultFlag.PVP)) { + if (!mgr.getApplicableRegions(pt).allows(DefaultFlag.PVP)) { ((Player) attacker).sendMessage(ChatColor.DARK_RED + "You are in a no-PvP area."); event.setCancelled(true); return; @@ -183,7 +183,7 @@ public void onEntityDamageByProjectile(EntityDamageByProjectileEvent event) { Vector pt = toVector(defender.getLocation()); RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld().getName()); - if (!mgr.getApplicableRegions(pt).isStateFlagAllowed(DefaultFlag.MOB_DAMAGE)) { + if (!mgr.getApplicableRegions(pt).allows(DefaultFlag.MOB_DAMAGE)) { event.setCancelled(true); return; } @@ -288,7 +288,7 @@ public void onEntityExplode(EntityExplodeEvent event) { Vector pt = toVector(l); RegionManager mgr = plugin.getGlobalRegionManager().get(wcfg.getWorldName()); - if (!mgr.getApplicableRegions(pt).isStateFlagAllowed(DefaultFlag.CREEPER_EXPLOSION)) { + if (!mgr.getApplicableRegions(pt).allows(DefaultFlag.CREEPER_EXPLOSION)) { event.setCancelled(true); return; } @@ -303,7 +303,7 @@ public void onEntityExplode(EntityExplodeEvent event) { Vector pt = toVector(l); RegionManager mgr = plugin.getGlobalRegionManager().get(wcfg.getWorldName()); - if (!mgr.getApplicableRegions(pt).isStateFlagAllowed(DefaultFlag.TNT)) { + if (!mgr.getApplicableRegions(pt).allows(DefaultFlag.TNT)) { event.setCancelled(true); return; } @@ -327,12 +327,14 @@ public void onCreatureSpawn(CreatureSpawnEvent event) { if (wcfg.blockCreatureSpawn.contains(creaType)) { cancelEvent = true; } - + + // TODO: Monsters and stuff +/* if (wcfg.useRegions) { Vector pt = toVector(event.getEntity().getLocation()); RegionManager mgr = plugin.getGlobalRegionManager().get(event.getEntity().getWorld().getName()); - Boolean flagValue = mgr.getApplicableRegions(pt).getStringFlag(DefaultFlag.DENY_SPAWN, true).getValue("").contains(creaType.getName()); + Boolean flagValue = mgr.getApplicableRegions(pt).getFlag(DefaultFlag.DENY_SPAWN).getValue("").contains(creaType.getName()); if (flagValue != null) { if (flagValue) { cancelEvent = true; @@ -340,7 +342,7 @@ public void onCreatureSpawn(CreatureSpawnEvent event) { cancelEvent = false; } } - } + }*/ if (cancelEvent) { event.setCancelled(true); diff --git a/src/com/sk89q/worldguard/bukkit/WorldGuardPlayerListener.java b/src/com/sk89q/worldguard/bukkit/WorldGuardPlayerListener.java index 542597ab..fba2c43c 100644 --- a/src/com/sk89q/worldguard/bukkit/WorldGuardPlayerListener.java +++ b/src/com/sk89q/worldguard/bukkit/WorldGuardPlayerListener.java @@ -38,7 +38,6 @@ import com.sk89q.worldguard.blacklist.events.ItemUseBlacklistEvent; import com.sk89q.worldguard.protection.ApplicableRegionSet; import com.sk89q.worldguard.protection.flags.DefaultFlag; -import com.sk89q.worldguard.protection.flags.RegionFlag.RegionGroup; import com.sk89q.worldguard.protection.managers.RegionManager; /** @@ -65,7 +64,7 @@ public WorldGuardPlayerListener(WorldGuardPlugin plugin) { public void registerEvents() { PluginManager pm = plugin.getServer().getPluginManager(); - pm.registerEvent(Event.Type.PLAYER_ITEM, this, Priority.High, plugin); + //pm.registerEvent(Event.Type.PLAYER_ITEM, this, Priority.High, plugin); pm.registerEvent(Event.Type.PLAYER_DROP_ITEM, this, Priority.High, plugin); pm.registerEvent(Event.Type.PLAYER_PICKUP_ITEM, this, Priority.High, plugin); pm.registerEvent(Event.Type.PLAYER_JOIN, this, Priority.Normal, plugin); @@ -122,7 +121,7 @@ public void onPlayerQuit(PlayerEvent event) { * Called when a player uses an item * * @param event Relevant event details - */ + *//* @Override public void onPlayerItem(PlayerItemEvent event) { @@ -185,7 +184,7 @@ public void onPlayerItem(PlayerItemEvent event) { return; } } - } + }*/ /** * Called when a player attempts to log in to the server @@ -271,7 +270,7 @@ public void onPlayerPickupItem(PlayerPickupItemEvent event) { } } } - +/* @Override public void onPlayerRespawn(PlayerRespawnEvent event) { Player player = event.getPlayer(); @@ -303,5 +302,5 @@ public void onPlayerRespawn(PlayerRespawnEvent event) { event.setRespawnLocation(spawn); } } - } + }*/ } diff --git a/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java b/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java index 6db42d21..4af2f96b 100644 --- a/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java +++ b/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java @@ -34,7 +34,6 @@ import com.sk89q.worldguard.LocalPlayer; import com.sk89q.worldguard.protection.GlobalRegionManager; import com.sk89q.worldguard.protection.TimedFlagsTimer; -import com.sk89q.worldguard.protection.flags.DefaultFlag; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -83,8 +82,6 @@ public class WorldGuardPlugin extends JavaPlugin { public void onEnable() { getDataFolder().mkdirs(); - DefaultFlag.init(); - configuration = new GlobalConfiguration(this); configuration.load(); diff --git a/src/com/sk89q/worldguard/bukkit/WorldGuardVehicleListener.java b/src/com/sk89q/worldguard/bukkit/WorldGuardVehicleListener.java index 3c1de0b7..494878c0 100644 --- a/src/com/sk89q/worldguard/bukkit/WorldGuardVehicleListener.java +++ b/src/com/sk89q/worldguard/bukkit/WorldGuardVehicleListener.java @@ -73,7 +73,7 @@ public void onVehicleCreate(VehicleCreateEvent event) { RegionManager mgr = cfg.getWorldGuardPlugin().getGlobalRegionManager().get(vhcl.getWorld().getName()); ApplicableRegionSet applicableRegions = mgr.getApplicableRegions(pt); - if (!applicableRegions.isStateFlagAllowed(DefaultFlag.PLACE_VEHICLE)) { + if (!applicableRegions.allows(DefaultFlag.PLACE_VEHICLE)) { vhcl.remove(); return; } diff --git a/src/com/sk89q/worldguard/bukkit/commands/CommandBuyRegion.java b/src/com/sk89q/worldguard/bukkit/commands/CommandBuyRegion.java deleted file mode 100644 index 94e5af2a..00000000 --- a/src/com/sk89q/worldguard/bukkit/commands/CommandBuyRegion.java +++ /dev/null @@ -1,115 +0,0 @@ -// $Id$ -/* - * WorldGuard - * Copyright (C) 2010 sk89q - * - * 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 . -*/ -package com.sk89q.worldguard.bukkit.commands; - -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import com.nijiko.coelho.iConomy.iConomy; -import com.nijiko.coelho.iConomy.system.*; -import com.sk89q.worldguard.bukkit.GlobalConfiguration; -import com.sk89q.worldguard.bukkit.WorldGuardPlugin; -import com.sk89q.worldguard.domains.DefaultDomain; -import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException; -import com.sk89q.worldguard.protection.flags.DefaultFlag; -import com.sk89q.worldguard.protection.flags.RegionFlags; -import com.sk89q.worldguard.protection.managers.RegionManager; -import com.sk89q.worldguard.protection.regions.ProtectedRegion; - -/** - * - * @author DarkLiKally - */ -public class CommandBuyRegion extends WgCommand { - - - @Override - public boolean handle(CommandSender sender, String senderName, - String command, String[] args, GlobalConfiguration cfg, WorldGuardPlugin plugin) - throws CommandHandlingException { - - if (!(sender instanceof Player)) { - sender.sendMessage("Only players may use this command"); - return true; - } - Player player = (Player) sender; - - if (cfg.getiConomy() == null) { - sender.sendMessage("iConomy is not installed on this Server."); - return true; - } - - CommandHandler.checkArgs(args, 1, 2); - - plugin.checkPermission(player, "regions.buy"); - - String id = args[0]; - - RegionManager mgr = cfg.getWorldGuardPlugin().getGlobalRegionManager().get(player.getWorld().getName()); - ProtectedRegion region = mgr.getRegion(id); - if (region != null) { - RegionFlags flags = region.getFlags(); - - if (flags.getBooleanFlag(DefaultFlag.BUYABLE).getValue(false)) { - if (args.length == 2) { - if (args[1].equalsIgnoreCase("info")) { - player.sendMessage(ChatColor.YELLOW + "Region " + id + " costs " + - iConomy.getBank().format(flags.getDoubleFlag(DefaultFlag.PRICE).getValue())); - if (iConomy.getBank().hasAccount(player.getName())) { - player.sendMessage(ChatColor.YELLOW + "You have " + - iConomy.getBank().format( - iConomy.getBank().getAccount(player.getName()).getBalance())); - } else { - player.sendMessage(ChatColor.YELLOW + "You have not enough money."); - } - } else { - player.sendMessage(ChatColor.RED + "Usage: /buyregion (info)"); - } - } else { - if (iConomy.getBank().hasAccount(player.getName())) { - Account account = iConomy.getBank().getAccount(player.getName()); - double balance = account.getBalance(); - double regionPrice = flags.getDoubleFlag(DefaultFlag.PRICE).getValue(); - - if (balance >= regionPrice) { - account.subtract(regionPrice); - player.sendMessage(ChatColor.YELLOW + "You have bought the region " + id + " for " + - iConomy.getBank().format(regionPrice)); - DefaultDomain owners = region.getOwners(); - owners.addPlayer(player.getName()); - region.setOwners(owners); - flags.getBooleanFlag(DefaultFlag.BUYABLE).setValue(false); - account.save(); - } else { - player.sendMessage(ChatColor.YELLOW + "You have not enough money."); - } - } else { - player.sendMessage(ChatColor.YELLOW + "You have not enough money."); - } - } - } else { - player.sendMessage(ChatColor.RED + "Region: " + id + " is not buyable"); - } - } else { - player.sendMessage(ChatColor.RED + "Region: " + id + " not defined"); - } - return true; - } -} diff --git a/src/com/sk89q/worldguard/bukkit/commands/CommandHandler.java b/src/com/sk89q/worldguard/bukkit/commands/CommandHandler.java deleted file mode 100644 index a95f0fcc..00000000 --- a/src/com/sk89q/worldguard/bukkit/commands/CommandHandler.java +++ /dev/null @@ -1,194 +0,0 @@ -// $Id$ -/* - * WorldGuard - * Copyright (C) 2010 sk89q - * - * 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 . -*/ - - -package com.sk89q.worldguard.bukkit.commands; - -import com.sk89q.worldguard.bukkit.WorldGuardPlugin; -import java.util.HashMap; -import java.util.Map; -import org.bukkit.ChatColor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.command.PluginCommand; -import org.bukkit.entity.Player; - -/** - * - * @author Michael - */ -public class CommandHandler implements CommandExecutor { - - private WorldGuardPlugin wg; - private Map commandMap; - - public static int CMD_LIST_SIZE = 9; - - public CommandHandler(WorldGuardPlugin wg) - { - this.wg = wg; - this.commandMap = new HashMap(); - - WgCommand regionHandler = new RegionCommandHandler(); - - // commands that DO support console as sender - this.commandMap.put("allowfire", new CommandAllowFire()); - this.commandMap.put("god", new CommandGod()); - this.commandMap.put("heal", new CommandHeal()); - this.commandMap.put("region", regionHandler); - this.commandMap.put("rd", regionHandler); - this.commandMap.put("rc", regionHandler); - this.commandMap.put("rf", regionHandler); - this.commandMap.put("ri", regionHandler); - this.commandMap.put("rlist", regionHandler); - this.commandMap.put("rp", regionHandler); - this.commandMap.put("reloadwg", new CommandReloadWG()); - this.commandMap.put("slay", new CommandSlay()); - this.commandMap.put("stopfire", new CommandStopFire()); - - // commands that DO NOT support console as sender - this.commandMap.put("stack", new CommandStack()); - this.commandMap.put("locate", new CommandLocate()); - this.commandMap.put("buyregion", new CommandBuyRegion()); - this.commandMap.put("tpregrion", new CommandTpRegion()); - } - - - public void registerCommands() - { - for(String cmd : this.commandMap.keySet()) - { - PluginCommand command = wg.getCommand(cmd); - if(command != null) - { - command.setExecutor(this); - } - } - } - - public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { - - try { - String cmdName = cmd.getName().toLowerCase(); - WgCommand wgcmd = commandMap.get(cmdName); - if (wgcmd == null) { - return false; - } - - String senderName = sender instanceof Player ? ((Player)sender).getName() : "Console"; - - wgcmd.handle(sender, senderName, cmdName, args, wg.getGlobalConfiguration(), wg); - return true; - - } catch (InsufficientArgumentsException e) { - if (e.getHelp() != null) { - sender.sendMessage(ChatColor.RED + e.getHelp()); - return true; - } else { - return false; - } - } catch (InsufficientPermissionsException e) { - sender.sendMessage(ChatColor.RED + "You don't have sufficient permission."); - return true; - } catch (CommandHandlingException e) { - return true; - } catch (Throwable t) { - sender.sendMessage(ChatColor.RED + "ERROR: " + t.getMessage()); - t.printStackTrace(); - return true; - } - - } - - /** - * Checks to make sure that there are enough but not too many arguments. - * - * @param args - * @param min - * @param max -1 for no maximum - * @throws InsufficientArgumentsException - */ - public static void checkArgs(String[] args, int min, int max) - throws InsufficientArgumentsException { - if (args.length < min || (max != -1 && args.length > max)) { - throw new InsufficientArgumentsException(); - } - } - - /** - * Checks to make sure that there are enough but not too many arguments. - * - * @param args - * @param min - * @param max -1 for no maximum - * @param help - * @throws InsufficientArgumentsException - */ - public static void checkArgs(String[] args, int min, int max, String help) - throws InsufficientArgumentsException { - if (args.length < min || (max != -1 && args.length > max)) { - throw new InsufficientArgumentsException(help); - } - } - - - /** - * Thrown when command handling has raised an exception. - * - * @author sk89q - */ - public static class CommandHandlingException extends Exception { - private static final long serialVersionUID = 7912130636812036780L; - } - - /** - * Thrown when a player has insufficient permissions. - * - * @author sk89q - */ - public static class InsufficientPermissionsException extends CommandHandlingException { - private static final long serialVersionUID = 9087662707619954750L; - } - - /** - * Thrown when a command wasn't given sufficient arguments. - * - * @author sk89q - */ - public static class InsufficientArgumentsException extends CommandHandlingException { - private static final long serialVersionUID = 4153597953889773788L; - private final String help; - - public InsufficientArgumentsException() { - help = null; - } - - public InsufficientArgumentsException(String msg) { - this.help = msg; - } - - public String getHelp() { - return help; - } - } - - - -} diff --git a/src/com/sk89q/worldguard/bukkit/commands/CommandRegionAddMember.java b/src/com/sk89q/worldguard/bukkit/commands/CommandRegionAddMember.java deleted file mode 100644 index 30e6bca3..00000000 --- a/src/com/sk89q/worldguard/bukkit/commands/CommandRegionAddMember.java +++ /dev/null @@ -1,108 +0,0 @@ -// $Id$ -/* - * WorldGuard - * Copyright (C) 2010 sk89q - * - * 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 . - */ -package com.sk89q.worldguard.bukkit.commands; - -import com.sk89q.worldguard.bukkit.BukkitPlayer; -import com.sk89q.worldguard.bukkit.GlobalConfiguration; -import com.sk89q.worldguard.bukkit.WorldConfiguration; -import com.sk89q.worldguard.bukkit.WorldGuardPlugin; -import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException; -import com.sk89q.worldguard.protection.managers.RegionManager; -import com.sk89q.worldguard.protection.regions.ProtectedRegion; -import com.sk89q.worldguard.util.RegionUtil; -import java.io.IOException; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -/** - * - * @author Michael - */ -public class CommandRegionAddMember extends WgRegionCommand { - - @Override - public boolean handle(CommandSender sender, String senderName, - String command, String[] args, GlobalConfiguration cfg, - WorldConfiguration wcfg, WorldGuardPlugin plugin) - throws CommandHandlingException { - - - boolean cmdIsOwner = command.equalsIgnoreCase("addowner"); - - String permOwn; - String permAll; - - if (cmdIsOwner) { - CommandHandler.checkArgs(args, 2, -1, "/region addowner [player1 [group1 [players/groups...]]]"); - permOwn = "region.addowner.own"; - permAll = "region.addowner"; - } else { - CommandHandler.checkArgs(args, 2, -1, "/region addmember [player1 [group1 [players/groups...]]]"); - permOwn = "region.addmember.own"; - permAll = "region.addmember"; - } - - RegionManager mgr = cfg.getWorldGuardPlugin().getGlobalRegionManager().get(wcfg.getWorldName()); - - String id = args[0].toLowerCase(); - if (!mgr.hasRegion(id)) { - sender.sendMessage(ChatColor.RED + "A region with ID '" - + id + "' doesn't exist."); - return true; - } - - ProtectedRegion existing = mgr.getRegion(id); - - if (sender instanceof Player) { - Player player = (Player) sender; - - if (existing.isOwner(BukkitPlayer.wrapPlayer(plugin, player))) { - plugin.checkPermission(sender, permOwn); - } - else { - plugin.checkPermission(sender, permAll); - } - } - else - { - plugin.checkPermission(sender, permAll); - } - - if (cmdIsOwner) { - RegionUtil.addToDomain(existing.getOwners(), args, 1); - } else { - RegionUtil.addToDomain(existing.getMembers(), args, 1); - } - - try { - mgr.save(); - sender.sendMessage(ChatColor.YELLOW + "Region updated!"); - sender.sendMessage(ChatColor.GRAY + "Current owners: " - + existing.getOwners().toUserFriendlyString()); - sender.sendMessage(ChatColor.GRAY + "Current members: " - + existing.getMembers().toUserFriendlyString()); - } catch (IOException e) { - sender.sendMessage(ChatColor.RED + "Region database failed to save: " - + e.getMessage()); - } - - return true; - } -} diff --git a/src/com/sk89q/worldguard/bukkit/commands/CommandRegionDelete.java b/src/com/sk89q/worldguard/bukkit/commands/CommandRegionDelete.java deleted file mode 100644 index cb8f7c3a..00000000 --- a/src/com/sk89q/worldguard/bukkit/commands/CommandRegionDelete.java +++ /dev/null @@ -1,80 +0,0 @@ -// $Id$ -/* - * WorldGuard - * Copyright (C) 2010 sk89q - * - * 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 . - */ -package com.sk89q.worldguard.bukkit.commands; - -import com.sk89q.worldguard.bukkit.BukkitPlayer; -import com.sk89q.worldguard.bukkit.GlobalConfiguration; -import com.sk89q.worldguard.bukkit.WorldConfiguration; -import com.sk89q.worldguard.bukkit.WorldGuardPlugin; -import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException; -import com.sk89q.worldguard.protection.managers.RegionManager; -import com.sk89q.worldguard.protection.regions.ProtectedRegion; -import java.io.IOException; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -/** - * - * @author Michael - */ -public class CommandRegionDelete extends WgRegionCommand { - @Override - public boolean handle(CommandSender sender, String senderName, - String command, String[] args, GlobalConfiguration cfg, - WorldConfiguration wcfg, WorldGuardPlugin plugin) - throws CommandHandlingException { - - CommandHandler.checkArgs(args, 0, 1, "/region delete "); - - try { - String id = args[0].toLowerCase(); - RegionManager mgr = cfg.getWorldGuardPlugin().getGlobalRegionManager().get(wcfg.getWorldName()); - - if (!mgr.hasRegion(id)) { - sender.sendMessage(ChatColor.RED + "A region with ID '" - + id + "' doesn't exist."); - return true; - } - - ProtectedRegion existing = mgr.getRegion(id); - - if (sender instanceof Player) { - Player player = (Player) sender; - - if (existing.isOwner(BukkitPlayer.wrapPlayer(plugin, player))) { - plugin.checkPermission(sender, "region.delete.own"); - } else { - plugin.checkPermission(sender, "region.delete"); - } - } else { - plugin.checkPermission(sender, "region.delete"); - } - - mgr.removeRegion(id); - mgr.save(); - sender.sendMessage(ChatColor.YELLOW + "Region removed!"); - } catch (IOException e) { - sender.sendMessage(ChatColor.RED + "Region database failed to save: " - + e.getMessage()); - } - - return true; - } -} diff --git a/src/com/sk89q/worldguard/bukkit/commands/CommandRegionFlag.java b/src/com/sk89q/worldguard/bukkit/commands/CommandRegionFlag.java deleted file mode 100644 index 6bcc90e6..00000000 --- a/src/com/sk89q/worldguard/bukkit/commands/CommandRegionFlag.java +++ /dev/null @@ -1,143 +0,0 @@ -// $Id$ -/* - * WorldGuard - * Copyright (C) 2010 sk89q - * - * 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 . - */ -package com.sk89q.worldguard.bukkit.commands; - -import com.sk89q.worldguard.bukkit.BukkitPlayer; -import com.sk89q.worldguard.bukkit.BukkitUtil; -import com.sk89q.worldguard.bukkit.GlobalConfiguration; -import com.sk89q.worldguard.bukkit.WorldConfiguration; -import com.sk89q.worldguard.bukkit.WorldGuardPlugin; -import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException; -import com.sk89q.worldguard.protection.flags.FlagDatabase; -import com.sk89q.worldguard.protection.flags.Flag; -import com.sk89q.worldguard.protection.flags.LocationFlag; -import com.sk89q.worldguard.protection.flags.RegionFlag.FlagDataType; -import com.sk89q.worldguard.protection.managers.RegionManager; -import com.sk89q.worldguard.protection.regions.ProtectedRegion; -import java.io.IOException; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -/** - * - * @author Michael - */ -public class CommandRegionFlag extends WgRegionCommand { - @Override - public boolean handle(CommandSender sender, String senderName, - String command, String[] args, GlobalConfiguration cfg, - WorldConfiguration wcfg, WorldGuardPlugin plugin) - throws CommandHandlingException { - - CommandHandler.checkArgs(args, 2, -1, "/region flag () [no value to unset flag]"); - - try { - String id = args[0].toLowerCase(); - String nameStr = args[1]; - String valueStr = null; - - if (args.length == 3) { - valueStr = args[2]; - } else if (args.length > 3) { - StringBuilder tmp = new StringBuilder(); - for (int i = 2; i < args.length; i++) { - tmp.append(args[i]); - } - valueStr = tmp.toString(); - } - - RegionManager mgr = cfg.getWorldGuardPlugin().getGlobalRegionManager().get(wcfg.getWorldName()); - ProtectedRegion region = mgr.getRegion(id); - - if (region == null) { - sender.sendMessage(ChatColor.RED + "Could not find a region by that ID."); - return true; - } - - if (sender instanceof Player) { - Player player = (Player) sender; - - if (region.isOwner(BukkitPlayer.wrapPlayer(plugin, player))) { - plugin.checkPermission(sender, "region.flag.own"); - } else if (region.isMember(BukkitPlayer.wrapPlayer(plugin, player))) { - plugin.checkPermission(sender, "region.flag.member"); - } else { - plugin.checkPermission(sender, "region.flag"); - } - } else { - plugin.checkPermission(sender, "region.flag"); - } - - Flag nfo = FlagDatabase.getFlagInfoFromName(nameStr); - - if (nfo == null) { - sender.sendMessage(ChatColor.RED + "Unknown flag specified."); - return true; - } - - if (nfo instanceof LocationFlag) { - if (!(sender instanceof Player)) { - sender.sendMessage(ChatColor.RED + "Flag not supported in console mode."); - return true; - } - Player player = (Player) sender; - LocationFlag lInfo = (LocationFlag)nfo; - - Location l = player.getLocation(); - - if (valueStr != null && valueStr.equals("set")) { - - if (region.contains(BukkitUtil.toVector(l))) { - region.getFlags().getLocationFlag(lInfo).setValue(l); - sender.sendMessage(ChatColor.YELLOW + "Region '" + id + "' updated. Flag " + nameStr + " set to current location"); - return true; - - } else { - player.sendMessage(ChatColor.RED + "You must set the " + nameStr + " location inside the region it belongs to."); - return true; - } - - } else if (valueStr == null || valueStr.equals("delete")) { - region.getFlags().getLocationFlag(lInfo).setValue((Location) null); - sender.sendMessage(ChatColor.YELLOW + "Region '" + id + "' updated. Flag " + nameStr + " removed."); - return true; - } - } - - if (!region.getFlags().getFlag(nfo).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; - } - } catch (IOException e) { - sender.sendMessage(ChatColor.RED + "Region database failed to save: " - + e.getMessage()); - } - - return true; - } -} diff --git a/src/com/sk89q/worldguard/bukkit/commands/CommandRegionInfo.java b/src/com/sk89q/worldguard/bukkit/commands/CommandRegionInfo.java deleted file mode 100644 index 8ff8363d..00000000 --- a/src/com/sk89q/worldguard/bukkit/commands/CommandRegionInfo.java +++ /dev/null @@ -1,101 +0,0 @@ -// $Id$ -/* - * WorldGuard - * Copyright (C) 2010 sk89q - * - * 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 . - */ -package com.sk89q.worldguard.bukkit.commands; - -import com.sk89q.worldguard.bukkit.BukkitPlayer; -import com.sk89q.worldguard.bukkit.GlobalConfiguration; -import com.sk89q.worldguard.bukkit.WorldConfiguration; -import com.sk89q.worldguard.bukkit.WorldGuardPlugin; -import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException; -import com.sk89q.worldguard.domains.DefaultDomain; -import com.sk89q.worldguard.protection.flags.FlagDatabase; -import com.sk89q.worldguard.protection.flags.Flag; -import com.sk89q.worldguard.protection.flags.RegionFlags; -import com.sk89q.worldguard.protection.managers.RegionManager; -import com.sk89q.worldguard.protection.regions.ProtectedRegion; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -/** - * - * @author Michael - */ -public class CommandRegionInfo extends WgRegionCommand { - - @Override - public boolean handle(CommandSender sender, String senderName, - String command, String[] args, GlobalConfiguration cfg, - WorldConfiguration wcfg, WorldGuardPlugin plugin) - throws CommandHandlingException { - - CommandHandler.checkArgs(args, 1, 1, "/region info "); - - RegionManager mgr = cfg.getWorldGuardPlugin().getGlobalRegionManager().get(wcfg.getWorldName()); - String id = args[0].toLowerCase(); - if (!mgr.hasRegion(id)) { - sender.sendMessage(ChatColor.RED + "A region with ID '" - + id + "' doesn't exist."); - return true; - } - - ProtectedRegion region = mgr.getRegion(id); - - if (sender instanceof Player) { - Player player = (Player) sender; - - if (region.isOwner(BukkitPlayer.wrapPlayer(plugin, player))) { - plugin.checkPermission(sender, "region.info.own"); - } else if (region.isMember(BukkitPlayer.wrapPlayer(plugin, player))) { - plugin.checkPermission(sender, "region.info.member"); - } else { - plugin.checkPermission(sender, "region.info"); - } - } else { - plugin.checkPermission(sender, "region.info"); - } - - RegionFlags flags = region.getFlags(); - DefaultDomain owners = region.getOwners(); - DefaultDomain members = region.getMembers(); - - sender.sendMessage(ChatColor.YELLOW + "Region: " + id - + ChatColor.GRAY + " (type: " + region.getTypeName() + ")"); - sender.sendMessage(ChatColor.BLUE + "Priority: " + region.getPriority()); - - StringBuilder s = new StringBuilder(); - - for (Flag nfo : FlagDatabase.getFlagInfoList()) { - if (s.length() > 0) { - s.append(", "); - } - - s.append(nfo.name + ": " + flags.getFlag(nfo).toString()); - } - - sender.sendMessage(ChatColor.BLUE + "Flags: " + s.toString()); - sender.sendMessage(ChatColor.BLUE + "Parent: " - + (region.getParent() == null ? "(none)" : region.getParent().getId())); - sender.sendMessage(ChatColor.LIGHT_PURPLE + "Owners: " - + owners.toUserFriendlyString()); - sender.sendMessage(ChatColor.LIGHT_PURPLE + "Members: " - + members.toUserFriendlyString()); - return true; - } -} diff --git a/src/com/sk89q/worldguard/bukkit/commands/CommandRegionList.java b/src/com/sk89q/worldguard/bukkit/commands/CommandRegionList.java deleted file mode 100644 index 9d156ee5..00000000 --- a/src/com/sk89q/worldguard/bukkit/commands/CommandRegionList.java +++ /dev/null @@ -1,85 +0,0 @@ -// $Id$ -/* - * WorldGuard - * Copyright (C) 2010 sk89q - * - * 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 . -*/ - -package com.sk89q.worldguard.bukkit.commands; - -import com.sk89q.worldguard.bukkit.GlobalConfiguration; -import com.sk89q.worldguard.bukkit.WorldConfiguration; -import com.sk89q.worldguard.bukkit.WorldGuardPlugin; -import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException; -import com.sk89q.worldguard.protection.managers.RegionManager; -import com.sk89q.worldguard.protection.regions.ProtectedRegion; -import java.util.Arrays; -import java.util.Map; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; - -/** - * - * @author Michael - */ -public class CommandRegionList extends WgRegionCommand { - - @Override - public boolean handle(CommandSender sender, String senderName, - String command, String[] args, GlobalConfiguration cfg, - WorldConfiguration wcfg, WorldGuardPlugin plugin) - throws CommandHandlingException { - - plugin.checkPermission(sender, "region.list"); - CommandHandler.checkArgs(args, 0, 1, "/region list [page]"); - - int page = 0; - - if (args.length >= 1) { - try { - page = Math.max(0, Integer.parseInt(args[0]) - 1); - } catch (NumberFormatException e) { - page = 0; - } - } - - RegionManager mgr = cfg.getWorldGuardPlugin().getGlobalRegionManager().get(wcfg.getWorldName()); - Map regions = mgr.getRegions(); - int size = regions.size(); - int pages = (int) Math.ceil(size / (float) CommandHandler.CMD_LIST_SIZE); - - String[] regionIDList = new String[size]; - int index = 0; - for (String id : regions.keySet()) { - regionIDList[index] = id; - index++; - } - Arrays.sort(regionIDList); - - sender.sendMessage(ChatColor.RED + "Regions (page " - + (page + 1) + " of " + pages + "):"); - - if (page < pages) { - for (int i = page * CommandHandler.CMD_LIST_SIZE; i < page * CommandHandler.CMD_LIST_SIZE + CommandHandler.CMD_LIST_SIZE; i++) { - if (i >= size) { - break; - } - sender.sendMessage(ChatColor.YELLOW.toString() + (i + 1) + ". " + regionIDList[i]); - } - } - - return true; - } -} diff --git a/src/com/sk89q/worldguard/bukkit/commands/CommandRegionLoad.java b/src/com/sk89q/worldguard/bukkit/commands/CommandRegionLoad.java deleted file mode 100644 index 5f764d21..00000000 --- a/src/com/sk89q/worldguard/bukkit/commands/CommandRegionLoad.java +++ /dev/null @@ -1,57 +0,0 @@ -// $Id$ -/* - * WorldGuard - * Copyright (C) 2010 sk89q - * - * 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 . -*/ - -package com.sk89q.worldguard.bukkit.commands; - -import com.sk89q.worldguard.bukkit.GlobalConfiguration; -import com.sk89q.worldguard.bukkit.WorldConfiguration; -import com.sk89q.worldguard.bukkit.WorldGuardPlugin; -import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException; -import com.sk89q.worldguard.protection.managers.RegionManager; -import java.io.IOException; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -/** - * - * @author Michael - */ -public class CommandRegionLoad extends WgRegionCommand { - - - @Override - public boolean handle(CommandSender sender, String senderName, - String command, String[] args, GlobalConfiguration cfg, - WorldConfiguration wcfg, WorldGuardPlugin plugin) - throws CommandHandlingException { - - plugin.checkPermission(sender, "region.load"); - CommandHandler.checkArgs(args, 0, 0, "/region load"); - - try { - RegionManager mgr = cfg.getWorldGuardPlugin().getGlobalRegionManager().get(wcfg.getWorldName()); - mgr.load(); - sender.sendMessage(ChatColor.YELLOW + "Region database loaded from file!"); - } catch (IOException e) { - sender.sendMessage(ChatColor.RED + "Region database failed to load: " - + e.getMessage()); - } - - return true; - } -} diff --git a/src/com/sk89q/worldguard/bukkit/commands/CommandRegionPriority.java b/src/com/sk89q/worldguard/bukkit/commands/CommandRegionPriority.java deleted file mode 100644 index 213ef06e..00000000 --- a/src/com/sk89q/worldguard/bukkit/commands/CommandRegionPriority.java +++ /dev/null @@ -1,93 +0,0 @@ -// $Id$ -/* - * WorldGuard - * Copyright (C) 2010 sk89q - * - * 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 . - */ -package com.sk89q.worldguard.bukkit.commands; - -import com.sk89q.worldguard.bukkit.BukkitPlayer; -import com.sk89q.worldguard.bukkit.GlobalConfiguration; -import com.sk89q.worldguard.bukkit.WorldConfiguration; -import com.sk89q.worldguard.bukkit.WorldGuardPlugin; -import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException; -import com.sk89q.worldguard.protection.managers.RegionManager; -import com.sk89q.worldguard.protection.regions.ProtectedRegion; -import java.io.IOException; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -/** - * - * @author Michael - */ -public class CommandRegionPriority extends WgRegionCommand { - - - @Override - public boolean handle(CommandSender sender, String senderName, - String command, String[] args, GlobalConfiguration cfg, - WorldConfiguration wcfg, WorldGuardPlugin plugin) - throws CommandHandlingException { - - CommandHandler.checkArgs(args, 1, 2, "/region priority ()"); - - try { - String id = args[0].toLowerCase(); - RegionManager mgr = cfg.getWorldGuardPlugin().getGlobalRegionManager().get(wcfg.getWorldName()); - - if (!mgr.hasRegion(id)) { - sender.sendMessage(ChatColor.RED + "A region with ID '" - + id + "' doesn't exist."); - return true; - } - - ProtectedRegion existing = mgr.getRegion(id); - - if (sender instanceof Player) { - Player player = (Player) sender; - - if (existing.isOwner(BukkitPlayer.wrapPlayer(plugin, player))) { - plugin.checkPermission(sender, "region.priority.own"); - } else { - plugin.checkPermission(sender, "region.priority"); - } - } else { - plugin.checkPermission(sender, "region.priority"); - } - - if (args.length > 1) { - try { - Integer prio = Integer.valueOf(args[1]); - existing.setPriority(prio); - mgr.save(); - sender.sendMessage(ChatColor.YELLOW + "Priority of region " + existing.getId() + " set to " + prio.toString()); - } catch (NumberFormatException e) { - sender.sendMessage(ChatColor.RED + "Not a valid number: " + args[1]); - } - } else { - sender.sendMessage(ChatColor.YELLOW + "Priority of region " + existing.getId() + " is " + existing.getPriority()); - } - - - } catch (IOException e) { - sender.sendMessage(ChatColor.RED + "Region database failed to save: " - + e.getMessage()); - } - - return true; - } -} diff --git a/src/com/sk89q/worldguard/bukkit/commands/CommandRegionRemoveMember.java b/src/com/sk89q/worldguard/bukkit/commands/CommandRegionRemoveMember.java deleted file mode 100644 index efaba8c0..00000000 --- a/src/com/sk89q/worldguard/bukkit/commands/CommandRegionRemoveMember.java +++ /dev/null @@ -1,109 +0,0 @@ -// $Id$ -/* - * WorldGuard - * Copyright (C) 2010 sk89q - * - * 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 . -*/ - -package com.sk89q.worldguard.bukkit.commands; - -import com.sk89q.worldguard.bukkit.BukkitPlayer; -import com.sk89q.worldguard.bukkit.GlobalConfiguration; -import com.sk89q.worldguard.bukkit.WorldConfiguration; -import com.sk89q.worldguard.bukkit.WorldGuardPlugin; -import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException; -import com.sk89q.worldguard.protection.managers.RegionManager; -import com.sk89q.worldguard.protection.regions.ProtectedRegion; -import com.sk89q.worldguard.util.RegionUtil; -import java.io.IOException; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -/** - * - * @author Michael - */ -public class CommandRegionRemoveMember extends WgRegionCommand { - - - @Override - public boolean handle(CommandSender sender, String senderName, - String command, String[] args, GlobalConfiguration cfg, - WorldConfiguration wcfg, WorldGuardPlugin plugin) - throws CommandHandlingException { - - boolean cmdIsOwner = command.equalsIgnoreCase("removeowner"); - String permOwn; - String permAll; - - if (cmdIsOwner) { - CommandHandler.checkArgs(args, 2, -1, "/region removeowner [player1 [group1 [players/groups...]]]"); - permOwn = "region.removeowner.own"; - permAll = "region.removeowner"; - } else { - CommandHandler.checkArgs(args, 2, -1, "/region removemember [player1 [group1 [players/groups...]]]"); - permOwn = "region.removemember.own"; - permAll = "region.removemember"; - } - - RegionManager mgr = cfg.getWorldGuardPlugin().getGlobalRegionManager().get(wcfg.getWorldName()); - - String id = args[0].toLowerCase(); - if (!mgr.hasRegion(id)) { - sender.sendMessage(ChatColor.RED + "A region with ID '" - + id + "' doesn't exist."); - return true; - } - - ProtectedRegion existing = mgr.getRegion(id); - - if (sender instanceof Player) { - Player player = (Player) sender; - - if (existing.isOwner(BukkitPlayer.wrapPlayer(plugin, player))) { - plugin.checkPermission(sender, permOwn); - } - else { - plugin.checkPermission(sender, permAll); - } - } - else - { - plugin.checkPermission(sender, permAll); - } - - - if (cmdIsOwner) { - RegionUtil.removeFromDomain(existing.getOwners(), args, 1); - } else { - RegionUtil.removeFromDomain(existing.getMembers(), args, 1); - } - - try { - mgr.save(); - sender.sendMessage(ChatColor.YELLOW + "Region updated!"); - sender.sendMessage(ChatColor.GRAY + "Current owners: " - + existing.getOwners().toUserFriendlyString()); - sender.sendMessage(ChatColor.GRAY + "Current members: " - + existing.getMembers().toUserFriendlyString()); - } catch (IOException e) { - sender.sendMessage(ChatColor.RED + "Region database failed to save: " - + e.getMessage()); - } - - return true; - } -} diff --git a/src/com/sk89q/worldguard/bukkit/commands/CommandRegionSave.java b/src/com/sk89q/worldguard/bukkit/commands/CommandRegionSave.java deleted file mode 100644 index 22644795..00000000 --- a/src/com/sk89q/worldguard/bukkit/commands/CommandRegionSave.java +++ /dev/null @@ -1,58 +0,0 @@ -// $Id$ -/* - * WorldGuard - * Copyright (C) 2010 sk89q - * - * 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 . -*/ - -package com.sk89q.worldguard.bukkit.commands; - -import com.sk89q.worldguard.bukkit.GlobalConfiguration; -import com.sk89q.worldguard.bukkit.WorldConfiguration; -import com.sk89q.worldguard.bukkit.WorldGuardPlugin; -import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException; -import com.sk89q.worldguard.protection.managers.RegionManager; -import java.io.IOException; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; - -/** - * - * @author Michael - */ -public class CommandRegionSave extends WgRegionCommand { - - - @Override - public boolean handle(CommandSender sender, String senderName, - String command, String[] args, GlobalConfiguration cfg, - WorldConfiguration wcfg, WorldGuardPlugin plugin) - throws CommandHandlingException { - - plugin.checkPermission(sender, "region.save"); - CommandHandler.checkArgs(args, 0, 0, "/region save"); - - try { - RegionManager mgr = cfg.getWorldGuardPlugin().getGlobalRegionManager().get(wcfg.getWorldName()); - mgr.save(); - sender.sendMessage(ChatColor.YELLOW + "Region database saved to file!"); - } catch (IOException e) { - sender.sendMessage(ChatColor.RED + "Region database failed to save: " - + e.getMessage()); - } - - return true; - } -} diff --git a/src/com/sk89q/worldguard/bukkit/commands/CommandRegionSetParent.java b/src/com/sk89q/worldguard/bukkit/commands/CommandRegionSetParent.java deleted file mode 100644 index 3149e484..00000000 --- a/src/com/sk89q/worldguard/bukkit/commands/CommandRegionSetParent.java +++ /dev/null @@ -1,110 +0,0 @@ -// $Id$ -/* - * WorldGuard - * Copyright (C) 2010 sk89q - * - * 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 . - */ -package com.sk89q.worldguard.bukkit.commands; - -import com.sk89q.worldguard.bukkit.BukkitPlayer; -import com.sk89q.worldguard.bukkit.GlobalConfiguration; -import com.sk89q.worldguard.bukkit.WorldConfiguration; -import com.sk89q.worldguard.bukkit.WorldGuardPlugin; -import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException; -import com.sk89q.worldguard.protection.managers.RegionManager; -import com.sk89q.worldguard.protection.regions.ProtectedRegion; -import com.sk89q.worldguard.protection.regions.ProtectedRegion.CircularInheritanceException; -import java.io.IOException; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -/** - * - * @author Michael - */ -public class CommandRegionSetParent extends WgRegionCommand { - - - @Override - public boolean handle(CommandSender sender, String senderName, - String command, String[] args, GlobalConfiguration cfg, - WorldConfiguration wcfg, WorldGuardPlugin plugin) - throws CommandHandlingException { - - CommandHandler.checkArgs(args, 1, 2, "/region setparent "); - - String id = args[0].toLowerCase(); - String parentId = args.length > 1 ? args[1].toLowerCase() : null; - RegionManager mgr = cfg.getWorldGuardPlugin().getGlobalRegionManager().get(wcfg.getWorldName()); - - ProtectedRegion region = mgr.getRegion(id); - - if (region == null) { - sender.sendMessage(ChatColor.RED + "Could not find a region with ID: " + id); - return true; - } - - if (sender instanceof Player) { - Player player = (Player) sender; - - if (region.isOwner(BukkitPlayer.wrapPlayer(plugin, player))) { - plugin.checkPermission(sender, "region.setparent.own"); - } else { - plugin.checkPermission(sender, "region.setparent"); - } - } else { - plugin.checkPermission(sender, "region.setparent"); - } - - ProtectedRegion parent = null; - - // Set a parent - if (parentId != null) { - parent = mgr.getRegion(parentId); - - if (parent == null) { - sender.sendMessage(ChatColor.RED + "Could not find a region with ID: " + parentId); - return true; - } - - if (sender instanceof Player) { - Player player = (Player) sender; - - if (parent.isOwner(BukkitPlayer.wrapPlayer(plugin, player))) { - plugin.checkPermission(sender, "region.setparent.own"); - } else { - plugin.checkPermission(sender, "region.setparent"); - } - } else { - plugin.checkPermission(sender, "region.setparent"); - } - } - - try { - region.setParent(parent); - - mgr.save(); - sender.sendMessage(ChatColor.YELLOW + "Region '" + id + "' updated."); - } catch (CircularInheritanceException e) { - sender.sendMessage(ChatColor.RED + "Circular inheritance detected. The operation failed."); - } catch (IOException e) { - sender.sendMessage(ChatColor.RED + "Region database failed to save: " - + e.getMessage()); - } - - return true; - } -} diff --git a/src/com/sk89q/worldguard/bukkit/commands/CommandReloadWG.java b/src/com/sk89q/worldguard/bukkit/commands/CommandReloadWG.java deleted file mode 100644 index c0f2a4c6..00000000 --- a/src/com/sk89q/worldguard/bukkit/commands/CommandReloadWG.java +++ /dev/null @@ -1,70 +0,0 @@ -// $Id$ -/* - * WorldGuard - * Copyright (C) 2010 sk89q - * - * 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 . - */ -package com.sk89q.worldguard.bukkit.commands; - -import com.sk89q.worldguard.bukkit.LoggerToChatHandler; -import com.sk89q.worldguard.bukkit.GlobalConfiguration; -import com.sk89q.worldguard.bukkit.WorldGuardPlugin; -import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -/** - * - * @author Michael - */ -public class CommandReloadWG extends WgCommand { - - @Override - public boolean handle(CommandSender sender, String senderName, - String command, String[] args, GlobalConfiguration cfg, WorldGuardPlugin plugin) - throws CommandHandlingException { - - plugin.checkPermission(sender, "reload"); - CommandHandler.checkArgs(args, 0, 0); - - LoggerToChatHandler handler = null; - Logger minecraftLogger = null; - if (sender instanceof Player) { - Player player = (Player) sender; - handler = new LoggerToChatHandler(player); - handler.setLevel(Level.ALL); - minecraftLogger = Logger.getLogger("Minecraft"); - minecraftLogger.addHandler(handler); - } - - try { - cfg.unload(); - cfg.load(); - - sender.sendMessage("WorldGuard configuration reloaded."); - } catch (Throwable t) { - sender.sendMessage("Error while reloading: " - + t.getMessage()); - } finally { - if (handler != null) { - minecraftLogger.removeHandler(handler); - } - } - - return true; - } -} diff --git a/src/com/sk89q/worldguard/bukkit/commands/CommandTpRegion.java b/src/com/sk89q/worldguard/bukkit/commands/CommandTpRegion.java deleted file mode 100644 index 24fa16d3..00000000 --- a/src/com/sk89q/worldguard/bukkit/commands/CommandTpRegion.java +++ /dev/null @@ -1,89 +0,0 @@ -/** - * - */ -package com.sk89q.worldguard.bukkit.commands; - -import com.sk89q.worldguard.LocalPlayer; -import com.sk89q.worldguard.bukkit.BukkitPlayer; -import com.sk89q.worldguard.bukkit.GlobalConfiguration; -import com.sk89q.worldguard.bukkit.WorldGuardPlugin; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException; -import com.sk89q.worldguard.protection.flags.DefaultFlag; -import com.sk89q.worldguard.protection.flags.RegionFlag.RegionGroup; -import com.sk89q.worldguard.protection.managers.RegionManager; -import com.sk89q.worldguard.protection.regions.ProtectedRegion; - -/** - * @author wallnuss - * - */ -public class CommandTpRegion extends WgCommand { - - @Override - public boolean handle(CommandSender sender, String senderName, - String command, String[] args, GlobalConfiguration cfg, WorldGuardPlugin plugin) - throws CommandHandlingException { - - if (!(sender instanceof Player)) { - sender.sendMessage("Only players may use this command"); - return true; - } - - Player player = (Player) sender; - plugin.checkPermission(sender, "region.teleport"); - - CommandHandler.checkArgs(args, 1, 2, "/tpregion {spawn}"); - - String id = args[0]; - Boolean spawn = false; - if (args.length == 2 && args[1].equals("spawn")) { - plugin.checkPermission(sender, "region.teleport.spawn"); - spawn = true; - } - RegionManager mgr = cfg.getWorldGuardPlugin().getGlobalRegionManager().get(player.getWorld().getName()); - ProtectedRegion region = mgr.getRegion(id); - if (region != null) { - - RegionGroup flagright; - if (spawn) { - flagright = region.getFlags().getRegionGroupFlag(DefaultFlag.SPAWN_PERM).getValue(RegionGroup.ALL); - } else { - flagright = region.getFlags().getRegionGroupFlag(DefaultFlag.TELE_PERM).getValue(RegionGroup.ALL); - } - - LocalPlayer lPlayer = BukkitPlayer.wrapPlayer(plugin, player); - if (flagright == RegionGroup.OWNER) { - if (!region.isOwner(lPlayer)) { - plugin.checkPermission(sender, "region.teleport.override"); - } - } else if (flagright == RegionGroup.MEMBER) { - if (!region.isMember(lPlayer)) { - plugin.checkPermission(sender, "region.teleport.override"); - } - } - - Location location = null; - - if (spawn) { - location = region.getFlags().getLocationFlag(DefaultFlag.SPAWN_LOC).getValue(cfg.getWorldGuardPlugin().getServer()); - } else { - location = region.getFlags().getLocationFlag(DefaultFlag.TELE_LOC).getValue(cfg.getWorldGuardPlugin().getServer()); - } - if (location != null) { - player.teleportTo(location); - return true; - } else { - player.sendMessage(ChatColor.RED + "Region: " + id + " has no teleport/spawn location assign."); - } - } else { - player.sendMessage(ChatColor.RED + "Region: " + id + " not defined"); - } - - return false; - } -} diff --git a/src/com/sk89q/worldguard/bukkit/commands/RegionCommands.java b/src/com/sk89q/worldguard/bukkit/commands/RegionCommands.java index e02c297e..8ba41256 100644 --- a/src/com/sk89q/worldguard/bukkit/commands/RegionCommands.java +++ b/src/com/sk89q/worldguard/bukkit/commands/RegionCommands.java @@ -31,14 +31,11 @@ import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.bukkit.selections.*; import com.sk89q.worldguard.LocalPlayer; -import com.sk89q.worldguard.bukkit.BukkitPlayer; import com.sk89q.worldguard.bukkit.WorldConfiguration; import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.domains.DefaultDomain; -import com.sk89q.worldguard.protection.ApplicableRegionSet; -import com.sk89q.worldguard.protection.flags.FlagDatabase; +import com.sk89q.worldguard.protection.flags.DefaultFlag; import com.sk89q.worldguard.protection.flags.Flag; -import com.sk89q.worldguard.protection.flags.RegionFlags; import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.regions.*; import com.sk89q.worldguard.util.RegionUtil; @@ -160,7 +157,7 @@ public static void claim(CommandContext args, WorldGuardPlugin plugin, throw new CommandException("This region already exists and you don't own it."); } } - +/* ApplicableRegionSet regions = mgr.getApplicableRegions(region); // Check if this region overlaps any other region @@ -175,7 +172,7 @@ public static void claim(CommandContext args, WorldGuardPlugin plugin, throw new CommandException("You may only claim regions inside " + "existing regions that you or your group own."); } - } + }*/ if (plugin.getGlobalConfiguration().getiConomy() != null && wcfg.useiConomy && wcfg.buyOnClaim) { if (iConomy.getBank().hasAccount(player.getName())) { @@ -236,10 +233,10 @@ public static void info(CommandContext args, WorldGuardPlugin plugin, player = plugin.checkPlayer(sender); localPlayer = plugin.wrapPlayer(player); world = player.getWorld(); - args.getString(0).toLowerCase(); + id = args.getString(0).toLowerCase(); } else { world = plugin.matchWorld(sender, args.getString(0)); - args.getString(1).toLowerCase(); + id = args.getString(1).toLowerCase(); } RegionManager mgr = plugin.getGlobalRegionManager().get(world.getName()); @@ -262,7 +259,6 @@ public static void info(CommandContext args, WorldGuardPlugin plugin, plugin.checkPermission(sender, "region.info"); } - RegionFlags flags = region.getFlags(); DefaultDomain owners = region.getOwners(); DefaultDomain members = region.getMembers(); @@ -272,12 +268,12 @@ public static void info(CommandContext args, WorldGuardPlugin plugin, StringBuilder s = new StringBuilder(); - for (Flag nfo : FlagDatabase.getFlagInfoList()) { + for (Flag flag : DefaultFlag.getFlags()) { if (s.length() > 0) { s.append(", "); } - s.append(nfo.name + ": " + flags.getFlag(nfo).toString()); + s.append(flag.getName() + ": " + String.valueOf(region.getFlag(flag))); } sender.sendMessage(ChatColor.BLUE + "Flags: " + s.toString()); @@ -287,6 +283,5 @@ public static void info(CommandContext args, WorldGuardPlugin plugin, + owners.toUserFriendlyString()); sender.sendMessage(ChatColor.LIGHT_PURPLE + "Members: " + members.toUserFriendlyString()); - return true; } } diff --git a/src/com/sk89q/worldguard/protection/ApplicableRegionSet.java b/src/com/sk89q/worldguard/protection/ApplicableRegionSet.java index 1808d8f9..1c7e591f 100644 --- a/src/com/sk89q/worldguard/protection/ApplicableRegionSet.java +++ b/src/com/sk89q/worldguard/protection/ApplicableRegionSet.java @@ -19,10 +19,15 @@ package com.sk89q.worldguard.protection; import com.sk89q.worldguard.protection.flags.*; +import com.sk89q.worldguard.protection.flags.StateFlag.State; import com.sk89q.worldguard.protection.regions.ProtectedRegion; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; +import java.util.Map; +import java.util.Set; import com.sk89q.worldguard.LocalPlayer; -import java.util.List; /** * Represents a setFlag of regions and their rules as applied to one point or @@ -32,9 +37,8 @@ */ public class ApplicableRegionSet { - private Iterator applicable; + private Collection applicable; private ProtectedRegion globalRegion; - private ProtectedRegion affectedRegion; /** * Construct the object. @@ -42,7 +46,7 @@ public class ApplicableRegionSet { * @param applicable * @param globalRegion */ - public ApplicableRegionSet(Iterator applicable, + public ApplicableRegionSet(Collection applicable, ProtectedRegion globalRegion) { this.applicable = applicable; this.globalRegion = globalRegion; @@ -55,25 +59,27 @@ public ApplicableRegionSet(Iterator applicable, * @return */ public boolean canBuild(LocalPlayer player) { - return isFlagAllowed(DefaultFlag.BUILD, player); + return internalGetState(DefaultFlag.BUILD, player); } - + /** - * Checks a flag. + * Checks if a player can build in an area. * * @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; - } - - return isFlagAllowed(flag, def, null); + public boolean canUse(LocalPlayer player) { + return internalGetState(DefaultFlag.USE, player); + } + + /** + * Gets the state of a state flag. This cannot be used for the build flag. + * + * @param flag + * @return + */ + public boolean allows(StateFlag flag) { + return internalGetState(flag, null); } /** @@ -85,12 +91,33 @@ public boolean allowsFlag(String flag) { * null to not check owners and members * @return */ - private boolean getState(StateFlag flag, LocalPlayer player) { + private boolean internalGetState(StateFlag flag, LocalPlayer player) { boolean found = false; boolean allowed = false; // Used for ALLOW override - if (player == null) { - allowed = def; + boolean def = false; + + // Handle defaults + if (globalRegion != null) { + State globalState = globalRegion.getFlag(flag); + + // The global region has this flag set + if (globalState != null) { + def = (globalState == State.ALLOW); + } + } else { + // There is no global region, so let's use the hard-coded default + def = flag.getDefault(); } + + // The player argument is used if and only if the flag is the build + // flag -- in which case, if there are any regions in this area, we + // default to FALSE, otherwise true if there are no defined regions. + // However, other flags are different -- if there are regions defined, + // we default to the global region value. + if (player == null) { + allowed = def; + } + int lastPriority = 0; // The algorithm is as follows: @@ -111,33 +138,40 @@ private boolean getState(StateFlag flag, LocalPlayer player) { Set needsClear = new HashSet(); Set hasCleared = new HashSet(); - while (applicable.hasNext()) { - ProtectedRegion region = applicable.next(); - - // Ignore non-build regions - if (player != null - && region.getFlags().get(AreaFlags.FLAG_PASSTHROUGH) == State.ALLOW) { - continue; - } - - // Allow DENY to override everything - if (region.getFlags().get(flag) == State.DENY) { - return false; - } - - // Forget about regions that allow it, although make sure the - // default state is now to allow - if (region.getFlags().get(flag) == State.ALLOW) { - allowed = true; - found = true; - continue; - } + Iterator it = applicable.iterator(); + + while (it.hasNext()) { + ProtectedRegion region = it.next(); // Ignore lower priority regions if (found && region.getPriority() < lastPriority) { break; } + // Ignore non-build regions + if (player != null + && region.getFlag(DefaultFlag.PASSTHROUGH) == State.ALLOW) { + continue; + } + + State v = region.getFlag(flag); + + // Allow DENY to override everything + if (v == State.DENY) { + return false; + } + + // Forget about regions that allow it, although make sure the + // default state is now to allow + if (v == State.ALLOW) { + allowed = true; + found = true; + continue; + } + + // For the build flag, the flags are conditional and are based + // on membership, so we have to check for parent-child + // relationships if (player != null) { if (hasCleared.contains(region)) { // Already cleared, so do nothing @@ -180,59 +214,62 @@ private void clearParents(Set needsClear, } /** - * Returns whether this set has any regions affected (discounting - * a global region). + * Gets the value of a flag. Do not use this for state flags. * + * @param flag + * @param + * @param * @return */ - public boolean isAnyRegionAffected() { - return applicable.size() > 0; - } + public , V> V getFlag(T flag) { + int lastPriority = 0; + boolean found = false; - /** - * Get the affected region. - * - * @return - */ - public ProtectedRegion _getAffectedRegion() { - if (affectedRegion != null) { - return affectedRegion; - } + Map needsClear = new HashMap(); + Set hasCleared = new HashSet(); - affectedRegion = null; - Iterator iter = applicable.iterator(); + Iterator it = applicable.iterator(); - while (iter.hasNext()) { - ProtectedRegion region = iter.next(); + while (it.hasNext()) { + ProtectedRegion region = it.next(); - if (affectedRegion == null - || affectedRegion.getPriority() < region.getPriority()) { - affectedRegion = region; + // Ignore lower priority regions + if (found && region.getPriority() < lastPriority) { + break; } + + if (hasCleared.contains(region)) { + // Already cleared, so do nothing + } else if (region.getFlag(flag) != null){ + clearParents(needsClear, hasCleared, region); + + needsClear.put(region, region.getFlag(flag)); + } + + found = true; + lastPriority = region.getPriority(); } - return affectedRegion; + return needsClear.values().iterator().next(); } /** - * Checks whether a player is an owner of any region in this set. + * Clear a region's parents for getFlag(). * - * @param player - * @return + * @param needsClear + * @param hasCleared + * @param region */ - public boolean _isOwner(LocalPlayer player) { - - return affectedRegion != null ? affectedRegion.isOwner(player) : false; - } + private void clearParents(Map needsClear, + Set hasCleared, ProtectedRegion region) { + ProtectedRegion parent = region.getParent(); - /** - * 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; - } + while (parent != null) { + if (needsClear.remove(parent) == null) { + hasCleared.add(parent); + } + parent = parent.getParent(); + } + } } diff --git a/src/com/sk89q/worldguard/protection/TimedFlagsTimer.java b/src/com/sk89q/worldguard/protection/TimedFlagsTimer.java index 5821d42b..e7dfcd1e 100644 --- a/src/com/sk89q/worldguard/protection/TimedFlagsTimer.java +++ b/src/com/sk89q/worldguard/protection/TimedFlagsTimer.java @@ -15,11 +15,10 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . -*/ + */ package com.sk89q.worldguard.protection; - import com.sk89q.worldguard.protection.flags.DefaultFlag; import com.sk89q.worldguard.protection.managers.RegionManager; import org.bukkit.ChatColor; @@ -33,27 +32,29 @@ import static com.sk89q.worldguard.bukkit.BukkitUtil.*; /** - * + * Timer for handling flags that require a constant timer.. + * * @author Michael */ public class TimedFlagsTimer implements Runnable { - WorldGuardPlugin wg; + private WorldGuardPlugin plugin; - Map playerData; + private Map playerData; - - public TimedFlagsTimer(WorldGuardPlugin wg) - { - this.wg = wg; - this.playerData = new HashMap (); + /** + * Construct the object. + * + * @param plugin + */ + public TimedFlagsTimer(WorldGuardPlugin plugin) { + this.plugin = plugin; + this.playerData = new HashMap(); } - private TimedFlagPlayerInfo getPlayerInfo(String name) - { + private TimedFlagPlayerInfo getPlayerInfo(String name) { TimedFlagPlayerInfo ret = playerData.get(name); - if(ret == null) - { + if (ret == null) { ret = new TimedFlagPlayerInfo(); playerData.put(name, ret); } @@ -62,34 +63,36 @@ private TimedFlagPlayerInfo getPlayerInfo(String name) } public void run() { - - //get players - Player[] players = wg.getServer().getOnlinePlayers(); +/* + // get players + Player[] players = plugin.getServer().getOnlinePlayers(); for (Player player : players) { TimedFlagPlayerInfo nfo = getPlayerInfo(player.getName()); long now = System.currentTimeMillis(); - //check healing flag - if(nfo.sheduledHealTick != null && now >= nfo.sheduledHealTick) - { + // check healing flag + if (nfo.sheduledHealTick != null && now >= nfo.sheduledHealTick) { player.setHealth(player.getHealth() + nfo.sheduledHealAmount); nfo.sheduledHealTick = null; nfo.lastHealTick = now; } - if(player.getWorld().getName() == null) { + if (player.getWorld().getName() == null) { continue; } - RegionManager mgr = wg.getGlobalRegionManager().get(player.getWorld().getName()); - ApplicableRegionSet regions = mgr.getApplicableRegions(toVector(player.getLocation())); + RegionManager mgr = plugin.getGlobalRegionManager().get( + player.getWorld().getName()); + ApplicableRegionSet regions = mgr + .getApplicableRegions(toVector(player.getLocation())); - int healDelay = regions.getIntegerFlag(DefaultFlag.HEAL_DELAY, true).getValue(-1); + Integer healDelay = regions.getFlag(DefaultFlag.HEAL_DELAY); if (healDelay > 0) { healDelay *= 1000; - int healAmount = regions.getIntegerFlag(DefaultFlag.HEAL_AMOUNT, true).getValue(1); + int healAmount = regions.getIntegerFlag( + DefaultFlag.HEAL_AMOUNT, true).getValue(1); if (now - nfo.lastHealTick > healDelay) { if (player.getHealth() < 20) { if (player.getHealth() + healAmount > 20) { @@ -104,16 +107,17 @@ public void run() { } } - - //check greeting/farewell flag + // check greeting/farewell flag String newRegionName = regions.getAffectedRegionId(); if (newRegionName != null) { - - if (nfo.lastRegion == null || !newRegionName.equals(nfo.lastRegion)) { - String newGreetMsg = regions.getStringFlag(DefaultFlag.GREET_MESSAGE, true).getValue(); - String farewellMsg = regions.getStringFlag(DefaultFlag.FAREWELL_MESSAGE, true).getValue(); + if (nfo.lastRegion == null + || !newRegionName.equals(nfo.lastRegion)) { + String newGreetMsg = regions.getStringFlag( + DefaultFlag.GREET_MESSAGE, true).getValue(); + String farewellMsg = regions.getStringFlag( + DefaultFlag.FAREWELL_MESSAGE, true).getValue(); if (nfo.lastFarewellMsg != null) { player.sendMessage(nfo.lastFarewellMsg); @@ -122,8 +126,11 @@ public void run() { if (newGreetMsg != null) { player.sendMessage(newGreetMsg); } - if (regions.getBooleanFlag(DefaultFlag.NOTIFY_GREET, false).getValue(false)) { - broadcastNotification(ChatColor.YELLOW + "Player " + player.getName() + " entered region " + newRegionName); + if (regions.getBooleanFlag(DefaultFlag.NOTIFY_GREET, false) + .getValue(false)) { + broadcastNotification(ChatColor.YELLOW + "Player " + + player.getName() + " entered region " + + newRegionName); } nfo.lastFarewellMsg = farewellMsg; nfo.lastRegion = newRegionName; @@ -134,29 +141,31 @@ public void run() { player.sendMessage(nfo.lastFarewellMsg); nfo.lastFarewellMsg = null; } - if (regions.getBooleanFlag(DefaultFlag.NOTIFY_FAREWELL, false).getValue(false)) { - broadcastNotification(ChatColor.YELLOW + "Player " + player.getName() + " left region " + nfo.lastRegion); + if (regions.getBooleanFlag(DefaultFlag.NOTIFY_FAREWELL, + false).getValue(false)) { + broadcastNotification(ChatColor.YELLOW + "Player " + + player.getName() + " left region " + + nfo.lastRegion); } nfo.lastRegion = null; } } - //check passthrough flag - LocalPlayer lplayer = BukkitPlayer.wrapPlayer(wg, player); - if(!regions.isStateFlagAllowed(DefaultFlag.PASSTHROUGH, lplayer)) - { + // check passthrough flag + LocalPlayer lplayer = BukkitPlayer.wrapPlayer(plugin, player); + if (!regions.isStateFlagAllowed(DefaultFlag.PASSTHROUGH, lplayer)) { Location newLoc = player.getLocation().clone(); newLoc.setX(newLoc.getBlockX() - 30); newLoc.setY(newLoc.getWorld().getHighestBlockYAt(newLoc) + 1); player.teleportTo(newLoc); } - - } + + }*/ } public void broadcastNotification(String msg) { - for (Player player : wg.getServer().getOnlinePlayers()) { - if (wg.hasPermission(player, "notify_onenter")) { + for (Player player : plugin.getServer().getOnlinePlayers()) { + if (plugin.hasPermission(player, "notify_onenter")) { player.sendMessage(msg); } } diff --git a/src/com/sk89q/worldguard/protection/flags/BooleanFlag.java b/src/com/sk89q/worldguard/protection/flags/BooleanFlag.java new file mode 100644 index 00000000..5f817400 --- /dev/null +++ b/src/com/sk89q/worldguard/protection/flags/BooleanFlag.java @@ -0,0 +1,35 @@ +// $Id$ +/* + * WorldGuard + * Copyright (C) 2010 sk89q + * + * 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 . + */ +package com.sk89q.worldguard.protection.flags; + +/** + * + * @author sk89q + */ +public class BooleanFlag extends Flag { + + public BooleanFlag(String name, char legacyCode) { + super(name, legacyCode); + } + + public BooleanFlag(String name) { + super(name); + } + +} diff --git a/src/com/sk89q/worldguard/protection/flags/DefaultFlag.java b/src/com/sk89q/worldguard/protection/flags/DefaultFlag.java index bc97fe10..469128ab 100644 --- a/src/com/sk89q/worldguard/protection/flags/DefaultFlag.java +++ b/src/com/sk89q/worldguard/protection/flags/DefaultFlag.java @@ -22,36 +22,47 @@ * * @author sk89q */ -public class DefaultFlag { +public final class DefaultFlag { - public static final Flag PASSTHROUGH = new StateFlag("passthrough", 'z'); - public static final Flag BUILD = new StateFlag("build", 'b'); - public static final Flag PVP = new StateFlag("pvp", 'p'); - public static final Flag MOB_DAMAGE = new StateFlag("mob-damage", 'm'); - public static final Flag CREEPER_EXPLOSION = new StateFlag("creeper-explosion", 'c'); - public static final Flag TNT = new StateFlag("tnt", 't'); - public static final Flag LIGHTER = new StateFlag("lighter", 'l'); - public static final Flag FIRE_SPREAD = new StateFlag("fire-spread", 'f'); - public static final Flag LAVA_FIRE = new StateFlag("lava-fire", 'F'); - public static final Flag CHEST_ACCESS = new StateFlag("chest-access", 'C'); - public static final Flag WATER_FLOW = new StateFlag("water-flow"); - public static final Flag LEVER_AND_BUTTON = new StateFlag("interface"); - public static final Flag PLACE_VEHICLE = new StateFlag("vehicle-place"); - public static final Flag GREET_MESSAGE = new StringFlag("greet-message"); - public static final Flag FAREWELL_MESSAGE = new StringFlag("farewell-message"); - public static final Flag NOTIFY_GREET = new StateFlag("notify-greet"); - public static final Flag NOTIFY_FAREWELL = new StateFlag("notify-farewell"); - public static final Flag DENY_SPAWN = new StringFlag("deny-spawn"); - public static final Flag HEAL_DELAY = new IntegerFlag("heal-delay"); - public static final Flag HEAL_AMOUNT = new IntegerFlag("heal-amount"); - public static final Flag TELE_LOC = new LocationFlag("teleport-loc"); - public static final Flag TELE_PERM = new RegionGroupFlag("teleport-groups"); - public static final Flag SPAWN_LOC = new LocationFlag("teleport-location"); - public static final Flag SPAWN_PERM = new RegionGroupFlag("spawn-groups"); - public static final Flag BUYABLE = new StateFlag("buyable"); - public static final Flag PRICE = new DoubleFlag("price"); + public static final StateFlag PASSTHROUGH = new StateFlag("passthrough", 'z', false); + public static final StateFlag BUILD = new StateFlag("build", 'b', true); + public static final StateFlag PVP = new StateFlag("pvp", 'p', true); + public static final StateFlag MOB_DAMAGE = new StateFlag("mob-damage", 'm', true); + public static final StateFlag CREEPER_EXPLOSION = new StateFlag("creeper-explosion", 'c', true); + public static final StateFlag TNT = new StateFlag("tnt", 't', true); + public static final StateFlag LIGHTER = new StateFlag("lighter", 'l', true); + public static final StateFlag FIRE_SPREAD = new StateFlag("fire-spread", 'f', true); + public static final StateFlag LAVA_FIRE = new StateFlag("lava-fire", 'F', true); + public static final StateFlag CHEST_ACCESS = new StateFlag("chest-access", 'C', true); + public static final StateFlag WATER_FLOW = new StateFlag("water-flow", true); + public static final StateFlag USE = new StateFlag("use", true); + public static final StateFlag PLACE_VEHICLE = new StateFlag("vehicle-place", true); + public static final StringFlag GREET_MESSAGE = new StringFlag("greet-message"); + public static final StringFlag FAREWELL_MESSAGE = new StringFlag("farewell-message"); + public static final BooleanFlag NOTIFY_GREET = new BooleanFlag("notify-greet"); + public static final BooleanFlag NOTIFY_FAREWELL = new BooleanFlag("notify-farewell"); + public static final StringFlag DENY_SPAWN = new StringFlag("deny-spawn"); + public static final IntegerFlag HEAL_DELAY = new IntegerFlag("heal-delay"); + public static final IntegerFlag HEAL_AMOUNT = new IntegerFlag("heal-amount"); + public static final LocationFlag TELE_LOC = new LocationFlag("teleport-loc"); + public static final RegionGroupFlag TELE_PERM = new RegionGroupFlag("teleport-groups"); + public static final LocationFlag SPAWN_LOC = new LocationFlag("teleport-location"); + public static final RegionGroupFlag SPAWN_PERM = new RegionGroupFlag("spawn-groups"); + public static final BooleanFlag BUYABLE = new BooleanFlag("buyable"); + public static final DoubleFlag PRICE = new DoubleFlag("price"); + + public static final Flag[] flagsList = new Flag[] { + PASSTHROUGH, BUILD, PVP, MOB_DAMAGE, CREEPER_EXPLOSION, + TNT, LIGHTER, FIRE_SPREAD, LAVA_FIRE, CHEST_ACCESS, WATER_FLOW, + USE, PLACE_VEHICLE, GREET_MESSAGE, FAREWELL_MESSAGE, NOTIFY_GREET, + NOTIFY_FAREWELL, DENY_SPAWN, HEAL_DELAY, HEAL_AMOUNT, TELE_LOC, + TELE_PERM, SPAWN_LOC, SPAWN_PERM, BUYABLE, PRICE + }; private DefaultFlag() { } + public static Flag[] getFlags() { + return flagsList; + } } diff --git a/src/com/sk89q/worldguard/protection/flags/DoubleFlag.java b/src/com/sk89q/worldguard/protection/flags/DoubleFlag.java index 50a6ccb1..9cda2407 100644 --- a/src/com/sk89q/worldguard/protection/flags/DoubleFlag.java +++ b/src/com/sk89q/worldguard/protection/flags/DoubleFlag.java @@ -20,9 +20,9 @@ /** * - * @author Michael + * @author sk89q */ -public class DoubleFlag extends Flag { +public class DoubleFlag extends Flag { public DoubleFlag(String name, char legacyCode) { super(name, legacyCode); diff --git a/src/com/sk89q/worldguard/protection/flags/Flag.java b/src/com/sk89q/worldguard/protection/flags/Flag.java index ff31ba5f..abd8a2e2 100644 --- a/src/com/sk89q/worldguard/protection/flags/Flag.java +++ b/src/com/sk89q/worldguard/protection/flags/Flag.java @@ -46,6 +46,4 @@ public char getLegacyCode() { return legacyCode; } - public abstract T getDefault(); - } diff --git a/src/com/sk89q/worldguard/protection/flags/IntegerFlag.java b/src/com/sk89q/worldguard/protection/flags/IntegerFlag.java index 1e7e7d64..c99b4661 100644 --- a/src/com/sk89q/worldguard/protection/flags/IntegerFlag.java +++ b/src/com/sk89q/worldguard/protection/flags/IntegerFlag.java @@ -20,9 +20,9 @@ /** * - * @author Michael + * @author sk89q */ -public class IntegerFlag extends Flag { +public class IntegerFlag extends Flag { public IntegerFlag(String name, char legacyCode) { super(name, legacyCode); diff --git a/src/com/sk89q/worldguard/protection/flags/LocationFlag.java b/src/com/sk89q/worldguard/protection/flags/LocationFlag.java index a6f380ff..338fa524 100644 --- a/src/com/sk89q/worldguard/protection/flags/LocationFlag.java +++ b/src/com/sk89q/worldguard/protection/flags/LocationFlag.java @@ -18,12 +18,13 @@ */ package com.sk89q.worldguard.protection.flags; +import org.bukkit.Location; /** * - * @author Michael + * @author sk89q */ -public class LocationFlag extends Flag { +public class LocationFlag extends Flag { public LocationFlag(String name, char legacyCode) { super(name, legacyCode); diff --git a/src/com/sk89q/worldguard/protection/flags/RegionGroupFlag.java b/src/com/sk89q/worldguard/protection/flags/RegionGroupFlag.java index b0b0b227..3e8711bb 100644 --- a/src/com/sk89q/worldguard/protection/flags/RegionGroupFlag.java +++ b/src/com/sk89q/worldguard/protection/flags/RegionGroupFlag.java @@ -20,9 +20,9 @@ /** * - * @author Michael + * @author sk89q */ -public class RegionGroupFlag extends Flag { +public class RegionGroupFlag extends Flag { public RegionGroupFlag(String name, char legacyCode) { super(name, legacyCode); diff --git a/src/com/sk89q/worldguard/protection/flags/StateFlag.java b/src/com/sk89q/worldguard/protection/flags/StateFlag.java index 37cb0a2a..f4aa4e7b 100644 --- a/src/com/sk89q/worldguard/protection/flags/StateFlag.java +++ b/src/com/sk89q/worldguard/protection/flags/StateFlag.java @@ -20,27 +20,29 @@ /** * - * @author Michael + * @author sk89q */ public class StateFlag extends Flag { public enum State { - NONE, ALLOW, DENY } - public StateFlag(String name, char legacyCode) { + private boolean def; + + public StateFlag(String name, char legacyCode, boolean def) { super(name, legacyCode); + this.def = def; } - public StateFlag(String name) { + public StateFlag(String name, boolean def) { super(name); + this.def = def; } - @Override - public State getDefault() { - return State.NONE; + public boolean getDefault() { + return def; } } diff --git a/src/com/sk89q/worldguard/protection/flags/StringFlag.java b/src/com/sk89q/worldguard/protection/flags/StringFlag.java index f9237234..7692c2e5 100644 --- a/src/com/sk89q/worldguard/protection/flags/StringFlag.java +++ b/src/com/sk89q/worldguard/protection/flags/StringFlag.java @@ -22,7 +22,7 @@ * * @author Michael */ -public class StringFlag extends Flag { +public class StringFlag extends Flag { public StringFlag(String name, char legacyCode) { super(name, legacyCode); diff --git a/src/com/sk89q/worldguard/protection/managers/FlatRegionManager.java b/src/com/sk89q/worldguard/protection/managers/FlatRegionManager.java index c1a86bfd..5f4e0c5d 100644 --- a/src/com/sk89q/worldguard/protection/managers/FlatRegionManager.java +++ b/src/com/sk89q/worldguard/protection/managers/FlatRegionManager.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.PriorityQueue; import java.util.TreeMap; import com.sk89q.worldedit.Vector; import com.sk89q.worldguard.LocalPlayer; @@ -138,8 +139,8 @@ public ProtectedRegion getRegion(String id) { */ @Override public ApplicableRegionSet getApplicableRegions(Vector pt) { - - List appRegions = new ArrayList(); + PriorityQueue appRegions = + new PriorityQueue(); for (ProtectedRegion region : regions.values()) { if (region.contains(pt)) { @@ -147,7 +148,7 @@ public ApplicableRegionSet getApplicableRegions(Vector pt) { } } - return new ApplicableRegionSet(appRegions); + return new ApplicableRegionSet(appRegions, regions.get("__global__")); } /** @@ -155,7 +156,7 @@ public ApplicableRegionSet getApplicableRegions(Vector pt) { * * @return */ - @Override + /*@Override public ApplicableRegionSet getApplicableRegions(ProtectedRegion checkRegion) { List appRegions = new ArrayList(); @@ -168,8 +169,8 @@ public ApplicableRegionSet getApplicableRegions(ProtectedRegion checkRegion) { intersectRegions = new ArrayList(); } - return new ApplicableRegionSet(intersectRegions); - } + return new ApplicableRegionSet(intersectRegions, regions.get("__global__")); + }*/ /** * Get a list of region IDs that contain a point. diff --git a/src/com/sk89q/worldguard/protection/managers/GlobalRegionManager.java b/src/com/sk89q/worldguard/protection/managers/GlobalRegionManager.java deleted file mode 100644 index d1204ced..00000000 --- a/src/com/sk89q/worldguard/protection/managers/GlobalRegionManager.java +++ /dev/null @@ -1,185 +0,0 @@ -// $Id$ -/* - * WorldGuard - * Copyright (C) 2010 sk89q - * - * 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 . - */ -package com.sk89q.worldguard.protection.managers; - -import com.sk89q.worldguard.protection.GlobalFlags; -import com.sk89q.worldguard.protection.databases.JSONDatabase; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.HashMap; -import java.util.logging.Logger; - -/** - * This class keeps track of region information for every world. It loads - * world region information as needed. - * - * @author sk89q - * @author Redecouverte - */ -public class GlobalRegionManager { - - private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard"); - - /** - * Path to the folder that region data is stored within. - */ - protected File dataFolder; - - /** - * Map of managers per-world. - */ - private HashMap managers; - - /** - * Stores the list of modification dates for the world files. This allows - * WorldGuard to reload files as needed. - */ - private HashMap lastModified; - - /** - * Construct the object. - */ - public GlobalRegionManager() { - managers = new HashMap(); - lastModified = new HashMap(); - } - - /** - * Unload region information. - */ - public void unload() { - managers.clear(); - lastModified.clear(); - } - - /** - * Get the path for a world's regions file. - * - * @param name - * @return - */ - protected File getPath(String name) { - return new File(dataFolder, - "name" + File.separator + "regions.json"); - } - - /** - * Unload region information for a world. - * - * @param name - */ - public void unload(String name) { - RegionManager manager = managers.get(name); - - if (manager != null) { - managers.remove(name); - lastModified.remove(name); - } - } - - /** - * Unload all region information. - */ - public void unloadAll() { - managers.clear(); - lastModified.clear(); - } - - /** - * Load region information for a world. - * - * @param name - */ - public void load(String name) { - File file = getPath(name); - - try { - // Create a manager - RegionManager manager = new FlatRegionManager( - new GlobalFlags(), new JSONDatabase(file)); - managers.put(name, manager); - manager.load(); - - // Store the last modification date so we can track changes - lastModified.put(name, file.lastModified()); - } catch (FileNotFoundException e) { - } catch (IOException e) { - logger.warning("WorldGuard: Failed to load regions from file " - + file.getAbsolutePath() + " : " + e.getMessage()); - } - } - - /** - * Reloads the region information from file when region databases - * have changed. - */ - public void reloadChanged() { - for (String name : managers.keySet()) { - - File file = getPath(name); - - Long oldDate = lastModified.get(name); - - if (oldDate == null) { - oldDate = 0L; - } - - try { - if (file.lastModified() > oldDate) { - load(name); - } - } catch (Exception e) { - } - } - } - - /** - * Get the region manager for a particular world. - * - * @param name - * @return - */ - public RegionManager get(String name) { - RegionManager manager = managers.get(name); - - if (manager == null) { - load(name); - } - - return manager; - } - - /** - * Set the global flags for a particular world. - * - * @param name - * @param globalflags - */ - public void setGlobalFlags(String name, GlobalFlags globalflags) { - if (globalflags != null) { - RegionManager ret = managers.get(name); - - if (ret != null) { - ret.setGlobalFlags(globalflags); - } - } - - } -} diff --git a/src/com/sk89q/worldguard/protection/managers/PRTreeRegionManager.java b/src/com/sk89q/worldguard/protection/managers/PRTreeRegionManager.java index b06ed65c..d8f7b3db 100644 --- a/src/com/sk89q/worldguard/protection/managers/PRTreeRegionManager.java +++ b/src/com/sk89q/worldguard/protection/managers/PRTreeRegionManager.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.PriorityQueue; import java.util.TreeMap; import org.khelekore.prtree.MBRConverter; import org.khelekore.prtree.PRTree; @@ -154,8 +155,8 @@ public void removeRegion(String id) { */ @Override public ApplicableRegionSet getApplicableRegions(Vector pt) { - - List appRegions = new ArrayList(); + PriorityQueue appRegions = + new PriorityQueue(); int x = pt.getBlockX(); int z = pt.getBlockZ(); @@ -166,10 +167,10 @@ public ApplicableRegionSet getApplicableRegions(Vector pt) { } } - return new ApplicableRegionSet(appRegions); + return new ApplicableRegionSet(appRegions, regions.get("__global__")); } - @Override + /*@Override public ApplicableRegionSet getApplicableRegions(ProtectedRegion checkRegion) { List appRegions = new ArrayList(); appRegions.addAll(regions.values()); @@ -181,8 +182,8 @@ public ApplicableRegionSet getApplicableRegions(ProtectedRegion checkRegion) { intersectRegions = new ArrayList(); } - return new ApplicableRegionSet(intersectRegions); - } + return new ApplicableRegionSet(intersectRegions, regions.get("__global__")); + }*/ /** * Get a list of region IDs that contain a point. diff --git a/src/com/sk89q/worldguard/protection/managers/RegionManager.java b/src/com/sk89q/worldguard/protection/managers/RegionManager.java index a262bf3b..5e551a05 100644 --- a/src/com/sk89q/worldguard/protection/managers/RegionManager.java +++ b/src/com/sk89q/worldguard/protection/managers/RegionManager.java @@ -125,8 +125,8 @@ public void save() throws IOException { * @param region * @return */ - public abstract ApplicableRegionSet getApplicableRegions( - ProtectedRegion region); + /*public abstract ApplicableRegionSet getApplicableRegions( + ProtectedRegion region);*/ /** * Get a list of region IDs that contain a point. diff --git a/src/com/sk89q/worldguard/protection/regions/GlobalProtectedRegion.java b/src/com/sk89q/worldguard/protection/regions/GlobalProtectedRegion.java new file mode 100644 index 00000000..b19fbabe --- /dev/null +++ b/src/com/sk89q/worldguard/protection/regions/GlobalProtectedRegion.java @@ -0,0 +1,66 @@ +// $Id$ +/* + * WorldGuard + * Copyright (C) 2010 sk89q + * + * 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 . +*/ + +package com.sk89q.worldguard.protection.regions; + +import java.util.ArrayList; +import java.util.List; +import com.sk89q.worldedit.BlockVector; +import com.sk89q.worldedit.Vector; +import com.sk89q.worldguard.protection.UnsupportedIntersectionException; + +public class GlobalProtectedRegion extends ProtectedRegion { + + public GlobalProtectedRegion(String id) { + super(id); + } + + @Override + public BlockVector getMinimumPoint() { + return new BlockVector(0, 0, 0); + } + + @Override + public BlockVector getMaximumPoint() { + return new BlockVector(0, 0, 0); + } + + @Override + public int countBlocks() { + return 0; + } + + @Override + public boolean contains(Vector pt) { + return false; + } + + @Override + public String getTypeName() { + return "global"; + } + + @Override + public List getIntersectingRegions( + List regions) + throws UnsupportedIntersectionException { + return new ArrayList(); + } + +} diff --git a/src/com/sk89q/worldguard/protection/regions/ProtectedRegion.java b/src/com/sk89q/worldguard/protection/regions/ProtectedRegion.java index ef945ba6..742e1f57 100644 --- a/src/com/sk89q/worldguard/protection/regions/ProtectedRegion.java +++ b/src/com/sk89q/worldguard/protection/regions/ProtectedRegion.java @@ -253,7 +253,7 @@ public boolean isMember(LocalPlayer player) { * @param * @param * @param flag - * @return + * @return value or null if isn't defined */ @SuppressWarnings("unchecked") public , V> V getFlag(T flag) { @@ -262,7 +262,7 @@ public , V> V getFlag(T flag) { if (obj != null) { val = (V) obj; } else { - return flag.getDefault(); + return null; } return val; } @@ -309,17 +309,17 @@ public int compareTo(ProtectedRegion other) { return 1; } } - + /** * Return the type of region as a user-friendly, lowercase name. * * @return type of region */ public abstract String getTypeName(); - - - public abstract List getIntersectingRegions(List regions) throws UnsupportedIntersectionException; + public abstract List getIntersectingRegions( + List regions) + throws UnsupportedIntersectionException; /** * Thrown when setting a curParent would create a circular inheritance diff --git a/tests/com/sk89q/worldguard/protection/ApplicableRegionSetTest.java b/tests/com/sk89q/worldguard/protection/ApplicableRegionSetTest.java index 8540a317..1ea0ba54 100644 --- a/tests/com/sk89q/worldguard/protection/ApplicableRegionSetTest.java +++ b/tests/com/sk89q/worldguard/protection/ApplicableRegionSetTest.java @@ -21,6 +21,7 @@ import com.sk89q.worldguard.protection.managers.FlatRegionManager; import com.sk89q.worldguard.protection.managers.RegionManager; +import com.sk89q.worldguard.protection.regions.GlobalProtectedRegion; import com.sk89q.worldguard.protection.regions.ProtectedRegion; import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion; import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; @@ -33,7 +34,6 @@ import com.sk89q.worldguard.TestPlayer; import com.sk89q.worldguard.domains.DefaultDomain; import java.util.ArrayList; -import java.util.List; public class ApplicableRegionSetTest { static String COURTYARD_ID = "courtyard"; @@ -47,6 +47,7 @@ public class ApplicableRegionSetTest { Vector outside = new Vector(15, 15, 15); Vector inNoFire = new Vector(150, 150, 150); RegionManager manager; + ProtectedRegion globalRegion; ProtectedRegion courtyard; ProtectedRegion fountain; TestPlayer player1; @@ -54,7 +55,9 @@ public class ApplicableRegionSetTest { @Before public void setUp() throws Exception { - manager = new FlatRegionManager(new GlobalFlags(), null); + setUpGlobalRegion(); + + manager = new FlatRegionManager(null); setUpPlayers(); setUpCourtyardRegion(); @@ -71,6 +74,10 @@ void setUpPlayers() { player2.addGroup(MEMBER_GROUP); } + void setUpGlobalRegion() { + globalRegion = new GlobalProtectedRegion("__global__"); + } + void setUpCourtyardRegion() { DefaultDomain domain = new DefaultDomain(); domain.addGroup(COURTYARD_GROUP); @@ -111,7 +118,7 @@ void setUpNoFireRegion() throws Exception { @Test public void testNonBuildFlag() { - ApplicableRegionSet appl; + /*ApplicableRegionSet appl; // Outside appl = manager.getApplicableRegions(outside); @@ -125,7 +132,7 @@ public void testNonBuildFlag() { // Inside no fire zone appl = manager.getApplicableRegions(inNoFire); - //assertFalse(appl.isStateFlagAllowed(AreaFlags.FLAG_FIRE_SPREAD)); + //assertFalse(appl.isStateFlagAllowed(AreaFlags.FLAG_FIRE_SPREAD));*/ } @Test diff --git a/tests/com/sk89q/worldguard/protection/CSVDatabaseTest.java b/tests/com/sk89q/worldguard/protection/CSVDatabaseTest.java index b580d946..5065ec29 100644 --- a/tests/com/sk89q/worldguard/protection/CSVDatabaseTest.java +++ b/tests/com/sk89q/worldguard/protection/CSVDatabaseTest.java @@ -28,7 +28,6 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; -import static org.junit.Assert.*; import com.sk89q.worldedit.BlockVector; import com.sk89q.worldguard.domains.DefaultDomain;