Fixed NPE in userinfo

This commit is contained in:
Norbi Peti 2016-11-14 17:41:55 +01:00
parent 8c5dd3b320
commit f665d1c8b9

View file

@ -31,7 +31,7 @@ public class UserinfoCommand extends DiscordCommandBase {
target = message.getMentions().get(0);
else if (args.contains("#")) {
String[] targettag = args.split("#");
final List<IUser> targets = message.getGuild().getUsersByName(targettag[0], true);
final List<IUser> targets = getUsers(message, args);
if (targets.size() == 0) {
DiscordPlugin.sendMessageToChannel(message.getChannel(), "The user cannot be found (by name): " + args);
return;
@ -48,12 +48,7 @@ public class UserinfoCommand extends DiscordCommandBase {
return;
}
} else {
final List<IUser> targets;
if (message.getChannel().isPrivate())
targets = DiscordPlugin.dc.getUsers().stream().filter(u -> u.getName().equalsIgnoreCase(args))
.collect(Collectors.toList());
else
targets = message.getGuild().getUsersByName(args, true);
final List<IUser> targets = getUsers(message, args);
if (targets.size() == 0) {
DiscordPlugin.sendMessageToChannel(message.getChannel(),
"The user cannot be found on Discord: " + args);
@ -82,6 +77,16 @@ public class UserinfoCommand extends DiscordCommandBase {
"The user is not found in our system (player has to be on the MC server for now)!");
}
private List<IUser> getUsers(IMessage message, String args) {
final List<IUser> targets;
if (message.getChannel().isPrivate())
targets = DiscordPlugin.dc.getUsers().stream().filter(u -> u.getName().equalsIgnoreCase(args))
.collect(Collectors.toList());
else
targets = message.getGuild().getUsersByName(args, true);
return targets;
}
@Override
public String[] getHelpText() {
return new String[] { //