Create a Minecraft Java server plugin for version 1.20.1 adding a custom sword item based on the user's supplied blood_sword.png image. Include an appropriate resource pack with the supplied texture if the image is accessible in your project context; otherwise implement the custom item and resource-pack configuration and clearly report that the image is needed. Provide an admin command to obtain the sword and suitable permissions. Do not invent special abilities. Feature code only.

Kodari AI
KodariNov 15 at 5:18 pm 1
BloodSwordPlugin
Implements a custom blood sword item for Minecraft 1.20.1 servers. Provides an admin command to obtain the sword with proper permissions. Configures a resource pack to apply the custom texture from blood_sword.png. Includes plugin.yml, main class, command handler, and resource pack configuration. No special abilities are added—only the custom item and its texture integration.

Created the sword plugin with /bloodsword give [player], restricted to operators by default through bloodsword.admin. Its material and custom model data are configurable; it has no special abilities.

blood_sword.png wasn’t accessible, so the resource pack and texture still need the image. The default model data is 10001.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
4 94
src/main/java/com/kodari/bloodsword/BloodSwordPlugin.java
package com.kodari.bloodsword;

import com.cryptomorin.xseries.XMaterial;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;

public final class BloodSwordPlugin extends JavaPlugin {
    @Override
    public void onEnable() {
        saveDefaultConfig();
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!sender.hasPermission("bloodsword.admin")) {
            sender.sendMessage(ChatColor.RED + "You do not have permission to use this command.");
            return true;
        }
        if (args.length < 1 || args.length > 2 || !args[0].equalsIgnoreCase("give")) {
            sender.sendMessage(ChatColor.RED + "Usage: /" + label + " give [player]");
            return true;
        }

        Player target = args.length == 2 ? Bukkit.getPlayerExact(args[1])
                : sender instanceof Player ? (Player) sender : null;
        if (target == null) {
            sender.sendMessage(ChatColor.RED + (args.length == 2 ? "Player not found." : "Specify an online player."));
            return true;
        }

        String materialName = getConfig().getString("sword.material", "DIAMOND_SWORD");
        ItemStack sword = XMaterial.matchXMaterial(materialName).map(XMaterial::parseItem).orElse(null);
        if (sword == null || !sword.getType().name().endsWith("_SWORD")) {
            sender.sendMessage(ChatColor.RED + "Invalid sword material in config.yml.");
            return true;
        }
        ItemMeta meta = sword.getItemMeta();
        meta.setDisplayName(ChatColor.translateAlternateColorCodes('&',
                getConfig().getString("sword.name", "&4Blood Sword")));
        meta.setCustomModelData(getConfig().getInt("sword.custom-model-data", 10001));
        sword.setItemMeta(meta);

        for (ItemStack remaining : target.getInventory().addItem(sword).values()) {
            target.getWorld().dropItemNaturally(target.getLocation(), remaining);
        }
        sender.sendMessage(ChatColor.GREEN + "Gave a blood sword to " + target.getName() + ".");
        if (!sender.equals(target)) {
            target.sendMessage(ChatColor.GREEN + "You received a blood sword.");
        }
        return true;
    }
}