mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-24 03:25:19 +01:00
Permission holder refactoring
This commit is contained in:
parent
3474c66c1c
commit
5b97d01363
@ -40,7 +40,7 @@ public interface NodeAddEvent extends NodeMutateEvent {
|
||||
*
|
||||
* @return the node that was added
|
||||
*/
|
||||
@Param(3)
|
||||
@Param(4)
|
||||
@NonNull Node getNode();
|
||||
|
||||
}
|
||||
|
@ -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<Node> getDataBefore();
|
||||
|
||||
/**
|
||||
@ -62,7 +71,7 @@ public interface NodeMutateEvent extends LuckPermsEvent {
|
||||
*
|
||||
* @return the data after the change
|
||||
*/
|
||||
@Param(2)
|
||||
@Param(3)
|
||||
@NonNull Set<Node> getDataAfter();
|
||||
|
||||
/**
|
||||
|
@ -40,7 +40,7 @@ public interface NodeRemoveEvent extends NodeMutateEvent {
|
||||
*
|
||||
* @return the node that was removed
|
||||
*/
|
||||
@Param(3)
|
||||
@Param(4)
|
||||
@NonNull Node getNode();
|
||||
|
||||
}
|
||||
|
@ -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> T supply(Supplier<T> enduringSupplier, Supplier<T> transientSupplier) {
|
||||
return enduringSupplier.get();
|
||||
}
|
||||
},
|
||||
TRANSIENT {
|
||||
@Override
|
||||
public void run(Runnable enduringTask, Runnable transientTask) {
|
||||
transientTask.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T supply(Supplier<T> enduringSupplier, Supplier<T> transientSupplier) {
|
||||
return transientSupplier.get();
|
||||
}
|
||||
};
|
||||
|
||||
// useful methods for fluent/conditional execution
|
||||
|
||||
public abstract void run(Runnable enduringTask, Runnable transientTask);
|
||||
|
||||
public abstract <T> T supply(Supplier<T> enduringSupplier, Supplier<T> transientSupplier);
|
||||
/**
|
||||
* Normal data.
|
||||
*/
|
||||
NORMAL,
|
||||
|
||||
/**
|
||||
* Data which expires automatically at the end of a session.
|
||||
* (when a user logs off)
|
||||
*
|
||||
* <p>This data is never saved to the backend storage provider.</p>
|
||||
*/
|
||||
TRANSIENT
|
||||
|
||||
}
|
@ -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)
|
||||
*
|
||||
* <p>This data is never saved to the backend storage provider.</p>
|
||||
*/
|
||||
TRANSIENT
|
||||
}
|
||||
|
||||
interface Data {
|
||||
|
||||
/**
|
||||
|
@ -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<Node> equalTo(Node node) {
|
||||
return other -> areEqual(node, other);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Some 'default' implementations of NodeEqualityPredicate are provided below.
|
||||
|
@ -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) <luck@lucko.me>
|
||||
* Copyright (c) contributors
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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<Object> {
|
||||
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<String, Boolean> child : p.getChildren().entrySet()) {
|
||||
@ -194,7 +195,7 @@ public class MigrationBPermissions extends SubCommand<Object> {
|
||||
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<Object> {
|
||||
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<Object> {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<Object> {
|
||||
|
||||
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<Object> {
|
||||
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<Object> {
|
||||
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);
|
||||
|
@ -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<Object> {
|
||||
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<Object> {
|
||||
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<Object> {
|
||||
if (data.isList("groups")) {
|
||||
List<String> 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<String> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<Object> {
|
||||
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<Object> {
|
||||
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<Object> {
|
||||
}
|
||||
}
|
||||
|
||||
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<Object> {
|
||||
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<Object> {
|
||||
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<Object> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<Object> {
|
||||
}
|
||||
|
||||
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<Object> {
|
||||
}
|
||||
|
||||
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<Object> {
|
||||
}
|
||||
|
||||
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<Object> {
|
||||
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<Object> {
|
||||
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<Object> {
|
||||
nb.withContext(DefaultContextKeys.SERVER_KEY, server);
|
||||
}
|
||||
|
||||
holder.setPermission(nb.build());
|
||||
holder.setPermission(DataType.NORMAL, nb.build(), true);
|
||||
}
|
||||
|
||||
private static <T> T joinFuture(Future<T> future) {
|
||||
|
@ -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<Object> {
|
||||
// migrate groups
|
||||
Set<Node> 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<Object> {
|
||||
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<Object> {
|
||||
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<Object> {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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<Object> {
|
||||
// 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<String, Server> 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<String, World> 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<Object> {
|
||||
// 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<Object> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<Node> getNodes() {
|
||||
return this.handle.getOwnNodes();
|
||||
return this.handle.getOwnNodes(QueryOptions.nonContextual());
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull SortedSet<Node> 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<ImmutableContextSet, Collection<Node>> getNodes() {
|
||||
return ApiPermissionHolder.this.handle.enduringData().immutable().asMap();
|
||||
return ApiPermissionHolder.this.handle.getData(this.dataType).immutable().asMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Set<Node> 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<? super Node> 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<ImmutableContextSet, Collection<Node>> getNodes() {
|
||||
return ApiPermissionHolder.this.handle.transientData().immutable().asMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Set<Node> 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<? super Node> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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<? extends Group> 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);
|
||||
|
@ -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(
|
||||
|
@ -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();
|
||||
|
@ -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 {
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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(
|
||||
|
@ -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(
|
||||
|
@ -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(
|
||||
|
@ -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();
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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<T extends PermissionHolder> extends SubCommand<T> {
|
||||
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<T extends PermissionHolder> extends SubCommand<T> {
|
||||
}
|
||||
|
||||
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 {
|
||||
|
@ -76,7 +76,7 @@ public class HolderShowTracks<T extends PermissionHolder> extends SubCommand<T>
|
||||
|
||||
if (holder.getType() == HolderType.USER) {
|
||||
// if the holder is a user, we want to query parent groups for tracks
|
||||
Set<InheritanceNode> nodes = holder.enduringData().immutable().values().stream()
|
||||
Set<InheritanceNode> nodes = holder.normalData().immutable().values().stream()
|
||||
.filter(NodeType.INHERITANCE::matches)
|
||||
.map(NodeType.INHERITANCE::cast)
|
||||
.filter(Node::getValue)
|
||||
|
@ -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));
|
||||
|
@ -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();
|
||||
|
@ -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 {
|
||||
|
@ -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);
|
||||
|
@ -78,7 +78,7 @@ public class ParentInfo extends SharedSubCommand {
|
||||
|
||||
// get the holders nodes
|
||||
List<InheritanceNode> 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());
|
||||
|
@ -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));
|
||||
|
||||
|
@ -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));
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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));
|
||||
|
||||
|
@ -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());
|
||||
|
@ -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));
|
||||
|
@ -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 {
|
||||
|
@ -77,7 +77,7 @@ public class PermissionInfo extends SharedSubCommand {
|
||||
SortMode sortMode = SortMode.determine(args);
|
||||
|
||||
// get the holders nodes
|
||||
List<Node> nodes = new ArrayList<>(holder.enduringData().asSortedSet());
|
||||
List<Node> 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()))
|
||||
|
@ -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));
|
||||
|
@ -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();
|
||||
|
@ -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));
|
||||
|
@ -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));
|
||||
|
@ -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<Group> {
|
||||
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());
|
||||
|
||||
|
@ -62,12 +62,12 @@ public class GroupInfo extends SubCommand<Group> {
|
||||
group.getWeight().isPresent() ? group.getWeight().getAsInt() : "None"
|
||||
);
|
||||
|
||||
List<InheritanceNode> parents = group.enduringData().inheritanceAsSortedSet().stream()
|
||||
List<InheritanceNode> parents = group.normalData().inheritanceAsSortedSet().stream()
|
||||
.filter(Node::getValue)
|
||||
.filter(n -> !n.hasExpiry())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<InheritanceNode> tempParents = group.enduringData().inheritanceAsSortedSet().stream()
|
||||
List<InheritanceNode> tempParents = group.normalData().inheritanceAsSortedSet().stream()
|
||||
.filter(Node::getValue)
|
||||
.filter(Node::hasExpiry)
|
||||
.collect(Collectors.toList());
|
||||
|
@ -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<Group> {
|
||||
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());
|
||||
|
||||
|
@ -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<Group> {
|
||||
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<Group> {
|
||||
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));
|
||||
|
||||
|
@ -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<Group> {
|
||||
|
||||
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());
|
||||
|
||||
|
@ -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<Log> {
|
||||
return false;
|
||||
}
|
||||
|
||||
Optional<? extends Node> ret = user.enduringData().immutable().get(ImmutableContextSet.empty()).stream()
|
||||
Optional<? extends Node> 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<Log> {
|
||||
|
||||
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();
|
||||
|
@ -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) {
|
||||
|
@ -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<NodeDataContainer> nodes = WebEditor.deserializePermissions(data.getAsJsonArray("nodes"));
|
||||
|
||||
Set<Node> before = new HashSet<>(holder.enduringData().immutable().values());
|
||||
Set<Node> before = new HashSet<>(holder.normalData().immutable().values());
|
||||
Set<Node> after = nodes.stream().map(NodeDataContainer::toNode).collect(Collectors.toSet());
|
||||
|
||||
Map.Entry<Set<Node>, Set<Node>> 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)
|
||||
|
@ -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()
|
||||
|
@ -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<User> {
|
||||
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());
|
||||
|
||||
|
@ -73,12 +73,12 @@ public class UserInfo extends SubCommand<User> {
|
||||
user.getPrimaryGroup().getValue()
|
||||
);
|
||||
|
||||
List<InheritanceNode> parents = user.enduringData().inheritanceAsSortedSet().stream()
|
||||
List<InheritanceNode> parents = user.normalData().inheritanceAsSortedSet().stream()
|
||||
.filter(Node::getValue)
|
||||
.filter(n -> !n.hasExpiry())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<InheritanceNode> tempParents = user.enduringData().inheritanceAsSortedSet().stream()
|
||||
List<InheritanceNode> tempParents = user.normalData().inheritanceAsSortedSet().stream()
|
||||
.filter(Node::getValue)
|
||||
.filter(Node::hasExpiry)
|
||||
.collect(Collectors.toList());
|
||||
|
@ -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<Node> checker = node -> holder.hasPermission(NodeMapType.ENDURING, node, NodeEqualityPredicate.IGNORE_VALUE_OR_IF_TEMPORARY) == tristate;
|
||||
Predicate<Node> 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("|", "||");
|
||||
|
@ -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) {
|
||||
|
@ -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<? extends Node> before, Collection<? extends Node> 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<? extends Node> before, Collection<? extends Node> after) {
|
||||
post(NodeAddEvent.class, () -> generate(NodeAddEvent.class, getDelegate(target), dataType, ImmutableSet.copyOf(before), ImmutableSet.copyOf(after), node));
|
||||
}
|
||||
|
||||
public void handleNodeClear(PermissionHolder target, Collection<? extends Node> before, Collection<? extends Node> after) {
|
||||
post(NodeClearEvent.class, () -> generate(NodeClearEvent.class, getDelegate(target), ImmutableSet.copyOf(before), ImmutableSet.copyOf(after)));
|
||||
public void handleNodeClear(PermissionHolder target, DataType dataType, Collection<? extends Node> before, Collection<? extends Node> after) {
|
||||
post(NodeClearEvent.class, () -> generate(NodeClearEvent.class, getDelegate(target), dataType, ImmutableSet.copyOf(before), ImmutableSet.copyOf(after)));
|
||||
}
|
||||
|
||||
public void handleNodeRemove(Node node, PermissionHolder target, Collection<? extends Node> before, Collection<? extends Node> 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<? extends Node> before, Collection<? extends Node> after) {
|
||||
post(NodeRemoveEvent.class, () -> generate(NodeRemoveEvent.class, getDelegate(target), dataType, ImmutableSet.copyOf(before), ImmutableSet.copyOf(after), node));
|
||||
}
|
||||
|
||||
public void handleConfigReload() {
|
||||
|
@ -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<String> {
|
||||
* @return the display name
|
||||
*/
|
||||
public Optional<String> 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());
|
||||
}
|
||||
|
@ -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 {
|
||||
*
|
||||
* <p>These (unlike transient nodes) are saved to the storage backing.</p>
|
||||
*
|
||||
* @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<? extends Node> set) {
|
||||
public void setNodes(DataType type, Set<? extends Node> set) {
|
||||
getData(type).setContent(set);
|
||||
invalidateCache();
|
||||
}
|
||||
|
||||
public void replaceNodes(NodeMapType type, Multimap<ImmutableContextSet, ? extends Node> multimap) {
|
||||
public void replaceNodes(DataType type, Multimap<ImmutableContextSet, ? extends Node> multimap) {
|
||||
getData(type).setContent(multimap);
|
||||
invalidateCache();
|
||||
}
|
||||
|
||||
public List<Node> getOwnNodes() {
|
||||
List<Node> ret = new ArrayList<>();
|
||||
this.transientNodes.copyTo(ret, QueryOptions.nonContextual());
|
||||
this.enduringNodes.copyTo(ret, QueryOptions.nonContextual());
|
||||
return ret;
|
||||
}
|
||||
|
||||
public List<Node> getOwnNodes(QueryOptions queryOptions) {
|
||||
List<Node> ret = new ArrayList<>();
|
||||
this.transientNodes.copyTo(ret, queryOptions);
|
||||
this.enduringNodes.copyTo(ret, queryOptions);
|
||||
this.normalNodes.copyTo(ret, queryOptions);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public SortedSet<Node> getOwnNodesSorted(QueryOptions queryOptions) {
|
||||
SortedSet<Node> ret = new TreeSet<>(NodeWithContextComparator.reverse());
|
||||
this.transientNodes.copyTo(ret, queryOptions);
|
||||
this.normalNodes.copyTo(ret, queryOptions);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public List<InheritanceNode> getOwnGroupNodes(QueryOptions queryOptions) {
|
||||
List<InheritanceNode> ret = new ArrayList<>();
|
||||
this.transientNodes.copyInheritanceNodesTo(ret, queryOptions);
|
||||
this.enduringNodes.copyInheritanceNodesTo(ret, queryOptions);
|
||||
this.normalNodes.copyInheritanceNodesTo(ret, queryOptions);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public SortedSet<Node> getOwnNodesSorted() {
|
||||
SortedSet<Node> ret = new TreeSet<>(NodeWithContextComparator.reverse());
|
||||
this.transientNodes.copyTo(ret, QueryOptions.nonContextual());
|
||||
this.enduringNodes.copyTo(ret, QueryOptions.nonContextual());
|
||||
return ret;
|
||||
}
|
||||
|
||||
public boolean removeIfEnduring(Predicate<? super Node> predicate) {
|
||||
return removeIfEnduring(predicate, null);
|
||||
}
|
||||
|
||||
public boolean removeIfEnduring(Predicate<? super Node> predicate, Runnable taskIfSuccess) {
|
||||
ImmutableCollection<? extends Node> before = enduringData().immutable().values();
|
||||
if (!this.enduringNodes.removeIf(predicate)) {
|
||||
return false;
|
||||
}
|
||||
if (taskIfSuccess != null) {
|
||||
taskIfSuccess.run();
|
||||
}
|
||||
invalidateCache();
|
||||
ImmutableCollection<? extends Node> after = enduringData().immutable().values();
|
||||
|
||||
this.plugin.getEventFactory().handleNodeClear(this, before, after);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean removeIfEnduring(ContextSet contextSet, Predicate<? super Node> predicate) {
|
||||
return removeIfEnduring(contextSet, predicate, null);
|
||||
}
|
||||
|
||||
public boolean removeIfEnduring(ContextSet contextSet, Predicate<? super Node> predicate, Runnable taskIfSuccess) {
|
||||
ImmutableCollection<? extends Node> before = enduringData().immutable().values();
|
||||
if (!this.enduringNodes.removeIf(contextSet, predicate)) {
|
||||
return false;
|
||||
}
|
||||
if (taskIfSuccess != null) {
|
||||
taskIfSuccess.run();
|
||||
}
|
||||
invalidateCache();
|
||||
ImmutableCollection<? extends Node> after = enduringData().immutable().values();
|
||||
|
||||
this.plugin.getEventFactory().handleNodeClear(this, before, after);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean removeIfTransient(Predicate<? super Node> predicate) {
|
||||
boolean result = this.transientNodes.removeIf(predicate);
|
||||
if (result) {
|
||||
invalidateCache();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean removeIfTransient(ContextSet contextSet, Predicate<? super Node> predicate) {
|
||||
boolean result = this.transientNodes.removeIf(contextSet, predicate);
|
||||
if (result) {
|
||||
invalidateCache();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void accumulateInheritancesTo(List<? super Node> accumulator, QueryOptions queryOptions) {
|
||||
InheritanceGraph graph = this.plugin.getInheritanceHandler().getGraph(queryOptions);
|
||||
Iterable<PermissionHolder> 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<? extends Node> before = enduringData().immutable().values();
|
||||
return transientWork || normalWork;
|
||||
}
|
||||
|
||||
private boolean auditTemporaryPermissions(DataType dataType) {
|
||||
ImmutableCollection<? extends Node> before = getData(dataType).immutable().values();
|
||||
Set<Node> removed = new HashSet<>();
|
||||
|
||||
boolean enduringWork = this.enduringNodes.auditTemporaryNodes(removed);
|
||||
if (enduringWork) {
|
||||
boolean work = getData(dataType).auditTemporaryNodes(removed);
|
||||
if (work) {
|
||||
// invalidate
|
||||
invalidateCache();
|
||||
|
||||
// call event
|
||||
ImmutableCollection<? extends Node> after = enduringData().immutable().values();
|
||||
ImmutableCollection<? extends Node> 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<Node> 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<? extends Node> before = enduringData().immutable().values();
|
||||
this.enduringNodes.add(node);
|
||||
invalidateCache();
|
||||
ImmutableCollection<? extends Node> after = enduringData().immutable().values();
|
||||
NodeMap data = getData(dataType);
|
||||
|
||||
ImmutableCollection<? extends Node> before = data.immutable().values();
|
||||
|
||||
data.add(node);
|
||||
invalidateCache();
|
||||
|
||||
ImmutableCollection<? extends Node> 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<? extends Node> before = data.immutable().values();
|
||||
|
||||
data.replace(newNode, otherMatch);
|
||||
invalidateCache();
|
||||
|
||||
ImmutableCollection<? extends Node> 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<? extends Node> before = null;
|
||||
if (callEvents) {
|
||||
before = data.immutable().values();
|
||||
}
|
||||
|
||||
data.replace(newNode, previous);
|
||||
invalidateCache();
|
||||
|
||||
if (callEvents) {
|
||||
ImmutableCollection<? extends Node> 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<? extends Node> before = null;
|
||||
if (callEvents) {
|
||||
before = data.immutable().values();
|
||||
}
|
||||
|
||||
data.replace(node, previous);
|
||||
invalidateCache();
|
||||
|
||||
if (callEvents) {
|
||||
ImmutableCollection<? extends Node> 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<? extends Node> before = enduringData().immutable().values();
|
||||
this.enduringNodes.remove(node);
|
||||
invalidateCache();
|
||||
ImmutableCollection<? extends Node> after = enduringData().immutable().values();
|
||||
ImmutableCollection<? extends Node> before = getData(dataType).immutable().values();
|
||||
|
||||
getData(dataType).remove(node);
|
||||
invalidateCache();
|
||||
|
||||
ImmutableCollection<? extends Node> 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<? super Node> predicate, @Nullable Runnable taskIfSuccess) {
|
||||
NodeMap data = getData(dataType);
|
||||
ImmutableCollection<? extends Node> 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<? extends Node> 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<? extends Node> before = enduringData().immutable().values();
|
||||
this.enduringNodes.clear();
|
||||
public boolean clearNodes(DataType dataType, ContextSet contextSet) {
|
||||
NodeMap data = getData(dataType);
|
||||
ImmutableCollection<? extends Node> before = data.immutable().values();
|
||||
|
||||
if (contextSet == null) {
|
||||
data.clear();
|
||||
} else {
|
||||
data.clear(contextSet);
|
||||
}
|
||||
|
||||
invalidateCache();
|
||||
ImmutableCollection<? extends Node> after = enduringData().immutable().values();
|
||||
|
||||
ImmutableCollection<? extends Node> 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<? extends Node> before = enduringData().immutable().values();
|
||||
this.enduringNodes.clear(contextSet);
|
||||
invalidateCache();
|
||||
ImmutableCollection<? extends Node> 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();
|
||||
}
|
||||
|
@ -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<String> {
|
||||
}
|
||||
|
||||
// find all groups that are inherited by the user in the exact contexts given and applicable to this track
|
||||
List<InheritanceNode> nodes = user.enduringData().immutable().get(context.immutableCopy()).stream()
|
||||
List<InheritanceNode> 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<String> {
|
||||
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<String> {
|
||||
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<String> {
|
||||
}
|
||||
|
||||
// find all groups that are inherited by the user in the exact contexts given and applicable to this track
|
||||
List<InheritanceNode> nodes = user.enduringData().immutable().get(context.immutableCopy()).stream()
|
||||
List<InheritanceNode> 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<String> {
|
||||
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<String> {
|
||||
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());
|
||||
|
@ -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<UserIdentifie
|
||||
/**
|
||||
* Clear all of the users permission nodes
|
||||
*/
|
||||
@Override
|
||||
public boolean clearEnduringNodes() {
|
||||
boolean ret = super.clearEnduringNodes();
|
||||
boolean ret = clearNodes(DataType.NORMAL, null);
|
||||
if (!ret) {
|
||||
return false;
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ package me.lucko.luckperms.common.model.manager.user;
|
||||
import com.google.common.collect.ImmutableCollection;
|
||||
|
||||
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.NodeType;
|
||||
import me.lucko.luckperms.api.node.types.InheritanceNode;
|
||||
@ -89,7 +90,7 @@ public abstract class AbstractUserManager<T extends User> 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<T extends User> 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<T extends User> 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<T extends User> 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<T extends User> extends AbstractManage
|
||||
*/
|
||||
@Override
|
||||
public boolean shouldSave(User user) {
|
||||
ImmutableCollection<Node> nodes = user.enduringData().immutable().values();
|
||||
ImmutableCollection<Node> nodes = user.normalData().immutable().values();
|
||||
if (nodes.size() != 1) {
|
||||
return true;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -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<Node> 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<NodeDataContainer> nodes = user.enduringData().immutable().values().stream().map(NodeDataContainer::fromNode).collect(Collectors.toCollection(LinkedHashSet::new));
|
||||
Set<NodeDataContainer> 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<Node> 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<NodeDataContainer> nodes = group.enduringData().immutable().values().stream().map(NodeDataContainer::fromNode).collect(Collectors.toCollection(LinkedHashSet::new));
|
||||
Set<NodeDataContainer> 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<NodeDataContainer> data = readNodes(object);
|
||||
Set<Node> 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<NodeDataContainer> nodes = group.enduringData().immutable().values().stream().map(NodeDataContainer::fromNode).collect(Collectors.toCollection(LinkedHashSet::new));
|
||||
Set<NodeDataContainer> nodes = group.normalData().immutable().values().stream().map(NodeDataContainer::fromNode).collect(Collectors.toCollection(LinkedHashSet::new));
|
||||
writeNodes(data, nodes);
|
||||
|
||||
saveFile(StorageLocation.GROUP, group.getName(), data);
|
||||
|
@ -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<Node> 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<Node> 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<Node> 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<Document> nodes = user.enduringData().immutable().values().stream()
|
||||
List<Document> 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<Document> nodes = group.enduringData().immutable().values().stream()
|
||||
List<Document> nodes = group.normalData().immutable().values().stream()
|
||||
.map(NodeDataContainer::fromNode)
|
||||
.map(MongoStorage::nodeToDoc)
|
||||
.collect(Collectors.toList());
|
||||
|
@ -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<Node> 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<NodeDataContainer> local = user.enduringData().immutable().values().stream().map(NodeDataContainer::fromNode).collect(Collectors.toSet());
|
||||
Set<NodeDataContainer> local = user.normalData().immutable().values().stream().map(NodeDataContainer::fromNode).collect(Collectors.toSet());
|
||||
|
||||
Map.Entry<Set<NodeDataContainer>, Set<NodeDataContainer>> diff = compareSets(local, remote);
|
||||
|
||||
@ -630,9 +630,9 @@ public class SqlStorage implements StorageImplementation {
|
||||
|
||||
if (!data.isEmpty()) {
|
||||
Set<Node> 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<NodeDataContainer> local = group.enduringData().immutable().values().stream().map(NodeDataContainer::fromNode).collect(Collectors.toSet());
|
||||
Set<NodeDataContainer> local = group.normalData().immutable().values().stream().map(NodeDataContainer::fromNode).collect(Collectors.toSet());
|
||||
|
||||
Map.Entry<Set<NodeDataContainer>, Set<NodeDataContainer>> diff = compareSets(local, remote);
|
||||
|
||||
|
@ -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<PermissionHolder> holders, Sender sender, String cmdLabel, LuckPermsPlugin plugin) {
|
||||
|
@ -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
|
||||
|
@ -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 */
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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<ImmutableContextSet, Map<String, Boolean>> permissions = new ConcurrentHashMap<>();
|
||||
private final Map<ImmutableContextSet, Set<LPSubjectReference>> parents = new ConcurrentHashMap<>();
|
||||
private final Map<ImmutableContextSet, Map<String, String>> 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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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<T extends PermissionHolder> 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() {
|
||||
|
@ -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<Boolean> 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<Boolean> clearPermissions(ImmutableContextSet contexts) {
|
||||
Objects.requireNonNull(contexts, "contexts");
|
||||
boolean ret = this.type.supply(
|
||||
() -> this.holder.clearEnduringNodes(contexts),
|
||||
() -> {
|
||||
List<Node> 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<Node> 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<Boolean> clearParents() {
|
||||
boolean ret = this.type.supply(
|
||||
() -> this.holder.clearEnduringParents(true),
|
||||
() -> {
|
||||
List<Node> 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<Node> 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<Boolean> clearParents(ImmutableContextSet contexts) {
|
||||
Objects.requireNonNull(contexts, "contexts");
|
||||
boolean ret = this.type.supply(
|
||||
() -> this.holder.clearEnduringParents(contexts, true),
|
||||
() -> {
|
||||
List<Node> 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<Node> 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);
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user