Make Rihla ATM operations focused and discoverable #14
17 changed files with 273 additions and 60 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import java.security.MessageDigest
|
||||
plugins { java }
|
||||
group = "com.dunerealms"
|
||||
version = "2.0.4"
|
||||
version = "2.0.5"
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
receiptAmount==null?"<gray>"+receiptMessage:"<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,42 @@ 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",r.receipt(),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",r.receipt(),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,Backend.CashReceipt facts,String message){
|
||||
receiptOperation=facts!=null&&facts.recovered()?"Recovered Rihla transaction":operation;
|
||||
receiptAmount=facts==null?null:facts.amountMinor();receiptReference=facts==null?null:facts.riaId();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",r.receipt(),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",r.receipt(),r.message());} else redraw(); }));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,9 @@ 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) {
|
||||
record CashReceipt(long amountMinor,String riaId,boolean recovered) {}
|
||||
record Result(boolean ok, String message, CashReceipt receipt) {
|
||||
public Result(boolean ok,String message){this(ok,message,null);}
|
||||
public static Result yes(String m) { return new Result(true, m); }
|
||||
public static Result no(String m) { return new Result(false, m); }
|
||||
}
|
||||
|
|
@ -96,7 +98,9 @@ public interface Backend {
|
|||
// 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) {}
|
||||
record Issued(boolean ok, String message, String riaId, CashReceipt receipt) {
|
||||
public Issued(boolean ok,String message,String riaId){this(ok,message,riaId,null);}
|
||||
}
|
||||
default CompletableFuture<Issued> atmCreateRia(Player p, List<DunemarkDenomination> pieces) { 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) {}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -97,7 +97,8 @@ final class JarvisBackend implements Backend, Listener {
|
|||
}
|
||||
return cashAction(player,request).thenApply(row->{
|
||||
String voucher=number(row,"voucher");
|
||||
return new Issued(!voucher.isEmpty(),voucher.isEmpty()?cashResult(row).message():"Rihla voucher created.",voucher);
|
||||
var result=cashResult(row);
|
||||
return new Issued(result.ok()&&!voucher.isEmpty(),result.message(),voucher,result.receipt());
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -133,7 +134,8 @@ final class JarvisBackend implements Backend, Listener {
|
|||
request.addProperty("voucher",voucher.riaId());
|
||||
request.addProperty("requestId",UUID.randomUUID().toString());
|
||||
var row=accepted(jarvis.requestRihla(actor,request));
|
||||
return Result.yes("Credited "+Ui.dm(money(row,"amountMinor"))+" to your Postbank account.");
|
||||
long amount=money(row,"amountMinor");
|
||||
return new Result(true,"Credited "+Ui.dm(amount)+" to your Postbank account.",new CashReceipt(amount,voucher.riaId(),false));
|
||||
}));
|
||||
}
|
||||
var pieces=change(voucher.amountMinor());
|
||||
|
|
@ -192,13 +194,14 @@ final class JarvisBackend implements Backend, Listener {
|
|||
return List.copyOf(result);
|
||||
}
|
||||
|
||||
private static Result cashResult(JsonObject result) {
|
||||
static Result cashResult(JsonObject result) {
|
||||
if(result.has("localError"))return Result.no(text(result,"localError"));
|
||||
if(text(result,"state").equals("aborted"))return Result.no("The previous unfinished Rihla cash action was released. Select your cash again.");
|
||||
if(!text(result,"state").equals("committed"))return Result.no("Rihla cash was not settled.");
|
||||
String voucher=number(result,"voucher");
|
||||
String prefix=yes(result,"recovered")?"Previous Rihla cash action recovered · ":"Rihla cash settled · ";
|
||||
return Result.yes(prefix+Ui.dm(money(result,"amountMinor"))+(voucher.isEmpty()?".":" · "+voucher+"."));
|
||||
long amount=money(result,"amountMinor");
|
||||
return new Result(true,prefix+Ui.dm(amount)+(voucher.isEmpty()?".":" · "+voucher+"."),new CashReceipt(amount,voucher,yes(result,"recovered")));
|
||||
}
|
||||
|
||||
private static String number(JsonObject row,String key){
|
||||
|
|
|
|||
|
|
@ -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
BIN
DuneMenus/src/main/resources/menu-art/art/rihla.png
Normal file
BIN
DuneMenus/src/main/resources/menu-art/art/rihla.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.5 MiB |
|
|
@ -4,6 +4,22 @@ public class RendererVerification {
|
|||
public static void main(String[]args)throws Exception{
|
||||
Path dir=Path.of(args[0]);Files.createDirectories(dir);var loader=new Page.Loader(false,dir.resolve("engine-cache"));int checked=0;
|
||||
Files.createDirectories(dir.resolve("art"));Files.copy(Path.of("src/main/resources/menu-art/art/logo.png"),dir.resolve("art/logo.png"),StandardCopyOption.REPLACE_EXISTING);
|
||||
Files.copy(Path.of("src/main/resources/menu-art/art/rihla.png"),dir.resolve("art/rihla.png"),StandardCopyOption.REPLACE_EXISTING);
|
||||
for(String operation:List.of("withdraw","deposit","redeem","receipt")){
|
||||
List<Card> cash=new ArrayList<>();Map<Integer,String> cashArt=new HashMap<>();
|
||||
if(operation.equals("withdraw")||operation.equals("deposit")){
|
||||
String[] names={"note_10","note_20","note_50","note_100","note_500","coin_050","coin_1dm","coin_2dm"};String[] amounts={"10.00","20.00","50.00","100.00","500.00","0.50","1.00","2.00"};
|
||||
for(int n=0;n<names.length;n++){cash.add(new Card(10+n,amounts[n]+" DM",List.of("Select one bill or coin"),"paper"));String asset="pack/assets/dunerealms/textures/item/currency/"+names[n]+".png";Path target=dir.resolve(asset);Files.createDirectories(target.getParent());Files.copy(Path.of("../network/resource-pack/central/overlay/assets/dunerealms/textures/item/currency/"+names[n]+".png"),target,StandardCopyOption.REPLACE_EXISTING);cashArt.put(10+n,asset);}
|
||||
cash.add(new Card(24,operation.equals("withdraw")?"Withdraw 50.00 DM":"Deposit 50.00 DM",List.of(),"gold_ingot"));
|
||||
}else if(operation.equals("redeem"))cash.add(new Card(13,"Enter RIA ID",List.of("Open the reference entry window"),"writable_book"));
|
||||
cash.add(new Card(36,"Back",List.of(),"arrow"));
|
||||
String html=SuppliedDocument.html(operation,"Rihla · "+operation,"Choose your transaction",cash,operation.equals("receipt")?List.of("Cash deposit — Amount: 50.00 DM","RIA ID — RIA-0123456789ABCDEF0123456789ABCDEF"):List.of(),cashArt);
|
||||
var page=Page.of(html,dir.resolve("rihla-"+operation+".html"),loader);
|
||||
var frame=HtmlRenderer.render(page,1536,896,1.5,0,Selector.State.NONE);
|
||||
if(!page.problems.isEmpty())throw new AssertionError(page.problems.toString());
|
||||
for(Card card:cash){var element=page.document.selectFirst("[data-slot='"+card.slot()+"']");var bounds=frame.boundsOf(element);if(bounds==null)throw new AssertionError("Missing Rihla action");var hit=frame.elementAt(bounds.getCenterX(),bounds.getCenterY());if(hit==null||hit.closest("[data-slot]")==null||!hit.closest("[data-slot]").attr("data-slot").equals(""+card.slot()))throw new AssertionError("Rihla action outside initial viewport "+operation+" "+card.slot());}
|
||||
ImageIO.write(frame.image(),"png",dir.resolve("rihla-"+operation+"-engine.png").toFile());
|
||||
}
|
||||
for(String id:List.of("hub","travel","exchange","clan","company","missions","spice","war","politics","house","equipment","bank","atm","withdraw","transfer")){
|
||||
long started=System.nanoTime();List<Card> cards=new ArrayList<>();int count=id.equals("exchange")?28:id.equals("travel")?5:8;
|
||||
for(int n=0;n<count;n++)cards.add(new Card(n,(n==0?"Imperial Postbank · very long official account title":"Entry "+(n+1)),(n==0||id.equals("exchange"))?List.of("Personal level, Reputation and active quests","LEGENDARY | MK XIV","Efficiency VIII","Fortune IV","Mending I","Unbreaking IV","4 available · 100.00 DM each","Seller: Guild"):List.of("Verified service detail","Amount: 100.00 DM"),id.equals("travel")?"compass":"emerald"));
|
||||
|
|
|
|||
|
|
@ -0,0 +1,46 @@
|
|||
package com.dunerealms.menus;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.inventory.AnvilInventory;
|
||||
import org.bukkit.inventory.view.AnvilView;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
class RiaInputLifecycleTest {
|
||||
@SuppressWarnings("unchecked")
|
||||
private static RiaInput input(DuneMenusPlugin plugin,Player player,AnvilView view,UUID world,Consumer<String> done)throws Exception{
|
||||
var input=new RiaInput(plugin);
|
||||
var field=RiaInput.class.getDeclaredField("entries");field.setAccessible(true);
|
||||
var entry=Class.forName(RiaInput.class.getName()+"$Entry").getDeclaredConstructor(AnvilView.class,UUID.class,Consumer.class);entry.setAccessible(true);
|
||||
((Map<UUID,Object>)field.get(input)).put(player.getUniqueId(),entry.newInstance(view,world,done));
|
||||
return input;
|
||||
}
|
||||
@Test void submitConsumesTemporaryInventoryAndRunsOnlyOnce()throws Exception{
|
||||
try(var bukkit=mockStatic(Bukkit.class)){
|
||||
var plugin=mock(DuneMenusPlugin.class);var player=mock(Player.class);var world=mock(World.class);UUID id=UUID.randomUUID(),location=UUID.randomUUID();
|
||||
when(player.getUniqueId()).thenReturn(id);when(player.isOnline()).thenReturn(true);when(player.getWorld()).thenReturn(world);when(world.getUID()).thenReturn(location);
|
||||
var view=mock(AnvilView.class);var inventory=mock(AnvilInventory.class);when(view.getTopInventory()).thenReturn(inventory);when(view.getRenameText()).thenReturn("ria-0123456789abcdef0123456789abcdef");when(player.getOpenInventory()).thenReturn(view);
|
||||
var scheduler=mock(BukkitScheduler.class);bukkit.when(Bukkit::getScheduler).thenReturn(scheduler);
|
||||
doAnswer(c->{((Runnable)c.getArgument(1)).run();return null;}).when(scheduler).runTask(eq(plugin),any(Runnable.class));
|
||||
Consumer<String> done=mock(Consumer.class);var input=input(plugin,player,view,location,done);
|
||||
var click=mock(InventoryClickEvent.class);when(click.getWhoClicked()).thenReturn(player);when(click.getView()).thenReturn(view);when(click.getRawSlot()).thenReturn(2);
|
||||
input.click(click);input.click(click);
|
||||
verify(click).setCancelled(true);verify(inventory).clear();verify(player).closeInventory();verify(done).accept("RIA-0123456789ABCDEF0123456789ABCDEF");verifyNoMoreInteractions(done);
|
||||
}
|
||||
}
|
||||
@Test void replacementViewCleansInputWithoutReopeningTheOldMenu()throws Exception{
|
||||
var plugin=mock(DuneMenusPlugin.class);var player=mock(Player.class);when(player.getUniqueId()).thenReturn(UUID.randomUUID());
|
||||
var view=mock(AnvilView.class);var inventory=mock(AnvilInventory.class);when(view.getTopInventory()).thenReturn(inventory);
|
||||
Consumer<String> done=mock(Consumer.class);var input=input(plugin,player,view,UUID.randomUUID(),done);
|
||||
var event=mock(InventoryCloseEvent.class);when(event.getPlayer()).thenReturn(player);when(event.getView()).thenReturn(view);when(event.getReason()).thenReturn(InventoryCloseEvent.Reason.OPEN_NEW);
|
||||
input.closed(event);input.closed(event);
|
||||
verify(inventory).clear();verifyNoInteractions(done);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package com.dunerealms.menus;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
class RihlaReceiptTest {
|
||||
@Test void recoveredReceiptUsesSettledFactsInsteadOfNewSelection(){
|
||||
var row=new JsonObject();row.addProperty("state","committed");row.addProperty("amountMinor",2000);row.addProperty("voucher","RIA-0123456789ABCDEF0123456789ABCDEF");row.addProperty("recovered",true);
|
||||
var result=JarvisBackend.cashResult(row);
|
||||
assertTrue(result.ok());assertEquals(2000,result.receipt().amountMinor());assertTrue(result.receipt().recovered());assertEquals(row.get("voucher").getAsString(),result.receipt().riaId());
|
||||
}
|
||||
@Test void nonCommittedResultsDoNotProduceSuccessfulReceipts(){
|
||||
for(String state:new String[]{"aborted","prepared","queued"}){var row=new JsonObject();row.addProperty("state",state);row.addProperty("amountMinor",5000);var result=JarvisBackend.cashResult(row);assertFalse(result.ok());assertNull(result.receipt());}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package com.dunerealms.menus;
|
||||
import java.util.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
class RihlaScreenTest {
|
||||
@Test void referenceEntryAcceptsOnlyCompleteRiaReferences(){
|
||||
assertEquals("RIA-0123456789ABCDEF0123456789ABCDEF",RiaInput.normalize(" ria-0123456789abcdef0123456789abcdef "));
|
||||
for(String invalid:List.of("RIA-","RIA-1234","<button>RIA-0123456789ABCDEF0123456789ABCDEF","ITM-0123456789abcdef0123456789abcdef"))assertNull(RiaInput.normalize(invalid));
|
||||
assertNull(RiaInput.normalize(null));
|
||||
}
|
||||
@Test void cashActionAndBackAreOutsideTheDenominationGrid(){
|
||||
for(String id:List.of("withdraw","deposit")){
|
||||
String verb=id.equals("withdraw")?"Withdraw":"Deposit";
|
||||
String html=SuppliedDocument.html(id,"Rihla · "+verb,"Select cash",List.of(new Card(11,"50.00 DM",List.of("Select one"),"paper"),new Card(24,verb+" 50.00 DM",List.of(),"gold_ingot"),new Card(36,"Back",List.of(),"arrow")),List.of());
|
||||
assertTrue(html.contains("art/rihla.png"));assertTrue(html.contains("RIHLA MONEY TRANSFER"));
|
||||
assertTrue(html.contains("class='cash-action' data-slot='24'"));assertTrue(html.contains("class='cash-action' data-slot='36'"));
|
||||
assertTrue(html.indexOf("data-slot='24'")<html.indexOf("<main"));
|
||||
assertEquals(1,html.split("class='cash-action' data-slot='24'",-1).length-1);
|
||||
}
|
||||
}
|
||||
@Test void receiptRendersOnlySuppliedReferenceAndResult(){
|
||||
String html=SuppliedDocument.html("receipt","Transaction receipt","Bank result",List.of(new Card(36,"Back",List.of(),"arrow")),List.of("Cash deposit — Amount: 50.00 DM","RIA ID — RIA-0123456789ABCDEF0123456789ABCDEF"));
|
||||
assertTrue(html.contains("RIA-0123456789ABCDEF0123456789ABCDEF"));assertFalse(html.contains("Fee: 0"));assertFalse(html.contains("Deposit cash"));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
plugins { java }
|
||||
group = "com.dunerealms"
|
||||
version = "1.1.38"
|
||||
version = "1.1.39"
|
||||
repositories { mavenCentral(); maven("https://repo.papermc.io/repository/maven-public/"); maven("https://repo.opencollab.dev/main/") }
|
||||
dependencies {
|
||||
compileOnly("io.papermc.paper:paper-api:1.21.8-R0.1-SNAPSHOT")
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ final class OrganisationMenus implements Listener {
|
|||
public Inventory getInventory(){return inventory;}
|
||||
}
|
||||
OrganisationMenus(JavaPlugin plugin,HouseBridge bridge,Consumer<Player> mentat,Consumer<Player> travel,Consumer<Player> house,Consumer<Player> quests,Consumer<Player> exchange,Consumer<Player> spice,java.util.function.Predicate<Player> artwork){this.plugin=plugin;this.bridge=bridge;this.mentat=mentat;this.travel=travel;this.house=house;this.quests=quests;this.exchange=exchange;this.spice=spice;this.artwork=artwork;Bukkit.getPluginManager().registerEvents(this,plugin);}
|
||||
void console(Player p){var panel=panel(p,"Imperial Codex",0);if(p.getWorld().getName().equals("arrakis"))put(panel,28,"Spice buyers","Spacing Guild · Smuggler · P&O payout",Material.ORANGE_DYE,()->spice.accept(p));put(panel,34,"Exchange","Buy, sell and collect your purchases",Material.CHEST,()->exchange.accept(p));var exchangeIcon=new ItemStack(Material.CHEST);var exchangeMeta=exchangeIcon.getItemMeta();exchangeMeta.displayName(Component.text("Exchange",NamedTextColor.GOLD));exchangeMeta.lore(List.of(Component.text("Buy · Sell · Add held item",NamedTextColor.GRAY)));exchangeIcon.setItemMeta(exchangeMeta);panel.inventory.setItem(34,exchangeIcon);put(panel,31,"Mission journal","Personal Experience and Reputation",Material.WRITABLE_BOOK,()->quests.accept(p));put(panel,4,"Item lore archive","Preview the shared item lore cards",Material.WRITABLE_BOOK,()->lore(p));put(panel,19,"Clan","Your clan and Home Block",Material.GREEN_BANNER,()->open(p,"clans"));put(panel,22,"Company","Your companies and Home Blocks",Material.CYAN_BANNER,()->open(p,"companies"));put(panel,25,"POL","Your current political offices",Material.PURPLE_BANNER,()->open(p,"offices"));put(panel,37,"Your Mentat","Your personal briefing. Indeed.",Material.BOOK,()->mentat.accept(p));put(panel,40,"Spacing Guild","Transport and boarding windows",Material.COMPASS,()->travel.accept(p));put(panel,43,"Your House","Your allegiance and adviser",Material.NETHER_STAR,()->house.accept(p));close(panel,p);show(p,panel);}
|
||||
void console(Player p){var panel=panel(p,"Imperial Codex",0);put(panel,7,"Rihla ATM","Deposit cash · Redeem RIA ID · Withdraw cash",Material.GOLD_INGOT,()->{if(!SuppliedMenus.open(p,"atm"))p.sendMessage("The Rihla ATM is temporarily unavailable.");});if(p.getWorld().getName().equals("arrakis"))put(panel,28,"Spice buyers","Spacing Guild · Smuggler · P&O payout",Material.ORANGE_DYE,()->spice.accept(p));put(panel,34,"Exchange","Buy, sell and collect your purchases",Material.CHEST,()->exchange.accept(p));var exchangeIcon=new ItemStack(Material.CHEST);var exchangeMeta=exchangeIcon.getItemMeta();exchangeMeta.displayName(Component.text("Exchange",NamedTextColor.GOLD));exchangeMeta.lore(List.of(Component.text("Buy · Sell · Add held item",NamedTextColor.GRAY)));exchangeIcon.setItemMeta(exchangeMeta);panel.inventory.setItem(34,exchangeIcon);put(panel,31,"Mission journal","Personal Experience and Reputation",Material.WRITABLE_BOOK,()->quests.accept(p));put(panel,4,"Item lore archive","Preview the shared item lore cards",Material.WRITABLE_BOOK,()->lore(p));put(panel,19,"Clan","Your clan and Home Block",Material.GREEN_BANNER,()->open(p,"clans"));put(panel,22,"Company","Your companies and Home Blocks",Material.CYAN_BANNER,()->open(p,"companies"));put(panel,25,"POL","Your current political offices",Material.PURPLE_BANNER,()->open(p,"offices"));put(panel,37,"Your Mentat","Your personal briefing. Indeed.",Material.BOOK,()->mentat.accept(p));put(panel,40,"Spacing Guild","Transport and boarding windows",Material.COMPASS,()->travel.accept(p));put(panel,43,"Your House","Your allegiance and adviser",Material.NETHER_STAR,()->house.accept(p));close(panel,p);show(p,panel);}
|
||||
void open(Player p,String kind){
|
||||
if(!busy.add(p.getUniqueId()))return;
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin,()->{JsonObject data=null;try{data=bridge.organisations(p.getUniqueId());}catch(Exception ignored){}JsonObject result=data;if(!plugin.isEnabled())return;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
name: DunerealmsGUI
|
||||
main: com.dunerealms.gui.DuneGUI
|
||||
version: 1.1.38
|
||||
version: 1.1.39
|
||||
api-version: '1.21.8'
|
||||
depend: [JarvisTranslator]
|
||||
softdepend: [Citizens, MCGUI, DecentHolograms, DuneLobby, DuneCore, DuneEss, DuneNPC, Vault, floodgate, ViaVersion]
|
||||
|
|
|
|||
21
docs/RIHLA-ATM-SCREENS-20261129.md
Normal file
21
docs/RIHLA-ATM-SCREENS-20261129.md
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# Focused Rihla ATM screens
|
||||
|
||||
## Objective
|
||||
|
||||
Make the cash flow discoverable from the Imperial Codex and separate operation selection from the actual transaction controls. The owner supplied reference screenshots of RIA forms and explicitly requested Dune/Rihla branding, English text, operation-only screens, one Back action and a final receipt with its actual RIA ID. No private training screenshots or customer information are packaged.
|
||||
|
||||
## Flow
|
||||
|
||||
- Imperial Codex has a Rihla ATM entry using the existing `atm` route.
|
||||
- ATM home offers Deposit cash, Redeem RIA ID and Withdraw cash. Back returns to the Codex.
|
||||
- Deposit/Withdraw show actual denomination artwork and selectors, one amount-labelled transaction action and Back. The action is above the denomination grid and visible in the initial viewport. There are no repeated operation tabs or a second lookalike Withdraw tile. Selecting a denomination still only selects it; the existing final action performs the transaction. No new confirmation step is added.
|
||||
- Redeem offers reference entry, then the existing verified voucher amount and payout destinations. Reference entry uses a native Minecraft anvil text window because pinned MCGUI 0.8.6 has no editable text-field API. It is not an editable HTML form. Input is normalized and validated, never sent through chat. Closing the entry window returns to Redeem. All input items and clicks are isolated and cleared on completion, close, quit and disable.
|
||||
- A successful bank response opens the transaction receipt. It displays the actual operation, bank-returned amount, backend result and RIA ID when the backend supplies one. It invents neither a withdrawal RIA ID nor fees, zero-cost claims or settlement status. Recovered cash operations use the earlier settled amount/reference and an explicit recovered-transaction label, never the current selection. Existing backend errors remain errors, not successful receipts. Back returns to ATM home.
|
||||
|
||||
The canonical `rihla-brand-v1.png` artwork is packaged locally and proportionally displayed using its existing top-logo region. No remote image fetch occurs when opening the screen. Currency artwork and the published resource pack are unchanged.
|
||||
|
||||
## Validation and release boundary
|
||||
|
||||
Run the DuneMenus and GUI tests, reference validation and cash-control/receipt rendering tests, plus pinned real MCGUI render checks for the four Rihla operation/receipt fixtures. Check both real transaction controls and Back are visible and clickable without scrolling; preserve all existing lifecycle and pending-operation guards. Read-only inspection confirmed the new native text-entry methods also exist in the available Paper 26.2 build 135 API.
|
||||
|
||||
These checks do not constitute a real cash withdrawal/deposit or connected-client anvil test. The coordinator must verify the built exact-head artifact and a lobby canary, including opening/cancelling native reference entry and returning to Redeem, before claiming deployed functional acceptance. No backend JARs, bank permissions, fees, settlement logic, balances or paid receipts are changed by this release. Frontend versions: DuneMenus 2.0.5 and DunerealmsGUI 1.1.39.
|
||||
Loading…
Reference in a new issue

Staff