mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2024-11-23 04:28:01 +00:00
make async pls, also add back the server list ping player structure back as an option
This commit is contained in:
parent
22a4d0332d
commit
c393f4c553
@ -6,7 +6,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.imaginarycode.minecraft.redisbungee;
|
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 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;
|
||||||
@ -82,11 +83,7 @@ public class RedisBungee extends Plugin implements Listener {
|
|||||||
try {
|
try {
|
||||||
for (String i : getConfiguration().getLinkedServers()) {
|
for (String i : getConfiguration().getLinkedServers()) {
|
||||||
if (i.equals(configuration.getServerId())) continue;
|
if (i.equals(configuration.getServerId())) continue;
|
||||||
for (String p : rsc.smembers("server:" + i + ":usersOnline")) {
|
players.addAll(rsc.smembers("server:" + i + ":usersOnline"));
|
||||||
if (!players.contains(p)) {
|
|
||||||
players.add(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
pool.returnResource(rsc);
|
pool.returnResource(rsc);
|
||||||
@ -141,9 +138,7 @@ public class RedisBungee extends Plugin implements Listener {
|
|||||||
Jedis tmpRsc = pool.getResource();
|
Jedis tmpRsc = pool.getResource();
|
||||||
try {
|
try {
|
||||||
tmpRsc.set("server:" + configuration.getServerId() + ":playerCount", "0"); // reset
|
tmpRsc.set("server:" + configuration.getServerId() + ":playerCount", "0"); // reset
|
||||||
for (String i : tmpRsc.smembers("server:" + configuration.getServerId() + ":usersOnline")) {
|
tmpRsc.srem("server:" + configuration.getServerId() + ":usersOnline", (String[]) tmpRsc.smembers("server:" + configuration.getServerId() + ":usersOnline").toArray());
|
||||||
tmpRsc.srem("server:" + configuration.getServerId() + ":usersOnline", i);
|
|
||||||
}
|
|
||||||
} finally {
|
} finally {
|
||||||
pool.returnResource(tmpRsc);
|
pool.returnResource(tmpRsc);
|
||||||
}
|
}
|
||||||
@ -177,9 +172,7 @@ public class RedisBungee extends Plugin implements Listener {
|
|||||||
Jedis tmpRsc = pool.getResource();
|
Jedis tmpRsc = pool.getResource();
|
||||||
try {
|
try {
|
||||||
tmpRsc.set("server:" + configuration.getServerId() + ":playerCount", "0"); // reset
|
tmpRsc.set("server:" + configuration.getServerId() + ":playerCount", "0"); // reset
|
||||||
for (String i : tmpRsc.smembers("server:" + configuration.getServerId() + ":usersOnline")) {
|
tmpRsc.srem("server:" + configuration.getServerId() + ":usersOnline", (String[]) tmpRsc.smembers("server:" + configuration.getServerId() + ":usersOnline").toArray());
|
||||||
tmpRsc.srem("server:" + configuration.getServerId() + ":usersOnline", i);
|
|
||||||
}
|
|
||||||
} catch (JedisException | ClassCastException ignored) {
|
} catch (JedisException | ClassCastException ignored) {
|
||||||
} finally {
|
} finally {
|
||||||
pool.returnResource(tmpRsc);
|
pool.returnResource(tmpRsc);
|
||||||
@ -223,6 +216,10 @@ public class RedisBungee extends Plugin implements Listener {
|
|||||||
configuration.setCanonicalGlist((Boolean) rawYaml.get("canonical-glist"));
|
configuration.setCanonicalGlist((Boolean) rawYaml.get("canonical-glist"));
|
||||||
} catch (NullPointerException ignored) {
|
} catch (NullPointerException ignored) {
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
configuration.setPlayerListInPing(((Boolean) rawYaml.get("player-list-in-ping")));
|
||||||
|
} catch (NullPointerException ignored) {
|
||||||
|
}
|
||||||
List<?> tmp = (List<?>) rawYaml.get("linked-servers");
|
List<?> tmp = (List<?>) rawYaml.get("linked-servers");
|
||||||
|
|
||||||
List<String> servers = new ArrayList<>();
|
List<String> servers = new ArrayList<>();
|
||||||
@ -244,51 +241,77 @@ public class RedisBungee extends Plugin implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerConnect(final PostLoginEvent event) {
|
public void onPlayerConnect(final PostLoginEvent event) {
|
||||||
if (pool != null) {
|
getProxy().getScheduler().runAsync(this, new Runnable() {
|
||||||
Jedis rsc = pool.getResource();
|
@Override
|
||||||
try {
|
public void run() {
|
||||||
rsc.sadd("server:" + configuration.getServerId() + ":usersOnline", event.getPlayer().getName());
|
if (pool != null) {
|
||||||
rsc.hset("player:" + event.getPlayer().getName(), "online", "0");
|
Jedis rsc = pool.getResource();
|
||||||
} finally {
|
try {
|
||||||
pool.returnResource(rsc);
|
rsc.sadd("server:" + configuration.getServerId() + ":usersOnline", event.getPlayer().getName());
|
||||||
|
rsc.hset("player:" + event.getPlayer().getName(), "online", "0");
|
||||||
|
} finally {
|
||||||
|
pool.returnResource(rsc);
|
||||||
|
}
|
||||||
|
// I used to have a task that eagerly waited for the user to be connected.
|
||||||
|
// Well, upon further inspection of BungeeCord's source code, this turned
|
||||||
|
// out to not be needed at all, since ServerConnectedEvent is called anyway.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// I used to have a task that eagerly waited for the user to be connected.
|
});
|
||||||
// Well, upon further inspection of BungeeCord's source code, this turned
|
|
||||||
// out to not be needed at all, since ServerConnectedEvent is called anyway.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerDisconnect(PlayerDisconnectEvent event) {
|
public void onPlayerDisconnect(final PlayerDisconnectEvent event) {
|
||||||
if (pool != null) {
|
getProxy().getScheduler().runAsync(this, new Runnable() {
|
||||||
Jedis rsc = pool.getResource();
|
@Override
|
||||||
try {
|
public void run() {
|
||||||
rsc.srem("server:" + configuration.getServerId() + ":usersOnline", event.getPlayer().getName());
|
if (pool != null) {
|
||||||
rsc.hset("player:" + event.getPlayer().getName(), "online", String.valueOf(getUnixTimestamp()));
|
Jedis rsc = pool.getResource();
|
||||||
rsc.hdel("player:" + event.getPlayer().getName(), "server");
|
try {
|
||||||
} finally {
|
rsc.srem("server:" + configuration.getServerId() + ":usersOnline", event.getPlayer().getName());
|
||||||
pool.returnResource(rsc);
|
rsc.hset("player:" + event.getPlayer().getName(), "online", String.valueOf(getUnixTimestamp()));
|
||||||
|
rsc.hdel("player:" + event.getPlayer().getName(), "server");
|
||||||
|
} finally {
|
||||||
|
pool.returnResource(rsc);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onServerChange(ServerConnectedEvent event) {
|
public void onServerChange(final ServerConnectedEvent event) {
|
||||||
if (pool != null) {
|
getProxy().getScheduler().runAsync(this, new Runnable() {
|
||||||
Jedis rsc = pool.getResource();
|
@Override
|
||||||
try {
|
public void run() {
|
||||||
rsc.hset("player:" + event.getPlayer().getName(), "server", event.getServer().getInfo().getName());
|
if (pool != null) {
|
||||||
} finally {
|
Jedis rsc = pool.getResource();
|
||||||
pool.returnResource(rsc);
|
try {
|
||||||
|
rsc.hset("player:" + event.getPlayer().getName(), "server", event.getServer().getInfo().getName());
|
||||||
|
} finally {
|
||||||
|
pool.returnResource(rsc);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPing(ProxyPingEvent event) {
|
public void onPing(ProxyPingEvent event) {
|
||||||
ServerPing old = event.getResponse();
|
ServerPing old = event.getResponse();
|
||||||
ServerPing reply = new ServerPing();
|
ServerPing reply = new ServerPing();
|
||||||
reply.setPlayers(new ServerPing.Players(old.getPlayers().getMax(), getCount(), EMPTY_PLAYERINFO));
|
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.setDescription(old.getDescription());
|
||||||
reply.setFavicon(old.getFavicon());
|
reply.setFavicon(old.getFavicon());
|
||||||
reply.setVersion(old.getVersion());
|
reply.setVersion(old.getVersion());
|
||||||
|
@ -24,5 +24,6 @@ import java.util.List;
|
|||||||
public class RedisBungeeConfiguration {
|
public class RedisBungeeConfiguration {
|
||||||
private String serverId = "iluvbungee";
|
private String serverId = "iluvbungee";
|
||||||
private boolean canonicalGlist = true;
|
private boolean canonicalGlist = true;
|
||||||
|
private boolean playerListInPing = false;
|
||||||
private List<String> linkedServers = Collections.emptyList();
|
private List<String> linkedServers = Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,9 @@ server-id: iluvbungee
|
|||||||
# Whether or not /glist showall output should match vanilla BungeeCord.
|
# Whether or not /glist showall output should match vanilla BungeeCord.
|
||||||
canonical-glist: true
|
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.
|
# All other RedisBungee server IDs in the network.
|
||||||
linked-servers:
|
linked-servers:
|
||||||
- dastank
|
- dastank
|
||||||
|
Loading…
Reference in New Issue
Block a user