3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-12-27 03:12:37 +01:00

Throw exception if player is retired to ensure task always finishes

Dieser Commit ist enthalten in:
SirYwell 2023-03-09 11:29:31 +01:00
Ursprung 00b13399d1
Commit c0653d0693
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden

Datei anzeigen

@ -117,6 +117,7 @@ public class FoliaTaskManager extends TaskManager {
private static final MethodHandle EXECUTE_FOR_LOCATION;
private static final MethodHandle EXECUTE_FOR_PLAYER;
private static final Runnable THROW_IF_RETIRED = () -> throwRetired();
private static final MethodType LOCATION_EXECUTE_TYPE = methodType(
void.class,
@ -160,7 +161,7 @@ public class FoliaTaskManager extends TaskManager {
// (ES, P, R, R, L)Z (ES, R, R, L)Z
executeForPlayer = insertArguments(executeForPlayer, 1, pluginInstance);
// (ES, R1, R2, L)Z -> (ES, R1)Z
executeForPlayer = insertArguments(executeForPlayer, 2, null, 0);
executeForPlayer = insertArguments(executeForPlayer, 2, THROW_IF_RETIRED, 0);
// (ES, R1)Z -> (ES, R1)V
executeForPlayer = dropReturn(executeForPlayer);
MethodHandle getScheduler = lookup.findVirtual(
@ -190,7 +191,6 @@ public class FoliaTaskManager extends TaskManager {
}
}
static void executeForEntity(Player player, Runnable task) {
// TODO task might not be run if player retires
try {
EXECUTE_FOR_PLAYER.invokeExact(BukkitAdapter.adapt(player), task);
} catch (Error | RuntimeException e) {
@ -200,6 +200,10 @@ public class FoliaTaskManager extends TaskManager {
}
}
private static void throwRetired() {
throw new RuntimeException("Player retired");
}
}
}