2
0
mirror of https://github.com/proxiodev/RedisBungee.git synced 2024-11-23 04:28:01 +00:00

Fix multiple players online on one proxy.

This commit is contained in:
Tux 2014-05-25 18:16:14 -04:00
parent dd4a33d9d4
commit dea8073b11

View File

@ -15,7 +15,9 @@ import com.imaginarycode.minecraft.redisbungee.consumerevents.PlayerLoggedInCons
import com.imaginarycode.minecraft.redisbungee.consumerevents.PlayerLoggedOffConsumerEvent; import com.imaginarycode.minecraft.redisbungee.consumerevents.PlayerLoggedOffConsumerEvent;
import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent; import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.ServerPing; import net.md_5.bungee.api.ServerPing;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.connection.Server; import net.md_5.bungee.api.connection.Server;
import net.md_5.bungee.api.event.*; import net.md_5.bungee.api.event.*;
import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.api.plugin.Listener;
@ -29,25 +31,21 @@ public class RedisBungeeListener implements Listener {
private final RedisBungee plugin; private final RedisBungee plugin;
@EventHandler @EventHandler
public void onPreLogin(PreLoginEvent event) { public void onPlayerConnect(final PostLoginEvent event) {
if (plugin.getPool() != null) { if (plugin.getPool() != null) {
Jedis rsc = plugin.getPool().getResource(); Jedis rsc = plugin.getPool().getResource();
try { try {
for (String server : plugin.getServerIds()) { for (String server : plugin.getServerIds()) {
if (rsc.sismember("server:" + server + ":usersOnline", event.getConnection().getName())) { if (rsc.sismember("server:" + server + ":usersOnline", event.getPlayer().getUniqueId().toString())) {
event.setCancelled(true); event.getPlayer().disconnect(new ComponentBuilder("You are already logged on to this server.").color(
event.setCancelReason("You are already logged on to this server."); ChatColor.RED).create());
break; return;
} }
} }
} finally { } finally {
plugin.getPool().returnResource(rsc); plugin.getPool().returnResource(rsc);
} }
} }
}
@EventHandler
public void onPlayerConnect(final PostLoginEvent event) {
plugin.getConsumer().queue(new PlayerLoggedInConsumerEvent(event.getPlayer())); plugin.getConsumer().queue(new PlayerLoggedInConsumerEvent(event.getPlayer()));
} }