Add latest revisions after getting it functional
This commit is contained in:
parent
9653e273e4
commit
ffcecb8e8e
1443 changed files with 258988 additions and 6046 deletions
148
src/main/java/com/zontreck/configs/server/AEServerConfig.java
Normal file
148
src/main/java/com/zontreck/configs/server/AEServerConfig.java
Normal file
|
@ -0,0 +1,148 @@
|
|||
package com.zontreck.configs.server;
|
||||
|
||||
import com.zontreck.AriasEssentials;
|
||||
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.util.EssentialsDatastore;
|
||||
import net.minecraft.nbt.*;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
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 static AEServerConfig deserialize(CompoundTag tag)
|
||||
{
|
||||
AEServerConfig config = new AEServerConfig();
|
||||
try {
|
||||
AriasEssentials.LOGGER.info("Loading Aria's Essentials configuration for - Server");
|
||||
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();
|
||||
}
|
||||
|
||||
AriasEssentials.LOGGER.info("Aria's Essentials Server Configuration Loaded");
|
||||
} 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());
|
||||
|
||||
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
public static AEServerConfig getInstance()
|
||||
{
|
||||
return inst;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue