# PROMPT: Build a complete Minecraft Crates plugin ("DeluxeCrates"-style, command `/dc`)
You are an expert Minecraft plugin developer (Paper/Spigot API, Java 17+, 1.20.x–1.21.x). Build a **complete, production-ready, fully configurable Crates plugin** with Maven or Gradle, a `plugin.yml`, and clean packages. Deliver **every file in full**: no placeholders, no "TODO", no "implement yourself". Everything below is mandatory.
---
## 1. CORE RULES
- Plugin name: `Crates`. Main command: `/dc` (aliases `/crates`, `/crate`).
- Everything user-facing must be configurable: **every message, GUI title, GUI item name/lore/material/slot, GUI size (rows), sound, action bar, title, subtitle, particle and broadcast.**
- Zero hardcoded strings in code. All text comes from `lang.yml`, `config.yml` or the GUI/crate files.
- Colour support everywhere: legacy `&` codes, `§` codes, hex `RRGGBB`, and small-caps unicode text (e.g. `ᴄʀᴀᴛᴇ`). Strip nothing.
- Be tolerant when reading YAML: reward keys may be quoted (`'1'`) or unquoted (`1`); `chance` may be written `10%`, `10.0%` or `10`; `chance` may sit inside `icon:` or beside it; a stray typo in one file must **never** stop the plugin. Log a clear warning with file name and line, skip only the broken part, keep loading.
- Async where safe (file I/O, saving). All inventory/world work on the main thread.
---
## 2. FOLDER STRUCTURE (auto-created on first start, with default example files)
```
plugins/Crates/
├── config.yml # general settings, sounds, broadcast
├── lang.yml # ALL messages + action bars + command usage
├── data.yml # crate block locations + player key data
├── crates/ # one file per crate: .yml
│ ├── common.yml
│ ├── gold.yml
│ ├── amethyst.yml
│ ├── crimson.yml
│ ├── dark.yml
│ └── prime.yml
├── keys/ # one file per crate key: .yml
├── effects/ # animation / opening-style files
│ ├── choose.yml
│ ├── rolling.yml
│ └── nowait.yml
└── gui/ # every GUI has its own file
├── confirm-gui.yml
├── itemeditor-gui.yml
├── crateeditor-gui.yml
├── rewardeditor-gui.yml
├── preview-gui.yml
├── list-gui.yml
└── (any other GUI = its own file)
```
Every GUI file defines: `title`, `rows` (size), and `items:` with `slot`, `action`, `icon` (`material`, `name`, `lore`, `custom-model-data`, `glow`) and per-GUI `sounds`.
---
## 2B. DEFAULT FILES ARE NOT HARDCODED (very important)
- The files in the **APPENDIX at the bottom** (`config.yml`, `lang.yml`, every crate, every effect, every GUI) are only **default templates**. Embed them as resources inside the jar and copy them out **only on the very first start** (when `plugins/Crates/` does not exist yet).
- After that first start, the plugin must **never recreate or overwrite** them. If the server owner deletes `gold.yml`, that crate is simply gone and must not come back after restart or `/dc reload`.
- **No crate, key, effect or GUI may be hardcoded in Java.** On startup and on `/dc reload`, scan the folders and load **every** `.yml` file found:
- every `crates/*.yml` = a crate (the top-level key, e.g. `gold-crate:`, is the crate id)
- every `keys/*.yml` = a key
- every `effects/*.yml` = an effect (the file name = the effect name, so a new `effects/myeffect.yml` can be used with `/dc seteffect myeffect`)
- every `gui/*.yml` = a GUI
- A new crate must work in **two ways**, with no restart and no code change:
1. Manually: copy a yml into `crates/`, run `/dc reload`.
2. By command: `/dc create ` generates the crate yml and key yml, then `/dc editor ` to fill it.
- `/dc remove ` deletes its files and unlinks its blocks. Missing files are never an error, only the `crate-not-found` message.
- If the owner deletes a file inside `lang.yml` / `config.yml`, add only the missing keys back, never touch the keys they already changed.
---
## 3. config.yml (exact structure to support)
```yaml
key-cooldown: 1 # seconds between key uses per player
sounds:
click-sound: UI_BUTTON_CLICK
confirm-sound: BLOCK_NOTE_BLOCK_PLING
denied-sound: BLOCK_NOTE_BLOCK_BASS
broadcast:
module:
chat:
enabled: false
message:
- "&f%player% &fopened a &a%crate% &fcrate and received &a%reward%&f!"
actionbar:
enabled: false
message: [""]
title:
enabled: false
message: [""]
subtitle:
enabled: false
message: [""]
```
Also add (all optional/configurable): `default-key-type`, `save-interval`, `debug`, `open-sound`, `anti-spam`, `inventory-full-behavior` (DROP / DENY / MAIL), per-crate broadcast override, and a `bstats`-free, metrics-free design. Each sound entry accepts `SOUND`, `SOUND;volume;pitch`. Any sound can be disabled by leaving it empty.
---
## 4. lang.yml (every message + action bar)
```yaml
prefix-enabled: false
prefix: ''
messages:
no-permission: "&cYou don't have permission to do this!"
player-only: "Only players can execute this command!"
reloaded: "&aCrates has been reloaded!"
invalid-usage: "&cUsage: %usage%"
crate-not-found: "&cCrate %crate% does not exist!"
invalid-amount: "&cInvalid amount!"
player-not-found: "&cPlayer not found!"
bind: "&cCrate bind to the block you are looking at!"
unbind: "&cCrate unbind from the block you are looking at!"
no-crate-bind: "&cNo crate is bind to this block!"
no-block: "&cYou must be looking at a block!"
effect-set: "&fEffect &a%effect% &fhas been set for crate &a%crate%&f!"
effect-removed: "&fEffect for crate &a%crate% &fhas been removed!"
invalid-effect: "&cInvalid effect!"
no-key: "&cYou don't have a key for this crate!"
received-keys: ""
given-keys: "&a%amount%x %crate% &fkeys have been given to &a%target%&f!"
removed-keys: "&a%amount% %crate% &fkeys have been removed!"
removed-all-keys: "&aAll %crate% &fkeys have been removed!"
inventory-full: "&cYour inventory is full!"
no-rewards: "&cThis crate has no rewards!"
reward-received: "&fYou received &a%reward%&f!"
no-players-online: "&cNo players are currently online!"
invalid-type: "&cInvalid type!"
keyall-success: "&fSuccessfully gave &a%amount% %crate% keys &7(%type%)&f to all online players!"
effect-not-found: "&cEffect %effect% does not exist! Check effects folder."
crate-already-exists: "&cCrate %crate% already exists!"
crate-created: "&aCrate %crate% and its key have been created successfully!"
crate-create-failed: "&cFailed to create crate %crate%!"
crate-removed: "&aCrate %crate% and its key have been removed successfully!"
crate-remove-partial: "&eCrate %crate% was partially removed. Some files could not be deleted."
crate-delete-failed: "&cFailed to delete crate file for %crate%!"
key-create-failed: "&cFailed to create key file for %crate%!"
key-delete-failed: "&cFailed to delete key file for %crate%!"
# + add new ones for: renamed, rows-changed, chance-changed, reward-added,
# reward-removed, already-opening, cooldown, crate-busy, crate-full,
# block-already-bound, key-given-to-you, key-taken-from-you, etc.
actionbars: # every action bar is customizable
no-key: "&cYou need a &a%crate% &ckey!"
opening: "&fOpening &a%crate%&f..."
reward: "&fYou won &a%reward%&f!"
cooldown: "&cWait %time%s before using another key!"
list-crates: |
afc00&lCRATES
afc00➤ &f%crates%
command-usage: |
afc00&lCRATES
afc00➤ &f/dc reload
afc00➤ &f/dc help
afc00➤ &f/dc bind
afc00➤ &f/dc unbind
afc00➤ &f/dc givekey
afc00➤ &f/dc takekey
afc00➤ &f/dc keyclear
afc00➤ &f/dc keyall
afc00➤ &f/dc seteffect
afc00➤ &f/dc removeeffect
afc00➤ &f/dc editor
afc00➤ &f/dc list
afc00➤ &f/dc create
afc00➤ &f/dc remove
```
---
## 5. COMMANDS (all required, with tab-complete and permissions `crates.admin` / `crates.`)
| Command | What it does |
| --- | --- |
| `/dc help` | Shows `command-usage` from lang.yml |
| `/dc reload` | Reloads config, lang, data, crates, keys, effects and every GUI file without restart |
| `/dc list` | Lists all crates (`list-crates` in lang.yml, optional clickable GUI) |
| `/dc create ` | Creates `crates/.yml` **and** `keys/.yml` with defaults |
| `/dc remove ` | Deletes crate file + key file, unbinds every block linked to it, reports partial failures |
| `/dc bind ` | Links the crate to the block the player is looking at (saved in `data.yml`) |
| `/dc unbind` | Unlinks the crate from the looked-at block |
| `/dc givekey ` | Gives keys to a player |
| `/dc takekey ` | Removes an amount of keys |
| `/dc keyclear ` | Removes **all** keys of that crate/type from a player |
| `/dc keyall ` | Gives keys to **every online player** |
| `/dc seteffect ` | Sets opening effect (`CHOOSE`, `ROLLING`, `NOWAIT`) and writes it into the crate yml |
| `/dc removeeffect ` | Removes the effect |
| `/dc editor ` | Opens the in-game crate editor GUI (see section 8) |
Key ``: `virtual` (stored as a number in data.yml) or `physical` (real item with NBT/PDC tag). Both supported on every command. Console must be able to run `givekey`, `takekey`, `keyclear`, `keyall`, `reload`, `list`, `create`, `remove`.
---
## 6. THE TWO MAIN CRATE TYPES
### TYPE A — **Real-item crates ("put the item in the crate")**
- The admin opens `/dc editor ` and **drops/places real items** (with full NBT: enchants, lore, names, custom data) into the editor GUI.
- Those exact item stacks are saved (serialized, base64 or YAML) and handed out as the reward.
- Per item: set **chance**, optional **commands**, optional **broadcast**, optional **limit**.
### TYPE B — **Fake-display crates ("display item + commands")**
- The GUI shows a **fake/display item** (`icon`: material, name, lore, enchantments, armor trim, glow, custom-model-data).
- The player never receives that display item. Instead the **`commands:` list is run by console** (`%player%` replaced). Example: `ss give spawner %player% zombie`.
- Supports `chance`, `commands`, `broadcast`, `give-item: true/false` (optionally also give the display item).
Reward format (must parse all of this, from the real sample files):
```yaml
amethyst-crate:
inventory:
name: 'ᴀᴍᴇᴛʜʏsᴛ ᴄʀᴀᴛᴇ'
effect: CHOOSE # CHOOSE | ROLLING | NOWAIT
rows: 3
rewards:
1:
slot: 10
chance: 10%
icon:
material: NETHERITE_AXE
name: 'A20AD6ᴀᴍᴇᴛʜʏsᴛ ᴀxᴇ'
lore:
- '&7Breaks Trees instantly'
enchantments:
mending: 1
efficiency: 5
trim:
material: redstone
pattern: snout
commands:
- 'tools give %player% treechopper'
back-button:
enable: false
displayname: 'FF0000ᴄʟᴏꜱᴇ'
material: RED_STAINED_GLASS_PANE
slot: 18
lore:
- '&fClick to close'
```
Also support per reward: `amount`, `custom-model-data`, `glow`, `hide-flags`, `permission`, `limit-per-player`, `broadcast`, `give-item`, `sound`, `actionbar`, `title`, `subtitle`, and **item-level armor trim + enchantments** (valid for 1.20+ trim API).
---
## 7. OPENING EFFECTS (the sub-types; all in `effects/`)
### 7.1 `CHOOSE` — click to open, then pick the reward
1. Player right-clicks the crate block (or uses `/dc open ` if enabled) holding/owning a key.
2. The crate GUI opens showing **all reward icons** (fake or real) at their `slot`s.
3. Player clicks the reward they want.
4. **`confirm-gui.yml` opens**: confirm / deny / display item (placeholders `%item%` and `%item_name%`).
5. On confirm: key is consumed, reward is given, effects/sounds/broadcast fire. On deny: back to the crate GUI, **no key used**.
`effects/choose.yml` is allowed to be an empty file (`#`) because it only marks the mode, but it must be read without errors.
### 7.2 `ROLLING` — random reward with animation and **custom percentages**
Driven by `effects/rolling.yml` (support exactly this structure):
```yaml
rolling-gui:
name: '&8ʀᴏʟʟɪɴɢ'
rows: 3
rolling-settings:
enabled: true
Direction: LEFT-TO-RIGHT # LEFT-TO-RIGHT | RIGHT-TO-LEFT | TOP-TO-BOTTOM | BOTTOM-TO-TOP
reward-item-slots: [9, 10, 11, 12, 13, 14, 15, 16, 17]
rolling-speed: 25 # ticks between steps
rolling-duration: 2000 # milliseconds
above-below-item-reward: HOPPER
sounds:
rolling: UI_BUTTON_CLICK
reward-get: BLOCK_NOTE_BLOCK_PLING
rolling:
items: # filler panes that scroll while spinning
- YELLOW_STAINED_GLASS_PANE
- BLUE_STAINED_GLASS_PANE
```
- The winning reward is **picked on the server BEFORE the animation starts** using weighted random from each reward's `chance` (chances need not sum to 100; normalise them).
- The animation is purely visual and must **end exactly on the pre-picked reward** in the centre slot.
- Slow down smoothly at the end (easing). Lock all clicks while rolling.
### 7.3 `NOWAIT` — instant open (third type)
- Key is used, reward is chosen by chance **instantly**, no GUI. Particles play at the crate block.
- `effects/nowait.yml`:
```yaml
particle:
enabled: true
type: TOTEM
count: 30
offset: 0.5
```
- Add configurable sound and optional hologram/actionbar message.
All three effects must be selectable by `/dc seteffect ` and by the crate file `effect:` key. Unknown effect → `effect-not-found`.
---
## 8. IN-GAME EDITOR (`/dc editor `)
Opens `crateeditor-gui.yml` (title from `itemeditor-gui.yml`: `"&8Edit: %crate%"`). Everything must **write back to the crate yml immediately** and live-reload the crate. Features:
- **Rename the crate**: click "Rename", type in chat (cancel with `cancel`) → updates `inventory.name` in the yml **and** updates the crate's display name everywhere (GUI titles, lists, key item, broadcast, PlaceholderAPI). Must not break the internal id/file name; optional "rename id" that safely renames the file, key file, and all `data.yml` links.
- Change rows (1–6), effect (CHOOSE/ROLLING/NOWAIT), key type, back-button.
- **Add items**: drop any item into the editor → becomes a reward (TYPE A). For TYPE B: add a display item and edit its commands.
- Per reward click-menu (`rewardeditor-gui.yml`): edit **chance**, slot, name, lore, commands (add/remove/list), broadcast, limit, delete reward.
- Save / Cancel / Reset buttons with confirm GUI.
- Lock the editor to one editor per crate at a time.
---
## 9. BLOCK LINKING + `data.yml`
`data.yml` stores **all crate locations** and player key balances:
```yaml
crates:
gold:
locations:
- "world;100;64;200"
- "world;105;64;200"
players:
:
keys:
gold:
virtual: 5
```
- `/dc bind ` links the block being looked at (ray trace, 5 blocks). One block = one crate. Multiple blocks per crate allowed.
- `/dc unbind` removes the link. Breaking a bound block is blocked unless the player has `crates.admin` and sneaks (then it auto-unbinds).
- Right-click with key = open. Left-click = preview rewards (`preview-gui.yml`). Shift+right-click = open preview or open-all if enabled.
- `/dc list` reads all crates from the crates folder and `data.yml`, shows each crate's name, effect and how many blocks are linked.
---
## 10. KEYS (`keys/.yml`)
```yaml
key:
material: TRIPWIRE_HOOK
name: '&a%crate% Key'
lore:
- '&7Right click a %crate% crate'
glow: true
custom-model-data: 0
type: PHYSICAL # PHYSICAL | VIRTUAL | BOTH
```
- Physical keys carry a hidden **PersistentDataContainer** tag with crate id (no NBT-name matching, so renaming in an anvil does not break/forge them).
- Virtual keys are stored in `data.yml` (or per-player files) and saved safely.
- `/dc create` makes the key file automatically; `/dc remove` deletes it.
---
## 11. PLACEHOLDERS
Message/GUI placeholders: `%player%`, `%target%`, `%crate%`, `%reward%`, `%amount%`, `%type%`, `%effect%`, `%crates%`, `%usage%`, `%item%`, `%item_name%`, `%time%`, `%chance%`, `%slot%`.
**PlaceholderAPI expansion** (register `crates`; soft-depend):
- `%crates_keys_%` — player's total keys for that crate
- `%crates_keys__virtual%` / `_physical%`
- `%crates_keys_total%` — all keys combined
- `%crates_opened_%` — how many times the player opened it
- `%crates_opened_total%`
- `%crates_amount%` — number of crates
- `%crates_list%`
- `%crates_name_%`
- `%crates_chance__%`
All GUI texts (names, lore, titles) and actions also parse PlaceholderAPI placeholders when installed.
---
## 12. SECURITY: NO EXPLOITS, NO DUPES (critical)
- **Cancel every click, drag, shift-click, number-key swap, double-click collect, hotbar swap and offhand-swap in all plugin GUIs.** Only the actions defined in the GUI file do anything.
- Never trust the client: check key ownership **server-side at the moment of reward**, consume the key **atomically before** giving the reward (rollback on failure).
- One opening per player at a time; ignore clicks while an animation runs.
- Block key use if player is in `key-cooldown`.
- If inventory is full: follow `inventory-full-behavior` (never delete the reward; deny before consuming the key whenever possible).
- Prevent dupes on: logout/disconnect mid-open (finish and give reward, or refund key), server stop (refund or finish all active opens), `/reload`, chunk unload, GUI close with Esc, death, world change, lag, double right-click, dropping the key while opening, and moving the key to another inventory/container while the GUI is open.
- Physical keys: tagged with PDC + unique-use check, cannot be stacked into containers while opening.
- Editor GUI and reward items: block taking/pulling items out of the editor except through the explicit buttons.
- Prevent piston/explosion/water breaking of crate blocks; block hopper/dropper interaction.
- Commands: sanitise `%player%` replacement and never run reward commands as op; run through console dispatch only.
- Thread-safe key balance changes (synchronised or atomic), saved on change and on disable.
- Permission-gate everything: `crates.admin`, `crates.open.`, `crates.reload`, `crates.keys`, `crates.editor`, etc.
- Provide a `debug` option that logs every open/key change for auditing.
---
## 13. QUALITY REQUIREMENTS
- Java 17, no deprecated API when a replacement exists, no NMS (use Paper/Bukkit API + Adventure/legacy serializer for hex).
- Clean architecture: `command`, `crate`, `effect`, `gui`, `key`, `data`, `config`, `listener`, `util`, `hook` packages.
- Full Javadoc on public classes. Meaningful error messages in console.
- Provide: complete source, `pom.xml` (or `build.gradle`), `plugin.yml` (commands, permissions, softdepend PlaceholderAPI), and **all default YAML files** pre-filled with the examples above.
- After the code, give a short **install + test checklist** (create crate, bind, give key, open with each effect, rename in editor, reload, keyall, keyclear, remove).
---
## 14. HOW TO RESPOND
Work in this order and output **complete files** (no truncating):
1. Project tree
2. `pom.xml` / `plugin.yml`
3. All default YAML files
4. Java source, package by package
5. Install + test checklist
If the answer is too long for one message, continue in parts and **say "CONTINUE" at the end of each part** until everything is delivered.
---
# APPENDIX: DEFAULT FILES (copy these exactly into the jar as first-run templates)
These are the real files from the original plugin. Ship them **exactly as written** (keep the small-caps text, hex colours, `§` codes and comments). Some contain small typos (for example `rows: 3'` in `prime.yml`, mixed quoted/unquoted reward ids, `chance` inside or outside `icon`); the parser must tolerate them as described in section 1. You may fix the typos in the shipped copies.