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