Merge commit '5bb36a4eb2' into fix/woodcutter-origin-20261204
Some checks failed
DuneRealms Plugin CI / plugins (push) Has been cancelled

This commit is contained in:
unimatrixgit 2026-12-04 20:48:05 +01:00
commit 1a1f6c8d09
8 changed files with 276 additions and 12 deletions

View file

@ -0,0 +1,54 @@
name: Guild and Cookbook Overlay
on:
workflow_dispatch:
push:
branches: ['fix/guild-navigator-*']
jobs:
guild-cookbook:
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 and package exact overlay donors
shell: bash
run: |
set -euo pipefail
for module in DuneRealmsGUI DuneNPC DuneLobby; do
gradle --no-daemon -p "$module" test jar
done
mkdir guild-cookbook
PYTHONPATH=tools python3 - <<'PY'
from pathlib import Path
from plugin_guild_cookbook import CLASSES
from plugin_wild_update import read_archive, write_archive
for module, jar in (
("gui", "DuneRealmsGUI/build/libs/DunerealmsGUI.jar"),
("npc", "DuneNPC/build/libs/DuneRealms-NPC.jar"),
("lobby", "DuneLobby/build/libs/DuneRealms-Lobby.jar"),
):
entries = read_archive(Path(jar).read_bytes())
Path(f"guild-cookbook/{module}.zip").write_bytes(write_archive({entry: entries[entry] for entry in CLASSES[module]}))
PY
cp tools/{GuildCookbookMerge.java,plugin_guild_cookbook.py,plugin_wild_update.py} guild-cookbook/
printf '%s\n' "$GITHUB_SHA" > guild-cookbook/SOURCE_COMMIT
(cd guild-cookbook && sha256sum -- *.zip *.py *.java SOURCE_COMMIT > SHA256SUMS)
- uses: actions/upload-artifact@v3
with:
name: DuneRealms-Guild-Cookbook
path: guild-cookbook
if-no-files-found: error

View file

@ -175,7 +175,11 @@ public final class DuneLobby extends JavaPlugin implements Listener, CommandExec
String role=e.getRightClicked().getPersistentDataContainer().get(roleKey,PersistentDataType.STRING);
if(role==null) return; e.setCancelled(true); if(e.getHand()!=EquipmentSlot.HAND) return;
switch(role) {
case "liaison" -> { if(Bukkit.getPluginCommand("duneess")!=null) e.getPlayer().performCommand("duneess travel"); else departure(e.getPlayer(),"arrakis"); }
case "liaison" -> {
if (!e.getPlayer().performCommand("dunerealmsgui:guildtravel")) {
e.getPlayer().sendMessage("The Spacing Guild menu is unavailable.");
}
}
case "exchange" -> { if(Bukkit.getPluginCommand("dune")!=null) e.getPlayer().performCommand("dune exchange"); else e.getPlayer().sendMessage(ChatColor.GOLD+"Koopkring market integration requires DuneCore on this backend."); }
case "water","spice" -> trade(e.getPlayer(),role);
}

View file

@ -99,7 +99,10 @@ public final class DuneNPC extends JavaPlugin implements Listener, CommandExecut
@EventHandler public void navigator(PlayerInteractEntityEvent event) {
if (!event.getRightClicked().getPersistentDataContainer().has(guildKey, PersistentDataType.BYTE)) return;
event.setCancelled(true);
if (event.getHand() == EquipmentSlot.HAND) Bukkit.dispatchCommand(event.getPlayer(), "duneess travel");
if (event.getHand() != EquipmentSlot.HAND) return;
if (!event.getPlayer().performCommand("dunerealmsgui:guildtravel")) {
event.getPlayer().sendMessage("The Spacing Guild menu is unavailable.");
}
}
@Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player player)) { sender.sendMessage("Run this command in-game."); return true; }

View file

