Add text commands for paid deliveries and Guild bookings
This commit is contained in:
parent
e56f3e7392
commit
618c611d82
4 changed files with 49 additions and 12 deletions
|
|
@ -92,8 +92,8 @@ public final class DuneGUI extends JavaPlugin implements Listener,CommandExecuto
|
|||
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&&command.getName().equals("sellall")){spice.sellAll(p,args.length==0?"guild":args[0].toLowerCase(Locale.ROOT));return true;}
|
||||
if(sender instanceof Player p&&(command.getName().equals("spice")||command.getName().equals("drgui")&&args.length==1&&args[0].equalsIgnoreCase("spice"))){spice.open(p);return true;}
|
||||
if(sender instanceof Player player&&(command.getName().equals("exchange")||command.getName().equals("drgui")&&args.length==1&&args[0].equalsIgnoreCase("exchange"))){exchange.open(player);return true;}
|
||||
if(sender instanceof Player p&&(command.getName().equals("spice")||command.getName().equals("drgui")&&args.length==1&&args[0].equalsIgnoreCase("spice"))){spice.command(p,command.getName().equals("spice")?args:new String[0]);return true;}
|
||||
if(sender instanceof Player player&&(command.getName().equals("exchange")||command.getName().equals("drgui")&&args.length==1&&args[0].equalsIgnoreCase("exchange"))){exchange.command(player,command.getName().equals("exchange")?args:new String[0]);return true;}
|
||||
if(sender instanceof Player player&&command.getName().equals("drgui")&&args.length>0&&args[0].equalsIgnoreCase("previewitem")){try{if(args.length!=3)throw new IllegalArgumentException();int revision=Integer.parseInt(args[2]);if(revision<1||revision>999999)throw new IllegalArgumentException();itemPreviews.open(player,UUID.fromString(args[1]),revision);}catch(IllegalArgumentException invalid){player.sendMessage("Use /drgui previewitem <saved-design-id> <revision>");}return true;}
|
||||
if(sender instanceof Player player&&command.getName().equals("drgui")&&args.length==1&&args[0].equalsIgnoreCase("quests")){quests.open(player);return true;}
|
||||
if(sender instanceof Player player&&command.getName().equals("drgui")&&args.length==2&&args[0].equalsIgnoreCase("movenpc")){polQuestNpcs.move(player,args[1]);return true;}
|
||||
|
|
@ -122,7 +122,8 @@ public final class DuneGUI extends JavaPlugin implements Listener,CommandExecuto
|
|||
p.sendMessage("Loading the DuneRealms GUI pack. Reopen your menu after loading.");return true;
|
||||
}
|
||||
if(command.getName().equals("drscoreboard")||args.length==1&&args[0].equalsIgnoreCase("scoreboard")){toggleSidebar(p);return true;}
|
||||
if(command.getName().equals("guildtravel")||args.length==1&&args[0].equalsIgnoreCase("travel")){if(args.length==1&&args[0].equalsIgnoreCase("cancel")){cancelBooking(p);return true;}openGuild(p,null);return true;}
|
||||
if(command.getName().equals("guildtravel")){guildCommand(p,args);return true;}
|
||||
if(args.length==1&&args[0].equalsIgnoreCase("travel")){openGuild(p,null);return true;}
|
||||
fetch(p,null,0,null,data->{if(command.getName().equals("mentat")&&selection(data)!=null)mentat(p,data);else select(p,data,null);});return true;
|
||||
}
|
||||
private void giveCodex(Player p,boolean explain){
|
||||
|
|
@ -138,6 +139,25 @@ public final class DuneGUI extends JavaPlugin implements Listener,CommandExecuto
|
|||
var data=item.getItemMeta().getPersistentDataContainer();for(var key:data.getKeys())if(data.has(key,PersistentDataType.STRING)&&"menu_opener".equals(data.get(key,PersistentDataType.STRING))){inventory.setItem(slot,null);break;}
|
||||
}
|
||||
}
|
||||
private void guildCommand(Player player,String[] args){
|
||||
if(args.length==0){openGuild(player,null);return;}
|
||||
if(args.length==1&&args[0].equalsIgnoreCase("cancel")){cancelBooking(player);return;}
|
||||
if(args.length==1&&args[0].equalsIgnoreCase("status")){
|
||||
var booking=bookings.get(player.getUniqueId());
|
||||
player.sendMessage(booking==null?"You have no pending Guild booking.":"Booked to "+booking.world()+" · "+String.format(Locale.ROOT,"%.2f DM",booking.fare()/100.0));
|
||||
return;
|
||||
}
|
||||
if(args.length==2&&args[0].equalsIgnoreCase("book")){
|
||||
if(!lobby(player)){player.sendMessage("Return to the Spacing Guild before booking passage.");return;}
|
||||
String destination=args[1].toLowerCase(Locale.ROOT).replace('-','_');
|
||||
if(GuildRoutes.ALL.stream().noneMatch(route->route.world().equals(destination)&&!destination.equals("lobby"))){
|
||||
player.sendMessage("Guild destinations: "+String.join(", ",GuildRoutes.ALL.stream().map(GuildRoutes.Route::world).toList()));return;
|
||||
}
|
||||
fetch(player,null,0,null,data->bookPassage(player,data,destination,false));
|
||||
return;
|
||||
}
|
||||
player.sendMessage("Use /guildtravel [status|cancel|book <world>].");
|
||||
}
|
||||
private void openGuild(Player p,String requested){if(!lobby(p)){try{bridge.returnGuild(p);}catch(Exception unavailable){p.sendMessage("The Guild could not confirm your return. Please retry.");}return;}fetch(p,null,0,null,data->{String house=selection(data);if(house==null){p.sendMessage("Choose and confirm your House before Guild passage.");select(p,data,null);return;}travelMenu(p,data);});}
|
||||
private static GuildBookings.Permit permit(JsonObject data){String house=selection(data);if(house==null||!data.has("keyId")||data.get("keyId").isJsonNull())return null;try{return new GuildBookings.Permit(house,UUID.fromString(data.get("keyId").getAsString()),data.get("version").getAsInt());}catch(RuntimeException invalid){return null;}}
|
||||
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);});}
|
||||
|
|
@ -158,11 +178,12 @@ public final class DuneGUI extends JavaPlugin implements Listener,CommandExecuto
|
|||
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 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){
|
||||
private void bookPassage(Player p,JsonObject shown,String destination){bookPassage(p,shown,destination,true);}
|
||||
private void bookPassage(Player p,JsonObject shown,String destination,boolean reopen){
|
||||
if(boarding.contains(p.getUniqueId())){p.sendMessage("Guild boarding is already being confirmed.");return;}
|
||||
var expected=permit(shown);if(expected==null){p.sendMessage("Confirm your current House key before booking passage.");select(p,shown,selection(shown));return;}
|
||||
fetch(p,null,0,null,fresh->{var current=permit(fresh);if(current==null||!current.equals(expected)){p.sendMessage("Your House key changed. Review the current passage.");travelMenu(p,fresh);return;}
|
||||
var q=new JsonObject();q.addProperty("action","quote");guildRequest(p,q,quote->{if(!quote.get("affordable").getAsBoolean()){p.sendMessage("Not enough available Dunemarks in your central personal bank account.");return;}var home=GuildRoutes.ALL.stream().filter(r->r.world().equals(destination)).findFirst().orElseThrow();int fare=quote.get("fareMinor").getAsInt();if(!quotedDestinations(quote).contains(destination)){p.sendMessage("Your House destination changed. Reopen the menu.");return;}var booked=bookings.book(p.getUniqueId(),current,home.world(),fare,Instant.now().getEpochSecond(),quotedDestinations(quote));p.closeInventory();p.sendMessage(Component.text("Passage booked to "+home.name()+". Fare "+String.format(java.util.Locale.ROOT,"%.2f",booked.fare()/100.0)+" DM is reserved at boarding and collected after arrival.",NamedTextColor.GOLD));});
|
||||
var expected=permit(shown);if(expected==null){p.sendMessage("Confirm your current House key before booking passage.");if(reopen)select(p,shown,selection(shown));return;}
|
||||
fetch(p,null,0,null,fresh->{var current=permit(fresh);if(current==null||!current.equals(expected)){p.sendMessage("Your House key changed. Review the current passage.");if(reopen)travelMenu(p,fresh);return;}
|
||||
var q=new JsonObject();q.addProperty("action","quote");guildRequest(p,q,quote->{if(!quote.get("affordable").getAsBoolean()){p.sendMessage("Not enough available Dunemarks in your central personal bank account.");return;}if(!quotedDestinations(quote).contains(destination)){p.sendMessage("This destination is unavailable under your current Guild passage.");return;}var home=GuildRoutes.ALL.stream().filter(r->r.world().equals(destination)).findFirst().orElseThrow();int fare=quote.get("fareMinor").getAsInt();var booked=bookings.book(p.getUniqueId(),current,home.world(),fare,Instant.now().getEpochSecond(),quotedDestinations(quote));p.closeInventory();p.sendMessage(Component.text("Passage booked to "+home.name()+". Fare "+String.format(java.util.Locale.ROOT,"%.2f",booked.fare()/100.0)+" DM is reserved at boarding and collected after arrival.",NamedTextColor.GOLD));});
|
||||
});
|
||||
}
|
||||
private void board(GuildBookings.Booking booking){
|
||||
|
|
@ -195,7 +216,7 @@ public final class DuneGUI extends JavaPlugin implements Listener,CommandExecuto
|
|||
@EventHandler(priority=EventPriority.HIGHEST,ignoreCancelled=true) 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 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);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);openGuild(e.getPlayer(),null);}}
|
||||
@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.command(e.getPlayer(),Arrays.copyOfRange(args,1,args.length));return;}if(label.equals("server")||label.equals("duneess")&&args.length>1&&args[1].equals("travel")){e.setCancelled(true);openGuild(e.getPlayer(),null);}}
|
||||
private void offerGuiPack(Player p){offerGuiPack(p,true);}
|
||||
private void offerGuiPack(Player p,boolean force){
|
||||
if(!p.isOnline()||BedrockForms.isBedrock(p))return;
|
||||
|
|
|
|||
|
|
@ -27,6 +27,11 @@ final class ExchangeMenus implements Listener,AutoCloseable {
|
|||
}
|
||||
private final java.util.concurrent.ConcurrentMap<UUID,org.bukkit.conversations.Conversation> priceInputs=new java.util.concurrent.ConcurrentHashMap<>();
|
||||
ExchangeMenus(JavaPlugin plugin,HouseBridge bridge,Consumer<Player> back,Predicate<Player> artwork){this.plugin=plugin;this.bridge=bridge;this.back=back;this.artwork=artwork;Bukkit.getPluginManager().registerEvents(this,plugin);Bukkit.getScheduler().runTaskTimer(plugin,()->{for(Player p:Bukkit.getOnlinePlayers())deliver(p,false);},80L,1200L);}
|
||||
void command(Player player,String[] args){
|
||||
if(args.length==0)open(player);
|
||||
else if(args.length==1&&args[0].equalsIgnoreCase("collect"))deliver(player,true);
|
||||
else player.sendMessage("Use /exchange [collect].");
|
||||
}
|
||||
void open(Player p){deliver(p,false);var retry=retries.get(p.getUniqueId());if(retry!=null){purchase(p,retry);return;}list(p,false,0);}
|
||||
void openKits(Player p){deliver(p,false);kits(p,0);}
|
||||
private static String money(long value){return BigDecimal.valueOf(value,2).toPlainString()+" DM";}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,14 @@ final class SpiceMenus implements Listener {
|
|||
if(!arrakis(p)){p.sendMessage("Spice buyers are available on Arrakis only.");return;}if(!busy.add(p.getUniqueId())){p.sendMessage("Your spice sale is being processed.");return;}
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin,()->{JsonObject data=null;String error=null;try{data=bridge.spice(p.getUniqueId(),q);}catch(Exception e){error=e.getMessage();}var result=data;var message=error;if(!plugin.isEnabled())return;Bukkit.getScheduler().runTask(plugin,()->{busy.remove(p.getUniqueId());if(!p.isOnline())return;if(result==null||result.has("rejectedStatus")){p.sendMessage(result!=null&&result.has("message")?result.get("message").getAsString():message==null?"Spice service unavailable. No unconfirmed inventory sale is made; committed sales remain payable.":message);return;}done.accept(result);});});
|
||||
}
|
||||
void command(Player player,String[] args){
|
||||
if(args.length==0){open(player);return;}
|
||||
if(args.length==1&&args[0].equalsIgnoreCase("collect")){
|
||||
if(arrakis(player))recover(player);else player.sendMessage("Spice payments can be collected on Arrakis.");
|
||||
return;
|
||||
}
|
||||
player.sendMessage("Use /spice [collect] or /sellall [guild|smuggler].");
|
||||
}
|
||||
void open(Player p){open(p,null);}
|
||||
void open(Player p,String selected){
|
||||
if(!arrakis(p)){p.sendMessage("Spice buyers are available on Arrakis only.");return;}
|
||||
|
|
@ -55,7 +63,7 @@ final class SpiceMenus implements Listener {
|
|||
private void settle(Player p,UUID id,boolean notify){var q=action("settle");q.addProperty("requestId",id.toString());call(p,q,data->{if(notify)p.sendMessage("Sold "+data.get("amount").getAsInt()+" Melange Spice. P&O paid "+money(data.get("netMinor").getAsLong())+" to your bank account.");});}
|
||||
@EventHandler public void join(PlayerJoinEvent e){Bukkit.getScheduler().runTaskLater(plugin,()->recover(e.getPlayer()),120);}
|
||||
private void recover(Player p){if(!arrakis(p))return;call(p,action("pending"),data->recoverNext(p,data.getAsJsonArray("pending").asList().stream().map(v->UUID.fromString(v.getAsString())).toList(),0));}
|
||||
private void recoverNext(Player p,List<UUID> ids,int index){if(index>=ids.size()||!arrakis(p))return;var q=action("settle");q.addProperty("requestId",ids.get(index).toString());call(p,q,data->recoverNext(p,ids,index+1));}
|
||||
private void recoverNext(Player p,List<UUID> ids,int index){if(!arrakis(p))return;if(index>=ids.size()){p.sendMessage(ids.isEmpty()?"No spice payments are waiting.":"Pending spice payments processed.");return;}var q=action("settle");q.addProperty("requestId",ids.get(index).toString());call(p,q,data->recoverNext(p,ids,index+1));}
|
||||
private static void put(Panel panel,int slot,Material material,String name,String lore,Runnable action,String art){var item=new ItemStack(material);var meta=item.getItemMeta();meta.displayName(Component.text(name,NamedTextColor.GOLD));meta.lore(Arrays.stream(lore.split("\n")).map(line->Component.text(line,NamedTextColor.GRAY)).toList());if(art!=null)meta.getPersistentDataContainer().set(new NamespacedKey("dunerealms","menu_art"),org.bukkit.persistence.PersistentDataType.STRING,art);item.setItemMeta(meta);panel.inventory.setItem(slot,item);if(action!=null)panel.actions.put(slot,action);}
|
||||
private void show(Player p,Panel panel){if(BedrockForms.isBedrock(p)){var choices=panel.actions.entrySet().stream().map(entry->new BedrockForms.Choice(net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer.plainText().serialize(panel.inventory.getItem(entry.getKey()).getItemMeta().displayName()),"",entry.getValue())).toList();BedrockForms.show(plugin,p,"Arrakis · Spice buyer","P&O pays your personal bank account",choices);return;}if(!MCGUIMenus.show(p,"Arrakis · Spice buyer","Guild trade and quest-authorised smuggling",panel.inventory,panel.actions,panel.gate))p.openInventory(panel.inventory);}
|
||||
@EventHandler public void click(InventoryClickEvent e){if(!(e.getView().getTopInventory().getHolder() instanceof Panel panel))return;e.setCancelled(true);if(!panel.owner.equals(e.getWhoClicked().getUniqueId()))return;Runnable action=panel.actions.get(e.getRawSlot());if(action!=null&&panel.gate.claim(e.getWhoClicked().getUniqueId()))Bukkit.getScheduler().runTask(plugin,action);}
|
||||
|
|
|
|||
|
|
@ -21,12 +21,14 @@ commands:
|
|||
description: Open your starter equipment mission and repair journal
|
||||
usage: /start
|
||||
spice:
|
||||
description: Open Arrakis Guild and Smuggler spice buyers
|
||||
description: Open Arrakis spice buyers or collect payments
|
||||
usage: /spice [collect]
|
||||
sellall:
|
||||
description: Sell all Melange Spice on Arrakis through P&O
|
||||
usage: /sellall [guild|smuggler]
|
||||
exchange:
|
||||
description: Open the central bank Exchange to buy or sell items
|
||||
description: Open the Exchange or collect paid items
|
||||
usage: /exchange [collect]
|
||||
clan:
|
||||
description: Open your key-linked clan panel
|
||||
company:
|
||||
|
|
@ -35,7 +37,8 @@ commands:
|
|||
aliases: [polgui]
|
||||
description: Open your political office or run an office operation
|
||||
guildtravel:
|
||||
description: Book or cancel twenty-minute Imperial passage to your House world
|
||||
description: Book, check or cancel Imperial Guild passage
|
||||
usage: /guildtravel [status|cancel|book <world>]
|
||||
drscoreboard:
|
||||
description: Toggle your private Personal XP, Reputation, bank and organisation scoreboard
|
||||
house:
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff