當前位置: 首頁>>代碼示例>>Java>>正文


Java CommandContext.hasAny方法代碼示例

本文整理匯總了Java中org.spongepowered.api.command.args.CommandContext.hasAny方法的典型用法代碼示例。如果您正苦於以下問題:Java CommandContext.hasAny方法的具體用法?Java CommandContext.hasAny怎麽用?Java CommandContext.hasAny使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.spongepowered.api.command.args.CommandContext的用法示例。


在下文中一共展示了CommandContext.hasAny方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: execute

import org.spongepowered.api.command.args.CommandContext; //導入方法依賴的package包/類
@Override
public CommandResult execute(CommandSource source, CommandContext context) throws CommandException {
    //https://docs.spongepowered.org/stable/zh-CN/plugin/commands/arguments.html?highlight=commandcontext
    if (context.hasAny("arg")) {
        String[] args = context.<String>getOne("arg").get().split(" ");
        for (CommandHandler handler : this.handlerList) {
            if (args[0].equalsIgnoreCase(handler.getName()) && handler.hasPermission(source)) {
                if (!handler.hasPermission(source)) {//如果命令已禁用後台執行並且執行者是後台
                    if (source instanceof Player) {
                        source.sendMessage(TextUtil.of("§c你沒有執行該命令的權限."));
                    } else {
                        source.sendMessage(TextUtil.of("§c後台無法執行該命令."));
                    }

                } else {//否則
                    handler.execute(source, args.length == 1 ? new String[0] : Util.subArray(args, 1, args.length - 1));
                    return CommandResult.success();
                }

            }
        }
    }
    source.sendMessage(TextUtil.of("§2輸入/" + McrmbPluginInfo.config.command + " help §2來查看幫助"));

    return CommandResult.success();
}
 
開發者ID:txgs888,項目名稱:McrmbCore_Sponge,代碼行數:27,代碼來源:CommandProxy.java

示例2: execute

import org.spongepowered.api.command.args.CommandContext; //導入方法依賴的package包/類
/**
 * Callback for the execution of a command.
 *
 * @param src  The commander who is executing this command
 * @param args The parsed command arguments for this command
 * @return the result of executing this command
 * @throws CommandException If a user-facing error occurs while executing this command
 */
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
	if (!(src instanceof Player))
		return execServer(src, args);

	HashMap<Player, UUID> deleteQueue = Maps.newHashMap();
	Player player = (Player) src;

	if (args.hasAny(ALL)) {
		player.sendMessage(Text.of(
			TextColors.GOLD, "Are you sure you want to unload all? ",
			TextColors.GREEN, Text.builder("Yes ").onClick(TextActions.executeCallback(unloadAll(player))),
			TextColors.RED, Text.builder("No").onClick(TextActions
				.executeCallback(s -> player.sendMessage(Text.of(TextColors.GREEN, "Unload All Cancelled."))))
		));
		return CommandResult.success();
	}

	dataStore.getPlayerRegions(player).forEach(region ->
		region.getChunks().forEach(chunk -> {
				if (player.getLocation().getChunkPosition().equals(chunk.getPosition())) {
					region.unForceChunks();
					region.invalidateTicket();
					deleteQueue.put(player, region.getUniqueId());
					player.sendMessage(Text.of(TextColors.GREEN, "Successfully removed loaded region"));
				}
			}
		));

	// Delete all the regions queued to be deleted
	deleteQueue.forEach((owner, regionId) -> dataStore.deletePlayerRegion(owner, regionId));

	return CommandResult.success();
}
 
開發者ID:DevOnTheRocks,項目名稱:StickyChunk,代碼行數:42,代碼來源:CommandUnload.java

示例3: execute

import org.spongepowered.api.command.args.CommandContext; //導入方法依賴的package包/類
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    final Player player_args = args.<Player>getOne("player").orElse(null);
    if (src.hasPermission(VTPermissions.COMMAND_BACKPACKLOCK)) {
        if (player_args != null) {
            if (args.hasAny("l") || args.hasAny("u")) {
                if (args.hasAny("l")) {
                    if (!Tools.backpackchecklock(player_args, this.vt)) {
                        this.bplock(player_args, src);
                    }
                }
                if (args.hasAny("u")) {
                    if (Tools.backpackchecklock(player_args, this.vt)) {
                        this.bpunlock(player_args, src);
                    }
                }
            } else {
                if (Tools.backpackchecklock(player_args, this.vt)) {
                    this.bpunlock(player_args, src);
                } else {
                    this.bplock(player_args, src);
                }
            }
        }
    } else {
        throw new CommandPermissionException(Text.of("You don't have permission to use this command."));
    }
    return CommandResult.success();
}
 
開發者ID:poqdavid,項目名稱:VirtualTool,代碼行數:30,代碼來源:BackpackLockCMD.java

示例4: execute

import org.spongepowered.api.command.args.CommandContext; //導入方法依賴的package包/類
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
	Collection<WorldProperties> worlds;

	if (args.hasAny(PARAM_WORLD)) {
		worlds = args.<WorldProperties>getAll(PARAM_WORLD);
	} else if (args.hasAny(PARAM_ALL)) {
		worlds = Sponge.getGame().getServer().getAllWorldProperties();
	} else if (src instanceof Locatable) {
		worlds = Collections.singleton(((Player) src).getWorld().getProperties());
	} else
		throw new CommandException(Text.of("You have to enter a world when using this from the console!"), true);

	final boolean mode = args.<Boolean>getOne(PARAM_MODE).get();
	final String permission = BASE_PERMISSION + '.' + (mode ? "enable" : "disable") + '.';
	final List<String> worldNames = worlds.stream().map(WorldProperties::getWorldName)
			.filter(world -> src.hasPermission(permission + world)).collect(Collectors.toList());

	worldNames.stream().forEach(world -> AuraSunDial.getConfig().setWorld(world, mode));

	AuraSunDial.getConfig().save();

	if (worldNames.size() > 0) {
		src.sendMessage(Text.of((mode ? "Enabled" : "Disabled") + " realtime on these worlds: "
				+ worldNames.stream().collect(Collectors.joining(", "))));
	} else
		throw new CommandPermissionException();

	return CommandResult.successCount(worldNames.size());
}
 
開發者ID:AuraDevelopmentTeam,項目名稱:AuraSunDial,代碼行數:31,代碼來源:CommandRealTime.java

示例5: has

import org.spongepowered.api.command.args.CommandContext; //導入方法依賴的package包/類
private static <T> Predicate<T> has(CommandContext ctx, String args) {
    return a -> ctx.hasAny(ALL) || ctx.hasAny(args);
}
 
開發者ID:killjoy1221,項目名稱:WhoIs,代碼行數:4,代碼來源:Whois.java


注:本文中的org.spongepowered.api.command.args.CommandContext.hasAny方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。