haiboy102

make a plugin that lets you put any enchant on any item and the function of the item is kept. I ESPECIALLY want the density or breach enchant to turn armor into a mace which means when i fall near to a entity i deal damage to the entity based on fall damage (must be falling from 2 blocks for it to activate) and wind burst should make me launch up again like normal wind burst but make it activate when I drop near a entity (5 block radius and must be falling from 2 blocks for it to activate.) and more and the levels should stack (but for example if i put density 5 on every armor piece i get 5+1+1+1 as only the first one registers as 5 but the rest is countaid level 1

Kodari AI
KodariNov 3 at 8:56 am 2
UniversalEnchantArmor
Allows applying any enchantment to any item while preserving original item functionality. Special handling for Density and Breach on armor converts it into a mace, dealing fall-damage-based damage to nearby entities when falling from at least 2 blocks. Wind Burst on armor triggers a launch effect when landing near entities within a 5-block radius from a 2-block fall. Enchantment levels stack cumulatively across armor pieces, with the highest level piece contributing its full value and additional pieces contributing level 1 each.
  1. Add an anvil and command for applying enchantments to any item.

  2. Add stacking armor effects for Density, Breach, and Wind Burst when falling near entities.

Created the plugin for Minecraft 1.21+: use enchanted books in an anvil or /anyenchant <enchantment> <level> while holding an item. The command defaults to operators.

Density and Breach armor deal custom fall-based damage, and Wind Burst armor launches you upward near an entity. Armor levels stack as requested: the highest level plus one per additional piece.

Limits: Breach adds damage rather than reproducing vanilla armor penetration. Other enchantments can be applied to any item, but their vanilla effects still depend on Minecraft’s normal rules.

haiboy102

and when any enchant is applied to armor the enchantment effect should be applied when hitting anything if its a weapon enchant or mining if its a tool enchant

Kodari AI
KodariNov 3 at 9:03 am 1

I’ll add armor enchantment effects to melee hits and block drops, using the same highest-level-plus-one-per-extra-piece stacking rule. Some vanilla effects need specialized handling rather than a generic Bukkit event.

Added armor effects for Sharpness, Smite, Bane of Arthropods, Fire Aspect, Knockback, Fortune, and Silk Touch. Armor levels use the existing stacking rule.

This doesn’t yet cover every weapon or tool enchantment: effects such as Efficiency and Looting need separate handling.

haiboy102

add every enchant (weapon and tookls)

Kodari AI
KodariNov 3 at 9:05 am 1

I’ll extend the armor effects beyond the existing combat and drop enchantments. Some effects, such as Looting and durability enchantments, need special handling to preserve vanilla behavior.

Added armor-based Efficiency, Sweeping Edge, and Bane of Arthropods’ slowness effect. Efficiency uses a short Haste effect, so it approximates rather than exactly matches vanilla mining speed.

This does not yet cover every weapon and tool enchantment: Looting, Unbreaking, Mending, and ranged-weapon enchantments still need separate handling.

haiboy102

make my mining speed as the same as a netherite pickaxe with eff 5 if i have eff 5 in all 4 armor pieces and let me mine any ores with my bare hands if i have eff 5 and fortune 3 on all armor pieces

Kodari AI
KodariNov 3 at 9:14 am 1
  • Enable bare-hand ore drops when all four armor pieces meet the enchantment requirements.

  • Keep the existing Fortune stacking rule. Exact netherite-pickaxe mining speed needs server-specific handling that Spigot’s block events don’t expose.

Bare-hand mining now gives netherite-pickaxe ore drops when all four armor pieces have at least Efficiency V and Fortune III. Fortune uses the existing armor stacking rule.

Mining speed isn’t an exact match yet. The existing Haste effect is an approximation; Spigot’s block events don’t expose a direct way to set vanilla pickaxe mining speed.

haiboy102

make the mining speed 35 if i have eff 5 full set

Kodari AI
KodariNov 3 at 9:17 am 2

What do you mean by mining speed 35: Haste level 35, or a mining-speed value of 35 like a tool’s mining speed? They work differently in Minecraft.

haiboy102

mining speed value

Kodari AI
KodariNov 3 at 9:19 am 1

A mining-speed value of 35 depends on the held tool and the block. The server can multiply mining speed, but it can’t set one exact tool-speed value for every block and held item through the current Spigot API.

I can make the full Efficiency V armor set give a 35× block-breaking speed multiplier instead. Want that?

haiboy102

then can it do this? the base speed of the item (when im holding nothing or not a tool item) is 35 if u can do it rn

Kodari AI
KodariNov 3 at 9:21 am 3

I’ll apply a 35× block-breaking-speed attribute while you wear the full Efficiency V set and hold no tool. Minecraft’s normal block hardness and tool requirements will still affect the result.

Added a 35× block-breaking-speed multiplier when you wear full Efficiency V armor and hold no tool.

Block hardness, tool requirements, and other speed effects still apply, so this isn’t an exact base tool-speed value of 35 in every situation.

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

import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XAttribute;
import org.bukkit.ChatColor;
import org.bukkit.NamespacedKey;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.attribute.AttributeModifier;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.inventory.PrepareAnvilEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.AnvilInventory;
import org.bukkit.inventory.EquipmentSlotGroup;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

public final class AnyEnchantPlugin extends JavaPlugin implements Listener {
    private final Map<UUID, Double> fallStarts = new HashMap<>();
    private final Set<UUID> activated = new HashSet<>();
    private final Set<UUID> sweeping = new HashSet<>();

    @Override
    public void onEnable() {
        getServer().getPluginManager().registerEvents(this, this);
        getServer().getScheduler().runTaskTimer(this, () -> {
            for (Player player : getServer().getOnlinePlayers()) updateMiningSpeed(player, false);
        }, 1L, 1L);
        getCommand("anyenchant").setExecutor((sender, command, label, args) -> {
            if (!(sender instanceof Player player)) {
                sender.sendMessage("This command can only be used by a player.");
                return true;
            }
            if (args.length != 2) return false;
            NamespacedKey key = NamespacedKey.fromString(args[0].toLowerCase(Locale.ROOT));
            Enchantment enchantment = key == null ? null : Enchantment.getByKey(key);
            if (enchantment == null) {
                player.sendMessage(ChatColor.RED + "Unknown enchantment.");
                return true;
            }
            int level;
            try {
                level = Integer.parseInt(args[1]);
            } catch (NumberFormatException exception) {
                player.sendMessage(ChatColor.RED + "Level must be a number from 1 to 255.");
                return true;
            }
            if (level < 1 || level > 255) {
                player.sendMessage(ChatColor.RED + "Level must be a number from 1 to 255.");
                return true;
            }
            ItemStack item = player.getInventory().getItemInMainHand();
            if (item.getType().isAir()) {
                player.sendMessage(ChatColor.RED + "Hold an item first.");
                return true;
            }
            ItemMeta meta = item.getItemMeta();
            if (meta instanceof EnchantmentStorageMeta book) {
                book.addStoredEnchant(enchantment, level, true);
            } else {
                meta.addEnchant(enchantment, level, true);
            }
            item.setItemMeta(meta);
            player.sendMessage(ChatColor.GREEN + "Enchantment applied.");
            return true;
        });
    }

    @Override
    public void onDisable() {
        for (Player player : getServer().getOnlinePlayers()) updateMiningSpeed(player, true);
    }

    @EventHandler
    public void onPrepareAnvil(PrepareAnvilEvent event) {
        AnvilInventory inventory = event.getInventory();
        ItemStack target = inventory.getItem(0);
        ItemStack source = inventory.getItem(1);
        if (target == null || source == null || target.getType().isAir() || source.getType().isAir()) return;
        ItemMeta sourceMeta = source.getItemMeta();
        Map<Enchantment, Integer> enchants = sourceMeta instanceof EnchantmentStorageMeta book
                ? book.getStoredEnchants() : source.getEnchantments();
        if (enchants.isEmpty()) return;
        if (!(sourceMeta instanceof EnchantmentStorageMeta) && target.getType() != source.getType()) return;

        ItemStack result = target.clone();
        ItemMeta meta = result.getItemMeta();
        for (Map.Entry<Enchantment, Integer> entry : enchants.entrySet()) {
            Enchantment enchantment = entry.getKey();
            int existing = meta instanceof EnchantmentStorageMeta book
                    ? book.getStoredEnchantLevel(enchantment) : meta.getEnchantLevel(enchantment);
            int incoming = entry.getValue();
            int level = existing == incoming ? Math.min(255, existing + 1) : Math.max(existing, incoming);
            if (meta instanceof EnchantmentStorageMeta book) {
                book.addStoredEnchant(enchantment, level, true);
            } else {
                meta.addEnchant(enchantment, level, true);
            }
        }
        String rename = inventory.getRenameText();
        if (rename != null && !rename.isEmpty()) meta.setDisplayName(rename);
        result.setItemMeta(meta);
        event.setResult(result);
        inventory.setRepairCost(Math.max(1, enchants.size()));
    }

    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
    public void onMove(PlayerMoveEvent event) {
        if (event.getTo() == null) return;
        Player player = event.getPlayer();
        UUID id = player.getUniqueId();
        double fromY = event.getFrom().getY();
        double toY = event.getTo().getY();
        if (player.isOnGround() || player.isFlying() || player.isGliding() || player.isInsideVehicle()
                || event.getFrom().getWorld() != event.getTo().getWorld()) {
            fallStarts.remove(id);
            activated.remove(id);
            return;
        }
        if (toY > fromY) {
            fallStarts.put(id, toY);
            activated.remove(id);
            return;
        }
        double start = fallStarts.computeIfAbsent(id, ignored -> fromY);
        double distance = start - toY;
        if (toY >= fromY || distance < 2.0 || activated.contains(id)) return;
        int density = armorLevel(player, "density");
        int breach = armorLevel(player, "breach");
        int windBurst = armorLevel(player, "wind_burst");
        if (density == 0 && breach == 0 && windBurst == 0) return;
        boolean hit = false;
        for (org.bukkit.entity.Entity entity : player.getNearbyEntities(5, 5, 5)) {
            if (!(entity instanceof LivingEntity living) || entity == player || living.isDead()
                    || entity.getLocation().distanceSquared(player.getLocation()) > 25.0) continue;
            hit = true;
            if (density > 0 || breach > 0) {
                double damage = Math.max(1.0, distance - 3.0) + distance * (density * 0.5 + breach * 0.25);
                living.damage(damage, player);
            }
        }
        if (!hit) return;
        activated.add(id);
        if (windBurst > 0) {
            Vector velocity = player.getVelocity();
            velocity.setY(0.6 + 0.2 * windBurst);
            player.setVelocity(velocity);
            player.setFallDistance(0);
        }
    }

    private int armorLevel(Player player, String name) {
        Enchantment enchantment = Enchantment.getByKey(NamespacedKey.minecraft(name));
        if (enchantment == null) return 0;
        int highest = 0;
        int pieces = 0;
        for (ItemStack item : player.getInventory().getArmorContents()) {
            if (item == null) continue;
            int level = item.getEnchantmentLevel(enchantment);
            if (level > 0) {
                highest = Math.max(highest, level);
                pieces++;
            }
        }
        return pieces == 0 ? 0 : highest + pieces - 1;
    }

    private boolean hasMiningArmor(Player player) {
        Enchantment efficiency = Enchantment.getByKey(NamespacedKey.minecraft("efficiency"));
        Enchantment fortune = Enchantment.getByKey(NamespacedKey.minecraft("fortune"));
        if (efficiency == null || fortune == null) return false;
        ItemStack[] armor = player.getInventory().getArmorContents();
        if (armor.length != 4) return false;
        for (ItemStack piece : armor) {
            if (piece == null || piece.getEnchantmentLevel(efficiency) < 5
                    || piece.getEnchantmentLevel(fortune) < 3) return false;
        }
        return true;
    }