From 7ac3f7ca03e2ae6066b17aa101f4be82d0b541d2 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Fri, 8 Jan 2021 12:59:33 +0000 Subject: [PATCH] Fix sync tasks not being sync --- .../plotsquared/bukkit/BukkitPlatform.java | 2 +- .../bukkit/util/BukkitSetupUtils.java | 37 ++++++++++--------- .../bukkit/util/task/BukkitTaskManager.java | 2 +- .../com/plotsquared/core/PlotSquared.java | 2 +- .../com/plotsquared/core/command/Confirm.java | 2 +- .../core/util/SchematicHandler.java | 4 +- 6 files changed, 26 insertions(+), 23 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java index 587487276..23a869023 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java @@ -333,7 +333,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl // Economy if (Settings.Enabled_Components.ECONOMY) { - TaskManager.runTask(() -> { + TaskManager.runTaskAsync(() -> { this.permissionHandler().initialize(); final EconHandler econHandler = injector().getInstance(EconHandler.class); econHandler.init(); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java index bc22faceb..4c740fe4e 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java @@ -40,9 +40,10 @@ import com.plotsquared.core.plot.PlotAreaType; import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.setup.PlotAreaBuilder; import com.plotsquared.core.util.SetupUtils; -import io.papermc.lib.PaperLib; +import com.plotsquared.core.util.task.TaskManager; import org.bukkit.Bukkit; import org.bukkit.Chunk; +import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.generator.ChunkGenerator; @@ -97,24 +98,26 @@ import java.util.Objects; } @Override public void unload(String worldName, boolean save) { - World world = Bukkit.getWorld(worldName); - if (world == null) { - return; - } - World dw = Bukkit.getWorlds().get(0); - for (Player player : world.getPlayers()) { - PaperLib.teleportAsync(player, dw.getSpawnLocation()); - } - if (save) { - for (Chunk chunk : world.getLoadedChunks()) { - chunk.unload(true); + TaskManager.runTask(() -> { + World world = Bukkit.getWorld(worldName); + if (world == null) { + return; } - } else { - for (Chunk chunk : world.getLoadedChunks()) { - chunk.unload(false); + Location location = Bukkit.getWorlds().get(0).getSpawnLocation(); + for (Player player : world.getPlayers()) { + player.teleport(location); } - } - Bukkit.unloadWorld(world, false); + if (save) { + for (Chunk chunk : world.getLoadedChunks()) { + chunk.unload(true); + } + } else { + for (Chunk chunk : world.getLoadedChunks()) { + chunk.unload(false); + } + } + Bukkit.unloadWorld(world, false); + }); } @Override public String setupWorld(PlotAreaBuilder builder) { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/task/BukkitTaskManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/task/BukkitTaskManager.java index 368bc49ce..24bec8b38 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/task/BukkitTaskManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/task/BukkitTaskManager.java @@ -92,7 +92,7 @@ import java.util.concurrent.TimeUnit; } @Override public void task(@Nonnull final Runnable runnable) { - new BukkitPlotSquaredTask(runnable).runTaskAsynchronously(this.bukkitMain); + new BukkitPlotSquaredTask(runnable).runTask(this.bukkitMain); } @Override public void taskLater(@Nonnull final Runnable runnable, diff --git a/Core/src/main/java/com/plotsquared/core/PlotSquared.java b/Core/src/main/java/com/plotsquared/core/PlotSquared.java index 0eeb67517..fb402609a 100644 --- a/Core/src/main/java/com/plotsquared/core/PlotSquared.java +++ b/Core/src/main/java/com/plotsquared/core/PlotSquared.java @@ -387,7 +387,7 @@ public class PlotSquared { if (!file.exists()) { return; } - TaskManager.runTask(() -> { + TaskManager.runTaskAsync(() -> { try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file))) { List list = (List) ois.readObject(); ArrayList regionInts = (ArrayList) list.get(0); diff --git a/Core/src/main/java/com/plotsquared/core/command/Confirm.java b/Core/src/main/java/com/plotsquared/core/command/Confirm.java index ec384d9aa..f01f735be 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Confirm.java +++ b/Core/src/main/java/com/plotsquared/core/command/Confirm.java @@ -47,7 +47,7 @@ public class Confirm extends SubCommand { player.sendMessage(TranslatableCaption.of("confirm.expired_confirm")); return false; } - TaskManager.runTask(command.command); + TaskManager.runTaskAsync(command.command); return true; } } diff --git a/Core/src/main/java/com/plotsquared/core/util/SchematicHandler.java b/Core/src/main/java/com/plotsquared/core/util/SchematicHandler.java index 1119f5800..f8c3a586d 100644 --- a/Core/src/main/java/com/plotsquared/core/util/SchematicHandler.java +++ b/Core/src/main/java/com/plotsquared/core/util/SchematicHandler.java @@ -210,7 +210,7 @@ public abstract class SchematicHandler { } this.exportAll = true; final ArrayList plots = new ArrayList<>(collection); - TaskManager.runTask(new Runnable() { + TaskManager.runTaskAsync(new Runnable() { @Override public void run() { if (plots.isEmpty()) { SchematicHandler.this.exportAll = false; @@ -637,7 +637,7 @@ public abstract class SchematicHandler { ByteArrayOutputStream buffer = new ByteArrayOutputStream(width * height * length); ByteArrayOutputStream biomeBuffer = new ByteArrayOutputStream(width * length); // Queue - TaskManager.runTask(() -> { + TaskManager.runTaskAsync(() -> { final BlockVector3 minimum = aabb.getMinimumPoint(); final BlockVector3 maximum = aabb.getMaximumPoint();