|
11 | 11 | import ch.njol.skript.util.StringMode; |
12 | 12 | import ch.njol.skript.util.Timespan; |
13 | 13 | import ch.njol.skript.variables.HintManager; |
| 14 | +import ch.njol.util.coll.CollectionUtils; |
14 | 15 | import com.mojang.brigadier.arguments.ArgumentType; |
15 | 16 | import com.mojang.brigadier.arguments.StringArgumentType; |
16 | 17 | import com.mojang.brigadier.builder.ArgumentBuilder; |
|
46 | 47 | import java.util.ArrayList; |
47 | 48 | import java.util.Arrays; |
48 | 49 | import java.util.Collection; |
| 50 | +import java.util.EnumSet; |
49 | 51 | import java.util.List; |
| 52 | +import java.util.Set; |
50 | 53 | import java.util.function.Predicate; |
51 | 54 | import java.util.regex.Matcher; |
52 | 55 | import java.util.regex.Pattern; |
@@ -88,20 +91,22 @@ protected List<String> getValue(String value) { |
88 | 91 | .addEntryData(new VariableStringEntryData("usage", null, true)) |
89 | 92 | .addEntry("prefix", null, true) |
90 | 93 | .addEntry("permission", null, true) |
91 | | - .addEntryData(new KeyValueEntryData<ExecutableBy>("executable by", null, true) { |
92 | | - private final Pattern pattern = Pattern.compile("\\s*,\\s*|\\s+(and|or)\\s+"); |
| 94 | + .addEntryData(new KeyValueEntryData<Set<ExecutableBy>>("executable by", null, true) { |
| 95 | + private final Pattern pattern = Pattern.compile("\\s*,(?:\\s+(?:and|or)\\s+)?\\s*|\\s+(?:and|or)\\s+"); |
93 | 96 |
|
94 | 97 | @Override |
95 | | - protected ExecutableBy getValue(String value) { |
96 | | - ExecutableBy executableBy = ExecutableBy.NONE; |
| 98 | + protected Set<ExecutableBy> getValue(String value) { |
| 99 | + EnumSet<ExecutableBy> executableBy = EnumSet.noneOf(ExecutableBy.class); |
97 | 100 | for (String type : pattern.split(value)) { |
98 | 101 | if (type.equalsIgnoreCase("console") || type.equalsIgnoreCase("the console")) { |
99 | | - executableBy = executableBy.with(ExecutableBy.CONSOLE); |
| 102 | + executableBy.add(ExecutableBy.CONSOLE); |
100 | 103 | } else if (type.equalsIgnoreCase("players") || type.equalsIgnoreCase("player")) { |
101 | | - executableBy = executableBy.with(ExecutableBy.PLAYERS); |
| 104 | + executableBy.add(ExecutableBy.PLAYERS); |
| 105 | + } else if (type.equalsIgnoreCase("blocks") || type.equalsIgnoreCase("block")) { |
| 106 | + executableBy.add(ExecutableBy.BLOCKS); |
102 | 107 | } else { |
103 | 108 | Skript.error("Invalid command sender type: " + type); |
104 | | - return ExecutableBy.NONE; |
| 109 | + return Set.of(); |
105 | 110 | } |
106 | 111 | } |
107 | 112 | return executableBy; |
@@ -228,18 +233,21 @@ public SubCommandEntryData(String key, boolean optional, boolean multiple) { |
228 | 233 | } |
229 | 234 |
|
230 | 235 | // executable by requirement |
231 | | - ExecutableBy executableBy = entryContainer.getOptional("executable by", ExecutableBy.class, false); |
| 236 | + Set<ExecutableBy> executableBy = entryContainer.getOptional("executable by", Set.class, false); |
232 | 237 | if (executableBy != null) { |
233 | | - if (executableBy == ExecutableBy.NONE) { // parsing failed |
| 238 | + if (executableBy.isEmpty()) { // parsing failed |
234 | 239 | return null; |
235 | 240 | } |
236 | | - ExecutableBy parent = parsingData.getExecutorData(ExecutorData::executableBy); |
237 | | - if (parent != null && !parent.includes(executableBy)) { |
238 | | - Skript.error("It is not possible to restrict execution to " + executableBy + |
239 | | - " as the parent command is only executable by " + parent + "."); |
| 241 | + Set<ExecutableBy> parent = parsingData.getExecutorData(ExecutorData::executableBy); |
| 242 | + if (parent != null && !parent.containsAll(executableBy)) { |
| 243 | + Skript.error("It is not possible to restrict execution to " + CollectionUtils.toString(executableBy, true) + |
| 244 | + " as the parent command is only executable by " + CollectionUtils.toString(parent, true) + "."); |
240 | 245 | return null; |
241 | 246 | } |
242 | | - requires = requires.and(executableBy.predicate()); |
| 247 | + requires = requires.and(executableBy.stream() |
| 248 | + .map(ExecutableBy::predicate) |
| 249 | + .reduce(Predicate::or) |
| 250 | + .orElseThrow()); |
243 | 251 | } |
244 | 252 |
|
245 | 253 | // prepare final requirements predicate |
|
0 commit comments