From 2cbc2f5226829be81405d1138d345069d6f87a2e Mon Sep 17 00:00:00 2001 From: Wojciech Stryjewski Date: Wed, 24 Oct 2012 02:31:28 -0500 Subject: [PATCH] Allow removing of -g group flags with /region flag The @Command parser requires that a value follow the -g option when used in /refion flag. Therefore, it's not possible to remove the -g flag by omitting it's value, as it is possible with the regular flags. Rather, if the group flag is set to what would be the default region group for the normal flag, then the group flag is actually removed and the user sees a "Region group flagfor '...' reset to default." message. --- .../bukkit/commands/RegionCommands.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 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 22f00017..a3769c99 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/commands/RegionCommands.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/commands/RegionCommands.java @@ -765,19 +765,28 @@ public void flag(CommandContext args, CommandSender sender) throws CommandExcept if (args.hasFlag('g')) { String group = args.getFlag('g'); - if (foundFlag.getRegionGroupFlag() == null) { + RegionGroupFlag groupFlag = foundFlag.getRegionGroupFlag(); + if (groupFlag == null) { throw new CommandException("Region flag '" + foundFlag.getName() + "' does not have a group flag!"); } try { - setFlag(region, foundFlag.getRegionGroupFlag(), sender, group); + // If group set to default value then clear the group flag + RegionGroup groupValue = groupFlag.parseInput(plugin, sender, group); + if (groupValue == groupFlag.getDefault()) { + region.setFlag(groupFlag, null); + sender.sendMessage(ChatColor.YELLOW + + "Region group flag for '" + foundFlag.getName() + "' reset to default."); + } else { + region.setFlag(groupFlag, groupValue); + sender.sendMessage(ChatColor.YELLOW + + "Region group flag for '" + foundFlag.getName() + "' set."); + } } catch (InvalidFlagFormat e) { throw new CommandException(e.getMessage()); } - sender.sendMessage(ChatColor.YELLOW - + "Region group flag for '" + foundFlag.getName() + "' set."); } else { if (value != null) { try {