Include internal weight value in meta output if not already present
This commit is contained in:
parent
aa2941fcdb
commit
e9e844c1f7
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.common.caching;
|
package me.lucko.luckperms.common.caching;
|
||||||
|
|
||||||
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
|
||||||
@ -42,9 +43,11 @@ import java.util.TreeMap;
|
|||||||
@ToString
|
@ToString
|
||||||
public class MetaHolder {
|
public class MetaHolder {
|
||||||
|
|
||||||
|
@Getter(AccessLevel.NONE)
|
||||||
private final Map<String, String> meta;
|
private final Map<String, String> meta;
|
||||||
private final SortedMap<Integer, String> prefixes;
|
private final SortedMap<Integer, String> prefixes;
|
||||||
private final SortedMap<Integer, String> suffixes;
|
private final SortedMap<Integer, String> suffixes;
|
||||||
|
private int weight = 0;
|
||||||
|
|
||||||
private final MetaStack prefixStack;
|
private final MetaStack prefixStack;
|
||||||
private final MetaStack suffixStack;
|
private final MetaStack suffixStack;
|
||||||
@ -88,4 +91,18 @@ public class MetaHolder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void accumulateWeight(int weight) {
|
||||||
|
this.weight = Math.max(this.weight, weight);
|
||||||
|
}
|
||||||
|
|
||||||
|
// We can assume that if this method is being called, this holder is effectively finalized. (it's not going to accumulate more nodes)
|
||||||
|
// Therefore, it should be ok to set the weight meta key, if not already present.
|
||||||
|
public Map<String, String> getMeta() {
|
||||||
|
if (!this.meta.containsKey("weight") && this.weight != 0) {
|
||||||
|
this.meta.put("weight", String.valueOf(this.weight));
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.meta;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -460,10 +460,10 @@ public class Util {
|
|||||||
return sb.delete(sb.length() - 6, sb.length()).toString();
|
return sb.delete(sb.length() - 6, sb.length()).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class MetaComparator implements Comparator<Map.Entry<Integer, ? extends Node>> {
|
public static class MetaComparator implements Comparator<Map.Entry<Integer, ?>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compare(Map.Entry<Integer, ? extends Node> o1, Map.Entry<Integer, ? extends Node> o2) {
|
public int compare(Map.Entry<Integer, ?> o1, Map.Entry<Integer, ?> o2) {
|
||||||
int result = Integer.compare(o1.getKey(), o2.getKey());
|
int result = Integer.compare(o1.getKey(), o2.getKey());
|
||||||
return result != 0 ? result : 1;
|
return result != 0 ? result : 1;
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,6 @@ import me.lucko.luckperms.common.utils.WeightComparator;
|
|||||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -493,7 +492,7 @@ public abstract class PermissionHolder {
|
|||||||
return exportNodesCache.getUnchecked(ExportNodesHolder.of(context, lowerCase));
|
return exportNodesCache.getUnchecked(ExportNodesHolder.of(context, lowerCase));
|
||||||
}
|
}
|
||||||
|
|
||||||
public MetaHolder accumulateMeta(MetaHolder holder, List<String> excludedGroups, ExtractedContexts contexts) {
|
public MetaHolder accumulateMeta(MetaHolder holder, Set<String> excludedGroups, ExtractedContexts contexts) {
|
||||||
if (holder == null) {
|
if (holder == null) {
|
||||||
holder = new MetaHolder(
|
holder = new MetaHolder(
|
||||||
plugin.getConfiguration().get(ConfigKeys.PREFIX_FORMATTING_OPTIONS).copy(),
|
plugin.getConfiguration().get(ConfigKeys.PREFIX_FORMATTING_OPTIONS).copy(),
|
||||||
@ -502,7 +501,7 @@ public abstract class PermissionHolder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (excludedGroups == null) {
|
if (excludedGroups == null) {
|
||||||
excludedGroups = new ArrayList<>();
|
excludedGroups = new HashSet<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
excludedGroups.add(getObjectName().toLowerCase());
|
excludedGroups.add(getObjectName().toLowerCase());
|
||||||
@ -524,6 +523,11 @@ public abstract class PermissionHolder {
|
|||||||
holder.accumulateNode(ln);
|
holder.accumulateNode(ln);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OptionalInt w = getWeight();
|
||||||
|
if (w.isPresent()) {
|
||||||
|
holder.accumulateWeight(w.getAsInt());
|
||||||
|
}
|
||||||
|
|
||||||
Set<Node> parents = all.stream()
|
Set<Node> parents = all.stream()
|
||||||
.map(LocalizedNode::getNode)
|
.map(LocalizedNode::getNode)
|
||||||
.filter(Node::getValue)
|
.filter(Node::getValue)
|
||||||
@ -536,23 +540,10 @@ public abstract class PermissionHolder {
|
|||||||
!node.shouldApplyWithContext(contexts.getContextSet(), false)
|
!node.shouldApplyWithContext(contexts.getContextSet(), false)
|
||||||
);
|
);
|
||||||
|
|
||||||
TreeSet<Map.Entry<Integer, Node>> sortedParents = new TreeSet<>(Util.META_COMPARATOR.reversed());
|
TreeSet<Map.Entry<Integer, Group>> sortedParents = new TreeSet<>(Util.META_COMPARATOR.reversed());
|
||||||
for (Node node : parents) {
|
for (Node node : parents) {
|
||||||
Group group = plugin.getGroupManager().getIfLoaded(node.getGroupName());
|
Group group = plugin.getGroupManager().getIfLoaded(node.getGroupName());
|
||||||
if (group != null) {
|
|
||||||
OptionalInt weight = group.getWeight();
|
|
||||||
if (weight.isPresent()) {
|
|
||||||
sortedParents.add(Maps.immutableEntry(weight.getAsInt(), node));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sortedParents.add(Maps.immutableEntry(0, node));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Map.Entry<Integer, Node> e : sortedParents) {
|
|
||||||
Node parent = e.getValue();
|
|
||||||
Group group = plugin.getGroupManager().getIfLoaded(parent.getGroupName());
|
|
||||||
if (group == null) {
|
if (group == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -561,7 +552,11 @@ public abstract class PermissionHolder {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
group.accumulateMeta(holder, excludedGroups, contexts);
|
sortedParents.add(Maps.immutableEntry(group.getWeight().orElse(0), group));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Map.Entry<Integer, Group> e : sortedParents) {
|
||||||
|
e.getValue().accumulateMeta(holder, excludedGroups, contexts);
|
||||||
}
|
}
|
||||||
|
|
||||||
return holder;
|
return holder;
|
||||||
|
Loading…
Reference in New Issue
Block a user