Give Rihla focused ATM screens, native reference entry and receipts
This commit is contained in:
parent
7a89b04c91
commit
abfa82bca8
5 changed files with 245 additions and 54 deletions
|
|
@ -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(); }));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ public final class DuneMenusPlugin extends JavaPlugin implements TabExecutor {
|
|||
"spice", "war", "mentat", "lore", "politics", "house", "equipment", "bank", "atm", "withdraw");
|
||||
private static final String PACK_CONTROL = "dunerealms:pack_control";
|
||||
private Backend backend;
|
||||
private RiaInput riaInput;
|
||||
void enterRia(Player player,java.util.function.Consumer<String> done){riaInput.ask(player,done);}
|
||||
private NativePresentationRoutes nativePresentationRoutes;
|
||||
private final Map<Player, String> loadedPacks = new HashMap<>();
|
||||
private final Map<UUID, Menu> openMenus = new HashMap<>();
|
||||
|
|
@ -45,6 +47,8 @@ public final class DuneMenusPlugin extends JavaPlugin implements TabExecutor {
|
|||
public void onEnable() {
|
||||
saveDefaultConfig();
|
||||
backend = JarvisBackend.create(this);
|
||||
riaInput=new RiaInput(this);
|
||||
getServer().getPluginManager().registerEvents(riaInput,this);
|
||||
var messenger = getServer().getMessenger();
|
||||
messenger.registerOutgoingPluginChannel(this, PACK_CONTROL);
|
||||
messenger.registerIncomingPluginChannel(this, PACK_CONTROL, (channel, player, bytes) -> {
|
||||
|
|
@ -65,6 +69,7 @@ public final class DuneMenusPlugin extends JavaPlugin implements TabExecutor {
|
|||
}
|
||||
|
||||
@Override public void onDisable() {
|
||||
if(riaInput!=null)riaInput.close();
|
||||
if(nativePresentationRoutes!=null)nativePresentationRoutes.close();
|
||||
for (Menu menu : List.copyOf(openMenus.values())) menu.closed();
|
||||
openMenus.clear();
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ abstract class Menu implements InventoryHolder {
|
|||
|
||||
private boolean available() {
|
||||
return switch (id()) {
|
||||
case "bank", "atm", "withdraw" -> {
|
||||
case "bank", "atm", "withdraw", "deposit", "redeem", "receipt" -> {
|
||||
if (plugin.getConfig().getBoolean("rihla.enabled", false)) yield true;
|
||||
say(Backend.Result.no("Rihla is currently unavailable in Minecraft."));
|
||||
yield false;
|
||||
|
|
|
|||
77
DuneMenus/src/main/java/com/dunerealms/menus/RiaInput.java
Normal file
77
DuneMenus/src/main/java/com/dunerealms/menus/RiaInput.java
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
package com.dunerealms.menus;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryDragEvent;
|
||||
import org.bukkit.event.inventory.PrepareAnvilEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.MenuType;
|
||||
import org.bukkit.inventory.view.AnvilView;
|
||||
|
||||
/** Native client text entry: no chat capture, world block or transferable input item. */
|
||||
final class RiaInput implements Listener {
|
||||
private record Entry(AnvilView view, UUID world, Consumer<String> done) {}
|
||||
private final DuneMenusPlugin plugin;
|
||||
private final Map<UUID,Entry> entries=new HashMap<>();
|
||||
RiaInput(DuneMenusPlugin plugin){this.plugin=plugin;}
|
||||
static String normalize(String text){
|
||||
if(text==null)return null;
|
||||
String value=text.strip().toUpperCase(java.util.Locale.ROOT);
|
||||
return value.matches("RIA-[A-F0-9]{32}")?value:null;
|
||||
}
|
||||
void ask(Player player,Consumer<String> done){
|
||||
var view=MenuType.ANVIL.builder().title(Ui.text("<gold>Rihla · Enter RIA ID")).checkReachable(false).build(player);
|
||||
view.getTopInventory().setItem(0,Ui.item(Material.PAPER,"RIA-"));
|
||||
entries.put(player.getUniqueId(),new Entry(view,player.getWorld().getUID(),done));
|
||||
player.openInventory(view);
|
||||
}
|
||||
@EventHandler public void prepare(PrepareAnvilEvent event){
|
||||
if(!(event.getView().getPlayer() instanceof Player player))return;
|
||||
Entry entry=entries.get(player.getUniqueId());
|
||||
if(entry==null||entry.view()!=event.getView())return;
|
||||
String value=normalize(entry.view().getRenameText());
|
||||
entry.view().setRepairCost(0);entry.view().setRepairItemCountCost(0);
|
||||
event.setResult(Ui.item(value==null?Material.BARRIER:Material.PAPER,
|
||||
value==null?"<gray>Enter the complete RIA ID":"<gold>Look up RIA ID"));
|
||||
}
|
||||
@EventHandler public void click(InventoryClickEvent event){
|
||||
if(!(event.getWhoClicked() instanceof Player player))return;
|
||||
Entry entry=entries.get(player.getUniqueId());
|
||||
if(entry==null||entry.view()!=event.getView())return;
|
||||
event.setCancelled(true);
|
||||
if(event.getRawSlot()!=2)return;
|
||||
String value=normalize(entry.view().getRenameText());
|
||||
if(value!=null)finish(player,entry,value);
|
||||
}
|
||||
@EventHandler public void drag(InventoryDragEvent event){
|
||||
Entry entry=entries.get(event.getWhoClicked().getUniqueId());
|
||||
if(entry!=null&&entry.view()==event.getView())event.setCancelled(true);
|
||||
}
|
||||
@EventHandler public void closed(InventoryCloseEvent event){
|
||||
if(!(event.getPlayer() instanceof Player player))return;
|
||||
Entry entry=entries.get(player.getUniqueId());
|
||||
if(entry==null||entry.view()!=event.getView())return;
|
||||
if(event.getReason()==InventoryCloseEvent.Reason.PLAYER)finish(player,entry,null);
|
||||
else {entries.remove(player.getUniqueId(),entry);entry.view().getTopInventory().clear();}
|
||||
}
|
||||
private void finish(Player player,Entry entry,String value){
|
||||
if(!entries.remove(player.getUniqueId(),entry))return;
|
||||
entry.view().getTopInventory().clear();
|
||||
Bukkit.getScheduler().runTask(plugin,()->{
|
||||
if(!player.isOnline()||!entry.world().equals(player.getWorld().getUID()))return;
|
||||
if(player.getOpenInventory()==entry.view())player.closeInventory();
|
||||
entry.done().accept(value);
|
||||
});
|
||||
}
|
||||
@EventHandler public void quit(PlayerQuitEvent event){Entry entry=entries.remove(event.getPlayer().getUniqueId());if(entry!=null)entry.view().getTopInventory().clear();}
|
||||
void close(){var closing=java.util.List.copyOf(entries.values());entries.clear();for(Entry entry:closing){entry.view().getTopInventory().clear();entry.view().close();}}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue

Staff