mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-03-10 13:49:17 +01:00
parent
c8126cf7d3
commit
2143736978
@ -7,6 +7,7 @@ import main.java.com.djrapitops.plan.utilities.Benchmark;
|
||||
import main.java.com.djrapitops.plan.utilities.HtmlUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -40,7 +41,7 @@ public class AnalysisData extends RawData {
|
||||
private long refreshDate;
|
||||
private String planVersion;
|
||||
private String pluginsTabLayout;
|
||||
private Map<String, String> additionalDataReplaceMap;
|
||||
private Map<String, Serializable> additionalDataReplaceMap;
|
||||
private String playersTable;
|
||||
|
||||
public AnalysisData(Map<String, Integer> commandUsage, List<TPS> tpsData) {
|
||||
@ -118,11 +119,11 @@ public class AnalysisData extends RawData {
|
||||
this.pluginsTabLayout = pluginsTabLayout;
|
||||
}
|
||||
|
||||
public Map<String, String> getAdditionalDataReplaceMap() {
|
||||
public Map<String, Serializable> getAdditionalDataReplaceMap() {
|
||||
return additionalDataReplaceMap;
|
||||
}
|
||||
|
||||
public void setAdditionalDataReplaceMap(Map<String, String> additionalDataReplaceMap) {
|
||||
public void setAdditionalDataReplaceMap(Map<String, Serializable> additionalDataReplaceMap) {
|
||||
this.additionalDataReplaceMap = additionalDataReplaceMap;
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.utilities.HtmlUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -155,8 +156,8 @@ public class HookHandler {
|
||||
* @param uuid UUID of the player whose page is being inspected.
|
||||
* @return Map: key|value - %placeholder%|value
|
||||
*/
|
||||
public Map<String, String> getAdditionalInspectReplaceRules(UUID uuid) {
|
||||
Map<String, String> addReplace = new HashMap<>();
|
||||
public Map<String, Serializable> getAdditionalInspectReplaceRules(UUID uuid) {
|
||||
Map<String, Serializable> addReplace = new HashMap<>();
|
||||
for (PluginData source : additionalDataSources) {
|
||||
if (source.analysisOnly()) {
|
||||
continue;
|
||||
|
@ -144,6 +144,7 @@ public class DataCacheHandler extends SessionCache {
|
||||
}
|
||||
try {
|
||||
periodicTaskIsSaving = true;
|
||||
Log.debug("Database", "Periodic Cache Save");
|
||||
handler.saveHandlerDataToCache();
|
||||
handler.saveCachedUserData();
|
||||
if (timesSaved % clearAfterXsaves == 0) {
|
||||
@ -340,6 +341,7 @@ public class DataCacheHandler extends SessionCache {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Log.debug("Database", "Periodic TPS Save");
|
||||
db.getTpsTable().saveTPSData(averages);
|
||||
} catch (SQLException ex) {
|
||||
Log.toLog(this.getClass().getName(), ex);
|
||||
|
@ -180,6 +180,7 @@ public abstract class SQLDB extends Database {
|
||||
public void run() {
|
||||
try {
|
||||
Benchmark.start("Convert BukkitData to DB data");
|
||||
Log.debug("Database", "Bukkit Data Conversion");
|
||||
Set<UUID> uuids = usersTable.getSavedUUIDs();
|
||||
uuids.removeAll(usersTable.getContainsBukkitData(uuids));
|
||||
if (uuids.isEmpty()) {
|
||||
@ -410,15 +411,15 @@ public abstract class SQLDB extends Database {
|
||||
Map<Integer, Map<String, Long>> worldTimes = worldTimesTable.getWorldTimes(ids);
|
||||
|
||||
Log.debug("Database", "Data found for:");
|
||||
Log.debug("Database", "UUIDs: " + uuids.size());
|
||||
Log.debug("Database", "IDs: " + userIds.size());
|
||||
Log.debug("Database", "UserData: " + data.size());
|
||||
Log.debug("Database", " Nicknames: " + nicknames.size());
|
||||
Log.debug("Database", " IPs: " + ipList.size());
|
||||
Log.debug("Database", " Kills: " + playerKills.size());
|
||||
Log.debug("Database", " Sessions: " + sessionData.size());
|
||||
Log.debug("Database", " GM Times: " + gmTimes.size());
|
||||
Log.debug("Database", " World Times: " + worldTimes.size());
|
||||
Log.debug("Database", " UUIDs: " + uuids.size());
|
||||
Log.debug("Database", " IDs: " + userIds.size());
|
||||
Log.debug("Database", " UserData: " + data.size());
|
||||
Log.debug("Database", " Nicknames: " + nicknames.size());
|
||||
Log.debug("Database", " IPs: " + ipList.size());
|
||||
Log.debug("Database", " Kills: " + playerKills.size());
|
||||
Log.debug("Database", " Sessions: " + sessionData.size());
|
||||
Log.debug("Database", " GM Times: " + gmTimes.size());
|
||||
Log.debug("Database", " World Times: " + worldTimes.size());
|
||||
|
||||
for (UserData uData : data) {
|
||||
UUID uuid = uData.getUuid();
|
||||
|
@ -8,6 +8,7 @@ import main.java.com.djrapitops.plan.ui.webserver.WebServer;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
@ -59,10 +60,10 @@ public class HtmlUtils {
|
||||
* @param replaceMap
|
||||
* @return
|
||||
*/
|
||||
public static String replacePlaceholders(String html, Map<String, String> replaceMap) {
|
||||
for (Map.Entry<String, String> entrySet : replaceMap.entrySet()) {
|
||||
public static String replacePlaceholders(String html, Map<String, Serializable> replaceMap) {
|
||||
for (Map.Entry<String, Serializable> entrySet : replaceMap.entrySet()) {
|
||||
String placeholder = entrySet.getKey();
|
||||
String replacer = entrySet.getValue();
|
||||
String replacer = entrySet.getValue().toString();
|
||||
|
||||
html = html.replace(placeholder, replacer);
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package main.java.com.djrapitops.plan.utilities;
|
||||
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import com.djrapitops.plugin.command.CommandUtils;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.utilities.player.Fetch;
|
||||
@ -12,6 +13,7 @@ import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@ -38,6 +40,10 @@ public class MiscUtils {
|
||||
return System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public static int getTimeZoneOffsetHours() {
|
||||
return TimeZone.getDefault().getOffset(MiscUtils.getTime()) / (int) TimeAmount.HOUR.ms();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args
|
||||
* @param sender
|
||||
|
@ -17,6 +17,7 @@ import main.java.com.djrapitops.plan.ui.html.tables.KillsTableCreator;
|
||||
import main.java.com.djrapitops.plan.utilities.analysis.AnalysisUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.analysis.MathUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@ -32,14 +33,14 @@ public class PlaceholderUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the HashMap that is used to replace placeholders in Analysis.
|
||||
* Gets the Map that is used to replace placeholders in Analysis.
|
||||
*
|
||||
* @param data AnalysisData used to replace the placeholders with
|
||||
* @return HashMap that contains string for each placeholder.
|
||||
*/
|
||||
public static Map<String, String> getAnalysisReplaceRules(AnalysisData data) {
|
||||
public static Map<String, Serializable> getAnalysisReplaceRules(AnalysisData data) {
|
||||
Benchmark.start("Replace Placeholders Analysis");
|
||||
HashMap<String, String> replaceMap = new HashMap<>();
|
||||
HashMap<String, Serializable> replaceMap = new HashMap<>();
|
||||
replaceMap.putAll(data.getReplaceMap());
|
||||
replaceMap.put("%plugins%", data.replacePluginsTabLayout());
|
||||
|
||||
@ -48,6 +49,8 @@ public class PlaceholderUtils {
|
||||
|
||||
replaceMap.put("%servername%", Settings.SERVER_NAME.toString());
|
||||
|
||||
replaceMap.put("%timezone%", MiscUtils.getTimeZoneOffsetHours());
|
||||
|
||||
// Html Theme colors
|
||||
String[] colors = new String[]{Settings.HCOLOR_MAIN.toString(), Settings.HCOLOR_MAIN_DARK.toString(), Settings.HCOLOR_SEC.toString(), Settings.HCOLOR_TER.toString(), Settings.HCOLOR_TER_DARK.toString()};
|
||||
String[] defaultCols = new String[]{"348e0f", "267F00", "5cb239", "89c471", "5da341"};
|
||||
@ -61,20 +64,22 @@ public class PlaceholderUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the HashMap that is used to replace placeholders.
|
||||
* Gets the Map that is used to replace placeholders.
|
||||
*
|
||||
* @param data UserData used to replace the placeholders with
|
||||
* @return HashMap that contains string for each placeholder.
|
||||
*/
|
||||
public static Map<String, String> getInspectReplaceRules(UserData data) {
|
||||
public static Map<String, Serializable> getInspectReplaceRules(UserData data) {
|
||||
Benchmark.start("Replace Placeholders Inspect");
|
||||
|
||||
HashMap<String, String> replaceMap = new HashMap<>();
|
||||
HashMap<String, Serializable> replaceMap = new HashMap<>();
|
||||
replaceMap.put("%timezone%", MiscUtils.getTimeZoneOffsetHours());
|
||||
|
||||
boolean showIPandUUID = Settings.SECURITY_IP_UUID.isTrue();
|
||||
UUID uuid = data.getUuid();
|
||||
replaceMap.put("%uuid%", (showIPandUUID ? String.valueOf(uuid) : Html.HIDDEN.parse()));
|
||||
replaceMap.put("%uuid%", (showIPandUUID ? uuid.toString() : Html.HIDDEN.parse()));
|
||||
replaceMap.put("%lastseen%", FormatUtils.formatTimeStampYear(data.getLastPlayed()));
|
||||
replaceMap.put("%logintimes%", String.valueOf(data.getLoginTimes()));
|
||||
replaceMap.put("%logintimes%", data.getLoginTimes());
|
||||
replaceMap.put("%geoloc%", data.getGeolocation());
|
||||
long now = MiscUtils.getTime();
|
||||
boolean isActive = AnalysisUtils.isActive(now, data.getLastPlayed(), data.getPlayTime(), data.getLoginTimes());
|
||||
@ -100,9 +105,9 @@ public class PlaceholderUtils {
|
||||
replaceMap.put("%banned%", data.isBanned() ? Html.BANNED.parse() : "");
|
||||
replaceMap.put("%op%", data.isOp() ? Html.OPERATOR.parse() : "");
|
||||
replaceMap.put("%isonline%", (data.isOnline()) ? Html.ONLINE.parse() : Html.OFFLINE.parse());
|
||||
replaceMap.put("%deaths%", String.valueOf(data.getDeaths()));
|
||||
replaceMap.put("%playerkills%", String.valueOf(data.getPlayerKills().size()));
|
||||
replaceMap.put("%mobkills%", String.valueOf(data.getMobKills()));
|
||||
replaceMap.put("%deaths%", data.getDeaths());
|
||||
replaceMap.put("%playerkills%", data.getPlayerKills().size());
|
||||
replaceMap.put("%mobkills%", data.getMobKills());
|
||||
replaceMap.put("%sessionaverage%", FormatUtils.formatTimeAmount(MathUtils.averageLong(AnalysisUtils.transformSessionDataToLengths(data.getSessions()))));
|
||||
replaceMap.put("%killstable%", KillsTableCreator.createKillsTable(data.getPlayerKills()));
|
||||
Plan plugin = Plan.getInstance();
|
||||
@ -127,10 +132,10 @@ public class PlaceholderUtils {
|
||||
}
|
||||
long cacheTime = plugin.getInspectCache().getCacheTime(uuid);
|
||||
replaceMap.put("%refresh%", FormatUtils.formatTimeAmountDifference(cacheTime, now));
|
||||
replaceMap.put("%refreshlong%", String.valueOf(cacheTime));
|
||||
replaceMap.put("%refreshlong%", cacheTime);
|
||||
replaceMap.put("%servername%", Settings.SERVER_NAME.toString());
|
||||
String pluginsTabHtml = plugin.getHookHandler().getPluginsTabLayoutForInspect();
|
||||
Map<String, String> additionalReplaceRules = plugin.getHookHandler().getAdditionalInspectReplaceRules(uuid);
|
||||
Map<String, Serializable> additionalReplaceRules = plugin.getHookHandler().getAdditionalInspectReplaceRules(uuid);
|
||||
String replacedOnce = HtmlUtils.replacePlaceholders(pluginsTabHtml, additionalReplaceRules);
|
||||
replaceMap.put("%plugins%", HtmlUtils.replacePlaceholders(replacedOnce, additionalReplaceRules));
|
||||
Benchmark.stop("Replace Placeholders Inspect");
|
||||
|
@ -181,9 +181,9 @@ public class Analysis {
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, String> analyzeAdditionalPluginData(List<UUID> uuids) {
|
||||
private Map<String, Serializable> analyzeAdditionalPluginData(List<UUID> uuids) {
|
||||
Benchmark.start("3rd party");
|
||||
final Map<String, String> replaceMap = new HashMap<>();
|
||||
final Map<String, Serializable> replaceMap = new HashMap<>();
|
||||
final HookHandler hookHandler = plugin.getHookHandler();
|
||||
final List<PluginData> sources = hookHandler.getAdditionalDataSources().stream()
|
||||
.filter(p -> !p.isBanData())
|
||||
|
@ -674,6 +674,11 @@
|
||||
<script src="https://code.highcharts.com/maps/modules/map.js"></script>
|
||||
<script src="https://code.highcharts.com/mapdata/custom/world.js"></script>
|
||||
<script>
|
||||
Highcharts.setOptions({
|
||||
global: {
|
||||
timezoneOffset: %timezone% * 60
|
||||
}
|
||||
});
|
||||
// Data Variables
|
||||
var playersOnlineSeries = {
|
||||
name: 'Players Online',
|
||||
|
@ -490,6 +490,11 @@
|
||||
<script src="https://www.kryogenix.org/code/browser/sorttable/sorttable.js"></script>
|
||||
<script src="https://code.highcharts.com/stock/highstock.js"></script>
|
||||
<script>
|
||||
Highcharts.setOptions({
|
||||
global: {
|
||||
timezoneOffset: %timezone% * 60
|
||||
}
|
||||
});
|
||||
function formatTime(seconds) {
|
||||
var out = "";
|
||||
seconds = Math.floor(seconds / 1000);
|
||||
|
@ -14,7 +14,9 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import test.java.utils.TestInit;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@ -56,7 +58,7 @@ public class HtmlUtilsTest {
|
||||
@Test
|
||||
public void testReplacePlaceholders() {
|
||||
String html = "%test%";
|
||||
HashMap<String, String> replaceMap = new HashMap<>();
|
||||
Map<String, Serializable> replaceMap = new HashMap<>();
|
||||
replaceMap.put("%test%", "Success");
|
||||
String expResult = "Success";
|
||||
String result = HtmlUtils.replacePlaceholders(html, replaceMap);
|
||||
@ -68,7 +70,7 @@ public class HtmlUtilsTest {
|
||||
*/
|
||||
@Test
|
||||
public void testReplacePlaceholdersBackslash() {
|
||||
HashMap<String, String> replace = new HashMap<>();
|
||||
Map<String, Serializable> replace = new HashMap<>();
|
||||
replace.put("%test%", "/\\");
|
||||
String result = HtmlUtils.replacePlaceholders("%test% alright %test%", replace);
|
||||
String exp = "/\\ alright /\\";
|
||||
|
Loading…
Reference in New Issue
Block a user