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,6 +241,9 @@ public class RedisBungee extends Plugin implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerConnect(final PostLoginEvent event) {
|
public void onPlayerConnect(final PostLoginEvent event) {
|
||||||
|
getProxy().getScheduler().runAsync(this, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
if (pool != null) {
|
if (pool != null) {
|
||||||
Jedis rsc = pool.getResource();
|
Jedis rsc = pool.getResource();
|
||||||
try {
|
try {
|
||||||
@ -257,9 +257,14 @@ public class RedisBungee extends Plugin implements Listener {
|
|||||||
// out to not be needed at all, since ServerConnectedEvent is called anyway.
|
// 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) {
|
||||||
|
getProxy().getScheduler().runAsync(this, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
if (pool != null) {
|
if (pool != null) {
|
||||||
Jedis rsc = pool.getResource();
|
Jedis rsc = pool.getResource();
|
||||||
try {
|
try {
|
||||||
@ -271,9 +276,14 @@ public class RedisBungee extends Plugin implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@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) {
|
if (pool != null) {
|
||||||
Jedis rsc = pool.getResource();
|
Jedis rsc = pool.getResource();
|
||||||
try {
|
try {
|
||||||
@ -283,12 +293,25 @@ public class RedisBungee extends Plugin implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@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();
|
||||||
|
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.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