davidnej novacek

Create plugin like Annihilation but faster and more modern

Kodari AI
KodariAug 31 at 4:30 pm 2
AnnihilationReborn
AnnihilationReborn is a fast-paced, modern Minecraft minigame plugin inspired by classic Annihilation. Teams of players must destroy the enemy Nexus while defending their own. The plugin features a streamlined game loop with rapid respawns, quick resource gathering, and accelerated phase progression. It includes team management, Nexus health tracking, shop systems for gear and upgrades, and dynamic map zones. Modern mechanics such as instant-action spawns, reduced build times, and enhanced combat pacing deliver a quicker, more engaging experience. The plugin handles game state management, player statistics, and configurable settings for server administrators.
  1. Scaffold a Kotlin/Paper plugin with a fast team-based Annihilation match loop.

  2. Add nexus objectives, PvP/build rules, respawns, elimination handling, and live sidebar status.

  3. Add player/admin commands plus configurable arena locations and match settings.

Built a Kotlin/Paper Annihilation plugin from scratch.

Features:

  • Team-based matches: Red, Blue, Green, Yellow

  • Nexus health and enemy Nexus destruction

  • Automatic team balancing

  • Countdown and match lifecycle

  • PvP with friendly-fire prevention

  • Respawns and team elimination

  • Spectator mode after Nexus destruction

  • Live sidebar scoreboard

  • Configurable spawns and Nexus locations

  • Commands:

    • /annihilation join [team]

    • /annihilation leave

    • /annihilation status

    • /annihilation start

    • /annihilation stop

    • /annihilation setspawn <team>

    • /annihilation setnexus <team>

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle.kts
manifest.kod
settings.gradle.kts
Code
11 588
src/main/kotlin/dev/kodari/annihilation/MatchManager.kt
package dev.kodari.annihilation

import dev.kodari.annihilation.model.GameState
import dev.kodari.annihilation.model.Team
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.format.NamedTextColor
import org.bukkit.Bukkit
import org.bukkit.GameMode
import org.bukkit.Location
import org.bukkit.entity.Player
import org.bukkit.scheduler.BukkitRunnable
import org.bukkit.scheduler.BukkitTask
import org.bukkit.scoreboard.Criteria
import org.bukkit.scoreboard.DisplaySlot

class MatchManager(private val plugin: AnnihilationPlugin) {
    var state: GameState = GameState.WAITING
        private set

    private val playerTeams = mutableMapOf<java.util.UUID, Team>()
    private val eliminatedTeams = mutableSetOf<Team>()
    private val nexusHealth = Team.values().associateWith { plugin.config.getInt("game.nexus-health", 100) }.toMutableMap()
    private var countdownTask: BukkitTask? = null

    private val minPlayers: Int
        get() = plugin.config.getInt("game.min-players", 2).coerceAtLeast(2)

    private val countdownSeconds: Int
        get() = plugin.config.getInt("game.countdown-seconds", 15).coerceAtLeast(3)

    fun join(player: Player, requestedTeam: Team?): Boolean {
        if (state != GameState.WAITING) return false
        if (playerTeams.containsKey(player.uniqueId)) return false

        val team = requestedTeam ?: Team.values().minByOrNull { membersOf(it).size } ?: Team.RED
        playerTeams[player.uniqueId] = team
        player.sendMessage(Component.text("You joined the ", NamedTextColor.GRAY)
            .append(Component.text(team.displayName, team.textColor))
            .append(Component.text(" team.", NamedTextColor.GRAY)))
        Bukkit.broadcast(Component.text("${player.name} joined ${team.displayName}.", team.textColor))

        if (playerTeams.size >= minPlayers && activeTeams().size >= 2) beginCountdown()
        updateScoreboards()
        return true
    }

    fun leave(player: Player): Boolean {
        if (playerTeams.remove(player.uniqueId) == null) return false
        player.scoreboard = Bukkit.getScoreboardManager().mainScoreboard
        if (state == GameState.COUNTDOWN && (playerTeams.size < minPlayers || activeTeams().size < 2)) {
            cancelCountdown()
            Bukkit.broadcast(Component.text("The countdown was cancelled; more players are needed.", NamedTextColor.RED))
            state = GameState.WAITING
        } else if (state == GameState.RUNNING) {
            checkWinner()
        }
        updateScoreboards()
        return true
    }

    fun handleQuit(player: Player) {
        if (playerTeams.containsKey(player.uniqueId)) leave(player)
    }

    fun startNow(): Boolean {
        if (state != GameState.WAITING || playerTeams.size < minPlayers || activeTeams().size < 2) return false
        startMatch()
        return true
    }

    fun stopMatch() {
        cancelCountdown()
        if (playerTeams.isNotEmpty()) Bukkit.broadcast(Component.text("The Annihilation match was stopped.", NamedTextColor.RED))
        resetMatch()
    }

    fun shutdown() {
        cancelCountdown()
        playerTeams.keys.mapNotNull { Bukkit.getPlayer(it) }.forEach {
            it.scoreboard = Bukkit.getScoreboardManager().mainScoreboard
        }
    }

