add region.contains(location) for /region flag <id> spawn set

This commit is contained in:
Valentin Churavy 2011-02-24 22:29:49 +01:00
parent 99b37147d3
commit ba4907e67b
2 changed files with 29 additions and 15 deletions

View File

@ -75,12 +75,16 @@ public boolean handle(CommandSender sender, String senderName, String command, S
player.sendMessage(ChatColor.YELLOW + "Region '" + id + "' updated. Flag spawn set to current location"); player.sendMessage(ChatColor.YELLOW + "Region '" + id + "' updated. Flag spawn set to current location");
AreaFlags flags = region.getFlags(); AreaFlags flags = region.getFlags();
Location l = player.getLocation(); Location l = player.getLocation();
flags.setFlag("spawn", "x", l.getX()); if(region.contains(BukkitUtil.toVector(l))){
flags.setFlag("spawn", "y", l.getY()); flags.setFlag("spawn", "x", l.getX());
flags.setFlag("spawn", "z", l.getZ()); flags.setFlag("spawn", "y", l.getY());
flags.setFlag("spawn", "yaw", l.getYaw()); flags.setFlag("spawn", "z", l.getZ());
flags.setFlag("spawn", "pitch", l.getPitch()); flags.setFlag("spawn", "yaw", l.getYaw());
flags.setFlag("spawn", "world", l.getWorld().getName()); flags.setFlag("spawn", "pitch", l.getPitch());
flags.setFlag("spawn", "world", l.getWorld().getName());
}else{
player.sendMessage(ChatColor.RED + "You must set the spawn location inside the region it belongs to.");
}
} else { } else {
AreaFlags flags = region.getFlags(); AreaFlags flags = region.getFlags();
flags.setFlag("spawn", "x", (String)null); flags.setFlag("spawn", "x", (String)null);
@ -103,7 +107,7 @@ public boolean handle(CommandSender sender, String senderName, String command, S
flags.setFlag("teleport", "z", l.getZ()); flags.setFlag("teleport", "z", l.getZ());
flags.setFlag("teleport", "world", l.getWorld().getName()); flags.setFlag("teleport", "world", l.getWorld().getName());
}else{ }else{
player.sendMessage(ChatColor.RED + "You cannot set a teleport location for a region outside of the region"); player.sendMessage(ChatColor.RED + "You must set the teleport location inside the region it belongs to.");
} }
}else if (valueStr.equals("delete")){ }else if (valueStr.equals("delete")){
AreaFlags flags = region.getFlags(); AreaFlags flags = region.getFlags();

View File

@ -35,20 +35,30 @@ public boolean handle(CommandSender sender, String senderName,
Player player = (Player) sender; Player player = (Player) sender;
ch.checkPermission(sender, "/tpregion"); ch.checkPermission(sender, "/tpregion");
ch.checkArgs(args, 1, 1, "/tpregion <region name>"); ch.checkArgs(args, 1, 1, "/tpregion <region name> ");
//ch.checkArgs(args, 1, 2, "/tpregion <region name> {spawn}");
String id = args[0]; String id = args[0];
/* Boolean spawn = false;
if(args.length==2 && args[1].equals("spawn")){
ch.checkPermission(player, "spawn");
spawn = true;
} */
RegionManager mgr = wg.getGlobalRegionManager().getRegionManager(player.getWorld().getName()); RegionManager mgr = wg.getGlobalRegionManager().getRegionManager(player.getWorld().getName());
ProtectedRegion region = mgr.getRegion(id); ProtectedRegion region = mgr.getRegion(id);
if(region !=null){ if(region !=null){
AreaFlags flags = region.getFlags(); AreaFlags flags = region.getFlags();
/* if(spawn){
Double x =flags.getDoubleFlag("teleport", "x"); Double x =flags.getDoubleFlag("spawn", "x");
Double y =flags.getDoubleFlag("teleport", "y"); Double y =flags.getDoubleFlag("spawn", "y");
Double z =flags.getDoubleFlag("teleport", "z"); Double z =flags.getDoubleFlag("spawn", "z");
World world=wg.getServer().getWorld(flags.getFlag("teleport", "world")); World world=wg.getServer().getWorld(flags.getFlag("teleport", "world"));
}else{ */
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){ if(x != null && y !=null && z != null &&world !=null){
Location location = new Location(world, x, y, z); Location location = new Location(world, x, y, z);
player.teleportTo(location); player.teleportTo(location);