Package net.uku3lig.ukulib.config
Class ConfigManager<T extends Serializable>
java.lang.Object
net.uku3lig.ukulib.config.ConfigManager<T>
- Type Parameters:
T- The type of the config
- All Implemented Interfaces:
net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener,net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener,net.minecraft.resource.ResourceReloader,net.minecraft.resource.SynchronousResourceReloader
public class ConfigManager<T extends Serializable>
extends Object
implements net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener
Manages a config, by holding it, saving it and loading it.
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.minecraft.resource.ResourceReloader
net.minecraft.resource.ResourceReloader.Synchronizer -
Constructor Summary
ConstructorsConstructorDescriptionConfigManager(ConfigSerializer<T> serializer) Creates a manager which provides an initial config by deserializing the file.ConfigManager(ConfigSerializer<T> serializer, T config) Creates a manager. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Serializable>
ConfigManager<T>createDefault(Class<T> configClass, String name) Creates a default config manager, with a default config serializer.The config held by the manager.net.minecraft.util.Identifiervoidreload(net.minecraft.resource.ResourceManager manager) voidreplaceConfig(T newConfig) Replaces the current config with a new one, serializing it in the process.voidResets the config to its default, from a default provided by theConfigSerializer.voidSaves the stored config.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener
getFabricDependenciesMethods inherited from interface net.minecraft.resource.ResourceReloader
getNameMethods inherited from interface net.minecraft.resource.SynchronousResourceReloader
reload
-
Constructor Details
-
ConfigManager
Creates a manager.- Parameters:
serializer- The serializerconfig- The initial config
-
ConfigManager
Creates a manager which provides an initial config by deserializing the file.- Parameters:
serializer- The serializer
-
-
Method Details
-
createDefault
public static <T extends Serializable> ConfigManager<T> createDefault(Class<T> configClass, String name) Creates a default config manager, with a default config serializer. The config will be saved to and read from./config/[name].toml(without the brackets).- Type Parameters:
T- The type of the config- Parameters:
configClass- The class of the configname- The name of the config, used for the filename- Returns:
- The generated config manager
-
saveConfig
public void saveConfig()Saves the stored config. -
replaceConfig
Replaces the current config with a new one, serializing it in the process.- Parameters:
newConfig- The new config
-
resetConfig
public void resetConfig()Resets the config to its default, from a default provided by theConfigSerializer. -
getFabricId
public net.minecraft.util.Identifier getFabricId()- Specified by:
getFabricIdin interfacenet.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener
-
reload
public void reload(net.minecraft.resource.ResourceManager manager) - Specified by:
reloadin interfacenet.minecraft.resource.SynchronousResourceReloader
-
getConfig
The config held by the manager.- Returns:
- The config
-