Display official organisation emblems and political Mentats
This commit is contained in:
parent
d6a009979f
commit
297eafe2b4
1 changed files with 123 additions and 16 deletions
|
|
@ -18,10 +18,11 @@ final class OrganisationMenus implements Listener {
|
|||
private final JavaPlugin plugin;private final HouseBridge bridge;private final Consumer<Player> mentat,travel,house,quests,exchange,spice;
|
||||
private final java.util.function.Predicate<Player> artwork;
|
||||
private final Set<UUID> busy=new HashSet<>();
|
||||
private final Map<UUID,UUID> brandingRequests=new HashMap<>();
|
||||
|
||||
|
||||
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;
|
||||
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;
|
||||
Panel(Player p){owner=p.getUniqueId();gate=new GuiSession(owner);}
|
||||
public Inventory getInventory(){return inventory;}
|
||||
}
|
||||
|
|
@ -107,7 +108,29 @@ final class OrganisationMenus implements Listener {
|
|||
put(panel,45,"Back","Your organisations",Material.ARROW,()->start(p,data));close(panel,p);show(p,panel);
|
||||
}
|
||||
private void organisation(Player p,JsonObject data,String kind,JsonObject row){
|
||||
if(!row.has("gameBranding")){
|
||||
UUID player=p.getUniqueId(),world=p.getWorld().getUID(),request=UUID.randomUUID();
|
||||
UUID id=UUID.fromString(row.get("id").getAsString());brandingRequests.put(player,request);
|
||||
String type=kind.equals("clans")?"clan":kind.equals("companies")?"company":"protected";
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin,()->{
|
||||
JsonObject branding;
|
||||
try{branding=bridge.organisationBranding(player,type,id);}
|
||||
catch(Exception unavailable){branding=new JsonObject();}
|
||||
JsonObject result=branding;
|
||||
if(plugin.isEnabled())Bukkit.getScheduler().runTask(plugin,()->{
|
||||
if(!brandingRequests.remove(player,request)||!p.isOnline()||!world.equals(p.getWorld().getUID()))return;
|
||||
row.add("gameBranding",result);
|
||||
organisation(p,data,kind,row);
|
||||
});
|
||||
});
|
||||
return;
|
||||
}
|
||||
boolean company=!kind.equals("clans"),manage=row.get("canManage").getAsBoolean();String title=name(row);var panel=panel(p,title,kind.equals("clans")?1:kind.equals("companies")?2:3);
|
||||
var identity=row.getAsJsonObject("gameBranding");
|
||||
String logo=identity.has("logoPng")&&!identity.get("logoPng").isJsonNull()?identity.get("logoPng").getAsString():"";
|
||||
var advisor=identity.has("mentat")&&identity.get("mentat").isJsonObject()?identity.getAsJsonObject("mentat"):null;
|
||||
String advisorName=advisor==null?"":advisor.get("name").getAsString();
|
||||
panel.branding=new MenuDocument.Branding(logo,advisorName,advisor==null?-1:advisor.get("portrait").getAsInt());
|
||||
int count=row.has("members")?row.getAsJsonArray("members").size():1;String role=manage?"Leader / manager":"Member";
|
||||
JsonObject home=row.has("homeBlock")&&!row.get("homeBlock").isJsonNull()?row.getAsJsonObject("homeBlock"):null;
|
||||
String homeText=home==null?"Not set":home.get("worldName").getAsString();
|
||||
|
|
@ -164,7 +187,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){if(BedrockForms.isBedrock(p)){BedrockForms.show(plugin,p,panel.title,"Current organisation keys",List.copyOf(panel.choices.values()));return;}if(MCGUIMenus.show(p,panel.title,"Current organisation keys",panel.inventory,panel.actions,panel.gate))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(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();}
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff