Share exact Navigator request builders with contract fixtures
This commit is contained in:
parent
9baca377a7
commit
d45fe6471c
3 changed files with 47 additions and 18 deletions
|
|
@ -19,7 +19,7 @@ final class GuildTransport implements Listener {
|
|||
void returnToGuild(Player p){returnToGuild(p,false);}
|
||||
void returnToGuild(Player p,boolean smuggler){
|
||||
if(!Bukkit.isPrimaryThread())throw new IllegalStateException("Request Guild return on the server thread");
|
||||
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");
|
||||
if(!p.isOnline()||!busy.add(p.getUniqueId()))return;UUID id=p.getUniqueId(),world=p.getWorld().getUID();var q=returnRequest(id,server,smuggler);
|
||||
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;}
|
||||
String target=result.has("destination")&&!result.get("destination").isJsonNull()?result.get("destination").getAsString():"";
|
||||
|
|
@ -27,6 +27,9 @@ final class GuildTransport implements Listener {
|
|||
try{p.closeInventory();connect(p,target);}catch(IOException failed){p.sendMessage("Guild return could not be sent. No fare was taken.");}
|
||||
});});
|
||||
}
|
||||
static JsonObject returnRequest(UUID actor,String server,boolean smuggler){
|
||||
var q=new JsonObject();q.addProperty("action",smuggler?"smuggler_return":"travel_check");q.addProperty("uuid",actor.toString());q.addProperty("sourceWorld",server);if(!smuggler)q.addProperty("destination","lobby");return q;
|
||||
}
|
||||
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();
|
||||
|
|
|
|||
|
|
@ -55,10 +55,7 @@ final class HomeSmugglerTransport implements Listener {
|
|||
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 input = sourceRequest(shown, actor, server, location(player.getLocation(), true));
|
||||
var result = new CompletableFuture<JsonObject>();
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
|
|
@ -84,6 +81,14 @@ final class HomeSmugglerTransport implements Listener {
|
|||
return result;
|
||||
}
|
||||
|
||||
static JsonObject sourceRequest(JsonObject shown, UUID actor, String server, JsonObject proof) {
|
||||
var input = shown.deepCopy();
|
||||
input.addProperty("uuid", actor.toString());
|
||||
input.addProperty("sourceWorld", server);
|
||||
input.add("sourceLocation", proof);
|
||||
return input;
|
||||
}
|
||||
|
||||
private JsonObject book(UUID actor, JsonObject input) throws Exception {
|
||||
Path file = receipt(actor, "board");
|
||||
if (Files.exists(file)) {
|
||||
|
|
@ -212,6 +217,10 @@ final class HomeSmugglerTransport implements Listener {
|
|||
private void finish(UUID actor) { Bukkit.getScheduler().runTask(plugin, () -> arriving.remove(actor)); }
|
||||
|
||||
private JsonObject message(UUID actor, String action, String request) {
|
||||
return destinationRequest(actor, server, action, request);
|
||||
}
|
||||
|
||||
static JsonObject destinationRequest(UUID actor, String server, String action, String request) {
|
||||
var input = new JsonObject();
|
||||
input.addProperty("action", action);
|
||||
input.addProperty("uuid", actor.toString());
|
||||
|
|
@ -220,7 +229,7 @@ final class HomeSmugglerTransport implements Listener {
|
|||
return input;
|
||||
}
|
||||
|
||||
private static JsonObject location(Location location, boolean observed) {
|
||||
static JsonObject location(Location location, boolean observed) {
|
||||
var proof = new JsonObject();
|
||||
proof.addProperty("worldUuid", location.getWorld().getUID().toString());
|
||||
var position = new JsonObject();
|
||||
|
|
|
|||
|
|
@ -106,7 +106,14 @@ public final class JarvisTranslator extends JavaPlugin implements Listener {
|
|||
return api.rihla(query);
|
||||
}
|
||||
|
||||
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 JsonObject requestGuild(UUID player,JsonObject input)throws Exception{return api.guild(guildPayload(player,input,serverKey));}
|
||||
static JsonObject guildPayload(UUID player,JsonObject input,String source){
|
||||
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",source.replace('-','_'));
|
||||
return q;
|
||||
}
|
||||
public void returnGuild(org.bukkit.entity.Player player){guildTransport.returnToGuild(player);}
|
||||
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");
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff