add ConfigPackLoadEvent#getLoader

This commit is contained in:
dfsek committed 2021-06-01 01:09:51 -07:00
1 parent 0600176e31
commit bb2601252a
4 files changed
+17 -9

No files matched your search

@@ -3,6 +3,7 @@ package com.dfsek.terra.api.event.events.config;
import com.dfsek.tectonic.config.ConfigTemplate; import com.dfsek.tectonic.config.ConfigTemplate;
import com.dfsek.tectonic.exception.ConfigException; import com.dfsek.tectonic.exception.ConfigException;
import com.dfsek.terra.api.event.events.PackEvent; import com.dfsek.terra.api.event.events.PackEvent;
import com.dfsek.terra.config.fileloaders.Loader;
import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.config.pack.ConfigPack;
/** /**
@@ -11,10 +12,12 @@ import com.dfsek.terra.config.pack.ConfigPack;
public abstract class ConfigPackLoadEvent implements PackEvent { public abstract class ConfigPackLoadEvent implements PackEvent {
private final ConfigPack pack; private final ConfigPack pack;
private final ExceptionalConsumer<ConfigTemplate> configLoader; private final ExceptionalConsumer<ConfigTemplate> configLoader;
private final Loader loader;
public ConfigPackLoadEvent(ConfigPack pack, ExceptionalConsumer<ConfigTemplate> configLoader) { public ConfigPackLoadEvent(ConfigPack pack, ExceptionalConsumer<ConfigTemplate> configLoader, Loader loader) {
this.pack = pack; this.pack = pack;
this.configLoader = configLoader; this.configLoader = configLoader;
this.loader = loader;
} }
@Override @Override
@@ -34,4 +37,8 @@ public abstract class ConfigPackLoadEvent implements PackEvent {
public interface ExceptionalConsumer<T extends ConfigTemplate> { public interface ExceptionalConsumer<T extends ConfigTemplate> {
void accept(T value) throws ConfigException; void accept(T value) throws ConfigException;
} }
public Loader getLoader() {
return loader;
}
} }
@@ -1,13 +1,14 @@
package com.dfsek.terra.api.event.events.config; package com.dfsek.terra.api.event.events.config;
import com.dfsek.tectonic.config.ConfigTemplate; import com.dfsek.tectonic.config.ConfigTemplate;
import com.dfsek.terra.config.fileloaders.Loader;
import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.config.pack.ConfigPack;
/** /**
* Called when a config pack has finished loading. * Called when a config pack has finished loading.
*/ */
public class ConfigPackPostLoadEvent extends ConfigPackLoadEvent { public class ConfigPackPostLoadEvent extends ConfigPackLoadEvent {
public ConfigPackPostLoadEvent(ConfigPack pack, ExceptionalConsumer<ConfigTemplate> loader) { public ConfigPackPostLoadEvent(ConfigPack pack, ExceptionalConsumer<ConfigTemplate> configTemplateLoader, Loader loader) {
super(pack, loader); super(pack, configTemplateLoader, loader);
} }
} }
@@ -1,14 +1,14 @@
package com.dfsek.terra.api.event.events.config; package com.dfsek.terra.api.event.events.config;
import com.dfsek.tectonic.config.ConfigTemplate; import com.dfsek.tectonic.config.ConfigTemplate;
import com.dfsek.tectonic.exception.ConfigException; import com.dfsek.terra.config.fileloaders.Loader;
import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.config.pack.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. At this point, the pack manifest has been loaded, and all registries are empty.
*/ */
public class ConfigPackPreLoadEvent extends ConfigPackLoadEvent { public class ConfigPackPreLoadEvent extends ConfigPackLoadEvent {
public ConfigPackPreLoadEvent(ConfigPack pack, ExceptionalConsumer<ConfigTemplate> configLoader) { public ConfigPackPreLoadEvent(ConfigPack pack, ExceptionalConsumer<ConfigTemplate> configLoader, Loader loader) {
super(pack, configLoader); super(pack, configLoader, loader);
} }
} }
@@ -138,7 +138,7 @@ public class ConfigPack implements LoaderRegistrar {
main.logger().info("Loading config pack \"" + template.getID() + "\""); main.logger().info("Loading config pack \"" + template.getID() + "\"");
main.getEventManager().callEvent(new ConfigPackPreLoadEvent(this, template -> selfLoader.load(template, configuration))); main.getEventManager().callEvent(new ConfigPackPreLoadEvent(this, template -> selfLoader.load(template, configuration), loader));
load(l, main); load(l, main);
@@ -185,7 +185,7 @@ public class ConfigPack implements LoaderRegistrar {
selfLoader.load(template, configuration); selfLoader.load(template, configuration);
main.logger().info("Loading config pack \"" + template.getID() + "\""); main.logger().info("Loading config pack \"" + template.getID() + "\"");
main.getEventManager().callEvent(new ConfigPackPreLoadEvent(this, template -> selfLoader.load(template, configuration))); main.getEventManager().callEvent(new ConfigPackPreLoadEvent(this, template -> selfLoader.load(template, configuration), loader));
load(l, main); load(l, main);
@@ -253,7 +253,7 @@ public class ConfigPack implements LoaderRegistrar {
.open("flora", ".yml").then(configs -> buildAll(new FloraFactory(), floraRegistry, abstractConfigLoader.loadConfigs(configs, FloraTemplate::new), main)).close() .open("flora", ".yml").then(configs -> buildAll(new FloraFactory(), floraRegistry, abstractConfigLoader.loadConfigs(configs, FloraTemplate::new), main)).close()
.open("biomes", ".yml").then(configs -> buildAll(new BiomeFactory(this), biomeRegistry, abstractConfigLoader.loadConfigs(configs, () -> new BiomeTemplate(this, main)), main)).close(); .open("biomes", ".yml").then(configs -> buildAll(new BiomeFactory(this), biomeRegistry, abstractConfigLoader.loadConfigs(configs, () -> new BiomeTemplate(this, main)), main)).close();
main.getEventManager().callEvent(new ConfigPackPostLoadEvent(this, template -> selfLoader.load(template, configuration))); main.getEventManager().callEvent(new ConfigPackPostLoadEvent(this, template -> selfLoader.load(template, configuration), loader));
main.logger().info("Loaded config pack \"" + template.getID() + "\" v" + template.getVersion() + " by " + template.getAuthor() + " in " + (System.nanoTime() - start) / 1000000D + "ms."); main.logger().info("Loaded config pack \"" + template.getID() + "\" v" + template.getVersion() + " by " + template.getAuthor() + " in " + (System.nanoTime() - start) / 1000000D + "ms.");
} }