From 82466c2e5d78e28aee58e9db9aa492eb8aef5274 Mon Sep 17 00:00:00 2001 From: Luck Date: Sun, 13 Aug 2017 22:21:04 +0200 Subject: [PATCH] Properly implement Contexts#allowAll - bump API to 3.3 --- api/pom.xml | 2 +- .../java/me/lucko/luckperms/api/Contexts.java | 24 ++++- .../luckperms/api/FullySatisfiedContexts.java | 51 ++++++++++ .../lucko/luckperms/api/LPConfiguration.java | 20 ++++ .../me/lucko/luckperms/api/LuckPermsApi.java | 27 ++++++ .../lucko/luckperms/api/PermissionHolder.java | 92 +++++++++++++++++++ .../java/me/lucko/luckperms/api/User.java | 7 +- bukkit-legacy/pom.xml | 2 +- bukkit/pom.xml | 2 +- bungee/pom.xml | 2 +- common/pom.xml | 2 +- .../luckperms/common/api/ApiProvider.java | 19 +++- .../delegates/LPConfigurationDelegate.java | 27 +++++- .../delegates/PermissionHolderDelegate.java | 33 +++++++ .../luckperms/common/caching/UserCache.java | 30 +++++- .../common/config/AbstractConfiguration.java | 2 +- .../luckperms/common/config/ConfigKeys.java | 11 ++- .../common/model/PermissionHolder.java | 21 +++++ pom.xml | 4 +- sponge/pom.xml | 2 +- sponge/sponge-service-api6/pom.xml | 2 +- sponge/sponge-service-api7/pom.xml | 2 +- sponge/sponge-service/pom.xml | 2 +- 23 files changed, 353 insertions(+), 33 deletions(-) create mode 100644 api/src/main/java/me/lucko/luckperms/api/FullySatisfiedContexts.java diff --git a/api/pom.xml b/api/pom.xml index 6734571b8..4d62b8898 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -5,7 +5,7 @@ luckperms me.lucko.luckperms - 3.2-SNAPSHOT + 3.3-SNAPSHOT 4.0.0 diff --git a/api/src/main/java/me/lucko/luckperms/api/Contexts.java b/api/src/main/java/me/lucko/luckperms/api/Contexts.java index 2ea47dbbc..d21fe7b1c 100644 --- a/api/src/main/java/me/lucko/luckperms/api/Contexts.java +++ b/api/src/main/java/me/lucko/luckperms/api/Contexts.java @@ -39,16 +39,28 @@ import javax.annotation.Nonnull; public class Contexts { public static final String SERVER_KEY = "server"; public static final String WORLD_KEY = "world"; - private static final Contexts ALLOW_ALL = new Contexts(ContextSet.empty(), true, true, true, true, true, true); + + private static final Contexts GLOBAL = new Contexts(ContextSet.empty(), true, true, true, true, true, false); /** - * Gets a context that will allow all nodes + * Gets the {@link FullySatisfiedContexts} instance. * - * @return a context that will not apply any filters + * @return a context that will satisfy all contextual requirements. */ @Nonnull public static Contexts allowAll() { - return ALLOW_ALL; + return FullySatisfiedContexts.getInstance(); + } + + /** + * A contexts instance with no defined context. + * + * @return the global contexts + * @since 3.3 + */ + @Nonnull + public static Contexts global() { + return GLOBAL; } public static Contexts of(@Nonnull ContextSet context, boolean includeGlobal, boolean includeGlobalWorld, boolean applyGroups, boolean applyGlobalGroups, boolean applyGlobalWorldGroups, boolean op) { @@ -193,7 +205,9 @@ public class Contexts { @Override public boolean equals(Object o) { if (o == this) return true; + if (o == allowAll()) return false; if (!(o instanceof Contexts)) return false; + final Contexts other = (Contexts) o; return this.getContexts().equals(other.getContexts()) && this.isOp() == other.isOp() && @@ -209,7 +223,7 @@ public class Contexts { final int PRIME = 59; int result = 1; final Object contexts = this.getContexts(); - result = result * PRIME + (contexts == null ? 43 : contexts.hashCode()); + result = result * PRIME + contexts.hashCode(); result = result * PRIME + (this.isOp() ? 79 : 97); result = result * PRIME + (this.isIncludeGlobal() ? 79 : 97); result = result * PRIME + (this.isIncludeGlobalWorld() ? 79 : 97); diff --git a/api/src/main/java/me/lucko/luckperms/api/FullySatisfiedContexts.java b/api/src/main/java/me/lucko/luckperms/api/FullySatisfiedContexts.java new file mode 100644 index 000000000..55675744c --- /dev/null +++ b/api/src/main/java/me/lucko/luckperms/api/FullySatisfiedContexts.java @@ -0,0 +1,51 @@ +package me.lucko.luckperms.api; + +import me.lucko.luckperms.api.caching.MetaContexts; +import me.lucko.luckperms.api.caching.UserData; +import me.lucko.luckperms.api.context.ContextSet; + +import javax.annotation.Nonnull; + +/** + * A special instance of {@link Contexts}, which when passed to: + * + *

