mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-24 11:38:40 +01:00
Automatically sort YAML/JSON storage - closes #113
This commit is contained in:
parent
a23f995717
commit
773bfe1407
@ -40,7 +40,7 @@ import java.util.Locale;
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class PriorityComparator implements Comparator<LocalizedNode> {
|
||||
private static final PriorityComparator INSTANCE = new PriorityComparator();
|
||||
public static Comparator<LocalizedNode> get() {
|
||||
public static PriorityComparator get() {
|
||||
return INSTANCE;
|
||||
}
|
||||
public static Comparator<LocalizedNode> reverse() {
|
||||
@ -97,14 +97,17 @@ public class PriorityComparator implements Comparator<LocalizedNode> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -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<String, Boolean> exportToLegacy(Set<Node> nodes) {
|
||||
Map<String, Boolean> m = new HashMap<>();
|
||||
Map<String, Boolean> m = new TreeMap<>((o1, o2) -> PriorityComparator.get().compareStrings(o1, o2));
|
||||
for (Node node : nodes) {
|
||||
m.put(node.toSerializedNode(), node.getValue());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user