Описание
# Better Enchant Commands
**Override `/enchant`, `/give`, and friends with extended enchantment levels, simplified syntax, presets, and an audited confirmation/undo workflow for Minecraft 1.21.x.**
Vanilla `/enchant` refuses non-integer levels and caps out where the enchantment says so. Vanilla `/give` needs verbose component syntax for enchanted items. Better Enchant Commands replaces the two core commands and adds a handful of workflow helpers, all gated behind op level 2 and backed by a structured audit log.
## Features
### `/enchant` — enchant beyond vanilla limits
Drop-in replacement for vanilla `/enchant`. Apply any enchantment to the item in a player's hand at **levels 1–255**.
- `/enchant @s minecraft:sharpness 255`
- `/enchant aGamingGod minecraft:protection 10`
- `/enchant list`
`/enchant list` prints the enchantments on the held item of the player running the command.
### `/give` — inline enchantment syntax
Drop-in replacement for vanilla `/give`. Works exactly like normal when used without enchantments. Append an optional `enchantments:` block for instant enchanted items:
- `/give @s minecraft:netherite_chestplate enchantments:protection:10,unbreaking:3`
- `/give @s minecraft:diamond_sword 1 enchantments:sharpness:255,fire_aspect:5,looting:10`
The `minecraft:` namespace is optional — `sharpness:255` works. No JSON, no brackets, no quotes. Tab completion filters candidates to enchantments actually compatible with the chosen item.
### `/enchantpreset` — save and replay enchantment bundles
- `/enchantpreset save ` — save currently-held item's enchantments
- `/enchantpreset apply `
- `/enchantpreset delete `
- `/enchantpreset list`
Names are validated (1–64 chars, `A–Z`, `a–z`, `0–9`, `_`, `-`). Skipped empty-hand targets are reported in the output.
### `/unenchant`, `/enchantinfo`, `/enchantlist`
Cleanup and inspection helpers:
- `/unenchant ` — strip all enchantments
- `/unenchant ` — strip one
- `/enchantinfo` — full detail on held item
- `/enchantlist [filter]` — registry listing, optionally filtered
### `/repair` — mended gear in one command
Hands out a copy of any item with Mending (and Unbreaking III where compatible) pre-applied. The reflective compat lookup is cached per session so repeat invocations are fast.
### `/enchants` — bulk operations, undo, and config
- `/enchants undo` — restore your last bulk modification
- `/enchants confirm ` — complete a gated bulk operation
- `/enchants status`
- `/enchants allow_all_enchantments true|false`
Operations over `confirmation_threshold` targets require a short-lived token — no more accidental "enchanted the entire server" incidents. Undo is a bounded per-operator deque (default 8 entries).
## Design highlights
- **Fail-safe validation.** Enchantment strings parse into fully-validated `(Identifier, level)` pairs before any item is touched. Parse failures leave items unmodified.
- **Structured audit log.** Every privileged action is emitted to a dedicated SLF4J `[AUDIT]` logger with sanitised operator, target, and label fields — safe to route to a log-aggregation pipeline.
- **Log-injection hardened.** Any string originating from player input is stripped of ASCII control characters before being formatted into log lines, so a crafted scoreboard name can't forge or break audit entries.
- **Bounded bulk modifications.** Commands that affect more targets than `confirmation_threshold` require a token-based confirmation round-trip.
- **Reflective compatibility layer.** Permission checks, registry lookups, and component reads resolve via method-shape heuristics cached per class, so the same jar runs across **all 1.21.x minor versions** without recompilation.
- **Zero mixins.** Pure Fabric API command registration — maximum compatibility with other mods.
- **Server-side only.** Clients don't need the mod installed.
## Why Better Enchant Commands?
- **Drop-in replacements.** Overrides vanilla `/enchant` and `/give` directly; no new commands to memorise for the core workflow.
- **Fully backward compatible.** `/give @s diamond 64` still works exactly like vanilla.
- **Lightweight.** ~105 KB, server-side only, no tick hooks, no mixins.
- **Crash-proof.** Every code path is defensively wrapped; malformed input gives helpful error messages, never a server crash.
- **Cross-version.** Built against 1.21 base — works on every 1.21.x subversion without recompilation.
- **Preset-driven workflow.** Save standard loadouts once; apply them to any number of players with one command.
- **Audit trail.** Operators can be held accountable for what they enchanted, for whom, and when.
## Requirements
- Minecraft **1.21.x** (any subversion)
- Fabric Loader **0.16.0+**
- Fabric API
## Permissions
All commands require **operator level 2**, matching vanilla `/enchant` and `/give`.
## Technical notes
Better Enchant Commands writes directly to the `DataComponents.ENCHANTMENTS` component on item stacks, bypassing vanilla's level validation but enforcing its own bounds (1–255). Enchantments are stored exactly like vanilla ones — no custom data, no compatibility issues with other mods reading your items.