From 3889aedddf43027568f0e77b04d6794d1ef4f16e Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Sun, 26 Nov 2017 12:53:19 +0200 Subject: [PATCH] Begun PluginData conversion, Fixes to containers --- .../data/additional/AnalysisContainer.java | 8 +- .../data/additional/InspectContainer.java | 14 +-- .../plan/data/additional/PluginData.java | 8 ++ .../plan/data/additional/TableContainer.java | 18 ++-- .../plan/utilities/analysis/Analysis.java | 2 +- .../djrapitops/plan/utilities/html/Html.java | 1 + PlanPluginBridge/pom.xml | 4 +- .../AdvancedAchievementsAchievements.java | 83 ------------------ .../AdvancedAchievementsData.java | 70 +++++++++++++++ .../AdvancedAchievementsHook.java | 3 +- .../AdvancedAchievementsTable.java | 85 ------------------- .../plan/askyblock/ASkyBlockData.java | 68 +++++++++++++++ .../plan/askyblock/ASkyBlockHook.java | 5 +- .../plan/askyblock/ASkyBlockIslandLevel.java | 50 ----------- .../plan/askyblock/ASkyBlockIslandName.java | 46 ---------- .../plan/askyblock/ASkyBlockIslandResets.java | 43 ---------- .../plan/askyblock/ASkyBlockIslands.java | 47 ---------- .../plan/essentials/EssentialsData.java | 76 +++++++++++++++++ .../plan/essentials/EssentialsHook.java | 4 +- .../plan/essentials/EssentialsJailed.java | 53 ------------ .../plan/essentials/EssentialsMuted.java | 53 ------------ .../plan/essentials/EssentialsWarps.java | 70 --------------- 22 files changed, 250 insertions(+), 561 deletions(-) delete mode 100644 PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/advancedachievements/AdvancedAchievementsAchievements.java create mode 100644 PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/advancedachievements/AdvancedAchievementsData.java delete mode 100644 PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/advancedachievements/AdvancedAchievementsTable.java create mode 100644 PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/askyblock/ASkyBlockData.java delete mode 100644 PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/askyblock/ASkyBlockIslandLevel.java delete mode 100644 PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/askyblock/ASkyBlockIslandName.java delete mode 100644 PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/askyblock/ASkyBlockIslandResets.java delete mode 100644 PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/askyblock/ASkyBlockIslands.java create mode 100644 PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/essentials/EssentialsData.java delete mode 100644 PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/essentials/EssentialsJailed.java delete mode 100644 PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/essentials/EssentialsMuted.java delete mode 100644 PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/essentials/EssentialsWarps.java 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 6bd18bceb..d7f869fec 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 @@ -30,13 +30,17 @@ import java.util.UUID; */ public final class AnalysisContainer extends InspectContainer { - private TreeMap> playerTableValues; + private TreeMap> playerTableValues; public AnalysisContainer() { playerTableValues = new TreeMap<>(); } - public TreeMap> getPlayerTableValues() { + public TreeMap> getPlayerTableValues() { return playerTableValues; } + + public void addPlayerTableValues(String columnName, Map values) { + playerTableValues.put(columnName, values); + } } \ No newline at end of file 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 82ee4be60..7e5762a97 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 @@ -4,8 +4,6 @@ */ package main.java.com.djrapitops.plan.data.additional; -import main.java.com.djrapitops.plan.utilities.html.Html; - import java.io.Serializable; import java.util.Map; import java.util.TreeMap; @@ -37,14 +35,6 @@ public class InspectContainer { tables = new TreeMap<>(); } - public final String getWithIcon(String text, String icon) { - return getWithColoredIcon(text, icon, "black"); - } - - public final String getWithColoredIcon(String text, String icon, String color) { - return Html.FA_COLORED_ICON.parse(color, icon) + " " + text; - } - public final void addValue(String label, Serializable value) { values.put(label, value.toString()); } @@ -78,4 +68,8 @@ public class InspectContainer { public final boolean hasOnlyValues() { return html.isEmpty() && tables.isEmpty(); } + + public final boolean isEmpty() { + return values.isEmpty() && 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 50d96a010..94cc23268 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 @@ -67,4 +67,12 @@ public abstract class PluginData { public final int hashCode() { return Objects.hashCode(size, sourcePlugin, pluginIcon); } + + public final String getWithIcon(String text, String icon) { + return getWithIcon(text, icon, "black"); + } + + public final String getWithIcon(String text, String icon, String color) { + return Html.FA_COLORED_ICON.parse(color, icon) + " " + text; + } } 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 40a4928ea..76fe55fef 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 @@ -20,6 +20,8 @@ public final class TableContainer { private final String[] header; private List values; + private String color; + /** * Constructor, call with super(...). * @@ -30,17 +32,15 @@ public final class TableContainer { values = new ArrayList<>(); } - protected void addRow(Serializable... values) { + public void addRow(Serializable... values) { this.values.add(values); } public String parseHtml() { - StringBuilder table = new StringBuilder(Html.TABLE.parse()); - - table.append(parseHeader()); - table.append(parseBody()); - - return table.append("").toString(); + return Html.TABLE_COLORED.parse(color != null ? color : "") + + parseHeader() + + parseBody() + + ""; } private String parseBody() { @@ -67,6 +67,10 @@ public final class TableContainer { return Html.TABLE_BODY.parse(body.toString()); } + public void setColor(String color) { + this.color = color; + } + public String parseHeader() { StringBuilder header = new StringBuilder(""); for (String title : this.header) { diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java index e268dae37..3f6f9942b 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java @@ -158,7 +158,7 @@ public class Analysis { Benchmark.start("Analysis", "Source " + source.getSourcePlugin()); AnalysisContainer container = source.getServerData(uuids, new AnalysisContainer()); - if (container != null) { + if (container != null && !container.isEmpty()) { containers.put(source, container); } diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/html/Html.java b/Plan/src/main/java/com/djrapitops/plan/utilities/html/Html.java index bcdd4d33e..822435f21 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/html/Html.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/html/Html.java @@ -54,6 +54,7 @@ public enum Html { // TABLE_END(""), TABLE(""), + TABLE_COLORED("
"), TABLE_HEAD("${0}"), TABLE_BODY("${0}"), TABLE_START_2("
"), diff --git a/PlanPluginBridge/pom.xml b/PlanPluginBridge/pom.xml index efa52f54d..e6f5a59d9 100644 --- a/PlanPluginBridge/pom.xml +++ b/PlanPluginBridge/pom.xml @@ -4,7 +4,7 @@ 4.0.0com.djrapitopsPlanPluginBridge - 4.0.5 + 4.1.0jar @@ -24,7 +24,7 @@ com.djrapitops Plan - 4.0.5 + 4.1.0 provided diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/advancedachievements/AdvancedAchievementsAchievements.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/advancedachievements/AdvancedAchievementsAchievements.java deleted file mode 100644 index 396f60062..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/advancedachievements/AdvancedAchievementsAchievements.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.djrapitops.pluginbridge.plan.advancedachievements; - -import com.hm.achievement.api.AdvancedAchievementsAPI; -import main.java.com.djrapitops.plan.data.additional.AnalysisType; -import main.java.com.djrapitops.plan.data.additional.PluginData; -import main.java.com.djrapitops.plan.utilities.MiscUtils; - -import java.io.Serializable; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -/** - * PluginData class for AdvancedAchievements-plugin. - *

- * Registered to the plugin by AdvancedAchievementsHook. - *

- * Gives the amount of achievements as value. - * - * @author Rsl1122 - * @see AdvancedAchievementsHook - * @since 3.1.0 - */ -public class AdvancedAchievementsAchievements extends PluginData { - - private final AdvancedAchievementsAPI aaAPI; - private long lastRefresh; - private Map totalAchievements; - - /** - * Class Constructor, sets the parameters of the PluginData object. - * - * @param aaAPI AdvancedAchievementsAPI given by AdvancedAchievementsHook - */ - public AdvancedAchievementsAchievements(AdvancedAchievementsAPI aaAPI) { - super("AdvancedAchievements", "achievements", AnalysisType.INT_TOTAL, AnalysisType.INT_AVG); - this.aaAPI = aaAPI; - super.setAnalysisOnly(false); - super.setIcon("check-circle-o"); - super.setPrefix("Achievements: "); - totalAchievements = aaAPI.getPlayersTotalAchievements(); - lastRefresh = MiscUtils.getTime(); - } - - @Override - public String getHtmlReplaceValue(String modifierPrefix, UUID uuid) { - if (MiscUtils.getTime() - lastRefresh > 60000) { - refreshTotalAchievements(); - } - Integer total = totalAchievements.get(uuid); - if (total != null) { - return parseContainer(modifierPrefix, total + ""); - } - return parseContainer(modifierPrefix, "0"); - } - - private void refreshTotalAchievements() { - totalAchievements = aaAPI.getPlayersTotalAchievements(); - lastRefresh = MiscUtils.getTime(); - } - - @Override - public Map getValues(Collection uuid) { - if (MiscUtils.getTime() - lastRefresh > 60000) { - refreshTotalAchievements(); - } - return new HashMap<>(totalAchievements); - } - - @Override - public Serializable getValue(UUID uuid) { - if (MiscUtils.getTime() - lastRefresh > 60000) { - refreshTotalAchievements(); - } - Integer total = totalAchievements.get(uuid); - if (total != null) { - return total; - } - return -1; - } - -} diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/advancedachievements/AdvancedAchievementsData.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/advancedachievements/AdvancedAchievementsData.java new file mode 100644 index 000000000..68df85bba --- /dev/null +++ b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/advancedachievements/AdvancedAchievementsData.java @@ -0,0 +1,70 @@ +/* + * 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 com.djrapitops.pluginbridge.plan.advancedachievements; + +import com.djrapitops.plugin.api.TimeAmount; +import com.hm.achievement.api.AdvancedAchievementsAPI; +import main.java.com.djrapitops.plan.data.additional.AnalysisContainer; +import main.java.com.djrapitops.plan.data.additional.ContainerSize; +import main.java.com.djrapitops.plan.data.additional.InspectContainer; +import main.java.com.djrapitops.plan.data.additional.PluginData; +import main.java.com.djrapitops.plan.utilities.FormatUtils; +import main.java.com.djrapitops.plan.utilities.MiscUtils; +import main.java.com.djrapitops.plan.utilities.analysis.MathUtils; + +import java.util.Collection; +import java.util.Map; +import java.util.UUID; + +/** + * PluginData class for AdvancedAchievements. + * + * @author Rsl1122 + */ +public class AdvancedAchievementsData extends PluginData { + + private final AdvancedAchievementsAPI aaAPI; + private long lastRefresh; + private Map totalAchievements; + + public AdvancedAchievementsData(AdvancedAchievementsAPI aaAPI) { + super(ContainerSize.THIRD, "AdvancedAchievements"); + super.setPluginIcon("star"); + super.setIconColor("green"); + this.aaAPI = aaAPI; + refreshTotalAchievements(); + } + + @Override + public InspectContainer getPlayerData(UUID uuid, InspectContainer inspectContainer) throws Exception { + String text = getWithIcon("Achievements", "check-circle-o", "green"); + inspectContainer.addValue(text, aaAPI.getPlayerTotalAchievements(uuid)); + + return inspectContainer; + } + + @Override + public AnalysisContainer getServerData(Collection collection, AnalysisContainer analysisContainer) throws Exception { + if (MiscUtils.getTime() - lastRefresh > TimeAmount.MINUTE.ms() * 5L) { + refreshTotalAchievements(); + } + long total = getTotal(totalAchievements); + String average = FormatUtils.cutDecimals(MathUtils.averageDouble(total, totalAchievements.size())); + + analysisContainer.addValue(getWithIcon("Total Achievements", "check-circle-o", "green"), total); + analysisContainer.addValue(getWithIcon("Average Achievements", "check-circle-o", "green"), average); + analysisContainer.addPlayerTableValues(getWithIcon("Achievements", "star"), totalAchievements); + return analysisContainer; + } + + private long getTotal(Map totalAchievements) { + return MathUtils.sumLong(totalAchievements.values().stream().map(i -> i)); + } + + private void refreshTotalAchievements() { + totalAchievements = aaAPI.getPlayersTotalAchievements(); + lastRefresh = MiscUtils.getTime(); + } +} \ No newline at end of file diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/advancedachievements/AdvancedAchievementsHook.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/advancedachievements/AdvancedAchievementsHook.java index 195eb62d3..6909e4d59 100644 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/advancedachievements/AdvancedAchievementsHook.java +++ b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/advancedachievements/AdvancedAchievementsHook.java @@ -36,8 +36,7 @@ public class AdvancedAchievementsHook extends Hook { AdvancedAchievements aa = getPlugin(AdvancedAchievements.class); if (Integer.parseInt(Character.toString(aa.getDescription().getVersion().charAt(0))) >= 5) { AdvancedAchievementsAPI aaAPI = AdvancedAchievementsBukkitAPI.linkAdvancedAchievements(); - addPluginDataSource(new AdvancedAchievementsAchievements(aaAPI)); - addPluginDataSource(new AdvancedAchievementsTable(aaAPI)); + addPluginDataSource(new AdvancedAchievementsData(aaAPI)); } else { enabled = false; } diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/advancedachievements/AdvancedAchievementsTable.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/advancedachievements/AdvancedAchievementsTable.java deleted file mode 100644 index 2830f8ce4..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/advancedachievements/AdvancedAchievementsTable.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.djrapitops.pluginbridge.plan.advancedachievements; - -import com.hm.achievement.api.AdvancedAchievementsAPI; -import main.java.com.djrapitops.plan.Plan; -import main.java.com.djrapitops.plan.data.additional.AnalysisType; -import main.java.com.djrapitops.plan.data.additional.PluginData; -import main.java.com.djrapitops.plan.utilities.html.Html; - -import java.io.Serializable; -import java.util.Map; -import java.util.Set; -import java.util.UUID; - -/** - * PluginData class for AdvancedAchievements-plugin. - *

- * Registered to the plugin by AdvancedAchievementsHook - *

- * Gives a table of players and achievements achievements. - * - * @author Rsl1122 - * @see AdvancedAchievementsHook - * @since 3.1.0 - */ -public class AdvancedAchievementsTable extends PluginData { - - private final AdvancedAchievementsAPI aaAPI; - - /** - * Class Constructor, sets the parameters of the PluginData object. - *

- * Uses Html to easily parse Html for the table. - * - * @param aaAPI AdvancedAchievementsAPI given by AdvancedAchievementsHook - * @see Html - */ - public AdvancedAchievementsTable(AdvancedAchievementsAPI aaAPI) { - super("AdvancedAchievements", "achievements_table", AnalysisType.HTML); - this.aaAPI = aaAPI; - String player = Html.FONT_AWESOME_ICON.parse("user") + " Player"; - String achievements = Html.FONT_AWESOME_ICON.parse("check-circle-o") + " Achievements"; - // analysisOnly true by default. - super.setPrefix(Html.TABLE_START_2.parse(player, achievements)); - super.setSuffix(Html.TABLE_END.parse()); - } - - @Override - public String getHtmlReplaceValue(String modifierPrefix, UUID uuidUnused) { - StringBuilder html = new StringBuilder(); - Set users = Plan.getInstance().getDataCache().getUuids(); - if (users.isEmpty()) { - html.append(Html.TABLELINE_2.parse("No Players.", "")); - } else if (aaAPI.getAdvancedAchievementsVersionCode() >= 520) { - appendTableLinesForV520Plus(users, html); - } else { - appendTableLinesForLessThanV520(users, html); - } - return parseContainer("", html.toString()); - } - - private void appendTableLinesForLessThanV520(Set users, StringBuilder html) { - users.forEach(uuid -> { - String name = super.getNameOf(uuid); - String inspectUrl = Plan.getPlanAPI().getPlayerInspectPageLink(name); - int achievements = aaAPI.getPlayerTotalAchievements(uuid); - html.append(Html.TABLELINE_2.parse(Html.LINK.parse(inspectUrl, name), achievements)); - }); - } - - private void appendTableLinesForV520Plus(Set users, StringBuilder html) { - Map achievementsMap = aaAPI.getPlayersTotalAchievements(); - for (Map.Entry entry : achievementsMap.entrySet()) { - UUID uuid = entry.getKey(); - int achievements = entry.getValue(); - String name = getNameOf(uuid); - String inspectUrl = Plan.getPlanAPI().getPlayerInspectPageLink(name); - html.append(Html.TABLELINE_2.parse(Html.LINK.parse(inspectUrl, name), achievements)); - } - } - - @Override - public Serializable getValue(UUID uuid) { - return -1; - } -} diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/askyblock/ASkyBlockData.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/askyblock/ASkyBlockData.java new file mode 100644 index 000000000..646091b63 --- /dev/null +++ b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/askyblock/ASkyBlockData.java @@ -0,0 +1,68 @@ +/* + * 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 com.djrapitops.pluginbridge.plan.askyblock; + +import com.wasteofplastic.askyblock.ASkyBlockAPI; +import main.java.com.djrapitops.plan.data.additional.AnalysisContainer; +import main.java.com.djrapitops.plan.data.additional.ContainerSize; +import main.java.com.djrapitops.plan.data.additional.InspectContainer; +import main.java.com.djrapitops.plan.data.additional.PluginData; + +import java.io.Serializable; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +/** + * //TODO Class Javadoc Comment + * + * @author Rsl1122 + */ +public class ASkyBlockData extends PluginData { + + private final ASkyBlockAPI api; + + public ASkyBlockData(ASkyBlockAPI api) { + super(ContainerSize.THIRD, "ASkyBlock"); + super.setPluginIcon("street-view"); + super.setIconColor("light-blue"); + this.api = api; + } + + @Override + public InspectContainer getPlayerData(UUID uuid, InspectContainer inspectContainer) throws Exception { + if (api.hasIsland(uuid)) { + String islandName = api.getIslandName(uuid); + int level = api.getIslandLevel(uuid); + int resetsLeft = api.getResetsLeft(uuid); + + inspectContainer.addValue(getWithIcon("Island Name", "street-view", "green"), islandName); + inspectContainer.addValue(getWithIcon("Island Level", "street-view", "amber"), level); + inspectContainer.addValue(getWithIcon("Island Resets Left", "refresh", "green"), resetsLeft); + } else { + inspectContainer.addValue(getWithIcon("Island Name", "street-view", "green"), "No Island"); + } + + return inspectContainer; + } + + @Override + public AnalysisContainer getServerData(Collection uuids, AnalysisContainer analysisContainer) throws Exception { + int islandCount = api.getIslandCount(); + String islandWorldName = api.getIslandWorld().getName(); + + analysisContainer.addValue(getWithIcon("Island World", "map-o", "green"), islandWorldName); + analysisContainer.addValue(getWithIcon("Island Count", "street-view", "green"), islandCount); + + Map islandLevels = new HashMap<>(); + for (UUID uuid : uuids) { + islandLevels.put(uuid, api.hasIsland(uuid) ? api.getIslandLevel(uuid) : "-"); + } + analysisContainer.addPlayerTableValues(getWithIcon("Island Level", "street-view"), islandLevels); + + return analysisContainer; + } +} \ No newline at end of file diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/askyblock/ASkyBlockHook.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/askyblock/ASkyBlockHook.java index 92aff191f..1806d3f96 100644 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/askyblock/ASkyBlockHook.java +++ b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/askyblock/ASkyBlockHook.java @@ -29,10 +29,7 @@ public class ASkyBlockHook extends Hook { public void hook() throws NoClassDefFoundError { if (enabled) { ASkyBlockAPI api = ASkyBlockAPI.getInstance(); - addPluginDataSource(new ASkyBlockIslandName(api)); - addPluginDataSource(new ASkyBlockIslandLevel(api)); - addPluginDataSource(new ASkyBlockIslandResets(api)); - addPluginDataSource(new ASkyBlockIslands(api)); + addPluginDataSource(new ASkyBlockData(api)); } } } diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/askyblock/ASkyBlockIslandLevel.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/askyblock/ASkyBlockIslandLevel.java deleted file mode 100644 index 9fda68a6a..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/askyblock/ASkyBlockIslandLevel.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.djrapitops.pluginbridge.plan.askyblock; - -import com.wasteofplastic.askyblock.ASkyBlockAPI; -import main.java.com.djrapitops.plan.data.additional.AnalysisType; -import main.java.com.djrapitops.plan.data.additional.PluginData; - -import java.io.Serializable; -import java.util.UUID; - -/** - * PluginData class for ASkyBlock-plugin. - * - * @author Rsl1122 - * @since 3.5.0 - */ -public class ASkyBlockIslandLevel extends PluginData { - - private final ASkyBlockAPI api; - - /** - * Class Constructor, sets the parameters of the PluginData object. - * - * @param aaAPI ASkyBlockAPI - */ - public ASkyBlockIslandLevel(ASkyBlockAPI aaAPI) { - super("ASkyBlock", "island_level", AnalysisType.INT_AVG); - this.api = aaAPI; - super.setAnalysisOnly(false); - super.setIcon("street-view"); - super.setPrefix("Island Level: "); - } - - @Override - public String getHtmlReplaceValue(String modifierPrefix, UUID uuid) { - if (api.hasIsland(uuid)) { - int level = api.getIslandLevel(uuid); - return parseContainer(modifierPrefix, Integer.toString(level)); - } - return parseContainer(modifierPrefix, "No Island"); - } - - @Override - public Serializable getValue(UUID uuid) { - if (api.hasIsland(uuid)) { - return api.getIslandLevel(uuid); - } - return -1; - } - -} diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/askyblock/ASkyBlockIslandName.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/askyblock/ASkyBlockIslandName.java deleted file mode 100644 index 46d86845b..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/askyblock/ASkyBlockIslandName.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.djrapitops.pluginbridge.plan.askyblock; - -import com.wasteofplastic.askyblock.ASkyBlockAPI; -import main.java.com.djrapitops.plan.data.additional.PluginData; - -import java.io.Serializable; -import java.util.UUID; - -/** - * PluginData class for ASkyBlock-plugin. - * - * @author Rsl1122 - * @since 3.5.0 - */ -public class ASkyBlockIslandName extends PluginData { - - private final ASkyBlockAPI api; - - /** - * Class Constructor, sets the parameters of the PluginData object. - * - * @param aaAPI ASkyBlockAPI - */ - public ASkyBlockIslandName(ASkyBlockAPI aaAPI) { - super("ASkyBlock", "island_name"); - this.api = aaAPI; - super.setIcon("street-view"); - super.setPrefix("Island name: "); - } - - @Override - public String getHtmlReplaceValue(String modifierPrefix, UUID uuid) { - if (api.hasIsland(uuid)) { - return parseContainer(modifierPrefix, api.getIslandName(uuid).replace("§r", "")); - } - return parseContainer(modifierPrefix, "No Island"); - - } - - @Override - public Serializable getValue(UUID uuid) { - //Not used ever - return -1; - } - -} diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/askyblock/ASkyBlockIslandResets.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/askyblock/ASkyBlockIslandResets.java deleted file mode 100644 index 9b2adf366..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/askyblock/ASkyBlockIslandResets.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.djrapitops.pluginbridge.plan.askyblock; - -import com.wasteofplastic.askyblock.ASkyBlockAPI; -import main.java.com.djrapitops.plan.data.additional.PluginData; - -import java.io.Serializable; -import java.util.UUID; - -/** - * PluginData class for ASkyBlock-plugin. - * - * @author Rsl1122 - * @since 3.5.0 - */ -public class ASkyBlockIslandResets extends PluginData { - - private final ASkyBlockAPI api; - - /** - * Class Constructor, sets the parameters of the PluginData object. - * - * @param aaAPI ASkyBlockAPI - */ - public ASkyBlockIslandResets(ASkyBlockAPI aaAPI) { - super("ASkyBlock", "island_resets_left"); - this.api = aaAPI; - super.setIcon("refresh"); - super.setPrefix("Island Resets Left: "); - } - - @Override - public String getHtmlReplaceValue(String modifierPrefix, UUID uuid) { - return parseContainer(modifierPrefix, Integer.toString(api.getResetsLeft(uuid))); - - } - - @Override - public Serializable getValue(UUID uuid) { - //Not used ever - return -1; - } - -} diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/askyblock/ASkyBlockIslands.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/askyblock/ASkyBlockIslands.java deleted file mode 100644 index 224982e07..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/askyblock/ASkyBlockIslands.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.djrapitops.pluginbridge.plan.askyblock; - -import com.wasteofplastic.askyblock.ASkyBlockAPI; -import main.java.com.djrapitops.plan.data.additional.AnalysisType; -import main.java.com.djrapitops.plan.data.additional.PluginData; - -import java.io.Serializable; -import java.util.UUID; - -/** - * PluginData class for ASkyBlock-plugin. - * - * @author Rsl1122 - * @since 3.5.0 - */ -public class ASkyBlockIslands extends PluginData { - - private final ASkyBlockAPI api; - - /** - * Class Constructor, sets the parameters of the PluginData object. - * - * @param aaAPI ASkyBlockAPI - */ - public ASkyBlockIslands(ASkyBlockAPI aaAPI) { - super("ASkyBlock", "island_count", AnalysisType.HTML); - this.api = aaAPI; - super.setIcon("street-view"); - super.setPrefix("Islands: "); - } - - @Override - public String getHtmlReplaceValue(String modifierPrefix, UUID uuid) { - int count = api.getIslandCount(); - if (count > 0) { - return parseContainer(modifierPrefix, Integer.toString(count)); - } - return parseContainer(modifierPrefix, "0"); - } - - @Override - public Serializable getValue(UUID uuid) { - //Not used ever - return -1; - } - -} diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/essentials/EssentialsData.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/essentials/EssentialsData.java new file mode 100644 index 000000000..6e8792968 --- /dev/null +++ b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/essentials/EssentialsData.java @@ -0,0 +1,76 @@ +/* + * 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 com.djrapitops.pluginbridge.plan.essentials; + +import com.earth2me.essentials.Essentials; +import com.earth2me.essentials.User; +import com.earth2me.essentials.UserMap; +import main.java.com.djrapitops.plan.data.additional.*; + +import java.util.*; + +/** + * //TODO Class Javadoc Comment + * + * @author Rsl1122 + */ +public class EssentialsData extends PluginData { + + private final Essentials essentials; + + public EssentialsData(Essentials essentials) { + super(ContainerSize.THIRD, "Essentials"); + super.setPluginIcon("flask"); + super.setIconColor("deep-orange"); + this.essentials = essentials; + } + + @Override + public InspectContainer getPlayerData(UUID uuid, InspectContainer inspectContainer) throws Exception { + if (essentials.getUserMap().userExists(uuid)) { + User user = essentials.getUser(uuid); + + boolean jailed = user.isJailed(); + boolean muted = user.isMuted(); + + inspectContainer.addValue(getWithIcon("Jailed", "ban", "deep-orange"), jailed ? "Yes" : "No"); + inspectContainer.addValue(getWithIcon("Muted", "bell-slash-o", "deep-orange"), muted ? "Yes" : "No"); + } else { + inspectContainer.addValue("No Essentials Data for this user", "-"); + } + return inspectContainer; + } + + @Override + public AnalysisContainer getServerData(Collection uuids, AnalysisContainer analysisContainer) throws Exception { + UserMap userMap = essentials.getUserMap(); + + Map jailed = new HashMap<>(); + Map muted = new HashMap<>(); + for (UUID uuid : uuids) { + if (userMap.userExists(uuid)) { + User user = essentials.getUser(uuid); + jailed.put(uuid, user.isJailed() ? "Yes" : "No"); + muted.put(uuid, user.isMuted() ? "Yes" : "No"); + } + } + + analysisContainer.addPlayerTableValues(getWithIcon("Jailed", "ban"), jailed); + analysisContainer.addPlayerTableValues(getWithIcon("Muted", "bell-slash-o"), muted); + + + List warpsList = new ArrayList<>(essentials.getWarps().getList()); + if (!warpsList.isEmpty()) { + TableContainer warps = new TableContainer(getWithIcon("Warp", "map-marker"), getWithIcon("Command", "terminal")); + Collections.sort(warpsList); + for (String warp : warpsList) { + warps.addRow(warp, "/warp " + warp); + } + analysisContainer.addTable("WarpTable", warps); + } + + return analysisContainer; + } +} \ No newline at end of file diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/essentials/EssentialsHook.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/essentials/EssentialsHook.java index 6f24cd865..7fb4dabff 100644 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/essentials/EssentialsHook.java +++ b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/essentials/EssentialsHook.java @@ -31,9 +31,7 @@ public class EssentialsHook extends Hook { public void hook() throws NoClassDefFoundError { if (enabled) { Essentials ess = getPlugin(Essentials.class); - addPluginDataSource(new EssentialsJailed(ess)); - addPluginDataSource(new EssentialsMuted(ess)); - addPluginDataSource(new EssentialsWarps(ess)); + addPluginDataSource(new EssentialsData(ess)); } } } diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/essentials/EssentialsJailed.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/essentials/EssentialsJailed.java deleted file mode 100644 index d3c643f23..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/essentials/EssentialsJailed.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.djrapitops.pluginbridge.plan.essentials; - -import com.earth2me.essentials.Essentials; -import com.earth2me.essentials.User; -import java.io.Serializable; -import java.util.UUID; -import main.java.com.djrapitops.plan.data.additional.AnalysisType; -import main.java.com.djrapitops.plan.data.additional.PluginData; - -/** - * PluginData class for Essentials-plugin. - * - * Registered to the plugin by EssentialsHook - * - * Gives Jailed boolean value. - * - * @author Rsl1122 - * @since 3.1.0 - * @see EssentialsHook - */ -public class EssentialsJailed extends PluginData { - - private final Essentials essentials; - - /** - * Class Constructor, sets the parameters of the PluginData object. - * - * @param essentials Instance of Essentials plugin. - */ - public EssentialsJailed(Essentials essentials) { - super("Essentials", "jailed", AnalysisType.BOOLEAN_PERCENTAGE, AnalysisType.BOOLEAN_TOTAL); - this.essentials = essentials; - super.setIcon("ban"); - super.setAnalysisOnly(false); - super.setPrefix("Jailed: "); - } - - @Override - public String getHtmlReplaceValue(String modifier, UUID uuid) { - User user = essentials.getUser(uuid); - if (user != null) { - return parseContainer(modifier, user.isJailed() ? "Yes" : "No"); - } - return parseContainer(modifier, "No"); - } - - @Override - public Serializable getValue(UUID uuid) { - User user = essentials.getUser(uuid); - return user != null && user.isJailed(); - } - -} diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/essentials/EssentialsMuted.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/essentials/EssentialsMuted.java deleted file mode 100644 index d9d7c83f4..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/essentials/EssentialsMuted.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.djrapitops.pluginbridge.plan.essentials; - -import com.earth2me.essentials.Essentials; -import com.earth2me.essentials.User; -import java.io.Serializable; -import java.util.UUID; -import main.java.com.djrapitops.plan.data.additional.AnalysisType; -import main.java.com.djrapitops.plan.data.additional.PluginData; - -/** - * PluginData class for Essentials-plugin. - * - * Registered to the plugin by EssentialsHook - * - * Gives Muted boolean value. - * - * @author Rsl1122 - * @since 3.1.0 - * @see EssentialsHook - */ -public class EssentialsMuted extends PluginData { - - private final Essentials essentials; - - /** - * Class Constructor, sets the parameters of the PluginData object. - * - * @param essentials Instance of Essentials plugin. - */ - public EssentialsMuted(Essentials essentials) { - super("Essentials", "muted", AnalysisType.BOOLEAN_PERCENTAGE, AnalysisType.BOOLEAN_TOTAL); - this.essentials = essentials; - super.setIcon("bell-slash-o"); - super.setAnalysisOnly(false); - super.setPrefix("Muted: "); - } - - @Override - public String getHtmlReplaceValue(String modifier, UUID uuid) { - User user = essentials.getUser(uuid); - if (user != null) { - return parseContainer("", user.isMuted() ? "Yes" : "No"); - } - return parseContainer(modifier, "No"); - } - - @Override - public Serializable getValue(UUID uuid) { - User user = essentials.getUser(uuid); - return user != null && user.isMuted(); - } - -} diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/essentials/EssentialsWarps.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/essentials/EssentialsWarps.java deleted file mode 100644 index 722221d6e..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/essentials/EssentialsWarps.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.djrapitops.pluginbridge.plan.essentials; - -import com.earth2me.essentials.Essentials; -import com.earth2me.essentials.Warps; -import main.java.com.djrapitops.plan.data.additional.AnalysisType; -import main.java.com.djrapitops.plan.data.additional.PluginData; -import main.java.com.djrapitops.plan.utilities.html.Html; - -import java.io.Serializable; -import java.util.*; - -/** - * PluginData class for Essentials-plugin. - * - * Registered to the plugin by EssentialsHook - * - * Gives a list of warps as a String value. - * - * @author Rsl1122 - * @since 3.1.0 - * @see EssentialsHook - */ -public class EssentialsWarps extends PluginData { - - private final Essentials essentials; - - /** - * Class Constructor, sets the parameters of the PluginData object. - * - * @param essentials Instance of Essentials plugin. - */ - public EssentialsWarps(Essentials essentials) { - super("Essentials", "warps", AnalysisType.HTML); - this.essentials = essentials; - String warps = Html.FONT_AWESOME_ICON.parse("map-marker") + " Warps"; - String command = Html.FONT_AWESOME_ICON.parse("fa-terminal") + " Command"; - super.setPrefix(Html.TABLE_START_2.parse(warps, command)); - super.setSuffix(Html.TABLE_END.parse()); - } - - @Override - public String getHtmlReplaceValue(String modifier, UUID uuid) { - Warps warps = essentials.getWarps(); - if (!warps.isEmpty()) { - Collection warpList = warps.getList(); - - return parseContainer("", getTableContents(new ArrayList<>(warpList))); - } - return parseContainer("", Html.TABLELINE_2.parse("No Warps.", "")); - } - - private String getTableContents(List warps) { - Collections.sort(warps); - StringBuilder html = new StringBuilder(); - if (warps.isEmpty()) { - html.append(Html.TABLELINE_4.parse("No Factions", "", "", "")); - } else { - for (String warp : warps) { - html.append(Html.TABLELINE_2.parse(warp, "/warp " + warp)); - } - } - return html.toString(); - } - - @Override - public Serializable getValue(UUID uuid) { - return -1; - } - -}

${0}${1}