|
20 | 20 | package com.sk89q.worldguard.protection.flags; |
21 | 21 |
|
22 | 22 | import com.google.common.collect.Sets; |
| 23 | +import com.sk89q.worldguard.protection.regions.ProtectedRegion; |
23 | 24 |
|
24 | | -import java.util.ArrayList; |
25 | | -import java.util.Collection; |
26 | | -import java.util.HashSet; |
27 | | -import java.util.List; |
28 | | -import java.util.Set; |
| 25 | +import java.util.*; |
29 | 26 |
|
30 | 27 | /** |
31 | 28 | * Stores a set of types. |
@@ -60,10 +57,31 @@ public Set<T> parseInput(FlagContext context) throws InvalidFlagFormat { |
60 | 57 | return Sets.newHashSet(); |
61 | 58 | } else { |
62 | 59 | Set<T> items = Sets.newHashSet(); |
| 60 | + boolean subtractive = false; |
| 61 | + |
| 62 | + // If the input starts with `add ` or `sub `, attempt to load the existing values, |
| 63 | + // and make this a modification, instead of an overwrite. |
| 64 | + if (input.startsWith("add ") || input.startsWith("sub ")) { |
| 65 | + ProtectedRegion region = Objects.requireNonNull((ProtectedRegion) context.get("region")); |
| 66 | + |
| 67 | + Set<T> existingValue = region.getFlag(this); |
| 68 | + if (existingValue != null) { |
| 69 | + items.addAll(existingValue); |
| 70 | + } |
| 71 | + |
| 72 | + subtractive = input.startsWith("sub "); |
| 73 | + input = input.substring(4); |
| 74 | + } |
63 | 75 |
|
64 | 76 | for (String str : input.split(",")) { |
65 | 77 | FlagContext copy = context.copyWith(null, str, null); |
66 | | - items.add(subFlag.parseInput(copy)); |
| 78 | + |
| 79 | + T subFlagValue = subFlag.parseInput(copy); |
| 80 | + if (subtractive) { |
| 81 | + items.remove(subFlagValue); |
| 82 | + } else { |
| 83 | + items.add(subFlagValue); |
| 84 | + } |
67 | 85 | } |
68 | 86 |
|
69 | 87 | return items; |
|
0 commit comments