diff --git a/common/src/main/java/me/lucko/luckperms/common/core/model/ImmutableNode.java b/common/src/main/java/me/lucko/luckperms/common/core/model/ImmutableNode.java index 0a79517f..836d0539 100644 --- a/common/src/main/java/me/lucko/luckperms/common/core/model/ImmutableNode.java +++ b/common/src/main/java/me/lucko/luckperms/common/core/model/ImmutableNode.java @@ -164,7 +164,7 @@ public class ImmutableNode implements Node { server = null; } - if (world != null && world.equals("")) { + if (world != null && (world.equalsIgnoreCase("global") || world.equals(""))) { world = null; } diff --git a/common/src/main/java/me/lucko/luckperms/common/messaging/RedisMessaging.java b/common/src/main/java/me/lucko/luckperms/common/messaging/RedisMessaging.java index 46867338..29f0d073 100644 --- a/common/src/main/java/me/lucko/luckperms/common/messaging/RedisMessaging.java +++ b/common/src/main/java/me/lucko/luckperms/common/messaging/RedisMessaging.java @@ -92,7 +92,7 @@ public class RedisMessaging implements MessagingService { private final LuckPermsPlugin plugin; private final Set receivedMsgs = Collections.synchronizedSet(new HashSet<>()); - UUID generateId() { + private UUID generateId() { UUID uuid = UUID.randomUUID(); receivedMsgs.add(uuid); return uuid; diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/StorageFactory.java b/common/src/main/java/me/lucko/luckperms/common/storage/StorageFactory.java index f70b8002..32979dcb 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/StorageFactory.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/StorageFactory.java @@ -27,7 +27,11 @@ import lombok.experimental.UtilityClass; import com.google.common.collect.ImmutableSet; import me.lucko.luckperms.common.LuckPermsPlugin; -import me.lucko.luckperms.common.storage.backing.*; +import me.lucko.luckperms.common.storage.backing.AbstractBacking; +import me.lucko.luckperms.common.storage.backing.JSONBacking; +import me.lucko.luckperms.common.storage.backing.MongoDBBacking; +import me.lucko.luckperms.common.storage.backing.SQLLegacyBacking; +import me.lucko.luckperms.common.storage.backing.YAMLBacking; import me.lucko.luckperms.common.storage.backing.sqlprovider.H2Provider; import me.lucko.luckperms.common.storage.backing.sqlprovider.MySQLProvider; import me.lucko.luckperms.common.storage.backing.sqlprovider.SQLiteProvider; diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/backing/sqlprovider/FlatfileProvider.java b/common/src/main/java/me/lucko/luckperms/common/storage/backing/sqlprovider/FlatfileProvider.java index 08f1720b..2b446c0d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/backing/sqlprovider/FlatfileProvider.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/backing/sqlprovider/FlatfileProvider.java @@ -77,7 +77,8 @@ abstract class FlatfileProvider extends SQLProvider { @Override public boolean runQuery(String query, QueryPS queryPS) { - try (Connection connection = getConnection()) { + try { + Connection connection = getConnection(); if (connection == null || connection.isClosed()) { throw new IllegalStateException("SQL connection is null"); } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/backing/utils/NodeDataHolder.java b/common/src/main/java/me/lucko/luckperms/common/storage/backing/utils/NodeDataHolder.java index 5b1d1a31..9cf9b712 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/backing/utils/NodeDataHolder.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/backing/utils/NodeDataHolder.java @@ -22,32 +22,35 @@ package me.lucko.luckperms.common.storage.backing.utils; -import com.google.gson.JsonParseException; -import com.google.gson.reflect.TypeToken; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.ToString; + import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; import me.lucko.luckperms.api.Node; import me.lucko.luckperms.common.core.NodeBuilder; import java.lang.reflect.Type; -import java.util.HashMap; +import java.util.Collection; import java.util.Map; @Getter @ToString @AllArgsConstructor(staticName = "of") public class NodeDataHolder { + private static final Gson GSON = new Gson(); + private static final Type CONTEXT_TYPE = new TypeToken>>(){}.getType(); + public static NodeDataHolder fromNode(Node node) { return NodeDataHolder.of( node.getPermission(), node.getValue(), - node.getServer().orElse(null), - node.getWorld().orElse(null), + node.getServer().orElse("global"), + node.getWorld().orElse("global"), node.isTemporary() ? node.getExpiryUnixTime() : 0L, - new Gson().toJson(node.getContexts().toMap()) + GSON.toJson(node.getContexts().toMultimap().asMap()) ); } @@ -59,18 +62,25 @@ public class NodeDataHolder { private final String contexts; public Node toNode() { - Type type = new TypeToken>(){}.getType(); - Map parsedContexts = new Gson().fromJson(contexts, type); - if (parsedContexts == null) { - parsedContexts = new HashMap<>(); - } - NodeBuilder builder = new NodeBuilder(permission); builder.setValue(value); builder.setServer(server); builder.setWorld(world); builder.setExpiry(expiry); - builder.withExtraContext(parsedContexts); + + try { + Map> deserializedContexts = GSON.fromJson(contexts, CONTEXT_TYPE); + if (deserializedContexts != null && !deserializedContexts.isEmpty()) { + for (Map.Entry> c : deserializedContexts.entrySet()) { + for (String val : c.getValue()) { + builder.withExtraContext(c.getKey(), val); + } + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return builder.build(); }