Ma Dun

Make me A samurai armor

Kodari AI
KodariNov 14 at 11:15 pm 1
SamuraiArmor
Adds craftable samurai armor sets to Minecraft with unique combat abilities. Players can forge four armor pieces (helmet, chestplate, leggings, boots) using custom materials like iron ingots and leather. Each piece provides enhanced protection values and grants set bonuses when worn together, including increased attack damage, speed boost, and resistance to projectiles. The plugin includes a crafting recipe system, durability management, and particle effects when abilities activate. Armor pieces display custom names and lore, with configurable stats via the plugin configuration file.

I’ll create a Java plugin that gives players a red-and-black samurai armor set with themed names and protective enchantments.

Added a crimson-dyed samurai armor set with themed names and Protection III/Unbreaking II. Use /samuraiarmor to get it, or /samuraiarmor <player> to give it to someone else.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
3 130
src/main/java/com/kodari/samuraiarmor/SamuraiArmorPlugin.java
package com.kodari.samuraiarmor;

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

import java.util.Arrays;
import java.util.List;
import java.util.Map;

public class SamuraiArmorPlugin extends JavaPlugin implements CommandExecutor {
    private static final Color ARMOR_COLOR = Color.fromRGB(112, 24, 31);

    @Override
    public void onEnable() {
        getCommand("samuraiarmor").setExecutor(this);
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!sender.hasPermission("samuraiarmor.give")) {
            sender.sendMessage(ChatColor.RED + "You don't have permission to use this command.");
            return true;
        }

        Player recipient;
        if (args.length == 0) {
            if (!(sender instanceof Player player)) {
                sender.sendMessage(ChatColor.RED + "Usage: /samuraiarmor <player>");
                return true;
            }
            recipient = player;
        } else {
            recipient = Bukkit.getPlayerExact(args[0]);
            if (recipient == null) {
                sender.sendMessage(ChatColor.RED + "That player is not online.");
                return true;
            }
        }

        for (ItemStack piece : createArmorSet()) {
            Map<Integer, ItemStack> leftovers = recipient.getInventory().addItem(piece);
            leftovers.values().forEach(item -> recipient.getWorld().dropItemNaturally(recipient.getLocation(), item));
        }

        recipient.sendMessage(ChatColor.RED + "You received the Crimson Samurai armor set.");
        if (recipient != sender) {
            sender.sendMessage(ChatColor.GREEN + "Gave the Crimson Samurai armor set to " + recipient.getName() + ".");
        }
        return true;
    }

    private List<ItemStack> createArmorSet() {
        return Arrays.asList(
                createPiece("LEATHER_HELMET", "Crimson Kabuto", "A warrior's crested helm."),
                createPiece("LEATHER_CHESTPLATE", "Crimson Do", "Lacquered plates forged for battle."),
                createPiece("LEATHER_LEGGINGS", "Crimson Kusazuri", "Layered armor for swift movement."),
                createPiece("LEATHER_BOOTS", "Crimson Suneate", "Armored greaves for the battlefield.")
        );
    }

    private ItemStack createPiece(String materialName, String displayName, String description) {
        ItemStack item = XMaterial.matchXMaterial(materialName)
                .map(XMaterial::parseItem)
                .orElseThrow(() -> new IllegalStateException("Unsupported armor material: " + materialName));

        ItemMeta itemMeta = item.getItemMeta();
        if (!(itemMeta instanceof LeatherArmorMeta meta)) {
            throw new IllegalStateException("Expected leather armor metadata for " + materialName);
        }

        meta.setColor(ARMOR_COLOR);
        meta.setDisplayName(ChatColor.RED + "" + ChatColor.BOLD + displayName);
        meta.setLore(Arrays.asList(ChatColor.GRAY + description, ChatColor.DARK_RED + "Way of the Crimson Samurai"));
        XEnchantment.matchXEnchantment("PROTECTION")
                .ifPresent(enchantment -> meta.addEnchant(enchantment.getEnchant(), 3, true));
        XEnchantment.matchXEnchantment("UNBREAKING")
                .ifPresent(enchantment -> meta.addEnchant(enchantment.getEnchant(), 2, true));
        item.setItemMeta(meta);
        return item;
    }
}