use of org.spongepowered.api.command.CommandNotFoundException in project SpongeAPI by SpongePowered.
the class SimpleDispatcher method process.
@Override
public CommandResult process(CommandSource source, String commandLine) throws CommandException {
final String[] argSplit = commandLine.split(" ", 2);
Optional<CommandMapping> cmdOptional = get(argSplit[0], source);
if (!cmdOptional.isPresent()) {
// TODO: Fix properly to use a SpongeTranslation??
throw new CommandNotFoundException(t("commands.generic.notFound"), argSplit[0]);
}
final String arguments = argSplit.length > 1 ? argSplit[1] : "";
CommandMapping mapping = cmdOptional.get();
Optional<PluginContainer> pluginOwner = Sponge.getCommandManager().getOwner(mapping);
if (pluginOwner.isPresent()) {
Sponge.getCauseStackManager().pushCause(pluginOwner.get());
}
final CommandCallable spec = mapping.getCallable();
try {
return spec.process(source, arguments);
} catch (CommandNotFoundException e) {
throw new CommandException(t("No such child command: %s", e.getCommand()));
} finally {
if (pluginOwner.isPresent()) {
Sponge.getCauseStackManager().popCause();
}
}
}
Aggregations