Fix running force actions in LoginSecurity thread-safe

This commit is contained in:
games647
2019-04-14 10:16:19 +02:00
parent 15c5857c4f
commit 9c1ba81cbe
3 changed files with 27 additions and 6 deletions

View File

@ -113,7 +113,7 @@
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>4.4.0-SNAPSHOT</version>
<version>4.4.0</version>
<scope>provided</scope>
</dependency>

View File

@ -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<Player> {
@Override
public boolean forceLogin(Player player) {
PlayerSession session = LoginSecurity.getSessionManager().getPlayerSession(player);
return session.isAuthorized() || session.performAction(new LoginAction(AuthService.PLUGIN, plugin)).isSuccess();
Future<Boolean> 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<Player> {
@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<Boolean> 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;
}
}
}

View File

@ -192,7 +192,6 @@ public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
return false;
}
public Configuration getConfig() {
return config;
}