mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-27 21:29:47 +01:00
Moreeee stuff
This commit is contained in:
parent
287c0f7f7a
commit
c836cce59b
@ -124,19 +124,19 @@ public interface PermissionHolder {
|
||||
@NonNull CachedDataManager getCachedData();
|
||||
|
||||
/**
|
||||
* Gets the {@link Data} of a particular type.
|
||||
* Gets the {@link NodeMap} of a particular type.
|
||||
*
|
||||
* @param dataType the data type
|
||||
* @return the data
|
||||
*/
|
||||
Data getData(@NonNull DataType dataType);
|
||||
NodeMap getData(@NonNull DataType dataType);
|
||||
|
||||
/**
|
||||
* Gets the holders {@link DataType#NORMAL} data.
|
||||
*
|
||||
* @return the normal data
|
||||
*/
|
||||
@NonNull Data data();
|
||||
@NonNull NodeMap data();
|
||||
|
||||
/**
|
||||
* Gets the holders {@link DataType#TRANSIENT} data.
|
||||
@ -154,7 +154,7 @@ public interface PermissionHolder {
|
||||
*
|
||||
* @return the transient data
|
||||
*/
|
||||
@NonNull Data transientData();
|
||||
@NonNull NodeMap transientData();
|
||||
|
||||
/**
|
||||
* Encapsulates a store of data ({@link Node}s) within a {@link PermissionHolder}.
|
||||
@ -170,7 +170,7 @@ public interface PermissionHolder {
|
||||
* made already. This can be done via {@link UserManager#loadUser(UUID)} or
|
||||
* {@link GroupManager#loadGroup(String)} respectively.</p>
|
||||
*/
|
||||
interface Data {
|
||||
interface NodeMap {
|
||||
|
||||
/**
|
||||
* Gets a map of the {@link Node}s contained within this instance,
|
||||
|
@ -25,17 +25,18 @@
|
||||
|
||||
package net.luckperms.api.model;
|
||||
|
||||
import net.luckperms.api.model.PermissionHolder.NodeMap;
|
||||
import net.luckperms.api.node.Node;
|
||||
|
||||
/**
|
||||
* Controls how the implementation should behave when new temporary nodes are set
|
||||
* that would otherwise conflict with existing entries.
|
||||
*
|
||||
* <p>The default behaviour of {@link PermissionHolder.Data#add(Node)} is
|
||||
* <p>The default behaviour of {@link NodeMap#add(Node)} is
|
||||
* to return a result of {@link DataMutateResult#ALREADY_HAS} when an equivalent
|
||||
* node is found. This can be replicated using {@link #FAIL_WITH_ALREADY_HAS}.</p>
|
||||
*
|
||||
* <p>However, the {@link PermissionHolder.Data#add(Node, TemporaryMergeBehaviour)}
|
||||
* <p>However, the {@link NodeMap#add(Node, TemporaryMergeBehaviour)}
|
||||
* method allows this behaviour to be customized for temporary permissions.</p>
|
||||
*/
|
||||
public enum TemporaryMergeBehaviour {
|
||||
|
@ -201,13 +201,13 @@ public class LPPermissionAttachment extends PermissionAttachment {
|
||||
|
||||
// remove transient permissions from the holder which were added by this attachment & equal the permission
|
||||
User user = this.permissible.getUser();
|
||||
user.removeIf(DataType.TRANSIENT, null, n -> n.getMetadata(TRANSIENT_SOURCE_KEY).orElse(null) == this && n.getKey().equals(name));
|
||||
user.removeIf(DataType.TRANSIENT, null, n -> n.getMetadata(TRANSIENT_SOURCE_KEY).orElse(null) == this && n.getKey().equals(name), false);
|
||||
}
|
||||
|
||||
private void clearInternal() {
|
||||
// remove all transient permissions added by this attachment
|
||||
User user = this.permissible.getUser();
|
||||
user.removeIf(DataType.TRANSIENT, null, n -> n.getMetadata(TRANSIENT_SOURCE_KEY).orElse(null) == this);
|
||||
user.removeIf(DataType.TRANSIENT, null, n -> n.getMetadata(TRANSIENT_SOURCE_KEY).orElse(null) == this, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -45,7 +45,7 @@ import net.luckperms.api.context.ImmutableContextSet;
|
||||
import net.luckperms.api.model.DataType;
|
||||
import net.luckperms.api.node.ChatMetaType;
|
||||
import net.luckperms.api.node.NodeBuilder;
|
||||
import net.luckperms.api.node.types.MetaNode;
|
||||
import net.luckperms.api.node.NodeType;
|
||||
import net.luckperms.api.query.Flag;
|
||||
import net.luckperms.api.query.QueryOptions;
|
||||
import net.milkbowl.vault.chat.Chat;
|
||||
@ -266,7 +266,7 @@ public class LuckPermsVaultChat extends AbstractVaultChat {
|
||||
}
|
||||
|
||||
// remove all prefixes/suffixes directly set on the user/group
|
||||
holder.removeIf(DataType.NORMAL, null, node -> type.nodeType().matches(node));
|
||||
holder.removeIf(DataType.NORMAL, null, type.nodeType()::matches, false);
|
||||
|
||||
if (value == null) {
|
||||
this.vaultPermission.holderSave(holder);
|
||||
@ -292,7 +292,7 @@ public class LuckPermsVaultChat extends AbstractVaultChat {
|
||||
logMsg("#setMeta: %s - %s - %s - %s", holder.getPlainDisplayName(), key, value, world);
|
||||
}
|
||||
|
||||
holder.removeIf(DataType.NORMAL, null, n -> n instanceof MetaNode && ((MetaNode) n).getMetaKey().equals(key));
|
||||
holder.removeIf(DataType.NORMAL, null, NodeType.META.predicate(n -> n.getMetaKey().equals(key)), false);
|
||||
|
||||
if (value == null) {
|
||||
this.vaultPermission.holderSave(holder);
|
||||
|
@ -52,13 +52,13 @@ import java.util.function.Predicate;
|
||||
public class ApiPermissionHolder implements net.luckperms.api.model.PermissionHolder {
|
||||
private final PermissionHolder handle;
|
||||
|
||||
private final DataImpl normalData;
|
||||
private final DataImpl transientData;
|
||||
private final NodeMapImpl normalData;
|
||||
private final NodeMapImpl transientData;
|
||||
|
||||
ApiPermissionHolder(PermissionHolder handle) {
|
||||
this.handle = Objects.requireNonNull(handle, "handle");
|
||||
this.normalData = new DataImpl(DataType.NORMAL);
|
||||
this.transientData = new DataImpl(DataType.TRANSIENT);
|
||||
this.normalData = new NodeMapImpl(DataType.NORMAL);
|
||||
this.transientData = new NodeMapImpl(DataType.TRANSIENT);
|
||||
}
|
||||
|
||||
PermissionHolder getHandle() {
|
||||
@ -81,7 +81,7 @@ public class ApiPermissionHolder implements net.luckperms.api.model.PermissionHo
|
||||
}
|
||||
|
||||
@Override
|
||||
public Data getData(@NonNull DataType dataType) {
|
||||
public NodeMap getData(@NonNull DataType dataType) {
|
||||
switch (dataType) {
|
||||
case NORMAL:
|
||||
return this.normalData;
|
||||
@ -93,12 +93,12 @@ public class ApiPermissionHolder implements net.luckperms.api.model.PermissionHo
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Data data() {
|
||||
public @NonNull net.luckperms.api.model.PermissionHolder.NodeMap data() {
|
||||
return this.normalData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Data transientData() {
|
||||
public @NonNull net.luckperms.api.model.PermissionHolder.NodeMap transientData() {
|
||||
return this.transientData;
|
||||
}
|
||||
|
||||
@ -127,10 +127,10 @@ public class ApiPermissionHolder implements net.luckperms.api.model.PermissionHo
|
||||
this.handle.auditTemporaryNodes();
|
||||
}
|
||||
|
||||
private class DataImpl implements Data {
|
||||
private class NodeMapImpl implements NodeMap {
|
||||
private final DataType dataType;
|
||||
|
||||
DataImpl(DataType dataType) {
|
||||
NodeMapImpl(DataType dataType) {
|
||||
this.dataType = dataType;
|
||||
}
|
||||
|
||||
|
@ -101,9 +101,9 @@ public class MetaClear extends SharedSubCommand {
|
||||
}
|
||||
|
||||
if (context.isEmpty()) {
|
||||
holder.removeIf(DataType.NORMAL, null, type::matches);
|
||||
holder.removeIf(DataType.NORMAL, null, type::matches, false);
|
||||
} else {
|
||||
holder.removeIf(DataType.NORMAL, context, type::matches);
|
||||
holder.removeIf(DataType.NORMAL, context, type::matches, false);
|
||||
}
|
||||
|
||||
int changed = before - holder.normalData().immutable().size();
|
||||
|
@ -89,10 +89,7 @@ public class MetaRemoveChatMeta extends SharedSubCommand {
|
||||
|
||||
// Handle bulk removal
|
||||
if (meta.equalsIgnoreCase("null") || meta.equals("*")) {
|
||||
holder.removeIf(DataType.NORMAL, null, n -> this.type.nodeType().matches(n) &&
|
||||
this.type.nodeType().cast(n).getPriority() == priority &&
|
||||
!n.hasExpiry() &&
|
||||
n.getContexts().equals(context));
|
||||
holder.removeIf(DataType.NORMAL, context, this.type.nodeType().predicate(n -> n.getPriority() == priority && !n.hasExpiry()), false);
|
||||
Message.BULK_REMOVE_CHATMETA_SUCCESS.send(sender, holder.getFormattedDisplayName(), this.type.name().toLowerCase(), priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
|
||||
LoggedAction.build().source(sender).target(holder)
|
||||
|
@ -89,10 +89,7 @@ public class MetaRemoveTempChatMeta extends SharedSubCommand {
|
||||
|
||||
// Handle bulk removal
|
||||
if (meta.equalsIgnoreCase("null") || meta.equals("*")) {
|
||||
holder.removeIf(DataType.NORMAL, null, n -> this.type.nodeType().matches(n) &&
|
||||
this.type.nodeType().cast(n).getPriority() == priority &&
|
||||
n.hasExpiry() &&
|
||||
n.getContexts().equals(context));
|
||||
holder.removeIf(DataType.NORMAL, context, this.type.nodeType().predicate(n -> n.getPriority() == priority && n.hasExpiry()), false);
|
||||
Message.BULK_REMOVE_TEMP_CHATMETA_SUCCESS.send(sender, holder.getFormattedDisplayName(), this.type.name().toLowerCase(), priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
|
||||
LoggedAction.build().source(sender).target(holder)
|
||||
|
@ -52,7 +52,7 @@ import net.luckperms.api.context.MutableContextSet;
|
||||
import net.luckperms.api.model.DataType;
|
||||
import net.luckperms.api.node.Node;
|
||||
import net.luckperms.api.node.NodeEqualityPredicate;
|
||||
import net.luckperms.api.node.types.MetaNode;
|
||||
import net.luckperms.api.node.NodeType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -86,7 +86,7 @@ public class MetaSet extends SharedSubCommand {
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
holder.removeIf(DataType.NORMAL, context, n -> n instanceof MetaNode && !n.hasExpiry() && ((MetaNode) n).getMetaKey().equalsIgnoreCase(key));
|
||||
holder.removeIf(DataType.NORMAL, context, NodeType.META.predicate(n -> !n.hasExpiry() && n.getMetaKey().equalsIgnoreCase(key)), false);
|
||||
holder.setNode(DataType.NORMAL, node, true);
|
||||
|
||||
TextComponent.Builder builder = Message.SET_META_SUCCESS.asComponent(plugin.getLocaleManager(), key, value, holder.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
|
||||
|
@ -107,7 +107,7 @@ public class MetaSetChatMeta extends SharedSubCommand {
|
||||
}
|
||||
|
||||
// remove all other prefixes/suffixes set in these contexts
|
||||
holder.removeIf(DataType.NORMAL, context, node -> this.type.nodeType().matches(node));
|
||||
holder.removeIf(DataType.NORMAL, context, this.type.nodeType()::matches, false);
|
||||
|
||||
// determine the priority to set at
|
||||
if (priority == Integer.MIN_VALUE) {
|
||||
|
@ -55,7 +55,7 @@ import net.luckperms.api.model.DataType;
|
||||
import net.luckperms.api.model.TemporaryMergeBehaviour;
|
||||
import net.luckperms.api.node.Node;
|
||||
import net.luckperms.api.node.NodeEqualityPredicate;
|
||||
import net.luckperms.api.node.types.MetaNode;
|
||||
import net.luckperms.api.node.NodeType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -91,7 +91,7 @@ public class MetaSetTemp extends SharedSubCommand {
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
holder.removeIf(DataType.NORMAL, context, n -> n instanceof MetaNode && n.hasExpiry() && ((MetaNode) n).getMetaKey().equalsIgnoreCase(key));
|
||||
holder.removeIf(DataType.NORMAL, context, NodeType.META.predicate(n -> n.hasExpiry() && n.getMetaKey().equalsIgnoreCase(key)), false);
|
||||
duration = holder.setNode(DataType.NORMAL, node, modifier).getMergedNode().getExpiry().getEpochSecond();
|
||||
|
||||
TextComponent.Builder builder = Message.SET_META_TEMP_SUCCESS.asComponent(plugin.getLocaleManager(), key, value, holder.getFormattedDisplayName(), DurationFormatter.LONG.formatDateDiff(duration), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
|
||||
|
@ -117,7 +117,7 @@ public class MetaSetTempChatMeta extends SharedSubCommand {
|
||||
}
|
||||
|
||||
// remove all other prefixes/suffixes set in these contexts
|
||||
holder.removeIf(DataType.NORMAL, context, node -> this.type.nodeType().matches(node));
|
||||
holder.removeIf(DataType.NORMAL, context, this.type.nodeType()::matches, false);
|
||||
|
||||
// determine the priority to set at
|
||||
if (priority == Integer.MIN_VALUE) {
|
||||
|
@ -46,7 +46,7 @@ import me.lucko.luckperms.common.util.Predicates;
|
||||
|
||||
import net.luckperms.api.context.MutableContextSet;
|
||||
import net.luckperms.api.model.DataType;
|
||||
import net.luckperms.api.node.types.MetaNode;
|
||||
import net.luckperms.api.node.NodeType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -72,7 +72,7 @@ public class MetaUnset extends SharedSubCommand {
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
if (holder.removeIf(DataType.NORMAL, context, n -> n instanceof MetaNode && !n.hasExpiry() && ((MetaNode) n).getMetaKey().equalsIgnoreCase(key))) {
|
||||
if (holder.removeIf(DataType.NORMAL, context, NodeType.META.predicate(n -> !n.hasExpiry() && n.getMetaKey().equalsIgnoreCase(key)), false)) {
|
||||
Message.UNSET_META_SUCCESS.send(sender, key, holder.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
|
||||
LoggedAction.build().source(sender).target(holder)
|
||||
|
@ -46,7 +46,7 @@ import me.lucko.luckperms.common.util.Predicates;
|
||||
|
||||
import net.luckperms.api.context.MutableContextSet;
|
||||
import net.luckperms.api.model.DataType;
|
||||
import net.luckperms.api.node.types.MetaNode;
|
||||
import net.luckperms.api.node.NodeType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -72,7 +72,7 @@ public class MetaUnsetTemp extends SharedSubCommand {
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
if (holder.removeIf(DataType.NORMAL, context, n -> n instanceof MetaNode && n.hasExpiry() && ((MetaNode) n).getMetaKey().equalsIgnoreCase(key))) {
|
||||
if (holder.removeIf(DataType.NORMAL, context, NodeType.META.predicate(n -> n.hasExpiry() && n.getMetaKey().equalsIgnoreCase(key)), false)) {
|
||||
Message.UNSET_META_TEMP_SUCCESS.send(sender, key, holder.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
|
||||
LoggedAction.build().source(sender).target(holder)
|
||||
|
@ -93,11 +93,7 @@ public class ParentClearTrack extends SharedSubCommand {
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
if (context.isEmpty()) {
|
||||
holder.removeIf(DataType.NORMAL, null, NodeType.INHERITANCE.predicate(n -> track.containsGroup(n.getGroupName())));
|
||||
} else {
|
||||
holder.removeIf(DataType.NORMAL, null, NodeType.INHERITANCE.predicate(n -> n.getContexts().equals(context) && track.containsGroup(n.getGroupName())));
|
||||
}
|
||||
holder.removeIf(DataType.NORMAL, context.isEmpty() ? null : context, NodeType.INHERITANCE.predicate(n -> track.containsGroup(n.getGroupName())), false);
|
||||
|
||||
if (holder.getType() == HolderType.USER) {
|
||||
plugin.getUserManager().giveDefaultIfNeeded(((User) holder), false);
|
||||
|
@ -114,7 +114,7 @@ public class ParentSetTrack extends SharedSubCommand {
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
holder.removeIf(DataType.NORMAL, null, NodeType.INHERITANCE.predicate(n -> n.getContexts().equals(context) && track.containsGroup(n.getGroupName())));
|
||||
holder.removeIf(DataType.NORMAL, context, NodeType.INHERITANCE.predicate(n -> track.containsGroup(n.getGroupName())), false);
|
||||
holder.setNode(DataType.NORMAL, Inheritance.builder(group.getName()).withContext(context).build(), true);
|
||||
|
||||
Message.SET_TRACK_PARENT_SUCCESS.send(sender, holder.getFormattedDisplayName(), track.getName(), group.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
|
@ -46,7 +46,7 @@ import me.lucko.luckperms.common.util.Predicates;
|
||||
|
||||
import net.luckperms.api.context.MutableContextSet;
|
||||
import net.luckperms.api.model.DataType;
|
||||
import net.luckperms.api.node.types.PermissionNode;
|
||||
import net.luckperms.api.node.NodeType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -72,11 +72,7 @@ public class PermissionClear extends SharedSubCommand {
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
if (context.isEmpty()) {
|
||||
holder.removeIf(DataType.NORMAL, null, node -> node instanceof PermissionNode);
|
||||
} else {
|
||||
holder.removeIf(DataType.NORMAL, context, node -> node instanceof PermissionNode);
|
||||
}
|
||||
holder.removeIf(DataType.NORMAL, context.isEmpty() ? null : context, NodeType.PERMISSION::matches, false);
|
||||
|
||||
int changed = before - holder.normalData().immutable().size();
|
||||
if (changed == 1) {
|
||||
|
@ -90,7 +90,7 @@ public class GroupSetDisplayName extends SubCommand<Group> {
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
group.removeIf(DataType.NORMAL, context, n -> n instanceof DisplayNameNode);
|
||||
group.removeIf(DataType.NORMAL, context, NodeType.DISPLAY_NAME::matches, false);
|
||||
|
||||
if (name.equals(group.getName())) {
|
||||
Message.GROUP_SET_DISPLAY_NAME_REMOVED.send(sender, group.getName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
|
||||
|
@ -61,7 +61,7 @@ public class GroupSetWeight extends SubCommand<Group> {
|
||||
|
||||
int weight = ArgumentParser.parsePriority(0, args);
|
||||
|
||||
group.removeIf(DataType.NORMAL, null, NodeType.WEIGHT::matches);
|
||||
group.removeIf(DataType.NORMAL, null, NodeType.WEIGHT::matches, false);
|
||||
group.setNode(DataType.NORMAL, Weight.builder(weight).build(), true);
|
||||
|
||||
Message.GROUP_SET_WEIGHT.send(sender, weight, group.getFormattedDisplayName());
|
||||
|
@ -79,7 +79,7 @@ public class LogNotify extends SubCommand<Log> {
|
||||
user.setNode(DataType.NORMAL, NodeBuilders.determineMostApplicable(IGNORE_NODE).build(), true);
|
||||
} else {
|
||||
// remove the perm
|
||||
user.removeIf(DataType.NORMAL, ImmutableContextSetImpl.EMPTY, n -> n.getKey().equalsIgnoreCase(IGNORE_NODE));
|
||||
user.removeIf(DataType.NORMAL, ImmutableContextSetImpl.EMPTY, n -> n.getKey().equalsIgnoreCase(IGNORE_NODE), false);
|
||||
}
|
||||
|
||||
plugin.getStorage().saveUser(user).join();
|
||||
|
@ -57,7 +57,7 @@ public final class MigrationUtils {
|
||||
}
|
||||
|
||||
public static void setGroupWeight(Group group, int weight) {
|
||||
group.removeIf(DataType.NORMAL, null, NodeType.WEIGHT::matches);
|
||||
group.removeIf(DataType.NORMAL, null, NodeType.WEIGHT::matches, false);
|
||||
group.setNode(DataType.NORMAL, Weight.builder(weight).build(), true);
|
||||
}
|
||||
|
||||
|
@ -478,10 +478,6 @@ public abstract class PermissionHolder {
|
||||
return DataMutateResult.SUCCESS;
|
||||
}
|
||||
|
||||
public boolean removeIf(DataType dataType, @Nullable ContextSet contextSet, Predicate<? super Node> predicate) {
|
||||
return removeIf(dataType, contextSet, predicate, false);
|
||||
}
|
||||
|
||||
public boolean removeIf(DataType dataType, @Nullable ContextSet contextSet, Predicate<? super Node> predicate, boolean giveDefault) {
|
||||
NodeMap data = getData(dataType);
|
||||
ImmutableCollection<? extends Node> before = data.immutable().values();
|
||||
|
@ -202,13 +202,13 @@ public class LPPermissionAttachment extends PermissionAttachment {
|
||||
|
||||
// remove transient permissions from the holder which were added by this attachment & equal the permission
|
||||
User user = this.permissible.getUser();
|
||||
user.removeIf(DataType.TRANSIENT, null, n -> n.getMetadata(TRANSIENT_SOURCE_KEY).orElse(null) == this && n.getKey().equals(name));
|
||||
user.removeIf(DataType.TRANSIENT, null, n -> n.getMetadata(TRANSIENT_SOURCE_KEY).orElse(null) == this && n.getKey().equals(name), false);
|
||||
}
|
||||
|
||||
private void clearInternal() {
|
||||
// remove all transient permissions added by this attachment
|
||||
User user = this.permissible.getUser();
|
||||
user.removeIf(DataType.TRANSIENT, null, n -> n.getMetadata(TRANSIENT_SOURCE_KEY).orElse(null) == this);
|
||||
user.removeIf(DataType.TRANSIENT, null, n -> n.getMetadata(TRANSIENT_SOURCE_KEY).orElse(null) == this, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user