markvix

Make a plugin for a special weapon called "Soul Slayer"

Kodari AI
KodariOct 5 at 12:28 am 1
SoulSlayerWeapon
A Minecraft Kotlin plugin introducing the legendary "Soul Slayer" weapon. Players craft or obtain this unique sword that drains enemy souls on hit, converting damage dealt into health and mana. The weapon features a custom glowing enchantment effect, soul particle trails, and a charged special attack that unleashes a devastating area-of-effect soul explosion when the player's soul meter is full. Includes configurable damage values, cooldowns, and soul meter display via action bar. Provides crafting recipe integration and permission-based access for server administrators.
  1. Create the Paper/Kotlin plugin setup and command registration.

  2. Add the Soul Slayer weapon, soul tracking on player kills, and bonus damage scaling up to 20 souls.

Created the Soul Slayer plugin. Use /soulslayer [player] to give out the netherite sword. Player kills with it collect up to 20 souls, each adding 0.5 bonus damage. The command requires the soulslayer.give permission, granted to operators by default.

markvix

Wait. Also create a crafting recipe for it:

Kodari AI
KodariOct 5 at 12:29 am 1
  1. Register a shaped recipe: Netherite Sword surrounded by Soul Sand and Echo Shards; crafted swords retain the Soul Slayer metadata.

Added a shaped crafting recipe: surround a Netherite Sword with four Soul Sand and four Echo Shards. It crafts a Soul Slayer with its soul-tracking metadata.

markvix

Now leme download it

Kodari AI
KodariOct 5 at 12:30 am 1

On desktop, click Compile in the top bar; on phone, tap ⋮ → Compile Project. In the window, click Compile. When it succeeds, click Download on the build or Download SoulSlayerWeapon.jar in the chat.

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

import org.bukkit.Bukkit
import org.bukkit.ChatColor
import org.bukkit.Material
import org.bukkit.NamespacedKey
import org.bukkit.command.Command
import org.bukkit.command.CommandSender
import org.bukkit.command.PluginCommand
import org.bukkit.command.TabExecutor
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.entity.EntityDamageByEntityEvent
import org.bukkit.event.entity.PlayerDeathEvent
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.ShapedRecipe
import org.bukkit.persistence.PersistentDataType
import org.bukkit.plugin.java.JavaPlugin

class SoulSlayerPlugin : JavaPlugin(), Listener, TabExecutor {
    private lateinit var soulsKey: NamespacedKey

    override fun onEnable() {
        soulsKey = NamespacedKey(this, "souls")
        server.pluginManager.registerEvents(this, this)
        registerRecipe()
        getCommand("soulslayer")?.apply {
            setExecutor(this@SoulSlayerPlugin)
            tabCompleter = this@SoulSlayerPlugin
        }
    }

    override fun onCommand(
        sender: CommandSender,
        command: Command,
        label: String,
        args: Array<out String>
    ): Boolean {
        if (args.size > 1) return false

        val target = when {
            args.isNotEmpty() -> Bukkit.getPlayerExact(args[0])
            sender is Player -> sender
            else -> null
        }

        if (target == null) {
            sender.sendMessage("${ChatColor.RED}Specify an online player: /soulslayer <player>")
            return true
        }

        target.inventory.addItem(createSoulSlayer())
        target.sendMessage("${ChatColor.DARK_PURPLE}You received the ${ChatColor.LIGHT_PURPLE}Soul Slayer${ChatColor.DARK_PURPLE}!")
        if (target != sender) {
            sender.sendMessage("${ChatColor.GREEN}Gave the Soul Slayer to ${target.name}.")
        }
        return true
    }

    override fun onTabComplete(
        sender: CommandSender,
        command: Command,
        alias: String,
        args: Array<out String>
    ): List<String> = if (args.size == 1) {
        Bukkit.getOnlinePlayers()
            .map { it.name }
            .filter { it.startsWith(args[0], ignoreCase = true) }
    } else {
        emptyList()
    }

    @EventHandler
    fun onPlayerKill(event: PlayerDeathEvent) {
        val killer = event.entity.killer ?: return
        val item = killer.inventory.itemInMainHand
        val meta = item.itemMeta ?: return
        if (!meta.persistentDataContainer.has(soulsKey, PersistentDataType.INTEGER)) return

        val souls = (meta.persistentDataContainer.get(soulsKey, PersistentDataType.INTEGER) ?: 0)
            .coerceAtMost(MAX_SOULS)
        if (souls >= MAX_SOULS) {
            killer.sendMessage("${ChatColor.DARK_PURPLE}The Soul Slayer is fully awakened.")
            return
        }

        val newSouls = souls + 1
        meta.persistentDataContainer.set(soulsKey, PersistentDataType.INTEGER, newSouls)
        updateLore(meta, newSouls)
        item.itemMeta = meta
        killer.sendMessage("${ChatColor.LIGHT_PURPLE}The Soul Slayer claimed a soul! ${ChatColor.GRAY}($newSouls/$MAX_SOULS)")
    }

    @EventHandler
    fun onSoulSlayerHit(event: EntityDamageByEntityEvent) {
        val attacker = event.damager as? Player ?: return
        val meta = attacker.inventory.itemInMainHand.itemMeta ?: return
        val souls = meta.persistentDataContainer.get(soulsKey, PersistentDataType.INTEGER) ?: return
        event.damage += souls.coerceIn(0, MAX_SOULS) * DAMAGE_PER_SOUL
    }

    private fun createSoulSlayer(): ItemStack {
        val item = ItemStack(Material.NETHERITE_SWORD)
        val meta = item.itemMeta
        meta.setDisplayName("${ChatColor.DARK_PURPLE}${ChatColor.BOLD}Soul Slayer")
        meta.persistentDataContainer.set(soulsKey, PersistentDataType.INTEGER, 0)
        updateLore(meta, 0)
        item.itemMeta = meta
        return item
    }

    private fun registerRecipe() {
        val recipe = ShapedRecipe(NamespacedKey(this, "soul_slayer"), createSoulSlayer())
        recipe.shape("ESE", "SWS", "ESE")
        recipe.setIngredient('E', Material.ECHO_SHARD)
        recipe.setIngredient('S', Material.SOUL_SAND)
        recipe.setIngredient('W', Material.NETHERITE_SWORD)
        server.addRecipe(recipe)
    }

    private fun updateLore(meta: org.bukkit.inventory.meta.ItemMeta, souls: Int) {
        val bonusDamage = souls * DAMAGE_PER_SOUL
        meta.lore = listOf(
            "${ChatColor.GRAY}A blade that grows with every soul claimed.",
            "",
            "${ChatColor.LIGHT_PURPLE}Souls: ${ChatColor.WHITE}$souls/$MAX_SOULS",
            "${ChatColor.LIGHT_PURPLE}Bonus damage: ${ChatColor.WHITE}+$bonusDamage"
        )
    }

    private companion object {
        const val MAX_SOULS = 20
        const val DAMAGE_PER_SOUL = 0.5
    }
}