Add the Guild and Smuggler Navigator routes #29
33 changed files with 1193 additions and 60 deletions
49
.forgejo/workflows/navigator.yml
Normal file
49
.forgejo/workflows/navigator.yml
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
name: Guild and Smuggler Navigator Build
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches: ['feat/smuggler-navigator-*']
|
||||
|
||||
jobs:
|
||||
navigator:
|
||||
runs-on: dune-ci
|
||||
steps:
|
||||
- name: Check out exact revision
|
||||
shell: bash
|
||||
env:
|
||||
REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
git init .
|
||||
git -c http.extraheader="AUTHORIZATION: basic $(printf 'x-access-token:%s' "$REPO_TOKEN" | base64 -w0)" fetch --depth=1 https://www.dunerealms.com/git/unimatrix/plugins.git "$GITHUB_SHA"
|
||||
git checkout --detach FETCH_HEAD
|
||||
- uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: temurin
|
||||
java-version: '21'
|
||||
- uses: gradle/actions/setup-gradle@v4
|
||||
with:
|
||||
gradle-version: '9.2.1'
|
||||
- name: Build the reviewed Navigator plugin transition
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
for module in JarvisConnector DuneRealmsGUI DuneMenus; do
|
||||
gradle --no-daemon -p "$module" test jar
|
||||
done
|
||||
python3 tools/plugin_navigator_transition.py
|
||||
python3 tools/test_plugin_fleet_install.py -v
|
||||
python3 tools/test_plugin_pack_properties.py -v
|
||||
mkdir navigator-artifacts
|
||||
cp JarvisConnector/build/libs/jarvistranslator.jar DuneRealmsGUI/build/libs/DunerealmsGUI.jar DuneMenus/build/libs/DuneMenus.jar navigator-artifacts/
|
||||
printf '%s\n' "$(git rev-parse HEAD)" > navigator-artifacts/SOURCE_COMMIT
|
||||
python3 tools/build-unified-resourcepack.py --source "$GITHUB_SHA" --output "navigator-artifacts/DuneRealms-Resources-${GITHUB_SHA}.zip"
|
||||
echo "446c0b60fa6e6752ff5260bb22c9a76280b7b10ffa03c3cca4b08f4d9320105b navigator-artifacts/DuneRealms-Resources-${GITHUB_SHA}.zip" | sha256sum --check
|
||||
python3 tools/write-plugin-manifest.py navigator-artifacts "$GITHUB_SHA"
|
||||
cp tools/install-plugin-fleet.py tools/plugin_menu_pack.py tools/plugin_backend_abi.py tools/plugin_pillager_abi.py tools/plugin_navigator_transition.py tools/plugin_fleet_rollback.py tools/plugin_pack_properties.py tools/publish-plugin-menu.py tools/navigator-transition.json JarvisConnector/src/test/resources/retained-jarvis-public-abi.json navigator-artifacts/
|
||||
(cd navigator-artifacts && sha256sum -- *.jar *.zip *.json *.py SOURCE_COMMIT > SHA256SUMS)
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: DuneRealms-Navigator
|
||||
path: navigator-artifacts/
|
||||
if-no-files-found: error
|
||||
|
|
@ -50,7 +50,10 @@ jobs:
|
|||
run: |
|
||||
set -euo pipefail
|
||||
python3 tools/test_plugin_ci_policy.py -v
|
||||
python3 tools/test_plugin_pillager_profile.py -v
|
||||
pillager_input="$(mktemp -d)"
|
||||
python3 tools/plugin_navigator_transition.py --stage-pillager-baseline "$pillager_input/baseline"
|
||||
DUNE_PILLAGER_BASELINE_DIR="$pillager_input/baseline" python3 tools/test_plugin_pillager_profile.py -v
|
||||
python3 tools/plugin_navigator_transition.py
|
||||
python3 tools/test_plugin_pillager_art.py -v
|
||||
python3 tools/test_plugin_fleet_install.py -v
|
||||
python3 tools/test_plugin_menu_pack.py -v
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import java.security.MessageDigest
|
||||
plugins { java }
|
||||
group = "com.dunerealms"
|
||||
version = "2.0.7-pillager1"
|
||||
version = "2.0.8-navigator1"
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ final class CanvasProvider implements FullscreenProvider {
|
|||
if(services==null||!services.isEnabled())return false;
|
||||
Map<Integer,String> images=new HashMap<>();
|
||||
try{if(prepared)for(Card card:screen.cards()){var inventory=screen.contents();if(card.slot()>=0&&card.slot()<inventory.length){String image=art.image(inventory[card.slot()]);if(!image.isEmpty())images.put(card.slot(),image);}}}catch(Exception failure){plugin.getLogger().warning("Menu artwork unavailable: "+failure.getClass().getSimpleName());}
|
||||
Map<Integer,Runnable> actions=new HashMap<>();for(Card card:screen.cards()){actions.put(card.slot(),()->select.accept(card.slot()));if(SuppliedDocument.summary(card).size()>1)actions.put(1000+card.slot(),()->open(player,screen,select,close,card.slot()));}
|
||||
Map<Integer,Runnable> actions=new HashMap<>();for(Card card:screen.cards()){if(!card.enabled())continue;actions.put(card.slot(),()->select.accept(card.slot()));if(SuppliedDocument.summary(card).size()>1)actions.put(1000+card.slot(),()->open(player,screen,select,close,card.slot()));}
|
||||
try{return Boolean.TRUE.equals(services.getClass().getMethod("presentSuppliedMenu",Player.class,String.class,String.class,Map.class,Runnable.class).invoke(services,player,screen.title(),SuppliedDocument.html(screen.id(),screen.title(),screen.subtitle(),screen.cards(),screen.info(),images,selected),actions,close));}
|
||||
catch(ReflectiveOperationException failure){plugin.getLogger().warning("Menu canvas unavailable: "+failure.getClass().getSimpleName());return false;}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,4 +3,8 @@ package com.dunerealms.menus;
|
|||
import java.util.List;
|
||||
|
||||
/** One clickable thing on a menu, in renderer-neutral form (used for Bedrock forms and fullscreen). */
|
||||
public record Card(int slot, String title, List<String> lore, String material) {}
|
||||
public record Card(int slot, String title, List<String> lore, String material, boolean enabled) {
|
||||
public Card(int slot, String title, List<String> lore, String material) {
|
||||
this(slot, title, lore, material, true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ public final class DuneMenusPlugin extends JavaPlugin implements TabExecutor {
|
|||
public void openSharedMenu(Player player, String title, org.bukkit.inventory.Inventory model, Map<Integer,Runnable> actions) {
|
||||
if (!getServer().isPrimaryThread() || !player.isOnline() || !player.hasPermission("dunemenus.use")) return;
|
||||
String lower=title.toLowerCase(java.util.Locale.ROOT);
|
||||
String section=lower.contains("travel")||lower.contains("guild")?"travel":lower.contains("exchange")?"exchange":lower.contains("spice")?"spice":lower.contains("quest")?"missions":"hub";
|
||||
String section=lower.contains("smuggler")?"smuggler":lower.contains("travel")||lower.contains("guild")?"travel":lower.contains("exchange")?"exchange":lower.contains("spice")?"spice":lower.contains("quest")?"missions":"hub";
|
||||
new ServiceMenu(this,player,section,title,"",model,actions).open();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -149,11 +149,19 @@ abstract class Menu implements InventoryHolder {
|
|||
|
||||
private List<Card> snapshot() {
|
||||
List<Card> out = new ArrayList<>();
|
||||
if (routeCards()) {
|
||||
for (int slot = 0; slot < inv.getSize(); slot++) {
|
||||
ItemStack it = inv.getItem(slot);
|
||||
if (disabledRoute(it) && !buttons.containsKey(slot) && !plain(it).isBlank())
|
||||
out.add(new Card(slot, plain(it), loreOf(it), "gray_dye", false));
|
||||
}
|
||||
}
|
||||
for (int slot : buttons.keySet()) {
|
||||
ItemStack it = inv.getItem(slot);
|
||||
if (it == null || plain(it).isBlank()) continue;
|
||||
out.add(new Card(slot, plain(it), loreOf(it), it.getType().name().toLowerCase()));
|
||||
}
|
||||
if (routeCards()) out.sort(java.util.Comparator.comparingInt(Card::slot));
|
||||
return out;
|
||||
}
|
||||
|
||||
|
|
@ -161,7 +169,7 @@ abstract class Menu implements InventoryHolder {
|
|||
List<String> out = new ArrayList<>();
|
||||
for (int i = 0; i < inv.getSize(); i++) {
|
||||
ItemStack it = inv.getItem(i);
|
||||
if (it == null || buttons.containsKey(i) || it.getType().name().endsWith("_PANE")) continue;
|
||||
if (it == null || buttons.containsKey(i) || it.getType().name().endsWith("_PANE") || routeCards() && disabledRoute(it)) continue;
|
||||
String n = plain(it);
|
||||
if (n.isBlank()) continue;
|
||||
List<String> lore = loreOf(it).stream().filter(s -> !s.isBlank()).toList();
|
||||
|
|
@ -170,6 +178,9 @@ abstract class Menu implements InventoryHolder {
|
|||
return out;
|
||||
}
|
||||
|
||||
private boolean routeCards() { return id().equals("travel") || id().equals("smuggler"); }
|
||||
private static boolean disabledRoute(ItemStack item) { return item != null && item.getType()==Material.GRAY_DYE; }
|
||||
|
||||
private void present() {
|
||||
long shown = ++presentation;
|
||||
var world = player.getWorld().getUID();
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -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(),
|
||||
"<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); });
|
||||
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(), w.up() ? fare : "", "",
|
||||
w.up() ? "<yellow>Click to travel" : "");
|
||||
if (w.up()) put(STARS[i], icon, t -> { end(); book(w); });
|
||||
else put(STARS[i], icon);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ public class RendererVerification {
|
|||
}
|
||||
System.out.println(id+": parser clean; "+cards.size()+" action hitboxes; maxScroll="+frame.maxScroll()+"; render-and-hitbox-ms="+((System.nanoTime()-started)/1_000_000));
|
||||
}
|
||||
verifyNavigators(dir,loader);
|
||||
var actualIcon=Path.of("../network/resource-pack/central/overlay/assets/dunerealms/textures/item/equipment/legendary_mk14_axe.png");Path iconTarget=dir.resolve("pack/assets/dunerealms/textures/item/equipment/legendary_mk14_axe.png");Files.createDirectories(iconTarget.getParent());Files.copy(actualIcon,iconTarget,StandardCopyOption.REPLACE_EXISTING);
|
||||
for(String name:List.of("item/iron_sword","block/cobblestone")){Path target=dir.resolve("pack/assets/minecraft/textures/"+name+".png");Files.createDirectories(target.getParent());Files.copy(Path.of("../network/resource-pack/vanilla-art/overlay/assets/minecraft/textures/"+name+".png"),target,StandardCopyOption.REPLACE_EXISTING);}
|
||||
var listing=new Card(13,"\uE400§6Paul's chopper",List.of("LEGENDARY | MK XIV","Used by Paul himself.","Efficiency VIII","Fortune IV","Mending I","Unbreaking IV","Seller: J.A.R.V.I.S. HQ","1 available · 500.00 DM each"),"netherite_axe");
|
||||
|
|
@ -48,4 +49,61 @@ public class RendererVerification {
|
|||
for(var element:listingPage.document.select(".market-tool,[data-slot='1013']")){var bounds=listingFrame.boundsOf(element);var at=listingFrame.elementAt(bounds.getCenterX(),bounds.getCenterY());if(at==null||!at.closest("[data-slot]").attr("data-slot").equals(element.attr("data-slot")))throw new AssertionError("Detail control hitbox");}
|
||||
System.out.println("PASS: "+checked+" direct action hitboxes across15 menu families.");
|
||||
}
|
||||
|
||||
private static void verifyNavigators(Path dir,Page.Loader loader)throws Exception{
|
||||
List<Card> guild=List.of(
|
||||
new Card(4,"Arrakduin",List.of("Fare: 125.00 DM"),"compass"),
|
||||
new Card(19,"Kaladam",List.of("Your House has no Imperial passage for this destination."),"gray_dye",false),
|
||||
new Card(25,"Giedermark",List.of("Current Guild embargo"),"gray_dye",false),
|
||||
new Card(37,"Kaiterhof",List.of("Fare: 125.00 DM"),"compass"),
|
||||
new Card(43,"Sigmadraken IV",List.of("World currently offline"),"gray_dye",false),
|
||||
new Card(45,"Back",List.of(),"arrow"));
|
||||
var owned=new ArrayList<Card>();
|
||||
for(int i=0;i<28;i++){
|
||||
int slot=10+i/7*9+i%7;
|
||||
owned.add(new Card(slot,"Company Home Block "+(i+1),
|
||||
List.of(i%2==0?"Kaladam · View fare":"No registered Home Block"),
|
||||
i%2==0?"cyan_banner":"gray_dye",i%2==0));
|
||||
}
|
||||
owned.add(new Card(45,"Back",List.of(),"arrow"));
|
||||
owned.add(new Card(51,"Next page",List.of(),"arrow"));
|
||||
var confirm=List.of(new Card(22,"Company Home Block",List.of("Smuggler fare: 125.07 DM"),"compass"),
|
||||
new Card(31,"Confirm paid passage",List.of("Payment settles after arrival"),"lime_dye"),
|
||||
new Card(45,"Back",List.of(),"arrow"));
|
||||
for(var family:Map.of("guild",guild,"esmar",guild,"owned-home",owned,"confirm",confirm).entrySet()){
|
||||
String name=family.getKey();
|
||||
var cards=family.getValue();
|
||||
String html=SuppliedDocument.html(name.equals("guild")?"travel":"smuggler","Smuggler Navigator","Choose a destination",cards,List.of());
|
||||
var page=Page.of(html,dir.resolve(name+"-navigator.html"),loader);
|
||||
var frame=HtmlRenderer.render(page,1536,896,1.5,0,Selector.State.NONE);
|
||||
if(!page.problems.isEmpty())throw new AssertionError(name+" parser problems "+page.problems);
|
||||
var rendered=page.document.select("main > *");
|
||||
if(rendered.size()!=cards.size())throw new AssertionError(name+" duplicate or missing rows: "+rendered.size());
|
||||
for(int index=0;index<cards.size();index++){
|
||||
Card card=cards.get(index);
|
||||
var element=rendered.get(index);
|
||||
var bounds=frame.boundsOf(element);
|
||||
if(bounds==null||bounds.isEmpty())throw new AssertionError(name+" invisible "+card.title());
|
||||
if(!card.enabled()&&(!element.hasClass("locked")||!element.select("[data-slot]").isEmpty()||element.hasAttr("data-slot")))
|
||||
throw new AssertionError(name+" disabled destination has an action "+card.title());
|
||||
if(!card.enabled()&&!element.text().contains(card.lore().get(0)))
|
||||
throw new AssertionError(name+" missing unavailable reason "+card.title());
|
||||
for(var text:element.select("h2,p")){
|
||||
var box=frame.boundsOf(text);
|
||||
if(box!=null&&(box.getMinX()<bounds.getMinX()-1||box.getMaxX()>bounds.getMaxX()+1
|
||||
||box.getMinY()<bounds.getMinY()-1||box.getMaxY()>bounds.getMaxY()+1))
|
||||
throw new AssertionError(name+" text outside card "+card.title()+": "+box+" vs "+bounds);
|
||||
}
|
||||
if(card.enabled()){
|
||||
double scroll=Math.max(0,Math.min(frame.maxScroll(),bounds.getCenterY()-260));
|
||||
var visible=HtmlRenderer.render(page,1536,896,1.5,scroll,Selector.State.NONE);
|
||||
var hit=visible.elementAt(bounds.getCenterX(),bounds.getCenterY()-scroll);
|
||||
if(hit==null||hit.closest("[data-slot]")==null||!hit.closest("[data-slot]").attr("data-slot").equals(""+card.slot()))
|
||||
throw new AssertionError(name+" unreachable action "+card.title());
|
||||
}
|
||||
}
|
||||
ImageIO.write(frame.image(),"png",dir.resolve(name+"-navigator-engine.png").toFile());
|
||||
System.out.println(name+" navigator: "+cards.size()+" distinct rows, contained text, disabled routes have no actions");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
plugins { java }
|
||||
group = "com.dunerealms"
|
||||
version = "1.1.39"
|
||||
version = "1.1.40-navigator1"
|
||||
repositories { mavenCentral(); maven("https://repo.papermc.io/repository/maven-public/"); maven("https://repo.opencollab.dev/main/") }
|
||||
dependencies {
|
||||
compileOnly("io.papermc.paper:paper-api:1.21.8-R0.1-SNAPSHOT")
|
||||
|
|
|
|||
|
|
@ -136,19 +136,54 @@ 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){
|
||||
item.setType(Material.GRAY_DYE);
|
||||
var meta=item.getItemMeta();meta.setItemModel(null);meta.displayName(Component.text(name,NamedTextColor.GRAY));item.setItemMeta(meta);
|
||||
}
|
||||
screen.inventory.setItem(centre,item);
|
||||
if(reason==null)screen.actions.put(centre,()->bookPassage(p,data,route.world()));
|
||||
}
|
||||
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 +220,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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,139 @@ 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=parseHomeDestinations(list);
|
||||
smugglerNavigator(player,destinations,0,destination->quoteSmuggler(player,contact,origin,destination,
|
||||
()->openSmuggler(player,contact,origin,back)),back);
|
||||
});
|
||||
}
|
||||
static List<SmugglerDestinations.Destination> parseHomeDestinations(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));
|
||||
}
|
||||
return List.copyOf(destinations);
|
||||
}
|
||||
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=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=smugglerFields(origin,action,fields);
|
||||
player.closeInventory();
|
||||
try{
|
||||
requestHomeSmuggler(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.");}
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
private static java.util.concurrent.CompletableFuture<JsonObject> requestHomeSmuggler(Player player,UUID contact,JsonObject request)
|
||||
throws ReflectiveOperationException {
|
||||
var translator=Bukkit.getPluginManager().getPlugin("JarvisTranslator");
|
||||
if(translator==null||!translator.isEnabled())throw new IllegalStateException("J.A.R.V.I.S. is unavailable.");
|
||||
return (java.util.concurrent.CompletableFuture<JsonObject>)translator.getClass()
|
||||
.getMethod("homeSmuggler",Player.class,UUID.class,JsonObject.class).invoke(translator,player,contact,request);
|
||||
}
|
||||
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);
|
||||
var page = SmugglerDestinations.page(destinations, pageNumber);
|
||||
int index = 0;
|
||||
for (var destination : page.destinations()) {
|
||||
String kind = switch (destination.kind()) {
|
||||
case CLAN -> "Clan";
|
||||
case COMPANY -> "Company";
|
||||
case WORLD -> "World";
|
||||
};
|
||||
String location = destination.world() == null ? "No registered Home Block" : destination.world();
|
||||
String details = kind + " · " + location;
|
||||
Material icon = switch (destination.kind()) {
|
||||
case CLAN -> Material.GREEN_BANNER;
|
||||
case COMPANY -> Material.CYAN_BANNER;
|
||||
case WORLD -> Material.COMPASS;
|
||||
};
|
||||
if (destination.available()) {
|
||||
put(screen, SmugglerDestinations.slot(index++), destination.name(), details + "\nView fare", icon,
|
||||
() -> select.accept(destination));
|
||||
} else {
|
||||
int slot = SmugglerDestinations.slot(index++);
|
||||
put(screen, slot, destination.name(), details + "\n" + destination.unavailableReason(), Material.GRAY_DYE, null);
|
||||
screen.choices.put(slot,new BedrockForms.Choice("§8"+destination.name()+" · "+destination.unavailableReason(),details,
|
||||
()->smugglerNavigator(player,destinations,pageNumber,select,back)));
|
||||
}
|
||||
}
|
||||
if (page.destinations().isEmpty()) {
|
||||
put(screen, 22, "No destinations", "There are no destinations to display.", Material.MAP,
|
||||
() -> smugglerNavigator(player, destinations, pageNumber, select, back));
|
||||
}
|
||||
if (page.hasPrevious()) put(screen, 47, "Previous page", "Earlier destinations", Material.ARROW,
|
||||
() -> smugglerNavigator(player, destinations, pageNumber - 1, select, back));
|
||||
if (page.hasNext()) put(screen, 51, "Next page", "More destinations", Material.ARROW,
|
||||
() -> smugglerNavigator(player, destinations, pageNumber + 1, select, back));
|
||||
put(screen, 45, "Back", "Return to the contact", Material.ARROW, back);
|
||||
close(screen, player);
|
||||
show(player, screen);
|
||||
}
|
||||
void confirmSmugglerPassage(Player player, SmugglerDestinations.Quote quote, Runnable board, Runnable back) {
|
||||
var screen = panel(player, "Confirm smuggler passage", false);
|
||||
var destination = quote.destination();
|
||||
put(screen, 22, destination.name(), destination.world() + "\nSmuggler fare: " + quote.fare(), Material.COMPASS, back);
|
||||
if (quote.canBoard()) {
|
||||
put(screen, 31, "Confirm paid passage", "Reserve the quoted fare. Payment settles on arrival.", Material.LIME_DYE, board);
|
||||
} else {
|
||||
put(screen, 31, "Passage unavailable", quote.unavailableReason(), Material.GRAY_DYE, null);
|
||||
screen.choices.put(31,new BedrockForms.Choice("§8"+quote.unavailableReason(),"Passage unavailable",back));
|
||||
}
|
||||
put(screen, 45, "Back", "Smuggler Navigator", Material.ARROW, back);
|
||||
close(screen, player);
|
||||
show(player, screen);
|
||||
}
|
||||
private void warStatus(Player p,Runnable back){
|
||||
var screen=panel(p,"War report",false);JsonObject result;
|
||||
try{result=bridge.warReport(p.getUniqueId());}catch(Exception unavailable){p.sendMessage("War reports are temporarily unavailable.");return;}
|
||||
|
|
@ -110,7 +247,7 @@ final class OrganisationMenus implements Listener {
|
|||
private static String name(JsonObject row){return row.get("name").getAsString();}
|
||||
private Panel panel(Player p,String title,boolean company){var panel=new Panel(p);panel.title=title;panel.inventory=Bukkit.createInventory(panel,54,Component.text(title,company?NamedTextColor.AQUA:NamedTextColor.GOLD));for(int slot=0;slot<54;slot++)if(slot<9||slot>=45||slot%9==0||slot%9==8){var trim=new ItemStack(company?Material.CYAN_STAINED_GLASS_PANE:Material.GREEN_STAINED_GLASS_PANE);var meta=trim.getItemMeta();meta.displayName(Component.empty());trim.setItemMeta(meta);panel.inventory.setItem(slot,trim);}return panel;}
|
||||
private Panel panel(Player p,String title,int screen){if(!artwork.test(p)||BedrockForms.isBedrock(p))return panel(p,title,screen==2);var panel=new Panel(p);panel.title=title;panel.artwork=true;panel.inventory=Bukkit.createInventory(panel,54,Component.text(GuiArtwork.background(0xE340+screen),NamedTextColor.WHITE).font(net.kyori.adventure.key.Key.key("dunerealms:house_selector")));return panel;}
|
||||
private void put(Panel panel,int slot,String title,String description,Material material,Runnable action){var item=new ItemStack(panel.artwork?Material.PAPER:material);var meta=item.getItemMeta();meta.displayName(Component.text(title,NamedTextColor.GOLD));meta.lore(Arrays.stream(description.split("\n")).map(line->Component.text(line,NamedTextColor.GRAY)).toList());if(panel.artwork)meta.setItemModel(new NamespacedKey("dunerealms","drgui_transparent"));item.setItemMeta(meta);panel.inventory.setItem(slot,item);panel.actions.put(slot,action);if(panel.artwork&&Set.of(19,22,25,37,40,43).contains(slot))for(int alias:new int[]{slot-1,slot+1}){panel.inventory.setItem(alias,item.clone());panel.actions.put(alias,action);}panel.choices.put(slot,new BedrockForms.Choice(title,description,action));}
|
||||
private void put(Panel panel,int slot,String title,String description,Material material,Runnable action){var item=new ItemStack(panel.artwork?Material.PAPER:material);var meta=item.getItemMeta();meta.displayName(Component.text(title,NamedTextColor.GOLD));meta.lore(Arrays.stream(description.split("\n")).map(line->Component.text(line,NamedTextColor.GRAY)).toList());if(panel.artwork)meta.setItemModel(new NamespacedKey("dunerealms","drgui_transparent"));item.setItemMeta(meta);panel.inventory.setItem(slot,item);if(action==null)return;panel.actions.put(slot,action);if(panel.artwork&&Set.of(19,22,25,37,40,43).contains(slot))for(int alias:new int[]{slot-1,slot+1}){panel.inventory.setItem(alias,item.clone());panel.actions.put(alias,action);}panel.choices.put(slot,new BedrockForms.Choice(title,description,action));}
|
||||
private void close(Panel panel,Player p){put(panel,53,"Close","Return to the game",Material.BARRIER,p::closeInventory);}
|
||||
private void show(Player p,Panel panel){if(BedrockForms.isBedrock(p)){BedrockForms.show(plugin,p,panel.title,"Current organisation keys",List.copyOf(panel.choices.values()));return;}if(MCGUIMenus.show(p,panel.title,"Current organisation keys",panel.inventory,panel.actions,panel.gate))return;p.openInventory(panel.inventory);Bukkit.getScheduler().runTaskLater(plugin,panel.gate::expire,2400L);}
|
||||
@EventHandler public void click(InventoryClickEvent e){if(!(e.getView().getTopInventory().getHolder() instanceof Panel panel))return;e.setCancelled(true);if(!(e.getWhoClicked() instanceof Player p)||!panel.owner.equals(p.getUniqueId())||e.getClickedInventory()!=panel.inventory||e.getClick()!=ClickType.LEFT)return;var action=panel.actions.get(e.getRawSlot());if(action!=null&&panel.gate.claim(p.getUniqueId()))Bukkit.getScheduler().runTask(plugin,()->{if(p.isOnline()&&p.getOpenInventory().getTopInventory()==panel.inventory)action.run();});}
|
||||
|
|
|
|||
|
|
@ -50,11 +50,73 @@ 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=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.");
|
||||
}});
|
||||
});
|
||||
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);
|
||||
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,35 @@
|
|||
package com.dunerealms.gui;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/** Display data from the travel authority. Availability is never inferred by the menu. */
|
||||
final class SmugglerDestinations {
|
||||
private static final int COLUMNS = 7;
|
||||
private static final int PAGE_SIZE = 4 * COLUMNS;
|
||||
|
||||
enum Kind { CLAN, COMPANY, WORLD }
|
||||
|
||||
record Destination(String id, Kind kind, String name, String world, String unavailableReason) {
|
||||
boolean available() { return unavailableReason == null; }
|
||||
}
|
||||
|
||||
record Page(List<Destination> destinations, boolean hasPrevious, boolean hasNext) {}
|
||||
|
||||
record Quote(Destination destination, long fareMinor, String unavailableReason) {
|
||||
String fare() { return BigDecimal.valueOf(fareMinor, 2).toPlainString() + " DM"; }
|
||||
boolean canBoard() { return unavailableReason == null; }
|
||||
}
|
||||
|
||||
static Page page(List<Destination> destinations, int requestedPage) {
|
||||
int lastPage = Math.max(0, (destinations.size() - 1) / PAGE_SIZE);
|
||||
int page = Math.max(0, Math.min(requestedPage, lastPage));
|
||||
int start = page * PAGE_SIZE;
|
||||
return new Page(List.copyOf(destinations.subList(start, Math.min(start + PAGE_SIZE, destinations.size()))),
|
||||
page > 0, page < lastPage);
|
||||
}
|
||||
|
||||
static int slot(int index) {
|
||||
return 10 + index / COLUMNS * 9 + index % COLUMNS;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
name: DunerealmsGUI
|
||||
main: com.dunerealms.gui.DuneGUI
|
||||
version: 1.1.39
|
||||
version: 1.1.40-navigator1
|
||||
api-version: '1.21.8'
|
||||
depend: [JarvisTranslator]
|
||||
softdepend: [Citizens, MCGUI, DecentHolograms, DuneLobby, DuneCore, DuneEss, DuneNPC, Vault, floodgate, ViaVersion]
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
package com.dunerealms.gui;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.IntStream;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class SmugglerDestinationsTest {
|
||||
@Test void pagesContainEveryOwnedOrganisationWithoutUsingTheFrameOrNavigationRow() {
|
||||
var destinations = IntStream.range(0, 30)
|
||||
.mapToObj(i -> new SmugglerDestinations.Destination(Integer.toString(i),
|
||||
SmugglerDestinations.Kind.COMPANY, "Company " + i, "Caladan", null))
|
||||
.toList();
|
||||
var first = SmugglerDestinations.page(destinations, 0);
|
||||
var last = SmugglerDestinations.page(destinations, 1);
|
||||
assertEquals(destinations.subList(0, 28), first.destinations());
|
||||
assertEquals(destinations.subList(28, 30), last.destinations());
|
||||
assertFalse(first.hasPrevious());
|
||||
assertTrue(first.hasNext());
|
||||
assertTrue(last.hasPrevious());
|
||||
assertFalse(last.hasNext());
|
||||
var slots = IntStream.range(0, 28).map(SmugglerDestinations::slot).boxed().toList();
|
||||
assertEquals(28, slots.stream().distinct().count());
|
||||
assertTrue(slots.stream().allMatch(slot -> slot >= 9 && slot < 45 && slot % 9 != 0 && slot % 9 != 8));
|
||||
}
|
||||
|
||||
@Test void unavailableOwnedDestinationsStayVisibleAndTheQuoteKeepsTheExactFare() {
|
||||
var unavailable = new SmugglerDestinations.Destination("1", SmugglerDestinations.Kind.CLAN,
|
||||
"Clan", null, "No registered Home Block");
|
||||
assertEquals(List.of(unavailable), SmugglerDestinations.page(List.of(unavailable), 0).destinations());
|
||||
assertFalse(unavailable.available());
|
||||
var quote = new SmugglerDestinations.Quote(unavailable, 12507, "Destination unavailable");
|
||||
assertEquals("125.07 DM", quote.fare());
|
||||
assertFalse(quote.canBoard());
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue

Staff