Add the Imperial Codex and item archive to the opt-in viewer

This commit is contained in:
unimatrixgit 2026-11-28 10:17:28 +01:00
commit 4abc909ed4
3 changed files with 108 additions and 24 deletions

View file

@ -19,7 +19,7 @@ public interface DecisionsViewTransport {
}
}
enum Style { AUTO, ORGANISATION, EXCHANGE, EXCHANGE_CHECKOUT, HOUSE, JOURNAL }
enum Style { AUTO, ORGANISATION, EXCHANGE, EXCHANGE_CHECKOUT, HOUSE, JOURNAL, CODEX, ITEM_ARCHIVE }
record Identity(String logo, String mentat, int portrait) {}
record Document(String title, String description, List<Card> cards, Style style, Identity identity) {

View file

@ -22,11 +22,18 @@ final class ItemPreviewMenu implements Listener {
UUID owner=player.getUniqueId(),world=player.getWorld().getUID();if(pending.containsKey(owner))return;UUID token=UUID.randomUUID();pending.put(owner,token);player.closeInventory();player.sendMessage(Component.text("Jarvis executing matrix",NamedTextColor.GOLD));
Bukkit.getScheduler().runTaskAsynchronously(plugin,()->{com.google.gson.JsonObject data=null;String error=null;try{data=bridge.itemPreview(owner,id,revision);}catch(Exception failure){error=failure instanceof java.io.IOException?failure.getMessage():"The saved item preview is unavailable. Refresh the website editor.";}var received=data;String message=error;if(!plugin.isEnabled())return;
Bukkit.getScheduler().runTask(plugin,()->{if(!token.equals(pending.get(owner)))return;pending.remove(owner);if(!player.isOnline()||!world.equals(player.getWorld().getUID()))return;if(message!=null){player.sendMessage(Component.text(message,NamedTextColor.RED));return;}if(player.getOpenInventory().getType()!=InventoryType.CRAFTING)return;
try{var item=bridge.buildItemPreview(player,received,panels.test(player)&&!BedrockForms.isBedrock(player));if(BedrockForms.isBedrock(player)){var plain=PlainTextComponentSerializer.plainText();String body=plain.serialize(item.getItemMeta().displayName())+"\n"+String.join("\n",item.getItemMeta().lore().stream().map(plain::serialize).toList());BedrockForms.show(plugin,player,"Saved item preview",body,List.of(new BedrockForms.Choice("Close","Return to the world",()->{})));return;}var panel=new Panel(player);panel.inventory.setItem(13,item);var close=new ItemStack(Material.BARRIER);var meta=close.getItemMeta();meta.displayName(Component.text("Close preview",NamedTextColor.GOLD));meta.lore(List.of(Component.text("This view cannot issue or withdraw items.",NamedTextColor.GRAY)));close.setItemMeta(meta);panel.inventory.setItem(22,close);if(MCGUIMenus.show(player,"Saved item preview","Your registered item design",panel.inventory,Map.of(22,()->{}),null))return;player.openInventory(panel.inventory);}
try{var item=bridge.buildItemPreview(player,received,panels.test(player)&&!BedrockForms.isBedrock(player));if(BedrockForms.isBedrock(player)){var plain=PlainTextComponentSerializer.plainText();String body=plain.serialize(item.getItemMeta().displayName())+"\n"+String.join("\n",item.getItemMeta().lore().stream().map(plain::serialize).toList());BedrockForms.show(plugin,player,"Saved item preview",body,List.of(new BedrockForms.Choice("Close","Return to the world",()->{})));return;}var panel=new Panel(player);panel.inventory.setItem(13,item);var close=new ItemStack(Material.BARRIER);var meta=close.getItemMeta();meta.displayName(Component.text("Close preview",NamedTextColor.GOLD));meta.lore(List.of(Component.text("This view cannot issue or withdraw items.",NamedTextColor.GRAY)));close.setItemMeta(meta);panel.inventory.setItem(22,close);Map<Integer,Runnable> actions=Map.of(22,()->{});if(showNative(player,panel,item,actions))return;if(MCGUIMenus.show(player,"Saved item preview","Your registered item design",panel.inventory,actions,null))return;player.openInventory(panel.inventory);}
catch(Exception invalid){player.sendMessage(Component.text(invalid instanceof IllegalArgumentException&&invalid.getMessage()!=null?invalid.getMessage():"This saved design cannot be previewed in the current world.",NamedTextColor.RED));}
});
});
}
private boolean showNative(Player player,Panel panel,ItemStack item,Map<Integer,Runnable> actions){
var meta=item.getItemMeta();
if(meta.hasItemModel()||meta instanceof org.bukkit.inventory.meta.ArmorMeta armor&&armor.hasTrim())return false;
return NativeMenus.show(plugin,player,"development.fullscreen-codex-viewers","Saved item preview",
"Your registered item design",panel.inventory,actions,new GuiSession(panel.owner),
DecisionsViewTransport.Style.ITEM_ARCHIVE,null);
}
@EventHandler(priority=EventPriority.HIGHEST) public void click(InventoryClickEvent event){if(!(event.getView().getTopInventory().getHolder() instanceof Panel panel))return;event.setCancelled(true);if(event.getWhoClicked() instanceof Player player&&panel.owner.equals(player.getUniqueId())&&event.getRawSlot()==22)Bukkit.getScheduler().runTask(plugin,()->{if(player.isOnline()&&player.getOpenInventory().getTopInventory()==panel.inventory)player.closeInventory();});}
@EventHandler(priority=EventPriority.HIGHEST) public void drag(InventoryDragEvent event){if(event.getView().getTopInventory().getHolder() instanceof Panel)event.setCancelled(true);}
@EventHandler public void quit(PlayerQuitEvent event){pending.remove(event.getPlayer().getUniqueId());}

View file

@ -22,12 +22,12 @@ final class OrganisationMenus implements Listener {
private static final class Panel implements DuneMenuInventory {
final UUID owner;final GuiSession gate;final Map<Integer,Runnable> actions=new HashMap<>();final Map<Integer,BedrockForms.Choice> choices=new TreeMap<>();String title;boolean artwork;Inventory inventory;MenuDocument.Branding branding;
final UUID owner;final GuiSession gate;final Map<Integer,Runnable> actions=new HashMap<>();final Map<Integer,BedrockForms.Choice> choices=new TreeMap<>();String title;DecisionsViewTransport.Style nativeStyle;boolean artwork;Inventory inventory;MenuDocument.Branding branding;
Panel(Player p){owner=p.getUniqueId();gate=new GuiSession(owner);}
public Inventory getInventory(){return inventory;}
}
OrganisationMenus(JavaPlugin plugin,HouseBridge bridge,Consumer<Player> mentat,Consumer<Player> travel,Consumer<Player> house,Consumer<Player> quests,Consumer<Player> decisions,Consumer<Player> exchange,Consumer<Player> spice,java.util.function.Predicate<Player> artwork){this.plugin=plugin;this.bridge=bridge;this.mentat=mentat;this.travel=travel;this.house=house;this.quests=quests;this.decisions=decisions;this.exchange=exchange;this.spice=spice;this.artwork=artwork;Bukkit.getPluginManager().registerEvents(this,plugin);}
void console(Player p){var panel=panel(p,"Imperial Codex",0);put(panel,8,"Emergency rescue · 1,000 DM","Teleport to safety and heal · 24-hour cooldown",Material.TOTEM_OF_UNDYING,()->p.performCommand("duneess:rescue"));if(p.getWorld().getName().equals("arrakis"))put(panel,28,"Spice buyers","Spacing Guild · Smuggler · P&O payout",Material.ORANGE_DYE,()->spice.accept(p));put(panel,34,"Exchange","Buy, sell and collect your purchases",Material.CHEST,()->exchange.accept(p));var exchangeIcon=new ItemStack(Material.CHEST);var exchangeMeta=exchangeIcon.getItemMeta();exchangeMeta.displayName(Component.text("Exchange",NamedTextColor.GOLD));exchangeMeta.lore(List.of(Component.text("Buy · Sell · Add held item",NamedTextColor.GRAY)));exchangeIcon.setItemMeta(exchangeMeta);panel.inventory.setItem(34,exchangeIcon);put(panel,31,"Mission journal","Personal Experience and Reputation",Material.WRITABLE_BOOK,()->quests.accept(p));put(panel,32,"Decisions","Your current J.A.R.V.I.S. decisions",Material.ENCHANTED_BOOK,()->decisions.accept(p));put(panel,4,"Item lore archive","Preview the shared item lore cards",Material.WRITABLE_BOOK,()->lore(p));put(panel,19,"Clan","Your clan and Home Block",Material.GREEN_BANNER,()->open(p,"clans"));put(panel,22,"Company","Your companies and Home Blocks",Material.CYAN_BANNER,()->open(p,"companies"));put(panel,25,"POL","Your current political offices",Material.PURPLE_BANNER,()->open(p,"offices"));put(panel,37,"Your Mentat","Your personal briefing",Material.BOOK,()->mentat.accept(p));put(panel,40,"Spacing Guild","Transport and boarding windows",Material.COMPASS,()->travel.accept(p));put(panel,43,"Your House","Your allegiance and adviser",Material.NETHER_STAR,()->house.accept(p));close(panel,p);show(p,panel);}
void console(Player p){var panel=panel(p,"Imperial Codex",0);panel.nativeStyle=DecisionsViewTransport.Style.CODEX;put(panel,8,"Emergency rescue · 1,000 DM","Teleport to safety and heal · 24-hour cooldown",Material.TOTEM_OF_UNDYING,()->p.performCommand("duneess:rescue"));if(p.getWorld().getName().equals("arrakis"))put(panel,28,"Spice buyers","Spacing Guild · Smuggler · P&O payout",Material.ORANGE_DYE,()->spice.accept(p));put(panel,34,"Exchange","Buy, sell and collect your purchases",Material.CHEST,()->exchange.accept(p));var exchangeIcon=new ItemStack(Material.CHEST);var exchangeMeta=exchangeIcon.getItemMeta();exchangeMeta.displayName(Component.text("Exchange",NamedTextColor.GOLD));exchangeMeta.lore(List.of(Component.text("Buy · Sell · Add held item",NamedTextColor.GRAY)));exchangeIcon.setItemMeta(exchangeMeta);panel.inventory.setItem(34,exchangeIcon);put(panel,31,"Mission journal","Personal Experience and Reputation",Material.WRITABLE_BOOK,()->quests.accept(p));put(panel,32,"Decisions","Your current J.A.R.V.I.S. decisions",Material.ENCHANTED_BOOK,()->decisions.accept(p));put(panel,4,"Item lore archive","Preview the shared item lore cards",Material.WRITABLE_BOOK,()->lore(p));put(panel,19,"Clan","Your clan and Home Block",Material.GREEN_BANNER,()->open(p,"clans"));put(panel,22,"Company","Your companies and Home Blocks",Material.CYAN_BANNER,()->open(p,"companies"));put(panel,25,"POL","Your current political offices",Material.PURPLE_BANNER,()->open(p,"offices"));put(panel,37,"Your Mentat","Your personal briefing",Material.BOOK,()->mentat.accept(p));put(panel,40,"Spacing Guild","Transport and boarding windows",Material.COMPASS,()->travel.accept(p));put(panel,43,"Your House","Your allegiance and adviser",Material.NETHER_STAR,()->house.accept(p));close(panel,p);show(p,panel);}
void open(Player p,String kind){
if(!busy.add(p.getUniqueId()))return;
Bukkit.getScheduler().runTaskAsynchronously(plugin,()->{JsonObject data=null;try{data=bridge.organisations(p.getUniqueId());}catch(Exception ignored){}JsonObject result=data;if(!plugin.isEnabled())return;
@ -96,7 +96,7 @@ final class OrganisationMenus implements Listener {
});
}
void lore(Player p){
var panel=panel(p,"Item lore archive · Preview",false);String[] kinds={"MENU","EQUIPMENT","KIT","COMPONENT","TICKET","CASH","RIHLA","DEED","QUEST"};Material[] materials={Material.COMPASS,Material.IRON_SWORD,Material.CHEST,Material.AMETHYST_SHARD,Material.PAPER,Material.GOLD_NUGGET,Material.WRITABLE_BOOK,Material.MAP,Material.BOOK};
var panel=panel(p,"Item lore archive · Preview",false);panel.nativeStyle=DecisionsViewTransport.Style.ITEM_ARCHIVE;String[] kinds={"MENU","EQUIPMENT","KIT","COMPONENT","TICKET","CASH","RIHLA","DEED","QUEST"};Material[] materials={Material.COMPASS,Material.IRON_SWORD,Material.CHEST,Material.AMETHYST_SHARD,Material.PAPER,Material.GOLD_NUGGET,Material.WRITABLE_BOOK,Material.MAP,Material.BOOK};
for(int i=0;i<kinds.length;i++){String kind=kinds[i];Map<String,String> facts=switch(kind){case "EQUIPMENT"->Map.of("Grade","From issued equipment key","House","From House key","Durability","From actual item");case "KIT"->Map.of("Contents","From kit definition","State","Design preview");case "COMPONENT"->Map.of("Recipe","From crafting definition");case "TICKET"->Map.of("Route","From passage key","Departure",":00 / :20 / :40");case "CASH"->Map.of("Value","From bank withdrawal","State","Design preview");case "RIHLA"->Map.of("Recipient","From RIA key","Amount","From transfer record");case "DEED"->Map.of("Organisation","From registered deed","Holder","From current authority");case "QUEST"->Map.of("Objective","From mission key","Progress","From verified events");default->Map.of("Service","DuneRealms","Access","Current JARVIS keys");};try{panel.inventory.setItem(18+i,bridge.lorePreview(kind,materials[i],kind.replace('_',' '),facts));}catch(Exception unavailable){p.sendMessage("The lore renderer is temporarily unavailable.");return;}}
put(panel,45,"Back","Imperial Codex",Material.ARROW,()->console(p));close(panel,p);show(p,panel);
}
@ -223,7 +223,7 @@ final class OrganisationMenus implements Listener {
private Panel panel(Player p,String title,int screen){if(!artwork.test(p)||BedrockForms.isBedrock(p))return panel(p,title,screen==2);var panel=new Panel(p);panel.title=title;panel.artwork=true;panel.inventory=Bukkit.createInventory(panel,54,Component.text(GuiArtwork.background(0xE340+screen),NamedTextColor.WHITE).font(net.kyori.adventure.key.Key.key("dunerealms:house_selector")));return panel;}
private void put(Panel panel,int slot,String title,String description,Material material,Runnable action){var item=new ItemStack(panel.artwork?Material.PAPER:material);var meta=item.getItemMeta();meta.displayName(Component.text(title,NamedTextColor.GOLD));meta.lore(Arrays.stream(description.split("\n")).map(line->Component.text(line,NamedTextColor.GRAY)).toList());if(panel.artwork)meta.setItemModel(new NamespacedKey("dunerealms","drgui_transparent"));item.setItemMeta(meta);panel.inventory.setItem(slot,item);panel.actions.put(slot,action);if(panel.artwork&&Set.of(19,22,25,37,40,43).contains(slot))for(int alias:new int[]{slot-1,slot+1}){panel.inventory.setItem(alias,item.clone());panel.actions.put(alias,action);}panel.choices.put(slot,new BedrockForms.Choice(title,description,action));}
private void close(Panel panel,Player p){put(panel,53,"Close","Return to the game",Material.BARRIER,p::closeInventory);}
private void show(Player p,Panel panel){brandingRequests.remove(p.getUniqueId());if(BedrockForms.isBedrock(p)){BedrockForms.show(plugin,p,panel.title,panel.branding==null||panel.branding.mentat().isEmpty()?"Current organisation keys":"Mentat · "+panel.branding.mentat(),List.copyOf(panel.choices.values()));return;}if(panel.branding!=null&&NativeMenus.show(plugin,p,"development.fullscreen-organisation-viewers",panel.title,"",panel.inventory,panel.actions,panel.gate,DecisionsViewTransport.Style.ORGANISATION,panel.branding))return;if(MCGUIMenus.show(p,panel.title,"Current organisation keys",panel.inventory,panel.actions,panel.gate,panel.branding))return;p.openInventory(panel.inventory);Bukkit.getScheduler().runTaskLater(plugin,panel.gate::expire,2400L);}
private void show(Player p,Panel panel){brandingRequests.remove(p.getUniqueId());if(BedrockForms.isBedrock(p)){BedrockForms.show(plugin,p,panel.title,panel.branding==null||panel.branding.mentat().isEmpty()?"Current organisation keys":"Mentat · "+panel.branding.mentat(),List.copyOf(panel.choices.values()));return;}if(panel.nativeStyle!=null&&NativeMenus.show(plugin,p,"development.fullscreen-codex-viewers",panel.title,"",panel.inventory,panel.actions,panel.gate,panel.nativeStyle,null))return;if(panel.branding!=null&&NativeMenus.show(plugin,p,"development.fullscreen-organisation-viewers",panel.title,"",panel.inventory,panel.actions,panel.gate,DecisionsViewTransport.Style.ORGANISATION,panel.branding))return;if(MCGUIMenus.show(p,panel.title,"Current organisation keys",panel.inventory,panel.actions,panel.gate,panel.branding))return;p.openInventory(panel.inventory);Bukkit.getScheduler().runTaskLater(plugin,panel.gate::expire,2400L);}
@EventHandler public void click(InventoryClickEvent e){if(!(e.getView().getTopInventory().getHolder() instanceof Panel panel))return;e.setCancelled(true);if(!(e.getWhoClicked() instanceof Player p)||!panel.owner.equals(p.getUniqueId())||e.getClickedInventory()!=panel.inventory||e.getClick()!=ClickType.LEFT)return;var action=panel.actions.get(e.getRawSlot());if(action!=null&&panel.gate.claim(p.getUniqueId()))Bukkit.getScheduler().runTask(plugin,()->{if(p.isOnline()&&p.getOpenInventory().getTopInventory()==panel.inventory)action.run();});}
@EventHandler public void drag(InventoryDragEvent e){if(e.getView().getTopInventory().getHolder() instanceof Panel)e.setCancelled(true);}
@EventHandler public void closed(InventoryCloseEvent e){if(e.getInventory().getHolder() instanceof Panel panel)panel.gate.expire();}