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

more try-with-resources.

This commit is contained in:
Tux 2015-06-06 16:39:10 -04:00
parent 86efdeaf8e
commit 665d73af0c

View File

@ -42,32 +42,29 @@ public class RedisBungeeListener implements Listener {
@EventHandler @EventHandler
public void onPlayerConnect(final PostLoginEvent event) { public void onPlayerConnect(final PostLoginEvent event) {
Jedis rsc = plugin.getPool().getResource(); try (Jedis rsc = plugin.getPool().getResource()) {
try {
for (String server : plugin.getServerIds()) { for (String server : plugin.getServerIds()) {
if (rsc.sismember("proxy:" + server + ":usersOnline", event.getPlayer().getUniqueId().toString())) { if (rsc.sismember("proxy:" + server + ":usersOnline", event.getPlayer().getUniqueId().toString())) {
event.getPlayer().disconnect(ALREADY_LOGGED_IN); event.getPlayer().disconnect(ALREADY_LOGGED_IN);
return; return;
} }
} }
plugin.getService().submit(new RedisCallable<Void>(plugin) {
@Override
protected Void call(Jedis jedis) {
jedis.sadd("proxy:" + RedisBungee.getApi().getServerId() + ":usersOnline", event.getPlayer().getUniqueId().toString());
jedis.hset("player:" + event.getPlayer().getUniqueId().toString(), "online", "0");
jedis.hset("player:" + event.getPlayer().getUniqueId().toString(), "ip", event.getPlayer().getAddress().getAddress().getHostAddress());
plugin.getUuidTranslator().persistInfo(event.getPlayer().getName(), event.getPlayer().getUniqueId(), jedis);
jedis.hset("player:" + event.getPlayer().getUniqueId().toString(), "proxy", RedisBungee.getConfiguration().getServerId());
jedis.publish("redisbungee-data", RedisBungee.getGson().toJson(new DataManager.DataManagerMessage<>(
event.getPlayer().getUniqueId(), DataManager.DataManagerMessage.Action.JOIN,
new DataManager.LoginPayload(event.getPlayer().getAddress().getAddress()))));
return null;
}
});
} finally {
plugin.getPool().returnResource(rsc);
} }
plugin.getService().submit(new RedisCallable<Void>(plugin) {
@Override
protected Void call(Jedis jedis) {
jedis.sadd("proxy:" + RedisBungee.getApi().getServerId() + ":usersOnline", event.getPlayer().getUniqueId().toString());
jedis.hset("player:" + event.getPlayer().getUniqueId().toString(), "online", "0");
jedis.hset("player:" + event.getPlayer().getUniqueId().toString(), "ip", event.getPlayer().getAddress().getAddress().getHostAddress());
plugin.getUuidTranslator().persistInfo(event.getPlayer().getName(), event.getPlayer().getUniqueId(), jedis);
jedis.hset("player:" + event.getPlayer().getUniqueId().toString(), "proxy", RedisBungee.getConfiguration().getServerId());
jedis.publish("redisbungee-data", RedisBungee.getGson().toJson(new DataManager.DataManagerMessage<>(
event.getPlayer().getUniqueId(), DataManager.DataManagerMessage.Action.JOIN,
new DataManager.LoginPayload(event.getPlayer().getAddress().getAddress()))));
return null;
}
});
} }
@EventHandler @EventHandler