Share exact Navigator request builders with contract fixtures
This commit is contained in:
parent
9baca377a7
commit
d45fe6471c
2 changed files with 47 additions and 18 deletions
|
|
@ -110,20 +110,24 @@ final class OrganisationMenus implements Listener {
|
|||
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"));
|
||||
}
|
||||
var booking=smugglerBooking(target,quote,UUID.randomUUID());
|
||||
confirmSmugglerPassage(player,view,()->smugglerRequest(player,contact,origin,"home_board",booking,
|
||||
ticket->player.sendMessage("Smuggler passage: "+ticket.get("state").getAsString())),back);
|
||||
});
|
||||
}
|
||||
static JsonObject smugglerBooking(JsonObject target,JsonObject quote,UUID requestId){
|
||||
var booking=new JsonObject();booking.add("target",target);
|
||||
booking.addProperty("requestId",requestId.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"));
|
||||
}
|
||||
return booking;
|
||||
}
|
||||
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);
|
||||
var request=smugglerFields(origin,action,fields);
|
||||
player.closeInventory();
|
||||
try{
|
||||
bridge.homeSmuggler(player,contact,request).whenComplete((response,failure)->Bukkit.getScheduler().runTask(plugin,()->{
|
||||
|
|
@ -135,6 +139,9 @@ final class OrganisationMenus implements Listener {
|
|||
}));
|
||||
}catch(Exception failure){busy.remove(player.getUniqueId());player.sendMessage("Smuggler Navigator is unavailable.");}
|
||||
}
|
||||
static JsonObject smugglerFields(JsonObject origin,String action,JsonObject fields){
|
||||
var request=fields.deepCopy();request.addProperty("action",action);request.add("origin",origin);return request;
|
||||
}
|
||||
void smugglerNavigator(Player player, List<SmugglerDestinations.Destination> destinations,
|
||||
int pageNumber, Consumer<SmugglerDestinations.Destination> select, Runnable back) {
|
||||
var screen = panel(player, "Smuggler Navigator", false);
|
||||
|
|
|
|||
|
|
@ -92,9 +92,7 @@ final class QuestMenus implements Listener {
|
|||
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());
|
||||
var board=esmarBooking(quote,offer,requestId);
|
||||
smugglerRequest(p,board,ticket->{try{bridge.dispatchGuild(p,ticket);}catch(Exception error){
|
||||
p.sendMessage("The transfer was not dispatched; unused reservation expires.");
|
||||
}});
|
||||
|
|
@ -102,6 +100,11 @@ final class QuestMenus implements Listener {
|
|||
put(screen,49,"Back","Smuggler Navigator",Material.ARROW,()->smugglerMenu(p,data,role));
|
||||
show(p,screen);
|
||||
}
|
||||
static JsonObject esmarBooking(JsonObject quote,GuildRoutes.Offer offer,UUID requestId){
|
||||
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());return board;
|
||||
}
|
||||
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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff