Caoyuan_TNT

星空短剑,黑紫配色,绝对对称

Kodari AI
KodariSep 5 at 11:08 pm 1
StarBladeSymmetry
StarBladeSymmetry is a Minecraft plugin that adds a custom symmetrical short sword with a starry night sky and black-purple color scheme. The plugin provides a craftable weapon with unique particle effects, glowing enchantment visuals, and a perfectly mirrored blade design. It includes custom crafting recipes, item lore, and configurable damage values. The sword emits star particles when swung and has a purple aura effect. The plugin ensures absolute visual symmetry in the item model and particle patterns, creating an aesthetically striking weapon for players.
  1. 创建一个可直接运行的 Paper 插件项目。

  2. 添加 /starsword 命令,生成黑紫配色、对称装饰的“星空短剑”。

  3. 注册对称合成配方,并使用自定义模型数据与物品标识。

已创建“星空短剑”插件项目:

  • 添加 /starsword 命令,生成黑紫配色星空短剑。

  • 物品名称、Lore、附魔和自定义模型数据均已配置。

  • 添加唯一 PersistentDataContainer 标识。

  • 添加绝对对称的合成配方:

    Plain Text
    OPO
    NAN
     S
    
  • 完成 plugin.yml、Gradle 构建配置和主插件类。

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
4 149
src/main/java/com/kodari/starrysword/StarrySkyShortSwordPlugin.java
package com.kodari.starrysword;

import com.cryptomorin.xseries.XEnchantment;
import com.cryptomorin.xseries.XMaterial;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
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.ShapedRecipe;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;

public final class StarrySkyShortSwordPlugin extends org.bukkit.plugin.java.JavaPlugin implements CommandExecutor {

    private NamespacedKey swordKey;

    @Override
    public void onEnable() {
        swordKey = new NamespacedKey(this, "starry_sky_short_sword");
        getCommand("starsword").setExecutor(this);
        registerRecipe();
    }

    @Override
    public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
                             @NotNull String label, @NotNull String[] args) {
        if (!(sender instanceof Player player)) {
            sender.sendMessage(color("&c只有玩家可以获得星空短剑。"));
            return true;
        }

        player.getInventory().addItem(createSword());
        player.sendMessage(color("&8✦ &5✦ &d星空短剑 &5✦ &8✦ &7已进入你的背包。"));
        return true;
    }

    private ItemStack createSword() {
        ItemStack sword = XMaterial.matchXMaterial("NETHERITE_SWORD")
                .map(XMaterial::parseItem)
                .orElseThrow(() -> new IllegalStateException("NETHERITE_SWORD is unavailable"));

        ItemMeta meta = sword.getItemMeta();
        meta.setDisplayName(color("&8✦ &5✦ &d星空短剑 &5✦ &8✦"));
        meta.setLore(Arrays.asList(
                color("&8✦ &5✧ &d✦ &5✧ &8✦"),
                color("&7划开夜幕的紫色星光"),
                color("&8✦ &5✧ &d✦ &5✧ &8✦")
        ));
        meta.setCustomModelData(24001);
        meta.getPersistentDataContainer().set(swordKey, PersistentDataType.BYTE, (byte) 1);

        XEnchantment.matchXEnchantment("SHARPNESS")
                .ifPresent(enchantment -> meta.addEnchant(enchantment.getEnchant(), 5, true));
        XEnchantment.matchXEnchantment("UNBREAKING")
                .ifPresent(enchantment -> meta.addEnchant(enchantment.getEnchant(), 3, true));

        sword.setItemMeta(meta);
        return sword;
    }

    private void registerRecipe() {
        Material obsidian = material("OBSIDIAN");
        Material purpleDye = material("PURPLE_DYE");
        Material netherStar = material("NETHER_STAR");
        Material amethyst = material("AMETHYST_SHARD");
        Material stick = material("STICK");

        if (obsidian == null || purpleDye == null || netherStar == null || amethyst == null || stick == null) {
            return;
        }

        ShapedRecipe recipe = new ShapedRecipe(new NamespacedKey(this, "starry_sky_short_sword"), createSword());
        recipe.shape("OPO", "NAN", " S ");
        recipe.setIngredient('O', obsidian);
        recipe.setIngredient('P', purpleDye);
        recipe.setIngredient('N', netherStar);
        recipe.setIngredient('A', amethyst);
        recipe.setIngredient('S', stick);
        getServer().addRecipe(recipe);
    }

    private Material material(String name) {
        return XMaterial.matchXMaterial(name).map(XMaterial::parseMaterial).orElse(null);
    }

    private String color(String message) {
        return ChatColor.translateAlternateColorCodes('&', message);
    }
}