Recognise server pack configuration success before player join
This commit is contained in:
parent
77cf4fd023
commit
a3dee6dfd8
6 changed files with 70 additions and 12 deletions
13
DuneMenus/docs/SERVER-PACK-READINESS.md
Normal file
13
DuneMenus/docs/SERVER-PACK-READINESS.md
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
# Server-owned pack readiness correction
|
||||||
|
|
||||||
|
Objective: allow the existing menu presentation after the required, pinned central pack has genuinely loaded in Paper configuration phase.
|
||||||
|
|
||||||
|
Scope: GUI readiness only. No artwork, JARVIS, economy, permissions, gameplay or second pack offer. Existing server configuration must pass the exact URL/hash/UUID pin validation before configuration status can seed readiness.
|
||||||
|
|
||||||
|
Evidence: the owner's client loaded central UUID before lobby join, then the menu reported artwork unavailable. On exact Paper 26.2-135, ServerConfigurationPacketListenerImpl.handleResourcePackResponse records Connection.resourcePackStatus but emits no Bukkit PlayerResourcePackStatusEvent. CraftPlayer.getResourcePackStatus reads that connection status after join. The previous GUI listened only for the later play-phase event.
|
||||||
|
|
||||||
|
Implementation: read actual connection status at join and for already-online players during adapter startup; only server-owned SUCCESSFULLY_LOADED seeds readiness. Later matching pending/failure/unload statuses revoke readiness. Other UUIDs never grant readiness. Quit clears all state; the next backend must establish its own connection status. MCGUI.hasPack remains required by menu presentation. Stacked legacy mode continues to require its own matching event.
|
||||||
|
|
||||||
|
Acceptance/tests: configuration-only success without a player event; all non-success/null statuses blocked; foreign UUID isolation; legacy overlay isolation; later failure/pending invalidation; reconnect/backend transfer lifecycle. Run full GUI tests/build and canonical plugin/pack CI at exact commit. Coordinator alone deploys the built artifact, then verifies server readiness log and owner menu rendering. Local tests are not connected-client proof.
|
||||||
|
|
||||||
|
Runtime evidence inspected read-only: existing isolated Paper26.2-135 JAR and API. No live host changes made from this chat. Current lobby/Arrakis77cf canaries retained; other four on hold. This correction ships GUI1.1.35; pack artwork remains byte-identical to77cf, under the new immutable source filename.
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
plugins { java }
|
plugins { java }
|
||||||
group = "com.dunerealms"
|
group = "com.dunerealms"
|
||||||
version = "1.1.34"
|
version = "1.1.35"
|
||||||
repositories { mavenCentral(); maven("https://repo.papermc.io/repository/maven-public/"); maven("https://repo.opencollab.dev/main/") }
|
repositories { mavenCentral(); maven("https://repo.papermc.io/repository/maven-public/"); maven("https://repo.opencollab.dev/main/") }
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly("io.papermc.paper:paper-api:1.21.8-R0.1-SNAPSHOT")
|
compileOnly("io.papermc.paper:paper-api:1.21.8-R0.1-SNAPSHOT")
|
||||||
|
|
|
||||||
|
|
@ -18,12 +18,12 @@ final class MCGUIMenus implements AutoCloseable, Listener {
|
||||||
private static MCGUIMenus active;
|
private static MCGUIMenus active;
|
||||||
private final JavaPlugin plugin;
|
private final JavaPlugin plugin;
|
||||||
private final Map<UUID,Session> sessions=new HashMap<>();
|
private final Map<UUID,Session> sessions=new HashMap<>();
|
||||||
private final Set<UUID> closeHints=new HashSet<>(),gameplayReady=new HashSet<>(),gameplayOffered=new HashSet<>();
|
private final Set<UUID> closeHints=new HashSet<>(),gameplayOffered=new HashSet<>();
|
||||||
private final ExecutorService drawings=Executors.newSingleThreadExecutor(r->{Thread t=new Thread(r,"DuneRealms-menu-render");t.setDaemon(true);return t;});
|
private final ExecutorService drawings=Executors.newSingleThreadExecutor(r->{Thread t=new Thread(r,"DuneRealms-menu-render");t.setDaemon(true);return t;});
|
||||||
private Plugin engine;private Object framework,loader,none;private Class<?> contentType,optionsType;private Object defaultOptions;
|
private Plugin engine;private Object framework,loader,none;private Class<?> contentType,optionsType;private Object defaultOptions;
|
||||||
private Method makeCanvas,openView,hasPack,pageOf,render,draw,hoverState;
|
private Method makeCanvas,openView,hasPack,pageOf,render,draw,hoverState;
|
||||||
private UUID packId;private String packUrl;private byte[] packHash;
|
private UUID packId;private String packUrl;private byte[] packHash;
|
||||||
private boolean serverOwnedPack;
|
private boolean serverOwnedPack;private MenuPackReadiness readiness;
|
||||||
private final Path base;
|
private final Path base;
|
||||||
MCGUIMenus(JavaPlugin plugin){
|
MCGUIMenus(JavaPlugin plugin){
|
||||||
this.plugin=plugin;base=plugin.getDataFolder().toPath().resolve("mcgui/menu.html");
|
this.plugin=plugin;base=plugin.getDataFolder().toPath().resolve("mcgui/menu.html");
|
||||||
|
|
@ -50,8 +50,9 @@ final class MCGUIMenus implements AutoCloseable, Listener {
|
||||||
packId=UUID.fromString(MenuPackPolicy.UNIFIED_ID);
|
packId=UUID.fromString(MenuPackPolicy.UNIFIED_ID);
|
||||||
}else packId=(UUID)Class.forName("ai.resourcepack.ui.framework.pack.ResourcePack",true,cl).getField("PACK_ID").get(null);
|
}else packId=(UUID)Class.forName("ai.resourcepack.ui.framework.pack.ResourcePack",true,cl).getField("PACK_ID").get(null);
|
||||||
if(!engine.getConfig().getString("resource-pack.mode","").equals("external")||!engine.getConfig().getString("resource-pack.public-url","").isBlank()||engine.getConfig().getBoolean("telemetry",true))throw new IllegalStateException("MCGUI must use external merged mode with telemetry disabled");
|
if(!engine.getConfig().getString("resource-pack.mode","").equals("external")||!engine.getConfig().getString("resource-pack.public-url","").isBlank()||engine.getConfig().getBoolean("telemetry",true))throw new IllegalStateException("MCGUI must use external merged mode with telemetry disabled");
|
||||||
|
readiness=new MenuPackReadiness(packId,serverOwnedPack);
|
||||||
packUrl=pin.url();packHash=HexFormat.of().parseHex(pin.sha1());
|
packUrl=pin.url();packHash=HexFormat.of().parseHex(pin.sha1());
|
||||||
active=this;Bukkit.getPluginManager().registerEvents(this,plugin);Bukkit.getScheduler().runTaskLater(plugin,()->Bukkit.getOnlinePlayers().forEach(this::offerGameplay),60L);plugin.getLogger().info("MC GUI presentation connected for all DuneRealms menus; Jarvis callbacks retained.");
|
active=this;Bukkit.getPluginManager().registerEvents(this,plugin);Bukkit.getScheduler().runTaskLater(plugin,()->Bukkit.getOnlinePlayers().forEach(p->{configurationJoined(p);offerGameplay(p);}),60L);plugin.getLogger().info("MC GUI presentation connected for all DuneRealms menus; Jarvis callbacks retained.");
|
||||||
}catch(Exception failure){framework=null;plugin.getLogger().warning("MC GUI adapter unavailable: "+failure.getClass().getSimpleName());}
|
}catch(Exception failure){framework=null;plugin.getLogger().warning("MC GUI adapter unavailable: "+failure.getClass().getSimpleName());}
|
||||||
}
|
}
|
||||||
static boolean show(Player p,String title,String description,Inventory inventory,Map<Integer,Runnable> actions,GuiSession gate){
|
static boolean show(Player p,String title,String description,Inventory inventory,Map<Integer,Runnable> actions,GuiSession gate){
|
||||||
|
|
@ -60,7 +61,7 @@ final class MCGUIMenus implements AutoCloseable, Listener {
|
||||||
}
|
}
|
||||||
static boolean showDocument(Player p,String title,String html,Map<Integer,Runnable> actions,Runnable closed){
|
static boolean showDocument(Player p,String title,String html,Map<Integer,Runnable> actions,Runnable closed){
|
||||||
if(active==null||active.framework==null||!p.isOnline()||BedrockForms.isBedrock(p))return false;
|
if(active==null||active.framework==null||!p.isOnline()||BedrockForms.isBedrock(p))return false;
|
||||||
try{if(!active.gameplayReady.contains(p.getUniqueId())||!Boolean.TRUE.equals(active.hasPack.invoke(active.framework,p))){active.sendPack(p);return false;}
|
try{if(!active.readiness.loaded(p.getUniqueId())||!Boolean.TRUE.equals(active.hasPack.invoke(active.framework,p))){active.sendPack(p);return false;}
|
||||||
Session old=active.sessions.remove(p.getUniqueId());if(old!=null)old.finish();
|
Session old=active.sessions.remove(p.getUniqueId());if(old!=null)old.finish();
|
||||||
Session next=active.new Session(p,title,"",List.of(),Map.copyOf(actions),null);
|
Session next=active.new Session(p,title,"",List.of(),Map.copyOf(actions),null);
|
||||||
next.suppliedHtml=html;next.onClose=closed;active.sessions.put(p.getUniqueId(),next);p.closeInventory();next.schedule();
|
next.suppliedHtml=html;next.onClose=closed;active.sessions.put(p.getUniqueId(),next);p.closeInventory();next.schedule();
|
||||||
|
|
@ -68,16 +69,18 @@ final class MCGUIMenus implements AutoCloseable, Listener {
|
||||||
}catch(Exception failure){active.plugin.getLogger().warning("Supplied menu presentation unavailable: "+failure.getClass().getSimpleName());return false;}
|
}catch(Exception failure){active.plugin.getLogger().warning("Supplied menu presentation unavailable: "+failure.getClass().getSimpleName());return false;}
|
||||||
}
|
}
|
||||||
static boolean isMenuPack(UUID id){return active!=null&&id.equals(active.packId);}
|
static boolean isMenuPack(UUID id){return active!=null&&id.equals(active.packId);}
|
||||||
static boolean assetsLoaded(Player player){if(active==null||active.framework==null)return false;try{return active.gameplayReady.contains(player.getUniqueId())&&Boolean.TRUE.equals(active.hasPack.invoke(active.framework,player));}catch(Exception failure){return false;}}
|
static boolean assetsLoaded(Player player){if(active==null||active.framework==null)return false;try{return active.readiness.loaded(player.getUniqueId())&&Boolean.TRUE.equals(active.hasPack.invoke(active.framework,player));}catch(Exception failure){return false;}}
|
||||||
static void forget(UUID player){if(active!=null){active.closeHints.remove(player);active.gameplayReady.remove(player);active.gameplayOffered.remove(player);}}
|
static void forget(UUID player){if(active!=null){active.closeHints.remove(player);if(active.readiness!=null)active.readiness.forget(player);active.gameplayOffered.remove(player);}}
|
||||||
static void offerPack(Player p){if(active!=null&&!BedrockForms.isBedrock(p))active.sendPack(p);}
|
static void offerPack(Player p){if(active!=null&&!BedrockForms.isBedrock(p))active.sendPack(p);}
|
||||||
private void sendPack(Player p){if(!serverOwnedPack&&p.isOnline()&&!gameplayReady.contains(p.getUniqueId())&&gameplayOffered.add(p.getUniqueId()))p.addResourcePack(packId,packUrl,packHash,"DuneRealms interactive menus",true);}
|
private void sendPack(Player p){if(!serverOwnedPack&&p.isOnline()&&!readiness.loaded(p.getUniqueId())&&gameplayOffered.add(p.getUniqueId()))p.addResourcePack(packId,packUrl,packHash,"DuneRealms interactive menus",true);}
|
||||||
private void offerGameplay(Player p){if(p.isOnline()&&!BedrockForms.isBedrock(p))sendPack(p);}
|
private void offerGameplay(Player p){if(p.isOnline()&&!BedrockForms.isBedrock(p))sendPack(p);}
|
||||||
@EventHandler public void playerJoined(PlayerJoinEvent e){Bukkit.getScheduler().runTaskLater(plugin,()->offerGameplay(e.getPlayer()),60L);}
|
@EventHandler public void playerJoined(PlayerJoinEvent e){configurationJoined(e.getPlayer());Bukkit.getScheduler().runTaskLater(plugin,()->offerGameplay(e.getPlayer()),60L);}
|
||||||
@EventHandler public void menuPackStatus(PlayerResourcePackStatusEvent e){if(packId==null||!packId.equals(e.getID()))return;var id=e.getPlayer().getUniqueId();if(e.getStatus()==PlayerResourcePackStatusEvent.Status.SUCCESSFULLY_LOADED){boolean first=gameplayReady.add(id);if(first&&serverOwnedPack)plugin.getLogger().info("Central resource pack loaded for "+e.getPlayer().getName()+" UUID "+packId);}else if(e.getStatus()!=PlayerResourcePackStatusEvent.Status.ACCEPTED&&e.getStatus()!=PlayerResourcePackStatusEvent.Status.DOWNLOADED) {gameplayReady.remove(id);gameplayOffered.remove(id);}}
|
private void configurationJoined(Player p){if(serverOwnedPack&&readiness.configurationJoined(p.getUniqueId(),p.getResourcePackStatus()))loadedLog(p);}
|
||||||
|
private void loadedLog(Player p){if(serverOwnedPack)plugin.getLogger().info("Central resource pack loaded for "+p.getName()+" UUID "+packId);}
|
||||||
|
@EventHandler public void menuPackStatus(PlayerResourcePackStatusEvent e){if(readiness==null||packId==null||!packId.equals(e.getID()))return;if(readiness.status(e.getPlayer().getUniqueId(),e.getID(),e.getStatus()))loadedLog(e.getPlayer());if(e.getStatus()!=PlayerResourcePackStatusEvent.Status.SUCCESSFULLY_LOADED&&e.getStatus()!=PlayerResourcePackStatusEvent.Status.ACCEPTED&&e.getStatus()!=PlayerResourcePackStatusEvent.Status.DOWNLOADED)gameplayOffered.remove(e.getPlayer().getUniqueId());}
|
||||||
private boolean present(Player p,String title,String description,Inventory inventory,Map<Integer,Runnable> actions,GuiSession suppliedGate){
|
private boolean present(Player p,String title,String description,Inventory inventory,Map<Integer,Runnable> actions,GuiSession suppliedGate){
|
||||||
if(framework==null||!engine.isEnabled()||!p.isOnline()||BedrockForms.isBedrock(p))return false;
|
if(framework==null||!engine.isEnabled()||!p.isOnline()||BedrockForms.isBedrock(p))return false;
|
||||||
if(!p.getWorld().getName().equals("guild_lobby")&&!gameplayReady.contains(p.getUniqueId()))return false;
|
if(!p.getWorld().getName().equals("guild_lobby")&&!readiness.loaded(p.getUniqueId()))return false;
|
||||||
try{if(!Boolean.TRUE.equals(hasPack.invoke(framework,p))){if(p.getWorld().getName().equals("guild_lobby")){sendPack(p);p.sendMessage("Loading the lobby menu artwork. Reopen your menu after loading.");}else return false;return true;}}catch(Exception e){p.sendMessage("The new menu is temporarily unavailable. Please retry /menu.");return true;}
|
try{if(!Boolean.TRUE.equals(hasPack.invoke(framework,p))){if(p.getWorld().getName().equals("guild_lobby")){sendPack(p);p.sendMessage("Loading the lobby menu artwork. Reopen your menu after loading.");}else return false;return true;}}catch(Exception e){p.sendMessage("The new menu is temporarily unavailable. Please retry /menu.");return true;}
|
||||||
List<MenuDocument.Card> cards=new ArrayList<>();Set<Runnable> aliases=Collections.newSetFromMap(new IdentityHashMap<>());Set<String> decorations=new HashSet<>(),transparent=new HashSet<>();
|
List<MenuDocument.Card> cards=new ArrayList<>();Set<Runnable> aliases=Collections.newSetFromMap(new IdentityHashMap<>());Set<String> decorations=new HashSet<>(),transparent=new HashSet<>();
|
||||||
var plain=PlainTextComponentSerializer.plainText();
|
var plain=PlainTextComponentSerializer.plainText();
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.dunerealms.gui;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
import org.bukkit.event.player.PlayerResourcePackStatusEvent.Status;
|
||||||
|
|
||||||
|
/** Main-thread readiness for configuration-phase server packs and later play-phase updates. */
|
||||||
|
final class MenuPackReadiness {
|
||||||
|
private final UUID packId;
|
||||||
|
private final boolean serverOwned;
|
||||||
|
private final Set<UUID> ready=new HashSet<>(),observed=new HashSet<>();
|
||||||
|
MenuPackReadiness(UUID packId,boolean serverOwned){this.packId=packId;this.serverOwned=serverOwned;}
|
||||||
|
// Paper records configuration responses on the connection, without a Bukkit player event.
|
||||||
|
// Read once at join, only for the exact server-owned pack already validated against server.properties.
|
||||||
|
boolean configurationJoined(UUID player,Status status){
|
||||||
|
if(!serverOwned||!observed.add(player))return false;
|
||||||
|
return status==Status.SUCCESSFULLY_LOADED&&ready.add(player);
|
||||||
|
}
|
||||||
|
boolean status(UUID player,UUID incoming,Status status){
|
||||||
|
if(!packId.equals(incoming))return false;
|
||||||
|
observed.add(player);
|
||||||
|
if(status==Status.SUCCESSFULLY_LOADED)return ready.add(player);
|
||||||
|
ready.remove(player);return false;
|
||||||
|
}
|
||||||
|
boolean loaded(UUID player){return ready.contains(player);}
|
||||||
|
void forget(UUID player){ready.remove(player);observed.remove(player);}
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
name: DunerealmsGUI
|
name: DunerealmsGUI
|
||||||
main: com.dunerealms.gui.DuneGUI
|
main: com.dunerealms.gui.DuneGUI
|
||||||
version: 1.1.34
|
version: 1.1.35
|
||||||
api-version: '1.21.8'
|
api-version: '1.21.8'
|
||||||
depend: [JarvisTranslator]
|
depend: [JarvisTranslator]
|
||||||
softdepend: [Citizens, MCGUI, DecentHolograms, DuneLobby, DuneCore, DuneEss, DuneNPC, Vault, floodgate, ViaVersion]
|
softdepend: [Citizens, MCGUI, DecentHolograms, DuneLobby, DuneCore, DuneEss, DuneNPC, Vault, floodgate, ViaVersion]
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.dunerealms.gui;
|
||||||
|
import java.util.UUID;
|
||||||
|
import org.bukkit.event.player.PlayerResourcePackStatusEvent.Status;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
class MenuPackReadinessTest {
|
||||||
|
final UUID pack=UUID.fromString(MenuPackPolicy.UNIFIED_ID),player=UUID.randomUUID();
|
||||||
|
@Test void configurationSuccessNeedsNoLaterBukkitEvent(){var state=new MenuPackReadiness(pack,true);assertTrue(state.configurationJoined(player,Status.SUCCESSFULLY_LOADED));assertTrue(state.loaded(player));}
|
||||||
|
@Test void pendingFailedAndUnknownConfigurationRemainBlocked(){for(Status status:Status.values()){if(status==Status.SUCCESSFULLY_LOADED)continue;var state=new MenuPackReadiness(pack,true);assertFalse(state.configurationJoined(player,status));assertFalse(state.loaded(player));}var state=new MenuPackReadiness(pack,true);assertFalse(state.configurationJoined(player,null));}
|
||||||
|
@Test void stackedPackCannotBorrowConfigurationSuccess(){var state=new MenuPackReadiness(pack,false);assertFalse(state.configurationJoined(player,Status.SUCCESSFULLY_LOADED));assertFalse(state.loaded(player));assertTrue(state.status(player,pack,Status.SUCCESSFULLY_LOADED));}
|
||||||
|
@Test void laterMatchingFailureOrPendingRevokesReadiness(){var state=new MenuPackReadiness(pack,true);state.configurationJoined(player,Status.SUCCESSFULLY_LOADED);state.status(player,pack,Status.ACCEPTED);assertFalse(state.loaded(player));assertFalse(state.configurationJoined(player,Status.SUCCESSFULLY_LOADED));state.status(player,pack,Status.SUCCESSFULLY_LOADED);assertTrue(state.loaded(player));state.status(player,pack,Status.FAILED_DOWNLOAD);assertFalse(state.loaded(player));}
|
||||||
|
@Test void foreignPackCannotSetOrRevokeThisPack(){var state=new MenuPackReadiness(pack,true);assertFalse(state.status(player,UUID.randomUUID(),Status.SUCCESSFULLY_LOADED));assertFalse(state.loaded(player));state.configurationJoined(player,Status.SUCCESSFULLY_LOADED);state.status(player,UUID.randomUUID(),Status.FAILED_DOWNLOAD);assertTrue(state.loaded(player));}
|
||||||
|
@Test void backendTransferStartsWithItsOwnConnectionStatus(){var oldBackend=new MenuPackReadiness(pack,true);oldBackend.configurationJoined(player,Status.SUCCESSFULLY_LOADED);oldBackend.forget(player);assertFalse(oldBackend.loaded(player));var nextBackend=new MenuPackReadiness(pack,true);assertFalse(nextBackend.configurationJoined(player,Status.ACCEPTED));nextBackend.status(player,pack,Status.SUCCESSFULLY_LOADED);assertTrue(nextBackend.loaded(player));nextBackend.forget(player);assertTrue(nextBackend.configurationJoined(player,Status.SUCCESSFULLY_LOADED));}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue

Staff