From 2a3a48f2ae5f2a01458e390f6a9174d260d4f000 Mon Sep 17 00:00:00 2001 From: Paul Reilly Date: Fri, 7 Apr 2023 17:59:23 -0500 Subject: [PATCH] Fixing errors --- .../totalfreedommod/perms/GroupWrapper.java | 23 +++---------------- .../totalfreedommod/perms/TrackWrapper.java | 4 ++-- .../totalfreedommod/perms/UserWrapper.java | 20 ++++++++++++++-- .../totalfreedommod/rank/Hierarchy.java | 13 ++--------- 4 files changed, 25 insertions(+), 35 deletions(-) diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/perms/GroupWrapper.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/perms/GroupWrapper.java index 08079a4b..017b4755 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/perms/GroupWrapper.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/perms/GroupWrapper.java @@ -3,23 +3,20 @@ package me.totalfreedom.totalfreedommod.perms; import net.luckperms.api.model.group.Group; import net.luckperms.api.model.group.GroupManager; -import java.util.Set; import java.util.concurrent.CompletableFuture; public class GroupWrapper { private final GroupManager manager; - private final Set groupSet; public GroupWrapper(GroupManager manager) { this.manager = manager; - this.groupSet = manager.getLoadedGroups(); } public CompletableFuture getGroup(String name) { - if (!manager.isLoaded(name) || !groupSet.contains(manager.getGroup(name))) + if (!manager.isLoaded(name) || !manager.getLoadedGroups().contains(manager.getGroup(name))) { return manager.createAndLoadGroup(name); } @@ -27,22 +24,8 @@ public class GroupWrapper return CompletableFuture.supplyAsync(() -> manager.getGroup(name)); } - public CompletableFuture removeGroup(String name) + public void saveGroup(String name) { - return getGroup(name).thenAccept(a -> - { - manager.deleteGroup(a); - groupSet.remove(a); - }); - } - - public CompletableFuture addGroup(String name) - { - return getGroup(name).thenAccept(groupSet::add); - } - - public CompletableFuture saveGroup(String name) - { - return getGroup(name).thenAccept(manager::saveGroup); + getGroup(name).thenAccept(manager::saveGroup); } } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/perms/TrackWrapper.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/perms/TrackWrapper.java index d5421944..808c7943 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/perms/TrackWrapper.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/perms/TrackWrapper.java @@ -32,8 +32,8 @@ public class TrackWrapper return CompletableFuture.supplyAsync(() -> manager.getTrack(name)); } - public CompletableFuture saveTrack(String name) + public void saveTrack(String name) { - return getTrack(name).thenAccept(manager::saveTrack); + getTrack(name).thenAccept(manager::saveTrack); } } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/perms/UserWrapper.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/perms/UserWrapper.java index 2c1725e9..95579d34 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/perms/UserWrapper.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/perms/UserWrapper.java @@ -3,8 +3,10 @@ package me.totalfreedom.totalfreedommod.perms; import net.luckperms.api.cacheddata.CachedMetaData; import net.luckperms.api.cacheddata.CachedPermissionData; import net.luckperms.api.context.ImmutableContextSet; +import net.luckperms.api.model.group.Group; import net.luckperms.api.model.user.User; import net.luckperms.api.model.user.UserManager; +import net.luckperms.api.node.NodeType; import net.luckperms.api.platform.PlayerAdapter; import net.luckperms.api.query.QueryOptions; import org.bukkit.entity.Player; @@ -88,8 +90,22 @@ public class UserWrapper }).thenAccept(userDataSet::add); } - public CompletableFuture saveUser(User user) + public void addToGroup(User user, Group group) { + CompletableFuture.runAsync(() -> + manager.modifyUser(user.getUniqueId(), c -> + group.getNodes(NodeType.INHERITANCE).forEach(node -> + c.data().add(node)))); + } + + public void removeFromGroup(User user, Group group) { + CompletableFuture.runAsync(() -> + manager.modifyUser(user.getUniqueId(), c -> + group.getNodes(NodeType.INHERITANCE).forEach(node -> + c.data().remove(node)))); + } + + public void saveUser(User user) { - return CompletableFuture.runAsync(() -> manager.saveUser(user)); + CompletableFuture.runAsync(() -> manager.saveUser(user)); } } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/Hierarchy.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/Hierarchy.java index 997cb8c7..cfe51c68 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/Hierarchy.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/Hierarchy.java @@ -202,13 +202,7 @@ public class Hierarchy { userWrapper.getUserData(player).thenAccept(user -> { - for (InheritanceNode node : group.getLuckPermsGroup().getNodes(NodeType.INHERITANCE)) - { - user.getUser().data().add(node); - } - - user.getUser().getInheritedGroups(user.getQueryOptions()).add(group.getLuckPermsGroup()); - + userWrapper.addToGroup(user.getUser(), group.getLuckPermsGroup()); userWrapper.saveUser(user.getUser()); }).whenComplete((a, b) -> { @@ -235,10 +229,7 @@ public class Hierarchy return; } - for (InheritanceNode node : g.getNodes(NodeType.INHERITANCE)) - { - data.getUser().data().remove(node); - } + userWrapper.removeFromGroup(data.getUser(), g); }); } userWrapper.saveUser(data.getUser());