本文整理汇总了Java中org.spongepowered.api.command.args.GenericArguments.seq方法的典型用法代码示例。如果您正苦于以下问题:Java GenericArguments.seq方法的具体用法?Java GenericArguments.seq怎么用?Java GenericArguments.seq使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spongepowered.api.command.args.GenericArguments
的用法示例。
在下文中一共展示了GenericArguments.seq方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onMessageReceived
import org.spongepowered.api.command.args.GenericArguments; //导入方法依赖的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();
}
}
}
}