diff --git a/core/src/main/java/co/aikar/commands/CommandCompletions.java b/core/src/main/java/co/aikar/commands/CommandCompletions.java index c048cf94..158f983a 100644 --- a/core/src/main/java/co/aikar/commands/CommandCompletions.java +++ b/core/src/main/java/co/aikar/commands/CommandCompletions.java @@ -82,6 +82,20 @@ public class CommandCompletions { return this.completionMap.put(prepareCompletionId(id), handler); } + /** + * Unregister a completion handler. + * @param id + * @return + * @throws IllegalStateException If the completion couldn't be found + */ + public CommandCompletionHandler unregisterCompletion(String id) { + if (!this.completionMap.containsKey(id)) { + throw new IllegalStateException("The supplied key " + id + " does not exist in any completions"); + } + + return this.completionMap.remove(id); + } + /** * Registr a completion handler to provide command completions based on the user input. * This handler is declared to be safe to be executed asynchronously. diff --git a/core/src/main/java/co/aikar/commands/CommandManager.java b/core/src/main/java/co/aikar/commands/CommandManager.java index ae4ab8d3..0b15ab98 100644 --- a/core/src/main/java/co/aikar/commands/CommandManager.java +++ b/core/src/main/java/co/aikar/commands/CommandManager.java @@ -532,6 +532,31 @@ public abstract class CommandManager< dependencies.put(clazz, key, instance); } + + /** + * Unregisters an instance of the class, it will no longer be able to be injected + * + * @param clazz the class the injector should look for to remove + * @throws IllegalStateException If the dependency was not found. + */ + public void unregisterDependency(Class clazz) { + unregisterDependency(clazz, clazz.getName()); + } + + /** + * Unregisters an instance of the class, it will no longer be able to be injected + * + * @param clazz the class the injector should look for to remove + * @param key the key which needs to be present if that + * @throws IllegalStateException If the dependency was not found. + */ + public void unregisterDependency(Class clazz, String key) { + if (!dependencies.containsKey(clazz, key)) { + throw new IllegalStateException("Unable to unregister a dependency of " + clazz.getName() + " with the key " + key + " because it wasn't registered"); + } + + dependencies.remove(clazz, key); + } /** * Attempts to inject instances of classes registered with {@link CommandManager#registerDependency(Class, Object)}