mirror of
https://github.com/TuxCoding/FastLogin.git
synced 2025-07-30 02:37:34 +02:00
Fix running force actions in LoginSecurity thread-safe
This commit is contained in:
@ -113,7 +113,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.comphenix.protocol</groupId>
|
<groupId>com.comphenix.protocol</groupId>
|
||||||
<artifactId>ProtocolLib</artifactId>
|
<artifactId>ProtocolLib</artifactId>
|
||||||
<version>4.4.0-SNAPSHOT</version>
|
<version>4.4.0</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
@ -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.LoginAction;
|
||||||
import com.lenis0012.bukkit.loginsecurity.session.action.RegisterAction;
|
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;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -29,9 +33,18 @@ public class LoginSecurityHook implements AuthPlugin<Player> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean forceLogin(Player player) {
|
public boolean forceLogin(Player player) {
|
||||||
PlayerSession session = LoginSecurity.getSessionManager().getPlayerSession(player);
|
Future<Boolean> future = Bukkit.getScheduler().callSyncMethod(plugin, () -> {
|
||||||
return session.isAuthorized() || session.performAction(new LoginAction(AuthService.PLUGIN, plugin)).isSuccess();
|
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
|
@Override
|
||||||
@ -42,7 +55,16 @@ public class LoginSecurityHook implements AuthPlugin<Player> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean forceRegister(Player player, String password) {
|
public boolean forceRegister(Player player, String password) {
|
||||||
PlayerSession session = LoginSecurity.getSessionManager().getPlayerSession(player);
|
Future<Boolean> future = Bukkit.getScheduler().callSyncMethod(plugin, () -> {
|
||||||
return session.performAction(new RegisterAction(AuthService.PLUGIN, plugin, password)).isSuccess();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -192,7 +192,6 @@ public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Configuration getConfig() {
|
public Configuration getConfig() {
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user