use of com.mojang.brigadier.context.CommandContextBuilder in project SpongeCommon by SpongePowered.
the class ForgeCommandManager method processCommand.
@Override
protected CommandResult processCommand(final CommandCause cause, final CommandMapping mapping, final String original, final String command, final String args) throws Throwable {
final CommandRegistrar<?> registrar = mapping.registrar();
final boolean isBrig = registrar instanceof BrigadierBasedRegistrar;
final ParseResults<CommandSourceStack> parseResults;
if (isBrig) {
parseResults = this.getDispatcher().parse(original, (CommandSourceStack) cause);
} else {
// We have a non Brig registrar, so we just create a dummy result for mods to inspect.
final CommandContextBuilder<CommandSourceStack> contextBuilder = new CommandContextBuilder<>(this.getDispatcher(), (CommandSourceStack) cause, this.getDispatcher().getRoot(), 0);
contextBuilder.withCommand(ctx -> 1);
if (!args.isEmpty()) {
contextBuilder.withArgument("parsed", new ParsedArgument<>(command.length(), original.length(), args));
}
parseResults = new ParseResults<>(contextBuilder, new SpongeStringReader(original), Collections.emptyMap());
}
// Relocated from Commands (injection short circuits it there)
final CommandEvent event = new CommandEvent(parseResults);
if (MinecraftForge.EVENT_BUS.post(event)) {
if (event.getException() != null) {
Throwables.throwIfUnchecked(event.getException());
}
// As per Forge, we just treat it as a zero success, and do nothing with it.
return CommandResult.builder().result(0).build();
}
if (isBrig) {
return CommandResult.builder().result(this.getDispatcher().execute(parseResults)).build();
} else {
return mapping.registrar().process(cause, mapping, command, args);
}
}
Aggregations