Connect Guild and Smuggler Navigator routes to JARVIS
This commit is contained in:
parent
af33fc87b9
commit
4da7c00ffe
13 changed files with 551 additions and 33 deletions
|
|
@ -373,20 +373,30 @@ final class JarvisBackend implements Backend, Listener {
|
|||
var quote = accepted(jarvis.requestGuild(owner,action("quote")));
|
||||
var worlds = new ArrayList<World>();
|
||||
String key = text(house,"keyId");
|
||||
int version = house.get("version").getAsInt();
|
||||
for (var destination : array(quote,"destinations")) {
|
||||
String id = destination.getAsString();
|
||||
String name = switch (id) {
|
||||
case "arrakis" -> "Arrakduin";
|
||||
case "caladan" -> "Kaladam";
|
||||
case "giedi_prime" -> "Giedermark";
|
||||
case "kaitain" -> "Kaiterhof";
|
||||
case "sigma_draconis_iv" -> "Sigmadraken IV";
|
||||
default -> null;
|
||||
};
|
||||
if (name != null) worlds.add(new World(id,name,"Imperial Guild passage",Material.COMPASS,-1,
|
||||
yes(quote,"affordable") && !key.isBlank() && jarvis.worldOnline(id),
|
||||
quote.get("fareMinor").getAsLong(),key,version));
|
||||
int version = house.has("version") && !house.get("version").isJsonNull() ? house.get("version").getAsInt() : 0;
|
||||
var allowed = new HashSet<String>();
|
||||
for (var destination : array(quote,"destinations")) allowed.add(destination.getAsString());
|
||||
var catalog = new HashMap<String, JsonObject>();
|
||||
for (var route : array(quote,"routes")) if (route.isJsonObject()) {
|
||||
var row = route.getAsJsonObject();
|
||||
catalog.putIfAbsent(text(row,"server"), row);
|
||||
}
|
||||
for (var route : List.of(Map.entry("caladan","Kaladam"), Map.entry("giedi_prime","Giedermark"),
|
||||
Map.entry("kaitain","Kaiterhof"), Map.entry("sigma_draconis_iv","Sigmadraken IV"),
|
||||
Map.entry("arrakis","Arrakduin"))) {
|
||||
String id = route.getKey();
|
||||
var offer = catalog.get(id);
|
||||
String unavailable = yes(quote,"prologueRequired") ? "Complete your House Prologue"
|
||||
: key.isBlank() || version <= 0 ? "Confirm your current House key"
|
||||
: offer != null && !yes(offer,"available") ? text(offer,"reason")
|
||||
: offer == null && !allowed.contains(id) ? "This route is unavailable under your current Guild passage"
|
||||
: !yes(quote,"affordable") ? "Insufficient available funds in your personal account"
|
||||
: !jarvis.worldOnline(id) ? "This world is currently offline" : null;
|
||||
if (unavailable!=null && unavailable.isBlank()) unavailable="Passage unavailable";
|
||||
String name=offer!=null&&!text(offer,"name").isBlank()?text(offer,"name"):route.getValue();
|
||||
long fare=offer!=null&&offer.has("fareMinor")?offer.get("fareMinor").getAsLong():quote.get("fareMinor").getAsLong();
|
||||
worlds.add(new World(id, name, unavailable == null ? "Imperial Guild passage" : unavailable,
|
||||
Material.COMPASS, -1, unavailable == null, fare, key, version));
|
||||
}
|
||||
return List.copyOf(worlds);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -33,10 +33,11 @@ final class TravelMenu extends Menu {
|
|||
for (int i = 0; i < Math.min(STARS.length, worlds.size()); i++) {
|
||||
var w = worlds.get(i);
|
||||
String fare = w.fareMinor() > 0 ? "<gray>Fare: <gold>" + Ui.dm(w.fareMinor()) : w.fareMinor() == 0 ? "<green>Free passage" : "";
|
||||
put(STARS[i], Ui.item(w.up() ? w.icon() : Material.GRAY_DYE, "<gold><b>" + w.name(),
|
||||
var icon = Ui.item(w.up() ? w.icon() : Material.GRAY_DYE, (w.up() ? "<gold><b>" : "<gray>") + w.name(),
|
||||
"<gray>" + w.tagline(), w.online() < 0 ? "" : "<gray>Players: <white>" + w.online(), fare, "",
|
||||
w.up() ? "<yellow>Click to travel" : "<red>Offline right now"),
|
||||
t -> { if (!w.up()) return; end(); book(w); });
|
||||
w.up() ? "<yellow>Click to travel" : "");
|
||||
if (w.up()) put(STARS[i], icon, t -> { end(); book(w); });
|
||||
else put(STARS[i], icon);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);}}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
package com.dunerealms.gui;
|
||||
import com.google.gson.JsonObject;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
final class GuildRoutes {
|
||||
record Route(String house,String world,String name,String sigil){}
|
||||
static final List<Route> ALL=List.of(
|
||||
|
|
@ -12,4 +15,20 @@ final class GuildRoutes {
|
|||
static Route home(String house){return ALL.stream().filter(r->r.house().equals(house)).findFirst().orElse(null);}
|
||||
static boolean allowed(String house,String world){Route route=home(house);return route!=null&&route.world().equals(world);}
|
||||
static boolean candidate(String house,String world){return home(house)!=null&&(allowed(house,world)||"arrakis".equals(world));}
|
||||
record Offer(String server,String name,boolean available,String reason,long fareMinor){}
|
||||
|
||||
static Map<String,Offer> catalog(JsonObject quote){
|
||||
Map<String,Offer> result=new LinkedHashMap<>();
|
||||
if(!quote.has("routes")||!quote.get("routes").isJsonArray())return result;
|
||||
for(var value:quote.getAsJsonArray("routes")){
|
||||
if(!value.isJsonObject())continue;
|
||||
var row=value.getAsJsonObject();
|
||||
if(!row.has("server")||!row.has("name")||!row.has("available")||!row.has("fareMinor"))continue;
|
||||
String server=row.get("server").getAsString();
|
||||
if(ALL.stream().noneMatch(route->route.world().equals(server)))continue;
|
||||
String reason=row.has("reason")&&!row.get("reason").isJsonNull()?row.get("reason").getAsString():"Passage unavailable";
|
||||
result.putIfAbsent(server,new Offer(server,row.get("name").getAsString(),row.get("available").getAsBoolean(),reason,row.get("fareMinor").getAsLong()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ final class HouseBridge {
|
|||
void returnGuild(org.bukkit.entity.Player player)throws Exception{call(translator.getClass().getMethod("returnGuild",org.bukkit.entity.Player.class),player);}
|
||||
boolean worldOnline(String name) throws Exception { return Boolean.TRUE.equals(call(world, name)); }
|
||||
JsonObject organisations(UUID player)throws Exception{return (JsonObject)call(translator.getClass().getMethod("requestOrganisations",UUID.class),player);}
|
||||
@SuppressWarnings("unchecked") java.util.concurrent.CompletableFuture<JsonObject> homeSmuggler(org.bukkit.entity.Player player,UUID contact,JsonObject input)throws Exception{return (java.util.concurrent.CompletableFuture<JsonObject>)call(translator.getClass().getMethod("homeSmuggler",org.bukkit.entity.Player.class,UUID.class,JsonObject.class),player,contact,input);}
|
||||
JsonObject warMuster(UUID player,JsonObject input)throws Exception{return (JsonObject)call(translator.getClass().getMethod("requestWarMuster",UUID.class,JsonObject.class),player,input);}
|
||||
JsonObject warReport(UUID player)throws Exception{return (JsonObject)call(translator.getClass().getMethod("warReport",UUID.class),player);}
|
||||
org.bukkit.inventory.ItemStack menuItem(org.bukkit.entity.Player player)throws Exception{return (org.bukkit.inventory.ItemStack)call(translator.getClass().getMethod("menuItem",org.bukkit.entity.Player.class),player);}
|
||||
|
|
|
|||
|
|
@ -34,9 +34,12 @@ final class OrganisationMenus implements Listener {
|
|||
});
|
||||
}
|
||||
void openHomeNpc(Player p,String kind,String id){
|
||||
openHomeNpc(p,kind,id,null);
|
||||
}
|
||||
void openHomeNpc(Player p,String kind,String id,UUID contact){
|
||||
if(!Set.of("clans","companies").contains(kind)||!busy.add(p.getUniqueId()))return;UUID world=p.getWorld().getUID();
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin,()->{JsonObject data=null;try{data=bridge.organisations(p.getUniqueId());}catch(Exception ignored){}JsonObject result=data;if(!plugin.isEnabled())return;
|
||||
Bukkit.getScheduler().runTask(plugin,()->{busy.remove(p.getUniqueId());if(!p.isOnline()||!world.equals(p.getWorld().getUID()))return;if(result!=null&&result.has(kind))for(var item:result.getAsJsonArray(kind)){var row=item.getAsJsonObject();if(row.has("id")&&id.equals(row.get("id").getAsString())){organisation(p,result,kind,row);return;}}p.sendMessage("This organisation contact is available to current authorised members.");});
|
||||
Bukkit.getScheduler().runTask(plugin,()->{busy.remove(p.getUniqueId());if(!p.isOnline()||!world.equals(p.getWorld().getUID()))return;if(result!=null&&result.has(kind))for(var item:result.getAsJsonArray(kind)){var row=item.getAsJsonObject();if(row.has("id")&&id.equals(row.get("id").getAsString())){organisation(p,result,kind,row,contact);return;}}p.sendMessage("This organisation contact is available to current authorised members.");});
|
||||
});
|
||||
}
|
||||
void lore(Player p){
|
||||
|
|
@ -55,6 +58,9 @@ 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){
|
||||
organisation(p,data,kind,row,null);
|
||||
}
|
||||
private void organisation(Player p,JsonObject data,String kind,JsonObject row,UUID contact){
|
||||
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);
|
||||
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;
|
||||
|
|
@ -69,8 +75,66 @@ final class OrganisationMenus implements Listener {
|
|||
put(panel,40,"Your Mentat","Your existing personal briefing",Material.BOOK,()->mentat.accept(p));
|
||||
put(panel,49,"War report","Home Blocks conquered · Campaign progress\nWar control remains on the website",Material.IRON_SWORD,()->warStatus(p,()->organisation(p,data,kind,row)));
|
||||
boolean war=row.has("wars")&&!row.getAsJsonArray("wars").isEmpty();put(panel,43,"War Transport",war?"Deploy for an active war\nShared Imperial boarding windows":"Unavailable · no active clan war",war?Material.CROSSBOW:Material.GRAY_DYE,()->{if(war)wars(p,data,kind,row);else organisation(p,data,kind,row);});
|
||||
if(contact!=null){
|
||||
put(panel,47,"Smuggler Navigator","Travel between Home Blocks you own",Material.COMPASS,
|
||||
()->openSmuggler(p,contact,reference(kind.equals("clans")?"clan":"company",row.get("id").getAsString()),
|
||||
()->openHomeNpc(p,kind,row.get("id").getAsString(),contact)));
|
||||
if(panel.artwork){
|
||||
var item=panel.inventory.getItem(47);var meta=item.getItemMeta();meta.setItemModel(null);item.setItemMeta(meta);
|
||||
item.setType(Material.COMPASS);panel.inventory.setItem(47,item);
|
||||
}
|
||||
}
|
||||
put(panel,45,"Back","Your organisations",Material.ARROW,()->start(p,data));close(panel,p);show(p,panel);
|
||||
}
|
||||
private static JsonObject reference(String kind,String id){
|
||||
var result=new JsonObject();result.addProperty("kind",kind);result.addProperty("id",id);return result;
|
||||
}
|
||||
private void openSmuggler(Player player,UUID contact,JsonObject origin,Runnable back){
|
||||
smugglerRequest(player,contact,origin,"home_list",new JsonObject(),list->{
|
||||
var destinations=new ArrayList<SmugglerDestinations.Destination>();
|
||||
for(var entry:list.getAsJsonArray("destinations")){
|
||||
var row=entry.getAsJsonObject();
|
||||
var kind=SmugglerDestinations.Kind.valueOf(row.get("kind").getAsString().toUpperCase(Locale.ROOT));
|
||||
String server=row.get("server").isJsonNull()?null:row.get("server").getAsString();
|
||||
String world=GuildRoutes.ALL.stream().filter(route->route.world().equals(server)).map(GuildRoutes.Route::name).findFirst().orElse(server);
|
||||
String reason=row.get("available").getAsBoolean()?null:row.get("reason").getAsString();
|
||||
destinations.add(new SmugglerDestinations.Destination(row.get("id").getAsString(),kind,row.get("name").getAsString(),world,reason));
|
||||
}
|
||||
smugglerNavigator(player,destinations,0,destination->quoteSmuggler(player,contact,origin,destination,
|
||||
()->openSmuggler(player,contact,origin,back)),back);
|
||||
});
|
||||
}
|
||||
private void quoteSmuggler(Player player,UUID contact,JsonObject origin,SmugglerDestinations.Destination destination,Runnable back){
|
||||
var target=reference(destination.kind().name().toLowerCase(Locale.ROOT),destination.id());
|
||||
var query=new JsonObject();query.add("target",target);
|
||||
smugglerRequest(player,contact,origin,"home_quote",query,quote->{
|
||||
var view=new SmugglerDestinations.Quote(destination,quote.get("fareMinor").getAsLong(),
|
||||
quote.get("affordable").getAsBoolean()?null:"Insufficient available funds in your personal account.");
|
||||
var booking=new JsonObject();booking.add("target",target);
|
||||
booking.addProperty("requestId",UUID.randomUUID().toString());booking.addProperty("confirmed",true);
|
||||
for(String field:List.of("keyId","version","fareMinor"))booking.add(field,quote.get(field));
|
||||
for(String side:List.of("origin","target")){
|
||||
var pin=quote.getAsJsonObject(side);
|
||||
booking.add(side+"HomeBlockId",pin.get("homeBlockId"));booking.add(side+"Revision",pin.get("claimRevision"));
|
||||
}
|
||||
confirmSmugglerPassage(player,view,()->smugglerRequest(player,contact,origin,"home_board",booking,
|
||||
ticket->player.sendMessage("Smuggler passage: "+ticket.get("state").getAsString())),back);
|
||||
});
|
||||
}
|
||||
private void smugglerRequest(Player player,UUID contact,JsonObject origin,String action,JsonObject fields,Consumer<JsonObject> callback){
|
||||
if(!busy.add(player.getUniqueId()))return;
|
||||
var request=fields.deepCopy();request.addProperty("action",action);request.add("origin",origin);
|
||||
player.closeInventory();
|
||||
try{
|
||||
bridge.homeSmuggler(player,contact,request).whenComplete((response,failure)->Bukkit.getScheduler().runTask(plugin,()->{
|
||||
busy.remove(player.getUniqueId());if(!player.isOnline())return;
|
||||
if(failure!=null){
|
||||
Throwable cause=failure;while(cause.getCause()!=null)cause=cause.getCause();
|
||||
player.sendMessage(cause instanceof java.io.IOException?cause.getMessage():"Smuggler Navigator is unavailable. Reopen the contact.");
|
||||
}else callback.accept(response);
|
||||
}));
|
||||
}catch(Exception failure){busy.remove(player.getUniqueId());player.sendMessage("Smuggler Navigator is unavailable.");}
|
||||
}
|
||||
void smugglerNavigator(Player player, List<SmugglerDestinations.Destination> destinations,
|
||||
int pageNumber, Consumer<SmugglerDestinations.Destination> select, Runnable back) {
|
||||
var screen = panel(player, "Smuggler Navigator", false);
|
||||
|
|
|
|||
|
|
@ -50,11 +50,70 @@ final class QuestMenus implements Listener {
|
|||
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));}
|
||||
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(role.key().equals("esmar_tuek")){
|
||||
put(screen,47,"Smuggler Navigator","Review personal passage to another world.",Material.COMPASS,()->smugglerMenu(p,data,role));
|
||||
if(!role.world().equals("guild_lobby"))put(screen,46,"Smuggler return","Return to the recorded origin of your confirmed passage.",
|
||||
Material.ENDER_PEARL,()->{try{bridge.returnSmuggler(p);}catch(Exception failure){p.sendMessage("Meet Esmar Tuek to confirm your 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,()->roleDecisionDashboard(p,data,role));put(screen,49,"Website journal","Full mission choices and history",Material.MAP,()->website(p));show(p,screen);
|
||||
}
|
||||
private void smugglerRequest(Player p,JsonObject input,Consumer<JsonObject> callback){try{bridge.questCharacterNpc(p,"esmar_tuek");}catch(Exception unavailable){p.sendMessage("Meet Esmar Tuek first.");return;}UUID id=p.getUniqueId(),world=p.getWorld().getUID(),operation=UUID.randomUUID();if(pending.putIfAbsent(id,operation)!=null)return;p.closeInventory();Bukkit.getScheduler().runTaskAsynchronously(plugin,()->{JsonObject result=null;String error=null;try{if(text(input,"action","").equals("smuggler_board")&&!bridge.worldOnline("arrakis"))throw new IllegalStateException("Arrakis is currently unavailable.");result=bridge.guild(id,input);}catch(Exception failure){error=failure.getMessage();}var response=result;String message=error;Bukkit.getScheduler().runTask(plugin,()->{if(!pending.remove(id,operation)||!p.isOnline()||!p.getWorld().getUID().equals(world))return;if(response==null){p.sendMessage(message==null?"The smuggler passage is unavailable.":message);return;}callback.accept(response);});});}
|
||||
private void smugglerMenu(Player p,JsonObject data,PolQuestNpc.Role role){var input=new JsonObject();input.addProperty("action","smuggler_quote");smugglerRequest(p,input,quote->{var screen=panel(p,"NPC turn-in · "+role.name());screen.description="A personal smuggler passage is distinct from sanctioned Guild travel. Unsanctioned arrival may carry the existing in-game bounty.";roleAvatar(screen,data,role);if(!yes(quote,"eligible")){put(screen,13,"Ordinary Guild passage","Your current lawful route is available. Use the normal Guild Navigator.",Material.COMPASS,null);}else if(!yes(quote,"allowed")){put(screen,13,"Personal passage","Opt in with Esmar if ordinary Arrakis passage is unavailable. One hour from the verified introduction.",Material.COMPASS,null);put(screen,31,"Opt in to smuggling","Register the existing smuggler introduction and personal permission.",Material.LIME_DYE,()->{var introduction=data.getAsJsonArray("quests").asList().stream().map(JsonElement::getAsJsonObject).filter(q->text(q,"id","").equals("POL-SMUGGLERS-01")).findFirst().orElse(null);if(introduction==null){p.sendMessage("The current smuggler mission is unavailable.");return;}Runnable emit=()->{try{bridge.smugglerIntroduction(p);p.sendMessage("Introduction recorded. Reopen personal passage after J.A.R.V.I.S. verifies it.");}catch(Exception error){p.sendMessage("Meet Esmar Tuek in the Guild lobby.");}};if(yes(introduction,"canStart")&&!Set.of("active","completed","claimed").contains(text(introduction,"state",""))){var start=new JsonObject();start.addProperty("action","start");start.addProperty("kind","pol");start.addProperty("definitionId","POL-SMUGGLERS-01");start.addProperty("requestId",UUID.randomUUID().toString());start.addProperty("confirmed",true);request(p,start,ignored->emit.run());}else emit.run();});}else{long expiry=quote.get("permitExpiresAt").getAsLong();int price=quote.get("fareMinor").getAsInt();put(screen,13,"Personal passage to Arrakis","Fare: "+String.format(Locale.ROOT,"%.2f DM",price/100.0)+"\nPermission expires: "+java.time.Instant.ofEpochMilli(expiry)+"\nExisting unsanctioned-arrival rules apply.",Material.COMPASS,null);if(yes(quote,"affordable"))put(screen,31,"Confirm paid passage","Reserve this exact fare; payment settles only after arrival.",Material.LIME_DYE,()->{var board=new JsonObject();board.addProperty("action","smuggler_board");board.addProperty("requestId",UUID.randomUUID().toString());board.add("keyId",quote.get("keyId"));board.add("version",quote.get("version"));board.add("fareMinor",quote.get("fareMinor"));board.addProperty("destination","arrakis");smugglerRequest(p,board,ticket->{try{bridge.dispatchGuild(p,ticket);}catch(Exception error){p.sendMessage("The transfer was not dispatched; unused reservation expires.");}});});else put(screen,31,"Insufficient funds","Your personal central bank account must cover the fare.",Material.CLOCK,null);}put(screen,33,"Starter spice shovel","Open the existing starter objective for your original shovel; no duplicate issue.",Material.WOODEN_SHOVEL,()->{p.closeInventory();p.performCommand("start");});put(screen,49,"Back","Return to Esmar's missions",Material.ARROW,()->load(p,"pol",null,null,0));show(p,screen);});}
|
||||
private void smugglerRequest(Player p,JsonObject input,Consumer<JsonObject> callback){try{bridge.questCharacterNpc(p,"esmar_tuek");}catch(Exception unavailable){p.sendMessage("Meet Esmar Tuek first.");return;}UUID id=p.getUniqueId(),world=p.getWorld().getUID(),operation=UUID.randomUUID();if(pending.putIfAbsent(id,operation)!=null)return;p.closeInventory();Bukkit.getScheduler().runTaskAsynchronously(plugin,()->{JsonObject result=null;String error=null;try{if(text(input,"action","").equals("smuggler_board")&&!bridge.worldOnline(text(input,"destination","")))throw new IllegalStateException("That world is currently unavailable.");result=bridge.guild(id,input);}catch(Exception failure){error=failure.getMessage();}var response=result;String message=error;Bukkit.getScheduler().runTask(plugin,()->{if(!pending.remove(id,operation)||!p.isOnline()||!p.getWorld().getUID().equals(world))return;if(response==null){p.sendMessage(message==null?"The smuggler passage is unavailable.":message);return;}callback.accept(response);});});}
|
||||
private void smugglerMenu(Player p,JsonObject data,PolQuestNpc.Role role){
|
||||
var input=new JsonObject();input.addProperty("action","smuggler_quote");
|
||||
smugglerRequest(p,input,quote->{
|
||||
var offers=GuildRoutes.catalog(quote);
|
||||
var screen=panel(p,"Esmar Tuek · Smuggler Navigator");
|
||||
screen.description="Personal smuggler passage. Existing unsanctioned arrival rules apply.";
|
||||
roleAvatar(screen,data,role);
|
||||
int slot=10;
|
||||
boolean available=false;
|
||||
for(var route:GuildRoutes.ALL){
|
||||
var offer=offers.get(route.world());
|
||||
if(offer==null){
|
||||
put(screen,slot++,route.name(),"No confirmed smuggler route for this world.",Material.GRAY_DYE,null);
|
||||
continue;
|
||||
}
|
||||
if(offer.available())available=true;
|
||||
String fare=java.math.BigDecimal.valueOf(offer.fareMinor(),2).toPlainString()+" DM";
|
||||
put(screen,slot++,offer.name(),offer.available()?"Smuggler fare: "+fare:offer.reason(),
|
||||
offer.available()?Material.COMPASS:Material.GRAY_DYE,
|
||||
offer.available()?()->confirmSmuggler(p,data,role,quote,offer,fare):null);
|
||||
}
|
||||
if(!available)put(screen,31,"Opt in to smuggling","Register Esmar's existing introduction and personal permission.",
|
||||
Material.LIME_DYE,()->smugglerOptIn(p,data));
|
||||
put(screen,33,"Starter spice shovel","Open the existing starter objective.",Material.WOODEN_SHOVEL,
|
||||
()->{p.closeInventory();p.performCommand("start");});
|
||||
put(screen,49,"Back","Return to Esmar's missions",Material.ARROW,()->load(p,"pol",null,null,0));
|
||||
show(p,screen);
|
||||
});
|
||||
}
|
||||
private void confirmSmuggler(Player p,JsonObject data,PolQuestNpc.Role role,JsonObject quote,GuildRoutes.Offer offer,String fare){
|
||||
var screen=panel(p,"Confirm smuggler passage");
|
||||
put(screen,13,offer.name(),"Smuggler fare: "+fare+"\nExisting unsanctioned arrival rules apply.",Material.COMPASS,null);
|
||||
UUID requestId=UUID.randomUUID();
|
||||
put(screen,31,"Confirm paid passage","Reserve this exact fare. Payment settles after arrival.",Material.LIME_DYE,()->{
|
||||
var board=new JsonObject();board.addProperty("action","smuggler_board");board.addProperty("requestId",requestId.toString());
|
||||
board.add("keyId",quote.get("keyId"));board.add("version",quote.get("version"));board.addProperty("fareMinor",offer.fareMinor());
|
||||
board.addProperty("destination",offer.server());
|
||||
smugglerRequest(p,board,ticket->{try{bridge.dispatchGuild(p,ticket);}catch(Exception error){
|
||||
p.sendMessage("The transfer was not dispatched; unused reservation expires.");
|
||||
}});
|
||||
});
|
||||
put(screen,49,"Back","Smuggler Navigator",Material.ARROW,()->smugglerMenu(p,data,role));
|
||||
show(p,screen);
|
||||
}
|
||||
private void smugglerOptIn(Player p,JsonObject data){
|
||||
var introduction=data.getAsJsonArray("quests").asList().stream().map(JsonElement::getAsJsonObject)
|
||||
.filter(q->text(q,"id","").equals("POL-SMUGGLERS-01")).findFirst().orElse(null);
|
||||
if(introduction==null){p.sendMessage("The current smuggler mission is unavailable.");return;}
|
||||
Runnable emit=()->{try{bridge.smugglerIntroduction(p);p.sendMessage("Introduction recorded. Reopen personal passage after J.A.R.V.I.S. verifies it.");}
|
||||
catch(Exception error){p.sendMessage("Meet Esmar Tuek in the Guild lobby.");}};
|
||||
if(yes(introduction,"canStart")&&!Set.of("active","completed","claimed").contains(text(introduction,"state",""))){
|
||||
var start=new JsonObject();start.addProperty("action","start");start.addProperty("kind","pol");
|
||||
start.addProperty("definitionId","POL-SMUGGLERS-01");start.addProperty("requestId",UUID.randomUUID().toString());
|
||||
start.addProperty("confirmed",true);request(p,start,ignored->emit.run());
|
||||
}else emit.run();
|
||||
}
|
||||
private void roleDecisionDashboard(Player p,JsonObject contact,PolQuestNpc.Role role){var input=new JsonObject();input.addProperty("action","read");input.addProperty("npcRole",role.key());decisionRequest(p,role,input,data->{var screen=panel(p,"NPC dashboard decision · "+role.name());screen.description="Choose a decision you currently have the authority to execute.";roleAvatar(screen,contact,role);int slot=9;for(var e:data.getAsJsonArray("decisions")){var row=e.getAsJsonObject();if(slot>=45)break;put(screen,slot++,text(row,"title","Decision"),"Required Reputation: "+text(row,"level","—")+"\n"+(text(row,"kind","").equals("website")?"Continue through the verified website workflow.":(row.has("fundingRequired")&&!yes(row,"fundingRequired")?"Review the parameter and confirm.":"Review funding and confirm.")),Material.BOOK,()->roleDecisionDetails(p,contact,role,row,null,null));}if(slot==9)put(screen,13,"No executable decisions","Your current office, authority and cooldown determine what appears here.",Material.MAP,null);put(screen,48,"Back","Mission dashboard",Material.ARROW,()->load(p,"pol",null,null,0));put(screen,49,"Website","Full decision definitions and history",Material.MAP,()->decisionWebsite(p));show(p,screen);});}
|
||||
private void decisionWebsite(Player p){decisionWebsite(p,null);}
|
||||
private void decisionWebsite(Player p,String decision){p.closeInventory();String url="https://clans.dunerealms.com/#quests/quests?xp=pol&view=decisions";if(decision!=null&&decision.matches("[A-Z0-9-]{1,32}"))url+="&decision="+decision;p.sendMessage(Component.text("Review POL decisions on the website →",NamedTextColor.GOLD).clickEvent(ClickEvent.openUrl(url)));}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
package com.dunerealms.gui;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import com.google.gson.JsonParser;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class GuildRouteCatalogTest {
|
||||
@Test void centralReasonsAndNamesStayBoundToOneCanonicalWorld() {
|
||||
var quote = JsonParser.parseString("""
|
||||
{"routes":[
|
||||
{"server":"arrakis","name":"Arrakduin","available":true,"fareMinor":12500},
|
||||
{"server":"arrakis","name":"Wrong duplicate","available":false,"fareMinor":12500},
|
||||
{"server":"sigma_draconis_iv","name":"Sigmadraken IV","available":false,
|
||||
"reason":"Current embargo","fareMinor":12500},
|
||||
{"server":"unknown","name":"Arrakduin","available":true,"fareMinor":12500}
|
||||
]}
|
||||
""").getAsJsonObject();
|
||||
var routes = GuildRoutes.catalog(quote);
|
||||
assertEquals(2, routes.size());
|
||||
assertEquals("Arrakduin", routes.get("arrakis").name());
|
||||
assertTrue(routes.get("arrakis").available());
|
||||
assertEquals(12500, routes.get("arrakis").fareMinor());
|
||||
assertFalse(routes.get("sigma_draconis_iv").available());
|
||||
assertEquals("Current embargo", routes.get("sigma_draconis_iv").reason());
|
||||
}
|
||||
}
|
||||
|
|
@ -22,17 +22,35 @@ final class GuildTransport implements Listener {
|
|||
if(!p.isOnline()||!busy.add(p.getUniqueId()))return;UUID id=p.getUniqueId(),world=p.getWorld().getUID();var q=new JsonObject();q.addProperty("action",smuggler?"smuggler_return":"travel_check");q.addProperty("uuid",id.toString());q.addProperty("sourceWorld",server);if(!smuggler)q.addProperty("destination","lobby");
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin,()->{JsonObject permit=null;try{permit=api.guild(q);}catch(Exception ignored){}var result=permit;if(!plugin.isEnabled())return;Bukkit.getScheduler().runTask(plugin,()->{busy.remove(id);if(!p.isOnline()||!p.getWorld().getUID().equals(world))return;
|
||||
if(result==null||!result.has("ok")||!result.get("ok").getAsBoolean()||!result.has("expiresAt")||result.get("expiresAt").getAsLong()<=System.currentTimeMillis()){p.sendMessage(result!=null&&result.has("message")?result.get("message").getAsString():"Guild return could not be confirmed. Please retry.");return;}
|
||||
try{var bytes=new ByteArrayOutputStream();var out=new DataOutputStream(bytes);out.writeUTF("Connect");out.writeUTF("lobby");p.closeInventory();p.sendPluginMessage(plugin,"BungeeCord",bytes.toByteArray());}catch(IOException failed){p.sendMessage("Guild return could not be sent. No fare was taken.");}
|
||||
String target=result.has("destination")&&!result.get("destination").isJsonNull()?result.get("destination").getAsString():"";
|
||||
if(!Set.of("lobby","caladan","giedi_prime","kaitain","sigma_draconis_iv","arrakis").contains(target)||target.equals(server)||!smuggler&&!target.equals("lobby")||!result.has("source")||!server.equals(result.get("source").getAsString())){p.sendMessage("The Guild return destination could not be confirmed.");return;}
|
||||
try{p.closeInventory();connect(p,target);}catch(IOException failed){p.sendMessage("Guild return could not be sent. No fare was taken.");}
|
||||
});});
|
||||
}
|
||||
void dispatch(Player p,JsonObject ticket)throws IOException{
|
||||
if(!Bukkit.isPrimaryThread())throw new IllegalStateException("Transfer must run on the server thread");
|
||||
String target=ticket.get("destination").getAsString();
|
||||
if(!p.isOnline()||!p.getWorld().getName().equals("guild_lobby")||!ticket.get("state").getAsString().equals("pending")||ticket.get("expiresAt").getAsLong()<=System.currentTimeMillis()||!Set.of("caladan","giedi_prime","kaitain","sigma_draconis_iv","arrakis").contains(target))throw new IOException("Passage is no longer ready for boarding");
|
||||
boolean smuggler=ticket.has("smuggler")&&ticket.get("smuggler").getAsBoolean();
|
||||
if(!smuggler&&!p.getWorld().getName().equals("guild_lobby"))throw new IOException("Board ordinary passage at the Guild.");
|
||||
requirePending(p,ticket,target);
|
||||
// Preserve Core's one-use arrival permit. The central House receipt supplies
|
||||
// the authority; a sanctioned Guild passenger must not become a smuggler.
|
||||
if(target.equals("arrakis")&&!(ticket.has("smuggler")&&ticket.get("smuggler").getAsBoolean()))try{var core=Bukkit.getPluginManager().getPlugin("DuneCore");if(core==null||!core.isEnabled())throw new IllegalStateException();var field=core.getClass().getDeclaredField("sharedDatabase");field.setAccessible(true);var db=field.get(core);if(db==null)throw new IllegalStateException();db.getClass().getMethod("issueArrakisPermit",UUID.class,long.class).invoke(db,p.getUniqueId(),ticket.get("expiresAt").getAsLong());}catch(ReflectiveOperationException|RuntimeException unavailable){throw new IOException("The Arrakis arrival permit could not be recorded",unavailable);}
|
||||
var bytes=new ByteArrayOutputStream();var out=new DataOutputStream(bytes);out.writeUTF("Connect");out.writeUTF(target);p.sendPluginMessage(plugin,"BungeeCord",bytes.toByteArray());p.sendMessage((ticket.has("smuggler")&&ticket.get("smuggler").getAsBoolean()?"Smuggler":"Spacing Guild")+" · transfer requested. The fare is collected only after arrival.");
|
||||
connect(p,target);p.sendMessage((smuggler?"Smuggler":"Spacing Guild")+" · transfer requested. The fare is collected only after arrival.");
|
||||
}
|
||||
void dispatchHome(Player p,JsonObject ticket)throws IOException{
|
||||
String target=ticket.get("destination").getAsString();
|
||||
requirePending(p,ticket,target);
|
||||
if(!ticket.has("home")||!ticket.has("smuggler")||!ticket.get("smuggler").getAsBoolean())throw new IOException("A current Home Block passage is required.");
|
||||
connect(p,target);
|
||||
}
|
||||
private void requirePending(Player p,JsonObject ticket,String target)throws IOException{
|
||||
if(!p.isOnline()||!ticket.get("state").getAsString().equals("pending")||ticket.get("expiresAt").getAsLong()<=System.currentTimeMillis()
|
||||
||target.equals(server)||!Set.of("caladan","giedi_prime","kaitain","sigma_draconis_iv","arrakis").contains(target))
|
||||
throw new IOException("Passage is no longer ready for boarding");
|
||||
}
|
||||
private void connect(Player p,String target)throws IOException{
|
||||
var bytes=new ByteArrayOutputStream();var out=new DataOutputStream(bytes);out.writeUTF("Connect");out.writeUTF(target);p.sendPluginMessage(plugin,"BungeeCord",bytes.toByteArray());
|
||||
}
|
||||
private void arrival(Player p){
|
||||
if(!Set.of("caladan","giedi_prime","kaitain","sigma_draconis_iv","arrakis").contains(server)||!p.isOnline()||!busy.add(p.getUniqueId()))return;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,264 @@
|
|||
package com.dunerealms.jarvis;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
/** Native contact validation and durable delivery for centrally authorized paid Home Block passages. */
|
||||
final class HomeSmugglerTransport implements Listener {
|
||||
private static final Set<String> WORLDS = Set.of("arrakis", "caladan", "giedi_prime", "kaitain", "sigma_draconis_iv");
|
||||
private final JavaPlugin plugin;
|
||||
private final SharedGameApi api;
|
||||
private final GuildTransport guild;
|
||||
private final String server;
|
||||
private final Path receipts;
|
||||
private final Set<UUID> boarding = new HashSet<>(), arriving = new HashSet<>();
|
||||
|
||||
HomeSmugglerTransport(JavaPlugin plugin, SharedGameApi api, GuildTransport guild, String server) {
|
||||
this.plugin = plugin;
|
||||
this.api = api;
|
||||
this.guild = guild;
|
||||
this.server = server.replace('-', '_');
|
||||
receipts = plugin.getDataFolder().toPath().resolve("smuggler-home-receipts");
|
||||
Bukkit.getPluginManager().registerEvents(this, plugin);
|
||||
Bukkit.getScheduler().runTaskTimer(plugin, () -> Bukkit.getOnlinePlayers().forEach(this::arrive), 600L, 600L);
|
||||
}
|
||||
|
||||
@EventHandler public void join(PlayerJoinEvent event) {
|
||||
Bukkit.getScheduler().runTaskLater(plugin, () -> arrive(event.getPlayer()), 40L);
|
||||
}
|
||||
|
||||
CompletableFuture<JsonObject> request(Player player, UUID npc, JsonObject shown) {
|
||||
if (!Bukkit.isPrimaryThread() || !atContact(player, npc, shown))
|
||||
return CompletableFuture.failedFuture(new IOException("Stand beside the registered Home Block contact."));
|
||||
String action = shown.get("action").getAsString();
|
||||
if (!Set.of("home_list", "home_quote", "home_board").contains(action))
|
||||
return CompletableFuture.failedFuture(new IOException("Unknown Home Block passage action."));
|
||||
UUID actor = player.getUniqueId(), world = player.getWorld().getUID();
|
||||
boolean board = action.equals("home_board");
|
||||
if (board && !boarding.add(actor))
|
||||
return CompletableFuture.failedFuture(new IOException("Your smuggler passage is already being confirmed."));
|
||||
var input = shown.deepCopy();
|
||||
input.addProperty("uuid", actor.toString());
|
||||
input.addProperty("sourceWorld", server);
|
||||
input.add("sourceLocation", location(player.getLocation(), true));
|
||||
var result = new CompletableFuture<JsonObject>();
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
var response = board ? book(actor, input) : api.guild(input);
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
if (board) boarding.remove(actor);
|
||||
try {
|
||||
if (!player.isOnline() || !world.equals(player.getWorld().getUID()) || !atContact(player, npc, shown))
|
||||
throw new IOException("Return to the Home Block contact to continue.");
|
||||
if (board && "pending".equals(response.get("state").getAsString())) guild.dispatchHome(player, response);
|
||||
result.complete(response);
|
||||
} catch (Exception failure) {
|
||||
result.completeExceptionally(failure);
|
||||
}
|
||||
});
|
||||
} catch (Exception failure) {
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
if (board) boarding.remove(actor);
|
||||
result.completeExceptionally(failure);
|
||||
});
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
private JsonObject book(UUID actor, JsonObject input) throws Exception {
|
||||
Path file = receipt(actor, "board");
|
||||
if (Files.exists(file)) {
|
||||
var prior = read(file);
|
||||
if (binding(prior).equals(binding(input))) input.add("requestId", prior.get("requestId"));
|
||||
else {
|
||||
var recorded = api.homeGuild(prior);
|
||||
if (!sameId(recorded, prior) || !recorded.has("state")
|
||||
|| !Set.of("arrived", "expired", "cancelled", "delivered").contains(recorded.get("state").getAsString()))
|
||||
throw new IOException("Resume your original smuggler booking before starting another passage.");
|
||||
}
|
||||
}
|
||||
write(file, input);
|
||||
var ticket = api.guild(input);
|
||||
if (!sameId(ticket, input) || !ticket.has("home")) throw new IOException("The booking receipt could not be confirmed.");
|
||||
if (!"pending".equals(ticket.get("state").getAsString())) Files.deleteIfExists(file);
|
||||
return ticket;
|
||||
}
|
||||
|
||||
private static JsonObject binding(JsonObject input) {
|
||||
var binding = input.deepCopy();
|
||||
binding.remove("sourceLocation");
|
||||
binding.remove("requestId");
|
||||
return binding;
|
||||
}
|
||||
|
||||
private boolean atContact(Player player, UUID npc, JsonObject input) {
|
||||
if (!player.isOnline() || player.isDead() || !WORLDS.contains(server)
|
||||
|| player.getGameMode()!=GameMode.SURVIVAL && player.getGameMode()!=GameMode.ADVENTURE) return false;
|
||||
var origin = input.getAsJsonObject("origin");
|
||||
String marker = origin.get("kind").getAsString() + ":" + origin.get("id").getAsString();
|
||||
return player.getNearbyEntities(5, 3, 5).stream().anyMatch(entity -> entity instanceof LivingEntity
|
||||
&& entity.getUniqueId().equals(npc) && marker.equals(entity.getPersistentDataContainer()
|
||||
.get(OrganisationHomeNpcs.KEY, PersistentDataType.STRING)));
|
||||
}
|
||||
|
||||
private void arrive(Player player) {
|
||||
UUID actor = player.getUniqueId();
|
||||
if (!player.isOnline() || !WORLDS.contains(server) || !arriving.add(actor)) return;
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
Path file = receipt(actor, "arrival");
|
||||
var saved = Files.exists(file) ? read(file) : null;
|
||||
if (saved != null && saved.has("delivery")) {
|
||||
acknowledge(file, saved.getAsJsonObject("delivery"));
|
||||
finish(actor);
|
||||
return;
|
||||
}
|
||||
var reply = api.guild(message(actor, "home_arrive", null));
|
||||
if (!reply.has("ticket") || reply.get("ticket").isJsonNull()) { finish(actor); return; }
|
||||
var ticket = reply.getAsJsonObject("ticket");
|
||||
if (!server.equals(ticket.get("destination").getAsString())
|
||||
|| saved != null && !sameJourney(saved.getAsJsonObject("ticket"), ticket)) { finish(actor); return; }
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
try { land(player, file, ticket); }
|
||||
catch (RuntimeException invalid) { arriving.remove(actor); }
|
||||
});
|
||||
} catch (Exception failure) { finish(actor); }
|
||||
});
|
||||
}
|
||||
|
||||
private void land(Player player, Path file, JsonObject ticket) {
|
||||
UUID actor = player.getUniqueId();
|
||||
var home = ticket.getAsJsonObject("home");
|
||||
var position = home.getAsJsonObject("position");
|
||||
var world = Bukkit.getWorld(UUID.fromString(home.get("worldUuid").getAsString()));
|
||||
if (world == null || !player.isOnline()) { arriving.remove(actor); return; }
|
||||
int x = position.get("x").getAsInt(), y = position.get("y").getAsInt(), z = position.get("z").getAsInt();
|
||||
var landing = new Location(world, x + 0.5, y, z + 0.5);
|
||||
world.getChunkAtAsync(Math.floorDiv(x,16), Math.floorDiv(z,16)).whenComplete((chunk,error) ->
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
if (error != null || !player.isOnline() || !OrganisationTransport.safeLanding(landing)) {
|
||||
arriving.remove(actor);
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
var saved = new JsonObject();
|
||||
saved.add("ticket", ticket);
|
||||
write(file, saved);
|
||||
var paid = api.homeGuild(message(actor, "home_ready", ticket.get("requestId").getAsString()));
|
||||
if (sameId(ticket,paid) && paid.has("needsReview") && paid.get("needsReview").getAsBoolean()) {
|
||||
saved.add("review", paid);
|
||||
write(file, saved);
|
||||
finish(actor);
|
||||
return;
|
||||
}
|
||||
if (!sameJourney(ticket, paid) || !paid.has("paid") || !paid.get("paid").getAsBoolean()
|
||||
|| !"arrived".equals(paid.get("state").getAsString())) { finish(actor); return; }
|
||||
saved.add("ticket", paid);
|
||||
write(file, saved);
|
||||
Bukkit.getScheduler().runTask(plugin, () -> deliver(player, file, landing, saved));
|
||||
} catch (Exception failure) { finish(actor); }
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
private void deliver(Player player, Path file, Location landing, JsonObject saved) {
|
||||
UUID actor = player.getUniqueId();
|
||||
if (!player.isOnline() || !OrganisationTransport.safeLanding(landing)) { arriving.remove(actor); return; }
|
||||
player.teleportAsync(landing).whenComplete((ok,error) -> Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
var actual = player.getLocation();
|
||||
if (!Boolean.TRUE.equals(ok) || error != null || !sameBlock(landing,actual)) {
|
||||
arriving.remove(actor);
|
||||
return;
|
||||
}
|
||||
var receipt = message(actor, "home_delivered", saved.getAsJsonObject("ticket").get("requestId").getAsString());
|
||||
receipt.addProperty("arrivedAt", System.currentTimeMillis());
|
||||
receipt.add("arrival", location(actual, false));
|
||||
saved.add("delivery", receipt);
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try { write(file, saved); acknowledge(file, receipt); }
|
||||
catch (Exception failure) { plugin.getLogger().warning("Smuggler arrival receipt awaits acknowledgement."); }
|
||||
finally { finish(actor); }
|
||||
});
|
||||
player.sendMessage("J.A.R.V.I.S. · Smuggler Home Block arrival confirmed.");
|
||||
}));
|
||||
}
|
||||
|
||||
private void acknowledge(Path file, JsonObject receipt) throws Exception {
|
||||
var response = api.guild(receipt);
|
||||
if (sameId(response, receipt) && response.has("delivered") && response.get("delivered").getAsBoolean())
|
||||
Files.deleteIfExists(file);
|
||||
}
|
||||
|
||||
private void finish(UUID actor) { Bukkit.getScheduler().runTask(plugin, () -> arriving.remove(actor)); }
|
||||
|
||||
private JsonObject message(UUID actor, String action, String request) {
|
||||
var input = new JsonObject();
|
||||
input.addProperty("action", action);
|
||||
input.addProperty("uuid", actor.toString());
|
||||
input.addProperty("server", server);
|
||||
if (request != null) input.addProperty("requestId", request);
|
||||
return input;
|
||||
}
|
||||
|
||||
private static JsonObject location(Location location, boolean observed) {
|
||||
var proof = new JsonObject();
|
||||
proof.addProperty("worldUuid", location.getWorld().getUID().toString());
|
||||
var position = new JsonObject();
|
||||
position.addProperty("x", location.getBlockX());
|
||||
position.addProperty("y", location.getBlockY());
|
||||
position.addProperty("z", location.getBlockZ());
|
||||
proof.add("position", position);
|
||||
if (observed) proof.addProperty("observedAt", System.currentTimeMillis());
|
||||
return proof;
|
||||
}
|
||||
|
||||
private static boolean sameId(JsonObject a, JsonObject b) {
|
||||
return a.has("requestId") && a.get("requestId").equals(b.get("requestId"));
|
||||
}
|
||||
|
||||
private static boolean sameJourney(JsonObject a, JsonObject b) {
|
||||
return sameId(a,b) && a.has("home") && a.get("home").equals(b.get("home"))
|
||||
&& a.has("destination") && a.get("destination").equals(b.get("destination"))
|
||||
&& a.has("fareMinor") && a.get("fareMinor").equals(b.get("fareMinor"));
|
||||
}
|
||||
|
||||
private static boolean sameBlock(Location a, Location b) {
|
||||
return a.getWorld().equals(b.getWorld()) && a.getBlockX()==b.getBlockX()
|
||||
&& a.getBlockY()==b.getBlockY() && a.getBlockZ()==b.getBlockZ();
|
||||
}
|
||||
|
||||
private Path receipt(UUID actor, String kind) { return receipts.resolve(actor + "-" + kind + ".json"); }
|
||||
private static JsonObject read(Path path) throws IOException { return JsonParser.parseString(Files.readString(path)).getAsJsonObject(); }
|
||||
|
||||
private void write(Path path, JsonObject data) throws IOException {
|
||||
Files.createDirectories(receipts);
|
||||
Path temporary = Files.createTempFile(receipts, "receipt-", ".tmp");
|
||||
try {
|
||||
try (var stream = new java.io.FileOutputStream(temporary.toFile())) {
|
||||
stream.write(data.toString().getBytes(java.nio.charset.StandardCharsets.UTF_8));
|
||||
stream.getFD().sync();
|
||||
}
|
||||
Files.move(temporary, path, StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING);
|
||||
} finally { Files.deleteIfExists(temporary); }
|
||||
}
|
||||
}
|
||||
|
|
@ -23,6 +23,11 @@ public final class JarvisTranslator extends JavaPlugin implements Listener {
|
|||
public JsonObject requestWarMuster(UUID player,JsonObject input)throws Exception{if(input.has("uuid")||input.has("server"))throw new IllegalArgumentException("War muster identity is server-owned");var q=input.deepCopy();q.addProperty("uuid",player.toString());q.addProperty("server",serverKey);return api.warMuster(q);}
|
||||
public JsonObject warReport(UUID player){if(!Bukkit.isPrimaryThread())throw new IllegalStateException("Read war reports on the server thread");if(warCampaigns!=null)return warCampaigns.report(player);var result=new JsonObject();result.addProperty("ok",true);result.add("campaigns",new com.google.gson.JsonArray());return result;}
|
||||
private OrganisationTransport transport;
|
||||
private HomeSmugglerTransport homeSmuggler;
|
||||
public CompletableFuture<JsonObject> homeSmuggler(org.bukkit.entity.Player player, UUID contact, JsonObject input){
|
||||
if(homeSmuggler==null)return CompletableFuture.failedFuture(new IllegalStateException("Smuggler Navigator is unavailable."));
|
||||
return homeSmuggler.request(player,contact,input);
|
||||
}
|
||||
private GuildTransport guildTransport;
|
||||
private ExchangeInventory exchangeInventory;
|
||||
private QuestObservations questObservations;
|
||||
|
|
@ -103,7 +108,10 @@ public final class JarvisTranslator extends JavaPlugin implements Listener {
|
|||
|
||||
public JsonObject requestGuild(UUID player,JsonObject input)throws Exception{if(input.has("uuid")||input.has("sourceWorld"))throw new IllegalArgumentException("Guild identity and source are server-owned");var q=input.deepCopy();q.addProperty("uuid",player.toString());if(Set.of("quote","board","smuggler_quote","smuggler_board","smuggler_return").contains(q.get("action").getAsString()))q.addProperty("sourceWorld",serverKey.replace('-','_'));return api.guild(q);}
|
||||
public void returnGuild(org.bukkit.entity.Player player){guildTransport.returnToGuild(player);}
|
||||
public void dispatchGuild(org.bukkit.entity.Player player,JsonObject ticket)throws Exception{guildTransport.dispatch(player,ticket);}
|
||||
public void dispatchGuild(org.bukkit.entity.Player player,JsonObject ticket)throws Exception{
|
||||
if(ticket.has("smuggler")&&ticket.get("smuggler").getAsBoolean())starterKit.questCharacter(player,"esmar_tuek");
|
||||
guildTransport.dispatch(player,ticket);
|
||||
}
|
||||
public void returnSmuggler(org.bukkit.entity.Player player){starterKit.questCharacter(player,"esmar_tuek");guildTransport.returnToGuild(player,true);}
|
||||
public String requestHome(UUID player,String input)throws Exception{
|
||||
if(!isEnabled()||input==null||input.length()>1024)throw new IllegalStateException("Home bridge unavailable");
|
||||
|
|
@ -144,6 +152,7 @@ public final class JarvisTranslator extends JavaPlugin implements Listener {
|
|||
try{refits=new EquipmentRefits(exchangeInventory,itemMetadata,starterKit,new ItemMetadataPolicy(getResource("item-templates.json")),serverKey);}catch(java.io.IOException failure){throw new IllegalStateException("Refit template catalogue unavailable",failure);}
|
||||
transport=new OrganisationTransport(this,api,serverKey);
|
||||
guildTransport=new GuildTransport(this,api,serverKey);
|
||||
homeSmuggler=new HomeSmugglerTransport(this,api,guildTransport,serverKey);
|
||||
actions = new NativeActions(work -> Bukkit.getScheduler().runTaskAsynchronously(this, work),
|
||||
work -> Bukkit.getScheduler().runTask(this, work),
|
||||
command -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command));
|
||||
|
|
|
|||
|
|
@ -15,6 +15,14 @@ final class OrganisationTransport implements Listener {
|
|||
OrganisationTransport(JavaPlugin plugin,SharedGameApi api,String server){this.plugin=plugin;this.api=api;this.server=server;Bukkit.getPluginManager().registerEvents(this,plugin);plugin.getServer().getMessenger().registerOutgoingPluginChannel(plugin,"BungeeCord");}
|
||||
@EventHandler public void join(PlayerJoinEvent e){Bukkit.getScheduler().runTaskLater(plugin,()->arrival(e.getPlayer(),0),40L);}
|
||||
private JsonObject request(Player p,String action){var q=new JsonObject();q.addProperty("action",action);q.addProperty("uuid",p.getUniqueId().toString());q.addProperty("server",server);return q;}
|
||||
static boolean safeLanding(Location landing){
|
||||
World world=landing.getWorld();
|
||||
int x=landing.getBlockX(),y=landing.getBlockY(),z=landing.getBlockZ();
|
||||
if(world==null||y<=world.getMinHeight()||y>=world.getMaxHeight()-1||!world.isChunkLoaded(Math.floorDiv(x,16),Math.floorDiv(z,16)))return false;
|
||||
var feet=world.getBlockAt(x,y,z);var head=world.getBlockAt(x,y+1,z);var floor=world.getBlockAt(x,y-1,z);
|
||||
return feet.isPassable()&&!feet.isLiquid()&&head.isPassable()&&!head.isLiquid()&&floor.getType().isSolid()
|
||||
&&!Set.of(Material.LAVA,Material.FIRE,Material.CACTUS,Material.MAGMA_BLOCK,Material.CAMPFIRE,Material.SOUL_CAMPFIRE).contains(floor.getType());
|
||||
}
|
||||
void dispatch(Player p,JsonObject ticket){
|
||||
if(!p.isOnline()||ticket.get("expiresAt").getAsLong()<=System.currentTimeMillis())return;
|
||||
String target=ticket.getAsJsonObject("destination").get("server").getAsString();
|
||||
|
|
@ -35,9 +43,9 @@ final class OrganisationTransport implements Listener {
|
|||
world.getChunkAtAsync(Math.floorDiv(x,16),Math.floorDiv(z,16)).whenComplete((chunk,error)->Bukkit.getScheduler().runTask(plugin,()->{
|
||||
if(error!=null||!p.isOnline()||ticket.get("expiresAt").getAsLong()<=System.currentTimeMillis()){busy.remove(actor);return;}
|
||||
int landingY=ticket.get("action").getAsString().equals("war-transport")?world.getHighestBlockYAt(x,z)+1:y;
|
||||
var feet=world.getBlockAt(x,landingY,z);var floor=world.getBlockAt(x,landingY-1,z);
|
||||
if(!feet.isPassable()||!world.getBlockAt(x,landingY+1,z).isPassable()||!floor.getType().isSolid()||Set.of(Material.LAVA,Material.FIRE,Material.CACTUS,Material.MAGMA_BLOCK,Material.CAMPFIRE,Material.SOUL_CAMPFIRE).contains(floor.getType())){busy.remove(actor);p.sendMessage("The destination is unsafe. Your location was preserved.");return;}
|
||||
Location landing=new Location(world,x+0.5,landingY,z+0.5);p.teleportAsync(landing).thenAccept(ok->Bukkit.getScheduler().runTask(plugin,()->{busy.remove(actor);if(!ok)return;delivered.add(receipt);p.sendMessage("J.A.R.V.I.S. · organisation arrival confirmed.");var ack=request(p,"delivered");ack.addProperty("requestId",receipt.toString());Bukkit.getScheduler().runTaskAsynchronously(plugin,()->{try{api.organisation(ack);}catch(Exception pending){plugin.getLogger().warning("Organisation arrival receipt awaits acknowledgement: "+receipt);}});}));
|
||||
Location landing=new Location(world,x+0.5,landingY,z+0.5);
|
||||
if(!safeLanding(landing)){busy.remove(actor);p.sendMessage("The destination is unsafe. Your location was preserved.");return;}
|
||||
p.teleportAsync(landing).thenAccept(ok->Bukkit.getScheduler().runTask(plugin,()->{busy.remove(actor);if(!ok)return;delivered.add(receipt);p.sendMessage("J.A.R.V.I.S. · organisation arrival confirmed.");var ack=request(p,"delivered");ack.addProperty("requestId",receipt.toString());Bukkit.getScheduler().runTaskAsynchronously(plugin,()->{try{api.organisation(ack);}catch(Exception pending){plugin.getLogger().warning("Organisation arrival receipt awaits acknowledgement: "+receipt);}});}));
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ final class SharedGameApi implements AutoCloseable {
|
|||
JsonObject redeemItem(JsonObject data)throws Exception{return post("/internal/game/item-redeem",data,16384,true);}
|
||||
JsonObject rihla(JsonObject data)throws Exception{return post("/internal/game/rihla",data,262144,true);}
|
||||
JsonObject guild(JsonObject data)throws Exception{return post("/internal/game/guild",data);}
|
||||
JsonObject homeGuild(JsonObject data)throws Exception{return post("/internal/game/guild",data,262144,true);}
|
||||
JsonObject home(JsonObject data)throws Exception{return post("/internal/game/home",data,16384,true);}
|
||||
JsonObject warMuster(JsonObject data)throws Exception{return post("/internal/game/war-muster",data,2000000,true);}
|
||||
JsonObject wars(JsonObject data)throws Exception{return post("/internal/game/wars",data,2000000,true);}
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff