diff --git a/worldguard-core/src/main/java/com/sk89q/worldguard/protection/flags/SetFlag.java b/worldguard-core/src/main/java/com/sk89q/worldguard/protection/flags/SetFlag.java index 408420ec1..fe635e866 100644 --- a/worldguard-core/src/main/java/com/sk89q/worldguard/protection/flags/SetFlag.java +++ b/worldguard-core/src/main/java/com/sk89q/worldguard/protection/flags/SetFlag.java @@ -20,12 +20,9 @@ package com.sk89q.worldguard.protection.flags; import com.google.common.collect.Sets; +import com.sk89q.worldguard.protection.regions.ProtectedRegion; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; /** * Stores a set of types. @@ -60,10 +57,31 @@ public Set parseInput(FlagContext context) throws InvalidFlagFormat { return Sets.newHashSet(); } else { Set items = Sets.newHashSet(); + boolean subtractive = false; + + // If the input starts with `add ` or `sub `, attempt to load the existing values, + // and make this a modification, instead of an overwrite. + if (input.startsWith("add ") || input.startsWith("sub ")) { + ProtectedRegion region = Objects.requireNonNull((ProtectedRegion) context.get("region")); + + Set existingValue = region.getFlag(this); + if (existingValue != null) { + items.addAll(existingValue); + } + + subtractive = input.startsWith("sub "); + input = input.substring(4); + } for (String str : input.split(",")) { FlagContext copy = context.copyWith(null, str, null); - items.add(subFlag.parseInput(copy)); + + T subFlagValue = subFlag.parseInput(copy); + if (subtractive) { + items.remove(subFlagValue); + } else { + items.add(subFlagValue); + } } return items;