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


Java CommandArgs类代码示例

本文整理汇总了Java中org.spongepowered.api.command.args.CommandArgs的典型用法代码示例。如果您正苦于以下问题:Java CommandArgs类的具体用法?Java CommandArgs怎么用?Java CommandArgs使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CommandArgs类属于org.spongepowered.api.command.args包,在下文中一共展示了CommandArgs类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseValue

import org.spongepowered.api.command.args.CommandArgs; //导入依赖的package包/类
/**
 * Attempt to extract a value for this element from the given arguments.
 * This method is expected to have no side-effects for the source, meaning
 * that executing it will not change the state of the {@link CommandSource}
 * in any way.
 *
 * @param source The source to parse for
 * @param args   the arguments
 * @return The extracted value
 * @throws ArgumentParseException if unable to extract a value
 */
@Override
@Nullable
@NonnullByDefault
protected Object parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException {
	String type = args.next().toLowerCase();

	if (LoadedRegion.ChunkType.asMap().containsKey(type)) {
		if (source.hasPermission(String.format("%s.%s", Permissions.COMMAND_CREATE, type)))
			return LoadedRegion.ChunkType.asMap().get(type);
		else
			throw new ArgumentParseException(Text.of(TextColors.RED, String.format("You do not have permission to create %s chunks", type)), type, 0);
	} else {
		throw new ArgumentParseException(Text.of(TextColors.RED, "Chunk type does not exist."), type, 0);
	}
}
 
开发者ID:DevOnTheRocks,项目名称:StickyChunk,代码行数:27,代码来源:ChunkTypeArgument.java

示例2: complete

import org.spongepowered.api.command.args.CommandArgs; //导入依赖的package包/类
/**
 * Fetch completions for command arguments.
 *
 * @param src     The source requesting tab completions
 * @param args    The arguments currently provided
 * @param context The context to store state in
 * @return Any relevant completions
 */
@Override
@NonnullByDefault
public List<String> complete(CommandSource src, CommandArgs args, CommandContext context) {
	try {
		String type = args.peek().toLowerCase();
		return LoadedRegion.ChunkType.asMap().entrySet().stream()
			.filter(s -> s.getKey().startsWith(type))
			.filter(s -> Permissions.hasPermission(src, s.getKey()))
			.map(Map.Entry::getKey)
			.collect(Collectors.toList());
	} catch (ArgumentParseException e) {
		e.printStackTrace();
	}

	return Lists.newArrayList();
}
 
开发者ID:DevOnTheRocks,项目名称:StickyChunk,代码行数:25,代码来源:ChunkTypeArgument.java

示例3: parseValue

import org.spongepowered.api.command.args.CommandArgs; //导入依赖的package包/类
@Nullable
@Override
protected Object parseValue(CommandSource src, CommandArgs args) throws ArgumentParseException {
    String arg = args.next().toLowerCase();

    if(plugin.getCameras().containsKey(arg)){
        Camera cam = plugin.getCameras().get(arg);

        if(cam.canUseCamera(src)){
            return cam;
        }
    }

    throw args.createError(
            plugin.translations.UNKNOWN_CAMERA_ID.apply(
                    ImmutableMap.of("camera.id", arg)
            ).build()
    );
}
 
开发者ID:Lergin,项目名称:Vigilate,代码行数:20,代码来源:CameraCommandArgument.java

示例4: process

import org.spongepowered.api.command.args.CommandArgs; //导入依赖的package包/类
@Override public CommandResult process(CommandSource source, String arguments) throws CommandException {
    // Get the first argument, is it a child?
    final CommandArgs args = new CommandArgs(arguments, tokenizer.tokenize(arguments, false));

    Optional<CommandSpec> optionalSpec = getSpec(args);
    if (optionalSpec.isPresent()) {
        CommandSpec spec = optionalSpec.get();
        CommandContext context = new CommandContext();
        spec.checkPermission(source);
        spec.populateContext(source, args, context);
        return spec.getExecutor().execute(source, context);
    }

    if (testPermission(source)) {
        // Else, what do we want to do here?
        source.sendMessage(Text.of("Phonon from Nucleus."));
        return CommandResult.success();
    }

    throw new CommandPermissionException();
}
 
开发者ID:NucleusPowered,项目名称:Phonon,代码行数:22,代码来源:PhononCommand.java

示例5: parseValue

