本文整理匯總了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();
}
}
}
}