Skip to content

Commit edad4cc

Browse files
committed
feat: folia support
1 parent 1277789 commit edad4cc

22 files changed

+495
-97
lines changed

bukkit/pom.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@
112112
</execution>
113113
</executions>
114114
</plugin>
115+
<plugin>
116+
<groupId>org.apache.maven.plugins</groupId>
117+
<artifactId>maven-compiler-plugin</artifactId>
118+
<configuration>
119+
<source>18</source>
120+
<target>18</target>
121+
</configuration>
122+
</plugin>
115123
</plugins>
116124
</build>
117125

@@ -398,5 +406,11 @@
398406
<version>1.80</version>
399407
<scope>test</scope>
400408
</dependency>
409+
<dependency>
410+
<groupId>org.projectlombok</groupId>
411+
<artifactId>lombok</artifactId>
412+
<version>1.18.30</version>
413+
<scope>provided</scope>
414+
</dependency>
401415
</dependencies>
402416
</project>

bukkit/src/main/java/com/github/games647/fastlogin/bukkit/BukkitScheduler.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,24 @@
2525
*/
2626
package com.github.games647.fastlogin.bukkit;
2727

28+
import com.github.games647.fastlogin.bukkit.scheduler.functions.Scheduler;
2829
import com.github.games647.fastlogin.core.scheduler.AsyncScheduler;
30+
import lombok.Getter;
2931
import org.bukkit.Bukkit;
3032
import org.bukkit.plugin.Plugin;
3133
import org.slf4j.Logger;
3234

3335
import java.util.concurrent.Executor;
3436

37+
@Getter
3538
public class BukkitScheduler extends AsyncScheduler {
3639

3740
private final Executor syncExecutor;
3841

3942
public BukkitScheduler(Plugin plugin, Logger logger) {
40-
super(logger, command -> Bukkit.getScheduler().runTaskAsynchronously(plugin, command));
43+
super(logger, command ->Scheduler.getAsyncScheduler().runTask(plugin, command));
4144

42-
syncExecutor = task -> Bukkit.getScheduler().runTask(plugin, task);
45+
syncExecutor = task -> Scheduler.getGlobalRegionScheduler().runTask(plugin, task);
4346
}
4447

45-
public Executor getSyncExecutor() {
46-
return syncExecutor;
47-
}
4848
}

bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import com.github.games647.fastlogin.bukkit.listener.protocollib.ProtocolLibListener;
3535
import com.github.games647.fastlogin.bukkit.listener.protocollib.SkinApplyListener;
3636
import com.github.games647.fastlogin.bukkit.listener.protocolsupport.ProtocolSupportListener;
37+
import com.github.games647.fastlogin.bukkit.scheduler.functions.Scheduler;
3738
import com.github.games647.fastlogin.bukkit.task.DelayedAuthHook;
3839
import com.github.games647.fastlogin.core.CommonUtil;
3940
import com.github.games647.fastlogin.core.PremiumStatus;
@@ -43,6 +44,7 @@
4344
import com.github.games647.fastlogin.core.hooks.bedrock.GeyserService;
4445
import com.github.games647.fastlogin.core.shared.FastLoginCore;
4546
import com.github.games647.fastlogin.core.shared.PlatformPlugin;
47+
import lombok.Getter;
4648
import org.bukkit.Bukkit;
4749
import org.bukkit.command.CommandSender;
4850
import org.bukkit.entity.Player;
@@ -72,14 +74,19 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
7274
Duration.ofMinutes(1), -1
7375
);
7476

77+
@Getter
7578
private final Map<UUID, PremiumStatus> premiumPlayers = new ConcurrentHashMap<>();
7679
private final Logger logger;
7780

7881
private boolean serverStarted;
82+
@Getter
7983
private BungeeManager bungeeManager;
8084
private final BukkitScheduler scheduler;
85+
@Getter
8186
private FastLoginCore<Player, CommandSender, FastLoginBukkit> core;
87+
@Getter
8288
private FloodgateService floodgateService;
89+
@Getter
8390
private GeyserService geyserService;
8491

8592
private PremiumPlaceholder premiumPlaceholder;
@@ -135,7 +142,7 @@ public void onEnable() {
135142
}
136143

137144
//delay dependency setup because we load the plugin very early where plugins are initialized yet
138-
getServer().getScheduler().runTaskLater(this, new DelayedAuthHook(this), 5L);
145+
Scheduler.getGlobalRegionScheduler().runTaskLater(this, new DelayedAuthHook(this), 5L);
139146

