diff --git a/api/src/main/java/me/lucko/luckperms/api/PermissionHolder.java b/api/src/main/java/me/lucko/luckperms/api/PermissionHolder.java index 83135db4a..23cadcec0 100644 --- a/api/src/main/java/me/lucko/luckperms/api/PermissionHolder.java +++ b/api/src/main/java/me/lucko/luckperms/api/PermissionHolder.java @@ -751,7 +751,7 @@ public interface PermissionHolder { * @param server the server to filter by, can be null * @param world the world to filter by, can be null * @param temporary whether the query is for temporary nodes or not. - * @deprecated in favour of {@link #removeIf(Predicate)} + * @deprecated in favour of {@link #clearMatching(Predicate)} */ @Deprecated void clearMetaKeys(String key, String server, String world, boolean temporary); diff --git a/common/src/main/java/me/lucko/luckperms/common/contexts/ContextManager.java b/common/src/main/java/me/lucko/luckperms/common/contexts/ContextManager.java index d0e080676..434b331fc 100644 --- a/common/src/main/java/me/lucko/luckperms/common/contexts/ContextManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/contexts/ContextManager.java @@ -46,6 +46,10 @@ public class ContextManager { .expireAfterWrite(50L, TimeUnit.MILLISECONDS) .build(t -> calculateApplicableContext(t, MutableContextSet.create()).makeImmutable()); + public ImmutableContextSet getApplicableContext(T subject) { + return cache.get(subject); + } + private MutableContextSet calculateApplicableContext(T subject, MutableContextSet accumulator) { for (ContextCalculator calculator : calculators) { try { @@ -58,14 +62,6 @@ public class ContextManager { return accumulator; } - public ImmutableContextSet getApplicableContext(T subject) { - return cache.get(subject); - } - - public void invalidateCache(T subject){ - cache.invalidate(subject); - } - public void registerCalculator(ContextCalculator calculator) { // calculators registered first should have priority (and be checked last.) calculators.add(0, calculator); @@ -83,6 +79,10 @@ public class ContextManager { return accumulator.makeImmutable(); } + public void invalidateCache(T subject){ + cache.invalidate(subject); + } + public int getCalculatorsSize() { return calculators.size(); } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/backing/JSONBacking.java b/common/src/main/java/me/lucko/luckperms/common/storage/backing/JSONBacking.java index a6f78bdb3..08de77ccd 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/backing/JSONBacking.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/backing/JSONBacking.java @@ -39,7 +39,6 @@ import me.lucko.luckperms.api.Node; import me.lucko.luckperms.api.context.ImmutableContextSet; import me.lucko.luckperms.common.bulkupdate.BulkUpdate; import me.lucko.luckperms.common.core.NodeModel; -import me.lucko.luckperms.common.core.PriorityComparator; import me.lucko.luckperms.common.core.UserIdentifier; import me.lucko.luckperms.common.core.model.Group; import me.lucko.luckperms.common.core.model.Track; @@ -51,7 +50,6 @@ import me.lucko.luckperms.common.storage.holder.NodeHeldPermission; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; -import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.ArrayList; @@ -216,12 +214,7 @@ public class JSONBacking extends FlatfileBacking { } if (!userFile.exists()) { - try { - userFile.createNewFile(); - } catch (IOException e) { - e.printStackTrace(); - return false; - } + userFile.createNewFile(); } JsonObject data = new JsonObject(); @@ -321,12 +314,7 @@ public class JSONBacking extends FlatfileBacking { group.setNodes(nodes); return true; } else { - try { - groupFile.createNewFile(); - } catch (IOException e) { - e.printStackTrace(); - return false; - } + groupFile.createNewFile(); JsonObject data = new JsonObject(); data.addProperty("name", group.getName()); @@ -375,12 +363,7 @@ public class JSONBacking extends FlatfileBacking { registerFileAction("groups", groupFile); if (!groupFile.exists()) { - try { - groupFile.createNewFile(); - } catch (IOException e) { - e.printStackTrace(); - return false; - } + groupFile.createNewFile(); } JsonObject data = new JsonObject(); @@ -445,12 +428,7 @@ public class JSONBacking extends FlatfileBacking { track.setGroups(groups); return true; } else { - try { - trackFile.createNewFile(); - } catch (IOException e) { - e.printStackTrace(); - return false; - } + trackFile.createNewFile(); JsonObject data = new JsonObject(); data.addProperty("name", track.getName()); @@ -504,12 +482,7 @@ public class JSONBacking extends FlatfileBacking { registerFileAction("tracks", trackFile); if (!trackFile.exists()) { - try { - trackFile.createNewFile(); - } catch (IOException e) { - e.printStackTrace(); - return false; - } + trackFile.createNewFile(); } JsonObject data = new JsonObject(); @@ -576,7 +549,7 @@ public class JSONBacking extends FlatfileBacking { } public static JsonArray serializePermissions(Set nodes) { - List data = new ArrayList<>(); + JsonArray arr = new JsonArray(); for (NodeModel node : nodes) { JsonObject attributes = new JsonObject(); @@ -600,17 +573,7 @@ public class JSONBacking extends FlatfileBacking { JsonObject perm = new JsonObject(); perm.add(node.getPermission(), attributes); - data.add(perm); - } - - data.sort((o1, o2) -> PriorityComparator.get().compareStrings( - Iterables.getFirst(o1.entrySet(), null).getKey(), - Iterables.getFirst(o2.entrySet(), null).getKey() - )); - - JsonArray arr = new JsonArray(); - for (JsonObject o : data) { - arr.add(o); + arr.add(perm); } return arr; diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/backing/YAMLBacking.java b/common/src/main/java/me/lucko/luckperms/common/storage/backing/YAMLBacking.java index 17039a6e3..f87f66b5f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/backing/YAMLBacking.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/backing/YAMLBacking.java @@ -48,7 +48,6 @@ import org.yaml.snakeyaml.Yaml; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; -import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.ArrayList; @@ -217,12 +216,7 @@ public class YAMLBacking extends FlatfileBacking { } if (!userFile.exists()) { - try { - userFile.createNewFile(); - } catch (IOException e) { - e.printStackTrace(); - return false; - } + userFile.createNewFile(); } Map values = new LinkedHashMap<>(); @@ -322,12 +316,7 @@ public class YAMLBacking extends FlatfileBacking { group.setNodes(nodes); return true; } else { - try { - groupFile.createNewFile(); - } catch (IOException e) { - e.printStackTrace(); - return false; - } + groupFile.createNewFile(); Map values = new LinkedHashMap<>(); values.put("name", group.getName()); @@ -374,12 +363,7 @@ public class YAMLBacking extends FlatfileBacking { registerFileAction("groups", groupFile); if (!groupFile.exists()) { - try { - groupFile.createNewFile(); - } catch (IOException e) { - e.printStackTrace(); - return false; - } + groupFile.createNewFile(); } Map values = new LinkedHashMap<>(); @@ -441,12 +425,7 @@ public class YAMLBacking extends FlatfileBacking { track.setGroups((List) values.get("groups")); return true; } else { - try { - trackFile.createNewFile(); - } catch (IOException e) { - e.printStackTrace(); - return false; - } + trackFile.createNewFile(); Map values = new LinkedHashMap<>(); values.put("name", track.getName()); @@ -491,12 +470,7 @@ public class YAMLBacking extends FlatfileBacking { registerFileAction("tracks", trackFile); if (!trackFile.exists()) { - try { - trackFile.createNewFile(); - } catch (IOException e) { - e.printStackTrace(); - return false; - } + trackFile.createNewFile(); } Map values = new LinkedHashMap<>();