juliennnw

yo can you make a plugin that doesnt let you put the dragon egg in any type of chest hopper or container no matter what you can drop it and pick it up but i want it to be in players inventorys to keep it more fun but you cant burn it or drop it in the void either

Kodari AI
KodariMay 30 at 7:07 pm 4
DragonEggGuard
Protects the Dragon Egg from being stored in any container (chests, hoppers, barrels, shulker boxes, etc.) or destroyed. Players can hold and drop the egg freely, but it cannot be placed into any inventory container. The egg is also protected from fire, lava, and void damage, ensuring it always stays in a player's inventory and remains a fun item to fight over.

Planning:

  • DragonEggGuard.kt — main plugin class

  • DragonEggListener.kt — all event handling (container block, inventory move, item damage, void protection)

  • plugin.yml — manifest

  • build.gradle.kts — build config

Here’s what the plugin does:

  • Container block — InventoryClickEvent cancels any attempt to click/place the egg into a chest, hopper, barrel, shulker box, or any other container. Shift-clicking from the player’s own inventory is also blocked.

  • Drag block — InventoryDragEvent catches drag-spreading the egg into a container.

  • Hopper/automation block — InventoryMoveItemEvent stops hoppers or droppers from sucking it in automatically.

  • Destruction protection — EntityDamageEvent on the dropped item entity cancels fire, lava, void, and suffocation damage so the egg can never be destroyed.

  • Dropping allowed — players can freely drop and pick it up, keeping the PvP egg-hunt gameplay intact.

juliennnw

can you make it so that the dragon egg gives like a buff like 2 extra hearts permanent speed 1 and strength 1

Kodari AI
KodariMay 30 at 7:12 pm 8

Here’s what was added:

  • +2 hearts — applied via an AttributeModifier on GENERIC_MAX_HEALTH (+4 HP). Uses a fixed UUID so it never stacks if the check runs twice.

  • Speed I + Strength I — infinite duration potion effects, ambient flag on so there are no particle clouds spamming around the player.

  • Buff tracking — an eggHolders set tracks who currently has the egg. Buffs apply on pickup and strip on drop or disconnect. A 1-tick delayed check runs after each event so the inventory state is settled before reading it.

  • Clean removal on quit — if the player logs off holding the egg, buffs are stripped so they don’t log back in with permanent Speed/Strength and extra hearts.

juliennnw

give file

Kodari AI
KodariMay 30 at 7:13 pm 2

Here are all four files:


src/main/kotlin/com/dragonEggGuard/DragonEggGuard.kt

Kotlin
package com.dragonEggGuard

import org.bukkit.plugin.java.JavaPlugin

class DragonEggGuard : JavaPlugin() {

    override fun onEnable() {
        server.pluginManager.registerEvents(DragonEggListener(this), this)
        logger.info("DragonEggGuard enabled - the egg is protected!")
    }

    override fun onDisable() {
        logger.info("DragonEggGuard disabled.")
    }
}

src/main/kotlin/com/dragonEggGuard/DragonEggListener.kt

Kotlin
package com.dragonEggGuard

import org.bukkit.Material
import org.bukkit.attribute.Attribute
import org.bukkit.attribute.AttributeModifier
import org.bukkit.entity.Item
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.EventPriority
import org.bukkit.event.Listener
import org.bukkit.event.entity.EntityDamageEvent
import org.bukkit.event.inventory.InventoryClickEvent
import org.bukkit.event.inventory.InventoryDragEvent
import org.bukkit.event.inventory.InventoryMoveItemEvent
import org.bukkit.event.inventory.InventoryType
import org.bukkit.event.player.PlayerDropItemEvent
import org.bukkit.event.player.PlayerItemHeldEvent
import org.bukkit.event.player.PlayerPickupItemEvent
import org.bukkit.event.player.PlayerQuitEvent
import org.bukkit.inventory.PlayerInventory
import org.bukkit.plugin.java.JavaPlugin
import org.bukkit.potion.PotionEffect
import org.bukkit.potion.PotionEffectType
import org.bukkit.scheduler.BukkitRunnable
import java.util.UUID

class DragonEggListener(private val plugin: JavaPlugin) : Listener {

