forked from unimatrix/web
Finish NPC and preview routing and retire old GUI release files
This commit is contained in:
parent
9144318f5f
commit
ef7163ac96
4 changed files with 24 additions and 133 deletions
|
|
@ -6,12 +6,16 @@ import java.util.List;
|
|||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
/** Routes menu-only calls made by the existing server commands and NPCs. */
|
||||
final class NativeMenuRoutes implements AutoCloseable {
|
||||
private static final NamespacedKey GUILD_NAVIGATOR = new NamespacedKey("dunerealms", "guild");
|
||||
private static final List<String> COMMANDS = List.of("dunecore:dune", "duneess:duneess", "duneess:exchange", "duneess:dune");
|
||||
private static final Map<String, String> DUNE_SERVICES = Map.ofEntries(
|
||||
Map.entry("menu", "dm"), Map.entry("faction", "house"), Map.entry("house", "house"),
|
||||
|
|
@ -34,13 +38,20 @@ final class NativeMenuRoutes implements AutoCloseable {
|
|||
if (name.equals("duneess:dune")) {
|
||||
String target = duneService(args);
|
||||
if (target != null) {
|
||||
return plugin.getCommand(target).execute(sender, "dune " + args[0],
|
||||
Arrays.copyOfRange(args, 1, args.length));
|
||||
PluginCommand destination = plugin.getCommand(target);
|
||||
if (destination != null)
|
||||
return destination.execute(sender, "dune " + args[0], Arrays.copyOfRange(args, 1, args.length));
|
||||
}
|
||||
}
|
||||
String menu = menuFor(name, args);
|
||||
if (menu != null && sender instanceof Player player && player.hasPermission("dunemenus.use")) {
|
||||
plugin.create(menu, player, null).open();
|
||||
if (name.equals("duneess:duneess") && menu.equals("travel") && player.isSneaking()
|
||||
&& player.getNearbyEntities(5, 3, 5).stream().anyMatch(entity -> entity instanceof Villager
|
||||
&& entity.getPersistentDataContainer().has(GUILD_NAVIGATOR, PersistentDataType.BYTE))) {
|
||||
plugin.openNativeQuestContact(player, "guild_navigator");
|
||||
} else {
|
||||
plugin.openMenu(player, menu);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return original.onCommand(sender, invoked, label, args);
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ public abstract class DuneServicesPlugin extends JavaPlugin implements Listener,
|
|||
Bukkit.getScheduler().runTaskTimer(this,this::tick,20L,20L);
|
||||
Bukkit.getScheduler().runTaskLater(this,this::ensureRegistrar,40L);
|
||||
new QuartermasterNpc(this,p->quests.quartermaster(p,()->exchange.open(p),()->exchange.openKits(p)));
|
||||
polQuestNpcs=new PolQuestNpc(this,(p,role)->{if(role.key().equals("war_marshal"))openMenu(p,"war");else if(role.key().equals("guild_navigator"))openMenu(p,"travel");else quests.openRole(p,role);});
|
||||
polQuestNpcs=new PolQuestNpc(this,(p,role)->{if(role.key().equals("war_marshal"))openMenu(p,"war");else quests.openRole(p,role);});
|
||||
Bukkit.getScheduler().runTaskTimer(this,()->{for(Player p:Bukkit.getOnlinePlayers()){refreshSidebar(p);}},80L,600L);
|
||||
getLogger().info("House selector and Mentat screens enabled; central J.A.R.V.I.S. bridge; no Core/Lobby replacement.");
|
||||
}
|
||||
|
|
@ -194,7 +194,7 @@ public abstract class DuneServicesPlugin extends JavaPlugin implements Listener,
|
|||
for(int i=0;i<GuildRoutes.ALL.size();i++){
|
||||
var route=GuildRoutes.ALL.get(i);boolean allowed=allowedDestinations.contains(route.world());
|
||||
String unavailable="Unavailable · another House world";
|
||||
var item=icon(p,route.name(),allowed?detail:unavailable,"drgui_transparent",allowed?Material.ENDER_PEARL:Material.GRAY_DYE);
|
||||
var item=icon(route.name(),allowed?detail:unavailable,allowed?Material.ENDER_PEARL:Material.GRAY_DYE);
|
||||
int centre=CENTRES[i];
|
||||
for(int row=i<3?-1:0;row<=1;row++)for(int col=-1;col<=1;col++){
|
||||
int slot=centre+row*9+col;
|
||||
|
|
@ -303,7 +303,7 @@ public abstract class DuneServicesPlugin extends JavaPlugin implements Listener,
|
|||
String current=selection(data),chosen=picked!=null?picked:current;
|
||||
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);
|
||||
var item=icon(houseName(data,id),selected?"Your current House":"Declare allegiance to this House",Material.PAPER);menuArt(item,"house_"+id);
|
||||
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);}
|
||||
}
|
||||
|
|
@ -328,7 +328,7 @@ public abstract class DuneServicesPlugin extends JavaPlugin implements Listener,
|
|||
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);
|
||||
Screen screen=screen(p,"Your Mentat · "+name,0xE310+index);
|
||||
var portrait=icon(p,name,houseName(data,house),"drgui_transparent",Material.PLAYER_HEAD);menuArt(portrait,"mentat_"+house);screen.inventory.setItem(13,portrait);
|
||||
var portrait=icon(name,houseName(data,house),Material.PLAYER_HEAD);menuArt(portrait,"mentat_"+house);screen.inventory.setItem(13,portrait);
|
||||
button(screen,p,38,"Open Mentat Report","Personal level, Reputation and active quests",Material.WRITABLE_BOOK,()->quests.open(p));
|
||||
button(screen,p,42,"Spacing Guild travel","Book passage to your House world",Material.COMPASS,()->openGuild(p,null));
|
||||
button(screen,p,45,"Your House",houseName(data,house),Material.ARROW,()->select(p,data,house));
|
||||
|
|
@ -339,8 +339,8 @@ public abstract class DuneServicesPlugin extends JavaPlugin implements Listener,
|
|||
private static void menuArt(ItemStack item,String artwork){var meta=item.getItemMeta();meta.getPersistentDataContainer().set(new NamespacedKey("dunerealms","menu_art"),PersistentDataType.STRING,artwork);item.setItemMeta(meta);}
|
||||
private void report(Player p){p.closeInventory();p.sendMessage(Component.text("Open your Mentat Report →",NamedTextColor.GOLD).clickEvent(net.kyori.adventure.text.event.ClickEvent.openUrl("https://clans.dunerealms.com/#quests/quests")));}
|
||||
private Screen screen(Player p,String title,int glyph){Screen s=new Screen(p);Component heading=guiPackLoaded.contains(p.getUniqueId())?Component.text(GuiArtwork.background(glyph),NamedTextColor.WHITE).font(Key.key("dunerealms:house_selector")):Component.text(title,NamedTextColor.GOLD);s.inventory=Bukkit.createInventory(s,54,heading);return s;}
|
||||
private ItemStack icon(Player p,String title,String description,String model,Material fallback){ItemStack item=new ItemStack(guiPackLoaded.contains(p.getUniqueId())?Material.PAPER:fallback);var meta=item.getItemMeta();meta.displayName(Component.text(title,NamedTextColor.GOLD));meta.lore(List.of(Component.text(description,NamedTextColor.GRAY)));if(guiPackLoaded.contains(p.getUniqueId()))meta.setItemModel(new NamespacedKey("dunerealms",model));item.setItemMeta(meta);return item;}
|
||||
private void button(Screen s,Player p,int slot,String title,String description,Material material,Runnable action){s.inventory.setItem(slot,icon(p,title,description,"drgui_transparent",material));s.actions.put(slot,action);}
|
||||
private ItemStack icon(String title,String description,Material material){ItemStack item=new ItemStack(material);var meta=item.getItemMeta();meta.displayName(Component.text(title,NamedTextColor.GOLD));meta.lore(List.of(Component.text(description,NamedTextColor.GRAY)));item.setItemMeta(meta);return item;}
|
||||
private void button(Screen s,Player p,int slot,String title,String description,Material material,Runnable action){s.inventory.setItem(slot,icon(title,description,material));s.actions.put(slot,action);}
|
||||
private void expire(Screen screen){Bukkit.getScheduler().runTaskLater(this,screen.gate::expire,2400L);}
|
||||
@EventHandler public void click(InventoryClickEvent event){if(!(event.getView().getTopInventory().getHolder() instanceof Screen s))return;event.setCancelled(true);
|
||||
if(!(event.getWhoClicked() instanceof Player p)||!p.getUniqueId().equals(s.owner)||event.getClickedInventory()!=s.inventory||event.getClick()!=ClickType.LEFT)return;
|
||||
|
|
|
|||
|
|
@ -229,7 +229,7 @@ final class OrganisationMenus implements Listener {
|
|||
}
|
||||
private Panel panel(Player p,String title,boolean company){var panel=new Panel(p);panel.title=title;panel.inventory=Bukkit.createInventory(panel,54,Component.text(title,company?NamedTextColor.AQUA:NamedTextColor.GOLD));for(int slot=0;slot<54;slot++)if(slot<9||slot>=45||slot%9==0||slot%9==8){var trim=new ItemStack(company?Material.CYAN_STAINED_GLASS_PANE:Material.GREEN_STAINED_GLASS_PANE);var meta=trim.getItemMeta();meta.displayName(Component.empty());trim.setItemMeta(meta);panel.inventory.setItem(slot,trim);}return panel;}
|
||||
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 put(Panel panel,int slot,String title,String description,Material material,Runnable action){var item=new ItemStack(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());item.setItemMeta(meta);panel.inventory.setItem(slot,item);panel.actions.put(slot,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){plugin.showService(p,"politics",panel.title,"Current organisation keys",panel.inventory,panel.actions,panel.gate);}
|
||||
@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();});}
|
||||
|
|
|
|||
|
|
@ -203,7 +203,7 @@ final class QuestMenus implements Listener {
|
|||
var available=new ArrayList<JsonObject>();for(var e:data.getAsJsonArray("quests")){var q=e.getAsJsonObject();if(roleAllowed(data,role,q)&&!text(q,"state","").equals("claimed")&&(Set.of("active","completed").contains(text(q,"state",""))||yes(q,"canStart")))available.add(q);}
|
||||
if(selected!=null){var row=available.stream().filter(q->selected.equals(text(q,"id",""))).findFirst().orElse(null);if(row!=null){roleSelected(p,data,role,row);return;}}
|
||||
var screen=panel(p,"NPC dashboard · "+role.name());screen.description="";roleAvatar(screen,data,role);int active=0,ready=0,claimed=0;for(var e:data.getAsJsonArray("quests")){var q=e.getAsJsonObject();if(!roleAllowed(data,role,q))continue;if(text(q,"state","").equals("claimed"))claimed++;else if(yes(q,"canClaim"))ready++;else if(text(q,"state","").equals("active"))active++;}String stats=active+" active · "+ready+" ready · "+claimed+" claimed";if(data.has("npcSummary")&&data.get("npcSummary").isJsonObject()){var rep=data.getAsJsonObject("npcSummary");stats+="\nReputation "+text(rep,"xp","—")+" / "+text(rep,"nextXP","—");if(rep.has("percent")&&!rep.get("percent").isJsonNull())stats+="\nProgress: "+Math.max(0,Math.min(100,rep.get("percent").getAsInt()))+"%";}put(screen,5,"Mission overview",stats,Material.PAPER,null);var summary=screen.inventory.getItem(5);var meta=summary.getItemMeta();meta.getPersistentDataContainer().set(new NamespacedKey("dunerealms","menu_art"),org.bukkit.persistence.PersistentDataType.STRING,"npc_summary");summary.setItemMeta(meta);screen.inventory.setItem(5,summary);var ordered=new ArrayList<JsonObject>(available);ordered.sort(Comparator.comparingInt(q->Set.of("active","completed").contains(text(q,"state",""))?0:1));
|
||||
int slot=9;for(var q:ordered){if(slot>=45)break;String status=Set.of("active","completed").contains(text(q,"state",""))?"Progress: "+text(q,"progress","0")+" / "+text(q,"target","1"):"Eligible to accept";put(screen,slot++,text(q,"title","Mission"),status+"\n"+text(q,"id","")+" · "+text(q,"objective",""),Material.WRITABLE_BOOK,()->roleSelected(p,data,role,q));}
|
||||
int slot=9;for(var q:ordered){if(slot>=45)break;boolean start=yes(q,"canStart")&&!website(q)&&!Set.of("active","completed").contains(text(q,"state",""));String status=start?"Click to accept":"Progress: "+text(q,"progress","0")+" / "+text(q,"target","1");Runnable action=start?()->act(p,"pol",text(q,"branch",""),0,q,"start"):()->roleSelected(p,data,role,q);put(screen,slot++,text(q,"title","Mission"),status+"\n"+text(q,"objective",""),Material.WRITABLE_BOOK,action);}
|
||||
if(ordered.isEmpty())put(screen,13,"No eligible missions","Read the website journal for the full record.",Material.MAP,null);
|
||||
if(role.key().equals("esmar_tuek"))put(screen,47,role.world().equals("guild_lobby")?"Personal smuggler passage":"Smuggler return",role.world().equals("guild_lobby")?"Opt in with Esmar or board your paid one-hour personal route.":"Return to the Guild from your confirmed smuggler arrival.",Material.COMPASS,()->{if(role.world().equals("guild_lobby"))smugglerMenu(p,data,role);else try{bridge.returnSmuggler(p);}catch(Exception failure){p.sendMessage("Meet Esmar Tuek on Arrakis to return.");}});
|
||||
if(Set.of("thufir_hawat","piter_de_vries","hasimir_fenring","roma_atani","imperial_attendant","stilgar","jessica_atreides","gaius_helen_mohiam","alia_atreides","edric","guild_navigator","duncan_idaho").contains(role.key()))put(screen,48,"POL decisions","See only current executable political decisions",Material.BOOK,()->openDecisions(p,0));put(screen,49,"Website journal","Full mission choices and history",Material.MAP,()->website(p));show(p,screen);
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff