mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2024-11-23 04:28: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:
parent
f6412b7517
commit
821a41c1a9
@ -67,7 +67,6 @@ public final class RedisBungee extends Plugin {
|
|||||||
private boolean usingLua;
|
private boolean usingLua;
|
||||||
private LuaManager.Script serverToPlayersScript;
|
private LuaManager.Script serverToPlayersScript;
|
||||||
private LuaManager.Script getPlayerCountScript;
|
private LuaManager.Script getPlayerCountScript;
|
||||||
private LuaManager.Script getServerPlayersScript;
|
|
||||||
|
|
||||||
private static final Object SERVER_TO_PLAYERS_KEY = new Object();
|
private static final Object SERVER_TO_PLAYERS_KEY = new Object();
|
||||||
private final Cache<Object, Multimap<String, UUID>> serverToPlayersCache = CacheBuilder.newBuilder()
|
private final Cache<Object, Multimap<String, UUID>> serverToPlayersCache = CacheBuilder.newBuilder()
|
||||||
@ -205,16 +204,6 @@ public final class RedisBungee extends Plugin {
|
|||||||
return setBuilder.build();
|
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) {
|
final void sendProxyCommand(@NonNull String proxyId, @NonNull String command) {
|
||||||
checkArgument(getServerIds().contains(proxyId) || proxyId.equals("allservers"), "proxyId is invalid");
|
checkArgument(getServerIds().contains(proxyId) || proxyId.equals("allservers"), "proxyId is invalid");
|
||||||
sendChannelMessage("redisbungee-" + proxyId, command);
|
sendChannelMessage("redisbungee-" + proxyId, command);
|
||||||
@ -258,7 +247,6 @@ public final class RedisBungee extends Plugin {
|
|||||||
LuaManager manager = new LuaManager(this);
|
LuaManager manager = new LuaManager(this);
|
||||||
serverToPlayersScript = manager.createScript(IOUtil.readInputStreamAsString(getResourceAsStream("lua/server_to_players.lua")));
|
serverToPlayersScript = manager.createScript(IOUtil.readInputStreamAsString(getResourceAsStream("lua/server_to_players.lua")));
|
||||||
getPlayerCountScript = manager.createScript(IOUtil.readInputStreamAsString(getResourceAsStream("lua/get_player_count.lua")));
|
getPlayerCountScript = manager.createScript(IOUtil.readInputStreamAsString(getResourceAsStream("lua/get_player_count.lua")));
|
||||||
getServerPlayersScript = manager.createScript(IOUtil.readInputStreamAsString(getResourceAsStream("lua/get_server_players.lua")));
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package com.imaginarycode.minecraft.redisbungee;
|
|||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
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
|
* @return a Set with all players found on this server
|
||||||
*/
|
*/
|
||||||
public final Set<UUID> getPlayersOnServer(@NonNull String server) {
|
public final Set<UUID> getPlayersOnServer(@NonNull String server) {
|
||||||
return plugin.getPlayersOnServer(server);
|
return ImmutableSet.copyOf(getServerToPlayers().get(server));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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
|
|
Loading…
Reference in New Issue
Block a user