152 lines
4.1 KiB
Java
152 lines
4.1 KiB
Java
package com.zontreck.configs.server;
|
|
|
|
import java.nio.file.Path;
|
|
|
|
import com.zontreck.ariaslib.util.Lists;
|
|
import com.zontreck.configs.server.sections.Bottles;
|
|
import com.zontreck.configs.server.sections.Drops;
|
|
import com.zontreck.configs.server.sections.Messages;
|
|
import com.zontreck.configs.server.sections.Teleportation;
|
|
import com.zontreck.libzontreck.util.SNbtIo;
|
|
import com.zontreck.libzontreck.vectors.WorldPosition;
|
|
import com.zontreck.util.EssentialsDatastore;
|
|
|
|
import net.minecraft.nbt.CompoundTag;
|
|
|
|
public class AEServerConfig
|
|
{
|
|
private static AEServerConfig inst;
|
|
public Bottles bottles;
|
|
public Teleportation teleport;
|
|
public Messages messages;
|
|
public Drops drops;
|
|
public boolean enable_debug = false;
|
|
public WorldPosition worldSpawn;
|
|
|
|
|
|
|
|
public static AEServerConfig deserialize(CompoundTag tag)
|
|
{
|
|
AEServerConfig config = new AEServerConfig();
|
|
try {
|
|
if(tag.contains(Bottles.TAG_NAME))
|
|
{
|
|
config.bottles = Bottles.deserialize(tag.getCompound(Bottles.TAG_NAME));
|
|
} else config.resetBottles();
|
|
|
|
|
|
if(tag.contains(Teleportation.TAG_NAME))
|
|
config.teleport = Teleportation.deserialize(tag.getCompound(Teleportation.TAG_NAME));
|
|
else {
|
|
config.resetTeleport();
|
|
}
|
|
|
|
if(tag.contains(Messages.TAG_NAME))
|
|
config.messages = Messages.deserialize(tag.getCompound(Messages.TAG_NAME));
|
|
else config.messages = new Messages();
|
|
|
|
if(tag.contains("use_debug"))
|
|
config.enable_debug = tag.getBoolean("use_debug");
|
|
else config.enable_debug=false;
|
|
|
|
if(tag.contains(Drops.TAG_NAME))
|
|
config.drops = Drops.load(tag.getCompound(Drops.TAG_NAME));
|
|
else {
|
|
config.resetDrops();
|
|
}
|
|
|
|
if(tag.contains("spawn")) {
|
|
config.worldSpawn = new WorldPosition(tag.getCompound("spawn"), true);
|
|
}else {
|
|
config.worldSpawn = null;
|
|
}
|
|
} catch(Exception e){
|
|
e.printStackTrace();
|
|
}
|
|
|
|
|
|
return config;
|
|
}
|
|
|
|
public static void loadFromFile()
|
|
{
|
|
Path serverConfig = EssentialsDatastore.of("server.snbt",false);
|
|
if(serverConfig.toFile().exists())
|
|
{
|
|
inst = deserialize(SNbtIo.loadSnbt(serverConfig));
|
|
|
|
save(); // incase of updates
|
|
}else {
|
|
initNewConfig();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
private static void initNewConfig()
|
|
{
|
|
inst = new AEServerConfig();
|
|
inst.resetBottles(); // also saves
|
|
inst.resetTeleport();
|
|
inst.resetDrops();
|
|
inst.messages = new Messages();
|
|
inst.enable_debug=false;
|
|
|
|
save();
|
|
}
|
|
|
|
private void resetBottles()
|
|
{
|
|
bottles = new Bottles();
|
|
}
|
|
|
|
private void resetTeleport() {
|
|
|
|
teleport = new Teleportation();
|
|
teleport.Effects = Lists.of(
|
|
"minecraft:darkness",
|
|
"minecraft:levitation",
|
|
"minecraft:slow_falling",
|
|
"minecraft:hunger"
|
|
);
|
|
teleport.Blacklist = Lists.of(
|
|
"dimdoors:dungeon_pockets",
|
|
"dimdoors:limbo",
|
|
"dimdoors:personal_pockets",
|
|
"dimdoors:public_pockets",
|
|
"witherstormmod:bowels"
|
|
);
|
|
}
|
|
|
|
private void resetDrops() {
|
|
drops = new Drops();
|
|
}
|
|
|
|
public static void save()
|
|
{
|
|
Path serverConfig = EssentialsDatastore.of("server.snbt", false);
|
|
|
|
CompoundTag tag = inst.serialize();
|
|
SNbtIo.writeSnbt(serverConfig, tag);
|
|
}
|
|
|
|
public CompoundTag serialize()
|
|
{
|
|
CompoundTag tag = new CompoundTag();
|
|
tag.put(Bottles.TAG_NAME, bottles.serialize());
|
|
tag.put(Teleportation.TAG_NAME, teleport.serialize());
|
|
tag.put(Messages.TAG_NAME, messages.serialize());
|
|
tag.putBoolean("use_debug", enable_debug);
|
|
tag.put(Drops.TAG_NAME, drops.save());
|
|
if(worldSpawn != null) tag.put("spawn", worldSpawn.serializePretty());
|
|
|
|
|
|
|
|
return tag;
|
|
}
|
|
|
|
public static AEServerConfig getInstance()
|
|
{
|
|
return inst;
|
|
}
|
|
}
|