当前位置: 首页>>代码示例>>Java>>正文


Java CommandExecutor类代码示例

本文整理汇总了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");
}
 
开发者ID:DosMike,项目名称:LangSwitch,代码行数:27,代码来源:LangSwitch.java

示例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();
}
 
开发者ID:prism,项目名称:Keys,代码行数:26,代码来源:KeysCommands.java

示例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();
}
 
开发者ID:prism,项目名称:Keys,代码行数:27,代码来源:LockCommand.java

示例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();
}
 
开发者ID:prism,项目名称:Keys,代码行数:27,代码来源:UnlockCommand.java

示例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();
}
 
开发者ID:prism,项目名称:Keys,代码行数:14,代码来源:ReloadCommand.java

示例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();
}
 
开发者ID:prism,项目名称:Keys,代码行数:15,代码来源:HelpCommand.java

示例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));
}
 
开发者ID:RobertHerhold,项目名称:BLWarps,代码行数:16,代码来源:WarpSubCommandElement.java

示例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();
}
 
开发者ID:RobertHerhold,项目名称:BLWarps,代码行数:32,代码来源:WarpExecutor.java

示例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();
}
 
开发者ID:Monospark,项目名称:ActionControl,代码行数:29,代码来源:ActionControl.java

示例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;
		}
	};
}
 
开发者ID:vorburger,项目名称:SwissKnightMinecraft,代码行数:13,代码来源:Script.java

示例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;
}
 
开发者ID:vorburger,项目名称:SwissKnightMinecraft,代码行数:13,代码来源:CommandHelper.java

示例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();
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:45,代码来源:LanternPaginationService.java

示例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);
}
 
开发者ID:vorburger,项目名称:SwissKnightMinecraft,代码行数:4,代码来源:CommandHelper.java

示例14: adapt

import org.spongepowered.api.command.spec.CommandExecutor; //导入依赖的package包/类
public static CommandExecutor adapt(CommandExecutorWithoutResultThrowsThrowable executor) {
	return new CommandExecutorAdapter(executor);
}
 
开发者ID:vorburger,项目名称:SwissKnightMinecraft,代码行数:4,代码来源:CommandExecutorAdapter.java

示例15: ExecutorListenerWrapper

import org.spongepowered.api.command.spec.CommandExecutor; //导入依赖的package包/类
public ExecutorListenerWrapper(HighCommand cmd, CommandExecutor exe) {
    this.command = cmd;
    this.executor = exe;
}
 
开发者ID:Bammerbom,项目名称:UltimateCore,代码行数:5,代码来源:ExecutorListenerWrapper.java


注:本文中的org.spongepowered.api.command.spec.CommandExecutor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。