本文整理汇总了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()
);
}
示例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);
}
示例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);
}
示例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;
}
示例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."));
}
示例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;
}
示例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()));
}
示例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;
}
示例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));
}
}
示例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;
}
示例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);
}
示例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."));
}
}
示例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!"));
}
示例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));
}
}
示例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;
}