From 8c05655330f5270ca0b52c64bae7c86f2f7dd05a Mon Sep 17 00:00:00 2001 From: Tux Date: Mon, 22 Jun 2015 04:54:15 -0400 Subject: [PATCH] Always kick the new player in online mode. Allowing the new player on is more seamless, but does not synchronize well, so I've forced a kick instead, which is a cleaner solution at the expense of minor inconvenience. --- .../redisbungee/RedisBungeeListener.java | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeListener.java b/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeListener.java index f817ea9..3356df7 100644 --- a/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeListener.java +++ b/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeListener.java @@ -60,6 +60,11 @@ public class RedisBungeeListener implements Listener { .append("\n\nIf you were disconnected forcefully, please wait up to one minute.\nIf this does not resolve your issue, please contact staff.") .color(ChatColor.GRAY) .create(); + private static final BaseComponent[] ONLINE_MODE_RECONNECT = + new ComponentBuilder("Whoops! You need to reconnect.").color(ChatColor.RED) + .append("\n\nWe found someone online using your username. They were kicked and you may reconnect.\nIf this does not work, please contact staff.") + .color(ChatColor.GRAY) + .create(); private final RedisBungee plugin; private final List exemptAddresses; @@ -74,22 +79,30 @@ public class RedisBungeeListener implements Listener { return null; } - // If a player with this name isn't on this proxy, we make sure they aren't trying to use an existing - // player's name. This is BungeeCord behavior I disapprove of but I don't really care at this point. - ProxiedPlayer player = plugin.getProxy().getPlayer(event.getConnection().getName()); + // We make sure they aren't trying to use an existing player's name. + // This is problematic for online-mode servers as they always disconnect old clients. + if (plugin.getProxy().getConfig().isOnlineMode()) { + ProxiedPlayer player = plugin.getProxy().getPlayer(event.getConnection().getName()); - if (player == null) { - String online = jedis.hget("player:" + event.getConnection().getUniqueId().toString(), "online"); - - if (online != null && online.equals("0")) { + if (player != null) { event.setCancelled(true); // TODO: Make it accept a BaseComponent[] like everything else. - event.setCancelReason(TextComponent.toLegacyText(ALREADY_LOGGED_IN)); + event.setCancelReason(TextComponent.toLegacyText(ONLINE_MODE_RECONNECT)); event.completeIntent(plugin); return null; } } + String online = jedis.hget("player:" + event.getConnection().getUniqueId().toString(), "online"); + + if (online != null && online.equals("0")) { + event.setCancelled(true); + // TODO: Make it accept a BaseComponent[] like everything else. + event.setCancelReason(TextComponent.toLegacyText(ALREADY_LOGGED_IN)); + event.completeIntent(plugin); + return null; + } + Map playerData = new HashMap<>(4); playerData.put("online", "0"); playerData.put("ip", event.getConnection().getAddress().getAddress().getHostAddress());