@ -7,13 +7,19 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.plugin.java.JavaPlugin;
final class CookbookCatalog {
private static final List<String> ROMAN = List.of("0", "I", "II", "III", "IV", "V");
record Recipe(String id, String name, Material material, int mark, String quality, String ingredients, String details) {
String grade() { return quality + " · MK " + ROMAN.get(mark); }
NamespacedKey key() {
if (id.equals("spice_tender")) return new NamespacedKey("minecarttrains", "fuel_cart");
if (id.equals("spice_coal")) return new NamespacedKey("dunerealms", id);
return new NamespacedKey("dunerealms", "spice_cooker_" + material.name().toLowerCase(Locale.ROOT));
}
String grade() { return quality + " · MK " + ROMAN.get(mark); }
}
private CookbookCatalog() {}

View file

@ -131,7 +131,27 @@ public final class DuneGUI extends JavaPlugin implements Listener,CommandExecuto
var data=item.getItemMeta().getPersistentDataContainer();for(var key:data.getKeys())if(data.has(key,PersistentDataType.STRING)&&"menu_opener".equals(data.get(key,PersistentDataType.STRING))){inventory.setItem(slot,null);break;}
}
}
private void openGuild(Player p,String requested){if(!lobby(p)){try{bridge.returnGuild(p);}catch(Exception unavailable){p.sendMessage("The Guild could not confirm your return. Please retry.");}return;}fetch(p,null,0,null,data->{String house=selection(data);if(house==null){p.sendMessage("Choose and confirm your House before Guild passage.");select(p,data,null);return;}travelMenu(p,data);});}
private void openGuild(Player p,String requested){if(!lobby(p)){guildReturnMenu(p);return;}fetch(p,null,0,null,data->{String house=selection(data);if(house==null){p.sendMessage("Choose and confirm your House before Guild passage.");select(p,data,null);return;}travelMenu(p,data);});}
private void guildReturnMenu(Player player){
String title="Spacing Guild · Return passage";
String detail="Return to the Guild Lobby to book onward passage.";
Runnable returnToLobby=()->{
player.closeInventory();
try{bridge.returnGuild(player);}
catch(Exception failure){player.sendMessage("The Guild could not confirm your return. Please retry.");}
};
if(BedrockForms.isBedrock(player)){
BedrockForms.show(this,player,title,detail,List.of(new BedrockForms.Choice("Return to Guild Lobby",detail,returnToLobby)));
return;
}
Screen panel=new Screen(player);
panel.inventory=Bukkit.createInventory(panel,54,Component.text(title,NamedTextColor.GOLD));
panel.inventory.setItem(22,icon(player,"Return to Guild Lobby",detail,"drgui_transparent",Material.COMPASS));
panel.actions.put(22,returnToLobby);
if(MCGUIMenus.show(player,title,detail,panel.inventory,panel.actions,panel.gate))return;
player.openInventory(panel.inventory);
expire(panel);
}
private static GuildBookings.Permit permit(JsonObject data){String house=selection(data);if(house==null||!data.has("keyId")||data.get("keyId").isJsonNull())return null;try{return new GuildBookings.Permit(house,UUID.fromString(data.get("keyId").getAsString()),data.get("version").getAsInt());}catch(RuntimeException invalid){return null;}}
private void travelMenu(Player p,JsonObject data){var q=new JsonObject();q.addProperty("action","quote");guildRequest(p,q,quote->{data.add("guildQuote",quote);renderTravelMenu(p,data);});}
private void guildRequest(Player p,JsonObject input,Consumer<JsonObject> done){UUID id=p.getUniqueId(),world=p.getWorld().getUID();if(!boarding.add(id)){p.sendMessage("J.A.R.V.I.S. is processing your passage.");return;}Bukkit.getScheduler().runTaskAsynchronously(this,()->{JsonObject result=null;String failure=null;try{result=bridge.guild(id,input);}catch(Exception e){failure=e.getMessage();}var response=result;String message=failure;if(!isEnabled())return;Bukkit.getScheduler().runTask(this,()->{if(!boarding.remove(id)||!p.isOnline()||!p.getWorld().getUID().equals(world))return;if(response==null){p.sendMessage(message==null?"The central Guild service is unavailable.":message);return;}done.accept(response);});});}

View file

