forked from TuxCoding/FastLogin
Call force methods sync
This commit is contained in:
@ -4,7 +4,7 @@
|
||||
|
||||
<parent>
|
||||
<groupId>com.github.games647</groupId>
|
||||
<artifactId>fastlogin-parent</artifactId>
|
||||
<artifactId>fastlogin</artifactId>
|
||||
<version>0.8</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
@ -2,15 +2,18 @@ package com.github.games647.fastlogin.bukkit;
|
||||
|
||||
import com.github.games647.fastlogin.bukkit.hooks.BukkitAuthPlugin;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
|
||||
public class ForceLoginTask implements Runnable {
|
||||
|
||||
private final FastLoginBukkit plugin;
|
||||
protected final FastLoginBukkit plugin;
|
||||
private final Player player;
|
||||
|
||||
public ForceLoginTask(FastLoginBukkit plugin, Player player) {
|
||||
@ -32,7 +35,7 @@ public class ForceLoginTask implements Runnable {
|
||||
player.setMetadata(plugin.getName(), new FixedMetadataValue(plugin, true));
|
||||
//check if it's the same player as we checked before
|
||||
|
||||
BukkitAuthPlugin authPlugin = plugin.getAuthPlugin();
|
||||
final BukkitAuthPlugin authPlugin = plugin.getAuthPlugin();
|
||||
if (session == null || !player.getName().equals(session.getUsername()) || authPlugin == null) {
|
||||
return;
|
||||
}
|
||||
@ -52,17 +55,37 @@ public class ForceLoginTask implements Runnable {
|
||||
}
|
||||
|
||||
if (success) {
|
||||
if (session.needsRegistration()) {
|
||||
forceRegister(authPlugin, player);
|
||||
} else {
|
||||
forceLogin(authPlugin, player);
|
||||
}
|
||||
performForceAction(session, authPlugin);
|
||||
}
|
||||
} else if (playerProfile != null) {
|
||||
storage.save(playerProfile);
|
||||
}
|
||||
}
|
||||
|
||||
private void performForceAction(PlayerSession session, final BukkitAuthPlugin authPlugin) {
|
||||
try {
|
||||
if (session.needsRegistration()) {
|
||||
Bukkit.getScheduler().callSyncMethod(plugin, new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
forceRegister(authPlugin, player);
|
||||
return null;
|
||||
}
|
||||
}).get();
|
||||
} else {
|
||||
Bukkit.getScheduler().callSyncMethod(plugin, new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
forceLogin(authPlugin, player);
|
||||
return null;
|
||||
}
|
||||
}).get();
|
||||
}
|
||||
} catch (InterruptedException | ExecutionException exception) {
|
||||
plugin.getLogger().log(Level.SEVERE, "Failed to perform sync force action", exception);
|
||||
}
|
||||
}
|
||||
|
||||
private void forceRegister(BukkitAuthPlugin authPlugin, Player player) {
|
||||
plugin.getLogger().log(Level.FINE, "Register player {0}", player.getName());
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
<parent>
|
||||
<groupId>com.github.games647</groupId>
|
||||
<artifactId>fastlogin-parent</artifactId>
|
||||
<artifactId>fastlogin</artifactId>
|
||||
<version>0.8</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
<parent>
|
||||
<groupId>com.github.games647</groupId>
|
||||
<artifactId>fastlogin-parent</artifactId>
|
||||
<artifactId>fastlogin</artifactId>
|
||||
<version>0.8</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
Reference in New Issue
Block a user