Fix user element throwing an IAE when checking for an exact match
* Fix potential ClassCastException
Fixes
@@ -1131,7 +1131,7 @@ protected UserCommandElement(@Nullable Text key, boolean returnSource) {
@Override
protected Object parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException {
try {
- return Iterables.filter((Iterable<Entity>) super.parseValue(source, args), e -> e instanceof User);
+ return Iterables.filter((Iterable<User>) super.parseValue(source, args), e -> e instanceof User);
} catch (ArgumentParseException ex2) {
if (this.returnSource && source instanceof User) {
return source;
@@ -1161,11 +1161,16 @@ public void parse(CommandSource source, CommandArgs args, CommandContext context
if (getKey() != null && !context.hasAny(CommandContext.TAB_COMPLETION)) {
Object state = args.getState();
String element = args.next();
+ try {
Optional<User> match = Sponge.getServiceManager().provideUnchecked(UserStorageService.class).get(element);
if (match.isPresent()) {
context.putArg(getKey(), match.get());
return;
}
+ } catch (IllegalArgumentException ignored) {
+ // Intentionally ignored
+ // If it's not an exact match, we just let this carry on to parse using the pattern element
+ }
args.setState(state);
}
