mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-28 13:45:20 +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)
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
public class PriorityComparator implements Comparator<LocalizedNode> {
|
public class PriorityComparator implements Comparator<LocalizedNode> {
|
||||||
private static final PriorityComparator INSTANCE = new PriorityComparator();
|
private static final PriorityComparator INSTANCE = new PriorityComparator();
|
||||||
public static Comparator<LocalizedNode> get() {
|
public static PriorityComparator get() {
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
public static Comparator<LocalizedNode> reverse() {
|
public static Comparator<LocalizedNode> reverse() {
|
||||||
@ -97,14 +97,17 @@ public class PriorityComparator implements Comparator<LocalizedNode> {
|
|||||||
return o1.getWildcardLevel() > o2.getWildcardLevel() ? 1 : -1;
|
return o1.getWildcardLevel() > o2.getWildcardLevel() ? 1 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return compareStrings(o1.getPermission(), o2.getPermission()) == 1 ? -1 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int compareStrings(String o1, String o2) {
|
||||||
try {
|
try {
|
||||||
CollationKey o1c = collationKeyCache.get(o1.getPermission());
|
CollationKey o1c = collationKeyCache.get(o1);
|
||||||
CollationKey o2c = collationKeyCache.get(o2.getPermission());
|
CollationKey o2c = collationKeyCache.get(o2);
|
||||||
return o1c.compareTo(o2c) == 1 ? -1 : 1;
|
return o1c.compareTo(o2c) == 1 ? 1 : -1;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// ignored
|
// ignored
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,6 +75,7 @@ import java.util.Optional;
|
|||||||
import java.util.OptionalInt;
|
import java.util.OptionalInt;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
|
import java.util.TreeMap;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@ -1166,7 +1167,7 @@ public abstract class PermissionHolder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Map<String, Boolean> exportToLegacy(Set<Node> nodes) {
|
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) {
|
for (Node node : nodes) {
|
||||||
m.put(node.toSerializedNode(), node.getValue());
|
m.put(node.toSerializedNode(), node.getValue());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user