    companion object {
        private val HEALTH_MODIFIER_UUID: UUID = UUID.fromString("a3b4c5d6-e7f8-1234-abcd-ef0123456789")
        private const val HEALTH_MODIFIER_NAME = "dragon_egg_health"
        private const val BONUS_HEARTS = 4.0 // 2 hearts = 4 HP
    }

    private val eggHolders = mutableSetOf<UUID>()

    fun applyBuffs(player: Player) {
        if (eggHolders.contains(player.uniqueId)) return
        eggHolders.add(player.uniqueId)

        val healthAttr = player.getAttribute(Attribute.MAX_HEALTH) ?: return
        val existing = healthAttr.modifiers.firstOrNull { it.name == HEALTH_MODIFIER_NAME }
        if (existing == null) {
            healthAttr.addModifier(
                AttributeModifier(
                    HEALTH_MODIFIER_UUID,
                    HEALTH_MODIFIER_NAME,
                    BONUS_HEARTS,
                    AttributeModifier.Operation.ADD_NUMBER
                )
            )
        }

        player.addPotionEffect(PotionEffect(PotionEffectType.SPEED, Int.MAX_VALUE, 0, true, false, true))
        player.addPotionEffect(PotionEffect(PotionEffectType.STRENGTH, Int.MAX_VALUE, 0, true, false, true))
    }

    fun removeBuffs(player: Player) {
        if (!eggHolders.contains(player.uniqueId)) return
        eggHolders.remove(player.uniqueId)

        val healthAttr = player.getAttribute(Attribute.MAX_HEALTH)
        healthAttr?.modifiers
            ?.filter { it.name == HEALTH_MODIFIER_NAME }
            ?.forEach { healthAttr.removeModifier(it) }

        player.removePotionEffect(PotionEffectType.SPEED)
        player.removePotionEffect(PotionEffectType.STRENGTH)
    }

    private fun hasDragonEgg(player: Player): Boolean =
        player.inventory.any { it?.type == Material.DRAGON_EGG }

    private fun scheduleBuffCheck(player: Player) {
        object : BukkitRunnable() {
            override fun run() {
                if (!player.isOnline) return
                if (hasDragonEgg(player)) applyBuffs(player) else removeBuffs(player)
            }
        }.runTaskLater(plugin, 1L)
    }

    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
    fun onPickup(event: PlayerPickupItemEvent) {
        if (event.item.itemStack.type != Material.DRAGON_EGG) return
        scheduleBuffCheck(event.player)
    }

    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
    fun onDrop(event: PlayerDropItemEvent) {
        if (event.itemDrop.itemStack.type != Material.DRAGON_EGG) return
        scheduleBuffCheck(event.player)
    }

    @EventHandler
    fun onQuit(event: PlayerQuitEvent) {
        removeBuffs(event.player)
    }

    @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
    fun onInventoryClick(event: InventoryClickEvent) {
        val player = event.whoClicked as? Player ?: return

        val clickedInv = event.clickedInventory
        val topInv = event.view.topInventory

        val cursor = event.cursor
        val current = event.currentItem

        val isDragonEggCursor = cursor?.type == Material.DRAGON_EGG
        val isDragonEggCurrent = current?.type == Material.DRAGON_EGG

        val topIsContainer = topInv.type != InventoryType.CRAFTING &&
                topInv.type != InventoryType.PLAYER &&
                topInv !is PlayerInventory

        if (!topIsContainer) return

        if (isDragonEggCursor && clickedInv != null && clickedInv !is PlayerInventory) {
            event.isCancelled = true
            return
        }

        if (isDragonEggCurrent && event.isShiftClick && clickedInv is PlayerInventory) {
            event.isCancelled = true
            return
        }

        if (isDragonEggCurrent && clickedInv != null && clickedInv !is PlayerInventory) {
            event.isCancelled = true
        }
    }

    @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
    fun onInventoryDrag(event: InventoryDragEvent) {
        if (event.oldCursor.type != Material.DRAGON_EGG) return

        val topInv = event.view.topInventory
        val topIsContainer = topInv.type != InventoryType.CRAFTING &&
                topInv.type != InventoryType.PLAYER &&
                topInv !is PlayerInventory

        if (!topIsContainer) return

        val topSize = topInv.size
        if (event.raw

**[Generation stopped]**
juliennnw

as a jar file?

Kodari AI
KodariMay 30 at 7:13 pm 2

I can’t send you a compiled .jar file directly — I can only write and edit code. To build it yourself:

  1. Download the project files from this chat

  2. Make sure you have JDK 17+ and Gradle installed

  3. Run in the project root:

    Plain Text
    ./gradlew build
    
  4. Your jar will be at:

    Plain Text
    build/libs/DragonEggGuard-1.0.jar
    

Drop that into your server’s plugins/ folder and restart. That’s it!

If you don’t want to build it yourself, you can use a free service like replit.com or GitHub Codespaces — paste the files in and run the Gradle build command there.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle.kts
Code
4 241
src/main/kotlin/com/dragonEggGuard/DragonEggListener.kt
package com.dragonEggGuard

import org.bukkit.Material
import org.bukkit.attribute.Attribute
import org.bukkit.attribute.AttributeModifier
import org.bukkit.entity.Item
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.EventPriority
import org.bukkit.event.Listener
import org.bukkit.event.entity.EntityDamageEvent
import org.bukkit.event.inventory.InventoryClickEvent
import org.bukkit.event.inventory.InventoryDragEvent
import org.bukkit.event.inventory.InventoryMoveItemEvent
import org.bukkit.event.inventory.InventoryType
import org.bukkit.event.player.PlayerDropItemEvent
import org.bukkit.event.player.PlayerItemHeldEvent
import org.bukkit.event.player.PlayerPickupItemEvent
import org.bukkit.event.player.PlayerQuitEvent
import org.bukkit.inventory.PlayerInventory
import org.bukkit.plugin.java.JavaPlugin
import org.bukkit.potion.PotionEffect
import org.bukkit.potion.PotionEffectType
import org.bukkit.scheduler.BukkitRunnable
import java.util.UUID

class DragonEggListener(private val plugin: JavaPlugin) : Listener {

    companion object {
        private val HEALTH_MODIFIER_UUID: UUID = UUID.fromString("a3b4c5d6-e7f8-1234-abcd-ef0123456789")
        private const val HEALTH_MODIFIER_NAME = "dragon_egg_health"
        private const val BONUS_HEARTS = 4.0 // 2 hearts = 4 HP
    }

    // Track which players currently have the egg in their inventory
    private val eggHolders = mutableSetOf<UUID>()

    fun applyBuffs(player: Player) {
        if (eggHolders.contains(player.uniqueId)) return
        eggHolders.add(player.uniqueId)

        // +2 hearts (4 HP) via attribute modifier
        val healthAttr = player.getAttribute(Attribute.MAX_HEALTH) ?: return
        val existing = healthAttr.modifiers.firstOrNull { it.name == HEALTH_MODIFIER_NAME }
        if (existing == null) {
            healthAttr.addModifier(
                AttributeModifier(
                    HEALTH_MODIFIER_UUID,
                    HEALTH_MODIFIER_NAME,
                    BONUS_HEARTS,
                    AttributeModifier.Operation.ADD_NUMBER
                )
            )
        }

        // Speed 1 and Strength 1 — infinite duration (max int), ambient so no particles spam
        player.addPotionEffect(PotionEffect(PotionEffectType.SPEED, Int.MAX_VALUE, 0, true, false, true))
        player.addPotionEffect(PotionEffect(PotionEffectType.STRENGTH, Int.MAX_VALUE, 0, true, false, true))
    }

    fun removeBuffs(player: Player) {
        if (!eggHolders.contains(player.uniqueId)) return
        eggHolders.remove(player.uniqueId)

        val healthAttr = player.getAttribute(Attribute.MAX_HEALTH)
        healthAttr?.modifiers
            ?.filter { it.name == HEALTH_MODIFIER_NAME }
            ?.forEach { healthAttr.removeModifier(it) }

        player.removePotionEffect(PotionEffectType.SPEED)
        player.removePotionEffect(PotionEffectType.STRENGTH)
    }

    private fun hasDragonEgg(player: Player): Boolean =
        player.inventory.any { it?.type == Material.DRAGON_EGG }

    // Re-check buffs whenever the player's inventory changes (pick up, drop, etc.)
    private fun scheduleBuffCheck(player: Player) {
        object : BukkitRunnable() {
            override fun run() {
                if (!player.isOnline) return
                if (hasDragonEgg(player)) applyBuffs(player) else removeBuffs(player)
            }
        }.runTaskLater(plugin, 1L)
    }

    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
    fun onPickup(event: PlayerPickupItemEvent) {
        if (event.item.itemStack.type != Material.DRAGON_EGG) return
        scheduleBuffCheck(event.player)
    }

    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
    fun onDrop(event: PlayerDropItemEvent) {
        if (event.itemDrop.itemStack.type != Material.DRAGON_EGG) return
        scheduleBuffCheck(event.player)
    }

    @EventHandler
    fun onQuit(event: PlayerQuitEvent) {
        removeBuffs(event.player)
    }

    // Prevent moving the egg into any non-player inventory via click
    @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
    fun onInventoryClick(event: InventoryClickEvent) {
        val player = event.whoClicked as? Player ?: return

        val clickedInv = event.clickedInventory
        val topInv = event.view.topInventory
        val bottomInv = event.view.bottomInventory

        val cursor = event.cursor
        val current = event.currentItem

        val isDragonEggCursor = cursor?.type == Material.DRAGON_EGG
        val isDragonEggCurrent = current?.type == Material.DRAGON_EGG

        // If the top inventory is not a player inventory, it's a container
        val topIsContainer = topInv.type != InventoryType.CRAFTING &&
                topInv.type != InventoryType.PLAYER &&
                topInv !is PlayerInventory

        if (!topIsContainer) return

        // Block placing egg into the container via cursor
        if (isDragonEggCursor && clickedInv != null && clickedInv !is PlayerInventory) {
            event.isCancelled = true
            return
        }

        // Block shift-clicking egg from player inventory into container
        if (isDragonEggCurrent && event.isShiftClick && clickedInv is PlayerInventory) {
            event.isCancelled = true
            return
        }

        // Block clicking egg that's already in the container (shouldn't happen, but safety net)
        if (isDragonEggCurrent && clickedInv != null && clickedInv !is PlayerInventory) {
            event.isCancelled = true
        }
    }

    // Prevent dragging the egg into a container inventory
    @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
    fun onInventoryDrag(event: InventoryDragEvent) {
        if (event.oldCursor.type != Material.DRAGON_EGG) return

        val topInv = event.view.topInventory
        val topIsContainer = topInv.type != InventoryType.CRAFTING &&
                topInv.type != InventoryType.PLAYER &&
                topInv !is PlayerInventory

        if (!topIsContainer) return

        val topSize = topInv.size
        // If any dragged slot falls in the top (container) inventory, cancel
        val touchesContainer = event.rawSlots.any { it < topSize }
        if (touchesContainer) {
            event.isCancelled = true
        }
    }

    // Prevent hoppers or other automation from moving the egg between inventories
    @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
    fun onInventoryMoveItem(event: InventoryMoveItemEvent) {
        if (event.item.type == Material.DRAGON_EGG) {
            event.isCancelled = true
        }
    }

    // Protect the egg item entity from fire, lava, void, and any damage
    @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
    fun onEntityDamage(event: EntityDamageEvent) {
        val entity = event.entity as? Item ?: return
        if (entity.itemStack.type != Material.DRAGON_EGG) return

        when (event.cause) {
            EntityDamageEvent.DamageCause.FIRE,
            EntityDamageEvent.DamageCause.FIRE_TICK,
            EntityDamageEvent.DamageCause.LAVA,
            EntityDamageEvent.DamageCause.VOID,
            EntityDamageEvent.DamageCause.CONTACT,
            EntityDamageEvent.DamageCause.SUFFOCATION -> event.isCancelled = true
            else -> {}
        }
    }

    // Allow dropping — the dropped item entity is protected from void via onEntityDamage.
    // Buffs are removed via onDrop above.
    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
    fun onPlayerDrop(event: PlayerDropItemEvent) {
        // Dropping is allowed — no cancellation
    }
}