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

Don't half-ass the clone detection.

This commit is contained in:
Tux 2013-12-03 15:39:36 -05:00
parent 89d9981db8
commit 0beae77548

View File

@ -12,10 +12,7 @@ import com.google.common.io.ByteStreams;
import net.md_5.bungee.api.ServerPing; import net.md_5.bungee.api.ServerPing;
import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.PlayerDisconnectEvent; import net.md_5.bungee.api.event.*;
import net.md_5.bungee.api.event.PostLoginEvent;
import net.md_5.bungee.api.event.ProxyPingEvent;
import net.md_5.bungee.api.event.ServerConnectedEvent;
import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.api.plugin.Plugin; import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.event.EventHandler; import net.md_5.bungee.event.EventHandler;
@ -39,7 +36,6 @@ public class RedisBungee extends Plugin implements Listener {
private static final ServerPing.PlayerInfo[] EMPTY_PLAYERINFO = new ServerPing.PlayerInfo[]{}; private static final ServerPing.PlayerInfo[] EMPTY_PLAYERINFO = new ServerPing.PlayerInfo[]{};
private RedisBungeeCommandSender commandSender = new RedisBungeeCommandSender(); private RedisBungeeCommandSender commandSender = new RedisBungeeCommandSender();
private static RedisBungeeConfiguration configuration = new RedisBungeeConfiguration(); private static RedisBungeeConfiguration configuration = new RedisBungeeConfiguration();
private List<String> forcefullyKicked = new ArrayList<>();
private JedisPool pool; private JedisPool pool;
private RedisBungee plugin; private RedisBungee plugin;
private static RedisBungeeAPI api; private static RedisBungeeAPI api;
@ -249,17 +245,25 @@ public class RedisBungee extends Plugin implements Listener {
} }
} }
@EventHandler
public void onPreLogin(PreLoginEvent event) {
Jedis rsc = pool.getResource();
try {
if (rsc.hexists("player:" + event.getConnection().getName(), "server")) {
event.setCancelled(true);
event.setCancelReason("You are already logged on to this server.");
}
} finally {
pool.returnResource(rsc);
}
}
@EventHandler @EventHandler
public void onPlayerConnect(final PostLoginEvent event) { public void onPlayerConnect(final PostLoginEvent event) {
Jedis rsc = pool.getResource(); Jedis rsc = pool.getResource();
try { try {
if (rsc.hexists("player:" + event.getPlayer().getName(), "server")) { rsc.sadd("server:" + configuration.getServerId() + ":usersOnline", event.getPlayer().getName());
forcefullyKicked.add(event.getPlayer().getName()); rsc.hset("player:" + event.getPlayer().getName(), "online", "0");
event.getPlayer().disconnect("You are already logged on this server.");
} else {
rsc.sadd("server:" + configuration.getServerId() + ":usersOnline", event.getPlayer().getName());
rsc.hset("player:" + event.getPlayer().getName(), "online", "0");
}
} finally { } finally {
pool.returnResource(rsc); pool.returnResource(rsc);
} }
@ -270,11 +274,6 @@ public class RedisBungee extends Plugin implements Listener {
@EventHandler @EventHandler
public void onPlayerDisconnect(final PlayerDisconnectEvent event) { public void onPlayerDisconnect(final PlayerDisconnectEvent event) {
if (forcefullyKicked.contains(event.getPlayer().getName())) {
forcefullyKicked.remove(event.getPlayer().getName());
return;
}
if (pool != null) { if (pool != null) {
Jedis rsc = pool.getResource(); Jedis rsc = pool.getResource();
try { try {