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


Java CommandArgs.next方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: parseValue

import org.spongepowered.api.command.args.CommandArgs; //导入方法依赖的package包/类
@Nullable
@Override
public Double parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException {
    String value = args.next();
    if (!ArgumentUtil.isDouble(value)) {
        throw args.createError(Messages.getFormatted("core.number.invalid", "%number%", value));
    }
    Double num = Double.parseDouble(value);
    if (max != null && num > max) {
        throw args.createError(Messages.getFormatted("core.number.toohigh", "%number%", value));
    }
    if (min != null && num < min) {
        throw args.createError(Messages.getFormatted("core.number.toolow", "%number%", value));
    }
    return num;
}
 
开发者ID:Bammerbom,项目名称:UltimateCore,代码行数:17,代码来源:BoundedDoubleArgument.java

示例6: parseValue

import org.spongepowered.api.command.args.CommandArgs; //导入方法依赖的package包/类
@Nullable
@Override
public Integer parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException {
    String value = args.next();
    if (!ArgumentUtil.isInteger(value)) {
        throw args.createError(Messages.getFormatted("core.number.invalid", "%number%", value));
    }
    Integer num = Integer.parseInt(value);
    if (max != null && num > max) {
        throw args.createError(Messages.getFormatted("core.number.toohigh", "%number%", value, "%max%", max));
    }
    if (min != null && num < min) {
        throw args.createError(Messages.getFormatted("core.number.toolow", "%number%", value, "%min%", min));
    }
    return num;
}
 
开发者ID:Bammerbom,项目名称:UltimateCore,代码行数:17,代码来源:BoundedIntegerArgument.java

示例7: parseValue

import org.spongepowered.api.command.args.CommandArgs; //导入方法依赖的package包/类
@Nullable
@Override
public User parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException {
    String player = args.next();
    Optional<Player> t = Selector.one(source, player);
    if (t.isPresent()) {
        return t.get();
    } else {
        try {
            UserStorageService service = Sponge.getServiceManager().provide(UserStorageService.class).get();
            GameProfile profile = Sponge.getServer().getGameProfileManager().get(player).get();
            return service.get(profile).get();
        } catch (Exception ex) {
            throw args.createError(Messages.getFormatted("core.playernotfound", "%player%", player));
        }
    }
}
 
开发者ID:Bammerbom,项目名称:UltimateCore,代码行数:18,代码来源:UserArgument.java

示例8: parseValue

import org.spongepowered.api.command.args.CommandArgs; //导入方法依赖的package包/类
@Nullable
@Override
protected Object parseValue(@Nonnull CommandSource source, @Nonnull CommandArgs args) throws ArgumentParseException {
    String name = args.next();
    UUID uuid;
    try {
        uuid = UUIDUtils.getUUIDOf(name);
    }
    catch (IOException e) {
        throw args.createError(Text.builder(Messages.UNKNOWN_EX).color(TextColors.RED).build());
    }

    if (uuid == null) {
        throw args.createError(Text.builder(Messages.PLAYER_DNE).color(TextColors.RED).build());
    }

    return new SimpleEntry<>(uuid, name);
}
 
开发者ID:Musician101,项目名称:ItemBank,代码行数:19,代码来源:PlayerCommandElement.java

示例9: parseValue

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

        if (arg.matches("<@!?([0-9]+)>")) {
            String id = arg.replaceAll("[@!<>]", "");
            if (id.contains("!")) {
                id = id.replace("!", "");
            }
            return bot.getJda().getUserById(id);
        }

        if (bot.getJda().getUsersByName(arg, true).size() == 1) {
            return bot.getJda().getUsersByName(arg, true).get(0);
        } else {
            String name = arg.substring(0, arg.length() - 5);
            String discriminator = arg.substring(arg.length() - 5);
            String symbol = discriminator.substring(0, 1);

            if (symbol.equals("#")) {
                return bot.getUserByDiscriminator(name, discriminator.substring(1))
                        .orElseThrow(() -> args.createError(Text.of(TextColors.RED, "User not found!")));
            }
        }
    }
    throw args.createError(Text.of(TextColors.RED, "User not found!"));
}
 
开发者ID:NucleusPowered,项目名称:Phonon,代码行数:29,代码来源:UserArgument.java

示例10: parseValue

import org.spongepowered.api.command.args.CommandArgs; //导入方法依赖的package包/类
@Override
protected Object parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException {
	CommandArgs oldState = args;
	String input = args.next();
	try {
		return TimeUtils.timeStringToLong(input);
	} catch (NumberFormatException e) {
		throw oldState.createError(Text.of(TextColors.RED, "Invalid time format: " + input));
	}
}
 
开发者ID:Karanum,项目名称:AdamantineShield,代码行数:11,代码来源:TimeStringArgument.java

示例11: parseValue

import org.spongepowered.api.command.args.CommandArgs; //导入方法依赖的package包/类
@Nullable
@Override
protected Object parseValue(CommandSource src, CommandArgs args) throws ArgumentParseException
{
    String name = args.next();
    Optional<VirtualChestInventory> inventoryOptional = this.dispatcher.getInventory(name);
    return new Tuple<>(inventoryOptional.filter(inventory -> this.hasPermission(src, name)).orElseThrow(() ->
    {
        Text error = this.translation.take("virtualchest.open.notExists", name);
        return args.createError(error);
    }), name);
}
 
开发者ID:ustc-zzzz,项目名称:VirtualChest,代码行数:13,代码来源:VirtualChestInventoryCommandElement.java

示例12: parseValue

import org.spongepowered.api.command.args.CommandArgs; //导入方法依赖的package包/类
@Override
protected String parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException {
    String flag = args.next();

    if (!SafeGuard.getZoneManager().getFlagDefaults().containsKey(flag)) {
        throw args.createError(Text.of(String.format("Invalid zone flag: %s", flag)));
    }

    return flag;
}
 
开发者ID:prism,项目名称:SafeGuard,代码行数:11,代码来源:FlagArgument.java

示例13: parseValue

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

if (next.equalsIgnoreCase("citizen") || next.equalsIgnoreCase("minister") || next.equalsIgnoreCase("president")) {
	return next;
}

return args.createError(Text.of(TextColors.RED, "Rank not found"));
  }
 
开发者ID:trentech,项目名称:SimpleTagsNations,代码行数:11,代码来源:RankElement.java

示例14: parseValue

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

Nation nation = DataHandler.getNation(next);

if (nation != null) {
	return nation;
}

return args.createError(Text.of(TextColors.RED, "Nation not found"));
  }
 
开发者ID:trentech,项目名称:SimpleTagsNations,代码行数:13,代码来源:NationElement.java

示例15: parseValue

import org.spongepowered.api.command.args.CommandArgs; //导入方法依赖的package包/类
@Override
public Object parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException {
	String n = args.next();
	for (String c : choices) {
		if (c.equalsIgnoreCase(n)) {
			return c;
		}
	}
	throw args.createError(Text.of("Argument was not a valid choice. Valid choices: %s", StringUtils.join(choices, ',')));
}
 
开发者ID:KaiKikuchi,项目名称:BetterKits,代码行数:11,代码来源:Utils.java


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