本文整理汇总了Java中org.spongepowered.api.command.spec.CommandExecutor类的典型用法代码示例。如果您正苦于以下问题:Java CommandExecutor类的具体用法?Java CommandExecutor怎么用?Java CommandExecutor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CommandExecutor类属于org.spongepowered.api.command.spec包,在下文中一共展示了CommandExecutor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.spongepowered.api.command.spec.CommandExecutor; //导入依赖的package包/类
@Listener(order=Order.FIRST)
public void init(GameInitializationEvent event) { instance = this; //myL=L.createLang(this);
reload();
Sponge.getServiceManager().setProvider(this, LanguageService.class, new LanguageServiceProvider());
l("The LanguageService is now available!");
Map<String, String> listMap = new HashMap<>();
for (String al : available) listMap.put(al, al);
Sponge.getCommandManager().register(this, CommandSpec.builder().arguments(GenericArguments.onlyOne(GenericArguments.choices(Text.of("Language"), listMap))).executor(new CommandExecutor() {
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
if (!(src instanceof Player)) { src.sendMessage(Text.of("Only available for players")); return CommandResult.success(); }
Optional<String> la = args.<String>getOne("Language");
if (!la.isPresent()) {
src.sendMessage(Text.of(playerLang.get(((Player)src).getUniqueId()).toString()));
} else {
String lang = la.get();
lang = lang.replace('_', '-'); //Locales toString used a underscore but the language tag requires a dash
Locale locale = Locale.forLanguageTag(lang);
playerChangedLang(((Player)src).getProfile(), locale);
}
return CommandResult.success();
}
}).build(), "language");
}
示例2: getCommand
import org.spongepowered.api.command.spec.CommandExecutor; //导入依赖的package包/类
/**
* Build a complete command hierarchy
* @return
*/
public static CommandSpec getCommand() {
ImmutableMap.Builder<List<String>, CommandCallable> builder = ImmutableMap.builder();
builder.put(ImmutableList.of("add"), AddKeyCommand.getCommand());
builder.put(ImmutableList.of("remove", "del", "delete"), RemoveKeyCommand.getCommand());
builder.put(ImmutableList.of("reload"), ReloadCommand.getCommand());
builder.put(ImmutableList.of("?", "help"), HelpCommand.getCommand());
return CommandSpec.builder()
.permission("keys.use")
.executor(new CommandExecutor() {
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
src.sendMessage(Text.of(
Format.heading(TextColors.GRAY, "By ", TextColors.GOLD, "viveleroi.\n"),
TextColors.GRAY, "IRC: ", TextColors.WHITE, "irc.esper.net #helion3\n"
));
return CommandResult.empty();
}
})
.children(builder.build()).build();
}
示例3: getCommand
import org.spongepowered.api.command.spec.CommandExecutor; //导入依赖的package包/类
public static CommandSpec getCommand() {
return CommandSpec.builder()
.description(Text.of("Locks a location."))
.permission("keys.use")
.executor(new CommandExecutor() {
@Override
public CommandResult execute(CommandSource source, CommandContext args) throws CommandException {
if (!(source instanceof Player)) {
source.sendMessage(Format.error("Command usable only by a player."));
return CommandResult.empty();
}
Player player = (Player) source;
if (Keys.getInteractionHandler(player).isPresent()) {
Keys.removeInteractionHandler(player);
player.sendMessage(Format.message("Canceled lock mode."));
} else {
Keys.registerInteractionHandler(player, new LockInteractionHandler());
player.sendMessage(Format.heading("Punch a block to lock it..."));
}
return CommandResult.success();
}
}).build();
}
示例4: getCommand
import org.spongepowered.api.command.spec.CommandExecutor; //导入依赖的package包/类
public static CommandSpec getCommand() {
return CommandSpec.builder()
.description(Text.of("Unlocks a locked location."))
.permission("keys.use")
.executor(new CommandExecutor() {
@Override
public CommandResult execute(CommandSource source, CommandContext args) throws CommandException {
if (!(source instanceof Player)) {
source.sendMessage(Format.error("Command usable only by a player."));
return CommandResult.empty();
}
Player player = (Player) source;
if (Keys.getInteractionHandler(player).isPresent()) {
Keys.removeInteractionHandler(player);
player.sendMessage(Format.message("Canceled unlock mode."));
} else {
Keys.registerInteractionHandler(player, new UnlockInteractionHandler());
player.sendMessage(Format.heading("Punch a locked block to unlock it..."));
}
return CommandResult.success();
}
}).build();
}
示例5: getCommand
import org.spongepowered.api.command.spec.CommandExecutor; //导入依赖的package包/类
public static CommandSpec getCommand() {
return CommandSpec.builder()
.description(Text.of("Reload config and zone files."))
.permission("keys.mod")
.executor(new CommandExecutor() {
@Override
public CommandResult execute(CommandSource source, CommandContext args) throws CommandException {
Keys.reload();
return CommandResult.success();
}
}).build();
}
示例6: getCommand
import org.spongepowered.api.command.spec.CommandExecutor; //导入依赖的package包/类
public static CommandSpec getCommand() {
return CommandSpec.builder()
.executor(new CommandExecutor() {
@Override
public CommandResult execute(CommandSource source, CommandContext args) throws CommandException {
source.sendMessage(Format.message("/lock", TextColors.GRAY, " - Lock a block manually."));
source.sendMessage(Format.message("/unlock", TextColors.GRAY, " - Unlock an block."));
source.sendMessage(Format.message("/keys add [player]", TextColors.GRAY, " - Add a player to a locked block."));
source.sendMessage(Format.message("/keys del [player]", TextColors.GRAY, " - Remove a player's access to a locked block."));
source.sendMessage(Format.message("/keys reload", TextColors.GRAY, " - Reload configuration."));
return CommandResult.empty();
}
}).build();
}
示例7: parseValue
import org.spongepowered.api.command.spec.CommandExecutor; //导入依赖的package包/类
@Override
protected CommandExecutor parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException {
String subCommand = args.next();
Iterator<List<String>> keySetIterator = subCommands.keySet().iterator();
while (keySetIterator.hasNext()) {
List<String> subCommandAliases = keySetIterator.next();
for (String subCommandAlias : subCommandAliases) {
if (subCommandAlias.equalsIgnoreCase(subCommand)) {
return subCommands.get(subCommandAliases).getExecutor();
}
}
}
throw args.createError(Text.of("'%s' did not match any subcommands", subCommand));
}
示例8: execute
import org.spongepowered.api.command.spec.CommandExecutor; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource source, CommandContext args) throws CommandException {
// Execute any subcommand that was used
Optional<CommandExecutor> subCmdExecOpt = args.getOne("subcommand");
if(subCmdExecOpt.isPresent()) {
return subCmdExecOpt.get().execute(source, args);
}
if (!(source instanceof Player)) {
source.sendMessage(Constants.MUST_BE_PLAYER_MSG);
return CommandResult.empty();
}
Player player = (Player) source;
Optional<Warp> optWarp = args.getOne("warp");
if (!optWarp.isPresent()) {
source.sendMessage(Constants.WARP_NOT_FOUND_MSG);
return CommandResult.empty();
}
Warp warp = optWarp.get();
if (Util.hasPermission(player, warp) == false) {
player.sendMessage(Constants.NO_PERMISSION_MSG);
return CommandResult.empty();
}
this.plugin.getWarpManager().scheduleWarp(player, warp);
return CommandResult.success();
}
示例9: createReloadCommandSpec
import org.spongepowered.api.command.spec.CommandExecutor; //导入依赖的package包/类
private CommandSpec createReloadCommandSpec() {
CommandSpec reloadCommand = CommandSpec.builder()
.description(Text.of("Reload all ActionControl config files"))
.permission("actioncontrol.reload")
.executor(new CommandExecutor() {
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
boolean successful = loadConfigs();
if (src instanceof Player) {
Player player = (Player) src;
if (successful) {
player.sendMessage(Text.builder("Successfully reloaded the config files")
.color(TextColors.GREEN)
.build());
} else {
player.sendMessage(Text.builder("An error occured while loading a config file. "
+ "Check the console for details.")
.color(TextColors.RED)
.build());
}
}
return CommandResult.success();
}
}).build();
return CommandSpec.builder().child(reloadCommand, "reload").build();
}
示例10: asCommandExecutor
import org.spongepowered.api.command.spec.CommandExecutor; //导入依赖的package包/类
public CommandExecutor asCommandExecutor(final CommandManager commandService) {
return new CommandExecutor() {
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
CommandResult lastResult = null;
for (String command : commands) {
lastResult = commandService.process(src, command);
}
return lastResult;
}
};
}
示例11: registerCommand
import org.spongepowered.api.command.spec.CommandExecutor; //导入依赖的package包/类
public Optional<CommandMapping> registerCommand(PluginContainer plugin, final List<String> commandNameAndAliases, String commandDescription, final CommandExecutor commandExecutor, CommandElement... args) {
final Builder builder = CommandSpec.builder();
if (!Strings.isNullOrEmpty(commandDescription))
builder.description(Text.of(commandDescription));
final CommandCallable spec = builder.arguments(args).executor(commandExecutor).build();
final Optional<CommandMapping> newCommand = game.getCommandManager().register(plugin, spec, commandNameAndAliases);
if (!newCommand.isPresent()) {
logger.error(commandNameAndAliases + " command could not be registered! :-(");
}
return newCommand;
}
示例12: buildPaginationCommand
import org.spongepowered.api.command.spec.CommandExecutor; //导入依赖的package包/类
@SuppressWarnings("ConstantConditions")
private CommandSpec buildPaginationCommand() {
// TODO Completely redo this once command refactor is out and PR changes to Sponge as well
final ActivePaginationCommandElement paginationElement = new ActivePaginationCommandElement(t("pagination-id"));
CommandSpec next = CommandSpec.builder()
.description(t("Go to the next page"))
.executor((src, args) -> {
args.<ActivePagination>getOne("pagination-id").get().nextPage();
return CommandResult.success();
}).build();
CommandSpec prev = CommandSpec.builder()
.description(t("Go to the previous page"))
.executor((src, args) -> {
args.<ActivePagination>getOne("pagination-id").get().previousPage();
return CommandResult.success();
}).build();
CommandElement pageArgs = integer(t("page"));
CommandExecutor pageExecutor = (src, args) -> {
args.<ActivePagination>getOne("pagination-id").get().specificPage(args.<Integer>getOne("page").get());
return CommandResult.success();
};
CommandSpec page = CommandSpec.builder()
.description(t("Go to a specific page"))
.arguments(pageArgs)
.executor(pageExecutor).build();
// Fallback to page arguments
ChildCommandElementExecutor childDispatcher = new ChildCommandElementExecutor(pageExecutor);
childDispatcher.register(next, "next", "n");
childDispatcher.register(prev, "prev", "p", "previous");
childDispatcher.register(page, "page");
// We create the child manually in order to force that paginationElement is required for all children + fallback
// https://github.com/SpongePowered/SpongeAPI/issues/1272
return CommandSpec.builder().arguments(paginationElement, firstParsing(childDispatcher, pageArgs))
.executor(childDispatcher)
.description(t("Helper command for paginations occurring"))
.build();
}
示例13: createCommand
import org.spongepowered.api.command.spec.CommandExecutor; //导入依赖的package包/类
public Optional<CommandMapping> createCommand(PluginContainer plugin, String name, String commandDescription, CommandExecutor commandExecutor) {
return registerCommand(plugin, Collections.singletonList(name), commandDescription, commandExecutor);
}
示例14: adapt
import org.spongepowered.api.command.spec.CommandExecutor; //导入依赖的package包/类
public static CommandExecutor adapt(CommandExecutorWithoutResultThrowsThrowable executor) {
return new CommandExecutorAdapter(executor);
}
示例15: ExecutorListenerWrapper
import org.spongepowered.api.command.spec.CommandExecutor; //导入依赖的package包/类
public ExecutorListenerWrapper(HighCommand cmd, CommandExecutor exe) {
this.command = cmd;
this.executor = exe;
}