From 99b37147d39ea7879e4d39d99186a9294f830f9a Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Thu, 24 Feb 2011 22:17:55 +0100 Subject: [PATCH] added /tpregion and /region flag teleport --- plugin.yml | 7 +- .../bukkit/commands/CommandHandler.java | 1 + .../bukkit/commands/CommandRegionFlag.java | 25 +++---- .../bukkit/commands/CommandTpRegion.java | 66 +++++++++++++++++++ 4 files changed, 86 insertions(+), 13 deletions(-) create mode 100644 src/com/sk89q/worldguard/bukkit/commands/CommandTpRegion.java diff --git a/plugin.yml b/plugin.yml index d01d738d..79d3f64a 100644 --- a/plugin.yml +++ b/plugin.yml @@ -30,4 +30,9 @@ commands: usage: / reloadwg: description: Reload WorldGuard's configuration - usage: / \ No newline at end of file + usage: / + tpregion: + description: Ports you to the region + usage: / ... + aliases: tpr + \ No newline at end of file diff --git a/src/com/sk89q/worldguard/bukkit/commands/CommandHandler.java b/src/com/sk89q/worldguard/bukkit/commands/CommandHandler.java index 2008efe9..58447792 100644 --- a/src/com/sk89q/worldguard/bukkit/commands/CommandHandler.java +++ b/src/com/sk89q/worldguard/bukkit/commands/CommandHandler.java @@ -57,6 +57,7 @@ public CommandHandler(WorldGuardPlugin wg) this.commandMap.put("slay", new CommandSlay()); this.commandMap.put("stack", new CommandStack()); this.commandMap.put("stopfire", new CommandStopFire()); + this.commandMap.put("tpregrion", new CommandTpRegion()); } diff --git a/src/com/sk89q/worldguard/bukkit/commands/CommandRegionFlag.java b/src/com/sk89q/worldguard/bukkit/commands/CommandRegionFlag.java index 3ff97d29..c876425d 100644 --- a/src/com/sk89q/worldguard/bukkit/commands/CommandRegionFlag.java +++ b/src/com/sk89q/worldguard/bukkit/commands/CommandRegionFlag.java @@ -18,6 +18,7 @@ */ package com.sk89q.worldguard.bukkit.commands; +import com.sk89q.worldguard.bukkit.BukkitUtil; import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException; import com.sk89q.worldguard.protection.regionmanager.RegionManager; @@ -96,20 +97,20 @@ public boolean handle(CommandSender sender, String senderName, String command, S player.sendMessage(ChatColor.YELLOW + "Region '" + id + "' updated. Flag teleport set to current location"); AreaFlags flags = region.getFlags(); Location l = player.getLocation(); - flags.setFlag("teleport", "x", l.getX()); - flags.setFlag("teleport", "y", l.getY()); - flags.setFlag("teleport", "z", l.getZ()); - flags.setFlag("teleport", "yaw", l.getYaw()); - flags.setFlag("teleport", "pitch", l.getPitch()); - flags.setFlag("teleport", "world", l.getWorld().getName()); + if(region.contains(BukkitUtil.toVector(l))){ + 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()); + }else{ + player.sendMessage(ChatColor.RED + "You cannot set a teleport location for a region outside of the region"); + } }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("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 "); diff --git a/src/com/sk89q/worldguard/bukkit/commands/CommandTpRegion.java b/src/com/sk89q/worldguard/bukkit/commands/CommandTpRegion.java new file mode 100644 index 00000000..044614de --- /dev/null +++ b/src/com/sk89q/worldguard/bukkit/commands/CommandTpRegion.java @@ -0,0 +1,66 @@ +/** + * + */ +package com.sk89q.worldguard.bukkit.commands; + +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; +import com.sk89q.worldguard.protection.regions.ProtectedRegion; + +/** + * @author wallnuss + * + */ +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 { + 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 "); + + String id = args[0]; + + RegionManager mgr = wg.getGlobalRegionManager().getRegionManager(player.getWorld().getName()); + ProtectedRegion region = mgr.getRegion(id); + if(region !=null){ + AreaFlags flags = region.getFlags(); + + Double x =flags.getDoubleFlag("teleport", "x"); + Double y =flags.getDoubleFlag("teleport", "y"); + Double z =flags.getDoubleFlag("teleport", "z"); + World world=wg.getServer().getWorld(flags.getFlag("teleport", "world")); + + 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 location assign."); + } + }else{ + player.sendMessage(ChatColor.RED + "Region: "+id+" not defined"); + } + + return false; + } + +}