Radu 2.0

You know i built a grave with three totems i want a plugin for 1.21.11 that when a player die one totem from there to pop and disapear meaning that he only has 2 lifes left

Kodari AI
KodariSep 24 at 3:44 am 1
TotemLifeSystem
A Minecraft 1.21.1 plugin that tracks player lives through totems. When a player dies, one totem from their inventory is automatically consumed and removed, reducing their remaining lives. The plugin monitors totem counts, handles death events, and manages the life system seamlessly. Players start with three totems, and each death consumes one, leaving them with fewer lives until none remain. The plugin provides clear feedback on remaining lives and ensures totems are properly deducted from inventory upon death.

[Generation stopped]

Radu 2.0

No they have a grave with 3 totems and after he dies one totem dissapears

Kodari AI
KodariSep 24 at 3:46 am 1
  1. Add the Paper/Gradle plugin scaffold for Minecraft 1.21.

  2. Add /totemgrave bind so each player can link their grave container.

  3. On death, remove one totem from that container and report how many remain.

Implemented TotemGrave: bind the container holding the three totems with /totemgrave bind while looking at it. Each time you die, the plugin removes one totem from that container; /totemgrave unbind clears the link.

Radu 2.0

Yeah and after one death make a system that i can choose a recipe that will craft a totem with his name "viata"

Kodari AI
KodariSep 24 at 3:50 am 1
  1. Add a configurable shaped crafting recipe for a Totem of Undying named viata.

  2. Register it on startup and document how to change the shape and ingredients in config.yml.

Added a configurable crafting recipe that produces a Totem of Undying named viata. Edit recipe.shape and recipe.ingredients in config.yml, then restart the server to apply your recipe. The recipe is available to all players; it isn’t unlocked by dying.

Radu 2.0

I want that when you make a grave with three totems to bind link it like its yours and only in creative mode you can add or take totems

Kodari AI
KodariSep 24 at 3:56 am 1
  1. Prevent two players from binding the same grave location.

  2. Allow only creative-mode players to move totems into or out of a bound grave, including drag, hotbar, offhand, and hopper transfers.

Updated the grave system:

  • A grave location can only be bound to one player.

  • Non-creative players can’t add or take totems from a bound grave. This also blocks shift-clicks, hotbar swaps, cursor collection, drag moves, and hopper transfers.

  • Creative-mode players can manage the grave’s totems normally.

  • Deaths still consume one totem from the bound grave.

Radu 2.0

After he loses all the totems from the grave he gets banned automatically

Kodari AI
KodariSep 24 at 3:58 am 1
  1. When the last grave totem is consumed, permanently ban the player and kick them with a clear message.

When the final totem is removed from the bound grave, the player is permanently banned and kicked with the message “You have lost all the totems in your grave.”

Radu 2.0

Make a system that recognizes that the grave has the totems on item frames

Kodari AI
KodariSep 24 at 4:01 am 1
  1. Let /totemgrave bind link the totem item frames you’re looking at; bind each frame in the grave.

  2. On death, remove one displayed totem from the linked frames and count what remains.

  3. Keep non-creative players from taking, adding, or breaking totems in linked frames.

Added item-frame support. Look at each frame containing a grave totem and run /totemgrave bind to link it to your grave. On death, one totem is removed from a linked frame; the plugin counts the remaining framed totems and bans the player when none remain. Non-creative players can’t take totems from or break linked frames.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
5 521
src/main/java/com/kodari/totemgrave/TotemGravePlugin.java
package com.kodari.totemgrave;

import com.cryptomorin.xseries.XMaterial;
import org.bukkit.BanList;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.Container;
import org.bukkit.block.DoubleChest;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.entity.Entity;
import org.bukkit.entity.ItemFrame;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.event.inventory.InventoryPickupItemEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;

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

public class TotemGravePlugin extends JavaPlugin implements Listener, CommandExecutor {
    private XMaterial totemType;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        totemType = XMaterial.matchXMaterial("TOTEM_OF_UNDYING").orElse(null);
        if (totemType == null) {
            getLogger().severe("Could not resolve TOTEM_OF_UNDYING; disabling plugin.");
            Bukkit.getPluginManager().disablePlugin(this);
            return;
        }

