From 885db23fc66951e198415bb69ff78dde32b65854 Mon Sep 17 00:00:00 2001 From: HaHaWTH Date: Sun, 14 Jan 2024 11:03:12 +0800 Subject: [PATCH] Folia Support(dev) --- pom.xml | 19 +++++++ src/main/java/fr/xephi/authme/AuthMe.java | 18 ++++++- .../xephi/authme/service/BukkitService.java | 53 ++++++++++--------- src/main/resources/plugin.yml | 1 + 4 files changed, 63 insertions(+), 28 deletions(-) diff --git a/pom.xml b/pom.xml index b19ca7fa..89c0d705 100644 --- a/pom.xml +++ b/pom.xml @@ -324,8 +324,18 @@ shade + + + + + ${project.finalNameBase}-Spigot-Universal + + com.github.Anon8281.universalScheduler + fr.xephi.authme.libs.com.github.Anon8281.universalScheduler + + com.google.common fr.xephi.authme.libs.com.google.common @@ -1049,6 +1059,15 @@ true + + + + com.github.Anon8281 + UniversalScheduler + 0.1.6 + compile + + de.luricos.bukkit diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index 5e2f74e5..73f95689 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -2,6 +2,8 @@ package fr.xephi.authme; import ch.jalu.injector.Injector; import ch.jalu.injector.InjectorBuilder; +import com.github.Anon8281.universalScheduler.UniversalScheduler; +import com.github.Anon8281.universalScheduler.scheduling.schedulers.TaskScheduler; import fr.xephi.authme.api.v3.AuthMeApi; import fr.xephi.authme.command.CommandHandler; import fr.xephi.authme.datasource.DataSource; @@ -77,6 +79,7 @@ public class AuthMe extends JavaPlugin { private static final String pluginBuild = "b"; private static String pluginBuildNumber = "40"; // Private instances + private static TaskScheduler scheduler; private EmailService emailService; private CommandHandler commandHandler; @Inject @@ -102,6 +105,14 @@ public class AuthMe extends JavaPlugin { return pluginBuild; } + /** + * Get the Universal Scheduler + * + * @return TaskScheduler + */ + public static TaskScheduler getScheduler() { + return scheduler; + } /** * Get the plugin's name. @@ -139,7 +150,7 @@ public class AuthMe extends JavaPlugin { public void onEnable() { // Load the plugin version data from the plugin description file loadPluginInfo(getDescription().getVersion()); - + scheduler = UniversalScheduler.getScheduler(this); // Set the Logger instance and log file path ConsoleLogger.initialize(getLogger(), new File(getDataFolder(), LOG_FILENAME)); logger = ConsoleLoggerFactory.get(AuthMe.class); @@ -189,6 +200,7 @@ public class AuthMe extends JavaPlugin { backupService.doBackup(BackupService.BackupCause.START); // Set up Metrics OnStartupTasks.sendMetrics(this, settings); + if (settings.getProperty(SecuritySettings.SHOW_STARTUP_BANNER)) { logger.info("\n" + " ___ __ __ __ ___ \n" + " / | __ __/ /_/ /_ / |/ /__ \n" + @@ -453,7 +465,9 @@ public class AuthMe extends JavaPlugin { private void checkServerType() { - if (isClassLoaded("com.destroystokyo.paper.PaperConfig")) { + if (isClassLoaded("io.papermc.paper.threadedregions.RegionizedServerInitEvent")) { + logger.info("AuthMeReReloaded is running on Folia"); + } else if (isClassLoaded("com.destroystokyo.paper.PaperConfig")) { logger.info("AuthMeReReloaded is running on Paper"); } else if (isClassLoaded("catserver.server.CatServerConfig")) { logger.info("AuthMeReReloaded is running on CatServer"); diff --git a/src/main/java/fr/xephi/authme/service/BukkitService.java b/src/main/java/fr/xephi/authme/service/BukkitService.java index a09b1850..87973ce2 100644 --- a/src/main/java/fr/xephi/authme/service/BukkitService.java +++ b/src/main/java/fr/xephi/authme/service/BukkitService.java @@ -1,5 +1,6 @@ package fr.xephi.authme.service; +import com.github.Anon8281.universalScheduler.scheduling.tasks.MyScheduledTask; import fr.xephi.authme.AuthMe; import fr.xephi.authme.initialization.SettingsDependent; import fr.xephi.authme.settings.Settings; @@ -48,10 +49,10 @@ public class BukkitService implements SettingsDependent { * This task will be executed by the main server thread. * * @param task Task to be executed - * @return Task id number (-1 if scheduling failed) + * Task id number (-1 if scheduling failed) */ - public int scheduleSyncDelayedTask(Runnable task) { - return Bukkit.getScheduler().scheduleSyncDelayedTask(authMe, task); + public void scheduleSyncDelayedTask(Runnable task) { + MyScheduledTask tsk = AuthMe.getScheduler().runTask(task); } /** @@ -59,12 +60,12 @@ public class BukkitService implements SettingsDependent { *

* This task will be executed by the main server thread. * - * @param task Task to be executed + * @param task Task to be executed * @param delay Delay in server ticks before executing task - * @return Task id number (-1 if scheduling failed) + * Task id number (-1 if scheduling failed) */ - public int scheduleSyncDelayedTask(Runnable task, long delay) { - return Bukkit.getScheduler().scheduleSyncDelayedTask(authMe, task, delay); + public void scheduleSyncDelayedTask(Runnable task, long delay) { + MyScheduledTask tsk = AuthMe.getScheduler().runTaskLater(task, delay); } /** @@ -76,7 +77,7 @@ public class BukkitService implements SettingsDependent { */ public void scheduleSyncTaskFromOptionallyAsyncTask(Runnable task) { if (Bukkit.isPrimaryThread()) { - task.run(); + AuthMe.getScheduler().runTask(task); } else { scheduleSyncDelayedTask(task); } @@ -86,12 +87,12 @@ public class BukkitService implements SettingsDependent { * Returns a task that will run on the next server tick. * * @param task the task to be run - * @return a BukkitTask that contains the id number + * a BukkitTask that contains the id number * @throws IllegalArgumentException if plugin is null * @throws IllegalArgumentException if task is null */ - public BukkitTask runTask(Runnable task) { - return Bukkit.getScheduler().runTask(authMe, task); + public void runTask(Runnable task) { + AuthMe.getScheduler().runTask(task); } /** @@ -105,7 +106,7 @@ public class BukkitService implements SettingsDependent { * @throws IllegalArgumentException if task is null */ public BukkitTask runTaskLater(Runnable task, long delay) { - return Bukkit.getScheduler().runTaskLater(authMe, task, delay); + return (BukkitTask) AuthMe.getScheduler().runTaskLater(task, delay); } /** @@ -116,9 +117,9 @@ public class BukkitService implements SettingsDependent { */ public void runTaskOptionallyAsync(Runnable task) { if (useAsyncTasks) { - runTaskAsynchronously(task); + AuthMe.getScheduler().runTaskAsynchronously(task); } else { - task.run(); + AuthMe.getScheduler().runTask(task); } } @@ -129,12 +130,12 @@ public class BukkitService implements SettingsDependent { * Returns a task that will run asynchronously. * * @param task the task to be run - * @return a BukkitTask that contains the id number + * a BukkitTask that contains the id number * @throws IllegalArgumentException if plugin is null * @throws IllegalArgumentException if task is null */ - public BukkitTask runTaskAsynchronously(Runnable task) { - return Bukkit.getScheduler().runTaskAsynchronously(authMe, task); + public void runTaskAsynchronously(Runnable task) { + AuthMe.getScheduler().runTaskAsynchronously(task); } /** @@ -148,27 +149,27 @@ public class BukkitService implements SettingsDependent { * @param delay the ticks to wait before running the task for the first * time * @param period the ticks to wait between runs - * @return a BukkitTask that contains the id number + * a BukkitTask that contains the id number * @throws IllegalArgumentException if task is null * @throws IllegalStateException if this was already scheduled */ - public BukkitTask runTaskTimerAsynchronously(BukkitRunnable task, long delay, long period) { - return task.runTaskTimerAsynchronously(authMe, delay, period); + public void runTaskTimerAsynchronously(BukkitRunnable task, long delay, long period) { + AuthMe.getScheduler().runTaskTimerAsynchronously(task, delay, period); } /** * Schedules the given task to repeatedly run until cancelled, starting after the * specified number of server ticks. * - * @param task the task to schedule - * @param delay the ticks to wait before running the task + * @param task the task to schedule + * @param delay the ticks to wait before running the task * @param period the ticks to wait between runs - * @return a BukkitTask that contains the id number + * a BukkitTask that contains the id number * @throws IllegalArgumentException if plugin is null - * @throws IllegalStateException if this was already scheduled + * @throws IllegalStateException if this was already scheduled */ - public BukkitTask runTaskTimer(BukkitRunnable task, long delay, long period) { - return task.runTaskTimer(authMe, delay, period); + public void runTaskTimer(BukkitRunnable task, long delay, long period) { + AuthMe.getScheduler().runTaskTimer(task, delay, period); } /** diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 3774e109..f0b0ebc8 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -16,6 +16,7 @@ softdepend: - EssentialsSpawn - ProtocolLib - floodgate +folia-supported: true commands: authme: description: AuthMe op commands