Add method to unregister context calculators (#1422)

This commit is contained in:
Luck 2019-02-07 12:24:23 +00:00
parent d91355e4d6
commit 85d2f0b51f
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
5 changed files with 17 additions and 22 deletions

View File

@ -150,13 +150,12 @@ public interface ContextManager {
void registerCalculator(@NonNull ContextCalculator<?> calculator); void registerCalculator(@NonNull ContextCalculator<?> calculator);
/** /**
* Registers a static context calculator with the manager. * Unregisters a context calculator with the manager.
*
* <p>Static calculators provide the same context for all subjects.</p>
* *
* @param calculator the calculator * @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 * Invalidates the lookup cache for a given subject

View File

@ -141,7 +141,7 @@ public class LPBungeePlugin extends AbstractLuckPermsPlugin {
this.contextManager.registerCalculator(new BackendServerCalculator(this)); this.contextManager.registerCalculator(new BackendServerCalculator(this));
if (this.bootstrap.getProxy().getPluginManager().getPlugin("RedisBungee") != null) { if (this.bootstrap.getProxy().getPluginManager().getPlugin("RedisBungee") != null) {
this.contextManager.registerStaticCalculator(new RedisBungeeCalculator()); this.contextManager.registerCalculator(new RedisBungeeCalculator());
} }
} }

View File

@ -29,7 +29,6 @@ import me.lucko.luckperms.api.Contexts;
import me.lucko.luckperms.api.User; import me.lucko.luckperms.api.User;
import me.lucko.luckperms.api.context.ContextCalculator; import me.lucko.luckperms.api.context.ContextCalculator;
import me.lucko.luckperms.api.context.ImmutableContextSet; 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.context.ContextManager;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
@ -109,9 +108,9 @@ public class ApiContextManager implements me.lucko.luckperms.api.context.Context
} }
@Override @Override
public void registerStaticCalculator(@NonNull StaticContextCalculator calculator) { public void unregisterCalculator(@NonNull ContextCalculator<?> calculator) {
Objects.requireNonNull(calculator, "calculator"); Objects.requireNonNull(calculator, "calculator");
this.handle.registerStaticCalculator(calculator);
} }
@Override @Override

View File

@ -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) { public void registerCalculator(ContextCalculator<? super T> calculator) {
// calculators registered first should have priority (and be checked last.) // calculators registered first should have priority (and be checked last.)
this.calculators.add(0, calculator); this.calculators.add(0, calculator);
if (calculator instanceof StaticContextCalculator) {
StaticContextCalculator staticCalculator = (StaticContextCalculator) calculator;
this.staticCalculators.add(0, staticCalculator);
}
} }
/** public void unregisterCalculator(ContextCalculator<? super T> calculator) {
* Registers a static context calculator with the manager. this.calculators.remove(calculator);
* if (calculator instanceof StaticContextCalculator) {
* @param calculator the calculator this.staticCalculators.remove(calculator);
*/ }
public void registerStaticCalculator(StaticContextCalculator calculator) {
registerCalculator(calculator);
this.staticCalculators.add(0, calculator);
} }
/** /**

View File

@ -153,7 +153,7 @@ public abstract class AbstractLuckPermsPlugin implements LuckPermsPlugin {
// setup contextmanager & register common calculators // setup contextmanager & register common calculators
setupContextManager(); setupContextManager();
getContextManager().registerStaticCalculator(new LPStaticContextsCalculator(getConfiguration())); getContextManager().registerCalculator(new LPStaticContextsCalculator(getConfiguration()));
// setup platform hooks // setup platform hooks
setupPlatformHooks(); setupPlatformHooks();