mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-28 05:35:26 +01:00
Enforce that ContextSets use the HashMultimap variant - closes #208
This commit is contained in:
parent
f1a9c3722c
commit
bdff84885a
@ -23,9 +23,10 @@
|
|||||||
package me.lucko.luckperms.api.context;
|
package me.lucko.luckperms.api.context;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.ImmutableMultimap;
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.common.collect.ImmutableSetMultimap;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
|
import com.google.common.collect.SetMultimap;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -37,7 +38,7 @@ import java.util.Set;
|
|||||||
* @since 2.16
|
* @since 2.16
|
||||||
*/
|
*/
|
||||||
public final class ImmutableContextSet implements ContextSet {
|
public final class ImmutableContextSet implements ContextSet {
|
||||||
private static final ImmutableContextSet EMPTY = new ImmutableContextSet(ImmutableMultimap.of());
|
private static final ImmutableContextSet EMPTY = new ImmutableContextSet(ImmutableSetMultimap.of());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a singleton ImmutableContextSet from a context pair
|
* Make a singleton ImmutableContextSet from a context pair
|
||||||
@ -55,7 +56,7 @@ public final class ImmutableContextSet implements ContextSet {
|
|||||||
throw new NullPointerException("value");
|
throw new NullPointerException("value");
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ImmutableContextSet(ImmutableMultimap.of(key.toLowerCase(), value));
|
return new ImmutableContextSet(ImmutableSetMultimap.of(key.toLowerCase(), value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -70,7 +71,7 @@ public final class ImmutableContextSet implements ContextSet {
|
|||||||
throw new NullPointerException("map");
|
throw new NullPointerException("map");
|
||||||
}
|
}
|
||||||
|
|
||||||
ImmutableMultimap.Builder<String, String> b = ImmutableMultimap.builder();
|
ImmutableSetMultimap.Builder<String, String> b = ImmutableSetMultimap.builder();
|
||||||
for (Map.Entry<String, String> e : map.entrySet()) {
|
for (Map.Entry<String, String> e : map.entrySet()) {
|
||||||
b.put(e.getKey().toLowerCase(), e.getValue());
|
b.put(e.getKey().toLowerCase(), e.getValue());
|
||||||
}
|
}
|
||||||
@ -129,10 +130,10 @@ public final class ImmutableContextSet implements ContextSet {
|
|||||||
return EMPTY;
|
return EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Multimap<String, String> map;
|
private final SetMultimap<String, String> map;
|
||||||
|
|
||||||
ImmutableContextSet(Multimap<String, String> contexts) {
|
ImmutableContextSet(Multimap<String, String> contexts) {
|
||||||
this.map = ImmutableMultimap.copyOf(contexts);
|
this.map = ImmutableSetMultimap.copyOf(contexts);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -27,6 +27,7 @@ import com.google.common.collect.ImmutableMap;
|
|||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
import com.google.common.collect.Multimaps;
|
import com.google.common.collect.Multimaps;
|
||||||
|
import com.google.common.collect.SetMultimap;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -136,14 +137,14 @@ public final class MutableContextSet implements ContextSet {
|
|||||||
return new MutableContextSet();
|
return new MutableContextSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Multimap<String, String> map;
|
private final SetMultimap<String, String> map;
|
||||||
|
|
||||||
public MutableContextSet() {
|
public MutableContextSet() {
|
||||||
this.map = Multimaps.synchronizedMultimap(HashMultimap.create());
|
this.map = Multimaps.synchronizedSetMultimap(HashMultimap.create());
|
||||||
}
|
}
|
||||||
|
|
||||||
private MutableContextSet(Multimap<String, String> contexts) {
|
private MutableContextSet(Multimap<String, String> contexts) {
|
||||||
this.map = Multimaps.synchronizedMultimap(HashMultimap.create(contexts));
|
this.map = Multimaps.synchronizedSetMultimap(HashMultimap.create(contexts));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -27,8 +27,7 @@ import lombok.EqualsAndHashCode;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
|
||||||
import com.google.common.collect.HashMultimap;
|
import com.google.common.collect.ImmutableSetMultimap;
|
||||||
import com.google.common.collect.Multimap;
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
|
||||||
@ -54,18 +53,18 @@ public class NodeDataHolder {
|
|||||||
node.getServer().orElse("global"),
|
node.getServer().orElse("global"),
|
||||||
node.getWorld().orElse("global"),
|
node.getWorld().orElse("global"),
|
||||||
node.isTemporary() ? node.getExpiryUnixTime() : 0L,
|
node.isTemporary() ? node.getExpiryUnixTime() : 0L,
|
||||||
node.getContexts().toMultimap()
|
ImmutableSetMultimap.copyOf(node.getContexts().toMultimap())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static NodeDataHolder of(String permission, boolean value, String server, String world, long expiry, String contexts) {
|
public static NodeDataHolder of(String permission, boolean value, String server, String world, long expiry, String contexts) {
|
||||||
Map<String, Collection<String>> deserializedContexts = GSON.fromJson(contexts, CONTEXT_TYPE);
|
Map<String, Collection<String>> deserializedContexts = GSON.fromJson(contexts, CONTEXT_TYPE);
|
||||||
Multimap<String, String> map = HashMultimap.create();
|
ImmutableSetMultimap.Builder<String, String> map = ImmutableSetMultimap.builder();
|
||||||
for (Map.Entry<String, Collection<String>> e : deserializedContexts.entrySet()) {
|
for (Map.Entry<String, Collection<String>> e : deserializedContexts.entrySet()) {
|
||||||
map.putAll(e.getKey(), e.getValue());
|
map.putAll(e.getKey(), e.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
return new NodeDataHolder(permission, value, server, world, expiry, map);
|
return new NodeDataHolder(permission, value, server, world, expiry, map.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
private final String permission;
|
private final String permission;
|
||||||
@ -73,7 +72,7 @@ public class NodeDataHolder {
|
|||||||
private final String server;
|
private final String server;
|
||||||
private final String world;
|
private final String world;
|
||||||
private final long expiry;
|
private final long expiry;
|
||||||
private final Multimap<String, String> contexts;
|
private final ImmutableSetMultimap<String, String> contexts;
|
||||||
|
|
||||||
public String serialiseContext() {
|
public String serialiseContext() {
|
||||||
return GSON.toJson(getContexts().asMap());
|
return GSON.toJson(getContexts().asMap());
|
||||||
|
Loading…
Reference in New Issue
Block a user