Connect Guild and Smuggler Navigator routes to JARVIS
This commit is contained in:
parent
af33fc87b9
commit
4da7c00ffe
1 changed files with 551 additions and 33 deletions
|
|
@ -136,19 +136,56 @@ public final class DuneGUI extends JavaPlugin implements Listener,CommandExecuto
|
|||
private void travelMenu(Player p,JsonObject data){var q=new JsonObject();q.addProperty("action","quote");guildRequest(p,q,quote->{data.add("guildQuote",quote);renderTravelMenu(p,data);});}
|
||||
private void guildRequest(Player p,JsonObject input,Consumer<JsonObject> done){UUID id=p.getUniqueId(),world=p.getWorld().getUID();if(!boarding.add(id)){p.sendMessage("J.A.R.V.I.S. is processing your passage.");return;}Bukkit.getScheduler().runTaskAsynchronously(this,()->{JsonObject result=null;String failure=null;try{result=bridge.guild(id,input);}catch(Exception e){failure=e.getMessage();}var response=result;String message=failure;if(!isEnabled())return;Bukkit.getScheduler().runTask(this,()->{if(!boarding.remove(id)||!p.isOnline()||!p.getWorld().getUID().equals(world))return;if(response==null){p.sendMessage(message==null?"The central Guild service is unavailable.":message);return;}done.accept(response);});});}
|
||||
private void renderTravelMenu(Player p,JsonObject data){
|
||||
String house=selection(data);var home=GuildRoutes.home(house);if(home==null){select(p,data,null);return;}if(data.getAsJsonObject("guildQuote").has("prologueRequired")&&data.getAsJsonObject("guildQuote").get("prologueRequired").getAsBoolean()){p.sendMessage("Complete the House Prologue first: meet your matching named Mentat at the Guild spawn, finish your website account and profile, and obtain your original starter kit with /start.");mentat(p,data);return;}
|
||||
String house=selection(data);var home=GuildRoutes.home(house);if(home==null){select(p,data,null);return;}
|
||||
var passage = data.getAsJsonObject("guildQuote");
|
||||
var eligible = quotedDestinations(passage);
|
||||
var catalog = GuildRoutes.catalog(passage);
|
||||
String quote="Guild fare: "+String.format(java.util.Locale.ROOT,"%.2f",data.getAsJsonObject("guildQuote").get("fareMinor").getAsInt()/100.0)+" DM from your central personal bank account. Collected after arrival."+(data.getAsJsonObject("guildQuote").has("subsidyMinor")?" Guild subsidy: "+String.format(java.util.Locale.ROOT,"%.2f",data.getAsJsonObject("guildQuote").get("subsidyMinor").getAsInt()/100.0)+" DM.":"");
|
||||
var booked=bookings.get(p.getUniqueId());String detail=quote+"\nTravel opens at :00, :20 and :40 for five minutes."+(booked==null?"":"\nYour passage is already booked.");
|
||||
if(BedrockForms.isBedrock(p)){List<BedrockForms.Choice> choices=new ArrayList<>();for(var route:GuildRoutes.ALL){boolean allowed=quotedDestinations(data.getAsJsonObject("guildQuote")).contains(route.world());choices.add(new BedrockForms.Choice((allowed?"§6":"§8")+route.name()+(allowed?(route.house().equals(house)?" · Your House":" · Imperial passage"):" · Unavailable"),allowed?detail:"Another House world",allowed?()->bookPassage(p,data,route.world()):()->travelMenu(p,data),"https://www.dunerealms.com/assets/gui/guild-world-"+route.world().replace('_','-')+(allowed?"":"-locked")+"-v1.png"));}choices.add(new BedrockForms.Choice("Cancel booking","No fare has been charged",()->{cancelBooking(p);travelMenu(p,data);}));choices.add(new BedrockForms.Choice("Your Mentat","Return to your House adviser",()->mentat(p,data)));BedrockForms.show(this,p,"Spacing Guild · Imperial passage",detail,choices);return;}
|
||||
if(BedrockForms.isBedrock(p)){
|
||||
List<BedrockForms.Choice> choices=new ArrayList<>();
|
||||
for(var route:GuildRoutes.ALL){
|
||||
var offer=catalog.get(route.world());
|
||||
String reason=offer==null?guildUnavailable(passage,eligible,route.world()):offer.available()?null:offer.reason();
|
||||
String name=offer==null?route.name():offer.name();
|
||||
choices.add(new BedrockForms.Choice((reason==null?"§6":"§8")+name+(reason==null?"":" · "+reason),
|
||||
reason==null?detail:reason,reason==null?()->bookPassage(p,data,route.world()):()->{p.sendMessage(reason);renderTravelMenu(p,data);},
|
||||
"https://www.dunerealms.com/assets/gui/guild-world-"+route.world().replace('_','-')+(reason==null?"":"-locked")+"-v1.png"));
|
||||
}
|
||||
choices.add(new BedrockForms.Choice("Cancel booking","No fare has been charged",()->{cancelBooking(p);travelMenu(p,data);}));
|
||||
choices.add(new BedrockForms.Choice("Your Mentat","Return to your House adviser",()->mentat(p,data)));
|
||||
BedrockForms.show(this,p,"Spacing Guild · Imperial passage",detail,choices);return;
|
||||
}
|
||||
int own=Arrays.asList(IDS).indexOf(house);Screen screen=screen(p,"Spacing Guild · Imperial passage",0xE330+own);
|
||||
for(int i=0;i<GuildRoutes.ALL.size();i++){var route=GuildRoutes.ALL.get(i);boolean allowed=quotedDestinations(data.getAsJsonObject("guildQuote")).contains(route.world());var item=icon(p,route.name(),allowed?detail:"Unavailable · another House world","drgui_transparent",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;screen.inventory.setItem(slot,item.clone());if(allowed)screen.actions.put(slot,()->bookPassage(p,data,route.world()));}}
|
||||
for(int i=0;i<GuildRoutes.ALL.size();i++){
|
||||
var route=GuildRoutes.ALL.get(i);
|
||||
var offer=catalog.get(route.world());
|
||||
String reason=offer==null?guildUnavailable(passage,eligible,route.world()):offer.available()?null:offer.reason();
|
||||
String name=offer==null?route.name():offer.name();
|
||||
int centre=CENTRES[i];
|
||||
var item=icon(p,name,reason==null?detail:reason,"drgui_transparent",reason==null?Material.ENDER_PEARL:Material.GRAY_DYE);
|
||||
if(reason!=null){
|
||||
var meta=item.getItemMeta();meta.displayName(Component.text(name,NamedTextColor.GRAY));item.setItemMeta(meta);
|
||||
}
|
||||
screen.inventory.setItem(centre,item);
|
||||
if(reason==null){
|
||||
Runnable book=()->bookPassage(p,data,route.world());
|
||||
for(int row=i<3?-1:0;row<=1;row++)for(int col=-1;col<=1;col++)screen.actions.put(centre+row*9+col,book);
|
||||
}
|
||||
}
|
||||
button(screen,p,45,"Your Mentat","Return to your House adviser",Material.ARROW,()->mentat(p,data));screen.actions.put(46,screen.actions.get(45));
|
||||
button(screen,p,49,"Cancel booking","No fare is taken for a cancelled booking",Material.BARRIER,()->{cancelBooking(p);travelMenu(p,data);});for(int slot:new int[]{48,50})screen.actions.put(slot,screen.actions.get(49));
|
||||
if(guild!=null){button(screen,p,53,booked==null?"Book passage":"Review booked passage",detail,Material.EMERALD,()->bookPassage(p,data));screen.actions.put(52,screen.actions.get(53));}
|
||||
if(guild!=null&&booked!=null){button(screen,p,53,"Review booked passage",detail,Material.EMERALD,()->bookPassage(p,data));screen.actions.put(52,screen.actions.get(53));}
|
||||
if(MCGUIMenus.show(p,"Spacing Guild · Imperial passage","",screen.inventory,screen.actions,screen.gate))return;
|
||||
p.openInventory(screen.inventory);expire(screen);
|
||||
}
|
||||
private void cancelBooking(Player p){boolean removed=bookings.cancel(p.getUniqueId());removed=boarding.remove(p.getUniqueId())||removed;p.sendMessage(removed?"Guild passage cancelled. No fare was charged.":"You have no pending Guild booking.");}
|
||||
private static String guildUnavailable(JsonObject quote,Set<String> eligible,String world){
|
||||
if(quote.has("prologueRequired")&"e.get("prologueRequired").getAsBoolean())return "Complete your House Prologue.";
|
||||
if(!eligible.contains(world))return "This route is unavailable under your current Guild passage.";
|
||||
if(!quote.get("affordable").getAsBoolean())return "Insufficient available funds in your personal account.";
|
||||
return null;
|
||||
}
|
||||
private static Set<String> quotedDestinations(JsonObject quote){Set<String> worlds=new HashSet<>();if(quote.has("destinations"))for(var value:quote.getAsJsonArray("destinations"))worlds.add(value.getAsString());else worlds.add(quote.get("destination").getAsString());return Set.copyOf(worlds);}
|
||||
private void bookPassage(Player p,JsonObject shown){var booked=bookings.get(p.getUniqueId());bookPassage(p,shown,booked==null?GuildRoutes.home(selection(shown)).world():booked.world());}
|
||||
private void bookPassage(Player p,JsonObject shown,String destination){
|
||||
|
|
@ -185,7 +222,7 @@ public final class DuneGUI extends JavaPlugin implements Listener,CommandExecuto
|
|||
}
|
||||
private void updateSidebar(Player p,JsonObject data){String house=selection(data),label=house==null?null:houseName(data,house);sidebar.update(p,data,label);nameplates.update(p,data,house,label);}
|
||||
private void toggleSidebar(Player p){sidebar.toggle(p);p.sendMessage(Component.text(sidebar.enabled(p)?"Personal scoreboard enabled.":"Personal scoreboard hidden.",NamedTextColor.GOLD));if(sidebar.enabled(p)){JsonObject data=records.get(p.getUniqueId());if(data!=null)updateSidebar(p,data);refreshSidebar(p);}}
|
||||
@EventHandler(priority=EventPriority.HIGHEST,ignoreCancelled=false) public void organisationContact(org.bukkit.event.player.PlayerInteractEntityEvent event){String marker=event.getRightClicked().getPersistentDataContainer().get(new NamespacedKey("dunerealms","organisation_home_npc"),PersistentDataType.STRING);if(marker==null)return;event.setCancelled(true);if(event.getHand()!=org.bukkit.inventory.EquipmentSlot.HAND)return;String[] parts=marker.split(":",2);if(parts.length!=2||!Set.of("clan","company").contains(parts[0]))return;try{String id=UUID.fromString(parts[1]).toString();organisations.openHomeNpc(event.getPlayer(),parts[0].equals("clan")?"clans":"companies",id);}catch(IllegalArgumentException ignored){}}
|
||||
@EventHandler(priority=EventPriority.HIGHEST,ignoreCancelled=false) public void organisationContact(org.bukkit.event.player.PlayerInteractEntityEvent event){String marker=event.getRightClicked().getPersistentDataContainer().get(new NamespacedKey("dunerealms","organisation_home_npc"),PersistentDataType.STRING);if(marker==null)return;event.setCancelled(true);if(event.getHand()!=org.bukkit.inventory.EquipmentSlot.HAND)return;String[] parts=marker.split(":",2);if(parts.length!=2||!Set.of("clan","company").contains(parts[0]))return;try{String id=UUID.fromString(parts[1]).toString();organisations.openHomeNpc(event.getPlayer(),parts[0].equals("clan")?"clans":"companies",id,event.getRightClicked().getUniqueId());}catch(IllegalArgumentException ignored){}}
|
||||
@EventHandler public void scoreboardCommand(PlayerCommandPreprocessEvent e){String command=e.getMessage().trim();if(command.equalsIgnoreCase("/scoreboard")){e.setCancelled(true);toggleSidebar(e.getPlayer());}}
|
||||
@EventHandler(priority=EventPriority.HIGHEST) public void oldNavigator(PlayerInteractEvent e){if(e.getHand()!=EquipmentSlot.HAND||e.getItem()==null||!e.getItem().hasItemMeta()||!e.getAction().isRightClick())return;var data=e.getItem().getItemMeta().getPersistentDataContainer();for(var key:data.getKeys())if(data.has(key,PersistentDataType.STRING)&&"menu_opener".equals(data.get(key,PersistentDataType.STRING))){e.setCancelled(true);if(!SuppliedMenus.open(e.getPlayer(),"hub"))organisations.console(e.getPlayer());return;}}
|
||||
@EventHandler(priority=EventPriority.LOWEST,ignoreCancelled=true) public void legacyTravel(PlayerCommandPreprocessEvent e){String[] args=e.getMessage().substring(1).trim().toLowerCase(Locale.ROOT).split("\\s+");String label=args[0].replaceFirst("^[^:]+:","");if(label.equals("balance")||label.equals("bal")||label.equals("money")){e.setCancelled(true);if(!sidebar.enabled(e.getPlayer()))sidebar.toggle(e.getPlayer());refreshSidebar(e.getPlayer());return;}if(label.equals("exchange")){e.setCancelled(true);exchange.open(e.getPlayer());return;}if(label.equals("server")||label.equals("duneess")&&args.length>1&&args[1].equals("travel")){e.setCancelled(true);if(!SuppliedMenus.open(e.getPlayer(),"travel"))openGuild(e.getPlayer(),null);}}
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff