Fix LowerCase/Session Stolen issue

This commit is contained in:
Xephi59 2015-08-10 22:56:07 +02:00
parent 253b54da1d
commit 11db85ac26
2 changed files with 41 additions and 10 deletions

View File

@ -46,6 +46,8 @@ public class DataManager {
return result.get();
} catch (Exception e) {
return (null);
} finally {
executor.shutdown();
}
}
@ -159,4 +161,32 @@ public class DataManager {
}
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " Permissions");
}
public boolean isOnline(Player player, final String name) {
if (player.isOnline())
return true;
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<Boolean> result = executor.submit(new Callable<Boolean>() {
public synchronized Boolean call() throws Exception {
Boolean result = null;
try {
for (OfflinePlayer op : Bukkit.getOnlinePlayers())
if (op.getName().equalsIgnoreCase(name)) {
result = true;
break;
}
} catch (Exception e) {
}
return result;
}
});
try {
return result.get().booleanValue();
} catch (Exception e) {
return (false);
} finally {
executor.shutdown();
}
}
}

View File

@ -446,15 +446,16 @@ public class AuthMePlayerListener implements Listener {
// Check if forceSingleSession is set to true, so kick player that has
// joined with same nick of online player
if (player.isOnline() && Settings.isForceSingleSessionEnabled) {
if (plugin.dataManager.isOnline(player, name) && Settings.isForceSingleSessionEnabled) {
event.setKickMessage(m.send("same_nick")[0]);
event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
if (LimboCache.getInstance().hasLimboPlayer(name))
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(player.getName().toLowerCase());
if (PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase())) {
if (player != null && limbo != null && PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase())) {
Utils.getInstance().addNormal(player, limbo.getGroup());
LimboCache.getInstance().deleteLimboPlayer(player.getName().toLowerCase());
}