package org.discord.discord

import org.bukkit.ChatColor
import org.bukkit.command.Command
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
import org.bukkit.plugin.java.JavaPlugin

class Discord : JavaPlugin() {

    private var discordLink = "discordlink.here"

    override fun onEnable() {
        // Plugin startup logic
        logger.info("Discord plugin has been enabled!")

        // Save default config
        saveDefaultConfig()

        // Load discord link from config if exists
        if (config.contains("discord-link")) {
            discordLink = config.getString("discord-link") ?: discordLink
        } else {
            // Save default link to config
            config.set("discord-link", discordLink)
            saveConfig()
        }
    }

    override fun onDisable() {
        // Plugin shutdown logic
        logger.info("Discord plugin has been disabled!")
    }

    override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
        if (command.name.equals("discord", ignoreCase = true)) {
            if (sender is Player) {
                sender.sendMessage("${ChatColor.GREEN}Tritt unseren Discord-Server bei: ${ChatColor.BLUE}${ChatColor.UNDERLINE}$discordLink")
            } else {
                sender.sendMessage("Tritt unseren Discord-Server bei: $discordLink")
            }
            return true
        }
        return false
    }
}