From 8932c711738ee70125cc2c157af6ee698a2c2d89 Mon Sep 17 00:00:00 2001 From: HaHaWTH Date: Mon, 25 Mar 2024 21:37:25 +0800 Subject: [PATCH] Fix --- .../authme/process/join/AsynchronousJoin.java | 4 ++- .../xephi/authme/service/BukkitService.java | 32 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) 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 31aff37e..aca8d306 100644 --- a/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java +++ b/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java @@ -189,7 +189,9 @@ public class AsynchronousJoin implements AsynchronousProcess { if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) { // Allow infinite blindness effect int blindTimeOut = (registrationTimeout <= 0) ? 99999 : registrationTimeout; - bukkitService.runTask(player,() -> player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, blindTimeOut, 2))); + + // AuthMeReReloaded - Fix potion apply on Folia + bukkitService.runTaskIfFolia(player,() -> player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, blindTimeOut, 2))); } commandManager.runCommandsOnJoin(player); }); diff --git a/src/main/java/fr/xephi/authme/service/BukkitService.java b/src/main/java/fr/xephi/authme/service/BukkitService.java index dd2603ab..989b608b 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; @@ -36,6 +37,8 @@ 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; + /** Whether the server is running Folia. */ + private static final boolean IS_FOLIA = Utils.isClassLoaded("io.papermc.paper.threadedregions.RegionizedServer"); private final AuthMe authMe; private boolean useAsyncTasks; @@ -102,6 +105,35 @@ public class BukkitService implements SettingsDependent { getScheduler().runTask(location, task); } + /** + * Runs the task synchronously if we are running Folia, else do nothing but run it. + * @param task the task to be run + */ + public void runTaskIfFolia(Runnable task) { + if (IS_FOLIA) { + runTask(task); + } else { + task.run(); + } + } + + public void runTaskIfFolia(Entity entity, Runnable task) { + if (IS_FOLIA) { + runTask(entity, task); + } else { + task.run(); + } + } + + public void runTaskIfFolia(Location location, Runnable task) { + if (IS_FOLIA) { + runTask(location, task); + } else { + task.run(); + } + } + + /** * Returns a task that will run after the specified number of server