    fun isParticipant(player: Player): Boolean = playerTeams.containsKey(player.uniqueId)

    fun teamOf(player: Player): Team? = playerTeams[player.uniqueId]

    fun nexusTeamAt(location: Location): Team? = Team.values().firstOrNull { team ->
        configuredLocation("game.arena.nexus.${team.id}")?.sameBlock(location) == true
    }

    fun respawnLocation(team: Team): Location? = configuredLocation("game.arena.spawns.${team.id}")

    fun damageNexus(team: Team, attacker: Player) {
        if (state != GameState.RUNNING || team in eliminatedTeams) return
        val attackerTeam = teamOf(attacker) ?: return
        if (attackerTeam == team) return

        val damage = plugin.config.getInt("game.nexus-damage", 10).coerceAtLeast(1)
        val remaining = (nexusHealth.getValue(team) - damage).coerceAtLeast(0)
        nexusHealth[team] = remaining
        Bukkit.broadcast(Component.text("${attacker.name} damaged the ${team.displayName} Nexus! ", NamedTextColor.GOLD)
            .append(Component.text("$remaining HP", team.textColor)))
        Bukkit.getOnlinePlayers().forEach { it.sendActionBar(Component.text("${team.displayName} Nexus: $remaining HP", team.textColor)) }
        updateScoreboards()

        if (remaining == 0) eliminate(team)
    }

    fun setSpawn(player: Player, team: Team) {
        saveLocation("game.arena.spawns.${team.id}", player.location)
    }

    fun setNexus(player: Player, team: Team) {
        saveLocation("game.arena.nexus.${team.id}", player.location.block.location)
    }

    fun statusLines(): List<Component> = buildList {
        add(Component.text("Annihilation: ${state.label}", NamedTextColor.AQUA))
        add(Component.text("Players: ${playerTeams.size}/$minPlayers minimum", NamedTextColor.GRAY))
        Team.values().forEach { team ->
            val members = membersOf(team).size
            val nexus = nexusHealth.getValue(team)
            val suffix = if (team in eliminatedTeams) " ELIMINATED" else " $nexus HP"
            add(Component.text("${team.displayName}: $members players |$suffix", team.textColor))
        }
    }

    private fun beginCountdown() {
        if (state != GameState.WAITING) return
        state = GameState.COUNTDOWN
        var remaining = countdownSeconds
        countdownTask = object : BukkitRunnable() {
            override fun run() {
                if (playerTeams.size < minPlayers || activeTeams().size < 2) {
                    cancel()
                    countdownTask = null
                    state = GameState.WAITING
                    Bukkit.broadcast(Component.text("The countdown was cancelled; more players are needed.", NamedTextColor.RED))
                    updateScoreboards()
                    return
                }
                if (remaining <= 0) {
                    cancel()
                    countdownTask = null
                    startMatch()
                    return
                }
                if (remaining <= 5 || remaining % 5 == 0) {
                    Bukkit.broadcast(Component.text("Match starts in $remaining...", NamedTextColor.YELLOW))
                }
                remaining--
            }
        }.runTaskTimer(plugin, 0L, 20L)
        updateScoreboards()
    }

    private fun startMatch() {
        state = GameState.RUNNING
        eliminatedTeams.clear()
        Team.values().forEach { nexusHealth[it] = plugin.config.getInt("game.nexus-health", 100) }
        playerTeams.keys.mapNotNull { Bukkit.getPlayer(it) }.forEach { player ->
            val team = teamOf(player) ?: return@forEach
            player.gameMode = GameMode.SURVIVAL
            player.inventory.clear()
            player.health = player.maxHealth
            player.foodLevel = 20
            player.saturation = 20f
            player.fireTicks = 0
            respawnLocation(team)?.let(player::teleport)
            player.sendMessage(Component.text("Fight! Destroy enemy Nexuses and be the last team standing.", NamedTextColor.GREEN))
        }
        Bukkit.broadcast(Component.text("The Annihilation match has begun!", NamedTextColor.GREEN))
        updateScoreboards()
    }

    private fun eliminate(team: Team) {
        eliminatedTeams += team
        Bukkit.broadcast(Component.text("${team.displayName} has been eliminated!", team.textColor))
        membersOf(team).forEach { player ->
            player.gameMode = GameMode.SPECTATOR
            player.sendMessage(Component.text("Your Nexus is gone. You are now spectating.", NamedTextColor.GRAY))
        }
        checkWinner()
    }

    private fun checkWinner() {
        if (state != GameState.RUNNING) return
        val active = activeTeams()
        if (active.size > 1) return
        val winner = active.firstOrNull()
        state = GameState.ENDING
        Bukkit.broadcast(if (winner == null) {
            Component.text("The match ended without a winner.", NamedTextColor.RED)
        } else {
            Component.text("${winner.displayName} wins the Annihilation match!", winner.textColor)
        })
        object : BukkitRunnable() {
            override fun run() = resetMatch()
        }.runTaskLater(plugin, 100L)