本文整理汇总了Java中org.spongepowered.api.command.args.CommandArgs.hasNext方法的典型用法代码示例。如果您正苦于以下问题:Java CommandArgs.hasNext方法的具体用法?Java CommandArgs.hasNext怎么用?Java CommandArgs.hasNext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spongepowered.api.command.args.CommandArgs
的用法示例。
在下文中一共展示了CommandArgs.hasNext方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
}
示例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: parse
import org.spongepowered.api.command.args.CommandArgs; //导入方法依赖的package包/类
@Override
public void parse(CommandSource source, CommandArgs args, CommandContext context) throws ArgumentParseException {
if (!args.hasNext()) {
return;
}
Object startState = args.getState();
try {
this.element.parse(source, args, context);
} catch (ArgumentParseException ex) {
if (args.hasNext()) { // If there are more args, suppress. Otherwise, throw the error
args.setState(startState);
} else {
throw ex;
}
}
}
示例4: complete
import org.spongepowered.api.command.args.CommandArgs; //导入方法依赖的package包/类
@Nonnull
@Override
public List<String> complete(@Nonnull CommandSource src, @Nonnull CommandArgs args, @Nonnull CommandContext context) {
Stream<String> nameStream = Sponge.getServer().getOnlinePlayers().stream().map(Player::getName);
if (args.hasNext()) {
nameStream = nameStream.filter(name -> {
try {
return name.startsWith(args.next());
}
catch (ArgumentParseException e) {
return false;
}
});
}
return nameStream.collect(Collectors.toList());
}
示例5: 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."));
}
}
示例6: getSpec
import org.spongepowered.api.command.args.CommandArgs; //导入方法依赖的package包/类
private Optional<CommandSpec> getSpec(CommandArgs args) throws CommandException {
if (args.hasNext()) {
String child = args.next().toLowerCase();
if (subCommands.containsKey(child)) {
// Try to execute it.
final CommandContext context = new CommandContext();
return Optional.of(subCommands.get(child));
}
// Just temporary.
throw new CommandException(Text.of(TextColors.RED, child, " is not a valid subcommand!"), true);
}
return Optional.empty();
}
示例7: 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!"));
}
示例8: parseValue
import org.spongepowered.api.command.args.CommandArgs; //导入方法依赖的package包/类
@Override
protected Object parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException {
final StringBuilder stringBuilder = new StringBuilder(args.next());
while (args.hasNext()) {
stringBuilder.append(' ').append(args.next());
}
return stringBuilder.toString();
}
示例9: parseValue
import org.spongepowered.api.command.args.CommandArgs; //导入方法依赖的package包/类
@Override
protected Object parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException {
List<String> values = new ArrayList<>();
// Move the position to the end
while (args.hasNext()) {
String arg = args.next();
if (!arg.isEmpty()) {
values.add(arg);
}
}
return values.toArray(new String[values.size()]);
}
示例10: parse
import org.spongepowered.api.command.args.CommandArgs; //导入方法依赖的package包/类
@Override
public void parse(CommandSource source, CommandArgs args, CommandContext context) throws ArgumentParseException {
if (!args.hasNext()) {
return;
}
element.parse(source, args, context);
}
示例11: parse
import org.spongepowered.api.command.args.CommandArgs; //导入方法依赖的package包/类
@Override
public void parse(CommandSource source, CommandArgs args, CommandContext context) throws ArgumentParseException {
//Parse at least once
if (atLeastOnce) {
this.element.parse(source, args, context);
}
while (args.hasNext()) {
this.element.parse(source, args, context);
}
}
示例12: parseValue
import org.spongepowered.api.command.args.CommandArgs; //导入方法依赖的package包/类
@Nullable
@Override
public String parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException {
args.next();
String ret = args.getRaw().substring(args.getRawPosition());
while (args.hasNext()) { // Consume remaining args
args.next();
}
return ret;
}
示例13: onMessageReceived
import org.spongepowered.api.command.args.CommandArgs; //导入方法依赖的package包/类
@Override
public void onMessageReceived(MessageReceivedEvent event) {
CoreConfig config = this.phononPlugin.getConfigAdapter(CoreModule.ID, CoreConfigAdapter.class).get().getNodeOrDefault();
if (event.getMessage().getRawContent().startsWith(config.getPrefix()) && !event.getMessage().getAuthor().isBot()) {
DiscordCommandSource source = new DiscordCommandSource(event.getAuthor(), event.getChannel());
int end = event.getMessage().getRawContent().indexOf(" ");
String commandName;
String arguments;
if (end == -1) {
commandName = event.getMessage().getRawContent().substring(1);
arguments = "";
} else {
commandName = event.getMessage().getRawContent().substring(1, end);
arguments = event.getMessage().getRawContent().substring(end + 1);
}
if (aliases.containsKey(commandName)) {
IDiscordCommand command = aliases.get(commandName);
CommandElement args= null;
try {
CommandArgs commandArgs = new CommandArgs(arguments,
InputTokenizer.quotedStrings(false).tokenize(arguments, true));
CommandContext context = new CommandContext();
args = GenericArguments.seq(command.getArgs());
args.parse(source, commandArgs, context);
if (commandArgs.hasNext()) {
commandArgs.next();
throw commandArgs.createError(t("Invalid arguments!"));
}
command.execute(event.getAuthor(), context, event.getChannel());
} catch (ArgumentParseException e) {
String message = "Invalid Arguments";
if (e.getMessage() != null) {
message = e.getMessage();
}
if (args == null) {
event.getChannel().sendMessage(message).queue();
} else {
event.getChannel().sendMessage(message + System.lineSeparator() +
config.getPrefix() + commandName + args.getUsage(source).toPlain()).queue();
}
}
if (!(event.getChannel() instanceof PrivateChannel)) {
event.getMessage().delete().queue();
}
}
}
}
示例14: parseValue
import org.spongepowered.api.command.args.CommandArgs; //导入方法依赖的package包/类
@Override
public Object parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException {
return args.hasNext() ? null : this.element.parseValue(source, args);
}