Currency Shops
On this page(18)
A currency can have a shop: a menu that sells things for that currency. It has fixed entries, sold all the time, and a rotating pool that changes every few hours for everyone at once. Shops give players a place to spend a currency on boosters, pouches or anything a command can give.
| Files | shop: true in currencies/<id>.yml, the menu guis/shop-<id>.yml, the shops: block of config.yml |
| Player command | /<currency> shop (/souls shop) |
| Menu actions | [shop] open <currency>, [shop] buy <currency> <entry> |
| Switch | shop: true (a root key of the currency file) + /dungeons reload |
How it works
- You switch it on. Set
shop: truein the currency file and run/dungeons reload. - The menu file appears. The reload creates
guis/shop-<currency>.ymlfrom the plugin's template. Every<currency>of the template becomes the currency id. - You edit it. The file is yours: SnDungeons never merges or rewrites it. Edit it and run
/dungeons reload. - Players open it.
/<currency> shop, or a button with[shop] open <currency>. - Players buy. A click buys one unit. A shift click buys many.
A new installation ships souls with its shop on, so guis/shop-souls.yml exists after the first start as a worked example.
Delete guis/shop-<currency>.yml and run /dungeons reload to get the template back. A currency switched back to shop: false keeps its file, which then loads as a plain menu with no entries.
The shop menu
The template is a menu file with the usual keys (title, layout, items), a templates: block and a shop: block. The entries are not items of items:: the plugin draws them from the shop: block on their slots.
The template layout (6 rows):
#######T#
#| #
#|##
######| #
######|##
####X#| #| Cell | What it is |
|---|---|
| blank cells on the left (9 to 13, 18 to 22) | The fixed entries. The template uses 9 to 12. |
| blank cells on the right (16, 34, 52) | The rotating entries. |
T | The rotation timer: %sndungeons_shop_<currency>_rotates_in%, refreshed every second. |
X | Close. |
# and the bar column | Fillers (black and purple glass panes). |
templates.entry
The one entry template holds the click of every entry. Keep it.
strict-clicks: true
templates:
entry:
click-actions:
- "[shop] buy {shop} {entry}"A file without templates.entry shows no entries (one console warning per reload). A display-name written there replaces the name of every entry. A lore there is added under the lore of each.
Configuration
shop (in the shop menu file)
The shop: block at the end of guis/shop-<currency>.yml says what is sold.
| Key | Default | What it does |
|---|---|---|
max-bulk | 64 | The most units one shift click buys (1 to 1000). |
fixed.<entry> | An entry sold all the time. The id: lowercase letters, digits and -, at most 64. | |
fixed.<entry>.slot | required | A cell of the menu. Not a rotating slot, not the slot of another entry. |
rotating.every | 8h | The length of a rotation window, 1 minute or more (30m, 1d 12h). |
rotating.offset | 0h | Moves the windows (3h gives 03:00, 11:00, 19:00 UTC). 0 or more. |
rotating.slots | [16, 34, 52] | The cells the picked entries go on, in this order. |
rotating.prefix | "&d[EXCLUSIVE] " | Put before the name of every rotating entry. |
rotating.pool.<entry> | An entry the rotation may pick. | |
rotating.pool.<entry>.weight | 1 | How often it is picked against the others (0 to 100000). 0 means never. |
Every entry, fixed or of the pool, also has:
| Key | Default | What it does |
|---|---|---|
price | required | The price of one unit: a number (250000000) or a text of the currency format (250M, '1e500'). 0 makes it free. |
limit | 0 | The units a player may buy per rotation window. 0 or absent means no limit. |
icon | required | The keys of a menu item: material, display-name, lore, glow, color, flags, custom-model-data... |
actions | none | Action lines run once per unit bought, as the buyer. |
Icon tokens. In the name and the lore:
| Token | Value |
|---|---|
{price} | The price of one unit for that player (after any API modifier) |
{currency} | The currency's name |
{purchased} | The units the player bought this window |
{limit}, {left} | The limit and what is left (both the word of status.unlimited without a limit) |
{entry} | The entry id |
The item name key is display-name. name is not a menu item key (one console warning).
Action tokens. {player}, {currency} (here the currency ID, not its name) and {entry}. Any action tag works: [give-pouch], [booster], [give-currency], [console], [player], [message]... See Menus and Action Tags.
A worked entry
guis/shop-souls.yml
shop:
max-bulk: 64
fixed:
damage-booster:
slot: 10
price: 5M
limit: 0
icon:
material: POTION
display-name: "&c+1 Damage Booster &7(15m)"
color: '#FF5555'
lore:
- "&7Cost: &a{price} {currency}"
actions:
- "[booster] damage 1 15m"Each unit costs 5M souls and stores one +1 damage booster of 15 minutes in the buyer's booster backpack.
Mistakes in the file
A refused value is one console warning naming the file and the key. These entries are not sold:
- an entry with a bad id, without a readable
priceor without anicon; - a fixed entry whose
slotis outside the menu, on a rotating slot or on another fixed entry; - a pool entry with the id of a fixed entry;
- an entry whose
[give-pouch]names a pouch that does not exist.
Any other bad value reads its default. A file without shop: sells nothing (one warning).
The template sells the t1 pouch of its own currency. A currency without a t1 pouch (experience, rebirth-points) needs those [give-pouch] actions edited, or those entries removed.
The rotation
Time is cut into windows of every, counted from 1970-01-01 00:00 UTC and moved by offset.
- When
everydivides a day (6h, 8h, 12h, 1d), the windows start at midnight UTC plus the offset.8hand0hgive 00:00, 08:00 and 16:00 UTC. - A length that does not divide 24h drifts across days.
- Each window offers a weighted pick of the pool, without repeats, one entry per rotating slot.
- A pool smaller than the slots leaves the other slots to the layout.
Why it is fair. The pick depends only on the currency and the window. Every player sees the same entries, they change at the same instant, and a restart changes nothing. An open shop menu redraws itself at the change.
Editing the pool (its ids or weights) during a window can change what that window shows.
Weights. The pool of the template has weights 10, 10, 10, 8 and 4 (total 42). The first pick takes pouch-crate (weight 4) about 4 times in 42.
Limits
Limits count per player, per entry and per window, and start over with the next window. A fixed entry counts by the same windows. A file without a rotating: block uses 8h windows from midnight UTC. The counts are stored, so a restart keeps them.
Buying
| Click | What it buys |
|---|---|
| Left or right click | One unit. |
Shift click, bulk-input: anvil (default) | An anvil opens. The player types how many and clicks the result: EXACTLY that many are bought, or nothing. |
Shift click, bulk-input: max | As many as the balance pays, up to max-bulk and the limit left. |
The total is charged at once (one COST row, cause shop:<entry>; none for a free entry). Then the actions run once per unit and the menu redraws. One click at a time: a click while the last purchase is still saving answers busy.
The Luck effect free-shop can waive one unit of a purchase.
shops (config.yml)
The shops: block of config.yml sets what a shift click does, for every shop.
| Key | Default | What it does |
|---|---|---|
bulk-input | anvil | anvil asks for an amount. max buys as many as the balance pays, up to max-bulk. |
anvil.title | '&8Buy how many? (max {max})' | The anvil title. |
anvil.input-item | a PAPER named {amount} | The item the player renames: its name is the starting text. |
anvil.confirm-item | an EMERALD | The result for an amount from 1 to {max}: a click buys it. |
anvil.invalid-item | a BARRIER | The result for anything else. |
Each item takes material, name and lore. The tokens:
| Token | Value |
|---|---|
{entry} | The entry's name |
{price} | The price of one unit |
{max} | The most the player may type now |
{amount} | What was typed |
{total} | The price of {amount} (on the confirm item) |
Messages
The answers are messages.shop.* of lang/messages_en.yml. They answer a click, and no setting hides them.
| Key | When |
|---|---|
purchased | After a purchase: {amount}, {item}, {price} (the total), {currency}. |
insufficient | The balance does not pay one unit. |
amount-insufficient, amount-limit | The anvil amount costs too much, or passes the limit or max-bulk. |
limit-reached | The player bought the limit of this window. |
not-offered | The entry left the rotation while the menu was open. |
no-shop, no-menu | The currency has no shop, or its menu is not loaded. |
busy | The last purchase is still saving. |
not-allowed | The shop subcommand is off or needs a permission the player lacks. |
Opening the shop
| Way | Gates |
|---|---|
/<currency> shop | Players only. Hidden from tab and help while shop: false (it then answers no-shop). |
[shop] open <currency> | Any menu button or reward. |
[shop] buy <currency> <entry> | Only from a click in a menu. |
One tick later, both actions check that the currency has shop: true. For a currency with commands, they also check the root permission and the shop subcommand. A broken line does nothing, with one console warning.
shop: true also works with commands-disabled: true. That shop opens only through [shop] open <currency> and the API, with no permission check.
commands.shop. A currency file without the shop block under commands: has /<currency> shop on for everyone. enable: false turns it off. permission and aliases work as for the other subcommands.
Commands
| Command | Permission | Description |
|---|---|---|
/<currency> shop | none (commands.shop.permission) | Opens the shop of the currency. Shown only while the currency has shop: true. |
Full list: Commands.
Placeholders
Full list: Placeholders.
| Placeholder | Description |
|---|---|
%sndungeons_shop_<currency>_rotates_in% | Time before the next rotation (like 2h 5m) |
%sndungeons_shop_<currency>_rotates_in_seconds% | The same time in seconds |
%sndungeons_shop_<currency>_<entry>_price%, _price_raw | The price of your next unit, formatted and plain |
%sndungeons_shop_<currency>_<entry>_purchased% | Units you bought in this window |
%sndungeons_shop_<currency>_<entry>_left% | Units you have left (empty without a limit) |
%sndungeons_shop_<currency>_<entry>_offered% | true while the entry is on sale now |
Tips
- Put a
limiton every rotating entry: it keeps the exclusive items rare. - Use the
{purchased}/{limit}lore line so players see what is left this window. - The purchases are stored in
sndungeons_shop_purchases. Rows of past windows are deleted by the next purchase and at the join. - The debug category
shopsprints every purchase and refusal with its reason./dungeons admin inspect playerhas ashopssection.
Default shop: block of the shop template
# What the shop sells.
# Every entry has:
# price: required. A number (250000000) or a text of the currency's format
# (250M, '1e500'); 0 = free. An entry without a readable price is not sold.
# limit: the units a player may buy per rotation window (0 or absent = no
# limit). Fixed entries count by the same windows as the rotating ones.
# icon: required. The keys of a menu item (material, display-name, lore,
# glow, color, flags, custom-model-data...). In its texts: {price} (one
# unit), {currency}, {purchased} (bought this window), {limit} (the word
# for no limit when 0), {left}, {entry}.
# actions: run once per unit bought, as the player; {player}, {currency},
# {entry}. Any action tag: [give-pouch], [booster], [give-currency],
# [console], [player], [message]...
# Fixed entries add slot: (a cell of the layout); pool entries add weight:
# (how often the rotation picks it against the others; 0 = never).
shop:
# The most units a shift click buys (1 to 1000).
max-bulk: 64
fixed:
pouch:
slot: 9
price: 250M
limit: 0
icon:
material: BUNDLE
display-name: "&a{currency} Pouch &7(Tier 1)"
lore:
- "&7Cost: &a{price} {currency}"
- ""
- "&8Left-Click to purchase!"
- "&8Shift-Click to choose an amount!"
actions:
- "[give-pouch] <currency>:t1 1"
damage-booster:
slot: 10
price: 5M
limit: 0
icon:
material: POTION
display-name: "&c+1 Damage Booster &7(15m)"
color: '#FF5555'
flags:
- HIDE_ADDITIONAL_TOOLTIP
lore:
- "&7Cost: &a{price} {currency}"
- ""
- "&8Left-Click to purchase!"
- "&8Shift-Click to choose an amount!"
actions:
- "[booster] damage 1 15m"
swings-booster:
slot: 11
price: 5M
limit: 0
icon:
material: POTION
display-name: "&e+1 Swings Booster &7(15m)"
color: '#FFFF55'
flags:
- HIDE_ADDITIONAL_TOOLTIP
lore:
- "&7Cost: &a{price} {currency}"
- ""
- "&8Left-Click to purchase!"
- "&8Shift-Click to choose an amount!"
actions:
- "[booster] swings 1 15m"
enchants-booster:
slot: 12
price: 5M
limit: 0
icon:
material: POTION
display-name: "&d+1 Enchants Booster &7(15m)"
color: '#FF55FF'
flags:
- HIDE_ADDITIONAL_TOOLTIP
lore:
- "&7Cost: &a{price} {currency}"
- ""
- "&8Left-Click to purchase!"
- "&8Shift-Click to choose an amount!"
actions:
- "[booster] enchants 1 15m"
rotating:
# The length of a window. Windows are counted from the epoch (1970-01-01
# 00:00 UTC) plus the offset, so every player sees the same entries and
# they change at the same instant (8h + offset 0h: 00:00, 08:00, 16:00
# UTC; a length that does not divide 24h drifts across days).
every: 8h
offset: 0h
# The cells the picked entries go on, in order. A pool smaller than the
# slots leaves the rest to the layout.
slots: [16, 34, 52]
# Put before the name of every rotating entry.
prefix: "&d[EXCLUSIVE] "
# Editing the pool mid-window can change what this window shows.
pool:
big-pouch:
weight: 10
price: 50M
limit: 6
icon:
material: BUNDLE
display-name: "&a5x {currency} Pouch &7(Tier 1)"
glow: true
lore:
- "&7Cost: &a{price} {currency}"
- "&7Purchased: &a{purchased}/{limit}"
- ""
- "&8Left-Click to purchase!"
- "&8Shift-Click to choose an amount!"
actions:
- "[give-pouch] <currency>:t1 5"
damage-booster-x3:
weight: 10
price: 25M
limit: 3
icon:
material: POTION
display-name: "&c+2 Damage Booster &7(30m)"
color: '#FF5555'
flags:
- HIDE_ADDITIONAL_TOOLTIP
lore:
- "&7Cost: &a{price} {currency}"
- "&7Purchased: &a{purchased}/{limit}"
- ""
- "&8Left-Click to purchase!"
- "&8Shift-Click to choose an amount!"
actions:
- "[booster] damage 2 30m"
swings-booster-x3:
weight: 10
price: 25M
limit: 3
icon:
material: POTION
display-name: "&e+2 Swings Booster &7(30m)"
color: '#FFFF55'
flags:
- HIDE_ADDITIONAL_TOOLTIP
lore:
- "&7Cost: &a{price} {currency}"
- "&7Purchased: &a{purchased}/{limit}"
- ""
- "&8Left-Click to purchase!"
- "&8Shift-Click to choose an amount!"
actions:
- "[booster] swings 2 30m"
enchants-booster-x3:
weight: 8
price: 25M
limit: 3
icon:
material: POTION
display-name: "&d+2 Enchants Booster &7(30m)"
color: '#FF55FF'
flags:
- HIDE_ADDITIONAL_TOOLTIP
lore:
- "&7Cost: &a{price} {currency}"
- "&7Purchased: &a{purchased}/{limit}"
- ""
- "&8Left-Click to purchase!"
- "&8Shift-Click to choose an amount!"
actions:
- "[booster] enchants 2 30m"
pouch-crate:
weight: 4
price: 100M
limit: 2
icon:
material: CHEST
display-name: "&a10x {currency} Pouch &7(Tier 1)"
glow: true
lore:
- "&7Cost: &a{price} {currency}"
- "&7Purchased: &a{purchased}/{limit}"
- ""
- "&8Left-Click to purchase!"
- "&8Shift-Click to choose an amount!"
actions:
- "[give-pouch] <currency>:t1 10"Default shops: block of config.yml
# ------------------------------------------------------------
# Currency shops: shop: true in a currencies/<id>.yml gives that currency
# a shop; what it sells (entries, prices, limits, rotation) is the shop:
# block of its menu guis/shop-<id>.yml. This block is what a shift click
# on a shop entry does. Re-read on /dungeons reload.
# ------------------------------------------------------------
shops:
# anvil = an anvil opens where the player types how many and clicks the
# result: exactly that many are bought, or nothing (not enough money, or
# more than the limit left or max-bulk). max = buys as many as the
# balance pays, up to max-bulk.
bulk-input: anvil
# The look of the anvil. {entry} (the entry's name), {price} (one unit),
# {max} (the most the player may type now), {amount} (what was typed) and
# {total} (the price of {amount}, on the confirm item).
anvil:
title: '&8Buy how many? (max {max})'
# The item the player renames: its name is the starting text.
input-item:
material: PAPER
name: '{amount}'
lore:
- '&7Type the amount, then click the result.'
# The result for an amount from 1 to {max}: a click buys it.
confirm-item:
material: EMERALD
name: '&aBuy {amount}x {entry}'
lore:
- '&7Price: &a{total}'
- ''
- '&8Click to confirm!'
# The result for anything else ({amount} = what was typed).
invalid-item:
material: BARRIER
name: '&c{amount}'
lore:
- '&7Type a whole number from &f1 &7to &f{max}&7.'