Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Folia support #2701

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
build_and_test:
strategy:
matrix:
jdkversion: [11]
jdkversion: [17]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
18 changes: 6 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<maven.minimumVersion>3.6.3</maven.minimumVersion>

<!-- Dependencies versions -->
<spigot.version>1.19.2-R0.1-SNAPSHOT</spigot.version>
<spigot.version>1.19.4-R0.1-SNAPSHOT</spigot.version>

<!-- Versioning properties -->
<project.outputName>AuthMe</project.outputName>
Expand Down Expand Up @@ -514,12 +514,11 @@
</snapshots>
</repository>

<!-- SpigotAPI Repo -->
<repository>
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots</url>
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
<releases>
<enabled>false</enabled>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
Expand Down Expand Up @@ -712,21 +711,16 @@
<optional>true</optional>
</dependency>

<!-- Spigot API, https://www.spigotmc.org/ -->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<groupId>dev.folia</groupId>
<artifactId>folia-api</artifactId>
<version>${spigot.version}</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>junit</artifactId>
<groupId>junit</groupId>
</exclusion>
<exclusion>
<artifactId>bungeecord-chat</artifactId>
<groupId>net.md-5</groupId>
</exclusion>
<exclusion>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
Expand Down
20 changes: 12 additions & 8 deletions src/main/java/fr/xephi/authme/AuthMe.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
import fr.xephi.authme.api.v3.AuthMeApi;
import fr.xephi.authme.command.CommandHandler;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.initialization.BukkitServiceProvider;
import fr.xephi.authme.initialization.DataFolder;
import fr.xephi.authme.initialization.DataSourceProvider;
import fr.xephi.authme.initialization.OnShutdownPlayerSaver;
import fr.xephi.authme.initialization.OnStartupTasks;
import fr.xephi.authme.initialization.SettingsProvider;
import fr.xephi.authme.initialization.TaskCloser;
import fr.xephi.authme.listener.BlockListener;
import fr.xephi.authme.listener.EntityListener;
import fr.xephi.authme.listener.PlayerListener;
Expand Down Expand Up @@ -39,12 +39,11 @@
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.java.JavaPluginLoader;
import org.bukkit.scheduler.BukkitScheduler;

import java.io.File;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;

import static fr.xephi.authme.service.BukkitService.TICKS_PER_MINUTE;
import static fr.xephi.authme.util.Utils.isClassLoaded;

