Skip to content

Commit 4552a89

Browse files
committed
fix: limits doesn't persist across reboots
Replaces: InsightsPlugin#249
1 parent f8f8c6a commit 4552a89

3 files changed

Lines changed: 25 additions & 40 deletions

File tree

Insights-API/src/main/java/dev/frankheijden/insights/api/concurrent/ChunkContainerExecutor.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ public CompletableFuture<Storage> submit(Chunk chunk, ChunkCuboid cuboid, ScanOp
6262
return submit(new LoadedChunkContainer(nms, chunk, cuboid, options), options);
6363
}
6464

65+
public CompletableFuture<Storage> submitLoadChunkContainer(World world, int chunkX, int chunkZ, ChunkCuboid cuboid, ScanOptions options) {
66+
return world.getChunkAtAsync(chunkX, chunkZ, false, true)
67+
.thenCompose(chunk ->
68+
submit(new LoadedChunkContainer(nms, chunk, cuboid, options), options)
69+
);
70+
}
71+
6572
public CompletableFuture<Storage> submit(World world, int x, int z, ChunkCuboid cuboid, ScanOptions options) {
6673
return submit(new UnloadedChunkContainer(nms, world, x, z, cuboid, options), options);
6774
}

Insights-API/src/main/java/dev/frankheijden/insights/api/concurrent/containers/LoadedChunkContainer.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,11 @@ public LoadedChunkContainer(InsightsNMS nms, Chunk chunk, ChunkCuboid cuboid, Sc
2626

2727
@Override
2828
public void getChunkSections(Consumer<@Nullable ChunkSection> sectionConsumer) {
29-
if (Bukkit.isOwnedByCurrentRegion(chunk.getWorld(), chunkX, chunkZ)) {
30-
nms.getLoadedChunkSections(chunk, sectionConsumer);
31-
} else {
32-
Bukkit.getRegionScheduler().execute(InsightsPlugin.getInstance(), chunk.getWorld(), chunkX, chunkZ, () -> nms.getLoadedChunkSections(chunk, sectionConsumer));
33-
}
29+
nms.getLoadedChunkSections(chunk, sectionConsumer);
3430
}
3531

3632
@Override
3733
public void getChunkEntities(Consumer<@NotNull ChunkEntity> entityConsumer) {
38-
if (Bukkit.isOwnedByCurrentRegion(chunk.getWorld(), chunkX, chunkZ)) {
39-
nms.getLoadedChunkEntities(chunk, entityConsumer);
40-
} else {
41-
Bukkit.getRegionScheduler().execute(InsightsPlugin.getInstance(), chunk.getWorld(), chunkX, chunkZ, () -> nms.getLoadedChunkEntities(chunk, entityConsumer));
42-
}
34+
nms.getLoadedChunkEntities(chunk, entityConsumer);
4335
}
4436
}

Insights-API/src/main/java/dev/frankheijden/insights/api/tasks/ScanTask.java

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -418,36 +418,22 @@ public void run() {
418418
var loc = chunkPart.getChunkLocation();
419419
var world = loc.getWorld();
420420

421-
Bukkit.getRegionScheduler().run(plugin, world, loc.getX(), loc.getZ(), scheduledTask -> {
422-
CompletableFuture<Storage> storageFuture;
423-
if (world.isChunkLoaded(loc.getX(), loc.getZ())) {
424-
storageFuture = executor.submit(
425-
world.getChunkAt(loc.getX(), loc.getZ()),
426-
chunkPart.getChunkCuboid(),
427-
options
428-
);
429-
} else {
430-
storageFuture = executor.submit(
431-
loc.getWorld(),
432-
loc.getX(),
433-
loc.getZ(),
434-
chunkPart.getChunkCuboid(),
435-
options
436-
);
437-
}
438-
storageFuture
439-
.thenAccept(storage -> resultMerger.accept(storage, loc, result))
440-
.thenRun(() -> {
441-
iterationChunks.incrementAndGet();
442-
chunks.incrementAndGet();
443-
})
444-
.exceptionally(th -> {
445-
if (!completedExceptionally.getAndSet(true)) {
446-
plugin.getLogger().log(Level.SEVERE, th, th::getMessage);
447-
}
448-
return null;
449-
});
450-
});
421+
executor.submitLoadChunkContainer(world,
422+
loc.getX(),
423+
loc.getZ(),
424+
chunkPart.getChunkCuboid(),
425+
options)
426+
.thenAccept(storage -> resultMerger.accept(storage, loc, result))
427+
.thenRun(() -> {
428+
iterationChunks.incrementAndGet();
429+
chunks.incrementAndGet();
430+
})
431+
.exceptionally(th -> {
432+
if (!completedExceptionally.getAndSet(true)) {
433+
plugin.getLogger().log(Level.SEVERE, th, th::getMessage);
434+
}
435+
return null;
436+
});
451437
}
452438
}
453439

0 commit comments

Comments
 (0)