Wagers and currencies
Betting on duels with Vault money, XP or any other currency, and how escrow keeps every bet safe.
Players can put something on the line. Both bet the same amount of the same currency, the winner takes both stakes. The stakes are taken before the fight and written to the database, so a crash, a disconnect or a server stop can never make a bet vanish or pay twice.
Currency types
| Type | What it uses | Needs |
|---|---|---|
VAULT | Money from your economy plugin | Vault and an economy plugin |
XP_LEVELS | Vanilla experience levels | Nothing |
XP_POINTS | Vanilla experience points | Nothing |
COMMAND | Any other currency (SolysCoins and similar), through a balance placeholder and console commands | PlaceholderAPI |
When the plugin a currency needs is missing, that currency is switched off with one console line and the menu shows it as unavailable. Everything else keeps working.
currencies.yml
You can have as many currency entries as you like. The id (money, levels and so on) is only used inside the plugin.
currencies:
money:
# Turns this currency on or off
enabled: true
# How the plugin talks to this currency: VAULT, XP_LEVELS, XP_POINTS or COMMAND
type: VAULT
# Name shown in menus and messages
display: "<green>Money"
# Item shown for this currency in the wager menu
icon: GOLD_INGOT
# Lowest amount a player can bet
min: 100
# Highest amount a player can bet
max: 1000000
# Allow amounts with decimals
decimals: true
# Quick amount buttons shown in the wager menu
presets: [1000, 10000, 100000]| Key | What it does |
|---|---|
enabled | Show this currency in the wager menu |
type | VAULT, XP_LEVELS, XP_POINTS or COMMAND. An unknown type skips the entry with a console warning |
display | Name in menus and messages, MiniMessage format |
icon | Item in the currency menu |
min, max | The smallest and largest bet |
decimals | Allow amounts like 12.50. Always off for XP_LEVELS and XP_POINTS |
presets | Quick amount buttons. Presets outside min and max, or with decimals when decimals are off, are left out |
Out of the box, money and levels are on, and experience (XP points) and solyscoins are off.
COMMAND currencies
A COMMAND currency connects any currency plugin without the plugin needing to know about it. You give it three things: a placeholder that shows the balance, a console command that takes coins, and one that gives them.
solyscoins:
enabled: true
type: COMMAND
display: "<gold>SolysCoins"
icon: SUNFLOWER
# Placeholder that returns the player's balance, change it to your plugin's one
balance-placeholder: "%solyscoins_balance%"
# Console command that removes coins from a player
take-command: "solyscoins take %player% %amount%"
# Console command that gives coins to a player
give-command: "solyscoins give %player% %amount%"
min: 10
max: 100000
decimals: false
presets: [50, 100, 500]%player%becomes the player name and%amount%the amount. Whole numbers are sent without decimals, for examplesolyscoins take Steve 500.- All three keys are required. An entry missing one is skipped with a console warning.
- Check your currency plugin's own command and placeholder names, the ones above are an example.
Reading the balance
The placeholder text is cleaned before it is read as a number. Colour codes, currency symbols and words are ignored, and both 1,234.56 and 1.234,56 styles work. If nothing readable is left, the currency is unavailable for that player and they are told the balance could not be read.
Checking the take really happened
Some currency plugins fail quietly. So after running take-command, the plugin reads the balance again. If it did not drop by the full amount:
- anything that was taken is given back with
give-command - the duel start is cancelled and both players are told
- the details are logged to console
Giving coins to a player with a COMMAND currency needs them online, so refunds and winnings for an offline player wait until they next join.
Proposing a wager
Pick a currency
Click the wager button in the setup menu. The currency menu shows your balance and the lowest and highest bet for each currency.
Pick an amount
Click a preset, or click Custom amount and enter the amount on a sign or in chat, see Custom amounts. Amounts like 1,000 are accepted.
The opponent answers
The plugin checks you can afford it and that it is within the limits, then sends it to your opponent as a menu with accept and decline buttons, plus a chat message with clickable buttons. A countdown shows on the menu and in the action bar.
Accepted or not
On accept, the plugin checks the opponent can afford it and the wager is set. On decline or when time runs out, the setup carries on with no wager and either player can propose again.
There is only ever one wager per duel. A new proposal replaces the old one and clears both confirmations. The No wager button in the currency menu removes the wager, or a pending proposal.
wager:
# Seconds the opponent has to answer a wager proposal
proposal-seconds: 10
# How a custom amount is entered: SIGN (a sign editor only the player sees) or CHAT (typed in chat and hidden from everyone else)
custom-amount-input: SIGN
# Seconds a player has to type a custom amount in chat
custom-amount-seconds: 30
# Word a player types in chat or on the sign to stop entering a custom amount
cancel-word: cancel| Key | What it does | Default |
|---|---|---|
proposal-seconds | Time the opponent has to answer a proposal | 10 |
custom-amount-input | SIGN or CHAT, see below | SIGN |
custom-amount-seconds | Time a player has to enter a custom amount, in both modes | 30 |
cancel-word | Word that stops entering a custom amount | cancel |
Custom amounts
Nobody else sees a custom amount while it is being entered, in either mode.
SIGN
A sign editor opens with the amount on the first line and a short hint on lines 2 to 4.
- Write the amount on the first line and click Done.
- Leave the first line empty, or write the cancel word, to stop and go back to the setup menu.
- A wrong amount, a decimal amount for a currency without decimals, or an amount the player cannot afford shows the reason in chat and opens the sign again.
- The sign is temporary. It is placed in an empty air block next to the player, other players are shown the block that was there before, and it is removed as soon as the player clicks Done, cancels, runs out of time, leaves, or the setup ends. It cannot be broken, blown up or dropped as an item.
- If there is no air block near the player, for example in a tight tunnel, the prompt falls back to chat for that amount.
Lines 2 to 4 come from wager.sign-lines in the language file, with the tokens <currency>, <min>, <max> and <cancel>. Keep them short, a sign line only fits about 15 characters. The chat line sent when the sign opens is wager.custom-prompt-sign.
CHAT
The player types the amount in chat. The message is cancelled and its recipients are cleared, so it is never shown to anyone. On Paper the plugin also cancels Paper's own chat event, so chat plugins built on it do not show the amount either. Type the cancel word to stop.
A chat plugin that sends messages itself before any other plugin sees them can still show the amount. If that happens, use SIGN.
How escrow keeps bets safe
- Taken at the start. When both players confirm and every start check passes, the stake is taken from player 1, then from player 2. If taking from player 2 fails, player 1 gets theirs back straight away and the start is cancelled.
- Written down before anything else. Both stakes are saved to the database as
HELDbefore the snapshot or teleport. If saving fails, both stakes are given back and the start is cancelled. - Settled once. When the duel has a winner, the rows are marked
SETTLEDand the winner is owed both stakes. A row can only be settled once, so it can never pay twice. - Refunded when nobody wins. A time limit draw, an admin end or a cancelled start marks the rows
REFUNDEDand each player is owed their stake back. - Paid after the restore. Winnings and refunds are handed out only after both players have their own inventory back, so the restore can never wipe XP that was just paid. Each payout is marked delivered, so it is never handed out twice.
- Safe across restarts. If the server stops mid duel, the rows stay
HELDand are refunded on the next startup. Anyone offline gets their payout when they next join.
Players see a "you won the wager" or "your wager was given back" message when the payout arrives.