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


Java CommandArgs.createError方法代码示例

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


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

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

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

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

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

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

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

示例7: parseValue

import org.spongepowered.api.command.args.CommandArgs; //导入方法依赖的package包/类
@Nullable
@Override
public Home parseValue(CommandSource src, CommandArgs args) throws ArgumentParseException {
    String value = args.next();
    if (!(src instanceof Player)) {
        //This shouldnt happen
        return null;
    }
    Player p = (Player) src;
    UltimateUser up = UltimateCore.get().getUserService().getUser(p);
    List<Home> homes = up.get(HomeKeys.HOMES).get();
    for (Home home : homes) {
        if (value.equalsIgnoreCase(home.getName())) {
            return home;
        }
    }
    throw args.createError(Messages.getFormatted(src, "home.command.home.notfound", "%home%", value.toLowerCase()));
}
 
开发者ID:Bammerbom,项目名称:UltimateCore,代码行数:19,代码来源:HomeArgument.java

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

示例9: parseValue

import org.spongepowered.api.command.args.CommandArgs; //导入方法依赖的package包/类
@Nullable
@Override
public Weather parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException {
    String value = args.next();
    switch (value) {
        case "sun":
        case "clear":
            return Weathers.CLEAR;
        case "rain":
        case "snow":
        case "downfall":
            return Weathers.RAIN;
        case "thunder":
        case "thunderstorm":
        case "thunder_storm":
        case "storm":
            return Weathers.THUNDER_STORM;
        default:
            throw args.createError(Messages.getFormatted(source, "weather.command.weather.invalidweathertype", "%weather%", value));
    }
}
 
开发者ID:Bammerbom,项目名称:UltimateCore,代码行数:22,代码来源:WeatherArgument.java

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

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

示例12: parseValue

import org.spongepowered.api.command.args.CommandArgs; //导入方法依赖的package包/类
@Override
protected Object parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException {
    if(!args.hasNext()) {
        throw args.createError(Text.of(TextColors.RED, "You must specify an IP address."));
    }

    try {
        return InetAddress.getByName(args.next());
    } catch (UnknownHostException e) {
        throw args.createError(Text.of(TextColors.RED, "This is not a valid IP address."));
    }
}
 
开发者ID:ichorpowered,项目名称:iplog,代码行数:13,代码来源:IpElement.java

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

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

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


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