package com.dazedndconfused.factionsmk2;

import com.dazedndconfused.factionsmk2.command.CommandFaction;
import com.dazedndconfused.factionsmk2.config.ConfigurationManager;
import com.google.inject.Inject;
import org.slf4j.Logger;
import org.spongepowered.api.Game;
import org.spongepowered.api.config.ConfigDir;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.game.state.GamePreInitializationEvent;
import org.spongepowered.api.event.game.state.GameStartedServerEvent;
import org.spongepowered.api.event.game.state.GameStoppedEvent;
import org.spongepowered.api.plugin.Plugin;

import java.nio.file.Path;

/**
 * Created by DazedPC on 2/24/2017.
 */
@SuppressWarnings("UnusedDeclaration")
@Plugin(id = "factionsmk2", name = Variables.NAME, version = Variables.VERSION, authors = {"Dazedndconfused"})
public class FactionsMK2 {

    //instance
    private static FactionsMK2 instance = null;
    private CommandFaction cf;

    @Inject
    private Game game;


    @Inject
    @ConfigDir(sharedRoot = false)
    private Path configDir;
    ConfigurationManager config;

    @Inject
    private Logger logger;

    @Listener
    public void onPreInitialization(GamePreInitializationEvent ev) {
        instance = this;
        config = new ConfigurationManager(configDir);
        config.load();
        getLogger().info("Loading FactionsMK2");
        //register events, listeners, etc
    }

    @Listener
    public void onServerStart(GameStartedServerEvent ev) {
        //register commands
        cf = new CommandFaction();
        cf.register();
    }

    @Listener
    public void onServerStop(GameStoppedEvent ev) {
        //stop
    }

    public Logger getLogger() {
        return logger;
    }

    public static FactionsMK2 getInstance() {
        return instance;
    }
    public Game getGame() { return game; }
    public ConfigurationManager getConfig() {return config;}
}
