Fix search command page number
This commit is contained in:
parent
da23b6ea9a
commit
1efce41767
@ -28,6 +28,7 @@ import me.lucko.luckperms.common.commands.CommandException;
|
|||||||
import me.lucko.luckperms.common.commands.CommandResult;
|
import me.lucko.luckperms.common.commands.CommandResult;
|
||||||
import me.lucko.luckperms.common.commands.generic.SharedSubCommand;
|
import me.lucko.luckperms.common.commands.generic.SharedSubCommand;
|
||||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
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.commands.utils.Util;
|
||||||
import me.lucko.luckperms.common.constants.Constants;
|
import me.lucko.luckperms.common.constants.Constants;
|
||||||
import me.lucko.luckperms.common.constants.Message;
|
import me.lucko.luckperms.common.constants.Message;
|
||||||
@ -56,14 +57,7 @@ public class PermissionInfo extends SharedSubCommand {
|
|||||||
Message.LISTNODES.send(sender, holder.getFriendlyName());
|
Message.LISTNODES.send(sender, holder.getFriendlyName());
|
||||||
sender.sendMessage(Util.color(Util.permNodesToStringConsole(holder.getPermissions(false))));
|
sender.sendMessage(Util.color(Util.permNodesToStringConsole(holder.getPermissions(false))));
|
||||||
} else {
|
} else {
|
||||||
int page = 1;
|
int page = ArgumentUtils.handleIntOrElse(0, args, 1);
|
||||||
if (args.size() > 0) {
|
|
||||||
try {
|
|
||||||
page = Integer.parseInt(args.get(0));
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
// ignored
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Map.Entry<FancyMessage, String> ent = Util.permNodesToMessage(holder.getPermissions(false), holder, label, page);
|
Map.Entry<FancyMessage, String> ent = Util.permNodesToMessage(holder.getPermissions(false), holder, label, page);
|
||||||
if (ent.getValue() != null) {
|
if (ent.getValue() != null) {
|
||||||
|
@ -48,8 +48,7 @@ public class InfoCommand extends SingleCommand {
|
|||||||
try {
|
try {
|
||||||
int i = Integer.parseInt(value);
|
int i = Integer.parseInt(value);
|
||||||
return "&a" + i;
|
return "&a" + i;
|
||||||
} catch (NumberFormatException ignored) {
|
} catch (NumberFormatException ignored) {}
|
||||||
}
|
|
||||||
|
|
||||||
return "&f" + value;
|
return "&f" + value;
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ import me.lucko.luckperms.common.commands.CommandException;
|
|||||||
import me.lucko.luckperms.common.commands.CommandResult;
|
import me.lucko.luckperms.common.commands.CommandResult;
|
||||||
import me.lucko.luckperms.common.commands.SingleCommand;
|
import me.lucko.luckperms.common.commands.SingleCommand;
|
||||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
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.commands.utils.Util;
|
||||||
import me.lucko.luckperms.common.constants.Message;
|
import me.lucko.luckperms.common.constants.Message;
|
||||||
import me.lucko.luckperms.common.constants.Permission;
|
import me.lucko.luckperms.common.constants.Permission;
|
||||||
@ -56,15 +57,7 @@ public class SearchCommand extends SingleCommand {
|
|||||||
@Override
|
@Override
|
||||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) throws CommandException {
|
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) throws CommandException {
|
||||||
String query = args.get(0);
|
String query = args.get(0);
|
||||||
|
int page = ArgumentUtils.handleIntOrElse(1, args, 1);
|
||||||
int page = 1;
|
|
||||||
if (args.size() > 1) {
|
|
||||||
try {
|
|
||||||
page = Integer.parseInt(args.get(1));
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
// ignored
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Message.SEARCH_SEARCHING.send(sender, query);
|
Message.SEARCH_SEARCHING.send(sender, query);
|
||||||
|
|
||||||
|
@ -52,6 +52,18 @@ public class ArgumentUtils {
|
|||||||
return args.get(index).replace("{SPACE}", " ");
|
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 {
|
public static String handleNode(int index, List<String> args) throws ArgumentException {
|
||||||
String node = args.get(index).replace("{SPACE}", " ");
|
String node = args.get(index).replace("{SPACE}", " ");
|
||||||
if (ArgumentChecker.checkNode(node)) {
|
if (ArgumentChecker.checkNode(node)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user