当前位置: 首页>>代码示例>>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;未经允许,请勿转载。