mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-28 05:35:26 +01:00
Make output of listnodes nicer
This commit is contained in:
parent
9b4bbe0500
commit
1fc88e147f
@ -23,14 +23,12 @@
|
||||
package me.lucko.luckperms.commands;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Patterns;
|
||||
import me.lucko.luckperms.utils.DateUtil;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
@UtilityClass
|
||||
public class Util {
|
||||
@ -115,35 +113,53 @@ public class Util {
|
||||
return sb.delete(sb.length() - 6, sb.length()).toString();
|
||||
}
|
||||
|
||||
public static String permNodesToString(Map<String, Boolean> nodes) {
|
||||
if (nodes.isEmpty()) return "&6None";
|
||||
|
||||
public static String permNodesToString(SortedSet<Node> nodes) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for (Map.Entry<String, Boolean> e : nodes.entrySet()) {
|
||||
if (e.getValue()) {
|
||||
sb.append("&a").append(e.getKey()).append("&7, ");
|
||||
} else {
|
||||
sb.append("&c").append(e.getKey()).append("&7, ");
|
||||
for (Node node : nodes) {
|
||||
if (node.isTemporary()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
sb.append("&6-> ").append(node.getValue() ? "&a" : "&c");
|
||||
sb.append(node.getPermission());
|
||||
if (node.isServerSpecific()) {
|
||||
sb.append(" &7(&f").append(node.getServer().get()).append("&7)");
|
||||
}
|
||||
if (node.isWorldSpecific()) {
|
||||
sb.append(" &7(&f").append(node.getWorld().get()).append("&7)");
|
||||
}
|
||||
sb.append("\n");
|
||||
}
|
||||
|
||||
return sb.delete(sb.length() - 2, sb.length()).toString();
|
||||
if (sb.length() == 0) {
|
||||
return "&6None";
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String tempNodesToString(Map<Map.Entry<String, Boolean>, Long> nodes) {
|
||||
if (nodes.isEmpty()) return "&6None";
|
||||
|
||||
public static String tempNodesToString(SortedSet<Node> nodes) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for (Map.Entry<Map.Entry<String, Boolean>, Long> e : nodes.entrySet()) {
|
||||
if (e.getKey().getValue()) {
|
||||
sb.append("&a").append(e.getKey().getKey()).append("&6 - expires in ")
|
||||
.append(DateUtil.formatDateDiff(e.getValue())).append("\n");
|
||||
} else {
|
||||
sb.append("&c").append(e.getKey().getKey()).append("&6 - expires in ")
|
||||
.append(DateUtil.formatDateDiff(e.getValue())).append("\n");
|
||||
for (Node node : nodes) {
|
||||
if (!node.isTemporary()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
sb.append("&6-> ").append(node.getValue() ? "&a" : "&c");
|
||||
sb.append(node.getPermission());
|
||||
if (node.isServerSpecific()) {
|
||||
sb.append(" &7(&f").append(node.getServer().get()).append("&7)");
|
||||
}
|
||||
if (node.isWorldSpecific()) {
|
||||
sb.append(" &7(&f").append(node.getWorld().get()).append("&7)");
|
||||
}
|
||||
|
||||
sb.append("&6 - expires in ").append(DateUtil.formatDateDiff(node.getExpiryUnixTime())).append("\n");
|
||||
}
|
||||
|
||||
if (sb.length() == 0) {
|
||||
return "&6None";
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
|
@ -30,8 +30,6 @@ import me.lucko.luckperms.groups.Group;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static me.lucko.luckperms.core.PermissionHolder.exportToLegacy;
|
||||
|
||||
public class GroupListNodes extends SubCommand<Group> {
|
||||
public GroupListNodes() {
|
||||
super("listnodes", "Lists the permission nodes the group has", "/%s group <group> listnodes",
|
||||
@ -40,8 +38,8 @@ public class GroupListNodes extends SubCommand<Group> {
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
Message.LISTNODES.send(sender, group.getName(), Util.permNodesToString(exportToLegacy(group.getPermanentNodes())));
|
||||
Message.LISTNODES_TEMP.send(sender, group.getName(), Util.tempNodesToString(group.getTemporaryNodesLegacy()));
|
||||
Message.LISTNODES.send(sender, group.getName(), Util.permNodesToString(group.getPermissions()));
|
||||
Message.LISTNODES_TEMP.send(sender, group.getName(), Util.tempNodesToString(group.getPermissions()));
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -30,8 +30,6 @@ import me.lucko.luckperms.users.User;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static me.lucko.luckperms.core.PermissionHolder.exportToLegacy;
|
||||
|
||||
public class UserListNodes extends SubCommand<User> {
|
||||
public UserListNodes() {
|
||||
super("listnodes", "Lists the permission nodes the user has", "/%s user <user> listnodes",
|
||||
@ -40,8 +38,8 @@ public class UserListNodes extends SubCommand<User> {
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
Message.LISTNODES.send(sender, user.getName(), Util.permNodesToString(exportToLegacy(user.getPermanentNodes())));
|
||||
Message.LISTNODES_TEMP.send(sender, user.getName(), Util.tempNodesToString(user.getTemporaryNodesLegacy()));
|
||||
Message.LISTNODES.send(sender, user.getName(), Util.permNodesToString(user.getPermissions()));
|
||||
Message.LISTNODES_TEMP.send(sender, user.getName(), Util.tempNodesToString(user.getPermissions()));
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user