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

make async pls, also add back the server list ping player structure back as an option

This commit is contained in:
Tux 2013-11-15 21:56:59 -05:00
parent 22a4d0332d
commit c393f4c553
3 changed files with 69 additions and 42 deletions

View File

@ -6,7 +6,8 @@
*/
package com.imaginarycode.minecraft.redisbungee;
import com.google.common.collect.*;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.io.ByteStreams;
import net.md_5.bungee.api.ServerPing;
import net.md_5.bungee.api.config.ServerInfo;
@ -82,11 +83,7 @@ public class RedisBungee extends Plugin implements Listener {
try {
for (String i : getConfiguration().getLinkedServers()) {
if (i.equals(configuration.getServerId())) continue;
for (String p : rsc.smembers("server:" + i + ":usersOnline")) {
if (!players.contains(p)) {
players.add(p);
}
}
players.addAll(rsc.smembers("server:" + i + ":usersOnline"));
}
} finally {
pool.returnResource(rsc);
@ -141,9 +138,7 @@ public class RedisBungee extends Plugin implements Listener {
Jedis tmpRsc = pool.getResource();
try {
tmpRsc.set("server:" + configuration.getServerId() + ":playerCount", "0"); // reset
for (String i : tmpRsc.smembers("server:" + configuration.getServerId() + ":usersOnline")) {
tmpRsc.srem("server:" + configuration.getServerId() + ":usersOnline", i);
}
tmpRsc.srem("server:" + configuration.getServerId() + ":usersOnline", (String[]) tmpRsc.smembers("server:" + configuration.getServerId() + ":usersOnline").toArray());
} finally {
pool.returnResource(tmpRsc);
}
@ -177,9 +172,7 @@ public class RedisBungee extends Plugin implements Listener {
Jedis tmpRsc = pool.getResource();
try {
tmpRsc.set("server:" + configuration.getServerId() + ":playerCount", "0"); // reset
for (String i : tmpRsc.smembers("server:" + configuration.getServerId() + ":usersOnline")) {
tmpRsc.srem("server:" + configuration.getServerId() + ":usersOnline", i);
}
tmpRsc.srem("server:" + configuration.getServerId() + ":usersOnline", (String[]) tmpRsc.smembers("server:" + configuration.getServerId() + ":usersOnline").toArray());
} catch (JedisException | ClassCastException ignored) {
} finally {
pool.returnResource(tmpRsc);
@ -223,6 +216,10 @@ public class RedisBungee extends Plugin implements Listener {
configuration.setCanonicalGlist((Boolean) rawYaml.get("canonical-glist"));
} catch (NullPointerException ignored) {
}
try {
configuration.setPlayerListInPing(((Boolean) rawYaml.get("player-list-in-ping")));
} catch (NullPointerException ignored) {
}
List<?> tmp = (List<?>) rawYaml.get("linked-servers");
List<String> servers = new ArrayList<>();
@ -244,6 +241,9 @@ public class RedisBungee extends Plugin implements Listener {
@EventHandler
public void onPlayerConnect(final PostLoginEvent event) {
getProxy().getScheduler().runAsync(this, new Runnable() {
@Override
public void run() {
if (pool != null) {
Jedis rsc = pool.getResource();
try {
@ -257,9 +257,14 @@ public class RedisBungee extends Plugin implements Listener {
// out to not be needed at all, since ServerConnectedEvent is called anyway.
}
}
});
}
@EventHandler
public void onPlayerDisconnect(PlayerDisconnectEvent event) {
public void onPlayerDisconnect(final PlayerDisconnectEvent event) {
getProxy().getScheduler().runAsync(this, new Runnable() {
@Override
public void run() {
if (pool != null) {
Jedis rsc = pool.getResource();
try {
@ -271,9 +276,14 @@ public class RedisBungee extends Plugin implements Listener {
}
}
}
});
}
@EventHandler
public void onServerChange(ServerConnectedEvent event) {
public void onServerChange(final ServerConnectedEvent event) {
getProxy().getScheduler().runAsync(this, new Runnable() {
@Override
public void run() {
if (pool != null) {
Jedis rsc = pool.getResource();
try {
@ -283,12 +293,25 @@ public class RedisBungee extends Plugin implements Listener {
}
}
}
});
}
@EventHandler
public void onPing(ProxyPingEvent event) {
ServerPing old = event.getResponse();
ServerPing reply = new ServerPing();
if (configuration.isPlayerListInPing()) {
Set<String> players = getPlayers();
ServerPing.PlayerInfo[] info = new ServerPing.PlayerInfo[players.size()];
int idx = 0;
for (String player : players) {
info[idx] = new ServerPing.PlayerInfo(player, "");
idx++;
}
reply.setPlayers(new ServerPing.Players(old.getPlayers().getMax(), players.size(), info));
} else {
reply.setPlayers(new ServerPing.Players(old.getPlayers().getMax(), getCount(), EMPTY_PLAYERINFO));
}
reply.setDescription(old.getDescription());
reply.setFavicon(old.getFavicon());
reply.setVersion(old.getVersion());

View File

@ -24,5 +24,6 @@ import java.util.List;
public class RedisBungeeConfiguration {
private String serverId = "iluvbungee";
private boolean canonicalGlist = true;
private boolean playerListInPing = false;
private List<String> linkedServers = Collections.emptyList();
}

View File

@ -8,6 +8,9 @@ server-id: iluvbungee
# Whether or not /glist showall output should match vanilla BungeeCord.
canonical-glist: true
# Output all players in the server list. Recommended only for smaller networks.
player-list-in-ping: false
# All other RedisBungee server IDs in the network.
linked-servers:
- dastank