From f4f4a47a7fc503c9b00c9c296011eacf8e660da8 Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Sun, 11 Mar 2012 19:05:24 +0100 Subject: [PATCH] Made /region info show the region you're in if you don't specify an id explicitly. --- .../bukkit/commands/RegionCommands.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/sk89q/worldguard/bukkit/commands/RegionCommands.java b/src/main/java/com/sk89q/worldguard/bukkit/commands/RegionCommands.java index 2492c84d..aaaa6c15 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/commands/RegionCommands.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/commands/RegionCommands.java @@ -337,24 +337,37 @@ public void claim(CommandContext args, CommandSender sender) throws CommandExcep } } - @Command(aliases = {"select", "sel", "s"}, usage = "", - desc = "Load a region as a WorldEdit selection", min = 1, max = 1) + @Command(aliases = {"select", "sel", "s"}, usage = "[id]", + desc = "Load a region as a WorldEdit selection", min = 0, max = 1) public void select(CommandContext args, 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); + + final String id; + if (args.argsLength() == 0) { + final Vector pt = localPlayer.getPosition(); + final ApplicableRegionSet set = mgr.getApplicableRegions(pt); + if (set.size() == 0) { + throw new CommandException("No region ID specified and no region found at current location!"); + } + + id = set.iterator().next().getId(); + } + else { + id = args.getString(0); + } + 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)) {