Dominic

okay so i need a plugin for my server 26.3 that has 2 commands /unban (player name) and /Life (amount) (player name) and these are self explainatory and only ops can use them anyway i want there to be a counter above the hearts, hotbar, and hunger big enough so you can see and its set to 1 base size and theres a command for everyone /Lifebar (size) to change it and you have to lives shown on the bar if you die once u lose a life if you die again itll ban that player also make it so there is a command /Nolife (player name) and itll make it so that player wont lose lifes for ever unless this command is used /Yeslife (same player name) and itll disable it and add more also those last two commands are op only so yea make it good its the dual life plugin and also make two crafting recipes Revive Beacon (image/model: normal becon): recipe: ABC: diamond block, dirt, diamond block DEF: dirt, soul sand, dirt GHI: diamond block, dirt, diamond block make this recipe always unlocked in the menu and work with /give and creative menu and the second is the Revive (image/model: wooden sword): recipe: ABC: Iron Sword, diamond, Iron sword DEF: diamond, netherack, diamond GHI: iron sword, diamond, iron sword and for this one make it the same setting as last like always unlocked and stuff also make both have to be in THAT speicific order

Kodari AI
KodariOct 1 at 11:28 pm 1
DualLifeRevive
A Minecraft Kotlin plugin for version 1.26.3 implementing a dual-life system. Players start with two lives displayed via a large, configurable counter above hearts, hunger, and hotbar (base size 1, adjustable with /Lifebar for all players). Dying once costs a life; dying twice triggers an automatic ban. OP-only commands include /unban to restore players, /Life to set lives, /Nolife to grant infinite lives, and /Yeslife to revoke that immunity. Two custom crafting recipes (Revive Beacon and Revive sword) are always unlocked and work with /give and creative menus, requiring exact ingredient patterns.
  • Build the Paper 26.3 Kotlin plugin and persistent lives/ban state.

  • Add the op/admin commands, public HUD-size command, and death protection flow.

  • Register and unlock both ordered recipes, with revive items usable through /give and the recipe menu.

Created DualLife for Paper 26.3.

  • Players start with 2 lives. Each unprotected death removes one; reaching 0 bans them.

  • Added op-only /life <amount> <player>, /unban <player>, /nolife <player>, and /yeslife <player>. /yeslife removes protection and grants one life.

  • /lifebar <size> is public; the lives counter appears in the action bar above the hotbar and defaults to size 1.

  • Added both exact-order recipes and unlocks them for every player. Revive items can also be given with /give <player|@s|@p|@a> dual_life:revive or dual_life:revive_beacon. A Revive item restores the most recently eliminated player; a placed Revive Beacon uses a Revive item to do the same.

The recipes are unlocked in the recipe book. The plugin API doesn’t add new entries to Minecraft’s built-in Creative item tabs; the give syntax provides the custom-tagged items there instead. /lifebar changes the number of heart markers—the client doesn’t expose action-bar font scaling to plugins.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle.kts
manifest.kod
Code
4 505
src/main/kotlin/com/kodari/duallife/DualLifePlugin.kt
package com.kodari.duallife

import net.kyori.adventure.text.Component
import org.bukkit.Bukkit
import org.bukkit.Material
import org.bukkit.NamespacedKey
import org.bukkit.block.Beacon
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 org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.block.Action
import org.bukkit.event.block.BlockPlaceEvent
import org.bukkit.event.entity.PlayerDeathEvent
import org.bukkit.event.player.PlayerCommandPreprocessEvent
import org.bukkit.event.player.PlayerInteractEvent
import org.bukkit.event.player.PlayerJoinEvent
import org.bukkit.inventory.EquipmentSlot
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.ShapedRecipe
import org.bukkit.persistence.PersistentDataType
import org.bukkit.plugin.java.JavaPlugin
import org.bukkit.scheduler.BukkitTask
import org.bukkit.configuration.file.YamlConfiguration
import java.io.File
import java.io.IOException
import java.util.UUID

class DualLifePlugin : JavaPlugin(), Listener, CommandExecutor, TabCompleter {
    private data class PlayerState(
        var name: String,
        var lives: Int = STARTING_LIVES,
        var lifeProtected: Boolean = false,
        var barSize: Int = 1
    )

    private val states = mutableMapOf<UUID, PlayerState>()
    private lateinit var beaconItemKey: NamespacedKey
    private lateinit var reviveItemKey: NamespacedKey
    private lateinit var beaconBlockKey: NamespacedKey
    private lateinit var beaconRecipeKey: NamespacedKey
    private lateinit var reviveRecipeKey: NamespacedKey
    private lateinit var dataFile: File
    private var lastEliminated: Pair<UUID, String>? = null
    private var hudTask: BukkitTask? = null

