Properly implement Contexts#allowAll - bump API to 3.3
This commit is contained in:
@@ -53,6 +53,7 @@ import me.lucko.luckperms.common.messaging.NoopMessagingService;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.references.UserIdentifier;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
@@ -87,7 +88,7 @@ public class ApiProvider implements LuckPermsApi {
|
||||
|
||||
@Override
|
||||
public double getApiVersion() {
|
||||
return 3.2;
|
||||
return 3.3;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -231,4 +232,20 @@ public class ApiProvider implements LuckPermsApi {
|
||||
public ContextSet getContextForPlayer(@NonNull Object player) {
|
||||
return plugin.getContextManager().getApplicableContext(player);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Contexts getContextsForPlayer(@NonNull Object player) {
|
||||
return plugin.getContextManager().getApplicableContexts(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UUID> getUniqueConnections() {
|
||||
return Collections.unmodifiableSet(plugin.getUniqueConnections());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getStartTime() {
|
||||
return plugin.getStartTime();
|
||||
}
|
||||
}
|
||||
|
||||
+24
-3
@@ -25,10 +25,9 @@
|
||||
|
||||
package me.lucko.luckperms.common.api.delegates;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.api.LPConfiguration;
|
||||
import me.lucko.luckperms.api.data.DatastoreConfiguration;
|
||||
import me.lucko.luckperms.common.config.ConfigKey;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.config.LuckPermsConfiguration;
|
||||
|
||||
@@ -37,9 +36,14 @@ import java.util.Map;
|
||||
/**
|
||||
* Provides a link between {@link LPConfiguration} and {@link LuckPermsConfiguration}
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
public class LPConfigurationDelegate implements LPConfiguration {
|
||||
private final LuckPermsConfiguration handle;
|
||||
private final Unsafe unsafe;
|
||||
|
||||
public LPConfigurationDelegate(LuckPermsConfiguration handle) {
|
||||
this.handle = handle;
|
||||
this.unsafe = new UnsafeImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServer() {
|
||||
@@ -140,4 +144,21 @@ public class LPConfigurationDelegate implements LPConfiguration {
|
||||
public Map<String, String> getSplitStorageOptions() {
|
||||
return handle.get(ConfigKeys.SPLIT_STORAGE_OPTIONS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Unsafe unsafe() {
|
||||
return unsafe;
|
||||
}
|
||||
|
||||
private final class UnsafeImpl implements Unsafe {
|
||||
|
||||
@Override
|
||||
public Object getObject(String key) {
|
||||
ConfigKey<?> configKey = ConfigKeys.getAllKeys().get(key.toUpperCase());
|
||||
if (configKey == null) {
|
||||
throw new IllegalArgumentException("Unknown key: " + key);
|
||||
}
|
||||
return handle.get(configKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+33
@@ -29,6 +29,7 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSetMultimap;
|
||||
import com.google.common.collect.ImmutableSortedSet;
|
||||
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
@@ -38,6 +39,7 @@ import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.api.PermissionHolder;
|
||||
import me.lucko.luckperms.api.Tristate;
|
||||
import me.lucko.luckperms.api.context.ContextSet;
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.api.context.MutableContextSet;
|
||||
import me.lucko.luckperms.common.contexts.ExtractedContexts;
|
||||
import me.lucko.luckperms.common.model.User;
|
||||
@@ -47,6 +49,7 @@ import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
@@ -72,6 +75,21 @@ public class PermissionHolderDelegate implements PermissionHolder {
|
||||
return handle.getFriendlyName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableSetMultimap<ImmutableContextSet, Node> getNodes() {
|
||||
return handle.getEnduringNodes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableSetMultimap<ImmutableContextSet, Node> getTransientNodes() {
|
||||
return handle.getTransientNodes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Node> getOwnNodes() {
|
||||
return handle.getOwnNodes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedSet<? extends Node> getPermissions() {
|
||||
return ImmutableSortedSet.copyOfSorted(handle.getOwnNodesSorted());
|
||||
@@ -92,6 +110,11 @@ public class PermissionHolderDelegate implements PermissionHolder {
|
||||
return new TreeSet<>(handle.resolveInheritancesAlmostEqual(ExtractedContexts.generate(contexts)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedSet<LocalizedNode> getAllNodes() {
|
||||
return new TreeSet<>(handle.resolveInheritancesAlmostEqual());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<LocalizedNode> getAllNodesFiltered(@NonNull Contexts contexts) {
|
||||
return new HashSet<>(handle.getAllNodes(ExtractedContexts.generate(contexts)));
|
||||
@@ -412,6 +435,16 @@ public class PermissionHolderDelegate implements PermissionHolder {
|
||||
return handle.getTemporaryNodes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LocalizedNode> resolveInheritances(Contexts contexts) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LocalizedNode> resolveInheritances() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Node> getPermanentPermissionNodes() {
|
||||
return handle.getPermanentNodes();
|
||||
|
||||
@@ -86,14 +86,26 @@ public class UserCache implements UserData {
|
||||
@Override
|
||||
public PermissionCache calculatePermissions(@NonNull Contexts contexts) {
|
||||
PermissionCache data = new PermissionCache(contexts, user, user.getPlugin().getCalculatorFactory());
|
||||
data.setPermissions(user.exportNodesAndShorthand(ExtractedContexts.generate(contexts), true));
|
||||
|
||||
if (contexts == Contexts.allowAll()) {
|
||||
data.setPermissions(user.exportNodesAndShorthand(true));
|
||||
} else {
|
||||
data.setPermissions(user.exportNodesAndShorthand(ExtractedContexts.generate(contexts), true));
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaCache calculateMeta(@NonNull MetaContexts contexts) {
|
||||
MetaCache data = new MetaCache();
|
||||
data.loadMeta(user.accumulateMeta(newAccumulator(contexts), null, ExtractedContexts.generate(contexts.getContexts())));
|
||||
|
||||
if (contexts.getContexts() == Contexts.allowAll()) {
|
||||
data.loadMeta(user.accumulateMeta(newAccumulator(contexts), null));
|
||||
} else {
|
||||
data.loadMeta(user.accumulateMeta(newAccumulator(contexts), null, ExtractedContexts.generate(contexts.getContexts())));
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -169,7 +181,12 @@ public class UserCache implements UserData {
|
||||
|
||||
@Override
|
||||
public PermissionCache reload(Contexts contexts, PermissionCache oldData) {
|
||||
oldData.comparePermissions(user.exportNodesAndShorthand(ExtractedContexts.generate(contexts), true));
|
||||
if (contexts == Contexts.allowAll()) {
|
||||
oldData.comparePermissions(user.exportNodesAndShorthand(true));
|
||||
} else {
|
||||
oldData.comparePermissions(user.exportNodesAndShorthand(ExtractedContexts.generate(contexts), true));
|
||||
}
|
||||
|
||||
return oldData;
|
||||
}
|
||||
}
|
||||
@@ -182,7 +199,12 @@ public class UserCache implements UserData {
|
||||
|
||||
@Override
|
||||
public MetaCache reload(MetaContexts contexts, MetaCache oldData) {
|
||||
oldData.loadMeta(user.accumulateMeta(newAccumulator(contexts), null, ExtractedContexts.generate(contexts.getContexts())));
|
||||
if (contexts.getContexts() == Contexts.allowAll()) {
|
||||
oldData.loadMeta(user.accumulateMeta(newAccumulator(contexts), null));
|
||||
} else {
|
||||
oldData.loadMeta(user.accumulateMeta(newAccumulator(contexts), null, ExtractedContexts.generate(contexts.getContexts())));
|
||||
}
|
||||
|
||||
return oldData;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ public abstract class AbstractConfiguration implements LuckPermsConfiguration {
|
||||
|
||||
@Override
|
||||
public void loadAll() {
|
||||
ConfigKeys.getAllKeys().forEach(cache::get);
|
||||
ConfigKeys.getAllKeys().values().forEach(cache::get);
|
||||
contextsFile.load();
|
||||
}
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@ import me.lucko.luckperms.common.utils.ImmutableCollectors;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
@@ -420,16 +421,16 @@ public class ConfigKeys {
|
||||
*/
|
||||
public static final ConfigKey<String> WEB_EDITOR_URL_PATTERN = StringKey.of("web-editor-url", "https://lpedit.lucko.me/");
|
||||
|
||||
private static List<ConfigKey<?>> KEYS = null;
|
||||
private static Map<String, ConfigKey<?>> KEYS = null;
|
||||
|
||||
/**
|
||||
* Gets all of the possible config keys defined in this class
|
||||
*
|
||||
* @return all of the possible config keys defined in this class
|
||||
*/
|
||||
public static synchronized List<ConfigKey<?>> getAllKeys() {
|
||||
public static synchronized Map<String, ConfigKey<?>> getAllKeys() {
|
||||
if (KEYS == null) {
|
||||
ImmutableList.Builder<ConfigKey<?>> keys = ImmutableList.builder();
|
||||
Map<String, ConfigKey<?>> keys = new LinkedHashMap<>();
|
||||
|
||||
try {
|
||||
Field[] values = ConfigKeys.class.getFields();
|
||||
@@ -440,14 +441,14 @@ public class ConfigKeys {
|
||||
|
||||
Object val = f.get(null);
|
||||
if (val instanceof ConfigKey<?>) {
|
||||
keys.add((ConfigKey<?>) val);
|
||||
keys.put(f.getName(), (ConfigKey<?>) val);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
KEYS = keys.build();
|
||||
KEYS = ImmutableMap.copyOf(keys);
|
||||
}
|
||||
|
||||
return KEYS;
|
||||
|
||||
@@ -717,6 +717,27 @@ public abstract class PermissionHolder {
|
||||
return ImmutableMap.copyOf(perms);
|
||||
}
|
||||
|
||||
public Map<String, Boolean> exportNodesAndShorthand(boolean lowerCase) {
|
||||
List<LocalizedNode> entries = resolveInheritances();
|
||||
|
||||
Map<String, Boolean> perms = new HashMap<>();
|
||||
boolean applyShorthand = plugin.getConfiguration().get(ConfigKeys.APPLYING_SHORTHAND);
|
||||
for (Node node : entries) {
|
||||
String perm = lowerCase ? node.getPermission().toLowerCase() : node.getPermission();
|
||||
|
||||
if (perms.putIfAbsent(perm, node.getValue()) == null) {
|
||||
if (applyShorthand) {
|
||||
List<String> sh = node.resolveShorthand();
|
||||
if (!sh.isEmpty()) {
|
||||
sh.stream().map(s -> lowerCase ? s.toLowerCase() : s).forEach(s -> perms.putIfAbsent(s, node.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ImmutableMap.copyOf(perms);
|
||||
}
|
||||
|
||||
public MetaAccumulator accumulateMeta(MetaAccumulator accumulator, Set<String> excludedGroups, ExtractedContexts context) {
|
||||
if (accumulator == null) {
|
||||
accumulator = MetaAccumulator.makeFromConfig(plugin);
|
||||
|
||||
Reference in New Issue
Block a user