blob: 957927e1ba5e0e0619774747b439b137dcb49440 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
package com.keuin.crosslink.plugin.bungee;
import com.google.inject.Inject;
import com.keuin.crosslink.config.GlobalConfigManager;
import com.keuin.crosslink.data.PlayerInfo;
import com.keuin.crosslink.data.ServerInfo;
import com.keuin.crosslink.messaging.endpoint.IEndpoint;
import com.keuin.crosslink.messaging.endpoint.local.BungeeServerChatEndpoint;
import com.keuin.crosslink.plugin.bungee.checker.BungeeServerStatusChecker;
import com.keuin.crosslink.plugin.common.ICoreAccessor;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.function.Consumer;
import java.util.stream.Collectors;
public class BungeeAccessor implements ICoreAccessor {
private final BungeeMainWrapper plugin;
@Inject
public BungeeAccessor(BungeeMainWrapper plugin) {
this.plugin = plugin;
}
@Override
public List<PlayerInfo> getOnlinePlayers() {
var players = plugin.getProxy().getPlayers();
return players.stream().map(PlayerInfo::fromBungeePlayer).toList();
}
@Override
public List<PlayerInfo> getOnlinePlayers(String serverName) {
Objects.requireNonNull(serverName);
return getOnlinePlayers().stream().filter((player) -> serverName.equals(player.serverName())).toList();
}
@Override
public void getServerInfo(Consumer<List<ServerInfo>> callback) {
var checker = new BungeeServerStatusChecker(
plugin.getProxy().getServers().values(),
plugin,
GlobalConfigManager.getInstance().getConfig().pingTimeoutMillis()
);
checker.ping((infoMap) -> callback.accept(infoMap.entrySet().stream().map(
(ent) -> new ServerInfo(ent.getKey().getName(), ent.getValue())
).toList()));
}
@Override
public Set<IEndpoint> getServerEndpoints() {
return plugin.getProxy().getServers().values().stream()
.map((si) -> new BungeeServerChatEndpoint(si, plugin.getProxy(), plugin))
.collect(Collectors.toUnmodifiableSet());
}
}
|