Abdullah Hasnain

make in jar file

📎 1 file 2,375 chars
📄
pasted-code-1790592691801.txt
txt 98 lines
▶
Create a complete Minecraft MaceOnly SMP plugin for Paper 1.21.x using Java 21.

No Commands & No Server Restart

The plugin must work 100% automatically.

No commands at all.

Players never need to type a command.

The plugin must not require a server restart to begin working after installation.

The plugin should initialize automatically when the plugin/server loads.

Do not require /reload, /mace, /reload confirm, or any other command.

All gameplay systems must activate automatically.

Configuration should be loaded automatically when the plugin starts.

If configuration changes need to take effect while the server is running, implement automatic configuration detection/reloading where safe, without requiring a server restart or command.

Automatic Mace System

Every player automatically receives a Simple Mace when they first join.

Progression:

0 kills → Simple Mace
1 kill  → Wooden Mace
           Wind Burst I

2 kills → Stone Mace
           Wind Burst I
           Density I

3 kills → Pro Mace
           Wind Burst II
           Density II

4 kills → Super Mace
           Wind Burst III
           Density III

5+ kills → God Mace
            Wind Burst V
            Density VIII
            Sharpness VIII

Automatic Kill Detection

When a player kills another player:

Automatically detect the kill.

Increase the killer's kill count.

Automatically upgrade their mace.

Remove the previous progression mace.

Give the upgraded mace.

No command or interaction is required.

Automatic Death Reset

When a player dies:

Immediately reset their kill count to 0.

Reset their progression to Simple Mace.

After respawn, automatically give them the Simple Mace.

The Simple Mace must have no enchantments.

Persistence

Save player progression automatically using UUIDs.

Player data must survive:

Disconnecting

Reconnecting

Server restarts

When a player reconnects, automatically restore the correct mace based on their saved kill count.

Important

The plugin should be completely hands-free:

Install plugin → plugin loads automatically → players join → Simple Mace automatically → kills automatically upgrade the mace → death automatically resets progression.

There must be no commands and no manual server restart/reload required for gameplay.
Kodari AI
KodariSep 28 at 10:53 am 1
MaceOnlySMP
An automatic hands-free Mace progression plugin for Paper 1.21.x. Players automatically receive a Simple Mace on first join. Kill tracking upgrades maces through tiers: Simple, Wooden, Stone, Pro, Super, and God with increasing Wind Burst, Density, and Sharpness enchantments. Death resets kill count and progression. Player data persists via UUID across disconnects and restarts. No commands or manual reloads needed; all systems activate on plugin load.
  1. Set up the Java 21 Paper project and automatic plugin configuration.

  2. Implement UUID-backed mace progression, kill upgrades, and death resets.

  3. Configure Gradle to produce the installable plugin JAR.

Created the Paper 1.21.x plugin project with automatic mace progression, UUID-based persistence, kill upgrades, death resets, and safe config-file change detection. It has no commands and is configured to build as build/libs/MaceOnlySMP-1.0.0.jar.

Paper loads plugins when the server starts; loading a newly copied JAR into an already-running server requires a restart or a separate hot-loader. After the plugin is loaded, gameplay starts automatically—no commands or manual reloads are needed.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
6 332
src/main/java/com/kodari/maceonly/MaceOnlySMP.java
package com.kodari.maceonly;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
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.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
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.util.Map;

public final class MaceOnlySMP extends JavaPlugin implements Listener {
    private static final MaceTier SIMPLE = new MaceTier("Simple Mace", "&f", 0, 0, 0);
    private static final MaceTier WOODEN = new MaceTier("Wooden Mace", "&6", 1, 0, 0);
    private static final MaceTier STONE = new MaceTier("Stone Mace", "&7", 1, 1, 0);
    private static final MaceTier PRO = new MaceTier("Pro Mace", "&b", 2, 2, 0);
    private static final MaceTier SUPER = new MaceTier("Super Mace", "&d", 3, 3, 0);
    private static final MaceTier GOD = new MaceTier("God Mace", "&c&l", 5, 8, 8);

    private ProgressionStore progressionStore;
    private NamespacedKey progressionMaceKey;
    private Material maceMaterial;
    private long configLastModified;
    private long configLength;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        reloadConfig();
        rememberConfigFileState();

        maceMaterial = Material.matchMaterial("MACE");
        if (maceMaterial == null) {
            getLogger().severe("The MACE item is unavailable. This plugin requires Paper 1.21 or newer.");
            getServer().getPluginManager().disablePlugin(this);
            return;
        }

