mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-11-05 10:20:23 +01:00
MCMMO Data
This commit is contained in:
parent
5b145601bf
commit
1ef2b1462c
@ -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<SkillType> 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<UUID> 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<PlayerProfile> 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<SkillType> 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;
|
||||||
|
}
|
||||||
|
}
|
@ -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.
|
|
||||||
* <p>
|
|
||||||
* 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") + "<br>";
|
|
||||||
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<PlayerProfile> 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<SkillType> 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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,8 +1,8 @@
|
|||||||
package com.djrapitops.pluginbridge.plan.mcmmo;
|
package com.djrapitops.pluginbridge.plan.mcmmo;
|
||||||
|
|
||||||
import main.java.com.djrapitops.plan.data.additional.HookHandler;
|
|
||||||
import com.djrapitops.pluginbridge.plan.Hook;
|
import com.djrapitops.pluginbridge.plan.Hook;
|
||||||
import main.java.com.djrapitops.plan.api.API;
|
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.
|
* 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 {
|
public void hook() throws NoClassDefFoundError {
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
addPluginDataSource(new McmmoInspectSkillTable());
|
addPluginDataSource(new McMmoData());
|
||||||
addPluginDataSource(new McmmoAnalysisSkillTable());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.
|
|
||||||
* <p>
|
|
||||||
* 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") + "<br>";
|
|
||||||
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<SkillType> 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;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user