Map core: claim outlines, pins, shop points, action poller, guild invite commands
This commit is contained in:
14 files changed
+1004
-11
No files matched your search
@@ -16,7 +16,7 @@ import java.util.UUID;
|
||||
* The panel is polled for a new copy only when its revision changes.
|
||||
*/
|
||||
public final class ClaimIndex {
|
||||
private record Guild(String id, String name, String tag) {}
|
||||
private record Guild(String id, String name, String tag, String icon) {}
|
||||
|
||||
private record Snapshot(String revision, Map<String, Map<Long, Guild>> claims, Map<String, Set<UUID>> members, int total) {}
|
||||
|
||||
@@ -59,6 +59,26 @@ public final class ClaimIndex {
|
||||
return new ChunkCheckResult(true, members != null && members.contains(player), guild.name(), guild.tag());
|
||||
}
|
||||
|
||||
/** One guild's claimed chunks in one dimension, for drawing on a map. */
|
||||
public record GuildClaims(String id, String name, String tag, String icon, Set<Long> chunks) {}
|
||||
|
||||
public static int chunkX(long key) { return (int) (key >> 32); }
|
||||
public static int chunkZ(long key) { return (int) key; }
|
||||
|
||||
/** Every claim grouped by dimension and guild (a copy; safe to use from any thread). */
|
||||
public Map<String, java.util.List<GuildClaims>> byDimension() {
|
||||
Snapshot s = snapshot;
|
||||
Map<String, java.util.List<GuildClaims>> out = new HashMap<>();
|
||||
if (s == null) return out;
|
||||
s.claims().forEach((dimension, chunks) -> {
|
||||
Map<String, GuildClaims> perGuild = new java.util.LinkedHashMap<>();
|
||||
chunks.forEach((key, guild) -> perGuild.computeIfAbsent(guild.id(),
|
||||
id -> new GuildClaims(guild.id(), guild.name(), guild.tag(), guild.icon(), new HashSet<>())).chunks().add(key));
|
||||
out.put(dimension, new java.util.ArrayList<>(perGuild.values()));
|
||||
});
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Applies a {@code guilds/claim-index} response. Returns true when the contents changed. */
|
||||
public boolean apply(JsonObject response) {
|
||||
if (response.has("unchanged") && response.get("unchanged").getAsBoolean()) return false;
|
||||
@@ -67,7 +87,8 @@ public final class ClaimIndex {
|
||||
Guild[] guilds = new Guild[guildList.size()];
|
||||
for (int i = 0; i < guilds.length; i++) {
|
||||
JsonObject g = guildList.get(i).getAsJsonObject();
|
||||
guilds[i] = new Guild(g.get("id").getAsString(), g.get("name").getAsString(), g.get("tag").getAsString());
|
||||
guilds[i] = new Guild(g.get("id").getAsString(), g.get("name").getAsString(), g.get("tag").getAsString(),
|
||||
g.has("icon_url") && g.get("icon_url").isJsonPrimitive() ? g.get("icon_url").getAsString() : "");
|
||||
}
|
||||
Map<String, Map<Long, Guild>> claims = new HashMap<>();
|
||||
JsonArray claimList = response.getAsJsonArray("claims");
|
||||
|
||||
Reference in new issue
Block a user