use of me.lucko.luckperms.common.command.utils.SortMode in project LuckPerms by lucko.
the class PermissionInfo method execute.
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) {
if (ArgumentPermissions.checkViewPerms(plugin, sender, permission, holder)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return CommandResult.NO_PERMISSION;
}
int page = ArgumentParser.parseIntOrElse(0, args, 1);
SortMode sortMode = SortMode.determine(args);
// get the holders nodes
List<LocalizedNode> nodes = new ArrayList<>(holder.getEnduringData().asSortedSet());
// remove irrelevant types (these are displayed in the other info commands)
nodes.removeIf(node -> (node.isGroupNode() && node.getValuePrimitive() && plugin.getGroupManager().isLoaded(node.getGroupName())) || // remove if the node is a meta node
node.isPrefix() || node.isSuffix() || node.isMeta());
// handle empty
if (nodes.isEmpty()) {
Message.PERMISSION_INFO_NO_DATA.send(sender, holder.getFriendlyName());
return CommandResult.SUCCESS;
}
// sort the list alphabetically instead
if (sortMode.getType() == SortType.ALPHABETICALLY) {
nodes.sort(ALPHABETICAL_NODE_COMPARATOR);
}
// reverse the order if necessary
if (!sortMode.isAscending()) {
Collections.reverse(nodes);
}
int pageIndex = page - 1;
List<List<LocalizedNode>> pages = Iterators.divideIterable(nodes, 19);
if (pageIndex < 0 || pageIndex >= pages.size()) {
page = 1;
pageIndex = 0;
}
List<LocalizedNode> content = pages.get(pageIndex);
// send header
Message.PERMISSION_INFO.send(sender, holder.getFriendlyName(), page, pages.size(), nodes.size());
// send content
for (LocalizedNode node : content) {
String s = "&3> " + (node.getValuePrimitive() ? "&a" : "&c") + node.getPermission() + (sender.isConsole() ? " &7(" + node.getValuePrimitive() + "&7)" : "") + MessageUtils.getAppendableNodeContextString(node);
if (node.isTemporary()) {
s += "\n&2- expires in " + DateUtil.formatDateDiff(node.getExpiryUnixTime());
}
TextComponent message = TextUtils.fromLegacy(s, CommandManager.AMPERSAND_CHAR).toBuilder().applyDeep(makeFancy(holder, label, node)).build();
sender.sendMessage(message);
}
return CommandResult.SUCCESS;
}
use of me.lucko.luckperms.common.command.utils.SortMode in project LuckPerms by lucko.
the class ParentInfo method execute.
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) {
if (ArgumentPermissions.checkViewPerms(plugin, sender, permission, holder)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return CommandResult.NO_PERMISSION;
}
int page = ArgumentParser.parseIntOrElse(0, args, 1);
SortMode sortMode = SortMode.determine(args);
// get the holders nodes
List<LocalizedNode> nodes = new ArrayList<>(holder.getEnduringData().asSortedSet());
// remove irrelevant types (these are displayed in the other info commands)
nodes.removeIf(node -> !node.isGroupNode() || !node.getValuePrimitive());
// handle empty
if (nodes.isEmpty()) {
Message.PARENT_INFO_NO_DATA.send(sender, holder.getFriendlyName());
return CommandResult.SUCCESS;
}
// sort the list alphabetically instead
if (sortMode.getType() == SortType.ALPHABETICALLY) {
nodes.sort(ALPHABETICAL_NODE_COMPARATOR);
}
// reverse the order if necessary
if (!sortMode.isAscending()) {
Collections.reverse(nodes);
}
int pageIndex = page - 1;
List<List<LocalizedNode>> pages = Iterators.divideIterable(nodes, 19);
if (pageIndex < 0 || pageIndex >= pages.size()) {
page = 1;
pageIndex = 0;
}
List<LocalizedNode> content = pages.get(pageIndex);
// send header
Message.PARENT_INFO.send(sender, holder.getFriendlyName(), page, pages.size(), nodes.size());
// send content
for (LocalizedNode node : content) {
String s = "&3> &a" + node.getGroupName() + MessageUtils.getAppendableNodeContextString(node);
if (node.isTemporary()) {
s += "\n&2 expires in " + DateUtil.formatDateDiff(node.getExpiryUnixTime());
}
TextComponent message = TextUtils.fromLegacy(s, CommandManager.AMPERSAND_CHAR).toBuilder().applyDeep(makeFancy(holder, label, node)).build();
sender.sendMessage(message);
}
return CommandResult.SUCCESS;
}
Aggregations