v1.4.3 Bugfix and Added comments
Fixed AAHook using wrong method. (Coding when tired is not good!) Flipped operation for usingUUID Added comments for later in case I forget what happens in DataUtils and DataFormatUtils
This commit is contained in:
parent
ce8490f814
commit
19d688f498
|
@ -21,6 +21,7 @@ public class AdvancedAchievementsHook implements Hook {
|
||||||
public AdvancedAchievementsHook(Plan plugin) throws Exception, NoClassDefFoundError {
|
public AdvancedAchievementsHook(Plan plugin) throws Exception, NoClassDefFoundError {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.aAPlugin = getPlugin(AdvancedAchievements.class);
|
this.aAPlugin = getPlugin(AdvancedAchievements.class);
|
||||||
|
// Version was important because 4.0.3 added required method for Offline players
|
||||||
String[] aAVersion = aAPlugin.getDescription().getVersion().split(".");
|
String[] aAVersion = aAPlugin.getDescription().getVersion().split(".");
|
||||||
try {
|
try {
|
||||||
double versionNumber = Double.parseDouble(aAVersion[0] + "." + aAVersion[1] + aAVersion[2]);
|
double versionNumber = Double.parseDouble(aAVersion[0] + "." + aAVersion[1] + aAVersion[2]);
|
||||||
|
@ -31,6 +32,7 @@ public class AdvancedAchievementsHook implements Hook {
|
||||||
plugin.logError("Advanced Achievements 4.0.3 or above required for Offline players");
|
plugin.logError("Advanced Achievements 4.0.3 or above required for Offline players");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
// Some versions were formatted with two numbers
|
||||||
try {
|
try {
|
||||||
double versionNumber = Double.parseDouble(aAVersion[0] + "." + aAVersion[1]);
|
double versionNumber = Double.parseDouble(aAVersion[0] + "." + aAVersion[1]);
|
||||||
if (versionNumber >= 4.03) {
|
if (versionNumber >= 4.03) {
|
||||||
|
@ -43,7 +45,7 @@ public class AdvancedAchievementsHook implements Hook {
|
||||||
plugin.logToFile("AAHOOK\nError getting version number.\n" + e2);
|
plugin.logToFile("AAHOOK\nError getting version number.\n" + e2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Get total number of Achievements
|
||||||
for (NormalAchievements category : NormalAchievements.values()) {
|
for (NormalAchievements category : NormalAchievements.values()) {
|
||||||
String categoryName = category.toString();
|
String categoryName = category.toString();
|
||||||
if (aAPlugin.getDisabledCategorySet().contains(categoryName)) {
|
if (aAPlugin.getDisabledCategorySet().contains(categoryName)) {
|
||||||
|
@ -65,15 +67,21 @@ public class AdvancedAchievementsHook implements Hook {
|
||||||
if (!aAPlugin.getDisabledCategorySet().contains("Commands")) {
|
if (!aAPlugin.getDisabledCategorySet().contains("Commands")) {
|
||||||
totalAchievements += aAPlugin.getPluginConfig().getConfigurationSection("Commands").getKeys(false).size();
|
totalAchievements += aAPlugin.getPluginConfig().getConfigurationSection("Commands").getKeys(false).size();
|
||||||
}
|
}
|
||||||
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HashMap<String, String> getData(String player) throws Exception {
|
public HashMap<String, String> getData(String player) throws Exception {
|
||||||
HashMap<String, String> data = new HashMap<>();
|
HashMap<String, String> data = new HashMap<>();
|
||||||
|
// Check if achievements exist
|
||||||
if (totalAchievements > 0) {
|
if (totalAchievements > 0) {
|
||||||
UUID uuid = UUIDFetcher.getUUIDOf(player);
|
UUID uuid = UUIDFetcher.getUUIDOf(player);
|
||||||
try {
|
try {
|
||||||
|
// Check if correct method is present
|
||||||
if (this.usingUUID) {
|
if (this.usingUUID) {
|
||||||
|
data.put("AAC-ACHIEVEMENTS", aAPlugin.getDb().getPlayerAchievementsAmount(uuid.toString()) + " / " + totalAchievements);
|
||||||
|
} else {
|
||||||
|
// Fallback method for older versions, only returns Online player data
|
||||||
Player p = getPlayer(player);
|
Player p = getPlayer(player);
|
||||||
if (uuid != null) {
|
if (uuid != null) {
|
||||||
p = getPlayer(uuid);
|
p = getPlayer(uuid);
|
||||||
|
@ -81,8 +89,6 @@ public class AdvancedAchievementsHook implements Hook {
|
||||||
if (p != null) {
|
if (p != null) {
|
||||||
data.put("AAC-ACHIEVEMENTS", aAPlugin.getDb().getPlayerAchievementsAmount(p) + " / " + totalAchievements);
|
data.put("AAC-ACHIEVEMENTS", aAPlugin.getDb().getPlayerAchievementsAmount(p) + " / " + totalAchievements);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
data.put("AAC-ACHIEVEMENTS", aAPlugin.getDb().getPlayerAchievementsAmount(uuid.toString()) + " / " + totalAchievements);
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
plugin.logToFile("AAHOOK-GetData\nFailed to get data\n" + e + "\nfor: " + player);
|
plugin.logToFile("AAHOOK-GetData\nFailed to get data\n" + e + "\nfor: " + player);
|
||||||
|
|
|
@ -7,7 +7,6 @@ import com.earth2me.essentials.Essentials;
|
||||||
import com.earth2me.essentials.User;
|
import com.earth2me.essentials.User;
|
||||||
import net.ess3.api.IEssentials;
|
import net.ess3.api.IEssentials;
|
||||||
import com.earth2me.essentials.craftbukkit.BanLookup;
|
import com.earth2me.essentials.craftbukkit.BanLookup;
|
||||||
import com.gmail.nossr50.util.uuid.UUIDFetcher;
|
|
||||||
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
|
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
|
||||||
import org.bukkit.BanList;
|
import org.bukkit.BanList;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
@ -22,6 +21,7 @@ public class EssentialsHook implements Hook {
|
||||||
this.plugin = p;
|
this.plugin = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Gets data with Essentials own User methods
|
||||||
@Override
|
@Override
|
||||||
public HashMap<String, String> getData(String player) throws Exception {
|
public HashMap<String, String> getData(String player) throws Exception {
|
||||||
HashMap<String, String> data = new HashMap<>();
|
HashMap<String, String> data = new HashMap<>();
|
||||||
|
|
|
@ -8,9 +8,7 @@ import java.util.HashMap;
|
||||||
import com.massivecraft.factions.entity.MPlayer;
|
import com.massivecraft.factions.entity.MPlayer;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||||
import static org.bukkit.Bukkit.getPlayer;
|
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
|
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
|
||||||
|
|
||||||
public class FactionsHook implements Hook {
|
public class FactionsHook implements Hook {
|
||||||
|
@ -28,11 +26,16 @@ public class FactionsHook implements Hook {
|
||||||
HashMap<String, String> data = new HashMap<>();
|
HashMap<String, String> data = new HashMap<>();
|
||||||
MPlayer mplayer;
|
MPlayer mplayer;
|
||||||
UUID uuid = UUIDFetcher.getUUIDOf(player);
|
UUID uuid = UUIDFetcher.getUUIDOf(player);
|
||||||
OfflinePlayer p = getOfflinePlayer(player);
|
OfflinePlayer p;
|
||||||
if (uuid != null) {
|
if (uuid != null) {
|
||||||
p = getOfflinePlayer(uuid);
|
p = getOfflinePlayer(uuid);
|
||||||
|
mplayer = MPlayer.get(uuid);
|
||||||
|
} else {
|
||||||
|
// Fallback method if UUID is not found
|
||||||
|
p = getOfflinePlayer(player);
|
||||||
|
mplayer = MPlayer.get(p.getUniqueId());
|
||||||
}
|
}
|
||||||
mplayer = MPlayer.get(p.getUniqueId());
|
// Check if player has played on server
|
||||||
if (p.hasPlayedBefore()) {
|
if (p.hasPlayedBefore()) {
|
||||||
if (mplayer.hasFaction()) {
|
if (mplayer.hasFaction()) {
|
||||||
data.put("FAC-FACTION", mplayer.getFactionName());
|
data.put("FAC-FACTION", mplayer.getFactionName());
|
||||||
|
|
|
@ -10,8 +10,6 @@ import com.palmergames.bukkit.towny.exceptions.TownyException;
|
||||||
import com.palmergames.bukkit.towny.object.Resident;
|
import com.palmergames.bukkit.towny.object.Resident;
|
||||||
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
||||||
import com.palmergames.bukkit.util.BukkitTools;
|
import com.palmergames.bukkit.util.BukkitTools;
|
||||||
import com.palmergames.bukkit.util.Colors;
|
|
||||||
import com.palmergames.util.StringMgmt;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
|
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
|
||||||
|
|
|
@ -24,9 +24,11 @@ public class VaultHook implements Hook {
|
||||||
HashMap<String, String> data = new HashMap<>();
|
HashMap<String, String> data = new HashMap<>();
|
||||||
try {
|
try {
|
||||||
UUID uuid = UUIDFetcher.getUUIDOf(player);
|
UUID uuid = UUIDFetcher.getUUIDOf(player);
|
||||||
OfflinePlayer p = getOfflinePlayer(player);
|
OfflinePlayer p;
|
||||||
if (uuid != null) {
|
if (uuid != null) {
|
||||||
p = getOfflinePlayer(uuid);
|
p = getOfflinePlayer(uuid);
|
||||||
|
} else {
|
||||||
|
p = getOfflinePlayer(player);
|
||||||
}
|
}
|
||||||
if (p.hasPlayedBefore()) {
|
if (p.hasPlayedBefore()) {
|
||||||
data.put("ECO-BALANCE", this.econ.format(this.econ.getBalance(p)));
|
data.put("ECO-BALANCE", this.econ.format(this.econ.getBalance(p)));
|
||||||
|
|
|
@ -18,11 +18,13 @@ public class DataFormatUtils {
|
||||||
Plan plugin = getPlugin(Plan.class);
|
Plan plugin = getPlugin(Plan.class);
|
||||||
for (String key : data.keySet()) {
|
for (String key : data.keySet()) {
|
||||||
try {
|
try {
|
||||||
|
// Process OnTime empty data (returns -1 if empty)
|
||||||
if (key.subSequence(0, 3).equals("ONT")) {
|
if (key.subSequence(0, 3).equals("ONT")) {
|
||||||
if ((data.get(key)).equals("-1") || (data.get(key)).equals("-1.0")) {
|
if ((data.get(key)).equals("-1") || (data.get(key)).equals("-1.0")) {
|
||||||
remove.add(key);
|
remove.add(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Process failed PlaceholderAPI requests (%string%)
|
||||||
if (key.subSequence(0, 3).equals("PHA")) {
|
if (key.subSequence(0, 3).equals("PHA")) {
|
||||||
if ((data.get(key)).contains("%")) {
|
if ((data.get(key)).contains("%")) {
|
||||||
remove.add(key);
|
remove.add(key);
|
||||||
|
@ -32,10 +34,12 @@ public class DataFormatUtils {
|
||||||
plugin.logToFile("FORMAT-Remove\n" + e + "\n" + key);
|
plugin.logToFile("FORMAT-Remove\n" + e + "\n" + key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Remove faulty data to prevent TOW-LAST LOGIN from being removed with empty data
|
||||||
for (String removedKey : remove) {
|
for (String removedKey : remove) {
|
||||||
data.remove(removedKey);
|
data.remove(removedKey);
|
||||||
}
|
}
|
||||||
remove.clear();
|
remove.clear();
|
||||||
|
// Process Towny data (Empty returns Java Epoch date 1970 for REGISTERED)
|
||||||
if (data.get("TOW-REGISTERED") != null) {
|
if (data.get("TOW-REGISTERED") != null) {
|
||||||
if (data.get("TOW-REGISTERED").contains("1970")) {
|
if (data.get("TOW-REGISTERED").contains("1970")) {
|
||||||
remove.add("TOW-REGISTERED");
|
remove.add("TOW-REGISTERED");
|
||||||
|
@ -48,14 +52,31 @@ public class DataFormatUtils {
|
||||||
remove.add("TOW-PLOT OPTIONS");
|
remove.add("TOW-PLOT OPTIONS");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// If both OnTime and Towny data found, OnTime priority.
|
||||||
if (data.get("ONT-LAST LOGIN") != null) {
|
if (data.get("ONT-LAST LOGIN") != null) {
|
||||||
remove.add("TOW-LAST LOGIN");
|
remove.add("TOW-LAST LOGIN");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Remove faulty Towny data
|
||||||
for (String removedKey : remove) {
|
for (String removedKey : remove) {
|
||||||
data.remove(removedKey);
|
data.remove(removedKey);
|
||||||
}
|
}
|
||||||
|
// Remove faulty Essentials SINCE data, reload turns data to 0
|
||||||
|
String[] keysRemoveIfZero = {"ESS-ONLINE SINCE", "ESS-OFFLINE SINCE"};
|
||||||
|
for (String key : keysRemoveIfZero) {
|
||||||
|
if (data.get(key) != null) {
|
||||||
|
if (data.get(key).equals("0")) {
|
||||||
|
data.remove(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Remove OnTime Total Votes if SuperbVote is present
|
||||||
|
if (data.get("SVO-VOTES") != null) {
|
||||||
|
if (data.get("ONT-TOTAL VOTES") != null) {
|
||||||
|
data.remove("ONT-TOTAL VOTES");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Format TimeStamps
|
||||||
String[] keysTimestamp = {"ONT-LAST LOGIN"};
|
String[] keysTimestamp = {"ONT-LAST LOGIN"};
|
||||||
for (String key : keysTimestamp) {
|
for (String key : keysTimestamp) {
|
||||||
if (data.get(key) != null) {
|
if (data.get(key) != null) {
|
||||||
|
@ -70,15 +91,7 @@ public class DataFormatUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String[] keysRemoveIfZero = {"ESS-ONLINE SINCE", "ESS-OFFLINE SINCE"};
|
// Format Milliseconds to readable format
|
||||||
for (String key : keysRemoveIfZero) {
|
|
||||||
if (data.get(key) != null) {
|
|
||||||
if (data.get(key).equals("0")) {
|
|
||||||
data.remove(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String[] keysTimeAmount = {"ONT-TOTAL PLAY", "ESS-ONLINE SINCE", "ESS-OFFLINE SINCE"};
|
String[] keysTimeAmount = {"ONT-TOTAL PLAY", "ESS-ONLINE SINCE", "ESS-OFFLINE SINCE"};
|
||||||
for (String key : keysTimeAmount) {
|
for (String key : keysTimeAmount) {
|
||||||
if (data.get(key) != null) {
|
if (data.get(key) != null) {
|
||||||
|
@ -93,81 +106,41 @@ public class DataFormatUtils {
|
||||||
data.replace(key, formatted);
|
data.replace(key, formatted);
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
|
|
||||||
plugin.logToFile("FORMAT-Since\nError Parsing number.\n" + e + "\n" + data.get(key));
|
plugin.logToFile("FORMAT-Since\nError Parsing number.\n" + e + "\n" + data.get(key));
|
||||||
|
|
||||||
data.remove(key);
|
data.remove(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (data.get("SVO-VOTES") != null) {
|
|
||||||
if (data.get("ONT-TOTAL VOTES") != null) {
|
|
||||||
data.remove("ONT-TOTAL VOTES");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
// Creates a new Date with Epoch second and returns Date and Time String
|
||||||
public static String formatTimeStamp(String string) throws NumberFormatException {
|
public static String formatTimeStamp(String string) throws NumberFormatException {
|
||||||
long ms = Long.parseLong(string);
|
long ms = Long.parseLong(string);
|
||||||
Date sfd = new Date(ms);
|
Date sfd = new Date(ms);
|
||||||
return ("" + sfd).substring(4, 19);
|
return ("" + sfd).substring(4, 19);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Formats Time Since (0 -> string)
|
||||||
public static String formatTimeAmount(String string) throws NumberFormatException {
|
public static String formatTimeAmount(String string) throws NumberFormatException {
|
||||||
String returnValue = "";
|
|
||||||
long ms = Long.parseLong(string);
|
long ms = Long.parseLong(string);
|
||||||
long x = ms / 1000;
|
return turnMsLongToString(ms);
|
||||||
long seconds = x % 60;
|
|
||||||
x /= 60;
|
|
||||||
long minutes = x % 60;
|
|
||||||
x /= 60;
|
|
||||||
long hours = x % 24;
|
|
||||||
x /= 24;
|
|
||||||
long days = x;
|
|
||||||
if (days != 0) {
|
|
||||||
returnValue += days + "d ";
|
|
||||||
}
|
|
||||||
if (hours != 0) {
|
|
||||||
returnValue += hours + "h ";
|
|
||||||
}
|
|
||||||
if (minutes != 0) {
|
|
||||||
returnValue += minutes + "m ";
|
|
||||||
}
|
|
||||||
if (seconds != 0) {
|
|
||||||
returnValue += seconds + "s";
|
|
||||||
}
|
|
||||||
return returnValue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Formats Time Difference String before -> Date now
|
||||||
public static String formatTimeAmountSinceString(String string, Date date) throws NumberFormatException {
|
public static String formatTimeAmountSinceString(String string, Date date) throws NumberFormatException {
|
||||||
String returnValue = "";
|
|
||||||
long ms = (date.toInstant().getEpochSecond() * 1000) - Long.parseLong(string);
|
long ms = (date.toInstant().getEpochSecond() * 1000) - Long.parseLong(string);
|
||||||
long x = ms / 1000;
|
return turnMsLongToString(ms);
|
||||||
long seconds = x % 60;
|
|
||||||
x /= 60;
|
|
||||||
long minutes = x % 60;
|
|
||||||
x /= 60;
|
|
||||||
long hours = x % 24;
|
|
||||||
x /= 24;
|
|
||||||
long days = x;
|
|
||||||
if (days != 0) {
|
|
||||||
returnValue += days + "d ";
|
|
||||||
}
|
|
||||||
if (hours != 0) {
|
|
||||||
returnValue += hours + "h ";
|
|
||||||
}
|
|
||||||
if (minutes != 0) {
|
|
||||||
returnValue += minutes + "m ";
|
|
||||||
}
|
|
||||||
if (seconds != 0) {
|
|
||||||
returnValue += seconds + "s";
|
|
||||||
}
|
|
||||||
return returnValue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Formats Time Difference Date before -> Date now
|
||||||
public static String formatTimeAmountSinceDate(Date before, Date now) throws NumberFormatException {
|
public static String formatTimeAmountSinceDate(Date before, Date now) throws NumberFormatException {
|
||||||
String returnValue = "";
|
|
||||||
long ms = (now.toInstant().getEpochSecond() * 1000) - (before.toInstant().getEpochSecond() * 1000);
|
long ms = (now.toInstant().getEpochSecond() * 1000) - (before.toInstant().getEpochSecond() * 1000);
|
||||||
|
return turnMsLongToString(ms);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Formats long in milliseconds into d:h:m:s string
|
||||||
|
private static String turnMsLongToString(long ms) {
|
||||||
|
String returnValue = "";
|
||||||
long x = ms / 1000;
|
long x = ms / 1000;
|
||||||
long seconds = x % 60;
|
long seconds = x % 60;
|
||||||
x /= 60;
|
x /= 60;
|
||||||
|
@ -191,10 +164,12 @@ public class DataFormatUtils {
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Analysis data Formatting, will be updated after more analysis is added
|
||||||
public static HashMap<String, String> formatAnalyzed(HashMap<String, String> analyzedData) {
|
public static HashMap<String, String> formatAnalyzed(HashMap<String, String> analyzedData) {
|
||||||
return removeExtraDataPoints(analyzedData);
|
return removeExtraDataPoints(analyzedData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Removes letters from a string leaving only numbers and dots.
|
||||||
public static String removeLetters(String dataPoint) {
|
public static String removeLetters(String dataPoint) {
|
||||||
String numbers = "0123456789.";
|
String numbers = "0123456789.";
|
||||||
List<Character> numList = new ArrayList<>();
|
List<Character> numList = new ArrayList<>();
|
||||||
|
@ -211,6 +186,7 @@ public class DataFormatUtils {
|
||||||
return returnString;
|
return returnString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sorts HashMap into Sorted List of Arrays
|
||||||
public static List<String[]> turnDataHashMapToSortedListOfArrays(HashMap<String, String> data) {
|
public static List<String[]> turnDataHashMapToSortedListOfArrays(HashMap<String, String> data) {
|
||||||
List<String[]> dataList = new ArrayList<>();
|
List<String[]> dataList = new ArrayList<>();
|
||||||
for (String key : data.keySet()) {
|
for (String key : data.keySet()) {
|
||||||
|
|
|
@ -16,6 +16,8 @@ import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
|
||||||
|
|
||||||
public class DataUtils {
|
public class DataUtils {
|
||||||
|
|
||||||
|
// allData defined by -a argument in InspectCommand
|
||||||
|
// returns data given by each Hook
|
||||||
public static HashMap<String, String> getData(boolean allData, String playerName) {
|
public static HashMap<String, String> getData(boolean allData, String playerName) {
|
||||||
HashMap<String, String> data = new HashMap<>();
|
HashMap<String, String> data = new HashMap<>();
|
||||||
Plan plugin = getPlugin(Plan.class);
|
Plan plugin = getPlugin(Plan.class);
|
||||||
|
@ -27,7 +29,6 @@ public class DataUtils {
|
||||||
data.putAll(plugin.getHooks().get(hook).getData(playerName));
|
data.putAll(plugin.getHooks().get(hook).getData(playerName));
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
||||||
String toLog = "UTILS-GetData"
|
String toLog = "UTILS-GetData"
|
||||||
+ "\nFailed to getData from " + hook
|
+ "\nFailed to getData from " + hook
|
||||||
+ "\n" + e
|
+ "\n" + e
|
||||||
|
@ -36,18 +37,18 @@ public class DataUtils {
|
||||||
toLog += "\n " + element;
|
toLog += "\n " + element;
|
||||||
}
|
}
|
||||||
plugin.logToFile(toLog);
|
plugin.logToFile(toLog);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns data HashMaps for all pplayers in a HashMap.
|
||||||
public static HashMap<UUID, HashMap<String, String>> getTotalData() {
|
public static HashMap<UUID, HashMap<String, String>> getTotalData() {
|
||||||
HashMap<UUID, HashMap<String, String>> playerData = new HashMap<>();
|
HashMap<UUID, HashMap<String, String>> playerData = new HashMap<>();
|
||||||
for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
|
for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
|
||||||
if (playerData.get(player.getUniqueId()) == null) {
|
if (playerData.get(player.getUniqueId()) == null) {
|
||||||
playerData.put(player.getUniqueId(), getData(true, player.getName()));
|
playerData.put(player.getUniqueId(), getData(true, player.getName()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return playerData;
|
return playerData;
|
||||||
}
|
}
|
||||||
|
@ -71,10 +72,11 @@ public class DataUtils {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HashMap<String, String> analyze(HashMap<UUID, HashMap<String, String>> playerData) {
|
public static HashMap<String, String> analyze(HashMap<UUID, HashMap<String, String>> playerData) {
|
||||||
Plan plugin = getPlugin(Plan.class);
|
Plan plugin = getPlugin(Plan.class);
|
||||||
HashMap<String, List<String>> playerDataLists = new HashMap<>();
|
HashMap<String, List<String>> playerDataLists = new HashMap<>();
|
||||||
|
// Ignore following keys (Strings, unprocessable or irrelevant data)
|
||||||
String[] ignore = {"ESS-BAN REASON", "ESS-OPPED", "ESS-MUTE TIME", "ESS-LOCATION", "ESS-HUNGER", "ESS-LOCATION WORLD",
|
String[] ignore = {"ESS-BAN REASON", "ESS-OPPED", "ESS-MUTE TIME", "ESS-LOCATION", "ESS-HUNGER", "ESS-LOCATION WORLD",
|
||||||
"ESS-NICKNAME", "ESS-UUID", "FAC-FACTION", "ONT-LAST LOGIN", "TOW-TOWN", "TOW-REGISTERED",
|
"ESS-NICKNAME", "ESS-UUID", "FAC-FACTION", "ONT-LAST LOGIN", "TOW-TOWN", "TOW-REGISTERED",
|
||||||
"TOW-LAST LOGIN", "TOW-OWNER OF", "TOW-PLOT PERMS", "TOW-PLOT OPTIONS", "TOW-FRIENDS", "ESS-ONLINE SINCE",
|
"TOW-LAST LOGIN", "TOW-OWNER OF", "TOW-PLOT PERMS", "TOW-PLOT OPTIONS", "TOW-FRIENDS", "ESS-ONLINE SINCE",
|
||||||
|
@ -89,7 +91,8 @@ public class DataUtils {
|
||||||
ignoreKeys.add("AAC-ACHIEVEMENTS");
|
ignoreKeys.add("AAC-ACHIEVEMENTS");
|
||||||
}
|
}
|
||||||
ignoreKeys.addAll(Arrays.asList(ignore));
|
ignoreKeys.addAll(Arrays.asList(ignore));
|
||||||
|
|
||||||
|
// Turn playerData into Hashmap of Lists sorted by keys.
|
||||||
for (UUID key : playerData.keySet()) {
|
for (UUID key : playerData.keySet()) {
|
||||||
for (String dataKey : playerData.get(key).keySet()) {
|
for (String dataKey : playerData.get(key).keySet()) {
|
||||||
if (ignoreKeys.contains(dataKey)) {
|
if (ignoreKeys.contains(dataKey)) {
|
||||||
|
@ -102,26 +105,32 @@ public class DataUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] numbers = {"AAC-ACHIEVEMENTS","ESS-HEALTH", "ESS-XP LEVEL", "FAC-POWER", "FAC-POWER PER HOUR",
|
// Define analysis method for keys
|
||||||
|
String[] numbers = {"AAC-ACHIEVEMENTS", "ESS-HEALTH", "ESS-XP LEVEL", "FAC-POWER", "FAC-POWER PER HOUR",
|
||||||
"FAC-POWER PER DEATH", "SVO-VOTES", "ONT-TOTAL VOTES", "ONT-TOTAL REFERRED", "ECO-BALANCE"};
|
"FAC-POWER PER DEATH", "SVO-VOTES", "ONT-TOTAL VOTES", "ONT-TOTAL REFERRED", "ECO-BALANCE"};
|
||||||
List<String> numberKeys = new ArrayList<>();
|
|
||||||
numberKeys.addAll(Arrays.asList(numbers));
|
|
||||||
String[] booleanValues = {"ESS-BANNED", "ESS-JAILED", "ESS-MUTED", "ESS-FLYING", "TOW-ONLINE"};
|
String[] booleanValues = {"ESS-BANNED", "ESS-JAILED", "ESS-MUTED", "ESS-FLYING", "TOW-ONLINE"};
|
||||||
List<String> boolKeys = new ArrayList<>();
|
|
||||||
boolKeys.addAll(Arrays.asList(booleanValues));
|
|
||||||
String[] timeValues = {"ONT-TOTAL PLAY"};
|
String[] timeValues = {"ONT-TOTAL PLAY"};
|
||||||
|
|
||||||
|
List<String> numberKeys = new ArrayList<>();
|
||||||
|
List<String> boolKeys = new ArrayList<>();
|
||||||
List<String> timeKeys = new ArrayList<>();
|
List<String> timeKeys = new ArrayList<>();
|
||||||
|
|
||||||
|
numberKeys.addAll(Arrays.asList(numbers));
|
||||||
|
boolKeys.addAll(Arrays.asList(booleanValues));
|
||||||
timeKeys.addAll(Arrays.asList(timeValues));
|
timeKeys.addAll(Arrays.asList(timeValues));
|
||||||
|
|
||||||
|
// TODO: Add extrahook analysis methods here
|
||||||
HashMap<String, String> analyzedData = new HashMap<>();
|
HashMap<String, String> analyzedData = new HashMap<>();
|
||||||
int errors = 0;
|
int errors = 0;
|
||||||
HashSet<String> errorTypes = new HashSet<>();
|
HashSet<String> errorTypes = new HashSet<>();
|
||||||
|
|
||||||
|
// Analyze - Go through each key - Go through each point of data in the list.
|
||||||
for (String dataKey : playerDataLists.keySet()) {
|
for (String dataKey : playerDataLists.keySet()) {
|
||||||
if (numberKeys.contains(dataKey)) {
|
if (numberKeys.contains(dataKey)) {
|
||||||
double sum = 0;
|
double sum = 0;
|
||||||
|
|
||||||
for (String dataPoint : playerDataLists.get(dataKey)) {
|
for (String dataPoint : playerDataLists.get(dataKey)) {
|
||||||
|
// Special cases separated.
|
||||||
try {
|
try {
|
||||||
if (dataKey.equals("FAC-POWER") || dataKey.equals("AAC-ACHIEVEMENTS")) {
|
if (dataKey.equals("FAC-POWER") || dataKey.equals("AAC-ACHIEVEMENTS")) {
|
||||||
sum += Double.parseDouble(dataPoint.split(" ")[0]);
|
sum += Double.parseDouble(dataPoint.split(" ")[0]);
|
||||||
|
@ -135,6 +144,7 @@ public class DataUtils {
|
||||||
errorTypes.add("" + e);
|
errorTypes.add("" + e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Average
|
||||||
analyzedData.put(dataKey, "" + (sum * 1.0 / playerData.size()));
|
analyzedData.put(dataKey, "" + (sum * 1.0 / playerData.size()));
|
||||||
|
|
||||||
} else if (boolKeys.contains(dataKey)) {
|
} else if (boolKeys.contains(dataKey)) {
|
||||||
|
@ -149,6 +159,7 @@ public class DataUtils {
|
||||||
errorTypes.add("" + e);
|
errorTypes.add("" + e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Average
|
||||||
analyzedData.put(dataKey, "" + ((amount * 1.0 / playerData.size()) * 100) + "%");
|
analyzedData.put(dataKey, "" + ((amount * 1.0 / playerData.size()) * 100) + "%");
|
||||||
} else if (timeKeys.contains(dataKey)) {
|
} else if (timeKeys.contains(dataKey)) {
|
||||||
Long time = Long.parseLong("0");
|
Long time = Long.parseLong("0");
|
||||||
|
@ -160,9 +171,11 @@ public class DataUtils {
|
||||||
errorTypes.add("" + e);
|
errorTypes.add("" + e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Average
|
||||||
analyzedData.put(dataKey, "" + (time * 1.0 / playerData.size()));
|
analyzedData.put(dataKey, "" + (time * 1.0 / playerData.size()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Log errors
|
||||||
if (errors > 0) {
|
if (errors > 0) {
|
||||||
String log = "ANALYZE\n" + errors + " error(s) occurred while analyzing total data.\nFollowing types:";
|
String log = "ANALYZE\n" + errors + " error(s) occurred while analyzing total data.\nFollowing types:";
|
||||||
for (String errorType : errorTypes) {
|
for (String errorType : errorTypes) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
name: Plan
|
name: Plan
|
||||||
main: com.djrapitops.plan.Plan
|
main: com.djrapitops.plan.Plan
|
||||||
version: 1.4.2
|
version: 1.4.3
|
||||||
|
|
||||||
commands:
|
commands:
|
||||||
plan:
|
plan:
|
||||||
|
|
Loading…
Reference in New Issue