From a091f0e9d59c07dfbe424224717279f68ce3cbd0 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Tue, 26 Sep 2017 18:00:48 +0300 Subject: [PATCH] Network page sending, Fixed SessionsTableCreator NPE related to Active sessions (No session ID) Fixed NPE related to 0 analysis notifications --- .../plan/command/commands/AnalyzeCommand.java | 4 ++ .../plan/database/tables/IPsTable.java | 1 - .../info/BukkitInformationManager.java | 12 +++++ .../info/BungeeInformationManager.java | 13 ++++- .../plan/systems/info/InformationManager.java | 2 + .../systems/listeners/PlanPlayerListener.java | 10 +++- .../bungee/PostNetworkPageContentWebAPI.java | 48 +++++++++++++++++++ .../plan/utilities/html/HtmlStructure.java | 10 +++- .../html/tables/SessionsTableCreator.java | 13 ++++- Plan/src/main/resources/Placeholders.txt | 8 ++-- Plan/src/main/resources/html/player.html | 4 +- Plan/src/main/resources/html/server.html | 7 ++- 12 files changed, 121 insertions(+), 11 deletions(-) create mode 100644 Plan/src/main/java/com/djrapitops/plan/systems/webserver/webapi/bungee/PostNetworkPageContentWebAPI.java diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/AnalyzeCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/AnalyzeCommand.java index fd0e05dcf..28099abdf 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/AnalyzeCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/AnalyzeCommand.java @@ -5,6 +5,7 @@ import com.djrapitops.plugin.command.CommandUtils; import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.command.SubCommand; import com.djrapitops.plugin.task.AbsRunnable; +import com.djrapitops.plugin.utilities.Verify; import main.java.com.djrapitops.plan.Log; import main.java.com.djrapitops.plan.Permissions; import main.java.com.djrapitops.plan.Plan; @@ -47,6 +48,9 @@ public class AnalyzeCommand extends SubCommand { } public static void sendAnalysisMessage(Collection senders, UUID serverUUID) throws SQLException { + if (Verify.isEmpty(senders)) { + return; + } Plan plugin = Plan.getInstance(); Optional serverName = plugin.getDB().getServerTable().getServerName(serverUUID); if (serverName.isPresent()) { diff --git a/Plan/src/main/java/com/djrapitops/plan/database/tables/IPsTable.java b/Plan/src/main/java/com/djrapitops/plan/database/tables/IPsTable.java index 0e3477d46..c6451e381 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/tables/IPsTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/tables/IPsTable.java @@ -91,7 +91,6 @@ public class IPsTable extends UserIDTable { if (ips.contains(ip)) { return; } - insertIp(uuid, ip, geolocation); } 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 c7db6874b..cfe663d06 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 @@ -279,4 +279,16 @@ public class BukkitInformationManager extends InformationManager { } analysisNotification.getOrDefault(serverUUID, new HashSet<>()).clear(); } + + @Override + public void updateNetworkPageContent() { + if (usingAnotherWebServer) { + try { + getWebAPI().getAPI(PostNetworkPageContentWebAPI.class).sendNetworkContent(webServerAddress, HtmlStructure.createServerContainer(plugin)); + } catch (WebAPIException e) { + attemptConnection(); + updateNetworkPageContent(); + } + } + } } \ No newline at end of file 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 9e3f59122..5ba8b0c17 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 @@ -73,6 +73,9 @@ public class BungeeInformationManager extends InformationManager { */ @Override public void refreshAnalysis(UUID serverUUID) { + if (PlanBungee.getServerUUID().equals(serverUUID)) { + return; + } ServerInfo serverInfo = getOnlineServerInfo(serverUUID); if (serverInfo == null) { return; @@ -323,7 +326,7 @@ public class BungeeInformationManager extends InformationManager { } public void removeNetworkPageContent(UUID serverUUID) { - networkPageContent.remove(serverUUID); + networkPageContent.put(serverUUID, HtmlStructure.parseOfflineServerContainer(networkPageContent.get(serverUUID))); } public Map getNetworkPageContent() { @@ -346,4 +349,12 @@ public class BungeeInformationManager extends InformationManager { } } } + + @Override + public void updateNetworkPageContent() { + Collection online = serverInfoManager.getOnlineBukkitServers(); + bukkitServers.values().stream() + .filter(s -> !online.contains(s)).map(ServerInfo::getUuid) + .forEach(this::removeNetworkPageContent); + } } diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/info/InformationManager.java b/Plan/src/main/java/com/djrapitops/plan/systems/info/InformationManager.java index f4c66deb0..b2d8a5d58 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/info/InformationManager.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/info/InformationManager.java @@ -87,4 +87,6 @@ public abstract class InformationManager { } public abstract void analysisReady(UUID serverUUID); + + public abstract void updateNetworkPageContent(); } \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/listeners/PlanPlayerListener.java b/Plan/src/main/java/com/djrapitops/plan/systems/listeners/PlanPlayerListener.java index c398d706a..78ab89b55 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/listeners/PlanPlayerListener.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/listeners/PlanPlayerListener.java @@ -4,6 +4,8 @@ import com.djrapitops.plugin.utilities.player.Fetch; import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.data.Session; import main.java.com.djrapitops.plan.systems.cache.DataCache; +import main.java.com.djrapitops.plan.systems.info.InformationManager; +import main.java.com.djrapitops.plan.systems.processing.Processor; import main.java.com.djrapitops.plan.systems.processing.player.*; import main.java.com.djrapitops.plan.utilities.MiscUtils; import org.bukkit.entity.Player; @@ -98,7 +100,13 @@ public class PlanPlayerListener implements Listener { new RegisterProcessor(uuid, player.getFirstPlayed(), time, playerName, playersOnline, new IPUpdateProcessor(uuid, ip), new NameProcessor(uuid, playerName, displayName) - ) + ), + new Processor(plugin.getInfoManager()) { + @Override + public void process() { + object.updateNetworkPageContent(); + } + } ); } diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/webserver/webapi/bungee/PostNetworkPageContentWebAPI.java b/Plan/src/main/java/com/djrapitops/plan/systems/webserver/webapi/bungee/PostNetworkPageContentWebAPI.java new file mode 100644 index 000000000..e84d60ef7 --- /dev/null +++ b/Plan/src/main/java/com/djrapitops/plan/systems/webserver/webapi/bungee/PostNetworkPageContentWebAPI.java @@ -0,0 +1,48 @@ +/* + * 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.webserver.webapi.bungee; + +import com.djrapitops.plugin.utilities.Compatibility; +import main.java.com.djrapitops.plan.api.IPlan; +import main.java.com.djrapitops.plan.api.exceptions.WebAPIException; +import main.java.com.djrapitops.plan.systems.info.BungeeInformationManager; +import main.java.com.djrapitops.plan.systems.webserver.response.Response; +import main.java.com.djrapitops.plan.systems.webserver.webapi.WebAPI; + +import java.util.Map; +import java.util.UUID; + +/** + * //TODO Class Javadoc Comment + * + * @author Rsl1122 + */ +public class PostNetworkPageContentWebAPI extends WebAPI { + @Override + public Response onRequest(IPlan plugin, Map variables) { + if (Compatibility.isBukkitAvailable()) { + return badRequest("Called a Bukkit server."); + } + + UUID serverUUID = UUID.fromString(variables.get("sender")); + String html = variables.get("html"); + if (html == null) { + return badRequest("html not present"); + } + + ((BungeeInformationManager) plugin.getInfoManager()).cacheNetworkPageContent(serverUUID, html); + return success(); + } + + @Override + public void sendRequest(String address) throws WebAPIException { + throw new IllegalStateException("Wrong method call for this WebAPI, call sendRequest(String, UUID, UUID) instead."); + } + + public void sendNetworkContent(String address, String html) throws WebAPIException { + addVariable("html", html); + super.sendRequest(address); + } +} \ No newline at end of file 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 4d1be2dfa..1f5b8813f 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 @@ -428,10 +428,18 @@ public class HtmlStructure { } else { b.append("Analysis"); } - // TODO Refresh functionality b.append("") .append(""); return b.toString(); } + + public static String parseOfflineServerContainer(String oldContent) { + if (oldContent == null) { + return ""; + } + String[] split = oldContent.split("

