fenox_god
📎 1 file 6,418 chars
📄
pasted-code-1794943180182.txt
txt 186 lines
▶
Create a complete Minecraft plugin for Paper 1.21.11 using Java 21.

The plugin must add five custom craftable maces:

1. Stormbreaker Mace
2. Black Hole Mace
3. Hell Mace
4. Frost Mace
5. Wind Mace

## Strength ranking

Keep this strength ranking:

1. Stormbreaker Mace — strongest
2. Black Hole Mace
3. Hell Mace
4. Frost Mace
5. Wind Mace — weakest

Each mace must have:

- A unique colored name.
- A unique 3D texture from the supplied resource pack.
- Three powers.
- Configurable cooldowns.
- Crafting recipes.
- Particles and sounds.
- A persistent custom item ID so normal renamed maces cannot use powers.

## Mace colors and texture IDs

Use the supplied 3D mace resource pack as the base. Keep its original 3D model and recolor its existing textures only.

| Mace | Name Color | Texture Color | Item Model ID |
|---|---|---|---|
| Stormbreaker Mace | Yellow | Yellow | `custommaces:stormbreaker` |
| Black Hole Mace | Black/Dark Gray | Black | `custommaces:blackhole` |
| Hell Mace | Red | Red | `custommaces:hell` |
| Frost Mace | Blue | Blue | `custommaces:frost` |
| Wind Mace | White | White | `custommaces:wind` |

Use Paper 1.21.11 item model metadata to assign the correct model to each custom mace. Also use PersistentDataContainer to store a unique mace ID for power detection.

## Damage rules

All damage values must be written in hearts.

One heart equals 2 Minecraft health points.

Convert heart values correctly when applying damage through the Paper API. Make all damage values configurable in `config.yml`.

Default power damage:

- Stormbreaker: Power 1 = 300 hearts, Power 2 = 200 hearts, Power 3 = 100 hearts.
- Black Hole: Power 1 = 200 hearts, Power 2 = 150 hearts, Power 3 = 100 hearts.
- Hell: Power 1 = 100 hearts, Power 2 = 90 hearts, Power 3 = 80 hearts.
- Frost: Power 1 = 100 hearts, Power 2 = 90 hearts, Power 3 = 50 hearts.
- Wind: Power 1 = 90 hearts, Power 2 = 50 hearts, Power 3 = 25 hearts.

## Power controls

Use these controls:

- Right-click: Power 1
- Sneak + right-click: Power 2
- Sneak + left-click: Power 3

Do not allow one click to activate multiple powers. Show cooldown time in the action bar.

## Powers

### Stormbreaker Mace

Display name: `&e&lStormbreaker Mace`

1. **Thunder Strike** — 25 second cooldown  
   Target an enemy within 20 blocks. Strike lightning without fire and deal 300 hearts. Use electric spark, cloud, and lightning particles with thunder sounds.

2. **Storm Slam** — 40 second cooldown  
   Damage enemies within 6 blocks for 200 hearts and knock them back. Use a circular electric spark and cloud particle explosion.

3. **Tempest Guard** — 60 second cooldown  
   Give the player a lightning shield for 8 seconds. Enemies that attack the player take 100 hearts of lightning damage. Use electric spark particles around the player.

### Black Hole Mace

Display name: `&0&lBlack Hole Mace`

1. **Gravity Well** — 30 second cooldown  
   Create a black hole up to 16 blocks away. Pull enemies within 6 blocks toward it for 3 seconds, then deal 200 hearts. Use portal, dragon breath, smoke, and dark dust particles.

2. **Singularity Slam** — 45 second cooldown  
   Pull enemies within 5 blocks toward the player, launch them upward, and deal 150 hearts. Use portal and smoke particles.

3. **Event Horizon** — 60 second cooldown  
   Create a gravity field around the player for 6 seconds. Pull and slow enemies within 4 blocks. Deal 100 hearts when the effect ends.

### Hell Mace

Display name: `&c&lHell Mace`

1. **Inferno Strike** — 25 second cooldown  
   Attack a target within 12 blocks, deal 100 hearts, and set the target on fire for 4 seconds. Use flame and lava particles.

2. **Magma Burst** — 40 second cooldown  
   Damage enemies within 5 blocks for 90 hearts, knock them back, and burn them for 3 seconds. Use flame and lava particles. Do not place real lava or fire blocks.

