當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。