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