diff --git a/sources/src/main/java/io/akarin/server/mixin/core/MixinMinecraftServer.java b/sources/src/main/java/io/akarin/server/mixin/core/MixinMinecraftServer.java index 2431bba94..7081a8aea 100644 --- a/sources/src/main/java/io/akarin/server/mixin/core/MixinMinecraftServer.java +++ b/sources/src/main/java/io/akarin/server/mixin/core/MixinMinecraftServer.java @@ -6,7 +6,6 @@ import java.util.concurrent.ExecutorCompletionService; import java.util.concurrent.Executors; import java.util.concurrent.FutureTask; -import org.bukkit.World; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.chunkio.ChunkIOExecutor; import org.bukkit.event.inventory.InventoryMoveItemEvent; diff --git a/sources/src/main/java/io/akarin/server/mixin/cps/MixinChunkProviderServer.java b/sources/src/main/java/io/akarin/server/mixin/cps/MixinChunkProviderServer.java index 06e45da06..c85915f23 100644 --- a/sources/src/main/java/io/akarin/server/mixin/cps/MixinChunkProviderServer.java +++ b/sources/src/main/java/io/akarin/server/mixin/cps/MixinChunkProviderServer.java @@ -42,6 +42,7 @@ public abstract class MixinChunkProviderServer { long unloadAfter = world.paperConfig.delayChunkUnloadsBy; SlackActivityAccountant activityAccountant = world.getMinecraftServer().slackActivityAccountant; activityAccountant.startActivity(0.5); + ObjectIterator> it = chunks.long2ObjectEntrySet().fastIterator(); int remainingChunks = chunks.size(); int targetSize = Math.min(remainingChunks - 100, (int) (remainingChunks * UNLOAD_QUEUE_RESIZE_FACTOR)); // Paper - Make more aggressive @@ -49,22 +50,19 @@ public abstract class MixinChunkProviderServer { while (it.hasNext()) { Entry entry = it.next(); Chunk chunk = entry.getValue(); - if (chunk == null) continue; - if (chunk.isUnloading()) { + if (chunk != null && chunk.isUnloading()) { if (chunk.scheduledForUnload != null) { - if (now - chunk.scheduledForUnload > unloadAfter) { - if (unloadChunk(chunk, true)) { - chunk.scheduledForUnload = null; - it.remove(); - } - chunk.setShouldUnload(false); - } else { - continue; - } + if (now - chunk.scheduledForUnload <= unloadAfter) continue; } - if (--remainingChunks <= targetSize || activityAccountant.activityTimeIsExhausted()) break; // more slack since the target size not work as intended + if (unloadChunk(chunk, true)) { + it.remove(); + } + chunk.setShouldUnload(false); + chunk.scheduledForUnload = null; + + if (--remainingChunks <= targetSize && activityAccountant.activityTimeIsExhausted()) break; } } activityAccountant.endActivity(); diff --git a/sources/src/main/java/net/minecraft/server/World.java b/sources/src/main/java/net/minecraft/server/World.java index 0e01687eb..27ad6d07f 100644 --- a/sources/src/main/java/net/minecraft/server/World.java +++ b/sources/src/main/java/net/minecraft/server/World.java @@ -41,6 +41,7 @@ import com.google.common.collect.Sets; // Paper end import com.google.common.util.concurrent.ThreadFactoryBuilder; +import io.akarin.launcher.AkarinMixinConfig; import io.akarin.server.core.AkarinGlobalConfig; /** @@ -3438,7 +3439,7 @@ public abstract class World implements IBlockAccess { boolean flag = true; short keepLoadedRange = paperConfig.keepLoadedRange; // Paper - return k >= -keepLoadedRange && k <= keepLoadedRange && l >= -keepLoadedRange && l <= keepLoadedRange && this.keepSpawnInMemory; // CraftBukkit - Added 'this.keepSpawnInMemory' // Paper - Re-add range var + return k >= -keepLoadedRange && k <= keepLoadedRange && l >= -keepLoadedRange && l <= keepLoadedRange && this.keepSpawnInMemory && !AkarinMixinConfig.removeChunkUnloadQueue; // CraftBukkit - Added 'this.keepSpawnInMemory' // Paper - Re-add range var // Akarin } public void a(Packet packet) {