mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-24 03:25:19 +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();
|
List<World> worlds = this.plugin.getBootstrap().getServer().getWorlds();
|
||||||
ImmutableContextSet.Builder builder = ImmutableContextSet.builder();
|
ImmutableContextSet.Builder builder = ImmutableContextSet.builder();
|
||||||
for (World world : worlds) {
|
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();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@ import me.lucko.luckperms.common.context.contextset.ImmutableContextSetImpl;
|
|||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
|
|
||||||
import net.luckperms.api.context.ContextCalculator;
|
import net.luckperms.api.context.ContextCalculator;
|
||||||
|
import net.luckperms.api.context.ContextSet;
|
||||||
import net.luckperms.api.context.ImmutableContextSet;
|
import net.luckperms.api.context.ImmutableContextSet;
|
||||||
import net.luckperms.api.context.StaticContextCalculator;
|
import net.luckperms.api.context.StaticContextCalculator;
|
||||||
import net.luckperms.api.query.QueryOptions;
|
import net.luckperms.api.query.QueryOptions;
|
||||||
@ -62,14 +63,6 @@ public abstract class ContextManager<T> {
|
|||||||
this.subjectClass = subjectClass;
|
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() {
|
public Class<T> getSubjectClass() {
|
||||||
return this.subjectClass;
|
return this.subjectClass;
|
||||||
}
|
}
|
||||||
@ -119,22 +112,19 @@ public abstract class ContextManager<T> {
|
|||||||
|
|
||||||
protected QueryOptions calculate(T subject) {
|
protected QueryOptions calculate(T subject) {
|
||||||
ImmutableContextSet.Builder accumulator = new ImmutableContextSetImpl.BuilderImpl();
|
ImmutableContextSet.Builder accumulator = new ImmutableContextSetImpl.BuilderImpl();
|
||||||
|
|
||||||
for (ContextCalculator<? super T> calculator : this.calculators) {
|
for (ContextCalculator<? super T> calculator : this.calculators) {
|
||||||
try {
|
try {
|
||||||
calculator.calculate(subject, accumulator::add);
|
calculator.calculate(subject, accumulator::add);
|
||||||
} catch (Throwable e) {
|
} 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();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return formQueryOptions(subject, accumulator.build());
|
return formQueryOptions(subject, accumulator.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
private QueryOptions calculateStatic() {
|
private QueryOptions calculateStatic() {
|
||||||
ImmutableContextSet.Builder accumulator = new ImmutableContextSetImpl.BuilderImpl();
|
ImmutableContextSet.Builder accumulator = new ImmutableContextSetImpl.BuilderImpl();
|
||||||
|
|
||||||
for (StaticContextCalculator calculator : this.staticCalculators) {
|
for (StaticContextCalculator calculator : this.staticCalculators) {
|
||||||
try {
|
try {
|
||||||
calculator.calculate(accumulator::add);
|
calculator.calculate(accumulator::add);
|
||||||
@ -143,10 +133,25 @@ public abstract class ContextManager<T> {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return formQueryOptions(accumulator.build());
|
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> {
|
private final class StaticLookupCache extends ExpiringCache<QueryOptions> {
|
||||||
StaticLookupCache() {
|
StaticLookupCache() {
|
||||||
super(50L, TimeUnit.MILLISECONDS);
|
super(50L, TimeUnit.MILLISECONDS);
|
||||||
|
Loading…
Reference in New Issue
Block a user