Network page sending,

Fixed SessionsTableCreator NPE related to Active sessions (No session ID)
Fixed NPE related to 0 analysis notifications
This commit is contained in:
Rsl1122 2017-09-26 18:00:48 +03:00
parent 9fa4839ee8
commit a091f0e9d5
12 changed files with 121 additions and 11 deletions

View File

@ -5,6 +5,7 @@ import com.djrapitops.plugin.command.CommandUtils;
import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.command.SubCommand; import com.djrapitops.plugin.command.SubCommand;
import com.djrapitops.plugin.task.AbsRunnable; 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.Log;
import main.java.com.djrapitops.plan.Permissions; import main.java.com.djrapitops.plan.Permissions;
import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.Plan;
@ -47,6 +48,9 @@ public class AnalyzeCommand extends SubCommand {
} }
public static void sendAnalysisMessage(Collection<ISender> senders, UUID serverUUID) throws SQLException { public static void sendAnalysisMessage(Collection<ISender> senders, UUID serverUUID) throws SQLException {
if (Verify.isEmpty(senders)) {
return;
}
Plan plugin = Plan.getInstance(); Plan plugin = Plan.getInstance();
Optional<String> serverName = plugin.getDB().getServerTable().getServerName(serverUUID); Optional<String> serverName = plugin.getDB().getServerTable().getServerName(serverUUID);
if (serverName.isPresent()) { if (serverName.isPresent()) {

View File

@ -91,7 +91,6 @@ public class IPsTable extends UserIDTable {
if (ips.contains(ip)) { if (ips.contains(ip)) {
return; return;
} }
insertIp(uuid, ip, geolocation); insertIp(uuid, ip, geolocation);
} }

View File

@ -279,4 +279,16 @@ public class BukkitInformationManager extends InformationManager {
} }
analysisNotification.getOrDefault(serverUUID, new HashSet<>()).clear(); 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();
}
}
}
} }

View File

@ -73,6 +73,9 @@ public class BungeeInformationManager extends InformationManager {
*/ */
@Override @Override
public void refreshAnalysis(UUID serverUUID) { public void refreshAnalysis(UUID serverUUID) {
if (PlanBungee.getServerUUID().equals(serverUUID)) {
return;
}
ServerInfo serverInfo = getOnlineServerInfo(serverUUID); ServerInfo serverInfo = getOnlineServerInfo(serverUUID);
if (serverInfo == null) { if (serverInfo == null) {
return; return;
@ -323,7 +326,7 @@ public class BungeeInformationManager extends InformationManager {
} }
public void removeNetworkPageContent(UUID serverUUID) { public void removeNetworkPageContent(UUID serverUUID) {
networkPageContent.remove(serverUUID); networkPageContent.put(serverUUID, HtmlStructure.parseOfflineServerContainer(networkPageContent.get(serverUUID)));
} }
public Map<UUID, String> getNetworkPageContent() { public Map<UUID, String> getNetworkPageContent() {
@ -346,4 +349,12 @@ public class BungeeInformationManager extends InformationManager {
} }
} }
} }
@Override
public void updateNetworkPageContent() {
Collection<ServerInfo> online = serverInfoManager.getOnlineBukkitServers();
bukkitServers.values().stream()
.filter(s -> !online.contains(s)).map(ServerInfo::getUuid)
.forEach(this::removeNetworkPageContent);
}
} }

View File

@ -87,4 +87,6 @@ public abstract class InformationManager {
} }
public abstract void analysisReady(UUID serverUUID); public abstract void analysisReady(UUID serverUUID);
public abstract void updateNetworkPageContent();
} }

View File

@ -4,6 +4,8 @@ import com.djrapitops.plugin.utilities.player.Fetch;
import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.data.Session; import main.java.com.djrapitops.plan.data.Session;
import main.java.com.djrapitops.plan.systems.cache.DataCache; 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.systems.processing.player.*;
import main.java.com.djrapitops.plan.utilities.MiscUtils; import main.java.com.djrapitops.plan.utilities.MiscUtils;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -98,7 +100,13 @@ public class PlanPlayerListener implements Listener {
new RegisterProcessor(uuid, player.getFirstPlayed(), time, playerName, playersOnline, new RegisterProcessor(uuid, player.getFirstPlayed(), time, playerName, playersOnline,
new IPUpdateProcessor(uuid, ip), new IPUpdateProcessor(uuid, ip),
new NameProcessor(uuid, playerName, displayName) new NameProcessor(uuid, playerName, displayName)
) ),
new Processor<InformationManager>(plugin.getInfoManager()) {
@Override
public void process() {
object.updateNetworkPageContent();
}
}
); );
} }

