Search in sources :

Example 1 with UnremovableModuleException

use of io.github.nucleuspowered.nucleus.api.exceptions.UnremovableModuleException in project Nucleus by NucleusPowered.

the class ModuleRegistrationProxyService method removeModule.

@Override
public void removeModule(String module, Object plugin) throws ModulesLoadedException, UnremovableModuleException, NoModuleException {
    if (!canDisableModules()) {
        throw new ModulesLoadedException();
    }
    // The plugin must actually be a plugin.
    Preconditions.checkNotNull(plugin);
    Plugin pluginAnnotation = plugin.getClass().getAnnotation(Plugin.class);
    if (pluginAnnotation == null) {
        throw new IllegalArgumentException("plugin must be your plugin instance.");
    }
    try {
        container.disableModule(module);
        nucleus.getLogger().info(NucleusPlugin.getNucleus().getMessageProvider().getMessageWithFormat("nucleus.module.disabled.modulerequest", pluginAnnotation.name(), pluginAnnotation.id(), module));
    } catch (IllegalStateException e) {
        throw new ModulesLoadedException();
    } catch (UndisableableModuleException e) {
        nucleus.getLogger().warn(NucleusPlugin.getNucleus().getMessageProvider().getMessageWithFormat("nucleus.module.disabled.forceload", pluginAnnotation.name(), pluginAnnotation.id(), module));
        nucleus.getLogger().warn(NucleusPlugin.getNucleus().getMessageProvider().getMessageWithFormat("nucleus.module.disabled.forceloadtwo", pluginAnnotation.name()));
        throw new UnremovableModuleException();
    } catch (uk.co.drnaylor.quickstart.exceptions.NoModuleException e) {
        throw new NoModuleException();
    }
}
Also used : NoModuleException(io.github.nucleuspowered.nucleus.api.exceptions.NoModuleException) UndisableableModuleException(uk.co.drnaylor.quickstart.exceptions.UndisableableModuleException) UnremovableModuleException(io.github.nucleuspowered.nucleus.api.exceptions.UnremovableModuleException) ModulesLoadedException(io.github.nucleuspowered.nucleus.api.exceptions.ModulesLoadedException) Plugin(org.spongepowered.api.plugin.Plugin) NucleusPlugin(io.github.nucleuspowered.nucleus.NucleusPlugin)

Aggregations

NucleusPlugin (io.github.nucleuspowered.nucleus.NucleusPlugin)1 ModulesLoadedException (io.github.nucleuspowered.nucleus.api.exceptions.ModulesLoadedException)1 NoModuleException (io.github.nucleuspowered.nucleus.api.exceptions.NoModuleException)1 UnremovableModuleException (io.github.nucleuspowered.nucleus.api.exceptions.UnremovableModuleException)1 Plugin (org.spongepowered.api.plugin.Plugin)1 UndisableableModuleException (uk.co.drnaylor.quickstart.exceptions.UndisableableModuleException)1