Add opt-in fullscreen Decisions transport boundary

This commit is contained in:
unimatrixgit 2026-11-28 08:46:52 +01:00
commit e3c91a6cb2
3 changed files with 73 additions and 8 deletions

View file

@ -0,0 +1,32 @@
package com.dunerealms.gui;
import java.util.List;
import java.util.function.IntConsumer;
import org.bukkit.entity.Player;
/**
* Bukkit service for an optional Java fullscreen provider. The provider owns its
* runtime-specific packet support and closes its scene before returning input.
*/
public interface DecisionsViewTransport {
record Card(int slot, String title, List<String> lore, boolean actionable) {
public Card {
lore = List.copyOf(lore);
}
}
record Document(String title, String description, List<Card> cards) {
public Document {
cards = List.copyOf(cards);
}
}
/**
* Called on the server thread. Return false on an unsupported runtime or if
* opening fails. Release partial state before returning false. After a
* successful open, call exactly one terminal callback on the server thread:
* select a visible actionable slot, or close without selecting. Finish
* transport cleanup before the callback. Never invoke it inside open.
*/
boolean open(Player viewer, Document document, IntConsumer select, Runnable close);
}

View file

@ -71,6 +71,16 @@ final class MCGUIMenus implements AutoCloseable, Listener {
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;
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=cards(inventory,actions);
GuiSession gate=suppliedGate==null?new GuiSession(p.getUniqueId()):suppliedGate;
Session old=sessions.remove(p.getUniqueId());if(old!=null)old.finish();
try{
Map<Integer,Runnable> callbacks=new HashMap<>(actions);callbacks.values().removeIf(Objects::isNull);
Session s=new Session(p,title,description,cards,Map.copyOf(callbacks),gate,branding);sessions.put(p.getUniqueId(),s);p.closeInventory();s.schedule();
Bukkit.getScheduler().runTaskLater(plugin,()->{if(sessions.get(p.getUniqueId())==s){s.finish();sessions.remove(p.getUniqueId());}},2400L);return true;
}catch(Exception failure){gate.expire();plugin.getLogger().warning("MC GUI menu unavailable: "+failure.getClass().getSimpleName());p.sendMessage("This menu is temporarily unavailable. Reopen your Imperial Codex.");return true;}
}
static List<MenuDocument.Card> cards(Inventory inventory,Map<Integer,Runnable> actions){
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++){
@ -83,13 +93,7 @@ final class MCGUIMenus implements AutoCloseable, Listener {
if(meta!=null)for(var key:meta.getPersistentDataContainer().getKeys())if(key.getKey().equals("quality")){String value=meta.getPersistentDataContainer().get(key,org.bukkit.persistence.PersistentDataType.STRING);if(value!=null)quality=value;}
cards.add(new MenuDocument.Card(slot,name,lore,material,item.getAmount(),action!=null,quality));
}
GuiSession gate=suppliedGate==null?new GuiSession(p.getUniqueId()):suppliedGate;
Session old=sessions.remove(p.getUniqueId());if(old!=null)old.finish();
try{
Map<Integer,Runnable> callbacks=new HashMap<>(actions);callbacks.values().removeIf(Objects::isNull);
Session s=new Session(p,title,description,cards,Map.copyOf(callbacks),gate,branding);sessions.put(p.getUniqueId(),s);p.closeInventory();s.schedule();
Bukkit.getScheduler().runTaskLater(plugin,()->{if(sessions.get(p.getUniqueId())==s){s.finish();sessions.remove(p.getUniqueId());}},2400L);return true;
}catch(Exception failure){gate.expire();plugin.getLogger().warning("MC GUI menu unavailable: "+failure.getClass().getSimpleName());p.sendMessage("This menu is temporarily unavailable. Reopen your Imperial Codex.");return true;}
return List.copyOf(cards);
}
private final class Session implements InvocationHandler {
final Player player;final UUID world;final String title,description;final List<MenuDocument.Card> cards;final Map<Integer,Runnable> actions;final GuiSession gate;final Object canvas;final MenuDocument.Branding branding;

View file

@ -293,9 +293,38 @@ final class QuestMenus implements Listener {
if(current<last)put(screen,53,"Next page","More decisions",Material.ARROW,()->openDecisions(p,current+1));
put(screen,48,"Back","Mission journal",Material.ARROW,()->open(p));
put(screen,49,"Website","Decision definitions and history",Material.MAP,()->decisionWebsite(p));
show(p,screen);
if(!showDevelopmentDecisions(p,screen))show(p,screen);
},true);
}
private boolean showDevelopmentDecisions(Player player,Panel screen){
if(!plugin.getConfig().getStringList("development.fullscreen-decisions-viewers")
.contains(player.getUniqueId().toString())||BedrockForms.isBedrock(player))return false;
var transport=Bukkit.getServicesManager().load(DecisionsViewTransport.class);
if(transport==null)return false;
var cards=MCGUIMenus.cards(screen.inventory,screen.actions).stream()
.map(card->new DecisionsViewTransport.Card(card.slot(),card.title(),card.lore(),card.action()))
.toList();
var document=new DecisionsViewTransport.Document(screen.title,screen.description,cards);
Map<Integer,Runnable> visibleActions=new HashMap<>();
for(var card:cards)if(card.actionable())visibleActions.put(card.slot(),screen.actions.get(card.slot()));
var callbacks=Map.copyOf(visibleActions);
var world=player.getWorld().getUID();
try{
if(!transport.open(player,document,slot->{
if(!Bukkit.isPrimaryThread())return;
if(!player.isOnline()||!world.equals(player.getWorld().getUID())){screen.gate.expire();return;}
var action=screen.gate.claimAction(player.getUniqueId(),callbacks.get(slot));
screen.gate.expire();
if(action!=null)action.run();
},screen.gate::expire))return false;
}catch(RuntimeException failure){
plugin.getLogger().warning("Development Decisions view unavailable: "+failure.getClass().getSimpleName());
return false;
}
player.closeInventory();
screen.gate.markFormVisible(world);
return true;
}
private void decisionWebsite(Player p){decisionWebsite(p,null);}
private void decisionWebsite(Player p,String decision){p.closeInventory();String url="https://clans.dunerealms.com/#quests/quests?xp=pol&view=decisions";if(decision!=null&&decision.matches("[A-Z0-9-]{1,32}"))url+="&decision="+decision;p.sendMessage(Component.text("Review POL decisions on the website →",NamedTextColor.GOLD).clickEvent(ClickEvent.openUrl(url)));}
private void roleDecisionDetails(Player p,JsonObject contact,PolQuestNpc.Role role,JsonObject row,String account,String parameter){var screen=panel(p,"NPC turn-in decision · "+role.name());screen.description=dialogue(row,"introduction","");roleAvatar(screen,contact,role);String kind=text(row,"kind","");String fee=text(row,"feeMinor","0");String amount;try{amount=new java.math.BigDecimal(fee).movePointLeft(2).toPlainString()+" DM";}catch(NumberFormatException invalid){amount="—";}put(screen,13,text(row,"title","Decision"),"Required Reputation: "+text(row,"level","—")+"\nBase cost: "+amount+"\nAward: "+text(row,"reputation","—")+" Reputation",Material.BOOK,null);