From 9e21286756ab5847b10c7975e2d19f18de36479f Mon Sep 17 00:00:00 2001 From: unimatrixgit <95320811+unimatrixgit@users.noreply.github.com> Date: Sat, 21 Nov 2026 14:48:04 +0100 Subject: [PATCH] Isolate lobby GUI from legacy renderer and defer plugin cleanup --- DuneRealmsGUI/build.gradle.kts | 1 - .../java/com/dunerealms/gui/BedrockForms.java | 22 +++++++++++++++++++ .../main/java/com/dunerealms/gui/DuneGUI.java | 22 +++++++++---------- .../java/com/dunerealms/gui/GuiSession.java | 16 ++++++++++++++ .../com/dunerealms/gui/GuiSessionTest.java | 11 ++++++++++ docs/design/LOBBY-HOUSE-GUI.md | 2 ++ 6 files changed, 62 insertions(+), 12 deletions(-) create mode 100644 DuneRealmsGUI/src/main/java/com/dunerealms/gui/BedrockForms.java create mode 100644 DuneRealmsGUI/src/main/java/com/dunerealms/gui/GuiSession.java create mode 100644 DuneRealmsGUI/src/test/java/com/dunerealms/gui/GuiSessionTest.java diff --git a/DuneRealmsGUI/build.gradle.kts b/DuneRealmsGUI/build.gradle.kts index 5202b24d..30a422ff 100644 --- a/DuneRealmsGUI/build.gradle.kts +++ b/DuneRealmsGUI/build.gradle.kts @@ -9,7 +9,6 @@ dependencies { testRuntimeOnly("org.junit.platform:junit-platform-launcher") } java { toolchain.languageVersion.set(JavaLanguageVersion.of(21)) } -sourceSets.main { java.srcDir("../gui-common/src/main/java") } tasks.withType { options.encoding = "UTF-8" } tasks.test { useJUnitPlatform() } tasks.jar { archiveFileName.set("DunerealmsGUI.jar") } diff --git a/DuneRealmsGUI/src/main/java/com/dunerealms/gui/BedrockForms.java b/DuneRealmsGUI/src/main/java/com/dunerealms/gui/BedrockForms.java new file mode 100644 index 00000000..3d8797f9 --- /dev/null +++ b/DuneRealmsGUI/src/main/java/com/dunerealms/gui/BedrockForms.java @@ -0,0 +1,22 @@ +package com.dunerealms.gui; +import java.util.List; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +/** Native controller/touch input, sharing the exact action session with the Java screens. */ +final class BedrockForms { + record Choice(String label,String description,Runnable action,String imageUrl){Choice(String label,String description,Runnable action){this(label,description,action,null);}} + static boolean isBedrock(Player player){return Bukkit.getPluginManager().isPluginEnabled("floodgate")&&Floodgate.isPlayer(player);} + static void show(JavaPlugin plugin,Player player,String title,String content,List choices){Floodgate.show(plugin,player,title,content,choices);} + private static final class Floodgate { + static boolean isPlayer(Player p){return org.geysermc.floodgate.api.FloodgateApi.getInstance().isFloodgatePlayer(p.getUniqueId());} + static void show(JavaPlugin plugin,Player p,String title,String content,List choices){ + GuiSession gate=new GuiSession(p.getUniqueId());Bukkit.getScheduler().runTaskLater(plugin,gate::expire,2400L); + var form=org.geysermc.cumulus.form.SimpleForm.builder().title(title).content(content); + for(Choice choice:choices){String url=choice.imageUrl();if(url!=null&&url.matches("https://www\\.dunerealms\\.com/assets/(seals|gui)/[a-z0-9-]+\\.png"))form.button(choice.label(),org.geysermc.cumulus.util.FormImage.Type.URL,url);else form.button(choice.label());} + form.closedOrInvalidResultHandler(gate::expire); + form.validResultHandler(result->{int index=result.clickedButtonId();if(!plugin.isEnabled())return;Bukkit.getScheduler().runTask(plugin,()->{if(p.isOnline()&&p.getWorld().getName().equals("guild_lobby")&&index>=0&&index HOUSE_IDS=Set.of(IDS); private static final class Screen implements InventoryHolder { - final UUID owner;final MenuSession gate;final Map actions=new HashMap<>();Inventory inventory; - Screen(Player player){owner=player.getUniqueId();gate=new MenuSession(owner);} + final UUID owner;final GuiSession gate;final Map actions=new HashMap<>();Inventory inventory; + Screen(Player player){owner=player.getUniqueId();gate=new GuiSession(owner);} public Inventory getInventory(){return inventory;} } @Override public void onEnable(){ @@ -46,7 +46,7 @@ public final class DuneGUI extends JavaPlugin implements Listener,CommandExecuto Bukkit.getScheduler().runTaskLater(this,this::ensureRegistrar,40L); getLogger().info("House selector and Mentat screens enabled; central J.A.R.V.I.S. bridge; no Core/Lobby replacement."); } - @Override public void onDisable(){requests.clear();records.clear();if(departure!=null)departure.removeAll();for(Player p:Bukkit.getOnlinePlayers())if(p.getOpenInventory().getTopInventory().getHolder() instanceof Screen)p.closeInventory();} + @Override public void onDisable(){requests.clear();records.clear();GuiSession.clear();if(departure!=null)departure.removeAll();for(Player p:Bukkit.getOnlinePlayers())if(p.getOpenInventory().getTopInventory().getHolder() instanceof Screen)p.closeInventory();} private boolean lobby(Player p){return p.getWorld().getName().equals("guild_lobby");} @Override public boolean onCommand(CommandSender sender,Command command,String label,String[] args){ if(!(sender instanceof Player p))return true;if(!lobby(p)){p.sendMessage("This service is available in the Spacing Guild lobby.");return true;} @@ -69,12 +69,12 @@ public final class DuneGUI extends JavaPlugin implements Listener,CommandExecuto private String houseName(JsonObject data,String id){for(var entry:data.getAsJsonArray("choices")){var h=entry.getAsJsonObject();if(h.get("id").getAsString().equals(id))return h.get("name").getAsString();}throw new IllegalArgumentException("Unknown House");} private void select(Player p,JsonObject data,String picked){ String current=selection(data),chosen=picked!=null?picked:current; - if(NativeMenus.isBedrock(p)){ - List choices=new ArrayList<>(); + if(BedrockForms.isBedrock(p)){ + List choices=new ArrayList<>(); for(var entry:data.getAsJsonArray("choices")){var house=entry.getAsJsonObject();String id=house.get("id").getAsString();if(!HOUSE_IDS.contains(id))continue; - choices.add(new NativeMenus.Choice(house.get("name").getAsString()+(id.equals(current)?" · Your House":""),"Review and confirm allegiance",()->confirmForm(p,data,id),"https://www.dunerealms.com/assets/seals/"+house.get("seal").getAsString())); + choices.add(new BedrockForms.Choice(house.get("name").getAsString()+(id.equals(current)?" · Your House":""),"Review and confirm allegiance",()->confirmForm(p,data,id),"https://www.dunerealms.com/assets/seals/"+house.get("seal").getAsString())); } - NativeMenus.show(this,p,"Choose your House","Declare your allegiance. Review a House before confirming.",choices);return; + BedrockForms.show(this,p,"Choose your House","Declare your allegiance. Review a House before confirming.",choices);return; } Screen screen=screen(p,"Choose your House",0xE300+(chosen==null?0:Arrays.asList(IDS).indexOf(chosen)+1)); for(int i=0;iconfirm(p,data,id)),new NativeMenus.Choice("Back","Review all five Houses",()->select(p,data,id))));} + private void confirmForm(Player p,JsonObject data,String id){BedrockForms.show(this,p,"Confirm House · "+houseName(data,id),"Confirm your allegiance to "+houseName(data,id)+". This initial selection does not grant an elected office.",List.of(new BedrockForms.Choice("Confirm House","Save through J.A.R.V.I.S.",()->confirm(p,data,id)),new BedrockForms.Choice("Back","Review all five Houses",()->select(p,data,id))));} private void confirm(Player p,JsonObject data,String id){ if(id.equals(selection(data))&&data.has("keyId")&&!data.get("keyId").isJsonNull()){mentat(p,data);return;} fetch(p,id,data.get("version").getAsInt(),UUID.randomUUID(),saved->{p.sendMessage(Component.text("House allegiance confirmed in J.A.R.V.I.S.",NamedTextColor.GREEN));mentat(p,saved);}); @@ -94,7 +94,7 @@ public final class DuneGUI extends JavaPlugin implements Listener,CommandExecuto private void mentat(Player p,JsonObject data){ String house=selection(data);if(house==null){select(p,data,null);return;} JsonObject mentor=data.getAsJsonObject("mentat");String name=mentor.get("name").getAsString();int index=Arrays.asList(IDS).indexOf(house); - if(NativeMenus.isBedrock(p)){NativeMenus.show(this,p,"Your Mentat · "+name,houseName(data,house)+"\nYour House briefing is ready.",List.of(new NativeMenus.Choice("Open Mentat Report","Open your website mission journal",()->report(p),"https://www.dunerealms.com/assets/gui/mentat-"+house+"-v1.png"),new NativeMenus.Choice("Return to lobby","Continue your journey",p::closeInventory)));return;} + if(BedrockForms.isBedrock(p)){BedrockForms.show(this,p,"Your Mentat · "+name,houseName(data,house)+"\nYour House briefing is ready.",List.of(new BedrockForms.Choice("Open Mentat Report","Open your website mission journal",()->report(p),"https://www.dunerealms.com/assets/gui/mentat-"+house+"-v1.png"),new BedrockForms.Choice("Return to lobby","Continue your journey",p::closeInventory)));return;} Screen screen=screen(p,"Your Mentat · "+name,0xE310+index); screen.inventory.setItem(13,icon(p,name,houseName(data,house),"drgui_transparent",Material.PLAYER_HEAD)); button(screen,p,38,"Open Mentat Report","Personal level, Reputation and active quests",Material.WRITABLE_BOOK,()->report(p)); diff --git a/DuneRealmsGUI/src/main/java/com/dunerealms/gui/GuiSession.java b/DuneRealmsGUI/src/main/java/com/dunerealms/gui/GuiSession.java new file mode 100644 index 00000000..cc82d796 --- /dev/null +++ b/DuneRealmsGUI/src/main/java/com/dunerealms/gui/GuiSession.java @@ -0,0 +1,16 @@ +package com.dunerealms.gui; +import java.time.Duration; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicBoolean; +/** Isolated namespace: older plugins bundle incompatible com.example.dunegui classes. */ +final class GuiSession { + private static final ConcurrentHashMap CURRENT=new ConcurrentHashMap<>(); + private final UUID owner; + private final long expires=System.nanoTime()+Duration.ofMinutes(2).toNanos(); + private final AtomicBoolean used=new AtomicBoolean(); + GuiSession(UUID owner){this.owner=owner;CURRENT.put(owner,this);} + boolean claim(UUID actor){return owner.equals(actor)&&System.nanoTime()