api to access Loader

This commit is contained in:
dfsek
2021-07-05 02:05:26 -07:00
parent 9f37285c9a
commit 58a5160d53
8 changed files with 66 additions and 19 deletions

View File

@@ -21,6 +21,8 @@ public interface ConfigPack extends LoaderRegistrar, LoaderHolder, RegistryHolde
void registerConfigType(ConfigType<?, ?> type, String id, int priority);
Loader getLoader();
Set<TerraAddon> addons();
String getID();

View File

@@ -0,0 +1,45 @@
package com.dfsek.terra.api.config;
import com.dfsek.tectonic.config.Configuration;
import com.dfsek.tectonic.exception.ConfigException;
import com.dfsek.terra.api.util.ExceptionalConsumer;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import java.util.Set;
public interface Loader {
/**
* Do something with the InputStreams.
*
* @param consumer Something to do with the streams.
*/
Loader then(ExceptionalConsumer<List<Configuration>> consumer) throws ConfigException;
Loader thenNames(ExceptionalConsumer<List<String>> consumer) throws ConfigException;
Loader thenEntries(ExceptionalConsumer<Set<Map.Entry<String, InputStream>>> consumer) throws ConfigException;
/**
* Get a single file from this Loader.
*
* @param singleFile File to get
* @return InputStream from file.
*/
InputStream get(String singleFile) throws IOException;
/**
* Open a subdirectory.
*
* @param directory Directory to open
* @param extension
*/
Loader open(String directory, String extension);
/**
* Close all InputStreams opened.
*/
Loader close();
}

View File

@@ -0,0 +1,8 @@
package com.dfsek.terra.api.util;
import com.dfsek.tectonic.exception.ConfigException;
@FunctionalInterface
public interface ExceptionalConsumer<T> {
void accept(T t) throws ConfigException;
}