minor bugfixes

This commit is contained in:
ActualPlayer 2020-06-30 18:02:48 +02:00
parent e991610ba2
commit 45c26293e4
3 changed files with 30 additions and 17 deletions

View File

@ -25,7 +25,7 @@ public class FileHandler implements IRememberMeHandler {
public CompletableFuture<String> getLastServerName(UUID uuid) { public CompletableFuture<String> getLastServerName(UUID uuid) {
try { try {
File userFile = FileUtils.getOrCreate(rememberMe.getDataFolderPath().resolve("data"), uuid.toString() + ".yml"); File userFile = FileUtils.getOrCreate(rememberMe.getDataFolderPath().resolve("data"), uuid.toString() + ".yml");
UserServer userServer = YamlUtils.readFile(userFile, UserServer.class); UserServer userServer = YamlUtils.readFile(userFile, com.actualplayer.rememberme.models.UserServer.class);
if(userServer == null) return null; if(userServer == null) return null;

View File

@ -9,10 +9,12 @@ import net.luckperms.api.model.user.User;
import net.luckperms.api.model.user.UserManager; import net.luckperms.api.model.user.UserManager;
import net.luckperms.api.node.Node; import net.luckperms.api.node.Node;
import net.luckperms.api.node.NodeType; import net.luckperms.api.node.NodeType;
import net.luckperms.api.node.types.MetaNode;
import net.luckperms.api.query.QueryMode; import net.luckperms.api.query.QueryMode;
import net.luckperms.api.query.QueryOptions; import net.luckperms.api.query.QueryOptions;
import org.checkerframework.checker.nullness.Opt; import org.checkerframework.checker.nullness.Opt;
import java.util.Collection;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -28,14 +30,19 @@ public class LuckPermsHandler implements IRememberMeHandler {
@Override @Override
public CompletableFuture<String> getLastServerName(UUID uuid) { public CompletableFuture<String> getLastServerName(UUID uuid) {
UserManager userManager = api.getUserManager(); UserManager userManager = api.getUserManager();
CompletableFuture<User> userFuture = userManager.loadUser(uuid); return userManager.loadUser(uuid).thenApply(user -> {
return userFuture.thenApply(user -> {
if (user != null) { if (user != null) {
ContextManager cm = api.getContextManager(); MetaNode lastServerNode = user.getNodes().stream()
ImmutableContextSet context = cm.getContext(user).orElse(cm.getStaticContext()); .filter(NodeType.META::matches)
.map(NodeType.META::cast)
.filter(n -> n.getMetaKey().equals("last-server"))
.findFirst().orElse(null);
CachedMetaData metaData = user.getCachedData().getMetaData(QueryOptions.builder(QueryMode.CONTEXTUAL).context(context).build()); if (lastServerNode != null) {
return metaData.getMetaValue("last-server"); return lastServerNode.getMetaValue();
}
return null;
} }
return null; return null;
@ -44,15 +51,22 @@ public class LuckPermsHandler implements IRememberMeHandler {
@Override @Override
public void setLastServerName(UUID uuid, String serverName) { public void setLastServerName(UUID uuid, String serverName) {
User user = api.getUserManager().getUser(uuid); api.getUserManager().loadUser(uuid).thenAcceptAsync(user -> {
if (user != null) { if (user != null) {
// Remove last server // Find last server
user.getNodes().removeIf(n -> n.getType() == NodeType.META && n.getKey().contains("last-server")); MetaNode serverNode = user.getNodes().stream()
.filter(NodeType.META::matches)
.map(NodeType.META::cast)
.filter(n -> n.getMetaKey().equals("last-server"))
.findFirst().orElse(MetaNode.builder("last-server", serverName).build());
// Add current server as last server user.data().remove(serverNode);
Node node = api.getNodeBuilderRegistry().forMeta().key("last-server").value(serverName).build(); serverNode = serverNode.toBuilder().value(serverName).build();
user.getNodes().add(node); user.data().add(serverNode);
// Save changes
api.getUserManager().saveUser(user); api.getUserManager().saveUser(user);
} }
});
} }
} }

View File

@ -1,6 +1,5 @@
package com.actualplayer.rememberme.models; package com.actualplayer.rememberme.models;
import lombok.Data; import lombok.Data;
@Data @Data