diff --git a/src/com/sk89q/worldguard/bukkit/commands/RegionCommands.java b/src/com/sk89q/worldguard/bukkit/commands/RegionCommands.java index 6a26f8d2..d3856568 100644 --- a/src/com/sk89q/worldguard/bukkit/commands/RegionCommands.java +++ b/src/com/sk89q/worldguard/bukkit/commands/RegionCommands.java @@ -98,6 +98,79 @@ public static void define(CommandContext args, WorldGuardPlugin plugin, } } + @Command(aliases = {"redefine", "update", "move"}, + usage = "", + desc = "Re-defines the shape of a region", + flags = "", min = 1, max = 1) + public static void redefine(CommandContext args, WorldGuardPlugin plugin, + CommandSender sender) throws CommandException { + + Player player = plugin.checkPlayer(sender); + World world = player.getWorld(); + WorldEditPlugin worldEdit = plugin.getWorldEdit(); + LocalPlayer localPlayer = plugin.wrapPlayer(player); + String id = args.getString(0); + + RegionManager mgr = plugin.getGlobalRegionManager().get(world); + ProtectedRegion existing = mgr.getRegion(id); + + if (existing == null) { + throw new CommandException("Could not find a region by that ID."); + } + + if (existing.isOwner(localPlayer)) { + plugin.checkPermission(sender, "worldguard.region.redefine.own"); + } else if (existing.isMember(localPlayer)) { + plugin.checkPermission(sender, "worldguard.region.redefine.member"); + } else { + plugin.checkPermission(sender, "worldguard.region.redefine"); + } + + // Attempt to get the player's selection from WorldEdit + Selection sel = worldEdit.getSelection(player); + + if (sel == null) { + throw new CommandException("Select a region with WorldEdit first."); + } + + ProtectedRegion region; + + // Detect the type of region from WorldEdit + if (sel instanceof Polygonal2DSelection) { + Polygonal2DSelection polySel = (Polygonal2DSelection) sel; + int minY = polySel.getNativeMinimumPoint().getBlockY(); + int maxY = polySel.getNativeMaximumPoint().getBlockY(); + region = new ProtectedPolygonalRegion(id, polySel.getNativePoints(), minY, maxY); + } else if (sel instanceof CuboidSelection) { + BlockVector min = sel.getNativeMinimumPoint().toBlockVector(); + BlockVector max = sel.getNativeMaximumPoint().toBlockVector(); + region = new ProtectedCuboidRegion(id, min, max); + } else { + throw new CommandException( + "The type of region selected in WorldEdit is unsupported in WorldGuard!"); + } + + region.setMembers(existing.getMembers()); + region.setOwners(existing.getOwners()); + region.setFlags(existing.getFlags()); + region.setPriority(existing.getPriority()); + try { + region.setParent(existing.getParent()); + } catch (CircularInheritanceException e) { + } + + mgr.addRegion(region); + + sender.sendMessage(ChatColor.YELLOW + "Region updated with new area."); + + try { + mgr.save(); + } catch (IOException e) { + throw new CommandException("Failed to write regions file: " + + e.getMessage()); + } + } + @Command(aliases = {"claim"}, usage = " [ [ []]]", desc = "Claim a region", diff --git a/src/com/sk89q/worldguard/protection/regions/ProtectedRegion.java b/src/com/sk89q/worldguard/protection/regions/ProtectedRegion.java index 0db4c8ba..8b0a9d98 100644 --- a/src/com/sk89q/worldguard/protection/regions/ProtectedRegion.java +++ b/src/com/sk89q/worldguard/protection/regions/ProtectedRegion.java @@ -291,6 +291,15 @@ public , V> void setFlag(T flag, V val) { public Map, Object> getFlags() { return flags; } + + /** + * Get the map of flags. + * + * @param flags + */ + public void setFlags(Map, Object> flags) { + this.flags = flags; + } /** * Get the number of blocks in this region