Implement group weights

This commit is contained in:
Luck 2016-11-05 09:04:26 +00:00
parent e15d03ed4e
commit 5361b1e87b
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
7 changed files with 45 additions and 2 deletions

View File

@ -67,6 +67,11 @@ apply-regex: true
# If set to true, LuckPerms will detect and expand shorthand node patterns.
apply-shorthand: true
# Define special group weights for this server.
# Default is just 0.
group-weight:
# admin: 10

View File

@ -77,6 +77,11 @@ apply-regex: true
# If set to true, LuckPerms will detect and expand shorthand node patterns.
apply-shorthand: true
# Define special group weights for this server.
# Default is just 0.
group-weight:
# admin: 10

View File

@ -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);

View File

@ -62,6 +62,8 @@ public interface LPConfiguration {
boolean isApplyingShorthand();
Map<String, Integer> getGroupWeights();
boolean isLogNotify();
boolean isOpsEnabled();

View File

@ -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;

View File

@ -34,6 +34,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@ -118,6 +119,7 @@ class SpongeConfig extends AbstractConfiguration<LPSpongePlugin> {
return node.getChildrenList().stream().map(n -> (String) n.getKey()).collect(Collectors.toList());
}
@SuppressWarnings("unchecked")
@Override
protected Map<String, String> getMap(String path, Map<String, String> def) {
ConfigurationNode node = getNode(path);
@ -125,6 +127,7 @@ class SpongeConfig extends AbstractConfiguration<LPSpongePlugin> {
return def;
}
return node.getChildrenList().stream().collect(Collectors.toMap(n -> (String) n.getKey(), ConfigurationNode::getString));
Map<String, Object> m = (Map<String, Object>) node.getValue(Collections.emptyMap());
return m.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, v -> v.getValue().toString()));
}
}

View File

@ -75,6 +75,12 @@ apply-regex=true
# If set to true, LuckPerms will detect and expand shorthand node patterns.
apply-shorthand=true
# Define special group weights for this server.
# Default is just 0.
group-weight {
# admin=10
}