From d1dbf777a42f706b36a04d56b74e62bf9291a849 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Thu, 11 Nov 2021 17:57:59 +0000 Subject: [PATCH] Don't check/set if a chunk should be saved if it's a world-plot --- .../bukkit/listener/ChunkListener.java | 6 ++-- .../bukkit/listener/SingleWorldListener.java | 30 ++--------------- .../core/plot/world/SinglePlotArea.java | 33 ++++++++++++++++++- 3 files changed, 37 insertions(+), 32 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 83acb6d13..9b76153df 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ChunkListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ChunkListener.java @@ -32,6 +32,7 @@ import com.plotsquared.core.location.Location; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.world.PlotAreaManager; +import com.plotsquared.core.plot.world.SinglePlotArea; import com.plotsquared.core.util.ReflectionUtils.RefClass; import com.plotsquared.core.util.ReflectionUtils.RefField; import com.plotsquared.core.util.ReflectionUtils.RefMethod; @@ -295,7 +296,7 @@ public class ChunkListener implements Listener { Chunk chunk = event.getChunk(); if (Settings.Chunk_Processor.AUTO_TRIM) { String world = chunk.getWorld().getName(); - if (this.plotAreaManager.hasPlotArea(world)) { + if ((!Settings.Enabled_Components.WORLDS || !SinglePlotArea.isSinglePlotWorld(world)) && this.plotAreaManager.hasPlotArea(world)) { if (unloadChunk(world, chunk, true)) { return; } @@ -365,8 +366,7 @@ public class ChunkListener implements Listener { } private void cleanChunk(final Chunk chunk) { - TaskManager.index.incrementAndGet(); - final int currentIndex = TaskManager.index.get(); + final int currentIndex = TaskManager.index.incrementAndGet(); PlotSquaredTask task = TaskManager.runTaskRepeat(() -> { if (!chunk.isLoaded()) { Objects.requireNonNull(TaskManager.removeTask(currentIndex)).cancel(); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/SingleWorldListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/SingleWorldListener.java index 3c9446979..92e580b6b 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/SingleWorldListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/SingleWorldListener.java @@ -27,6 +27,7 @@ package com.plotsquared.bukkit.listener; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.plot.world.PlotAreaManager; +import com.plotsquared.core.plot.world.SinglePlotArea; import com.plotsquared.core.plot.world.SinglePlotAreaManager; import com.plotsquared.core.util.ReflectionUtils; import org.bukkit.Chunk; @@ -86,7 +87,7 @@ public class SingleWorldListener implements Listener { if (!(man instanceof SinglePlotAreaManager)) { return; } - if (!isPlotId(name)) { + if (!SinglePlotArea.isSinglePlotWorld(name)) { return; } @@ -103,31 +104,4 @@ public class SingleWorldListener implements Listener { handle(event); } - private boolean isPlotId(String worldName) { - int len = worldName.length(); - int separator = 0; - for (int i = 0; i < len; i++) { - switch (worldName.charAt(i)) { - case '_': - separator++; - break; - case '-': - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - break; - default: - return false; - } - } - return separator == 1; - } - } diff --git a/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotArea.java b/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotArea.java index deb0e75af..a1830b5de 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotArea.java +++ b/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotArea.java @@ -37,7 +37,6 @@ import com.plotsquared.core.inject.annotations.WorldConfig; import com.plotsquared.core.listener.PlotListener; import com.plotsquared.core.location.BlockLoc; import com.plotsquared.core.location.Location; -import com.plotsquared.core.location.PlotLoc; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotAreaType; import com.plotsquared.core.plot.PlotId; @@ -78,6 +77,38 @@ public class SinglePlotArea extends GridPlotWorld { this.setDefaultHome(new BlockLoc(Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE)); } + /** + * Returns true if the given string matches the naming system used to identify single plot worlds + * e.g. -1_5 represents plot id *;-1;5. "*" being the plot area name given to single plot world + * {@link com.plotsquared.core.plot.PlotArea}. + */ + public static boolean isSinglePlotWorld(String worldName) { + int len = worldName.length(); + int separator = 0; + for (int i = 0; i < len; i++) { + switch (worldName.charAt(i)) { + case '_': + separator++; + break; + case '-': + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + break; + default: + return false; + } + } + return separator == 1; + } + @NonNull @Override protected PlotManager createManager() {