+ * + *

will always satisfy all contextual requirements.

+ * + *

This effectively allows you to do lookups which ignore context.

+ * + * @since 3.3 + */ +public final class FullySatisfiedContexts extends Contexts { + private static final FullySatisfiedContexts INSTANCE = new FullySatisfiedContexts(); + + @Nonnull + public static Contexts getInstance() { + return INSTANCE; + } + + private FullySatisfiedContexts() { + super(ContextSet.empty(), true, true, true, true, true, false); + } + + @Nonnull + @Override + public String toString() { + return "FullySatisfiedContexts"; + } + + @Override + public boolean equals(Object o) { + return o == this; + } + + @Override + public int hashCode() { + return System.identityHashCode(this); + } +} diff --git a/api/src/main/java/me/lucko/luckperms/api/LPConfiguration.java b/api/src/main/java/me/lucko/luckperms/api/LPConfiguration.java index a35abe1c8..07876b54a 100644 --- a/api/src/main/java/me/lucko/luckperms/api/LPConfiguration.java +++ b/api/src/main/java/me/lucko/luckperms/api/LPConfiguration.java @@ -173,4 +173,24 @@ public interface LPConfiguration { @Nonnull Map getSplitStorageOptions(); + @Nonnull + Unsafe unsafe(); + + interface Unsafe { + + /** + * Gets an Object from the config. + * + *

This method is nested under {@link Unsafe} because the keys + * and return types may change between versions without warning.

+ * + * @param key the key, as defined as a parameter name in + * the "ConfigKeys" class. + * @return the corresponding object, if one is present + * @throws IllegalArgumentException if the key isn't known + */ + @Nonnull + Object getObject(String key); + } + } diff --git a/api/src/main/java/me/lucko/luckperms/api/LuckPermsApi.java b/api/src/main/java/me/lucko/luckperms/api/LuckPermsApi.java index 643209fd9..dc2098815 100644 --- a/api/src/main/java/me/lucko/luckperms/api/LuckPermsApi.java +++ b/api/src/main/java/me/lucko/luckperms/api/LuckPermsApi.java @@ -328,4 +328,31 @@ public interface LuckPermsApi { @Nonnull ContextSet getContextForPlayer(@Nonnull Object player); + /** + * Gets a Contexts instance for the player using the platforms {@link ContextCalculator}s. + * + * @param player the player to calculate for. Must be the player instance for the platform. + * @return a set of contexts. + * @since 3.3 + */ + @Nonnull + Contexts getContextsForPlayer(@Nonnull Object player); + + /** + * Gets the unique players which have connected to the server since it started. + * + * @return the unique connections + * @since 3.3 + */ + @Nonnull + Set getUniqueConnections(); + + /** + * Gets the time when the plugin first started in milliseconds. + * + * @return the enable time + * @since 3.3 + */ + long getStartTime(); + } diff --git a/api/src/main/java/me/lucko/luckperms/api/PermissionHolder.java b/api/src/main/java/me/lucko/luckperms/api/PermissionHolder.java index 04083bddf..0d4f977f4 100644 --- a/api/src/main/java/me/lucko/luckperms/api/PermissionHolder.java +++ b/api/src/main/java/me/lucko/luckperms/api/PermissionHolder.java @@ -25,10 +25,15 @@ package me.lucko.luckperms.api; +import com.google.common.collect.ImmutableSetMultimap; +import com.google.common.collect.Multimap; + import me.lucko.luckperms.api.context.ContextSet; +import me.lucko.luckperms.api.context.ImmutableContextSet; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectLacksException; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.SortedSet; @@ -67,6 +72,47 @@ public interface PermissionHolder { @Nonnull String getFriendlyName(); + /** + * Gets the backing multimap containing every permission this holder has. + * + *

This method does not resolve inheritance rules, and returns a + * view of what's 'in the file'.

+ * + * @return the holders own permissions + * @since 3.3 + */ + @Nonnull + ImmutableSetMultimap getNodes(); + + /** + * Gets the backing multimap containing every transient permission this holder has. + * + *

This method does not resolve inheritance rules.

+ * + *

Transient permissions only exist for the duration of the session.

+ * + * @return the holders own permissions + * @since 3.3 + */ + @Nonnull + ImmutableSetMultimap getTransientNodes(); + + /** + * Gets a flattened/squashed view of the holders permissions. + * + *

This list is constructed using the {@link Multimap#values()} method + * of both the transient and enduring backing multimaps.

+ * + *

This means that it may contain duplicate entries.

+ * + *

Use {@link #getPermissions()} for a view without duplicates.

+ * + * @return a list of the holders own nodes. + * @since 3.3 + */ + @Nonnull + List getOwnNodes(); + /** * Gets a sorted set of all held permissions. * @@ -116,6 +162,38 @@ public interface PermissionHolder { @Nonnull Set getTemporaryPermissionNodes(); + /** + * Recursively resolves this holders permissions. + * + *

The returned list will contain every inherited + * node the holder has, in the order that they were inherited in.

+ * + *

This means the list will contain duplicates.

+ * + * @param contexts the contexts for the lookup + * @return a list of nodes + * @since 3.3 + */ + @Nonnull + List resolveInheritances(Contexts contexts); + + /** + * Recursively resolves this holders permissions. + * + *

The returned list will contain every inherited + * node the holder has, in the order that they were inherited in.

+ * + *

This means the list will contain duplicates.

+ * + *

Unlike {@link #resolveInheritances(Contexts)}, this method does not + * filter by context, at all.

+ * + * @return a list of nodes + * @since 3.3 + */ + @Nonnull + List resolveInheritances(); + /** * Gets a mutable sorted set of the nodes that this object has and inherits, filtered by context * @@ -132,6 +210,20 @@ public interface PermissionHolder { @Nonnull SortedSet getAllNodes(@Nonnull Contexts contexts); + /** + * Gets a mutable sorted set of the nodes that this object has and inherits. + * + *

Unlike {@link #getAllNodes(Contexts)}, this method does not filter by context, at all.

+ * + *

Nodes are sorted into priority order.

+ * + * @return a mutable sorted set of permissions + * @throws NullPointerException if the context is null + * @since 3.3 + */ + @Nonnull + SortedSet getAllNodes(); + /** * Gets a mutable set of the nodes that this object has and inherits, filtered by context. * diff --git a/api/src/main/java/me/lucko/luckperms/api/User.java b/api/src/main/java/me/lucko/luckperms/api/User.java index d87ba0c20..752003cfa 100644 --- a/api/src/main/java/me/lucko/luckperms/api/User.java +++ b/api/src/main/java/me/lucko/luckperms/api/User.java @@ -129,12 +129,13 @@ public interface User extends PermissionHolder { Optional getUserDataCache(); /** - * Sets up the users data cache, if the don't have one setup already. + * Pre-calculates some values in the user's data cache. + * + *

Is it not necessary to call this method before + * using {@link #getCachedData()}.

* * @since 2.17 - * @deprecated in version 3.2, as this cache is now always loaded. */ - @Deprecated void setupDataCache(); /** diff --git a/bukkit-legacy/pom.xml b/bukkit-legacy/pom.xml index b3c259ce3..a825fc0f5 100644 --- a/bukkit-legacy/pom.xml +++ b/bukkit-legacy/pom.xml @@ -5,7 +5,7 @@ luckperms me.lucko.luckperms - 3.2-SNAPSHOT + 3.3-SNAPSHOT 4.0.0 diff --git a/bukkit/pom.xml b/bukkit/pom.xml index b41239220..21450fb30 100644 --- a/bukkit/pom.xml +++ b/bukkit/pom.xml @@ -5,7 +5,7 @@ luckperms me.lucko.luckperms - 3.2-SNAPSHOT + 3.3-SNAPSHOT 4.0.0 diff --git a/bungee/pom.xml b/bungee/pom.xml index 528df5670..36d7698d5 100644 --- a/bungee/pom.xml +++ b/bungee/pom.xml @@ -5,7 +5,7 @@ luckperms me.lucko.luckperms - 3.2-SNAPSHOT + 3.3-SNAPSHOT 4.0.0 diff --git a/common/pom.xml b/common/pom.xml index e7c6bc45e..b45e4918c 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -5,7 +5,7 @@ luckperms me.lucko.luckperms - 3.2-SNAPSHOT + 3.3-SNAPSHOT 4.0.0 diff --git a/common/src/main/java/me/lucko/luckperms/common/api/ApiProvider.java b/common/src/main/java/me/lucko/luckperms/common/api/ApiProvider.java index 2fa8efbb5..2f194e4e5 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/ApiProvider.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/ApiProvider.java @@ -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 getUniqueConnections() { + return Collections.unmodifiableSet(plugin.getUniqueConnections()); + } + + @Override + public long getStartTime() { + return plugin.getStartTime(); + } } diff --git a/common/src/main/java/me/lucko/luckperms/common/api/delegates/LPConfigurationDelegate.java b/common/src/main/java/me/lucko/luckperms/common/api/delegates/LPConfigurationDelegate.java index c1348e557..930602f53 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/delegates/LPConfigurationDelegate.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/delegates/LPConfigurationDelegate.java @@ -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 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); + } + } } diff --git a/common/src/main/java/me/lucko/luckperms/common/api/delegates/PermissionHolderDelegate.java b/common/src/main/java/me/lucko/luckperms/common/api/delegates/PermissionHolderDelegate.java index 69927ba59..8e6d01492 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/delegates/PermissionHolderDelegate.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/delegates/PermissionHolderDelegate.java @@ -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 getNodes() { + return handle.getEnduringNodes(); + } + + @Override + public ImmutableSetMultimap getTransientNodes() { + return handle.getTransientNodes(); + } + + @Override + public List getOwnNodes() { + return handle.getOwnNodes(); + } + @Override public SortedSet 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 getAllNodes() { + return new TreeSet<>(handle.resolveInheritancesAlmostEqual()); + } + @Override public Set 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 resolveInheritances(Contexts contexts) { + return null; + } + + @Override + public List resolveInheritances() { + return null; + } + @Override public Set getPermanentPermissionNodes() { return handle.getPermanentNodes(); diff --git a/common/src/main/java/me/lucko/luckperms/common/caching/UserCache.java b/common/src/main/java/me/lucko/luckperms/common/caching/UserCache.java index 8d908de85..53d640997 100644 --- a/common/src/main/java/me/lucko/luckperms/common/caching/UserCache.java +++ b/common/src/main/java/me/lucko/luckperms/common/caching/UserCache.java @@ -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; } } diff --git a/common/src/main/java/me/lucko/luckperms/common/config/AbstractConfiguration.java b/common/src/main/java/me/lucko/luckperms/common/config/AbstractConfiguration.java index 31346a1dc..999136f2e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/config/AbstractConfiguration.java +++ b/common/src/main/java/me/lucko/luckperms/common/config/AbstractConfiguration.java @@ -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(); } diff --git a/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java b/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java index 8ffc11758..24cc14c93 100644 --- a/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java +++ b/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java @@ -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 WEB_EDITOR_URL_PATTERN = StringKey.of("web-editor-url", "https://lpedit.lucko.me/"); - private static List> KEYS = null; + private static Map> 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> getAllKeys() { + public static synchronized Map> getAllKeys() { if (KEYS == null) { - ImmutableList.Builder> keys = ImmutableList.builder(); + Map> 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; diff --git a/common/src/main/java/me/lucko/luckperms/common/model/PermissionHolder.java b/common/src/main/java/me/lucko/luckperms/common/model/PermissionHolder.java index 9aa612f78..9b791ca09 100644 --- a/common/src/main/java/me/lucko/luckperms/common/model/PermissionHolder.java +++ b/common/src/main/java/me/lucko/luckperms/common/model/PermissionHolder.java @@ -717,6 +717,27 @@ public abstract class PermissionHolder { return ImmutableMap.copyOf(perms); } + public Map exportNodesAndShorthand(boolean lowerCase) { + List entries = resolveInheritances(); + + Map 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 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 excludedGroups, ExtractedContexts context) { if (accumulator == null) { accumulator = MetaAccumulator.makeFromConfig(plugin); diff --git a/pom.xml b/pom.xml index 986d29493..a2cea2a78 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.lucko.luckperms luckperms - 3.2-SNAPSHOT + 3.3-SNAPSHOT api @@ -47,7 +47,7 @@ true - 3.2 + 3.3 ${git.closest.tag.commit.count} diff --git a/sponge/pom.xml b/sponge/pom.xml index 7bfca3455..6ab38f934 100644 --- a/sponge/pom.xml +++ b/sponge/pom.xml @@ -5,7 +5,7 @@ luckperms me.lucko.luckperms - 3.2-SNAPSHOT + 3.3-SNAPSHOT 4.0.0 diff --git a/sponge/sponge-service-api6/pom.xml b/sponge/sponge-service-api6/pom.xml index e4d5e3106..0273ebc02 100644 --- a/sponge/sponge-service-api6/pom.xml +++ b/sponge/sponge-service-api6/pom.xml @@ -5,7 +5,7 @@ luckperms me.lucko.luckperms - 3.2-SNAPSHOT + 3.3-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/sponge/sponge-service-api7/pom.xml b/sponge/sponge-service-api7/pom.xml index 56965e762..db343c8e1 100644 --- a/sponge/sponge-service-api7/pom.xml +++ b/sponge/sponge-service-api7/pom.xml @@ -5,7 +5,7 @@ luckperms me.lucko.luckperms - 3.2-SNAPSHOT + 3.3-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/sponge/sponge-service/pom.xml b/sponge/sponge-service/pom.xml index ae8f37725..0bcede21c 100644 --- a/sponge/sponge-service/pom.xml +++ b/sponge/sponge-service/pom.xml @@ -5,7 +5,7 @@ luckperms me.lucko.luckperms - 3.2-SNAPSHOT + 3.3-SNAPSHOT ../../pom.xml 4.0.0