znsuyt

make a minecraft plugin by which we can craft only 1 mace in the smp and if a player craft mace once it can not be crafted again so a message in chat will go like Player name who crafted it

Kodari AI
KodariSep 28 at 8:39 am 1
MaceCraftLimiter
This plugin restricts mace crafting to a single instance per server. When a player crafts a mace, the plugin intercepts the crafting event, checks if a mace has already been crafted, and either allows the craft (recording the player's name) or blocks it with a chat notification. If a mace was previously crafted, the plugin prevents further crafting and broadcasts a message showing the original crafter's name. The plugin uses a persistent data file to track the mace crafting status across server restarts, ensuring the one-mace limit remains enforced. It also handles edge cases like mace crafting through shift-click or quick-move operations, and provides configurable messages for both successful and blocked crafting attempts.

I’ll create a Paper plugin with one-time mace crafting, persistent claim tracking, and a server-wide announcement naming the first crafter.

Created UniqueMaceCraft: the first mace craft is saved persistently and announced server-wide as “<Player> crafted the one and only mace!” Later mace crafting attempts are cancelled. Targets Paper 1.21.4 and Java 21.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
4 91
src/main/java/com/example/uniquemacecraft/UniqueMaceCraftPlugin.java
package com.example.uniquemacecraft;

import java.io.File;
import java.io.IOException;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.configuration.file.YamlConfiguration;

public final class UniqueMaceCraftPlugin extends JavaPlugin implements Listener {
    private File dataFile;
    private YamlConfiguration data;
    private boolean maceClaimed;

    @Override
    public void onEnable() {
        if (!getDataFolder().exists() && !getDataFolder().mkdirs()) {
            getLogger().severe("Could not create the plugin data folder; disabling to prevent duplicate mace crafts.");
            getServer().getPluginManager().disablePlugin(this);
            return;
        }

        dataFile = new File(getDataFolder(), "mace-data.yml");
        data = YamlConfiguration.loadConfiguration(dataFile);
        maceClaimed = data.getBoolean("claimed", false);
        getServer().getPluginManager().registerEvents(this, this);
    }

    @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
    public void onMaceCraft(CraftItemEvent event) {
        if (!"MACE".equals(event.getRecipe().getResult().getType().name())) {
            return;
        }

        if (!(event.getWhoClicked() instanceof Player player)) {
            return;
        }

        if (maceClaimed) {
            event.setCancelled(true);
            player.sendMessage("§cA mace has already been crafted on this server.");
            return;
        }

        maceClaimed = true;
        data.set("claimed", true);
        data.set("crafter", player.getName());
        try {
            data.save(dataFile);
        } catch (IOException exception) {
            event.setCancelled(true);
            getLogger().severe("Could not save the mace claim; the craft was cancelled.");
            exception.printStackTrace();
            return;
        }

        getServer().broadcastMessage("§a" + player.getName() + " crafted the one and only mace!");
    }
}