3. **Hellfire Trail** — 55 second cooldown  
   Leave a flame-particle trail for 6 seconds. Enemies touching it take 80 hearts per tick, with at least one second between damage hits for the same target.

### Frost Mace

Display name: `&9&lFrost Mace`

1. **Frostbite** — 20 second cooldown  
   Attack an enemy within 12 blocks, deal 100 hearts, and apply Slowness for 4 seconds. Use snowflake and cloud particles.

2. **Glacial Slam** — 35 second cooldown  
   Damage enemies within 4 blocks for 90 hearts, slow them for 3 seconds, and knock them back slightly. Use snowflake, cloud, and ice particles.

3. **Frozen Guard** — 50 second cooldown  
   Give the player Resistance for 5 seconds. Attackers take 50 hearts of frost damage and Slowness for 3 seconds. Use snowflake particles around the player.

### Wind Mace

Display name: `&f&lWind Mace`

1. **Gust Strike** — 15 second cooldown  
   Push a target within 10 blocks away and deal 90 hearts. Use cloud and sweep attack particles.

2. **Updraft** — 25 second cooldown  
   Launch the player upward safely, give Slow Falling for 5 seconds, and push enemies within 4 blocks away while dealing 50 hearts. Use spiral cloud particles.

3. **Cyclone** — 40 second cooldown  
   Create a whirlwind around the player for 4 seconds. Push nearby enemies away and deal 25 hearts once per second. Use rotating cloud and sweep attack particles.

## Recipes and commands

Create configurable shaped 3×3 crafting recipes for all five maces.

Recipes must be editable in `config.yml` without changing source code.

Add these commands:

- `/custommaces help`
- `/custommaces list`
- `/custommaces give   [amount]`
- `/custommaces giveall  [amount]`
- `/custommaces recipe `
- `/custommaces reload`

Mace IDs:

- `stormbreaker`
- `blackhole`
- `hell`
- `frost`
- `wind`

## Permissions

Add these permissions:

- `custommaces.use.stormbreaker`
- `custommaces.use.blackhole`
- `custommaces.use.hell`
- `custommaces.use.frost`
- `custommaces.use.wind`
- `custommaces.admin.give`
- `custommaces.admin.giveall`
- `custommaces.admin.reload`

## Deliverables

Provide:

- Complete Paper 1.21.11 Java source code.
- A working Maven or Gradle build.
- `plugin.yml`.
- Example `config.yml`.
- All five editable recipes.
- Resource-pack source files.
- A ready-to-use resource-pack ZIP containing the five colored 3D mace models.
- README with setup, commands, permissions, recipes, cooldowns, damage values, and resource-pack installation instructions.
- A successful build result.
Kodari AI
KodariTue at 7:22 pm 7
CustomMaces
A Paper 1.21.11 plugin adding five craftable 3D maces with unique powers, configurable cooldowns, and editable recipes. Features Stormbreaker, Black Hole, Hell, Frost, and Wind maces with three powers each, activated via right-click, sneak+right-click, and sneak+left-click. Includes persistent custom item IDs, particles, sounds, damage scaling, action bar cooldown display, admin commands, permissions, and a resource pack with recolored 3D models.

I’ll build the plugin, editable recipes and documentation. The supplied attachment contains the specification but no resource-pack files; texture and model generation can be enabled in Settings → Generation, or for all projects at https://kodari.ai/settings?tab=features.

Created the plugin source, configuration, editable recipes, commands, permissions, Gradle build, and README.

The resource-pack source and ZIP are not included because the original pack was not attached. A successful build has not yet been verified.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
README.md
settings.gradle
Code
6 493
src/main/java/com/kodari/custommaces/CustomMaces.java
package com.kodari.custommaces;

import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XPotion;
import com.cryptomorin.xseries.XSound;
import com.cryptomorin.xseries.particles.XParticle;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.Particle;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

