Some small fixes for new SQL backing

This commit is contained in:
Luck 2016-12-27 13:03:59 +00:00
parent f8a77cf809
commit 4660e68abf
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
5 changed files with 32 additions and 17 deletions

View File

@ -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;
}

View File

@ -92,7 +92,7 @@ public class RedisMessaging implements MessagingService {
private final LuckPermsPlugin plugin;
private final Set<UUID> receivedMsgs = Collections.synchronizedSet(new HashSet<>());
UUID generateId() {
private UUID generateId() {
UUID uuid = UUID.randomUUID();
receivedMsgs.add(uuid);
return uuid;

View File

@ -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;

View File

@ -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");
}

View File

@ -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<Map<String, Collection<String>>>(){}.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<Map<String, String>>(){}.getType();
Map<String, String> 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<String, Collection<String>> deserializedContexts = GSON.fromJson(contexts, CONTEXT_TYPE);
if (deserializedContexts != null && !deserializedContexts.isEmpty()) {
for (Map.Entry<String, Collection<String>> c : deserializedContexts.entrySet()) {
for (String val : c.getValue()) {
builder.withExtraContext(c.getKey(), val);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return builder.build();
}