Fix search command page number

This commit is contained in:
Luck 2017-01-30 20:13:10 +00:00
parent da23b6ea9a
commit 1efce41767
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
4 changed files with 17 additions and 19 deletions

View File

@ -28,6 +28,7 @@ import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.generic.SharedSubCommand;
import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.commands.utils.ArgumentUtils;
import me.lucko.luckperms.common.commands.utils.Util;
import me.lucko.luckperms.common.constants.Constants;
import me.lucko.luckperms.common.constants.Message;
@ -56,14 +57,7 @@ public class PermissionInfo extends SharedSubCommand {
Message.LISTNODES.send(sender, holder.getFriendlyName());
sender.sendMessage(Util.color(Util.permNodesToStringConsole(holder.getPermissions(false))));
} else {
int page = 1;
if (args.size() > 0) {
try {
page = Integer.parseInt(args.get(0));
} catch (NumberFormatException e) {
// ignored
}
}
int page = ArgumentUtils.handleIntOrElse(0, args, 1);
Map.Entry<FancyMessage, String> ent = Util.permNodesToMessage(holder.getPermissions(false), holder, label, page);
if (ent.getValue() != null) {

View File

@ -48,8 +48,7 @@ public class InfoCommand extends SingleCommand {
try {
int i = Integer.parseInt(value);
return "&a" + i;
} catch (NumberFormatException ignored) {
}
} catch (NumberFormatException ignored) {}
return "&f" + value;
}

View File

@ -29,6 +29,7 @@ import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.SingleCommand;
import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.commands.utils.ArgumentUtils;
import me.lucko.luckperms.common.commands.utils.Util;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
@ -56,15 +57,7 @@ public class SearchCommand extends SingleCommand {
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) throws CommandException {
String query = args.get(0);
int page = 1;
if (args.size() > 1) {
try {
page = Integer.parseInt(args.get(1));
} catch (NumberFormatException e) {
// ignored
}
}
int page = ArgumentUtils.handleIntOrElse(1, args, 1);
Message.SEARCH_SEARCHING.send(sender, query);

View File

@ -52,6 +52,18 @@ public class ArgumentUtils {
return args.get(index).replace("{SPACE}", " ");
}
public static int handleIntOrElse(int index, List<String> args, int other) {
if (index < 0 || index >= args.size()) {
return other;
}
try {
return Integer.parseInt(args.get(index));
} catch (NumberFormatException e) {
return other;
}
}
public static String handleNode(int index, List<String> args) throws ArgumentException {
String node = args.get(index).replace("{SPACE}", " ");
if (ArgumentChecker.checkNode(node)) {