@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()) { throw new CommandNotFoundException(t("commands.generic.notFound"), argSplit[0]); // TODO: Fix properly to use a SpongeTranslation?? } final String arguments = argSplit.length > 1 ? argSplit[1] : ""; CommandMapping mapping = cmdOptional.get(); Optional<PluginContainer> pluginOwner = Sponge.getCommandManager().getOwner(mapping); pluginOwner.ifPresent(pluginContainer -> Sponge.getCauseStackManager().pushCause(pluginContainer)); final CommandCallable spec = mapping.getCallable(); Sponge.getCauseStackManager().pushCause(spec); 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(); } Sponge.getCauseStackManager().popCause(); } }
@Override public CommandResult execute(CommandSource src, CommandContext args) throws CommandException { CommandMapping mapping = args.<CommandMapping>getOne(getUntranslatedKey()).orElse(null); if (mapping == null) { if (this.fallbackExecutor == null) { throw new CommandException(t("Invalid subcommand state -- no more than one mapping may be provided for child arg %s", getKey())); } return this.fallbackExecutor.execute(src, args); } if (mapping.getCallable() instanceof CommandSpec) { CommandSpec spec = ((CommandSpec) mapping.getCallable()); spec.checkPermission(src); return spec.getExecutor().execute(src, args); } final String arguments = args.<String>getOne(getUntranslatedKey() + "_args").orElse(""); return mapping.getCallable().process(src, arguments); }
@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()) { throw new CommandNotFoundException(t("commands.generic.notFound"), argSplit[0]); // TODO: Fix properly to use a SpongeTranslation?? } final String arguments = argSplit.length > 1 ? argSplit[1] : ""; final CommandCallable spec = cmdOptional.get().getCallable(); try { return spec.process(source, arguments); } catch (CommandNotFoundException e) { throw new CommandException(t("No such child command: %s", e.getCommand())); } }
@Override public CommandResult execute(CommandSource src, CommandContext args) throws CommandException { CommandMapping mapping = args.<CommandMapping>getOne(getUntranslatedKey()).orElse(null); if (mapping == null) { if (this.fallbackExecutor != null) { return this.fallbackExecutor.execute(src, args); } else { throw new CommandException(t("Invalid subcommand state -- no more than one mapping may be provided for child arg %s", getKey())); } } if (mapping.getCallable() instanceof CommandSpec) { CommandSpec spec = ((CommandSpec) mapping.getCallable()); spec.checkPermission(src); return spec.getExecutor().execute(src, args); } else { final String arguments = args.<String>getOne(getUntranslatedKey() + "_args").orElse(""); return mapping.getCallable().process(src, arguments); } }