    override fun onEnable() {
        beaconItemKey = NamespacedKey(this, "revive_beacon")
        reviveItemKey = NamespacedKey(this, "revive")
        beaconBlockKey = NamespacedKey(this, "revive_beacon")
        beaconRecipeKey = NamespacedKey(this, "revive_beacon")
        reviveRecipeKey = NamespacedKey(this, "revive")
        dataFile = File(dataFolder, "lives.yml")

        loadStates()
        registerRecipes()
        listOf("life", "unban", "nolife", "yeslife", "lifebar").forEach { name ->
            getCommand(name)?.setExecutor(this)
            getCommand(name)?.tabCompleter = this
        }
        server.pluginManager.registerEvents(this, this)
        server.onlinePlayers.forEach(::unlockRecipes)
        hudTask = server.scheduler.runTaskTimer(this, Runnable {
            server.onlinePlayers.forEach(::sendLivesBar)
        }, 1L, 20L)
    }

    override fun onDisable() {
        hudTask?.cancel()
        saveStates()
    }

    override fun onCommand(
        sender: CommandSender,
        command: Command,
        label: String,
        args: Array<out String>
    ): Boolean {
        when (command.name.lowercase()) {
            "lifebar" -> {
                val player = sender as? Player ?: run {
                    sender.sendMessage("Only players can change their lives bar.")
                    return true
                }
                val size = args.firstOrNull()?.toIntOrNull()
                if (size == null || size !in 1..10) {
                    player.sendMessage("Usage: /lifebar <size 1-10>")
                    return true
                }
                stateFor(player.uniqueId, player.name).barSize = size
                saveStates()
                sendLivesBar(player)
                player.sendMessage("Lives bar size set to $size.")
                return true
            }
        }

        if (!sender.isOp) {
            sender.sendMessage("Only operators can use this command.")
            return true
        }

        when (command.name.lowercase()) {
            "life" -> {
                if (args.size != 2) {
                    sender.sendMessage("Usage: /life <amount> <player>")
                    return true
                }
                val amount = args[0].toIntOrNull()
                if (amount == null || amount < 0) {
                    sender.sendMessage("Life amount must be 0 or greater.")
                    return true
                }
                val target = Bukkit.getOfflinePlayer(args[1])
                val state = stateFor(target.uniqueId, target.name ?: args[1])
                state.lives = amount
                saveStates()
                sender.sendMessage("Set ${state.name}'s lives to $amount.")
                target.player?.let(::sendLivesBar)
                return true
            }
            "unban" -> {
                if (args.size != 1) {
                    sender.sendMessage("Usage: /unban <player>")
                    return true
                }
                val name = args[0]
                if (!PLAYER_NAME_PATTERN.matches(name)) {
                    sender.sendMessage("Invalid player name.")
                    return true
                }
                pardonPlayer(name)
                val target = Bukkit.getOfflinePlayer(name)
                val state = stateFor(target.uniqueId, target.name ?: name)
                if (state.lives < 1) state.lives = 1
                saveStates()
                sender.sendMessage("Unbanned $name.")
                return true
            }
            "nolife" -> {
                if (args.size != 1) {
                    sender.sendMessage("Usage: /nolife <player>")
                    return true
                }
                val target = Bukkit.getOfflinePlayer(args[0])
                val state = stateFor(target.uniqueId, target.name ?: args[0])
                state.lifeProtected = true
                saveStates()
                sender.sendMessage("${state.name} will no longer lose lives until /yeslife is used.")
                return true
            }
            "yeslife" -> {
                if (args.size != 1) {
                    sender.sendMessage("Usage: /yeslife <player>")
                    return true
                }
                val target = Bukkit.getOfflinePlayer(args[0])
                val state = stateFor(target.uniqueId, target.name ?: args[0])
                state.lifeProtected = false
                if (state.lives < Int.MAX_VALUE) state.lives++
                saveStates()
                sender.sendMessage("${state.name}'s protection is disabled and they gained one life (${state.lives}).")
                target.player?.let(::sendLivesBar)
                return true
            }
        }
        return false
    }

    override fun onTabComplete(
        sender: CommandSender,
        command: Command,
        alias: String,
        args: Array<out String>
    ): List<String> {
        if (command.name.equals("lifebar", true)) {
            return if (args.size == 1) (1..10).map(Int::toString).filter { it.startsWith(args[0]) } else emptyList()
        }
        return when {
            command.name.equals("life", true) && args.size == 1 -> listOf("1", "2", "3", "5", "10")
            args.size == 1 -> Bukkit.getOnlinePlayers().map(Player::getName).filter { it.startsWith(args[0], true) }
            command.name.equals("life", true) && args.size == 2 -> Bukkit.getOnlinePlayers().map(Player::getName)
            else -> emptyList()
        }
    }

    @EventHandler
    fun onJoin(event: PlayerJoinEvent) {
        val state = stateFor(event.player.uniqueId, event.player.name)
        unlockRecipes(event.player)
        if (state.lives <= 0) {
            banPlayer(event.player.name, "You have no lives remaining.")
            server.scheduler.runTask(this, Runnable {
                event.player.kick(Component.text("You have no lives remaining."))
            })
            return
        }