Search in sources :

Example 6 with CatalogRegistryModule

use of org.spongepowered.api.registry.CatalogRegistryModule in project SpongeCommon by SpongePowered.

the class SpongeGameRegistry method syncModules.

private void syncModules() {
    final DirectedGraph<Class<? extends RegistryModule>> graph = new DirectedGraph<>();
    for (RegistryModule aModule : this.registryModules) {
        if (!this.classMap.containsKey(aModule.getClass())) {
            this.classMap.put(aModule.getClass(), aModule);
        }
        addToGraph(aModule, graph);
    }
    // Now we need ot do the catalog ones
    for (CatalogRegistryModule<?> aModule : this.catalogRegistryMap.values()) {
        if (!this.classMap.containsKey(aModule.getClass())) {
            this.classMap.put(aModule.getClass(), aModule);
        }
        addToGraph(aModule, graph);
    }
    this.orderedModules.clear();
    try {
        this.orderedModules.addAll(TopologicalOrder.createOrderedLoad(graph));
    } catch (CyclicGraphException e) {
        StringBuilder msg = new StringBuilder();
        msg.append("Registry module dependencies are cyclical!\n");
        msg.append("Dependency loops are:\n");
        for (DataNode<?>[] cycle : e.getCycles()) {
            msg.append("[");
            for (DataNode<?> node : cycle) {
                msg.append(node.getData().toString()).append(" ");
            }
            msg.append("]\n");
        }
        SpongeImpl.getLogger().fatal(msg.toString());
        throw new RuntimeException("Registry modules dependencies error.");
    }
}
Also used : DisplaySlotRegistryModule(org.spongepowered.common.registry.type.scoreboard.DisplaySlotRegistryModule) AdditionalCatalogRegistryModule(org.spongepowered.api.registry.AdditionalCatalogRegistryModule) RegistryModule(org.spongepowered.api.registry.RegistryModule) PluginProvidedRegistryModule(org.spongepowered.api.registry.util.PluginProvidedRegistryModule) ExtraClassCatalogRegistryModule(org.spongepowered.api.registry.ExtraClassCatalogRegistryModule) CatalogRegistryModule(org.spongepowered.api.registry.CatalogRegistryModule) RotationRegistryModule(org.spongepowered.common.registry.type.block.RotationRegistryModule) DirectedGraph(org.spongepowered.common.util.graph.DirectedGraph) DataNode(org.spongepowered.common.util.graph.DirectedGraph.DataNode) CyclicGraphException(org.spongepowered.common.util.graph.CyclicGraphException)

Example 7 with CatalogRegistryModule

use of org.spongepowered.api.registry.CatalogRegistryModule in project SpongeCommon by SpongePowered.

the class SpongeGameRegistry method throwRegistryEvent.

@SuppressWarnings("unchecked")
private void throwRegistryEvent(RegistryModule module) {
    if (this.phase == RegistrationPhase.INIT && module instanceof AdditionalCatalogRegistryModule && (!(module instanceof SpongeAdditionalCatalogRegistryModule) || ((SpongeAdditionalCatalogRegistryModule) module).allowsApiRegistration()) && module.getClass().getAnnotation(CustomRegistrationPhase.class) == null) {
        Class<? extends CatalogType> catalogClass = null;
        for (Map.Entry<Class<? extends CatalogType>, CatalogRegistryModule<?>> entry : this.catalogRegistryMap.entrySet()) {
            if (entry.getValue() == module) {
                catalogClass = entry.getKey();
            }
        }
        if (catalogClass == null) {
            // This isn't a valid registered registry
            // We should throw an exception or print out an exception, but otherwise, not going to bother at this moment.
            new PrettyPrinter(60).centre().add("Unregistered RegistryModule").hr().addWrapped(60, "An unknown registry module was added to the ordered set of modules, but the " + "module itself is not registered with the GameRegistry!").add().add("%s : %s", "Registry Module", module.toString()).add().add(new Exception()).add().add("To fix this, the developer providing the module needs to register the module correctly.").trace();
            return;
        }
        final AdditionalCatalogRegistryModule registryModule = (AdditionalCatalogRegistryModule) module;
        SpongeImpl.postEvent(new SpongeGameRegistryRegisterEvent(Sponge.getCauseStackManager().getCurrentCause(), catalogClass, registryModule));
    }
}
Also used : CatalogType(org.spongepowered.api.CatalogType) PrettyPrinter(org.spongepowered.asm.util.PrettyPrinter) AdditionalCatalogRegistryModule(org.spongepowered.api.registry.AdditionalCatalogRegistryModule) ExtraClassCatalogRegistryModule(org.spongepowered.api.registry.ExtraClassCatalogRegistryModule) CatalogRegistryModule(org.spongepowered.api.registry.CatalogRegistryModule) AdditionalCatalogRegistryModule(org.spongepowered.api.registry.AdditionalCatalogRegistryModule) SpongeGameRegistryRegisterEvent(org.spongepowered.common.event.registry.SpongeGameRegistryRegisterEvent) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) CyclicGraphException(org.spongepowered.common.util.graph.CyclicGraphException) RegistryModuleAlreadyRegisteredException(org.spongepowered.api.registry.RegistryModuleAlreadyRegisteredException) IOException(java.io.IOException)