View File

@ -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<String, String> 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);
}
}

View File

@ -428,10 +428,18 @@ public class HtmlStructure {
} else { } else {
b.append("<a class=\"button disabled right\">Analysis</a>"); b.append("<a class=\"button disabled right\">Analysis</a>");
} }
// TODO Refresh functionality
b.append("</div>") b.append("</div>")
.append("</div>"); .append("</div>");
return b.toString(); return b.toString();
} }
public static String parseOfflineServerContainer(String oldContent) {
if (oldContent == null) {
return "";
}
String[] split = oldContent.split("<p>", 2);
String[] split2 = split[1].split("box-footer", 2);
return split[0] + "<p>Offline</p></div><div class=\"box-footer" + split2[1];
}
} }

View File

@ -49,12 +49,23 @@ public class SessionsTableCreator {
DataCache dataCache = Plan.getInstance().getDataCache(); DataCache dataCache = Plan.getInstance().getDataCache();
Map<Long, UUID> uuidBySessionStart = new HashMap<>();
for (Map.Entry<UUID, Session> entry : dataCache.getActiveSessions().entrySet()) {
uuidBySessionStart.put(entry.getValue().getSessionStart(), entry.getKey());
}
for (Session session : allSessions) { for (Session session : allSessions) {
if (i >= 50) { if (i >= 50) {
break; 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 name = dataCache.getName(uuid);
String start = FormatUtils.formatTimeStamp(session.getSessionStart()); String start = FormatUtils.formatTimeStamp(session.getSessionStart());

View File

@ -97,8 +97,8 @@ ${killCount} num
${mobKillCount} num ${mobKillCount} num
${deathCount} num ${deathCount} num
${commandCount} num //TODO ${commandCount} num
${commandUniqueCount} num //TODO ${commandUniqueCount} num
//done //done
${tpsAverageDay} num ${tpsAverageDay} num
@ -131,7 +131,7 @@ ${punchCardSeries}
${playersGraphColor} // done ${playersGraphColor} // done
${gmColors} // TODO Move to World Graph ${gmColors}
// done // done
${active} ${active}
@ -141,7 +141,7 @@ ${banned}
${activityColors} ${activityColors}
${worldTotal} timeamount //done ${worldTotal} timeamount //done
${worldColors} //TODO NOT IMPLEMENTED ${worldColors}
//done //done
${tpsMedium} ${tpsMedium}

View File

@ -115,7 +115,7 @@
<h2><i class="fa fa-pie-chart" aria-hidden="true"></i> Server Preference</h2> <h2><i class="fa fa-pie-chart" aria-hidden="true"></i> Server Preference</h2>
</div> </div>
<div class="box-footer"> <div class="box-footer">
<div id="serverPie" style="width: 75%; height: 400px;"></div> <div id="serverPie" style="width: 100%; height: 300px;"></div>
</div> </div>
</div> </div>
</div> </div>
@ -217,6 +217,7 @@
}; };
</script> </script>
<script> <script>
var navButtons = document.getElementsByClassName("nav-button"); var navButtons = document.getElementsByClassName("nav-button");
@ -270,6 +271,7 @@
</script> </script>
</div> </div>
</body> </body>

View File

@ -288,7 +288,8 @@
<div id="tab-command-usage" class="tab"> <div id="tab-command-usage" class="tab">
<div class="column"> <div class="column">
<div class="box-header"> <div class="box-header">
<h2><i class="fa fa-terminal"></i> Command Usage</h2> <h2 style="padding: 2px; margin: 0px;"><i class="fa fa-terminal"></i> Command Usage</h2>
<p style="padding: 2px; margin: 0px;">Unique Commands: ${commandUniqueCount} &#x2022; Total Command Count: ${commandCount}</p>
</div> </div>
<div class="box-footer scrollbar" style="padding: 2px;"> <div class="box-footer scrollbar" style="padding: 2px;">
<table class="sortable table"> <table class="sortable table">
@ -447,6 +448,8 @@
}; };
</script> </script>
<script> <script>
var navButtons = document.getElementsByClassName("nav-button"); var navButtons = document.getElementsByClassName("nav-button");
@ -504,6 +507,8 @@
} }
</script> </script>
</div> </div>
</body> </body>