public final class CustomMaces extends JavaPlugin implements Listener {
    private static final List<String> IDS = Arrays.asList("stormbreaker", "blackhole", "hell", "frost", "wind");
    private final Map<String, Long> cooldowns = new HashMap<>();
    private final Map<UUID, Long> stormGuards = new HashMap<>();
    private final Map<UUID, Long> frostGuards = new HashMap<>();
    private final Map<UUID, Long> safeFalls = new HashMap<>();
    private NamespacedKey itemId;
    private boolean reflectingDamage;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        itemId = new NamespacedKey(this, "mace_id");
        registerRecipes();
        Bukkit.getPluginManager().registerEvents(this, this);
        getCommand("custommaces").setExecutor(this::command);
    }

    private ItemStack makeItem(String id, int amount) {
        ItemStack item = XMaterial.matchXMaterial("MACE").map(XMaterial::parseItem).orElseThrow();
        item.setAmount(amount);
        ItemMeta meta = item.getItemMeta();
        meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', getConfig().getString("maces." + id + ".name", id)));
        meta.setItemModel(new NamespacedKey("custommaces", id));
        meta.getPersistentDataContainer().set(itemId, PersistentDataType.STRING, id);
        item.setItemMeta(meta);
        return item;
    }

    private String idOf(ItemStack item) {
        if (item == null || !item.hasItemMeta() || XMaterial.matchXMaterial(item.getType()) != XMaterial.matchXMaterial("MACE").orElse(null)) return null;
        String id = item.getItemMeta().getPersistentDataContainer().get(itemId, PersistentDataType.STRING);
        return IDS.contains(id) ? id : null;
    }

    private NamespacedKey recipeKey(String id) { return new NamespacedKey(this, id); }

    private void registerRecipes() {
        for (String id : IDS) {
            Bukkit.removeRecipe(recipeKey(id));
            String path = "maces." + id + ".recipe";
            List<String> shape = getConfig().getStringList(path + ".shape");
            ConfigurationSection ingredients = getConfig().getConfigurationSection(path + ".ingredients");
            if (shape.size() != 3 || shape.stream().anyMatch(row -> row.length() != 3) || ingredients == null) {
                getLogger().warning("Invalid recipe for " + id);
                continue;
            }
            try {
                ShapedRecipe recipe = new ShapedRecipe(recipeKey(id), makeItem(id, 1));
                recipe.shape(shape.toArray(new String[0]));
                for (String key : ingredients.getKeys(false)) {
                    if (key.length() != 1 || key.charAt(0) == ' ') throw new IllegalArgumentException("Invalid ingredient key " + key);
                    Material material = XMaterial.matchXMaterial(ingredients.getString(key, "")).map(XMaterial::parseMaterial).orElseThrow();
                    recipe.setIngredient(key.charAt(0), material);
                }
                if (!Bukkit.addRecipe(recipe)) getLogger().warning("Could not register recipe for " + id);
            } catch (IllegalArgumentException | java.util.NoSuchElementException ex) {
                getLogger().warning("Invalid recipe for " + id + ": " + ex.getMessage());
            }
        }
    }

    @EventHandler(ignoreCancelled = true)
    public void onCraft(CraftItemEvent event) {
        if (!(event.getRecipe() instanceof ShapedRecipe)) return;
        ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
        if (!recipe.getKey().getNamespace().equals(getName().toLowerCase(java.util.Locale.ROOT)) || !IDS.contains(recipe.getKey().getKey())) return;
        for (ItemStack ingredient : event.getInventory().getMatrix()) {
            if (idOf(ingredient) != null) {
                event.setCancelled(true);
                event.getWhoClicked().sendMessage(ChatColor.RED + "Custom maces cannot be used as recipe ingredients.");
                return;
            }
        }
    }

    private double value(String id, String key, int power) {
        List<Double> values = getConfig().getDoubleList("maces." + id + "." + key);
        return values.size() > power ? Math.max(0, values.get(power)) : 0;
    }

    @EventHandler(ignoreCancelled = true)
    public void onInteract(PlayerInteractEvent event) {
        if (event.getHand() != EquipmentSlot.HAND) return;
        Player player = event.getPlayer();
        String id = idOf(player.getInventory().getItemInMainHand());
        if (id == null) return;
        Action action = event.getAction();
        boolean right = action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK;
        boolean left = action == Action.LEFT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK;
        if (!right && !(left && player.isSneaking())) return;
        event.setCancelled(true);
        if (!player.hasPermission("custommaces.use." + id)) { player.sendMessage(ChatColor.RED + "You cannot use this mace."); return; }
        int power = right ? (player.isSneaking() ? 1 : 0) : 2;
        String key = player.getUniqueId() + ":" + id + ":" + power;
        long now = System.currentTimeMillis();
        long remaining = cooldowns.getOrDefault(key, 0L) - now;
        if (remaining > 0) { player.sendActionBar(Component.text("Cooldown: " + (long) Math.ceil(remaining / 1000.0) + "s")); return; }
        if (power == 0 && !id.equals("blackhole") && target(player, range(id)) == null) {
            player.sendActionBar(Component.text("No target in range"));
            return;
        }
        cooldowns.put(key, now + (long) (value(id, "cooldown-seconds", power) * 1000));
        player.sendActionBar(Component.text("Power " + (power + 1) + " activated"));
        activate(player, id, power, value(id, "damage-hearts", power) * 2.0);
    }

    private double range(String id) { return id.equals("stormbreaker") ? 20 : id.equals("wind") ? 10 : 12; }

    private LivingEntity target(Player player, double range) {
        org.bukkit.util.RayTraceResult result = player.getWorld().rayTraceEntities(player.getEyeLocation(), player.getEyeLocation().getDirection(), range, 0.5,
                entity -> entity instanceof LivingEntity && entity != player && !entity.isDead());
        if (result == null || !(result.getHitEntity() instanceof LivingEntity)) return null;
        LivingEntity entity = (LivingEntity) result.getHitEntity();
        return player.hasLineOfSight(entity) ? entity : null;
    }

    private List<LivingEntity> enemies(Player player, Location center, double radius) {
        List<LivingEntity> result = new ArrayList<>();
        for (Entity entity : center.getWorld().getNearbyEntities(center, radius, radius, radius)) {
            if (entity instanceof LivingEntity && entity != player && !entity.isDead() && entity.getLocation().distanceSquared(center) <= radius * radius) result.add((LivingEntity) entity);
        }
        return result;
    }

    private void damage(Player source, LivingEntity target, double amount) { if (amount > 0 && !target.isDead()) target.damage(amount, source); }
    private void potion(LivingEntity entity, String name, int ticks, int amplifier) {
        XPotion.matchXPotion(name).map(p -> p.buildPotionEffect(ticks, amplifier)).ifPresent(entity::addPotionEffect);
    }
    private void particle(Location location, String name, int count, double spread) {
        XParticle.of(name).ifPresent(p -> location.getWorld().spawnParticle(p.get(), location, count, spread, spread, spread, 0.02));
    }
    private void sound(Player player, String name) { XSound.matchXSound(name).ifPresent(s -> s.play(player)); }
    private void push(LivingEntity entity, Location origin, double strength, double up) {
        Vector v = entity.getLocation().toVector().subtract(origin.toVector()).setY(0);
        if (v.lengthSquared() < 0.0001) v = new Vector(1, 0, 0);
        entity.setVelocity(v.normalize().multiply(strength).setY(up));
    }
    private void pull(LivingEntity entity, Location center, double strength) {
        Vector v = center.toVector().subtract(entity.getLocation().toVector());
        if (v.lengthSquared() > 0.01) entity.setVelocity(v.normalize().multiply(strength));
    }
    private void ring(Location center, String particle, double radius, int step) {
        for (int i = 0; i < 24; i++) {
            double angle = 2 * Math.PI * i / 24 + step * 0.2;
            particle(center.clone().add(Math.cos(angle) * radius, 0.3 + (i % 4) * 0.3, Math.sin(angle) * radius), particle, 1, 0);
        }
    }

    private void activate(Player p, String id, int power, double damage) {
        Location center = p.getLocation();
        if (id.equals("stormbreaker")) {
            sound(p, "ENTITY_LIGHTNING_BOLT_THUNDER");
            if (power == 0) {
                LivingEntity t = target(p, 20); if (t == null) return;
                t.getWorld().strikeLightningEffect(t.getLocation()); damage(p, t, damage);
                particle(t.getLocation(), "ELECTRIC_SPARK", 60, 1); particle(t.getLocation(), "CLOUD", 30, 1);
            } else if (power == 1) {
                for (LivingEntity t : enemies(p, center, 6)) { damage(p, t, damage); push(t, center, 1.3, 0.5); }
                ring(center, "ELECTRIC_SPARK", 6, 0); particle(center, "CLOUD", 60, 2);