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

Better support Redis on ports other than 6379. Also improve the anti-clone.

This commit is contained in:
Tux 2013-12-02 22:02:55 -05:00
parent 7ff324c6d8
commit 70c3f5fcdc
2 changed files with 12 additions and 1 deletions

View File

@ -39,6 +39,7 @@ 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;
@ -208,10 +209,15 @@ public class RedisBungee extends Plugin implements Listener {
} }
String redisServer = "localhost"; String redisServer = "localhost";
int redisPort = 6379;
try { try {
redisServer = ((String) rawYaml.get("redis-server")); redisServer = ((String) rawYaml.get("redis-server"));
} catch (NullPointerException ignored) { } catch (NullPointerException ignored) {
} }
try {
redisPort = ((Integer) rawYaml.get("redis-port"));
} catch (NullPointerException ignored) {
}
try { try {
configuration.setServerId((String) rawYaml.get("server-id")); configuration.setServerId((String) rawYaml.get("server-id"));
} catch (NullPointerException ignored) { } catch (NullPointerException ignored) {
@ -238,7 +244,7 @@ public class RedisBungee extends Plugin implements Listener {
if (redisServer != null) { if (redisServer != null) {
if (!redisServer.equals("")) { if (!redisServer.equals("")) {
pool = new JedisPool(new JedisPoolConfig(), redisServer); pool = new JedisPool(new JedisPoolConfig(), redisServer, redisPort);
} }
} }
} }
@ -248,6 +254,7 @@ public class RedisBungee extends Plugin implements Listener {
Jedis rsc = pool.getResource(); Jedis rsc = pool.getResource();
try { try {
if (rsc.hexists("player:" + event.getPlayer().getName(), "server")) { if (rsc.hexists("player:" + event.getPlayer().getName(), "server")) {
forcefullyKicked.add(event.getPlayer().getName());
event.getPlayer().disconnect("You are already logged on this server."); event.getPlayer().disconnect("You are already logged on this server.");
} else { } else {
rsc.sadd("server:" + configuration.getServerId() + ":usersOnline", event.getPlayer().getName()); rsc.sadd("server:" + configuration.getServerId() + ":usersOnline", event.getPlayer().getName());
@ -263,6 +270,9 @@ 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()))
return;
if (pool != null) { if (pool != null) {
Jedis rsc = pool.getResource(); Jedis rsc = pool.getResource();
try { try {

View File

@ -1,6 +1,7 @@
# The Redis server you use. # The Redis server you use.
# Get Redis from http://redis.io/ # Get Redis from http://redis.io/
redis-server: 127.0.0.1 redis-server: 127.0.0.1
redis-port: 6379
# An identifier for this BungeeCord instance. # An identifier for this BungeeCord instance.
server-id: iluvbungee server-id: iluvbungee