Call force methods sync

This commit is contained in:
games647
2016-05-03 16:55:08 +02:00
parent ffa5059c67
commit a7b164b513
4 changed files with 33 additions and 10 deletions

View File

@ -4,7 +4,7 @@
<parent> <parent>
<groupId>com.github.games647</groupId> <groupId>com.github.games647</groupId>
<artifactId>fastlogin-parent</artifactId> <artifactId>fastlogin</artifactId>
<version>0.8</version> <version>0.8</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>

View File

@ -2,15 +2,18 @@ package com.github.games647.fastlogin.bukkit;
import com.github.games647.fastlogin.bukkit.hooks.BukkitAuthPlugin; import com.github.games647.fastlogin.bukkit.hooks.BukkitAuthPlugin;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.logging.Level; import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.metadata.FixedMetadataValue;
public class ForceLoginTask implements Runnable { public class ForceLoginTask implements Runnable {
private final FastLoginBukkit plugin; protected final FastLoginBukkit plugin;
private final Player player; private final Player player;
public ForceLoginTask(FastLoginBukkit plugin, 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)); player.setMetadata(plugin.getName(), new FixedMetadataValue(plugin, true));
//check if it's the same player as we checked before //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) { if (session == null || !player.getName().equals(session.getUsername()) || authPlugin == null) {
return; return;
} }
@ -52,17 +55,37 @@ public class ForceLoginTask implements Runnable {
} }
if (success) { if (success) {
if (session.needsRegistration()) { performForceAction(session, authPlugin);
forceRegister(authPlugin, player);
} else {
forceLogin(authPlugin, player);
}
} }
} else if (playerProfile != null) { } else if (playerProfile != null) {
storage.save(playerProfile); 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) { private void forceRegister(BukkitAuthPlugin authPlugin, Player player) {
plugin.getLogger().log(Level.FINE, "Register player {0}", player.getName()); plugin.getLogger().log(Level.FINE, "Register player {0}", player.getName());

View File

@ -4,7 +4,7 @@
<parent> <parent>
<groupId>com.github.games647</groupId> <groupId>com.github.games647</groupId>
<artifactId>fastlogin-parent</artifactId> <artifactId>fastlogin</artifactId>
<version>0.8</version> <version>0.8</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>

View File

@ -4,7 +4,7 @@
<parent> <parent>
<groupId>com.github.games647</groupId> <groupId>com.github.games647</groupId>
<artifactId>fastlogin-parent</artifactId> <artifactId>fastlogin</artifactId>
<version>0.8</version> <version>0.8</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>