Shared Services
Money
Since 2.1, one way to move money, whichever plugin holds it. A price names its currency by id: an XCore currency (dollar, gems), or vault (or an empty id) for the economy registered with Vault, which is XCore's own on most servers and another plugin's on the others. A plugin that sells things asks money() and does not care which.
String currency = money().defaultCurrency(); // XCore's primary, else Vault's
double price = money().ceil(currency, raw); // what a player pays, rounded up
double payout = money().floor(currency, raw); // what a player receives, rounded down
money().withdraw(uuid, currency, price).thenAccept(paid -> {
if (!paid) return; // refused: nothing was taken
// hand the item over
});
money().deposit(uuid, currency, payout);
money().format(currency, price); // "$1,234.50"
money().room(uuid, currency); // what still fits under max-balance
- A withdrawal says whether it happened.
withdrawcompletes withtrueonly when the whole amount left the balance: hand nothing over before it has.depositcompletes withtruewhen the payment went through. An amount of zero or less is nothing to move, and answerstrue. - Rounding never creates money. Bring an amount to what the currency counts before it moves:
ceilfor what a player pays,floorfor what they receive.decimalsandunitsay what it counts: an XCore currency's owndecimals, two for another plugin's economy. - Room before items. A deposit that does not fit under
max-balanceis trimmed, so a plugin that takes items for money checksroomfirst, or the items would be sold for nothing. - Another plugin's economy is only called on the server thread, since most of them are not thread-safe:
withdrawanddepositgo there by themselves, andbalanceasked from another thread answers 0. When the economy behind Vault is XCore's own, the balance is reached directly, off that thread. - One balance, one id.
canonical(id)gives the id of the balance a currency id moves.vaultand XCore's primary currency are one balance when XCore's economy is behind Vault, so a plugin comparing prices across products groups them by it; otherwise "vault" and "dollar" pass for two currencies. - Also there:
exists(id);isCore(id), whether a balance is XCore's own, reachable offline and from any thread;currencies(), XCore's, thenvaultwhen another plugin's economy is registered;has,balanceandsymbol; andround, for showing an amount, never for one about to move.
Deliveries
The mailbox: things a plugin owes a player but could not hand over. Written once, given on their next join.
delivery().sendItem(uuid, item, "Auction sale", "XAuctionHouse");
delivery().sendMoney(uuid, "coins", 250.0, "Vote reward", "XVote");
delivery().countPending(uuid).thenAccept(count -> ...);
Money always goes through. An item is only closed once it is really in the inventory, so a full inventory postpones it rather than losing it.
Leaderboards
Declared once, refreshed on a timer, read from memory. Reading one never touches the database, which matters when a scoreboard asks for it several times a second.
leaderboards().define("kills")
.table("myaddon_stats").value("kills")
.size(10).refreshEvery(300)
.register();
leaderboards().get("kills").top(10); // the last snapshot
That also publishes %xcore_top_kills_1_name% and %xcore_top_kills_1_value%.
Network
Every server announces itself on the sync channel, so a plugin can know what the network looks like instead of guessing.
network().servers(); // name, players, TPS, version
network().locate(uuid); // which server holds this player
network().totalOnline(); // across the network
network().send("lobby", "mychannel", new SyncMessage("KICK", uuid.toString()));Discord
One queue for the whole installation, with retries and rate-limit handling. Each plugin keeps its own webhook address in its own config.
discord().send(url, DiscordNotifier.embed()
.title("Ban")
.description(player + " was banned by " + staff)
.color(0xC0362C)
.field("Reason", reason, false)
.timestamp()
.build());
discord().sendRaw(url, json) takes a payload a plugin has already assembled.
Toolbox
| Class | Purpose |
|---|---|
Items | Items to base64 and back, giving without losing the overflow, counting, taking |
Cooldowns | Per-player cooldowns that expire on their own |
Notify | Titles, action bars and boss bars |
Formats | Durations both ways, thousands separators, compact numbers, byte sizes |
CommandHelpers | Suggestions, offline target resolution, the silent flag |
WorldConfig | Per-world overrides, resolved once at load |
BlinkCache | Both faces of a blinking item, built once |
ranks() | Primary group, weight, numbered permission levels |
Placeholders without an expansion
placeholders()
.register("kits", (player, arg) -> String.valueOf(available(player)))
.register("cooldown", (player, arg) -> Formats.duration(remaining(player, arg)));
placeholders().publish();
The identifier is the plugin name in lower case, so those become %mykits_kits% and %mykits_cooldown_starter%.
Play Time
XCore counts how long each player has been connected, across sessions, in the playtime column of the shared table.
long seconds = api().getPlaytime(uuid);
The session in progress is included, so the value moves while a player is online rather than only when they disconnect. %xcore_playtime% gives it formatted.