zRivals Duels logozRivals Duels

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.

The wager escrow lifecycle from taking both stakes to HELD rows, then SETTLED for a winner, REFUNDED with no winner, or refunded on next startup after a server stop, then delivered after both players are restored.

Currency types

TypeWhat it usesNeeds
VAULTMoney from your economy pluginVault and an economy plugin
XP_LEVELSVanilla experience levelsNothing
XP_POINTSVanilla experience pointsNothing
COMMANDAny other currency (SolysCoins and similar), through a balance placeholder and console commandsPlaceholderAPI

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]
KeyWhat it does
enabledShow this currency in the wager menu
typeVAULT, XP_LEVELS, XP_POINTS or COMMAND. An unknown type skips the entry with a console warning
displayName in menus and messages, MiniMessage format
iconItem in the currency menu
min, maxThe smallest and largest bet
decimalsAllow amounts like 12.50. Always off for XP_LEVELS and XP_POINTS
presetsQuick 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 example solyscoins 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:

  1. anything that was taken is given back with give-command
  2. the duel start is cancelled and both players are told
  3. 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
KeyWhat it doesDefault
proposal-secondsTime the opponent has to answer a proposal10
custom-amount-inputSIGN or CHAT, see belowSIGN
custom-amount-secondsTime a player has to enter a custom amount, in both modes30
cancel-wordWord that stops entering a custom amountcancel

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

  1. 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.
  2. Written down before anything else. Both stakes are saved to the database as HELD before the snapshot or teleport. If saving fails, both stakes are given back and the start is cancelled.
  3. Settled once. When the duel has a winner, the rows are marked SETTLED and the winner is owed both stakes. A row can only be settled once, so it can never pay twice.
  4. Refunded when nobody wins. A time limit draw, an admin end or a cancelled start marks the rows REFUNDED and each player is owed their stake back.
  5. 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.
  6. Safe across restarts. If the server stops mid duel, the rows stay HELD and 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.

On this page