package de.steamwar.tntleague

import de.steamwar.tntleague.command.AcceptCommand
import de.steamwar.tntleague.command.InviteCommand
import de.steamwar.tntleague.command.LeaveCommand
import de.steamwar.tntleague.command.RemoveCommand
import de.steamwar.tntleague.events.GlobalListener
import de.steamwar.tntleague.events.LobbyListener
import net.kyori.adventure.key.Key
import net.kyori.adventure.translation.GlobalTranslator
import net.kyori.adventure.translation.TranslationRegistry
import net.kyori.adventure.util.UTF8ResourceBundleControl
import org.bukkit.plugin.java.JavaPlugin
import java.util.*

lateinit var plugin: TNTLeague

class TNTLeague : JavaPlugin() {
    init {
        plugin = this
    }

    override fun onEnable() {
        saveResource("config.yml", false)
        saveDefaultConfig()

        val registry = TranslationRegistry.create(Key.key("steamwar:tntleague"))

        val bundleDe = ResourceBundle.getBundle("de.steamwar.tntleague.TNTLeague", Locale.GERMAN, UTF8ResourceBundleControl())
        val bundleEn = ResourceBundle.getBundle("de.steamwar.tntleague.TNTLeague", Locale.US, UTF8ResourceBundleControl())
        registry.defaultLocale(Locale.US)

        registry.registerAll(Locale.GERMAN, bundleDe, true)
        registry.registerAll(Locale.US, bundleEn, true)

        GlobalTranslator.translator().addSource(registry)

        server.pluginManager.registerEvents(LobbyListener, this)
        server.pluginManager.registerEvents(GlobalListener, this)

        logger.info("TNTLeague enabled")

        InviteCommand.register()
        AcceptCommand.register()
        RemoveCommand.register()
        LeaveCommand.register()
    }
}
