From 130520ff1f041c0b684e105f027bbd7ffeaa0d90 Mon Sep 17 00:00:00 2001 From: unimatrixgit <95320811+unimatrixgit@users.noreply.github.com> Date: Wed, 2 Dec 2026 12:38:18 +0100 Subject: [PATCH] Route legacy Towny plot writes through organisation keys --- .forgejo/workflows/native-plot-command.yml | 40 +++++++++++++++++++ .../jarvis/NativeCommandPolicy.java | 3 +- .../jarvis/NativeCommandPolicyTest.java | 4 ++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 .forgejo/workflows/native-plot-command.yml diff --git a/.forgejo/workflows/native-plot-command.yml b/.forgejo/workflows/native-plot-command.yml new file mode 100644 index 00000000..e09a2729 --- /dev/null +++ b/.forgejo/workflows/native-plot-command.yml @@ -0,0 +1,40 @@ +name: Native Plot Command Policy Build +on: + workflow_dispatch: + push: + branches: ['fix/native-plot-command-policy-*'] + +jobs: + native-plot-command: + 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: Build the exact command policy class + shell: bash + run: | + set -euo pipefail + gradle --no-daemon -p JarvisConnector test --tests com.dunerealms.jarvis.NativeCommandPolicyTest + mkdir native-plot-command-artifacts + cp JarvisConnector/build/classes/java/main/com/dunerealms/jarvis/NativeCommandPolicy.class native-plot-command-artifacts/ + printf '%s\n' "$(git rev-parse HEAD)" > native-plot-command-artifacts/SOURCE_COMMIT + (cd native-plot-command-artifacts && sha256sum -- NativeCommandPolicy.class SOURCE_COMMIT > SHA256SUMS) + - uses: actions/upload-artifact@v3 + with: + name: DuneRealms-Native-Plot-Command-Policy + path: native-plot-command-artifacts/ + if-no-files-found: error diff --git a/JarvisConnector/src/main/java/com/dunerealms/jarvis/NativeCommandPolicy.java b/JarvisConnector/src/main/java/com/dunerealms/jarvis/NativeCommandPolicy.java index 13b79b46..b17318ac 100644 --- a/JarvisConnector/src/main/java/com/dunerealms/jarvis/NativeCommandPolicy.java +++ b/JarvisConnector/src/main/java/com/dunerealms/jarvis/NativeCommandPolicy.java @@ -2,11 +2,12 @@ package com.dunerealms.jarvis; import java.util.*; /** Native reads remain useful during testing. Mutations go through domain keys. */ final class NativeCommandPolicy { - private static final Set ROOTS=Set.of("mf","f","faction","factions","power","t","town","towny","townyadmin","ta","n","nation"); + private static final Set ROOTS=Set.of("mf","f","faction","factions","power","t","town","towny","townyadmin","ta","n","nation","plot"); static boolean blocked(String command){ String[] words=command.trim().toLowerCase(Locale.ROOT).replaceFirst("^/","").split("\\s+"); String root=words[0].substring(words[0].lastIndexOf(':')+1);if(!ROOTS.contains(root))return false; if(words.length==1||Set.of("info","list","members","who","help","here").contains(words[1]))return false; + if(root.equals("plot")&&words.length==2&&Set.of("?","perm").contains(words[1]))return false; if(Set.of("mf","f","faction","factions").contains(root)&&words[1].equals("power")&&words.length==2)return false; // Unknown aliases cannot reopen claim or authority writes behind the GUI. return true; diff --git a/JarvisConnector/src/test/java/com/dunerealms/jarvis/NativeCommandPolicyTest.java b/JarvisConnector/src/test/java/com/dunerealms/jarvis/NativeCommandPolicyTest.java index f42af341..cb70d6a8 100644 --- a/JarvisConnector/src/test/java/com/dunerealms/jarvis/NativeCommandPolicyTest.java +++ b/JarvisConnector/src/test/java/com/dunerealms/jarvis/NativeCommandPolicyTest.java @@ -6,4 +6,8 @@ class NativeCommandPolicyTest { for(String command:new String[]{"/mf claim","/medievalfactions:faction sethome","/f declarewar URT","/power setfixed player 100","/mf power setfixed player 100","/medievalfactions:mf power set player 100","/t new Example","/towny:town set homeblock","/nation set spawn","/ta town Test claim"})assertTrue(NativeCommandPolicy.blocked(command),command); for(String command:new String[]{"/mf info URT","/mf info HOME","/mf power","/f list","/town list","/nation info","/clan","/minecraft:me claim"})assertFalse(NativeCommandPolicy.blocked(command),command); } + @Test void legacyPlotWritesUseTheOrganisationKeyFlow(){ + for(String command:new String[]{"/plot claim","/towny:plot group add Example","/PLOT clear","/plot perm reset","/plot trust Player","/plot toggle pvp"})assertTrue(NativeCommandPolicy.blocked(command),command); + for(String command:new String[]{"/plot","/plot ?","/plot info","/plot list","/towny:plot perm","/plot help"})assertFalse(NativeCommandPolicy.blocked(command),command); + } }