Kotlin Plugin

GameJoiner

Maak een Minecraft plugin gemaakt door "MaatjesCraft" (domein is maatjescraft.nl). Ik wil 1 command /game open/sluit <naam> (admins) en je kan joinen met /join <server>. Maak ook een functie waarbij als je OP hebt dat je elke game gewoon kan joinen zonder problemen. Hij moet je trouwens naar de server sturen die in de config staat en de lobby zit aan een velocity netwerk

src/main/kotlin/eu/codexe/gamejoinor/commands/GameCommand.kt
package eu.codexe.gamejoinor.commands

import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender
import org.bukkit.command.TabCompleter
import org.bukkit.entity.Player
import eu.codexe.gamejoinor.GameJoiner
import eu.codexe.gamejoinor.config.PluginConfig
import eu.codexe.gamejoinor.managers.GameManager
import eu.codexe.gamejoinor.utils.sendColoredMessage

class GameCommand(private val plugin: GameJoiner) : CommandExecutor, TabCompleter {

    override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
        if (!sender.isOp) {
            sender.sendColoredMessage(PluginConfig.getMessage("no-permission"))
            return true
        }

        if (args.isEmpty()) {
            sender.sendColoredMessage(PluginConfig.getMessage("invalid-args", "command" to "game", "args" to "open/sluit <naam>"))
            return true
        }

        val action = args[0].lowercase()
        val gameName = if (args.size > 1) args[1].lowercase() else ""

        if (gameName.isEmpty()) {
            sender.sendColoredMessage(PluginConfig.getMessage("invalid-args", "command" to "game", "args" to "open/sluit <naam>"))
            return true
        }

        val games = PluginConfig.getGames()
        if (!games.containsKey(gameName)) {
            sender.sendColoredMessage(PluginConfig.getMessage("game-not-found", "game" to gameName))
            return true
        }

        when (action) {
            "open", "openen" -> {
                if (GameManager.isOpen(gameName)) {
                    sender.sendColoredMessage(PluginConfig.getMessage("game-already-open"))
                    return true
                }
                GameManager.openGame(gameName)
                sender.sendColoredMessage(PluginConfig.getMessage("game-opened", "game" to gameName))
            }
            "sluit", "sluiten", "close" -> {
                if (!GameManager.isOpen(gameName)) {
                    sender.sendColoredMessage(PluginConfig.getMessage("game-already-closed"))
                    return true
                }
                GameManager.closeGame(gameName)
                sender.sendColoredMessage(PluginConfig.getMessage("game-closed", "game" to gameName))
            }
            else -> {
                sender.sendColoredMessage(PluginConfig.getMessage("invalid-args", "command" to "game", "args" to "open/sluit <naam>"))
            }
        }