From 224468e9d21e0a27faaa92876b37abd3d3c2ed2f Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Sun, 26 Nov 2017 12:02:23 +0200 Subject: [PATCH] Analysis Plugin Section html parsing, Version bump to 4.1.0 --- Plan/pom.xml | 2 +- .../djrapitops/plan/data/PlayerProfile.java | 6 -- .../data/additional/AnalysisContainer.java | 2 +- .../data/additional/InspectContainer.java | 16 +-- .../plan/data/additional/PluginData.java | 19 ++-- .../plan/data/additional/TableContainer.java | 2 +- .../info/parsing/InspectPageParser.java | 14 --- .../comparators/PluginDataNameComparator.java | 23 ++++ .../AnalysisPluginsTabContentCreator.java | 100 +++++++++++++++++- Plan/src/main/resources/bungee.yml | 2 +- Plan/src/main/resources/plugin.yml | 2 +- 11 files changed, 148 insertions(+), 40 deletions(-) create mode 100644 Plan/src/main/java/com/djrapitops/plan/utilities/comparators/PluginDataNameComparator.java diff --git a/Plan/pom.xml b/Plan/pom.xml index 7f71d8acf..d4db18509 100644 --- a/Plan/pom.xml +++ b/Plan/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.djrapitops Plan - 4.0.7 + 4.1.0 jar diff --git a/Plan/src/main/java/com/djrapitops/plan/data/PlayerProfile.java b/Plan/src/main/java/com/djrapitops/plan/data/PlayerProfile.java index e238729f5..f03580eb8 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/PlayerProfile.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/PlayerProfile.java @@ -76,12 +76,6 @@ public class PlayerProfile implements OfflinePlayer { } // Calculating Getters - - @Deprecated // TODO Remove after 4.1.0, made for old html users - public boolean isActive(long date) { - return getActivityIndex(date) > 1.0; - } - public double getActivityIndex(long date) { Double activityIndx = activityIndex.get(date); if (activityIndx != null) { diff --git a/Plan/src/main/java/com/djrapitops/plan/data/additional/AnalysisContainer.java b/Plan/src/main/java/com/djrapitops/plan/data/additional/AnalysisContainer.java index 24f62bc59..6bd18bceb 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/additional/AnalysisContainer.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/additional/AnalysisContainer.java @@ -28,7 +28,7 @@ import java.util.UUID; * @see InspectContainer * @since 4.1.0 */ -public class AnalysisContainer extends InspectContainer { +public final class AnalysisContainer extends InspectContainer { private TreeMap> playerTableValues; diff --git a/Plan/src/main/java/com/djrapitops/plan/data/additional/InspectContainer.java b/Plan/src/main/java/com/djrapitops/plan/data/additional/InspectContainer.java index c6b2ec051..82ee4be60 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/additional/InspectContainer.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/additional/InspectContainer.java @@ -37,27 +37,27 @@ public class InspectContainer { tables = new TreeMap<>(); } - public String getWithIcon(String text, String icon) { + public final String getWithIcon(String text, String icon) { return getWithColoredIcon(text, icon, "black"); } - public String getWithColoredIcon(String text, String icon, String color) { + public final String getWithColoredIcon(String text, String icon, String color) { return Html.FA_COLORED_ICON.parse(color, icon) + " " + text; } - public void addValue(String label, Serializable value) { + public final void addValue(String label, Serializable value) { values.put(label, value.toString()); } - public void addHtml(String key, String html) { + public final void addHtml(String key, String html) { this.html.put(key, html); } - public void addTable(String key, TableContainer table) { + public final void addTable(String key, TableContainer table) { tables.put(key, table); } - public String parseHtml() { + public final String parseHtml() { StringBuilder html = new StringBuilder(); for (Map.Entry entry : values.entrySet()) { @@ -74,4 +74,8 @@ public class InspectContainer { return html.toString(); } + + public final boolean hasOnlyValues() { + return html.isEmpty() && tables.isEmpty(); + } } \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/data/additional/PluginData.java b/Plan/src/main/java/com/djrapitops/plan/data/additional/PluginData.java index 89e9abb8f..50d96a010 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/additional/PluginData.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/additional/PluginData.java @@ -22,6 +22,7 @@ public abstract class PluginData { private final String sourcePlugin; private String pluginIcon; + private String iconColor; public PluginData(ContainerSize size, String sourcePlugin) { this.size = size; @@ -32,24 +33,28 @@ public abstract class PluginData { public abstract AnalysisContainer getServerData(Collection uuids, AnalysisContainer fillThis) throws Exception; - protected void setPluginIcon(String pluginIcon) { + protected final void setPluginIcon(String pluginIcon) { this.pluginIcon = pluginIcon; } - public String parsePluginIcon() { - return pluginIcon != null ? Html.FONT_AWESOME_ICON.parse(pluginIcon) : Html.FONT_AWESOME_ICON.parse("cube"); + protected final void setIconColor(String iconColor) { + this.iconColor = iconColor; } - public ContainerSize getSize() { + public final String parsePluginIcon() { + return pluginIcon != null ? Html.FA_COLORED_ICON.parse((iconColor != null ? iconColor : "black"), pluginIcon) : Html.FONT_AWESOME_ICON.parse("cube"); + } + + public final ContainerSize getSize() { return size; } - public String getSourcePlugin() { + public final String getSourcePlugin() { return sourcePlugin; } @Override - public boolean equals(Object o) { + public final boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PluginData that = (PluginData) o; @@ -59,7 +64,7 @@ public abstract class PluginData { } @Override - public int hashCode() { + public final int hashCode() { return Objects.hashCode(size, sourcePlugin, pluginIcon); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/data/additional/TableContainer.java b/Plan/src/main/java/com/djrapitops/plan/data/additional/TableContainer.java index 0955d12bd..40a4928ea 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/additional/TableContainer.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/additional/TableContainer.java @@ -15,7 +15,7 @@ import java.util.List; * * @author Rsl1122 */ -public class TableContainer { +public final class TableContainer { private final String[] header; private List values; diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/info/parsing/InspectPageParser.java b/Plan/src/main/java/com/djrapitops/plan/systems/info/parsing/InspectPageParser.java index a3c7c1c4c..bd289edf5 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/info/parsing/InspectPageParser.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/info/parsing/InspectPageParser.java @@ -220,10 +220,6 @@ public class InspectPageParser extends PageParser { addValue("playerStatus", HtmlStructure.playerStatus(online, profile.getBannedOnServers(), profile.isOp())); - boolean isActive = profile.isActive(now); - String active = isActive ? "Active" : "Inactive"; - playerClassification(profile, active); - if (!plugin.getInfoManager().isUsingAnotherWebServer()) { addValue("networkName", Settings.SERVER_NAME.toString()); } @@ -234,14 +230,4 @@ public class InspectPageParser extends PageParser { throw new ParseException(e); } } - - private void playerClassification(PlayerProfile profile, String active) { - boolean isBanned = profile.isBanned(); - boolean isOP = profile.isOp(); - - String banned = isBanned ? "Banned" : ""; - String op = isOP ? "Operator (OP)" : ""; - - addValue("playerClassification", HtmlStructure.separateWithDots(active, banned, op)); - } } diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/comparators/PluginDataNameComparator.java b/Plan/src/main/java/com/djrapitops/plan/utilities/comparators/PluginDataNameComparator.java new file mode 100644 index 000000000..0d4f1a5ad --- /dev/null +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/comparators/PluginDataNameComparator.java @@ -0,0 +1,23 @@ +/* + * 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.utilities.comparators; + +import main.java.com.djrapitops.plan.data.additional.PluginData; + +import java.util.Comparator; + +/** + * Comparator for UserInfo for Alphabetical Name order. + * + * @author Rsl1122 + */ +public class PluginDataNameComparator implements Comparator { + + @Override + public int compare(PluginData u1, PluginData u2) { + return u1.getSourcePlugin().compareTo(u2.getSourcePlugin()); + } +} diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/html/structure/AnalysisPluginsTabContentCreator.java b/Plan/src/main/java/com/djrapitops/plan/utilities/html/structure/AnalysisPluginsTabContentCreator.java index 31b221e66..b0e1460ca 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/html/structure/AnalysisPluginsTabContentCreator.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/html/structure/AnalysisPluginsTabContentCreator.java @@ -6,17 +6,113 @@ 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 main.java.com.djrapitops.plan.utilities.comparators.PluginDataNameComparator; +import java.util.ArrayList; +import java.util.List; import java.util.Map; /** - * //TODO Class Javadoc Comment + * Creates Plugin section contents for Analysis page. * * @author Rsl1122 */ public class AnalysisPluginsTabContentCreator { public static String[] createContent(Map containers) { - return new String[]{"", ""}; + if (containers.isEmpty()) { + return new String[]{"
  • No Compatible Plugins
  • ", ""}; + } + + List order = new ArrayList<>(containers.keySet()); + order.sort(new PluginDataNameComparator()); + + StringBuilder nav = new StringBuilder(); + StringBuilder generalTab = new StringBuilder(); + StringBuilder otherTabs = new StringBuilder(); + + generalTab.append("
    "); + + boolean hadOtherThanTabs = false; + + for (PluginData pluginData : order) { + AnalysisContainer container = containers.get(pluginData); + + switch (pluginData.getSize()) { + case TAB: + appendNewTab(pluginData, container, nav, otherTabs); + break; + case WHOLE: + if (!container.hasOnlyValues()) { + appendWhole(pluginData, container, generalTab); + hadOtherThanTabs = true; + break; + } + + case TWO_THIRDS: + if (!container.hasOnlyValues()) { + appendTwoThirds(pluginData, container, generalTab); + hadOtherThanTabs = true; + break; + } + case THIRD: + default: + appendThird(pluginData, container, generalTab); + hadOtherThanTabs = true; + break; + } + } + + generalTab.append("
    "); + + return new String[]{ + hadOtherThanTabs ? "
  • General
  • " + nav.toString() : nav.toString(), + hadOtherThanTabs ? generalTab.toString() + otherTabs.toString() : otherTabs.toString() + }; + } + + private static void appendThird(PluginData pluginData, AnalysisContainer container, StringBuilder generalTab) { + generalTab.append("
    " + + "
    " + + "
    " + + "

    ") + .append(pluginData.parsePluginIcon()).append(" ").append(pluginData.getSourcePlugin()) + .append("

    ").append("
    ") + .append(container.parseHtml()) + .append("
    "); + } + + private static void appendTwoThirds(PluginData pluginData, AnalysisContainer container, StringBuilder generalTab) { + generalTab.append("
    " + + "
    " + + "
    " + + "

    ") + .append(pluginData.parsePluginIcon()).append(" ").append(pluginData.getSourcePlugin()) + .append("

    ").append("
    ") + .append(container.parseHtml()) + .append("
    "); + } + + private static void appendWhole(PluginData pluginData, AnalysisContainer container, StringBuilder generalTab) { + generalTab.append("
    " + + "
    " + + "
    " + + "

    ") + .append(pluginData.parsePluginIcon()).append(" ").append(pluginData.getSourcePlugin()) + .append("

    ").append("
    ") + .append(container.parseHtml()) + .append("
    "); + } + + private static void appendNewTab(PluginData pluginData, AnalysisContainer container, StringBuilder nav, StringBuilder otherTabs) { + nav.append("
  • ").append(pluginData.getSourcePlugin()).append("
  • "); + otherTabs.append("
    " + + "
    " + + "
    " + + "

    ") + .append(pluginData.parsePluginIcon()).append(" ").append(pluginData.getSourcePlugin()) + .append("

    ").append("
    ") + .append(container.parseHtml()) + .append("
    "); } } \ No newline at end of file diff --git a/Plan/src/main/resources/bungee.yml b/Plan/src/main/resources/bungee.yml index 91d654f28..e2062e074 100644 --- a/Plan/src/main/resources/bungee.yml +++ b/Plan/src/main/resources/bungee.yml @@ -1,4 +1,4 @@ name: Plan author: Rsl1122 main: main.java.com.djrapitops.plan.PlanBungee -version: 4.0.7 \ No newline at end of file +version: 4.1.0 \ No newline at end of file diff --git a/Plan/src/main/resources/plugin.yml b/Plan/src/main/resources/plugin.yml index ffda8b0e4..1123809aa 100644 --- a/Plan/src/main/resources/plugin.yml +++ b/Plan/src/main/resources/plugin.yml @@ -1,7 +1,7 @@ name: Plan author: Rsl1122 main: main.java.com.djrapitops.plan.Plan -version: 4.0.7 +version: 4.1.0 softdepend: - OnTime - EssentialsX