        progressionMaceKey = new NamespacedKey(this, "progression_mace");
        progressionStore = new ProgressionStore(this);
        getServer().getPluginManager().registerEvents(this, this);
        getServer().getScheduler().runTaskTimer(this, this::reloadConfigIfChanged, 100L, 100L);
    }

    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event) {
        Player player = event.getPlayer();
        progressionStore.ensurePlayer(player.getUniqueId());
        int kills = progressionStore.getKills(player.getUniqueId());
        replaceProgressionMace(player, kills);
        sendProgressionMessage(player, "messages.join", "&aYour mace progression is now &f%mace%&a.", kills);
    }

    @EventHandler
    public void onPlayerDeath(PlayerDeathEvent event) {
        Player victim = event.getEntity();
        Player killer = victim.getKiller();

        progressionStore.setKills(victim.getUniqueId(), 0);
        event.getDrops().removeIf(this::isProgressionMace);
        sendProgressionMessage(victim, "messages.reset", "&cYour mace progression reset to &f%mace%&c.", 0);

        if (killer == null || killer.getUniqueId().equals(victim.getUniqueId())) {
            return;
        }

        int kills = Math.min(progressionStore.getKills(killer.getUniqueId()) + 1, Integer.MAX_VALUE);
        progressionStore.setKills(killer.getUniqueId(), kills);
        replaceProgressionMace(killer, kills);
        sendProgressionMessage(killer, "messages.upgrade", "&aMace upgraded to &f%mace%&a (&f%kills% kills&a).", kills);
    }

    @EventHandler
    public void onPlayerRespawn(PlayerRespawnEvent event) {
        Player player = event.getPlayer();
        Bukkit.getScheduler().runTask(this, () -> {
            if (player.isOnline()) {
                replaceProgressionMace(player, 0);
            }
        });
    }

    private void replaceProgressionMace(Player player, int kills) {
        removeProgressionMaces(player);
        ItemStack mace = createMace(kills);
        Map<Integer, ItemStack> leftovers = player.getInventory().addItem(mace);
        for (ItemStack leftover : leftovers.values()) {
            player.getWorld().dropItemNaturally(player.getLocation(), leftover);
        }
    }

    private ItemStack createMace(int kills) {
        MaceTier tier = getTier(kills);
        ItemStack mace = new ItemStack(maceMaterial);
        ItemMeta meta = mace.getItemMeta();
        meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', tier.color() + tier.name()));
        meta.getPersistentDataContainer().set(progressionMaceKey, PersistentDataType.BYTE, (byte) 1);
        mace.setItemMeta(meta);

        addEnchantment(mace, "wind_burst", tier.windBurst());
        addEnchantment(mace, "density", tier.density());
        addEnchantment(mace, "sharpness", tier.sharpness());
        return mace;
    }

    private void addEnchantment(ItemStack item, String key, int level) {
        if (level <= 0) {
            return;
        }

        Enchantment enchantment = Enchantment.getByKey(NamespacedKey.minecraft(key));
        if (enchantment == null) {
            getLogger().warning("Could not find required enchantment: " + key);
            return;
        }
        item.addUnsafeEnchantment(enchantment, level);
    }

    private void removeProgressionMaces(Player player) {
        PlayerInventory inventory = player.getInventory();

        ItemStack[] contents = inventory.getContents();
        for (int slot = 0; slot < contents.length; slot++) {
            if (isProgressionMace(contents[slot])) {
                inventory.setItem(slot, null);
            }
        }

        ItemStack[] armor = inventory.getArmorContents();
        boolean armorChanged = false;
        for (int slot = 0; slot < armor.length; slot++) {
            if (isProgressionMace(armor[slot])) {
                armor[slot] = null;
                armorChanged = true;
            }
        }
        if (armorChanged) {
            inventory.setArmorContents(armor);
        }

        ItemStack[] extra = inventory.getExtraContents();
        boolean extraChanged = false;
        for (int slot = 0; slot < extra.length; slot++) {
            if (isProgressionMace(extra[slot])) {
                extra[slot] = null;
                extraChanged = true;
            }
        }
        if (extraChanged) {
            inventory.setExtraContents(extra);
        }
    }

    private boolean isProgressionMace(ItemStack item) {
        if (item == null || !item.hasItemMeta()) {
            return false;
        }
        return item.getItemMeta().getPersistentDataContainer().has(progressionMaceKey, PersistentDataType.BYTE);
    }

    private void sendProgressionMessage(Player player, String path, String fallback, int kills) {
        String message = getConfig().getString(path, fallback)
                .replace("%mace%", getTier(kills).name())
                .replace("%kills%", Integer.toString(kills));
        player.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
    }

    private MaceTier getTier(int kills) {
        if (kills >= 5) {
            return GOD;
        }
        if (kills == 4) {
            return SUPER;
        }
        if (kills == 3) {
            return PRO;
        }
        if (kills == 2) {
            return STONE;
        }
        if (kills == 1) {
            return WOODEN;
        }
        return SIMPLE;
    }

    private void reloadConfigIfChanged() {
        File configFile = new File(getDataFolder(), "config.yml");
        if (!configFile.exists()) {