From d94cbe7c946ea3ccdc311e654264d59dfdae937b Mon Sep 17 00:00:00 2001 From: Euphyllia Bierque Date: Sun, 7 Jul 2024 21:27:18 +0200 Subject: [PATCH] Re-support Folia : https://github.com/Euphillya/WorldEdit-Folia/commit/1e71b32593f1eae9960a59b3f83d93868d9e2599 --- .github/workflows/gradle.yml | 5 +++++ .../sk89q/worldedit/bukkit/BukkitBlockCommandSender.java | 6 ++++-- .../main/java/com/sk89q/worldedit/bukkit/BukkitEntity.java | 3 ++- .../main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java | 6 ++++-- .../com/sk89q/worldedit/bukkit/BukkitServerInterface.java | 4 +++- .../java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java | 7 ++++++- worldedit-bukkit/src/main/resources/plugin.yml | 5 +++-- 7 files changed, 27 insertions(+), 9 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 38be938e24..eeacdadf34 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -41,3 +41,8 @@ jobs: name: logs for ${{ matrix.os }} path: '**/*.log' + - name: Upload WorldEdit jar + uses: actions/upload-artifact@v2 + with: + name: WorldEdit-Folia-Snapshot + path: worldedit-bukkit/build/libs/* \ No newline at end of file diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockCommandSender.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockCommandSender.java index 12840c4dd7..151a618102 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockCommandSender.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockCommandSender.java @@ -156,11 +156,13 @@ public boolean isActive() { updateActive(); } else { // we should update it eventually - Bukkit.getScheduler().callSyncMethod(plugin, + Bukkit.getGlobalRegionScheduler().execute(plugin, + this::updateActive); + /*Bukkit.getScheduler().callSyncMethod(plugin, () -> { updateActive(); return null; - }); + });*/ } return active; } diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntity.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntity.java index e719902862..faed60f112 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntity.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntity.java @@ -74,7 +74,8 @@ public Location getLocation() { public boolean setLocation(Location location) { org.bukkit.entity.Entity entity = entityRef.get(); if (entity != null) { - return entity.teleport(BukkitAdapter.adapt(location)); + entity.teleportAsync(BukkitAdapter.adapt(location)); + return true; } else { return false; } diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java index ea4a3214e7..5ac403bc36 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java @@ -146,8 +146,9 @@ public void print(Component component) { @Override public boolean trySetPosition(Vector3 pos, float pitch, float yaw) { - return player.teleport(new Location(player.getWorld(), pos.x(), pos.y(), + player.teleportAsync(new Location(player.getWorld(), pos.x(), pos.y(), pos.z(), yaw, pitch)); + return true; } @Override @@ -224,7 +225,8 @@ public com.sk89q.worldedit.util.Location getLocation() { @Override public boolean setLocation(com.sk89q.worldedit.util.Location location) { - return player.teleport(BukkitAdapter.adapt(location)); + player.teleportAsync(BukkitAdapter.adapt(location)); + return true; } @SuppressWarnings("deprecation") // Paper's deprecation, we need to support Spigot still diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java index 8aed036162..7bf0e70eec 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java @@ -121,7 +121,9 @@ public void reload() { @Override public int schedule(long delay, long period, Runnable task) { - return Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, task, delay, period); + io.papermc.paper.threadedregions.scheduler.ScheduledTask scheduledTask = Bukkit.getGlobalRegionScheduler().runAtFixedRate(plugin, task1 -> task.run(), delay, period); + return scheduledTask.getExecutionState() == io.papermc.paper.threadedregions.scheduler.ScheduledTask.ExecutionState.CANCELLED ? -1 : scheduledTask.hashCode(); + //return Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, task, delay, period); } @Override diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java index a84370da7c..a52e29999b 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java @@ -326,7 +326,7 @@ public void onDisable() { if (config != null) { config.unload(); } - this.getServer().getScheduler().cancelTasks(this); + cancelTasks(); worldEdit.getExecutorService().shutdown(); } @@ -575,4 +575,9 @@ public void onAsyncTabComplete(com.destroystokyo.paper.event.server.AsyncTabComp event.setHandled(true); } } + + private void cancelTasks() { + this.getServer().getAsyncScheduler().cancelTasks(this); + this.getServer().getGlobalRegionScheduler().cancelTasks(this); + } } diff --git a/worldedit-bukkit/src/main/resources/plugin.yml b/worldedit-bukkit/src/main/resources/plugin.yml index aa19044bb0..cc0ad3957e 100644 --- a/worldedit-bukkit/src/main/resources/plugin.yml +++ b/worldedit-bukkit/src/main/resources/plugin.yml @@ -1,8 +1,9 @@ name: WorldEdit main: com.sk89q.worldedit.bukkit.WorldEditPlugin -version: "${internalVersion}" +version: "${internalVersion}-Folia" load: STARTUP api-version: 1.13 softdepend: [Vault] author: EngineHub -website: https://enginehub.org/worldedit \ No newline at end of file +website: https://enginehub.org/worldedit +folia-supported: true \ No newline at end of file