From 1ef2b1462cab8850a84ecf9cc00a8f4adfab01a6 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Sun, 26 Nov 2017 14:46:17 +0200 Subject: [PATCH] MCMMO Data --- .../pluginbridge/plan/mcmmo/McMmoData.java | 93 +++++++++++++++++++ .../plan/mcmmo/McmmoAnalysisSkillTable.java | 75 --------------- .../pluginbridge/plan/mcmmo/McmmoHook.java | 5 +- .../plan/mcmmo/McmmoInspectSkillTable.java | 69 -------------- 4 files changed, 95 insertions(+), 147 deletions(-) create mode 100644 PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/mcmmo/McMmoData.java delete mode 100644 PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/mcmmo/McmmoAnalysisSkillTable.java delete mode 100644 PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/mcmmo/McmmoInspectSkillTable.java diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/mcmmo/McMmoData.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/mcmmo/McMmoData.java new file mode 100644 index 000000000..79f58a876 --- /dev/null +++ b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/mcmmo/McMmoData.java @@ -0,0 +1,93 @@ +/* + * 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.mcmmo; + +import com.gmail.nossr50.database.DatabaseManager; +import com.gmail.nossr50.datatypes.player.McMMOPlayer; +import com.gmail.nossr50.datatypes.player.PlayerProfile; +import com.gmail.nossr50.datatypes.skills.SkillType; +import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.util.player.UserManager; +import main.java.com.djrapitops.plan.data.additional.*; +import main.java.com.djrapitops.plan.utilities.FormatUtils; +import main.java.com.djrapitops.plan.utilities.analysis.MathUtils; +import main.java.com.djrapitops.plan.utilities.html.Html; +import org.apache.commons.lang3.StringUtils; + +import java.io.Serializable; +import java.util.*; +import java.util.stream.Collectors; + +import static org.bukkit.Bukkit.getOnlinePlayers; + +/** + * PluginData for McMmo plugin. + * + * @author Rsl1122 + */ +public class McMmoData extends PluginData { + + public McMmoData() { + super(ContainerSize.THIRD, "MCMMO"); + super.setIconColor("indigo"); + super.setPluginIcon("compass"); + } + + @Override + public InspectContainer getPlayerData(UUID uuid, InspectContainer inspectContainer) throws Exception { + DatabaseManager db = mcMMO.getDatabaseManager(); + + PlayerProfile profile = db.loadPlayerProfile(uuid); + + String skillS = Html.FONT_AWESOME_ICON.parse("star") + " Skill"; + String levelS = Html.FONT_AWESOME_ICON.parse("plus") + " Level"; + TableContainer skillTable = new TableContainer(skillS, levelS); + skillTable.setColor("indigo"); + + List skills = new ArrayList<>(); + skills.addAll(Arrays.stream(SkillType.values()).distinct().collect(Collectors.toList())); + for (SkillType skill : skills) { + skillTable.addRow(StringUtils.capitalize(skill.getName().toLowerCase()), profile.getSkillLevel(skill)); + } + + return inspectContainer; + } + + @Override + public AnalysisContainer getServerData(Collection collection, AnalysisContainer analysisContainer) throws Exception { + String skillS = Html.FONT_AWESOME_ICON.parse("star") + " Skill"; + String tLevel = Html.FONT_AWESOME_ICON.parse("plus") + " Total Level"; + String aLevel = Html.FONT_AWESOME_ICON.parse("plus") + " Average Level"; + + analysisContainer.addValue("Only Online Players Shown", "Skills available on Inspect pages."); + + TableContainer skillTable = new TableContainer(skillS, tLevel, aLevel); + skillTable.setColor("indigo"); + + List profiles = getOnlinePlayers().stream() + .filter(Objects::nonNull) + .map(UserManager::getOfflinePlayer) + .filter(Objects::nonNull) + .map(McMMOPlayer::getProfile) + .collect(Collectors.toList()); + if (profiles.isEmpty()) { + skillTable.addRow("No players online"); + } + + List skills = new ArrayList<>(); + skills.addAll(Arrays.stream(SkillType.values()).distinct().collect(Collectors.toList())); + + for (SkillType skill : skills) { + long total = MathUtils.sumInt(profiles.stream().map(p -> (Serializable) p.getSkillLevel(skill))); + skillTable.addRow( + StringUtils.capitalize(skill.getName().toLowerCase()), + Long.toString(total), + FormatUtils.cutDecimals(MathUtils.average((int) total, profiles.size())) + ); + } + + return analysisContainer; + } +} \ No newline at end of file diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/mcmmo/McmmoAnalysisSkillTable.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/mcmmo/McmmoAnalysisSkillTable.java deleted file mode 100644 index 94b1d627d..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/mcmmo/McmmoAnalysisSkillTable.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.djrapitops.pluginbridge.plan.mcmmo; - -import com.gmail.nossr50.datatypes.player.McMMOPlayer; -import com.gmail.nossr50.datatypes.player.PlayerProfile; -import com.gmail.nossr50.datatypes.skills.SkillType; -import com.gmail.nossr50.util.player.UserManager; -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.FormatUtils; -import main.java.com.djrapitops.plan.utilities.analysis.MathUtils; -import main.java.com.djrapitops.plan.utilities.html.Html; -import org.apache.commons.lang.StringUtils; - -import java.io.Serializable; -import java.util.*; -import java.util.stream.Collectors; - -import static org.bukkit.Bukkit.getOnlinePlayers; - -/** - * PluginData class for McMMO-plugin. - *

- * Registered to the plugin by McmmoHook - * - * @author Rsl1122 - * @see McmmoHook - * @since 3.2.1 - */ -public class McmmoAnalysisSkillTable extends PluginData { - - /** - * Class Constructor, sets the parameters of the PluginData object. - */ - public McmmoAnalysisSkillTable() { - super("McMMO", "analysis_table", AnalysisType.HTML); - final String skill = Html.FONT_AWESOME_ICON.parse("star") + " Skill"; - final String tLevel = Html.FONT_AWESOME_ICON.parse("plus") + " Total Level"; - final String aLevel = Html.FONT_AWESOME_ICON.parse("plus") + " Average Level"; - final String notice = "Only online players shown. " + Html.LINK_EXTERNAL.parse("https://github.com/mcMMO-Dev/mcMMO/blob/master/src/main/java/com/gmail/nossr50/util/player/UserManager.java#L105", "More info") + "
"; - super.setPrefix(notice + Html.TABLE_START_3.parse(skill, tLevel, aLevel)); - super.setSuffix(Html.TABLE_END.parse()); - } - - @Override - public String getHtmlReplaceValue(String modifierPrefix, UUID uuid) { - List profiles = getOnlinePlayers().stream() - .filter(Objects::nonNull) - .map(UserManager::getOfflinePlayer) - .filter(Objects::nonNull) - .map(McMMOPlayer::getProfile) - .collect(Collectors.toList()); - if (profiles.isEmpty()) { - return parseContainer("", Html.TABLELINE_3.parse("No players online", "", "")); - } - - final List skills = new ArrayList<>(); - skills.addAll(Arrays.stream(SkillType.values()).distinct().collect(Collectors.toList())); - - final StringBuilder html = new StringBuilder(); - for (SkillType skill : skills) { - long total = MathUtils.sumInt(profiles.stream().map(p -> (Serializable) p.getSkillLevel(skill))); - html.append(Html.TABLELINE_3.parse( - StringUtils.capitalize(skill.getName().toLowerCase()), - Long.toString(total), - FormatUtils.cutDecimals(MathUtils.average((int) total, profiles.size())) - )); - } - return parseContainer("", html.toString()); - } - - @Override - public Serializable getValue(UUID uuid) { - return -1; - } -} diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/mcmmo/McmmoHook.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/mcmmo/McmmoHook.java index 5a7b2a57e..185b5af37 100644 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/mcmmo/McmmoHook.java +++ b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/mcmmo/McmmoHook.java @@ -1,8 +1,8 @@ package com.djrapitops.pluginbridge.plan.mcmmo; -import main.java.com.djrapitops.plan.data.additional.HookHandler; import com.djrapitops.pluginbridge.plan.Hook; import main.java.com.djrapitops.plan.api.API; +import main.java.com.djrapitops.plan.data.additional.HookHandler; /** * A Class responsible for hooking to MCMMO and registering data sources. @@ -26,8 +26,7 @@ public class McmmoHook extends Hook { public void hook() throws NoClassDefFoundError { if (enabled) { - addPluginDataSource(new McmmoInspectSkillTable()); - addPluginDataSource(new McmmoAnalysisSkillTable()); + addPluginDataSource(new McMmoData()); } } } diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/mcmmo/McmmoInspectSkillTable.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/mcmmo/McmmoInspectSkillTable.java deleted file mode 100644 index 75826d0d2..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/mcmmo/McmmoInspectSkillTable.java +++ /dev/null @@ -1,69 +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 com.djrapitops.pluginbridge.plan.mcmmo; - -import com.gmail.nossr50.datatypes.player.McMMOPlayer; -import com.gmail.nossr50.datatypes.player.PlayerProfile; -import com.gmail.nossr50.datatypes.skills.SkillType; -import com.gmail.nossr50.util.player.UserManager; -import main.java.com.djrapitops.plan.data.additional.PluginData; -import main.java.com.djrapitops.plan.utilities.html.Html; -import org.apache.commons.lang.StringUtils; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.UUID; -import java.util.stream.Collectors; - -import static org.bukkit.Bukkit.getOfflinePlayer; - -/** - * PluginData class for McMMO-plugin. - *

- * Registered to the plugin by McmmoHook - * - * @author Rsl1122 - * @see McmmoHook - * @since 3.2.1 - */ -public class McmmoInspectSkillTable extends PluginData { - - /** - * Class Constructor, sets the parameters of the PluginData object. - */ - public McmmoInspectSkillTable() { - super("McMMO", "inspect_skill_table"); - super.setAnalysisOnly(false); - final String skill = Html.FONT_AWESOME_ICON.parse("star") + " Skill"; - final String level = Html.FONT_AWESOME_ICON.parse("plus") + " Level"; - final String notice = "Only online players shown. " + Html.LINK_EXTERNAL.parse("https://github.com/mcMMO-Dev/mcMMO/blob/master/src/main/java/com/gmail/nossr50/util/player/UserManager.java#L105", "More info") + "
"; - super.setPrefix(notice + Html.TABLE_START_2.parse(skill, level)); - super.setSuffix(Html.TABLE_END.parse()); - } - - @Override - public String getHtmlReplaceValue(String modifierPrefix, UUID uuid) { - McMMOPlayer user = UserManager.getOfflinePlayer(getOfflinePlayer(uuid)); - if (user == null) { - return parseContainer("", Html.TABLELINE_2.parse("User not known/online", "")); - } - final PlayerProfile skillProfile = user.getProfile(); - final List skills = new ArrayList<>(); - skills.addAll(Arrays.stream(SkillType.values()).distinct().collect(Collectors.toList())); - final StringBuilder html = new StringBuilder(); - for (SkillType skill : skills) { - html.append(Html.TABLELINE_2.parse(StringUtils.capitalize(skill.getName().toLowerCase()), skillProfile.getSkillLevel(skill))); - } - return parseContainer("", html.toString()); - } - - @Override - public Serializable getValue(UUID uuid) { - return -1; - } -}