forked from unimatrix/web
Preserve public nameplates when DuneMenus takes over
This commit is contained in:
parent
53d2e211b3
commit
022b8f3823
2 changed files with 45 additions and 10 deletions
|
|
@ -1,5 +1,6 @@
|
|||
package com.dunerealms.menus;
|
||||
|
||||
import com.dunerealms.identity.PublicNameplates;
|
||||
import com.dunerealms.npc.PolQuestNpc;
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
|
|
@ -23,6 +24,7 @@ public final class DuneMenusPlugin extends JavaPlugin implements TabExecutor {
|
|||
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<>();
|
||||
|
||||
|
|
@ -67,12 +69,21 @@ public final class DuneMenusPlugin extends JavaPlugin implements TabExecutor {
|
|||
} 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);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override public void onDisable() {
|
||||
if (nativeRoutes != null) nativeRoutes.close();
|
||||
if (nameplates != null) nameplates.close();
|
||||
}
|
||||
|
||||
Backend backend() { return backend; }
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.dunerealms.menus;
|
||||
|
||||
import com.dunerealms.identity.PublicNameplates;
|
||||
import com.dunerealms.jarvis.DunemarkDenomination;
|
||||
import com.dunerealms.jarvis.JarvisTranslator;
|
||||
import com.google.gson.JsonArray;
|
||||
|
|
@ -330,6 +331,27 @@ 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,()->{
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff