Leo Flanagan

make a plugin for paper 1.21.11 where if someone dies they drop a blaze rod with a cooldown of 30 seconds so if someone dies they drop it and die 10 seconds after they dont

Kodari AI
KodariOct 27 at 5:53 pm 1
DeathRodDrop
A Paper 1.21.11 plugin that makes players drop a blaze rod upon death. Each player has a 30-second cooldown between drops, so if they die again within 10 seconds of the previous death, no rod is dropped. The plugin tracks cooldowns per player using a HashMap with timestamps, checks the time difference on death, and spawns the blaze rod item at the death location when eligible. It registers a PlayerDeathEvent listener and provides configurable messages for the cooldown system.

What should happen 10 seconds after a player dies? I can make the blaze rod drop on death with a 30-second cooldown, but I’m not sure what you mean by “die 10 seconds after they don’t”—for example, should they die again if they don’t pick up the rod?

Leo Flanagan

no i mean there is a cooldown of it dropping

Kodari AI
KodariOct 27 at 6:05 pm 1
  1. Add a death listener that drops one blaze rod.

  2. Track a separate 30-second drop cooldown for each player.

  3. Register the plugin for Paper 1.21.

Added the death-drop plugin: a player drops one blaze rod on death, with a separate 30-second cooldown for each player.

Leo Flanagan

make it so when you kill someone it goes straighit in your inventory but if you dont have space it just drops on the floor

Kodari AI
KodariNov 9 at 8:05 pm 1
  1. Award the rod to the player who gets the kill, not to the person who died.

  2. Keep the 30-second cooldown per killer; drop the rod at their feet if their inventory is full.

Now, when a player kills someone, the killer receives a blaze rod. The 30-second cooldown is per killer; if their inventory is full, the rod drops at their location. Uncredited deaths don’t award a rod.

Kodari can make mistakes. Review important code before using.
Files
src
Code
2 55
src/main/java/com/kodari/deathrod/DeathRodPlugin.java
package com.kodari.deathrod;

import com.cryptomorin.xseries.XMaterial;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public final class DeathRodPlugin extends JavaPlugin implements Listener {
    private static final long DROP_COOLDOWN_NANOS = 30_000_000_000L;

    private final Map<UUID, Long> lastDropTimes = new HashMap<>();

    @Override
    public void onEnable() {
        getServer().getPluginManager().registerEvents(this, this);
    }

    @EventHandler
    public void onPlayerDeath(PlayerDeathEvent event) {
        Player killer = event.getEntity().getKiller();
        if (killer == null) {
            return;
        }

        ItemStack blazeRod = XMaterial.matchXMaterial("BLAZE_ROD")
                .map(XMaterial::parseItem)
                .orElse(null);
        if (blazeRod == null) {
            return;
        }

        UUID playerId = killer.getUniqueId();
        long now = System.nanoTime();
        Long lastDropTime = lastDropTimes.get(playerId);
        if (lastDropTime != null && now - lastDropTime < DROP_COOLDOWN_NANOS) {
            return;
        }

        lastDropTimes.put(playerId, now);
        Map<Integer, ItemStack> leftovers = killer.getInventory().addItem(blazeRod);
        leftovers.values().forEach(item -> killer.getWorld().dropItemNaturally(killer.getLocation(), item));
    }
}