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();
}
}
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);
}
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;
}
Aggregations