Fixed Compile errors, added TODOs for the new Plugin section parsing

This commit is contained in:
Rsl1122 2017-11-26 11:27:16 +02:00
parent 8065d21ee1
commit 973076bb55
11 changed files with 61 additions and 469 deletions

View File

@ -3,6 +3,8 @@ package main.java.com.djrapitops.plan.data;
import com.djrapitops.plugin.api.TimeAmount;
import com.google.common.base.Objects;
import main.java.com.djrapitops.plan.Settings;
import main.java.com.djrapitops.plan.data.additional.AnalysisContainer;
import main.java.com.djrapitops.plan.data.additional.PluginData;
import main.java.com.djrapitops.plan.data.time.WorldTimes;
import main.java.com.djrapitops.plan.database.tables.Actions;
import main.java.com.djrapitops.plan.systems.webserver.theme.Colors;
@ -14,11 +16,11 @@ import main.java.com.djrapitops.plan.utilities.comparators.SessionStartComparato
import main.java.com.djrapitops.plan.utilities.html.Html;
import main.java.com.djrapitops.plan.utilities.html.HtmlUtils;
import main.java.com.djrapitops.plan.utilities.html.graphs.*;
import main.java.com.djrapitops.plan.utilities.html.structure.AnalysisPluginsTabContentCreator;
import main.java.com.djrapitops.plan.utilities.html.structure.SessionTabStructureCreator;
import main.java.com.djrapitops.plan.utilities.html.tables.CommandUseTableCreator;
import main.java.com.djrapitops.plan.utilities.html.tables.SessionsTableCreator;
import java.io.Serializable;
import java.util.*;
import java.util.stream.Collectors;
@ -39,8 +41,6 @@ import java.util.stream.Collectors;
public class AnalysisData extends RawData {
private long refreshDate;
private String pluginsTabLayout;
private Map<String, Serializable> additionalDataReplaceMap;
private Map<String, Long> analyzedValues;
private Set<StickyData> stickyMonthData;
@ -50,12 +50,10 @@ public class AnalysisData extends RawData {
stickyMonthData = new HashSet<>();
}
public void setPluginsTabLayout(String pluginsTabLayout) {
this.pluginsTabLayout = pluginsTabLayout;
}
public void setAdditionalDataReplaceMap(Map<String, Serializable> additionalDataReplaceMap) {
this.additionalDataReplaceMap = additionalDataReplaceMap;
public void parsePluginsSection(Map<PluginData, AnalysisContainer> containers) {
String[] navAndTabs = AnalysisPluginsTabContentCreator.createContent(containers);
addValue("navPluginsTabs", navAndTabs[0]);
addValue("tabsPlugins", navAndTabs[1]);
}
private void addConstants() {
@ -78,10 +76,6 @@ public class AnalysisData extends RawData {
addValue("playersOnline", ServerProfile.getPlayersOnline());
}
public String replacePluginsTabLayout() {
return HtmlUtils.replacePlaceholders(pluginsTabLayout, additionalDataReplaceMap);
}
public long getRefreshDate() {
return refreshDate;
}

View File

@ -3,11 +3,9 @@ package main.java.com.djrapitops.plan.data.additional;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.pluginbridge.plan.Bridge;
import main.java.com.djrapitops.plan.Plan;
import org.apache.commons.lang3.StringUtils;
import java.io.Serializable;
import java.util.*;
import java.util.stream.Collectors;
import java.util.ArrayList;
import java.util.List;
/**
* Class responsible for hooking to other plugins and managing the %plugins%
@ -48,12 +46,15 @@ public class HookHandler {
* @param dataSource an object extending the PluginData class.
*/
public void addPluginDataSource(PluginData dataSource) {
if (dataSource == null) {
return;
}
try {
if (!configHandler.hasSection(dataSource)) {
configHandler.createSection(dataSource);
}
if (configHandler.isEnabled(dataSource)) {
Log.debug("Registered a new datasource: " + StringUtils.remove(dataSource.getPlaceholder(), '%'));
Log.debug("Registered a new datasource: " + dataSource.getSourcePlugin());
additionalDataSources.add(dataSource);
}
} catch (Exception e) {
@ -70,47 +71,4 @@ public class HookHandler {
public List<PluginData> getAdditionalDataSources() {
return additionalDataSources;
}
private List<String> getPluginNamesAnalysis() {
List<String> pluginNames = additionalDataSources.stream()
.filter(source -> !source.getAnalysisTypes().isEmpty())
.map(PluginData::getSourcePlugin)
.distinct()
.collect(Collectors.toList());
Collections.sort(pluginNames);
return pluginNames;
}
private List<String> getPluginNamesInspect() {
List<String> pluginNames = additionalDataSources.stream()
.filter(source -> !source.analysisOnly())
.map(PluginData::getSourcePlugin)
.distinct()
.collect(Collectors.toList());
Collections.sort(pluginNames);
return pluginNames;
}
/**
* Used to get the replaceMap for inspect page.
*
* @param uuid UUID of the player whose page is being inspected.
* @return Map: key|value - %placeholder%|value
*/
public Map<String, Serializable> getAdditionalInspectReplaceRules(UUID uuid) {
Map<String, Serializable> addReplace = new HashMap<>();
for (PluginData source : additionalDataSources) {
if (source.analysisOnly()) {
continue;
}
try {
addReplace.put(source.getPlaceholderName(), source.getHtmlReplaceValue("", uuid));
} catch (Exception e) {
addReplace.put(source.getPlaceholderName(), "Error occurred: " + e);
Log.error("PluginDataSource caused an exception: " + source.getSourcePlugin());
Log.toLog("PluginDataSource " + source.getSourcePlugin(), e);
}
}
return addReplace;
}
}

View File

@ -24,12 +24,7 @@ public class PluginConfigSectionHandler {
public boolean hasSection(PluginData dataSource) {
ConfigNode section = getPluginsSection();
String pluginName = dataSource.getSourcePlugin();
if (!section.getChildren().containsKey(pluginName)) {
return false;
}
ConfigNode pluginSection = section.getConfigNode(pluginName + ".Data");
return pluginSection.getChildren().containsKey(dataSource.placeholder);
return section.getChildren().containsKey(pluginName);
}
private ConfigNode getPluginsSection() {
@ -39,10 +34,8 @@ public class PluginConfigSectionHandler {
public void createSection(PluginData dataSource) {
ConfigNode section = getPluginsSection();
String pluginName = dataSource.getSourcePlugin();
String source = dataSource.placeholder;
section.set(pluginName + ".Enabled", true);
section.set(pluginName + ".Data." + source, true);
try {
section.sort();
section.save();
@ -55,11 +48,6 @@ public class PluginConfigSectionHandler {
ConfigNode section = getPluginsSection();
String pluginName = dataSource.getSourcePlugin();
if (!section.getBoolean(pluginName + ".Enabled")) {
return false;
}
String source = dataSource.placeholder;
return section.getBoolean(pluginName + ".Data." + source);
return section.getBoolean(pluginName + ".Enabled");
}
}

View File

@ -32,7 +32,6 @@ import main.java.com.djrapitops.plan.utilities.analysis.Analysis;
import main.java.com.djrapitops.plan.utilities.html.HtmlStructure;
import java.io.IOException;
import java.io.Serializable;
import java.sql.SQLException;
import java.util.*;
@ -132,9 +131,10 @@ public class BukkitInformationManager extends InformationManager {
String serverName = plugin.getServerInfoManager().getServerName();
HookHandler hookHandler = plugin.getHookHandler();
List<PluginData> plugins = hookHandler.getAdditionalDataSources();
Map<String, Serializable> replaceMap = hookHandler.getAdditionalInspectReplaceRules(uuid);
String contents = HtmlStructure.createInspectPluginsTabContent(serverName, plugins, replaceMap);
cacheInspectPluginsTab(uuid, contents);
// TODO Inspect Plugins Tab
// Map<String, Serializable> replaceMap = hookHandler.getAdditionalInspectReplaceRules(uuid);
// String contents = HtmlStructure.createInspectPluginsTabContent(serverName, plugins, replaceMap);
cacheInspectPluginsTab(uuid, "");
}
}

View File

@ -33,7 +33,6 @@ public class AnalysisPageParser extends PageParser {
@Override
public String parse() throws ParseException {
addValues(data.getReplaceMap());
addValue("tabContentPlugins", data.replacePluginsTabLayout());
try {
return HtmlUtils.replacePlaceholders(FileUtil.getStringFromResource("web/server.html"), placeHolders);

View File

@ -5,12 +5,11 @@ import com.djrapitops.plugin.api.Benchmark;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.task.RunnableFactory;
import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.Settings;
import main.java.com.djrapitops.plan.data.AnalysisData;
import main.java.com.djrapitops.plan.data.ServerProfile;
import main.java.com.djrapitops.plan.data.additional.HookHandler;
import main.java.com.djrapitops.plan.data.additional.AnalysisContainer;
import main.java.com.djrapitops.plan.data.additional.PluginData;
import main.java.com.djrapitops.plan.database.Database;
import main.java.com.djrapitops.plan.locale.Locale;
@ -19,12 +18,8 @@ import main.java.com.djrapitops.plan.systems.info.BukkitInformationManager;
import main.java.com.djrapitops.plan.systems.info.InformationManager;
import main.java.com.djrapitops.plan.systems.webserver.response.ErrorResponse;
import main.java.com.djrapitops.plan.systems.webserver.response.InternalErrorResponse;
import main.java.com.djrapitops.plan.utilities.html.HtmlStructure;
import org.apache.commons.lang3.StringUtils;
import java.io.Serializable;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author Rsl1122
@ -107,14 +102,14 @@ public class Analysis {
Benchmark.start("Create Empty dataset");
AnalysisData analysisData = new AnalysisData();
List<PluginData> thirdPartyPlugins = plugin.getHookHandler().getAdditionalDataSources();
analysisData.setPluginsTabLayout(HtmlStructure.createAnalysisPluginsTabLayout(thirdPartyPlugins));
Benchmark.stop("Analysis", "Create Empty dataset");
Benchmark.start("Fetch Phase");
ServerProfile profile = db.getServerProfile(Plan.getServerUUID());
long fetchPhaseLength = Benchmark.stop("Analysis", "Fetch Phase");
// TODO BanData (PluginData) effects
Benchmark.start("Analysis Phase");
Log.logDebug("Analysis", "Analysis Phase");
@ -126,7 +121,7 @@ public class Analysis {
log(Locale.get(Msg.ANALYSIS_3RD_PARTY).toString());
Log.logDebug("Analysis", "Analyzing additional data sources (3rd party)");
analysisData.setAdditionalDataReplaceMap(analyzeAdditionalPluginData(profile.getUuids()));
analysisData.parsePluginsSection(analyzeAdditionalPluginData(profile.getUuids()));
((BukkitInformationManager) infoManager).cacheAnalysisData(analysisData);
// TODO Export
@ -150,68 +145,32 @@ public class Analysis {
}
}
private Map<String, Serializable> analyzeAdditionalPluginData(Set<UUID> uuids) {
private Map<PluginData, AnalysisContainer> analyzeAdditionalPluginData(Set<UUID> uuids) {
Map<PluginData, AnalysisContainer> containers = new HashMap<>();
Benchmark.start("Analysis", "3rd party Analysis");
final Map<String, Serializable> replaceMap = new HashMap<>();
final HookHandler hookHandler = plugin.getHookHandler();
final List<PluginData> sources = hookHandler.getAdditionalDataSources().stream()
.filter(p -> !p.isBanData())
.filter(p -> !p.getAnalysisTypes().isEmpty())
.collect(Collectors.toList());
final AnalysisType[] totalTypes = new AnalysisType[]{
AnalysisType.INT_TOTAL, AnalysisType.LONG_TOTAL, AnalysisType.LONG_TIME_MS_TOTAL, AnalysisType.DOUBLE_TOTAL
};
final AnalysisType[] avgTypes = new AnalysisType[]{
AnalysisType.INT_AVG, AnalysisType.LONG_AVG, AnalysisType.LONG_TIME_MS_AVG, AnalysisType.LONG_EPOCH_MS_MINUS_NOW_AVG, AnalysisType.DOUBLE_AVG
};
final AnalysisType bool = AnalysisType.BOOLEAN_PERCENTAGE;
final AnalysisType boolTot = AnalysisType.BOOLEAN_TOTAL;
List<PluginData> sources = plugin.getHookHandler().getAdditionalDataSources();
Log.logDebug("Analysis", "Additional Sources: " + sources.size());
sources.parallelStream().filter(Verify::notNull).forEach(source -> {
sources.parallelStream().forEach(source -> {
StaticHolder.saveInstance(this.getClass(), plugin.getClass());
try {
Benchmark.start("Analysis", "Source " + source.getPlaceholder());
final List<AnalysisType> analysisTypes = source.getAnalysisTypes();
if (analysisTypes.isEmpty()) {
return;
}
if (analysisTypes.contains(AnalysisType.HTML)) {
String html = source.getHtmlReplaceValue(AnalysisType.HTML.getModifier(), UUID.randomUUID());
String placeholderName = source.getPlaceholderName(AnalysisType.HTML.getPlaceholderModifier());
int length = html.length();
if (length < 20000) {
replaceMap.put(placeholderName, html);
} else {
replaceMap.put(placeholderName, "<p>Html was removed because it contained too many characters to be responsive (" + length + "/20000)</p>");
}
return;
}
for (AnalysisType type : totalTypes) {
if (analysisTypes.contains(type)) {
replaceMap.put(source.getPlaceholderName(type.getPlaceholderModifier()), AnalysisUtils.getTotal(type, source, uuids));
}
}
for (AnalysisType type : avgTypes) {
if (analysisTypes.contains(type)) {
replaceMap.put(source.getPlaceholderName(type.getPlaceholderModifier()), AnalysisUtils.getAverage(type, source, uuids));
}
}
if (analysisTypes.contains(bool)) {
replaceMap.put(source.getPlaceholderName(bool.getPlaceholderModifier()), AnalysisUtils.getBooleanPercentage(bool, source, uuids));
}
if (analysisTypes.contains(boolTot)) {
replaceMap.put(source.getPlaceholderName(boolTot.getPlaceholderModifier()), AnalysisUtils.getBooleanTotal(boolTot, source, uuids));
}
} catch (Exception | NoClassDefFoundError | NoSuchFieldError | NoSuchMethodError e) {
Log.error("A PluginData-source caused an exception: " + StringUtils.remove(source.getPlaceholder(), '%'));
Benchmark.start("Analysis", "Source " + source.getSourcePlugin());
AnalysisContainer container = source.getServerData(uuids, new AnalysisContainer());
if (container != null) {
containers.put(source, container);
}
} catch (Exception | NoClassDefFoundError | NoSuchFieldError | NoSuchMethodError e) {
Log.error("A PluginData-source caused an exception: " + source.getSourcePlugin());
Log.toLog(this.getClass().getName(), e);
} finally {
Benchmark.stop("Analysis", "Source " + source.getPlaceholder());
Benchmark.stop("Analysis", "Source " + source.getSourcePlugin());
}
});
Benchmark.stop("Analysis", "3rd party Analysis");
return replaceMap;
return containers;
}
/**

View File

@ -4,19 +4,14 @@ import com.djrapitops.plugin.api.TimeAmount;
import com.djrapitops.plugin.api.utility.log.Log;
import main.java.com.djrapitops.plan.api.IPlan;
import main.java.com.djrapitops.plan.data.Session;
import main.java.com.djrapitops.plan.data.additional.PluginData;
import main.java.com.djrapitops.plan.data.time.GMTimes;
import main.java.com.djrapitops.plan.data.time.WorldTimes;
import main.java.com.djrapitops.plan.utilities.FormatUtils;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
import main.java.com.djrapitops.plan.utilities.comparators.SessionLengthComparator;
import org.apache.commons.lang3.StringUtils;
import java.io.Serializable;
import java.sql.SQLException;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* @author Rsl1122
@ -60,113 +55,6 @@ public class AnalysisUtils {
.collect(Collectors.toList());
}
public static String getTotal(AnalysisType analysisType, PluginData source, Collection<UUID> uuids) {
if (analysisType == null) {
return source.parseContainer("Err ", "Null Analysistype. ");
}
try {
Number total;
switch (analysisType) {
case INT_TOTAL:
total = MathUtils.sumInt(getCorrectValues(uuids, source));
break;
case LONG_TOTAL:
total = MathUtils.sumLong(getCorrectValues(uuids, source));
break;
case LONG_TIME_MS_TOTAL:
total = MathUtils.sumLong(getCorrectValues(uuids, source));
return source.parseContainer(analysisType.getModifier(), FormatUtils.formatTimeAmount((long) total));
case DOUBLE_TOTAL:
total = MathUtils.sumDouble(getCorrectValues(uuids, source));
break;
default:
return source.parseContainer("", "Wrong Analysistype specified: " + analysisType.name());
}
return source.parseContainer(analysisType.getModifier(), String.valueOf(total));
} catch (Exception | NoClassDefFoundError | NoSuchFieldError e) {
return logPluginDataCausedError(source, e);
}
}
private static Stream<Serializable> getCorrectValues(Collection<UUID> uuids, PluginData source) {
return uuids.stream()
.map(source::getValue)
.filter(value -> !value.equals(-1))
.filter(value -> !value.equals(-1L));
}
public static String getAverage(AnalysisType analysisType, PluginData source, Collection<UUID> uuids) {
if (analysisType == null) {
return source.parseContainer("Err ", "Null Analysistype. ");
}
try {
double average;
switch (analysisType) {
case LONG_EPOCH_MS_MINUS_NOW_AVG:
final long now = MiscUtils.getTime();
average = MathUtils.averageLong(getCorrectValues(uuids, source).map(value -> ((long) value) - now));
return source.parseContainer(analysisType.getModifier(), FormatUtils.formatTimeAmount((long) average));
case LONG_AVG:
long averageLong = MathUtils.averageLong(getCorrectValues(uuids, source).map(i -> (Long) i));
return source.parseContainer(analysisType.getModifier(), String.valueOf(averageLong));
case LONG_TIME_MS_AVG:
average = MathUtils.averageLong(getCorrectValues(uuids, source).map(i -> (Long) i));
return source.parseContainer(analysisType.getModifier(), FormatUtils.formatTimeAmount((long) average));
case INT_AVG:
average = MathUtils.averageInt(getCorrectValues(uuids, source).map(i -> (Integer) i));
break;
case DOUBLE_AVG:
average = MathUtils.averageDouble(getCorrectValues(uuids, source).map(i -> (Double) i));
break;
default:
return source.parseContainer("Err ", "Wrong Analysistype specified: " + analysisType.name());
}
return source.parseContainer(analysisType.getModifier(), FormatUtils.cutDecimals(average));
} catch (Exception | NoClassDefFoundError | NoSuchFieldError e) {
return logPluginDataCausedError(source, e);
}
}
public static String getBooleanPercentage(AnalysisType analysisType, PluginData source, Collection<UUID> uuids) {
if (analysisType != AnalysisType.BOOLEAN_PERCENTAGE) {
return source.parseContainer("Err ", "Wrong Analysistype specified: " + analysisType.name());
}
try {
List<Boolean> tempList = getCorrectValues(uuids, source)
.map(value -> (boolean) value)
.collect(Collectors.toList());
long count = tempList.stream().filter(value -> value).count();
return source.parseContainer(analysisType.getModifier(), (((double) count / tempList.size()) * 100) + "%");
} catch (Exception | NoClassDefFoundError | NoSuchFieldError e) {
return logPluginDataCausedError(source, e);
}
}
public static String getBooleanTotal(AnalysisType analysisType, PluginData source, Collection<UUID> uuids) {
if (analysisType != AnalysisType.BOOLEAN_TOTAL) {
return source.parseContainer("Err ", "Wrong Analysistype specified: " + analysisType.name());
}
try {
List<Boolean> tempList = getCorrectValues(uuids, source)
.map(value -> (boolean) value)
.collect(Collectors.toList());
long count = tempList.stream().filter(value -> value).count();
return source.parseContainer(analysisType.getModifier(), count + " / " + tempList.size());
} catch (Exception e) {
return logPluginDataCausedError(source, e);
}
}
private static String logPluginDataCausedError(PluginData source, Throwable e) {
String placeholder = StringUtils.remove(source.getPlaceholder(), '%');
Log.error("A PluginData-source caused an exception: " + placeholder);
Log.toLog("PluginData-source caused an exception: " + placeholder, e);
return source.parseContainer("", "Exception during calculation.");
}
/**
* Used to calculate unique players that have played within the time frame determined by scale.
*

View File

@ -10,7 +10,6 @@ import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.ServerVariableHolder;
import main.java.com.djrapitops.plan.Settings;
import main.java.com.djrapitops.plan.data.Session;
import main.java.com.djrapitops.plan.data.additional.PluginData;
import main.java.com.djrapitops.plan.database.Database;
import main.java.com.djrapitops.plan.systems.info.BukkitInformationManager;
import main.java.com.djrapitops.plan.utilities.FormatUtils;
@ -18,9 +17,7 @@ import main.java.com.djrapitops.plan.utilities.analysis.AnalysisUtils;
import main.java.com.djrapitops.plan.utilities.html.graphs.PlayerActivityGraphCreator;
import main.java.com.djrapitops.plan.utilities.html.structure.SessionTabStructureCreator;
import main.java.com.djrapitops.plan.utilities.html.tables.SessionsTableCreator;
import org.apache.commons.lang3.text.StrSubstitutor;
import java.io.Serializable;
import java.sql.SQLException;
import java.util.*;
@ -120,182 +117,6 @@ public class HtmlStructure {
return new String[]{/*Html.TABLE_SESSIONS.parse(SessionsTableCreator.createTable(uuidByID, allSessions)[0]),*/"", ""};
}
public static String createInspectPluginsTabContent(String serverName, List<PluginData> plugins, Map<String, Serializable> replaceMap) {
if (plugins.isEmpty()) {
String icon = Html.FONT_AWESOME_ICON.parse("server");
// TODO Move plain text to Locale
String headerText = Html.HEADER_2.parse(icon + " " + serverName) + Html.PARAGRAPH.parse("No Compatible Plugins");
String header = Html.DIV_W_CLASS.parse("box-header", headerText);
String row = Html.ROW.parse(header);
String pluginsHeader = Html.DIV_W_CLASS.parse("plugins-header", row);
return Html.DIV_W_CLASS.parse("plugins-server", pluginsHeader);
}
Map<String, List<String>> placeholders = getPlaceholdersInspect(plugins);
StringBuilder html = new StringBuilder();
html.append("<div class=\"plugins-server\">")
// Header
.append("<div class=\"plugins-header\">")
.append("<div class=\"row\">")
.append("<div class=\"column\">")
.append("<div class=\"box-header\">")
.append("<h2><i style=\"padding: 8px;\" class=\"fa fa-chevron-down\" aria-hidden=\"true\"></i> ")
.append(serverName)
.append("</h2>")
.append("</div>")
.append("</div>")
.append("</div>")
.append("</div>")
// Content
.append("<div class=\"plugins-content\">");
List<String> pluginNames = new ArrayList<>(placeholders.keySet());
Collections.sort(pluginNames);
int pluginCount = pluginNames.size();
int lastRowColumns = pluginCount % 3;
int column = 0;
for (String pluginName : pluginNames) {
List<String> pluginPhs = placeholders.get(pluginName);
if (column % 3 == 0) {
html.append("<div class=\"row\">");
}
html.append("<div class=\"column\">")
.append("<div class=\"box-header\">")
.append("<h2><i class=\"fa fa-cube\" aria-hidden=\"true\"></i> ").append(pluginName).append("</h2></div>");
html.append("<div class=\"box plugin\">");
for (String ph : pluginPhs) {
html.append(ph);
}
html.append("</div></div>"); // Closes column
if ((column + 1) % 3 == 0) {
html.append("</div>");
}
column++;
}
if (lastRowColumns != 0) {
if (lastRowColumns == 1) {
html.append("<div class=\"column\" style=\"width: 200%;\">");
} else if (lastRowColumns == 2) {
html.append("<div class=\"column\">");
}
html.append("</div>");
}
html.append("</div>") // Close content
.append("</div>");
return StrSubstitutor.replace(html.toString(), replaceMap);
}
public static String createAnalysisPluginsTabLayout(List<PluginData> plugins) {
StringBuilder html = new StringBuilder();
if (plugins.isEmpty()) {
html.append("<div class=\"row\">")
.append("<div class=\"column\">")
.append("<div class=\"box-header\">")
.append("<h2><i class=\"fa fa-cube\" aria-hidden=\"true\"></i> No Plugins</h2></div>")
.append("<div class=\"box plugin\">")
.append("<p>No Supported Plugins were detected.</p>")
.append("</div></div>")
.append("</div>");
return html.toString();
}
Map<String, List<String>> placeholders = getPlaceholdersAnalysis(plugins);
List<String> pluginNames = new ArrayList<>(placeholders.keySet());
Collections.sort(pluginNames);
int pluginCount = pluginNames.size();
int lastRowColumns = pluginCount % 3;
int column = 0;
for (String pluginName : pluginNames) {
List<String> pluginPhs = placeholders.get(pluginName);
if (column % 3 == 0) {
html.append("<div class=\"row\">");
}
html.append("<div class=\"column\">")
.append("<div class=\"box-header\">")
.append("<h2><i class=\"fa fa-cube\" aria-hidden=\"true\"></i> ").append(pluginName).append("</h2></div>");
html.append("<div class=\"box plugin\">");
for (String ph : pluginPhs) {
html.append(ph);
}
html.append("</div></div>"); // Closes column
if ((column + 1) % 3 == 0) {
html.append("</div>");
}
column++;
}
if (lastRowColumns != 0) {
if (lastRowColumns == 1) {
html.append("<div class=\"column\" style=\"width: 200%;\">");
} else if (lastRowColumns == 2) {
html.append("<div class=\"column\">");
}
html.append("<div class=\"box-header\" style=\"margin-top: 10px;\">")
.append("<h2>That's all..</h2>")
.append("</div>")
.append("<div class=\"box plugin\">")
.append("<p>Do you have more plugins? ._.</p>")
.append("</div>")
.append("</div>");
}
return html.toString();
}
private static Map<String, List<String>> getPlaceholdersAnalysis(List<PluginData> plugins) {
Map<String, List<String>> placeholders = new HashMap<>();
for (PluginData source : plugins) {
List<AnalysisType> analysisTypes = source.getAnalysisTypes();
if (analysisTypes.isEmpty()) {
continue;
}
String pluginName = source.getSourcePlugin();
List<String> pluginPlaceholderList = placeholders.getOrDefault(pluginName, new ArrayList<>());
for (AnalysisType t : analysisTypes) {
pluginPlaceholderList.add(source.getPlaceholder(t.getPlaceholderModifier()));
}
placeholders.put(pluginName, pluginPlaceholderList);
}
return placeholders;
}
private static Map<String, List<String>> getPlaceholdersInspect(List<PluginData> plugins) {
Map<String, List<String>> placeholders = new HashMap<>();
for (PluginData source : plugins) {
if (source.analysisOnly()) {
continue;
}
String pluginName = source.getSourcePlugin();
List<String> pluginPlaceholderList = placeholders.getOrDefault(pluginName, new ArrayList<>());
pluginPlaceholderList.add(source.getPlaceholder());
placeholders.put(pluginName, pluginPlaceholderList);
}
return placeholders;
}
public static String createInspectPageTabContentCalculating() {
return "<div class=\"row\">" +
"<div class=\"column\">" +

View File

@ -0,0 +1,22 @@
/*
* 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.utilities.html.structure;
import main.java.com.djrapitops.plan.data.additional.AnalysisContainer;
import main.java.com.djrapitops.plan.data.additional.PluginData;
import java.util.Map;
/**
* //TODO Class Javadoc Comment
*
* @author Rsl1122
*/
public class AnalysisPluginsTabContentCreator {
public static String[] createContent(Map<PluginData, AnalysisContainer> containers) {
return new String[]{"", ""};
}
}

View File

@ -150,9 +150,6 @@
<span>Plugins</span>
</a>
<ul class="ml-menu">
<li>
<a class="nav-button" href="javascript:void(0)">General</a>
</li>
${navPluginsTabs}
</ul>
</li>
@ -900,9 +897,6 @@
</div>
</div>
<!-- #END# Tab Commands -->
<div id="tab-plugins-General" class="tab">
${tabContentPluginsGeneral}
</div>
${tabsPlugins}
<!-- #END# Tabs Plugins -->
<div class="tab"></div>

View File

@ -1,31 +0,0 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package main.java.com.djrapitops.plan.data.additional;
import org.junit.Test;
import test.java.utils.TestUtils;
import static org.junit.Assert.assertEquals;
/**
* @author Rsl1122
*/
public class AnalysisTypeTest {
@Test
public void testGetModifier() throws NoSuchFieldException, IllegalAccessException {
for (AnalysisType type : AnalysisType.values()) {
assertEquals(TestUtils.getStringFieldValue(type, "modifier"), type.getModifier());
}
}
@Test
public void testGetPlaceholderModifier() throws NoSuchFieldException, IllegalAccessException {
for (AnalysisType type : AnalysisType.values()) {
assertEquals(TestUtils.getStringFieldValue(type, "placeholderModifier"), type.getPlaceholderModifier());
}
}
}