Added Registered player counts per servers

This commit is contained in:
Rsl1122 2018-10-25 10:32:58 +03:00
parent 1bb75299ff
commit b7595b12e8
5 changed files with 44 additions and 6 deletions

View File

@ -85,16 +85,21 @@ public class NetworkContainer extends DataContainer {
putSupplier(NetworkKeys.NETWORK_PLAYER_ONLINE_DATA, () -> dbSystem.getDatabase().fetch().getPlayersOnlineForServers( putSupplier(NetworkKeys.NETWORK_PLAYER_ONLINE_DATA, () -> dbSystem.getDatabase().fetch().getPlayersOnlineForServers(
getValue(NetworkKeys.BUKKIT_SERVERS).orElse(new ArrayList<>())) getValue(NetworkKeys.BUKKIT_SERVERS).orElse(new ArrayList<>()))
); );
putSupplier(NetworkKeys.SERVER_REGISTER_DATA, () -> dbSystem.getDatabase().fetch().getPlayersRegisteredForServers(
getValue(NetworkKeys.BUKKIT_SERVERS).orElse(new ArrayList<>()))
);
putSupplier(NetworkKeys.SERVERS_TAB, () -> { putSupplier(NetworkKeys.SERVERS_TAB, () -> {
StringBuilder serverBoxes = new StringBuilder(); StringBuilder serverBoxes = new StringBuilder();
Map<Integer, List<TPS>> playersOnlineData = getValue(NetworkKeys.NETWORK_PLAYER_ONLINE_DATA).orElse(new HashMap<>()); Map<Integer, List<TPS>> playersOnlineData = getValue(NetworkKeys.NETWORK_PLAYER_ONLINE_DATA).orElse(new HashMap<>());
Map<Integer, Integer> registerData = getValue(NetworkKeys.SERVER_REGISTER_DATA).orElse(new HashMap<>());
getValue(NetworkKeys.BUKKIT_SERVERS).orElse(new ArrayList<>()) getValue(NetworkKeys.BUKKIT_SERVERS).orElse(new ArrayList<>())
.stream() .stream()
.sorted((one, two) -> String.CASE_INSENSITIVE_ORDER.compare(one.getName(), two.getName())) .sorted((one, two) -> String.CASE_INSENSITIVE_ORDER.compare(one.getName(), two.getName()))
.forEach(server -> { .forEach(server -> {
TPSMutator tpsMutator = new TPSMutator(playersOnlineData.getOrDefault(server.getId(), new ArrayList<>())); int serverId = server.getId();
// TODO Add Registered players per server. TPSMutator tpsMutator = new TPSMutator(playersOnlineData.getOrDefault(serverId, new ArrayList<>()));
NetworkServerBox serverBox = new NetworkServerBox(server, 0, tpsMutator, graphs); int registered = registerData.getOrDefault(serverId, 0);
NetworkServerBox serverBox = new NetworkServerBox(server, registered, tpsMutator, graphs);
serverBoxes.append(serverBox.toHtml()); serverBoxes.append(serverBox.toHtml());
}); });
return serverBoxes.toString(); return serverBoxes.toString();

View File

@ -58,6 +58,7 @@ public class NetworkKeys {
public static final Key<Collection<Server>> BUKKIT_SERVERS = new Key<>(new Type<Collection<Server>>() {}, "BUKKIT_SERVERS"); public static final Key<Collection<Server>> BUKKIT_SERVERS = new Key<>(new Type<Collection<Server>>() {}, "BUKKIT_SERVERS");
public static final Key<TreeMap<Long, Map<String, Set<UUID>>>> ACTIVITY_DATA = CommonKeys.ACTIVITY_DATA; public static final Key<TreeMap<Long, Map<String, Set<UUID>>>> ACTIVITY_DATA = CommonKeys.ACTIVITY_DATA;
public static final Key<Map<Integer, List<TPS>>> NETWORK_PLAYER_ONLINE_DATA = new Key<>(new Type<Map<Integer, List<TPS>>>() {}, "NETWORK_PLAYER_ONLINE_DATA"); public static final Key<Map<Integer, List<TPS>>> NETWORK_PLAYER_ONLINE_DATA = new Key<>(new Type<Map<Integer, List<TPS>>>() {}, "NETWORK_PLAYER_ONLINE_DATA");
public static final Key<Map<Integer, Integer>> SERVER_REGISTER_DATA = new Key<>(new Type<Map<Integer, Integer>>() {}, "SERVER_REGISTER_DATA");
private NetworkKeys() { private NetworkKeys() {
/* static variable class */ /* static variable class */

View File

@ -116,5 +116,7 @@ public interface FetchOperations {
List<UUID> getServerUUIDs(); List<UUID> getServerUUIDs();
Map<Integer, List<TPS>> getPlayersOnlineForServers(Collection<Server> serverUUIDs); Map<Integer, List<TPS>> getPlayersOnlineForServers(Collection<Server> servers);
Map<Integer, Integer> getPlayersRegisteredForServers(Collection<Server> servers);
} }

View File

@ -469,7 +469,12 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
} }
@Override @Override
public Map<Integer, List<TPS>> getPlayersOnlineForServers(Collection<Server> serverUUIDs) { public Map<Integer, List<TPS>> getPlayersOnlineForServers(Collection<Server> servers) {
return tpsTable.getPlayersOnlineForServers(serverUUIDs); return tpsTable.getPlayersOnlineForServers(servers);
}
@Override
public Map<Integer, Integer> getPlayersRegisteredForServers(Collection<Server> servers) {
return userInfoTable.getPlayersRegisteredForServers(servers);
} }
} }

View File

@ -11,6 +11,7 @@ import com.djrapitops.plan.system.database.databases.sql.processing.ExecStatemen
import com.djrapitops.plan.system.database.databases.sql.processing.QueryAllStatement; import com.djrapitops.plan.system.database.databases.sql.processing.QueryAllStatement;
import com.djrapitops.plan.system.database.databases.sql.processing.QueryStatement; import com.djrapitops.plan.system.database.databases.sql.processing.QueryStatement;
import com.djrapitops.plan.system.database.databases.sql.statements.*; import com.djrapitops.plan.system.database.databases.sql.statements.*;
import com.djrapitops.plan.system.info.server.Server;
import com.djrapitops.plugin.utilities.Verify; import com.djrapitops.plugin.utilities.Verify;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
@ -315,6 +316,30 @@ public class UserInfoTable extends UserIDTable {
return isRegistered(player, getServerUUID()); return isRegistered(player, getServerUUID());
} }
public Map<Integer, Integer> getPlayersRegisteredForServers(Collection<Server> servers) {
if (servers.isEmpty()) {
return new HashMap<>();
}
String sql = "SELECT " + Col.SERVER_ID + ", " +
"COUNT(" + Col.REGISTERED + ") AS count " +
"FROM " + tableName +
"GROUP BY " + Col.SERVER_ID;
return query(new QueryAllStatement<Map<Integer, Integer>>(sql, 10000) {
@Override
public Map<Integer, Integer> processResults(ResultSet set) throws SQLException {
Map<Integer, Integer> map = new HashMap<>();
while (set.next()) {
int serverID = set.getInt(Col.SERVER_ID.get());
int count = set.getInt("count");
map.put(serverID, count);
}
return map;
}
});
}
public enum Col implements Column { public enum Col implements Column {
USER_ID(UserIDTable.Col.USER_ID.get()), USER_ID(UserIDTable.Col.USER_ID.get()),
SERVER_ID("server_id"), SERVER_ID("server_id"),