From 1e71b32593f1eae9960a59b3f83d93868d9e2599 Mon Sep 17 00:00:00 2001 From: Euphyllia Bierque Date: Fri, 24 May 2024 00:08:03 +0200 Subject: [PATCH] Folia re-support --- .../bukkit/BukkitBlockCommandSender.java | 7 ++----- .../com/sk89q/worldedit/bukkit/BukkitEntity.java | 7 ++++++- .../com/sk89q/worldedit/bukkit/BukkitPlayer.java | 16 +++++++++++++--- .../worldedit/bukkit/BukkitServerInterface.java | 4 +++- .../sk89q/worldedit/bukkit/WorldEditPlugin.java | 3 ++- worldedit-bukkit/src/main/resources/plugin.yml | 5 +++-- 6 files changed, 29 insertions(+), 13 deletions(-) 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..3777aa6648 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,8 @@ public boolean isActive() { updateActive(); } else { // we should update it eventually - Bukkit.getScheduler().callSyncMethod(plugin, - () -> { - updateActive(); - return null; - }); + Bukkit.getGlobalRegionScheduler().execute(plugin, + this::updateActive); } 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..e04ec07207 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,12 @@ public Location getLocation() { public boolean setLocation(Location location) { org.bukkit.entity.Entity entity = entityRef.get(); if (entity != null) { - return entity.teleport(BukkitAdapter.adapt(location)); + try { + entity.teleportAsync(BukkitAdapter.adapt(location)); + return true; + } catch (Exception ignored) { + return false; + } } 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..f5a3340b15 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,13 @@ 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(), - pos.z(), yaw, pitch)); + try { + player.teleportAsync(new Location(player.getWorld(), pos.x(), pos.y(), + pos.z(), yaw, pitch)); + return true; + } catch (Exception ignored) { + return false; + } } @Override @@ -224,7 +229,12 @@ public com.sk89q.worldedit.util.Location getLocation() { @Override public boolean setLocation(com.sk89q.worldedit.util.Location location) { - return player.teleport(BukkitAdapter.adapt(location)); + try { + player.teleportAsync(BukkitAdapter.adapt(location)); + return true; + } catch (Exception ignored) { + return false; + } } @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..6726bf35d1 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 @@ -38,6 +38,7 @@ import com.sk89q.worldedit.world.DataFixer; import com.sk89q.worldedit.world.registry.Registries; import io.papermc.lib.PaperLib; +import io.papermc.paper.threadedregions.scheduler.ScheduledTask; import org.bukkit.Bukkit; import org.bukkit.NamespacedKey; import org.bukkit.Registry; @@ -121,7 +122,8 @@ public void reload() { @Override public int schedule(long delay, long period, Runnable task) { - return Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, task, delay, period); + ScheduledTask scheduledTask = Bukkit.getGlobalRegionScheduler().runAtFixedRate(plugin, task1 -> task.run(), delay, period); + return scheduledTask.getExecutionState() == ScheduledTask.ExecutionState.CANCELLED ? -1 : scheduledTask.hashCode(); } @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 a4167c0bb7..69582c5938 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,8 @@ public void onDisable() { if (config != null) { config.unload(); } - this.getServer().getScheduler().cancelTasks(this); + 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