Gta

I want a plugin where I can Do /spawn to teleport to spawn /setspawn to set spawn configureable msg countdown to 5 cancel on move it damage In msg make this

&a⚡ Teleporting in &b5 &aseconds.

Kodari AI
KodariFri at 8:17 pm 2
SpawnTeleport
A Minecraft Kotlin plugin providing spawn teleportation commands. Players use /spawn to teleport to the configured spawn location, while admins use /setspawn to set it. Features a configurable countdown timer (default 5 seconds) that cancels if the player moves or takes damage. Displays a customizable color-coded countdown message using Minecraft color codes, with the countdown number highlighted in blue. Includes config file for adjusting countdown duration and messages.

Created /spawn and /setspawn with a configurable 5-second countdown. Moving or taking damage cancels the teleport.

Messages and countdown length can be changed in config.yml. /setspawn is restricted to operators by default.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle.kts
manifest.kod
settings.gradle.kts
Code
6 155
src/main/kotlin/com/kodari/spawn/SpawnTeleport.kt
package com.kodari.spawn

import org.bukkit.ChatColor
import org.bukkit.Location
import org.bukkit.command.Command
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.entity.EntityDamageEvent
import org.bukkit.event.player.PlayerMoveEvent
import org.bukkit.event.player.PlayerQuitEvent
import org.bukkit.plugin.java.JavaPlugin
import org.bukkit.scheduler.BukkitTask
import java.util.UUID

class SpawnTeleport : JavaPlugin(), Listener {
    private val pending = mutableMapOf<UUID, BukkitTask>()

    override fun onEnable() {
        saveDefaultConfig()
        server.pluginManager.registerEvents(this, this)
    }

    override fun onDisable() {
        pending.values.forEach { it.cancel() }
        pending.clear()
    }

    override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
        if (sender !is Player) {
            sender.sendMessage(message("players-only"))
            return true
        }

        if (command.name.equals("setspawn", ignoreCase = true)) {
            config.set("spawn", sender.location)
            saveConfig()
            sender.sendMessage(message("spawn-set"))
            return true
        }

        val destination = config.getLocation("spawn")
        if (destination == null || destination.world == null) {
            sender.sendMessage(message("spawn-not-set"))
            return true
        }
        if (pending.containsKey(sender.uniqueId)) {
            sender.sendMessage(message("already-counting"))
            return true
        }

        var remaining = config.getInt("countdown-seconds", 5).coerceAtLeast(0)
        if (remaining == 0) {
            teleport(sender, destination)
            return true
        }
        sender.sendMessage(message("countdown").replace("%seconds%", remaining.toString()))
        val task = server.scheduler.runTaskTimer(this, Runnable {
            remaining--
            if (remaining <= 0) {
                pending.remove(sender.uniqueId)?.cancel()
                teleport(sender, destination)
            } else {
                sender.sendMessage(message("countdown").replace("%seconds%", remaining.toString()))
            }
        }, 20L, 20L)
        pending[sender.uniqueId] = task
        return true
    }

    @EventHandler(ignoreCancelled = true)
    fun onMove(event: PlayerMoveEvent) {
        val to = event.to ?: return
        val from = event.from
        if (from.world != to.world || from.x != to.x || from.y != to.y || from.z != to.z) {
            cancel(event.player, "cancelled-move")
        }
    }

    @EventHandler(ignoreCancelled = true)
    fun onDamage(event: EntityDamageEvent) {
        val player = event.entity as? Player ?: return
        cancel(player, "cancelled-damage")
    }

    @EventHandler
    fun onQuit(event: PlayerQuitEvent) {
        pending.remove(event.player.uniqueId)?.cancel()
    }

    private fun cancel(player: Player, messageKey: String) {
        val task = pending.remove(player.uniqueId) ?: return
        task.cancel()
        player.sendMessage(message(messageKey))
    }

    private fun teleport(player: Player, destination: Location) {
        if (player.teleport(destination)) {
            player.sendMessage(message("teleported"))
        }
    }

    private fun message(key: String): String =
        ChatColor.translateAlternateColorCodes('&', config.getString("messages.$key", "") ?: "")
}