forked from unimatrix/web
Add opt-in organisation, Exchange and House fullscreen styles
This commit is contained in:
parent
e8452c887f
commit
5f58251ee3
6 changed files with 303 additions and 90 deletions
|
|
@ -19,7 +19,14 @@ public interface DecisionsViewTransport {
|
|||
}
|
||||
}
|
||||
|
||||
record Document(String title, String description, List<Card> cards) {
|
||||
enum Style { AUTO, ORGANISATION, EXCHANGE, HOUSE }
|
||||
record Identity(String logo, String mentat, int portrait) {}
|
||||
|
||||
record Document(String title, String description, List<Card> cards, Style style, Identity identity) {
|
||||
public Document(String title, String description, List<Card> cards) {
|
||||
this(title, description, cards, Style.AUTO, null);
|
||||
}
|
||||
|
||||
public Document {
|
||||
cards = List.copyOf(cards);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -276,12 +276,14 @@ public final class DuneGUI extends JavaPlugin implements Listener,CommandExecuto
|
|||
Screen screen=screen(p,"Choose your House",0xE300+(chosen==null?0:Arrays.asList(IDS).indexOf(chosen)+1));
|
||||
for(int i=0;i<IDS.length;i++){String id=IDS[i];int centre=CENTRES[i];boolean selected=id.equals(chosen);
|
||||
var item=icon(p,houseName(data,id),selected?"Your current House":"Declare allegiance to this House","drgui_transparent",Material.PAPER);menuArt(item,"house_"+id);
|
||||
for(int row=i<3?-1:0;row<=1;row++)for(int col=-1;col<=1;col++){int slot=centre+row*9+col;screen.inventory.setItem(slot,item.clone());screen.actions.put(slot,()->declareHouse(p,data,id,true));}
|
||||
Runnable allegiance=()->declareHouse(p,data,id,true);
|
||||
for(int row=i<3?-1:0;row<=1;row++)for(int col=-1;col<=1;col++){int slot=centre+row*9+col;screen.inventory.setItem(slot,item.clone());screen.actions.put(slot,allegiance);}
|
||||
}
|
||||
button(screen,p,45,"Close","Return to the lobby",Material.ARROW,p::closeInventory);
|
||||
button(screen,p,49,sidebar.enabled(p)?"Hide scoreboard":"Show scoreboard","Toggle your personal briefing",Material.LEVER,()->{toggleSidebar(p);select(p,data,chosen);});
|
||||
for(int slot:new int[]{48,50})screen.actions.put(slot,screen.actions.get(49));
|
||||
screen.actions.put(46,screen.actions.get(45));
|
||||
if(NativeMenus.show(this,p,"development.fullscreen-house-viewers","Choose your House","",screen.inventory,screen.actions,screen.gate,DecisionsViewTransport.Style.HOUSE,null))return;
|
||||
if(MCGUIMenus.show(p,"Choose your House","",screen.inventory,screen.actions,screen.gate))return;
|
||||
p.openInventory(screen.inventory);expire(screen);
|
||||
}
|
||||
|
|
@ -307,6 +309,7 @@ public final class DuneGUI extends JavaPlugin implements Listener,CommandExecuto
|
|||
button(screen,p,45,"Your House",houseName(data,house),Material.ARROW,()->select(p,data,house));
|
||||
button(screen,p,49,sidebar.enabled(p)?"Hide scoreboard":"Show scoreboard","Toggle your personal briefing",Material.LEVER,()->{toggleSidebar(p);mentat(p,data);});for(int slot:new int[]{48,50})screen.actions.put(slot,screen.actions.get(49));
|
||||
for(int slot:new int[]{37,39})screen.actions.put(slot,screen.actions.get(38));for(int slot:new int[]{41,43})screen.actions.put(slot,screen.actions.get(42));screen.actions.put(46,screen.actions.get(45));
|
||||
if(NativeMenus.show(this,p,"development.fullscreen-house-viewers","Your Mentat · "+name,"",screen.inventory,screen.actions,screen.gate,DecisionsViewTransport.Style.HOUSE,null))return;
|
||||
if(MCGUIMenus.show(p,"Your Mentat · "+name,"",screen.inventory,screen.actions,screen.gate))return;
|
||||
p.openInventory(screen.inventory);expire(screen);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ final class ExchangeMenus implements Listener,AutoCloseable {
|
|||
private static ItemStack icon(Material material,String title,String... lore){var item=new ItemStack(material);var meta=item.getItemMeta();meta.displayName(Component.text(title,NamedTextColor.GOLD));meta.lore(Arrays.stream(lore).map(s->Component.text(s,NamedTextColor.GRAY)).toList());item.setItemMeta(meta);return item;}
|
||||
private Panel panel(Player p,String title){int screen=title.endsWith("Your listings")?1:title.endsWith("Add item")?2:title.endsWith("Purchase details")?3:title.endsWith("Withdraw listing")?4:0;var s=new Panel(p,title,artwork.test(p)&&!BedrockForms.isBedrock(p),screen);if(!s.artwork){var pane=icon(Material.GREEN_STAINED_GLASS_PANE," ");for(int i=0;i<54;i++)s.inventory.setItem(i,pane);}return s;}
|
||||
private void button(Panel s,int slot,Material material,String title,String description,Runnable action){s.inventory.setItem(slot,icon(material,title,description));s.actions.put(slot,action);s.choices.add(new BedrockForms.Choice(title,description,action));}
|
||||
private void show(Player p,Panel s){if(BedrockForms.isBedrock(p)){s.gate.expire();BedrockForms.show(plugin,p,s.title,s.description,s.choices);}else{if(MCGUIMenus.show(p,s.title,s.description,s.inventory,s.actions,s.gate))return;p.openInventory(s.inventory);Bukkit.getScheduler().runTaskLater(plugin,s.gate::expire,2400L);}}
|
||||
private void show(Player p,Panel s){if(BedrockForms.isBedrock(p)){s.gate.expire();BedrockForms.show(plugin,p,s.title,s.description,s.choices);}else{if(Set.of("Exchange · Buy","Exchange · Your listings","Exchange · Kits").contains(s.title)&&NativeMenus.show(plugin,p,"development.fullscreen-exchange-viewers",s.title,s.description,s.inventory,s.actions,s.gate,DecisionsViewTransport.Style.EXCHANGE,null))return;if(MCGUIMenus.show(p,s.title,s.description,s.inventory,s.actions,s.gate))return;p.openInventory(s.inventory);Bukkit.getScheduler().runTaskLater(plugin,s.gate::expire,2400L);}}
|
||||
private void request(Player p,JsonObject input,Consumer<JsonObject> success,Consumer<String> failure){
|
||||
UUID id=p.getUniqueId(),world=p.getWorld().getUID();if(pending.containsKey(id)){p.sendMessage("J.A.R.V.I.S. is processing your Exchange action.");return;}UUID token=UUID.randomUUID();pending.put(id,token);p.closeInventory();
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin,()->{JsonObject result=null;String error=null;try{result=bridge.exchange(id,input);}catch(Exception e){error=e.getMessage();}var response=result;String message=error;if(!plugin.isEnabled())return;Bukkit.getScheduler().runTask(plugin,()->{if(!token.equals(pending.get(id)))return;pending.remove(id);if(!p.isOnline()||!world.equals(p.getWorld().getUID()))return;if(response==null){failure.accept(message==null?"The Exchange is temporarily unavailable.":message);return;}if(response.has("rejectedStatus")){if(Set.of("buy","buy_kit").contains(input.get("action").getAsString()))retries.remove(id);failure.accept(response.has("message")?response.get("message").getAsString():"The Exchange rejected this action.");return;}success.accept(response);});});
|
||||
|
|
|
|||
|
|
@ -0,0 +1,48 @@
|
|||
package com.dunerealms.gui;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
/** Bridges the existing menu document and its server-side callbacks to an opt-in renderer. */
|
||||
final class NativeMenus {
|
||||
private NativeMenus() {}
|
||||
|
||||
static boolean show(JavaPlugin plugin, Player player, String setting, String title, String description,
|
||||
Inventory inventory, Map<Integer,Runnable> actions, GuiSession gate,
|
||||
DecisionsViewTransport.Style style, MenuDocument.Branding branding) {
|
||||
if (!plugin.getConfig().getStringList(setting).contains(player.getUniqueId().toString())) return false;
|
||||
var transport = Bukkit.getServicesManager().load(DecisionsViewTransport.class);
|
||||
if (transport == null) return false;
|
||||
var cards = MCGUIMenus.cards(inventory, actions).stream().map(card ->
|
||||
new DecisionsViewTransport.Card(card.slot(), card.title(), card.lore(), card.action(), card.material())).toList();
|
||||
var identity = branding == null ? null :
|
||||
new DecisionsViewTransport.Identity(branding.logo(), branding.mentat(), branding.portrait());
|
||||
var document = new DecisionsViewTransport.Document(title, description, cards, style, identity);
|
||||
Map<Integer,Runnable> visibleActions = new HashMap<>();
|
||||
for (var card : cards) if (card.actionable()) visibleActions.put(card.slot(), actions.get(card.slot()));
|
||||
var callbacks = Map.copyOf(visibleActions);
|
||||
player.closeInventory();
|
||||
var world = player.getWorld().getUID();
|
||||
try {
|
||||
if (!transport.open(player, document, slot -> {
|
||||
if (!Bukkit.isPrimaryThread()) return;
|
||||
if (!player.isOnline() || !world.equals(player.getWorld().getUID())) {
|
||||
gate.expire();
|
||||
return;
|
||||
}
|
||||
var action = gate.claimAction(player.getUniqueId(), callbacks.get(slot));
|
||||
gate.expire();
|
||||
if (action != null) action.run();
|
||||
}, gate::expire)) return false;
|
||||
} catch (RuntimeException | LinkageError failure) {
|
||||
plugin.getLogger().warning("Development fullscreen view unavailable: " + failure.getClass().getSimpleName());
|
||||
return false;
|
||||
}
|
||||
gate.markFormVisible(world);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -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(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.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();}
|
||||
|
|
|
|||
|
|
@ -302,37 +302,13 @@ final class QuestMenus implements Listener {
|
|||
screen.title.startsWith("NPC next quest · ");
|
||||
if(!decisions&&!quests)return false;
|
||||
String setting=decisions?"development.fullscreen-decisions-viewers":"development.fullscreen-quest-viewers";
|
||||
if(!plugin.getConfig().getStringList(setting).contains(player.getUniqueId().toString()))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(),card.material()))
|
||||
.toList();
|
||||
String dialogue=screen.description;
|
||||
for(int index=screen.descriptionNotes.size()-1;index>=0;index--){
|
||||
String note=screen.descriptionNotes.get(index);
|
||||
if(dialogue.endsWith(note))dialogue=dialogue.substring(0,dialogue.length()-note.length());
|
||||
}
|
||||
var document=new DecisionsViewTransport.Document(screen.title,dialogue,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);
|
||||
player.closeInventory();
|
||||
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;
|
||||
}
|
||||
screen.gate.markFormVisible(world);
|
||||
return true;
|
||||
return NativeMenus.show(plugin,player,setting,screen.title,dialogue,screen.inventory,screen.actions,screen.gate,
|
||||
DecisionsViewTransport.Style.AUTO,null);
|
||||
}
|
||||
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)));}
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff