diff --git a/api/src/main/java/me/lucko/luckperms/api/event/node/NodeAddEvent.java b/api/src/main/java/me/lucko/luckperms/api/event/node/NodeAddEvent.java index 0ceba5248..a458434f8 100644 --- a/api/src/main/java/me/lucko/luckperms/api/event/node/NodeAddEvent.java +++ b/api/src/main/java/me/lucko/luckperms/api/event/node/NodeAddEvent.java @@ -40,7 +40,7 @@ public interface NodeAddEvent extends NodeMutateEvent { * * @return the node that was added */ - @Param(3) + @Param(4) @NonNull Node getNode(); } diff --git a/api/src/main/java/me/lucko/luckperms/api/event/node/NodeMutateEvent.java b/api/src/main/java/me/lucko/luckperms/api/event/node/NodeMutateEvent.java index 4ccb9da31..3f4b474fd 100644 --- a/api/src/main/java/me/lucko/luckperms/api/event/node/NodeMutateEvent.java +++ b/api/src/main/java/me/lucko/luckperms/api/event/node/NodeMutateEvent.java @@ -27,6 +27,7 @@ package me.lucko.luckperms.api.event.node; import me.lucko.luckperms.api.event.LuckPermsEvent; import me.lucko.luckperms.api.event.Param; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.model.PermissionHolder; import me.lucko.luckperms.api.model.group.Group; import me.lucko.luckperms.api.model.user.User; @@ -49,12 +50,20 @@ public interface NodeMutateEvent extends LuckPermsEvent { @Param(0) @NonNull PermissionHolder getTarget(); + /** + * Gets the data type that was mutated. + * + * @return the data type + */ + @Param(1) + @NonNull DataType getDataType(); + /** * Gets an immutable copy of the holders data before the change * * @return the data before the change */ - @Param(1) + @Param(2) @NonNull Set getDataBefore(); /** @@ -62,7 +71,7 @@ public interface NodeMutateEvent extends LuckPermsEvent { * * @return the data after the change */ - @Param(2) + @Param(3) @NonNull Set getDataAfter(); /** diff --git a/api/src/main/java/me/lucko/luckperms/api/event/node/NodeRemoveEvent.java b/api/src/main/java/me/lucko/luckperms/api/event/node/NodeRemoveEvent.java index 68b6777cc..abe96d40f 100644 --- a/api/src/main/java/me/lucko/luckperms/api/event/node/NodeRemoveEvent.java +++ b/api/src/main/java/me/lucko/luckperms/api/event/node/NodeRemoveEvent.java @@ -40,7 +40,7 @@ public interface NodeRemoveEvent extends NodeMutateEvent { * * @return the node that was removed */ - @Param(3) + @Param(4) @NonNull Node getNode(); } diff --git a/common/src/main/java/me/lucko/luckperms/common/model/NodeMapType.java b/api/src/main/java/me/lucko/luckperms/api/model/DataType.java similarity index 56% rename from common/src/main/java/me/lucko/luckperms/common/model/NodeMapType.java rename to api/src/main/java/me/lucko/luckperms/api/model/DataType.java index 60f55cfa6..3599e4a54 100644 --- a/common/src/main/java/me/lucko/luckperms/common/model/NodeMapType.java +++ b/api/src/main/java/me/lucko/luckperms/api/model/DataType.java @@ -23,40 +23,24 @@ * SOFTWARE. */ -package me.lucko.luckperms.common.model; +package me.lucko.luckperms.api.model; -import java.util.function.Supplier; +/** + * Represents a type of data. + */ +public enum DataType { -public enum NodeMapType { - - ENDURING { - @Override - public void run(Runnable enduringTask, Runnable transientTask) { - enduringTask.run(); - } - - @Override - public T supply(Supplier enduringSupplier, Supplier transientSupplier) { - return enduringSupplier.get(); - } - }, - TRANSIENT { - @Override - public void run(Runnable enduringTask, Runnable transientTask) { - transientTask.run(); - } - - @Override - public T supply(Supplier enduringSupplier, Supplier transientSupplier) { - return transientSupplier.get(); - } - }; - - // useful methods for fluent/conditional execution - - public abstract void run(Runnable enduringTask, Runnable transientTask); - - public abstract T supply(Supplier enduringSupplier, Supplier transientSupplier); + /** + * Normal data. + */ + NORMAL, + /** + * Data which expires automatically at the end of a session. + * (when a user logs off) + * + *

This data is never saved to the backend storage provider.

+ */ + TRANSIENT } diff --git a/api/src/main/java/me/lucko/luckperms/api/model/PermissionHolder.java b/api/src/main/java/me/lucko/luckperms/api/model/PermissionHolder.java index 8669316ab..b87705169 100644 --- a/api/src/main/java/me/lucko/luckperms/api/model/PermissionHolder.java +++ b/api/src/main/java/me/lucko/luckperms/api/model/PermissionHolder.java @@ -140,25 +140,6 @@ public interface PermissionHolder { */ @NonNull Data transientData(); - /** - * Represents a type of data. - */ - enum DataType { - - /** - * Normal data. - */ - NORMAL, - - /** - * Data which expires automatically at the end of a session. - * (when a user logs off) - * - *

This data is never saved to the backend storage provider.

- */ - TRANSIENT - } - interface Data { /** diff --git a/api/src/main/java/me/lucko/luckperms/api/node/NodeEqualityPredicate.java b/api/src/main/java/me/lucko/luckperms/api/node/NodeEqualityPredicate.java index 467e2ddbb..72f67c6d1 100644 --- a/api/src/main/java/me/lucko/luckperms/api/node/NodeEqualityPredicate.java +++ b/api/src/main/java/me/lucko/luckperms/api/node/NodeEqualityPredicate.java @@ -27,6 +27,8 @@ package me.lucko.luckperms.api.node; import org.checkerframework.checker.nullness.qual.NonNull; +import java.util.function.Predicate; + /** * A rule for determining if two nodes are equal. * @@ -48,6 +50,17 @@ public interface NodeEqualityPredicate { */ boolean areEqual(@NonNull Node o1, @NonNull Node o2); + /** + * Returns a {@link Predicate}, returning true if the tested node is equal + * to the one given, according to the {@link NodeEqualityPredicate}. + * + * @param node the given node + * @return a predicate + */ + default Predicate equalTo(Node node) { + return other -> areEqual(node, other); + } + /* * Some 'default' implementations of NodeEqualityPredicate are provided below. diff --git a/api/src/main/java/me/lucko/luckperms/api/node/metadata/SimpleNodeMetadataKey.java b/api/src/main/java/me/lucko/luckperms/api/node/metadata/SimpleNodeMetadataKey.java index 740278558..2f771fdff 100644 --- a/api/src/main/java/me/lucko/luckperms/api/node/metadata/SimpleNodeMetadataKey.java +++ b/api/src/main/java/me/lucko/luckperms/api/node/metadata/SimpleNodeMetadataKey.java @@ -1,5 +1,5 @@ /* - * This file is part of luckperms, licensed under the MIT License. + * This file is part of LuckPerms, licensed under the MIT License. * * Copyright (c) lucko (Luck) * Copyright (c) contributors diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/calculator/ChildProcessor.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/calculator/ChildProcessor.java index 2906b9b51..f67f5e4e2 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/calculator/ChildProcessor.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/calculator/ChildProcessor.java @@ -50,7 +50,7 @@ public class ChildProcessor extends AbstractPermissionProcessor implements Permi @Override public TristateResult hasPermission(String permission) { - return this.childPermissions.getOrDefault(permission, TristateResult.UNDEFINED);; + return this.childPermissions.getOrDefault(permission, TristateResult.UNDEFINED); } @Override diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/permissible/LPPermissionAttachment.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/permissible/LPPermissionAttachment.java index 1f77fbf97..0eb8e375e 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/permissible/LPPermissionAttachment.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/permissible/LPPermissionAttachment.java @@ -27,6 +27,7 @@ package me.lucko.luckperms.bukkit.inject.permissible; import com.google.common.base.Preconditions; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.node.Node; import me.lucko.luckperms.api.node.metadata.NodeMetadata; import me.lucko.luckperms.api.node.metadata.NodeMetadataKey; @@ -189,7 +190,7 @@ public class LPPermissionAttachment extends PermissionAttachment implements Node // set the transient node User user = this.permissible.getUser(); - user.setTransientPermission(node); + user.setPermission(DataType.TRANSIENT, node, true); } private void unsetPermissionInternal(String name) { @@ -199,13 +200,13 @@ public class LPPermissionAttachment extends PermissionAttachment implements Node // remove transient permissions from the holder which were added by this attachment & equal the permission User user = this.permissible.getUser(); - user.removeIfTransient(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), null); } private void clearInternal() { // remove all transient permissions added by this attachment User user = this.permissible.getUser(); - user.removeIfTransient(n -> n.getMetadata(TRANSIENT_SOURCE_KEY).orElse(null) == this); + user.removeIf(DataType.TRANSIENT, null, n -> n.getMetadata(TRANSIENT_SOURCE_KEY).orElse(null) == this, null); } @Override diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java index 8f47356fe..f77e3e27f 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java @@ -33,6 +33,7 @@ import de.bananaco.bpermissions.api.WorldManager; import me.lucko.luckperms.api.context.DefaultContextKeys; import me.lucko.luckperms.api.event.cause.CreationCause; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.node.ChatMetaType; import me.lucko.luckperms.common.command.CommandResult; import me.lucko.luckperms.common.command.abstraction.SubCommand; @@ -186,7 +187,7 @@ public class MigrationBPermissions extends SubCommand { if (p.name().isEmpty()) { continue; } - holder.setPermission(NodeFactory.make(p.name(), p.isTrue(), "global", world.getName())); + holder.setPermission(DataType.NORMAL, NodeFactory.make(p.name(), p.isTrue(), "global", world.getName()), true); // Include any child permissions for (Map.Entry child : p.getChildren().entrySet()) { @@ -194,7 +195,7 @@ public class MigrationBPermissions extends SubCommand { continue; } - holder.setPermission(NodeFactory.make(child.getKey(), child.getValue(), "global", world.getName())); + holder.setPermission(DataType.NORMAL, NodeFactory.make(child.getKey(), child.getValue(), "global", world.getName()), true); } } @@ -205,7 +206,7 @@ public class MigrationBPermissions extends SubCommand { parentName = NodeFactory.DEFAULT_GROUP_NAME; } - holder.setPermission(NodeFactory.make(NodeFactory.groupNode(parentName), true, "global", world.getName())); + holder.setPermission(DataType.NORMAL, NodeFactory.make(NodeFactory.groupNode(parentName), true, "global", world.getName()), true); }); // Migrate existing meta @@ -216,11 +217,11 @@ public class MigrationBPermissions extends SubCommand { if (meta.getKey().equalsIgnoreCase(NodeTypes.PREFIX_KEY) || meta.getKey().equalsIgnoreCase(NodeTypes.SUFFIX_KEY)) { ChatMetaType type = ChatMetaType.valueOf(meta.getKey().toUpperCase()); - holder.setPermission(NodeFactory.buildChatMetaNode(type, c.getPriority(), meta.getValue()).withContext(DefaultContextKeys.WORLD_KEY, world.getName()).build()); + holder.setPermission(DataType.NORMAL, NodeFactory.buildChatMetaNode(type, c.getPriority(), meta.getValue()).withContext(DefaultContextKeys.WORLD_KEY, world.getName()).build(), true); continue; } - holder.setPermission(NodeFactory.buildMetaNode(meta.getKey(), meta.getValue()).withContext(DefaultContextKeys.WORLD_KEY, world.getName()).build()); + holder.setPermission(DataType.NORMAL, NodeFactory.buildMetaNode(meta.getKey(), meta.getValue()).withContext(DefaultContextKeys.WORLD_KEY, world.getName()).build(), true); } } } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationGroupManager.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationGroupManager.java index 227196ef1..3ffa75e3a 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationGroupManager.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationGroupManager.java @@ -27,6 +27,7 @@ package me.lucko.luckperms.bukkit.migration; import me.lucko.luckperms.api.context.DefaultContextKeys; import me.lucko.luckperms.api.event.cause.CreationCause; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.node.ChatMetaType; import me.lucko.luckperms.api.node.Node; import me.lucko.luckperms.common.command.CommandResult; @@ -104,11 +105,11 @@ public class MigrationGroupManager extends SubCommand { for (String node : g.getPermissionList()) { if (node.isEmpty()) continue; - group.setPermission(MigrationUtils.parseNode(node, true).build()); + group.setPermission(DataType.NORMAL, MigrationUtils.parseNode(node, true).build(), true); } for (String s : g.getInherits()) { if (s.isEmpty()) continue; - group.setPermission(NodeFactory.make(NodeFactory.groupNode(MigrationUtils.standardizeName(s)))); + group.setPermission(DataType.NORMAL, NodeFactory.make(NodeFactory.groupNode(MigrationUtils.standardizeName(s))), true); } plugin.getStorage().saveGroup(group); @@ -226,7 +227,7 @@ public class MigrationGroupManager extends SubCommand { Group group = plugin.getStorage().createAndLoadGroup(e.getKey(), CreationCause.INTERNAL).join(); for (Node node : e.getValue()) { - group.setPermission(node); + group.setPermission(DataType.NORMAL, node, true); } plugin.getStorage().saveGroup(group); @@ -240,14 +241,14 @@ public class MigrationGroupManager extends SubCommand { User user = plugin.getStorage().loadUser(e.getKey().getUuid(), e.getKey().getUsername().orElse(null)).join(); for (Node node : e.getValue()) { - user.setPermission(node); + user.setPermission(DataType.NORMAL, node, true); } String primaryGroup = primaryGroups.get(e.getKey().getUuid()); if (primaryGroup != null && !primaryGroup.isEmpty()) { - user.setPermission(NodeFactory.buildGroupNode(primaryGroup).build()); + user.setPermission(DataType.NORMAL, NodeFactory.buildGroupNode(primaryGroup).build(), true); user.getPrimaryGroup().setStoredValue(primaryGroup); - user.unsetPermission(NodeFactory.buildGroupNode(NodeFactory.DEFAULT_GROUP_NAME).build()); + user.unsetPermission(DataType.NORMAL, NodeFactory.buildGroupNode(NodeFactory.DEFAULT_GROUP_NAME).build()); } plugin.getStorage().saveUser(user); diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsBukkit.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsBukkit.java index bb3ca8902..12ab030ac 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsBukkit.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsBukkit.java @@ -29,6 +29,7 @@ import com.platymuus.bukkit.permissions.PermissionsPlugin; import me.lucko.luckperms.api.context.DefaultContextKeys; import me.lucko.luckperms.api.event.cause.CreationCause; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.common.command.CommandResult; import me.lucko.luckperms.common.command.abstraction.SubCommand; import me.lucko.luckperms.common.command.access.CommandPermission; @@ -130,7 +131,7 @@ public class MigrationPermissionsBukkit extends SubCommand { ConfigurationSection permsSection = data.getConfigurationSection("permissions"); for (String perm : permsSection.getKeys(false)) { boolean value = permsSection.getBoolean(perm); - holder.setPermission(MigrationUtils.parseNode(perm, value).build()); + holder.setPermission(DataType.NORMAL, MigrationUtils.parseNode(perm, value).build(), true); } } @@ -141,7 +142,7 @@ public class MigrationPermissionsBukkit extends SubCommand { ConfigurationSection permsSection = worldSection.getConfigurationSection(world); for (String perm : permsSection.getKeys(false)) { boolean value = permsSection.getBoolean(perm); - holder.setPermission(MigrationUtils.parseNode(perm, value).withContext(DefaultContextKeys.WORLD_KEY, world).build()); + holder.setPermission(DataType.NORMAL, MigrationUtils.parseNode(perm, value).withContext(DefaultContextKeys.WORLD_KEY, world).build(), true); } } } @@ -151,13 +152,13 @@ public class MigrationPermissionsBukkit extends SubCommand { if (data.isList("groups")) { List groups = data.getStringList("groups"); for (String group : groups) { - holder.setPermission(NodeFactory.buildGroupNode(MigrationUtils.standardizeName(group)).build()); + holder.setPermission(DataType.NORMAL, NodeFactory.buildGroupNode(MigrationUtils.standardizeName(group)).build(), true); } } if (data.isList("inheritance")) { List groups = data.getStringList("inheritance"); for (String group : groups) { - holder.setPermission(NodeFactory.buildGroupNode(MigrationUtils.standardizeName(group)).build()); + holder.setPermission(DataType.NORMAL, NodeFactory.buildGroupNode(MigrationUtils.standardizeName(group)).build(), true); } } } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java index 67dcabffe..a4d246e0c 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java @@ -29,6 +29,7 @@ import com.google.common.base.Strings; import me.lucko.luckperms.api.context.DefaultContextKeys; import me.lucko.luckperms.api.event.cause.CreationCause; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.common.command.CommandResult; import me.lucko.luckperms.common.command.abstraction.SubCommand; import me.lucko.luckperms.common.command.access.CommandPermission; @@ -200,7 +201,7 @@ public class MigrationPermissionsEx extends SubCommand { String world = standardizeWorld(worldData.getKey()); for (String node : worldData.getValue()) { if (node.isEmpty()) continue; - holder.setPermission(MigrationUtils.parseNode(node, true).withContext(DefaultContextKeys.WORLD_KEY, world).build()); + holder.setPermission(DataType.NORMAL, MigrationUtils.parseNode(node, true).withContext(DefaultContextKeys.WORLD_KEY, world).build(), true); } } @@ -222,7 +223,7 @@ public class MigrationPermissionsEx extends SubCommand { for (String node : worldData.getValue()) { if (node.isEmpty()) continue; long expiry = timedPermissionsTime.getOrDefault(Strings.nullToEmpty(world) + ":" + node, 0L); - holder.setPermission(MigrationUtils.parseNode(node, true).withContext(DefaultContextKeys.WORLD_KEY, world).expiry(expiry).build()); + holder.setPermission(DataType.NORMAL, MigrationUtils.parseNode(node, true).withContext(DefaultContextKeys.WORLD_KEY, world).expiry(expiry).build(), true); } } @@ -250,7 +251,7 @@ public class MigrationPermissionsEx extends SubCommand { } } - holder.setPermission(NodeFactory.buildGroupNode(MigrationUtils.standardizeName(parentName)).withContext(DefaultContextKeys.WORLD_KEY, world).expiry(expiry).build()); + holder.setPermission(DataType.NORMAL, NodeFactory.buildGroupNode(MigrationUtils.standardizeName(parentName)).withContext(DefaultContextKeys.WORLD_KEY, world).expiry(expiry).build(), true); // migrate primary groups if (world == null && holder instanceof User && expiry == 0) { @@ -264,7 +265,7 @@ public class MigrationPermissionsEx extends SubCommand { if (primary != null && !primary.isEmpty() && !primary.equalsIgnoreCase(NodeFactory.DEFAULT_GROUP_NAME)) { User user = ((User) holder); user.getPrimaryGroup().setStoredValue(primary); - user.unsetPermission(NodeFactory.buildGroupNode(NodeFactory.DEFAULT_GROUP_NAME).build()); + holder.unsetPermission(DataType.NORMAL, NodeFactory.buildGroupNode(NodeFactory.DEFAULT_GROUP_NAME).build()); } } @@ -273,11 +274,11 @@ public class MigrationPermissionsEx extends SubCommand { String suffix = entity.getOwnSuffix(); if (prefix != null && !prefix.isEmpty()) { - holder.setPermission(NodeFactory.buildPrefixNode(weight, prefix).build()); + holder.setPermission(DataType.NORMAL, NodeFactory.buildPrefixNode(weight, prefix).build(), true); } if (suffix != null && !suffix.isEmpty()) { - holder.setPermission(NodeFactory.buildSuffixNode(weight, suffix).build()); + holder.setPermission(DataType.NORMAL, NodeFactory.buildSuffixNode(weight, suffix).build(), true); } // migrate options @@ -302,7 +303,7 @@ public class MigrationPermissionsEx extends SubCommand { continue; } - holder.setPermission(NodeFactory.buildMetaNode(opt.getKey(), opt.getValue()).withContext(DefaultContextKeys.WORLD_KEY, world).build()); + holder.setPermission(DataType.NORMAL, NodeFactory.buildMetaNode(opt.getKey(), opt.getValue()).withContext(DefaultContextKeys.WORLD_KEY, world).build(), true); } } } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPowerfulPerms.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPowerfulPerms.java index 838842c50..a1351a3c4 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPowerfulPerms.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPowerfulPerms.java @@ -35,6 +35,7 @@ import com.zaxxer.hikari.HikariDataSource; import me.lucko.luckperms.api.context.DefaultContextKeys; import me.lucko.luckperms.api.event.cause.CreationCause; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.node.NodeBuilder; import me.lucko.luckperms.common.command.CommandResult; import me.lucko.luckperms.common.command.abstraction.SubCommand; @@ -171,7 +172,7 @@ public class MigrationPowerfulPerms extends SubCommand { } for (Group parent : g.getParents()) { - group.setPermission(NodeFactory.buildGroupNode(parent.getName().toLowerCase()).build()); + group.setPermission(DataType.NORMAL, NodeFactory.buildGroupNode(parent.getName().toLowerCase()).build(), true); } // server --> prefix afaik @@ -184,9 +185,9 @@ public class MigrationPowerfulPerms extends SubCommand { } if (server != null) { - group.setPermission(NodeFactory.buildPrefixNode(g.getRank(), prefix.getValue()).withContext(DefaultContextKeys.SERVER_KEY, server).build()); + group.setPermission(DataType.NORMAL, NodeFactory.buildPrefixNode(g.getRank(), prefix.getValue()).withContext(DefaultContextKeys.SERVER_KEY, server).build(), true); } else { - group.setPermission(NodeFactory.buildPrefixNode(g.getRank(), prefix.getValue()).build()); + group.setPermission(DataType.NORMAL, NodeFactory.buildPrefixNode(g.getRank(), prefix.getValue()).build(), true); } } @@ -199,9 +200,9 @@ public class MigrationPowerfulPerms extends SubCommand { } if (server != null) { - group.setPermission(NodeFactory.buildSuffixNode(g.getRank(), suffix.getValue()).withContext(DefaultContextKeys.SERVER_KEY, server).build()); + group.setPermission(DataType.NORMAL, NodeFactory.buildSuffixNode(g.getRank(), suffix.getValue()).withContext(DefaultContextKeys.SERVER_KEY, server).build(), true); } else { - group.setPermission(NodeFactory.buildSuffixNode(g.getRank(), suffix.getValue()).build()); + group.setPermission(DataType.NORMAL, NodeFactory.buildSuffixNode(g.getRank(), suffix.getValue()).build(), true); } } @@ -246,18 +247,18 @@ public class MigrationPowerfulPerms extends SubCommand { String suffix = joinFuture(pm.getPlayerOwnSuffix(uuid)); if (prefix != null && !prefix.isEmpty()) { - user.setPermission(NodeFactory.buildPrefixNode(maxWeight.get(), prefix).build()); + user.setPermission(DataType.NORMAL, NodeFactory.buildPrefixNode(maxWeight.get(), prefix).build(), true); } if (suffix != null && !suffix.isEmpty()) { - user.setPermission(NodeFactory.buildSuffixNode(maxWeight.get(), suffix).build()); + user.setPermission(DataType.NORMAL, NodeFactory.buildSuffixNode(maxWeight.get(), suffix).build(), true); } Group primaryGroup = joinFuture(pm.getPlayerPrimaryGroup(uuid)); if (primaryGroup != null && primaryGroup.getName() != null) { String primary = primaryGroup.getName().toLowerCase(); if (!primary.equals(NodeFactory.DEFAULT_GROUP_NAME)) { - user.setPermission(NodeFactory.buildGroupNode(primary).build()); + user.setPermission(DataType.NORMAL, NodeFactory.buildGroupNode(primary).build(), true); user.getPrimaryGroup().setStoredValue(primary); } } @@ -308,7 +309,7 @@ public class MigrationPowerfulPerms extends SubCommand { if (server != null) nb.withContext(DefaultContextKeys.SERVER_KEY, server); if (world != null) nb.withContext(DefaultContextKeys.WORLD_KEY, world); - holder.setPermission(nb.build()); + holder.setPermission(DataType.NORMAL, nb.build(), true); } private void applyGroup(PermissionManager pm, PermissionHolder holder, CachedGroup g, String server) { @@ -330,7 +331,7 @@ public class MigrationPowerfulPerms extends SubCommand { nb.withContext(DefaultContextKeys.SERVER_KEY, server); } - holder.setPermission(nb.build()); + holder.setPermission(DataType.NORMAL, nb.build(), true); } private static T joinFuture(Future future) { diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationZPermissions.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationZPermissions.java index 226bfd8da..3233f164c 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationZPermissions.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationZPermissions.java @@ -27,6 +27,7 @@ package me.lucko.luckperms.bukkit.migration; import me.lucko.luckperms.api.context.DefaultContextKeys; import me.lucko.luckperms.api.event.cause.CreationCause; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.node.ChatMetaType; import me.lucko.luckperms.api.node.Node; import me.lucko.luckperms.common.command.CommandResult; @@ -177,7 +178,7 @@ public class MigrationZPermissions extends SubCommand { // migrate groups Set parents = userParents.get(u); if (parents != null) { - parents.forEach(user::setPermission); + parents.forEach(node -> user.setPermission(DataType.NORMAL, node, true)); } user.getPrimaryGroup().setStoredValue(MigrationUtils.standardizeName(service.getPlayerPrimaryGroup(u))); @@ -197,9 +198,9 @@ public class MigrationZPermissions extends SubCommand { if (e.getPermission().isEmpty()) continue; if (e.getWorld() != null && !e.getWorld().getName().equals("")) { - holder.setPermission(NodeFactory.builder(e.getPermission()).value(e.isValue()).withContext(DefaultContextKeys.WORLD_KEY, e.getWorld().getName()).build()); + holder.setPermission(DataType.NORMAL, NodeFactory.builder(e.getPermission()).value(e.isValue()).withContext(DefaultContextKeys.WORLD_KEY, e.getWorld().getName()).build(), true); } else { - holder.setPermission(NodeFactory.builder(e.getPermission()).value(e.isValue()).build()); + holder.setPermission(DataType.NORMAL, NodeFactory.builder(e.getPermission()).value(e.isValue()).build(), true); } } @@ -207,7 +208,7 @@ public class MigrationZPermissions extends SubCommand { if (entity.isGroup()) { for (PermissionEntity inheritance : entity.getParents()) { if (!inheritance.getDisplayName().equals(holder.getObjectName())) { - holder.setPermission(NodeFactory.buildGroupNode(MigrationUtils.standardizeName(inheritance.getDisplayName())).build()); + holder.setPermission(DataType.NORMAL, NodeFactory.buildGroupNode(MigrationUtils.standardizeName(inheritance.getDisplayName())).build(), true); } } } @@ -223,9 +224,9 @@ public class MigrationZPermissions extends SubCommand { if (key.equals(NodeTypes.PREFIX_KEY) || key.equals(NodeTypes.SUFFIX_KEY)) { ChatMetaType type = ChatMetaType.valueOf(key.toUpperCase()); - holder.setPermission(NodeFactory.buildChatMetaNode(type, weight, valueString).build()); + holder.setPermission(DataType.NORMAL, NodeFactory.buildChatMetaNode(type, weight, valueString).build(), true); } else { - holder.setPermission(NodeFactory.buildMetaNode(key, valueString).build()); + holder.setPermission(DataType.NORMAL, NodeFactory.buildMetaNode(key, valueString).build(), true); } } } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/LuckPermsVaultChat.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/LuckPermsVaultChat.java index 663ad6439..5609313f7 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/LuckPermsVaultChat.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/LuckPermsVaultChat.java @@ -29,6 +29,7 @@ import com.google.common.base.Strings; import me.lucko.luckperms.api.context.DefaultContextKeys; import me.lucko.luckperms.api.context.ImmutableContextSet; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.node.ChatMetaType; import me.lucko.luckperms.api.node.NodeBuilder; import me.lucko.luckperms.api.node.types.MetaNode; @@ -263,7 +264,7 @@ public class LuckPermsVaultChat extends AbstractVaultChat { } // remove all prefixes/suffixes directly set on the user/group - holder.removeIfEnduring(node -> type.nodeType().matches(node)); + holder.removeIf(DataType.NORMAL, null, node -> type.nodeType().matches(node), null); if (value == null) { this.vaultPermission.holderSave(holder); @@ -279,7 +280,8 @@ public class LuckPermsVaultChat extends AbstractVaultChat { chatMetaNode.withContext(DefaultContextKeys.SERVER_KEY, this.vaultPermission.getVaultServer()); chatMetaNode.withContext(DefaultContextKeys.WORLD_KEY, world); - holder.setPermission(chatMetaNode.build()); // assume success + // assume success + holder.setPermission(DataType.NORMAL, chatMetaNode.build(), true); this.vaultPermission.holderSave(holder); } @@ -288,7 +290,7 @@ public class LuckPermsVaultChat extends AbstractVaultChat { logMsg("#setMeta: %s - %s - %s - %s", holder.getPlainDisplayName(), key, value, world); } - holder.removeIfEnduring(n -> n instanceof MetaNode && ((MetaNode) n).getMetaKey().equals(key)); + holder.removeIf(DataType.NORMAL, null, n -> n instanceof MetaNode && ((MetaNode) n).getMetaKey().equals(key), null); if (value == null) { this.vaultPermission.holderSave(holder); @@ -305,7 +307,8 @@ public class LuckPermsVaultChat extends AbstractVaultChat { metaNode.withContext(DefaultContextKeys.SERVER_KEY, this.vaultPermission.getVaultServer()); metaNode.withContext(DefaultContextKeys.WORLD_KEY, world); - holder.setPermission(metaNode.build()); // assume success + // assume success + holder.setPermission(DataType.NORMAL, metaNode.build(), true); this.vaultPermission.holderSave(holder); } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/LuckPermsVaultPermission.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/LuckPermsVaultPermission.java index 71441fbf2..1e97ed716 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/LuckPermsVaultPermission.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/LuckPermsVaultPermission.java @@ -30,6 +30,7 @@ import com.google.common.base.Preconditions; import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.api.context.DefaultContextKeys; import me.lucko.luckperms.api.context.MutableContextSet; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.node.NodeType; import me.lucko.luckperms.api.node.Tristate; import me.lucko.luckperms.api.query.Flag; @@ -261,7 +262,7 @@ public class LuckPermsVaultPermission extends AbstractVaultPermission { PermissionHolder user = lookupUser(uuid); ContextSet contexts = getQueryOptions(uuid, world).context(); - String[] ret = user.enduringData().immutable().values().stream() + String[] ret = user.normalData().immutable().values().stream() .filter(NodeType.INHERITANCE::matches) .map(NodeType.INHERITANCE::cast) .filter(n -> n.shouldApplyWithContext(contexts)) @@ -438,7 +439,7 @@ public class LuckPermsVaultPermission extends AbstractVaultPermission { logMsg("#holderAddPermission: %s - %s - %s", holder.getPlainDisplayName(), permission, world); } - if (((Result) holder.setPermission(NodeFactory.make(permission, true, getVaultServer(), world))).wasSuccessful()) { + if (((Result) holder.setPermission(DataType.NORMAL, NodeFactory.make(permission, true, getVaultServer(), world), true)).wasSuccessful()) { return holderSave(holder); } return false; @@ -452,7 +453,7 @@ public class LuckPermsVaultPermission extends AbstractVaultPermission { logMsg("#holderRemovePermission: %s - %s - %s", holder.getPlainDisplayName(), permission, world); } - if (((Result) holder.unsetPermission(NodeFactory.make(permission, getVaultServer(), world))).wasSuccessful()) { + if (((Result) holder.unsetPermission(DataType.NORMAL, NodeFactory.make(permission, getVaultServer(), world))).wasSuccessful()) { return holderSave(holder); } return false; diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/migration/MigrationBungeePerms.java b/bungee/src/main/java/me/lucko/luckperms/bungee/migration/MigrationBungeePerms.java index 54ccd9cc9..e7ee9b1af 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/migration/MigrationBungeePerms.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/migration/MigrationBungeePerms.java @@ -27,6 +27,7 @@ package me.lucko.luckperms.bungee.migration; import me.lucko.luckperms.api.context.DefaultContextKeys; import me.lucko.luckperms.api.event.cause.CreationCause; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.common.command.CommandResult; import me.lucko.luckperms.common.command.abstraction.SubCommand; import me.lucko.luckperms.common.command.access.CommandPermission; @@ -132,21 +133,21 @@ public class MigrationBungeePerms extends SubCommand { // Migrate global perms for (String perm : entity.getPerms()) { if (perm.isEmpty()) continue; - holder.setPermission(MigrationUtils.parseNode(perm, true).build()); + holder.setPermission(DataType.NORMAL, MigrationUtils.parseNode(perm, true).build(), true); } // Migrate per-server perms for (Map.Entry e : entity.getServers().entrySet()) { for (String perm : e.getValue().getPerms()) { if (perm.isEmpty()) continue; - holder.setPermission(MigrationUtils.parseNode(perm, true).withContext(DefaultContextKeys.SERVER_KEY, e.getKey()).build()); + holder.setPermission(DataType.NORMAL, MigrationUtils.parseNode(perm, true).withContext(DefaultContextKeys.SERVER_KEY, e.getKey()).build(), true); } // Migrate per-world perms for (Map.Entry we : e.getValue().getWorlds().entrySet()) { for (String perm : we.getValue().getPerms()) { if (perm.isEmpty()) continue; - holder.setPermission(MigrationUtils.parseNode(perm, true).withContext(DefaultContextKeys.SERVER_KEY, e.getKey()).withContext(DefaultContextKeys.WORLD_KEY, we.getKey()).build()); + holder.setPermission(DataType.NORMAL, MigrationUtils.parseNode(perm, true).withContext(DefaultContextKeys.SERVER_KEY, e.getKey()).withContext(DefaultContextKeys.WORLD_KEY, we.getKey()).build(), true); } } } @@ -154,7 +155,7 @@ public class MigrationBungeePerms extends SubCommand { // Migrate any parent groups for (String inherit : parents) { if (inherit.isEmpty()) continue; - holder.setPermission(NodeFactory.buildGroupNode(MigrationUtils.standardizeName(inherit)).build()); + holder.setPermission(DataType.NORMAL, NodeFactory.buildGroupNode(MigrationUtils.standardizeName(inherit)).build(), true); } // Migrate prefix and suffix @@ -162,10 +163,10 @@ public class MigrationBungeePerms extends SubCommand { String suffix = entity.getSuffix(); if (prefix != null && !prefix.isEmpty()) { - holder.setPermission(NodeFactory.buildPrefixNode(weight, prefix).build()); + holder.setPermission(DataType.NORMAL, NodeFactory.buildPrefixNode(weight, prefix).build(), true); } if (suffix != null && !suffix.isEmpty()) { - holder.setPermission(NodeFactory.buildSuffixNode(weight, suffix).build()); + holder.setPermission(DataType.NORMAL, NodeFactory.buildSuffixNode(weight, suffix).build(), true); } } } diff --git a/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiPermissionHolder.java b/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiPermissionHolder.java index 509ebada8..c304f9b0a 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiPermissionHolder.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiPermissionHolder.java @@ -31,6 +31,7 @@ import me.lucko.luckperms.api.cacheddata.CachedDataManager; import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.api.context.ImmutableContextSet; import me.lucko.luckperms.api.model.DataMutateResult; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.model.TemporaryDataMutateResult; import me.lucko.luckperms.api.model.TemporaryMergeBehaviour; import me.lucko.luckperms.api.node.Node; @@ -38,7 +39,6 @@ import me.lucko.luckperms.api.node.NodeEqualityPredicate; import me.lucko.luckperms.api.node.NodeType; import me.lucko.luckperms.api.node.Tristate; import me.lucko.luckperms.api.query.QueryOptions; -import me.lucko.luckperms.common.model.NodeMapType; import me.lucko.luckperms.common.model.PermissionHolder; import me.lucko.luckperms.common.node.comparator.NodeWithContextComparator; import me.lucko.luckperms.common.node.utils.NodeTools; @@ -58,12 +58,12 @@ import java.util.function.Predicate; public class ApiPermissionHolder implements me.lucko.luckperms.api.model.PermissionHolder { private final PermissionHolder handle; - private final Enduring enduringData; + private final Normal normalData; private final Transient transientData; ApiPermissionHolder(PermissionHolder handle) { this.handle = Objects.requireNonNull(handle, "handle"); - this.enduringData = new Enduring(); + this.normalData = new Normal(); this.transientData = new Transient(); } @@ -95,7 +95,7 @@ public class ApiPermissionHolder implements me.lucko.luckperms.api.model.Permiss public Data getData(@NonNull DataType dataType) { switch (dataType) { case NORMAL: - return this.enduringData; + return this.normalData; case TRANSIENT: return this.transientData; default: @@ -105,7 +105,7 @@ public class ApiPermissionHolder implements me.lucko.luckperms.api.model.Permiss @Override public @NonNull Data data() { - return this.enduringData; + return this.normalData; } @Override @@ -115,12 +115,12 @@ public class ApiPermissionHolder implements me.lucko.luckperms.api.model.Permiss @Override public @NonNull List getNodes() { - return this.handle.getOwnNodes(); + return this.handle.getOwnNodes(QueryOptions.nonContextual()); } @Override public @NonNull SortedSet getDistinctNodes() { - return this.handle.getOwnNodesSorted(); + return this.handle.getOwnNodesSorted(QueryOptions.nonContextual()); } @Override @@ -149,137 +149,99 @@ public class ApiPermissionHolder implements me.lucko.luckperms.api.model.Permiss return this.handle.inheritsPermission(node, equalityPredicate); } - private final class Enduring implements Data { + private abstract class AbstractData implements Data { + private final DataType dataType; + + private AbstractData(DataType dataType) { + this.dataType = dataType; + } + @Override public @NonNull Map> getNodes() { - return ApiPermissionHolder.this.handle.enduringData().immutable().asMap(); + return ApiPermissionHolder.this.handle.getData(this.dataType).immutable().asMap(); } @Override public @NonNull Set getFlattenedNodes() { - return ApiPermissionHolder.this.handle.enduringData().asSet(); + return ApiPermissionHolder.this.handle.getData(this.dataType).asSet(); } @Override public @NonNull Tristate hasNode(@NonNull Node node, @NonNull NodeEqualityPredicate equalityPredicate) { - return ApiPermissionHolder.this.handle.hasPermission(NodeMapType.ENDURING, node, equalityPredicate); + return ApiPermissionHolder.this.handle.hasPermission(this.dataType, node, equalityPredicate); } @Override public @NonNull DataMutateResult addNode(@NonNull Node node) { - return ApiPermissionHolder.this.handle.setPermission(node); + return ApiPermissionHolder.this.handle.setPermission(this.dataType, node, true); } @Override public @NonNull TemporaryDataMutateResult addNode(@NonNull Node node, @NonNull TemporaryMergeBehaviour temporaryMergeBehaviour) { - return ApiPermissionHolder.this.handle.setPermission(node, temporaryMergeBehaviour); + return ApiPermissionHolder.this.handle.setPermission(this.dataType, node, temporaryMergeBehaviour); } @Override public @NonNull DataMutateResult removeNode(@NonNull Node node) { - return ApiPermissionHolder.this.handle.unsetPermission(node); + return ApiPermissionHolder.this.handle.unsetPermission(this.dataType, node); } @Override public void clearMatching(@NonNull Predicate test) { - ApiPermissionHolder.this.handle.removeIfEnduring(test); + ApiPermissionHolder.this.handle.removeIf(this.dataType, null, test, null); } @Override public void clearNodes() { - ApiPermissionHolder.this.handle.clearEnduringNodes(); + ApiPermissionHolder.this.handle.clearNodes(this.dataType, null); } @Override public void clearNodes(@NonNull ContextSet contextSet) { - ApiPermissionHolder.this.handle.clearEnduringNodes(contextSet); - } - - @Override - public void clearParents() { - ApiPermissionHolder.this.handle.clearEnduringParents(true); - } - - @Override - public void clearParents(@NonNull ContextSet contextSet) { - ApiPermissionHolder.this.handle.clearEnduringParents(contextSet, true); + ApiPermissionHolder.this.handle.clearNodes(this.dataType, contextSet); } @Override public void clearMeta() { - ApiPermissionHolder.this.handle.removeIfEnduring(NodeType.META_OR_CHAT_META::matches); + ApiPermissionHolder.this.handle.removeIf(this.dataType, null, NodeType.META_OR_CHAT_META::matches, null); } @Override public void clearMeta(@NonNull ContextSet contextSet) { - ApiPermissionHolder.this.handle.removeIfEnduring(contextSet, NodeType.META_OR_CHAT_META::matches); + ApiPermissionHolder.this.handle.removeIf(this.dataType, contextSet, NodeType.META_OR_CHAT_META::matches, null); } } - private final class Transient implements Data { - @Override - public @NonNull Map> getNodes() { - return ApiPermissionHolder.this.handle.transientData().immutable().asMap(); - } - - @Override - public @NonNull Set getFlattenedNodes() { - return ApiPermissionHolder.this.handle.transientData().asSet(); - } - - @Override - public @NonNull Tristate hasNode(@NonNull Node node, @NonNull NodeEqualityPredicate equalityPredicate) { - return ApiPermissionHolder.this.handle.hasPermission(NodeMapType.TRANSIENT, node, equalityPredicate); - } - - @Override - public @NonNull DataMutateResult addNode(@NonNull Node node) { - return ApiPermissionHolder.this.handle.setTransientPermission(node); - } - - @Override - public @NonNull TemporaryDataMutateResult addNode(@NonNull Node node, @NonNull TemporaryMergeBehaviour temporaryMergeBehaviour) { - return ApiPermissionHolder.this.handle.setTransientPermission(node, temporaryMergeBehaviour); - } - - @Override - public @NonNull DataMutateResult removeNode(@NonNull Node node) { - return ApiPermissionHolder.this.handle.unsetTransientPermission(node); - } - - @Override - public void clearMatching(@NonNull Predicate test) { - ApiPermissionHolder.this.handle.removeIfTransient(test); - } - - @Override - public void clearNodes() { - ApiPermissionHolder.this.handle.clearTransientNodes(); - } - - @Override - public void clearNodes(@NonNull ContextSet contextSet) { - ApiPermissionHolder.this.handle.clearTransientNodes(contextSet); + private final class Normal extends AbstractData implements Data { + private Normal() { + super(DataType.NORMAL); } @Override public void clearParents() { - ApiPermissionHolder.this.handle.removeIfTransient(NodeType.INHERITANCE::matches); + ApiPermissionHolder.this.handle.clearNormalParents(null, true); } @Override public void clearParents(@NonNull ContextSet contextSet) { - ApiPermissionHolder.this.handle.removeIfTransient(contextSet, NodeType.INHERITANCE::matches); + ApiPermissionHolder.this.handle.clearNormalParents(contextSet, true); + } + + } + + private final class Transient extends AbstractData implements Data { + private Transient() { + super(DataType.TRANSIENT); } @Override - public void clearMeta() { - ApiPermissionHolder.this.handle.removeIfTransient(NodeType.META_OR_CHAT_META::matches); + public void clearParents() { + ApiPermissionHolder.this.handle.removeIf(DataType.TRANSIENT, null, NodeType.INHERITANCE::matches, null); } @Override - public void clearMeta(@NonNull ContextSet contextSet) { - ApiPermissionHolder.this.handle.removeIfTransient(contextSet, NodeType.META_OR_CHAT_META::matches); + public void clearParents(@NonNull ContextSet contextSet) { + ApiPermissionHolder.this.handle.removeIf(DataType.TRANSIENT, contextSet, NodeType.INHERITANCE::matches, null); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiUser.java b/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiUser.java index cdfff0b64..79fe7f877 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiUser.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiUser.java @@ -28,9 +28,9 @@ package me.lucko.luckperms.common.api.implementation; import com.google.common.base.Preconditions; import me.lucko.luckperms.api.model.DataMutateResult; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.node.NodeEqualityPredicate; import me.lucko.luckperms.common.cacheddata.UserCachedDataManager; -import me.lucko.luckperms.common.model.NodeMapType; import me.lucko.luckperms.common.model.User; import me.lucko.luckperms.common.node.factory.NodeFactory; @@ -79,7 +79,7 @@ public class ApiUser extends ApiPermissionHolder implements me.lucko.luckperms.a return DataMutateResult.ALREADY_HAS; } - if (!this.handle.hasPermission(NodeMapType.ENDURING, NodeFactory.buildGroupNode(group.toLowerCase()).build(), NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE).asBoolean()) { + if (!this.handle.hasPermission(DataType.NORMAL, NodeFactory.buildGroupNode(group.toLowerCase()).build(), NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE).asBoolean()) { return DataMutateResult.FAIL; } diff --git a/common/src/main/java/me/lucko/luckperms/common/backup/Exporter.java b/common/src/main/java/me/lucko/luckperms/common/backup/Exporter.java index 541eca942..75fa0a650 100644 --- a/common/src/main/java/me/lucko/luckperms/common/backup/Exporter.java +++ b/common/src/main/java/me/lucko/luckperms/common/backup/Exporter.java @@ -130,7 +130,7 @@ public class Exporter implements Runnable { } write(writer, "# Export group: " + group.getName()); - for (Node node : group.enduringData().immutable().values()) { + for (Node node : group.normalData().immutable().values()) { write(writer, "/lp " + NodeFactory.nodeAsCommand(node, group.getName(), HolderType.GROUP, true, false)); } write(writer, ""); @@ -220,7 +220,7 @@ public class Exporter implements Runnable { output.add("# Export user: " + user.getUuid().toString() + " - " + user.getName().orElse("unknown username")); boolean inDefault = false; - for (Node node : user.enduringData().immutable().values()) { + for (Node node : user.normalData().immutable().values()) { if (NodeType.INHERITANCE.tryCast(node).map(n -> n.getGroupName().equalsIgnoreCase(NodeFactory.DEFAULT_GROUP_NAME)).orElse(false)) { inDefault = true; continue; diff --git a/common/src/main/java/me/lucko/luckperms/common/command/CommandManager.java b/common/src/main/java/me/lucko/luckperms/common/command/CommandManager.java index 5ba121ab3..fea33e75c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/command/CommandManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/command/CommandManager.java @@ -27,6 +27,7 @@ package me.lucko.luckperms.common.command; import com.google.common.collect.ImmutableList; +import me.lucko.luckperms.api.query.QueryOptions; import me.lucko.luckperms.common.command.abstraction.Command; import me.lucko.luckperms.common.command.abstraction.CommandException; import me.lucko.luckperms.common.command.access.CommandPermission; @@ -172,7 +173,7 @@ public class CommandManager { return CommandResult.SUCCESS; } else { Collection groups = this.plugin.getGroupManager().getAll().values(); - if (groups.size() <= 1 && groups.stream().allMatch(g -> g.getOwnNodes().isEmpty())) { + if (groups.size() <= 1 && groups.stream().allMatch(g -> g.getOwnNodes(QueryOptions.nonContextual()).isEmpty())) { Message.FIRST_TIME_SETUP.send(sender, label, sender.getName()); } else { Message.NO_PERMISSION_FOR_SUBCOMMANDS.send(sender); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddChatMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddChatMeta.java index dcec00c98..4fd33caa3 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddChatMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddChatMeta.java @@ -27,6 +27,7 @@ package me.lucko.luckperms.common.commands.generic.meta; import me.lucko.luckperms.api.context.MutableContextSet; import me.lucko.luckperms.api.model.DataMutateResult; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.node.ChatMetaType; import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; import me.lucko.luckperms.common.command.CommandResult; @@ -83,7 +84,7 @@ public class MetaAddChatMeta extends SharedSubCommand { return CommandResult.NO_PERMISSION; } - DataMutateResult result = holder.setPermission(NodeFactory.buildChatMetaNode(this.type, priority, meta).withContext(context).build()); + DataMutateResult result = holder.setPermission(DataType.NORMAL, NodeFactory.buildChatMetaNode(this.type, priority, meta).withContext(context).build(), true); if (result.wasSuccessful()) { TextComponent.Builder builder = Message.ADD_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), holder.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder(); HoverEvent event = HoverEvent.showText(TextUtils.fromLegacy( diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempChatMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempChatMeta.java index a0de59ac7..36dc5cdb2 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempChatMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempChatMeta.java @@ -26,6 +26,7 @@ package me.lucko.luckperms.common.commands.generic.meta; import me.lucko.luckperms.api.context.MutableContextSet; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.model.TemporaryDataMutateResult; import me.lucko.luckperms.api.model.TemporaryMergeBehaviour; import me.lucko.luckperms.api.node.ChatMetaType; @@ -89,7 +90,7 @@ public class MetaAddTempChatMeta extends SharedSubCommand { return CommandResult.NO_PERMISSION; } - TemporaryDataMutateResult ret = holder.setPermission(NodeFactory.buildChatMetaNode(this.type, priority, meta).expiry(duration).withContext(context).build(), modifier); + TemporaryDataMutateResult ret = holder.setPermission(DataType.NORMAL, NodeFactory.buildChatMetaNode(this.type, priority, meta).expiry(duration).withContext(context).build(), modifier); if (((Result) ret.getResult()).wasSuccessful()) { duration = ret.getMergedNode().getExpiry().getEpochSecond(); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaClear.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaClear.java index b901796f2..fa89e9612 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaClear.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaClear.java @@ -26,6 +26,7 @@ package me.lucko.luckperms.common.commands.generic.meta; import me.lucko.luckperms.api.context.MutableContextSet; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.node.NodeType; import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; import me.lucko.luckperms.common.command.CommandResult; @@ -87,7 +88,7 @@ public class MetaClear extends SharedSubCommand { type = NodeType.META_OR_CHAT_META; } - int before = holder.enduringData().immutable().size(); + int before = holder.normalData().immutable().size(); MutableContextSet context = ArgumentParser.parseContext(0, args, plugin); @@ -98,12 +99,12 @@ public class MetaClear extends SharedSubCommand { } if (context.isEmpty()) { - holder.clearMeta(type); + holder.removeIf(DataType.NORMAL, null, type::matches, null); } else { - holder.clearMeta(type, context); + holder.removeIf(DataType.NORMAL, context, type::matches, null); } - int changed = before - holder.enduringData().immutable().size(); + int changed = before - holder.normalData().immutable().size(); if (changed == 1) { Message.META_CLEAR_SUCCESS_SINGULAR.send(sender, holder.getFormattedDisplayName(), type.name().toLowerCase(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed); } else { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveChatMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveChatMeta.java index 59652b63d..b2d21ea4b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveChatMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveChatMeta.java @@ -27,6 +27,7 @@ package me.lucko.luckperms.common.commands.generic.meta; import me.lucko.luckperms.api.context.ImmutableContextSet; import me.lucko.luckperms.api.model.DataMutateResult; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.node.ChatMetaType; import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; import me.lucko.luckperms.common.command.CommandResult; @@ -85,11 +86,10 @@ public class MetaRemoveChatMeta extends SharedSubCommand { // Handle bulk removal if (meta.equalsIgnoreCase("null") || meta.equals("*")) { - holder.removeIfEnduring(n -> this.type.nodeType().matches(n) && + holder.removeIf(DataType.NORMAL, null, n -> this.type.nodeType().matches(n) && this.type.nodeType().cast(n).getPriority() == priority && !n.hasExpiry() && - n.getContexts().equals(context) - ); + n.getContexts().equals(context), null); Message.BULK_REMOVE_CHATMETA_SUCCESS.send(sender, holder.getFormattedDisplayName(), this.type.name().toLowerCase(), priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); ExtendedLogEntry.build().actor(sender).acted(holder) @@ -100,7 +100,7 @@ public class MetaRemoveChatMeta extends SharedSubCommand { return CommandResult.SUCCESS; } - DataMutateResult result = holder.unsetPermission(NodeFactory.buildChatMetaNode(this.type, priority, meta).withContext(context).build()); + DataMutateResult result = holder.unsetPermission(DataType.NORMAL, NodeFactory.buildChatMetaNode(this.type, priority, meta).withContext(context).build()); if (result.wasSuccessful()) { TextComponent.Builder builder = Message.REMOVE_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), holder.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder(); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempChatMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempChatMeta.java index 9c8b82a11..064249dad 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempChatMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempChatMeta.java @@ -27,6 +27,7 @@ package me.lucko.luckperms.common.commands.generic.meta; import me.lucko.luckperms.api.context.ImmutableContextSet; import me.lucko.luckperms.api.model.DataMutateResult; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.node.ChatMetaType; import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; import me.lucko.luckperms.common.command.CommandResult; @@ -85,11 +86,10 @@ public class MetaRemoveTempChatMeta extends SharedSubCommand { // Handle bulk removal if (meta.equalsIgnoreCase("null") || meta.equals("*")) { - holder.removeIfEnduring(n -> this.type.nodeType().matches(n) && + holder.removeIf(DataType.NORMAL, null, n -> this.type.nodeType().matches(n) && this.type.nodeType().cast(n).getPriority() == priority && n.hasExpiry() && - n.getContexts().equals(context) - ); + n.getContexts().equals(context), null); Message.BULK_REMOVE_TEMP_CHATMETA_SUCCESS.send(sender, holder.getFormattedDisplayName(), this.type.name().toLowerCase(), priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); ExtendedLogEntry.build().actor(sender).acted(holder) @@ -100,7 +100,7 @@ public class MetaRemoveTempChatMeta extends SharedSubCommand { return CommandResult.SUCCESS; } - DataMutateResult result = holder.unsetPermission(NodeFactory.buildChatMetaNode(this.type, priority, meta).expiry(10L).withContext(context).build()); + DataMutateResult result = holder.unsetPermission(DataType.NORMAL, NodeFactory.buildChatMetaNode(this.type, priority, meta).expiry(10L).withContext(context).build()); if (result.wasSuccessful()) { TextComponent.Builder builder = Message.REMOVE_TEMP_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), holder.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder(); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSet.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSet.java index 5dbd31381..573d395f2 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSet.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSet.java @@ -26,8 +26,10 @@ package me.lucko.luckperms.common.commands.generic.meta; import me.lucko.luckperms.api.context.MutableContextSet; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.node.Node; import me.lucko.luckperms.api.node.NodeEqualityPredicate; +import me.lucko.luckperms.api.node.types.MetaNode; import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; import me.lucko.luckperms.common.command.CommandResult; import me.lucko.luckperms.common.command.abstraction.CommandException; @@ -40,7 +42,6 @@ import me.lucko.luckperms.common.command.utils.StorageAssistant; import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.locale.command.CommandSpec; import me.lucko.luckperms.common.locale.message.Message; -import me.lucko.luckperms.common.model.NodeMapType; import me.lucko.luckperms.common.model.PermissionHolder; import me.lucko.luckperms.common.node.factory.NodeFactory; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; @@ -78,13 +79,13 @@ public class MetaSet extends SharedSubCommand { Node n = NodeFactory.buildMetaNode(key, value).withContext(context).build(); - if (holder.hasPermission(NodeMapType.ENDURING, n, NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE).asBoolean()) { + if (holder.hasPermission(DataType.NORMAL, n, NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE).asBoolean()) { Message.ALREADY_HAS_META.send(sender, holder.getFormattedDisplayName(), key, value, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); return CommandResult.STATE_ERROR; } - holder.clearMetaKeys(key, context, false); - holder.setPermission(n); + holder.removeIf(DataType.NORMAL, context, n1 -> n1 instanceof MetaNode && (n1.hasExpiry() == false) && ((MetaNode) n1).getMetaKey().equalsIgnoreCase(key), null); + holder.setPermission(DataType.NORMAL, n, true); TextComponent.Builder builder = Message.SET_META_SUCCESS.asComponent(plugin.getLocaleManager(), key, value, holder.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder(); HoverEvent event = HoverEvent.showText(TextUtils.fromLegacy( diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetChatMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetChatMeta.java index 17f0a3478..60cf13961 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetChatMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetChatMeta.java @@ -27,6 +27,7 @@ package me.lucko.luckperms.common.commands.generic.meta; import me.lucko.luckperms.api.context.MutableContextSet; import me.lucko.luckperms.api.model.DataMutateResult; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.node.ChatMetaType; import me.lucko.luckperms.api.query.QueryOptions; import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; @@ -103,7 +104,7 @@ public class MetaSetChatMeta extends SharedSubCommand { } // remove all other prefixes/suffixes set in these contexts - holder.removeIfEnduring(context, node -> this.type.nodeType().matches(node)); + holder.removeIf(DataType.NORMAL, context, node -> this.type.nodeType().matches(node), null); // determine the priority to set at if (priority == Integer.MIN_VALUE) { @@ -119,7 +120,7 @@ public class MetaSetChatMeta extends SharedSubCommand { } } - DataMutateResult result = holder.setPermission(NodeFactory.buildChatMetaNode(this.type, priority, meta).withContext(context).build()); + DataMutateResult result = holder.setPermission(DataType.NORMAL, NodeFactory.buildChatMetaNode(this.type, priority, meta).withContext(context).build(), true); if (result.wasSuccessful()) { TextComponent.Builder builder = Message.ADD_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), holder.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder(); HoverEvent event = HoverEvent.showText(TextUtils.fromLegacy( diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetTemp.java index dcc0a34df..d95fdfa22 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetTemp.java @@ -26,9 +26,11 @@ package me.lucko.luckperms.common.commands.generic.meta; import me.lucko.luckperms.api.context.MutableContextSet; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.model.TemporaryMergeBehaviour; import me.lucko.luckperms.api.node.Node; import me.lucko.luckperms.api.node.NodeEqualityPredicate; +import me.lucko.luckperms.api.node.types.MetaNode; import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; import me.lucko.luckperms.common.command.CommandResult; import me.lucko.luckperms.common.command.abstraction.CommandException; @@ -42,7 +44,6 @@ import me.lucko.luckperms.common.config.ConfigKeys; import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.locale.command.CommandSpec; import me.lucko.luckperms.common.locale.message.Message; -import me.lucko.luckperms.common.model.NodeMapType; import me.lucko.luckperms.common.model.PermissionHolder; import me.lucko.luckperms.common.node.factory.NodeFactory; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; @@ -83,13 +84,13 @@ public class MetaSetTemp extends SharedSubCommand { Node n = NodeFactory.buildMetaNode(key, value).withContext(context).expiry(duration).build(); - if (holder.hasPermission(NodeMapType.ENDURING, n, NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE).asBoolean()) { + if (holder.hasPermission(DataType.NORMAL, n, NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE).asBoolean()) { Message.ALREADY_HAS_TEMP_META.send(sender, holder.getFormattedDisplayName(), key, value, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); return CommandResult.STATE_ERROR; } - holder.clearMetaKeys(key, context, true); - duration = holder.setPermission(n, modifier).getMergedNode().getExpiry().getEpochSecond(); + holder.removeIf(DataType.NORMAL, context, n1 -> n1 instanceof MetaNode && (n1.hasExpiry() == true) && ((MetaNode) n1).getMetaKey().equalsIgnoreCase(key), null); + duration = holder.setPermission(DataType.NORMAL, n, 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(); HoverEvent event = HoverEvent.showText(TextUtils.fromLegacy( diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetTempChatMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetTempChatMeta.java index c2e160d91..9d6429a40 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetTempChatMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetTempChatMeta.java @@ -26,6 +26,7 @@ package me.lucko.luckperms.common.commands.generic.meta; import me.lucko.luckperms.api.context.MutableContextSet; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.model.TemporaryDataMutateResult; import me.lucko.luckperms.api.model.TemporaryMergeBehaviour; import me.lucko.luckperms.api.node.ChatMetaType; @@ -113,7 +114,7 @@ public class MetaSetTempChatMeta extends SharedSubCommand { } // remove all other prefixes/suffixes set in these contexts - holder.removeIfEnduring(context, node -> this.type.nodeType().matches(node)); + holder.removeIf(DataType.NORMAL, context, node -> this.type.nodeType().matches(node), null); // determine the priority to set at if (priority == Integer.MIN_VALUE) { @@ -129,7 +130,7 @@ public class MetaSetTempChatMeta extends SharedSubCommand { } } - TemporaryDataMutateResult ret = holder.setPermission(NodeFactory.buildChatMetaNode(this.type, priority, meta).expiry(duration).withContext(context).build(), modifier); + TemporaryDataMutateResult ret = holder.setPermission(DataType.NORMAL, NodeFactory.buildChatMetaNode(this.type, priority, meta).expiry(duration).withContext(context).build(), modifier); if (((Result) ret.getResult()).wasSuccessful()) { duration = ret.getMergedNode().getExpiry().getEpochSecond(); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnset.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnset.java index 354f6a058..bfdd5ab32 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnset.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnset.java @@ -26,6 +26,8 @@ package me.lucko.luckperms.common.commands.generic.meta; import me.lucko.luckperms.api.context.MutableContextSet; +import me.lucko.luckperms.api.model.DataType; +import me.lucko.luckperms.api.node.types.MetaNode; import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; import me.lucko.luckperms.common.command.CommandResult; import me.lucko.luckperms.common.command.abstraction.CommandException; @@ -67,7 +69,7 @@ public class MetaUnset extends SharedSubCommand { return CommandResult.NO_PERMISSION; } - if (holder.clearMetaKeys(key, context, false)) { + if (holder.removeIf(DataType.NORMAL, context, n -> n instanceof MetaNode && (n.hasExpiry() == false) && ((MetaNode) n).getMetaKey().equalsIgnoreCase(key), null)) { Message.UNSET_META_SUCCESS.send(sender, key, holder.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); ExtendedLogEntry.build().actor(sender).acted(holder) diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnsetTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnsetTemp.java index 9e6ab6fde..8a2490bb6 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnsetTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnsetTemp.java @@ -26,6 +26,8 @@ package me.lucko.luckperms.common.commands.generic.meta; import me.lucko.luckperms.api.context.MutableContextSet; +import me.lucko.luckperms.api.model.DataType; +import me.lucko.luckperms.api.node.types.MetaNode; import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; import me.lucko.luckperms.common.command.CommandResult; import me.lucko.luckperms.common.command.abstraction.CommandException; @@ -67,7 +69,7 @@ public class MetaUnsetTemp extends SharedSubCommand { return CommandResult.NO_PERMISSION; } - if (holder.clearMetaKeys(key, context, true)) { + if (holder.removeIf(DataType.NORMAL, context, n -> n instanceof MetaNode && (n.hasExpiry() == true) && ((MetaNode) n).getMetaKey().equalsIgnoreCase(key), null)) { Message.UNSET_META_TEMP_SUCCESS.send(sender, key, holder.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); ExtendedLogEntry.build().actor(sender).acted(holder) diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/other/HolderClear.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/other/HolderClear.java index ef99a73da..0cb39c76a 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/other/HolderClear.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/other/HolderClear.java @@ -26,6 +26,7 @@ package me.lucko.luckperms.common.commands.generic.other; import me.lucko.luckperms.api.context.MutableContextSet; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; import me.lucko.luckperms.common.command.CommandResult; import me.lucko.luckperms.common.command.abstraction.CommandException; @@ -57,7 +58,7 @@ public class HolderClear extends SubCommand { return CommandResult.NO_PERMISSION; } - int before = holder.enduringData().immutable().size(); + int before = holder.normalData().immutable().size(); MutableContextSet context = ArgumentParser.parseContext(0, args, plugin); @@ -68,12 +69,12 @@ public class HolderClear extends SubCommand { } if (context.isEmpty()) { - holder.clearEnduringNodes(); + holder.clearNodes(DataType.NORMAL, null); } else { - holder.clearEnduringNodes(context); + holder.clearNodes(DataType.NORMAL, context); } - int changed = before - holder.enduringData().immutable().size(); + int changed = before - holder.normalData().immutable().size(); if (changed == 1) { Message.CLEAR_SUCCESS_SINGULAR.send(sender, holder.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed); } else { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/other/HolderShowTracks.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/other/HolderShowTracks.java index 55df218de..db12cda89 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/other/HolderShowTracks.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/other/HolderShowTracks.java @@ -76,7 +76,7 @@ public class HolderShowTracks extends SubCommand if (holder.getType() == HolderType.USER) { // if the holder is a user, we want to query parent groups for tracks - Set nodes = holder.enduringData().immutable().values().stream() + Set nodes = holder.normalData().immutable().values().stream() .filter(NodeType.INHERITANCE::matches) .map(NodeType.INHERITANCE::cast) .filter(Node::getValue) diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentAdd.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentAdd.java index 9e1bfaa51..69c8e423a 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentAdd.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentAdd.java @@ -27,6 +27,7 @@ package me.lucko.luckperms.common.commands.generic.parent; import me.lucko.luckperms.api.context.MutableContextSet; import me.lucko.luckperms.api.model.DataMutateResult; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; import me.lucko.luckperms.common.command.CommandResult; import me.lucko.luckperms.common.command.abstraction.CommandException; @@ -78,7 +79,7 @@ public class ParentAdd extends SharedSubCommand { return CommandResult.NO_PERMISSION; } - DataMutateResult result = holder.setPermission(NodeFactory.buildGroupNode(group.getName()).withContext(context).build()); + DataMutateResult result = holder.setPermission(DataType.NORMAL, NodeFactory.buildGroupNode(group.getName()).withContext(context).build(), true); if (result.wasSuccessful()) { Message.SET_INHERIT_SUCCESS.send(sender, holder.getFormattedDisplayName(), group.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentAddTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentAddTemp.java index 0d5f9f305..bbdfb562f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentAddTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentAddTemp.java @@ -26,6 +26,7 @@ package me.lucko.luckperms.common.commands.generic.parent; import me.lucko.luckperms.api.context.MutableContextSet; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.model.TemporaryDataMutateResult; import me.lucko.luckperms.api.model.TemporaryMergeBehaviour; import me.lucko.luckperms.api.util.Result; @@ -89,7 +90,7 @@ public class ParentAddTemp extends SharedSubCommand { return CommandResult.STATE_ERROR; } - TemporaryDataMutateResult ret = holder.setPermission(NodeFactory.buildGroupNode(group.getName()).expiry(duration).withContext(context).build(), modifier); + TemporaryDataMutateResult ret = holder.setPermission(DataType.NORMAL, NodeFactory.buildGroupNode(group.getName()).expiry(duration).withContext(context).build(), modifier); if (((Result) ret.getResult()).wasSuccessful()) { duration = ret.getMergedNode().getExpiry().getEpochSecond(); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentClear.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentClear.java index 26f42a6fb..d1b492192 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentClear.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentClear.java @@ -57,7 +57,7 @@ public class ParentClear extends SharedSubCommand { return CommandResult.NO_PERMISSION; } - int before = holder.enduringData().immutable().size(); + int before = holder.normalData().immutable().size(); MutableContextSet context = ArgumentParser.parseContext(0, args, plugin); @@ -67,12 +67,12 @@ public class ParentClear extends SharedSubCommand { } if (context.isEmpty()) { - holder.clearEnduringParents(true); + holder.clearNormalParents(null, true); } else { - holder.clearEnduringParents(context, true); + holder.clearNormalParents(context, true); } - int changed = before - holder.enduringData().immutable().size(); + int changed = before - holder.normalData().immutable().size(); if (changed == 1) { Message.PARENT_CLEAR_SUCCESS_SINGULAR.send(sender, holder.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed); } else { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentClearTrack.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentClearTrack.java index d2aba1415..ff5e23edc 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentClearTrack.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentClearTrack.java @@ -26,6 +26,7 @@ package me.lucko.luckperms.common.commands.generic.parent; import me.lucko.luckperms.api.context.ImmutableContextSet; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.node.NodeType; import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; import me.lucko.luckperms.common.command.CommandResult; @@ -80,7 +81,7 @@ public class ParentClearTrack extends SharedSubCommand { return CommandResult.STATE_ERROR; } - int before = holder.enduringData().immutable().size(); + int before = holder.normalData().immutable().size(); ImmutableContextSet context = ArgumentParser.parseContext(1, args, plugin).immutableCopy(); @@ -92,16 +93,16 @@ public class ParentClearTrack extends SharedSubCommand { } if (context.isEmpty()) { - holder.removeIfEnduring(NodeType.INHERITANCE.predicate(n -> track.containsGroup(n.getGroupName()))); + holder.removeIf(DataType.NORMAL, null, NodeType.INHERITANCE.predicate(n -> track.containsGroup(n.getGroupName())), null); } else { - holder.removeIfEnduring(NodeType.INHERITANCE.predicate(n -> n.getContexts().equals(context) && track.containsGroup(n.getGroupName()))); + holder.removeIf(DataType.NORMAL, null, NodeType.INHERITANCE.predicate(n -> n.getContexts().equals(context) && track.containsGroup(n.getGroupName())), null); } if (holder.getType() == HolderType.USER) { plugin.getUserManager().giveDefaultIfNeeded(((User) holder), false); } - int changed = before - holder.enduringData().immutable().size(); + int changed = before - holder.normalData().immutable().size(); if (changed == 1) { Message.PARENT_CLEAR_TRACK_SUCCESS_SINGULAR.send(sender, holder.getFormattedDisplayName(), track.getName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentInfo.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentInfo.java index ea654ea14..e1a8472d0 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentInfo.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentInfo.java @@ -78,7 +78,7 @@ public class ParentInfo extends SharedSubCommand { // get the holders nodes List nodes = new LinkedList<>(); - holder.enduringData().copyInheritanceNodesTo(nodes, QueryOptions.nonContextual()); + holder.normalData().copyInheritanceNodesTo(nodes, QueryOptions.nonContextual()); // remove irrelevant types (these are displayed in the other info commands) nodes.removeIf(node -> !node.getValue()); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentRemove.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentRemove.java index c106c057e..dd3f3345c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentRemove.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentRemove.java @@ -27,6 +27,7 @@ package me.lucko.luckperms.common.commands.generic.parent; import me.lucko.luckperms.api.context.MutableContextSet; import me.lucko.luckperms.api.model.DataMutateResult; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; import me.lucko.luckperms.common.command.CommandResult; import me.lucko.luckperms.common.command.abstraction.CommandException; @@ -89,7 +90,7 @@ public class ParentRemove extends SharedSubCommand { } } - DataMutateResult result = holder.unsetPermission(NodeFactory.buildGroupNode(groupName).withContext(context).build()); + DataMutateResult result = holder.unsetPermission(DataType.NORMAL, NodeFactory.buildGroupNode(groupName).withContext(context).build()); if (result.wasSuccessful()) { Message.UNSET_INHERIT_SUCCESS.send(sender, holder.getFormattedDisplayName(), groupName, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentRemoveTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentRemoveTemp.java index 115d3afe8..12f5b2898 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentRemoveTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentRemoveTemp.java @@ -27,6 +27,7 @@ package me.lucko.luckperms.common.commands.generic.parent; import me.lucko.luckperms.api.context.MutableContextSet; import me.lucko.luckperms.api.model.DataMutateResult; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; import me.lucko.luckperms.common.command.CommandResult; import me.lucko.luckperms.common.command.abstraction.CommandException; @@ -72,7 +73,7 @@ public class ParentRemoveTemp extends SharedSubCommand { return CommandResult.NO_PERMISSION; } - DataMutateResult result = holder.unsetPermission(NodeFactory.buildGroupNode(groupName).expiry(10L).withContext(context).build()); + DataMutateResult result = holder.unsetPermission(DataType.NORMAL, NodeFactory.buildGroupNode(groupName).expiry(10L).withContext(context).build()); if (result.wasSuccessful()) { Message.UNSET_TEMP_INHERIT_SUCCESS.send(sender, holder.getFormattedDisplayName(), groupName, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentSet.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentSet.java index aacecb508..cd8e67be1 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentSet.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentSet.java @@ -26,6 +26,7 @@ package me.lucko.luckperms.common.commands.generic.parent; import me.lucko.luckperms.api.context.MutableContextSet; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; import me.lucko.luckperms.common.command.CommandResult; import me.lucko.luckperms.common.command.abstraction.CommandException; @@ -79,8 +80,8 @@ public class ParentSet extends SharedSubCommand { return CommandResult.NO_PERMISSION; } - holder.clearEnduringParents(context, false); - holder.setPermission(NodeFactory.buildGroupNode(group.getName()).withContext(context).build()); + holder.clearNormalParents(context, false); + holder.setPermission(DataType.NORMAL, NodeFactory.buildGroupNode(group.getName()).withContext(context).build(), true); if (holder.getType() == HolderType.USER) { ((User) holder).getPrimaryGroup().setStoredValue(group.getName()); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentSetTrack.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentSetTrack.java index 6c40cf05a..d6012b8b1 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentSetTrack.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentSetTrack.java @@ -26,6 +26,7 @@ package me.lucko.luckperms.common.commands.generic.parent; import me.lucko.luckperms.api.context.ImmutableContextSet; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.node.NodeType; import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; import me.lucko.luckperms.common.command.CommandResult; @@ -112,8 +113,8 @@ public class ParentSetTrack extends SharedSubCommand { return CommandResult.NO_PERMISSION; } - holder.removeIfEnduring(NodeType.INHERITANCE.predicate(n -> n.getContexts().equals(context) && track.containsGroup(n.getGroupName()))); - holder.setPermission(NodeFactory.buildGroupNode(group.getName()).withContext(context).build()); + holder.removeIf(DataType.NORMAL, null, NodeType.INHERITANCE.predicate(n -> n.getContexts().equals(context) && track.containsGroup(n.getGroupName())), null); + holder.setPermission(DataType.NORMAL, NodeFactory.buildGroupNode(group.getName()).withContext(context).build(), true); Message.SET_TRACK_PARENT_SUCCESS.send(sender, holder.getFormattedDisplayName(), track.getName(), group.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/UserSwitchPrimaryGroup.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/UserSwitchPrimaryGroup.java index 46fe40c4c..cbfe2e14f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/UserSwitchPrimaryGroup.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/UserSwitchPrimaryGroup.java @@ -26,6 +26,7 @@ package me.lucko.luckperms.common.commands.generic.parent; import me.lucko.luckperms.api.context.ImmutableContextSet; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.node.Node; import me.lucko.luckperms.api.node.NodeEqualityPredicate; import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; @@ -41,7 +42,6 @@ import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.locale.command.CommandSpec; import me.lucko.luckperms.common.locale.message.Message; import me.lucko.luckperms.common.model.Group; -import me.lucko.luckperms.common.model.NodeMapType; import me.lucko.luckperms.common.model.PermissionHolder; import me.lucko.luckperms.common.model.User; import me.lucko.luckperms.common.node.factory.NodeFactory; @@ -93,9 +93,9 @@ public class UserSwitchPrimaryGroup extends SharedSubCommand { } Node node = NodeFactory.buildGroupNode(group.getName()).build(); - if (!user.hasPermission(NodeMapType.ENDURING, node, NodeEqualityPredicate.IGNORE_VALUE).asBoolean()) { + if (!user.hasPermission(DataType.NORMAL, node, NodeEqualityPredicate.IGNORE_VALUE).asBoolean()) { Message.USER_PRIMARYGROUP_ERROR_NOTMEMBER.send(sender, user.getFormattedDisplayName(), group.getName()); - user.setPermission(node); + holder.setPermission(DataType.NORMAL, node, true); } user.getPrimaryGroup().setStoredValue(group.getName()); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionCheck.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionCheck.java index f59398a5d..b57b8afdf 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionCheck.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionCheck.java @@ -26,6 +26,7 @@ package me.lucko.luckperms.common.commands.generic.permission; import me.lucko.luckperms.api.context.MutableContextSet; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.node.NodeEqualityPredicate; import me.lucko.luckperms.api.node.Tristate; import me.lucko.luckperms.common.command.CommandResult; @@ -40,7 +41,6 @@ import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.locale.command.CommandSpec; import me.lucko.luckperms.common.locale.message.Message; -import me.lucko.luckperms.common.model.NodeMapType; import me.lucko.luckperms.common.model.PermissionHolder; import me.lucko.luckperms.common.node.factory.NodeFactory; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; @@ -64,7 +64,7 @@ public class PermissionCheck extends SharedSubCommand { String node = ArgumentParser.parseString(0, args); MutableContextSet context = ArgumentParser.parseContext(1, args, plugin); - Tristate result = holder.hasPermission(NodeMapType.ENDURING, NodeFactory.builder(node).withContext(context).build(), NodeEqualityPredicate.IGNORE_VALUE_OR_IF_TEMPORARY); + Tristate result = holder.hasPermission(DataType.NORMAL, NodeFactory.builder(node).withContext(context).build(), NodeEqualityPredicate.IGNORE_VALUE_OR_IF_TEMPORARY); String s = MessageUtils.formatTristate(result); Message.CHECK_PERMISSION.send(sender, holder.getFormattedDisplayName(), node, s, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionClear.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionClear.java index ad0c1ad8f..5bbfc39ac 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionClear.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionClear.java @@ -26,6 +26,7 @@ package me.lucko.luckperms.common.commands.generic.permission; import me.lucko.luckperms.api.context.MutableContextSet; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.node.types.PermissionNode; import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; import me.lucko.luckperms.common.command.CommandResult; @@ -58,7 +59,7 @@ public class PermissionClear extends SharedSubCommand { return CommandResult.NO_PERMISSION; } - int before = holder.enduringData().immutable().size(); + int before = holder.normalData().immutable().size(); MutableContextSet context = ArgumentParser.parseContext(0, args, plugin); @@ -69,12 +70,12 @@ public class PermissionClear extends SharedSubCommand { } if (context.isEmpty()) { - holder.removeIfEnduring(node -> node instanceof PermissionNode); + holder.removeIf(DataType.NORMAL, null, node -> node instanceof PermissionNode, null); } else { - holder.removeIfEnduring(context, node -> node instanceof PermissionNode); + holder.removeIf(DataType.NORMAL, context, node -> node instanceof PermissionNode, null); } - int changed = before - holder.enduringData().immutable().size(); + int changed = before - holder.normalData().immutable().size(); if (changed == 1) { Message.PERMISSION_CLEAR_SUCCESS_SINGULAR.send(sender, holder.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed); } else { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionInfo.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionInfo.java index 932cf0c1d..91b9a76cf 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionInfo.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionInfo.java @@ -77,7 +77,7 @@ public class PermissionInfo extends SharedSubCommand { SortMode sortMode = SortMode.determine(args); // get the holders nodes - List nodes = new ArrayList<>(holder.enduringData().asSortedSet()); + List nodes = new ArrayList<>(holder.normalData().asSortedSet()); // remove irrelevant types (these are displayed in the other info commands) nodes.removeIf(NodeType.INHERITANCE.predicate(n -> n.getValue() && plugin.getGroupManager().isLoaded(n.getGroupName())) diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSet.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSet.java index 8082957fd..1500cd3d5 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSet.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSet.java @@ -27,6 +27,7 @@ package me.lucko.luckperms.common.commands.generic.permission; import me.lucko.luckperms.api.context.MutableContextSet; import me.lucko.luckperms.api.model.DataMutateResult; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.node.Node; import me.lucko.luckperms.api.node.types.InheritanceNode; import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; @@ -83,7 +84,7 @@ public class PermissionSet extends SharedSubCommand { } } - DataMutateResult result = holder.setPermission(builtNode); + DataMutateResult result = holder.setPermission(DataType.NORMAL, builtNode, true); if (result.wasSuccessful()) { Message.SETPERMISSION_SUCCESS.send(sender, node, value, holder.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSetTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSetTemp.java index 1eeffaef4..3a6242545 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSetTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSetTemp.java @@ -26,6 +26,7 @@ package me.lucko.luckperms.common.commands.generic.permission; import me.lucko.luckperms.api.context.MutableContextSet; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.model.TemporaryDataMutateResult; import me.lucko.luckperms.api.model.TemporaryMergeBehaviour; import me.lucko.luckperms.api.node.Node; @@ -89,7 +90,7 @@ public class PermissionSetTemp extends SharedSubCommand { } } - TemporaryDataMutateResult result = holder.setPermission(builtNode, modifier); + TemporaryDataMutateResult result = holder.setPermission(DataType.NORMAL, builtNode, modifier); if (((Result) result.getResult()).wasSuccessful()) { duration = result.getMergedNode().getExpiry().getEpochSecond(); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnset.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnset.java index 91f400c15..aaeeafdcc 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnset.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnset.java @@ -27,6 +27,7 @@ package me.lucko.luckperms.common.commands.generic.permission; import me.lucko.luckperms.api.context.MutableContextSet; import me.lucko.luckperms.api.model.DataMutateResult; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.node.Node; import me.lucko.luckperms.api.node.types.InheritanceNode; import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; @@ -82,7 +83,7 @@ public class PermissionUnset extends SharedSubCommand { } } - DataMutateResult result = holder.unsetPermission(builtNode); + DataMutateResult result = holder.unsetPermission(DataType.NORMAL, builtNode); if (result.wasSuccessful()) { Message.UNSETPERMISSION_SUCCESS.send(sender, node, holder.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnsetTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnsetTemp.java index 036a5d393..175abc428 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnsetTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnsetTemp.java @@ -27,6 +27,7 @@ package me.lucko.luckperms.common.commands.generic.permission; import me.lucko.luckperms.api.context.MutableContextSet; import me.lucko.luckperms.api.model.DataMutateResult; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.node.Node; import me.lucko.luckperms.api.node.types.InheritanceNode; import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; @@ -82,7 +83,7 @@ public class PermissionUnsetTemp extends SharedSubCommand { } } - DataMutateResult result = holder.unsetPermission(builtNode); + DataMutateResult result = holder.unsetPermission(DataType.NORMAL, builtNode); if (result.wasSuccessful()) { Message.UNSET_TEMP_PERMISSION_SUCCESS.send(sender, node, holder.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupClone.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupClone.java index 854157e04..fcbe5e226 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupClone.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupClone.java @@ -26,6 +26,7 @@ package me.lucko.luckperms.common.commands.group; import me.lucko.luckperms.api.event.cause.CreationCause; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; import me.lucko.luckperms.common.command.CommandResult; import me.lucko.luckperms.common.command.abstraction.SubCommand; @@ -36,7 +37,6 @@ import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.locale.command.CommandSpec; import me.lucko.luckperms.common.locale.message.Message; import me.lucko.luckperms.common.model.Group; -import me.lucko.luckperms.common.model.NodeMapType; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.sender.Sender; import me.lucko.luckperms.common.storage.misc.DataConstraints; @@ -73,7 +73,7 @@ public class GroupClone extends SubCommand { return CommandResult.NO_PERMISSION; } - newGroup.replaceNodes(NodeMapType.ENDURING, group.enduringData().immutable()); + newGroup.replaceNodes(DataType.NORMAL, group.normalData().immutable()); Message.CLONE_SUCCESS.send(sender, group.getName(), newGroup.getName()); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupInfo.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupInfo.java index 749b8a47a..90ca99474 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupInfo.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupInfo.java @@ -62,12 +62,12 @@ public class GroupInfo extends SubCommand { group.getWeight().isPresent() ? group.getWeight().getAsInt() : "None" ); - List parents = group.enduringData().inheritanceAsSortedSet().stream() + List parents = group.normalData().inheritanceAsSortedSet().stream() .filter(Node::getValue) .filter(n -> !n.hasExpiry()) .collect(Collectors.toList()); - List tempParents = group.enduringData().inheritanceAsSortedSet().stream() + List tempParents = group.normalData().inheritanceAsSortedSet().stream() .filter(Node::getValue) .filter(Node::hasExpiry) .collect(Collectors.toList()); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupRename.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupRename.java index 98bdeb061..d335e322b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupRename.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupRename.java @@ -27,6 +27,7 @@ package me.lucko.luckperms.common.commands.group; import me.lucko.luckperms.api.event.cause.CreationCause; import me.lucko.luckperms.api.event.cause.DeletionCause; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; import me.lucko.luckperms.common.command.CommandResult; import me.lucko.luckperms.common.command.abstraction.SubCommand; @@ -36,7 +37,6 @@ import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.locale.command.CommandSpec; import me.lucko.luckperms.common.locale.message.Message; import me.lucko.luckperms.common.model.Group; -import me.lucko.luckperms.common.model.NodeMapType; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.sender.Sender; import me.lucko.luckperms.common.storage.misc.DataConstraints; @@ -79,7 +79,7 @@ public class GroupRename extends SubCommand { return CommandResult.FAILURE; } - newGroup.replaceNodes(NodeMapType.ENDURING, group.enduringData().immutable()); + newGroup.replaceNodes(DataType.NORMAL, group.normalData().immutable()); Message.RENAME_SUCCESS.send(sender, group.getName(), newGroup.getName()); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupSetDisplayName.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupSetDisplayName.java index 73239ae67..d160fc1e7 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupSetDisplayName.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupSetDisplayName.java @@ -26,6 +26,7 @@ package me.lucko.luckperms.common.commands.group; import me.lucko.luckperms.api.context.MutableContextSet; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.node.types.DisplayNameNode; import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; import me.lucko.luckperms.common.command.CommandResult; @@ -80,7 +81,7 @@ public class GroupSetDisplayName extends SubCommand { return CommandResult.STATE_ERROR; } - group.removeIfEnduring(context, n -> n instanceof DisplayNameNode); + group.removeIf(DataType.NORMAL, context, n -> n instanceof DisplayNameNode, null); if (name.equals(group.getName())) { Message.GROUP_SET_DISPLAY_NAME_REMOVED.send(sender, group.getName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); @@ -93,7 +94,7 @@ public class GroupSetDisplayName extends SubCommand { return CommandResult.SUCCESS; } - group.setPermission(NodeFactory.builder(NodeFactory.displayName(name)).withContext(context).build()); + group.setPermission(DataType.NORMAL, NodeFactory.builder(NodeFactory.displayName(name)).withContext(context).build(), true); Message.GROUP_SET_DISPLAY_NAME.send(sender, name, group.getName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupSetWeight.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupSetWeight.java index 243d7dc5b..9e5ae0377 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupSetWeight.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupSetWeight.java @@ -25,6 +25,7 @@ package me.lucko.luckperms.common.commands.group; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.node.types.WeightNode; import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; import me.lucko.luckperms.common.command.CommandResult; @@ -59,8 +60,8 @@ public class GroupSetWeight extends SubCommand { int weight = ArgumentParser.parsePriority(0, args); - group.removeIfEnduring(n -> n instanceof WeightNode); - group.setPermission(NodeFactory.buildWeightNode(weight).build()); + group.removeIf(DataType.NORMAL, null, n -> n instanceof WeightNode, null); + group.setPermission(DataType.NORMAL, NodeFactory.buildWeightNode(weight).build(), true); Message.GROUP_SET_WEIGHT.send(sender, weight, group.getFormattedDisplayName()); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/log/LogNotify.java b/common/src/main/java/me/lucko/luckperms/common/commands/log/LogNotify.java index fe4f1a08b..2529de874 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/log/LogNotify.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/log/LogNotify.java @@ -26,6 +26,7 @@ package me.lucko.luckperms.common.commands.log; import me.lucko.luckperms.api.context.ImmutableContextSet; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.node.Node; import me.lucko.luckperms.common.actionlog.Log; import me.lucko.luckperms.common.command.CommandResult; @@ -57,7 +58,7 @@ public class LogNotify extends SubCommand { return false; } - Optional ret = user.enduringData().immutable().get(ImmutableContextSet.empty()).stream() + Optional ret = user.normalData().immutable().get(ImmutableContextSet.empty()).stream() .filter(n -> n.getKey().equalsIgnoreCase(IGNORE_NODE)) .findFirst(); @@ -74,10 +75,10 @@ public class LogNotify extends SubCommand { if (state) { // add the perm - user.setPermission(NodeFactory.make(IGNORE_NODE)); + user.setPermission(DataType.NORMAL, NodeFactory.make(IGNORE_NODE), true); } else { // remove the perm - user.removeIfEnduring(ImmutableContextSet.empty(), n -> n.getKey().equalsIgnoreCase(IGNORE_NODE)); + user.removeIf(DataType.NORMAL, ImmutableContextSet.empty(), n -> n.getKey().equalsIgnoreCase(IGNORE_NODE), null); } plugin.getStorage().saveUser(user).join(); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/migration/MigrationUtils.java b/common/src/main/java/me/lucko/luckperms/common/commands/migration/MigrationUtils.java index 25619ca6b..99fe148f8 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/migration/MigrationUtils.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/migration/MigrationUtils.java @@ -25,6 +25,7 @@ package me.lucko.luckperms.common.commands.migration; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.node.NodeBuilder; import me.lucko.luckperms.api.node.NodeType; import me.lucko.luckperms.common.model.Group; @@ -54,8 +55,8 @@ public final class MigrationUtils { } public static void setGroupWeight(Group group, int weight) { - group.removeIfEnduring(NodeType.WEIGHT::matches); - group.setPermission(NodeFactory.buildWeightNode(weight).build()); + group.removeIf(DataType.NORMAL, null, NodeType.WEIGHT::matches, null); + group.setPermission(DataType.NORMAL, NodeFactory.buildWeightNode(weight).build(), true); } public static String standardizeName(String string) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/misc/ApplyEditsCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/misc/ApplyEditsCommand.java index d6f2a0ff5..218405a81 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/misc/ApplyEditsCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/misc/ApplyEditsCommand.java @@ -30,6 +30,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.node.Node; import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; import me.lucko.luckperms.common.command.CommandResult; @@ -41,7 +42,6 @@ import me.lucko.luckperms.common.command.utils.StorageAssistant; import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.locale.command.CommandSpec; import me.lucko.luckperms.common.locale.message.Message; -import me.lucko.luckperms.common.model.NodeMapType; import me.lucko.luckperms.common.model.PermissionHolder; import me.lucko.luckperms.common.node.model.NodeDataContainer; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; @@ -116,7 +116,7 @@ public class ApplyEditsCommand extends SingleCommand { Set nodes = WebEditor.deserializePermissions(data.getAsJsonArray("nodes")); - Set before = new HashSet<>(holder.enduringData().immutable().values()); + Set before = new HashSet<>(holder.normalData().immutable().values()); Set after = nodes.stream().map(NodeDataContainer::toNode).collect(Collectors.toSet()); Map.Entry, Set> diff = diff(before, after); @@ -130,7 +130,7 @@ public class ApplyEditsCommand extends SingleCommand { return false; } - holder.setNodes(NodeMapType.ENDURING, after); + holder.setNodes(DataType.NORMAL, after); for (Node n : diffAdded) { ExtendedLogEntry.build().actor(sender).acted(holder) diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/misc/DebugCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/misc/DebugCommand.java index eaa2e09c7..489f49a4b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/misc/DebugCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/misc/DebugCommand.java @@ -106,7 +106,7 @@ public class DebugCommand extends SingleCommand { return new JObject() .add("type", plugin.getBootstrap().getType().name()) .add("version", new JObject() - .add("api", String.valueOf(plugin.getApiProvider().getPlatform().getApiVersion())) + .add("api", plugin.getApiProvider().getPluginMetadata().getApiVersion()) .add("plugin", plugin.getBootstrap().getVersion()) ) .add("server", new JObject() diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserClone.java b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserClone.java index cc4be7df4..20e5860e0 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserClone.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserClone.java @@ -25,6 +25,7 @@ package me.lucko.luckperms.common.commands.user; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; import me.lucko.luckperms.common.command.CommandResult; import me.lucko.luckperms.common.command.abstraction.SubCommand; @@ -35,7 +36,6 @@ import me.lucko.luckperms.common.command.utils.StorageAssistant; import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.locale.command.CommandSpec; import me.lucko.luckperms.common.locale.message.Message; -import me.lucko.luckperms.common.model.NodeMapType; import me.lucko.luckperms.common.model.User; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.sender.Sender; @@ -72,7 +72,7 @@ public class UserClone extends SubCommand { return CommandResult.NO_PERMISSION; } - otherUser.replaceNodes(NodeMapType.ENDURING, user.enduringData().immutable()); + otherUser.replaceNodes(DataType.NORMAL, user.normalData().immutable()); Message.CLONE_SUCCESS.send(sender, user.getFormattedDisplayName(), otherUser.getFormattedDisplayName()); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserInfo.java b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserInfo.java index 9e2179693..e5040401b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserInfo.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserInfo.java @@ -73,12 +73,12 @@ public class UserInfo extends SubCommand { user.getPrimaryGroup().getValue() ); - List parents = user.enduringData().inheritanceAsSortedSet().stream() + List parents = user.normalData().inheritanceAsSortedSet().stream() .filter(Node::getValue) .filter(n -> !n.hasExpiry()) .collect(Collectors.toList()); - List tempParents = user.enduringData().inheritanceAsSortedSet().stream() + List tempParents = user.normalData().inheritanceAsSortedSet().stream() .filter(Node::getValue) .filter(Node::hasExpiry) .collect(Collectors.toList()); diff --git a/common/src/main/java/me/lucko/luckperms/common/defaultassignments/AssignmentExpression.java b/common/src/main/java/me/lucko/luckperms/common/defaultassignments/AssignmentExpression.java index fc76e4156..c160710d5 100644 --- a/common/src/main/java/me/lucko/luckperms/common/defaultassignments/AssignmentExpression.java +++ b/common/src/main/java/me/lucko/luckperms/common/defaultassignments/AssignmentExpression.java @@ -27,10 +27,10 @@ package me.lucko.luckperms.common.defaultassignments; import com.google.common.collect.ImmutableList; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.node.Node; import me.lucko.luckperms.api.node.NodeEqualityPredicate; import me.lucko.luckperms.api.node.Tristate; -import me.lucko.luckperms.common.model.NodeMapType; import me.lucko.luckperms.common.model.PermissionHolder; import me.lucko.luckperms.common.node.factory.NodeFactory; import me.lucko.luckperms.common.util.Scripting; @@ -62,7 +62,7 @@ public class AssignmentExpression { throw new NullPointerException("script engine"); } - Predicate checker = node -> holder.hasPermission(NodeMapType.ENDURING, node, NodeEqualityPredicate.IGNORE_VALUE_OR_IF_TEMPORARY) == tristate; + Predicate checker = node -> holder.hasPermission(DataType.NORMAL, node, NodeEqualityPredicate.IGNORE_VALUE_OR_IF_TEMPORARY) == tristate; String exp = this.expression.stream().map(t -> t.forExpression(checker)).collect(Collectors.joining()) .replace("&", "&&").replace("|", "||"); diff --git a/common/src/main/java/me/lucko/luckperms/common/defaultassignments/AssignmentRule.java b/common/src/main/java/me/lucko/luckperms/common/defaultassignments/AssignmentRule.java index 0bc3ccb49..0a19ad213 100644 --- a/common/src/main/java/me/lucko/luckperms/common/defaultassignments/AssignmentRule.java +++ b/common/src/main/java/me/lucko/luckperms/common/defaultassignments/AssignmentRule.java @@ -25,6 +25,7 @@ package me.lucko.luckperms.common.defaultassignments; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.node.Node; import me.lucko.luckperms.api.node.Tristate; import me.lucko.luckperms.common.model.User; @@ -96,11 +97,11 @@ public class AssignmentRule { // The holder meets all of the requirements of this rule. for (Node n : this.toTake) { - user.unsetPermission(n); + user.unsetPermission(DataType.NORMAL, n); } for (Node n : this.toGive) { - user.setPermission(n); + user.setPermission(DataType.NORMAL, n, true); } if (this.setPrimaryGroup != null) { diff --git a/common/src/main/java/me/lucko/luckperms/common/event/EventFactory.java b/common/src/main/java/me/lucko/luckperms/common/event/EventFactory.java index f4ce782f2..ef68cd468 100644 --- a/common/src/main/java/me/lucko/luckperms/common/event/EventFactory.java +++ b/common/src/main/java/me/lucko/luckperms/common/event/EventFactory.java @@ -67,6 +67,7 @@ import me.lucko.luckperms.api.event.user.UserFirstLoginEvent; import me.lucko.luckperms.api.event.user.UserLoadEvent; import me.lucko.luckperms.api.event.user.track.UserDemoteEvent; import me.lucko.luckperms.api.event.user.track.UserPromoteEvent; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.model.PlayerSaveResult; import me.lucko.luckperms.api.node.Node; import me.lucko.luckperms.common.api.implementation.ApiPermissionHolder; @@ -140,7 +141,7 @@ public final class EventFactory { } public void handleGroupDelete(Group group, DeletionCause cause) { - post(GroupDeleteEvent.class, () -> generate(GroupDeleteEvent.class, group.getName(), ImmutableSet.copyOf(group.enduringData().immutable().values()), cause)); + post(GroupDeleteEvent.class, () -> generate(GroupDeleteEvent.class, group.getName(), ImmutableSet.copyOf(group.normalData().immutable().values()), cause)); } public void handleGroupLoadAll() { @@ -195,16 +196,16 @@ public final class EventFactory { post(LogReceiveEvent.class, () -> generate(LogReceiveEvent.class, id, entry)); } - public void handleNodeAdd(Node node, PermissionHolder target, Collection before, Collection after) { - post(NodeAddEvent.class, () -> generate(NodeAddEvent.class, getDelegate(target), ImmutableSet.copyOf(before), ImmutableSet.copyOf(after), node)); + public void handleNodeAdd(Node node, PermissionHolder target, DataType dataType, Collection before, Collection after) { + post(NodeAddEvent.class, () -> generate(NodeAddEvent.class, getDelegate(target), dataType, ImmutableSet.copyOf(before), ImmutableSet.copyOf(after), node)); } - public void handleNodeClear(PermissionHolder target, Collection before, Collection after) { - post(NodeClearEvent.class, () -> generate(NodeClearEvent.class, getDelegate(target), ImmutableSet.copyOf(before), ImmutableSet.copyOf(after))); + public void handleNodeClear(PermissionHolder target, DataType dataType, Collection before, Collection after) { + post(NodeClearEvent.class, () -> generate(NodeClearEvent.class, getDelegate(target), dataType, ImmutableSet.copyOf(before), ImmutableSet.copyOf(after))); } - public void handleNodeRemove(Node node, PermissionHolder target, Collection before, Collection after) { - post(NodeRemoveEvent.class, () -> generate(NodeRemoveEvent.class, getDelegate(target), ImmutableSet.copyOf(before), ImmutableSet.copyOf(after), node)); + public void handleNodeRemove(Node node, PermissionHolder target, DataType dataType, Collection before, Collection after) { + post(NodeRemoveEvent.class, () -> generate(NodeRemoveEvent.class, getDelegate(target), dataType, ImmutableSet.copyOf(before), ImmutableSet.copyOf(after), node)); } public void handleConfigReload() { diff --git a/common/src/main/java/me/lucko/luckperms/common/model/Group.java b/common/src/main/java/me/lucko/luckperms/common/model/Group.java index 0e8e38952..ae92fc58f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/model/Group.java +++ b/common/src/main/java/me/lucko/luckperms/common/model/Group.java @@ -26,6 +26,7 @@ package me.lucko.luckperms.common.model; import me.lucko.luckperms.api.context.ContextSet; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.node.Node; import me.lucko.luckperms.api.node.types.DisplayNameNode; import me.lucko.luckperms.common.api.implementation.ApiGroup; @@ -115,7 +116,7 @@ public class Group extends PermissionHolder implements Identifiable { * @return the display name */ public Optional getDisplayName(ContextSet contextSet) { - for (Node n : getData(NodeMapType.ENDURING).immutable().get(contextSet.immutableCopy())) { + for (Node n : getData(DataType.NORMAL).immutable().get(contextSet.immutableCopy())) { if (n instanceof DisplayNameNode) { return Optional.of(((DisplayNameNode) n).getDisplayName()); } 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 fc0702a0f..5bb470a64 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 @@ -33,6 +33,7 @@ import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.api.context.DefaultContextKeys; import me.lucko.luckperms.api.context.ImmutableContextSet; import me.lucko.luckperms.api.model.DataMutateResult; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.model.TemporaryDataMutateResult; import me.lucko.luckperms.api.model.TemporaryMergeBehaviour; import me.lucko.luckperms.api.node.Node; @@ -40,7 +41,6 @@ import me.lucko.luckperms.api.node.NodeEqualityPredicate; import me.lucko.luckperms.api.node.NodeType; import me.lucko.luckperms.api.node.Tristate; import me.lucko.luckperms.api.node.types.InheritanceNode; -import me.lucko.luckperms.api.node.types.MetaNode; import me.lucko.luckperms.api.query.Flag; import me.lucko.luckperms.api.query.QueryOptions; import me.lucko.luckperms.common.cacheddata.HolderCachedDataManager; @@ -53,6 +53,7 @@ import me.lucko.luckperms.common.node.utils.NodeTools; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; import java.time.Duration; import java.time.Instant; @@ -63,7 +64,6 @@ import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.OptionalInt; import java.util.Set; import java.util.SortedSet; @@ -106,9 +106,9 @@ public abstract class PermissionHolder { * *

These (unlike transient nodes) are saved to the storage backing.

* - * @see #enduringData() + * @see #normalData() */ - private final NodeMap enduringNodes = new NodeMap(this); + private final NodeMap normalNodes = new NodeMap(this); /** * The holders transient nodes. @@ -156,10 +156,10 @@ public abstract class PermissionHolder { return this.inheritanceComparator; } - public NodeMap getData(NodeMapType type) { + public NodeMap getData(DataType type) { switch (type) { - case ENDURING: - return this.enduringNodes; + case NORMAL: + return this.normalNodes; case TRANSIENT: return this.transientNodes; default: @@ -167,8 +167,8 @@ public abstract class PermissionHolder { } } - public NodeMap enduringData() { - return this.enduringNodes; + public NodeMap normalData() { + return this.normalNodes; } public NodeMap transientData() { @@ -215,105 +215,44 @@ public abstract class PermissionHolder { public abstract HolderType getType(); protected void invalidateCache() { - this.enduringNodes.invalidate(); + this.normalNodes.invalidate(); this.transientNodes.invalidate(); getCachedData().invalidate(); getPlugin().getEventFactory().handleDataRecalculate(this); } - public void setNodes(NodeMapType type, Set set) { + public void setNodes(DataType type, Set set) { getData(type).setContent(set); invalidateCache(); } - public void replaceNodes(NodeMapType type, Multimap multimap) { + public void replaceNodes(DataType type, Multimap multimap) { getData(type).setContent(multimap); invalidateCache(); } - public List getOwnNodes() { - List ret = new ArrayList<>(); - this.transientNodes.copyTo(ret, QueryOptions.nonContextual()); - this.enduringNodes.copyTo(ret, QueryOptions.nonContextual()); - return ret; - } - public List getOwnNodes(QueryOptions queryOptions) { List ret = new ArrayList<>(); this.transientNodes.copyTo(ret, queryOptions); - this.enduringNodes.copyTo(ret, queryOptions); + this.normalNodes.copyTo(ret, queryOptions); + return ret; + } + + public SortedSet getOwnNodesSorted(QueryOptions queryOptions) { + SortedSet ret = new TreeSet<>(NodeWithContextComparator.reverse()); + this.transientNodes.copyTo(ret, queryOptions); + this.normalNodes.copyTo(ret, queryOptions); return ret; } public List getOwnGroupNodes(QueryOptions queryOptions) { List ret = new ArrayList<>(); this.transientNodes.copyInheritanceNodesTo(ret, queryOptions); - this.enduringNodes.copyInheritanceNodesTo(ret, queryOptions); + this.normalNodes.copyInheritanceNodesTo(ret, queryOptions); return ret; } - public SortedSet getOwnNodesSorted() { - SortedSet ret = new TreeSet<>(NodeWithContextComparator.reverse()); - this.transientNodes.copyTo(ret, QueryOptions.nonContextual()); - this.enduringNodes.copyTo(ret, QueryOptions.nonContextual()); - return ret; - } - - public boolean removeIfEnduring(Predicate predicate) { - return removeIfEnduring(predicate, null); - } - - public boolean removeIfEnduring(Predicate predicate, Runnable taskIfSuccess) { - ImmutableCollection before = enduringData().immutable().values(); - if (!this.enduringNodes.removeIf(predicate)) { - return false; - } - if (taskIfSuccess != null) { - taskIfSuccess.run(); - } - invalidateCache(); - ImmutableCollection after = enduringData().immutable().values(); - - this.plugin.getEventFactory().handleNodeClear(this, before, after); - return true; - } - - public boolean removeIfEnduring(ContextSet contextSet, Predicate predicate) { - return removeIfEnduring(contextSet, predicate, null); - } - - public boolean removeIfEnduring(ContextSet contextSet, Predicate predicate, Runnable taskIfSuccess) { - ImmutableCollection before = enduringData().immutable().values(); - if (!this.enduringNodes.removeIf(contextSet, predicate)) { - return false; - } - if (taskIfSuccess != null) { - taskIfSuccess.run(); - } - invalidateCache(); - ImmutableCollection after = enduringData().immutable().values(); - - this.plugin.getEventFactory().handleNodeClear(this, before, after); - return true; - } - - public boolean removeIfTransient(Predicate predicate) { - boolean result = this.transientNodes.removeIf(predicate); - if (result) { - invalidateCache(); - } - return result; - } - - public boolean removeIfTransient(ContextSet contextSet, Predicate predicate) { - boolean result = this.transientNodes.removeIf(contextSet, predicate); - if (result) { - invalidateCache(); - } - return result; - } - public void accumulateInheritancesTo(List accumulator, QueryOptions queryOptions) { InheritanceGraph graph = this.plugin.getInheritanceHandler().getGraph(queryOptions); Iterable traversal = graph.traverse(this); @@ -415,39 +354,28 @@ public abstract class PermissionHolder { * @return true if permissions had expired and were removed */ public boolean auditTemporaryPermissions() { - // audit temporary nodes first, but don't track ones which are removed - // we don't call events for transient nodes - boolean transientWork = this.transientNodes.auditTemporaryNodes(null); + boolean transientWork = auditTemporaryPermissions(DataType.TRANSIENT); + boolean normalWork = auditTemporaryPermissions(DataType.NORMAL); - ImmutableCollection before = enduringData().immutable().values(); + return transientWork || normalWork; + } + + private boolean auditTemporaryPermissions(DataType dataType) { + ImmutableCollection before = getData(dataType).immutable().values(); Set removed = new HashSet<>(); - boolean enduringWork = this.enduringNodes.auditTemporaryNodes(removed); - if (enduringWork) { + boolean work = getData(dataType).auditTemporaryNodes(removed); + if (work) { // invalidate invalidateCache(); // call event - ImmutableCollection after = enduringData().immutable().values(); + ImmutableCollection after = getData(dataType).immutable().values(); for (Node r : removed) { - this.plugin.getEventFactory().handleNodeRemove(r, this, before, after); + this.plugin.getEventFactory().handleNodeRemove(r, this, dataType, before, after); } } - - if (transientWork && !enduringWork) { - invalidateCache(); - } - - return transientWork || enduringWork; - } - - private Optional searchForMatch(NodeMapType type, Node node, NodeEqualityPredicate equalityPredicate) { - for (Node n : getData(type).immutable().values()) { - if (n.equals(node, equalityPredicate)) { - return Optional.of(n); - } - } - return Optional.empty(); + return work; } /** @@ -458,12 +386,15 @@ public abstract class PermissionHolder { * @param equalityPredicate how to match * @return a tristate, returns undefined if no match */ - public Tristate hasPermission(NodeMapType type, Node node, NodeEqualityPredicate equalityPredicate) { + public Tristate hasPermission(DataType type, Node node, NodeEqualityPredicate equalityPredicate) { if (this.getType() == HolderType.GROUP && node instanceof InheritanceNode && ((InheritanceNode) node).getGroupName().equalsIgnoreCase(getObjectName())) { return Tristate.TRUE; } - return searchForMatch(type, node, equalityPredicate).map(n -> Tristate.of(n.getValue())).orElse(Tristate.UNDEFINED); + return getData(type).immutable().values().stream() + .filter(equalityPredicate.equalTo(node)) + .findFirst() + .map(n -> Tristate.of(n.getValue())).orElse(Tristate.UNDEFINED); } /** @@ -487,219 +418,141 @@ public abstract class PermissionHolder { return searchForInheritedMatch(node, equalityPredicate).getResult(); } - public DataMutateResult setPermission(Node node) { - return setPermission(node, true); - } - - public DataMutateResult setPermission(Node node, boolean callEvent) { - if (hasPermission(NodeMapType.ENDURING, node, NodeEqualityPredicate.IGNORE_EXPIRY_TIME) != Tristate.UNDEFINED) { + public DataMutateResult setPermission(DataType dataType, Node node, boolean callEvent) { + if (hasPermission(dataType, node, NodeEqualityPredicate.IGNORE_EXPIRY_TIME) != Tristate.UNDEFINED) { return DataMutateResult.ALREADY_HAS; } - ImmutableCollection before = enduringData().immutable().values(); - this.enduringNodes.add(node); - invalidateCache(); - ImmutableCollection after = enduringData().immutable().values(); + NodeMap data = getData(dataType); + ImmutableCollection before = data.immutable().values(); + + data.add(node); + invalidateCache(); + + ImmutableCollection after = data.immutable().values(); if (callEvent) { - this.plugin.getEventFactory().handleNodeAdd(node, this, before, after); + this.plugin.getEventFactory().handleNodeAdd(node, this, dataType, before, after); } + return DataMutateResult.SUCCESS; } - public TemporaryDataMutateResult setPermission(Node node, TemporaryMergeBehaviour modifier) { - TemporaryDataMutateResult result = handleTemporaryMergeBehaviour(NodeMapType.ENDURING, node, modifier); - if (result != null) { - return result; + public TemporaryDataMutateResult setPermission(DataType dataType, Node node, TemporaryMergeBehaviour mergeBehaviour) { + if (node.hasExpiry() && mergeBehaviour != TemporaryMergeBehaviour.FAIL_WITH_ALREADY_HAS) { + Node otherMatch = getData(dataType).immutable().values().stream() + .filter(NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE.equalTo(node)) + .findFirst().orElse(null); + if (otherMatch != null) { + NodeMap data = getData(dataType); + + Node newNode = null; + switch (mergeBehaviour) { + case ADD_NEW_DURATION_TO_EXISTING: { + // Create a new Node with the same properties, but add the expiry dates together + long newExpiry = otherMatch.getExpiry().plus(Duration.between(Instant.now(), node.getExpiry())).getEpochSecond(); + newNode = node.toBuilder().expiry(newExpiry).build(); + } + case REPLACE_EXISTING_IF_DURATION_LONGER: { + // Only replace if the new expiry time is greater than the old one. + if (node.getExpiry().getEpochSecond() <= otherMatch.getExpiry().getEpochSecond()) { + break; + } + newNode = node; + } + } + + if (newNode != null) { + // Remove the old Node & add the new one. + ImmutableCollection before = data.immutable().values(); + + data.replace(newNode, otherMatch); + invalidateCache(); + + ImmutableCollection after = data.immutable().values(); + this.plugin.getEventFactory().handleNodeAdd(newNode, this, dataType, before, after); + + return new TemporaryResult(DataMutateResult.SUCCESS, newNode); + } + } } // Fallback to the normal handling. - return new TemporaryResult(setPermission(node), node); + return new TemporaryResult(setPermission(dataType, node, true), node); } - public DataMutateResult setTransientPermission(Node node) { - if (hasPermission(NodeMapType.TRANSIENT, node, NodeEqualityPredicate.IGNORE_EXPIRY_TIME) != Tristate.UNDEFINED) { - return DataMutateResult.ALREADY_HAS; - } - - // don't call any events for transient operations - this.transientNodes.add(node); - invalidateCache(); - return DataMutateResult.SUCCESS; - } - - public TemporaryDataMutateResult setTransientPermission(Node node, TemporaryMergeBehaviour modifier) { - TemporaryDataMutateResult result = handleTemporaryMergeBehaviour(NodeMapType.TRANSIENT, node, modifier); - if (result != null) { - return result; - } - - // Fallback to the normal handling. - return new TemporaryResult(setTransientPermission(node), node); - } - - private TemporaryDataMutateResult handleTemporaryMergeBehaviour(NodeMapType nodeMapType, Node node, TemporaryMergeBehaviour mergeBehaviour) { - // If the Node is temporary, we should take note of the modifier - if (!node.hasExpiry() || mergeBehaviour == TemporaryMergeBehaviour.FAIL_WITH_ALREADY_HAS) { - return null; - } - - Node previous = searchForMatch(nodeMapType, node, NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE).orElse(null); - if (previous == null) { - return null; - } - - NodeMap data = getData(nodeMapType); - boolean callEvents = nodeMapType == NodeMapType.ENDURING; - - switch (mergeBehaviour) { - case ADD_NEW_DURATION_TO_EXISTING: { - // Create a new Node with the same properties, but add the expiry dates together - Node newNode = node.toBuilder().expiry(previous.getExpiry().plus(Duration.between(Instant.now(), node.getExpiry())).getEpochSecond()).build(); - - // Remove the old Node & add the new one. - ImmutableCollection before = null; - if (callEvents) { - before = data.immutable().values(); - } - - data.replace(newNode, previous); - invalidateCache(); - - if (callEvents) { - ImmutableCollection after = data.immutable().values(); - this.plugin.getEventFactory().handleNodeAdd(newNode, this, before, after); - } - - return new TemporaryResult(DataMutateResult.SUCCESS, newNode); - } - case REPLACE_EXISTING_IF_DURATION_LONGER: { - // Only replace if the new expiry time is greater than the old one. - if (node.getExpiry().getEpochSecond() <= previous.getExpiry().getEpochSecond()) { - break; - } - - ImmutableCollection before = null; - if (callEvents) { - before = data.immutable().values(); - } - - data.replace(node, previous); - invalidateCache(); - - if (callEvents) { - ImmutableCollection after = data.immutable().values(); - this.plugin.getEventFactory().handleNodeAdd(node, this, before, after); - } - - return new TemporaryResult(DataMutateResult.SUCCESS, node); - } - default: - break; - } - return null; - } - - public DataMutateResult unsetPermission(Node node) { - if (hasPermission(NodeMapType.ENDURING, node, NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE) == Tristate.UNDEFINED) { + public DataMutateResult unsetPermission(DataType dataType, Node node) { + if (hasPermission(dataType, node, NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE) == Tristate.UNDEFINED) { return DataMutateResult.LACKS; } - ImmutableCollection before = enduringData().immutable().values(); - this.enduringNodes.remove(node); - invalidateCache(); - ImmutableCollection after = enduringData().immutable().values(); + ImmutableCollection before = getData(dataType).immutable().values(); + + getData(dataType).remove(node); + invalidateCache(); + + ImmutableCollection after = getData(dataType).immutable().values(); + this.plugin.getEventFactory().handleNodeRemove(node, this, dataType, before, after); - this.plugin.getEventFactory().handleNodeRemove(node, this, before, after); return DataMutateResult.SUCCESS; } - public DataMutateResult unsetTransientPermission(Node node) { - if (hasPermission(NodeMapType.TRANSIENT, node, NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE) == Tristate.UNDEFINED) { - return DataMutateResult.LACKS; + public boolean removeIf(DataType dataType, @Nullable ContextSet contextSet, Predicate predicate, @Nullable Runnable taskIfSuccess) { + NodeMap data = getData(dataType); + ImmutableCollection before = data.immutable().values();; + + if (contextSet == null) { + if (!data.removeIf(predicate)) { + return false; + } + } else { + if (!data.removeIf(contextSet, predicate)) { + return false; + } + } + + if (taskIfSuccess != null) { + taskIfSuccess.run(); } - // don't call any events for transient operations - this.transientNodes.remove(node); invalidateCache(); - return DataMutateResult.SUCCESS; + + ImmutableCollection after = data.immutable().values(); + this.plugin.getEventFactory().handleNodeClear(this, dataType, before, after); + + return true; } - /** - * Clear all of the holders permission nodes - */ - public boolean clearEnduringNodes() { - ImmutableCollection before = enduringData().immutable().values(); - this.enduringNodes.clear(); + public boolean clearNodes(DataType dataType, ContextSet contextSet) { + NodeMap data = getData(dataType); + ImmutableCollection before = data.immutable().values(); + + if (contextSet == null) { + data.clear(); + } else { + data.clear(contextSet); + } + invalidateCache(); - ImmutableCollection after = enduringData().immutable().values(); + + ImmutableCollection after = data.immutable().values(); if (before.size() == after.size()) { return false; } - this.plugin.getEventFactory().handleNodeClear(this, before, after); + this.plugin.getEventFactory().handleNodeClear(this, dataType, before, after); return true; } - public boolean clearEnduringNodes(ContextSet contextSet) { - ImmutableCollection before = enduringData().immutable().values(); - this.enduringNodes.clear(contextSet); - invalidateCache(); - ImmutableCollection after = enduringData().immutable().values(); - - if (before.size() == after.size()) { - return false; - } - - this.plugin.getEventFactory().handleNodeClear(this, before, after); - return true; - } - - public boolean clearEnduringParents(boolean giveDefault) { - return removeIfEnduring(n -> n instanceof InheritanceNode, () -> { + public boolean clearNormalParents(ContextSet contextSet, boolean giveDefault) { + return removeIf(DataType.NORMAL, contextSet, n -> n instanceof InheritanceNode, () -> { if (this.getType() == HolderType.USER && giveDefault) { this.plugin.getUserManager().giveDefaultIfNeeded((User) this, false); } }); } - public boolean clearEnduringParents(ContextSet contextSet, boolean giveDefault) { - return removeIfEnduring(contextSet, n -> n instanceof InheritanceNode, () -> { - if (this.getType() == HolderType.USER && giveDefault) { - this.plugin.getUserManager().giveDefaultIfNeeded((User) this, false); - } - }); - } - - public boolean clearMeta(NodeType type) { - return removeIfEnduring(type::matches); - } - - public boolean clearMeta(NodeType type, ContextSet contextSet) { - return removeIfEnduring(contextSet, type::matches); - } - - public boolean clearMetaKeys(String key, boolean temp) { - return removeIfEnduring(n -> n instanceof MetaNode && (n.hasExpiry() == temp) && ((MetaNode) n).getMetaKey().equalsIgnoreCase(key)); - } - - public boolean clearMetaKeys(String key, ContextSet contextSet, boolean temp) { - return removeIfEnduring(contextSet, n -> n instanceof MetaNode && (n.hasExpiry() == temp) && ((MetaNode) n).getMetaKey().equalsIgnoreCase(key)); - } - - public boolean clearTransientNodes() { - this.transientNodes.clear(); - invalidateCache(); - return true; - } - - public boolean clearTransientNodes(ContextSet contextSet) { - this.transientNodes.clear(); - invalidateCache(); - return true; - } - public OptionalInt getWeight() { return OptionalInt.empty(); } diff --git a/common/src/main/java/me/lucko/luckperms/common/model/Track.java b/common/src/main/java/me/lucko/luckperms/common/model/Track.java index a7b224a22..89a609aac 100644 --- a/common/src/main/java/me/lucko/luckperms/common/model/Track.java +++ b/common/src/main/java/me/lucko/luckperms/common/model/Track.java @@ -29,6 +29,7 @@ import com.google.common.collect.ImmutableList; import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.api.model.DataMutateResult; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.node.Node; import me.lucko.luckperms.api.node.NodeType; import me.lucko.luckperms.api.node.types.InheritanceNode; @@ -276,7 +277,7 @@ public final class Track implements Identifiable { } // find all groups that are inherited by the user in the exact contexts given and applicable to this track - List nodes = user.enduringData().immutable().get(context.immutableCopy()).stream() + List nodes = user.normalData().immutable().get(context.immutableCopy()).stream() .filter(NodeType.INHERITANCE::matches) .map(NodeType.INHERITANCE::cast) .filter(Node::getValue) @@ -300,7 +301,7 @@ public final class Track implements Identifiable { return PromotionResults.undefinedFailure(); } - user.setPermission(NodeFactory.buildGroupNode(nextGroup.getId()).withContext(context).build()); + user.setPermission(DataType.NORMAL, NodeFactory.buildGroupNode(nextGroup.getId()).withContext(context).build(), true); this.plugin.getEventFactory().handleUserPromote(user, this, null, first, sender); return PromotionResults.addedToFirst(first); } @@ -326,8 +327,8 @@ public final class Track implements Identifiable { return PromotionResults.undefinedFailure(); } - user.unsetPermission(oldNode); - user.setPermission(NodeFactory.buildGroupNode(nextGroup.getName()).withContext(context).build()); + user.unsetPermission(DataType.NORMAL, oldNode); + user.setPermission(DataType.NORMAL, NodeFactory.buildGroupNode(nextGroup.getName()).withContext(context).build(), true); if (context.isEmpty() && user.getPrimaryGroup().getStoredValue().orElse(NodeFactory.DEFAULT_GROUP_NAME).equalsIgnoreCase(old)) { user.getPrimaryGroup().setStoredValue(nextGroup.getName()); @@ -343,7 +344,7 @@ public final class Track implements Identifiable { } // find all groups that are inherited by the user in the exact contexts given and applicable to this track - List nodes = user.enduringData().immutable().get(context.immutableCopy()).stream() + List nodes = user.normalData().immutable().get(context.immutableCopy()).stream() .filter(NodeType.INHERITANCE::matches) .map(NodeType.INHERITANCE::cast) .filter(Node::getValue) @@ -372,7 +373,7 @@ public final class Track implements Identifiable { return DemotionResults.removedFromFirst(null); } - user.unsetPermission(oldNode); + user.unsetPermission(DataType.NORMAL, oldNode); this.plugin.getEventFactory().handleUserDemote(user, this, old, null, sender); return DemotionResults.removedFromFirst(old); } @@ -382,8 +383,8 @@ public final class Track implements Identifiable { return DemotionResults.malformedTrack(previous); } - user.unsetPermission(oldNode); - user.setPermission(NodeFactory.buildGroupNode(previousGroup.getName()).withContext(context).build()); + user.unsetPermission(DataType.NORMAL, oldNode); + user.setPermission(DataType.NORMAL, NodeFactory.buildGroupNode(previousGroup.getName()).withContext(context).build(), true); if (context.isEmpty() && user.getPrimaryGroup().getStoredValue().orElse(NodeFactory.DEFAULT_GROUP_NAME).equalsIgnoreCase(old)) { user.getPrimaryGroup().setStoredValue(previousGroup.getName()); diff --git a/common/src/main/java/me/lucko/luckperms/common/model/User.java b/common/src/main/java/me/lucko/luckperms/common/model/User.java index 5e4167eae..9b666f0cc 100644 --- a/common/src/main/java/me/lucko/luckperms/common/model/User.java +++ b/common/src/main/java/me/lucko/luckperms/common/model/User.java @@ -25,6 +25,7 @@ package me.lucko.luckperms.common.model; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.common.api.implementation.ApiUser; import me.lucko.luckperms.common.cacheddata.UserCachedDataManager; import me.lucko.luckperms.common.config.ConfigKeys; @@ -183,9 +184,8 @@ public class User extends PermissionHolder implements Identifiable extends AbstractManage String pg = user.getPrimaryGroup().getValue(); boolean has = false; - for (Node node : user.enduringData().immutable().get(ImmutableContextSet.empty())) { + for (Node node : user.normalData().immutable().get(ImmutableContextSet.empty())) { if (node instanceof InheritanceNode && ((InheritanceNode) node).getGroupName().equalsIgnoreCase(pg)) { has = true; break; @@ -98,7 +99,7 @@ public abstract class AbstractUserManager extends AbstractManage // need to find a new primary group for the user. if (!has) { - String group = user.enduringData().immutable().get(ImmutableContextSet.empty()).stream() + String group = user.normalData().immutable().get(ImmutableContextSet.empty()).stream() .filter(NodeType.INHERITANCE::matches) .map(NodeType.INHERITANCE::cast) .findFirst() @@ -116,7 +117,7 @@ public abstract class AbstractUserManager extends AbstractManage // check that all users are member of at least one group boolean hasGroup = false; if (user.getPrimaryGroup().getStoredValue().isPresent()) { - for (Node node : user.enduringData().immutable().values()) { + for (Node node : user.normalData().immutable().values()) { if (!node.getContexts().isEmpty()) { continue; } @@ -130,7 +131,7 @@ public abstract class AbstractUserManager extends AbstractManage if (!hasGroup) { user.getPrimaryGroup().setStoredValue(NodeFactory.DEFAULT_GROUP_NAME); - user.setPermission(NodeFactory.buildGroupNode(NodeFactory.DEFAULT_GROUP_NAME).build(), false); + user.setPermission(DataType.NORMAL, NodeFactory.buildGroupNode(NodeFactory.DEFAULT_GROUP_NAME).build(), false); work = true; } @@ -182,7 +183,7 @@ public abstract class AbstractUserManager extends AbstractManage */ @Override public boolean shouldSave(User user) { - ImmutableCollection nodes = user.enduringData().immutable().values(); + ImmutableCollection nodes = user.normalData().immutable().values(); if (nodes.size() != 1) { return true; } diff --git a/common/src/main/java/me/lucko/luckperms/common/plugin/util/AbstractConnectionListener.java b/common/src/main/java/me/lucko/luckperms/common/plugin/util/AbstractConnectionListener.java index 78eee10cd..0be9463ea 100644 --- a/common/src/main/java/me/lucko/luckperms/common/plugin/util/AbstractConnectionListener.java +++ b/common/src/main/java/me/lucko/luckperms/common/plugin/util/AbstractConnectionListener.java @@ -25,6 +25,7 @@ package me.lucko.luckperms.common.plugin.util; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.model.PlayerSaveResult; import me.lucko.luckperms.api.platform.Platform; import me.lucko.luckperms.common.config.ConfigKeys; @@ -134,7 +135,7 @@ public abstract class AbstractConnectionListener { this.plugin.getBootstrap().getScheduler().executeAsync(() -> { User user = this.plugin.getUserManager().getIfLoaded(uuid); if (user != null) { - user.clearTransientNodes(); + user.clearNodes(DataType.TRANSIENT, null); } }); } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/file/AbstractConfigurateStorage.java b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/file/AbstractConfigurateStorage.java index ac2d4bb61..d8aa36d4d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/file/AbstractConfigurateStorage.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/file/AbstractConfigurateStorage.java @@ -31,6 +31,7 @@ import com.google.common.collect.Maps; import me.lucko.luckperms.api.actionlog.Action; import me.lucko.luckperms.api.context.ImmutableContextSet; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.model.PlayerSaveResult; import me.lucko.luckperms.api.node.ChatMetaType; import me.lucko.luckperms.api.node.Node; @@ -42,7 +43,6 @@ import me.lucko.luckperms.common.actionlog.Log; import me.lucko.luckperms.common.bulkupdate.BulkUpdate; import me.lucko.luckperms.common.context.ContextSetConfigurateSerializer; import me.lucko.luckperms.common.model.Group; -import me.lucko.luckperms.common.model.NodeMapType; import me.lucko.luckperms.common.model.Track; import me.lucko.luckperms.common.model.User; import me.lucko.luckperms.common.model.UserIdentifier; @@ -199,7 +199,7 @@ public abstract class AbstractConfigurateStorage implements StorageImplementatio user.getPrimaryGroup().setStoredValue(object.getNode(this.loader instanceof JsonLoader ? "primaryGroup" : "primary-group").getString()); Set nodes = readNodes(object).stream().map(NodeDataContainer::toNode).collect(Collectors.toSet()); - user.setNodes(NodeMapType.ENDURING, nodes); + user.setNodes(DataType.NORMAL, nodes); user.setName(name, true); boolean save = this.plugin.getUserManager().giveDefaultIfNeeded(user, false); @@ -239,7 +239,7 @@ public abstract class AbstractConfigurateStorage implements StorageImplementatio data.getNode("name").setValue(user.getName().orElse("null")); data.getNode(this.loader instanceof JsonLoader ? "primaryGroup" : "primary-group").setValue(user.getPrimaryGroup().getStoredValue().orElse(NodeFactory.DEFAULT_GROUP_NAME)); - Set nodes = user.enduringData().immutable().values().stream().map(NodeDataContainer::fromNode).collect(Collectors.toCollection(LinkedHashSet::new)); + Set nodes = user.normalData().immutable().values().stream().map(NodeDataContainer::fromNode).collect(Collectors.toCollection(LinkedHashSet::new)); writeNodes(data, nodes); saveFile(StorageLocation.USER, user.getUuid().toString(), data); @@ -260,14 +260,14 @@ public abstract class AbstractConfigurateStorage implements StorageImplementatio if (object != null) { Set nodes = readNodes(object).stream().map(NodeDataContainer::toNode).collect(Collectors.toSet()); - group.setNodes(NodeMapType.ENDURING, nodes); + group.setNodes(DataType.NORMAL, nodes); } else { ConfigurationNode data = SimpleConfigurationNode.root(); if (this instanceof SeparatedConfigurateStorage) { data.getNode("name").setValue(group.getName()); } - Set nodes = group.enduringData().immutable().values().stream().map(NodeDataContainer::fromNode).collect(Collectors.toCollection(LinkedHashSet::new)); + Set nodes = group.normalData().immutable().values().stream().map(NodeDataContainer::fromNode).collect(Collectors.toCollection(LinkedHashSet::new)); writeNodes(data, nodes); saveFile(StorageLocation.GROUP, name, data); @@ -301,7 +301,7 @@ public abstract class AbstractConfigurateStorage implements StorageImplementatio Set data = readNodes(object); Set nodes = data.stream().map(NodeDataContainer::toNode).collect(Collectors.toSet()); - group.setNodes(NodeMapType.ENDURING, nodes); + group.setNodes(DataType.NORMAL, nodes); } catch (Exception e) { throw reportException(name, e); @@ -322,7 +322,7 @@ public abstract class AbstractConfigurateStorage implements StorageImplementatio data.getNode("name").setValue(group.getName()); } - Set nodes = group.enduringData().immutable().values().stream().map(NodeDataContainer::fromNode).collect(Collectors.toCollection(LinkedHashSet::new)); + Set nodes = group.normalData().immutable().values().stream().map(NodeDataContainer::fromNode).collect(Collectors.toCollection(LinkedHashSet::new)); writeNodes(data, nodes); saveFile(StorageLocation.GROUP, group.getName(), data); diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/mongodb/MongoStorage.java b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/mongodb/MongoStorage.java index 787275805..6831a006e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/mongodb/MongoStorage.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/mongodb/MongoStorage.java @@ -41,6 +41,7 @@ import me.lucko.luckperms.api.actionlog.Action; 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.api.model.DataType; import me.lucko.luckperms.api.model.PlayerSaveResult; import me.lucko.luckperms.api.node.HeldNode; import me.lucko.luckperms.api.node.Node; @@ -49,7 +50,6 @@ import me.lucko.luckperms.common.actionlog.Log; import me.lucko.luckperms.common.bulkupdate.BulkUpdate; import me.lucko.luckperms.common.bulkupdate.comparison.Constraint; import me.lucko.luckperms.common.model.Group; -import me.lucko.luckperms.common.model.NodeMapType; import me.lucko.luckperms.common.model.Track; import me.lucko.luckperms.common.model.User; import me.lucko.luckperms.common.model.UserIdentifier; @@ -276,7 +276,7 @@ public class MongoStorage implements StorageImplementation { user.getPrimaryGroup().setStoredValue(d.getString("primaryGroup")); Set nodes = nodesFromDoc(d).stream().map(NodeDataContainer::toNode).collect(Collectors.toSet()); - user.setNodes(NodeMapType.ENDURING, nodes); + user.setNodes(DataType.NORMAL, nodes); user.setName(name, true); boolean save = this.plugin.getUserManager().giveDefaultIfNeeded(user, false); @@ -360,7 +360,7 @@ public class MongoStorage implements StorageImplementation { if (cursor.hasNext()) { Document d = cursor.next(); Set nodes = nodesFromDoc(d).stream().map(NodeDataContainer::toNode).collect(Collectors.toSet()); - group.setNodes(NodeMapType.ENDURING, nodes); + group.setNodes(DataType.NORMAL, nodes); } else { c.insertOne(groupToDoc(group)); } @@ -391,7 +391,7 @@ public class MongoStorage implements StorageImplementation { Document d = cursor.next(); Set nodes = nodesFromDoc(d).stream().map(NodeDataContainer::toNode).collect(Collectors.toSet()); - group.setNodes(NodeMapType.ENDURING, nodes); + group.setNodes(DataType.NORMAL, nodes); } } finally { if (group != null) { @@ -633,7 +633,7 @@ public class MongoStorage implements StorageImplementation { } private static Document userToDoc(User user) { - List nodes = user.enduringData().immutable().values().stream() + List nodes = user.normalData().immutable().values().stream() .map(NodeDataContainer::fromNode) .map(MongoStorage::nodeToDoc) .collect(Collectors.toList()); @@ -657,7 +657,7 @@ public class MongoStorage implements StorageImplementation { } private static Document groupToDoc(Group group) { - List nodes = group.enduringData().immutable().values().stream() + List nodes = group.normalData().immutable().values().stream() .map(NodeDataContainer::fromNode) .map(MongoStorage::nodeToDoc) .collect(Collectors.toList()); diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/SqlStorage.java b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/SqlStorage.java index de1924741..8f5ba44e4 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/SqlStorage.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/SqlStorage.java @@ -29,6 +29,7 @@ import com.google.common.collect.Maps; import com.google.gson.reflect.TypeToken; import me.lucko.luckperms.api.actionlog.Action; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.model.PlayerSaveResult; import me.lucko.luckperms.api.node.HeldNode; import me.lucko.luckperms.api.node.Node; @@ -39,7 +40,6 @@ import me.lucko.luckperms.common.bulkupdate.PreparedStatementBuilder; import me.lucko.luckperms.common.bulkupdate.comparison.Constraint; import me.lucko.luckperms.common.context.ContextSetJsonSerializer; import me.lucko.luckperms.common.model.Group; -import me.lucko.luckperms.common.model.NodeMapType; import me.lucko.luckperms.common.model.Track; import me.lucko.luckperms.common.model.User; import me.lucko.luckperms.common.model.UserIdentifier; @@ -377,7 +377,7 @@ public class SqlStorage implements StorageImplementation { // If the user has any data in storage if (!data.isEmpty()) { Set nodes = data.stream().map(NodeDataContainer::toNode).collect(Collectors.toSet()); - user.setNodes(NodeMapType.ENDURING, nodes); + user.setNodes(DataType.NORMAL, nodes); // Save back to the store if data they were given any defaults or had permissions expire if (this.plugin.getUserManager().giveDefaultIfNeeded(user, false) | user.auditTemporaryPermissions()) { @@ -439,7 +439,7 @@ public class SqlStorage implements StorageImplementation { } } - Set local = user.enduringData().immutable().values().stream().map(NodeDataContainer::fromNode).collect(Collectors.toSet()); + Set local = user.normalData().immutable().values().stream().map(NodeDataContainer::fromNode).collect(Collectors.toSet()); Map.Entry, Set> diff = compareSets(local, remote); @@ -630,9 +630,9 @@ public class SqlStorage implements StorageImplementation { if (!data.isEmpty()) { Set nodes = data.stream().map(NodeDataContainer::toNode).collect(Collectors.toSet()); - group.setNodes(NodeMapType.ENDURING, nodes); + group.setNodes(DataType.NORMAL, nodes); } else { - group.clearEnduringNodes(); + group.clearNodes(DataType.NORMAL, null); } } finally { group.getIoLock().unlock(); @@ -678,7 +678,7 @@ public class SqlStorage implements StorageImplementation { group.getIoLock().lock(); try { // Empty data, just delete. - if (group.enduringData().immutable().isEmpty()) { + if (group.normalData().immutable().isEmpty()) { try (Connection c = this.connectionFactory.getConnection()) { try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.apply(GROUP_PERMISSIONS_DELETE))) { ps.setString(1, group.getName()); @@ -708,7 +708,7 @@ public class SqlStorage implements StorageImplementation { } } - Set local = group.enduringData().immutable().values().stream().map(NodeDataContainer::fromNode).collect(Collectors.toSet()); + Set local = group.normalData().immutable().values().stream().map(NodeDataContainer::fromNode).collect(Collectors.toSet()); Map.Entry, Set> diff = compareSets(local, remote); diff --git a/common/src/main/java/me/lucko/luckperms/common/web/WebEditor.java b/common/src/main/java/me/lucko/luckperms/common/web/WebEditor.java index 132819b06..6d8b7c502 100644 --- a/common/src/main/java/me/lucko/luckperms/common/web/WebEditor.java +++ b/common/src/main/java/me/lucko/luckperms/common/web/WebEditor.java @@ -79,7 +79,7 @@ public final class WebEditor { obj.add("uuid", ((User) holder).getUuid().toString()); } })) - .add("nodes", serializePermissions(holder.enduringData().immutable().values().stream().map(NodeDataContainer::fromNode))); + .add("nodes", serializePermissions(holder.normalData().immutable().values().stream().map(NodeDataContainer::fromNode))); } public static JsonObject formPayload(List holders, Sender sender, String cmdLabel, LuckPermsPlugin plugin) { diff --git a/nukkit/src/main/java/me/lucko/luckperms/nukkit/inject/permissible/LPPermissionAttachment.java b/nukkit/src/main/java/me/lucko/luckperms/nukkit/inject/permissible/LPPermissionAttachment.java index c6a467b19..19a1b77ff 100644 --- a/nukkit/src/main/java/me/lucko/luckperms/nukkit/inject/permissible/LPPermissionAttachment.java +++ b/nukkit/src/main/java/me/lucko/luckperms/nukkit/inject/permissible/LPPermissionAttachment.java @@ -27,6 +27,7 @@ package me.lucko.luckperms.nukkit.inject.permissible; import com.google.common.base.Preconditions; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.node.Node; import me.lucko.luckperms.api.node.metadata.NodeMetadata; import me.lucko.luckperms.api.node.metadata.NodeMetadataKey; @@ -191,7 +192,7 @@ public class LPPermissionAttachment extends PermissionAttachment implements Node // set the transient node User user = this.permissible.getUser(); - ((Result) user.setTransientPermission(node)).wasSuccessful(); + ((Result) user.setPermission(DataType.TRANSIENT, node, true)).wasSuccessful(); } private void unsetPermissionInternal(String name) { @@ -201,13 +202,13 @@ public class LPPermissionAttachment extends PermissionAttachment implements Node // remove transient permissions from the holder which were added by this attachment & equal the permission User user = this.permissible.getUser(); - user.removeIfTransient(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), (Runnable) null); } private void clearInternal() { // remove all transient permissions added by this attachment User user = this.permissible.getUser(); - user.removeIfTransient(n -> n.getMetadata(TRANSIENT_SOURCE_KEY).orElse(null) == this); + user.removeIf(DataType.TRANSIENT, null, n -> n.getMetadata(TRANSIENT_SOURCE_KEY).orElse(null) == this, (Runnable) null); } @Override diff --git a/sponge/sponge-service/src/main/java/me/lucko/luckperms/sponge/service/model/LPSubjectData.java b/sponge/sponge-service/src/main/java/me/lucko/luckperms/sponge/service/model/LPSubjectData.java index 219ca7957..bc8d25f1f 100644 --- a/sponge/sponge-service/src/main/java/me/lucko/luckperms/sponge/service/model/LPSubjectData.java +++ b/sponge/sponge-service/src/main/java/me/lucko/luckperms/sponge/service/model/LPSubjectData.java @@ -29,8 +29,8 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import me.lucko.luckperms.api.context.ImmutableContextSet; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.node.Tristate; -import me.lucko.luckperms.common.model.NodeMapType; import org.spongepowered.api.service.permission.SubjectData; @@ -45,7 +45,7 @@ public interface LPSubjectData { LPSubject getParentSubject(); - NodeMapType getType(); + DataType getType(); /* permissions */ diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/ProxyFactory.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/ProxyFactory.java index 727dda56c..8e8349999 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/ProxyFactory.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/ProxyFactory.java @@ -25,7 +25,7 @@ package me.lucko.luckperms.sponge.service; -import me.lucko.luckperms.common.model.NodeMapType; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.sponge.service.model.LPPermissionDescription; import me.lucko.luckperms.sponge.service.model.LPPermissionService; import me.lucko.luckperms.sponge.service.model.LPSubject; @@ -75,8 +75,8 @@ public final class ProxyFactory { public static SubjectData toSponge(LPSubjectData luckPerms) { LPSubject parentSubject = luckPerms.getParentSubject(); return IS_API_7 ? - new me.lucko.luckperms.sponge.service.proxy.api7.SubjectDataProxy(parentSubject.getService(), parentSubject.toReference(), luckPerms.getType() == NodeMapType.ENDURING) : - new me.lucko.luckperms.sponge.service.proxy.api6.SubjectDataProxy(parentSubject.getService(), parentSubject.toReference(), luckPerms.getType() == NodeMapType.ENDURING); + new me.lucko.luckperms.sponge.service.proxy.api7.SubjectDataProxy(parentSubject.getService(), parentSubject.toReference(), luckPerms.getType() == DataType.NORMAL) : + new me.lucko.luckperms.sponge.service.proxy.api6.SubjectDataProxy(parentSubject.getService(), parentSubject.toReference(), luckPerms.getType() == DataType.NORMAL); } public static PermissionDescription toSponge(LPPermissionDescription luckPerms) { diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/calculated/CalculatedSubjectData.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/calculated/CalculatedSubjectData.java index 01299b8f9..15c50294c 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/calculated/CalculatedSubjectData.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/calculated/CalculatedSubjectData.java @@ -30,10 +30,10 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import me.lucko.luckperms.api.context.ImmutableContextSet; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.node.Tristate; import me.lucko.luckperms.api.query.QueryOptions; import me.lucko.luckperms.common.context.ContextSetComparator; -import me.lucko.luckperms.common.model.NodeMapType; import me.lucko.luckperms.sponge.service.ProxyFactory; import me.lucko.luckperms.sponge.service.model.LPPermissionService; import me.lucko.luckperms.sponge.service.model.LPSubject; @@ -58,14 +58,14 @@ import java.util.concurrent.ConcurrentHashMap; */ public class CalculatedSubjectData implements LPSubjectData { private final LPSubject parentSubject; - private final NodeMapType type; + private final DataType type; private final LPPermissionService service; private final Map> permissions = new ConcurrentHashMap<>(); private final Map> parents = new ConcurrentHashMap<>(); private final Map> options = new ConcurrentHashMap<>(); - public CalculatedSubjectData(LPSubject parentSubject, NodeMapType type, LPPermissionService service) { + public CalculatedSubjectData(LPSubject parentSubject, DataType type, LPPermissionService service) { this.parentSubject = parentSubject; this.type = type; this.service = service; @@ -82,7 +82,7 @@ public class CalculatedSubjectData implements LPSubjectData { } @Override - public NodeMapType getType() { + public DataType getType() { return this.type; } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/calculated/MonitoredSubjectData.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/calculated/MonitoredSubjectData.java index fae6865df..3a8c6c4f7 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/calculated/MonitoredSubjectData.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/calculated/MonitoredSubjectData.java @@ -26,8 +26,8 @@ package me.lucko.luckperms.sponge.service.model.calculated; import me.lucko.luckperms.api.context.ImmutableContextSet; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.node.Tristate; -import me.lucko.luckperms.common.model.NodeMapType; import me.lucko.luckperms.sponge.service.LuckPermsService; import me.lucko.luckperms.sponge.service.model.LPSubject; import me.lucko.luckperms.sponge.service.model.LPSubjectReference; @@ -38,7 +38,7 @@ import java.util.concurrent.CompletableFuture; * Extension of CalculatedSubjectData which allows subclasses to respond to updates */ public abstract class MonitoredSubjectData extends CalculatedSubjectData { - public MonitoredSubjectData(LPSubject subject, NodeMapType type, LuckPermsService service) { + public MonitoredSubjectData(LPSubject subject, DataType type, LuckPermsService service) { super(subject, type, service); } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/permissionholder/PermissionHolderSubject.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/permissionholder/PermissionHolderSubject.java index 1094bc208..075bd6197 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/permissionholder/PermissionHolderSubject.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/permissionholder/PermissionHolderSubject.java @@ -28,13 +28,13 @@ package me.lucko.luckperms.sponge.service.model.permissionholder; import com.google.common.collect.ImmutableList; import me.lucko.luckperms.api.context.ImmutableContextSet; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.node.Tristate; import me.lucko.luckperms.api.query.QueryOptions; import me.lucko.luckperms.common.cacheddata.type.MetaCache; import me.lucko.luckperms.common.graph.TraversalAlgorithm; import me.lucko.luckperms.common.inheritance.InheritanceGraph; import me.lucko.luckperms.common.model.Group; -import me.lucko.luckperms.common.model.NodeMapType; import me.lucko.luckperms.common.model.PermissionHolder; import me.lucko.luckperms.common.node.factory.NodeFactory; import me.lucko.luckperms.common.node.factory.NodeTypes; @@ -67,8 +67,8 @@ public abstract class PermissionHolderSubject implem PermissionHolderSubject(LPSpongePlugin plugin, T parent) { this.parent = parent; this.plugin = plugin; - this.subjectData = new PermissionHolderSubjectData(plugin.getService(), NodeMapType.ENDURING, parent, this); - this.transientSubjectData = new PermissionHolderSubjectData(plugin.getService(), NodeMapType.TRANSIENT, parent, this); + this.subjectData = new PermissionHolderSubjectData(plugin.getService(), DataType.NORMAL, parent, this); + this.transientSubjectData = new PermissionHolderSubjectData(plugin.getService(), DataType.TRANSIENT, parent, this); } public void fireUpdateEvent() { diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/permissionholder/PermissionHolderSubjectData.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/permissionholder/PermissionHolderSubjectData.java index 8970e3695..945579000 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/permissionholder/PermissionHolderSubjectData.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/permissionholder/PermissionHolderSubjectData.java @@ -30,6 +30,7 @@ import com.google.common.collect.ImmutableMap; import me.lucko.luckperms.api.context.ImmutableContextSet; import me.lucko.luckperms.api.model.DataMutateResult; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.api.node.ChatMetaType; import me.lucko.luckperms.api.node.Node; import me.lucko.luckperms.api.node.NodeType; @@ -42,7 +43,6 @@ import me.lucko.luckperms.api.query.QueryOptions; import me.lucko.luckperms.common.cacheddata.type.MetaAccumulator; import me.lucko.luckperms.common.model.Group; import me.lucko.luckperms.common.model.HolderType; -import me.lucko.luckperms.common.model.NodeMapType; import me.lucko.luckperms.common.model.PermissionHolder; import me.lucko.luckperms.common.model.User; import me.lucko.luckperms.common.node.factory.NodeFactory; @@ -68,11 +68,11 @@ import java.util.stream.Stream; public class PermissionHolderSubjectData implements LPSubjectData { private final LuckPermsService service; - private final NodeMapType type; + private final DataType type; private final PermissionHolder holder; private final LPSubject parentSubject; - public PermissionHolderSubjectData(LuckPermsService service, NodeMapType type, PermissionHolder holder, LPSubject parentSubject) { + public PermissionHolderSubjectData(LuckPermsService service, DataType type, PermissionHolder holder, LPSubject parentSubject) { this.type = type; this.service = service; this.holder = holder; @@ -94,7 +94,7 @@ public class PermissionHolderSubjectData implements LPSubjectData { } @Override - public NodeMapType getType() { + public DataType getType() { return this.type; } @@ -129,35 +129,52 @@ public class PermissionHolderSubjectData implements LPSubjectData { if (tristate == Tristate.UNDEFINED) { // Unset Node node = NodeFactory.builder(permission).withContext(contexts).build(); - this.type.run( - () -> this.holder.unsetPermission(node), - () -> this.holder.unsetTransientPermission(node) - ); + switch (this.type) { + case NORMAL: + this.holder.unsetPermission(DataType.NORMAL, node); + break; + case TRANSIENT: + this.holder.unsetPermission(DataType.TRANSIENT, node); + break; + default: + throw new AssertionError(); + } return save(this.holder).thenApply(v -> true); } Node node = NodeFactory.builder(permission).value(tristate.asBoolean()).withContext(contexts).build(); - this.type.run( - () -> { - // unset the inverse, to allow false -> true, true -> false overrides. - this.holder.unsetPermission(node); - this.holder.setPermission(node); - }, - () -> { - // unset the inverse, to allow false -> true, true -> false overrides. - this.holder.unsetTransientPermission(node); - this.holder.setTransientPermission(node); - } - ); + // unset the inverse, to allow false -> true, true -> false overrides. + // unset the inverse, to allow false -> true, true -> false overrides. + switch (this.type) { + case NORMAL: + // unset the inverse, to allow false -> true, true -> false overrides. + this.holder.unsetPermission(DataType.NORMAL, node); + this.holder.setPermission(DataType.NORMAL, node, true); + break; + case TRANSIENT: + // unset the inverse, to allow false -> true, true -> false overrides. + this.holder.unsetPermission(DataType.TRANSIENT, node); + this.holder.setPermission(DataType.TRANSIENT, node, true); + break; + default: + throw new AssertionError(); + } return save(this.holder).thenApply(v -> true); } @Override public CompletableFuture clearPermissions() { - boolean ret = this.type.supply( - this.holder::clearEnduringNodes, - this.holder::clearTransientNodes - ); + boolean ret; + switch (this.type) { + case NORMAL: + ret = this.holder.clearNodes(DataType.NORMAL, null); + break; + case TRANSIENT: + ret = this.holder.clearNodes(DataType.TRANSIENT, null); + break; + default: + throw new AssertionError(); + } if (!ret) { return CompletableFuture.completedFuture(false); @@ -173,17 +190,22 @@ public class PermissionHolderSubjectData implements LPSubjectData { @Override public CompletableFuture clearPermissions(ImmutableContextSet contexts) { Objects.requireNonNull(contexts, "contexts"); - boolean ret = this.type.supply( - () -> this.holder.clearEnduringNodes(contexts), - () -> { - List toRemove = streamNodes() - .filter(n -> n.getContexts().equals(contexts)) - .collect(Collectors.toList()); + boolean ret; + switch (this.type) { + case NORMAL: + ret = this.holder.clearNodes(DataType.NORMAL, contexts); + break; + case TRANSIENT: + List toRemove = streamNodes() + .filter(n -> n.getContexts().equals(contexts)) + .collect(Collectors.toList()); - toRemove.forEach(this.holder::unsetTransientPermission); - return !toRemove.isEmpty(); - } - ); + toRemove.forEach(node -> this.holder.unsetPermission(DataType.TRANSIENT, node)); + ret = !toRemove.isEmpty(); + break; + default: + throw new AssertionError(); + } if (!ret) { return CompletableFuture.completedFuture(false); @@ -235,10 +257,17 @@ public class PermissionHolderSubjectData implements LPSubjectData { .withContext(contexts) .build(); - DataMutateResult result = this.type.supply( - () -> this.holder.setPermission(node), - () -> this.holder.setTransientPermission(node) - ); + DataMutateResult result; + switch (this.type) { + case NORMAL: + result = this.holder.setPermission(DataType.NORMAL, node, true); + break; + case TRANSIENT: + result = this.holder.setPermission(DataType.TRANSIENT, node, true); + break; + default: + throw new AssertionError(); + } if (!result.wasSuccessful()) { return CompletableFuture.completedFuture(false); @@ -260,10 +289,17 @@ public class PermissionHolderSubjectData implements LPSubjectData { .withContext(contexts) .build(); - DataMutateResult result = this.type.supply( - () -> this.holder.unsetPermission(node), - () -> this.holder.unsetTransientPermission(node) - ); + DataMutateResult result; + switch (this.type) { + case NORMAL: + result = this.holder.unsetPermission(DataType.NORMAL, node); + break; + case TRANSIENT: + result = this.holder.unsetPermission(DataType.TRANSIENT, node); + break; + default: + throw new AssertionError(); + } if (!result.wasSuccessful()) { return CompletableFuture.completedFuture(false); @@ -274,17 +310,22 @@ public class PermissionHolderSubjectData implements LPSubjectData { @Override public CompletableFuture clearParents() { - boolean ret = this.type.supply( - () -> this.holder.clearEnduringParents(true), - () -> { - List toRemove = streamNodes() - .filter(n -> n instanceof InheritanceNode) - .collect(Collectors.toList()); + boolean ret; + switch (this.type) { + case NORMAL: + ret = this.holder.clearNormalParents(null, true); + break; + case TRANSIENT: + List toRemove = streamNodes() + .filter(n -> n instanceof InheritanceNode) + .collect(Collectors.toList()); - toRemove.forEach(this.holder::unsetTransientPermission); - return !toRemove.isEmpty(); - } - ); + toRemove.forEach(node -> this.holder.unsetPermission(DataType.TRANSIENT, node)); + ret = !toRemove.isEmpty(); + break; + default: + throw new AssertionError(); + } if (!ret) { return CompletableFuture.completedFuture(false); @@ -296,18 +337,23 @@ public class PermissionHolderSubjectData implements LPSubjectData { @Override public CompletableFuture clearParents(ImmutableContextSet contexts) { Objects.requireNonNull(contexts, "contexts"); - boolean ret = this.type.supply( - () -> this.holder.clearEnduringParents(contexts, true), - () -> { - List toRemove = streamNodes() - .filter(n -> n instanceof InheritanceNode) - .filter(n -> n.getContexts().equals(contexts)) - .collect(Collectors.toList()); + boolean ret; + switch (this.type) { + case NORMAL: + ret = this.holder.clearNormalParents(contexts, true); + break; + case TRANSIENT: + List toRemove = streamNodes() + .filter(n -> n instanceof InheritanceNode) + .filter(n -> n.getContexts().equals(contexts)) + .collect(Collectors.toList()); - toRemove.forEach(this.holder::unsetTransientPermission); - return !toRemove.isEmpty(); - } - ); + toRemove.forEach(node -> this.holder.unsetPermission(DataType.TRANSIENT, node)); + ret = !toRemove.isEmpty(); + break; + default: + throw new AssertionError(); + } if (!ret) { return CompletableFuture.completedFuture(false); @@ -380,11 +426,19 @@ public class PermissionHolderSubjectData implements LPSubjectData { // remove all prefixes/suffixes from the user streamNodes() .filter(node1 -> type.nodeType().matches(node1)) - .filter(n -> ((Node) n).getContexts().equals(contexts)) - .forEach(n -> this.type.run( - () -> this.holder.unsetPermission(n), - () -> this.holder.unsetTransientPermission(n) - )); + .filter(n -> n.getContexts().equals(contexts)) + .forEach(n -> { + switch (this.type) { + case NORMAL: + this.holder.unsetPermission(DataType.NORMAL, n); + break; + case TRANSIENT: + this.holder.unsetPermission(DataType.TRANSIENT, n); + break; + default: + throw new AssertionError(); + } + }); MetaAccumulator metaAccumulator = this.holder.accumulateMeta(null, QueryOptions.defaultContextualOptions().toBuilder().context(contexts).build()); metaAccumulator.complete(); @@ -397,18 +451,32 @@ public class PermissionHolderSubjectData implements LPSubjectData { streamNodes() .filter(n -> n instanceof MetaNode && ((MetaNode) n).getMetaKey().equals(key)) .filter(n -> n.getContexts().equals(contexts)) - .forEach(n -> this.type.run( - () -> this.holder.unsetPermission(n), - () -> this.holder.unsetTransientPermission(n) - )); + .forEach(n -> { + switch (this.type) { + case NORMAL: + this.holder.unsetPermission(DataType.NORMAL, n); + break; + case TRANSIENT: + this.holder.unsetPermission(DataType.TRANSIENT, n); + break; + default: + throw new AssertionError(); + } + }); node = NodeFactory.buildMetaNode(key, value).withContext(contexts).build(); } - this.type.run( - () -> this.holder.setPermission(node), - () -> this.holder.setTransientPermission(node) - ); + switch (this.type) { + case NORMAL: + this.holder.setPermission(DataType.NORMAL, node, true); + break; + case TRANSIENT: + this.holder.setPermission(DataType.TRANSIENT, node, true); + break; + default: + throw new AssertionError(); + } return save(this.holder).thenApply(v -> true); } @@ -428,10 +496,18 @@ public class PermissionHolderSubjectData implements LPSubjectData { } }) .filter(n -> n.getContexts().equals(contexts)) - .forEach(node -> this.type.run( - () -> this.holder.unsetPermission(node), - () -> this.holder.unsetTransientPermission(node) - )); + .forEach(node -> { + switch (this.type) { + case NORMAL: + this.holder.unsetPermission(DataType.NORMAL, node); + break; + case TRANSIENT: + this.holder.unsetPermission(DataType.TRANSIENT, node); + break; + default: + throw new AssertionError(); + } + }); return save(this.holder).thenApply(v -> true); } @@ -445,10 +521,18 @@ public class PermissionHolderSubjectData implements LPSubjectData { .filter(n -> n.getContexts().equals(contexts)) .collect(Collectors.toList()); - toRemove.forEach(node -> this.type.run( - () -> this.holder.unsetPermission(node), - () -> this.holder.unsetTransientPermission(node) - )); + toRemove.forEach(node -> { + switch (this.type) { + case NORMAL: + this.holder.unsetPermission(DataType.NORMAL, node); + break; + case TRANSIENT: + this.holder.unsetPermission(DataType.TRANSIENT, node); + break; + default: + throw new AssertionError(); + } + }); if (toRemove.isEmpty()) { return CompletableFuture.completedFuture(false); @@ -463,10 +547,18 @@ public class PermissionHolderSubjectData implements LPSubjectData { .filter(NodeType.META_OR_CHAT_META::matches) .collect(Collectors.toList()); - toRemove.forEach(node -> this.type.run( - () -> this.holder.unsetPermission(node), - () -> this.holder.unsetTransientPermission(node) - )); + toRemove.forEach(node -> { + switch (this.type) { + case NORMAL: + this.holder.unsetPermission(DataType.NORMAL, node); + break; + case TRANSIENT: + this.holder.unsetPermission(DataType.TRANSIENT, node); + break; + default: + throw new AssertionError(); + } + }); if (toRemove.isEmpty()) { return CompletableFuture.completedFuture(false); @@ -483,7 +575,7 @@ public class PermissionHolderSubjectData implements LPSubjectData { } // no further action required for transient types - if (this.type == NodeMapType.TRANSIENT) { + if (this.type == DataType.TRANSIENT) { return CompletableFuture.completedFuture(null); } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/persisted/PersistedSubject.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/persisted/PersistedSubject.java index 771690fd0..fda48b7fa 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/persisted/PersistedSubject.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/persisted/PersistedSubject.java @@ -25,8 +25,8 @@ package me.lucko.luckperms.sponge.service.model.persisted; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.common.cache.BufferedRequest; -import me.lucko.luckperms.common.model.NodeMapType; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.sponge.service.LuckPermsService; import me.lucko.luckperms.sponge.service.ProxyFactory; @@ -81,7 +81,7 @@ public class PersistedSubject extends CalculatedSubject implements LPSubject { this.parentCollection = parentCollection; this.identifier = identifier; - this.subjectData = new PersistedSubjectData(this, NodeMapType.ENDURING, service) { + this.subjectData = new PersistedSubjectData(this, DataType.NORMAL, service) { @Override protected void onUpdate(boolean success) { super.onUpdate(success); @@ -90,7 +90,7 @@ public class PersistedSubject extends CalculatedSubject implements LPSubject { } } }; - this.transientSubjectData = new MonitoredSubjectData(this, NodeMapType.TRANSIENT, service) { + this.transientSubjectData = new MonitoredSubjectData(this, DataType.TRANSIENT, service) { @Override protected void onUpdate(boolean success) { if (success) { diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/persisted/PersistedSubjectData.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/persisted/PersistedSubjectData.java index bea2fe24e..9d94decc7 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/persisted/PersistedSubjectData.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/persisted/PersistedSubjectData.java @@ -25,7 +25,7 @@ package me.lucko.luckperms.sponge.service.model.persisted; -import me.lucko.luckperms.common.model.NodeMapType; +import me.lucko.luckperms.api.model.DataType; import me.lucko.luckperms.sponge.service.LuckPermsService; import me.lucko.luckperms.sponge.service.model.calculated.MonitoredSubjectData; @@ -36,7 +36,7 @@ public class PersistedSubjectData extends MonitoredSubjectData { private final PersistedSubject subject; private boolean save = true; - public PersistedSubjectData(PersistedSubject subject, NodeMapType type, LuckPermsService service) { + public PersistedSubjectData(PersistedSubject subject, DataType type, LuckPermsService service) { super(subject, type, service); this.subject = subject; }