This repository has been archived on 2024-10-31. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
LibZontreck/src/main/java/dev/zontreck/libzontreck/config/ServerConfig.java

39 lines
970 B
Java

package dev.zontreck.libzontreck.config;
import dev.zontreck.libzontreck.LibZontreck;
import dev.zontreck.libzontreck.config.sections.DatabaseSection;
import dev.zontreck.libzontreck.util.SNbtIo;
import net.minecraft.nbt.CompoundTag;
import java.nio.file.Path;
public class ServerConfig
{
public static final Path BASE = LibZontreck.BASE_CONFIG.resolve("server.snbt");
public static DatabaseSection database;
public static void init()
{
if(BASE.toFile().exists())
{
var config = SNbtIo.loadSnbt(BASE);
database = DatabaseSection.deserialize(config.getCompound(DatabaseSection.TAG_NAME));
commit();
} else {
database = new DatabaseSection();
commit();
}
}
public static void commit()
{
CompoundTag tag = new CompoundTag();
tag.put(DatabaseSection.TAG_NAME, database.serialize());
SNbtIo.writeSnbt(BASE, tag);
}
}