forked from unimatrix/web
Merge game services into the DuneMenus plugin
This commit is contained in:
parent
022b8f3823
commit
9144318f5f
79 changed files with 290 additions and 369 deletions
|
|
@ -34,7 +34,7 @@ jobs:
|
|||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
modules=(DuneEss DuneLobby DuneNPC DuneRealms-minecraft-only DuneRealmsGUI DuneTerrain JarvisConnector)
|
||||
modules=(DuneEss DuneLobby DuneNPC DuneRealms-minecraft-only DuneTerrain JarvisConnector)
|
||||
if [[ -f network/proxy/central-pack/build.gradle.kts ]]; then
|
||||
modules+=(network/proxy/central-pack)
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -49,17 +49,17 @@ jobs:
|
|||
gradle-version: '9.2.1'
|
||||
- name: Build and test pack delivery plugin
|
||||
run: |
|
||||
gradle --no-daemon -p DuneRealmsGUI test jar
|
||||
gradle --no-daemon -p DuneTerrain test jar
|
||||
gradle --no-daemon -p DuneRealms-minecraft-only test jar
|
||||
gradle --no-daemon -p JarvisConnector test jar
|
||||
gradle --no-daemon -p DuneMenus test jar
|
||||
- name: Upload reviewed packs and GUI plugin
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: DuneRealms-Resourcepack-Repair
|
||||
path: |
|
||||
resourcepack-output/
|
||||
DuneRealmsGUI/build/libs/DunerealmsGUI.jar
|
||||
DuneMenus/build/libs/DuneMenus.jar
|
||||
DuneTerrain/build/libs/DuneRealms-Terrain.jar
|
||||
DuneRealms-minecraft-only/build/libs/DuneRealms-Core.jar
|
||||
JarvisConnector/build/libs/jarvistranslator.jar
|
||||
|
|
|
|||
|
|
@ -24,15 +24,15 @@ final class DuneCommands implements TabExecutor {
|
|||
Map.entry("accept", "jarvistranslator:accept"), Map.entry("join", "jarvistranslator:join"),
|
||||
Map.entry("leave", "jarvistranslator:leave"), Map.entry("redeem", "jarvistranslator:redeem"),
|
||||
Map.entry("jarvis", "jarvistranslator:jarvistranslator"),
|
||||
Map.entry("faction", "dunerealmsgui:house"), Map.entry("house", "dunerealmsgui:house"),
|
||||
Map.entry("start", "dunerealmsgui:start"), Map.entry("mentat", "dunerealmsgui:mentat"),
|
||||
Map.entry("exchange", "dunerealmsgui:exchange"), Map.entry("spice", "dunerealmsgui:spice"),
|
||||
Map.entry("sell", "dunerealmsgui:sellall"), Map.entry("sellall", "dunerealmsgui:sellall"),
|
||||
Map.entry("clan", "dunerealmsgui:clan"),
|
||||
Map.entry("company", "dunerealmsgui:company"), Map.entry("office", "dunerealmsgui:polgui"),
|
||||
Map.entry("scoreboard", "dunerealmsgui:drscoreboard"), Map.entry("menu", "dunemenus:dm"),
|
||||
Map.entry("guildtravel", "dunerealmsgui:guildtravel"), Map.entry("warmuster", "dunerealmsgui:warmuster"),
|
||||
Map.entry("rosterkey", "dunerealmsgui:rosterkey"), Map.entry("lobby", "dunelobby:lobby"),
|
||||
Map.entry("faction", "dunemenus:house"), Map.entry("house", "dunemenus:house"),
|
||||
Map.entry("start", "dunemenus:start"), Map.entry("mentat", "dunemenus:mentat"),
|
||||
Map.entry("exchange", "dunemenus:exchange"), Map.entry("spice", "dunemenus:spice"),
|
||||
Map.entry("sell", "dunemenus:sellall"), Map.entry("sellall", "dunemenus:sellall"),
|
||||
Map.entry("clan", "dunemenus:clan"),
|
||||
Map.entry("company", "dunemenus:company"), Map.entry("office", "dunemenus:politics"),
|
||||
Map.entry("scoreboard", "dunemenus:scoreboard"), Map.entry("menu", "dunemenus:dm"),
|
||||
Map.entry("guildtravel", "dunemenus:guildtravel"), Map.entry("warmuster", "dunemenus:warmuster"),
|
||||
Map.entry("rosterkey", "dunemenus:rosterkey"), Map.entry("lobby", "dunelobby:lobby"),
|
||||
Map.entry("lobbyadmin", "dunelobby:dunelobby"), Map.entry("npc", "dunenpc:dunenpc"),
|
||||
Map.entry("protect", "duneprotect:duneprotect"), Map.entry("ban", "duneban:duneban"),
|
||||
Map.entry("unban", "duneban:duneunban"));
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class DuneCommandsTest {
|
|||
var invite = destination(server, enabledPlugin, "jarvistranslator:invite");
|
||||
var pay = destination(server, enabledPlugin, "jarvistranslator:pay");
|
||||
var home = destination(server, enabledPlugin, "duneess:home");
|
||||
var house = destination(server, enabledPlugin, "dunerealmsgui:house");
|
||||
var house = destination(server, enabledPlugin, "dunemenus:house");
|
||||
var menu = destination(server, enabledPlugin, "dunemenus:dm");
|
||||
var core = destination(server, enabledPlugin, "dunecore:dune");
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ plugins {
|
|||
|
||||
dependencies {
|
||||
paperweight.paperDevBundle("26.2.build.135-stable")
|
||||
compileOnly(files("../DuneRealmsGUI/build/libs/DunerealmsGUI.jar"))
|
||||
compileOnly(files("../DuneMenus/build/libs/DuneMenus.jar"))
|
||||
testImplementation("org.junit.jupiter:junit-jupiter:5.11.4")
|
||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.dunerealms.fullscreen;
|
||||
|
||||
import com.dunerealms.gui.DecisionsViewTransport;
|
||||
import com.dunerealms.services.DecisionsViewTransport;
|
||||
import io.papermc.paper.ServerBuildInfo;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.ServicePriority;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.dunerealms.fullscreen;
|
||||
|
||||
import com.dunerealms.gui.DecisionsViewTransport;
|
||||
import com.dunerealms.services.DecisionsViewTransport;
|
||||
import java.util.function.IntConsumer;
|
||||
|
||||
import java.awt.Color;
|
||||
|
|
|
|||
|
|
@ -2,4 +2,4 @@ name: DuneFullscreenPaper
|
|||
main: com.dunerealms.fullscreen.FullscreenProvider
|
||||
version: 0.1.0
|
||||
api-version: '26.2'
|
||||
depend: [DunerealmsGUI]
|
||||
depend: [DuneMenus]
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
plugins { java }
|
||||
group = "com.dunerealms"
|
||||
version = "2.0.0"
|
||||
version = "2.1.0"
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
|
|
@ -19,6 +19,18 @@ java { toolchain.languageVersion.set(JavaLanguageVersion.of(21)) }
|
|||
sourceSets.main { java.srcDir("../gui-common/src/main/java/com/dunerealms") }
|
||||
tasks.withType<JavaCompile> { options.encoding = "UTF-8" }
|
||||
tasks.jar { archiveFileName.set("DuneMenus.jar") }
|
||||
tasks.processResources { filesMatching("plugin.yml") { expand("version" to project.version) } }
|
||||
tasks.processResources {
|
||||
filesMatching("plugin.yml") { expand("version" to project.version) }
|
||||
from("../website/web/assets/dunerealms-season-logo-v2.png") { into("mcgui") }
|
||||
from("../DuneLobby/artwork/exchange.png") { into("mcgui/native") }
|
||||
from("../website/web/assets/seals") {
|
||||
include("house-aerdrecht-v1.png", "house-harkveen-v1.png", "house-korenholt-v1.png", "house-oordwijk-v1.png", "house-vrijduin-v1.png")
|
||||
into("mcgui/native")
|
||||
}
|
||||
from("../website/web/assets/gui") {
|
||||
include("mentat-atreides-v1.png", "mentat-harkonnen-v1.png", "mentat-corrino-v1.png", "mentat-ordos-v1.png", "mentat-fremen-v1.png")
|
||||
into("mcgui/native")
|
||||
}
|
||||
}
|
||||
|
||||
tasks.test { useJUnitPlatform() }
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
package com.dunerealms.menus;
|
||||
|
||||
import com.dunerealms.identity.PublicNameplates;
|
||||
import com.dunerealms.npc.PolQuestNpc;
|
||||
import java.io.File;
|
||||
import com.dunerealms.services.DuneServicesPlugin;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -15,16 +13,13 @@ import org.bukkit.command.Command;
|
|||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public final class DuneMenusPlugin extends JavaPlugin implements TabExecutor {
|
||||
public final class DuneMenusPlugin extends DuneServicesPlugin implements TabExecutor {
|
||||
static final List<String> IDS = List.of("hub", "travel", "exchange", "clan", "company", "missions",
|
||||
"spice", "war", "mentat", "lore", "politics", "house", "equipment", "bank", "atm", "withdraw");
|
||||
private static final String PACK_CONTROL = "dunerealms:pack_control";
|
||||
private Backend backend;
|
||||
private NativeMenuRoutes nativeRoutes;
|
||||
private PolQuestNpc questNpcs;
|
||||
private PublicNameplates nameplates;
|
||||
private final Map<Player, String> loadedPacks = new HashMap<>();
|
||||
private final Map<UUID, Menu> openMenus = new HashMap<>();
|
||||
|
||||
|
|
@ -37,6 +32,10 @@ public final class DuneMenusPlugin extends JavaPlugin implements TabExecutor {
|
|||
openMenus.remove(player.getUniqueId(), menu);
|
||||
}
|
||||
|
||||
boolean hasOpenMenu(Player player, Menu menu) {
|
||||
return openMenus.get(player.getUniqueId()) == menu;
|
||||
}
|
||||
|
||||
void dismiss(Player player) {
|
||||
Menu menu = openMenus.remove(player.getUniqueId());
|
||||
if (menu != null) menu.closed();
|
||||
|
|
@ -46,6 +45,7 @@ public final class DuneMenusPlugin extends JavaPlugin implements TabExecutor {
|
|||
public void onEnable() {
|
||||
saveDefaultConfig();
|
||||
backend = JarvisBackend.create(this);
|
||||
super.onEnable();
|
||||
var messenger = getServer().getMessenger();
|
||||
messenger.registerOutgoingPluginChannel(this, PACK_CONTROL);
|
||||
messenger.registerIncomingPluginChannel(this, PACK_CONTROL, (channel, player, bytes) -> {
|
||||
|
|
@ -59,37 +59,26 @@ public final class DuneMenusPlugin extends JavaPlugin implements TabExecutor {
|
|||
getServer().getPluginManager().registerEvents(new ChatPrompt(this), this);
|
||||
getCommand("dm").setExecutor(this);
|
||||
getCommand("dm").setTabCompleter(this);
|
||||
getServer().getScheduler().runTask(this, () -> {
|
||||
nativeRoutes = new NativeMenuRoutes(this);
|
||||
if (!getServer().getPluginManager().isPluginEnabled("DunerealmsGUI")) {
|
||||
File oldPositions = new File(getDataFolder().getParentFile(), "DunerealmsGUI/quest-npc-positions.yml");
|
||||
File positions = new File(getDataFolder(), "quest-npc-positions.yml");
|
||||
if (oldPositions.isFile() && !positions.isFile()) {
|
||||
getLogger().warning("Transfer quest-npc-positions.yml before enabling quest NPC persistence.");
|
||||
} else {
|
||||
questNpcs = new PolQuestNpc(this);
|
||||
}
|
||||
if (backend instanceof JarvisBackend jarvis) {
|
||||
nameplates = new PublicNameplates(this);
|
||||
getServer().getScheduler().runTaskTimer(this, () -> {
|
||||
if (nameplates.isRendering()) {
|
||||
getServer().getOnlinePlayers().forEach(player -> jarvis.refreshNameplate(player, nameplates));
|
||||
}
|
||||
}, 40, 600);
|
||||
}
|
||||
}
|
||||
});
|
||||
getServer().getScheduler().runTask(this, () -> nativeRoutes = new NativeMenuRoutes(this));
|
||||
}
|
||||
|
||||
@Override public void onDisable() {
|
||||
if (nativeRoutes != null) nativeRoutes.close();
|
||||
if (nameplates != null) nameplates.close();
|
||||
super.onDisable();
|
||||
}
|
||||
|
||||
Backend backend() { return backend; }
|
||||
|
||||
public void updateImperialQuestNpc(UUID uuid, String name, String term) {
|
||||
if (questNpcs != null) questNpcs.imperialAppearance(uuid, name, term);
|
||||
@Override
|
||||
protected void openMenu(Player player, String menu) {
|
||||
if (player.hasPermission("dunemenus.use")) create(menu, player, null).open();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void presentService(Player player, String section, String title, String description,
|
||||
org.bukkit.inventory.Inventory inventory, Map<Integer, Runnable> actions) {
|
||||
if (player.hasPermission("dunemenus.use"))
|
||||
new ServiceMenu(this, player, section, title, description, inventory, actions).open();
|
||||
}
|
||||
|
||||
public void warObjective(Player player, com.google.gson.JsonObject target, Runnable capture) {
|
||||
|
|
@ -153,6 +142,7 @@ public final class DuneMenusPlugin extends JavaPlugin implements TabExecutor {
|
|||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender s, Command c, String l, String[] a) {
|
||||
if (!c.getName().equals("dm")) return super.onCommand(s, c, l, a);
|
||||
if (a.length > 0 && a[0].equalsIgnoreCase("reload")) {
|
||||
if (!s.hasPermission("dunemenus.admin")) { s.sendMessage("No permission."); return true; }
|
||||
reloadConfig();
|
||||
|
|
|
|||
|
|
@ -331,27 +331,6 @@ final class JarvisBackend implements Backend, Listener {
|
|||
}
|
||||
}
|
||||
|
||||
void refreshNameplate(Player player, PublicNameplates nameplates) {
|
||||
UUID owner = player.getUniqueId();
|
||||
UUID world = player.getWorld().getUID();
|
||||
remote(player, () -> accepted(jarvis.requestHouse(owner, null, 0, null))).whenComplete((briefing, error) -> {
|
||||
if (!nameplates.isRendering() || !player.isOnline() || !world.equals(player.getWorld().getUID())) return;
|
||||
String faction = null;
|
||||
String houseName = null;
|
||||
if (error == null && briefing.has("choices") && briefing.get("choices").isJsonArray()) {
|
||||
String selection = text(briefing, "selection");
|
||||
for (var choice : briefing.getAsJsonArray("choices")) {
|
||||
var row = choice.getAsJsonObject();
|
||||
if (selection.isBlank() || !selection.equals(text(row, "id"))) continue;
|
||||
faction = selection;
|
||||
houseName = text(row, "name");
|
||||
break;
|
||||
}
|
||||
}
|
||||
nameplates.update(player, briefing, faction, houseName);
|
||||
});
|
||||
}
|
||||
|
||||
@Override public CompletableFuture<String> mentat(Player player) {
|
||||
UUID owner=player.getUniqueId();
|
||||
return remote(player,()->{
|
||||
|
|
|
|||
|
|
@ -2,24 +2,16 @@ package com.dunerealms.menus;
|
|||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryDragEvent;
|
||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
final class MenuListener implements Listener {
|
||||
private static final NamespacedKey QUEST_CHARACTER = new NamespacedKey("dunerealms", "quest_character");
|
||||
private static final Set<String> WAR_MARSHAL_WORLDS =
|
||||
Set.of("arrakis", "caladan", "giedi_prime", "guild_lobby", "kaitain", "sigma_draconis_iv");
|
||||
private final Map<UUID, Long> last = new HashMap<>();
|
||||
private final DuneMenusPlugin plugin;
|
||||
|
||||
|
|
@ -46,18 +38,6 @@ final class MenuListener implements Listener {
|
|||
plugin.create("hub", event.getPlayer(), null).open();
|
||||
}
|
||||
|
||||
@EventHandler(priority = org.bukkit.event.EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void openWarMarshal(PlayerInteractEntityEvent event) {
|
||||
var player = event.getPlayer();
|
||||
if (!(event.getRightClicked() instanceof org.bukkit.entity.LivingEntity)
|
||||
|| !WAR_MARSHAL_WORLDS.contains(player.getWorld().getName())
|
||||
|| !"war_marshal".equals(event.getRightClicked().getPersistentDataContainer().get(
|
||||
QUEST_CHARACTER, PersistentDataType.STRING))
|
||||
|| !player.hasPermission("dunemenus.use")) return;
|
||||
event.setCancelled(true);
|
||||
if (event.getHand() == EquipmentSlot.HAND) plugin.create("war", player, null).open();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onClick(InventoryClickEvent e) {
|
||||
var top = e.getView().getTopInventory();
|
||||
|
|
|
|||
|
|
@ -1,15 +1,26 @@
|
|||
package com.dunerealms.menus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/** Routes menu-only calls made by the existing server commands and NPCs. */
|
||||
final class NativeMenuRoutes implements AutoCloseable {
|
||||
private static final List<String> COMMANDS = List.of("dunecore:dune", "duneess:duneess", "duneess:exchange");
|
||||
private static final List<String> COMMANDS = List.of("dunecore:dune", "duneess:duneess", "duneess:exchange", "duneess:dune");
|
||||
private static final Map<String, String> DUNE_SERVICES = Map.ofEntries(
|
||||
Map.entry("menu", "dm"), Map.entry("faction", "house"), Map.entry("house", "house"),
|
||||
Map.entry("start", "start"), Map.entry("mentat", "mentat"), Map.entry("exchange", "exchange"),
|
||||
Map.entry("spice", "spice"), Map.entry("sell", "sellall"), Map.entry("sellall", "sellall"),
|
||||
Map.entry("clan", "clan"), Map.entry("company", "company"), Map.entry("office", "politics"),
|
||||
Map.entry("scoreboard", "scoreboard"), Map.entry("guildtravel", "guildtravel"),
|
||||
Map.entry("warmuster", "warmuster"), Map.entry("rosterkey", "rosterkey"));
|
||||
private static final Set<String> CLAN_MEMBERSHIP = Set.of("invite", "accept", "join", "leave");
|
||||
private final List<Binding> bindings = new ArrayList<>();
|
||||
|
||||
private record Binding(PluginCommand command, CommandExecutor original, CommandExecutor route) {}
|
||||
|
|
@ -20,6 +31,13 @@ final class NativeMenuRoutes implements AutoCloseable {
|
|||
if (command == null || !command.getPlugin().isEnabled()) continue;
|
||||
CommandExecutor original = command.getExecutor();
|
||||
CommandExecutor route = (sender, invoked, label, args) -> {
|
||||
if (name.equals("duneess:dune")) {
|
||||
String target = duneService(args);
|
||||
if (target != null) {
|
||||
return plugin.getCommand(target).execute(sender, "dune " + args[0],
|
||||
Arrays.copyOfRange(args, 1, args.length));
|
||||
}
|
||||
}
|
||||
String menu = menuFor(name, args);
|
||||
if (menu != null && sender instanceof Player player && player.hasPermission("dunemenus.use")) {
|
||||
plugin.create(menu, player, null).open();
|
||||
|
|
@ -32,6 +50,14 @@ final class NativeMenuRoutes implements AutoCloseable {
|
|||
}
|
||||
}
|
||||
|
||||
static String duneService(String[] args) {
|
||||
if (args.length == 0) return null;
|
||||
String action = args[0].toLowerCase(Locale.ROOT);
|
||||
if (action.equals("clan") && args.length > 1 && CLAN_MEMBERSHIP.contains(args[1].toLowerCase(Locale.ROOT)))
|
||||
return null;
|
||||
return DUNE_SERVICES.get(action);
|
||||
}
|
||||
|
||||
static String menuFor(String command, String[] args) {
|
||||
if (args.length > 1) return null;
|
||||
if (command.equals("duneess:exchange")) return args.length == 0 ? "exchange" : null;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,67 @@
|
|||
package com.dunerealms.menus;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
final class ServiceMenu extends Menu {
|
||||
private final String section;
|
||||
private final String title;
|
||||
private final String subtitle;
|
||||
private final ItemStack[] cards;
|
||||
private final Map<Integer, Runnable> actions;
|
||||
private final UUID world;
|
||||
|
||||
ServiceMenu(DuneMenusPlugin plugin, Player player, String section, String title, String description,
|
||||
Inventory inventory, Map<Integer, Runnable> actions) {
|
||||
super(plugin, player, null);
|
||||
this.section = section;
|
||||
this.title = title.replaceFirst("^NPC (dashboard|turn-in) · ", "");
|
||||
this.subtitle = description.lines().findFirst().orElse("");
|
||||
this.cards = inventory.getContents();
|
||||
this.actions = Map.copyOf(actions);
|
||||
this.world = player.getWorld().getUID();
|
||||
}
|
||||
|
||||
String id() { return section; }
|
||||
Skin skin() {
|
||||
return switch (section) {
|
||||
case "missions" -> Skin.QUEST;
|
||||
case "exchange" -> Skin.MARKET;
|
||||
case "spice" -> Skin.SPICE;
|
||||
case "war" -> Skin.WAR;
|
||||
case "politics" -> Skin.POLITICS;
|
||||
case "travel" -> Skin.TRAVEL;
|
||||
case "house", "mentat" -> Skin.HOUSE;
|
||||
default -> Skin.GOLD;
|
||||
};
|
||||
}
|
||||
String title() { return title; }
|
||||
String subtitle() { return subtitle; }
|
||||
int rows() { return cards.length / 9; }
|
||||
|
||||
void draw() {
|
||||
backdrop(Material.BLACK_STAINED_GLASS_PANE);
|
||||
for (int slot = 0; slot < cards.length; slot++) {
|
||||
ItemStack card = cards[slot];
|
||||
Runnable action = actions.get(slot);
|
||||
if (card == null || action == null && card.getType().name().endsWith("_PANE") &&
|
||||
(card.getItemMeta() == null || !card.getItemMeta().hasLore())) continue;
|
||||
if (action == null) put(slot, card);
|
||||
else put(slot, card, click -> {
|
||||
if (click != ClickType.LEFT && !(section.equals("exchange") && click == ClickType.RIGHT)) return;
|
||||
Runnable run = () -> {
|
||||
if (plugin.hasOpenMenu(player, this) && player.isOnline() && world.equals(player.getWorld().getUID()))
|
||||
action.run();
|
||||
};
|
||||
if (player.getOpenInventory().getTopInventory().getHolder() == this)
|
||||
plugin.getServer().getScheduler().runTask(plugin, run);
|
||||
else run.run();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package com.dunerealms.services;
|
||||
import java.util.List;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
/** Native controller/touch input, sharing the exact action session with the Java screens. */
|
||||
final class BedrockForms {
|
||||
record Choice(String label,String description,Runnable action,String imageUrl){Choice(String label,String description,Runnable action){this(label,description,action,null);}}
|
||||
static boolean isBedrock(Player player){return Bukkit.getPluginManager().isPluginEnabled("floodgate")&&Floodgate.isPlayer(player);}
|
||||
static void show(JavaPlugin plugin,Player player,String title,String content,List<Choice> choices){Floodgate.show(plugin,player,title,content,choices);}
|
||||
static void input(JavaPlugin plugin,Player player,String title,String label,String initial,java.util.function.Consumer<String> done){Floodgate.input(plugin,player,title,label,initial,done);}
|
||||
private static final class Floodgate {
|
||||
static boolean isPlayer(Player p){return org.geysermc.floodgate.api.FloodgateApi.getInstance().isFloodgatePlayer(p.getUniqueId());}
|
||||
static void input(JavaPlugin plugin,Player p,String title,String label,String initial,java.util.function.Consumer<String> done){var world=p.getWorld().getUID();var gate=new GuiSession(p.getUniqueId());Bukkit.getScheduler().runTaskLater(plugin,gate::expire,2400L);var form=org.geysermc.cumulus.form.CustomForm.builder().title(title).input(label,"1.00",initial).closedOrInvalidResultHandler(gate::expire).validResultHandler(result->{String value=result.asInput(0);if(plugin.isEnabled())Bukkit.getScheduler().runTask(plugin,()->{if(p.isOnline()&&world.equals(p.getWorld().getUID())&&gate.claim(p.getUniqueId()))done.accept(value);});});if(org.geysermc.floodgate.api.FloodgateApi.getInstance().sendForm(p.getUniqueId(),form.build()))gate.markFormVisible(p.getWorld().getUID());else gate.expire();}
|
||||
static void show(JavaPlugin plugin,Player p,String title,String content,List<Choice> choices){
|
||||
var worldId=p.getWorld().getUID();
|
||||
GuiSession gate=new GuiSession(p.getUniqueId());Bukkit.getScheduler().runTaskLater(plugin,gate::expire,2400L);
|
||||
var form=org.geysermc.cumulus.form.SimpleForm.builder().title(title).content(content);
|
||||
for(Choice choice:choices){String url=choice.imageUrl();if(url!=null&&url.matches("https://www\\.dunerealms\\.com/assets/(seals|gui)/[a-z0-9-]+\\.png"))form.button(choice.label(),org.geysermc.cumulus.util.FormImage.Type.URL,url);else form.button(choice.label());}
|
||||
form.closedOrInvalidResultHandler(gate::expire);
|
||||
form.validResultHandler(result->{int index=result.clickedButtonId();if(!plugin.isEnabled())return;Bukkit.getScheduler().runTask(plugin,()->{if(p.isOnline()&&p.getWorld().getUID().equals(worldId)&&index>=0&&index<choices.size()&&gate.claim(p.getUniqueId()))choices.get(index).action().run();});});
|
||||
if(org.geysermc.floodgate.api.FloodgateApi.getInstance().sendForm(p.getUniqueId(),form.build()))gate.markFormVisible(p.getWorld().getUID());else gate.expire();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
package com.dunerealms.services;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.IntConsumer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Bukkit service for an optional Java fullscreen roleplay provider. It owns its
|
||||
* runtime-specific packet support and closes its scene before returning input.
|
||||
*/
|
||||
public interface DecisionsViewTransport {
|
||||
record Card(int slot, String title, List<String> lore, boolean actionable, String material) {
|
||||
public Card(int slot, String title, List<String> lore, boolean actionable) {
|
||||
this(slot, title, lore, actionable, "");
|
||||
}
|
||||
|
||||
public Card {
|
||||
lore = List.copyOf(lore);
|
||||
}
|
||||
}
|
||||
|
||||
enum Style { AUTO, ORGANISATION, EXCHANGE, EXCHANGE_CHECKOUT, HOUSE, JOURNAL, CODEX, ITEM_ARCHIVE, GUILD, SPICE, WORKSHOP, DECISION_DETAIL, WAR_MUSTER }
|
||||
record Identity(String logo, String mentat, int portrait) {}
|
||||
|
||||
record Document(String title, String description, List<Card> cards, Style style, Identity identity) {
|
||||
public Document(String title, String description, List<Card> cards) {
|
||||
this(title, description, cards, Style.AUTO, null);
|
||||
}
|
||||
|
||||
public Document {
|
||||
cards = List.copyOf(cards);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on the server thread. Return false on an unsupported runtime or if
|
||||
* opening fails. Release partial state before returning false. After a
|
||||
* successful open, call exactly one terminal callback on the server thread:
|
||||
* select a visible actionable slot, or close without selecting. Finish
|
||||
* transport cleanup before the callback. Never invoke it inside open.
|
||||
*/
|
||||
boolean open(Player viewer, Document document, IntConsumer select, Runnable close);
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package com.dunerealms.services;
|
||||
final class DepartureWindow {
|
||||
private DepartureWindow(){}
|
||||
static final long CYCLE=1200,BOARDING=300,LAUNCH_END=420;
|
||||
enum Phase { BOARDING, LAUNCHING, WAITING }
|
||||
static Phase phase(long now){long at=Math.floorMod(now,CYCLE);return at<BOARDING?Phase.BOARDING:at<LAUNCH_END?Phase.LAUNCHING:Phase.WAITING;}
|
||||
static boolean open(long now){return phase(now)==Phase.BOARDING;}
|
||||
static long remaining(long now){long at=Math.floorMod(now,CYCLE);return (at<BOARDING?BOARDING:at<LAUNCH_END?LAUNCH_END:CYCLE)-at;}
|
||||
static long nextBoarding(long now){return open(now)?now:now+CYCLE-Math.floorMod(now,CYCLE);}
|
||||
static double progress(long now){return remaining(now)/(phase(now)==Phase.BOARDING?(double)BOARDING:phase(now)==Phase.LAUNCHING?120.0:780.0);}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package com.dunerealms.services;
|
||||
import java.lang.reflect.Field;
|
||||
/** Detach only the lobby's vanilla End fight, without killing entities or editing NBT. */
|
||||
final class DragonController {
|
||||
record Detached(Object handle,Field field,Object previous){
|
||||
void restore() throws IllegalAccessException {if(field.get(handle)==null)field.set(handle,previous);}
|
||||
}
|
||||
static Detached detach(Object handle)throws ReflectiveOperationException {
|
||||
for(Class<?> type=handle.getClass();type!=null;type=type.getSuperclass())for(Field field:type.getDeclaredFields())if(field.getType().getSimpleName().equals("EndDragonFight")){
|
||||
field.setAccessible(true);Object previous=field.get(handle);field.set(handle,null);return new Detached(handle,field,previous);
|
||||
}
|
||||
throw new NoSuchFieldException("Lobby EndDragonFight controller");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package com.dunerealms.services;
|
||||
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
interface DuneMenuInventory extends InventoryHolder {}
|
||||
|
|
@ -0,0 +1,373 @@
|
|||
package com.dunerealms.services;
|
||||
|
||||
import com.dunerealms.npc.PolQuestNpc;
|
||||
import com.dunerealms.identity.PublicNameplates;
|
||||
|
||||
|
||||
|
||||
import com.google.gson.*;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.boss.*;
|
||||
import org.bukkit.command.*;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.event.*;
|
||||
import org.bukkit.event.inventory.*;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.inventory.*;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import java.time.*;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/** Lobby presentation only. Character authority and committed keys remain central. */
|
||||
public abstract class DuneServicesPlugin extends JavaPlugin implements Listener,CommandExecutor {
|
||||
protected abstract void openMenu(Player player,String menu);
|
||||
protected abstract void presentService(Player player,String section,String title,String description,Inventory inventory,Map<Integer,Runnable> actions);
|
||||
final void showService(Player player,String section,String title,String description,Inventory inventory,Map<Integer,Runnable> actions,GuiSession gate){
|
||||
var world=player.getWorld().getUID();
|
||||
var guarded=new HashMap<Integer,Runnable>();
|
||||
actions.forEach((slot,action)->{
|
||||
if(action!=null)guarded.put(slot,()->{
|
||||
if(player.isOnline()&&world.equals(player.getWorld().getUID())&&gate.claim(player.getUniqueId()))action.run();
|
||||
});
|
||||
});
|
||||
presentService(player,section,title,description,inventory,guarded);
|
||||
Bukkit.getScheduler().runTaskLater(this,gate::expire,2400L);
|
||||
}
|
||||
public void warObjective(Player player,JsonObject target,Runnable capture){if(!Bukkit.isPrimaryThread()||!isEnabled())throw new IllegalStateException("Open objectives on the server thread");organisations.warObjective(player,target,capture);}
|
||||
private HouseBridge bridge;
|
||||
private OrganisationMenus organisations;
|
||||
private MCGUIMenus modernMenus;
|
||||
private EcologyArtwork ecologyArtwork;
|
||||
private QuestMenus quests;
|
||||
private WarMenus warMenus;
|
||||
private PolQuestNpc polQuestNpcs;
|
||||
public void updateImperialQuestNpc(UUID uuid,String name,String term){if(polQuestNpcs!=null)polQuestNpcs.imperialAppearance(uuid,name,term);}
|
||||
public void openNativeQuestContact(Player p,String role){if(polQuestNpcs!=null)polQuestNpcs.nativeContact(p,role);}
|
||||
private ExchangeMenus exchange;
|
||||
private SpiceMenus spice;
|
||||
|
||||
private final Map<UUID,UUID> requests=new HashMap<>();
|
||||
private final Map<UUID,JsonObject> records=new HashMap<>();
|
||||
private BossBar departure;
|
||||
private NamespacedKey registrar;
|
||||
private PersonalSidebar sidebar;
|
||||
private PublicNameplates nameplates;
|
||||
private final Map<UUID,DragonController.Detached> detached=new HashMap<>();
|
||||
private final Set<UUID> dragonWarnings=new HashSet<>();
|
||||
private ExistingGuildService guild;
|
||||
private final GuildBookings bookings=new GuildBookings();
|
||||
private final Set<UUID> boarding=new HashSet<>();
|
||||
private ProxyPackBridge proxyPacks;
|
||||
private final Set<UUID> guiPackLoaded=new HashSet<>();
|
||||
private final Map<UUID,NetworkArtworkPolicy.Pack> offeredGuiPacks=new HashMap<>();
|
||||
private NetworkArtworkPolicy.Pack guiPack(Player player){
|
||||
boolean inLobby=lobby(player);
|
||||
var file=new java.io.File(getDataFolder(),"gui-pack.yml");if(!file.isFile())return NetworkArtworkPolicy.select(inLobby,null,null);
|
||||
var data=org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(file);
|
||||
String prefix="world.";
|
||||
return NetworkArtworkPolicy.select(inLobby,data.getString(prefix+"url"),data.getString(prefix+"sha1"));
|
||||
}
|
||||
private long lastDepartureNotice=-1;
|
||||
static final int[] CENTRES={10,13,16,29,33};
|
||||
static final String[] IDS={"atreides","harkonnen","corrino","ordos","fremen"};
|
||||
private static final Set<String> HOUSE_IDS=Set.of(IDS);
|
||||
private static final class Screen implements DuneMenuInventory {
|
||||
final UUID owner,worldId;final GuiSession gate;final Map<Integer,Runnable> actions=new HashMap<>();Inventory inventory;
|
||||
Screen(Player player){owner=player.getUniqueId();worldId=player.getWorld().getUID();gate=new GuiSession(owner);}
|
||||
public Inventory getInventory(){return inventory;}
|
||||
}
|
||||
@Override public void onEnable(){
|
||||
bridge=new HouseBridge();
|
||||
spice=new SpiceMenus(this,bridge,p->organisations.console(p));
|
||||
exchange=new ExchangeMenus(this,bridge,p->organisations.console(p),p->guiPackLoaded.contains(p.getUniqueId()));
|
||||
quests=new QuestMenus(this,bridge,p->openMenu(p,"hub"));warMenus=new WarMenus(this,bridge);
|
||||
|
||||
organisations=new OrganisationMenus(this,bridge,p->fetch(p,null,0,null,data->mentat(p,data)),p->openGuild(p,null),p->fetch(p,null,0,null,data->select(p,data,null)),p->quests.open(p),p->quests.openDecisions(p,0),p->exchange.open(p),p->spice.open(p),p->guiPackLoaded.contains(p.getUniqueId()));
|
||||
registrar=new NamespacedKey("dunerealmsgui","house_registrar");
|
||||
modernMenus=new MCGUIMenus(this);
|
||||
ecologyArtwork=new EcologyArtwork(this);
|
||||
proxyPacks=new ProxyPackBridge(this,this::receiveProxyArtworkStatus);
|
||||
new PlanetTexturePacks(this,proxyPacks);
|
||||
|
||||
sidebar=new PersonalSidebar(this);nameplates=new PublicNameplates(this);
|
||||
for(String command:List.of("start","spice","sellall","exchange","house","mentat","scoreboard","guildtravel","clan","company","politics"))Objects.requireNonNull(getCommand(command)).setExecutor(this);
|
||||
try{guild=new ExistingGuildService(p->spice.open(p),(p,world)->openGuild(p,world),p->exchange.open(p),p->quests.open(p),p->organisations.console(p),p->{if(!sidebar.enabled(p))sidebar.toggle(p);refreshSidebar(p);p.sendMessage("Your central bank balance appears in your personal scoreboard.");});getLogger().info("Spacing Guild lobby entry connected to current House keys and twenty-minute boarding windows.");}catch(RuntimeException unavailable){getLogger().warning("Spacing Guild travel consumer unavailable; no journeys can be booked.");}
|
||||
getServer().getPluginManager().registerEvents(this,this);
|
||||
departure=Bukkit.createBossBar("Spacing Guild · next Imperial departure",BarColor.YELLOW,BarStyle.SOLID);
|
||||
Bukkit.getScheduler().runTaskTimer(this,this::tick,20L,20L);
|
||||
Bukkit.getScheduler().runTaskLater(this,this::ensureRegistrar,40L);
|
||||
new QuartermasterNpc(this,p->quests.quartermaster(p,()->exchange.open(p),()->exchange.openKits(p)));
|
||||
polQuestNpcs=new PolQuestNpc(this,(p,role)->{if(role.key().equals("war_marshal"))openMenu(p,"war");else if(role.key().equals("guild_navigator"))openMenu(p,"travel");else quests.openRole(p,role);});
|
||||
Bukkit.getScheduler().runTaskTimer(this,()->{for(Player p:Bukkit.getOnlinePlayers()){refreshSidebar(p);}},80L,600L);
|
||||
getLogger().info("House selector and Mentat screens enabled; central J.A.R.V.I.S. bridge; no Core/Lobby replacement.");
|
||||
}
|
||||
@Override public void onDisable(){if(modernMenus!=null)modernMenus.close();if(nameplates!=null)nameplates.close();if(exchange!=null)exchange.close();if(quests!=null)quests.close();requests.clear();records.clear();bookings.clear();boarding.clear();if(guild!=null)guild.close();GuiSession.clear();if(sidebar!=null)sidebar.clear();for(var controller:detached.values())try{controller.restore();}catch(ReflectiveOperationException ignored){}detached.clear();if(departure!=null)departure.removeAll();for(Player p:Bukkit.getOnlinePlayers())if(p.getOpenInventory().getTopInventory().getHolder() instanceof Screen)p.closeInventory();}
|
||||
private boolean lobby(Player p){return p.getWorld().getName().equals("guild_lobby");}
|
||||
@Override public boolean onCommand(CommandSender sender,Command command,String label,String[] args){
|
||||
if(sender instanceof Player player&&args.length==0){
|
||||
String menu=switch(command.getName()){
|
||||
case "spice","exchange","clan","company","politics","house","mentat","missions"->command.getName();
|
||||
case "warmuster"->"war";
|
||||
case "guildtravel"->"travel";
|
||||
default->null;
|
||||
};
|
||||
if(menu!=null){openMenu(player,menu);return true;}
|
||||
}
|
||||
if(sender instanceof Player p&&command.getName().equals("sellall")){spice.sellAll(p,args.length==0?"guild":args[0].toLowerCase(Locale.ROOT));return true;}
|
||||
if(sender instanceof Player p&&(command.getName().equals("spice"))){spice.command(p,command.getName().equals("spice")?args:new String[0]);return true;}
|
||||
if(sender instanceof Player player&&(command.getName().equals("exchange"))){exchange.command(player,command.getName().equals("exchange")?args:new String[0]);return true;}
|
||||
if(sender instanceof Player member&&List.of("clan","company","politics","polgui").contains(command.getName())){organisations.command(member,command.getName().equals("clan")?"clans":command.getName().equals("company")?"companies":"offices",args);return true;}
|
||||
if(!(sender instanceof Player p))return true;
|
||||
if(command.getName().equals("house")&&args.length>0){
|
||||
String id=args[0].toLowerCase(Locale.ROOT);
|
||||
if(args.length!=1||!HOUSE_IDS.contains(id)){p.sendMessage("Use /house <"+String.join("|",IDS)+">");return true;}
|
||||
fetch(p,null,0,null,data->declareHouse(p,data,id,false));return true;
|
||||
}
|
||||
if(command.getName().equals("questnpc")){
|
||||
if(args.length==2&&args[0].equalsIgnoreCase("skin"))polQuestNpcs.assignSkin(p,args[1]);
|
||||
else if(args.length==2&&args[0].equalsIgnoreCase("move"))polQuestNpcs.move(p,args[1]);
|
||||
else p.sendMessage("Look at a quest NPC and use /questnpc skin #id.");
|
||||
return true;
|
||||
}
|
||||
if(command.getName().equals("missions")){quests.missionCommand(p,args);return true;}
|
||||
if(command.getName().equals("decisions")){quests.decisionCommand(p,args);return true;}
|
||||
if(command.getName().equals("rosterkey")){if(args.length!=1)p.sendMessage("Use /rosterkey <team invite code>");else warMenus.accept(p,args[0]);return true;}
|
||||
if(command.getName().equals("warmuster")){warMenus.command(p,args);return true;}
|
||||
if(command.getName().equals("start")){quests.starterJournal(p);return true;}
|
||||
if(command.getName().equals("scoreboard")||args.length==1&&args[0].equalsIgnoreCase("scoreboard")){toggleSidebar(p);return true;}
|
||||
if(command.getName().equals("guildtravel")){guildCommand(p,args);return true;}
|
||||
if(args.length==1&&args[0].equalsIgnoreCase("travel")){openGuild(p,null);return true;}
|
||||
fetch(p,null,0,null,data->{if(command.getName().equals("mentat")&&selection(data)!=null)mentat(p,data);else select(p,data,null);});return true;
|
||||
}
|
||||
private void guildCommand(Player player,String[] args){
|
||||
if(args.length==0){openGuild(player,null);return;}
|
||||
if(args.length==1&&args[0].equalsIgnoreCase("cancel")){cancelBooking(player);return;}
|
||||
if(args.length==1&&args[0].equalsIgnoreCase("status")){
|
||||
var booking=bookings.get(player.getUniqueId());
|
||||
player.sendMessage(booking==null?"You have no pending Guild booking.":"Booked to "+booking.world()+" · "+String.format(Locale.ROOT,"%.2f DM",booking.fare()/100.0));
|
||||
return;
|
||||
}
|
||||
if(args.length==1&&args[0].equalsIgnoreCase("quote")){
|
||||
if(!lobby(player)){player.sendMessage("Return to the Spacing Guild to request an outbound fare.");return;}
|
||||
var query=new JsonObject();query.addProperty("action","quote");
|
||||
guildRequest(player,query,quote->{
|
||||
if(quote.has("prologueRequired")&"e.get("prologueRequired").getAsBoolean()){
|
||||
player.sendMessage("Complete the House Prologue before booking Guild passage.");return;
|
||||
}
|
||||
if(!quote.has("fareMinor")){player.sendMessage("The current Guild fare is unavailable.");return;}
|
||||
player.sendMessage("Guild fare: "+String.format(Locale.ROOT,"%.2f DM",quote.get("fareMinor").getAsLong()/100.0)+
|
||||
(quote.has("affordable")&"e.get("affordable").getAsBoolean()?" · Available funds verified.":" · Insufficient available funds."));
|
||||
var destinations=quotedDestinations(quote);
|
||||
player.sendMessage(destinations.isEmpty()?"No current destinations.":"Destinations: "+String.join(", ",new TreeSet<>(destinations)));
|
||||
player.sendMessage("Boarding opens at :00, :20 and :40 for five minutes.");
|
||||
});
|
||||
return;
|
||||
}
|
||||
if(args.length==2&&args[0].equalsIgnoreCase("book")){
|
||||
if(!lobby(player)){player.sendMessage("Return to the Spacing Guild before booking passage.");return;}
|
||||
String destination=args[1].toLowerCase(Locale.ROOT).replace('-','_');
|
||||
if(GuildRoutes.ALL.stream().noneMatch(route->route.world().equals(destination)&&!destination.equals("lobby"))){
|
||||
player.sendMessage("Guild destinations: "+String.join(", ",GuildRoutes.ALL.stream().map(GuildRoutes.Route::world).toList()));return;
|
||||
}
|
||||
fetch(player,null,0,null,data->bookPassage(player,data,destination,false));
|
||||
return;
|
||||
}
|
||||
player.sendMessage("Use /guildtravel [quote|status|cancel|book <world>].");
|
||||
}
|
||||
private void openGuild(Player p,String requested){if(!lobby(p)){try{bridge.returnGuild(p);}catch(Exception unavailable){p.sendMessage("The Guild could not confirm your return. Please retry.");}return;}fetch(p,null,0,null,data->{String house=selection(data);if(house==null){p.sendMessage("Choose and confirm your House before Guild passage.");select(p,data,null);return;}travelMenu(p,data);});}
|
||||
private static GuildBookings.Permit permit(JsonObject data){String house=selection(data);if(house==null||!data.has("keyId")||data.get("keyId").isJsonNull())return null;try{return new GuildBookings.Permit(house,UUID.fromString(data.get("keyId").getAsString()),data.get("version").getAsInt());}catch(RuntimeException invalid){return null;}}
|
||||
private void travelMenu(Player p,JsonObject data){var q=new JsonObject();q.addProperty("action","quote");guildRequest(p,q,quote->{data.add("guildQuote",quote);renderTravelMenu(p,data);});}
|
||||
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 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.");
|
||||
String title="Spacing Guild · Imperial passage";
|
||||
int own=Arrays.asList(IDS).indexOf(house);Screen screen=screen(p,title,0xE330+own);
|
||||
var allowedDestinations=quotedDestinations(data.getAsJsonObject("guildQuote"));
|
||||
var routeCards=new ArrayList<DecisionsViewTransport.Card>();
|
||||
for(int i=0;i<GuildRoutes.ALL.size();i++){
|
||||
var route=GuildRoutes.ALL.get(i);boolean allowed=allowedDestinations.contains(route.world());
|
||||
String unavailable="Unavailable · another House world";
|
||||
var item=icon(p,route.name(),allowed?detail:unavailable,"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()));
|
||||
}
|
||||
routeCards.add(new DecisionsViewTransport.Card(centre,route.name(),List.of(allowed?
|
||||
(route.house().equals(house)?"Your House":"Imperial passage"):unavailable),allowed,
|
||||
"guild_world_"+route.world()+(allowed?"":"_locked")));
|
||||
}
|
||||
String cancellation="No fare is taken for a cancelled booking";
|
||||
String adviser="Return to your House adviser";
|
||||
button(screen,p,45,"Your Mentat",adviser,Material.ARROW,()->mentat(p,data));screen.actions.put(46,screen.actions.get(45));
|
||||
routeCards.add(new DecisionsViewTransport.Card(45,"Your Mentat",List.of(adviser),true));
|
||||
button(screen,p,49,"Cancel booking",cancellation,Material.BARRIER,()->{cancelBooking(p);travelMenu(p,data);});
|
||||
for(int slot:new int[]{48,50})screen.actions.put(slot,screen.actions.get(49));
|
||||
routeCards.add(new DecisionsViewTransport.Card(49,"Cancel booking",List.of(cancellation),true));
|
||||
if(guild!=null){
|
||||
String bookingLabel=booked==null?"Book passage":"Review booked passage";
|
||||
button(screen,p,53,bookingLabel,detail,Material.EMERALD,()->bookPassage(p,data));screen.actions.put(52,screen.actions.get(53));
|
||||
routeCards.add(new DecisionsViewTransport.Card(53,bookingLabel,List.of(),true));
|
||||
}
|
||||
String nativeDetail=detail;
|
||||
if(booked!=null)nativeDetail+="\nBooked to "+booked.world()+" · "+String.format(Locale.ROOT,"%.2f DM",booked.fare()/100.0);
|
||||
showService(p,"travel","Spacing Guild · Imperial passage","",screen.inventory,screen.actions,screen.gate);
|
||||
}
|
||||
private void cancelBooking(Player p){boolean removed=bookings.cancel(p.getUniqueId());removed=boarding.remove(p.getUniqueId())||removed;p.sendMessage(removed?"Guild passage cancelled. No fare was charged.":"You have no pending Guild booking.");}
|
||||
private static Set<String> quotedDestinations(JsonObject quote){Set<String> worlds=new HashSet<>();if(quote.has("destinations"))for(var value:quote.getAsJsonArray("destinations"))worlds.add(value.getAsString());else worlds.add(quote.get("destination").getAsString());return Set.copyOf(worlds);}
|
||||
private void bookPassage(Player p,JsonObject shown){var booked=bookings.get(p.getUniqueId());bookPassage(p,shown,booked==null?GuildRoutes.home(selection(shown)).world():booked.world());}
|
||||
private void bookPassage(Player p,JsonObject shown,String destination){bookPassage(p,shown,destination,true);}
|
||||
private void bookPassage(Player p,JsonObject shown,String destination,boolean reopen){
|
||||
if(boarding.contains(p.getUniqueId())){p.sendMessage("Guild boarding is already being confirmed.");return;}
|
||||
var expected=permit(shown);if(expected==null){p.sendMessage("Confirm your current House key before booking passage.");if(reopen)select(p,shown,selection(shown));return;}
|
||||
fetch(p,null,0,null,fresh->{var current=permit(fresh);if(current==null||!current.equals(expected)){p.sendMessage("Your House key changed. Review the current passage.");if(reopen)travelMenu(p,fresh);return;}
|
||||
var q=new JsonObject();q.addProperty("action","quote");guildRequest(p,q,quote->{if(!quote.get("affordable").getAsBoolean()){p.sendMessage("Not enough available Dunemarks in your central personal bank account.");return;}if(!quotedDestinations(quote).contains(destination)){p.sendMessage("This destination is unavailable under your current Guild passage.");return;}var home=GuildRoutes.ALL.stream().filter(r->r.world().equals(destination)).findFirst().orElseThrow();int fare=quote.get("fareMinor").getAsInt();var booked=bookings.book(p.getUniqueId(),current,home.world(),fare,Instant.now().getEpochSecond(),quotedDestinations(quote));p.closeInventory();p.sendMessage(Component.text("Passage booked to "+home.name()+". Fare "+String.format(java.util.Locale.ROOT,"%.2f",booked.fare()/100.0)+" DM is reserved at boarding and collected after arrival.",NamedTextColor.GOLD));});
|
||||
});
|
||||
}
|
||||
private void board(GuildBookings.Booking booking){
|
||||
Player p=Bukkit.getPlayer(booking.player());if(p==null||!p.isOnline()||!lobby(p)||!boarding.add(booking.player()))return;
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this,()->{JsonObject ticket=null;String failure=null;try{var fresh=bridge.request(booking.player(),null,0,null);var current=permit(fresh);if(current==null||!booking.matches(current,booking.fare(),Instant.now().getEpochSecond())||!bridge.worldOnline(booking.world()))throw new IllegalStateException("Your key, boarding window or destination changed. Please rebook.");var q=new JsonObject();q.addProperty("action","board");q.addProperty("requestId",booking.requestId().toString());q.addProperty("keyId",current.keyId().toString());q.addProperty("version",current.version());q.addProperty("fareMinor",booking.fare());q.addProperty("destination",booking.world());ticket=bridge.guild(booking.player(),q);}catch(Exception e){failure=e.getMessage();}var result=ticket;String message=failure;if(!isEnabled())return;Bukkit.getScheduler().runTask(this,()->{if(!boarding.remove(booking.player())||!p.isOnline()||!lobby(p))return;try{if(result==null){p.sendMessage(message==null?"Passage was not confirmed. Any unused reservation expires automatically.":message);return;}p.closeInventory();bridge.dispatchGuild(p,result);}catch(Exception unavailable){p.sendMessage("The transfer was not sent. Your unused fare reservation will expire automatically.");}});});
|
||||
}
|
||||
private void fetch(Player p,String house,int version,UUID requestId,Consumer<JsonObject> callback){
|
||||
UUID owner=p.getUniqueId();if(requests.containsKey(owner)){p.sendMessage("The House register is processing your request.");return;}
|
||||
UUID operation=UUID.randomUUID(),worldId=p.getWorld().getUID();requests.put(owner,operation);p.closeInventory();p.sendMessage(Component.text("Jarvis executing matrix",NamedTextColor.GOLD));
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this,()->{
|
||||
JsonObject result=null;String error=null;
|
||||
try{result=bridge.request(owner,house,version,requestId);}catch(Exception unavailable){error=unavailable instanceof java.io.IOException?unavailable.getMessage():"The House register is unavailable. Please retry.";}
|
||||
JsonObject received=result;String failure=error;if(!isEnabled())return;
|
||||
Bukkit.getScheduler().runTask(this,()->{if(!operation.equals(requests.get(owner)))return;requests.remove(owner);if(!p.isOnline()||!worldId.equals(p.getWorld().getUID()))return;
|
||||
if(received==null){p.sendMessage(Component.text(failure,NamedTextColor.RED));return;}
|
||||
records.put(owner,received);updateSidebar(p,received);callback.accept(received);
|
||||
});
|
||||
});
|
||||
}
|
||||
private void refreshSidebar(Player p){
|
||||
UUID owner=p.getUniqueId();if(requests.containsKey(owner))return;UUID operation=UUID.randomUUID();requests.put(owner,operation);
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this,()->{JsonObject result=null;try{result=bridge.request(owner,null,0,null);}catch(Exception unavailable){}JsonObject received=result;if(!isEnabled())return;
|
||||
Bukkit.getScheduler().runTask(this,()->{if(!operation.equals(requests.get(owner)))return;requests.remove(owner);if(!p.isOnline())return;
|
||||
if(received!=null){records.put(owner,received);updateSidebar(p,received);}else{records.remove(owner);sidebar.update(p,null,null);nameplates.update(p,null,null,null);}
|
||||
});
|
||||
});
|
||||
}
|
||||
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=true) public void organisationContact(org.bukkit.event.player.PlayerInteractEntityEvent event){String marker=event.getRightClicked().getPersistentDataContainer().get(new NamespacedKey("dunerealms","organisation_home_npc"),PersistentDataType.STRING);if(marker==null)return;event.setCancelled(true);if(event.getHand()!=org.bukkit.inventory.EquipmentSlot.HAND)return;String[] parts=marker.split(":",2);if(parts.length!=2||!Set.of("clan","company").contains(parts[0]))return;try{String id=UUID.fromString(parts[1]).toString();organisations.openHomeNpc(event.getPlayer(),parts[0].equals("clan")?"clans":"companies",id);}catch(IllegalArgumentException ignored){}}
|
||||
@EventHandler public void scoreboardCommand(PlayerCommandPreprocessEvent e){String command=e.getMessage().trim();if(command.equalsIgnoreCase("/scoreboard")){e.setCancelled(true);toggleSidebar(e.getPlayer());}}
|
||||
@EventHandler(priority=EventPriority.LOWEST,ignoreCancelled=true) public void legacyTravel(PlayerCommandPreprocessEvent e){String[] args=e.getMessage().substring(1).trim().toLowerCase(Locale.ROOT).split("\\s+");String label=args[0].replaceFirst("^[^:]+:","");if(label.equals("balance")||label.equals("bal")||label.equals("money")){e.setCancelled(true);if(!sidebar.enabled(e.getPlayer()))sidebar.toggle(e.getPlayer());refreshSidebar(e.getPlayer());return;}if(label.equals("exchange")){e.setCancelled(true);exchange.command(e.getPlayer(),Arrays.copyOfRange(args,1,args.length));return;}if(label.equals("server")||label.equals("duneess")&&args.length>1&&args[1].equals("travel")){e.setCancelled(true);openGuild(e.getPlayer(),null);}}
|
||||
private void offerGuiPack(Player p){offerGuiPack(p,true);}
|
||||
private void offerGuiPack(Player p,boolean force){
|
||||
if(!p.isOnline()||BedrockForms.isBedrock(p))return;
|
||||
if(proxyPacks.ownsCommon()){
|
||||
proxyPacks.requestStatus(p);
|
||||
if(lobby(p)){MCGUIMenus.offerPack(p);ecologyArtwork.offer(p);}
|
||||
return;
|
||||
}
|
||||
var pack=guiPack(p);
|
||||
if(!force&&pack.equals(offeredGuiPacks.get(p.getUniqueId())))return;
|
||||
guiPackLoaded.remove(p.getUniqueId());
|
||||
// Replace only the network pack, never the separately managed planet pack.
|
||||
offeredGuiPacks.put(p.getUniqueId(),pack);
|
||||
p.addResourcePack(NetworkArtworkPolicy.PACK_ID,pack.url(),java.util.HexFormat.of().parseHex(pack.hash()),"DuneRealms menus and item artwork",true);
|
||||
if(lobby(p)){MCGUIMenus.offerPack(p);ecologyArtwork.offer(p);}
|
||||
}
|
||||
@EventHandler public void join(PlayerJoinEvent e){Bukkit.getScheduler().runTaskLater(this,()->{
|
||||
Player p=e.getPlayer();if(!p.isOnline())return;
|
||||
// Offer once in the play phase too: configuration-phase pack loading may finish
|
||||
// before the ordinary Bukkit player status event is available. The hash reuses cache.
|
||||
offerGuiPack(p,false);
|
||||
if(sidebar.enabled(p))refreshSidebar(p);
|
||||
},40L);}
|
||||
private void receiveProxyArtworkStatus(Player player,boolean loaded){
|
||||
if(loaded)guiPackLoaded.add(player.getUniqueId());
|
||||
else guiPackLoaded.remove(player.getUniqueId());
|
||||
}
|
||||
@EventHandler public void packStatus(PlayerResourcePackStatusEvent e){
|
||||
if(proxyPacks.ownsCommon()||!NetworkArtworkPolicy.PACK_ID.equals(e.getID()))return;
|
||||
getLogger().info("GUI pack status for "+e.getPlayer().getName()+": "+e.getStatus());
|
||||
if(e.getStatus()==PlayerResourcePackStatusEvent.Status.SUCCESSFULLY_LOADED){guiPackLoaded.add(e.getPlayer().getUniqueId());e.getPlayer().sendMessage(Component.text("DuneRealms artwork loaded. Reopen your menu.",NamedTextColor.GREEN));return;}
|
||||
guiPackLoaded.remove(e.getPlayer().getUniqueId());
|
||||
if(Set.of("FAILED_DOWNLOAD","FAILED_RELOAD","INVALID_URL","DECLINED","DISCARDED").contains(e.getStatus().name()))offeredGuiPacks.remove(e.getPlayer().getUniqueId());
|
||||
}
|
||||
@EventHandler public void world(PlayerChangedWorldEvent e){offerGuiPack(e.getPlayer(),false);bookings.cancel(e.getPlayer().getUniqueId());boarding.remove(e.getPlayer().getUniqueId());sidebar.hide(e.getPlayer());records.remove(e.getPlayer().getUniqueId());if(sidebar.enabled(e.getPlayer()))refreshSidebar(e.getPlayer());}
|
||||
static String selection(JsonObject data){if(!data.has("selection")||data.get("selection").isJsonNull())return null;String value=data.get("selection").getAsString();return HOUSE_IDS.contains(value)?value:null;}
|
||||
private String houseName(JsonObject data,String id){for(var entry:data.getAsJsonArray("choices")){var h=entry.getAsJsonObject();if(h.get("id").getAsString().equals(id))return h.get("name").getAsString();}throw new IllegalArgumentException("Unknown House");}
|
||||
private void select(Player p,JsonObject data,String picked){
|
||||
String current=selection(data),chosen=picked!=null?picked:current;
|
||||
Screen screen=screen(p,"Choose your House",0xE300+(chosen==null?0:Arrays.asList(IDS).indexOf(chosen)+1));
|
||||
for(int i=0;i<IDS.length;i++){String id=IDS[i];int centre=CENTRES[i];boolean selected=id.equals(chosen);
|
||||
var item=icon(p,houseName(data,id),selected?"Your current House":"Declare allegiance to this House","drgui_transparent",Material.PAPER);menuArt(item,"house_"+id);
|
||||
Runnable allegiance=()->declareHouse(p,data,id,true);
|
||||
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());screen.actions.put(slot,allegiance);}
|
||||
}
|
||||
button(screen,p,45,"Close","Return to the lobby",Material.ARROW,p::closeInventory);
|
||||
button(screen,p,49,sidebar.enabled(p)?"Hide scoreboard":"Show scoreboard","Toggle your personal briefing",Material.LEVER,()->{toggleSidebar(p);select(p,data,chosen);});
|
||||
for(int slot:new int[]{48,50})screen.actions.put(slot,screen.actions.get(49));
|
||||
screen.actions.put(46,screen.actions.get(45));
|
||||
showService(p,"house","Choose your House","",screen.inventory,screen.actions,screen.gate);
|
||||
}
|
||||
private void declareHouse(Player p,JsonObject data,String id,boolean openMenu){
|
||||
if(id.equals(selection(data))&&data.has("keyId")&&!data.get("keyId").isJsonNull()){
|
||||
if(openMenu)mentat(p,data);
|
||||
else p.sendMessage("Your House is "+houseName(data,id)+".");
|
||||
return;
|
||||
}
|
||||
fetch(p,id,data.get("version").getAsInt(),UUID.randomUUID(),saved->{
|
||||
p.sendMessage(Component.text("House allegiance saved in J.A.R.V.I.S.",NamedTextColor.GREEN));
|
||||
if(openMenu)mentat(p,saved);
|
||||
});
|
||||
}
|
||||
private void mentat(Player p,JsonObject data){
|
||||
String house=selection(data);if(house==null){select(p,data,null);return;}
|
||||
JsonObject mentor=data.getAsJsonObject("mentat");String name=mentor.get("name").getAsString();int index=Arrays.asList(IDS).indexOf(house);
|
||||
Screen screen=screen(p,"Your Mentat · "+name,0xE310+index);
|
||||
var portrait=icon(p,name,houseName(data,house),"drgui_transparent",Material.PLAYER_HEAD);menuArt(portrait,"mentat_"+house);screen.inventory.setItem(13,portrait);
|
||||
button(screen,p,38,"Open Mentat Report","Personal level, Reputation and active quests",Material.WRITABLE_BOOK,()->quests.open(p));
|
||||
button(screen,p,42,"Spacing Guild travel","Book passage to your House world",Material.COMPASS,()->openGuild(p,null));
|
||||
button(screen,p,45,"Your House",houseName(data,house),Material.ARROW,()->select(p,data,house));
|
||||
button(screen,p,49,sidebar.enabled(p)?"Hide scoreboard":"Show scoreboard","Toggle your personal briefing",Material.LEVER,()->{toggleSidebar(p);mentat(p,data);});for(int slot:new int[]{48,50})screen.actions.put(slot,screen.actions.get(49));
|
||||
for(int slot:new int[]{37,39})screen.actions.put(slot,screen.actions.get(38));for(int slot:new int[]{41,43})screen.actions.put(slot,screen.actions.get(42));screen.actions.put(46,screen.actions.get(45));
|
||||
showService(p,"mentat","Your Mentat · "+name,"",screen.inventory,screen.actions,screen.gate);
|
||||
}
|
||||
private static void menuArt(ItemStack item,String artwork){var meta=item.getItemMeta();meta.getPersistentDataContainer().set(new NamespacedKey("dunerealms","menu_art"),PersistentDataType.STRING,artwork);item.setItemMeta(meta);}
|
||||
private void report(Player p){p.closeInventory();p.sendMessage(Component.text("Open your Mentat Report →",NamedTextColor.GOLD).clickEvent(net.kyori.adventure.text.event.ClickEvent.openUrl("https://clans.dunerealms.com/#quests/quests")));}
|
||||
private Screen screen(Player p,String title,int glyph){Screen s=new Screen(p);Component heading=guiPackLoaded.contains(p.getUniqueId())?Component.text(GuiArtwork.background(glyph),NamedTextColor.WHITE).font(Key.key("dunerealms:house_selector")):Component.text(title,NamedTextColor.GOLD);s.inventory=Bukkit.createInventory(s,54,heading);return s;}
|
||||
private ItemStack icon(Player p,String title,String description,String model,Material fallback){ItemStack item=new ItemStack(guiPackLoaded.contains(p.getUniqueId())?Material.PAPER:fallback);var meta=item.getItemMeta();meta.displayName(Component.text(title,NamedTextColor.GOLD));meta.lore(List.of(Component.text(description,NamedTextColor.GRAY)));if(guiPackLoaded.contains(p.getUniqueId()))meta.setItemModel(new NamespacedKey("dunerealms",model));item.setItemMeta(meta);return item;}
|
||||
private void button(Screen s,Player p,int slot,String title,String description,Material material,Runnable action){s.inventory.setItem(slot,icon(p,title,description,"drgui_transparent",material));s.actions.put(slot,action);}
|
||||
private void expire(Screen screen){Bukkit.getScheduler().runTaskLater(this,screen.gate::expire,2400L);}
|
||||
@EventHandler public void click(InventoryClickEvent event){if(!(event.getView().getTopInventory().getHolder() instanceof Screen s))return;event.setCancelled(true);
|
||||
if(!(event.getWhoClicked() instanceof Player p)||!p.getUniqueId().equals(s.owner)||event.getClickedInventory()!=s.inventory||event.getClick()!=ClickType.LEFT)return;
|
||||
Runnable action=s.actions.get(event.getRawSlot());if(action==null||!s.gate.claim(p.getUniqueId()))return;
|
||||
Bukkit.getScheduler().runTask(this,()->{if(p.isOnline()&&s.worldId.equals(p.getWorld().getUID())&&p.getOpenInventory().getTopInventory()==s.inventory)action.run();});
|
||||
}
|
||||
@EventHandler public void drag(InventoryDragEvent e){if(e.getView().getTopInventory().getHolder() instanceof Screen)e.setCancelled(true);}
|
||||
@EventHandler(ignoreCancelled=true)
|
||||
public void protectMenuPlayer(org.bukkit.event.entity.EntityDamageEvent event){
|
||||
if(event.getEntity() instanceof Player player&&(
|
||||
player.getOpenInventory().getTopInventory().getHolder() instanceof DuneMenuInventory||
|
||||
MCGUIMenus.isOpen(player)||GuiSession.hasVisibleForm(player.getUniqueId(),player.getWorld().getUID())))event.setCancelled(true);
|
||||
}
|
||||
@EventHandler public void close(InventoryCloseEvent e){if(e.getInventory().getHolder() instanceof Screen s)s.gate.expire();}
|
||||
@EventHandler public void quit(PlayerQuitEvent e){GuiSession.expire(e.getPlayer().getUniqueId());MCGUIMenus.forget(e.getPlayer().getUniqueId());guiPackLoaded.remove(e.getPlayer().getUniqueId());offeredGuiPacks.remove(e.getPlayer().getUniqueId());bookings.cancel(e.getPlayer().getUniqueId());boarding.remove(e.getPlayer().getUniqueId());requests.remove(e.getPlayer().getUniqueId());records.remove(e.getPlayer().getUniqueId());sidebar.hide(e.getPlayer());departure.removePlayer(e.getPlayer());}
|
||||
private void ensureRegistrar(){World world=Bukkit.getWorld("guild_lobby");if(world==null)return;Location at=world.getSpawnLocation().clone().add(2,0,0);at.getChunk().load();
|
||||
for(Entity entity:world.getEntities())if(entity.getPersistentDataContainer().has(registrar,PersistentDataType.BYTE))return;
|
||||
Villager npc=world.spawn(at,Villager.class);npc.setAI(false);npc.setInvulnerable(true);npc.setPersistent(true);npc.setSilent(true);npc.setCollidable(false);npc.setProfession(Villager.Profession.LIBRARIAN);npc.customName(Component.text("House Registrar · Choose your House",NamedTextColor.GOLD));npc.setCustomNameVisible(true);npc.getPersistentDataContainer().set(registrar,PersistentDataType.BYTE,(byte)1);
|
||||
}
|
||||
@EventHandler public void npc(PlayerInteractEntityEvent e){if(!e.getRightClicked().getPersistentDataContainer().has(registrar,PersistentDataType.BYTE))return;e.setCancelled(true);if(e.getHand()!=EquipmentSlot.HAND||!lobby(e.getPlayer()))return;fetch(e.getPlayer(),null,0,null,data->{openMenu(e.getPlayer(),selection(data)!=null?"mentat":"house");});}
|
||||
private void tick(){
|
||||
long seconds=Instant.now().getEpochSecond(),remaining=DepartureWindow.remaining(seconds);var phase=DepartureWindow.phase(seconds);departure.setTitle("Spacing Guild · "+switch(phase){case BOARDING->"Travel open · closes in ";case LAUNCHING->"Launching · ";case WAITING->"Boarding opens in ";}+String.format(Locale.ROOT,"%02d:%02d",remaining/60,remaining%60));departure.setColor(phase==DepartureWindow.Phase.BOARDING?BarColor.GREEN:BarColor.YELLOW);departure.setProgress(DepartureWindow.progress(seconds));
|
||||
long now=Instant.now().getEpochSecond();for(var booking:bookings.due(now))board(booking);
|
||||
if(((phase==DepartureWindow.Phase.BOARDING&&remaining==300)||(phase==DepartureWindow.Phase.WAITING&&(remaining==300||remaining==60||remaining==10)))&&lastDepartureNotice!=now){lastDepartureNotice=now;for(Player p:Bukkit.getOnlinePlayers())if(lobby(p))p.sendMessage(Component.text(phase==DepartureWindow.Phase.BOARDING?"Spacing Guild · travel is open for five minutes.":"Spacing Guild · boarding opens in "+(remaining>=60?remaining/60+" minute(s).":remaining+" seconds."),NamedTextColor.GOLD));}
|
||||
for(World world:Bukkit.getWorlds())if(world.getName().equals("guild_lobby")){var battle=world.getEnderDragonBattle();if(battle!=null){if(battle.getBossBar()!=null){battle.getBossBar().setVisible(false);battle.getBossBar().removeAll();}
|
||||
if(!detached.containsKey(world.getUID()))try{Object handle=world.getClass().getMethod("getHandle").invoke(world);detached.put(world.getUID(),DragonController.detach(handle));getLogger().info("Lobby dragon controller detached; native bossbar disabled.");}catch(ReflectiveOperationException|RuntimeException unsupported){if(dragonWarnings.add(world.getUID()))getLogger().warning("Lobby dragon controller could not be detached; native bossbar fallback active.");}
|
||||
}}
|
||||
for(Player p:Bukkit.getOnlinePlayers())if(lobby(p)){if(!departure.getPlayers().contains(p))departure.addPlayer(p);}else departure.removePlayer(p);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue

Staff