use of net.minecraft.commands.CommandRuntimeException in project SpongeCommon by SpongePowered.
the class SpongeParameterValue method parseInternal.
private void parseInternal(final ArgumentReader.Mutable args, final CommandContext.Builder context) throws ArgumentParseException {
List<ArgumentParseException> currentExceptions = null;
final ArgumentReader.Immutable state = args.immutable();
final CommandContext.Builder.Transaction transaction = context.startTransaction();
for (final ValueParser<? extends T> parser : this.parsers) {
try {
T value = parser.parseValue(this.key, args, context).orElse(null);
if (this.modifier != null) {
value = this.modifier.modifyResult(this.key, args.immutable(), context, value).orElse(null);
}
if (value != null) {
context.putEntry(this.key, value);
}
context.commit(transaction);
// something parsed, so we exit.
return;
} catch (final ArgumentParseException ex) {
if (currentExceptions == null) {
currentExceptions = new ArrayList<>();
}
currentExceptions.add(ex);
args.setState(state);
context.rollback(transaction);
}
}
// If we get this far, we failed to parse, return the exceptions
if (currentExceptions == null) {
throw new CommandRuntimeException(new TextComponent("Could not parse element"));
// throw new ArgumentParseException(t("Could not parse element"), args.getInput(), args.cursor());
} else if (currentExceptions.size() == 1) {
throw currentExceptions.get(0);
} else {
final List<Component> errors = currentExceptions.stream().map(ArgumentParseException::superText).collect(Collectors.toList());
throw new ArgumentParseException(Component.join(Component.newline(), errors), args.input(), args.cursor());
}
}
Aggregations