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

Check the remote player set

This commit is contained in:
vemacs 2014-01-20 08:34:40 -07:00
parent cfd1c20ad7
commit af88046eb3

View File

@ -90,11 +90,15 @@ public final class RedisBungee extends Plugin implements Listener {
return c; return c;
} }
final Set<String> getPlayers() { final Set<String> getLocalPlayers() {
Set<String> players = new HashSet<>(); Set<String> players = new HashSet<>();
for (ProxiedPlayer pp : getProxy().getPlayers()) { for (ProxiedPlayer pp : getProxy().getPlayers())
players.add(pp.getName()); players.add(pp.getName());
} return players;
}
final Set<String> getPlayers() {
Set<String> players = getLocalPlayers();
if (pool != null) { if (pool != null) {
Jedis rsc = pool.getResource(); Jedis rsc = pool.getResource();
try { try {
@ -213,6 +217,19 @@ public final class RedisBungee extends Plugin implements Listener {
api = new RedisBungeeAPI(this); api = new RedisBungeeAPI(this);
psl = new PubSubListener(); psl = new PubSubListener();
new Thread(psl, "RedisBungee PubSub Listener").start(); new Thread(psl, "RedisBungee PubSub Listener").start();
getProxy().getScheduler().schedule(this, new Runnable() {
final Random random = new Random();
final Thread psc = new Thread(new PlayerSetCheck(), "RedisBungee PlayerSetCheck Task");
@Override
public void run() {
try {
Thread.sleep(60000 * (1 + random.nextInt(3)));
psc.start();
} catch (InterruptedException ignored) {
}
}
}, 1, 5, TimeUnit.MINUTES);
} }
} }
@ -447,7 +464,8 @@ public final class RedisBungee extends Plugin implements Listener {
private Jedis rsc; private Jedis rsc;
private JedisPubSubHandler jpsh; private JedisPubSubHandler jpsh;
private PubSubListener() {} private PubSubListener() {
}
@Override @Override
public void run() { public void run() {
@ -498,4 +516,24 @@ public final class RedisBungee extends Plugin implements Listener {
public void onPSubscribe(String s, int i) { public void onPSubscribe(String s, int i) {
} }
} }
private class PlayerSetCheck implements Runnable {
private PlayerSetCheck() {
}
@Override
public void run() {
Jedis tmpRsc = pool.getResource();
try {
Set<String> players = getLocalPlayers();
for (String member : tmpRsc.smembers("server:" + configuration.getString("server-id") + ":usersOnline"))
if (!players.contains(member)) {
cleanUpPlayer(member, tmpRsc);
getLogger().warning("Player found in set that was not found locally: " + member);
}
} finally {
pool.returnResource(tmpRsc);
}
}
}
} }