Expose MetaStacks in the API, general cleanup, release 3.2
This commit is contained in:
@@ -43,6 +43,7 @@ import me.lucko.luckperms.api.User;
|
||||
import me.lucko.luckperms.api.UuidCache;
|
||||
import me.lucko.luckperms.api.context.ContextCalculator;
|
||||
import me.lucko.luckperms.api.context.ContextSet;
|
||||
import me.lucko.luckperms.common.api.delegates.MetaStackFactoryDelegate;
|
||||
import me.lucko.luckperms.common.api.delegates.NodeFactoryDelegate;
|
||||
import me.lucko.luckperms.common.api.delegates.UserDelegate;
|
||||
import me.lucko.luckperms.common.core.UserIdentifier;
|
||||
@@ -69,10 +70,14 @@ public class ApiProvider implements LuckPermsApi {
|
||||
@Getter
|
||||
private final EventFactory eventFactory;
|
||||
|
||||
@Getter
|
||||
private final MetaStackFactoryDelegate metaStackFactory;
|
||||
|
||||
public ApiProvider(LuckPermsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.eventBus = new LuckPermsEventBus(plugin);
|
||||
this.eventFactory = new EventFactory(eventBus);
|
||||
this.metaStackFactory = new MetaStackFactoryDelegate(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -82,7 +87,7 @@ public class ApiProvider implements LuckPermsApi {
|
||||
|
||||
@Override
|
||||
public double getApiVersion() {
|
||||
return 3.1;
|
||||
return 3.2;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -33,6 +33,7 @@ import com.google.common.base.Preconditions;
|
||||
|
||||
import me.lucko.luckperms.api.Group;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.api.context.ContextSet;
|
||||
import me.lucko.luckperms.common.core.NodeFactory;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||
@@ -70,9 +71,14 @@ public final class GroupDelegate extends PermissionHolderDelegate implements Gro
|
||||
return handle.inheritsGroup(cast(group));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inheritsGroup(@NonNull Group group, @NonNull ContextSet contextSet) {
|
||||
return handle.inheritsGroup(cast(group), contextSet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inheritsGroup(@NonNull Group group, @NonNull String server) {
|
||||
return handle.inheritsGroup(((GroupDelegate) group).getHandle(), server);
|
||||
return handle.inheritsGroup(cast(group), server);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+31
-19
@@ -23,30 +23,42 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.common.metastacking.definition;
|
||||
package me.lucko.luckperms.common.api.delegates;
|
||||
|
||||
import me.lucko.luckperms.common.metastacking.GenericMetaStack;
|
||||
import me.lucko.luckperms.common.metastacking.MetaStack;
|
||||
import me.lucko.luckperms.common.metastacking.MetaType;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import me.lucko.luckperms.api.metastacking.MetaStackDefinition;
|
||||
import me.lucko.luckperms.api.metastacking.MetaStackElement;
|
||||
import me.lucko.luckperms.api.metastacking.MetaStackFactory;
|
||||
import me.lucko.luckperms.common.metastacking.definition.SimpleMetaStackDefinition;
|
||||
import me.lucko.luckperms.common.metastacking.definition.StandardStackElements;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface MetaStackDefinition {
|
||||
@AllArgsConstructor
|
||||
public class MetaStackFactoryDelegate implements MetaStackFactory {
|
||||
public final LuckPermsPlugin plugin;
|
||||
|
||||
static MetaStackDefinition create(List<MetaStackElement> elements, String startSpacer, String middleSpacer, String endSpacer) {
|
||||
@Override
|
||||
public Optional<MetaStackElement> fromString(@NonNull String definition) {
|
||||
return StandardStackElements.parseFromString(plugin, definition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MetaStackElement> fromStrings(@NonNull List<String> definitions) {
|
||||
if (definitions.isEmpty()) {
|
||||
return ImmutableList.of();
|
||||
}
|
||||
return StandardStackElements.parseList(plugin, definitions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaStackDefinition createDefinition(List<MetaStackElement> elements, String startSpacer, String middleSpacer, String endSpacer) {
|
||||
return new SimpleMetaStackDefinition(elements, startSpacer, middleSpacer, endSpacer);
|
||||
}
|
||||
|
||||
List<MetaStackElement> getElements();
|
||||
|
||||
String getStartSpacer();
|
||||
|
||||
String getMiddleSpacer();
|
||||
|
||||
String getEndSpacer();
|
||||
|
||||
default MetaStack newStack(MetaType type) {
|
||||
return new GenericMetaStack(this, type);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,6 +27,7 @@ package me.lucko.luckperms.common.api.delegates;
|
||||
|
||||
import lombok.NonNull;
|
||||
|
||||
import me.lucko.luckperms.api.ChatMetaType;
|
||||
import me.lucko.luckperms.api.Group;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.common.core.NodeFactory;
|
||||
@@ -64,6 +65,11 @@ public class NodeFactoryDelegate implements me.lucko.luckperms.api.NodeFactory {
|
||||
return NodeFactory.makeMetaNode(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Node.Builder makeChatMetaNode(@NonNull ChatMetaType type, int priority, @NonNull String value) {
|
||||
return NodeFactory.makeChatMetaNode(type, priority, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Node.Builder makePrefixNode(int priority, @NonNull String prefix) {
|
||||
return NodeFactory.makePrefixNode(priority, prefix);
|
||||
|
||||
+36
@@ -37,8 +37,10 @@ import me.lucko.luckperms.api.LocalizedNode;
|
||||
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.MutableContextSet;
|
||||
import me.lucko.luckperms.common.core.NodeFactory;
|
||||
import me.lucko.luckperms.common.core.model.User;
|
||||
import me.lucko.luckperms.common.utils.ExtractedContexts;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||
@@ -49,6 +51,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import static me.lucko.luckperms.common.api.ApiUtils.checkTime;
|
||||
|
||||
@@ -64,6 +67,11 @@ public class PermissionHolderDelegate implements PermissionHolder {
|
||||
return handle.getObjectName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFriendlyName() {
|
||||
return handle.getFriendlyName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedSet<? extends Node> getPermissions() {
|
||||
return ImmutableSortedSet.copyOfSorted(handle.mergePermissionsToSortedSet());
|
||||
@@ -239,6 +247,19 @@ public class PermissionHolderDelegate implements PermissionHolder {
|
||||
return handle.unsetTransientPermission(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearMatching(Predicate<Node> test) {
|
||||
handle.removeIf(test);
|
||||
if (handle instanceof User) {
|
||||
handle.getPlugin().getUserManager().giveDefaultIfNeeded((User) handle, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearMatchingTransient(Predicate<Node> test) {
|
||||
handle.removeIfTransient(test);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsetPermission(@NonNull String node, @NonNull boolean temporary) throws ObjectLacksException {
|
||||
handle.unsetPermission(NodeFactory.make(node, temporary)).throwException();
|
||||
@@ -274,6 +295,11 @@ public class PermissionHolderDelegate implements PermissionHolder {
|
||||
handle.clearNodes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearNodes(@NonNull ContextSet contextSet) {
|
||||
handle.clearNodes(contextSet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearNodes(String server) {
|
||||
MutableContextSet set = new MutableContextSet();
|
||||
@@ -302,6 +328,11 @@ public class PermissionHolderDelegate implements PermissionHolder {
|
||||
handle.clearParents(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearParents(@NonNull ContextSet contextSet) {
|
||||
handle.clearParents(contextSet, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearParents(String server) {
|
||||
MutableContextSet set = new MutableContextSet();
|
||||
@@ -330,6 +361,11 @@ public class PermissionHolderDelegate implements PermissionHolder {
|
||||
handle.clearMeta();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearMeta(@NonNull ContextSet contextSet) {
|
||||
handle.clearMeta(contextSet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearMeta(String server) {
|
||||
MutableContextSet set = new MutableContextSet();
|
||||
|
||||
@@ -34,6 +34,7 @@ import me.lucko.luckperms.api.Group;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.api.User;
|
||||
import me.lucko.luckperms.api.caching.UserData;
|
||||
import me.lucko.luckperms.api.context.ContextSet;
|
||||
import me.lucko.luckperms.common.core.NodeFactory;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||
@@ -95,9 +96,13 @@ public final class UserDelegate extends PermissionHolderDelegate implements User
|
||||
handle.getRefreshBuffer().requestDirectly();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserData getCachedData() {
|
||||
return handle.getUserData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<UserData> getUserDataCache() {
|
||||
// TODO Deprecate this and return a nonnull instance
|
||||
return Optional.of(handle.getUserData());
|
||||
}
|
||||
|
||||
@@ -111,14 +116,19 @@ public final class UserDelegate extends PermissionHolderDelegate implements User
|
||||
return handle.inheritsGroup(GroupDelegate.cast(group));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInGroup(@NonNull Group group, @NonNull ContextSet contextSet) {
|
||||
return handle.inheritsGroup(GroupDelegate.cast(group), contextSet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInGroup(@NonNull Group group, @NonNull String server) {
|
||||
return handle.inheritsGroup(((GroupDelegate) group).getHandle(), server);
|
||||
return handle.inheritsGroup(GroupDelegate.cast(group), server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInGroup(@NonNull Group group, @NonNull String server, @NonNull String world) {
|
||||
return handle.inheritsGroup(((GroupDelegate) group).getHandle(), server, world);
|
||||
return handle.inheritsGroup(GroupDelegate.cast(group), server, world);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -30,10 +30,11 @@ import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.ToString;
|
||||
|
||||
import me.lucko.luckperms.api.ChatMetaType;
|
||||
import me.lucko.luckperms.api.LocalizedNode;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.metastacking.GenericMetaStack;
|
||||
import me.lucko.luckperms.common.metastacking.MetaStack;
|
||||
import me.lucko.luckperms.common.metastacking.MetaType;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
|
||||
import java.util.Comparator;
|
||||
@@ -50,8 +51,8 @@ import java.util.TreeMap;
|
||||
public class MetaAccumulator {
|
||||
public static MetaAccumulator makeFromConfig(LuckPermsPlugin plugin) {
|
||||
return new MetaAccumulator(
|
||||
plugin.getConfiguration().get(ConfigKeys.PREFIX_FORMATTING_OPTIONS).newStack(MetaType.PREFIX),
|
||||
plugin.getConfiguration().get(ConfigKeys.SUFFIX_FORMATTING_OPTIONS).newStack(MetaType.SUFFIX)
|
||||
new GenericMetaStack(plugin.getConfiguration().get(ConfigKeys.PREFIX_FORMATTING_OPTIONS), ChatMetaType.PREFIX),
|
||||
new GenericMetaStack(plugin.getConfiguration().get(ConfigKeys.SUFFIX_FORMATTING_OPTIONS), ChatMetaType.SUFFIX)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -113,12 +114,12 @@ public class MetaAccumulator {
|
||||
return this.meta;
|
||||
}
|
||||
|
||||
public Map<Integer, String> getChatMeta(MetaType type) {
|
||||
return type == MetaType.PREFIX ? prefixes : suffixes;
|
||||
public Map<Integer, String> getChatMeta(ChatMetaType type) {
|
||||
return type == ChatMetaType.PREFIX ? prefixes : suffixes;
|
||||
}
|
||||
|
||||
public MetaStack getStack(MetaType type) {
|
||||
return type == MetaType.PREFIX ? prefixStack : suffixStack;
|
||||
public MetaStack getStack(ChatMetaType type) {
|
||||
return type == ChatMetaType.PREFIX ? prefixStack : suffixStack;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSortedMap;
|
||||
|
||||
import me.lucko.luckperms.api.caching.MetaData;
|
||||
import me.lucko.luckperms.api.metastacking.MetaStackDefinition;
|
||||
import me.lucko.luckperms.common.metastacking.MetaStack;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -94,4 +95,14 @@ public class MetaCache implements MetaData {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaStackDefinition getPrefixStackDefinition() {
|
||||
return prefixStack.getDefinition();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaStackDefinition getSuffixStackDefinition() {
|
||||
return suffixStack.getDefinition();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.common.caching;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.ToString;
|
||||
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.metastacking.MetaType;
|
||||
import me.lucko.luckperms.common.metastacking.definition.MetaStackDefinition;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
|
||||
@Getter
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
public final class MetaContexts {
|
||||
public static MetaContexts makeFromConfig(Contexts contexts, LuckPermsPlugin plugin) {
|
||||
return new MetaContexts(
|
||||
contexts,
|
||||
plugin.getConfiguration().get(ConfigKeys.PREFIX_FORMATTING_OPTIONS),
|
||||
plugin.getConfiguration().get(ConfigKeys.SUFFIX_FORMATTING_OPTIONS)
|
||||
);
|
||||
}
|
||||
|
||||
private final Contexts contexts;
|
||||
private final MetaStackDefinition prefixStackDefinition;
|
||||
private final MetaStackDefinition suffixStackDefinition;
|
||||
|
||||
public MetaContexts(@NonNull Contexts contexts, @NonNull MetaStackDefinition prefixStackDefinition, @NonNull MetaStackDefinition suffixStackDefinition) {
|
||||
this.contexts = contexts;
|
||||
this.prefixStackDefinition = prefixStackDefinition;
|
||||
this.suffixStackDefinition = suffixStackDefinition;
|
||||
}
|
||||
|
||||
public MetaAccumulator newAccumulator() {
|
||||
return new MetaAccumulator(
|
||||
prefixStackDefinition.newStack(MetaType.PREFIX),
|
||||
suffixStackDefinition.newStack(MetaType.SUFFIX)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -33,11 +33,16 @@ import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import me.lucko.luckperms.api.ChatMetaType;
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.caching.MetaContexts;
|
||||
import me.lucko.luckperms.api.caching.MetaData;
|
||||
import me.lucko.luckperms.api.caching.PermissionData;
|
||||
import me.lucko.luckperms.api.caching.UserData;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.core.model.User;
|
||||
import me.lucko.luckperms.common.metastacking.GenericMetaStack;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.utils.ExtractedContexts;
|
||||
|
||||
import java.util.Set;
|
||||
@@ -79,7 +84,7 @@ public class UserCache implements UserData {
|
||||
|
||||
@Override
|
||||
public MetaCache reload(MetaContexts contexts, MetaCache oldData) {
|
||||
oldData.loadMeta(user.accumulateMeta(contexts.newAccumulator(), null, ExtractedContexts.generate(contexts.getContexts())));
|
||||
oldData.loadMeta(user.accumulateMeta(newAccumulator(contexts), null, ExtractedContexts.generate(contexts.getContexts())));
|
||||
return oldData;
|
||||
}
|
||||
});
|
||||
@@ -90,15 +95,16 @@ public class UserCache implements UserData {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaData getMetaData(@NonNull Contexts contexts) {
|
||||
// just create a MetaContexts instance using the values in the config
|
||||
return getMetaData(MetaContexts.makeFromConfig(contexts, user.getPlugin()));
|
||||
}
|
||||
|
||||
public MetaData getMetaData(@NonNull MetaContexts contexts) {
|
||||
return meta.get(contexts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaData getMetaData(@NonNull Contexts contexts) {
|
||||
// just create a MetaContexts instance using the values in the config
|
||||
return getMetaData(makeFromMetaContextsConfig(contexts, user.getPlugin()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionCache calculatePermissions(@NonNull Contexts contexts) {
|
||||
PermissionCache data = new PermissionCache(contexts, user, user.getPlugin().getCalculatorFactory());
|
||||
@@ -107,31 +113,33 @@ public class UserCache implements UserData {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaCache calculateMeta(@NonNull Contexts contexts) {
|
||||
// just create a MetaContexts instance using the values in the config
|
||||
return calculateMeta(MetaContexts.makeFromConfig(contexts, user.getPlugin()));
|
||||
}
|
||||
|
||||
public MetaCache calculateMeta(@NonNull MetaContexts contexts) {
|
||||
MetaCache data = new MetaCache();
|
||||
data.loadMeta(user.accumulateMeta(contexts.newAccumulator(), null, ExtractedContexts.generate(contexts.getContexts())));
|
||||
data.loadMeta(user.accumulateMeta(newAccumulator(contexts), null, ExtractedContexts.generate(contexts.getContexts())));
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaCache calculateMeta(@NonNull Contexts contexts) {
|
||||
// just create a MetaContexts instance using the values in the config
|
||||
return calculateMeta(makeFromMetaContextsConfig(contexts, user.getPlugin()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recalculatePermissions(@NonNull Contexts contexts) {
|
||||
permission.refresh(contexts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recalculateMeta(@NonNull Contexts contexts) {
|
||||
recalculateMeta(MetaContexts.makeFromConfig(contexts, user.getPlugin()));
|
||||
}
|
||||
|
||||
public void recalculateMeta(@NonNull MetaContexts contexts) {
|
||||
meta.refresh(contexts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recalculateMeta(@NonNull Contexts contexts) {
|
||||
recalculateMeta(makeFromMetaContextsConfig(contexts, user.getPlugin()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recalculatePermissions() {
|
||||
Set<Contexts> keys = ImmutableSet.copyOf(permission.asMap().keySet());
|
||||
@@ -152,7 +160,7 @@ public class UserCache implements UserData {
|
||||
@Override
|
||||
public void preCalculate(@NonNull Contexts contexts) {
|
||||
permission.get(contexts);
|
||||
meta.get(MetaContexts.makeFromConfig(contexts, user.getPlugin()));
|
||||
meta.get(makeFromMetaContextsConfig(contexts, user.getPlugin()));
|
||||
}
|
||||
|
||||
public void invalidateCache() {
|
||||
@@ -175,4 +183,19 @@ public class UserCache implements UserData {
|
||||
meta.invalidateAll();
|
||||
}
|
||||
|
||||
private static MetaContexts makeFromMetaContextsConfig(Contexts contexts, LuckPermsPlugin plugin) {
|
||||
return new MetaContexts(
|
||||
contexts,
|
||||
plugin.getConfiguration().get(ConfigKeys.PREFIX_FORMATTING_OPTIONS),
|
||||
plugin.getConfiguration().get(ConfigKeys.SUFFIX_FORMATTING_OPTIONS)
|
||||
);
|
||||
}
|
||||
|
||||
private static MetaAccumulator newAccumulator(MetaContexts contexts) {
|
||||
return new MetaAccumulator(
|
||||
new GenericMetaStack(contexts.getPrefixStackDefinition(), ChatMetaType.PREFIX),
|
||||
new GenericMetaStack(contexts.getSuffixStackDefinition(), ChatMetaType.SUFFIX)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+9
-9
@@ -27,10 +27,10 @@ package me.lucko.luckperms.common.commands.impl.generic.meta;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import me.lucko.luckperms.api.ChatMetaType;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SharedMainCommand;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.core.model.PermissionHolder;
|
||||
import me.lucko.luckperms.common.metastacking.MetaType;
|
||||
|
||||
public class CommandMeta<T extends PermissionHolder> extends SharedMainCommand<T> {
|
||||
public CommandMeta(boolean user) {
|
||||
@@ -40,14 +40,14 @@ public class CommandMeta<T extends PermissionHolder> extends SharedMainCommand<T
|
||||
.add(new MetaUnset())
|
||||
.add(new MetaSetTemp())
|
||||
.add(new MetaUnsetTemp())
|
||||
.add(new MetaAddChatMeta(MetaType.PREFIX))
|
||||
.add(new MetaAddChatMeta(MetaType.SUFFIX))
|
||||
.add(new MetaRemoveChatMeta(MetaType.PREFIX))
|
||||
.add(new MetaRemoveChatMeta(MetaType.SUFFIX))
|
||||
.add(new MetaAddTempChatMeta(MetaType.PREFIX))
|
||||
.add(new MetaAddTempChatMeta(MetaType.SUFFIX))
|
||||
.add(new MetaRemoveTempChatMeta(MetaType.PREFIX))
|
||||
.add(new MetaRemoveTempChatMeta(MetaType.SUFFIX))
|
||||
.add(new MetaAddChatMeta(ChatMetaType.PREFIX))
|
||||
.add(new MetaAddChatMeta(ChatMetaType.SUFFIX))
|
||||
.add(new MetaRemoveChatMeta(ChatMetaType.PREFIX))
|
||||
.add(new MetaRemoveChatMeta(ChatMetaType.SUFFIX))
|
||||
.add(new MetaAddTempChatMeta(ChatMetaType.PREFIX))
|
||||
.add(new MetaAddTempChatMeta(ChatMetaType.SUFFIX))
|
||||
.add(new MetaRemoveTempChatMeta(ChatMetaType.PREFIX))
|
||||
.add(new MetaRemoveTempChatMeta(ChatMetaType.SUFFIX))
|
||||
.add(new MetaClear())
|
||||
.build());
|
||||
}
|
||||
|
||||
+5
-5
@@ -25,6 +25,7 @@
|
||||
|
||||
package me.lucko.luckperms.common.commands.impl.generic.meta;
|
||||
|
||||
import me.lucko.luckperms.api.ChatMetaType;
|
||||
import me.lucko.luckperms.api.DataMutateResult;
|
||||
import me.lucko.luckperms.api.context.MutableContextSet;
|
||||
import me.lucko.luckperms.common.commands.Arg;
|
||||
@@ -39,7 +40,6 @@ import me.lucko.luckperms.common.constants.Permission;
|
||||
import me.lucko.luckperms.common.core.NodeFactory;
|
||||
import me.lucko.luckperms.common.core.model.PermissionHolder;
|
||||
import me.lucko.luckperms.common.data.LogEntry;
|
||||
import me.lucko.luckperms.common.metastacking.MetaType;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.utils.Predicates;
|
||||
|
||||
@@ -47,13 +47,13 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class MetaAddChatMeta extends SharedSubCommand {
|
||||
private final MetaType type;
|
||||
private final ChatMetaType type;
|
||||
|
||||
public MetaAddChatMeta(MetaType type) {
|
||||
public MetaAddChatMeta(ChatMetaType type) {
|
||||
super("add" + type.name().toLowerCase(),
|
||||
"Adds a " + type.name().toLowerCase(),
|
||||
type == MetaType.PREFIX ? Permission.USER_META_ADDPREFIX : Permission.USER_META_ADDSUFFIX,
|
||||
type == MetaType.PREFIX ? Permission.GROUP_META_ADDPREFIX : Permission.GROUP_META_ADDSUFFIX,
|
||||
type == ChatMetaType.PREFIX ? Permission.USER_META_ADDPREFIX : Permission.USER_META_ADDSUFFIX,
|
||||
type == ChatMetaType.PREFIX ? Permission.GROUP_META_ADDPREFIX : Permission.GROUP_META_ADDSUFFIX,
|
||||
Predicates.inRange(0, 1),
|
||||
Arg.list(
|
||||
Arg.create("priority", true, "the priority to add the " + type.name().toLowerCase() + " at"),
|
||||
|
||||
+5
-5
@@ -25,6 +25,7 @@
|
||||
|
||||
package me.lucko.luckperms.common.commands.impl.generic.meta;
|
||||
|
||||
import me.lucko.luckperms.api.ChatMetaType;
|
||||
import me.lucko.luckperms.api.DataMutateResult;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.api.context.MutableContextSet;
|
||||
@@ -42,7 +43,6 @@ import me.lucko.luckperms.common.core.NodeFactory;
|
||||
import me.lucko.luckperms.common.core.TemporaryModifier;
|
||||
import me.lucko.luckperms.common.core.model.PermissionHolder;
|
||||
import me.lucko.luckperms.common.data.LogEntry;
|
||||
import me.lucko.luckperms.common.metastacking.MetaType;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.utils.DateUtil;
|
||||
import me.lucko.luckperms.common.utils.Predicates;
|
||||
@@ -52,13 +52,13 @@ import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class MetaAddTempChatMeta extends SharedSubCommand {
|
||||
private final MetaType type;
|
||||
private final ChatMetaType type;
|
||||
|
||||
public MetaAddTempChatMeta(MetaType type) {
|
||||
public MetaAddTempChatMeta(ChatMetaType type) {
|
||||
super("addtemp" + type.name().toLowerCase(),
|
||||
"Adds a " + type.name().toLowerCase() + " temporarily",
|
||||
type == MetaType.PREFIX ? Permission.USER_META_ADDTEMP_PREFIX : Permission.USER_META_ADDTEMP_SUFFIX,
|
||||
type == MetaType.PREFIX ? Permission.GROUP_META_ADDTEMP_PREFIX : Permission.GROUP_META_ADDTEMP_SUFFIX,
|
||||
type == ChatMetaType.PREFIX ? Permission.USER_META_ADDTEMP_PREFIX : Permission.USER_META_ADDTEMP_SUFFIX,
|
||||
type == ChatMetaType.PREFIX ? Permission.GROUP_META_ADDTEMP_PREFIX : Permission.GROUP_META_ADDTEMP_SUFFIX,
|
||||
Predicates.inRange(0, 2),
|
||||
Arg.list(
|
||||
Arg.create("priority", true, "the priority to add the " + type.name().toLowerCase() + " at"),
|
||||
|
||||
+5
-5
@@ -25,6 +25,7 @@
|
||||
|
||||
package me.lucko.luckperms.common.commands.impl.generic.meta;
|
||||
|
||||
import me.lucko.luckperms.api.ChatMetaType;
|
||||
import me.lucko.luckperms.api.DataMutateResult;
|
||||
import me.lucko.luckperms.api.context.MutableContextSet;
|
||||
import me.lucko.luckperms.common.commands.Arg;
|
||||
@@ -39,7 +40,6 @@ import me.lucko.luckperms.common.constants.Permission;
|
||||
import me.lucko.luckperms.common.core.NodeFactory;
|
||||
import me.lucko.luckperms.common.core.model.PermissionHolder;
|
||||
import me.lucko.luckperms.common.data.LogEntry;
|
||||
import me.lucko.luckperms.common.metastacking.MetaType;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.utils.Predicates;
|
||||
|
||||
@@ -47,13 +47,13 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class MetaRemoveChatMeta extends SharedSubCommand {
|
||||
private final MetaType type;
|
||||
private final ChatMetaType type;
|
||||
|
||||
public MetaRemoveChatMeta(MetaType type) {
|
||||
public MetaRemoveChatMeta(ChatMetaType type) {
|
||||
super("remove" + type.name().toLowerCase(),
|
||||
"Removes a " + type.name().toLowerCase(),
|
||||
type == MetaType.PREFIX ? Permission.USER_META_REMOVEPREFIX : Permission.USER_META_REMOVESUFFIX,
|
||||
type == MetaType.PREFIX ? Permission.GROUP_META_REMOVEPREFIX : Permission.GROUP_META_REMOVESUFFIX,
|
||||
type == ChatMetaType.PREFIX ? Permission.USER_META_REMOVEPREFIX : Permission.USER_META_REMOVESUFFIX,
|
||||
type == ChatMetaType.PREFIX ? Permission.GROUP_META_REMOVEPREFIX : Permission.GROUP_META_REMOVESUFFIX,
|
||||
Predicates.is(0),
|
||||
Arg.list(
|
||||
Arg.create("priority", true, "the priority to remove the " + type.name().toLowerCase() + " at"),
|
||||
|
||||
+5
-5
@@ -25,6 +25,7 @@
|
||||
|
||||
package me.lucko.luckperms.common.commands.impl.generic.meta;
|
||||
|
||||
import me.lucko.luckperms.api.ChatMetaType;
|
||||
import me.lucko.luckperms.api.DataMutateResult;
|
||||
import me.lucko.luckperms.api.context.MutableContextSet;
|
||||
import me.lucko.luckperms.common.commands.Arg;
|
||||
@@ -39,7 +40,6 @@ import me.lucko.luckperms.common.constants.Permission;
|
||||
import me.lucko.luckperms.common.core.NodeFactory;
|
||||
import me.lucko.luckperms.common.core.model.PermissionHolder;
|
||||
import me.lucko.luckperms.common.data.LogEntry;
|
||||
import me.lucko.luckperms.common.metastacking.MetaType;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.utils.Predicates;
|
||||
|
||||
@@ -47,13 +47,13 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class MetaRemoveTempChatMeta extends SharedSubCommand {
|
||||
private final MetaType type;
|
||||
private final ChatMetaType type;
|
||||
|
||||
public MetaRemoveTempChatMeta(MetaType type) {
|
||||
public MetaRemoveTempChatMeta(ChatMetaType type) {
|
||||
super("removetemp" +type.name().toLowerCase(),
|
||||
"Removes a temporary " + type.name().toLowerCase(),
|
||||
type == MetaType.PREFIX ? Permission.USER_META_REMOVETEMP_PREFIX : Permission.USER_META_REMOVETEMP_SUFFIX,
|
||||
type == MetaType.PREFIX ? Permission.GROUP_META_REMOVETEMP_PREFIX : Permission.GROUP_META_REMOVETEMP_SUFFIX,
|
||||
type == ChatMetaType.PREFIX ? Permission.USER_META_REMOVETEMP_PREFIX : Permission.USER_META_REMOVETEMP_SUFFIX,
|
||||
type == ChatMetaType.PREFIX ? Permission.GROUP_META_REMOVETEMP_PREFIX : Permission.GROUP_META_REMOVETEMP_SUFFIX,
|
||||
Predicates.is(0),
|
||||
Arg.list(
|
||||
Arg.create("priority", true, "the priority to remove the " + type.name().toLowerCase() + " at"),
|
||||
|
||||
@@ -30,6 +30,7 @@ import lombok.experimental.UtilityClass;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import me.lucko.luckperms.api.metastacking.MetaStackDefinition;
|
||||
import me.lucko.luckperms.common.config.keys.AbstractKey;
|
||||
import me.lucko.luckperms.common.config.keys.BooleanKey;
|
||||
import me.lucko.luckperms.common.config.keys.EnduringKey;
|
||||
@@ -41,7 +42,7 @@ import me.lucko.luckperms.common.config.keys.StringKey;
|
||||
import me.lucko.luckperms.common.core.TemporaryModifier;
|
||||
import me.lucko.luckperms.common.core.model.User;
|
||||
import me.lucko.luckperms.common.defaults.Rule;
|
||||
import me.lucko.luckperms.common.metastacking.definition.MetaStackDefinition;
|
||||
import me.lucko.luckperms.common.metastacking.definition.SimpleMetaStackDefinition;
|
||||
import me.lucko.luckperms.common.metastacking.definition.StandardStackElements;
|
||||
import me.lucko.luckperms.common.primarygroup.AllParentsByWeightHolder;
|
||||
import me.lucko.luckperms.common.primarygroup.ParentsByWeightHolder;
|
||||
@@ -227,7 +228,7 @@ public class ConfigKeys {
|
||||
String middleSpacer = l.getString("meta-formatting.prefix.middle-spacer", " ");
|
||||
String endSpacer = l.getString("meta-formatting.prefix.end-spacer", "");
|
||||
|
||||
return MetaStackDefinition.create(StandardStackElements.parseList(l.getPlugin(), format), startSpacer, middleSpacer, endSpacer);
|
||||
return new SimpleMetaStackDefinition(StandardStackElements.parseList(l.getPlugin(), format), startSpacer, middleSpacer, endSpacer);
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -242,7 +243,7 @@ public class ConfigKeys {
|
||||
String middleSpacer = l.getString("meta-formatting.suffix.middle-spacer", " ");
|
||||
String endSpacer = l.getString("meta-formatting.suffix.end-spacer", "");
|
||||
|
||||
return MetaStackDefinition.create(StandardStackElements.parseList(l.getPlugin(), format), startSpacer, middleSpacer, endSpacer);
|
||||
return new SimpleMetaStackDefinition(StandardStackElements.parseList(l.getPlugin(), format), startSpacer, middleSpacer, endSpacer);
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,11 +31,11 @@ import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||
import com.google.common.base.Splitter;
|
||||
|
||||
import me.lucko.luckperms.api.ChatMetaType;
|
||||
import me.lucko.luckperms.api.MetaUtils;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.api.context.ContextSet;
|
||||
import me.lucko.luckperms.common.core.model.Group;
|
||||
import me.lucko.luckperms.common.metastacking.MetaType;
|
||||
import me.lucko.luckperms.common.utils.PatternCache;
|
||||
|
||||
import java.util.List;
|
||||
@@ -123,8 +123,8 @@ public class NodeFactory {
|
||||
return new NodeBuilder("meta." + MetaUtils.escapeCharacters(key) + "." + MetaUtils.escapeCharacters(value));
|
||||
}
|
||||
|
||||
public static Node.Builder makeChatMetaNode(MetaType type, int priority, String s) {
|
||||
return type == MetaType.PREFIX ? makePrefixNode(priority, s) : makeSuffixNode(priority, s);
|
||||
public static Node.Builder makeChatMetaNode(ChatMetaType type, int priority, String s) {
|
||||
return type == ChatMetaType.PREFIX ? makePrefixNode(priority, s) : makeSuffixNode(priority, s);
|
||||
}
|
||||
|
||||
public static Node.Builder makePrefixNode(int priority, String prefix) {
|
||||
|
||||
@@ -36,7 +36,6 @@ import com.google.common.collect.Maps;
|
||||
|
||||
import me.lucko.luckperms.api.MetaUtils;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
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;
|
||||
@@ -265,16 +264,6 @@ public final class ImmutableNode implements Node {
|
||||
this.optWorld = Optional.ofNullable(this.world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tristate getTristate() {
|
||||
return Tristate.fromBoolean(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNegated() {
|
||||
return !value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> getServer() {
|
||||
return optServer;
|
||||
@@ -310,11 +299,6 @@ public final class ImmutableNode implements Node {
|
||||
return expireAt != 0L;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPermanent() {
|
||||
return !isTemporary();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getExpiryUnixTime() {
|
||||
Preconditions.checkState(isTemporary(), "Node does not have an expiry time.");
|
||||
|
||||
@@ -1062,6 +1062,10 @@ public abstract class PermissionHolder {
|
||||
return group.getName().equalsIgnoreCase(this.getObjectName()) || hasPermission("group." + group.getName(), true);
|
||||
}
|
||||
|
||||
public boolean inheritsGroup(Group group, ContextSet contextSet) {
|
||||
return group.getName().equalsIgnoreCase(this.getObjectName()) || hasPermission(NodeFactory.newBuilder("group." + group.getName()).withExtraContext(contextSet).build()).asBoolean();
|
||||
}
|
||||
|
||||
public boolean inheritsGroup(Group group, String server) {
|
||||
return group.getName().equalsIgnoreCase(this.getObjectName()) || hasPermission("group." + group.getName(), true, server);
|
||||
}
|
||||
|
||||
@@ -28,8 +28,9 @@ package me.lucko.luckperms.common.metastacking;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
|
||||
import me.lucko.luckperms.api.ChatMetaType;
|
||||
import me.lucko.luckperms.api.LocalizedNode;
|
||||
import me.lucko.luckperms.common.metastacking.definition.MetaStackDefinition;
|
||||
import me.lucko.luckperms.api.metastacking.MetaStackDefinition;
|
||||
import me.lucko.luckperms.common.utils.ImmutableCollectors;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -39,12 +40,12 @@ import java.util.List;
|
||||
public class GenericMetaStack implements MetaStack {
|
||||
|
||||
private final MetaStackDefinition definition;
|
||||
private final MetaType targetType;
|
||||
private final ChatMetaType targetType;
|
||||
|
||||
@Getter(AccessLevel.NONE)
|
||||
private final List<MetaStackEntry> entries;
|
||||
|
||||
public GenericMetaStack(MetaStackDefinition definition, MetaType targetType) {
|
||||
public GenericMetaStack(MetaStackDefinition definition, ChatMetaType targetType) {
|
||||
this.definition = definition;
|
||||
this.targetType = targetType;
|
||||
this.entries = definition.getElements().stream()
|
||||
|
||||
@@ -25,14 +25,15 @@
|
||||
|
||||
package me.lucko.luckperms.common.metastacking;
|
||||
|
||||
import me.lucko.luckperms.api.ChatMetaType;
|
||||
import me.lucko.luckperms.api.LocalizedNode;
|
||||
import me.lucko.luckperms.common.metastacking.definition.MetaStackDefinition;
|
||||
import me.lucko.luckperms.api.metastacking.MetaStackDefinition;
|
||||
|
||||
public interface MetaStack {
|
||||
|
||||
MetaStackDefinition getDefinition();
|
||||
|
||||
MetaType getTargetType();
|
||||
ChatMetaType getTargetType();
|
||||
|
||||
String toFormattedString();
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
package me.lucko.luckperms.common.metastacking;
|
||||
|
||||
import me.lucko.luckperms.api.LocalizedNode;
|
||||
import me.lucko.luckperms.common.metastacking.definition.MetaStackElement;
|
||||
import me.lucko.luckperms.api.metastacking.MetaStackElement;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.common.metastacking;
|
||||
|
||||
import me.lucko.luckperms.api.Node;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public enum MetaType {
|
||||
|
||||
PREFIX {
|
||||
@Override
|
||||
public boolean matches(Node node) {
|
||||
return node.isPrefix();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldIgnore(Node node) {
|
||||
return !node.isPrefix();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map.Entry<Integer, String> getEntry(Node node) {
|
||||
return node.getPrefix();
|
||||
}
|
||||
},
|
||||
|
||||
SUFFIX {
|
||||
@Override
|
||||
public boolean matches(Node node) {
|
||||
return node.isSuffix();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldIgnore(Node node) {
|
||||
return !node.isSuffix();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map.Entry<Integer, String> getEntry(Node node) {
|
||||
return node.getSuffix();
|
||||
}
|
||||
};
|
||||
|
||||
public abstract boolean matches(Node node);
|
||||
|
||||
public abstract boolean shouldIgnore(Node node);
|
||||
|
||||
public abstract Map.Entry<Integer, String> getEntry(Node node);
|
||||
|
||||
}
|
||||
+4
-3
@@ -29,19 +29,20 @@ import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.api.ChatMetaType;
|
||||
import me.lucko.luckperms.api.LocalizedNode;
|
||||
import me.lucko.luckperms.common.metastacking.definition.MetaStackElement;
|
||||
import me.lucko.luckperms.api.metastacking.MetaStackElement;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public class SimpleMetaStackEntry implements MetaStackEntry {
|
||||
class SimpleMetaStackEntry implements MetaStackEntry {
|
||||
|
||||
private final MetaStack parentStack;
|
||||
private final MetaStackElement element;
|
||||
private final MetaType type;
|
||||
private final ChatMetaType type;
|
||||
|
||||
@Getter(AccessLevel.NONE)
|
||||
private Map.Entry<Integer, String> current = null;
|
||||
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.common.metastacking.definition;
|
||||
|
||||
import me.lucko.luckperms.api.LocalizedNode;
|
||||
import me.lucko.luckperms.common.metastacking.MetaType;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface MetaStackElement {
|
||||
|
||||
boolean shouldAccumulate(LocalizedNode node, MetaType type, Map.Entry<Integer, String> current);
|
||||
|
||||
}
|
||||
+4
-1
@@ -32,12 +32,15 @@ import lombok.ToString;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import me.lucko.luckperms.api.metastacking.MetaStackDefinition;
|
||||
import me.lucko.luckperms.api.metastacking.MetaStackElement;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@EqualsAndHashCode
|
||||
@ToString
|
||||
final class SimpleMetaStackDefinition implements MetaStackDefinition {
|
||||
public final class SimpleMetaStackDefinition implements MetaStackDefinition {
|
||||
|
||||
private final List<MetaStackElement> elements;
|
||||
private final String startSpacer;
|
||||
|
||||
+10
-9
@@ -30,9 +30,10 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import me.lucko.luckperms.api.ChatMetaType;
|
||||
import me.lucko.luckperms.api.LocalizedNode;
|
||||
import me.lucko.luckperms.api.metastacking.MetaStackElement;
|
||||
import me.lucko.luckperms.common.core.model.Track;
|
||||
import me.lucko.luckperms.common.metastacking.MetaType;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.utils.ImmutableCollectors;
|
||||
|
||||
@@ -167,7 +168,7 @@ public class StandardStackElements {
|
||||
@ToString
|
||||
private static final class HighestPriority implements MetaStackElement {
|
||||
@Override
|
||||
public boolean shouldAccumulate(LocalizedNode node, MetaType type, Map.Entry<Integer, String> current) {
|
||||
public boolean shouldAccumulate(LocalizedNode node, ChatMetaType type, Map.Entry<Integer, String> current) {
|
||||
if (type.shouldIgnore(node)) {
|
||||
return false;
|
||||
}
|
||||
@@ -180,7 +181,7 @@ public class StandardStackElements {
|
||||
@ToString
|
||||
private static final class HighestPriorityOwn implements MetaStackElement {
|
||||
@Override
|
||||
public boolean shouldAccumulate(LocalizedNode node, MetaType type, Map.Entry<Integer, String> current) {
|
||||
public boolean shouldAccumulate(LocalizedNode node, ChatMetaType type, Map.Entry<Integer, String> current) {
|
||||
if (type.shouldIgnore(node)) {
|
||||
return false;
|
||||
}
|
||||
@@ -202,7 +203,7 @@ public class StandardStackElements {
|
||||
private final String trackName;
|
||||
|
||||
@Override
|
||||
public boolean shouldAccumulate(LocalizedNode node, MetaType type, Map.Entry<Integer, String> current) {
|
||||
public boolean shouldAccumulate(LocalizedNode node, ChatMetaType type, Map.Entry<Integer, String> current) {
|
||||
if (type.shouldIgnore(node)) {
|
||||
return false;
|
||||
}
|
||||
@@ -220,7 +221,7 @@ public class StandardStackElements {
|
||||
private final String trackName;
|
||||
|
||||
@Override
|
||||
public boolean shouldAccumulate(LocalizedNode node, MetaType type, Map.Entry<Integer, String> current) {
|
||||
public boolean shouldAccumulate(LocalizedNode node, ChatMetaType type, Map.Entry<Integer, String> current) {
|
||||
if (type.shouldIgnore(node)) {
|
||||
return false;
|
||||
}
|
||||
@@ -233,7 +234,7 @@ public class StandardStackElements {
|
||||
@ToString
|
||||
private static final class LowestPriority implements MetaStackElement {
|
||||
@Override
|
||||
public boolean shouldAccumulate(LocalizedNode node, MetaType type, Map.Entry<Integer, String> current) {
|
||||
public boolean shouldAccumulate(LocalizedNode node, ChatMetaType type, Map.Entry<Integer, String> current) {
|
||||
if (type.shouldIgnore(node)) {
|
||||
return false;
|
||||
}
|
||||
@@ -246,7 +247,7 @@ public class StandardStackElements {
|
||||
@ToString
|
||||
private static final class LowestPriorityOwn implements MetaStackElement {
|
||||
@Override
|
||||
public boolean shouldAccumulate(LocalizedNode node, MetaType type, Map.Entry<Integer, String> current) {
|
||||
public boolean shouldAccumulate(LocalizedNode node, ChatMetaType type, Map.Entry<Integer, String> current) {
|
||||
if (type.shouldIgnore(node)) {
|
||||
return false;
|
||||
}
|
||||
@@ -268,7 +269,7 @@ public class StandardStackElements {
|
||||
private final String trackName;
|
||||
|
||||
@Override
|
||||
public boolean shouldAccumulate(LocalizedNode node, MetaType type, Map.Entry<Integer, String> current) {
|
||||
public boolean shouldAccumulate(LocalizedNode node, ChatMetaType type, Map.Entry<Integer, String> current) {
|
||||
if (type.shouldIgnore(node)) {
|
||||
return false;
|
||||
}
|
||||
@@ -286,7 +287,7 @@ public class StandardStackElements {
|
||||
private final String trackName;
|
||||
|
||||
@Override
|
||||
public boolean shouldAccumulate(LocalizedNode node, MetaType type, Map.Entry<Integer, String> current) {
|
||||
public boolean shouldAccumulate(LocalizedNode node, ChatMetaType type, Map.Entry<Integer, String> current) {
|
||||
if (type.shouldIgnore(node)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user