Abdullah Hasnain
📎 1 file 5,255 chars
📄
pasted-code-1792587054414.txt
txt 81 lines
▶
# Minecraft Plugin: Kill-to-Upgrade Mace

Develop a complete, working Minecraft Java Edition plugin called **Kill-to-Upgrade Mace** for a PvP SMP server.

## Core Concept
Every player automatically receives a mace named **Mace** when they join or respawn. Each time a player kills another player, their mace automatically upgrades to the next tier. If a player dies, their progress resets and they receive the basic Mace again.

**IMPORTANT: THE ENTIRE SYSTEM MUST WORK AUTOMATICALLY WITHOUT ANY COMMANDS.** No setup commands, no upgrade commands, no reset commands, and no commands required for normal gameplay.

## Mace Upgrade System

| Player kills | Mace name | Enchantments |
|---:|---|---|
| 0 kills | Mace | None |
| 1 kill | Wooden Mace | Density I |
| 2 kills | Stone Mace | Density I, Wind Burst I |
| 3 kills | Pro Mace | Density II, Wind Burst II |
| 4 kills | Super Mace | Density V, Wind Burst III |
| 5+ kills | God Mace | Density VI, Wind Burst V, Sharpness IX |

## Automatic Gameplay Rules

1. **On player join:** Automatically give the player a basic mace named `Mace` with no enchantments if they do not already have saved progression.
2. **On player kill:** When a player kills another player, increase the killer's kill streak by exactly one and immediately replace their current mace with the correct upgraded mace.
3. **On death:** Reset the dead player's kill streak to zero and give them a fresh basic mace named `Mace` with no enchantments.
4. **On respawn:** Ensure the player has exactly the correct mace for their current progression.
5. **God Mace:** At five kills, award the God Mace. Keep it at the God tier for every additional kill until the player dies.
6. **No duplicate rewards:** Never give duplicate maces through repeated events, reconnects, or respawns.
7. **Persistent progression:** Save player progression using UUIDs so it is handled consistently across reconnects and server restarts.
8. **Correct kill detection:** Count only actual player-versus-player kills. Do not count environmental deaths, suicides, mob kills, or non-player damage as player kills.
9. **Automatic item replacement:** Replace the player's designated progression mace immediately on an upgrade. Do not require the player to run a command or manually craft anything.
10. **Death handling:** The dead player's progression resets regardless of whether they had a Wooden, Stone, Pro, Super, or God Mace.

## Enchantment Requirements

Use Minecraft's actual mace enchantments wherever supported by the target server version:

- **Mace:** No enchantments.
- **Wooden Mace:** Density I.
- **Stone Mace:** Density I + Wind Burst I.
- **Pro Mace:** Density II + Wind Burst II.
- **Super Mace:** Density V + Wind Burst III.
- **God Mace:** Density VI + Wind Burst V + Sharpness IX.

Allow the specified enchantment levels even when they exceed vanilla survival limits, using the appropriate server API methods. Do not silently reduce the levels to vanilla maximums.

If the target Minecraft version does not support the mace, Density, or Wind Burst enchantments, report the incompatibility rather than pretending the enchantments work.

## Item Design

Give every mace its exact tier name, using Minecraft's item display-name system. Use the actual MACE material, not a renamed stick or another weapon.

Optionally give each tier a distinct color-coded name and suitable lore describing its kill requirement and abilities. Do not change the required names or enchantment levels.

## Technical Requirements

- Platform: Paper or compatible Spigot-based Minecraft Java server.
- Use Java and the appropriate server API for the selected Minecraft version.
- Include a valid `plugin.yml`.
- Use event listeners for player joins, player deaths, kills, and respawns.
- Store progression safely using player UUIDs.
- Handle inventory replacement safely and prevent duplication or item-loss exploits.
- Make all core features automatic, with **zero custom commands** and no permissions required for normal players.
- Include all source code, build configuration, and installation instructions.
- Ensure the plugin compiles and works on the declared target server version.
- Do not include fake or unfinished methods, pseudocode, or unimplemented features.

## Final Acceptance Test

1. A new player joins and receives Mace with no enchantments.
2. After one PvP kill, it becomes Wooden Mace with Density I.
3. After two total kills, it becomes Stone Mace with Density I and Wind Burst I.
4. After three total kills, it becomes Pro Mace with Density II and Wind Burst II.
5. After four total kills, it becomes Super Mace with Density V and Wind Burst III.
6. After five total kills, it becomes God Mace with Density VI, Wind Burst V, and Sharpness IX.
7. Additional kills keep the player at God Mace.
8. Any player death resets that player's progression and mace to the basic Mace.
9. Reconnecting or restarting the server does not break progression persistence.
10. All tests pass without any player or administrator running a custom command.