", 2); + String[] split2 = split[1].split("box-footer", 2); + return split[0] + "

Offline

uuidBySessionStart = new HashMap<>(); + for (Map.Entry entry : dataCache.getActiveSessions().entrySet()) { + uuidBySessionStart.put(entry.getValue().getSessionStart(), entry.getKey()); + } + + for (Session session : allSessions) { if (i >= 50) { break; } - UUID uuid = uuidByID.get(session.getSessionID()); + UUID uuid; + if (session.isFetchedFromDB()) { + uuid = uuidByID.get(session.getSessionID()); + } else { + uuid = uuidBySessionStart.get(session.getSessionStart()); + } String name = dataCache.getName(uuid); String start = FormatUtils.formatTimeStamp(session.getSessionStart()); diff --git a/Plan/src/main/resources/Placeholders.txt b/Plan/src/main/resources/Placeholders.txt index 85bb819a3..abc6cd767 100644 --- a/Plan/src/main/resources/Placeholders.txt +++ b/Plan/src/main/resources/Placeholders.txt @@ -97,8 +97,8 @@ ${killCount} num ${mobKillCount} num ${deathCount} num -${commandCount} num //TODO -${commandUniqueCount} num //TODO +${commandCount} num +${commandUniqueCount} num //done ${tpsAverageDay} num @@ -131,7 +131,7 @@ ${punchCardSeries} ${playersGraphColor} // done -${gmColors} // TODO Move to World Graph +${gmColors} // done ${active} @@ -141,7 +141,7 @@ ${banned} ${activityColors} ${worldTotal} timeamount //done -${worldColors} //TODO NOT IMPLEMENTED +${worldColors} //done ${tpsMedium} diff --git a/Plan/src/main/resources/html/player.html b/Plan/src/main/resources/html/player.html index 2dbf54b1d..43032594e 100644 --- a/Plan/src/main/resources/html/player.html +++ b/Plan/src/main/resources/html/player.html @@ -115,7 +115,7 @@

Server Preference

@@ -217,6 +217,7 @@ }; + diff --git a/Plan/src/main/resources/html/server.html b/Plan/src/main/resources/html/server.html index f8d52dbd3..cded1f89a 100644 --- a/Plan/src/main/resources/html/server.html +++ b/Plan/src/main/resources/html/server.html @@ -288,7 +288,8 @@
-

Command Usage

+

Command Usage

+

Unique Commands: ${commandUniqueCount} • Total Command Count: ${commandCount}