Skip to content

Commit

Permalink
Folia re-support
Browse files Browse the repository at this point in the history
  • Loading branch information
Euphillya committed May 23, 2024
1 parent 17029fe commit 1e71b32
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions worldedit-bukkit/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -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
website: https://enginehub.org/worldedit
folia-supported: true

0 comments on commit 1e71b32

Please sign in to comment.