Deliver the complete, compilable plugin project and explain how to build the JAR and install it in the server's `plugins` folder.
Kodari AI
KodariOct 21 at 12:55 pm 1
KillToUpgradeMace
A fully automatic PvP mace progression plugin. Every player receives a basic Mace on join and respawn. Each player kill upgrades their mace through tiers: Wooden, Stone, Pro, Super, and God, adding Density, Wind Burst, and Sharpness enchantments. Death resets progression to the basic Mace. Progression persists via UUIDs across reconnects and restarts. Zero commands required; all mechanics operate through event listeners for joins, kills, deaths, and respawns. Handles inventory replacement safely to prevent duplication and item-loss exploits.
  1. Create a Paper 1.21.4 plugin with automatic PvP kill tiers and UUID-based persistence.

  2. Add tagged mace replacement, death/respawn handling, and startup checks for required mace enchantments.

  3. Include the Gradle build file, plugin metadata, and Kodari/server installation steps.

Created Kill-to-Upgrade Mace for Paper/compatible servers on Minecraft 1.21.4+. It handles automatic PvP kill upgrades, death resets, UUID-based progression saves, and marked-mace replacement. It also checks for the required mace and enchantments at startup and disables itself with an incompatibility message if they are unavailable.

The project includes the Gradle build file, plugin.yml, and installation steps in README.md. To get the JAR, click Compile in Kodari (on a phone: ⋮ → Compile Project), then download the successful build and place it in the server’s plugins folder.

Abdullah Hasnain

make for 1.21.1

Kodari AI
KodariOct 21 at 1:02 pm 1

The generation was stopped before any content could be produced.

Abdullah Hasnain

make for 1.21.11

Kodari AI
KodariOct 21 at 1:02 pm 1
  1. Update the Paper API dependency to 1.21.11.

  2. Update the README’s stated target and install requirement to match.

Updated the Paper API dependency and README target to Minecraft 1.21.11. Compile the project in Kodari and install the resulting JAR in the server’s plugins folder.

Abdullah Hasnain

give me download file

Kodari AI
KodariOct 21 at 1:05 pm 1

To download the plugin JAR, click Compile in the top bar (on a phone: ⋮ → Compile Project), then click Compile in the window. When the build succeeds, click Download or Download Kill-to-Upgrade-Mace.jar in the chat.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
README.md
Code
4 309
src/main/java/com/kodari/killupgrademace/KillToUpgradeMacePlugin.java
package com.kodari.killupgrademace;

import com.cryptomorin.xseries.XEnchantment;
import com.cryptomorin.xseries.XMaterial;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerSwapHandItemsEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.bukkit.configuration.file.YamlConfiguration;

public final class KillToUpgradeMacePlugin extends JavaPlugin implements Listener {
    private final Map<UUID, Integer> killProgress = new HashMap<>();
    private Material maceMaterial;
    private Enchantment density;
    private Enchantment windBurst;
    private Enchantment sharpness;
    private NamespacedKey progressionMaceKey;
    private File progressionFile;

    @Override
    public void onEnable() {
        maceMaterial = XMaterial.matchXMaterial("MACE")
                .map(XMaterial::parseMaterial)
                .orElse(null);
        density = XEnchantment.matchXEnchantment("DENSITY")
                .map(XEnchantment::getEnchant)
                .orElse(null);
        windBurst = XEnchantment.matchXEnchantment("WIND_BURST")
                .map(XEnchantment::getEnchant)
                .orElse(null);
        sharpness = XEnchantment.matchXEnchantment("SHARPNESS")
                .map(XEnchantment::getEnchant)
                .orElse(null);

        if (maceMaterial == null || density == null || windBurst == null || sharpness == null) {
            getLogger().severe("This server does not support MACE, Density, Wind Burst, and Sharpness as required (Minecraft 1.21+). Disabling the plugin.");
            getServer().getPluginManager().disablePlugin(this);
            return;
        }

        progressionMaceKey = new NamespacedKey(this, "progression_mace");
        progressionFile = new File(getDataFolder(), "progression.yml");
        if (!getDataFolder().exists() && !getDataFolder().mkdirs()) {
            getLogger().severe("Could not create the plugin data directory. Disabling the plugin.");
            getServer().getPluginManager().disablePlugin(this);
            return;
        }

        loadProgression();
        getServer().getPluginManager().registerEvents(this, this);
    }

