diff --git a/DuneFullscreenPaper/README.md b/DuneFullscreenPaper/README.md index 6cd90628..2a3361f2 100644 --- a/DuneFullscreenPaper/README.md +++ b/DuneFullscreenPaper/README.md @@ -2,6 +2,6 @@ DuneGit builds this provider as a separate development artifact. It requires Paper 26.2 build 135 and Java 25. Build `DuneRealmsGUI` first, then run `gradle -p DuneFullscreenPaper test jar` with Java 25 and Gradle 9.2.1. -The Java Decisions dashboard uses this provider only for UUIDs listed under `development.fullscreen-decisions-viewers` in the DunerealmsGUI config. Quest dashboards, turn-ins and next-mission screens use `development.fullscreen-quest-viewers`. Branded organisation modules use `development.fullscreen-organisation-viewers`, Exchange browse, listing and kit shelves use `development.fullscreen-exchange-viewers`, and House or Mentat screens use `development.fullscreen-house-viewers`. Keep these allowlists empty on live servers. Existing menus handle unavailable providers, invalid card slots, documents outside the 54-card inventory limit, and quest text that exceeds the native layout. +The Java Decisions dashboard uses this provider only for UUIDs listed under `development.fullscreen-decisions-viewers` in the DunerealmsGUI config. Quest dashboards, turn-ins and next-mission screens use `development.fullscreen-quest-viewers`. Branded organisation modules use `development.fullscreen-organisation-viewers`, Exchange browse, listing and kit shelves, plus loose-item and kit checkout, use `development.fullscreen-exchange-viewers`, and House or Mentat screens use `development.fullscreen-house-viewers`. Keep these allowlists empty on live servers. Existing menus handle unavailable providers, invalid card slots, documents outside the 54-card inventory limit, and quest text that exceeds the native layout. Larger documents retain their server-provided slots and show four entries per page in Decisions, quests and organisation modules, and six in Exchange and House views. The mounted view can still expose vanilla overlays such as the experience bar, crosshair, chat and system notifications. diff --git a/DuneFullscreenPaper/src/main/java/com/dunerealms/fullscreen/PaperDecisionsScene.java b/DuneFullscreenPaper/src/main/java/com/dunerealms/fullscreen/PaperDecisionsScene.java index 6336f431..23e4bef1 100644 --- a/DuneFullscreenPaper/src/main/java/com/dunerealms/fullscreen/PaperDecisionsScene.java +++ b/DuneFullscreenPaper/src/main/java/com/dunerealms/fullscreen/PaperDecisionsScene.java @@ -36,7 +36,9 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut private static final int LAST_ROW = 5, LAST_CARD_HEIGHT = 64; private static final Font CARD_TITLE = new Font(Font.SANS_SERIF, Font.BOLD, 17); private static final Font CARD_LORE = new Font(Font.SANS_SERIF, Font.PLAIN, 13); + private static final Font CHECKOUT_TERMS = new Font(Font.SANS_SERIF, Font.BOLD, 15); private static final int PREVIOUS = -1, NEXT = -2, EMPTY = -3; + private static final int CHECKOUT_BACK = 45, CHECKOUT_BUY = 49, CHECKOUT_CONTROLS = 2; private final Map scenes = new HashMap<>(); private final JavaPlugin plugin; // This range is private to each connection and reused on reopen to bound the client map cache. @@ -198,6 +200,7 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut } private static Page page(Document document, int index) { + if (document.style() == Style.EXCHANGE_CHECKOUT) return checkoutPage(document, index); var cards = document.cards(); int capacity = capacity(document.style()); if (cards.size() <= capacity) return new Page(0, document.style(), cards); @@ -211,6 +214,30 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut return new Page(index, document.style(), List.copyOf(visible)); } + private static Page checkoutPage(Document document, int index) { + var controls = document.cards().stream() + .filter(card -> card.slot() != CHECKOUT_BACK && card.slot() != CHECKOUT_BUY) + .sorted(Comparator.comparingInt(card -> switch (card.slot()) { + case 30 -> 0; + case 32 -> 1; + case 31 -> 2; + default -> 3; + })).toList(); + int start = index * CHECKOUT_CONTROLS; + int end = Math.min(start + CHECKOUT_CONTROLS, controls.size()); + var visible = new ArrayList<>(controls.subList(start, end)); + while (visible.size() < CHECKOUT_CONTROLS) visible.add(new Card(EMPTY, "", List.of(), false)); + for (int slot : new int[]{CHECKOUT_BACK,CHECKOUT_BUY}) { + visible.add(document.cards().stream().filter(card -> card.slot() == slot).findFirst().orElseThrow()); + } + if (controls.size() > CHECKOUT_CONTROLS) { + String number = "Page " + (index + 1) + " / " + ((controls.size() + CHECKOUT_CONTROLS - 1) / CHECKOUT_CONTROLS); + visible.add(new Card(PREVIOUS, "Previous", List.of(number), index > 0)); + visible.add(new Card(NEXT, "Next", List.of(number), end < controls.size())); + } + return new Page(index, document.style(), List.copyOf(visible)); + } + private void paint(Scene scene, boolean initial) { BufferedImage art = artwork(scene); scene.buttons.clear(); @@ -389,7 +416,7 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut draw.drawRect(445, 335, 518, 374); draw.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 38)); String heading = scene.roleplay != null ? scene.roleplay.heading : - scene.document.style() == Style.AUTO ? "YOUR DECISIONS" : scene.document.title(); + scene.document.style() == Style.AUTO ? "YOUR DECISIONS" : styledTitle(scene.document); int headlineWidth = draw.getFontMetrics().stringWidth(heading); draw.drawString(heading, (image.getWidth() - headlineWidth) / 2, 372); if (scene.roleplay != null) drawRoleplay(draw, scene); @@ -423,7 +450,7 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut private static Palette palette(Scene scene) { return switch (scene.document.style()) { case ORGANISATION -> new Palette(new Color(16, 31, 37), new Color(29, 75, 79), new Color(142, 228, 211)); - case EXCHANGE -> new Palette(new Color(42, 28, 18), new Color(91, 62, 36), new Color(245, 208, 139)); + case EXCHANGE, EXCHANGE_CHECKOUT -> new Palette(new Color(42, 28, 18), new Color(91, 62, 36), new Color(245, 208, 139)); case HOUSE -> new Palette(new Color(34, 26, 39), new Color(72, 52, 79), new Color(244, 211, 152)); case AUTO -> scene.roleplay == null ? new Palette(new Color(25, 40, 46), new Color(52, 93, 107), new Color(237, 199, 105)) @@ -435,7 +462,14 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut var graphics = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB).createGraphics(); try { graphics.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 38)); - if (!wrap(graphics, document.title(), 500, 1).complete) return false; + if (!wrap(graphics, styledTitle(document), 500, 1).complete) return false; + if (document.style() == Style.EXCHANGE_CHECKOUT) { + if (document.description().isBlank() || !hasCheckoutAction(document, CHECKOUT_BACK) || + !hasCheckoutAction(document, CHECKOUT_BUY)) return false; + graphics.setFont(CHECKOUT_TERMS); + var terms = checkoutTerms(graphics, document.description()); + if (terms.isEmpty() || terms.size() > 9) return false; + } graphics.setFont(CARD_TITLE); if (document.identity() != null && !wrap(graphics, document.identity().mentat(), 112, 2).complete) return false; for (Card card : document.cards()) { @@ -451,11 +485,30 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut } } + private static String styledTitle(Document document) { + return document.style() == Style.EXCHANGE_CHECKOUT ? "Exchange checkout" : document.title(); + } + + private static boolean hasCheckoutAction(Document document, int slot) { + return document.cards().stream().anyMatch(card -> card.slot() == slot && card.actionable()); + } + + private static List checkoutTerms(java.awt.Graphics2D graphics, String description) { + var lines = new ArrayList(); + for (String term : description.lines().toList()) { + var wrapped = wrap(graphics, term, 106, 9); + if (!wrapped.complete) return List.of(); + lines.addAll(wrapped.lines); + } + return lines; + } + private static String styledLore(Style style, Card card) { if (card.lore().isEmpty()) return ""; if (style == Style.HOUSE && card.material().startsWith("house_")) return card.lore().getFirst().equals("Your current House") ? card.lore().getFirst() : ""; - if (style == Style.EXCHANGE) { + if (style == Style.EXCHANGE_CHECKOUT && !card.actionable()) return String.join(" ", card.lore()); + if (style == Style.EXCHANGE || style == Style.EXCHANGE_CHECKOUT) { // The listing renderer appends the server price after the stored item lore. for (int index = card.lore().size() - 1; index >= 0; index--) { String line = card.lore().get(index); @@ -481,6 +534,15 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut draw.setColor(palette.background.darker()); draw.fillRect(644, 389, 120, 232); switch (document.style()) { + case EXCHANGE_CHECKOUT -> { + draw.setColor(Color.WHITE); + draw.setFont(CHECKOUT_TERMS); + int y = 420; + for (String line : checkoutTerms(draw, document.description())) { + draw.drawString(line, 651, y); + y += draw.getFontMetrics().getHeight(); + } + } case ORGANISATION -> { if (identity != null) { BufferedImage mark = organisationLogo(identity.logo()); @@ -506,7 +568,7 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut if (style == Style.ORGANISATION) { draw.fillRect(x, y + 3, 4, 122); draw.drawLine(x + 7, y + 69, x + 119, y + 69); - } else if (style == Style.EXCHANGE) { + } else if (style == Style.EXCHANGE || style == Style.EXCHANGE_CHECKOUT) { draw.fillRect(x, y + 70, 128, 5); draw.fillRect(x, y + 120, 128, 5); } else if (art != null) { diff --git a/DuneRealmsGUI/src/main/java/com/dunerealms/gui/DecisionsViewTransport.java b/DuneRealmsGUI/src/main/java/com/dunerealms/gui/DecisionsViewTransport.java index 243ba500..fe2f1bf1 100644 --- a/DuneRealmsGUI/src/main/java/com/dunerealms/gui/DecisionsViewTransport.java +++ b/DuneRealmsGUI/src/main/java/com/dunerealms/gui/DecisionsViewTransport.java @@ -19,7 +19,7 @@ public interface DecisionsViewTransport { } } - enum Style { AUTO, ORGANISATION, EXCHANGE, HOUSE } + enum Style { AUTO, ORGANISATION, EXCHANGE, EXCHANGE_CHECKOUT, HOUSE } record Identity(String logo, String mentat, int portrait) {} record Document(String title, String description, List cards, Style style, Identity identity) { diff --git a/DuneRealmsGUI/src/main/java/com/dunerealms/gui/ExchangeMenus.java b/DuneRealmsGUI/src/main/java/com/dunerealms/gui/ExchangeMenus.java index 4ac75ebe..331c62be 100644 --- a/DuneRealmsGUI/src/main/java/com/dunerealms/gui/ExchangeMenus.java +++ b/DuneRealmsGUI/src/main/java/com/dunerealms/gui/ExchangeMenus.java @@ -117,7 +117,18 @@ final class ExchangeMenus implements Listener,AutoCloseable { private static ItemStack icon(Material material,String title,String... lore){var item=new ItemStack(material);var meta=item.getItemMeta();meta.displayName(Component.text(title,NamedTextColor.GOLD));meta.lore(Arrays.stream(lore).map(s->Component.text(s,NamedTextColor.GRAY)).toList());item.setItemMeta(meta);return item;} private Panel panel(Player p,String title){int screen=title.endsWith("Your listings")?1:title.endsWith("Add item")?2:title.endsWith("Purchase details")?3:title.endsWith("Withdraw listing")?4:0;var s=new Panel(p,title,artwork.test(p)&&!BedrockForms.isBedrock(p),screen);if(!s.artwork){var pane=icon(Material.GREEN_STAINED_GLASS_PANE," ");for(int i=0;i<54;i++)s.inventory.setItem(i,pane);}return s;} private void button(Panel s,int slot,Material material,String title,String description,Runnable action){s.inventory.setItem(slot,icon(material,title,description));s.actions.put(slot,action);s.choices.add(new BedrockForms.Choice(title,description,action));} - private void show(Player p,Panel s){if(BedrockForms.isBedrock(p)){s.gate.expire();BedrockForms.show(plugin,p,s.title,s.description,s.choices);}else{if(Set.of("Exchange · Buy","Exchange · Your listings","Exchange · Kits").contains(s.title)&&NativeMenus.show(plugin,p,"development.fullscreen-exchange-viewers",s.title,s.description,s.inventory,s.actions,s.gate,DecisionsViewTransport.Style.EXCHANGE,null))return;if(MCGUIMenus.show(p,s.title,s.description,s.inventory,s.actions,s.gate))return;p.openInventory(s.inventory);Bukkit.getScheduler().runTaskLater(plugin,s.gate::expire,2400L);}} + private void show(Player p,Panel s){ + if(BedrockForms.isBedrock(p)){s.gate.expire();BedrockForms.show(plugin,p,s.title,s.description,s.choices);return;} + var style=switch(s.title){ + case "Exchange · Buy","Exchange · Your listings","Exchange · Kits" -> DecisionsViewTransport.Style.EXCHANGE; + case "Exchange · Purchase details" -> DecisionsViewTransport.Style.EXCHANGE_CHECKOUT; + default -> null; + }; + if(style!=null&&NativeMenus.show(plugin,p,"development.fullscreen-exchange-viewers",s.title,s.description,s.inventory,s.actions,s.gate,style,null))return; + if(MCGUIMenus.show(p,s.title,s.description,s.inventory,s.actions,s.gate))return; + p.openInventory(s.inventory); + Bukkit.getScheduler().runTaskLater(plugin,s.gate::expire,2400L); + } private void request(Player p,JsonObject input,Consumer success,Consumer failure){ UUID id=p.getUniqueId(),world=p.getWorld().getUID();if(pending.containsKey(id)){p.sendMessage("J.A.R.V.I.S. is processing your Exchange action.");return;}UUID token=UUID.randomUUID();pending.put(id,token);p.closeInventory(); Bukkit.getScheduler().runTaskAsynchronously(plugin,()->{JsonObject result=null;String error=null;try{result=bridge.exchange(id,input);}catch(Exception e){error=e.getMessage();}var response=result;String message=error;if(!plugin.isEnabled())return;Bukkit.getScheduler().runTask(plugin,()->{if(!token.equals(pending.get(id)))return;pending.remove(id);if(!p.isOnline()||!world.equals(p.getWorld().getUID()))return;if(response==null){failure.accept(message==null?"The Exchange is temporarily unavailable.":message);return;}if(response.has("rejectedStatus")){if(Set.of("buy","buy_kit").contains(input.get("action").getAsString()))retries.remove(id);failure.accept(response.has("message")?response.get("message").getAsString():"The Exchange rejected this action.");return;}success.accept(response);});}); diff --git a/website/tests/game-exchange-service.test.mjs b/website/tests/game-exchange-service.test.mjs index 43ac0216..9d4956c4 100644 --- a/website/tests/game-exchange-service.test.mjs +++ b/website/tests/game-exchange-service.test.mjs @@ -41,3 +41,17 @@ test('embargo applies before pagination and purchase but preserves owner withdra for(let id=2;id<145;id++)await f.db.query('INSERT INTO dunegameplay.dune_exchange_listings VALUES(?,?,?,?,?,?,?,?,?,?)',[id,f.users[1].uuid,'Seller','arrakis','ores','DIAMOND',1,'1.00',originPayload('caladan'),'Diamond']);await f.db.query('UPDATE dunegameplay.dune_exchange_listings SET payload=NULL WHERE id IN (1,2,3,4,5,6,7,8,9,10,11,12,13)');const page=await f.service.list(f.users[0],f.users[0].uuid);assert.equal(page.listings.length,12);assert.equal(page.hasNext,true);assert.equal((await f.service.list(f.users[0],f.users[0].uuid,{page:1})).listings.length,1); }finally{f.db.close();} }); +test('a checkout offer with a stale unit price or quantity moves no stock or funds',async()=>{ + const f=await fixture(); + try{ + const quoted=f.input({amount:2}); + await f.db.query("UPDATE dunegameplay.dune_exchange_listings SET price='22.01' WHERE id=1"); + await assert.rejects(f.service.buy(f.users[0],f.users[0].uuid,quoted),/price or available quantity changed/); + await f.db.query("UPDATE dunegameplay.dune_exchange_listings SET price='21.01',quantity=1 WHERE id=1"); + await assert.rejects(f.service.buy(f.users[0],f.users[0].uuid,quoted),/price or available quantity changed/); + assert.equal((await f.db.first('SELECT quantity FROM dunegameplay.dune_exchange_listings WHERE id=1')).quantity,1); + assert.equal((await f.db.first('SELECT balance_minor FROM pb_accounts WHERE id=?',[f.account(0)])).balance_minor,10000); + assert.equal((await f.db.first('SELECT balance_minor FROM pb_accounts WHERE id=?',[f.account(1)])).balance_minor,0); + assert.equal((await f.db.first('SELECT COUNT(*) n FROM dunegameplay.dune_exchange_deliveries')).n,0); + }finally{f.db.close();} +});