mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-11-05 10:20:23 +01:00
[Debt] Refactored Server Boxes to network page generation
Some features could not be implemented or will have reduced precision: - Server type - Players Online is deduced from TPS data - Analysis Refresh date is now a true/false based on cache value
This commit is contained in:
parent
add18feb83
commit
7f9146fcf4
@ -1,5 +1,6 @@
|
|||||||
package com.djrapitops.plan.data.store.containers;
|
package com.djrapitops.plan.data.store.containers;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.data.container.TPS;
|
||||||
import com.djrapitops.plan.data.store.Key;
|
import com.djrapitops.plan.data.store.Key;
|
||||||
import com.djrapitops.plan.data.store.keys.NetworkKeys;
|
import com.djrapitops.plan.data.store.keys.NetworkKeys;
|
||||||
import com.djrapitops.plan.data.store.keys.ServerKeys;
|
import com.djrapitops.plan.data.store.keys.ServerKeys;
|
||||||
@ -8,6 +9,7 @@ import com.djrapitops.plan.data.store.mutators.TPSMutator;
|
|||||||
import com.djrapitops.plan.data.store.mutators.health.NetworkHealthInformation;
|
import com.djrapitops.plan.data.store.mutators.health.NetworkHealthInformation;
|
||||||
import com.djrapitops.plan.data.store.objects.DateHolder;
|
import com.djrapitops.plan.data.store.objects.DateHolder;
|
||||||
import com.djrapitops.plan.system.database.databases.Database;
|
import com.djrapitops.plan.system.database.databases.Database;
|
||||||
|
import com.djrapitops.plan.system.info.server.Server;
|
||||||
import com.djrapitops.plan.system.info.server.properties.ServerProperties;
|
import com.djrapitops.plan.system.info.server.properties.ServerProperties;
|
||||||
import com.djrapitops.plan.system.settings.Settings;
|
import com.djrapitops.plan.system.settings.Settings;
|
||||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||||
@ -17,13 +19,14 @@ import com.djrapitops.plan.utilities.formatting.Formatter;
|
|||||||
import com.djrapitops.plan.utilities.html.graphs.Graphs;
|
import com.djrapitops.plan.utilities.html.graphs.Graphs;
|
||||||
import com.djrapitops.plan.utilities.html.graphs.bar.BarGraph;
|
import com.djrapitops.plan.utilities.html.graphs.bar.BarGraph;
|
||||||
import com.djrapitops.plan.utilities.html.graphs.stack.StackGraph;
|
import com.djrapitops.plan.utilities.html.graphs.stack.StackGraph;
|
||||||
|
import com.djrapitops.plan.utilities.html.structure.NetworkServerBox;
|
||||||
import com.djrapitops.plugin.api.Check;
|
import com.djrapitops.plugin.api.Check;
|
||||||
import com.djrapitops.plugin.api.TimeAmount;
|
import com.djrapitops.plugin.api.TimeAmount;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -48,19 +51,35 @@ public class NetworkContainer extends DataContainer {
|
|||||||
private Formatter<DateHolder> yearFormatter;
|
private Formatter<DateHolder> yearFormatter;
|
||||||
private Formatter<Long> secondLongFormatter;
|
private Formatter<Long> secondLongFormatter;
|
||||||
|
|
||||||
private final Map<UUID, AnalysisContainer> serverContainers;
|
|
||||||
|
|
||||||
public NetworkContainer(ServerContainer bungeeContainer) {
|
public NetworkContainer(ServerContainer bungeeContainer) {
|
||||||
this.bungeeContainer = bungeeContainer;
|
this.bungeeContainer = bungeeContainer;
|
||||||
serverContainers = new HashMap<>();
|
|
||||||
|
|
||||||
putSupplier(NetworkKeys.PLAYERS_MUTATOR, () -> PlayersMutator.forContainer(bungeeContainer));
|
putSupplier(NetworkKeys.PLAYERS_MUTATOR, () -> PlayersMutator.forContainer(bungeeContainer));
|
||||||
|
|
||||||
addConstants();
|
addConstants();
|
||||||
|
addServerBoxes();
|
||||||
addPlayerInformation();
|
addPlayerInformation();
|
||||||
addNetworkHealth();
|
addNetworkHealth();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addServerBoxes() {
|
||||||
|
putSupplier(NetworkKeys.NETWORK_PLAYER_ONLINE_DATA, () -> database.fetch().getPlayersOnlineForServers(
|
||||||
|
getValue(NetworkKeys.BUKKIT_SERVERS).orElse(new ArrayList<>()))
|
||||||
|
);
|
||||||
|
putSupplier(NetworkKeys.SERVERS_TAB, () -> {
|
||||||
|
StringBuilder serverBoxes = new StringBuilder();
|
||||||
|
Map<Integer, List<TPS>> playersOnlineData = getValue(NetworkKeys.NETWORK_PLAYER_ONLINE_DATA).orElse(new HashMap<>());
|
||||||
|
for (Server server : getValue(NetworkKeys.BUKKIT_SERVERS).orElse(new ArrayList<>())) {
|
||||||
|
TPSMutator tpsMutator = new TPSMutator(playersOnlineData.getOrDefault(server.getId(), new ArrayList<>()));
|
||||||
|
|
||||||
|
// TODO Add Registered players per server.
|
||||||
|
NetworkServerBox serverBox = new NetworkServerBox(server, 0, tpsMutator, graphs);
|
||||||
|
serverBoxes.append(serverBox.toHtml());
|
||||||
|
}
|
||||||
|
return serverBoxes.toString();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void addNetworkHealth() {
|
private void addNetworkHealth() {
|
||||||
Key<NetworkHealthInformation> healthInformation = new Key<>(NetworkHealthInformation.class, "HEALTH_INFORMATION");
|
Key<NetworkHealthInformation> healthInformation = new Key<>(NetworkHealthInformation.class, "HEALTH_INFORMATION");
|
||||||
putSupplier(healthInformation, () -> new NetworkHealthInformation(this));
|
putSupplier(healthInformation, () -> new NetworkHealthInformation(this));
|
||||||
@ -68,20 +87,6 @@ public class NetworkContainer extends DataContainer {
|
|||||||
putSupplier(NetworkKeys.HEALTH_NOTES, () -> getUnsafe(healthInformation).toHtml());
|
putSupplier(NetworkKeys.HEALTH_NOTES, () -> getUnsafe(healthInformation).toHtml());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void putAnalysisContainer(AnalysisContainer analysisContainer) {
|
|
||||||
serverContainers.put(analysisContainer.getServerContainer().getUnsafe(ServerKeys.SERVER_UUID), analysisContainer);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<AnalysisContainer> getAnalysisContainer(UUID serverUUID) {
|
|
||||||
AnalysisContainer container = serverContainers.get(serverUUID);
|
|
||||||
if (container != null) {
|
|
||||||
return Optional.of(container);
|
|
||||||
}
|
|
||||||
AnalysisContainer analysisContainer = new AnalysisContainer(database.fetch().getServerContainer(serverUUID));
|
|
||||||
serverContainers.put(serverUUID, analysisContainer);
|
|
||||||
return Optional.of(analysisContainer);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addConstants() {
|
private void addConstants() {
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
putRawData(NetworkKeys.REFRESH_TIME, now);
|
putRawData(NetworkKeys.REFRESH_TIME, now);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.djrapitops.plan.data.store.keys;
|
package com.djrapitops.plan.data.store.keys;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.data.container.TPS;
|
||||||
import com.djrapitops.plan.data.store.Key;
|
import com.djrapitops.plan.data.store.Key;
|
||||||
import com.djrapitops.plan.data.store.PlaceholderKey;
|
import com.djrapitops.plan.data.store.PlaceholderKey;
|
||||||
import com.djrapitops.plan.data.store.Type;
|
import com.djrapitops.plan.data.store.Type;
|
||||||
@ -37,6 +38,7 @@ public class NetworkKeys {
|
|||||||
public static final PlaceholderKey<Integer> PLAYERS_NEW_WEEK = CommonPlaceholderKeys.PLAYERS_NEW_WEEK;
|
public static final PlaceholderKey<Integer> PLAYERS_NEW_WEEK = CommonPlaceholderKeys.PLAYERS_NEW_WEEK;
|
||||||
public static final PlaceholderKey<Integer> PLAYERS_NEW_MONTH = CommonPlaceholderKeys.PLAYERS_NEW_MONTH;
|
public static final PlaceholderKey<Integer> PLAYERS_NEW_MONTH = CommonPlaceholderKeys.PLAYERS_NEW_MONTH;
|
||||||
|
|
||||||
|
public static final PlaceholderKey<String> SERVERS_TAB = new PlaceholderKey<>(String.class, "tabContentServers");
|
||||||
public static final PlaceholderKey<String> WORLD_MAP_SERIES = CommonPlaceholderKeys.WORLD_MAP_SERIES;
|
public static final PlaceholderKey<String> WORLD_MAP_SERIES = CommonPlaceholderKeys.WORLD_MAP_SERIES;
|
||||||
public static final PlaceholderKey<String> PLAYERS_ONLINE_SERIES = CommonPlaceholderKeys.PLAYERS_ONLINE_SERIES;
|
public static final PlaceholderKey<String> PLAYERS_ONLINE_SERIES = CommonPlaceholderKeys.PLAYERS_ONLINE_SERIES;
|
||||||
public static final PlaceholderKey<String> ACTIVITY_STACK_SERIES = CommonPlaceholderKeys.ACTIVITY_STACK_SERIES;
|
public static final PlaceholderKey<String> ACTIVITY_STACK_SERIES = CommonPlaceholderKeys.ACTIVITY_STACK_SERIES;
|
||||||
@ -55,6 +57,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");
|
||||||
|
|
||||||
private NetworkKeys() {
|
private NetworkKeys() {
|
||||||
/* static variable class */
|
/* static variable class */
|
||||||
|
@ -116,4 +116,5 @@ public interface FetchOperations {
|
|||||||
|
|
||||||
List<UUID> getServerUUIDs();
|
List<UUID> getServerUUIDs();
|
||||||
|
|
||||||
|
Map<Integer, List<TPS>> getPlayersOnlineForServers(Collection<Server> serverUUIDs);
|
||||||
}
|
}
|
||||||
|
@ -461,4 +461,8 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
|
|||||||
return serverTable.getServerUUIDs();
|
return serverTable.getServerUUIDs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<Integer, List<TPS>> getPlayersOnlineForServers(Collection<Server> serverUUIDs) {
|
||||||
|
return tpsTable.getPlayersOnlineForServers(serverUUIDs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,10 +7,7 @@ import com.djrapitops.plan.system.database.databases.sql.SQLDB;
|
|||||||
import com.djrapitops.plan.system.database.databases.sql.processing.ExecStatement;
|
import com.djrapitops.plan.system.database.databases.sql.processing.ExecStatement;
|
||||||
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.Column;
|
import com.djrapitops.plan.system.database.databases.sql.statements.*;
|
||||||
import com.djrapitops.plan.system.database.databases.sql.statements.Select;
|
|
||||||
import com.djrapitops.plan.system.database.databases.sql.statements.Sql;
|
|
||||||
import com.djrapitops.plan.system.database.databases.sql.statements.TableSqlParser;
|
|
||||||
import com.djrapitops.plan.system.info.server.Server;
|
import com.djrapitops.plan.system.info.server.Server;
|
||||||
import com.djrapitops.plugin.api.TimeAmount;
|
import com.djrapitops.plugin.api.TimeAmount;
|
||||||
import com.djrapitops.plugin.utilities.Verify;
|
import com.djrapitops.plugin.utilities.Verify;
|
||||||
@ -304,6 +301,40 @@ public class TPSTable extends Table {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<Integer, List<TPS>> getPlayersOnlineForServers(Collection<Server> servers) {
|
||||||
|
WhereParser sqlParser = Select.from(tableName, Col.SERVER_ID, Col.DATE, Col.PLAYERS_ONLINE)
|
||||||
|
.where(Col.DATE.get() + ">" + (System.currentTimeMillis() - TimeAmount.WEEK.toMillis(2L)));
|
||||||
|
String statementSelectServerID = serverTable.statementSelectServerID;
|
||||||
|
for (Server server : servers) {
|
||||||
|
sqlParser.or(Col.SERVER_ID + "=" + statementSelectServerID.replace("?", server.getUuid().toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
String sql = sqlParser.toString();
|
||||||
|
|
||||||
|
return query(new QueryAllStatement<Map<Integer, List<TPS>>>(sql, 10000) {
|
||||||
|
@Override
|
||||||
|
public Map<Integer, List<TPS>> processResults(ResultSet set) throws SQLException {
|
||||||
|
Map<Integer, List<TPS>> map = new HashMap<>();
|
||||||
|
while (set.next()) {
|
||||||
|
int serverID = set.getInt(Col.SERVER_ID.get());
|
||||||
|
int playersOnline = set.getInt(Col.PLAYERS_ONLINE.get());
|
||||||
|
long date = set.getLong(Col.DATE.get());
|
||||||
|
|
||||||
|
List<TPS> tpsList = map.getOrDefault(serverID, new ArrayList<>());
|
||||||
|
|
||||||
|
TPS tps = TPSBuilder.get().date(date)
|
||||||
|
.skipTPS()
|
||||||
|
.playersOnline(playersOnline)
|
||||||
|
.toTPS();
|
||||||
|
tpsList.add(tps);
|
||||||
|
|
||||||
|
map.put(serverID, tpsList);
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public enum Col implements Column {
|
public enum Col implements Column {
|
||||||
SERVER_ID("server_id"),
|
SERVER_ID("server_id"),
|
||||||
DATE("date"),
|
DATE("date"),
|
||||||
|
@ -13,7 +13,6 @@ import com.djrapitops.plan.system.info.request.InfoRequestFactory;
|
|||||||
import com.djrapitops.plan.system.info.request.SetupRequest;
|
import com.djrapitops.plan.system.info.request.SetupRequest;
|
||||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||||
import com.djrapitops.plan.system.webserver.WebServer;
|
import com.djrapitops.plan.system.webserver.WebServer;
|
||||||
import com.djrapitops.plan.utilities.html.HtmlStructure;
|
|
||||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||||
import dagger.Lazy;
|
import dagger.Lazy;
|
||||||
|
|
||||||
@ -55,7 +54,7 @@ public class ServerInfoSystem extends InfoSystem {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateNetworkPage() throws WebException {
|
public void updateNetworkPage() throws WebException {
|
||||||
String html = HtmlStructure.createServerContainer();
|
String html = ""; // TODO Rework this part of the info system
|
||||||
sendRequest(infoRequestFactory.cacheNetworkPageContentRequest(serverInfo.getServerUUID(), html));
|
sendRequest(infoRequestFactory.cacheNetworkPageContentRequest(serverInfo.getServerUUID(), html));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,20 +4,11 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.utilities.html;
|
package com.djrapitops.plan.utilities.html;
|
||||||
|
|
||||||
import com.djrapitops.plan.data.store.mutators.TPSMutator;
|
|
||||||
import com.djrapitops.plan.system.database.databases.Database;
|
|
||||||
import com.djrapitops.plan.system.info.server.Server;
|
|
||||||
import com.djrapitops.plan.system.info.server.properties.ServerProperties;
|
|
||||||
import com.djrapitops.plan.utilities.formatting.Formatter;
|
|
||||||
import com.djrapitops.plan.utilities.html.graphs.Graphs;
|
|
||||||
import com.djrapitops.plan.utilities.html.icon.Color;
|
import com.djrapitops.plan.utilities.html.icon.Color;
|
||||||
import com.djrapitops.plan.utilities.html.icon.Icon;
|
import com.djrapitops.plan.utilities.html.icon.Icon;
|
||||||
import com.djrapitops.plan.utilities.html.icon.Icons;
|
import com.djrapitops.plan.utilities.html.icon.Icons;
|
||||||
import org.apache.commons.text.TextStringBuilder;
|
import org.apache.commons.text.TextStringBuilder;
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for parsing layout components of the websites.
|
* Class for parsing layout components of the websites.
|
||||||
*
|
*
|
||||||
@ -60,76 +51,6 @@ public class HtmlStructure {
|
|||||||
return new String[]{"<li><a>Calculating... Refresh shortly</a></li>", tab};
|
return new String[]{"<li><a>Calculating... Refresh shortly</a></li>", tab};
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Rework into NetworkPage generation
|
|
||||||
@Deprecated
|
|
||||||
public static String createServerContainer() {
|
|
||||||
ServerProperties properties = null; // TODO
|
|
||||||
int maxPlayers = properties.getMaxPlayers();
|
|
||||||
int online = properties.getOnlinePlayers();
|
|
||||||
Formatter<Long> clockLongFormatter = null; //TODO
|
|
||||||
String refresh = clockLongFormatter.apply(System.currentTimeMillis());
|
|
||||||
|
|
||||||
Server server = null; // TODO
|
|
||||||
|
|
||||||
String serverName = server.getName();
|
|
||||||
String serverType = properties.getVersion();
|
|
||||||
String address = "../server/" + serverName;
|
|
||||||
|
|
||||||
Database db = null; // TODO
|
|
||||||
UUID serverUUID = server.getUuid();
|
|
||||||
String id = ThreadLocalRandom.current().nextInt(100) + serverUUID.toString().replace("-", "");
|
|
||||||
|
|
||||||
int playerCount = 0;
|
|
||||||
String playerData = "[]";
|
|
||||||
playerCount = db.count().getServerPlayerCount(serverUUID);
|
|
||||||
Graphs graphs = null; // TODO
|
|
||||||
playerData = graphs.line().playersOnlineGraph(new TPSMutator(db.fetch().getTPSData(serverUUID))).toHighChartsSeries();
|
|
||||||
|
|
||||||
return "<div class=\"col-xs-12 col-sm-12 col-md-6 col-lg-6\">" +
|
|
||||||
"<div class=\"card\">" +
|
|
||||||
"<div class=\"header\">" +
|
|
||||||
"<div class=\"row clearfix\">" +
|
|
||||||
"<div class=\"col-xs-12 col-sm-12\">" +
|
|
||||||
"<h2><i class=\"col-light-green fa fa-server\"></i> " + serverName + "</h2>" +
|
|
||||||
"</div></div></div>" +
|
|
||||||
"<div class=\"panel panel-default\">" +
|
|
||||||
"<div class=\"panel-heading\">" +
|
|
||||||
"<div class=\"row\">" +
|
|
||||||
"<div id=\"playerChart" + id + "\" style=\"width: 100%; height: 300px;\"></div>" +
|
|
||||||
"</div></div>" +
|
|
||||||
"<div class=\"panel-body\">" +
|
|
||||||
"<div class=\"row\">" +
|
|
||||||
"<div class=\"col-md-8\">" +
|
|
||||||
"<p><i class=\"fa fa-users\"></i> Registered Players " +
|
|
||||||
"<span class=\"pull-right\">" + playerCount + "</span></p>" +
|
|
||||||
"<p><i class=\"col-blue fa fa-user\"></i> Players Online " +
|
|
||||||
"<span class=\"pull-right\">" + online + " / " + maxPlayers + "</span></p>" +
|
|
||||||
"<p><i class=\"col-deep-orange far fa-compass\"></i> Type " +
|
|
||||||
"<span class=\"pull-right\">" + serverType + "</span></p></div>" +
|
|
||||||
"<div class=\"col-md-4\">" +
|
|
||||||
"<p><i class=\"far fa-clock\"></i> Last Updated" +
|
|
||||||
"<span class=\"pull-right\"><b>" + refresh + "</b></span></p>" +
|
|
||||||
"<br>" +
|
|
||||||
"<a href=\"" + address + "\"><button href=\"" + address + "\" type=\"button\" class=\"pull-right btn bg-light-green waves-effect\">" +
|
|
||||||
"<i class=\"material-icons\">trending_up</i>" +
|
|
||||||
"<span>ANALYSIS</span>" +
|
|
||||||
"</button></a></div></div></div></div></div></div>" +
|
|
||||||
"<script>" +
|
|
||||||
"var playersOnlineSeries" + id + " = {" +
|
|
||||||
"name: 'Players Online'," +
|
|
||||||
"data: " + playerData + "," +
|
|
||||||
"type: 'areaspline'," +
|
|
||||||
"color: '${playersGraphColor}'," +
|
|
||||||
"tooltip: {" +
|
|
||||||
"valueDecimals: 0" +
|
|
||||||
"}};" +
|
|
||||||
"</script>" +
|
|
||||||
"<script>$(function () {setTimeout(" +
|
|
||||||
"function() {" +
|
|
||||||
"playersChartNoNav(playerChart" + id + ", playersOnlineSeries" + id + ");}, 1000);" +
|
|
||||||
"})</script>";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String playerStatus(boolean online, boolean banned, boolean op) {
|
public static String playerStatus(boolean online, boolean banned, boolean op) {
|
||||||
StringBuilder html = new StringBuilder("<p>");
|
StringBuilder html = new StringBuilder("<p>");
|
||||||
if (online) {
|
if (online) {
|
||||||
|
@ -0,0 +1,96 @@
|
|||||||
|
package com.djrapitops.plan.utilities.html.structure;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.data.store.mutators.PlayersOnlineResolver;
|
||||||
|
import com.djrapitops.plan.data.store.mutators.TPSMutator;
|
||||||
|
import com.djrapitops.plan.system.info.server.Server;
|
||||||
|
import com.djrapitops.plan.system.webserver.cache.PageId;
|
||||||
|
import com.djrapitops.plan.system.webserver.cache.ResponseCache;
|
||||||
|
import com.djrapitops.plan.utilities.html.graphs.Graphs;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Html that represents a server box on the network page.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
public class NetworkServerBox {
|
||||||
|
|
||||||
|
private final Server server;
|
||||||
|
private final int registeredPlayers;
|
||||||
|
private final TPSMutator tpsMutator;
|
||||||
|
|
||||||
|
private final Graphs graphs;
|
||||||
|
|
||||||
|
public NetworkServerBox(
|
||||||
|
Server server,
|
||||||
|
int registeredPlayers,
|
||||||
|
TPSMutator tpsMutator,
|
||||||
|
Graphs graphs
|
||||||
|
) {
|
||||||
|
this.server = server;
|
||||||
|
this.registeredPlayers = registeredPlayers;
|
||||||
|
this.tpsMutator = tpsMutator;
|
||||||
|
this.graphs = graphs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toHtml() {
|
||||||
|
Optional<Integer> playersOnline = new PlayersOnlineResolver(tpsMutator).getOnlineOn(System.currentTimeMillis());
|
||||||
|
int onlineCount = playersOnline.orElse(0);
|
||||||
|
int maxCount = server.getMaxPlayers();
|
||||||
|
|
||||||
|
String serverName = server.getName();
|
||||||
|
String address = "../server/" + serverName;
|
||||||
|
UUID serverUUID = server.getUuid();
|
||||||
|
String htmlID = ThreadLocalRandom.current().nextInt(100) + serverUUID.toString().replace("-", "");
|
||||||
|
|
||||||
|
String playersOnlineData = graphs.line().playersOnlineGraph(tpsMutator).toHighChartsSeries();
|
||||||
|
|
||||||
|
boolean isCached = ResponseCache.isCached(PageId.SERVER.of(serverUUID));
|
||||||
|
String cached = isCached ? "Yes" : "No";
|
||||||
|
|
||||||
|
return "<div class=\"col-xs-12 col-sm-12 col-md-6 col-lg-6\">" +
|
||||||
|
"<div class=\"card\">" +
|
||||||
|
"<div class=\"header\">" +
|
||||||
|
"<div class=\"row clearfix\">" +
|
||||||
|
"<div class=\"col-xs-12 col-sm-12\">" +
|
||||||
|
"<h2><i class=\"col-light-green fa fa-server\"></i> " + serverName + "</h2>" +
|
||||||
|
"</div></div></div>" +
|
||||||
|
"<div class=\"panel panel-default\">" +
|
||||||
|
"<div class=\"panel-heading\">" +
|
||||||
|
"<div class=\"row\">" +
|
||||||
|
"<div id=\"playerChart" + htmlID + "\" style=\"width: 100%; height: 300px;\"></div>" +
|
||||||
|
"</div></div>" +
|
||||||
|
"<div class=\"panel-body\">" +
|
||||||
|
"<div class=\"row\">" +
|
||||||
|
"<div class=\"col-md-8\">" +
|
||||||
|
"<p><i class=\"fa fa-users\"></i> Registered Players " +
|
||||||
|
"<span class=\"pull-right\">" + registeredPlayers + "</span></p>" +
|
||||||
|
"<p><i class=\"col-blue fa fa-user\"></i> Players Online " +
|
||||||
|
"<span class=\"pull-right\">" + onlineCount + " / " + maxCount + "</span></p>" +
|
||||||
|
"</div>" +
|
||||||
|
"<div class=\"col-md-4\">" +
|
||||||
|
"<p><i class=\"far fa-chart-pie \"></i> Analysis Cached" +
|
||||||
|
"<span class=\"pull-right\"><b>" + cached + "</b></span></p>" +
|
||||||
|
"<a href=\"" + address + "\"><button href=\"" + address + "\" type=\"button\" class=\"pull-right btn bg-light-green waves-effect\">" +
|
||||||
|
"<i class=\"material-icons\">trending_up</i>" +
|
||||||
|
"<span>ANALYSIS</span>" +
|
||||||
|
"</button></a></div></div></div></div></div></div>" +
|
||||||
|
"<script>" +
|
||||||
|
"var playersOnlineSeries" + htmlID + " = {" +
|
||||||
|
"name: 'Players Online'," +
|
||||||
|
"data: " + playersOnlineData + "," +
|
||||||
|
"type: 'areaspline'," +
|
||||||
|
"color: '${playersGraphColor}'," +
|
||||||
|
"tooltip: {" +
|
||||||
|
"valueDecimals: 0" +
|
||||||
|
"}};" +
|
||||||
|
"</script>" +
|
||||||
|
"<script>$(function () {setTimeout(" +
|
||||||
|
"function() {" +
|
||||||
|
"playersChartNoNav(playerChart" + htmlID + ", playersOnlineSeries" + htmlID + ");}, 1000);" +
|
||||||
|
"})</script>";
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user