140147
pluginManager.registerEvents(new ConnectionListener(this), this);
141148

@@ -201,10 +208,6 @@ public void onDisable() {
201208
}
202209
}
203210

204-
public FastLoginCore<Player, CommandSender, FastLoginBukkit> getCore() {
205-
return core;
206-
}
207-
208211
/**
209212
* Gets a thread-safe map about players which are connecting to the server are being checked to be premium (paid
210213
* account)
@@ -234,10 +237,6 @@ public void removeSession(InetSocketAddress address) {
234237
loginSession.remove(id);
235238
}
236239

237-
public Map<UUID, PremiumStatus> getPremiumPlayers() {
238-
return premiumPlayers;
239-
}
240-
241240
/**
242241
* Fetches the premium status of an online player.
243242
* {@snippet :
@@ -279,10 +278,6 @@ public void markInitialized() {
279278
this.serverStarted = true;
280279
}
281280

282-
public BungeeManager getBungeeManager() {
283-
return bungeeManager;
284-
}
285-
286281
@Override
287282
public Path getPluginFolder() {
288283
return getDataFolder().toPath();
@@ -315,14 +310,6 @@ public boolean isPluginInstalled(String name) {
315310
return Bukkit.getServer().getPluginManager().getPlugin(name) != null;
316311
}
317312

318-
public FloodgateService getFloodgateService() {
319-
return floodgateService;
320-
}
321-
322-
public GeyserService getGeyserService() {
323-
return geyserService;
324-
}
325-
326313
@Override
327314
public BedrockService<?> getBedrockService() {
328315
if (floodgateService != null) {

bukkit/src/main/java/com/github/games647/fastlogin/bukkit/command/DeleteCommand.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.ArrayList;
2929
import java.util.List;
3030

31+
import com.github.games647.fastlogin.bukkit.scheduler.functions.Scheduler;
3132
import org.bukkit.Bukkit;
3233
import org.bukkit.command.Command;
3334
import org.bukkit.command.CommandSender;
@@ -65,10 +66,10 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
6566
return false;
6667
}
6768

68-
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
69+
Scheduler.getAsyncScheduler().runTask(plugin, () -> {
6970
int count = plugin.getCore().getStorage().deleteProfile(args[0]);
7071
if (!(sender instanceof ConsoleCommandSender)) {
71-
Bukkit.getScheduler().runTask(plugin, () -> {
72+
Scheduler.getGlobalRegionScheduler().runTask(plugin, () -> {
7273
if (count == 0) {
7374
sender.sendMessage("Error: No profile entries found!");
7475
} else {

bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hook/CrazyLoginHook.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,19 @@
2828
import com.comphenix.protocol.reflect.accessors.Accessors;
2929
import com.comphenix.protocol.reflect.accessors.FieldAccessor;
3030
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
31+
import com.github.games647.fastlogin.bukkit.scheduler.functions.Scheduler;
32+
import com.github.games647.fastlogin.bukkit.scheduler.task.TaskCallback;
3133
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
3234
import de.st_ddt.crazylogin.CrazyLogin;
3335
import de.st_ddt.crazylogin.data.LoginPlayerData;
3436
import de.st_ddt.crazylogin.databases.CrazyLoginDataDatabase;
3537
import de.st_ddt.crazylogin.listener.PlayerListener;
3638
import de.st_ddt.crazylogin.metadata.Authenticated;
39+
import lombok.var;
3740
import org.bukkit.Bukkit;
3841
import org.bukkit.entity.Player;
3942

43+
import java.util.Objects;
4044
import java.util.Optional;
4145
import java.util.concurrent.ExecutionException;
4246
import java.util.concurrent.Future;
@@ -65,13 +69,14 @@ public CrazyLoginHook(FastLoginBukkit plugin) {
6569
@Override
6670
public boolean forceLogin(Player player) {
6771
//not thread-safe operation
68-
Future<Optional<LoginPlayerData>> future = Bukkit.getScheduler().callSyncMethod(plugin, () -> {
72+
TaskCallback<Optional<LoginPlayerData>> callback = new TaskCallback<>();
73+
Scheduler.getAsyncScheduler().runTask(plugin, () -> {
6974
LoginPlayerData playerData = crazyLoginPlugin.getPlayerData(player);
7075
if (playerData != null) {
7176
//mark the account as logged in
7277
playerData.setLoggedIn(true);
7378

74-
String ip = player.getAddress().getAddress().getHostAddress();
79+
String ip = Objects.requireNonNull(player.getAddress()).getAddress().getHostAddress();
7580
//this should be done after login to restore the inventory, show players, prevent potential memory leaks...
7681
//from: https://github.com/ST-DDT/CrazyLogin/blob/master/src/main/java/de/st_ddt/crazylogin/CrazyLogin.java#L1948
7782
playerData.resetLoginFails();
@@ -90,25 +95,20 @@ public boolean forceLogin(Player player) {
9095
playerData.addIP(ip);
9196
player.setMetadata("Authenticated", new Authenticated(crazyLoginPlugin, player));
9297
crazyLoginPlugin.unregisterDynamicHooks();
93-
return Optional.of(playerData);
98+
callback.setCallBack(Optional.of(playerData));
9499
}
95100

96-
return Optional.empty();
101+
callback.setCallBack(Optional.empty());
97102
});
98103

99-
try {
100-
Optional<LoginPlayerData> result = future.get().filter(LoginPlayerData::isLoggedIn);
104+
var result = callback.getCallBack().filter(LoginPlayerData::isLoggedIn);
101105
if (result.isPresent()) {
102106
//SQL-Queries should run async
103107
crazyLoginPlugin.getCrazyDatabase().saveWithoutPassword(result.get());
104108
return true;
105109
}
106-
} catch (InterruptedException | ExecutionException ex) {
107-
plugin.getLog().error("Failed to forceLogin player: {}", player, ex);
108-
return false;
109-
}
110110

111-
return false;
111+
return false;
112112
}
113113

114114
@Override

bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hook/UltraAuthHook.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,13 @@
2626
package com.github.games647.fastlogin.bukkit.hook;
2727

2828
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
29+
import com.github.games647.fastlogin.bukkit.scheduler.functions.Scheduler;
30+
import com.github.games647.fastlogin.bukkit.scheduler.task.TaskCallback;
2931
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
30-
import org.bukkit.Bukkit;
3132
import org.bukkit.entity.Player;
3233
import ultraauth.api.UltraAuthAPI;
3334
import ultraauth.managers.PlayerManager;
3435

35-
import java.util.concurrent.ExecutionException;
36-
import java.util.concurrent.Future;
37-
3836
/**
3937
* Project page:
4038
* <p>
@@ -53,22 +51,17 @@ public UltraAuthHook(FastLoginBukkit plugin) {
5351
@Override
5452
public boolean forceLogin(Player player) {
5553
//not thread-safe
56-
Future<Boolean> future = Bukkit.getScheduler().callSyncMethod(plugin, () -> {
54+
TaskCallback<Boolean> callback = new TaskCallback<>();
55+
Scheduler.getAsyncScheduler().runTask(plugin, () -> {
5756
if (UltraAuthAPI.isAuthenticated(player)) {
5857
plugin.getLog().warn(ALREADY_AUTHENTICATED, player);
59-
return false;
58+
callback.setCallBack(false);
6059
}
6160

6261
UltraAuthAPI.authenticatedPlayer(player);
63-
return UltraAuthAPI.isAuthenticated(player);
62+
callback.setCallBack(UltraAuthAPI.isAuthenticated(player));
6463
});
65-
66-
try {
67-
return future.get();
68-
} catch (InterruptedException | ExecutionException ex) {
69-
plugin.getLog().error("Failed to forceLogin player: {}", player, ex);
70-
return false;
71-
}
64+
return callback.getCallBack();
7265
}
7366

7467
@Override

bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hook/XAuthHook.java

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,13 @@
2626
package com.github.games647.fastlogin.bukkit.hook;
2727

2828
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
29+
import com.github.games647.fastlogin.bukkit.scheduler.functions.Scheduler;
30+
import com.github.games647.fastlogin.bukkit.scheduler.task.TaskCallback;
2931
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
3032
import de.luricos.bukkit.xAuth.xAuth;
3133
import de.luricos.bukkit.xAuth.xAuthPlayer;
32-
import org.bukkit.Bukkit;
3334
import org.bukkit.entity.Player;
3435

35-
import java.util.concurrent.ExecutionException;
36-
import java.util.concurrent.Future;
37-
3836
/**
3937
* GitHub: <a href="https://github.com/LycanDevelopment/xAuth/">...</a>
4038
* <p>
@@ -54,30 +52,26 @@ public XAuthHook(FastLoginBukkit plugin) {
5452
@Override
5553
public boolean forceLogin(Player player) {
5654
//not thread-safe
57-
Future<Boolean> future = Bukkit.getScheduler().callSyncMethod(plugin, () -> {
55+
TaskCallback<Boolean> callback = new TaskCallback<>();
56+
Scheduler.getAsyncScheduler().runTask(plugin, () -> {
5857
xAuthPlayer xAuthPlayer = xAuthPlugin.getPlayerManager().getPlayer(player);
5958
if (xAuthPlayer != null) {
6059
if (xAuthPlayer.isAuthenticated()) {
6160
plugin.getLog().warn(ALREADY_AUTHENTICATED, player);
62-
return false;
61+
callback.setCallBack(false);
6362
}
6463

6564
//we checked that the player is premium (paid account)
6665
xAuthPlayer.setPremium(true);
6766

6867
//unprotect the inventory, op status...
69-
return xAuthPlugin.getPlayerManager().doLogin(xAuthPlayer);
68+
callback.setCallBack(xAuthPlugin.getPlayerManager().doLogin(xAuthPlayer));
7069
}
7170

72-
return false;
71+
callback.setCallBack(false);
7372
});
7473

75-
try {
76-
return future.get();
77-
} catch (InterruptedException | ExecutionException ex) {
78-
plugin.getLog().error("Failed to forceLogin player: {}", player, ex);
79-
return false;
80-
}
74+
return callback.getCallBack();
8175
}
8276

8377
@Override
@@ -90,21 +84,16 @@ public boolean isRegistered(String playerName) {
9084
@Override
9185
public boolean forceRegister(Player player, final String password) {
9286
//not thread-safe
93-
Future<Boolean> future = Bukkit.getScheduler().callSyncMethod(xAuthPlugin, () -> {
87+
TaskCallback<Boolean> callback = new TaskCallback<>();
88+
Scheduler.getAsyncScheduler().runTask(plugin, () -> {
9489
xAuthPlayer xAuthPlayer = xAuthPlugin.getPlayerManager().getPlayer(player);
9590
//this should run async because the plugin executes a sql query, but the method
9691
//accesses non thread-safe collections :(
97-
return xAuthPlayer != null
98-
&& xAuthPlugin.getAuthClass(xAuthPlayer).adminRegister(player.getName(), password, null);
92+
callback.setCallBack(xAuthPlayer != null
93+
&& xAuthPlugin.getAuthClass(xAuthPlayer).adminRegister(player.getName(), password, null));
9994

10095
});
101-
102-
try {
103-
//login in the player after registration
104-
return future.get() && forceLogin(player);
105-
} catch (InterruptedException | ExecutionException ex) {
106-
plugin.getLog().error("Failed to forceRegister player: {}", player, ex);
107-
return false;
108-
}
96+
// login in the player after registration
97+
return callback.getCallBack() && forceLogin(player);
10998
}
110-
}
99+
}

bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/BungeeListener.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import com.github.games647.fastlogin.bukkit.BukkitLoginSession;
2929
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
30+
import com.github.games647.fastlogin.bukkit.scheduler.functions.Scheduler;
3031
import com.github.games647.fastlogin.bukkit.task.ForceLoginTask;
3132
import com.github.games647.fastlogin.core.PremiumStatus;
3233
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
@@ -108,7 +109,7 @@ private void onLoginMessage(Player player, String playerName) {
108109
}
109110

110111
private void onRegisterMessage(Player player, String playerName) {
111-
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
112+
Scheduler.getAsyncScheduler().runTask(plugin, () -> {
112113
AuthPlugin<Player> authPlugin = plugin.getCore().getAuthPluginHook();
113114
try {
114115
//we need to check if the player is registered on Bukkit too
@@ -131,7 +132,7 @@ private void startLoginTaskIfReady(Player player, BukkitLoginSession session) {
131132
plugin.getLog().info("Delaying force login until join event fired?: {}", result);
132133
if (result) {
133134
Runnable forceLoginTask = new ForceLoginTask(plugin.getCore(), player, session);
134-
Bukkit.getScheduler().runTaskAsynchronously(plugin, forceLoginTask);
135+
Scheduler.getAsyncScheduler().runTask(plugin, forceLoginTask);
135136
}
136137
}
137138
}

0 commit comments

Comments
 (0)