Offer required network artwork only in Spacing Guild lobby

This commit is contained in:
unimatrix 2026-11-23 19:15:25 +00:00
commit aecfcb5fa6

View file

@ -37,6 +37,8 @@ final class MCGUIMenus implements AutoCloseable {
Class<?> canvas=Class.forName("ai.resourcepack.ui.framework.api.Canvas",true,cl);draw=canvas.getMethod("draw",java.awt.image.BufferedImage.class,int.class,int.class);
packId=(UUID)Class.forName("ai.resourcepack.ui.framework.pack.ResourcePack",true,cl).getField("PACK_ID").get(null);
packUrl=engine.getConfig().getString("resource-pack.public-url","");
// MC GUI external-without-URL means the pack was delivered by lobby.
if(packUrl.isBlank())packUrl="https://www.dunerealms.com/downloads/DuneRealms-MCGUI-0.8.6-1.21.11.zip";
if(!packUrl.startsWith("https://"))throw new IllegalStateException("A hosted menu pack URL is required");
packHash=java.security.MessageDigest.getInstance("SHA-1").digest(Files.readAllBytes(engine.getDataFolder().toPath().resolve("pack.zip")));
active=this;plugin.getLogger().info("MC GUI presentation connected for all DuneRealms menus; Jarvis callbacks retained.");
@ -46,10 +48,10 @@ final class MCGUIMenus implements AutoCloseable {
return active!=null&&active.present(p,title,description,inventory,actions,gate);
}
static void offerPack(Player p){if(active!=null&&!BedrockForms.isBedrock(p))active.sendPack(p);}
private void sendPack(Player p){p.addResourcePack(packId,packUrl,packHash,"DuneRealms interactive menus",false);}
private void sendPack(Player p){if(!p.getWorld().getName().equals("guild_lobby"))return;p.addResourcePack(packId,packUrl,packHash,"DuneRealms interactive menus",true);}
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;
try{if(!Boolean.TRUE.equals(hasPack.invoke(framework,p))){sendPack(p);p.sendMessage("Loading the new menu pack. Accept it, then use /menu again.");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 p.sendMessage("Visit Spacing Guild lobby to update your menu artwork.");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<>();
var plain=PlainTextComponentSerializer.plainText();
for(int slot=0;slot<inventory.getSize();slot++){