diff --git a/Plan/src/main/java/com/djrapitops/plan/Settings.java b/Plan/src/main/java/com/djrapitops/plan/Settings.java index a92bbde1d..bce054491 100644 --- a/Plan/src/main/java/com/djrapitops/plan/Settings.java +++ b/Plan/src/main/java/com/djrapitops/plan/Settings.java @@ -88,15 +88,16 @@ public enum Settings { THEME_GRAPH_RAM("Theme.Graphs.RAM"), THEME_GRAPH_CHUNKS("Theme.Graphs.Chunks"), THEME_GRAPH_ENTITIES("Theme.Graphs.Entities"), - THEME_GRAPH_WORLDPIE("Theme.Graphs.WorldPie"), - THEME_GRAPH_ACTIVITYPIE("Theme.Graphs.ActivityPie"), - THEME_GRAPH_SERVERPREFPIE("Theme.Graphs.ServerPreferencePie"), + THEME_GRAPH_WORLD_PIE("Theme.Graphs.WorldPie"), + THEME_GRAPH_ACTIVITY_PIE("Theme.Graphs.ActivityPie"), + THEME_GRAPH_SERVER_PREF_PIE("Theme.Graphs.ServerPreferencePie"), // StringList HIDE_FACTIONS("Plugins.Factions.HideFactions"), HIDE_TOWNS("Plugins.Towny.HideTowns"), // // Bungee - BUNGEE_IP("Server.IP"); + BUNGEE_IP("Server.IP"), + BUNGEE_NETWROK_NAME("Network.Name"); private static final ServerSpecificSettings serverSpecificSettings = new ServerSpecificSettings(); diff --git a/Plan/src/main/java/com/djrapitops/plan/data/analysis/ActivityPart.java b/Plan/src/main/java/com/djrapitops/plan/data/analysis/ActivityPart.java index b98a6292f..308936e9d 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/analysis/ActivityPart.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/analysis/ActivityPart.java @@ -2,6 +2,7 @@ package main.java.com.djrapitops.plan.data.analysis; import com.djrapitops.plugin.api.TimeAmount; import com.djrapitops.plugin.utilities.Verify; +import main.java.com.djrapitops.plan.Settings; import main.java.com.djrapitops.plan.data.Session; import main.java.com.djrapitops.plan.data.TPS; import main.java.com.djrapitops.plan.systems.webserver.theme.Colors; @@ -9,13 +10,11 @@ import main.java.com.djrapitops.plan.utilities.FormatUtils; import main.java.com.djrapitops.plan.utilities.MiscUtils; import main.java.com.djrapitops.plan.utilities.analysis.AnalysisUtils; import main.java.com.djrapitops.plan.utilities.analysis.MathUtils; -import main.java.com.djrapitops.plan.utilities.html.HtmlUtils; import main.java.com.djrapitops.plan.utilities.html.graphs.PlayerActivityGraphCreator; import main.java.com.djrapitops.plan.utilities.html.graphs.PunchCardGraphCreator; import java.util.*; import java.util.stream.Collectors; -import main.java.com.djrapitops.plan.Settings; /** * Part responsible for all Player Activity related analysis. @@ -93,7 +92,7 @@ public class ActivityPart extends RawData { int[] counts = new int[]{active.size(), inactive.size(), joinedOnce.size(), bans.size()}; - addValue("activityPieColors", Settings.THEME_GRAPH_ACTIVITYPIE.toString()); + addValue("activityPieColors", Settings.THEME_GRAPH_ACTIVITY_PIE.toString()); addValue("playersActive", counts[0]); addValue("active", counts[0]); addValue("inactive", counts[1]); diff --git a/Plan/src/main/java/com/djrapitops/plan/data/analysis/WorldPart.java b/Plan/src/main/java/com/djrapitops/plan/data/analysis/WorldPart.java index 45bff87bd..30e46c9ba 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/analysis/WorldPart.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/analysis/WorldPart.java @@ -1,11 +1,11 @@ package main.java.com.djrapitops.plan.data.analysis; +import main.java.com.djrapitops.plan.Settings; import main.java.com.djrapitops.plan.data.time.WorldTimes; import main.java.com.djrapitops.plan.utilities.FormatUtils; import main.java.com.djrapitops.plan.utilities.html.graphs.WorldPieCreator; import java.util.HashMap; -import main.java.com.djrapitops.plan.Settings; /** * Part responsible for all World Playtime related analysis. @@ -35,7 +35,7 @@ public class WorldPart extends RawData { String[] seriesData = WorldPieCreator.createSeriesData(worldTimes); addValue("worldSeries", seriesData[0]); addValue("gmSeries", seriesData[1]); - addValue("worldPieColors", Settings.THEME_GRAPH_WORLDPIE.toString()); + addValue("worldPieColors", Settings.THEME_GRAPH_WORLD_PIE.toString()); } public WorldTimes getWorldTimes() { diff --git a/Plan/src/main/java/com/djrapitops/plan/database/tables/ServerTable.java b/Plan/src/main/java/com/djrapitops/plan/database/tables/ServerTable.java index 133cac6ad..20562c73a 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/tables/ServerTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/tables/ServerTable.java @@ -365,4 +365,22 @@ public class ServerTable extends Table { close(set, statement); } } + + public int getMaxPlayers() throws SQLException { + PreparedStatement statement = null; + ResultSet set = null; + try { + statement = prepareStatement("SELECT SUM(" + columnMaxPlayers + ") AS max FROM " + tableName); + statement.setFetchSize(5000); + + set = statement.executeQuery(); + if (set.next()) { + return set.getInt("max"); + } + return 0; + } finally { + endTransaction(statement); + close(set, statement); + } + } } \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/database/tables/TPSTable.java b/Plan/src/main/java/com/djrapitops/plan/database/tables/TPSTable.java index 267105928..4d3a8d979 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/tables/TPSTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/tables/TPSTable.java @@ -272,4 +272,30 @@ public class TPSTable extends Table { close(statement); } } + + public List getNetworkOnlineData() throws SQLException { + PreparedStatement statement = null; + ResultSet set = null; + try { + statement = prepareStatement("SELECT " + + columnDate + ", " + + "SUM(" + columnPlayers + ") as players" + + " FROM " + tableName + + " GROUP BY " + columnDate + ); + statement.setFetchSize(50000); + set = statement.executeQuery(); + List tpsList = new ArrayList<>(); + while (set.next()) { + long date = set.getLong(columnDate); + int players = set.getInt("players"); + + tpsList.add(new TPS(date, 0, players, 0, 0, 0, 0)); + } + return tpsList; + } finally { + endTransaction(statement); + close(set, statement); + } + } } diff --git a/Plan/src/main/java/com/djrapitops/plan/database/tables/UsersTable.java b/Plan/src/main/java/com/djrapitops/plan/database/tables/UsersTable.java index 4b4d50515..afe10a1cb 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/tables/UsersTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/tables/UsersTable.java @@ -429,4 +429,22 @@ public class UsersTable extends UserIDTable { close(set, statement); } } + + public int getPlayerCount() throws SQLException { + PreparedStatement statement = null; + ResultSet set = null; + try { + statement = prepareStatement("SELECT COUNT(*) AS player_count FROM " + tableName); + statement.setFetchSize(5000); + + set = statement.executeQuery(); + if (set.next()) { + return set.getInt("player_count"); + } + return 0; + } finally { + endTransaction(statement); + close(set, statement); + } + } } diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/info/BukkitInformationManager.java b/Plan/src/main/java/com/djrapitops/plan/systems/info/BukkitInformationManager.java index bc93193ad..c51f63946 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/info/BukkitInformationManager.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/info/BukkitInformationManager.java @@ -20,6 +20,7 @@ import main.java.com.djrapitops.plan.systems.processing.Processor; import main.java.com.djrapitops.plan.systems.webserver.PageCache; import main.java.com.djrapitops.plan.systems.webserver.response.AnalysisPageResponse; import main.java.com.djrapitops.plan.systems.webserver.response.InspectPageResponse; +import main.java.com.djrapitops.plan.systems.webserver.response.InternalErrorResponse; import main.java.com.djrapitops.plan.systems.webserver.response.Response; import main.java.com.djrapitops.plan.systems.webserver.theme.Theme; import main.java.com.djrapitops.plan.systems.webserver.webapi.WebAPIManager; @@ -169,9 +170,8 @@ public class BukkitInformationManager extends InformationManager { try { return Theme.replaceColors(new AnalysisPageParser(analysisData, plugin).parse()); } catch (ParseException e) { - Log.toLog(this.getClass().getName(), e); + return new InternalErrorResponse(e, this.getClass().getSimpleName()).getContent(); } - return ""; } @Override @@ -179,9 +179,8 @@ public class BukkitInformationManager extends InformationManager { try { return Theme.replaceColors(new InspectPageParser(uuid, plugin).parse()); } catch (ParseException e) { - Log.toLog(this.getClass().getName(), e); + return new InternalErrorResponse(e, this.getClass().getSimpleName()).getContent(); } - return ""; } @Override diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/info/BungeeInformationManager.java b/Plan/src/main/java/com/djrapitops/plan/systems/info/BungeeInformationManager.java index 3cf51e436..a781989e6 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/info/BungeeInformationManager.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/info/BungeeInformationManager.java @@ -6,13 +6,16 @@ package main.java.com.djrapitops.plan.systems.info; import main.java.com.djrapitops.plan.Log; import main.java.com.djrapitops.plan.PlanBungee; +import main.java.com.djrapitops.plan.api.exceptions.ParseException; import main.java.com.djrapitops.plan.api.exceptions.WebAPIConnectionFailException; import main.java.com.djrapitops.plan.api.exceptions.WebAPIException; import main.java.com.djrapitops.plan.api.exceptions.WebAPINotFoundException; import main.java.com.djrapitops.plan.systems.cache.DataCache; +import main.java.com.djrapitops.plan.systems.info.parsing.NetworkPageParser; import main.java.com.djrapitops.plan.systems.info.server.ServerInfo; import main.java.com.djrapitops.plan.systems.webserver.PageCache; import main.java.com.djrapitops.plan.systems.webserver.response.InspectPageResponse; +import main.java.com.djrapitops.plan.systems.webserver.response.InternalErrorResponse; import main.java.com.djrapitops.plan.systems.webserver.response.NotFoundResponse; import main.java.com.djrapitops.plan.systems.webserver.response.Response; import main.java.com.djrapitops.plan.systems.webserver.webapi.WebAPIManager; @@ -162,7 +165,11 @@ public class BungeeInformationManager extends InformationManager { @Override public String getAnalysisHtml() { - return new NotFoundResponse("Network page not yet created").getContent(); + try { + return new NetworkPageParser(plugin).parse(); + } catch (ParseException e) { + return new InternalErrorResponse(e, this.getClass().getSimpleName()).getContent(); + } } @Override @@ -201,7 +208,7 @@ public class BungeeInformationManager extends InformationManager { public void askForNetWorkPageContent() { // TODO WebAPI for network page content } - + public void cacheNetworkPageContent(UUID serverUUID, String html) { networkPageContent.put(serverUUID, html); } diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/info/parsing/InspectPageParser.java b/Plan/src/main/java/com/djrapitops/plan/systems/info/parsing/InspectPageParser.java index 25c71687b..66d9cb7d7 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/info/parsing/InspectPageParser.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/info/parsing/InspectPageParser.java @@ -6,6 +6,7 @@ package main.java.com.djrapitops.plan.systems.info.parsing; import com.djrapitops.plugin.api.TimeAmount; import main.java.com.djrapitops.plan.Log; +import main.java.com.djrapitops.plan.Settings; import main.java.com.djrapitops.plan.api.IPlan; import main.java.com.djrapitops.plan.api.exceptions.ParseException; import main.java.com.djrapitops.plan.data.Action; @@ -25,6 +26,7 @@ import main.java.com.djrapitops.plan.utilities.file.FileUtil; import main.java.com.djrapitops.plan.utilities.html.HtmlStructure; import main.java.com.djrapitops.plan.utilities.html.HtmlUtils; import main.java.com.djrapitops.plan.utilities.html.graphs.PunchCardGraphCreator; +import main.java.com.djrapitops.plan.utilities.html.graphs.ServerPreferencePieCreator; import main.java.com.djrapitops.plan.utilities.html.graphs.WorldPieCreator; import main.java.com.djrapitops.plan.utilities.html.tables.ActionsTableCreator; @@ -33,8 +35,6 @@ import java.util.List; import java.util.Map; import java.util.UUID; import java.util.stream.Collectors; -import main.java.com.djrapitops.plan.Settings; -import main.java.com.djrapitops.plan.utilities.html.graphs.ServerPreferencePieCreator; /** * Used for parsing Inspect page out of database data and the html. @@ -82,8 +82,8 @@ public class InspectPageParser extends PageParser { Map playtimeByServer = sessionsTable.getPlaytimeByServer(uuid); addValue("serverPieSeries", ServerPreferencePieCreator.createSeriesData(playtimeByServer)); - addValue("worldPieColors", Settings.THEME_GRAPH_WORLDPIE.toString()); - addValue("serverPieColors", Settings.THEME_GRAPH_SERVERPREFPIE.toString()); + addValue("worldPieColors", Settings.THEME_GRAPH_WORLD_PIE.toString()); + addValue("serverPieColors", Settings.THEME_GRAPH_SERVER_PREF_PIE.toString()); List geolocations = db.getIpsTable().getGeolocations(uuid); List nicknames = db.getNicknamesTable().getNicknames(uuid).stream() diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/info/parsing/NetworkPageParser.java b/Plan/src/main/java/com/djrapitops/plan/systems/info/parsing/NetworkPageParser.java new file mode 100644 index 000000000..414299160 --- /dev/null +++ b/Plan/src/main/java/com/djrapitops/plan/systems/info/parsing/NetworkPageParser.java @@ -0,0 +1,65 @@ +/* + * Licence is provided in the jar as license.yml also here: + * https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml + */ +package main.java.com.djrapitops.plan.systems.info.parsing; + +import com.djrapitops.plugin.api.TimeAmount; +import main.java.com.djrapitops.plan.PlanBungee; +import main.java.com.djrapitops.plan.Settings; +import main.java.com.djrapitops.plan.api.exceptions.ParseException; +import main.java.com.djrapitops.plan.data.TPS; +import main.java.com.djrapitops.plan.database.Database; +import main.java.com.djrapitops.plan.systems.info.BungeeInformationManager; +import main.java.com.djrapitops.plan.utilities.MiscUtils; +import main.java.com.djrapitops.plan.utilities.analysis.AnalysisUtils; +import main.java.com.djrapitops.plan.utilities.file.FileUtil; +import main.java.com.djrapitops.plan.utilities.html.HtmlStructure; +import main.java.com.djrapitops.plan.utilities.html.HtmlUtils; +import main.java.com.djrapitops.plan.utilities.html.graphs.PlayerActivityGraphCreator; + +import java.util.List; +import java.util.Map; +import java.util.UUID; + +/** + * //TODO Class Javadoc Comment + * + * @author Rsl1122 + */ +public class NetworkPageParser extends PageParser { + + private final PlanBungee plugin; + + public NetworkPageParser(PlanBungee plugin) { + this.plugin = plugin; + } + + @Override + public String parse() throws ParseException { + try { + long now = MiscUtils.getTime(); + Database db = plugin.getDB(); + List networkOnlineData = db.getTpsTable().getNetworkOnlineData(); + + addValue("networkName", Settings.BUNGEE_NETWROK_NAME.toString()); + addValue("version", plugin.getVersion()); + addValue("playersOnlineSeries", PlayerActivityGraphCreator.buildSeriesDataString(networkOnlineData)); + addValue("playersOnline", plugin.getProxy().getOnlineCount()); + addValue("playersMax", db.getServerTable().getMaxPlayers()); + + addValue("playersTotal", db.getUsersTable().getPlayerCount()); + + List registerDates = db.getUsersTable().getRegisterDates(); + addValue("playersNewDay", AnalysisUtils.getNewPlayers(registerDates, TimeAmount.DAY.ms(), now)); + addValue("playersNewWeek", AnalysisUtils.getNewPlayers(registerDates, TimeAmount.WEEK.ms(), now)); + + Map networkPageContents = ((BungeeInformationManager) plugin.getInfoManager()).getNetworkPageContent(); + addValue("contentServers", HtmlStructure.createNetworkPageContent(networkPageContents)); + + return HtmlUtils.replacePlaceholders(FileUtil.getStringFromResource("network.html"), placeHolders); + } catch (Exception e) { + throw new ParseException(e); + } + } +} \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/webserver/response/InternalErrorResponse.java b/Plan/src/main/java/com/djrapitops/plan/systems/webserver/response/InternalErrorResponse.java index 6de4e531b..ebd4deff6 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/webserver/response/InternalErrorResponse.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/webserver/response/InternalErrorResponse.java @@ -21,10 +21,24 @@ public class InternalErrorResponse extends ErrorResponse { for (StackTraceElement element : e.getStackTrace()) { paragraph.append("
"); - paragraph.append(" ").append(element); + paragraph.append("  ").append(element); + } + if (e.getCause() != null) { + appendCause(e.getCause(), paragraph); } super.setParagraph(paragraph.toString()); super.replacePlaceholders(); } + + private void appendCause(Throwable cause, StringBuilder paragraph) { + paragraph.append("
Caused by: ").append(cause); + for (StackTraceElement element : cause.getStackTrace()) { + paragraph.append("
"); + paragraph.append("  ").append(element); + } + if (cause.getCause() != null) { + appendCause(cause.getCause(), paragraph); + } + } } diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/html/HtmlStructure.java b/Plan/src/main/java/com/djrapitops/plan/utilities/html/HtmlStructure.java index 86371a8e2..4d1be2dfa 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/html/HtmlStructure.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/html/HtmlStructure.java @@ -5,9 +5,11 @@ package main.java.com.djrapitops.plan.utilities.html; import com.djrapitops.plugin.utilities.Verify; +import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.data.Session; import main.java.com.djrapitops.plan.data.additional.AnalysisType; import main.java.com.djrapitops.plan.data.additional.PluginData; +import main.java.com.djrapitops.plan.systems.info.BukkitInformationManager; import main.java.com.djrapitops.plan.utilities.FormatUtils; import main.java.com.djrapitops.plan.utilities.analysis.AnalysisUtils; import main.java.com.djrapitops.plan.utilities.html.graphs.WorldPieCreator; @@ -196,7 +198,7 @@ public class HtmlStructure { "
" + "
" + "
" + - "

"+ serverName+ + "

" + serverName + "

No Compatible Plugins

" + "
"; } @@ -376,4 +378,60 @@ public class HtmlStructure { "" + ""; } + + public static String createNetworkPageContent(Map networkPageContents) { + if (Verify.isEmpty(networkPageContents)) { + return ""; + } + int i = 0; + StringBuilder b = new StringBuilder(); + Collection values = networkPageContents.values(); + int size = values.size(); + for (String server : values) { + if (i % 3 == 0) { + b.append("
"); + } + b.append(server); + if ((i + 1) % 3 == 0 || i + 1 == size) { + b.append("
"); + } + i++; + } + return b.toString(); + } + + public static String createServerContainer(Plan plugin) { + int maxPlayers = plugin.getVariable().getMaxPlayers(); + int online = plugin.getServer().getOnlinePlayers().size(); + Optional analysisRefreshDate = ((BukkitInformationManager) plugin.getInfoManager()).getAnalysisRefreshDate(); + String refresh = analysisRefreshDate.map(FormatUtils::formatTimeStamp).orElse("-"); + boolean analysisIsAvailable = analysisRefreshDate.isPresent(); + + String serverName = plugin.getServerInfoManager().getServerName(); + String address = plugin.getInfoManager().getLinkTo("/server/" + serverName).relative().toString(); + + StringBuilder b = new StringBuilder("
"); + + // Header + b.append("

") + .append(serverName) + .append("

"); + + // Online players + b.append("

").append(online).append("/").append(maxPlayers) + .append(" Players Online

"); + + // Footer + b.append("

Last Refresh: ").append(refresh).append("

"); + if (analysisIsAvailable) { + b.append("Analysis"); + } else { + b.append("Analysis"); + } + // TODO Refresh functionality + + b.append("
") + .append("
"); + return b.toString(); + } } \ No newline at end of file diff --git a/Plan/src/main/resources/bungeeconfig.yml b/Plan/src/main/resources/bungeeconfig.yml index cc085a932..0ae298032 100644 --- a/Plan/src/main/resources/bungeeconfig.yml +++ b/Plan/src/main/resources/bungeeconfig.yml @@ -1,5 +1,7 @@ Server: IP: 0.0.0.0 +Network: + Name: Plan Plugin: Debug: 'false' diff --git a/Plan/src/main/resources/html/error.html b/Plan/src/main/resources/html/error.html index 09926510b..cfa7ab90d 100644 --- a/Plan/src/main/resources/html/error.html +++ b/Plan/src/main/resources/html/error.html @@ -30,7 +30,7 @@

${title}

-
+

${paragraph}

diff --git a/Plan/src/main/resources/html/network.html b/Plan/src/main/resources/html/network.html index 534e3faad..570f7300e 100644 --- a/Plan/src/main/resources/html/network.html +++ b/Plan/src/main/resources/html/network.html @@ -32,7 +32,7 @@

Players Online

@@ -41,26 +41,27 @@

${playersOnline}/${playersMax} Players Online

-

${playersActive} Active Players
${playersTotal} Total Players

+

${playersTotal} Total Players

${playersNewDay} New Players Today
${playersNewWeek} New Players This Week

${contentServers} + + \ No newline at end of file diff --git a/Plan/src/main/resources/html/server.html b/Plan/src/main/resources/html/server.html index 3a54f3ea6..f8d52dbd3 100644 --- a/Plan/src/main/resources/html/server.html +++ b/Plan/src/main/resources/html/server.html @@ -349,8 +349,8 @@ type: 'areaspline', color: '${playersGraphColor}', tooltip: { - valueDecimals: 0 - } + valueDecimals: 0 + } }; var tpsSeries = { name: 'TPS',