Compare commits
17 changed files with 8 additions and 444 deletions
|
|
@ -1,47 +0,0 @@
|
|||
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
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
name: Home Dimension Return Overlay
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches: ['fix/home-dimension-return-*']
|
||||
|
||||
jobs:
|
||||
home-dimension:
|
||||
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 DuneEss and extract the dimension route class
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
gradle --no-daemon -p DuneEss test jar
|
||||
mkdir home-dimension
|
||||
PYTHONPATH=tools python3 - <<'PY'
|
||||
from pathlib import Path
|
||||
from plugin_home_dimension import ROUTES
|
||||
from plugin_wild_update import read_archive, write_archive
|
||||
source = read_archive(Path("DuneEss/build/libs/DuneRealms-Essentials.jar").read_bytes())
|
||||
Path("home-dimension/donor.zip").write_bytes(write_archive({ROUTES: source[ROUTES]}))
|
||||
PY
|
||||
cp tools/{HomeDimensionOverlay.java,plugin_home_dimension.py,plugin_wild_update.py} home-dimension/
|
||||
printf '%s\n' "$GITHUB_SHA" > home-dimension/SOURCE_COMMIT
|
||||
(cd home-dimension && sha256sum -- *.zip *.py *.java SOURCE_COMMIT > SHA256SUMS)
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: DuneRealms-Home-Dimension-Return
|
||||
path: home-dimension
|
||||
if-no-files-found: error
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
package com.example.duneess;
|
||||
|
||||
import java.util.Set;
|
||||
import org.bukkit.World;
|
||||
|
||||
/** Dimension returns on one backend, preserving the Guild boundary between planets. */
|
||||
final class HomeDimensionRoutes {
|
||||
private static final Set<String> MAIN_WORLDS = Set.of(
|
||||
"arrakis", "caladan", "giedi_prime", "kaitain", "sigma_draconis_iv", "lobby_base");
|
||||
|
||||
private HomeDimensionRoutes() {}
|
||||
|
||||
static boolean canReturn(World source, Object destination) {
|
||||
if (source == null || !(destination instanceof World target)) return false;
|
||||
if (source.equals(target)) return true;
|
||||
String main = target.getName();
|
||||
if (target.getEnvironment() != World.Environment.NORMAL || !MAIN_WORLDS.contains(main)) return false;
|
||||
return source.getEnvironment() == World.Environment.NETHER && source.getName().equals(main + "_nether")
|
||||
|| source.getEnvironment() == World.Environment.THE_END && source.getName().equals(main + "_the_end");
|
||||
}
|
||||
}
|
||||
|
|
@ -50,7 +50,7 @@ final class PersonalHomeTravel implements Listener {
|
|||
private void begin(Player p,Location destination,String mode){
|
||||
boolean rescue=mode.equals("rescue");
|
||||
if(!valid(destination)){p.sendMessage("That saved home is unavailable or outside the world's playable bounds.");return;}
|
||||
if(rescue?!p.getWorld().equals(destination.getWorld()):!HomeDimensionRoutes.canReturn(p.getWorld(),destination.getWorld())){p.sendMessage("Travel to that world through the Guild first, then use /home.");return;}
|
||||
if(!p.getWorld().equals(destination.getWorld())){p.sendMessage("Travel to that world through the Guild first, then use /home.");return;}
|
||||
String id=p.getUniqueId().toString();if(waiting.containsKey(p.getUniqueId())||journal.contains(id)){p.sendMessage("Your home journey is already being completed.");return;}
|
||||
var connector=Bukkit.getPluginManager().getPlugin("JarvisTranslator");if(connector==null||!connector.isEnabled()){p.sendMessage("Central home travel is unavailable. No payment was made.");return;}
|
||||
UUID token=UUID.randomUUID(),world=p.getWorld().getUID();waiting.put(p.getUniqueId(),token);Location target=destination.clone();
|
||||
|
|
@ -91,7 +91,7 @@ final class PersonalHomeTravel implements Listener {
|
|||
if(!state.equals("pending")){journal.set(id,null);persist();return;}
|
||||
if(!stage.equals("reserve"))return;
|
||||
Player current=Bukkit.getPlayer(UUID.fromString(id));Location target=journal.getLocation(id+".destination");
|
||||
if(current==null||!current.isOnline()||current.isDead()||!valid(target)||(rescue?!safe(target)||!current.getWorld().equals(target.getWorld()):!HomeDimensionRoutes.canReturn(current.getWorld(),target.getWorld()))){stage(id,"cancel");return;}
|
||||
if(current==null||!current.isOnline()||current.isDead()||!valid(target)||rescue&&!safe(target)||!current.getWorld().equals(target.getWorld())){stage(id,"cancel");return;}
|
||||
// Keep the busy latch until the actual native result. Crash recovery re-delivers the same destination.
|
||||
current.teleportAsync(target).whenComplete((success,failure)->Bukkit.getScheduler().runTask(plugin,()->{
|
||||
boolean arrived=Boolean.TRUE.equals(success)&&failure==null;
|
||||
|
|
|
|||
|
|
@ -1,34 +0,0 @@
|
|||
package com.example.duneess;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
class HomeDimensionRoutesTest {
|
||||
@Test void onlyReturnsToTheOwningMainWorld() {
|
||||
var sigma = world("sigma_draconis_iv", World.Environment.NORMAL);
|
||||
var end = world("sigma_draconis_iv_the_end", World.Environment.THE_END);
|
||||
var giedi = world("giedi_prime", World.Environment.NORMAL);
|
||||
var nether = world("giedi_prime_nether", World.Environment.NETHER);
|
||||
var build = world("lobby_arrakis", World.Environment.NORMAL);
|
||||
assertTrue(HomeDimensionRoutes.canReturn(end, sigma));
|
||||
assertTrue(HomeDimensionRoutes.canReturn(nether, giedi));
|
||||
assertTrue(HomeDimensionRoutes.canReturn(giedi, giedi));
|
||||
assertFalse(HomeDimensionRoutes.canReturn(end, giedi));
|
||||
assertFalse(HomeDimensionRoutes.canReturn(nether, sigma));
|
||||
assertFalse(HomeDimensionRoutes.canReturn(sigma, end));
|
||||
assertFalse(HomeDimensionRoutes.canReturn(end, nether));
|
||||
assertFalse(HomeDimensionRoutes.canReturn(build, sigma));
|
||||
assertFalse(HomeDimensionRoutes.canReturn(end, null));
|
||||
assertFalse(HomeDimensionRoutes.canReturn(world("sigma_draconis_iv_the_end", World.Environment.CUSTOM), sigma));
|
||||
}
|
||||
|
||||
private static World world(String name, World.Environment environment) {
|
||||
var world = mock(World.class);
|
||||
when(world.getName()).thenReturn(name);
|
||||
when(world.getEnvironment()).thenReturn(environment);
|
||||
return world;
|
||||
}
|
||||
}
|
||||
|
|
@ -25,7 +25,6 @@ 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";}; }
|
||||
|
|
@ -68,12 +67,7 @@ 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));
|
||||
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();});
|
||||
}
|
||||
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();
|
||||
|
|
@ -112,19 +106,7 @@ 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() {
|
||||
|
|
@ -136,7 +118,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;
|
||||
referenceButton(entered);
|
||||
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; }
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
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")));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
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));
|
||||
}
|
||||
}
|
||||
|
|
@ -74,14 +74,7 @@
|
|||
"spawners": {
|
||||
"ambient": [],
|
||||
"axolotls": [],
|
||||
"creature": [
|
||||
{
|
||||
"type": "minecraft:goat",
|
||||
"weight": 5,
|
||||
"minCount": 1,
|
||||
"maxCount": 3
|
||||
}
|
||||
],
|
||||
"creature": [],
|
||||
"misc": [],
|
||||
"monster": [
|
||||
{
|
||||
|
|
|
|||
|
|
@ -74,14 +74,7 @@
|
|||
"spawners": {
|
||||
"ambient": [],
|
||||
"axolotls": [],
|
||||
"creature": [
|
||||
{
|
||||
"type": "minecraft:goat",
|
||||
"weight": 5,
|
||||
"minCount": 1,
|
||||
"maxCount": 3
|
||||
}
|
||||
],
|
||||
"creature": [],
|
||||
"misc": [],
|
||||
"monster": [
|
||||
{
|
||||
|
|
|
|||
|
|
@ -74,14 +74,7 @@
|
|||
"spawners": {
|
||||
"ambient": [],
|
||||
"axolotls": [],
|
||||
"creature": [
|
||||
{
|
||||
"type": "minecraft:goat",
|
||||
"weight": 5,
|
||||
"minCount": 1,
|
||||
"maxCount": 3
|
||||
}
|
||||
],
|
||||
"creature": [],
|
||||
"misc": [],
|
||||
"monster": [
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import org.bukkit.plugin.Plugin;
|
|||
public final class PlanetMobs implements Listener {
|
||||
private static final Set<String> NETHER=Set.of("BLAZE","GHAST","HOGLIN","MAGMA_CUBE","PIGLIN","PIGLIN_BRUTE","STRIDER","WITHER_SKELETON","ZOGLIN","ZOMBIFIED_PIGLIN","SKELETON","ENDERMAN");
|
||||
private static final Set<String> PASSIVE=Set.of("ALLAY","ARMADILLO","AXOLOTL","BAT","CAMEL","CAT","CHICKEN","COD","COW","DONKEY","FROG","GLOW_SQUID","HORSE","MUSHROOM_COW","MOOSHROOM","MULE","OCELOT","PARROT","PIG","PUFFERFISH","RABBIT","SALMON","SHEEP","SNIFFER","SNOWMAN","SNOW_GOLEM","SQUID","STRIDER","TADPOLE","TROPICAL_FISH","TURTLE","VILLAGER","WANDERING_TRADER");
|
||||
public static boolean allowed(String planet,String mob,boolean island){if("sigma_draconis_iv".equals(planet)&&"GOAT".equals(mob)||allowedColdPig(planet,mob))return true;return switch(planet){case "caladan"->!mob.equals("CREEPER");case "kaitain"->PASSIVE.contains(mob);case "giedi_prime"->NETHER.contains(mob);case "sigma_draconis_iv"->Set.of("SKELETON","STRAY","WITHER_SKELETON","BOGGED").contains(mob)||island&&Set.of("MUSHROOM_COW","MOOSHROOM","SULFUR_CUBE").contains(mob);default->true;};}
|
||||
public static boolean allowed(String planet,String mob,boolean island){if(allowedColdPig(planet,mob))return true;return switch(planet){case "caladan"->!mob.equals("CREEPER");case "kaitain"->PASSIVE.contains(mob);case "giedi_prime"->NETHER.contains(mob);case "sigma_draconis_iv"->Set.of("SKELETON","STRAY","WITHER_SKELETON","BOGGED").contains(mob)||island&&Set.of("MUSHROOM_COW","MOOSHROOM","SULFUR_CUBE").contains(mob);default->true;};}
|
||||
public static boolean allowedSpawn(String planet,String mob,boolean island,String reason){return allowed(planet,mob,island)||planet.equals("giedi_prime")&&(reason.equals("SPAWNER")&&Set.of("SKELETON","ZOMBIE","SPIDER","CAVE_SPIDER").contains(mob)||mob.equals("WARDEN"));}
|
||||
public static void start(Plugin plugin){Bukkit.getPluginManager().registerEvents(new PlanetMobs(),plugin);Bukkit.getPluginManager().registerEvents(new NativePlants(),plugin);PlanetSoil.start(plugin);}
|
||||
@EventHandler(priority=EventPriority.HIGHEST,ignoreCancelled=true) public void spawning(CreatureSpawnEvent event){if(sigmaColdPig(event))return;var e=event.getEntity();String planet=e.getWorld().getName();if(!TemperateLandscape.enabled(planet))return;
|
||||
|
|
|
|||
|
|
@ -1,44 +0,0 @@
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.MethodInsnNode;
|
||||
|
||||
final class HomeDimensionOverlay implements Opcodes {
|
||||
private static final String TRAVEL = "com/example/duneess/PersonalHomeTravel";
|
||||
private static final String ROUTES = "com/example/duneess/HomeDimensionRoutes";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
if (args.length != 2) throw new IllegalArgumentException("Expected retained and output class");
|
||||
var old = new ClassReader(Files.readAllBytes(Path.of(args[0])));
|
||||
var retained = new ClassNode();
|
||||
old.accept(retained, 0);
|
||||
if (!retained.name.equals(TRAVEL)) throw new IllegalArgumentException("Unexpected retained travel class");
|
||||
|
||||
replace(retained, "begin", "(Lorg/bukkit/entity/Player;Lorg/bukkit/Location;)V");
|
||||
replace(retained, "lambda$attempt$3",
|
||||
"(Lcom/google/gson/JsonObject;Ljava/lang/String;Lorg/bukkit/entity/Player;Ljava/lang/String;)V");
|
||||
|
||||
var writer = new ClassWriter(old, 0);
|
||||
retained.accept(writer);
|
||||
Files.write(Path.of(args[1]), writer.toByteArray());
|
||||
}
|
||||
|
||||
private static void replace(ClassNode retained, String name, String descriptor) {
|
||||
var method = retained.methods.stream().filter(m -> m.name.equals(name) && m.desc.equals(descriptor))
|
||||
.findFirst().orElseThrow();
|
||||
int patched = 0;
|
||||
for (var instruction : method.instructions.toArray()) {
|
||||
if (instruction instanceof MethodInsnNode call && call.getOpcode() == INVOKEINTERFACE
|
||||
&& call.owner.equals("org/bukkit/World") && call.name.equals("equals")
|
||||
&& call.desc.equals("(Ljava/lang/Object;)Z")) {
|
||||
method.instructions.set(call, new MethodInsnNode(INVOKESTATIC, ROUTES, "canReturn",
|
||||
"(Lorg/bukkit/World;Ljava/lang/Object;)Z", false));
|
||||
patched++;
|
||||
}
|
||||
}
|
||||
if (patched != 1) throw new IllegalArgumentException("Expected one retained world predicate: " + name);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.tree.*;
|
||||
|
||||
class SigmaGoatMerge {
|
||||
public static void main(String[] args) throws Exception {
|
||||
var reader = new ClassReader(Files.readAllBytes(Path.of(args[0])));
|
||||
var retained = new ClassNode();
|
||||
reader.accept(retained, 0);
|
||||
if (!retained.name.equals("com/example/duneterrain/PlanetMobs")
|
||||
|| retained.methods.stream().noneMatch(m -> m.name.equals("allowedColdPig"))) {
|
||||
throw new IllegalArgumentException("Expected the retained Sigma cold-pig baseline");
|
||||
}
|
||||
var allowed = retained.methods.stream()
|
||||
.filter(m -> m.name.equals("allowed") && m.desc.equals("(Ljava/lang/String;Ljava/lang/String;Z)Z"))
|
||||
.findFirst().orElseThrow();
|
||||
var resume = new LabelNode();
|
||||
var patch = new InsnList();
|
||||
match(patch, "sigma_draconis_iv", 0, resume);
|
||||
match(patch, "GOAT", 1, resume);
|
||||
patch.add(new InsnNode(Opcodes.ICONST_1));
|
||||
patch.add(new InsnNode(Opcodes.IRETURN));
|
||||
patch.add(resume);
|
||||
patch.add(new FrameNode(Opcodes.F_SAME, 0, null, 0, null));
|
||||
allowed.instructions.insert(patch);
|
||||
var writer = new ClassWriter(reader, 0);
|
||||
retained.accept(writer);
|
||||
Files.write(Path.of(args[1]), writer.toByteArray());
|
||||
}
|
||||
|
||||
private static void match(InsnList patch, String value, int local, LabelNode resume) {
|
||||
patch.add(new LdcInsnNode(value));
|
||||
patch.add(new VarInsnNode(Opcodes.ALOAD, local));
|
||||
patch.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false));
|
||||
patch.add(new JumpInsnNode(Opcodes.IFEQ, resume));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
"""Permit a local return from a native dimension without replacing the home payment journal."""
|
||||
import argparse
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
from tempfile import TemporaryDirectory
|
||||
|
||||
from plugin_wild_update import digest, read_archive, write_archive
|
||||
|
||||
TRAVEL = "com/example/duneess/PersonalHomeTravel.class"
|
||||
ROUTES = "com/example/duneess/HomeDimensionRoutes.class"
|
||||
TRAVEL_BASELINES = {
|
||||
"7fde0b6b5aba9e6755292a88b8157780e212708aadc5fe62de084f599234587d",
|
||||
"dee4b89e17c254e28254c5dfe88fbcf9f5c284a6a21332f0e7ab121d8c882afc",
|
||||
}
|
||||
|
||||
|
||||
def assemble(baseline, baseline_sha, donor, donor_sha, output, classpath):
|
||||
existing = baseline.read_bytes()
|
||||
compiled = donor.read_bytes()
|
||||
if digest(existing) != baseline_sha or digest(compiled) != donor_sha:
|
||||
raise ValueError("Unexpected baseline or donor checksum")
|
||||
retained = read_archive(existing)
|
||||
source = read_archive(compiled)
|
||||
if set(source) != {ROUTES} or ROUTES in retained or digest(retained[TRAVEL]) not in TRAVEL_BASELINES:
|
||||
raise ValueError("Unexpected home travel class scope")
|
||||
java_home = os.environ.get("JAVA_HOME")
|
||||
executable = "java.exe" if os.name == "nt" else "java"
|
||||
java = str(Path(java_home) / "bin" / executable) if java_home else executable
|
||||
helper = Path(__file__).with_name("HomeDimensionOverlay.java")
|
||||
with TemporaryDirectory() as temporary:
|
||||
root = Path(temporary)
|
||||
old, merged = root / "retained.class", root / "merged.class"
|
||||
old.write_bytes(retained[TRAVEL])
|
||||
subprocess.run([java, "--class-path", classpath, str(helper), str(old), str(merged)], check=True)
|
||||
retained[TRAVEL] = merged.read_bytes()
|
||||
retained[ROUTES] = source[ROUTES]
|
||||
with output.open("xb") as candidate:
|
||||
candidate.write(write_archive(retained))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("baseline", type=Path)
|
||||
parser.add_argument("baseline_sha")
|
||||
parser.add_argument("donor", type=Path)
|
||||
parser.add_argument("donor_sha")
|
||||
parser.add_argument("output", type=Path)
|
||||
parser.add_argument("classpath", help="ASM core and tree JARs")
|
||||
assemble(**vars(parser.parse_args()))
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
"""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()))
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
"""Build Sigma goat overlays from explicitly pinned live archives."""
|
||||
import argparse
|
||||
import json
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
from tempfile import TemporaryDirectory
|
||||
|
||||
from plugin_wild_update import digest, read_archive, write_archive
|
||||
|
||||
CLASS = "com/example/duneterrain/PlanetMobs.class"
|
||||
BIOMES = ("snowy_slopes", "frozen_peaks", "jagged_peaks")
|
||||
|
||||
|
||||
def read_pinned(path, sha):
|
||||
payload = path.read_bytes()
|
||||
if digest(payload) != sha:
|
||||
raise ValueError(f"Unexpected baseline: {path.name}")
|
||||
return read_archive(payload)
|
||||
|
||||
|
||||
def assemble(terrain, terrain_sha, biomes, biomes_sha, output, classpath):
|
||||
existing = read_pinned(terrain, terrain_sha)
|
||||
pack = read_pinned(biomes, biomes_sha)
|
||||
for biome in BIOMES:
|
||||
path = f"data/minecraft/worldgen/biome/{biome}.json"
|
||||
data = json.loads(pack[path])
|
||||
creatures = data["spawners"]["creature"]
|
||||
if any(spawner["type"] == "minecraft:goat" for spawner in creatures):
|
||||
raise ValueError(f"Goats already registered: {biome}")
|
||||
creatures.append({"type": "minecraft:goat", "weight": 5, "minCount": 1, "maxCount": 3})
|
||||
pack[path] = (json.dumps(data, ensure_ascii=False, indent=2) + "\n").encode()
|
||||
with TemporaryDirectory() as temporary:
|
||||
retained = Path(temporary) / "retained.class"
|
||||
changed = Path(temporary) / "changed.class"
|
||||
retained.write_bytes(existing[CLASS])
|
||||
helper = Path(__file__).with_name("SigmaGoatMerge.java")
|
||||
subprocess.run(["java", "--class-path", classpath, str(helper), str(retained), str(changed)], check=True)
|
||||
existing[CLASS] = changed.read_bytes()
|
||||
output.mkdir()
|
||||
(output / terrain.name).write_bytes(write_archive(existing))
|
||||
(output / biomes.name).write_bytes(write_archive(pack))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("terrain", type=Path)
|
||||
parser.add_argument("terrain_sha")
|
||||
parser.add_argument("biomes", type=Path)
|
||||
parser.add_argument("biomes_sha")
|
||||
parser.add_argument("output", type=Path)
|
||||
parser.add_argument("classpath", help="ASM core and tree JARs")
|
||||
assemble(**vars(parser.parse_args()))
|
||||
Loading…
Reference in a new issue

Staff