Compare commits

...
Sign in to create a new pull request.
Author SHA1 Message Date
unimatrixgit
130520ff1f Route legacy Towny plot writes through organisation keys
Some checks failed
Native Plot Command Policy Build / native-plot-command (push) Successful in 27s
DuneRealms Plugin CI / plugins (push) Failing after 2m3s
2026-12-02 12:38:18 +01:00
3 changed files with 46 additions and 1 deletions

View file

@ -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

View file

@ -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<String> ROOTS=Set.of("mf","f","faction","factions","power","t","town","towny","townyadmin","ta","n","nation");
private static final Set<String> 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;

View file

@ -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);
}
}