Isolate lobby GUI from legacy renderer and defer plugin cleanup
This commit is contained in:
parent
51f67bd1ba
commit
9e21286756
1 changed files with 62 additions and 12 deletions
|
|
@ -1,7 +1,7 @@
|
|||
package com.dunerealms.gui;
|
||||
|
||||
import com.example.dunegui.MenuSession;
|
||||
import com.example.dunegui.NativeMenus;
|
||||
|
||||
|
||||
import com.google.gson.*;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
|
@ -32,8 +32,8 @@ public final class DuneGUI extends JavaPlugin implements Listener,CommandExecuto
|
|||
static final String[] IDS={"atreides","harkonnen","corrino","ordos","fremen"};
|
||||
private static final Set<String> HOUSE_IDS=Set.of(IDS);
|
||||
private static final class Screen implements InventoryHolder {
|
||||
final UUID owner;final MenuSession gate;final Map<Integer,Runnable> actions=new HashMap<>();Inventory inventory;
|
||||
Screen(Player player){owner=player.getUniqueId();gate=new MenuSession(owner);}
|
||||
final UUID owner;final GuiSession gate;final Map<Integer,Runnable> actions=new HashMap<>();Inventory inventory;
|
||||
Screen(Player player){owner=player.getUniqueId();gate=new GuiSession(owner);}
|
||||
public Inventory getInventory(){return inventory;}
|
||||
}
|
||||
@Override public void onEnable(){
|
||||
|
|
@ -46,7 +46,7 @@ public final class DuneGUI extends JavaPlugin implements Listener,CommandExecuto
|
|||
Bukkit.getScheduler().runTaskLater(this,this::ensureRegistrar,40L);
|
||||
getLogger().info("House selector and Mentat screens enabled; central J.A.R.V.I.S. bridge; no Core/Lobby replacement.");
|
||||
}
|
||||
@Override public void onDisable(){requests.clear();records.clear();if(departure!=null)departure.removeAll();for(Player p:Bukkit.getOnlinePlayers())if(p.getOpenInventory().getTopInventory().getHolder() instanceof Screen)p.closeInventory();}
|
||||
@Override public void onDisable(){requests.clear();records.clear();GuiSession.clear();if(departure!=null)departure.removeAll();for(Player p:Bukkit.getOnlinePlayers())if(p.getOpenInventory().getTopInventory().getHolder() instanceof Screen)p.closeInventory();}
|
||||
private boolean lobby(Player p){return p.getWorld().getName().equals("guild_lobby");}
|
||||
@Override public boolean onCommand(CommandSender sender,Command command,String label,String[] args){
|
||||
if(!(sender instanceof Player p))return true;if(!lobby(p)){p.sendMessage("This service is available in the Spacing Guild lobby.");return true;}
|
||||
|
|
@ -69,12 +69,12 @@ public final class DuneGUI extends JavaPlugin implements Listener,CommandExecuto
|
|||
private String houseName(JsonObject data,String id){for(var entry:data.getAsJsonArray("choices")){var h=entry.getAsJsonObject();if(h.get("id").getAsString().equals(id))return h.get("name").getAsString();}throw new IllegalArgumentException("Unknown House");}
|
||||
private void select(Player p,JsonObject data,String picked){
|
||||
String current=selection(data),chosen=picked!=null?picked:current;
|
||||
if(NativeMenus.isBedrock(p)){
|
||||
List<NativeMenus.Choice> choices=new ArrayList<>();
|
||||
if(BedrockForms.isBedrock(p)){
|
||||
List<BedrockForms.Choice> choices=new ArrayList<>();
|
||||
for(var entry:data.getAsJsonArray("choices")){var house=entry.getAsJsonObject();String id=house.get("id").getAsString();if(!HOUSE_IDS.contains(id))continue;
|
||||
choices.add(new NativeMenus.Choice(house.get("name").getAsString()+(id.equals(current)?" · Your House":""),"Review and confirm allegiance",()->confirmForm(p,data,id),"https://www.dunerealms.com/assets/seals/"+house.get("seal").getAsString()));
|
||||
choices.add(new BedrockForms.Choice(house.get("name").getAsString()+(id.equals(current)?" · Your House":""),"Review and confirm allegiance",()->confirmForm(p,data,id),"https://www.dunerealms.com/assets/seals/"+house.get("seal").getAsString()));
|
||||
}
|
||||
NativeMenus.show(this,p,"Choose your House","Declare your allegiance. Review a House before confirming.",choices);return;
|
||||
BedrockForms.show(this,p,"Choose your House","Declare your allegiance. Review a House before confirming.",choices);return;
|
||||
}
|
||||
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);
|
||||
|
|
@ -86,7 +86,7 @@ public final class DuneGUI extends JavaPlugin implements Listener,CommandExecuto
|
|||
screen.actions.put(46,screen.actions.get(45));if(chosen!=null)screen.actions.put(52,screen.actions.get(53));
|
||||
p.openInventory(screen.inventory);expire(screen);
|
||||
}
|
||||
private void confirmForm(Player p,JsonObject data,String id){NativeMenus.show(this,p,"Confirm House · "+houseName(data,id),"Confirm your allegiance to "+houseName(data,id)+". This initial selection does not grant an elected office.",List.of(new NativeMenus.Choice("Confirm House","Save through J.A.R.V.I.S.",()->confirm(p,data,id)),new NativeMenus.Choice("Back","Review all five Houses",()->select(p,data,id))));}
|
||||
private void confirmForm(Player p,JsonObject data,String id){BedrockForms.show(this,p,"Confirm House · "+houseName(data,id),"Confirm your allegiance to "+houseName(data,id)+". This initial selection does not grant an elected office.",List.of(new BedrockForms.Choice("Confirm House","Save through J.A.R.V.I.S.",()->confirm(p,data,id)),new BedrockForms.Choice("Back","Review all five Houses",()->select(p,data,id))));}
|
||||
private void confirm(Player p,JsonObject data,String id){
|
||||
if(id.equals(selection(data))&&data.has("keyId")&&!data.get("keyId").isJsonNull()){mentat(p,data);return;}
|
||||
fetch(p,id,data.get("version").getAsInt(),UUID.randomUUID(),saved->{p.sendMessage(Component.text("House allegiance confirmed in J.A.R.V.I.S.",NamedTextColor.GREEN));mentat(p,saved);});
|
||||
|
|
@ -94,7 +94,7 @@ public final class DuneGUI extends JavaPlugin implements Listener,CommandExecuto
|
|||
private void mentat(Player p,JsonObject data){
|
||||
String house=selection(data);if(house==null){select(p,data,null);return;}
|
||||
JsonObject mentor=data.getAsJsonObject("mentat");String name=mentor.get("name").getAsString();int index=Arrays.asList(IDS).indexOf(house);
|
||||
if(NativeMenus.isBedrock(p)){NativeMenus.show(this,p,"Your Mentat · "+name,houseName(data,house)+"\nYour House briefing is ready.",List.of(new NativeMenus.Choice("Open Mentat Report","Open your website mission journal",()->report(p),"https://www.dunerealms.com/assets/gui/mentat-"+house+"-v1.png"),new NativeMenus.Choice("Return to lobby","Continue your journey",p::closeInventory)));return;}
|
||||
if(BedrockForms.isBedrock(p)){BedrockForms.show(this,p,"Your Mentat · "+name,houseName(data,house)+"\nYour House briefing is ready.",List.of(new BedrockForms.Choice("Open Mentat Report","Open your website mission journal",()->report(p),"https://www.dunerealms.com/assets/gui/mentat-"+house+"-v1.png"),new BedrockForms.Choice("Return to lobby","Continue your journey",p::closeInventory)));return;}
|
||||
Screen screen=screen(p,"Your Mentat · "+name,0xE310+index);
|
||||
screen.inventory.setItem(13,icon(p,name,houseName(data,house),"drgui_transparent",Material.PLAYER_HEAD));
|
||||
button(screen,p,38,"Open Mentat Report","Personal level, Reputation and active quests",Material.WRITABLE_BOOK,()->report(p));
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff