diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultPermissionHook.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultPermissionHook.java index 55c9b6864..186eff99f 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultPermissionHook.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultPermissionHook.java @@ -220,7 +220,7 @@ public class VaultPermissionHook extends AbstractVaultPermission { String value = user.getPrimaryGroup().getValue(); Group group = getGroup(value); if (group != null) { - return group.getDisplayName().orElse(group.getName()); + value = group.getDisplayName().orElse(group.getName()); } if (log()) { diff --git a/common/src/main/java/me/lucko/luckperms/common/node/NodeFactory.java b/common/src/main/java/me/lucko/luckperms/common/node/NodeFactory.java index e7f8f6fe0..820f00890 100644 --- a/common/src/main/java/me/lucko/luckperms/common/node/NodeFactory.java +++ b/common/src/main/java/me/lucko/luckperms/common/node/NodeFactory.java @@ -210,12 +210,23 @@ public class NodeFactory { } public static String nodeAsCommand(Node node, String id, HolderType type, boolean set) { - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(32); sb.append(type.toString()).append(" ").append(id).append(" "); if (node.isGroupNode()) { - sb.append(node.isTemporary() ? (set ? "parent addtemp " : "parent removetemp ") : (set ? "parent add " : "parent remove ")); - sb.append(node.getGroupName()); + sb.append("parent "); + + if (set) { + sb.append("add"); + } else { + sb.append("remove"); + } + + if (node.isTemporary()) { + sb.append("temp"); + } + + sb.append(" ").append(node.getGroupName()); if (node.isTemporary() && set) { sb.append(" ").append(node.getExpiryUnixTime()); @@ -225,17 +236,33 @@ public class NodeFactory { } if (node.getValuePrimitive() && (node.isPrefix() || node.isSuffix())) { - ChatMetaType nodeType = node.isPrefix() ? ChatMetaType.PREFIX : ChatMetaType.SUFFIX; - String typeName = type.name().toLowerCase(); + ChatMetaType chatMetaType = node.isPrefix() ? ChatMetaType.PREFIX : ChatMetaType.SUFFIX; - sb.append(node.isTemporary() ? (set ? "meta addtemp" + typeName + " " : "meta removetemp" + typeName + " ") : (set ? "meta add" + typeName + " " : "meta remove" + typeName + " ")); - sb.append(nodeType.getEntry(node).getKey()).append(" "); + sb.append("meta "); - if (nodeType.getEntry(node).getValue().contains(" ")) { - sb.append("\"").append(nodeType.getEntry(node).getValue()).append("\""); + if (set) { + sb.append("add"); } else { - sb.append(nodeType.getEntry(node).getValue()); + sb.append("remove"); } + + if (node.isTemporary()) { + sb.append("temp"); + } + + sb.append(chatMetaType) + .append(" ") + .append(chatMetaType.getEntry(node).getKey()) // weight + .append(" "); + + String value = chatMetaType.getEntry(node).getValue(); + if (value.contains(" ")) { + // wrap value in quotes + sb.append("\"").append(value).append("\""); + } else { + sb.append(value); + } + if (set && node.isTemporary()) { sb.append(" ").append(node.getExpiryUnixTime()); } @@ -244,21 +271,36 @@ public class NodeFactory { } if (node.getValuePrimitive() && node.isMeta()) { - sb.append(node.isTemporary() ? (set ? "meta settemp " : "meta unsettemp ") : (set ? "meta set " : "meta unset ")); + sb.append("meta "); - if (node.getMeta().getKey().contains(" ")) { - sb.append("\"").append(node.getMeta().getKey()).append("\""); + if (set) { + sb.append("set"); } else { - sb.append(node.getMeta().getKey()); + sb.append("unset"); + } + + if (node.isTemporary()) { + sb.append("temp"); + } + + sb.append(" "); + + + String key = node.getMeta().getKey(); + if (key.contains(" ")) { + sb.append("\"").append(key).append("\""); + } else { + sb.append(key); } if (set) { sb.append(" "); - if (node.getMeta().getValue().contains(" ")) { - sb.append("\"").append(node.getMeta().getValue()).append("\""); + String value = node.getMeta().getValue(); + if (value.contains(" ")) { + sb.append("\"").append(value).append("\""); } else { - sb.append(node.getMeta().getValue()); + sb.append(value); } if (node.isTemporary()) { @@ -269,11 +311,25 @@ public class NodeFactory { return appendContextToCommand(sb, node).toString(); } - sb.append(node.isTemporary() ? (set ? "permission settemp " : "permission unsettemp ") : (set ? "permission set " : "permission unset ")); - if (node.getPermission().contains(" ")) { - sb.append("\"").append(node.getPermission()).append("\""); + sb.append("permission "); + + if (set) { + sb.append("set"); } else { - sb.append(node.getPermission()); + sb.append("unset"); + } + + if (node.isTemporary()) { + sb.append("temp"); + } + + sb.append(" "); + + String perm = node.getPermission(); + if (perm.contains(" ")) { + sb.append("\"").append(perm).append("\""); + } else { + sb.append(perm); } if (set) { sb.append(" ").append(node.getValuePrimitive()); @@ -287,10 +343,10 @@ public class NodeFactory { } private static StringBuilder appendContextToCommand(StringBuilder sb, Node node) { - if (node.isServerSpecific()) { + if (node.getServer().isPresent()) { sb.append(" server=").append(node.getServer().get()); } - if (node.isWorldSpecific()) { + if (node.getWorld().isPresent()) { sb.append(" world=").append(node.getWorld().get()); } @@ -311,7 +367,7 @@ public class NodeFactory { } public static Map.Entry parseMetaNode(String s) { - if (!s.startsWith(META_NODE_MARKER)) { + if (!s.toLowerCase().startsWith(META_NODE_MARKER)) { return null; } @@ -327,7 +383,7 @@ public class NodeFactory { } private static Map.Entry parseChatMetaNode(String marker, String s) { - if (!s.startsWith(marker)) { + if (!s.toLowerCase().startsWith(marker)) { return null; }