Skip to content

Commit 5d67bb5

Browse files
committed
Fix duplicate entries in list arguments using non-string comparisons
1 parent 0270492 commit 5d67bb5

File tree

1 file changed

+3
-1
lines changed
  • commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments

1 file changed

+3
-1
lines changed

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ListArgumentCommon.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,18 @@ public <CommandSourceStack> List<T> parseArgument(CommandContext<CommandSourceSt
132132

133133
// If the argument's value is in the list of values, include it
134134
List<T> list = new ArrayList<>();
135+
Set<String> listKeys = new HashSet<>(); // Set to keep track of duplicates - we can't use the main list because of object hashing
135136
final String argument = cmdCtx.getArgument(key, String.class);
136137
final String[] strArr = argument.split(Pattern.quote(delimiter));
137138
final StringReader context = new StringReader(argument);
138139
for (String str : strArr) {
139140
if (!values.containsKey(str)) {
140141
throw new SimpleCommandExceptionType(new LiteralMessage("Item is not allowed in list")).createWithContext(context);
141-
} else if (!allowDuplicates && list.contains(values.get(str))) {
142+
} else if (!allowDuplicates && listKeys.contains(str)) {
142143
throw new SimpleCommandExceptionType(new LiteralMessage("Duplicate arguments are not allowed")).createWithContext(context);
143144
} else {
144145
list.add(values.get(str));
146+
listKeys.add(str);
145147
}
146148
context.setCursor(context.getCursor() + str.length() + delimiter.length());
147149
}

0 commit comments

Comments
 (0)