mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-28 13:45:20 +01:00
Some small fixes for new SQL backing
This commit is contained in:
parent
f8a77cf809
commit
4660e68abf
@ -164,7 +164,7 @@ public class ImmutableNode implements Node {
|
|||||||
server = null;
|
server = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (world != null && world.equals("")) {
|
if (world != null && (world.equalsIgnoreCase("global") || world.equals(""))) {
|
||||||
world = null;
|
world = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ public class RedisMessaging implements MessagingService {
|
|||||||
private final LuckPermsPlugin plugin;
|
private final LuckPermsPlugin plugin;
|
||||||
private final Set<UUID> receivedMsgs = Collections.synchronizedSet(new HashSet<>());
|
private final Set<UUID> receivedMsgs = Collections.synchronizedSet(new HashSet<>());
|
||||||
|
|
||||||
UUID generateId() {
|
private UUID generateId() {
|
||||||
UUID uuid = UUID.randomUUID();
|
UUID uuid = UUID.randomUUID();
|
||||||
receivedMsgs.add(uuid);
|
receivedMsgs.add(uuid);
|
||||||
return uuid;
|
return uuid;
|
||||||
|
@ -27,7 +27,11 @@ import lombok.experimental.UtilityClass;
|
|||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
import me.lucko.luckperms.common.LuckPermsPlugin;
|
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.H2Provider;
|
||||||
import me.lucko.luckperms.common.storage.backing.sqlprovider.MySQLProvider;
|
import me.lucko.luckperms.common.storage.backing.sqlprovider.MySQLProvider;
|
||||||
import me.lucko.luckperms.common.storage.backing.sqlprovider.SQLiteProvider;
|
import me.lucko.luckperms.common.storage.backing.sqlprovider.SQLiteProvider;
|
||||||
|
@ -77,7 +77,8 @@ abstract class FlatfileProvider extends SQLProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean runQuery(String query, QueryPS queryPS) {
|
public boolean runQuery(String query, QueryPS queryPS) {
|
||||||
try (Connection connection = getConnection()) {
|
try {
|
||||||
|
Connection connection = getConnection();
|
||||||
if (connection == null || connection.isClosed()) {
|
if (connection == null || connection.isClosed()) {
|
||||||
throw new IllegalStateException("SQL connection is null");
|
throw new IllegalStateException("SQL connection is null");
|
||||||
}
|
}
|
||||||
|
@ -22,32 +22,35 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.common.storage.backing.utils;
|
package me.lucko.luckperms.common.storage.backing.utils;
|
||||||
|
|
||||||
import com.google.gson.JsonParseException;
|
|
||||||
import com.google.gson.reflect.TypeToken;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.Node;
|
import me.lucko.luckperms.api.Node;
|
||||||
import me.lucko.luckperms.common.core.NodeBuilder;
|
import me.lucko.luckperms.common.core.NodeBuilder;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.HashMap;
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@ToString
|
@ToString
|
||||||
@AllArgsConstructor(staticName = "of")
|
@AllArgsConstructor(staticName = "of")
|
||||||
public class NodeDataHolder {
|
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) {
|
public static NodeDataHolder fromNode(Node node) {
|
||||||
return NodeDataHolder.of(
|
return NodeDataHolder.of(
|
||||||
node.getPermission(),
|
node.getPermission(),
|
||||||
node.getValue(),
|
node.getValue(),
|
||||||
node.getServer().orElse(null),
|
node.getServer().orElse("global"),
|
||||||
node.getWorld().orElse(null),
|
node.getWorld().orElse("global"),
|
||||||
node.isTemporary() ? node.getExpiryUnixTime() : 0L,
|
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;
|
private final String contexts;
|
||||||
|
|
||||||
public Node toNode() {
|
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);
|
NodeBuilder builder = new NodeBuilder(permission);
|
||||||
builder.setValue(value);
|
builder.setValue(value);
|
||||||
builder.setServer(server);
|
builder.setServer(server);
|
||||||
builder.setWorld(world);
|
builder.setWorld(world);
|
||||||
builder.setExpiry(expiry);
|
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();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user