From f020a4bf2a903385f3ceb67a2ced1e65f6d3bb14 Mon Sep 17 00:00:00 2001 From: Warrior <50800980+Warriorrrr@users.noreply.github.com> Date: Tue, 9 Aug 2022 20:34:06 +0200 Subject: [PATCH] Add WorldCoord#getChunks --- .../bukkit/towny/object/WorldCoord.java | 46 +++++++++++-------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/src/com/palmergames/bukkit/towny/object/WorldCoord.java b/src/com/palmergames/bukkit/towny/object/WorldCoord.java index d4be9e2a75..1f2a369488 100644 --- a/src/com/palmergames/bukkit/towny/object/WorldCoord.java +++ b/src/com/palmergames/bukkit/towny/object/WorldCoord.java @@ -14,8 +14,13 @@ import org.bukkit.entity.Entity; import org.bukkit.util.BoundingBox; import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.Unmodifiable; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; import java.util.Objects; +import java.util.Set; import java.util.concurrent.CompletableFuture; public class WorldCoord extends Coord { @@ -157,7 +162,7 @@ public boolean isWilderness() { /** * Loads the chunks represented by a WorldCoord. Creates a PluginChunkTicket so * that the WorldCoord will remain loaded, even when no players are present. - * + *
* Uses PaperLib's getChunkAtAsync when Paper is present.
*/
public void loadChunks() {
@@ -169,25 +174,13 @@ public void loadChunks() {
}
private void loadChunks(Towny plugin) {
- if (getCellSize() > 16) {
- // Dealing with a townblocksize greater than 16, we will have multiple chunks per WorldCoord.
- int side = Math.round(getCellSize() / 16);
- for (int x = 0; x <= side; x++) {
- for (int z = 0; z <= side; z++) {
- CompletableFuture
* Uses PaperLib's getChunkAtAsync when Paper is present.
*/
public void unloadChunks() {
@@ -199,18 +192,31 @@ public void unloadChunks() {
}
private void unloadChunks(Towny plugin) {
+ getChunks().forEach(future -> future.thenAccept(chunk -> chunk.addPluginChunkTicket(plugin)));
+ }
+
+ /**
+ * Loads & returns the chunk(s) inside this WorldCoord.
+ *
+ * Chunks are loaded async on servers using paper.
+ * @return An unmodifiable collection of chunk futures.
+ */
+ @Unmodifiable
+ public Collection