Search in sources :

Example 1 with CommandNotFoundException

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();
        }
    }
}
Also used : PluginContainer(org.spongepowered.api.plugin.PluginContainer) ImmutableCommandMapping(org.spongepowered.api.command.ImmutableCommandMapping) CommandMapping(org.spongepowered.api.command.CommandMapping) CommandException(org.spongepowered.api.command.CommandException) CommandNotFoundException(org.spongepowered.api.command.CommandNotFoundException) CommandCallable(org.spongepowered.api.command.CommandCallable)

Aggregations

CommandCallable (org.spongepowered.api.command.CommandCallable)1 CommandException (org.spongepowered.api.command.CommandException)1 CommandMapping (org.spongepowered.api.command.CommandMapping)1 CommandNotFoundException (org.spongepowered.api.command.CommandNotFoundException)1 ImmutableCommandMapping (org.spongepowered.api.command.ImmutableCommandMapping)1 PluginContainer (org.spongepowered.api.plugin.PluginContainer)1