2
0
mirror of https://github.com/proxiodev/RedisBungee.git synced 2024-12-23 10:38:01 +00:00

Switch getPlayersOnServer() to use server-to-players multimap

This is now safe to do since the multimap is now cached. May fix #39
This commit is contained in:
Tux 2016-06-25 02:19:23 -04:00
parent f6412b7517
commit 821a41c1a9
3 changed files with 2 additions and 46 deletions

View File

@ -67,7 +67,6 @@ public final class RedisBungee extends Plugin {
private boolean usingLua;
private LuaManager.Script serverToPlayersScript;
private LuaManager.Script getPlayerCountScript;
private LuaManager.Script getServerPlayersScript;
private static final Object SERVER_TO_PLAYERS_KEY = new Object();
private final Cache<Object, Multimap<String, UUID>> serverToPlayersCache = CacheBuilder.newBuilder()
@ -205,16 +204,6 @@ public final class RedisBungee extends Plugin {
return setBuilder.build();
}
final Set<UUID> getPlayersOnServer(@NonNull String server) {
checkArgument(getProxy().getServers().containsKey(server), "server does not exist");
Collection<String> asStrings = (Collection<String>) getServerPlayersScript.eval(ImmutableList.<String>of(), ImmutableList.<String>of(server));
ImmutableSet.Builder<UUID> builder = ImmutableSet.builder();
for (String s : asStrings) {
builder.add(UUID.fromString(s));
}
return builder.build();
}
final void sendProxyCommand(@NonNull String proxyId, @NonNull String command) {
checkArgument(getServerIds().contains(proxyId) || proxyId.equals("allservers"), "proxyId is invalid");
sendChannelMessage("redisbungee-" + proxyId, command);
@ -258,7 +247,6 @@ public final class RedisBungee extends Plugin {
LuaManager manager = new LuaManager(this);
serverToPlayersScript = manager.createScript(IOUtil.readInputStreamAsString(getResourceAsStream("lua/server_to_players.lua")));
getPlayerCountScript = manager.createScript(IOUtil.readInputStreamAsString(getResourceAsStream("lua/get_player_count.lua")));
getServerPlayersScript = manager.createScript(IOUtil.readInputStreamAsString(getResourceAsStream("lua/get_server_players.lua")));
}
break;
}

View File

@ -2,6 +2,7 @@ package com.imaginarycode.minecraft.redisbungee;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Multimap;
import lombok.NonNull;
import net.md_5.bungee.api.config.ServerInfo;
@ -103,7 +104,7 @@ public class RedisBungeeAPI {
* @return a Set with all players found on this server
*/
public final Set<UUID> getPlayersOnServer(@NonNull String server) {
return plugin.getPlayersOnServer(server);
return ImmutableSet.copyOf(getServerToPlayers().get(server));
}
/**

View File

@ -1,33 +0,0 @@
local c = redis.call
local u = string.upper
local curTime = c("TIME")
local time = tonumber(curTime[1])
local heartbeats = c("HGETALL", "heartbeats")
local all = {}
local key
local preUppercased = u(ARGV[1])
for _, v in ipairs(heartbeats) do
if not key then
key = v
else
local n = tonumber(v)
if n then
if n + 30 >= time then
local players = c("SMEMBERS", "proxy:" .. key .. ":usersOnline")
for _, player in ipairs(players) do
local server = c("HGET", "player:" .. player, "server")
if server and u(server) == preUppercased then
all[#all + 1] = player
end
end
end
end
key = nil
end
end
return all