Add private RIA copy actions and prefilled voucher redemption
This commit is contained in:
parent
1309c4d338
commit
986bf4d57e
5 changed files with 129 additions and 2 deletions
47
.forgejo/workflows/atm-ria-copy.yml
Normal file
47
.forgejo/workflows/atm-ria-copy.yml
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
name: ATM RIA Copy and Sigma Goats
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches: ['fix/atm-ria-copy-*']
|
||||
jobs:
|
||||
atm-ria-copy:
|
||||
runs-on: dune-ci
|
||||
steps:
|
||||
- name: Check out exact revision
|
||||
shell: bash
|
||||
env:
|
||||
REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
git init .
|
||||
git -c http.extraheader="AUTHORIZATION: basic $(printf 'x-access-token:%s' "$REPO_TOKEN" | base64 -w0)" fetch --depth=1 https://www.dunerealms.com/git/unimatrix/plugins.git "$GITHUB_SHA"
|
||||
git checkout --detach FETCH_HEAD
|
||||
- uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: temurin
|
||||
java-version: '21'
|
||||
- uses: gradle/actions/setup-gradle@v4
|
||||
with:
|
||||
gradle-version: '9.2.1'
|
||||
- name: Test ATM controls and preserve Sigma ecology
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
gradle --no-daemon -p DuneMenus test jar
|
||||
gradle --no-daemon -p DuneTerrain test jar
|
||||
mkdir atm-ria-copy
|
||||
PYTHONPATH=tools python3 - <<'PY'
|
||||
from pathlib import Path
|
||||
from plugin_ria_copy import ATM, COPY
|
||||
from plugin_wild_update import read_archive, write_archive
|
||||
compiled=read_archive(Path('DuneMenus/build/libs/DuneMenus.jar').read_bytes())
|
||||
Path('atm-ria-copy/donor.zip').write_bytes(write_archive({p:compiled[p] for p in (ATM,COPY)}))
|
||||
PY
|
||||
cp tools/{plugin_ria_copy.py,plugin_wild_update.py,plugin_sigma_goats.py,SigmaGoatMerge.java} atm-ria-copy/
|
||||
printf '%s\n' "$GITHUB_SHA" > atm-ria-copy/SOURCE_COMMIT
|
||||
(cd atm-ria-copy && sha256sum -- *.zip *.py *.java SOURCE_COMMIT > SHA256SUMS)
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: DuneRealms-ATM-RIA-Copy-Sigma-Goats
|
||||
path: atm-ria-copy
|
||||
if-no-files-found: error
|
||||
|
|
@ -25,6 +25,7 @@ final class AtmMenu extends Menu {
|
|||
private String entered; // RIA ID typed on the Redeem tab
|
||||
private String receiptOperation,receiptReference,receiptMessage;
|
||||
private Long receiptAmount;
|
||||
private boolean receiptCanRedeem;
|
||||
|
||||
AtmMenu(DuneMenusPlugin plugin, Player p, Menu parent, Tab tab) { super(plugin, p, parent); this.tab = tab; }
|
||||
String id() { return switch(tab){case WITHDRAW->"withdraw";case DEPOSIT->"deposit";case REDEEM->"redeem";case RECEIPT->"receipt";default->"atm";}; }
|
||||
|
|
@ -67,7 +68,12 @@ final class AtmMenu extends Menu {
|
|||
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));
|
||||
String reference=RiaReference.normalize(receiptReference);
|
||||
if(reference!=null){
|
||||
referenceButton(reference);
|
||||
if(receiptCanRedeem)put(31,Ui.item(Material.ENDER_CHEST,"<aqua>Use this RIA ID",
|
||||
"<gray>Open its payout options","<gray>No need to type the reference"),c->{entered=reference;tab=Tab.REDEEM;redraw();});
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (tab == Tab.REDEEM) drawRedeem(); else drawCash();
|
||||
|
|
@ -106,7 +112,19 @@ final class AtmMenu extends Menu {
|
|||
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;
|
||||
receiptCanRedeem="Cash deposit".equals(operation)&&RiaReference.normalize(receiptReference)!=null;
|
||||
selected.clear();tab=Tab.RECEIPT;redraw();
|
||||
if(RiaReference.normalize(receiptReference)!=null)player.sendMessage(RiaClipboard.message(receiptReference));
|
||||
}
|
||||
|
||||
private void referenceButton(String reference){
|
||||
boolean bedrock=plugin.modeFor(player)==Mode.BEDROCK;
|
||||
put(29,Ui.item(Material.NAME_TAG,bedrock?"<gold>Show RIA ID in chat":"<gold>Copy RIA ID",
|
||||
"<white>"+reference,bedrock?"<gray>Send the reference privately to chat":"<gray>Open a private click-to-copy link"),c->{
|
||||
end();plugin.closeNativePresentation(player);
|
||||
if(!bedrock)player.sendMessage(net.kyori.adventure.text.Component.text("Press T, then click the RIA ID below to copy it."));
|
||||
player.sendMessage(RiaClipboard.message(reference));
|
||||
});
|
||||
}
|
||||
|
||||
private void drawRedeem() {
|
||||
|
|
@ -118,7 +136,7 @@ final class AtmMenu extends Menu {
|
|||
});
|
||||
for (int s : new int[]{28, 30}) put(s, Ui.pane(Material.YELLOW_STAINED_GLASS_PANE));
|
||||
if (entered == null) return;
|
||||
put(29,Ui.item(Material.NAME_TAG,"<gold>RIA ID","<white>"+entered));
|
||||
referenceButton(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; }
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
package com.dunerealms.menus;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
/** A private native-client copy action; never submits or redeems a voucher. */
|
||||
final class RiaClipboard {
|
||||
private RiaClipboard() {}
|
||||
|
||||
static Component message(String reference) {
|
||||
String complete=RiaReference.normalize(reference);
|
||||
if(complete==null)throw new IllegalArgumentException("A complete RIA reference is required");
|
||||
return Component.text("RIA ID: ",NamedTextColor.GOLD)
|
||||
.append(Component.text(complete,NamedTextColor.AQUA))
|
||||
.clickEvent(ClickEvent.copyToClipboard(complete))
|
||||
.hoverEvent(HoverEvent.showText(Component.text("Click to copy the complete RIA ID")));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package com.dunerealms.menus;
|
||||
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class RiaClipboardTest {
|
||||
@Test void copiesTheCompleteReferenceWithoutSubmittingAnyCommand(){
|
||||
String id="RIA-0123456789ABCDEF0123456789ABCDEF";
|
||||
var message=RiaClipboard.message(" "+id.toLowerCase(java.util.Locale.ROOT)+" ");
|
||||
assertEquals(ClickEvent.Action.COPY_TO_CLIPBOARD,message.clickEvent().action());
|
||||
assertEquals(id,message.clickEvent().value());
|
||||
assertTrue(PlainTextComponentSerializer.plainText().serialize(message).contains(id));
|
||||
}
|
||||
@Test void incompleteOrForeignReferencesCannotBecomeCopyActions(){
|
||||
for(String invalid:new String[]{null,"","RIA-1234","ITM-0123456789ABCDEF0123456789ABCDEF"})
|
||||
assertThrows(IllegalArgumentException.class,()->RiaClipboard.message(invalid));
|
||||
}
|
||||
}
|
||||
22
tools/plugin_ria_copy.py
Normal file
22
tools/plugin_ria_copy.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
"""Install the scoped ATM reference actions onto an exact retained menu archive."""
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
from plugin_wild_update import digest, read_archive, write_archive
|
||||
|
||||
ATM='com/dunerealms/menus/AtmMenu.class'
|
||||
COPY='com/dunerealms/menus/RiaClipboard.class'
|
||||
ATM_PREIMAGE='3139e7085a1779098e8651f4fc79b32ae67de58fe61a59155843c6e9bd93eb62'
|
||||
|
||||
def assemble(baseline,baseline_sha,donor,donor_sha,output):
|
||||
old=baseline.read_bytes();payload=donor.read_bytes()
|
||||
if digest(old)!=baseline_sha or digest(payload)!=donor_sha:raise ValueError('Unexpected archive checksum')
|
||||
retained=read_archive(old);compiled=read_archive(payload)
|
||||
if digest(retained[ATM])!=ATM_PREIMAGE:raise ValueError('Unexpected retained ATM implementation')
|
||||
if COPY in retained or set(compiled)!={ATM,COPY}:raise ValueError('Unexpected ATM overlay scope')
|
||||
retained.update(compiled)
|
||||
with output.open('xb') as stream:stream.write(write_archive(retained))
|
||||
|
||||
if __name__=='__main__':
|
||||
p=argparse.ArgumentParser(description=__doc__)
|
||||
p.add_argument('baseline',type=Path);p.add_argument('baseline_sha');p.add_argument('donor',type=Path);p.add_argument('donor_sha');p.add_argument('output',type=Path)
|
||||
assemble(**vars(p.parse_args()))
|
||||
Loading…
Reference in a new issue

Staff