        registerViataRecipe();
        getServer().getPluginManager().registerEvents(this, this);
        getCommand("totemgrave").setExecutor(this);
    }

    private void registerViataRecipe() {
        ItemStack result = totemType.parseItem();
        if (result == null) {
            getLogger().severe("Could not create the Viata totem recipe result.");
            return;
        }

        ItemMeta meta = result.getItemMeta();
        meta.setDisplayName(ChatColor.GOLD + "viata");
        result.setItemMeta(meta);

        ShapedRecipe recipe = new ShapedRecipe(new NamespacedKey(this, "viata_totem"), result);
        java.util.List<String> shape = getConfig().getStringList("recipe.shape");
        if (shape.isEmpty() || shape.size() > 3) {
            getLogger().severe("recipe.shape must contain between 1 and 3 rows.");
            return;
        }
        recipe.shape(shape.toArray(new String[0]));

        Map<Character, Material> ingredients = new HashMap<>();
        if (getConfig().getConfigurationSection("recipe.ingredients") == null) {
            getLogger().severe("Missing recipe.ingredients in config.yml.");
            return;
        }
        for (String key : getConfig().getConfigurationSection("recipe.ingredients").getKeys(false)) {
            if (key.length() != 1 || key.charAt(0) == ' ') {
                getLogger().severe("Recipe ingredient keys must be one non-space character: " + key);
                return;
            }
            String materialName = getConfig().getString("recipe.ingredients." + key);
            Material material = materialName == null ? null : XMaterial.matchXMaterial(materialName)
                    .map(XMaterial::parseMaterial)
                    .orElse(null);
            if (material == null) {
                getLogger().severe("Unknown recipe material for key " + key + ": " + materialName);
                return;
            }
            ingredients.put(key.charAt(0), material);
        }

        for (String row : shape) {
            for (char symbol : row.toCharArray()) {
                if (symbol != ' ' && !ingredients.containsKey(symbol)) {
                    getLogger().severe("No recipe ingredient is configured for symbol: " + symbol);
                    return;
                }
            }
        }
        ingredients.forEach(recipe::setIngredient);
        Bukkit.addRecipe(recipe);
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!(sender instanceof Player player)) {
            sender.sendMessage("This command can only be used by a player.");
            return true;
        }

        if (args.length != 1) {
            player.sendMessage(ChatColor.YELLOW + "Usage: /totemgrave <bind|unbind>");
            return true;
        }

        if (args[0].equalsIgnoreCase("bind")) {
            Entity targetedEntity = player.getTargetEntity(5);
            if (targetedEntity instanceof ItemFrame frame) {
                if (!isTotem(frame.getItem())) {
                    player.sendMessage(ChatColor.RED + "The item frame you are looking at must contain a totem.");
                    return true;
                }

                String playerId = player.getUniqueId().toString();
                if (isFrameBoundToAnotherPlayer(frame.getUniqueId(), playerId)) {
                    player.sendMessage(ChatColor.RED + "That item frame is already bound to another player.");
                    return true;
                }

                String framePath = "graves." + playerId + ".frames." + frame.getUniqueId();
                getConfig().set(framePath + ".world", frame.getWorld().getName());
                getConfig().set(framePath + ".x", frame.getLocation().getBlockX());
                getConfig().set(framePath + ".y", frame.getLocation().getBlockY());
                getConfig().set(framePath + ".z", frame.getLocation().getBlockZ());
                saveConfig();
                player.sendMessage(ChatColor.GREEN + "Totem item frame bound to your grave. Bind each of its other totem frames too.");
                return true;
            }

            Block target = player.getTargetBlock(Collections.emptySet(), 5);
            BlockState state = target.getState();
            if (!(state instanceof Container)) {
                player.sendMessage(ChatColor.RED + "Look at your grave's chest or other container, within 5 blocks.");
                return true;
            }

            if (isBoundToAnotherPlayer(target, player.getUniqueId().toString())) {
                player.sendMessage(ChatColor.RED + "That grave is already bound to another player.");
                return true;
            }

            String path = "graves." + player.getUniqueId();
            getConfig().set(path + ".world", player.getWorld().getName());
            getConfig().set(path + ".x", target.getX());
            getConfig().set(path + ".y", target.getY());
            getConfig().set(path + ".z", target.getZ());
            saveConfig();
            player.sendMessage(ChatColor.GREEN + "Your grave is bound. One totem will be removed from it each time you die.");
            return true;
        }

        if (args[0].equalsIgnoreCase("unbind")) {
            getConfig().set("graves." + player.getUniqueId(), null);
            saveConfig();
            player.sendMessage(ChatColor.GREEN + "Your grave has been unbound.");
            return true;
        }

        player.sendMessage(ChatColor.YELLOW + "Usage: /totemgrave <bind|unbind>");
        return true;
    }

    @EventHandler
    public void onGraveInventoryClick(InventoryClickEvent event) {
        if (!(event.getWhoClicked() instanceof Player player) || player.getGameMode() == GameMode.CREATIVE) {
            return;
        }

        Inventory graveInventory = event.getView().getTopInventory();
        if (!isBoundGraveInventory(graveInventory)) {
            return;
        }

        Inventory clickedInventory = event.getClickedInventory();
        boolean movesTotem = false;
        if (clickedInventory == graveInventory) {
            movesTotem |= isTotem(event.getCurrentItem()) || isTotem(event.getCursor());
            if (event.getClick() == ClickType.NUMBER_KEY) {
                int hotbarButton = event.getHotbarButton();