Added the ability to clear parents with /region setparent.

This commit is contained in:
sk89q 2011-04-02 18:01:59 -07:00
parent beb10e22f2
commit e45ecf9c86

View File

@ -609,9 +609,9 @@ public static void setPriority(CommandContext args, WorldGuardPlugin plugin,
}
@Command(aliases = {"setparent"},
usage = "<id> <parent-id>",
usage = "<id> [parent-id]",
desc = "Set the parent of a region",
flags = "", min = 2, max = 2)
flags = "", min = 2, max = 1)
public static void setParent(CommandContext args, WorldGuardPlugin plugin,
CommandSender sender) throws CommandException {
Player player = plugin.checkPlayer(sender);
@ -619,7 +619,6 @@ public static void setParent(CommandContext args, WorldGuardPlugin plugin,
LocalPlayer localPlayer = plugin.wrapPlayer(player);
String id = args.getString(0);
String parentId = args.getString(1);
if (id.equalsIgnoreCase("__global__")) {
throw new CommandException("The region cannot be named __global__");
@ -627,42 +626,51 @@ public static void setParent(CommandContext args, WorldGuardPlugin plugin,
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
ProtectedRegion region = mgr.getRegion(id);
ProtectedRegion parent = mgr.getRegion(parentId);
if (region == null) {
throw new CommandException("Could not find a target region by that ID.");
}
if (parent == null) {
throw new CommandException("Could not find the parent region by that ID.");
}
if (region.isOwner(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.setparent.own." + id.toLowerCase());
} else if (region.isMember(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.setparent.member." + id.toLowerCase());
if (args.argsLength() == 1) {
region.setParent(null);
sender.sendMessage(ChatColor.YELLOW
+ "Parent of '" + region.getId() + "' cleared.");
} else {
plugin.checkPermission(sender, "worldguard.region.setparent." + id.toLowerCase());
}
if (parent.isOwner(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.setparent.own." + id.toLowerCase());
} else if (parent.isMember(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.setparent.member." + id.toLowerCase());
} else {
plugin.checkPermission(sender, "worldguard.region.setparent." + id.toLowerCase());
String parentId = args.getString(1);
ProtectedRegion parent = mgr.getRegion(parentId);
if (region == null) {
throw new CommandException("Could not find a target region by that ID.");
}
if (parent == null) {
throw new CommandException("Could not find the parent region by that ID.");
}
if (region.isOwner(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.setparent.own." + id.toLowerCase());
} else if (region.isMember(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.setparent.member." + id.toLowerCase());
} else {
plugin.checkPermission(sender, "worldguard.region.setparent." + id.toLowerCase());
}
if (parent.isOwner(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.setparent.own." + id.toLowerCase());
} else if (parent.isMember(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.setparent.member." + id.toLowerCase());
} else {
plugin.checkPermission(sender, "worldguard.region.setparent." + id.toLowerCase());
}
try {
region.setParent(parent);
} catch (CircularInheritanceException e) {
throw new CommandException("Circular inheritance detected!");
}
sender.sendMessage(ChatColor.YELLOW
+ "Parent of '" + region.getId() + "' set to '"
+ parent.getId() + "'.");
}
try {
region.setParent(parent);
} catch (CircularInheritanceException e) {
throw new CommandException("Circular inheritance detected!");
}
sender.sendMessage(ChatColor.YELLOW
+ "Parent of '" + region.getId() + "' set to '"
+ parent.getId() + "'.");
try {
mgr.save();
} catch (IOException e) {