Search in sources :

Example 1 with Plugin

use of org.spongepowered.api.plugin.Plugin 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)

Example 2 with Plugin

use of org.spongepowered.api.plugin.Plugin in project Nucleus by NucleusPowered.

the class SeenHandler method register.

@Override
public void register(@Nonnull Object plugin, @Nonnull SeenInformationProvider seenInformationProvider) throws IllegalArgumentException {
    Preconditions.checkNotNull(plugin);
    Preconditions.checkNotNull(seenInformationProvider);
    Plugin pl = plugin.getClass().getAnnotation(Plugin.class);
    Preconditions.checkArgument(pl != null, NucleusPlugin.getNucleus().getMessageProvider().getMessageWithFormat("seen.error.requireplugin"));
    String name = pl.name();
    List<SeenInformationProvider> providers;
    if (pluginInformationProviders.containsKey(name)) {
        providers = pluginInformationProviders.get(name);
    } else {
        providers = Lists.newArrayList();
        pluginInformationProviders.put(name, providers);
    }
    providers.add(seenInformationProvider);
}
Also used : NucleusPlugin(io.github.nucleuspowered.nucleus.NucleusPlugin) Plugin(org.spongepowered.api.plugin.Plugin)

Example 3 with Plugin

use of org.spongepowered.api.plugin.Plugin in project SpongeAPI by SpongePowered.

the class PluginProcessor method process.

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    if (roundEnv.processingOver()) {
        if (!roundEnv.errorRaised()) {
            finish();
        }
        return false;
    }
    if (!ProcessorUtils.contains(annotations, Plugin.class)) {
        return false;
    }
    for (Element e : roundEnv.getElementsAnnotatedWith(Plugin.class)) {
        if (e.getKind() != ElementKind.CLASS) {
            getMessager().printMessage(ERROR, "Invalid element of type " + e.getKind() + " annotated with @Plugin", e);
            continue;
        }
        final TypeElement pluginElement = (TypeElement) e;
        AnnotationWrapper<Plugin> annotation = AnnotationWrapper.of(pluginElement, Plugin.class);
        final String id = annotation.get().id();
        if (id.isEmpty()) {
            getMessager().printMessage(ERROR, "Plugin ID cannot be empty", pluginElement, annotation.getMirror(), annotation.getValue("id"));
            continue;
        }
        PluginMetadata meta = this.meta.remove(id);
        if (meta == null) {
            meta = new PluginMetadata(id);
        }
        PluginElement plugin = new PluginElement(pluginElement, annotation, meta);
        // Check for conflicting plugin IDs
        if (this.duplicates.contains(id) || this.plugins.containsKey(id)) {
            PluginElement otherPlugin = this.plugins.remove(id);
            if (otherPlugin != null) {
                reportDuplicatePlugin(id, otherPlugin);
                this.duplicates.add(id);
            }
            reportDuplicatePlugin(id, plugin);
            continue;
        }
        this.plugins.put(id, plugin);
        plugin.apply(getMessager());
    }
    return false;
}
Also used : TypeElement(javax.lang.model.element.TypeElement) TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) PluginMetadata(org.spongepowered.plugin.meta.PluginMetadata) Plugin(org.spongepowered.api.plugin.Plugin)

Aggregations

Plugin (org.spongepowered.api.plugin.Plugin)3 NucleusPlugin (io.github.nucleuspowered.nucleus.NucleusPlugin)2 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 Element (javax.lang.model.element.Element)1 TypeElement (javax.lang.model.element.TypeElement)1 PluginMetadata (org.spongepowered.plugin.meta.PluginMetadata)1 UndisableableModuleException (uk.co.drnaylor.quickstart.exceptions.UndisableableModuleException)1