Skip to content

Commit

Permalink
Fix PlayerTeleportEvent called async
Browse files Browse the repository at this point in the history
  • Loading branch information
Euphillya committed Dec 12, 2024
1 parent 013bd36 commit ac2ea7e
Showing 1 changed file with 2 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ public TeleportEvent(InterneAPI interneAPI) {
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerTeleportEvent(final PlayerTeleportEvent event) {
if (event.isCancelled()) return;

Location to = event.getTo();
Runnable task = () -> {
Location to = event.getTo();
World world = to.getWorld();
if (world == null || !WorldUtils.isWorldSkyblock(world.getName())) return;

Expand All @@ -46,8 +45,7 @@ public void onPlayerTeleportEvent(final PlayerTeleportEvent event) {
Location centerIsland = RegionHelper.getCenterRegion(world, island.getPosition().x(), island.getPosition().z());
api.getPlayerNMS().setOwnWorldBorder(api.getPlugin(), event.getPlayer(), centerIsland, island.getSize(), 0, 0);
};

executeAsync(task);
Bukkit.getRegionScheduler().execute(api.getPlugin(), to, task);
}

@EventHandler(priority = EventPriority.HIGHEST)
Expand Down Expand Up @@ -83,12 +81,4 @@ public void onPlayerUsePortal(final PlayerPortalEvent event) {
ListenersUtils.checkPermission(location, player, permission, event);
}
}

private void executeAsync(Runnable task) {
if (ConfigToml.useVirtualThread) {
Thread.startVirtualThread(task);
} else {
Bukkit.getAsyncScheduler().runNow(api.getPlugin(), scheduledTask -> task.run());
}
}
}

0 comments on commit ac2ea7e

Please sign in to comment.