mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-28 05:35:26 +01:00
Implement group weights
This commit is contained in:
parent
e15d03ed4e
commit
5361b1e87b
@ -67,6 +67,11 @@ apply-regex: true
|
|||||||
# If set to true, LuckPerms will detect and expand shorthand node patterns.
|
# If set to true, LuckPerms will detect and expand shorthand node patterns.
|
||||||
apply-shorthand: true
|
apply-shorthand: true
|
||||||
|
|
||||||
|
# Define special group weights for this server.
|
||||||
|
# Default is just 0.
|
||||||
|
group-weight:
|
||||||
|
# admin: 10
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -77,6 +77,11 @@ apply-regex: true
|
|||||||
# If set to true, LuckPerms will detect and expand shorthand node patterns.
|
# If set to true, LuckPerms will detect and expand shorthand node patterns.
|
||||||
apply-shorthand: true
|
apply-shorthand: true
|
||||||
|
|
||||||
|
# Define special group weights for this server.
|
||||||
|
# Default is just 0.
|
||||||
|
group-weight:
|
||||||
|
# admin: 10
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,6 +59,7 @@ public abstract class AbstractConfiguration<T extends LuckPermsPlugin> implement
|
|||||||
private boolean applyingWildcards;
|
private boolean applyingWildcards;
|
||||||
private boolean applyingRegex;
|
private boolean applyingRegex;
|
||||||
private boolean applyingShorthand;
|
private boolean applyingShorthand;
|
||||||
|
private Map<String, Integer> groupWeights;
|
||||||
private boolean logNotify;
|
private boolean logNotify;
|
||||||
private boolean opsEnabled;
|
private boolean opsEnabled;
|
||||||
private boolean commandsAllowOp;
|
private boolean commandsAllowOp;
|
||||||
@ -109,6 +110,14 @@ public abstract class AbstractConfiguration<T extends LuckPermsPlugin> implement
|
|||||||
applyingWildcards = getBoolean("apply-wildcards", true);
|
applyingWildcards = getBoolean("apply-wildcards", true);
|
||||||
applyingRegex = getBoolean("apply-regex", true);
|
applyingRegex = getBoolean("apply-regex", true);
|
||||||
applyingShorthand = getBoolean("apply-shorthand", 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);
|
logNotify = getBoolean("log-notify", true);
|
||||||
autoOp = getBoolean("auto-op", false);
|
autoOp = getBoolean("auto-op", false);
|
||||||
opsEnabled = !isAutoOp() && getBoolean("enable-ops", true);
|
opsEnabled = !isAutoOp() && getBoolean("enable-ops", true);
|
||||||
|
@ -62,6 +62,8 @@ public interface LPConfiguration {
|
|||||||
|
|
||||||
boolean isApplyingShorthand();
|
boolean isApplyingShorthand();
|
||||||
|
|
||||||
|
Map<String, Integer> getGroupWeights();
|
||||||
|
|
||||||
boolean isLogNotify();
|
boolean isLogNotify();
|
||||||
|
|
||||||
boolean isOpsEnabled();
|
boolean isOpsEnabled();
|
||||||
|
@ -25,6 +25,7 @@ package me.lucko.luckperms.common.core;
|
|||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.ImmutableSortedSet;
|
import com.google.common.collect.ImmutableSortedSet;
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.RequiredArgsConstructor;
|
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.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.api.internal.GroupLink;
|
import me.lucko.luckperms.common.api.internal.GroupLink;
|
||||||
import me.lucko.luckperms.common.api.internal.PermissionHolderLink;
|
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.groups.Group;
|
||||||
import me.lucko.luckperms.common.utils.Cache;
|
import me.lucko.luckperms.common.utils.Cache;
|
||||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||||
@ -263,7 +265,18 @@ public abstract class PermissionHolder {
|
|||||||
!node.shouldApplyWithContext(contexts, false)
|
!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());
|
Group group = plugin.getGroupManager().get(parent.getGroupName());
|
||||||
if (group == null) {
|
if (group == null) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -34,6 +34,7 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
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());
|
return node.getChildrenList().stream().map(n -> (String) n.getKey()).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
protected Map<String, String> getMap(String path, Map<String, String> def) {
|
protected Map<String, String> getMap(String path, Map<String, String> def) {
|
||||||
ConfigurationNode node = getNode(path);
|
ConfigurationNode node = getNode(path);
|
||||||
@ -125,6 +127,7 @@ class SpongeConfig extends AbstractConfiguration<LPSpongePlugin> {
|
|||||||
return def;
|
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()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,6 +75,12 @@ apply-regex=true
|
|||||||
# If set to true, LuckPerms will detect and expand shorthand node patterns.
|
# If set to true, LuckPerms will detect and expand shorthand node patterns.
|
||||||
apply-shorthand=true
|
apply-shorthand=true
|
||||||
|
|
||||||
|
# Define special group weights for this server.
|
||||||
|
# Default is just 0.
|
||||||
|
group-weight {
|
||||||
|
# admin=10
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user