mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-27 21:29:47 +01:00
Slightly optimize weight and display name lookups
This commit is contained in:
parent
45188c6334
commit
97d1deec9c
@ -72,11 +72,7 @@ public class MetaInfo extends GenericChildCommand {
|
||||
Set<MetaNode> meta = new LinkedHashSet<>();
|
||||
|
||||
// Collect data
|
||||
for (Node node : target.resolveInheritedNodes(QueryOptionsImpl.DEFAULT_NON_CONTEXTUAL)) {
|
||||
if (!NodeType.META_OR_CHAT_META.matches(node)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (Node node : target.resolveInheritedNodes(NodeType.META_OR_CHAT_META, QueryOptionsImpl.DEFAULT_NON_CONTEXTUAL)) {
|
||||
if (node instanceof PrefixNode) {
|
||||
PrefixNode pn = (PrefixNode) node;
|
||||
prefixes.add(Maps.immutableEntry(pn.getPriority(), pn));
|
||||
|
@ -34,7 +34,7 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.luckperms.api.node.Node;
|
||||
import net.luckperms.api.node.NodeType;
|
||||
import net.luckperms.api.node.types.DisplayNameNode;
|
||||
import net.luckperms.api.query.QueryOptions;
|
||||
|
||||
@ -137,11 +137,8 @@ public class Group extends PermissionHolder {
|
||||
|
||||
public Optional<String> calculateDisplayName(QueryOptions queryOptions) {
|
||||
// query for a displayname node
|
||||
for (Node n : getOwnNodes(queryOptions)) {
|
||||
if (n instanceof DisplayNameNode) {
|
||||
DisplayNameNode displayNameNode = (DisplayNameNode) n;
|
||||
return Optional.of(displayNameNode.getDisplayName());
|
||||
}
|
||||
for (DisplayNameNode n : getOwnNodes(NodeType.DISPLAY_NAME, queryOptions)) {
|
||||
return Optional.of(n.getDisplayName());
|
||||
}
|
||||
|
||||
// fallback to config
|
||||
|
@ -29,7 +29,7 @@ import me.lucko.luckperms.common.cache.Cache;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.query.QueryOptionsImpl;
|
||||
|
||||
import net.luckperms.api.node.Node;
|
||||
import net.luckperms.api.node.NodeType;
|
||||
import net.luckperms.api.node.types.WeightNode;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
@ -50,29 +50,25 @@ public class WeightCache extends Cache<OptionalInt> {
|
||||
@Override
|
||||
protected @NonNull OptionalInt supply() {
|
||||
boolean seen = false;
|
||||
int best = 0;
|
||||
for (Node n : this.group.getOwnNodes(QueryOptionsImpl.DEFAULT_NON_CONTEXTUAL)) {
|
||||
if (n instanceof WeightNode) {
|
||||
WeightNode weightNode = (WeightNode) n;
|
||||
int value = weightNode.getWeight();
|
||||
int weight = 0;
|
||||
|
||||
if (!seen || value > best) {
|
||||
for (WeightNode n : this.group.getOwnNodes(NodeType.WEIGHT, QueryOptionsImpl.DEFAULT_NON_CONTEXTUAL)) {
|
||||
int value = n.getWeight();
|
||||
if (!seen || value > weight) {
|
||||
seen = true;
|
||||
best = value;
|
||||
}
|
||||
weight = value;
|
||||
}
|
||||
}
|
||||
|
||||
OptionalInt weight = seen ? OptionalInt.of(best) : OptionalInt.empty();
|
||||
|
||||
if (!weight.isPresent()) {
|
||||
if (!seen) {
|
||||
Map<String, Integer> configWeights = this.group.getPlugin().getConfiguration().get(ConfigKeys.GROUP_WEIGHTS);
|
||||
Integer w = configWeights.get(this.group.getObjectName().toLowerCase());
|
||||
if (w != null) {
|
||||
weight = OptionalInt.of(w);
|
||||
Integer value = configWeights.get(this.group.getObjectName().toLowerCase());
|
||||
if (value != null) {
|
||||
seen = true;
|
||||
weight = value;
|
||||
}
|
||||
}
|
||||
|
||||
return weight;
|
||||
return seen ? OptionalInt.of(weight) : OptionalInt.empty();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user