mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-12-29 12:37:40 +01:00
Fix/catch IllegalArgumentException when estimating potential world contexts (#1951)
This commit is contained in:
parent
0864cf756c
commit
8fa629a243
@ -64,7 +64,10 @@ public class WorldCalculator implements ContextCalculator<Player> {
|
||||
List<World> worlds = this.plugin.getBootstrap().getServer().getWorlds();
|
||||
ImmutableContextSet.Builder builder = ImmutableContextSet.builder();
|
||||
for (World world : worlds) {
|
||||
builder.add(DefaultContextKeys.WORLD_KEY, world.getName().toLowerCase());
|
||||
String name = world.getName().toLowerCase();
|
||||
if (!name.trim().isEmpty()) {
|
||||
builder.add(DefaultContextKeys.WORLD_KEY, name);
|
||||
}
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ import me.lucko.luckperms.common.context.contextset.ImmutableContextSetImpl;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
|
||||
import net.luckperms.api.context.ContextCalculator;
|
||||
import net.luckperms.api.context.ContextSet;
|
||||
import net.luckperms.api.context.ImmutableContextSet;
|
||||
import net.luckperms.api.context.StaticContextCalculator;
|
||||
import net.luckperms.api.query.QueryOptions;
|
||||
@ -62,14 +63,6 @@ public abstract class ContextManager<T> {
|
||||
this.subjectClass = subjectClass;
|
||||
}
|
||||
|
||||
public ImmutableContextSet getPotentialContexts() {
|
||||
ImmutableContextSet.Builder builder = ImmutableContextSet.builder();
|
||||
for (ContextCalculator<? super T> calculator : this.calculators) {
|
||||
builder.addAll(calculator.estimatePotentialContexts());
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public Class<T> getSubjectClass() {
|
||||
return this.subjectClass;
|
||||
}
|
||||
@ -119,22 +112,19 @@ public abstract class ContextManager<T> {
|
||||
|
||||
protected QueryOptions calculate(T subject) {
|
||||
ImmutableContextSet.Builder accumulator = new ImmutableContextSetImpl.BuilderImpl();
|
||||
|
||||
for (ContextCalculator<? super T> calculator : this.calculators) {
|
||||
try {
|
||||
calculator.calculate(subject, accumulator::add);
|
||||
} catch (Throwable e) {
|
||||
ContextManager.this.plugin.getLogger().warn("An exception was thrown by " + getCalculatorClass(calculator) + " whilst calculating the context of subject " + subject);
|
||||
this.plugin.getLogger().warn("An exception was thrown by " + getCalculatorClass(calculator) + " whilst calculating the context of subject " + subject);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return formQueryOptions(subject, accumulator.build());
|
||||
}
|
||||
|
||||
private QueryOptions calculateStatic() {
|
||||
ImmutableContextSet.Builder accumulator = new ImmutableContextSetImpl.BuilderImpl();
|
||||
|
||||
for (StaticContextCalculator calculator : this.staticCalculators) {
|
||||
try {
|
||||
calculator.calculate(accumulator::add);
|
||||
@ -143,10 +133,25 @@ public abstract class ContextManager<T> {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return formQueryOptions(accumulator.build());
|
||||
}
|
||||
|
||||
public ImmutableContextSet getPotentialContexts() {
|
||||
ImmutableContextSet.Builder builder = ImmutableContextSet.builder();
|
||||
for (ContextCalculator<? super T> calculator : this.calculators) {
|
||||
ContextSet potentialContexts;
|
||||
try {
|
||||
potentialContexts = calculator.estimatePotentialContexts();
|
||||
} catch (Throwable e) {
|
||||
this.plugin.getLogger().warn("An exception was thrown by " + getCalculatorClass(calculator) + " whilst estimating potential contexts");
|
||||
e.printStackTrace();
|
||||
continue;
|
||||
}
|
||||
builder.addAll(potentialContexts);
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private final class StaticLookupCache extends ExpiringCache<QueryOptions> {
|
||||
StaticLookupCache() {
|
||||
super(50L, TimeUnit.MILLISECONDS);
|
||||
|
Loading…
Reference in New Issue
Block a user