import org.spongepowered.api.command.args.CommandArgs; //导入依赖的package包/类
@Nullable
@Override
protected Object parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException {
    UUID id;

    final SourcePaginations paginations = getPaginationState(source, false);
    if (paginations == null) {
        throw args.createError(t("Source %s has no paginations!", source.getName()));
    }

    Object state = args.getState();
    try {
        id = UUID.fromString(args.next());
    } catch (IllegalArgumentException ex) {
        if (paginations.getLastUuid() != null) {
            args.setState(state);
            return paginations.get(paginations.getLastUuid());
        }
        throw args.createError(t("Input was not a valid UUID!"));
    }
    final ActivePagination pagination = paginations.get(id);
    if (pagination == null) {
        throw args.createError(t("No pagination registered for id %s", id.toString()));
    }
    return paginations.get(id);
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:27,代码来源:LanternPaginationService.java

示例6: complete

import org.spongepowered.api.command.args.CommandArgs; //导入依赖的package包/类
@Override
public List<String> complete(CommandSource src, CommandArgs args, CommandContext context) {
    final SourcePaginations paginations = getPaginationState(src, false);
    if (paginations == null) {
        return ImmutableList.of();
    }

    final Optional<String> optNext = args.nextIfPresent();
    if (optNext.isPresent()) {
        return paginations.keys().stream()
                .map(Object::toString)
                .filter(new StartsWithPredicate(optNext.get()))
                .collect(ImmutableList.toImmutableList());
    }
    return ImmutableList.copyOf(Iterables.transform(paginations.keys(), Object::toString));
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:17,代码来源:LanternPaginationService.java

示例7: complete

import org.spongepowered.api.command.args.CommandArgs; //导入依赖的package包/类
@Override
public List<String> complete(CommandSource src, CommandArgs args, CommandContext context) {
    Optional<String> arg = args.nextIfPresent();
    // Traverse through the possible arguments. We can't really complete arbitrary integers
    if (arg.isPresent()) {
        if (arg.get().startsWith("#")) {
            return SPECIAL_TOKENS.stream().filter(new StartsWithPredicate(arg.get()))
                    .collect(ImmutableList.toImmutableList());
        } else if (arg.get().contains(",") || !args.hasNext()) {
            return ImmutableList.of(arg.get());
        } else {
            arg = args.nextIfPresent();
            if (args.hasNext()) {
                return ImmutableList.of(args.nextIfPresent().get());
            } else {
                return ImmutableList.of(arg.get());
            }
        }
    } else {
        return ImmutableList.of();
    }
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:23,代码来源:GenericArguments2.java

示例8: parseRelativeDouble

import org.spongepowered.api.command.args.CommandArgs; //导入依赖的package包/类
private static RelativeDouble parseRelativeDouble(CommandArgs args, String arg) throws ArgumentParseException {
    boolean relative = arg.startsWith("~");
    double value;
    if (relative) {
        arg = arg.substring(1);
        if (arg.isEmpty()) {
            return RelativeDouble.ZERO_RELATIVE;
        }
    }
    try {
        value = Double.parseDouble(arg);
    } catch (NumberFormatException e) {
        throw args.createError(t("Expected input %s to be a double, but was not", arg));
    }
    return new RelativeDouble(value, relative);
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:17,代码来源:GenericArguments2.java

示例9: parseValue

import org.spongepowered.api.command.args.CommandArgs; //导入依赖的package包/类
@Override
public Object parseValue(CommandSource src, CommandArgs args) throws ArgumentParseException {
    String key = args.next();
    if (!this.caseSensitive) {
        key = key.toLowerCase();
    }
    // TODO: Force the choices to be lowercase?
    Object value = this.choicesFunction.apply(src).get(key);
    if (this.aliasesChoicesFunction != null && value == null) {
        value = this.aliasesChoicesFunction.apply(src).get(key);
    }
    if (value == null) {
        throw args.createError(t("Argument was not a valid choice. Valid choices: %s",
                this.choicesFunction.apply(src).keySet().toString()));
    }
    return value;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:18,代码来源:ChoicesElement.java

示例10: parseValue

import org.spongepowered.api.command.args.CommandArgs; //导入依赖的package包/类
@Nullable
@Override
protected Object parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException {
    if (!args.hasNext()) {
        throw args.createError(Text.of("No time was specified"));
    }

    String s = args.next();
    Matcher m = timeString.matcher(s);
    if (m.matches()) {
        long time = amount(m.group(2), secondsInWeek);
        time += amount(m.group(4), secondsInDay);
        time += amount(m.group(6), secondsInHour);
        time += amount(m.group(8), secondsInMinute);
        time += amount(m.group(10), 1);

        if (time > 0) {
            return time;
        }
    }

    throw args.createError(Text.of("Could not parse " + s + " - must use w, d, h, m and/or s in that order."));
}
 
开发者ID:hsyyid,项目名称:EssentialCmds,代码行数:24,代码来源:TimespanParser.java

示例11: complete

import org.spongepowered.api.command.args.CommandArgs; //导入依赖的package包/类
@Override
public List<String> complete(CommandSource src, CommandArgs args, CommandContext context)
{
	String peek;
	try
	{
		peek = args.peek();
	}
	catch (ArgumentParseException e)
	{
		return Sponge.getGame().getServer().getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
	}

	return Sponge.getGame().getServer().getOnlinePlayers().stream().filter(x -> x.getName().toLowerCase().startsWith(peek))
		.map(Player::getName).collect(Collectors.toList());
}
 
开发者ID:hsyyid,项目名称:EssentialCmds,代码行数:17,代码来源:UserParser.java

示例12: complete

import org.spongepowered.api.command.args.CommandArgs; //导入依赖的package包/类
@Nonnull
@Override
public List<String> complete(
        @Nonnull CommandSource src, CommandArgs args, CommandContext context) {
    Object state = args.getState();
    final Optional<String> nextArg = args.nextIfPresent();
    args.setState(state);
    List<String> choices = nextArg.map(Selector::complete).orElseGet(ImmutableList::of);

    if (choices.isEmpty()) {
        choices = super.complete(src, args, context);
    }

    if (choices.size() == 1) {
        currentSurvivalGame = choices.get(0);
    } else {
        currentSurvivalGame = null;
    }

    return choices;
}
 
开发者ID:m0pt0pmatt,项目名称:SurvivalGames,代码行数:22,代码来源:SurvivalGameCommandElement.java

示例13: parseValue

import org.spongepowered.api.command.args.CommandArgs; //导入依赖的package包/类
@Override
protected Object parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException {
    String clazz = args.next();
    ConfigClass configClass = NtRpgPlugin.GlobalScope.groupService.getNClass(clazz);
    if (configClass == null) {
        throw args.createError(TextHelper.parse(Localization.UNKNOWN_CLASS, Arg.arg("class",clazz)));
    }
    IActiveCharacter character = NtRpgPlugin.GlobalScope.characterService.getCharacter((Player) source);

    if (validate && PluginConfig.VALIDATE_RACE_DURING_CLASS_SELECTION) {
        Race race = character.getRace();
        if (race == Race.Default) {
            throw args.createError(TextHelper.parse(Localization.RACE_NOT_SELECTED));
        }
        if (!race.getAllowedClasses().contains(configClass)) {
            throw args.createError(TextHelper.parse(Localization.RACE_CANNOT_BECOME_CLASS,
                    Arg.arg("race", race.getName()).with("class", configClass.getName())));
        }
    }
    if (!source.hasPermission("ntrpg.groups."+configClass.getName().toLowerCase())) {
        throw args.createError(TextHelper.parse("&CNo permission ntrpg.groups.%class%",
                Arg.arg("class", configClass.getName().toLowerCase())));
    }
    return configClass;
}
 
开发者ID:NeumimTo,项目名称:NT-RPG,代码行数:26,代码来源:PlayerClassCommandElement.java

示例14: complete

import org.spongepowered.api.command.args.CommandArgs; //导入依赖的package包/类
@Override
public List<String> complete(CommandSource src, CommandArgs args, CommandContext context) {
    if (PluginConfig.VALIDATE_RACE_DURING_CLASS_SELECTION) {
        IActiveCharacter character = NtRpgPlugin.GlobalScope.characterService.getCharacter((Player) src);
        Race race = character.getRace();
        if (race == Race.Default) {
            return Collections.emptyList();
        }
        return race.getAllowedClasses().stream()
                .map(ConfigClass::getName)
                .filter(a -> src.hasPermission("ntrpg.groups."+a.toLowerCase()))
                .collect(Collectors.toList());
    }
    return NtRpgPlugin.GlobalScope.groupService.getClasses().stream()
            .map(ConfigClass::getName)
            .filter(a -> src.hasPermission("ntrpg.groups."+a.toLowerCase()))
            .collect(Collectors.toList());
}
 
开发者ID:NeumimTo,项目名称:NT-RPG,代码行数:19,代码来源:PlayerClassCommandElement.java

示例15: parseValue

import org.spongepowered.api.command.args.CommandArgs; //导入依赖的package包/类
@Override
protected T parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException {
    String givenIdentifier = args.next();
    // If the source is not a player and they have not provided a full warp
    // id, they must be referring to a global warp
    String owner = source instanceof Player ? ((Player) source).getName() : "global";
    String id = "";
    if (givenIdentifier.indexOf('/') != -1) {
        id = givenIdentifier;
    } else {
        id = owner + "/" + givenIdentifier;
    }

    Optional<? extends WarpBase> optWarpBase = this.plugin.getWarpBaseManagers().get(type).getOne(id);
    if (!optWarpBase.isPresent()) {
        throw new ArgumentParseException(Constants.WARP_NOT_FOUND_MSG, id, 0);
    }
    return (T) optWarpBase.get();
}
 
开发者ID:RobertHerhold,项目名称:BLWarps,代码行数:20,代码来源:WarpBaseCommandElement.java


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