/**
Expand All @@ -55,7 +54,7 @@ public class AuthMe extends JavaPlugin {
// Constants
private static final String PLUGIN_NAME = "AuthMeReloaded";
private static final String LOG_FILENAME = "authme.log";
private static final int CLEANUP_INTERVAL = 5 * TICKS_PER_MINUTE;
private static final int CLEANUP_INTERVAL_MINUTES = 5;

// Version and build number values
private static String pluginVersion = "N/D";
Expand Down Expand Up @@ -161,7 +160,7 @@ public void onEnable() {

// Schedule clean up task
CleanupTask cleanupTask = injector.getSingleton(CleanupTask.class);
cleanupTask.runTaskTimerAsynchronously(this, CLEANUP_INTERVAL, CLEANUP_INTERVAL);
bukkitService.runOnAsyncSchedulerAtFixedRate(cleanupTask, CLEANUP_INTERVAL_MINUTES, CLEANUP_INTERVAL_MINUTES, TimeUnit.MINUTES);

// Do a backup on start
backupService.doBackup(BackupService.BackupCause.START);
Expand Down Expand Up @@ -207,7 +206,7 @@ private void initialize() {
injector.register(AuthMe.class, this);
injector.register(Server.class, getServer());
injector.register(PluginManager.class, getServer().getPluginManager());
injector.register(BukkitScheduler.class, getServer().getScheduler());
injector.registerProvider(BukkitService.class, BukkitServiceProvider.class);
injector.provide(DataFolder.class, getDataFolder());
injector.registerProvider(Settings.class, SettingsProvider.class);
injector.registerProvider(DataSource.class, DataSourceProvider.class);
Expand Down Expand Up @@ -313,8 +312,13 @@ public void onDisable() {
backupService.doBackup(BackupService.BackupCause.STOP);
}

// Wait for tasks and close data source
new TaskCloser(this, database).run();
// Wait for tasks
bukkitService.waitAllTasks();

// Close data source
if (database != null) {
database.closeConnection();
}

// Disabled correctly
Consumer<String> infoLogMethod = logger == null ? getLogger()::info : logger::info;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void executeCommand(final CommandSender sender, List<String> arguments) {

// Assumption: a player name cannot contain '.'
if (playerName.contains(".")) {
bukkitService.runTaskAsynchronously(() -> {
bukkitService.runOnAsyncSchedulerNow(task -> {
List<String> accountList = dataSource.getAllAuthsByIp(playerName);
if (accountList.isEmpty()) {
sender.sendMessage("[AuthMe] This IP does not exist in the database.");
Expand All @@ -44,7 +44,7 @@ public void executeCommand(final CommandSender sender, List<String> arguments) {
}
});
} else {
bukkitService.runTaskAsynchronously(() -> {
bukkitService.runOnAsyncSchedulerNow(task -> {
PlayerAuth auth = dataSource.getAuth(playerName.toLowerCase(Locale.ROOT));
if (auth == null) {
commonService.send(sender, MessageKey.UNKNOWN_USER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void executeCommand(CommandSender sender, List<String> arguments) {
final Converter converter = converterFactory.newInstance(converterClass);

// Run the convert job
bukkitService.runTaskAsynchronously(() -> {
bukkitService.runOnAsyncSchedulerNow(task -> {
try {
converter.execute(sender);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fr.xephi.authme.command.executable.authme;

import fr.xephi.authme.command.PlayerCommand;
import fr.xephi.authme.service.BukkitService;
import fr.xephi.authme.settings.SpawnLoader;
import org.bukkit.entity.Player;

Expand All @@ -12,6 +13,8 @@
*/
public class FirstSpawnCommand extends PlayerCommand {

@Inject
private BukkitService bukkitService;
@Inject
private SpawnLoader spawnLoader;

Expand All @@ -20,7 +23,8 @@ public void runCommand(Player player, List<String> arguments) {
if (spawnLoader.getFirstSpawn() == null) {
player.sendMessage("[AuthMe] First spawn has failed, please try to define the first spawn");
} else {
player.teleport(spawnLoader.getFirstSpawn());
bukkitService.executeOptionallyOnEntityScheduler(player,
() -> bukkitService.teleport(player, spawnLoader.getFirstSpawn()), null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public class PurgePlayerCommand implements ExecutableCommand {
@Override
public void executeCommand(CommandSender sender, List<String> arguments) {
String option = arguments.size() > 1 ? arguments.get(1) : null;
bukkitService.runTaskAsynchronously(
() -> executeCommand(sender, arguments.get(0), option));
bukkitService.runOnAsyncSchedulerNow(task -> executeCommand(sender, arguments.get(0), option));
}

private void executeCommand(CommandSender sender, String name, String option) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ public void executeCommand(final CommandSender sender, List<String> arguments) {
logger.info(sender.getName() + " registered " + playerName);
final Player player = bukkitService.getPlayerExact(playerName);
if (player != null) {
bukkitService.scheduleSyncTaskFromOptionallyAsyncTask(() ->
player.kickPlayer(commonService.retrieveSingleMessage(player, MessageKey.KICK_FOR_ADMIN_REGISTER)));
bukkitService.executeOptionallyOnEntityScheduler(player, () ->
player.kickPlayer(commonService.retrieveSingleMessage(player, MessageKey.KICK_FOR_ADMIN_REGISTER))
, () -> logger.info("Can't kick player " + playerName + " because it's not available"));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fr.xephi.authme.command.executable.authme;

import fr.xephi.authme.command.PlayerCommand;
import fr.xephi.authme.service.BukkitService;
import fr.xephi.authme.settings.SpawnLoader;
import org.bukkit.entity.Player;

Expand All @@ -9,6 +10,8 @@

public class SpawnCommand extends PlayerCommand {

@Inject
private BukkitService bukkitService;
@Inject
private SpawnLoader spawnLoader;

Expand All @@ -17,7 +20,8 @@ public void runCommand(Player player, List<String> arguments) {
if (spawnLoader.getSpawn() == null) {
player.sendMessage("[AuthMe] Spawn has failed, please try to define the spawn");
} else {
player.teleport(spawnLoader.getSpawn());
bukkitService.executeOptionallyOnEntityScheduler(player,
() -> bukkitService.teleport(player, spawnLoader.getSpawn()), null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ protected void runCommand(Player player, List<String> arguments) {
return;
}

bukkitService.runTaskAsynchronously(() -> {
bukkitService.runOnAsyncSchedulerNow(task -> {
if (recoveryCodeService.isRecoveryCodeNeeded()) {
// Recovery code is needed; generate and send one
recoveryService.createAndSendRecoveryCode(player, email);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/fr/xephi/authme/data/TempbanManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void tempbanPlayer(final Player player) {
long newTime = expires.getTime() + (length * MILLIS_PER_MINUTE);
expires.setTime(newTime);

bukkitService.scheduleSyncDelayedTask(() -> {
bukkitService.runOnGlobalRegionScheduler(task -> {
if (customCommand.isEmpty()) {
bukkitService.banIp(ip, reason, expires, "AuthMe");
player.kickPlayer(reason);
Expand Down
21 changes: 12 additions & 9 deletions src/main/java/fr/xephi/authme/data/limbo/LimboPlayer.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package fr.xephi.authme.data.limbo;

import fr.xephi.authme.task.CancellableTask;
import fr.xephi.authme.task.MessageTask;
import org.bukkit.Location;
import org.bukkit.scheduler.BukkitTask;

import java.util.ArrayList;
import java.util.Collection;
Expand All @@ -22,8 +22,9 @@ public class LimboPlayer {
private final Location loc;
private final float walkSpeed;
private final float flySpeed;
private BukkitTask timeoutTask = null;
private CancellableTask timeoutTask = null;
private MessageTask messageTask = null;
private CancellableTask messageCancellableTask = null;
private LimboPlayerState state = LimboPlayerState.PASSWORD_REQUIRED;

public LimboPlayer(Location loc, boolean operator, Collection<UserGroup> groups, boolean fly, float walkSpeed,
Expand Down Expand Up @@ -81,7 +82,7 @@ public float getFlySpeed() {
*
* @return The timeout task associated to the player
*/
public BukkitTask getTimeoutTask() {
public CancellableTask getTimeoutTask() {
return timeoutTask;
}

Expand All @@ -91,7 +92,7 @@ public BukkitTask getTimeoutTask() {
*
* @param timeoutTask The task to set
*/
public void setTimeoutTask(BukkitTask timeoutTask) {
public void setTimeoutTask(CancellableTask timeoutTask) {
if (this.timeoutTask != null) {
this.timeoutTask.cancel();
}
Expand All @@ -110,20 +111,22 @@ public MessageTask getMessageTask() {
/**
* Set the messages task responsible for telling the player to log in or register.
*
* @param messageTask The message task to set
* @param messageTask The message task to set
* @param messageCancellableTask The related cancellable task
*/
public void setMessageTask(MessageTask messageTask) {
if (this.messageTask != null) {
this.messageTask.cancel();
public void setMessageTask(MessageTask messageTask, CancellableTask messageCancellableTask) {
if (this.messageCancellableTask != null) {
this.messageCancellableTask.cancel();
}
this.messageTask = messageTask;
this.messageCancellableTask = messageCancellableTask;
}

/**
* Clears all tasks associated to the player.
*/
public void clearTasks() {
setMessageTask(null);
setMessageTask(null, messageCancellableTask);
setTimeoutTask(null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.task.CancellableTask;
import fr.xephi.authme.task.MessageTask;
import fr.xephi.authme.task.TimeoutTask;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.NotNull;

import javax.inject.Inject;

import java.util.concurrent.TimeUnit;

import static fr.xephi.authme.service.BukkitService.TICKS_PER_SECOND;

/**
Expand Down Expand Up @@ -53,8 +57,9 @@ void registerMessageTask(Player player, LimboPlayer limbo, LimboMessageType mess
if (interval > 0) {
String[] joinMessage = messages.retrieveSingle(player, result.messageKey, result.args).split("\n");
MessageTask messageTask = new MessageTask(player, joinMessage);
bukkitService.runTaskTimer(messageTask, 2 * TICKS_PER_SECOND, interval * TICKS_PER_SECOND);
limbo.setMessageTask(messageTask);
CancellableTask messageCancellableTask
= bukkitService.runOnAsyncSchedulerAtFixedRate(messageTask, 2, interval, TimeUnit.SECONDS);
limbo.setMessageTask(messageTask, messageCancellableTask);
}
}

Expand All @@ -68,7 +73,7 @@ void registerTimeoutTask(Player player, LimboPlayer limbo) {
final int timeout = settings.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
if (timeout > 0) {
String message = messages.retrieveSingle(player, MessageKey.LOGIN_TIMEOUT_ERROR);
BukkitTask task = bukkitService.runTaskLater(new TimeoutTask(player, message, playerCache), timeout);
CancellableTask task = bukkitService.runOnGlobalRegionSchedulerDelayed(t -> new TimeoutTask(player, message, playerCache), timeout);
limbo.setTimeoutTask(task);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package fr.xephi.authme.initialization;

import fr.xephi.authme.AuthMe;
import fr.xephi.authme.service.BukkitService;
import fr.xephi.authme.service.FoliaBukkitService;
import fr.xephi.authme.service.PaperBukkitService;
import fr.xephi.authme.service.SpigotBukkitService;
import fr.xephi.authme.settings.Settings;

import javax.inject.Inject;
import javax.inject.Provider;

/**
* Creates the AuthMe bukkit service provider.
*/
public class BukkitServiceProvider implements Provider<BukkitService> {

@Inject
private AuthMe authMe;
@Inject
private Settings settings;

BukkitServiceProvider() {
}

@Override
public BukkitService get() {
try {
Class.forName("io.papermc.paper.threadedregions.scheduler.AsyncScheduler");
return new FoliaBukkitService(authMe, settings);
} catch (ClassNotFoundException ignored) {
try {
Class.forName("io.papermc.paper.util.Tick");
return new PaperBukkitService(authMe, settings);
} catch (ClassNotFoundException ignored2) {
return new SpigotBukkitService(authMe, settings);
}
}
}
}
Loading
Loading