Give Rihla focused ATM screens, native reference entry and receipts

This commit is contained in:
unimatrixgit 2026-11-29 13:22:40 +01:00
commit abfa82bca8

View file

@ -7,13 +7,13 @@ import org.bukkit.Material;
import org.bukkit.entity.Player;
/**
* ONE ATM, three tabs, 5 rows, no PIN, no confirmations.
* Focused cash operations and a bank-reported receipt; no extra confirmation screen.
* Deposit : tap bills and coins, one click -> a new RIA ID is created and shown in the ID box.
* Redeem : type an RIA ID, then one click pays it out as Cash or To bank.
* Withdraw : tap bills and coins, one click takes the cash out of your own account.
*/
final class AtmMenu extends Menu {
enum Tab { HOME, DEPOSIT, REDEEM, WITHDRAW }
enum Tab { HOME, DEPOSIT, REDEEM, WITHDRAW, RECEIPT }
private static final int[] BILLS = {10, 11, 12, 19, 20};
private static final int[] COINS = {14, 15, 16};
private static final List<DunemarkDenomination> NOTES = List.of(DunemarkDenomination.NOTE_10, DunemarkDenomination.NOTE_20,
@ -22,19 +22,20 @@ final class AtmMenu extends Menu {
DunemarkDenomination.COIN_1DM, DunemarkDenomination.COIN_2DM);
private Tab tab;
private final List<DunemarkDenomination> selected = new ArrayList<>();
private boolean recoveredDeposit;
private String issued; // RIA ID created by the last deposit
private String entered; // RIA ID typed on the Redeem tab
private String receiptOperation,receiptReference,receiptMessage;
private long receiptAmount;
AtmMenu(DuneMenusPlugin plugin, Player p, Menu parent, Tab tab) { super(plugin, p, parent); this.tab = tab; }
String id() { return tab == Tab.WITHDRAW ? "withdraw" : "atm"; }
String id() { return switch(tab){case WITHDRAW->"withdraw";case DEPOSIT->"deposit";case REDEEM->"redeem";case RECEIPT->"receipt";default->"atm";}; }
Skin skin() { return tab == Tab.REDEEM ? Skin.GOLD : Skin.TRAVEL; }
String title() { return "Rihla ATM"; }
String title() { return switch(tab){case HOME->"Rihla ATM";case DEPOSIT->"Rihla · Deposit cash";case WITHDRAW->"Rihla · Withdraw cash";case REDEEM->"Rihla · Redeem RIA ID";case RECEIPT->"Rihla · Transaction receipt";}; }
String subtitle() { return switch (tab) {
case HOME -> "Choose a cash service. Bills and coins are selected inside the operation.";
case DEPOSIT -> "Put in cash. You get an RIA ID to keep or give away.";
case REDEEM -> "Got an RIA ID? Type it in and take the money as cash or to your bank.";
case WITHDRAW -> "Take cash out of your own bank account."; }; }
case WITHDRAW -> "Select bills and coins, then withdraw the displayed amount.";
case RECEIPT -> "Your bank-reported transaction result. Keep your RIA ID."; }; }
int rows() { return 5; }
@Override boolean renderWhileLoading(){return true;}
@Override boolean navigationWhileLoading(int slot){return slot==0||slot==1||slot==2||slot==36;}
@ -55,11 +56,20 @@ final class AtmMenu extends Menu {
void draw() {
backdrop(Material.BLACK_STAINED_GLASS_PANE);
for (int s : new int[]{3, 5, 6, 7, 8}) put(s, Ui.pane(Material.CYAN_STAINED_GLASS_PANE));
tabButton(0, Material.EMERALD, "Deposit cash", Tab.DEPOSIT);
tabButton(1, Material.NAME_TAG, "Redeem RIA ID", Tab.REDEEM);
tabButton(2, Material.GOLD_INGOT, "Withdraw cash", Tab.WITHDRAW);
back(36);
if(tab==Tab.HOME)return;
if(tab==Tab.HOME){
tabButton(0, Material.EMERALD, "Deposit cash", Tab.DEPOSIT);
tabButton(1, Material.NAME_TAG, "Redeem RIA ID", Tab.REDEEM);
tabButton(2, Material.GOLD_INGOT, "Withdraw cash", Tab.WITHDRAW);
put(36,Ui.item(Material.ARROW,"<gray>Back"),c->{end();plugin.openNativeService(player,"hub");});
return;
}
put(36,Ui.item(Material.ARROW,"<gray>Back"),c->{tab=Tab.HOME;selected.clear();redraw();});
if(tab==Tab.RECEIPT){
put(13,Ui.item(Material.PAPER,"<gold>"+receiptOperation,
"<gray>Amount: <white>"+Ui.dm(receiptAmount),"<gray>"+receiptMessage));
if(receiptReference!=null&&!receiptReference.isBlank())put(29,Ui.item(Material.NAME_TAG,"<gold>RIA ID","<white>"+receiptReference));
return;
}
if (tab == Tab.REDEEM) drawRedeem(); else drawCash();
}
@ -67,13 +77,10 @@ final class AtmMenu extends Menu {
long minor = selected.stream().mapToLong(DunemarkDenomination::faceMinor).sum();
boolean dep = tab == Tab.DEPOSIT;
String verb = dep ? "Deposit" : "Withdraw";
put(4, Ui.glow(Ui.item(Material.LIGHTNING_ROD, "<aqua><b>" + (minor == 0 ? "Choose bills and coins" : verb + " " + Ui.dm(minor)),
minor == 0 ? "<gray>Tap the bills and coins below" : "<gray>Ready")));
put(9, Ui.item(Material.GREEN_STAINED_GLASS_PANE, "<green><b>Bills"));
put(13, Ui.item(Material.YELLOW_STAINED_GLASS_PANE, "<gold><b>Coins"));
for (int i = 0; i < BILLS.length; i++) add(BILLS[i], NOTES.get(i));
for (int i = 0; i < COINS.length; i++) add(COINS[i], COIN_VALUES.get(i));
put(21, Ui.item(Material.RED_STAINED_GLASS_PANE, "<red><b>Clear"), c -> { selected.clear(); redraw(); });
put(24, minor == 0 ? Ui.item(Material.GRAY_DYE, "<gray>" + verb, "<dark_gray>Choose bills and coins first")
: Ui.glow(Ui.item(dep ? Material.EMERALD : Material.GOLD_INGOT, "<green><b>" + verb + " " + Ui.dm(minor),
@ -84,59 +91,41 @@ final class AtmMenu extends Menu {
if (dep) load(backend().atmCreateRia(player, pieces), r -> {
say(new Backend.Result(r.ok(), r.message()));
if (r.ok()) { issued = r.riaId(); selected.clear(); }
redraw();
if (r.ok()) { receipt("Cash deposit",minor,r.riaId(),r.message()); }
else redraw();
});
else load(backend().bankWithdraw(player, pieces), r -> {
say(r);
if (r.ok()) selected.clear();
redraw();
if (r.ok()) receipt("Cash withdrawal",minor,null,r.message());
else redraw();
});
});
// framed ID box
for (int s : new int[]{28, 30}) put(s, Ui.pane(Material.YELLOW_STAINED_GLASS_PANE));
if (dep) {
drawIssuedVoucher();
if (!recoveredDeposit) load(backend().atmRecentDeposit(player), voucher -> {
recoveredDeposit = true;
issued = voucher.isEmpty() ? null : voucher;
drawIssuedVoucher();
});
} else {
put(29, Ui.item(Material.NAME_TAG, "<gold><b>Rihla reference", "<gray>Loading…"));
load(backend().bankAccount(player), a -> put(29, Ui.item(Material.NAME_TAG, "<gold><b>Rihla reference",
"<white>" + a.accountNo(), "<gray>Postbank available: <white>" + (a.postbankAvailableMinor()==null?"Unavailable":Ui.dm(a.postbankAvailableMinor())))));
}
}
private void drawIssuedVoucher() {
put(29, issued == null ? Ui.item(Material.NAME_TAG, "<gold><b>Your new RIA ID", "<dark_gray>Appears here after you deposit")
: Ui.glow(Ui.item(Material.NAME_TAG, "<gold><b>Your new RIA ID", "<white>" + issued, "<gray>Give it to anyone to collect the money",
"<yellow>Click to show in chat")),
c -> { if (issued != null) player.sendMessage(Ui.text("<gold>RIA ID: <click:copy_to_clipboard:'" + issued + "'><white><u>" + issued + "</u></click>")); });
private void receipt(String operation,long amount,String reference,String message){
receiptOperation=operation;receiptAmount=amount;receiptReference=reference;receiptMessage=message;
selected.clear();tab=Tab.RECEIPT;redraw();
}
private void drawRedeem() {
put(4, Ui.glow(Ui.item(Material.LIGHTNING_ROD, "<aqua><b>Redeem an RIA ID", "<gray>1. Type the ID", "<gray>2. Pick Cash or To bank")));
put(13, Ui.item(Material.WRITABLE_BOOK, entered == null ? "<yellow><b>Type RIA ID" : "<yellow><b>Change RIA ID",
"<gray>Click, then type it in chat"), c -> {
put(13, Ui.item(Material.WRITABLE_BOOK, entered == null ? "<yellow><b>Enter RIA ID" : "<yellow><b>Change RIA ID",
"<gray>Open the reference entry window"), c -> {
end();
ChatPrompt.ask(player, "<gold>Type the RIA ID in chat:", text -> { if (text != null && text.matches("RIA-[A-F0-9]{32}")) entered = text; open(); });
plugin.closeNativePresentation(player);
plugin.enterRia(player,text->{if(text!=null)entered=text;open();});
});
for (int s : new int[]{28, 30}) put(s, Ui.pane(Material.YELLOW_STAINED_GLASS_PANE));
put(29, Ui.item(Material.NAME_TAG, "<gold><b>RIA ID", entered == null ? "<dark_gray>Nothing entered yet" : "<white>" + entered));
put(24, Ui.item(Material.GRAY_DYE, "<gray>Take as cash", "<dark_gray>Enter an RIA ID first"));
put(26, Ui.item(Material.GRAY_DYE, "<gray>Send to my bank", "<dark_gray>Enter an RIA ID first"));
if (entered == null) return;
put(29,Ui.item(Material.NAME_TAG,"<gold>RIA ID","<white>"+entered));
final String id = entered;
load(backend().atmLookup(player, id), v -> {
if (v == null) { put(22, Ui.item(Material.BARRIER, "<red>RIA ID not found")); return; }
put(22, Ui.glow(Ui.item(Material.GOLD_BLOCK, "<gold><b>" + Ui.dm(v.amountMinor()), "<gray>From: <white>" + v.fromName())));
put(24, Ui.glow(Ui.item(Material.GOLD_INGOT, "<green><b>Take as cash", "<gray>Bills and coins in your inventory")),
c -> load(backend().atmRedeem(player, v, false), r -> { say(r); if (r.ok()) entered = null; redraw(); }));
c -> load(backend().atmRedeem(player, v, false), r -> { say(r); if (r.ok()) {entered = null;receipt("RIA payout · Cash",v.amountMinor(),id,r.message());} else redraw(); }));
put(26, Ui.glow(Ui.item(Material.ENDER_CHEST, "<aqua><b>Send to my bank", "<gray>Credited to your account")),
c -> load(backend().atmRedeem(player, v, true), r -> { say(r); if (r.ok()) entered = null; redraw(); }));
c -> load(backend().atmRedeem(player, v, true), r -> { say(r); if (r.ok()) {entered = null;receipt("RIA payout · Bank",v.amountMinor(),id,r.message());} else redraw(); }));
});
}
}