net.luckperms.api.context.ContextCalculator Java Examples

The following examples show how to use net.luckperms.api.context.ContextCalculator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ContextManager.java    From LuckPerms with MIT License 5 votes vote down vote up
public void registerCalculator(ContextCalculator<? super S> calculator) {
    // calculators registered first should have priority (and be checked last.)
    this.calculators.add(0, calculator);

    if (calculator instanceof StaticContextCalculator) {
        StaticContextCalculator staticCalculator = (StaticContextCalculator) calculator;
        this.staticCalculators.add(0, staticCalculator);
    }
}
 
Example #2
Source File: ContextManager.java    From LuckPerms with MIT License 5 votes vote down vote up
protected QueryOptions calculate(S subject) {
    ImmutableContextSet.Builder accumulator = new ImmutableContextSetImpl.BuilderImpl();
    for (ContextCalculator<? super S> calculator : this.calculators) {
        try {
            calculator.calculate(subject, accumulator::add);
        } catch (Throwable e) {
            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());
}
 
Example #3
Source File: ContextManager.java    From LuckPerms with MIT License 5 votes vote down vote up
public ImmutableContextSet getPotentialContexts() {
    ImmutableContextSet.Builder builder = new ImmutableContextSetImpl.BuilderImpl();
    for (ContextCalculator<? super S> 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();
}
 
Example #4
Source File: ContextManager.java    From LuckPerms with MIT License 5 votes vote down vote up
private static String getCalculatorClass(ContextCalculator<?> calculator) {
    Class<?> calculatorClass;
    if (calculator instanceof ForwardingContextCalculator) {
        calculatorClass = ((ForwardingContextCalculator<?>) calculator).delegate().getClass();
    } else {
        calculatorClass = calculator.getClass();
    }
    return calculatorClass.getName();
}
 
Example #5
Source File: ApiContextManager.java    From LuckPerms with MIT License 4 votes vote down vote up
@Override
public void registerCalculator(@NonNull ContextCalculator<?> calculator) {
    Objects.requireNonNull(calculator, "calculator");
    this.handle.registerCalculator(calculator);
}
 
Example #6
Source File: ApiContextManager.java    From LuckPerms with MIT License 4 votes vote down vote up
@Override
public void unregisterCalculator(@NonNull ContextCalculator<?> calculator) {
    Objects.requireNonNull(calculator, "calculator");
    this.handle.unregisterCalculator(calculator);
}
 
Example #7
Source File: ContextManager.java    From LuckPerms with MIT License 4 votes vote down vote up
public void unregisterCalculator(ContextCalculator<? super S> calculator) {
    this.calculators.remove(calculator);
    if (calculator instanceof StaticContextCalculator) {
        this.staticCalculators.remove(calculator);
    }
}