Plugins Tab placeholders now replaced properly

This commit is contained in:
Rsl1122 2017-09-09 14:51:33 +03:00
parent 7fd3386a47
commit 4a246d4c5c
6 changed files with 46 additions and 22 deletions

View File

@ -20,56 +20,56 @@ public enum AnalysisType {
* <p>
* -1 values will be disregarded from the calculation (size will not grow).
*/
INT_AVG("avgInt_", "Average "),
INT_AVG("_avgInt", "Average "),
/**
* Used when the getValue() method returns a long and average should be
* calculated.
* <p>
* -1 values will be disregarded from the calculation (size will not grow).
*/
LONG_AVG("avgLong_", "Average "),
LONG_AVG("_avgLong", "Average "),
/**
* Used when the getValue() method returns double and average should be
* calculated.
* <p>
* -1 values will be disregarded from the calculation (size will not grow).
*/
DOUBLE_AVG("avgDouble_", "Average "),
DOUBLE_AVG("_avgDouble", "Average "),
/**
* Used when the getValue() method returns an integer and total should be
* calculated.
* <p>
* -1 values will be disregarded from the calculation (size will not grow).
*/
INT_TOTAL("totalInt_", "Total "),
INT_TOTAL("_totalInt", "Total "),
/**
* Used when the getValue() method returns a long and total should be
* calculated.
* <p>
* -1 values will be disregarded from the calculation (size will not grow).
*/
LONG_TOTAL("totalLong_", "Total "),
LONG_TOTAL("_totalLong", "Total "),
/**
* Used when the getValue() method returns a double and total should be
* calculated.
* <p>
* -1 values will be disregarded from the calculation (size will not grow).
*/
DOUBLE_TOTAL("totalDouble_", "Total "),
DOUBLE_TOTAL("_totalDouble", "Total "),
/**
* Used when the getValue() method returns an amount of milliseconds as long
* and average should be calculated.
* <p>
* -1 values will be disregarded from the calculation (size will not grow).
*/
LONG_TIME_MS_AVG("avgTimeMs_", "Average "),
LONG_TIME_MS_AVG("_avgTimeMs", "Average "),
/**
* Used when the getValue() method returns an amount of milliseconds as long
* and total should be calculated.
* <p>
* -1 values will be disregarded from the calculation (size will not grow).
*/
LONG_TIME_MS_TOTAL("totalTimeMs_"),
LONG_TIME_MS_TOTAL("_totalTimeMs"),
/**
* Used when the getValue() method returns an Epoch Millisecond as long and
* average of differences between the millisecond and current millisecond
@ -81,18 +81,18 @@ public enum AnalysisType {
* <p>
* -1 values will be disregarded from the calculation (size will not grow).
*/
LONG_EPOCH_MS_MINUS_NOW_AVG("avgEpochMsMinusNow_", "Average "),
LONG_EPOCH_MS_MINUS_NOW_AVG("_avgEpochMsMinusNow", "Average "),
/**
* Used to calculate %-true for the returned boolean values of getValue().
*/
BOOLEAN_PERCENTAGE("perchBool_", "Percentage "),
BOOLEAN_PERCENTAGE("_perchBool", "Percentage "),
/**
* Used to calculate number of true values for the returned boolean values
* of getValue().
* <p>
* Will be presented as "n / total".
*/
BOOLEAN_TOTAL("totalBool_"),
BOOLEAN_TOTAL("_totalBool"),
/**
* Used to add html tags to the plugins tab.
* <p>

View File

@ -104,9 +104,9 @@ public class HookHandler {
continue;
}
try {
addReplace.put(source.getPlaceholder(), source.getHtmlReplaceValue("", uuid));
addReplace.put(source.getPlaceholderName(), source.getHtmlReplaceValue("", uuid));
} catch (Exception e) {
addReplace.put(source.getPlaceholder(), "Error occurred: " + e);
addReplace.put(source.getPlaceholderName(), "Error occurred: " + e);
Log.error("PluginDataSource caused an exception: " + source.getSourcePlugin());
Log.toLog("PluginDataSource " + source.getSourcePlugin(), e);
}

View File

@ -156,7 +156,7 @@ public abstract class PluginData {
* @see AnalysisType
*/
public final String getPlaceholder(String modifier) {
return "${" + sourcePlugin + "_" + placeholder + modifier + "}";
return "${" + getPlaceholderName(modifier) + "}";
}
/**
@ -166,7 +166,27 @@ public abstract class PluginData {
* @see #getPlaceholder(String)
*/
public final String getPlaceholder() {
return "${" + sourcePlugin + "_" + placeholder + "}";
return "${" + getPlaceholderName() + "}";
}
/**
* Used to get the placeholder name with modifier.
*
* @return for example "StepCounter_stepsTaken_modifier"
* @see #getPlaceholder(String)
*/
public final String getPlaceholderName(String modifier) {
return getPlaceholderName() + modifier;
}
/**
* Used to get the placeholder name.
*
* @return for example "StepCounter_stepsTaken"
* @see #getPlaceholder(String)
*/
public final String getPlaceholderName() {
return sourcePlugin + "_" + placeholder;
}
/**

View File

@ -478,6 +478,7 @@ public class WebServer {
return PageCache.loadPage("notFound: " + error, () -> new NotFoundResponse(error));
}
plugin.getInfoManager().cachePlayer(uuid);
return PageCache.loadPage("inspectPage: " + uuid, () -> new InspectPageResponse(infoManager, uuid));
}

View File

@ -171,24 +171,24 @@ public class Analysis {
return;
}
if (analysisTypes.contains(AnalysisType.HTML)) {
replaceMap.put(source.getPlaceholder(AnalysisType.HTML.getPlaceholderModifier()), source.getHtmlReplaceValue(AnalysisType.HTML.getModifier(), UUID.randomUUID()));
replaceMap.put(source.getPlaceholderName(AnalysisType.HTML.getPlaceholderModifier()), source.getHtmlReplaceValue(AnalysisType.HTML.getModifier(), UUID.randomUUID()));
return;
}
for (AnalysisType type : totalTypes) {
if (analysisTypes.contains(type)) {
replaceMap.put(source.getPlaceholder(type.getPlaceholderModifier()), AnalysisUtils.getTotal(type, source, uuids));
replaceMap.put(source.getPlaceholderName(type.getPlaceholderModifier()), AnalysisUtils.getTotal(type, source, uuids));
}
}
for (AnalysisType type : avgTypes) {
if (analysisTypes.contains(type)) {
replaceMap.put(source.getPlaceholder(type.getPlaceholderModifier()), AnalysisUtils.getAverage(type, source, uuids));
replaceMap.put(source.getPlaceholderName(type.getPlaceholderModifier()), AnalysisUtils.getAverage(type, source, uuids));
}
}
if (analysisTypes.contains(bool)) {
replaceMap.put(source.getPlaceholder(bool.getPlaceholderModifier()), AnalysisUtils.getBooleanPercentage(bool, source, uuids));
replaceMap.put(source.getPlaceholderName(bool.getPlaceholderModifier()), AnalysisUtils.getBooleanPercentage(bool, source, uuids));
}
if (analysisTypes.contains(boolTot)) {
replaceMap.put(source.getPlaceholder(boolTot.getPlaceholderModifier()), AnalysisUtils.getBooleanTotal(boolTot, source, uuids));
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(), '%'));

View File

@ -19,7 +19,8 @@
<i style="padding: 0; color: #348e0f; font-size: 95px;" class="fa fa-square fa-stack-1x"></i>
<i style="padding: 0; color: #fff; font-size: 60px;" class="fa fa-circle fa-stack-1x"></i>
<div style="margin: 0px; padding: 0px; width: 100%; height: 100%; position: relative; overflow: hidden; top: -6px;">
<i style="position: absolute; left: -4px; top: 8px; color: #348e0f; font-size: 40px;" class="fa fa-bar-chart fa-stack-1x"></i>
<i style="position: absolute; left: -4px; top: 8px; color: #348e0f; font-size: 40px;"
class="fa fa-bar-chart fa-stack-1x"></i>
</div>
</div>
<p class="right">Player Analytics v.${version}</p>
@ -42,7 +43,7 @@
</a>
</div>
<div id="limiter" class="main-limiter">
<div id="main" class="main-wrapper" style="width: 400%;">
<div id="main" class="main-wrapper">
<div id="tab-information" class="tab">
<div class="row">
<div class="column">
@ -206,6 +207,7 @@
color: '#222',
data: ${punchCardSeries}
};
</script>
<script>
var navButtons = document.getElementsByClassName("nav-button");
@ -256,6 +258,7 @@
};
}
</script>
</div>
</body>