zexoplayz6-lang

Make a Minecraft Plugin which add a mace which has windburst 4 density 5 breech 5 and gives strength 5 while holding and speed 5 and a fire effect on the player while holding that mace for 26.2

Kodari AI
KodariAug 22 at 11:00 am 1
  1. Create the Gradle project and plugin metadata for a Paper 1.21.x plugin.

  2. Add the custom mace item with the requested enchantments and persistent identification.

  3. Add the /mace command and held-item effects: Strength V, Speed V, Fire Resistance, and flame particles refreshed for 26.2 seconds.

Created the MacePower Minecraft plugin.

Features:

  • /mace command gives the custom mace.

  • Mace enchantments:

    • Wind Burst IV

    • Density V

    • Breach V

  • While holding the mace:

    • Strength V

    • Speed V

    • Fire Resistance

    • Flame particle effect

  • Effects refresh for 26.2 seconds.

  • Custom persistent item identification prevents regular maces from triggering effects.

  • Includes Gradle setup and plugin.yml.

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

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.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;

public class MacePowerPlugin extends JavaPlugin implements CommandExecutor {

    private NamespacedKey maceKey;

    @Override
    public void onEnable() {
        maceKey = new NamespacedKey(this, "power_mace");
        getServer().getPluginManager().registerEvents(new MaceListener(this), this);
        getCommand("mace").setExecutor(this);
    }

    public NamespacedKey getMaceKey() {
        return maceKey;
    }

    public ItemStack createMace() {
        ItemStack mace = XMaterial.matchXMaterial("MACE")
                .map(XMaterial::parseItem)
                .orElse(null);
        if (mace == null) {
            return null;
        }

        ItemMeta meta = mace.getItemMeta();
        if (meta == null) {
            return null;
        }

        meta.setDisplayName(ChatColor.GOLD + "Mace of the Inferno");
        meta.setLore(java.util.List.of(
                ChatColor.GRAY + "Wind Burst IV",
                ChatColor.GRAY + "Density V",
                ChatColor.GRAY + "Breach V",
                ChatColor.RED + "Grants powerful effects while held"
        ));
        meta.getPersistentDataContainer().set(maceKey, PersistentDataType.BYTE, (byte) 1);
        addEnchantment(meta, "WIND_BURST", 4);
        addEnchantment(meta, "DENSITY", 5);
        addEnchantment(meta, "BREACH", 5);
        mace.setItemMeta(meta);
        return mace;
    }

    private void addEnchantment(ItemMeta meta, String name, int level) {
        XEnchantment.matchXEnchantment(name)
                .ifPresent(enchantment -> meta.addEnchant(enchantment.getEnchant(), level, true));
    }

    public boolean isMace(ItemStack item) {
        if (item == null || item.getType() == Material.AIR || !item.hasItemMeta()) {
            return false;
        }
        ItemMeta meta = item.getItemMeta();
        return meta != null && meta.getPersistentDataContainer().has(maceKey, PersistentDataType.BYTE);
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!(sender instanceof Player player)) {
            sender.sendMessage(ChatColor.RED + "Only players can use this command.");
            return true;
        }

        ItemStack mace = createMace();
        if (mace == null) {
            player.sendMessage(ChatColor.RED + "This server version does not support the mace item.");
            return true;
        }

        java.util.Map<Integer, ItemStack> leftovers = player.getInventory().addItem(mace);
        leftovers.values().forEach(item -> player.getWorld().dropItemNaturally(player.getLocation(), item));
        player.sendMessage(ChatColor.GOLD + "You received the Mace of the Inferno.");
        return true;
    }
}