Fix async entity dismounts

This commit is contained in:
Josh Roy 2023-03-29 19:57:57 -04:00
parent a649f978c5
commit 04683ee43b
No known key found for this signature in database
GPG Key ID: 86A69D08540BC29A
3 changed files with 19 additions and 4 deletions

View File

@ -13,6 +13,7 @@ import net.ess3.api.events.teleport.PreTeleportEvent;
import net.ess3.api.events.teleport.TeleportWarmupEvent;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
@ -141,13 +142,13 @@ public class AsyncTeleport implements IAsyncTeleport {
paperFuture.exceptionally(future::completeExceptionally);
}
private void runOnMain(final Runnable runnable) throws ExecutionException, InterruptedException {
if (Bukkit.isPrimaryThread()) {
private void runOnEntity(final Entity entity, final Runnable runnable) throws ExecutionException, InterruptedException {
if (ess.isEntityThread(entity)) {
runnable.run();
return;
}
final CompletableFuture<Object> taskLock = new CompletableFuture<>();
Bukkit.getScheduler().runTask(ess, () -> {
ess.scheduleEntityDelayedTask(entity, () -> {
runnable.run();
taskLock.complete(new Object());
});
@ -171,7 +172,7 @@ public class AsyncTeleport implements IAsyncTeleport {
}
try {
runOnMain(() -> teleportee.getBase().eject()); //EntityDismountEvent requires a sync context.
runOnEntity(teleportee.getBase(), () -> teleportee.getBase().eject()); //EntityDismountEvent requires a sync context.
} catch (final ExecutionException | InterruptedException e) {
future.completeExceptionally(e);
return;

View File

@ -1228,6 +1228,16 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
return schedulingProvider.runGlobalLocationalTaskRepeating(run, delay, period);
}
@Override
public boolean isEntityThread(Entity entity) {
return schedulingProvider.isEntityThread(entity);
}
@Override
public boolean isRegionThread(Location location) {
return schedulingProvider.isRegionThread(location);
}
@Override
public PermissionsHandler getPermissionsHandler() {
return permissionsHandler;

View File

@ -125,6 +125,10 @@ public interface IEssentials extends Plugin {
void scheduleInitTask(Runnable runnable);
boolean isEntityThread(Entity entity);
boolean isRegionThread(Location location);
PermissionsHandler getPermissionsHandler();
AlternativeCommandsHandler getAlternativeCommandsHandler();