Example 8 with CatalogRegistryModule

use of org.spongepowered.api.registry.CatalogRegistryModule in project LanternServer by LanternPowered.

the class LanternGameRegistry method registerModulePhase.

@SuppressWarnings("unchecked")
private void registerModulePhase() {
    syncModules();
    for (Class<? extends RegistryModule> moduleClass : this.orderedModules) {
        if (!this.classMap.containsKey(moduleClass)) {
            throw new IllegalStateException("Something funky happened! The module " + moduleClass + " is required but seems to be missing.");
        }
        tryModulePhaseRegistration(this.classMap.get(moduleClass));
        if (this.phase == RegistrationPhase.INIT) {
            Map.Entry<Class<? extends CatalogType>, CatalogRegistryModule<?>> selectedEntry = null;
            for (Map.Entry<Class<? extends CatalogType>, CatalogRegistryModule<?>> entry : this.catalogRegistryMap.entrySet()) {
                if (entry.getValue().getClass() == moduleClass) {
                    selectedEntry = entry;
                    break;
                }
            }
            if (selectedEntry == null) {
                continue;
            }
            final CatalogRegistryModule module = selectedEntry.getValue();
            if (module instanceof AdditionalCatalogRegistryModule && module.getClass().getAnnotation(CustomRegistrationPhase.class) == null) {
                this.game.getEventManager().post(new LanternGameRegistryRegisterEvent(CauseStack.current().getCurrentCause(), selectedEntry.getKey(), (AdditionalCatalogRegistryModule) module));
            }
        }
    }
    registerAdditionalPhase();
}
Also used : PluginCatalogType(org.lanternpowered.server.catalog.PluginCatalogType) CatalogType(org.spongepowered.api.CatalogType) AdditionalCatalogRegistryModule(org.spongepowered.api.registry.AdditionalCatalogRegistryModule) AlternateCatalogRegistryModule(org.spongepowered.api.registry.AlternateCatalogRegistryModule) CatalogRegistryModule(org.spongepowered.api.registry.CatalogRegistryModule) LanternGameRegistryRegisterEvent(org.lanternpowered.server.event.registry.LanternGameRegistryRegisterEvent) AdditionalCatalogRegistryModule(org.spongepowered.api.registry.AdditionalCatalogRegistryModule) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap)

Aggregations

CatalogRegistryModule (org.spongepowered.api.registry.CatalogRegistryModule)8 Map (java.util.Map)6 CatalogType (org.spongepowered.api.CatalogType)5 AdditionalCatalogRegistryModule (org.spongepowered.api.registry.AdditionalCatalogRegistryModule)5 ArrayList (java.util.ArrayList)4 IdentityHashMap (java.util.IdentityHashMap)3 RegistryModule (org.spongepowered.api.registry.RegistryModule)3 IOException (java.io.IOException)2 Field (java.lang.reflect.Field)2 ExtraClassCatalogRegistryModule (org.spongepowered.api.registry.ExtraClassCatalogRegistryModule)2 CyclicGraphException (org.spongepowered.common.util.graph.CyclicGraphException)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 ImmutableList (com.google.common.collect.ImmutableList)1 TypeToken (com.google.common.reflect.TypeToken)1 Inject (com.google.inject.Inject)1 Singleton (com.google.inject.Singleton)1 BufferedImage (java.awt.image.BufferedImage)1 InputStream (java.io.InputStream)1 Method (java.lang.reflect.Method)1