@ -67,14 +67,57 @@ final class OrganisationMenus implements Listener {
}
private void cookbookRecipe(Player player,CookbookCatalog.Recipe recipe){
var panel=panel(player,"Cookbook · "+recipe.name(),false);
panel.description=recipe.grade()+"\n"+recipe.ingredients()+"\n"+recipe.details();
put(panel,22,recipe.name(),panel.description,recipe.material(),null);
var icon=panel.inventory.getItem(22);
var meta=icon.getItemMeta();
meta.setItemModel(new NamespacedKey("dunerealms","crafting/"+recipe.id()));
icon.setItemMeta(meta);
panel.inventory.setItem(22,icon);
put(panel,45,"Back","Cookbook",Material.ARROW,()->cookbook(player));close(panel,player);show(player,panel);
var nativeRecipe=Bukkit.getRecipe(recipe.key());
if(nativeRecipe instanceof org.bukkit.inventory.ShapedRecipe shaped){
var shape=shaped.getShape();
var ingredients=shaped.getChoiceMap();
for(int row=0;row<shape.length;row++){
for(int col=0;col<shape[row].length();col++){
var choice=ingredients.get(shape[row].charAt(col));
if(choice!=null)recipeIngredient(panel,10+row*9+col,recipe,choice);
}
}
}else if(nativeRecipe instanceof org.bukkit.inventory.ShapelessRecipe shapeless){
var ingredients=shapeless.getChoiceList();
for(int i=0;i<ingredients.size();i++)recipeIngredient(panel,10+i/3*9+i%3,recipe,ingredients.get(i));
}else{
put(panel,22,"Recipe unavailable","This server has not registered this recipe.",Material.BARRIER,null);
}
if(nativeRecipe!=null){
put(panel,23,"Produces",recipe.details(),Material.ARROW,null);
put(panel,25,recipe.name(),recipe.grade()+" · "+nativeRecipe.getResult().getAmount()+" per craft",recipe.material(),null);
var icon=panel.inventory.getItem(25);
var meta=icon.getItemMeta();
meta.setItemModel(new NamespacedKey("dunerealms","crafting/"+recipe.id()));
icon.setItemMeta(meta);
icon.setAmount(nativeRecipe.getResult().getAmount());
panel.inventory.setItem(25,icon);
}
put(panel,45,"Back","Cookbook",Material.ARROW,()->cookbook(player));close(panel,player);
// Keep the native row and column positions, including repeated ingredients.
player.openInventory(panel.inventory);
Bukkit.getScheduler().runTaskLater(plugin,panel.gate::expire,2400L);
}
private void recipeIngredient(Panel panel,int slot,CookbookCatalog.Recipe recipe,org.bukkit.inventory.RecipeChoice choice){
Material material=choice.getItemStack().getType();
String name=material.name().replace('_',' ').toLowerCase(Locale.ROOT);
String detail="1 per slot";
if(material==Material.ORANGE_DYE){
name="Raw Melange Spice";
detail="Use genuine raw Melange Spice.";
}else if(material==Material.COAL&&recipe.id().equals("spice_tender")){
name="Spice Coal";
}else if(choice instanceof org.bukkit.inventory.RecipeChoice.MaterialChoice alternatives&&alternatives.getChoices().contains(Material.CHARCOAL)){
name="Coal or Charcoal";
}
put(panel,slot,name,detail,material,null);
if(name.equals("Spice Coal")){
var icon=panel.inventory.getItem(slot);
var meta=icon.getItemMeta();
meta.setItemModel(new NamespacedKey("dunerealms","crafting/spice_coal"));
icon.setItemMeta(meta);
panel.inventory.setItem(slot,icon);
}
}
private void start(Player p,JsonObject data){
var panel=panel(p,"Your organisations",false);put(panel,19,"Clan","Your clan and Home Block",Material.GREEN_BANNER,()->choose(p,data,"clans"));put(panel,22,"Company","Your companies and Home Blocks",Material.CYAN_BANNER,()->choose(p,data,"companies"));put(panel,25,"POL","Your current political offices",Material.PURPLE_BANNER,()->choose(p,data,"offices"));close(panel,p);show(p,panel);

View file

@ -0,0 +1,81 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Handle;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.InvokeDynamicInsnNode;
import org.objectweb.asm.tree.MethodNode;
class GuildCookbookMerge {
private static final String GUI = "com/dunerealms/gui/";
private static final Map<String, Set<String>> TARGETS = Map.of(
GUI + "DuneGUI", Set.of("openGuild", "guildReturnMenu"),
GUI + "OrganisationMenus", Set.of("cookbookRecipe", "recipeIngredient"),
GUI + "CookbookCatalog$Recipe", Set.of("key"),
"com/example/dunelobby/DuneLobby", Set.of("entityInteract"),
"com/example/dunenpc/DuneNPC", Set.of("navigator"));
public static void main(String[] args) throws Exception {
if (args.length != 3) throw new IllegalArgumentException("Expected retained, donor and output classes");
var retainedReader = new ClassReader(Files.readAllBytes(Path.of(args[0])));
var retained = parse(retainedReader);
var donor = parse(new ClassReader(Files.readAllBytes(Path.of(args[1]))));
var targets = TARGETS.get(retained.name);
if (targets == null || !retained.name.equals(donor.name)) throw new IllegalArgumentException("Unexpected overlay class");
var additions = new LinkedHashMap<String, MethodNode>();
var renamed = new HashMap<String, String>();
for (String target : targets.stream().sorted().toList()) {
var method = donor.methods.stream().filter(m -> m.name.equals(target)).toList();
if (method.size() != 1) throw new IllegalArgumentException("Expected one donor method " + target);
prepare(donor, method.getFirst(), additions, renamed);
}
for (var entry : additions.entrySet()) {
var method = entry.getValue();
if (!targets.contains(method.name) &&
retained.methods.stream().anyMatch(old -> old.name.equals(method.name) && old.desc.equals(method.desc))) {
throw new IllegalArgumentException("Unexpected existing helper " + method.name);
}
retained.methods.removeIf(old -> old.name.equals(method.name) && old.desc.equals(method.desc));
retained.methods.add(method);
}
var writer = new ClassWriter(retainedReader, 0);
retained.accept(writer);
Files.write(Path.of(args[2]), writer.toByteArray());
}
private static void prepare(ClassNode donor, MethodNode method, Map<String, MethodNode> copies,
Map<String, String> renamed) {
String key = method.name + method.desc;
if (copies.putIfAbsent(key, method) != null) return;
for (var instruction : method.instructions) {
if (!(instruction instanceof InvokeDynamicInsnNode dynamic)) continue;
for (int i = 0; i < dynamic.bsmArgs.length; i++) {
if (!(dynamic.bsmArgs[i] instanceof Handle handle) || !handle.getOwner().equals(donor.name) ||
!handle.getName().startsWith("lambda$")) continue;
String original = handle.getName() + handle.getDesc();
String replacement = renamed.get(original);
if (replacement == null) {
var helper = donor.methods.stream().filter(m -> m.name.equals(handle.getName()) &&
m.desc.equals(handle.getDesc())).findFirst().orElseThrow();
replacement = "guildCookbook$" + handle.getName();
renamed.put(original, replacement);
helper.name = replacement;
prepare(donor, helper, copies, renamed);
}
dynamic.bsmArgs[i] = new Handle(handle.getTag(), handle.getOwner(), replacement,
handle.getDesc(), handle.isInterface());
}
}
}
private static ClassNode parse(ClassReader reader) {
var node = new ClassNode();
reader.accept(node, 0);
return node;
}
}

View file

@ -0,0 +1,53 @@
"""Assemble reviewed Guild and Cookbook methods onto the installed plugin variants."""
import argparse
import os
from pathlib import Path
import subprocess
from tempfile import TemporaryDirectory
from plugin_wild_update import digest, read_archive, write_archive
CLASSES = {
"gui": (
"com/dunerealms/gui/DuneGUI.class",
"com/dunerealms/gui/OrganisationMenus.class",
"com/dunerealms/gui/CookbookCatalog$Recipe.class",
),
"npc": ("com/example/dunenpc/DuneNPC.class",),
"lobby": ("com/example/dunelobby/DuneLobby.class",),
}
def assemble(module, baseline, baseline_sha, donor, donor_sha, output, classpath):
baseline_bytes = baseline.read_bytes()
donor_bytes = donor.read_bytes()
if digest(baseline_bytes) != baseline_sha or digest(donor_bytes) != donor_sha:
raise ValueError("Unexpected baseline or donor checksum")
retained = read_archive(baseline_bytes)
compiled = read_archive(donor_bytes)
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("GuildCookbookMerge.java")
with TemporaryDirectory() as temporary:
temp = Path(temporary)
for index, entry in enumerate(CLASSES[module]):
old, new, merged = (temp / f"{index}-{name}.class" for name in ("retained", "donor", "merged"))
old.write_bytes(retained[entry])
new.write_bytes(compiled[entry])
subprocess.run([java, "--class-path", classpath, str(helper), str(old), str(new), str(merged)], check=True)
retained[entry] = merged.read_bytes()
with output.open("xb") as candidate:
candidate.write(write_archive(retained))
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("module", choices=CLASSES)
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()))