diff --git a/common/src/main/java/me/lucko/luckperms/common/core/PriorityComparator.java b/common/src/main/java/me/lucko/luckperms/common/core/PriorityComparator.java index 63ef62eac..265f2cab9 100644 --- a/common/src/main/java/me/lucko/luckperms/common/core/PriorityComparator.java +++ b/common/src/main/java/me/lucko/luckperms/common/core/PriorityComparator.java @@ -40,7 +40,7 @@ import java.util.Locale; @NoArgsConstructor(access = AccessLevel.PRIVATE) public class PriorityComparator implements Comparator { private static final PriorityComparator INSTANCE = new PriorityComparator(); - public static Comparator get() { + public static PriorityComparator get() { return INSTANCE; } public static Comparator reverse() { @@ -97,14 +97,17 @@ public class PriorityComparator implements Comparator { return o1.getWildcardLevel() > o2.getWildcardLevel() ? 1 : -1; } + return compareStrings(o1.getPermission(), o2.getPermission()) == 1 ? -1 : 1; + } + + public int compareStrings(String o1, String o2) { try { - CollationKey o1c = collationKeyCache.get(o1.getPermission()); - CollationKey o2c = collationKeyCache.get(o2.getPermission()); - return o1c.compareTo(o2c) == 1 ? -1 : 1; + CollationKey o1c = collationKeyCache.get(o1); + CollationKey o2c = collationKeyCache.get(o2); + return o1c.compareTo(o2c) == 1 ? 1 : -1; } catch (Exception e) { // ignored } - return 1; } } diff --git a/common/src/main/java/me/lucko/luckperms/common/core/model/PermissionHolder.java b/common/src/main/java/me/lucko/luckperms/common/core/model/PermissionHolder.java index 4f67d03ab..3f8a93706 100644 --- a/common/src/main/java/me/lucko/luckperms/common/core/model/PermissionHolder.java +++ b/common/src/main/java/me/lucko/luckperms/common/core/model/PermissionHolder.java @@ -75,6 +75,7 @@ import java.util.Optional; import java.util.OptionalInt; import java.util.Set; import java.util.SortedSet; +import java.util.TreeMap; import java.util.TreeSet; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; @@ -1166,7 +1167,7 @@ public abstract class PermissionHolder { } public static Map exportToLegacy(Set nodes) { - Map m = new HashMap<>(); + Map m = new TreeMap<>((o1, o2) -> PriorityComparator.get().compareStrings(o1, o2)); for (Node node : nodes) { m.put(node.toSerializedNode(), node.getValue()); }