From 8c0f7b207e0a581287e37a8a24bf3c42c5fc82f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Wed, 13 May 2020 14:39:58 +0200 Subject: [PATCH] Make the chunk listener NOT delete all tile entities in the chunk --- .../bukkit/listener/ChunkListener.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ChunkListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ChunkListener.java index 2f84732a7..1cfc897d4 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ChunkListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ChunkListener.java @@ -266,7 +266,7 @@ public class ChunkListener implements Listener { long start = System.currentTimeMillis(); int i = 0; while (System.currentTimeMillis() - start < 250) { - if (i >= tiles.length) { + if (i >= tiles.length - Settings.Chunk_Processor.MAX_TILES) { Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex)); TaskManager.tasks.remove(currentIndex); PlotSquared.debug("Successfully processed and unloaded chunk!"); @@ -287,11 +287,16 @@ public class ChunkListener implements Listener { Entity[] entities = chunk.getEntities(); BlockState[] tiles = chunk.getTileEntities(); if (entities.length > Settings.Chunk_Processor.MAX_ENTITIES) { - for (Entity ent : entities) { - if (!(ent instanceof Player)) { - ent.remove(); + int toRemove = entities.length - Settings.Chunk_Processor.MAX_ENTITIES; + int index = 0; + while (toRemove > 0 && index < entities.length) { + final Entity entity = entities[index++]; + if (!(entity instanceof Player)) { + entity.remove(); + toRemove--; } } + PlotSquared.debug( "PlotSquared detected unsafe chunk and processed: " + (chunk.getX() << 4) + "," + ( chunk.getX() << 4)); @@ -304,8 +309,9 @@ public class ChunkListener implements Listener { cleanChunk(chunk); return true; } - for (BlockState tile : tiles) { - tile.getBlock().setType(Material.AIR, false); + + for (int i = 0 ; i < (tiles.length - Settings.Chunk_Processor.MAX_TILES); i++) { + tiles[i].getBlock().setType(Material.AIR, false); } } return false;