From 9c1ba81cbed69288f51a4969587be28a54a57db5 Mon Sep 17 00:00:00 2001 From: games647 Date: Sun, 14 Apr 2019 10:16:19 +0200 Subject: [PATCH] Fix running force actions in LoginSecurity thread-safe --- bukkit/pom.xml | 2 +- .../bukkit/hook/LoginSecurityHook.java | 30 ++++++++++++++++--- .../fastlogin/core/shared/FastLoginCore.java | 1 - 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/bukkit/pom.xml b/bukkit/pom.xml index 5428b7b1..cc043f8c 100644 --- a/bukkit/pom.xml +++ b/bukkit/pom.xml @@ -113,7 +113,7 @@ com.comphenix.protocol ProtocolLib - 4.4.0-SNAPSHOT + 4.4.0 provided diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hook/LoginSecurityHook.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hook/LoginSecurityHook.java index 85832b9d..28c05466 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hook/LoginSecurityHook.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hook/LoginSecurityHook.java @@ -8,6 +8,10 @@ import com.lenis0012.bukkit.loginsecurity.session.PlayerSession; import com.lenis0012.bukkit.loginsecurity.session.action.LoginAction; import com.lenis0012.bukkit.loginsecurity.session.action.RegisterAction; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; + +import org.bukkit.Bukkit; import org.bukkit.entity.Player; /** @@ -29,9 +33,18 @@ public class LoginSecurityHook implements AuthPlugin { @Override public boolean forceLogin(Player player) { - PlayerSession session = LoginSecurity.getSessionManager().getPlayerSession(player); - return session.isAuthorized() || session.performAction(new LoginAction(AuthService.PLUGIN, plugin)).isSuccess(); + Future future = Bukkit.getScheduler().callSyncMethod(plugin, () -> { + PlayerSession session = LoginSecurity.getSessionManager().getPlayerSession(player); + return session.isAuthorized() + || session.performAction(new LoginAction(AuthService.PLUGIN, plugin)).isSuccess(); + }); + try { + return future.get(); + } catch (InterruptedException | ExecutionException ex) { + plugin.getLog().error("Failed to forceLogin player: {}", player, ex); + return false; + } } @Override @@ -42,7 +55,16 @@ public class LoginSecurityHook implements AuthPlugin { @Override public boolean forceRegister(Player player, String password) { - PlayerSession session = LoginSecurity.getSessionManager().getPlayerSession(player); - return session.performAction(new RegisterAction(AuthService.PLUGIN, plugin, password)).isSuccess(); + Future future = Bukkit.getScheduler().callSyncMethod(plugin, () -> { + PlayerSession session = LoginSecurity.getSessionManager().getPlayerSession(player); + return session.performAction(new RegisterAction(AuthService.PLUGIN, plugin, password)).isSuccess(); + }); + + try { + return future.get(); + } catch (InterruptedException | ExecutionException ex) { + plugin.getLog().error("Failed to forceLogin player: {}", player, ex); + return false; + } } } diff --git a/core/src/main/java/com/github/games647/fastlogin/core/shared/FastLoginCore.java b/core/src/main/java/com/github/games647/fastlogin/core/shared/FastLoginCore.java index 9b676354..da22fffd 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/shared/FastLoginCore.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/shared/FastLoginCore.java @@ -192,7 +192,6 @@ public class FastLoginCore

> { return false; } - public Configuration getConfig() { return config; }