diff --git a/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java b/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java index bc097276..4d277bda 100644 --- a/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java +++ b/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java @@ -191,9 +191,7 @@ public class AsynchronousJoin implements AsynchronousProcess { int blindTimeOut = (registrationTimeout <= 0) ? 99999 : registrationTimeout; // AuthMeReReloaded start - Fix async potion apply on Folia - bukkitService.runTask(() -> { - player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, blindTimeOut, 2)); - }); + bukkitService.runTaskSyncIfFolia(() -> player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, blindTimeOut, 2))); // AuthMeReReloaded end } diff --git a/src/main/java/fr/xephi/authme/service/BukkitService.java b/src/main/java/fr/xephi/authme/service/BukkitService.java index c73257d6..ff59329f 100644 --- a/src/main/java/fr/xephi/authme/service/BukkitService.java +++ b/src/main/java/fr/xephi/authme/service/BukkitService.java @@ -6,6 +6,7 @@ import fr.xephi.authme.AuthMe; import fr.xephi.authme.initialization.SettingsDependent; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.PluginSettings; +import fr.xephi.authme.util.Utils; import org.bukkit.BanEntry; import org.bukkit.BanList; import org.bukkit.Bukkit; @@ -34,6 +35,7 @@ public class BukkitService implements SettingsDependent { public static final int TICKS_PER_SECOND = 20; /** Number of ticks per minute. */ public static final int TICKS_PER_MINUTE = 60 * TICKS_PER_SECOND; + private static final boolean IS_FOLIA = Utils.isClassLoaded("io.papermc.paper.threadedregions.RegionizedServer"); private final AuthMe authMe; private boolean useAsyncTasks; @@ -139,6 +141,18 @@ public class BukkitService implements SettingsDependent { getScheduler().runTaskAsynchronously(task); } + /** + * Runs the task synchronously if we are on a Folia server, else runs normally. + * @param task the task to run + */ + public void runTaskSyncIfFolia(Runnable task) { + if (IS_FOLIA) { + runTask(task); + } else { + task.run(); + } + } + /** * Asynchronous tasks should never access any API in Bukkit. Great care * should be taken to assure the thread-safety of asynchronous tasks.