forked from unimatrix/web
Import the supplied DuneMenus plugin and connect its first JARVIS actions
This commit is contained in:
parent
6aa77a3d65
commit
41ef8f4329
1 changed files with 1782 additions and 0 deletions
104
DuneMenus/src/main/java/com/dunerealms/menus/Backend.java
Normal file
104
DuneMenus/src/main/java/com/dunerealms/menus/Backend.java
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
package com.dunerealms.menus;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* Everything the menus need from the game backend (Jarvis). Menus never talk to Jarvis directly.
|
||||
* <p>Every method defaults to "not connected", so a backend only overrides what it supports and the
|
||||
* menu tells the player politely instead of faking data or touching money.
|
||||
* <p>Rules for implementers (full detail in docs/BACKEND.md):
|
||||
* money is minor units (1.00 DM = 100); futures may complete on any thread; there are NO confirm screens,
|
||||
* so each mutating call must be idempotent and safe against a double click.
|
||||
*/
|
||||
public interface Backend {
|
||||
/** Complete a future exceptionally with this to mean "this feature is not wired yet". */
|
||||
final class Unavailable extends RuntimeException { public Unavailable() { super("not wired", null, false, false); } }
|
||||
|
||||
record Result(boolean ok, String message) {
|
||||
public static Result yes(String m) { return new Result(true, m); }
|
||||
public static Result no(String m) { return new Result(false, m); }
|
||||
}
|
||||
/** fareMinor: -1 unknown (no fare line shown), 0 free, >0 price. */
|
||||
record World(String id, String name, String tagline, Material icon, int online, boolean up, long fareMinor) {}
|
||||
record Listing(String id, String title, Material icon, String seller, long priceMinor, int quantity, Integer kitVersion, boolean purchasable) {}
|
||||
record Page(List<Listing> items, boolean hasNext) {}
|
||||
record Org(String name, String role, int members, long vaultMinor) {}
|
||||
record Member(UUID id, String name, String role) {}
|
||||
/** state is one of ACTIVE, AVAILABLE, DONE. */
|
||||
record Mission(String id, String title, Material icon, String state, int percent, boolean claimable, String summary, Long revision) {}
|
||||
record Spice(int carried, long guildQuote, long smugglerQuote, long pendingMinor) {}
|
||||
/** roster has 8 entries; blank = empty slot. */
|
||||
record War(String title, List<String> roster, List<String> status, boolean canLaunch) {}
|
||||
record Decision(String id, String title, Material icon, String cost, String effect, boolean allowed) {}
|
||||
record House(String id, String name, String motto, Material banner, int version) {}
|
||||
/** Rihla account. reservedMinor = amount+tax locked by pending outgoing transfers. collectableMinor = incoming transfers waiting to be collected. */
|
||||
record Account(String accountNo, long balanceMinor, long reservedMinor, long collectableMinor) {}
|
||||
/** direction is "OUT" (you sent it, still pending, cancellable) or "IN" (waiting for you to collect). taxMinor is only set for OUT. */
|
||||
record Transfer(long id, String direction, String counterparty, long amountMinor, long taxMinor, String when) {}
|
||||
record Refit(boolean possible, String itemName, Material icon, List<String> costs, String note) {}
|
||||
|
||||
private static <T> CompletableFuture<T> na() { return CompletableFuture.failedFuture(new Unavailable()); }
|
||||
|
||||
// ---- wallet / travel ----
|
||||
default CompletableFuture<Long> balance(Player p) { return na(); }
|
||||
default CompletableFuture<List<World>> worlds(Player p) { return na(); }
|
||||
default CompletableFuture<Result> book(Player p, String worldId) { return na(); }
|
||||
// ---- exchange (tab is "buy" | "kits" | "mine") ----
|
||||
default CompletableFuture<Page> listings(Player p, String tab, int page) { return na(); }
|
||||
default CompletableFuture<Result> buy(Player p, Listing offer, int qty) { return na(); }
|
||||
default CompletableFuture<Result> withdraw(Player p, Listing offer) { return na(); }
|
||||
/** Lists the item in the player's main hand at the given unit price. */
|
||||
default CompletableFuture<Result> sell(Player p, ItemStack expected, int slot, long priceMinor) { return na(); }
|
||||
default CompletableFuture<Result> collectPurchases(Player p) { return na(); }
|
||||
// ---- organisations (kind is "clan" | "company") ----
|
||||
default CompletableFuture<Org> org(Player p, String kind) { return na(); }
|
||||
default CompletableFuture<List<Member>> members(Player p, String kind) { return na(); }
|
||||
/** action ids used by the menus: home, claims, vault, allies, wars, invite, transactions, roles, war-transport */
|
||||
default CompletableFuture<Result> orgAction(Player p, String kind, String action) { return na(); }
|
||||
// ---- missions ----
|
||||
default CompletableFuture<List<Mission>> missions(Player p) { return na(); }
|
||||
default CompletableFuture<Result> missionAction(Player p, Mission mission, boolean claim) { return na(); }
|
||||
// ---- spice (channel is "guild" | "smuggler") ----
|
||||
default CompletableFuture<Spice> spice(Player p) { return na(); }
|
||||
default CompletableFuture<Result> sellSpice(Player p, String channel) { return na(); }
|
||||
default CompletableFuture<Result> collectSpice(Player p) { return na(); }
|
||||
// ---- war muster ----
|
||||
default CompletableFuture<War> war(Player p) { return na(); }
|
||||
default CompletableFuture<List<Member>> warCandidates(Player p) { return na(); }
|
||||
default CompletableFuture<Result> warAssign(Player p, int slot, UUID candidateOrNull) { return na(); }
|
||||
default CompletableFuture<Result> warSave(Player p) { return na(); }
|
||||
default CompletableFuture<Result> warLaunch(Player p) { return na(); }
|
||||
// ---- politics / house / equipment ----
|
||||
default CompletableFuture<List<Decision>> decisions(Player p) { return na(); }
|
||||
default CompletableFuture<Result> enact(Player p, String id) { return na(); }
|
||||
default CompletableFuture<List<House>> houses(Player p) { return na(); }
|
||||
default CompletableFuture<Result> chooseHouse(Player p, House house) { return na(); }
|
||||
default CompletableFuture<Refit> refitQuote(Player p) { return na(); }
|
||||
default CompletableFuture<Result> refit(Player p) { return na(); }
|
||||
// ---- Rihla money transfer (Corrino Group). Used by the Bank screen and the ATM. ----
|
||||
// Rules (docs/BACKEND.md): private account per user; sending creates a pending transfer that reserves
|
||||
// amount + tax (1% up to and including 3,000 DM, 5% above, rounded UP to the next cent); the recipient
|
||||
// receives the full amount and collects it in-game; cancelling releases the reservation.
|
||||
default CompletableFuture<Account> bankAccount(Player p) { return na(); }
|
||||
/** ATM, tab 1. The player taps bills and coins; the menu sends the total. Backend takes the cash and CREATES a new RIA ID worth that amount. */
|
||||
record Issued(boolean ok, String message, String riaId) {}
|
||||
default CompletableFuture<Issued> atmCreateRia(Player p, long amountMinor) { return na(); }
|
||||
/** ATM, tab 2. Look an RIA ID up so the menu can show the amount before payout. Return null/exceptional if unknown. */
|
||||
record Voucher(String riaId, long amountMinor, String fromName) {}
|
||||
default CompletableFuture<Voucher> atmLookup(Player p, String riaId) { return na(); }
|
||||
/** ATM, tab 2. Pay the RIA ID out: toBank=false gives cash, toBank=true credits the player's bank account. One click, no confirmation. */
|
||||
default CompletableFuture<Result> atmRedeem(Player p, String riaId, boolean toBank) { return na(); }
|
||||
/** Cash withdrawal from the RIA account. The menu builds amountMinor from the bills and coins the player tapped.
|
||||
* The backend debits the account and gives the player that cash (however cash is represented), or returns Result.no (insufficient funds, inventory full...). */
|
||||
default CompletableFuture<Result> bankWithdraw(Player p, long amountMinor) { return na(); }
|
||||
default CompletableFuture<List<Transfer>> bankTransfers(Player p) { return na(); }
|
||||
default CompletableFuture<Result> bankSend(Player p, UUID to, long amountMinor) { return na(); }
|
||||
default CompletableFuture<Result> bankCancel(Player p, long transferId) { return na(); }
|
||||
/** transferId -1 collects every incoming transfer. */
|
||||
default CompletableFuture<Result> bankCollect(Player p, long transferId) { return na(); }
|
||||
}
|
||||
Loading…
Reference in a new issue

Staff