Implement group weights

This commit is contained in:
Luck
2016-11-05 09:04:26 +00:00
Unverified
parent e15d03ed4e
commit 5361b1e87b
7 changed files with 45 additions and 2 deletions
@@ -59,6 +59,7 @@ public abstract class AbstractConfiguration<T extends LuckPermsPlugin> implement
private boolean applyingWildcards;
private boolean applyingRegex;
private boolean applyingShorthand;
private Map<String, Integer> groupWeights;
private boolean logNotify;
private boolean opsEnabled;
private boolean commandsAllowOp;
@@ -109,6 +110,14 @@ public abstract class AbstractConfiguration<T extends LuckPermsPlugin> implement
applyingWildcards = getBoolean("apply-wildcards", true);
applyingRegex = getBoolean("apply-regex", true);
applyingShorthand = getBoolean("apply-shorthand", true);
Map<String, String> weights = getMap("group-weight", Collections.emptyMap());
ImmutableMap.Builder<String, Integer> mb = ImmutableMap.builder();
for (Map.Entry<String, String> e : weights.entrySet()) {
try {
mb.put(e.getKey().toLowerCase(), Integer.parseInt(e.getValue()));
} catch (NumberFormatException ignored) {}
}
groupWeights = mb.build();
logNotify = getBoolean("log-notify", true);
autoOp = getBoolean("auto-op", false);
opsEnabled = !isAutoOp() && getBoolean("enable-ops", true);
@@ -62,6 +62,8 @@ public interface LPConfiguration {
boolean isApplyingShorthand();
Map<String, Integer> getGroupWeights();
boolean isLogNotify();
boolean isOpsEnabled();
@@ -25,6 +25,7 @@ package me.lucko.luckperms.common.core;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Maps;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@@ -37,6 +38,7 @@ import me.lucko.luckperms.api.event.events.*;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.api.internal.GroupLink;
import me.lucko.luckperms.common.api.internal.PermissionHolderLink;
import me.lucko.luckperms.common.commands.Util;
import me.lucko.luckperms.common.groups.Group;
import me.lucko.luckperms.common.utils.Cache;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
@@ -263,7 +265,18 @@ public abstract class PermissionHolder {
!node.shouldApplyWithContext(contexts, false)
);
for (Node parent : parents) {
TreeSet<Map.Entry<Integer, Node>> sortedParents = new TreeSet<>(Util.getMetaComparator().reversed());
Map<String, Integer> weights = plugin.getConfiguration().getGroupWeights();
for (Node node : parents) {
if (weights.containsKey(node.getGroupName().toLowerCase())) {
sortedParents.add(Maps.immutableEntry(weights.get(node.getGroupName().toLowerCase()), node));
} else {
sortedParents.add(Maps.immutableEntry(0, node));
}
}
for (Map.Entry<Integer, Node> e : sortedParents) {
Node parent = e.getValue();
Group group = plugin.getGroupManager().get(parent.getGroupName());
if (group == null) {
continue;