mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2025-01-01 05:57:51 +01:00
Add method to unregister context calculators (#1422)
This commit is contained in:
parent
d91355e4d6
commit
85d2f0b51f
@ -150,13 +150,12 @@ public interface ContextManager {
|
||||
void registerCalculator(@NonNull ContextCalculator<?> calculator);
|
||||
|
||||
/**
|
||||
* Registers a static context calculator with the manager.
|
||||
*
|
||||
* <p>Static calculators provide the same context for all subjects.</p>
|
||||
* Unregisters a context calculator with the manager.
|
||||
*
|
||||
* @param calculator the calculator
|
||||
* @since 4.4
|
||||
*/
|
||||
void registerStaticCalculator(@NonNull StaticContextCalculator calculator);
|
||||
void unregisterCalculator(@NonNull ContextCalculator<?> calculator);
|
||||
|
||||
/**
|
||||
* Invalidates the lookup cache for a given subject
|
||||
|
@ -141,7 +141,7 @@ public class LPBungeePlugin extends AbstractLuckPermsPlugin {
|
||||
this.contextManager.registerCalculator(new BackendServerCalculator(this));
|
||||
|
||||
if (this.bootstrap.getProxy().getPluginManager().getPlugin("RedisBungee") != null) {
|
||||
this.contextManager.registerStaticCalculator(new RedisBungeeCalculator());
|
||||
this.contextManager.registerCalculator(new RedisBungeeCalculator());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,6 @@ import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.User;
|
||||
import me.lucko.luckperms.api.context.ContextCalculator;
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.api.context.StaticContextCalculator;
|
||||
import me.lucko.luckperms.common.context.ContextManager;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
|
||||
@ -109,9 +108,9 @@ public class ApiContextManager implements me.lucko.luckperms.api.context.Context
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerStaticCalculator(@NonNull StaticContextCalculator calculator) {
|
||||
public void unregisterCalculator(@NonNull ContextCalculator<?> calculator) {
|
||||
Objects.requireNonNull(calculator, "calculator");
|
||||
this.handle.registerStaticCalculator(calculator);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -163,24 +163,21 @@ public abstract class ContextManager<T> {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a context calculator with the manager.
|
||||
*
|
||||
* @param calculator the calculator
|
||||
*/
|
||||
public void registerCalculator(ContextCalculator<? super T> 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a static context calculator with the manager.
|
||||
*
|
||||
* @param calculator the calculator
|
||||
*/
|
||||
public void registerStaticCalculator(StaticContextCalculator calculator) {
|
||||
registerCalculator(calculator);
|
||||
this.staticCalculators.add(0, calculator);
|
||||
public void unregisterCalculator(ContextCalculator<? super T> calculator) {
|
||||
this.calculators.remove(calculator);
|
||||
if (calculator instanceof StaticContextCalculator) {
|
||||
this.staticCalculators.remove(calculator);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -153,7 +153,7 @@ public abstract class AbstractLuckPermsPlugin implements LuckPermsPlugin {
|
||||
|
||||
// setup contextmanager & register common calculators
|
||||
setupContextManager();
|
||||
getContextManager().registerStaticCalculator(new LPStaticContextsCalculator(getConfiguration()));
|
||||
getContextManager().registerCalculator(new LPStaticContextsCalculator(getConfiguration()));
|
||||
|
||||
// setup platform hooks
|
||||
setupPlatformHooks();
|
||||
|
Loading…
Reference in New Issue
Block a user