package io.stellarfrontier.stellarplugin

import io.stellarfrontier.stellarplugin.commands.LinkCommand
import io.stellarfrontier.stellarplugin.listeners.GameListener
import org.bukkit.plugin.java.JavaPlugin
import java.net.URI

class StellarPlugin : JavaPlugin() {

    private var socketClient: SocketClient? = null

    override fun onEnable() {
        // Plugin startup logic
        logger.info("StellarPlugin is enabling...")

        // Connect to WebSocket
        try {
            val uri = URI("ws://localhost:5000/socket.io/?EIO=4&transport=websocket")
            socketClient = SocketClient(uri, logger)
            socketClient?.connect()
        } catch (e: Exception) {
            logger.severe("Failed to connect to WebSocket: ${e.message}")
        }

        // Register Listeners
        // GameListener is superseded by UniversalListener
        io.stellarfrontier.stellarplugin.listeners.UniversalListener(this, socketClient!!)

        // Register Commands
        getCommand("link")?.setExecutor(LinkCommand())
        
        logger.info("StellarPlugin enabled!")
    }

    override fun onDisable() {
        // Plugin shutdown logic
        socketClient?.shutdown()
        logger.info("StellarPlugin disabled!")
    }
}
