Add account connections, guild wallets and admin fixes [skip ci]
This commit is contained in:
1 parent
7076e847ea
commit
004862ea88
38 files changed
+1696
-458
No files matched your search
@@ -132,6 +132,10 @@ public final class Integration implements AutoCloseable {
|
||||
return client.checkChunk(dimension, chunkX, chunkZ, uuid);
|
||||
}
|
||||
|
||||
public void prefetchClaims(String dimension, int chunkX, int chunkZ, UUID uuid) {
|
||||
client.prefetchClaims(dimension, chunkX, chunkZ, uuid);
|
||||
}
|
||||
|
||||
@Override public void close() {
|
||||
closed = true;
|
||||
client.close();
|
||||
|
||||
@@ -12,6 +12,7 @@ public final class PanelClient {
|
||||
private record Cached(ChunkCheckResult result, long expires) {}
|
||||
private final java.util.Map<ChunkKey, Cached> claims = new java.util.concurrent.ConcurrentHashMap<>();
|
||||
private final java.util.Set<ChunkKey> pendingClaims = java.util.concurrent.ConcurrentHashMap.newKeySet();
|
||||
private final java.util.Set<ChunkKey> pendingSnapshots = java.util.concurrent.ConcurrentHashMap.newKeySet();
|
||||
private final java.util.concurrent.ThreadPoolExecutor claimWorker = new java.util.concurrent.ThreadPoolExecutor(
|
||||
2, 2, 0, java.util.concurrent.TimeUnit.SECONDS, new java.util.concurrent.ArrayBlockingQueue<>(64),
|
||||
task -> { Thread t = new Thread(task, "scopenet-claims"); t.setDaemon(true); return t; });
|
||||
@@ -86,6 +87,43 @@ public final class PanelClient {
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
||||
/** Warm a 5x5 area when a player changes chunks, including environmental protection. */
|
||||
public void prefetchClaims(String dimension, int chunkX, int chunkZ, java.util.UUID uuid) {
|
||||
if (!settings.guildsEnabled() || !settings.landClaimingEnabled()) return;
|
||||
ChunkKey center = new ChunkKey(dimension, chunkX, chunkZ, uuid);
|
||||
Cached cached = claims.get(center);
|
||||
if (cached != null && cached.expires() > System.nanoTime()) return;
|
||||
if (!pendingSnapshots.add(center)) return;
|
||||
long generation = claimGeneration.get();
|
||||
try { claimWorker.execute(() -> {
|
||||
try {
|
||||
JsonObject req = new JsonObject();
|
||||
req.addProperty("uuid", uuid.toString());
|
||||
req.addProperty("dimension", dimension);
|
||||
req.addProperty("chunk_x", chunkX);
|
||||
req.addProperty("chunk_z", chunkZ);
|
||||
JsonObject snapshot = post("guilds/claim-snapshot", req);
|
||||
java.util.Map<String, ChunkCheckResult> found = new java.util.HashMap<>();
|
||||
for (JsonElement el : snapshot.getAsJsonArray("claims")) {
|
||||
JsonObject c = el.getAsJsonObject();
|
||||
String coord = c.get("chunk_x").getAsInt() + ":" + c.get("chunk_z").getAsInt();
|
||||
found.put(coord, new ChunkCheckResult(true, c.get("allowed").getAsBoolean(),
|
||||
c.get("guild_name").getAsString(), c.get("guild_tag").getAsString()));
|
||||
}
|
||||
long expiry = System.nanoTime() + java.util.concurrent.TimeUnit.SECONDS.toNanos(15);
|
||||
if (generation != claimGeneration.get()) return;
|
||||
if (claims.size() > 4096) claims.clear();
|
||||
for (int x = chunkX - 2; x <= chunkX + 2; x++) for (int z = chunkZ - 2; z <= chunkZ + 2; z++) {
|
||||
ChunkCheckResult value = found.getOrDefault(x + ":" + z, new ChunkCheckResult(false, true, null, null));
|
||||
claims.put(new ChunkKey(dimension, x, z, uuid), new Cached(value, expiry));
|
||||
claims.put(new ChunkKey(dimension, x, z, new java.util.UUID(0, 0)),
|
||||
new Cached(new ChunkCheckResult(value.claimed(), !value.claimed(), value.guildName(), value.guildTag()), expiry));
|
||||
}
|
||||
} catch (Exception ignored) { /* cold checks remain fail closed */ }
|
||||
finally { pendingSnapshots.remove(center); }
|
||||
}); } catch (java.util.concurrent.RejectedExecutionException e) { pendingSnapshots.remove(center); }
|
||||
}
|
||||
|
||||
private ChunkCheckResult checkChunkRemote(String dimension, int chunkX, int chunkZ, java.util.UUID uuid) {
|
||||
if (!settings.guildsEnabled() || !settings.landClaimingEnabled()) {
|
||||
return new ChunkCheckResult(false, true, null, null);
|
||||
@@ -226,4 +264,3 @@ public final class PanelClient {
|
||||
return el.isJsonArray() ? el.getAsJsonArray() : new JsonArray();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user