Added /region select.

This commit is contained in:
sk89q 2011-04-03 11:04:18 -07:00
parent 2e7f96aab0
commit 4332ed92f2

View File

@ -28,6 +28,7 @@
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.sk89q.minecraft.util.commands.*; import com.sk89q.minecraft.util.commands.*;
import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.bukkit.selections.*; import com.sk89q.worldedit.bukkit.selections.*;
import com.sk89q.worldguard.LocalPlayer; import com.sk89q.worldguard.LocalPlayer;
@ -307,6 +308,55 @@ public static void claim(CommandContext args, WorldGuardPlugin plugin,
} }
} }
@Command(aliases = {"select", "sel"},
usage = "<id>",
desc = "Load a region as a WorldEdit selection",
flags = "", min = 1, max = 1)
public static void select(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 region = mgr.getRegion(id);
if (region == null) {
throw new CommandException("Could not find a region by that ID.");
}
if (region.isOwner(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.select.own." + id.toLowerCase());
} else if (region.isMember(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.select.member." + id.toLowerCase());
} else {
plugin.checkPermission(sender, "worldguard.region.select." + id.toLowerCase());
}
if (region instanceof ProtectedCuboidRegion) {
ProtectedCuboidRegion cuboid = (ProtectedCuboidRegion) region;
Vector pt1 = cuboid.getMinimumPoint();
Vector pt2 = cuboid.getMaximumPoint();
CuboidSelection selection = new CuboidSelection(world, pt1, pt2);
worldEdit.setSelection(player, selection);
sender.sendMessage(ChatColor.YELLOW + "Region selected as a cuboid.");
} else if (region instanceof ProtectedPolygonalRegion) {
ProtectedPolygonalRegion poly2d = (ProtectedPolygonalRegion) region;
Polygonal2DSelection selection = new Polygonal2DSelection(world, poly2d.getPoints(),
poly2d.getMinimumPoint().getBlockY(), poly2d.getMaximumPoint().getBlockY());
worldEdit.setSelection(player, selection);
sender.sendMessage(ChatColor.YELLOW + "Region selected as a polygon.");
} else if (region instanceof GlobalProtectedRegion) {
throw new CommandException("Can't select global regions.");
} else {
throw new CommandException("Unknown region type: " + region.getClass().getCanonicalName());
}
}
@Command(aliases = {"info"}, @Command(aliases = {"info"},
usage = "[world] <id>", usage = "[world] <id>",
desc = "Get information about a region", desc = "Get information about a region",