package com.loganmagnan.eventcore.managers;

import com.loganmagnan.eventcore.EventCore;
import com.loganmagnan.eventcore.utils.ColorUtils;
import com.loganmagnan.eventcore.utils.CustomLocation;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;

@Getter
@Setter
public class SpawnManager {

    private EventCore main = EventCore.getInstance();

    private FileConfiguration config = this.main.getMainConfig().getConfig();

    private CustomLocation spawnLocation;

    public SpawnManager() {
        this.loadConfig();
    }

    private void loadConfig() {
        if (this.config.contains("SPAWN.LOCATION")) {
            try {
                this.spawnLocation = CustomLocation.stringToLocation(this.config.getString("SPAWN.LOCATION"));
            } catch (NullPointerException exception) {
                this.main.getServer().getConsoleSender().sendMessage(ColorUtils.getMessageType("&cSpawn location not found"));
            }
        }
    }

    public void saveConfig() {
        this.config.set("SPAWN.LOCATION", CustomLocation.locationToString(this.spawnLocation));
        this.main.getMainConfig().save();
    }
}
