mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-12-28 20:17:55 +01:00
Don't catch exceptions thrown inside i/o (#291)
This commit is contained in:
parent
ca1dacf2b6
commit
cc907b6530
@ -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);
|
||||
|
@ -46,6 +46,10 @@ public class ContextManager<T> {
|
||||
.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<T> calculator : calculators) {
|
||||
try {
|
||||
@ -58,14 +62,6 @@ public class ContextManager<T> {
|
||||
return accumulator;
|
||||
}
|
||||
|
||||
public ImmutableContextSet getApplicableContext(T subject) {
|
||||
return cache.get(subject);
|
||||
}
|
||||
|
||||
public void invalidateCache(T subject){
|
||||
cache.invalidate(subject);
|
||||
}
|
||||
|
||||
public void registerCalculator(ContextCalculator<T> calculator) {
|
||||
// calculators registered first should have priority (and be checked last.)
|
||||
calculators.add(0, calculator);
|
||||
@ -83,6 +79,10 @@ public class ContextManager<T> {
|
||||
return accumulator.makeImmutable();
|
||||
}
|
||||
|
||||
public void invalidateCache(T subject){
|
||||
cache.invalidate(subject);
|
||||
}
|
||||
|
||||
public int getCalculatorsSize() {
|
||||
return calculators.size();
|
||||
}
|
||||
|
@ -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<NodeModel> nodes) {
|
||||
List<JsonObject> 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;
|
||||
|
@ -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<String, Object> 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<String, Object> 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<String, Object> values = new LinkedHashMap<>();
|
||||
@ -441,12 +425,7 @@ public class YAMLBacking extends FlatfileBacking {
|
||||
track.setGroups((List<String>) values.get("groups"));
|
||||
return true;
|
||||
} else {
|
||||
try {
|
||||
trackFile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
trackFile.createNewFile();
|
||||
|
||||
Map<String, Object> 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<String, Object> values = new LinkedHashMap<>();
|
||||
|
Loading…
Reference in New Issue
Block a user