From 0a45292587716c9ad3aa832fb2963e2cbf26adc8 Mon Sep 17 00:00:00 2001 From: Redecouverte Date: Fri, 25 Feb 2011 17:28:08 +0100 Subject: [PATCH] merged with recent commits --- nbproject/project.properties | 4 +- permissions_list.txt | 7 +- .../bukkit/WorldGuardBlockListener.java | 3 +- .../bukkit/WorldGuardConfiguration.java | 15 ++- .../worldguard/bukkit/WorldGuardPlugin.java | 19 ++-- .../bukkit/WorldGuardServerListener.java | 5 +- .../bukkit/WorldGuardWorldConfiguration.java | 7 ++ .../bukkit/commands/CommandBuyRegion.java | 15 ++- .../bukkit/commands/CommandHandler.java | 2 + .../bukkit/commands/CommandRegionClaim.java | 4 +- .../bukkit/commands/CommandRegionFlag.java | 101 +++++++++++------- .../bukkit/commands/CommandTpRegion.java | 67 ++++++------ 12 files changed, 148 insertions(+), 101 deletions(-) diff --git a/nbproject/project.properties b/nbproject/project.properties index 94056ec2..46d27552 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -28,6 +28,7 @@ endorsed.classpath= excludes= file.reference.Bukkit.jar=lib/Bukkit.jar file.reference.gson-1.7-SNAPSHOT.jar=lib\\gson-1.7-SNAPSHOT.jar +file.reference.iConomy.jar=lib\\iConomy.jar file.reference.prtree.jar=lib/prtree.jar file.reference.truezip.jar=lib/truezip.jar file.reference.WorldEdit.jar=lib/WorldEdit.jar @@ -38,7 +39,8 @@ javac.classpath=\ ${file.reference.prtree.jar}:\ ${file.reference.truezip.jar}:\ ${file.reference.WorldEdit.jar}:\ - ${file.reference.gson-1.7-SNAPSHOT.jar} + ${file.reference.gson-1.7-SNAPSHOT.jar}:\ + ${file.reference.iConomy.jar} # Space-separated list of extra javac options javac.compilerargs= javac.deprecation=false diff --git a/permissions_list.txt b/permissions_list.txt index c2a1e2c5..4385dfa7 100644 --- a/permissions_list.txt +++ b/permissions_list.txt @@ -45,4 +45,9 @@ worldguard.region.delete.all worldguard.region.define -worldguard.region.claim \ No newline at end of file +worldguard.region.claim + +worldguard.tpregion +worldguard.tpregion.spawn + +worldguard.buyregion \ No newline at end of file diff --git a/src/com/sk89q/worldguard/bukkit/WorldGuardBlockListener.java b/src/com/sk89q/worldguard/bukkit/WorldGuardBlockListener.java index acd3c92e..113a0809 100644 --- a/src/com/sk89q/worldguard/bukkit/WorldGuardBlockListener.java +++ b/src/com/sk89q/worldguard/bukkit/WorldGuardBlockListener.java @@ -34,7 +34,6 @@ import com.sk89q.worldedit.Vector; import com.sk89q.worldguard.LocalPlayer; import com.sk89q.worldguard.blacklist.events.*; -import com.sk89q.worldguard.protection.GlobalFlags; import com.sk89q.worldguard.protection.ApplicableRegionSet; import com.sk89q.worldguard.protection.regions.AreaFlags; import static com.sk89q.worldguard.bukkit.BukkitUtil.*; @@ -217,7 +216,7 @@ public void onBlockFlow(BlockFromToEvent event) { } } - if (plugin.useRegions) { + if (wcfg.useRegions) { Vector pt = toVector(blockFrom.getLocation()); RegionManager mgr = plugin.getGlobalRegionManager().getRegionManager(world.getName()); diff --git a/src/com/sk89q/worldguard/bukkit/WorldGuardConfiguration.java b/src/com/sk89q/worldguard/bukkit/WorldGuardConfiguration.java index 551ac5b5..3d3ac9f1 100644 --- a/src/com/sk89q/worldguard/bukkit/WorldGuardConfiguration.java +++ b/src/com/sk89q/worldguard/bukkit/WorldGuardConfiguration.java @@ -18,6 +18,7 @@ */ package com.sk89q.worldguard.bukkit; +import com.nijikokun.bukkit.iConomy.iConomy; import com.sk89q.bukkit.migration.PermissionsResolverManager; import com.sk89q.bukkit.migration.PermissionsResolverServerListener; import com.sk89q.worldedit.Vector; @@ -61,10 +62,12 @@ public class WorldGuardConfiguration { private boolean suppressTickSyncWarnings; private static Pattern groupPattern = Pattern.compile("^[gG]:(.+)$"); + private iConomy iConomy; public WorldGuardConfiguration(WorldGuardPlugin wg) { this.wg = wg; this.worldConfig = new HashMap(); + this.iConomy = null; } public WorldGuardWorldConfiguration getWorldConfig(String worldName) { @@ -415,5 +418,15 @@ public WorldGuardPlugin getWorldGuardPlugin() { return this.wg; } - + + + public iConomy getiConomy() + { + return this.iConomy; + } + + public void setiConomy(iConomy newVal) + { + this.iConomy = newVal; + } } diff --git a/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java b/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java index 1291e377..b16947a7 100644 --- a/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java +++ b/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java @@ -18,8 +18,8 @@ */ package com.sk89q.worldguard.bukkit; +import com.nijikokun.bukkit.iConomy.iConomy; import java.util.logging.*; -import org.bukkit.plugin.Plugin; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.event.Event.Priority; @@ -38,7 +38,7 @@ public class WorldGuardPlugin extends JavaPlugin { private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard"); - + private final WorldGuardPlayerListener playerListener = new WorldGuardPlayerListener(this); private final WorldGuardBlockListener blockListener = @@ -46,17 +46,18 @@ public class WorldGuardPlugin extends JavaPlugin { private final WorldGuardEntityListener entityListener = new WorldGuardEntityListener(this); private final WorldGuardServerListener serverListener = - new WorldGuardServerListener(this); - + new WorldGuardServerListener(this); + private final CommandHandler commandHandler = new CommandHandler(this); - private final GlobalRegionManager globalRegionManager = new GlobalRegionManager(this); + private final GlobalRegionManager globalRegionManager = new GlobalRegionManager(this); private final WorldGuardConfiguration configuration = new WorldGuardConfiguration(this); + /** * Called on plugin enable. */ public void onEnable() { - + getDataFolder().mkdirs(); globalRegionManager.onEnable(); registerEvents(); @@ -68,9 +69,9 @@ public void onEnable() { * Called on plugin disable. */ public void onDisable() { - + globalRegionManager.onDisable(); - + logger.info("WorldGuard " + this.getDescription().getVersion() + " disabled."); } @@ -103,6 +104,8 @@ private void registerEvents() { pm.registerEvent(Event.Type.PLAYER_LOGIN, playerListener, Priority.Normal, this); pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Normal, this); + pm.registerEvent(Event.Type.PLUGIN_ENABLE, serverListener, Priority.Monitor, this); + // 25 equals about 1s real time this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new TimedFlagsTimer(this), 25 * 5, 25 * 5); } diff --git a/src/com/sk89q/worldguard/bukkit/WorldGuardServerListener.java b/src/com/sk89q/worldguard/bukkit/WorldGuardServerListener.java index aa87c20c..b72ef362 100644 --- a/src/com/sk89q/worldguard/bukkit/WorldGuardServerListener.java +++ b/src/com/sk89q/worldguard/bukkit/WorldGuardServerListener.java @@ -22,9 +22,8 @@ import org.bukkit.event.server.PluginEvent; import org.bukkit.event.server.ServerListener; -import com.nijiko.iConomy.configuration.PropertyHandler; import com.nijikokun.bukkit.iConomy.iConomy; -import com.sk89q.worldguard.bukkit.WorldGuardPlugin; + /** * @@ -48,7 +47,7 @@ public WorldGuardServerListener(WorldGuardPlugin plugin) { @Override public void onPluginEnabled(PluginEvent event) { if(event.getPlugin().getDescription().getName().equals("iConomy")) { - WorldGuardPlugin.iConomy = (iConomy)event.getPlugin(); + plugin.getWgConfiguration().setiConomy((iConomy)event.getPlugin()); } } } \ No newline at end of file diff --git a/src/com/sk89q/worldguard/bukkit/WorldGuardWorldConfiguration.java b/src/com/sk89q/worldguard/bukkit/WorldGuardWorldConfiguration.java index 7838fc2f..c1b582ea 100644 --- a/src/com/sk89q/worldguard/bukkit/WorldGuardWorldConfiguration.java +++ b/src/com/sk89q/worldguard/bukkit/WorldGuardWorldConfiguration.java @@ -89,6 +89,9 @@ public class WorldGuardWorldConfiguration { public boolean useRegions; public int regionWand = 287; public String blockCreatureSpawn; + public boolean useiConomy; + public boolean buyOnClaim; + public int buyOnClaimPrice; /* Configuration data end */ @@ -198,6 +201,10 @@ private void loadConfiguration() { useRegions = config.getBoolean("regions.enable", true); regionWand = config.getInt("regions.wand", 287); + useiConomy = config.getBoolean("iconomy.enable", false); + buyOnClaim = config.getBoolean("iconomy.buy-on-claim", false); + buyOnClaimPrice = config.getInt("iconomy.buy-on-claim-price", 1); + for (String creature : config.getStringList("mobs.block-creature-spawn", null)) { blockCreatureSpawn += creature.toLowerCase() + " "; } diff --git a/src/com/sk89q/worldguard/bukkit/commands/CommandBuyRegion.java b/src/com/sk89q/worldguard/bukkit/commands/CommandBuyRegion.java index 89bb3606..ff38f83d 100644 --- a/src/com/sk89q/worldguard/bukkit/commands/CommandBuyRegion.java +++ b/src/com/sk89q/worldguard/bukkit/commands/CommandBuyRegion.java @@ -24,7 +24,7 @@ import com.nijikokun.bukkit.iConomy.Account; import com.nijikokun.bukkit.iConomy.iConomy; -import com.sk89q.worldguard.bukkit.WorldGuardPlugin; +import com.sk89q.worldguard.bukkit.WorldGuardConfiguration; import com.sk89q.worldguard.domains.DefaultDomain; import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException; import com.sk89q.worldguard.protection.regionmanager.RegionManager; @@ -37,19 +37,24 @@ */ public class CommandBuyRegion extends WgCommand { - public boolean handle(CommandSender sender, String senderName, String command, String[] args, CommandHandler ch, WorldGuardPlugin wg) throws CommandHandlingException { + public boolean handle(CommandSender sender, String senderName, String command, String[] args, WorldGuardConfiguration cfg) throws CommandHandlingException { if (!(sender instanceof Player)) { sender.sendMessage("Only players may use this command"); return true; } - if (wg.iConomy == null) { + Player player = (Player) sender; + + if (cfg.getiConomy() == null) { sender.sendMessage("iConomy is not installed on this Server."); return true; } + + cfg.checkRegionPermission(player, "buyregion"); + String id = args[0]; - Player player = (Player) sender; - RegionManager mgr = wg.getGlobalRegionManager().getRegionManager(player.getWorld().getName()); + + RegionManager mgr = cfg.getWorldGuardPlugin().getGlobalRegionManager().getRegionManager(player.getWorld().getName()); ProtectedRegion region = mgr.getRegion(id); if (region != null) { AreaFlags flags = region.getFlags(); diff --git a/src/com/sk89q/worldguard/bukkit/commands/CommandHandler.java b/src/com/sk89q/worldguard/bukkit/commands/CommandHandler.java index eec6318b..03acdf1d 100644 --- a/src/com/sk89q/worldguard/bukkit/commands/CommandHandler.java +++ b/src/com/sk89q/worldguard/bukkit/commands/CommandHandler.java @@ -56,6 +56,8 @@ public CommandHandler(WorldGuardPlugin wg) // commands that DO NOT support console as sender this.commandMap.put("stack", new CommandStack()); this.commandMap.put("locate", new CommandLocate()); + this.commandMap.put("tpregrion", new CommandTpRegion()); + this.commandMap.put("buyregion", new CommandBuyRegion()); } diff --git a/src/com/sk89q/worldguard/bukkit/commands/CommandRegionClaim.java b/src/com/sk89q/worldguard/bukkit/commands/CommandRegionClaim.java index 5503c535..1546a460 100644 --- a/src/com/sk89q/worldguard/bukkit/commands/CommandRegionClaim.java +++ b/src/com/sk89q/worldguard/bukkit/commands/CommandRegionClaim.java @@ -106,11 +106,11 @@ public boolean handle(CommandSender sender, String senderName, String command, S region.getOwners().addPlayer(player.getName()); - if (wg.iConomy != null && wg.useiConomy && wg.buyOnClaim) { + if (cfg.getiConomy() != null && wcfg.useiConomy && wcfg.buyOnClaim) { if (iConomy.getBank().hasAccount(player.getName())) { Account account = iConomy.getBank().getAccount(player.getName()); double balance = account.getBalance(); - int regionCosts = region.countBlocks() * wg.buyOnClaimPrice; + int regionCosts = region.countBlocks() * wcfg.buyOnClaimPrice; if (balance >= regionCosts) { account.subtract(regionCosts); player.sendMessage(ChatColor.YELLOW + "You have bought that region for " + diff --git a/src/com/sk89q/worldguard/bukkit/commands/CommandRegionFlag.java b/src/com/sk89q/worldguard/bukkit/commands/CommandRegionFlag.java index 113a5e5c..8e65a5a3 100644 --- a/src/com/sk89q/worldguard/bukkit/commands/CommandRegionFlag.java +++ b/src/com/sk89q/worldguard/bukkit/commands/CommandRegionFlag.java @@ -18,9 +18,8 @@ */ package com.sk89q.worldguard.bukkit.commands; -import com.sk89q.worldguard.bukkit.WorldGuardPlugin; - import com.sk89q.worldguard.bukkit.BukkitPlayer; +import com.sk89q.worldguard.bukkit.BukkitUtil; import com.sk89q.worldguard.bukkit.WorldGuardConfiguration; import com.sk89q.worldguard.bukkit.WorldGuardWorldConfiguration; import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException; @@ -64,63 +63,83 @@ public boolean handle(CommandSender sender, String senderName, String command, S return true; } - if (sender instanceof Player) { - Player player = (Player) sender; + if (sender instanceof Player) { + Player player = (Player) sender; - if (region.isOwner(BukkitPlayer.wrapPlayer(cfg, player))) { - cfg.checkRegionPermission(sender, "region.flag.ownregions"); - } - else if(region.isMember(BukkitPlayer.wrapPlayer(cfg, player))) { - cfg.checkRegionPermission(sender, "region.flag.memberregions"); - } - else { + if (region.isOwner(BukkitPlayer.wrapPlayer(cfg, player))) { + cfg.checkRegionPermission(sender, "region.flag.ownregions"); + } else if (region.isMember(BukkitPlayer.wrapPlayer(cfg, player))) { + cfg.checkRegionPermission(sender, "region.flag.memberregions"); + } else { + cfg.checkRegionPermission(sender, "region.flag.foreignregions"); + } + } else { cfg.checkRegionPermission(sender, "region.flag.foreignregions"); } - } - else - { - cfg.checkRegionPermission(sender, "region.flag.foreignregions"); - } FlagInfo nfo = FlagInfo.getFlagInfo(nameStr, subnameStr); if (nfo == null) { - if(!(sender instanceof Player)) - { + if (!(sender instanceof Player)) { sender.sendMessage(ChatColor.RED + "Unknown flag, or not supported in console mode."); return true; } - Player player = (Player)sender; + Player player = (Player) sender; - if(nameStr.equals("spawn")) - { + if (nameStr.equals("spawn")) { if (valueStr.equals("set")) { - sender.sendMessage(ChatColor.YELLOW + "Region '" + id + "' updated. Flag spawn set to current location"); - AreaFlags flags = region.getFlags(); Location l = player.getLocation(); - - flags.setFlag("spawn", "x", l.getX()); - flags.setFlag("spawn", "y", l.getY()); - flags.setFlag("spawn", "z", l.getZ()); - flags.setFlag("spawn", "yaw", l.getYaw()); - flags.setFlag("spawn", "pitch", l.getPitch()); - flags.setFlag("spawn", "world", l.getWorld().getName()); - } else { + if (region.contains(BukkitUtil.toVector(l))) { + AreaFlags flags = region.getFlags(); + flags.setFlag("spawn", "x", l.getX()); + flags.setFlag("spawn", "y", l.getY()); + flags.setFlag("spawn", "z", l.getZ()); + flags.setFlag("spawn", "yaw", l.getYaw()); + flags.setFlag("spawn", "pitch", l.getPitch()); + flags.setFlag("spawn", "world", l.getWorld().getName()); + sender.sendMessage(ChatColor.YELLOW + "Region '" + id + "' updated. Flag spawn set to current location"); + + } else { + player.sendMessage(ChatColor.RED + "You must set the teleport location inside the region it belongs to."); + } + } else if (valueStr.equals("delete")) { AreaFlags flags = region.getFlags(); - flags.setFlag("spawn", "x", (String)null); - flags.setFlag("spawn", "y", (String)null); - flags.setFlag("spawn", "z", (String)null); - flags.setFlag("spawn", "yaw", (String)null); - flags.setFlag("spawn", "pitch", (String)null); - flags.setFlag("spawn", "world", (String)null); + flags.setFlag("spawn", "x", (String) null); + flags.setFlag("spawn", "y", (String) null); + flags.setFlag("spawn", "z", (String) null); + flags.setFlag("spawn", "yaw", (String) null); + flags.setFlag("spawn", "pitch", (String) null); + flags.setFlag("spawn", "world", (String) null); sender.sendMessage(ChatColor.YELLOW + "Region '" + id + "' updated. Flag spawn removed."); - }else{ + } else { player.sendMessage(ChatColor.RED + "Usage: /region flag spawn "); } - }else if(nameStr.equals("teleport")) - { - sender.sendMessage(ChatColor.RED + "Unknown flag specified."); + } else if (nameStr.equals("teleport")) { + if (valueStr.equals("set")) { + Location l = player.getLocation(); + if (region.contains(BukkitUtil.toVector(l))) { + AreaFlags flags = region.getFlags(); + flags.setFlag("teleport", "x", l.getX()); + flags.setFlag("teleport", "y", l.getY()); + flags.setFlag("teleport", "z", l.getZ()); + flags.setFlag("teleport", "world", l.getWorld().getName()); + player.sendMessage(ChatColor.YELLOW + "Region '" + id + "' updated. Flag teleport set to current location"); + } else { + player.sendMessage(ChatColor.RED + "You must set the teleport location inside the region it belongs to."); + } + } else if (valueStr.equals("delete")) { + AreaFlags flags = region.getFlags(); + flags.setFlag("teleport", "x", (String) null); + flags.setFlag("teleport", "y", (String) null); + flags.setFlag("teleport", "z", (String) null); + flags.setFlag("teleport", "world", (String) null); + player.sendMessage(ChatColor.YELLOW + "Region '" + id + "' updated. Flag teleport removed."); + } else { + player.sendMessage(ChatColor.RED + "Usage: /region flag teleport "); + } + } else { + player.sendMessage(ChatColor.RED + "Unknown flag specified."); } return true; } diff --git a/src/com/sk89q/worldguard/bukkit/commands/CommandTpRegion.java b/src/com/sk89q/worldguard/bukkit/commands/CommandTpRegion.java index 93c29d10..9c6c15b7 100644 --- a/src/com/sk89q/worldguard/bukkit/commands/CommandTpRegion.java +++ b/src/com/sk89q/worldguard/bukkit/commands/CommandTpRegion.java @@ -3,13 +3,13 @@ */ package com.sk89q.worldguard.bukkit.commands; +import com.sk89q.worldguard.bukkit.WorldGuardConfiguration; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException; import com.sk89q.worldguard.protection.regionmanager.RegionManager; import com.sk89q.worldguard.protection.regions.AreaFlags; @@ -21,58 +21,51 @@ */ public class CommandTpRegion extends WgCommand { - /** - * @see com.sk89q.worldguard.bukkit.commands.WgCommand#handle(org.bukkit.command.CommandSender, java.lang.String, java.lang.String, java.lang.String[], com.sk89q.worldguard.bukkit.commands.CommandHandler, com.sk89q.worldguard.bukkit.WorldGuardPlugin) - */ - @Override - public boolean handle(CommandSender sender, String senderName, - String command, String[] args, CommandHandler ch, - WorldGuardPlugin wg) throws CommandHandlingException { + public boolean handle(CommandSender sender, String senderName, String command, String[] args, WorldGuardConfiguration cfg) throws CommandHandlingException { if (!(sender instanceof Player)) { sender.sendMessage("Only players may use this command"); return true; } - + Player player = (Player) sender; - ch.checkPermission(sender, "/tpregion"); - //ch.checkArgs(args, 1, 1, "/tpregion "); - ch.checkArgs(args, 1, 2, "/tpregion {spawn}"); - + cfg.checkPermission(sender, "tpregion"); + + CommandHandler.checkArgs(args, 1, 2, "/tpregion {spawn}"); + String id = args[0]; - Boolean spawn = false; - if(args.length==2 && args[1].equals("spawn")){ - ch.checkPermission(player, "/tpregion.spawn"); + Boolean spawn = false; + if (args.length == 2 && args[1].equals("spawn")) { + cfg.checkPermission(player, "tpregion.spawn"); spawn = true; - } - RegionManager mgr = wg.getGlobalRegionManager().getRegionManager(player.getWorld().getName()); + } + RegionManager mgr = cfg.getWorldGuardPlugin().getGlobalRegionManager().getRegionManager(player.getWorld().getName()); ProtectedRegion region = mgr.getRegion(id); - if(region !=null){ + if (region != null) { AreaFlags flags = region.getFlags(); - Double x,y,z; + Double x, y, z; World world; - if(spawn){ - x =flags.getDoubleFlag("spawn", "x"); - y =flags.getDoubleFlag("spawn", "y"); - z =flags.getDoubleFlag("spawn", "z"); - world=wg.getServer().getWorld(flags.getFlag("teleport", "world")); - }else{ - x =flags.getDoubleFlag("teleport", "x"); - y =flags.getDoubleFlag("teleport", "y"); - z =flags.getDoubleFlag("teleport", "z"); - world=wg.getServer().getWorld(flags.getFlag("teleport", "world")); + if (spawn) { + x = flags.getDoubleFlag("spawn", "x"); + y = flags.getDoubleFlag("spawn", "y"); + z = flags.getDoubleFlag("spawn", "z"); + world = cfg.getWorldGuardPlugin().getServer().getWorld(flags.getFlag("teleport", "world")); + } else { + x = flags.getDoubleFlag("teleport", "x"); + y = flags.getDoubleFlag("teleport", "y"); + z = flags.getDoubleFlag("teleport", "z"); + world = cfg.getWorldGuardPlugin().getServer().getWorld(flags.getFlag("teleport", "world")); } - if(x != null && y !=null && z != null &&world !=null){ + if (x != null && y != null && z != null && world != null) { Location location = new Location(world, x, y, z); 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 + " has no teleport/spawn location assign."); } - }else{ - player.sendMessage(ChatColor.RED + "Region: "+id+" not defined"); + } else { + player.sendMessage(ChatColor.RED + "Region: " + id + " not defined"); } - + return false; } - }