greenknight52._68625

Make a Minecraft plugin that allows custom heart with different effects but you have to use one of your hearts to make it

And make it so it shows the heart and the number next to it above the players head and make it to actually craft the custom hearts you need to /withdraw heart and when you craft a custom heart right click and it will be in your health bar and each heart gives an ability and the hearts have different colors

Kodari AI
KodariJul 3 at 8:09 pm 4
CustomHeartsPlugin
A Minecraft plugin that adds custom hearts with unique abilities. Players can /withdraw heart to sacrifice a heart and receive a Heart Essence, which is used to craft colored custom hearts. Each heart type grants a passive potion effect (Strength, Speed, Regeneration, Resistance, Jump, Fire Resistance). Custom hearts show in the health bar, and an armor stand display above the player's head shows the total custom heart count.

Creating all project files:

greenknight52._68625

The compilation failed with this error:

code
[ERROR] Kotlin compilation failed
src/main/kotlin/com/customhearts/CustomHeartsPlugin.kt:43:32: error: this declaration needs opt-in. Its usage must be marked with '@kotlin.ExperimentalStdlibApi' or '@OptIn(kotlin.ExperimentalStdlibApi::class)'
src/main/kotlin/com/customhearts/CustomHeartsPlugin.kt:93:26: error: this declaration needs opt-in. Its usage must be marked with '@kotlin.ExperimentalStdlibApi' or '@OptIn(kotlin.ExperimentalStdlibApi::class)'
src/main/kotlin/com/customhearts/HeartDisplay.kt:14:40: error: overload resolution ambiguity between candidates:
src/main/kotlin/com/customhearts/HeartListener.kt:50:33: error: overload resolution ambiguity between candidates:
src/main/kotlin/com/customhearts/HeartType.kt:18:26: error: unresolved reference 'INCREASE_DAMAGE'.
src/main/kotlin/com/customhearts/HeartType.kt:42:26: error: unresolved reference 'DAMAGE_RESISTANCE'.
src/main/kotlin/com/customhearts/HeartType.kt:50:26: error: unresolved reference 'JUMP'.

Please fix this error by creating a new artifact with the corrected code.

Kodari AI
KodariJul 3 at 8:10 pm 2

Let me read the files to fix all the errors

Fixing all compilation errors — outdated PotionEffectType names, Kotlin experimental API, and scheduler overload ambiguity

Now let me fix the scheduler ambiguity and the experimental lowercase() call

Now let me check the remaining files for any other potential issues:

I see args[0].lowercase() in HeartCommand.kt also needs fixing

All 5 files fixed. Compilation errors should be resolved:

Error
Fix
INCREASE_DAMAGE
→ renamed to
STRENGTH
PotionEffectType.STRENGTH
DAMAGE_RESISTANCE
→ renamed to
RESISTANCE
PotionEffectType.RESISTANCE
JUMP
→ renamed to
JUMP_BOOST
PotionEffectType.JUMP_BOOST
HeartType.entries
→
HeartType.values()
entries
is deprecated/experimental
.lowercase()
→
.toLowerCase()
lowercase()
requires opt-in in older Kotlin
Lambda overload ambiguity (
{ ... }
) →
Runnable { ... }
Bukkit scheduler has multiple overloads matching lambdas

All patches applied. Should be good to build now.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle.kts
manifest.kod
Code
11 505
src/main/kotlin/com/customhearts/HeartManager.kt
package com.customhearts

import org.bukkit.configuration.file.YamlConfiguration
import org.bukkit.entity.Player
import org.bukkit.potion.PotionEffect
import java.io.File
import java.util.UUID

class HeartManager(private val plugin: CustomHeartsPlugin) {

    private val playerDataMap = mutableMapOf<UUID, PlayerData>()
    private val dataFile: File = File(plugin.dataFolder, "heartdata.yml")

    fun getData(player: Player): PlayerData {
        return playerDataMap.getOrPut(player.uniqueId) { PlayerData() }
    }

    fun loadData() {
        if (!dataFile.exists()) return
        val config = YamlConfiguration.loadConfiguration(dataFile)
        for (key in config.getKeys(false)) {
            try {
                val uuid = UUID.fromString(key)
                val withdrawn = config.getInt("$key.withdrawn", 0)
                val hearts = config.getStringList("$key.hearts")
                val heartMap = mutableMapOf<HeartType, Int>()
                for (heartStr in hearts) {
                    val parts = heartStr.split(":")
                    if (parts.size == 2) {
                        try {
                            val type = HeartType.valueOf(parts[0])
                            val count = parts[1].toInt()
                            heartMap[type] = count
                        } catch (_: Exception) {
                            plugin.logger.warning("Failed to parse heart data: $heartStr")
                        }
                    }
                }
                playerDataMap[uuid] = PlayerData(withdrawn, heartMap)
            } catch (_: Exception) {
                plugin.logger.warning("Failed to parse player data key: $key")
            }
        }
        plugin.logger.info("Loaded ${playerDataMap.size} player data entries")
    }

    fun saveData() {
        val config = YamlConfiguration()
        for ((uuid, data) in playerDataMap) {
            config.set("$uuid.withdrawn", data.withdrawnCount)
            val hearts = data.activeHearts.map { (type, count) -> "${type.name}:$count" }
            config.set("$uuid.hearts", hearts)
        }
        try {
            config.save(dataFile)
        } catch (e: Exception) {
            plugin.logger.severe("Failed to save player data: ${e.message}")
        }
    }

    fun withdrawHeart(player: Player): Boolean {
        val data = getData(player)
        val currentMax = calculateMaxHealth(data)

        if (currentMax <= 2.0) {
            player.sendMessage("§cYou cannot withdraw any more hearts!")
            return false
        }

        val newData = data.copy(withdrawnCount = data.withdrawnCount + 1)
        playerDataMap[player.uniqueId] = newData

        val newMax = calculateMaxHealth(newData)
        player.maxHealth = newMax
        if (player.health > newMax) {
            player.health = newMax
        }

        return true
    }

    fun equipHeart(player: Player, type: HeartType): Boolean {
        val data = getData(player)

        if (data.totalActiveHearts >= data.withdrawnCount) {
            return false
        }

        val newHearts = data.activeHearts.toMutableMap()
        newHearts[type] = (newHearts[type] ?: 0) + 1
        val newData = data.copy(activeHearts = newHearts)
        playerDataMap[player.uniqueId] = newData

        player.addPotionEffect(
            PotionEffect(type.effectType, Int.MAX_VALUE, type.effectAmplifier, false, false, true)
        )

        val newMax = calculateMaxHealth(newData)
        player.maxHealth = newMax

        return true
    }

    fun applyEffects(player: Player) {
        val data = getData(player)
        for ((type, _) in data.activeHearts) {
            player.addPotionEffect(
                PotionEffect(type.effectType, Int.MAX_VALUE, type.effectAmplifier, false, false, true)
            )
        }
        val maxHealth = calculateMaxHealth(data)
        player.maxHealth = maxHealth
        if (player.health > maxHealth) {
            player.health = maxHealth
        }
    }

    private fun calculateMaxHealth(data: PlayerData): Double {
        return 20.0 + (2.0 * (data.totalActiveHearts - data.withdrawnCount))
    }

    fun getPlayerDataMap(): Map<UUID, PlayerData> = playerDataMap
}