Refactor meta accumulation

This commit is contained in:
Luck 2016-11-07 19:01:15 +00:00
parent d320679f69
commit 0c33b26fa9
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
2 changed files with 25 additions and 26 deletions

View File

@ -24,6 +24,7 @@ package me.lucko.luckperms.common.caching;
import lombok.Getter; import lombok.Getter;
import lombok.ToString; import lombok.ToString;
import me.lucko.luckperms.api.Node;
import java.util.*; import java.util.*;
@ -38,4 +39,27 @@ public class MetaHolder {
private final SortedMap<Integer, String> prefixes = new TreeMap<>(Comparator.reverseOrder()); private final SortedMap<Integer, String> prefixes = new TreeMap<>(Comparator.reverseOrder());
private final SortedMap<Integer, String> suffixes = new TreeMap<>(Comparator.reverseOrder()); private final SortedMap<Integer, String> suffixes = new TreeMap<>(Comparator.reverseOrder());
public void accumulateNode(Node n) {
if (n.isMeta()) {
Map.Entry<String, String> entry = n.getMeta();
if (!meta.containsKey(entry.getKey())) {
meta.put(entry.getKey(), entry.getValue());
}
}
if (n.isPrefix()) {
Map.Entry<Integer, String> value = n.getPrefix();
if (!prefixes.containsKey(value.getKey())) {
prefixes.put(value.getKey(), value.getValue());
}
}
if (n.isSuffix()) {
Map.Entry<Integer, String> value = n.getSuffix();
if (!suffixes.containsKey(value.getKey())) {
suffixes.put(value.getKey(), value.getValue());
}
}
}
} }

View File

@ -220,8 +220,6 @@ public abstract class PermissionHolder {
it.remove(); it.remove();
} }
} }
} }
if (work) { if (work) {
@ -309,29 +307,6 @@ public abstract class PermissionHolder {
return all; return all;
} }
private static void accumulateMetaNode(Node n, MetaHolder holder) {
if (n.isPrefix()) {
Map.Entry<Integer, String> value = n.getPrefix();
if (!holder.getPrefixes().containsKey(value.getKey())) {
holder.getPrefixes().put(value.getKey(), value.getValue());
}
}
if (n.isSuffix()) {
Map.Entry<Integer, String> value = n.getSuffix();
if (!holder.getSuffixes().containsKey(value.getKey())) {
holder.getSuffixes().put(value.getKey(), value.getValue());
}
}
if (n.isMeta()) {
Map.Entry<String, String> meta = n.getMeta();
if (!holder.getMeta().containsKey(meta.getKey())) {
holder.getMeta().put(meta.getKey(), meta.getValue());
}
}
}
public MetaHolder accumulateMeta(MetaHolder holder, List<String> excludedGroups, Contexts context) { public MetaHolder accumulateMeta(MetaHolder holder, List<String> excludedGroups, Contexts context) {
if (holder == null) { if (holder == null) {
holder = new MetaHolder(); holder = new MetaHolder();
@ -359,7 +334,7 @@ public abstract class PermissionHolder {
if (!n.shouldApplyOnWorld(world, context.isIncludeGlobalWorld(), false)) continue; if (!n.shouldApplyOnWorld(world, context.isIncludeGlobalWorld(), false)) continue;
if (!n.shouldApplyWithContext(contexts, false)) continue; if (!n.shouldApplyWithContext(contexts, false)) continue;
accumulateMetaNode(n, holder); holder.accumulateNode(n);
} }
Set<Node> parents = all.stream() Set<Node> parents = all.stream()