diff --git a/common/api/src/main/java/com/dfsek/terra/api/event/events/config/pack/ConfigPackPreLoadEvent.java b/common/api/src/main/java/com/dfsek/terra/api/event/events/config/pack/ConfigPackPreLoadEvent.java index 4f9e86dca..2fc9c96e2 100644 --- a/common/api/src/main/java/com/dfsek/terra/api/event/events/config/pack/ConfigPackPreLoadEvent.java +++ b/common/api/src/main/java/com/dfsek/terra/api/event/events/config/pack/ConfigPackPreLoadEvent.java @@ -4,7 +4,7 @@ import com.dfsek.tectonic.config.ConfigTemplate; import com.dfsek.terra.api.config.ConfigPack; /** - * Called before a config pack's registries are filled. At this point, the pack manifest has been loaded, and all registries are empty. + * Called before a config pack's registries are filled. */ public class ConfigPackPreLoadEvent extends ConfigPackLoadEvent { public ConfigPackPreLoadEvent(ConfigPack pack, ExceptionalConsumer configLoader) { diff --git a/common/api/src/main/java/com/dfsek/terra/api/event/events/config/type/ConfigTypeLoadEvent.java b/common/api/src/main/java/com/dfsek/terra/api/event/events/config/type/ConfigTypeLoadEvent.java new file mode 100644 index 000000000..b604bcf04 --- /dev/null +++ b/common/api/src/main/java/com/dfsek/terra/api/event/events/config/type/ConfigTypeLoadEvent.java @@ -0,0 +1,28 @@ +package com.dfsek.terra.api.event.events.config.type; + +import com.dfsek.terra.api.config.ConfigPack; +import com.dfsek.terra.api.config.ConfigType; +import com.dfsek.terra.api.event.events.PackEvent; +import com.dfsek.terra.api.registry.CheckedRegistry; + +public abstract class ConfigTypeLoadEvent implements PackEvent { + private final ConfigType type; + private final CheckedRegistry registry; + + public ConfigTypeLoadEvent(ConfigType type, CheckedRegistry registry) { + this.type = type; + this.registry = registry; + } + + @Override + public ConfigPack getPack() { + return null; + } + + @SuppressWarnings("unchecked") + public CheckedRegistry getRegistry(Class clazz) { + if(!clazz.isAssignableFrom(type.getTypeClass())) + throw new ClassCastException("Cannot assign object from loader of type " + type.getTypeClass().getCanonicalName() + " to class " + clazz.getCanonicalName()); + return (CheckedRegistry) registry; + } +} diff --git a/common/api/src/main/java/com/dfsek/terra/api/event/events/config/type/ConfigTypePostLoadEvent.java b/common/api/src/main/java/com/dfsek/terra/api/event/events/config/type/ConfigTypePostLoadEvent.java new file mode 100644 index 000000000..35ddba976 --- /dev/null +++ b/common/api/src/main/java/com/dfsek/terra/api/event/events/config/type/ConfigTypePostLoadEvent.java @@ -0,0 +1,10 @@ +package com.dfsek.terra.api.event.events.config.type; + +import com.dfsek.terra.api.config.ConfigType; +import com.dfsek.terra.api.registry.CheckedRegistry; + +public class ConfigTypePostLoadEvent extends ConfigTypeLoadEvent{ + public ConfigTypePostLoadEvent(ConfigType type, CheckedRegistry registry) { + super(type, registry); + } +} diff --git a/common/api/src/main/java/com/dfsek/terra/api/event/events/config/type/ConfigTypePreLoadEvent.java b/common/api/src/main/java/com/dfsek/terra/api/event/events/config/type/ConfigTypePreLoadEvent.java new file mode 100644 index 000000000..3be1e9586 --- /dev/null +++ b/common/api/src/main/java/com/dfsek/terra/api/event/events/config/type/ConfigTypePreLoadEvent.java @@ -0,0 +1,10 @@ +package com.dfsek.terra.api.event.events.config.type; + +import com.dfsek.terra.api.config.ConfigType; +import com.dfsek.terra.api.registry.CheckedRegistry; + +public class ConfigTypePreLoadEvent extends ConfigTypeLoadEvent{ + public ConfigTypePreLoadEvent(ConfigType type, CheckedRegistry registry) { + super(type, registry); + } +} diff --git a/common/implementation/src/main/java/com/dfsek/terra/config/pack/ConfigPackImpl.java b/common/implementation/src/main/java/com/dfsek/terra/config/pack/ConfigPackImpl.java index a38adcab1..25ebf41ac 100644 --- a/common/implementation/src/main/java/com/dfsek/terra/config/pack/ConfigPackImpl.java +++ b/common/implementation/src/main/java/com/dfsek/terra/config/pack/ConfigPackImpl.java @@ -22,6 +22,8 @@ import com.dfsek.terra.api.event.events.config.ConfigurationLoadEvent; import com.dfsek.terra.api.event.events.config.pack.ConfigPackPostLoadEvent; import com.dfsek.terra.api.event.events.config.pack.ConfigPackPreLoadEvent; import com.dfsek.terra.api.event.events.config.ConfigurationDiscoveryEvent; +import com.dfsek.terra.api.event.events.config.type.ConfigTypePostLoadEvent; +import com.dfsek.terra.api.event.events.config.type.ConfigTypePreLoadEvent; import com.dfsek.terra.api.registry.CheckedRegistry; import com.dfsek.terra.api.registry.OpenRegistry; import com.dfsek.terra.api.registry.exception.DuplicateEntryException; @@ -244,6 +246,7 @@ public class ConfigPackImpl implements ConfigPack { for(ConfigType configType : configTypeRegistry.entries()) { // Load the configs CheckedRegistry registry = getCheckedRegistry(configType.getTypeClass()); + main.getEventManager().callEvent(new ConfigTypePreLoadEvent(configType, registry)); for(AbstractConfiguration config : abstractConfigLoader.loadConfigs(configs.getOrDefault(configType, Collections.emptyList()))) { try { Object loaded = ((ConfigFactory) configType.getFactory()).build(selfLoader.load(configType.getTemplate(this, main), config), main); @@ -253,6 +256,7 @@ public class ConfigPackImpl implements ConfigPack { throw new LoadException("Duplicate registry entry: ", e); } } + main.getEventManager().callEvent(new ConfigTypePostLoadEvent(configType, registry)); } main.getEventManager().callEvent(new ConfigPackPostLoadEvent(this, template -> selfLoader.load(template, configuration)));