    @Override
    public void onDisable() {
        if (progressionFile != null) {
            saveProgression();
        }
    }

    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event) {
        Player player = event.getPlayer();
        UUID playerId = player.getUniqueId();
        if (!killProgress.containsKey(playerId)) {
            killProgress.put(playerId, 0);
            saveProgression();
        }
        synchronizeMace(player);
    }

    @EventHandler
    public void onPlayerDeath(PlayerDeathEvent event) {
        Player victim = event.getEntity();
        killProgress.put(victim.getUniqueId(), 0);
        event.getDrops().removeIf(this::isProgressionMace);

        Player killer = victim.getKiller();
        if (killer != null && !killer.getUniqueId().equals(victim.getUniqueId())) {
            killProgress.merge(killer.getUniqueId(), 1, Integer::sum);
            synchronizeMace(killer);
        }
        saveProgression();
    }

    @EventHandler
    public void onPlayerRespawn(PlayerRespawnEvent event) {
        Player player = event.getPlayer();
        getServer().getScheduler().runTask(this, () -> synchronizeMace(player));
    }

    @EventHandler
    public void onPlayerDropItem(PlayerDropItemEvent event) {
        if (isProgressionMace(event.getItemDrop().getItemStack())) {
            event.setCancelled(true);
        }
    }

    @EventHandler
    public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) {
        if (isProgressionMace(event.getMainHandItem()) || isProgressionMace(event.getOffHandItem())) {
            event.setCancelled(true);
        }
    }

    @EventHandler
    public void onInventoryClick(InventoryClickEvent event) {
        if (!(event.getWhoClicked() instanceof Player player)) {
            return;
        }

        ItemStack hotbarItem = event.getHotbarButton() >= 0
                ? player.getInventory().getItem(event.getHotbarButton())
                : null;
        if (event.getClickedInventory() != null
                && event.getClickedInventory() != player.getInventory()
                && (isProgressionMace(event.getCurrentItem())
                || isProgressionMace(event.getCursor())
                || isProgressionMace(hotbarItem))) {
            event.setCancelled(true);
            return;
        }

        if (event.isShiftClick() && isProgressionMace(event.getCurrentItem())) {
            event.setCancelled(true);
        }
    }

    @EventHandler
    public void onInventoryDrag(InventoryDragEvent event) {
        if (!isProgressionMace(event.getOldCursor())) {
            return;
        }

        Inventory topInventory = event.getView().getTopInventory();
        for (int rawSlot : event.getRawSlots()) {
            if (rawSlot < topInventory.getSize()) {
                event.setCancelled(true);
                return;
            }
        }
    }

    private void synchronizeMace(Player player) {
        PlayerInventory inventory = player.getInventory();
        ItemStack[] contents = inventory.getContents();
        int keptSlot = -1;

        for (int slot = 0; slot < contents.length; slot++) {
            if (!isProgressionMace(contents[slot])) {
                continue;
            }
            if (keptSlot == -1) {
                keptSlot = slot;
            } else {
                inventory.setItem(slot, null);
            }
        }

        ItemStack mace = createMace(killProgress.getOrDefault(player.getUniqueId(), 0));
        if (keptSlot >= 0) {
            inventory.setItem(keptSlot, mace);
            return;
        }

        Map<Integer, ItemStack> leftovers = inventory.addItem(mace);
        leftovers.values().forEach(item -> player.getWorld().dropItemNaturally(player.getLocation(), item));
    }

    private ItemStack createMace(int kills) {
        ItemStack mace = new ItemStack(maceMaterial);
        ItemMeta meta = mace.getItemMeta();
        meta.setDisplayName(tierName(kills));
        meta.getPersistentDataContainer().set(progressionMaceKey, PersistentDataType.BYTE, (byte) 1);

        if (kills >= 1) {
            meta.addEnchant(density, kills >= 5 ? 6 : kills == 4 ? 5 : kills == 3 ? 2 : 1, true);
        }
        if (kills >= 2) {
            meta.addEnchant(windBurst, kills >= 5 ? 5 : kills == 4 ? 3 : kills == 3 ? 2 : 1, true);