📎
1 file
14,656 chars
📄
pasted-code-1773166011100.txt
txt
529 lines
▶
pasted-code-1773166011100.txt
txt
529 lines
Create a production-ready Minecraft Paper plugin for version 1.21.11 called DailyBorderTrader.
TECH STACK
- Language: Java 21
- Build system: Gradle Kotlin DSL
- Paper dependency: io.papermc.paper:paper-api:1.21.11-R0.1-SNAPSHOT
- Use plugin.yml with api-version: '1.21.11'
- No NMS
- No ProtocolLib
- No database
- Clean OOP architecture
- Return the FULL plugin project with every required file, not snippets
MAIN IDEA
Create a fully customizable daily wandering trader plugin.
The plugin must spawn exactly one plugin-managed WanderingTrader entity once per real-world day at a configurable time, at a random valid location inside the CURRENT world border of a configured world.
IMPORTANT TRADE DESIGN
Do NOT build this around vanilla MerchantRecipe only.
The trader must be a real WanderingTrader entity in the world, but when a player interacts with the managed trader, open a CUSTOM paginated inventory shop INVENTORY GUI instead of relying on vanilla merchant slots.
Reason:
The trade system must support:
- normal vanilla item costs
- exact custom items from other plugins such as coins, keys, sellwands, etc.
- Vault economy money costs
- exact custom item rewards from other plugins
- command-based rewards for plugins that give items by command
This means the plugin must implement its own trade engine and INVENTORY GUI.
CORE SPAWN BEHAVIOR
1. Spawn one plugin-managed trader once per day at a configurable local time.
2. Store last spawn date in a data file so restarts do not create duplicates.
3. Store the UUID of the current managed trader and restore tracking after restart if it still exists.
4. Only one managed trader may exist at a time unless config explicitly allows replacement.
5. Add config to remove the previous managed trader before spawning the new one.
6. Add config to cancel natural vanilla wandering trader spawns.
7. Add config for target world, timezone, edge padding, and max random attempts.
8. Use the live world border at the moment of spawn.
9. All world/entity operations must be on the main thread.
10. If no valid spawn location is found, log a warning and fail gracefully.
RANDOM SPAWN RULES
- Use configured world from config.yml
- Use that world’s current WorldBorder
- Pick random X/Z within the border minus configurable edge padding
- Find safe Y automatically
- Valid spawn location requirements:
- inside border
- loaded chunk or safely load/check chunk
- solid block under trader
- enough free air
- not in lava, water, powder snow, fire, cactus, berry bush, or void
- optionally avoid leaves
- optionally avoid configured biomes
- optionally avoid configured materials underfoot
- Retry up to configurable max attempts
- Log debug info when debug mode is enabled
TRADER CUSTOMIZATION
Configurable in config.yml:
- custom name
- show custom name
- invulnerable
- silent
- glowing
- has AI
- profession style behavior if applicable
- despawn after X minutes, or never despawn
- persistent when required
- particles and sound on spawn
- broadcast message on spawn
- include coordinates true/false
- include biome true/false
- whether players can locate the trader
- whether trader interaction opens the custom INVENTORY GUI
- whether normal vanilla trading is completely blocked
LLAMAS
- Optional trader llamas
- configurable count
- configurable leash behavior
- mark llamas as plugin-managed companions
- despawn/remove llamas with the trader when appropriate
- restore tracking only if needed
- do not interfere with unrelated llamas
TRADE SYSTEM REQUIREMENTS
The plugin must have a fully customizable trade system that supports multiple cost types and multiple reward types.
The trade engine must support these COST types:
1. VANILLA_ITEM
- Uses Material + amount
2. SAVED_ITEM
- Uses an exact custom item saved by the admin from their hand
- This is how the plugin supports coins, sellwands, keys, custom tokens, and other plugin items
3. ECONOMY
- Uses Vault money
4. COMMAND_COST
- Optional advanced type for future flexibility
- If implemented, only use it if it is safe and reliable
- Otherwise omit this type
The trade engine must support these REWARD types:
1. VANILLA_ITEM
2. SAVED_ITEM
3. ECONOMY
4. COMMAND
- Executes console commands and/or player commands on successful purchase
- Useful for plugins that expose give commands but not stable ItemStacks
VERY IMPORTANT:
The best generic way to support “other plugin items” is a SAVED ITEM REGISTRY.
Implement an item registry system:
- Admin can hold any item in hand and save it under a custom key
- The plugin serializes and stores the exact ItemStack in items.yml
- Trades can then reference that saved item key as a cost or reward
- This must preserve custom name, lore, enchantments, flags, damage, custom model data, potion data, data components, and metadata supported by Bukkit/Paper serialization
- Matching for saved-item costs should compare similarity while ignoring only stack amount
- Add an optional strict match mode for exact metadata-sensitive comparisons if useful
This is the core feature that allows using coins, custom currency items, sellwands, keys, crate items, voucher items, etc. from other plugins without hardcoding support for each plugin.
VAULT INTEGRATION
- Add optional Vault economy support as a soft dependency
- If Vault or an economy provider is not installed, ECONOMY trades must be skipped or disabled gracefully with warnings
- The plugin must still load normally without Vault if economy trades are not used
SHOP INVENTORY GUI REQUIREMENTS
When a player right-clicks the plugin-managed trader:
- Open a custom inventory INVENTORY GUI
- INVENTORY GUI title configurable
- INVENTORY GUI size configurable
- Support pagination
- Support filler items
- Support configurable navigation buttons
- Show each trade as a clickable icon
- Trade icon must display:
- item name
- description/lore
- costs
- rewards
- out-of-stock / disabled status if applicable
- Configurable sounds/messages on successful purchase and failed purchase
PURCHASE FLOW
Purchase logic must be safe and transactional:
1. Validate the trade exists and is enabled
2. Validate the player can purchase it
3. Check all costs first
4. Check inventory space or configured overflow behavior
5. Remove item costs and withdraw economy money
6. Grant item rewards and run command rewards
7. If something fails mid-transaction, rollback where reasonable and log a clear error
8. Prevent spam click / double purchase / shift-click abuse
9. Handle full inventory safely using configurable behavior:
- cancel purchase
- drop excess at player location
- send to overflow if implemented
CONFIGURABLE TRADE FEATURES
Each trade should support:
- id
- enabled
- slot
- page
- icon
- display name
- lore
- costs list
- rewards list
- required permission optional
- purchase cooldown optional
- max purchases per player optional
- global max purchases optional
- close INVENTORY GUI after purchase true/false
- refresh INVENTORY GUI after purchase true/false
- success message
- failure message
- sounds
- hidden true/false if player lacks permission
PLAYER DATA
If purchase cooldowns or limits are implemented:
- persist them in a player data file
- do not use a database
- make it restart-safe
COMMAND-BASED REWARDS
Support rewards like:
- give a sellwand via another plugin command
- give crate keys via command
- give custom vouchers or tokens via command
Command rewards must support placeholders:
- %player%
- %uuid%
- %world%
- %x%
- %y%
- %z%
EXAMPLE TRADE CONFIG FORMAT
Put trades in a separate trades.yml file.
Use a clean format like this:
shop:
title: "&6Daily Trader"
size: 54
filler:
enabled: true
material: BLACK_STAINED_GLASS_PANE
name: " "
navigation:
previous-page-slot: 45
next-page-slot: 53
close-slot: 49
trades:
coin_diamond:
enabled: true
page: 1
slot: 10
icon:
material: DIAMOND
amount: 1
name: "&bDiamond"
lore:
- "&7Buy 1 Diamond"
- "&7Cost: 16 Coins"
costs:
- type: SAVED_ITEM
key: coin
amount: 16
rewards:
- type: VANILLA_ITEM
material: DIAMOND
amount: 1
required-permission: ""
cooldown-seconds: 0
max-purchases-per-player: 0
close-after-purchase: false
money_sellwand:
enabled: true
page: 1
slot: 12
icon:
material: BLAZE_ROD
amount: 1
name: "&6Sell Wand"
lore:
- "&7A custom plugin item"
- "&7Cost: $50,000"
costs:
- type: ECONOMY
amount: 50000
rewards:
- type: SAVED_ITEM
key: basic_sellwand
amount: 1
required-permission: ""
cooldown-seconds: 0
max-purchases-per-player: 0
close-after-purchase: false
crate_key_bundle:
enabled: true
page: 1
slot: 14
icon:
material: TRIPWIRE_HOOK
amount: 1
name: "&eRare Key Bundle"
lore:
- "&7Costs coins + money"
costs:
- type: SAVED_ITEM
key: coin
amount: 8
- type: ECONOMY
amount: 2500
rewards:
- type: COMMAND
commands:
- "crates give %player% rare 3"
required-permission: ""
cooldown-seconds: 0
max-purchases-per-player: 0
close-after-purchase: false
custom_token_pack:
enabled: true
page: 1
slot: 16
icon:
material: SUNFLOWER
amount: 1
name: "&eToken Pack"
lore:
- "&7Reward is a saved custom item"
costs:
- type: VANILLA_ITEM
material: EMERALD
amount: 32
rewards:
- type: SAVED_ITEM
key: token_pack
amount: 1
SAVED ITEM REGISTRY
Create items.yml and admin commands for it.
Commands:
- /dailybordertrader item save
Save the exact item in the player’s main hand to items.yml
- /dailybordertrader item delete
- /dailybordertrader item give [player] [amount]
- /dailybordertrader item list
- /dailybordertrader item inspect
Requirements:
- Reject AIR
- Prevent duplicate overwrite unless confirmed by config or replace flag
- Save exact serialized ItemStack data
- Load saved items safely at startup
- Log warnings for corrupt entries and skip them without crashing
MAIN ADMIN COMMAND
Create root command:
/dailybordertrader
Subcommands:
- /dailybordertrader spawn
- /dailybordertrader remove
- /dailybordertrader reload
- /dailybordertrader where
- /dailybordertrader tp
- /dailybordertrader next
- /dailybordertrader shop [player]
- /dailybordertrader item save
- /dailybordertrader item delete
- /dailybordertrader item give [player] [amount]
- /dailybordertrader item list
- /dailybordertrader item inspect
PERMISSIONS
- dailybordertrader.admin
- dailybordertrader.spawn
- dailybordertrader.remove
- dailybordertrader.reload
- dailybordertrader.where
- dailybordertrader.tp
- dailybordertrader.next
- dailybordertrader.shop
- dailybordertrader.item.save
- dailybordertrader.item.delete
- dailybordertrader.item.give
- dailybordertrader.item.list
- dailybordertrader.item.inspect
- dailybordertrader.use
Permission behavior:
- OPs have access by default
- players need explicit nodes if not OP
- console can use admin commands where appropriate
DATA / IDENTIFICATION
- Mark managed trader with PersistentDataContainer and/or scoreboard tag
- Save UUID and last known location in data.yml
- Clear active state if trader dies or is removed
- Listen for death/remove/chunk unload cases sensibly
- Restore tracking after restart if entity still exists
MESSAGES
Create messages.yml with support for & color codes.
Include messages for:
- trader spawned
- trader spawn failed
- trader removed
- no trader exists
- trader location
- next spawn time
- shop opened
- purchase success
- purchase failed
- missing items
- missing money
- inventory full
- no permission
- reload complete
- item saved
- item deleted
- item not found
- invalid usage
CONFIG FILES TO GENERATE
Generate all of these:
- build.gradle.kts
- settings.gradle.kts
- src/main/resources/plugin.yml
- src/main/resources/config.yml
- src/main/resources/messages.yml
- src/main/resources/trades.yml
- src/main/resources/items.yml
- src/main/resources/data.yml if used as default/generated example
- full Java source tree
- README.md
CONFIG.YML SECTIONS
Include sections such as:
- world
- spawn
- border
- safety
- trader
- llamas
- interaction
- INVENTORY GUI
- broadcast
- particles
- sounds
- economy
- vanilla-spawn-control
- debug
Suggested defaults:
world: world
spawn:
time: "18:00"
timezone: "server"
replace-existing: false
remove-previous-before-spawn: false
save-last-spawn-date: true
border:
edge-padding: 16
max-attempts: 100
safety:
avoid-water: true
avoid-lava: true
avoid-powder-snow: true
avoid-leaves: true
blacklist-biomes: []
blacklist-ground-materials: []
interaction:
open-custom-shop-on-right-click: true
block-vanilla-trading-screen: true
INVENTORY GUI:
title: "&6Daily Trader"
size: 54
cancel-player-inventory-clicks-where-needed: true
drop-rewards-on-full-inventory: false
trader:
custom-name: "&eDaily Trader"
show-name: true
invulnerable: false
silent: false
glowing: false
has-ai: true
despawn-minutes: 60
llamas:
enabled: true
count: 2
leashed: true
broadcast:
enabled: true
include-coordinates: true
include-biome: false
message: "&6A wandering trader has appeared at &e%world% %x% %y% %z%&6."
economy:
use-vault: true
vanilla-spawn-control:
cancel-natural-wandering-trader-spawns: true
debug:
enabled: false
ROBUSTNESS REQUIREMENTS
- Validate all configs on load
- Skip bad trades, bad materials, bad item keys, or unavailable economy gracefully
- Never crash because one trade is invalid
- Log meaningful warnings with trade IDs
- Keep code modular and maintainable
- Avoid giant god-classes
- Use sensible package structure such as:
- command
- config
- data
- INVENTORY GUI
- integration
- listener
- manager
- model
- util
README
README.md must include:
- what the plugin does
- install steps
- Paper version
- Java version
- optional Vault setup
- how to save custom items into items.yml using commands
- how to create trades with saved items, economy, and command rewards
- full command list
- full permission list
- config explanation
- examples for coins, money, and sellwand-style rewards
FINAL OUTPUT REQUIREMENT
Return the complete finished Paper plugin project source code and all required resource files.
Do not return pseudo-code.
Do not leave TODO stubs.
The project should be ready to compile immediately.
Kodari can make mistakes. Review important code before using.
Files
No files in this session
Code