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.
This commit is contained in:
Wojciech Stryjewski 2012-10-24 02:31:28 -05:00 committed by sk89q
parent 68b5e3e0a8
commit 2cbc2f5226

View File

@ -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 {