You are an expert Paper plugin developer. Build a COMPLETE, compile-ready Paper
plugin called "MASL" (Mace And Spear Limiter). Output every file in full. Do NOT
use placeholders, "TODO", "...", or "rest of the code here". If your response
length is limited, finish ALL Tier 1 features completely first, then deliver
Tier 2 in a clearly labeled second part. Never truncate Tier 1 to fit Tier 2.
==================================================================
1. PROJECT SETUP
==================================================================
- Plugin name: MASL. Main class: MaslPlugin. Package: io.masl.limiter
(the owner will rename it later, so keep it in one package root).
- Platform: Paper only (Purpur may be tested later, so do not break on forks).
- Target Minecraft versions: 1.21.11, 26.2 and 26.3.
- Build system: Gradle (Kotlin DSL), with the Gradle wrapper commands in the
instructions. Compile against the Paper API for 1.21.11 and use ONLY stable,
public Bukkit/Paper API calls.
- NO NMS, NO CraftBukkit imports, NO reflection into server internals.
- Compile with Java toolchain/release 21 so the jar loads on 1.21.11 (Java 21) AND
on 26.x (which requires a Java 25 runtime). State this clearly in the build notes.
- plugin.yml: name, version, main, api-version "1.21", authors, description,
commands (masl, with aliases), permissions. In the build notes, tell the
owner what to change in api-version if Paper 26.x rejects it.
- Dependencies: none. Use Paper's built-in Adventure MiniMessage for all messages.
- Not Folia-compatible; do not declare folia-supported.
- Performance matters: this runs on low-end servers. Early-return from every
event handler as soon as the item/player is not relevant. No per-tick repeating
tasks. No full-world scans.
==================================================================
2. DEFINITIONS
==================================================================
- "Weapon types": exactly two, "mace" and "spear".
- MACE = Material.MACE.
- SPEAR = ANY Material whose name ends with "_SPEAR" (case-insensitive, found by
iterating Material.values() once at startup and again on reload). Do NOT
hardcode spear materials, so new tiers added by future updates work
automatically. Unknown/new spear materials default to ALLOWED.
- Provide one helper class (WeaponType + ItemClassifier) that answers:
isMace(ItemStack), isSpear(ItemStack), getType(ItemStack) -> WeaponType or null,
and handles null/air safely. Use it everywhere.
- Resolve enchantments by NamespacedKey through Paper's enchantment registry.
If an enchantment key is missing on the current version, log a warning once
and skip it. NEVER throw.
==================================================================
3. CONFIG (config.yml) - EXACT STRUCTURE
==================================================================
Use this exact structure, with comments explaining every key. Generate it on
first run from the jar's default config.
settings:
prefix: "[MASL] "
audit-on-join: true
audit-interval-seconds: 0 # 0 = off. Else re-check online players periodically
exceed-action: DROP # DROP = drop excess items at player's feet, REMOVE = delete them
denied-enchant-action: STRIP # STRIP = remove enchant, DELETE_ITEM = remove the item
disabled-weapon-action: BLOCK_USE # what happens to existing items when a type is disabled
notify-cooldown-actionbar: true
mace:
enabled: true
limit: infinite # integer >= 0, or "infinite"
limit-scope: PLAYER # PLAYER or SERVER
cooldown-seconds: 0 # 0 = off. Decimals allowed (e.g. 2.5)
enchantments: {} # see below
spear:
enabled: true
limit: infinite
limit-scope: PLAYER
cooldown-seconds: 0
enchantments: {}
materials: {} # e.g. iron_spear: deny (missing = allow)
messages: # every player-facing message, MiniMessage format
(list every message with {placeholders}: {type} {limit} {current}
{seconds} {enchantment} {level} {material} {player} {error})
Enchantment rules format (per weapon type), keyed by namespaced key without the
"minecraft:" prefix when vanilla:
enchantments:
density: { mode: max, max-level: 3 }
breach: { mode: deny }
wind_burst: { mode: allow }
Missing = allowed at any level. Modes: allow, deny, max (requires max-level >= 1).
Config handling rules:
- The config is the single source of truth. Every command writes to it
immediately and saves.
- Parse config into an IMMUTABLE settings snapshot object (e.g. MaslSettings).
Event handlers only read from the current snapshot (a volatile/atomic reference).
Reload builds a new snapshot and swaps it atomically.
- Parsing is tolerant: accept "infinite", "inf", "unlimited" (any case) for limit.
Reject negative numbers. Invalid values never crash; they produce a clear error.
- Keep comments in the saved config where the API allows it.
==================================================================
4. COMMANDS (root: /masl, alias /maceandspear)
==================================================================
All commands must work from console and players. Full tab-completion on every
argument, filtered by permission. Invalid usage prints the exact correct usage.
/masl help
/masl info [mace|spear]
Shows, per type: enabled, limit, scope, cooldown, enchant rules, (for
spear) denied materials, and the detected spear materials on this version.
/masl reload
/masl limit
/masl scope
/masl cooldown
/masl enable
/masl disable
/masl enchant [level]
"max" REQUIRES a level >= 1. allow/deny must not take a level.
/masl enchant reset
/masl enchant list
/masl spear material
Tab-complete only detected *_SPEAR materials. Accept names with or
without "minecraft:" and in any case.
/masl spear material list
Validation:
- limit: integer >= 0 or infinite. 0 means nobody may hold any.
- cooldown: number > 0 and <= 3600, or "off".
- Unknown enchantment/material -> friendly error with suggestions.
- Every successful change shows a confirmation including old -> new value.
- After any change that could affect online players (limit, enable/disable,
enchant or material rules), re-run the enforcement audit on all online players.
RELOAD (/masl reload) behavior - must be exact:
1. Re-read config.yml from disk (reloadConfig()).
2. Parse and validate into a NEW snapshot. If anything is invalid, KEEP THE OLD
WORKING SNAPSHOT, and tell the sender exactly which key is wrong and why.
3. If valid: swap the snapshot, rebuild the spear material list, re-run the
enforcement audit for all online players, and send a success message that
includes any non-fatal warnings (e.g. unknown enchantment keys).
4. Never require a server restart. Log the result to console too.
==================================================================
5. PERMISSIONS
==================================================================
- masl.admin (default: op): all /masl subcommands.
- masl.info (default: op): /masl info and /masl help only.
- masl.bypass.limit, masl.bypass.cooldown, masl.bypass.enchant,
masl.bypass.material (default: false), and parent masl.bypass that grants all four.
- masl.admin must NOT grant bypass automatically.
- Players with a bypass node are exempt from that specific rule only.
==================================================================
6. FEATURE BEHAVIOR - TIER 1 (must be perfect)
==================================================================
6.1 ENABLE/DISABLE
- If a type is disabled: cancel ALL attacks with it, block crafting it, and block
picking it up. Existing items are NOT deleted (disabled-weapon-action BLOCK_USE).
Send a throttled message (max 1 per 3 seconds per player).
6.2 COOLDOWN
- Applies per player, per weapon type. Triggered when a player successfully
attacks with the weapon in the main hand: listen for EntityDamageByEntityEvent
where the damager is a Player and the main-hand item is a mace/spear. Do NOT
depend on one specific DamageCause (spear jab, spear charge, and mace smash
attacks must ALL trigger it).
- On trigger: call Player#setCooldown(Material, ticks) with ticks = seconds * 20
so the hotbar shows the same overlay animation as a shield disabled by an
axe. Use the held item's exact material.
- While the cooldown is active (check Player#hasCooldown / getCooldown), cancel
further damage events from that weapon. The vanilla overlay does not stop melee,
so cancel the event ourselves.
- Optional actionbar message with remaining seconds when an attack is blocked,
throttled (settings.notify-cooldown-actionbar).
- Players with masl.bypass.cooldown ignore it. Cooldown 0/off = fully disabled.
- Also apply when a mace smash attack is used regardless of fall distance.
6.3 LIMIT - scope PLAYER (implement fully)
- A player's count = all matching items in: main inventory, hotbar, armor slots,
offhand, and ender chest. Count item amounts, not just stacks.
- PREVENT (cancel the event + message) in: EntityPickupItemEvent (players only),
CraftItemEvent / PrepareItemCraftEvent (set result to air when it would exceed),
and InventoryCreativeEvent.
- CORRECT (schedule a task 1 tick later) after: InventoryClickEvent,
InventoryDragEvent, PlayerSwapHandItemsEvent, PlayerDropItemEvent, any trade or
result-slot click, then run enforce(player). enforce() finds any excess and
applies settings.exceed-action. For DROP, drop excess at the player's feet
with a pickup delay of at least 40 ticks and notify the player.
- On PlayerJoinEvent (if settings.audit-on-join) run enforce(player), after a
short delay of ~10 ticks.
- Optional repeating audit if settings.audit-interval-seconds > 0.
- Limit "infinite" = never enforced. masl.bypass.limit = exempt.
- Count shulker box contents too if the shulker is in the player's inventory
(setting count-shulker-contents: true by default). Implement via BlockStateMeta
+ ShulkerBox inventory. Keep this isolated in its own method.
6.4 ENCHANTMENT RESTRICTIONS
- deny: the enchantment cannot be applied or held. max: level is capped.
- PREVENT in: PrepareAnvilEvent (set result to null or clamp when the result
would contain a denied/over-max enchant, including enchanted books combined
onto the weapon), PrepareItemEnchantEvent + EnchantItemEvent (remove denied
offers / remove denied or over-max enchants from the to-add map).
- CORRECT for existing items (on pickup, join, and enforce()): STRIP denied
enchants, CLAMP over-max levels down to the max, or DELETE_ITEM, per
settings.denied-enchant-action. Handle enchanted-book-style stored enchantments
on the weapon only when they are normal enchantments.
- Mace and spear rules are independent. masl.bypass.enchant = exempt.
6.5 SPEAR MATERIAL RESTRICTION
- A denied spear material cannot be crafted, picked up, or used to attack. Use the
same prevent/correct patterns as the limit. Existing denied spears in
inventories are handled by exceed-action (DROP or REMOVE) during enforce().
- Missing entries = allowed. masl.bypass.material = exempt.
==================================================================
7. TIER 2 (implement after Tier 1 is fully complete)
==================================================================
SERVER limit scope:
- Each weapon type has its own scope. When scope = SERVER, "limit" is the max
number of that weapon allowed to exist on the whole server.
- Track each item with a UUID stored in PersistentDataContainer under the key
masl:tracked_id. A registry of live ids per type is persisted in data.yml
(save async-safe, load on enable, save on disable and periodically).
- An unstamped weapon that a player gains is registered if the registry is below
the limit; otherwise it is blocked or removed, with a message.
- Unregister ids when the item is destroyed: PlayerItemBreakEvent, and in
EntityRemoveEvent for item entities when the cause is DESPAWN or DEATH.
- Because not every destruction path can be tracked, add admin tools:
/masl registry list
/masl registry remove
/masl registry clear
and document this limitation honestly in the README.
- Keep SERVER mode in its own classes (ServerLimitManager, TrackedItemRegistry)
so a bug there cannot break PLAYER mode.
==================================================================
8. CODE QUALITY RULES
==================================================================
- Suggested classes: MaslPlugin, MaslSettings (+ parser), WeaponType,
ItemClassifier, MaslCommand (executor + TabCompleter), LimitManager,
CooldownManager, EnchantRestrictionManager, MaterialRestrictionManager,
MessageService, listener classes per concern, ServerLimitManager,
TrackedItemRegistry.
- Every public method gets a short comment. Every class gets a one-line purpose.
- Null-check everything: items, metas, worlds, offline players.
- No exceptions may reach players. Catch, log a concise warning to console, and
show a friendly message.
- Messages sent via MiniMessage with placeholder replacement. No legacy color codes.
- Thread safety: all Bukkit API calls on the main thread only.
- Do not use deprecated APIs where a stable replacement exists.
==================================================================
9. REQUIRED OUTPUT FORMAT
==================================================================
1. A file tree.
2. EVERY file in full, each in its own code block labeled with its path:
build.gradle.kts, settings.gradle.kts, gradle.properties (if needed),
plugin.yml, config.yml, all source files, README.md.
3. Build instructions for Linux and Windows (the exact ./gradlew build command and
where the output jar is).
4. Install instructions (drop the jar in /plugins, start, edit config, /masl reload).
5. A "Assumptions and API notes" section listing any API call you were unsure
exists on all of 1.21.11, 26.2 and 26.3.
6. A short manual test checklist: limit blocks pickup, drop-on-join audit works,
cooldown overlay appears and blocks attacks, anvil rejects a denied enchant,
a denied spear material cannot be crafted, /masl reload applies a hand-edited
config and rejects a broken one without losing the old settings.
7. Known limitations, stated honestly.