mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-02-01 04:51:20 +01:00
Refactoring & Bugfixes to PluginData objects
This commit is contained in:
parent
e8aafd2c08
commit
aa827ffe04
5
.gitignore
vendored
5
.gitignore
vendored
@ -5,4 +5,7 @@
|
||||
/Plan/target/
|
||||
/Plan/temporaryTestFolder/
|
||||
/Debugger/nbproject/private/
|
||||
/PlanDebugger/
|
||||
/PlanDebugger/
|
||||
/ProjectHelper/nbproject/private/
|
||||
/ProjectHelper/nbproject/
|
||||
/ProjectHelper/target/
|
@ -5,8 +5,8 @@ import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import main.java.com.djrapitops.plan.utilities.FormatUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
|
||||
/**
|
||||
* This class manages the messages going to the Bukkit's Logger.
|
||||
@ -99,7 +99,7 @@ public class Log {
|
||||
}
|
||||
FileWriter fw = new FileWriter(log, true);
|
||||
try (PrintWriter pw = new PrintWriter(fw)) {
|
||||
String timestamp = FormatUtils.formatTimeStamp(new Date().getTime() + "");
|
||||
String timestamp = FormatUtils.formatTimeStamp(MiscUtils.getTime());
|
||||
pw.println("[" + timestamp + "] " + message);
|
||||
pw.flush();
|
||||
}
|
||||
|
@ -26,7 +26,6 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
@ -209,7 +208,7 @@ public class Plan extends JavaPlugin {
|
||||
public void run() {
|
||||
if (!analysisCache.isCached()) {
|
||||
analysisCache.updateCache();
|
||||
} else if (new Date().getTime() - analysisCache.getData().getRefreshDate() > 60000) {
|
||||
} else if (MiscUtils.getTime() - analysisCache.getData().getRefreshDate() > 60000) {
|
||||
analysisCache.updateCache();
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package main.java.com.djrapitops.plan.command.commands;
|
||||
|
||||
import java.util.Date;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
@ -10,6 +9,7 @@ import main.java.com.djrapitops.plan.command.SubCommand;
|
||||
import main.java.com.djrapitops.plan.data.cache.AnalysisCacheHandler;
|
||||
import main.java.com.djrapitops.plan.ui.TextUI;
|
||||
import main.java.com.djrapitops.plan.utilities.HtmlUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -56,7 +56,7 @@ public class AnalyzeCommand extends SubCommand {
|
||||
plugin.getServer().getScheduler().cancelTask(bootAnID);
|
||||
}
|
||||
analysisCache.updateCache();
|
||||
} else if (new Date().getTime() - analysisCache.getData().getRefreshDate() > 60000) {
|
||||
} else if (MiscUtils.getTime() - analysisCache.getData().getRefreshDate() > 60000) {
|
||||
analysisCache.updateCache();
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package main.java.com.djrapitops.plan.command.commands;
|
||||
|
||||
import java.util.Date;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
@ -8,6 +7,7 @@ import main.java.com.djrapitops.plan.command.CommandType;
|
||||
import main.java.com.djrapitops.plan.command.SubCommand;
|
||||
import main.java.com.djrapitops.plan.data.cache.AnalysisCacheHandler;
|
||||
import main.java.com.djrapitops.plan.ui.TextUI;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
@ -45,7 +45,7 @@ public class QuickAnalyzeCommand extends SubCommand {
|
||||
plugin.getServer().getScheduler().cancelTask(bootAnID);
|
||||
}
|
||||
analysisCache.updateCache();
|
||||
} else if (new Date().getTime() - analysisCache.getData().getRefreshDate() > 60000) {
|
||||
} else if (MiscUtils.getTime() - analysisCache.getData().getRefreshDate() > 60000) {
|
||||
analysisCache.updateCache();
|
||||
}
|
||||
|
||||
|
@ -148,7 +148,7 @@ public abstract class PluginData {
|
||||
* @see AnalysisType
|
||||
*/
|
||||
public final String parseContainer(String modifier, String contents) {
|
||||
return "<div class=\"plugin-data\">" + Html.FONT_AWESOME_ICON.parse(icon) + modifier + prefix + contents + suffix + "</div>";
|
||||
return "<div class=\"plugin-data\">" + Html.FONT_AWESOME_ICON.parse(icon) + " " + modifier + prefix + contents + suffix + "</div>";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -25,6 +25,7 @@ public class FactionsMaxPower extends PluginData {
|
||||
public FactionsMaxPower() {
|
||||
super("Factions", "maxpower");
|
||||
super.setPrefix("Max Power: ");
|
||||
super.setIcon("bolt");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -25,7 +25,7 @@ public class OntimeRefer extends PluginData {
|
||||
* Class Constructor, sets the parameters of the PluginData object.
|
||||
*/
|
||||
public OntimeRefer() {
|
||||
super("OnTime", "refer", AnalysisType.INT_TOTAL, AnalysisType.INT_AVG);
|
||||
super("OnTime", "refer", AnalysisType.LONG_TOTAL, AnalysisType.LONG_AVG);
|
||||
super.setAnalysisOnly(false);
|
||||
super.setIcon("commenting-o");
|
||||
super.setPrefix("Referrals All Time: ");
|
||||
@ -49,12 +49,12 @@ public class OntimeRefer extends PluginData {
|
||||
public Serializable getValue(UUID uuid) {
|
||||
OfflinePlayer offlinePlayer = getOfflinePlayer(uuid);
|
||||
if (!offlinePlayer.hasPlayedBefore()) {
|
||||
return 0;
|
||||
return -1L;
|
||||
}
|
||||
String name = offlinePlayer.getName();
|
||||
long referTotal = OnTimeAPI.getPlayerTimeData(name, OnTimeAPI.data.TOTALREFER);
|
||||
if (referTotal == -1) {
|
||||
return 0;
|
||||
return -1L;
|
||||
}
|
||||
return referTotal;
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ public class OntimeReferMonth extends PluginData {
|
||||
* Class Constructor, sets the parameters of the PluginData object.
|
||||
*/
|
||||
public OntimeReferMonth() {
|
||||
super("OnTime", "refer_30d", AnalysisType.INT_TOTAL);
|
||||
super("OnTime", "refer_30d", AnalysisType.LONG_TOTAL);
|
||||
super.setAnalysisOnly(false);
|
||||
super.setIcon("commenting-o");
|
||||
super.setPrefix("Referrals Last 30d: ");
|
||||
@ -49,12 +49,12 @@ public class OntimeReferMonth extends PluginData {
|
||||
public Serializable getValue(UUID uuid) {
|
||||
OfflinePlayer offlinePlayer = getOfflinePlayer(uuid);
|
||||
if (!offlinePlayer.hasPlayedBefore()) {
|
||||
return 0;
|
||||
return -1L;
|
||||
}
|
||||
String name = offlinePlayer.getName();
|
||||
long referTotal = OnTimeAPI.getPlayerTimeData(name, OnTimeAPI.data.MONTHREFER);
|
||||
if (referTotal == -1) {
|
||||
return 0;
|
||||
return -1L;
|
||||
}
|
||||
return referTotal;
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ public class OntimeReferWeek extends PluginData {
|
||||
* Class Constructor, sets the parameters of the PluginData object.
|
||||
*/
|
||||
public OntimeReferWeek() {
|
||||
super("OnTime", "refer_7d", AnalysisType.INT_TOTAL);
|
||||
super("OnTime", "refer_7d", AnalysisType.LONG_TOTAL);
|
||||
super.setAnalysisOnly(false);
|
||||
super.setIcon("commenting-o");
|
||||
super.setPrefix("Referrals Last 7d: ");
|
||||
@ -49,12 +49,12 @@ public class OntimeReferWeek extends PluginData {
|
||||
public Serializable getValue(UUID uuid) {
|
||||
OfflinePlayer offlinePlayer = getOfflinePlayer(uuid);
|
||||
if (!offlinePlayer.hasPlayedBefore()) {
|
||||
return 0;
|
||||
return -1L;
|
||||
}
|
||||
String name = offlinePlayer.getName();
|
||||
long referTotal = OnTimeAPI.getPlayerTimeData(name, OnTimeAPI.data.WEEKREFER);
|
||||
if (referTotal == -1) {
|
||||
return 0;
|
||||
return -1L;
|
||||
}
|
||||
return referTotal;
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ public class OntimeVotes extends PluginData {
|
||||
* Class Constructor, sets the parameters of the PluginData object.
|
||||
*/
|
||||
public OntimeVotes() {
|
||||
super("OnTime", "votes", AnalysisType.INT_TOTAL, AnalysisType.INT_AVG);
|
||||
super("OnTime", "votes", AnalysisType.LONG_TOTAL, AnalysisType.LONG_AVG);
|
||||
super.setAnalysisOnly(false);
|
||||
super.setIcon("check");
|
||||
super.setPrefix("Votes All Time: ");
|
||||
@ -49,12 +49,12 @@ public class OntimeVotes extends PluginData {
|
||||
public Serializable getValue(UUID uuid) {
|
||||
OfflinePlayer offlinePlayer = getOfflinePlayer(uuid);
|
||||
if (!offlinePlayer.hasPlayedBefore()) {
|
||||
return 0;
|
||||
return -1L;
|
||||
}
|
||||
String name = offlinePlayer.getName();
|
||||
long votesTotal = OnTimeAPI.getPlayerTimeData(name, OnTimeAPI.data.TOTALVOTE);
|
||||
if (votesTotal == -1) {
|
||||
return 0;
|
||||
return -1L;
|
||||
}
|
||||
return votesTotal;
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ public class OntimeVotesMonth extends PluginData {
|
||||
* Class Constructor, sets the parameters of the PluginData object.
|
||||
*/
|
||||
public OntimeVotesMonth() {
|
||||
super("OnTime", "votes_30d", AnalysisType.INT_TOTAL);
|
||||
super("OnTime", "votes_30d", AnalysisType.LONG_TOTAL);
|
||||
super.setAnalysisOnly(false);
|
||||
super.setIcon("check");
|
||||
super.setPrefix("Votes Last 30d: ");
|
||||
@ -49,12 +49,12 @@ public class OntimeVotesMonth extends PluginData {
|
||||
public Serializable getValue(UUID uuid) {
|
||||
OfflinePlayer offlinePlayer = getOfflinePlayer(uuid);
|
||||
if (!offlinePlayer.hasPlayedBefore()) {
|
||||
return 0;
|
||||
return -1L;
|
||||
}
|
||||
String name = offlinePlayer.getName();
|
||||
long votesTotal = OnTimeAPI.getPlayerTimeData(name, OnTimeAPI.data.MONTHVOTE);
|
||||
if (votesTotal == -1) {
|
||||
return 0;
|
||||
return -1L;
|
||||
}
|
||||
return votesTotal;
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ public class OntimeVotesWeek extends PluginData {
|
||||
* Class Constructor, sets the parameters of the PluginData object.
|
||||
*/
|
||||
public OntimeVotesWeek() {
|
||||
super("OnTime", "votes_7d", AnalysisType.INT_TOTAL);
|
||||
super("OnTime", "votes_7d", AnalysisType.LONG_TOTAL);
|
||||
super.setAnalysisOnly(false);
|
||||
super.setIcon("check");
|
||||
super.setPrefix("Votes Last 7d: ");
|
||||
@ -49,12 +49,12 @@ public class OntimeVotesWeek extends PluginData {
|
||||
public Serializable getValue(UUID uuid) {
|
||||
OfflinePlayer offlinePlayer = getOfflinePlayer(uuid);
|
||||
if (!offlinePlayer.hasPlayedBefore()) {
|
||||
return 0;
|
||||
return -1L;
|
||||
}
|
||||
String name = offlinePlayer.getName();
|
||||
long votesTotal = OnTimeAPI.getPlayerTimeData(name, OnTimeAPI.data.WEEKVOTE);
|
||||
if (votesTotal == -1) {
|
||||
return 0;
|
||||
return -1L;
|
||||
}
|
||||
return votesTotal;
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -22,6 +21,7 @@ import main.java.com.djrapitops.plan.data.handling.info.HandlingInfo;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.LogoutInfo;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.ReloadInfo;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.NewPlayerCreator;
|
||||
import main.java.com.djrapitops.plan.utilities.comparators.HandlingInfoTimeComparator;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -245,7 +245,7 @@ public class DataCacheHandler extends LocationCache {
|
||||
* If processTask has unprocessed information, it will be processed.
|
||||
*/
|
||||
public void saveCacheOnDisable() {
|
||||
long time = new Date().getTime();
|
||||
long time = MiscUtils.getTime();
|
||||
Log.debug("SaveCacheOnDisable! " + time);
|
||||
saveTask.stop();
|
||||
getTask.stop();
|
||||
@ -339,7 +339,7 @@ public class DataCacheHandler extends LocationCache {
|
||||
}
|
||||
|
||||
private void saveHandlerDataToCache(Player player) {
|
||||
long time = new Date().getTime();
|
||||
long time = MiscUtils.getTime();
|
||||
UUID uuid = player.getUniqueId();
|
||||
addToPool(new ReloadInfo(uuid, time, player.getAddress().getAddress(), player.isBanned(), player.getDisplayName(), player.getGameMode()));
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
package main.java.com.djrapitops.plan.data.cache;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.data.SessionData;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
|
||||
/**
|
||||
* This class is used to store active sessions of players in memory.
|
||||
@ -31,7 +31,7 @@ public class SessionCache {
|
||||
* @param uuid UUID of the player.
|
||||
*/
|
||||
public void startSession(UUID uuid) {
|
||||
long now = new Date().getTime();
|
||||
long now = MiscUtils.getTime();
|
||||
Log.debug(uuid + ": Starting a session: " + now);
|
||||
SessionData session = new SessionData(now);
|
||||
activeSessions.put(uuid, session);
|
||||
@ -45,7 +45,7 @@ public class SessionCache {
|
||||
public void endSession(UUID uuid) {
|
||||
SessionData currentSession = activeSessions.get(uuid);
|
||||
if (currentSession != null) {
|
||||
long now = new Date().getTime();
|
||||
long now = MiscUtils.getTime();
|
||||
Log.debug(uuid + ": Ending a session: " + now);
|
||||
currentSession.endSession(now);
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
package main.java.com.djrapitops.plan.data.listeners;
|
||||
|
||||
import java.util.Date;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.cache.DataCacheHandler;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.DeathInfo;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.KillInfo;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -40,7 +40,7 @@ public class PlanDeathEventListener implements Listener {
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onDeath(EntityDeathEvent event) {
|
||||
long time = new Date().getTime();
|
||||
long time = MiscUtils.getTime();
|
||||
LivingEntity dead = event.getEntity();
|
||||
Player killer = dead.getKiller();
|
||||
boolean killerIsPlayer = killer != null;
|
||||
|
@ -1,9 +1,9 @@
|
||||
package main.java.com.djrapitops.plan.data.listeners;
|
||||
|
||||
import java.util.Date;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.cache.DataCacheHandler;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.GamemodeInfo;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -42,6 +42,6 @@ public class PlanGamemodeChangeListener implements Listener {
|
||||
return;
|
||||
}
|
||||
Player p = event.getPlayer();
|
||||
handler.addToPool(new GamemodeInfo(p.getUniqueId(), new Date().getTime(), event.getNewGameMode()));
|
||||
handler.addToPool(new GamemodeInfo(p.getUniqueId(), MiscUtils.getTime(), event.getNewGameMode()));
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package main.java.com.djrapitops.plan.data.listeners;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
@ -9,6 +8,7 @@ import main.java.com.djrapitops.plan.data.cache.DataCacheHandler;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.KickInfo;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.LoginInfo;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.LogoutInfo;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.NewPlayerCreator;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -60,7 +60,7 @@ public class PlanPlayerListener implements Listener {
|
||||
BukkitTask asyncNewPlayerCheckTask = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
LoginInfo loginInfo = new LoginInfo(uuid, new Date().getTime(), player.getAddress().getAddress(), player.isBanned(), player.getDisplayName(), player.getGameMode(), 1);
|
||||
LoginInfo loginInfo = new LoginInfo(uuid, MiscUtils.getTime(), player.getAddress().getAddress(), player.isBanned(), player.getDisplayName(), player.getGameMode(), 1);
|
||||
boolean isNewPlayer = !plugin.getDB().wasSeenBefore(uuid);
|
||||
if (isNewPlayer) {
|
||||
UserData newUserData = NewPlayerCreator.createNewPlayer(player);
|
||||
@ -90,7 +90,7 @@ public class PlanPlayerListener implements Listener {
|
||||
UUID uuid = player.getUniqueId();
|
||||
handler.endSession(uuid);
|
||||
Log.debug(uuid + ": PlayerQuitEvent");
|
||||
handler.addToPool(new LogoutInfo(uuid, new Date().getTime(), player.isBanned(), player.getGameMode(), handler.getSession(uuid)));
|
||||
handler.addToPool(new LogoutInfo(uuid, MiscUtils.getTime(), player.isBanned(), player.getGameMode(), handler.getSession(uuid)));
|
||||
handler.saveCachedData(uuid);
|
||||
Log.debug(uuid + ": PlayerQuitEvent_END");
|
||||
}
|
||||
@ -110,7 +110,7 @@ public class PlanPlayerListener implements Listener {
|
||||
Player player = event.getPlayer();
|
||||
UUID uuid = player.getUniqueId();
|
||||
handler.endSession(uuid);
|
||||
handler.addToPool(new LogoutInfo(uuid, new Date().getTime(), player.isBanned(), player.getGameMode(), handler.getSession(uuid)));
|
||||
handler.addToPool(new LogoutInfo(uuid, MiscUtils.getTime(), player.isBanned(), player.getGameMode(), handler.getSession(uuid)));
|
||||
handler.addToPool(new KickInfo(uuid));
|
||||
handler.saveCachedData(uuid);
|
||||
}
|
||||
|
@ -9,6 +9,8 @@ import main.java.com.djrapitops.plan.data.cache.AnalysisCacheHandler;
|
||||
import main.java.com.djrapitops.plan.data.cache.InspectCacheHandler;
|
||||
import main.java.com.djrapitops.plan.utilities.AnalysisUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.FormatUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.MathUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
/**
|
||||
@ -24,6 +26,7 @@ public class TextUI {
|
||||
*/
|
||||
public static String[] getInspectMessages(UUID uuid) {
|
||||
InspectCacheHandler inspectCache = Plan.getInstance().getInspectCache();
|
||||
long now = MiscUtils.getTime();
|
||||
if (!inspectCache.isCached(uuid)) {
|
||||
return new String[]{"Error has occurred, please retry."};
|
||||
}
|
||||
@ -31,17 +34,17 @@ public class TextUI {
|
||||
ChatColor main = Phrase.COLOR_MAIN.color();
|
||||
ChatColor sec = Phrase.COLOR_SEC.color();
|
||||
ChatColor ter = Phrase.COLOR_TER.color();
|
||||
boolean active = AnalysisUtils.isActive(d.getLastPlayed(), d.getPlayTime(), d.getLoginTimes());
|
||||
boolean active = AnalysisUtils.isActive(now, d.getLastPlayed(), d.getPlayTime(), d.getLoginTimes());
|
||||
boolean banned = d.isBanned();
|
||||
boolean online = d.isOnline();
|
||||
String ball = sec + " " + Phrase.BALL + main;
|
||||
return new String[]{
|
||||
sec + " " + Phrase.BALL + (banned ? ChatColor.DARK_RED + " Banned" : ter + (active ? " Active" : " Inactive")) + (online ? ChatColor.GREEN + " Online" : ChatColor.RED + " Offline"),
|
||||
ball + " Registered: " + sec + FormatUtils.formatTimeStamp(d.getRegistered() + ""),
|
||||
ball + " Last seen: " + sec + FormatUtils.formatTimeStamp(d.getLastPlayed() + ""),
|
||||
ball + " Playtime: " + sec + FormatUtils.formatTimeAmount(d.getPlayTime() + ""),
|
||||
ball + " Registered: " + sec + FormatUtils.formatTimeStamp(d.getRegistered()),
|
||||
ball + " Last seen: " + sec + FormatUtils.formatTimeStamp(d.getLastPlayed()),
|
||||
ball + " Playtime: " + sec + FormatUtils.formatTimeAmount(d.getPlayTime()),
|
||||
ball + " Login times: " + sec + d.getLoginTimes(),
|
||||
ball + " Average session length: " + sec + FormatUtils.formatTimeAmount(AnalysisUtils.average(AnalysisUtils.transformSessionDataToLengths(d.getSessions())) + ""),
|
||||
ball + " Average session length: " + sec + FormatUtils.formatTimeAmount(MathUtils.averageLong(AnalysisUtils.transformSessionDataToLengths(d.getSessions()))),
|
||||
ball + " Kills: " + sec + d.getPlayerKills().size() + main + " Mobs: " + sec + d.getMobKills() + main + " Deaths: " + sec + d.getDeaths(),
|
||||
ball + " Geolocation: " + sec + d.getDemData().getGeoLocation()
|
||||
};
|
||||
@ -66,8 +69,8 @@ public class TextUI {
|
||||
ball + " Active: " + sec + d.getActive() + main + " Inactive: " + sec + d.getInactive() + main + " Single join: " + sec + d.getJoinleaver() + main + " Banned: " + sec + d.getBanned(),
|
||||
ball + " New Players 24h: " + sec + d.getNewPlayersDay() + main + " 7d: " + sec + d.getNewPlayersWeek() + main + " 30d: " + sec + d.getNewPlayersMonth(),
|
||||
"",
|
||||
ball + " Total Playtime: " + sec + FormatUtils.formatTimeAmount(d.getTotalPlayTime() + "") + main + " Player Avg: " + sec + FormatUtils.formatTimeAmount(d.getAveragePlayTime() + ""),
|
||||
ball + " Average Session Length: " + sec + FormatUtils.formatTimeAmount(d.getSessionAverage() + ""),
|
||||
ball + " Total Playtime: " + sec + FormatUtils.formatTimeAmount(d.getTotalPlayTime()) + main + " Player Avg: " + sec + FormatUtils.formatTimeAmount(d.getAveragePlayTime()),
|
||||
ball + " Average Session Length: " + sec + FormatUtils.formatTimeAmount(d.getSessionAverage()),
|
||||
ball + " Total Logintimes: " + sec + d.getTotalLoginTimes(),
|
||||
ball + " Kills: " + sec + d.getTotalPlayerKills() + main + " Mobs: " + sec + d.getTotalMobKills() + main + " Deaths: " + sec + d.getTotalDeaths()
|
||||
};
|
||||
|
@ -47,7 +47,7 @@ public class PlayerActivityGraphCreator {
|
||||
|
||||
if (lastSavedPValue != lastPValue || i - lastSaveI > (scale / (long) 75)) {
|
||||
lastSaveI = i;
|
||||
labels.add("\"" + FormatUtils.formatTimeStamp(i + "") + "\"");
|
||||
labels.add("\"" + FormatUtils.formatTimeStamp(i) + "\"");
|
||||
lastSavedPValue = lastPValue;
|
||||
playersOnline.add(lastPValue);
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ public class SortableKillsTableCreator {
|
||||
OfflinePlayer victim = getOfflinePlayer(kill.getVictim());
|
||||
String name = victim.getName();
|
||||
html += Html.TABLELINE_3_CUSTOMKEY_1.parse(
|
||||
date + "", FormatUtils.formatTimeStamp(date + ""),
|
||||
date + "", FormatUtils.formatTimeStamp(date),
|
||||
Html.LINK.parse(HtmlUtils.getInspectUrl(name), name),
|
||||
kill.getWeapon()
|
||||
);
|
||||
|
@ -6,6 +6,7 @@ import main.java.com.djrapitops.plan.ui.Html;
|
||||
import main.java.com.djrapitops.plan.utilities.AnalysisUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.FormatUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.HtmlUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -20,17 +21,18 @@ public class SortablePlayersTableCreator {
|
||||
*/
|
||||
public static String createSortablePlayersTable(Collection<UserData> data) {
|
||||
String html = "";
|
||||
long now = MiscUtils.getTime();
|
||||
for (UserData uData : data) {
|
||||
try {
|
||||
String bORaORi = uData.isBanned() ? Html.GRAPH_BANNED.parse()
|
||||
: (AnalysisUtils.isActive(uData.getLastPlayed(), uData.getPlayTime(), uData.getLoginTimes())
|
||||
: (AnalysisUtils.isActive(now, uData.getLastPlayed(), uData.getPlayTime(), uData.getLoginTimes())
|
||||
? Html.GRAPH_ACTIVE.parse() : Html.GRAPH_INACTIVE.parse());
|
||||
|
||||
html += Html.TABLELINE_PLAYERS.parse("<img style=\"float: left; padding: 2px 2px 0px 2px\" alt=\"" + uData.getName() + "\" src=\"https://minotar.net/avatar/" + uData.getName() + "/19\"> " + Html.LINK.parse(HtmlUtils.getInspectUrl(uData.getName()), uData.getName()), bORaORi,
|
||||
uData.getPlayTime() + "", FormatUtils.formatTimeAmount(uData.getPlayTime() + ""),
|
||||
uData.getPlayTime() + "", FormatUtils.formatTimeAmount(uData.getPlayTime()),
|
||||
uData.getLoginTimes() + "",
|
||||
uData.getRegistered() + "", FormatUtils.formatTimeStamp(uData.getRegistered() + ""),
|
||||
uData.getLastPlayed() + "", FormatUtils.formatTimeStamp(uData.getLastPlayed() + ""),
|
||||
uData.getRegistered() + "", FormatUtils.formatTimeStamp(uData.getRegistered()),
|
||||
uData.getLastPlayed() + "", FormatUtils.formatTimeStamp(uData.getLastPlayed()),
|
||||
uData.getDemData().getGeoLocation()
|
||||
);
|
||||
} catch (NullPointerException e) {
|
||||
|
@ -37,9 +37,9 @@ public class SortableSessionTableCreator {
|
||||
continue;
|
||||
}
|
||||
html += Html.TABLELINE_3_CUSTOMKEY.parse(
|
||||
start + "", FormatUtils.formatTimeStamp(start + ""),
|
||||
end + "", FormatUtils.formatTimeStamp(end + ""),
|
||||
length + "", FormatUtils.formatTimeAmount(length + "")
|
||||
start + "", FormatUtils.formatTimeStamp(start),
|
||||
end + "", FormatUtils.formatTimeStamp(end),
|
||||
length + "", FormatUtils.formatTimeAmount(length)
|
||||
);
|
||||
i++;
|
||||
}
|
||||
|
@ -28,6 +28,8 @@ import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.ui.Html;
|
||||
import main.java.com.djrapitops.plan.ui.RecentPlayersButtonsCreator;
|
||||
import main.java.com.djrapitops.plan.ui.graphs.PlayerActivityGraphCreator;
|
||||
import main.java.com.djrapitops.plan.ui.tables.SortableCommandUseTableCreator;
|
||||
import main.java.com.djrapitops.plan.ui.tables.SortablePlayersTableCreator;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
@ -147,11 +149,13 @@ public class Analysis {
|
||||
*/
|
||||
public boolean analyzeData(List<UserData> rawData, List<UUID> uuids, AnalysisCacheHandler analysisCache) {
|
||||
// Create empty Dataset
|
||||
long now = MiscUtils.getTime();
|
||||
final RawAnalysisData sorted = new RawAnalysisData();
|
||||
sorted.setCommandUse(plugin.getHandler().getCommandUse());
|
||||
log(Phrase.ANALYSIS_BEGIN_ANALYSIS + "");
|
||||
AnalysisData analysisData = new AnalysisData();
|
||||
analysisData.setSortablePlayersTable(AnalysisUtils.createSortablePlayersTable(rawData));
|
||||
String playersTable = SortablePlayersTableCreator.createSortablePlayersTable(rawData);
|
||||
analysisData.setSortablePlayersTable(playersTable);
|
||||
sorted.fillGeolocations();
|
||||
// Fill Dataset with userdata.
|
||||
rawData.stream().forEach((uData) -> {
|
||||
@ -201,7 +205,7 @@ public class Analysis {
|
||||
sorted.addTotalBanned(1);
|
||||
} else if (uData.getLoginTimes() == 1) {
|
||||
sorted.addJoinleaver(1);
|
||||
} else if (AnalysisUtils.isActive(uData.getLastPlayed(), playTime, uData.getLoginTimes())) {
|
||||
} else if (AnalysisUtils.isActive(now, uData.getLastPlayed(), playTime, uData.getLoginTimes())) {
|
||||
sorted.addActive(1);
|
||||
sorted.getPlaytimes().put(html, playTime);
|
||||
} else {
|
||||
@ -246,7 +250,7 @@ public class Analysis {
|
||||
long totalPlaytime = sorted.getTotalPlaytime();
|
||||
analysisData.setTotalPlayTime(totalPlaytime);
|
||||
analysisData.setAveragePlayTime(totalPlaytime / rawData.size());
|
||||
analysisData.setSessionAverage(AnalysisUtils.average(AnalysisUtils.transformSessionDataToLengths(sorted.getSessiondata())));
|
||||
analysisData.setSessionAverage(MathUtils.averageLong(AnalysisUtils.transformSessionDataToLengths(sorted.getSessiondata())));
|
||||
analysisData.setTotalLoginTimes(sorted.getTotalLoginTimes());
|
||||
createActivityVisalization(uuids.size(), sorted.getTotalBanned(), sorted.getActive(), sorted.getInactive(), sorted.getJoinleaver(), analysisData);
|
||||
analysisData.setOps(sorted.getOps());
|
||||
@ -256,7 +260,7 @@ public class Analysis {
|
||||
analysisData.setTotaldeaths(sorted.getTotalDeaths());
|
||||
analysisData.setTotalkills(sorted.getTotalKills());
|
||||
analysisData.setTotalmobkills(sorted.getTotalMobKills());
|
||||
analysisData.setRefreshDate(new Date().getTime());
|
||||
analysisData.setRefreshDate(now);
|
||||
analysisData.setGenderData(sorted.getGenders());
|
||||
analysisData.setAdditionalDataReplaceMap(analyzeAdditionalPluginData(uuids));
|
||||
analysisCache.cache(analysisData);
|
||||
@ -269,7 +273,8 @@ public class Analysis {
|
||||
private void createCommandUseTable(final RawAnalysisData raw, AnalysisData data) {
|
||||
Map<String, Integer> commandUse = raw.getCommandUse();
|
||||
if (!commandUse.isEmpty()) {
|
||||
data.setCommandUseTableHtml(AnalysisUtils.createTableOutOfMap(commandUse));
|
||||
String tableHtml = SortableCommandUseTableCreator.createSortedCommandUseTable(commandUse);
|
||||
data.setCommandUseTableHtml(tableHtml);
|
||||
data.setTotalCommands(commandUse.size());
|
||||
} else {
|
||||
data.setCommandUseTableHtml(Html.ERROR_TABLE_2.parse());
|
||||
|
@ -2,21 +2,15 @@ package main.java.com.djrapitops.plan.utilities;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.OptionalDouble;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
import main.java.com.djrapitops.plan.data.SessionData;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.data.additional.AnalysisType;
|
||||
import main.java.com.djrapitops.plan.data.additional.PluginData;
|
||||
import main.java.com.djrapitops.plan.ui.tables.SortableCommandUseTableCreator;
|
||||
import main.java.com.djrapitops.plan.ui.tables.SortablePlayersTableCreator;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -31,13 +25,18 @@ public class AnalysisUtils {
|
||||
* @param loginTimes
|
||||
* @return
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean isActive(long lastPlayed, long playTime, int loginTimes) {
|
||||
return isActive(MiscUtils.getTime(), lastPlayed, playTime, loginTimes);
|
||||
}
|
||||
|
||||
public static boolean isActive(long now, long lastPlayed, long playTime, int loginTimes) {
|
||||
int timeToActive = Settings.ANALYSIS_MINUTES_FOR_ACTIVE.getNumber();
|
||||
if (timeToActive < 0) {
|
||||
timeToActive = 0;
|
||||
}
|
||||
long twoWeeks = 1209600000;
|
||||
if (new Date().getTime() - lastPlayed < twoWeeks) {
|
||||
if (now - lastPlayed < twoWeeks) {
|
||||
if (loginTimes > 3) {
|
||||
if (playTime > 60 * timeToActive) {
|
||||
return true;
|
||||
@ -47,14 +46,6 @@ public class AnalysisUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
static String createTableOutOfMap(Map<String, Integer> commandUse) {
|
||||
return SortableCommandUseTableCreator.createSortedCommandUseTable(commandUse);
|
||||
}
|
||||
|
||||
static String createSortablePlayersTable(Collection<UserData> data) {
|
||||
return SortablePlayersTableCreator.createSortablePlayersTable(data);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param registered
|
||||
@ -89,24 +80,6 @@ public class AnalysisUtils {
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param list
|
||||
* @return
|
||||
*/
|
||||
public static long average(Collection<Long> list) {
|
||||
if (list.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
long total = 0;
|
||||
for (Long long1 : list) {
|
||||
total += long1;
|
||||
}
|
||||
return total / list.size();
|
||||
}
|
||||
|
||||
// Refactor to MathUtils class
|
||||
|
||||
/**
|
||||
*
|
||||
* @param analysisType
|
||||
@ -115,49 +88,40 @@ public class AnalysisUtils {
|
||||
* @return
|
||||
*/
|
||||
public static String getTotal(AnalysisType analysisType, PluginData source, List<UUID> uuids) {
|
||||
try {
|
||||
if (null != analysisType) {
|
||||
Number total;
|
||||
switch (analysisType) {
|
||||
case INT_TOTAL:
|
||||
total = getCorrectValues(uuids, source)
|
||||
.mapToInt(value -> (Integer) value)
|
||||
.sum();
|
||||
break;
|
||||
case LONG_TOTAL:
|
||||
total = getCorrectValues(uuids, source)
|
||||
.mapToLong(value -> (Long) value)
|
||||
.sum();
|
||||
break;
|
||||
case LONG_TIME_MS_TOTAL:
|
||||
total = getCorrectValues(uuids, source)
|
||||
.mapToLong(value -> (Long) value)
|
||||
.sum();
|
||||
return source.parseContainer(analysisType.getModifier(), FormatUtils.formatTimeAmount(total + ""));
|
||||
case DOUBLE_TOTAL:
|
||||
total = getCorrectValues(uuids, source)
|
||||
.mapToDouble(value -> (Double) value)
|
||||
.sum();
|
||||
break;
|
||||
default:
|
||||
return source.parseContainer("ERROR ", "Wrong Analysistype specified: " + analysisType.name());
|
||||
}
|
||||
return source.parseContainer(analysisType.getModifier(), total + "");
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Log.toLog("com.djrapitops.plan.utilities.AnalysisUtils", e);
|
||||
if (analysisType == null) {
|
||||
return source.parseContainer("Err ", "Null Analysistype. ");
|
||||
}
|
||||
try {
|
||||
Number total;
|
||||
switch (analysisType) {
|
||||
case INT_TOTAL:
|
||||
total = MathUtils.sumInt(getCorrectValues(uuids, source));
|
||||
break;
|
||||
case LONG_TOTAL:
|
||||
total = MathUtils.sumLong(getCorrectValues(uuids, source));
|
||||
break;
|
||||
case LONG_TIME_MS_TOTAL:
|
||||
total = MathUtils.sumLong(getCorrectValues(uuids, source));
|
||||
return source.parseContainer(analysisType.getModifier(), FormatUtils.formatTimeAmount((long) total));
|
||||
case DOUBLE_TOTAL:
|
||||
total = MathUtils.sumDouble(getCorrectValues(uuids, source));
|
||||
break;
|
||||
default:
|
||||
return source.parseContainer("", "Wrong Analysistype specified: " + analysisType.name());
|
||||
}
|
||||
return source.parseContainer(analysisType.getModifier(), total + "");
|
||||
} catch (Throwable e) {
|
||||
return logPluginDataCausedError(source, e);
|
||||
}
|
||||
return source.parseContainer("ERROR ", "Exception during total calculation.");
|
||||
}
|
||||
|
||||
private static Stream<Serializable> getCorrectValues(List<UUID> uuids, PluginData source) {
|
||||
return uuids.stream()
|
||||
.map(uuid -> source.getValue(uuid))
|
||||
.filter(value -> !value.equals(-1));
|
||||
.filter(value -> !value.equals(-1))
|
||||
.filter(value -> !value.equals(-1L));
|
||||
}
|
||||
|
||||
// Refactor to MathUtils class
|
||||
|
||||
/**
|
||||
*
|
||||
* @param analysisType
|
||||
@ -166,61 +130,38 @@ public class AnalysisUtils {
|
||||
* @return
|
||||
*/
|
||||
public static String getAverage(AnalysisType analysisType, PluginData source, List<UUID> uuids) {
|
||||
try {
|
||||
if (null != analysisType) {
|
||||
Number total;
|
||||
switch (analysisType) {
|
||||
case LONG_EPOCH_MS_MINUS_NOW_AVG:
|
||||
final long now = new Date().getTime();
|
||||
List<Long> longValues = getCorrectValues(uuids, source)
|
||||
.map(value -> ((long) value) - now)
|
||||
.collect(Collectors.toList());
|
||||
return source.parseContainer(analysisType.getModifier(), FormatUtils.formatTimeAmount(average(longValues) + ""));
|
||||
case INT_AVG:
|
||||
OptionalDouble avg = getCorrectValues(uuids, source)
|
||||
.map(value -> (Integer) value)
|
||||
.mapToInt(i -> i)
|
||||
.average();
|
||||
if (!avg.isPresent()) {
|
||||
total = 0;
|
||||
} else {
|
||||
total = avg.getAsDouble();
|
||||
}
|
||||
break;
|
||||
case LONG_AVG:
|
||||
List<Long> longVal = getCorrectValues(uuids, source)
|
||||
.map(value -> (Long) value)
|
||||
.collect(Collectors.toList());
|
||||
total = average(longVal);
|
||||
break;
|
||||
case LONG_TIME_MS_AVG:
|
||||
List<Long> longVal2 = getCorrectValues(uuids, source)
|
||||
.map(value -> (Long) value)
|
||||
.collect(Collectors.toList());
|
||||
return source.parseContainer(analysisType.getModifier(), FormatUtils.formatTimeAmount(average(longVal2) + ""));
|
||||
case DOUBLE_AVG:
|
||||
OptionalDouble average = getCorrectValues(uuids, source)
|
||||
.mapToDouble(value -> (Double) value)
|
||||
.average();
|
||||
if (!average.isPresent()) {
|
||||
total = 0;
|
||||
} else {
|
||||
total = average.getAsDouble();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return source.parseContainer("", "Wrong Analysistype specified: " + analysisType.name());
|
||||
}
|
||||
return source.parseContainer(analysisType.getModifier(), total + "");
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Log.error("A PluginData-source caused an exception: "+source.getPlaceholder("").replace("%", ""));
|
||||
Log.toLog("com.djrapitops.plan.utilities.AnalysisUtils", e);
|
||||
if (analysisType == null) {
|
||||
return source.parseContainer("Err ", "Null Analysistype. ");
|
||||
}
|
||||
try {
|
||||
Number average;
|
||||
switch (analysisType) {
|
||||
case LONG_EPOCH_MS_MINUS_NOW_AVG:
|
||||
final long now = MiscUtils.getTime();
|
||||
average = MathUtils.averageLong(getCorrectValues(uuids, source).map(value -> ((long) value) - now));
|
||||
return source.parseContainer(analysisType.getModifier(), FormatUtils.formatTimeAmount((long) average));
|
||||
case INT_AVG:
|
||||
average = MathUtils.averageInt(getCorrectValues(uuids, source).map(i -> (Integer) i));
|
||||
break;
|
||||
case LONG_AVG:
|
||||
average = MathUtils.averageLong(getCorrectValues(uuids, source).map(i -> (Long) i));
|
||||
break;
|
||||
case LONG_TIME_MS_AVG:
|
||||
average = MathUtils.averageLong(getCorrectValues(uuids, source).map(i -> (Long) i));
|
||||
return source.parseContainer(analysisType.getModifier(), FormatUtils.formatTimeAmount((long) average));
|
||||
case DOUBLE_AVG:
|
||||
average = MathUtils.averageDouble(getCorrectValues(uuids, source).map(i -> (Double) i));
|
||||
break;
|
||||
default:
|
||||
return source.parseContainer("Err ", "Wrong Analysistype specified: " + analysisType.name());
|
||||
}
|
||||
return source.parseContainer(analysisType.getModifier(), average + "");
|
||||
} catch (Throwable e) {
|
||||
return logPluginDataCausedError(source, e);
|
||||
}
|
||||
return source.parseContainer("", "Exception during average calculation.");
|
||||
}
|
||||
|
||||
static String getBooleanPercentage(AnalysisType analysisType, PluginData source, List<UUID> uuids) {
|
||||
public static String getBooleanPercentage(AnalysisType analysisType, PluginData source, List<UUID> uuids) {
|
||||
if (analysisType == AnalysisType.BOOLEAN_PERCENTAGE) {
|
||||
try {
|
||||
List<Boolean> tempList = getCorrectValues(uuids, source)
|
||||
@ -229,15 +170,13 @@ public class AnalysisUtils {
|
||||
long count = tempList.stream().filter(value -> value).count();
|
||||
return source.parseContainer(analysisType.getModifier(), ((double) (count / tempList.size()) * 100) + "%");
|
||||
} catch (Throwable e) {
|
||||
Log.error("A PluginData-source caused an exception: "+source.getPlaceholder("").replace("%", ""));
|
||||
Log.toLog("com.djrapitops.plan.utilities.AnalysisUtils", e);
|
||||
return source.parseContainer("", "Exception during calculation.");
|
||||
return logPluginDataCausedError(source, e);
|
||||
}
|
||||
}
|
||||
return source.parseContainer("", "Wrong Analysistype specified: " + analysisType.name());
|
||||
return source.parseContainer("Err ", "Wrong Analysistype specified: " + analysisType.name());
|
||||
}
|
||||
|
||||
static String getBooleanTotal(AnalysisType analysisType, PluginData source, List<UUID> uuids) {
|
||||
public static String getBooleanTotal(AnalysisType analysisType, PluginData source, List<UUID> uuids) {
|
||||
if (analysisType == AnalysisType.BOOLEAN_TOTAL) {
|
||||
try {
|
||||
List<Boolean> tempList = getCorrectValues(uuids, source)
|
||||
@ -246,11 +185,16 @@ public class AnalysisUtils {
|
||||
long count = tempList.stream().filter(value -> value).count();
|
||||
return source.parseContainer(analysisType.getModifier(), count + " / " + tempList.size());
|
||||
} catch (Throwable e) {
|
||||
Log.error("A PluginData-source caused an exception: "+source.getPlaceholder("").replace("%", ""));
|
||||
Log.toLog("com.djrapitops.plan.utilities.AnalysisUtils", e);
|
||||
return source.parseContainer("", "Exception during calculation.");
|
||||
return logPluginDataCausedError(source, e);
|
||||
}
|
||||
}
|
||||
return source.parseContainer("", "Wrong Analysistype specified: " + analysisType.name());
|
||||
return source.parseContainer("Err ", "Wrong Analysistype specified: " + analysisType.name());
|
||||
}
|
||||
}
|
||||
|
||||
private static String logPluginDataCausedError(PluginData source, Throwable e) {
|
||||
Log.error("A PluginData-source caused an exception: " + source.getPlaceholder("").replace("%", ""));
|
||||
Log.toLog("A PluginData-source caused an exception: " + source.getPlaceholder("").replace("%", ""));
|
||||
Log.toLog("com.djrapitops.plan.utilities.AnalysisUtils", e);
|
||||
return source.parseContainer("", "Exception during calculation.");
|
||||
}
|
||||
}
|
@ -2,7 +2,6 @@ package main.java.com.djrapitops.plan.utilities;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Date;
|
||||
import main.java.com.djrapitops.plan.ui.Html;
|
||||
import org.bukkit.Location;
|
||||
|
||||
/**
|
||||
@ -11,58 +10,19 @@ import org.bukkit.Location;
|
||||
*/
|
||||
public class FormatUtils {
|
||||
|
||||
/**
|
||||
* Formats a String of long in ms to readable format.
|
||||
*
|
||||
* @param string String of a Long in ms
|
||||
* @return Readable format
|
||||
* @throws NumberFormatException if String is not long.
|
||||
*/
|
||||
public static String formatTimeAmount(String string) throws NumberFormatException {
|
||||
long ms = Long.parseLong(string);
|
||||
return turnMsLongToString(ms);
|
||||
public static String formatTimeAmount(long ms) {
|
||||
return formatMilliseconds(ms);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the difference between the two dates into readable format.
|
||||
*
|
||||
* @param before
|
||||
* @param now
|
||||
* @return Readable format
|
||||
* @throws NumberFormatException
|
||||
*/
|
||||
public static String formatTimeAmountSinceDate(Date before, Date now) throws NumberFormatException {
|
||||
long ms = Math.abs((now.toInstant().getEpochSecond() * 1000) - (before.toInstant().getEpochSecond() * 1000));
|
||||
return turnMsLongToString(ms);
|
||||
public static String formatTimeAmountDifference(long before, long after) {
|
||||
return formatMilliseconds(Math.abs(after - before));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Date with Epoch second and returns Date and Time String.
|
||||
*
|
||||
* @param string
|
||||
* @return Readable TimeStamp
|
||||
* @throws NumberFormatException String is not Long
|
||||
*/
|
||||
public static String formatTimeStamp(String string) throws NumberFormatException {
|
||||
long ms = Long.parseLong(string);
|
||||
Date sfd = new Date(ms);
|
||||
public static String formatTimeStamp(long epochMs) {
|
||||
Date sfd = new Date(epochMs);
|
||||
return ("" + sfd).substring(4, 19);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the difference between the two dates, where first is in String of
|
||||
* Long format, into readable format.
|
||||
*
|
||||
* @param string Long in ms, date
|
||||
* @param now
|
||||
* @return
|
||||
* @throws NumberFormatException
|
||||
*/
|
||||
public static String formatTimeAmountSinceString(String string, Date now) throws NumberFormatException {
|
||||
long ms = Math.abs((now.toInstant().getEpochSecond() * 1000) - Long.parseLong(string));
|
||||
return turnMsLongToString(ms);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes letters from a string leaving only numbers and dots.
|
||||
*
|
||||
@ -72,7 +32,7 @@ public class FormatUtils {
|
||||
public static String removeLetters(String dataPoint) {
|
||||
return dataPoint.replaceAll("[^\\d.]", "");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param dataPoint
|
||||
@ -80,15 +40,15 @@ public class FormatUtils {
|
||||
*/
|
||||
public static String removeNumbers(String dataPoint) {
|
||||
for (char c : removeLetters(dataPoint).toCharArray()) {
|
||||
dataPoint = dataPoint.replace(c+"", "");
|
||||
dataPoint = dataPoint.replace(c + "", "");
|
||||
}
|
||||
dataPoint = dataPoint.replace(" ", "");
|
||||
return dataPoint;
|
||||
}
|
||||
|
||||
// Formats long in milliseconds into d:h:m:s string
|
||||
private static String turnMsLongToString(long ms) {
|
||||
String returnValue = "";
|
||||
private static String formatMilliseconds(long ms) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
long x = ms / 1000;
|
||||
long seconds = x % 60;
|
||||
x /= 60;
|
||||
@ -98,21 +58,22 @@ public class FormatUtils {
|
||||
x /= 24;
|
||||
long days = x;
|
||||
if (days != 0) {
|
||||
returnValue += days + "d ";
|
||||
builder.append(days).append("d ");
|
||||
}
|
||||
if (hours != 0) {
|
||||
returnValue += hours + "h ";
|
||||
builder.append(hours).append("h ");
|
||||
}
|
||||
if (minutes != 0) {
|
||||
returnValue += minutes + "m ";
|
||||
builder.append(minutes).append("m ");
|
||||
}
|
||||
if (seconds != 0) {
|
||||
returnValue += seconds + "s";
|
||||
builder.append(seconds).append("s");
|
||||
}
|
||||
if (returnValue.isEmpty()) {
|
||||
returnValue += "0s";
|
||||
String formattedTime = builder.toString();
|
||||
if (formattedTime.isEmpty()) {
|
||||
return "0s";
|
||||
}
|
||||
return returnValue;
|
||||
return formattedTime;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -165,21 +126,6 @@ public class FormatUtils {
|
||||
return "x " + loc.getBlockX() + " z " + loc.getBlockZ() + " in " + loc.getWorld();
|
||||
}
|
||||
|
||||
static String swapColorsToSpan(String string) {
|
||||
Html[] replacer = new Html[]{Html.COLOR_0, Html.COLOR_1, Html.COLOR_2, Html.COLOR_3,
|
||||
Html.COLOR_4, Html.COLOR_5, Html.COLOR_6, Html.COLOR_7, Html.COLOR_8, Html.COLOR_9,
|
||||
Html.COLOR_a, Html.COLOR_b, Html.COLOR_c, Html.COLOR_d, Html.COLOR_e, Html.COLOR_f};
|
||||
|
||||
for (Html html : replacer) {
|
||||
string = string.replaceAll("§" + html.name().charAt(6), html.parse());
|
||||
}
|
||||
int spans = string.split("<span").length - 1;
|
||||
for (int i = 0; i < spans; i++) {
|
||||
string = Html.SPAN.parse(string);
|
||||
}
|
||||
return string.replaceAll("§r", "");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param d
|
||||
|
@ -145,4 +145,19 @@ public class HtmlUtils {
|
||||
html.append("</div>");
|
||||
return html.toString();
|
||||
}
|
||||
|
||||
public static String swapColorsToSpan(String string) {
|
||||
Html[] replacer = new Html[]{Html.COLOR_0, Html.COLOR_1, Html.COLOR_2, Html.COLOR_3,
|
||||
Html.COLOR_4, Html.COLOR_5, Html.COLOR_6, Html.COLOR_7, Html.COLOR_8, Html.COLOR_9,
|
||||
Html.COLOR_a, Html.COLOR_b, Html.COLOR_c, Html.COLOR_d, Html.COLOR_e, Html.COLOR_f};
|
||||
|
||||
for (Html html : replacer) {
|
||||
string = string.replaceAll("§" + html.name().charAt(6), html.parse());
|
||||
}
|
||||
int spans = string.split("<span").length - 1;
|
||||
for (int i = 0; i < spans; i++) {
|
||||
string = Html.SPAN.parse(string);
|
||||
}
|
||||
return string.replaceAll("§r", "");
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,70 @@
|
||||
package main.java.com.djrapitops.plan.utilities;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.OptionalDouble;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class MathUtils {
|
||||
|
||||
public static double averageInt(Stream<Integer> values) {
|
||||
OptionalDouble average = values.mapToInt(i -> i).average();
|
||||
if (average.isPresent()) {
|
||||
return average.getAsDouble();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static long averageLong(Collection<Long> values) {
|
||||
return averageLong(values.stream());
|
||||
}
|
||||
|
||||
public static long averageLong(Stream<Long> values) {
|
||||
OptionalDouble average = values.mapToLong(i -> i).average();
|
||||
if (average.isPresent()) {
|
||||
return (long) average.getAsDouble();
|
||||
} else {
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
public static double averageDouble(Stream<Double> values) {
|
||||
OptionalDouble average = values.mapToDouble(i -> i).average();
|
||||
if (average.isPresent()) {
|
||||
return average.getAsDouble();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static double average(int total, int size) {
|
||||
return 1.0 * total / size;
|
||||
}
|
||||
|
||||
public static long countTrueBoolean(Stream<Boolean> values) {
|
||||
return values.filter(i -> i).count();
|
||||
}
|
||||
|
||||
public static int sumInt(Stream<Serializable> values) {
|
||||
return values
|
||||
.mapToInt(value -> (Integer) value)
|
||||
.sum();
|
||||
}
|
||||
|
||||
public static long sumLong(Stream<Serializable> values) {
|
||||
return values
|
||||
.mapToLong(value -> (Long) value)
|
||||
.sum();
|
||||
}
|
||||
|
||||
public static double sumDouble(Stream<Serializable> values) {
|
||||
return values
|
||||
.mapToDouble(value -> (Double) value)
|
||||
.sum();
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
@ -23,6 +24,10 @@ import org.bukkit.entity.Player;
|
||||
*/
|
||||
public class MiscUtils {
|
||||
|
||||
public static long getTime() {
|
||||
return new Date().getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the version and returns response String.
|
||||
*
|
||||
@ -80,7 +85,7 @@ public class MiscUtils {
|
||||
public static String getPlayerName(String[] args, CommandSender sender) {
|
||||
return getPlayerName(args, sender, Permissions.INSPECT_OTHER);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Used by the inspect command.
|
||||
*
|
||||
|
@ -1,6 +1,5 @@
|
||||
package main.java.com.djrapitops.plan.utilities;
|
||||
|
||||
import java.util.Date;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.data.DemographicsData;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
@ -44,7 +43,7 @@ public class NewPlayerCreator {
|
||||
public static UserData createNewPlayer(OfflinePlayer player, GameMode gm) {
|
||||
UserData data = new UserData(player, new DemographicsData());
|
||||
data.setLastGamemode(gm);
|
||||
data.setLastPlayed(new Date().getTime());
|
||||
data.setLastPlayed(MiscUtils.getTime());
|
||||
long zero = Long.parseLong("0");
|
||||
data.setPlayTime(zero);
|
||||
data.setTimesKicked(0);
|
||||
|
@ -2,7 +2,6 @@ package main.java.com.djrapitops.plan.utilities;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@ -46,10 +45,10 @@ public class PlaceholderUtils {
|
||||
replaceMap.put("%commanduse%", HtmlUtils.removeXSS(data.getCommandUseListHtml()));
|
||||
replaceMap.put("%totalcommands%", data.getTotalCommands() + "");
|
||||
replaceMap.put("%avgage%", (data.getAverageAge() != -1) ? "" + data.getAverageAge() : Phrase.DEM_UNKNOWN + "");
|
||||
replaceMap.put("%avgplaytime%", FormatUtils.formatTimeAmount("" + data.getAveragePlayTime()));
|
||||
replaceMap.put("%totalplaytime%", FormatUtils.formatTimeAmount("" + data.getTotalPlayTime()));
|
||||
replaceMap.put("%avgplaytime%", FormatUtils.formatTimeAmount(data.getAveragePlayTime()));
|
||||
replaceMap.put("%totalplaytime%", FormatUtils.formatTimeAmount(data.getTotalPlayTime()));
|
||||
replaceMap.put("%ops%", "" + data.getOps());
|
||||
replaceMap.put("%refresh%", FormatUtils.formatTimeAmountSinceString("" + data.getRefreshDate(), new Date()));
|
||||
replaceMap.put("%refresh%", FormatUtils.formatTimeAmountDifference(data.getRefreshDate(), MiscUtils.getTime()));
|
||||
replaceMap.put("%totallogins%", "" + data.getTotalLoginTimes());
|
||||
replaceMap.put("%top20mostactive%", Html.ERROR_NOT_SET.parse());
|
||||
replaceMap.put("%recentlogins%", data.getRecentPlayers());
|
||||
@ -105,7 +104,7 @@ public class PlaceholderUtils {
|
||||
+ "\",\"#" + Settings.HCOLOR_GENP_U + "\"");
|
||||
replaceMap.put("%genderfcolor%", "#" + Settings.HCOLOR_GENP_F);
|
||||
replaceMap.put("%gendermcolor%", "#" + Settings.HCOLOR_GENP_M);
|
||||
replaceMap.put("%sessionaverage%", FormatUtils.formatTimeAmount(data.getSessionAverage() + ""));
|
||||
replaceMap.put("%sessionaverage%", FormatUtils.formatTimeAmount(data.getSessionAverage()));
|
||||
replaceMap.put("%geomapcountries%", data.getGeomapCountries());
|
||||
replaceMap.put("%geomapz%", data.getGeomapZ());
|
||||
replaceMap.put("%geomapcodes%", data.getGeomapCodes());
|
||||
@ -116,7 +115,7 @@ public class PlaceholderUtils {
|
||||
String[] defaultCols = new String[]{"348e0f", "267F00", "5cb239", "89c471", "5da341"};
|
||||
for (int i = 0; i < colors.length; i++) {
|
||||
if (!defaultCols[i].equals(colors[i])) {
|
||||
replaceMap.put("#"+defaultCols[i], "#"+colors[i]);
|
||||
replaceMap.put("#" + defaultCols[i], "#" + colors[i]);
|
||||
}
|
||||
}
|
||||
return replaceMap;
|
||||
@ -134,10 +133,11 @@ public class PlaceholderUtils {
|
||||
boolean showIPandUUID = Settings.SECURITY_IP_UUID.isTrue();
|
||||
UUID uuid = data.getUuid();
|
||||
replaceMap.put("%uuid%", (showIPandUUID ? "" + uuid : Html.HIDDEN.parse()));
|
||||
replaceMap.put("%lastseen%", FormatUtils.formatTimeStamp("" + data.getLastPlayed()));
|
||||
replaceMap.put("%lastseen%", FormatUtils.formatTimeStamp(data.getLastPlayed()));
|
||||
replaceMap.put("%logintimes%", "" + data.getLoginTimes());
|
||||
replaceMap.put("%geoloc%", data.getDemData().getGeoLocation());
|
||||
boolean isActive = AnalysisUtils.isActive(data.getLastPlayed(), data.getPlayTime(), data.getLoginTimes());
|
||||
long now = MiscUtils.getTime();
|
||||
boolean isActive = AnalysisUtils.isActive(now, data.getLastPlayed(), data.getPlayTime(), data.getLoginTimes());
|
||||
replaceMap.put("%active%", isActive ? Html.ACTIVE.parse() : Html.INACTIVE.parse());
|
||||
int age = data.getDemData().getAge();
|
||||
replaceMap.put("%age%", (age != -1) ? "" + age : Phrase.DEM_UNKNOWN + "");
|
||||
@ -160,21 +160,21 @@ public class PlaceholderUtils {
|
||||
gmThree
|
||||
};
|
||||
long total = gmData[0] + gmData[1] + gmData[2] + gmData[3];
|
||||
replaceMap.put("%gm0%", FormatUtils.formatTimeAmount("" + gmData[0]));
|
||||
replaceMap.put("%gm1%", FormatUtils.formatTimeAmount("" + gmData[1]));
|
||||
replaceMap.put("%gm2%", FormatUtils.formatTimeAmount("" + gmData[2]));
|
||||
replaceMap.put("%gm3%", FormatUtils.formatTimeAmount("" + gmData[3]));
|
||||
replaceMap.put("%gm0%", FormatUtils.formatTimeAmount(gmData[0]));
|
||||
replaceMap.put("%gm1%", FormatUtils.formatTimeAmount(gmData[1]));
|
||||
replaceMap.put("%gm2%", FormatUtils.formatTimeAmount(gmData[2]));
|
||||
replaceMap.put("%gm3%", FormatUtils.formatTimeAmount(gmData[3]));
|
||||
replaceMap.put("%gmdata%", Arrays.toString(gmData));
|
||||
replaceMap.put("%gmlabels%", "[\"Survival\", \"Creative\", \"Adventure\", \"Spectator\"]");
|
||||
replaceMap.put("%gmcolors%", "\"#" + Settings.HCOLOR_GMP_0 + "\",\"#" + Settings.HCOLOR_GMP_1
|
||||
+ "\",\"#" + Settings.HCOLOR_GMP_2 + "\",\"#" + Settings.HCOLOR_GMP_3 + "\"");
|
||||
replaceMap.put("%gmtotal%", FormatUtils.formatTimeAmount("" + total));
|
||||
replaceMap.put("%gmtotal%", FormatUtils.formatTimeAmount(total));
|
||||
replaceMap.put("%ips%", (showIPandUUID ? data.getIps().toString() : Html.HIDDEN.parse()));
|
||||
replaceMap.put("%nicknames%", HtmlUtils.removeXSS(FormatUtils.swapColorsToSpan(data.getNicknames().toString())));
|
||||
replaceMap.put("%nicknames%", HtmlUtils.removeXSS(HtmlUtils.swapColorsToSpan(data.getNicknames().toString())));
|
||||
replaceMap.put("%name%", data.getName());
|
||||
replaceMap.put("%registered%", FormatUtils.formatTimeStamp("" + data.getRegistered()));
|
||||
replaceMap.put("%registered%", FormatUtils.formatTimeStamp(data.getRegistered()));
|
||||
replaceMap.put("%timeskicked%", "" + data.getTimesKicked());
|
||||
replaceMap.put("%playtime%", FormatUtils.formatTimeAmount("" + data.getPlayTime()));
|
||||
replaceMap.put("%playtime%", FormatUtils.formatTimeAmount(data.getPlayTime()));
|
||||
replaceMap.put("%banned%", data.isBanned() ? Html.BANNED.parse() : "");
|
||||
replaceMap.put("%op%", data.isOp() ? Html.OPERATOR.parse() : "");
|
||||
replaceMap.put("%isonline%", (data.isOnline()) ? Html.ONLINE.parse() : Html.OFFLINE.parse());
|
||||
@ -183,7 +183,7 @@ public class PlaceholderUtils {
|
||||
replaceMap.put("%playerkills%", data.getPlayerKills().size() + "");
|
||||
replaceMap.put("%mobkills%", data.getMobKills() + "");
|
||||
replaceMap.put("%sessionstable%", SortableSessionTableCreator.createSortedSessionDataTable10(data.getSessions()));
|
||||
replaceMap.put("%sessionaverage%", FormatUtils.formatTimeAmount(AnalysisUtils.average(AnalysisUtils.transformSessionDataToLengths(data.getSessions())) + ""));
|
||||
replaceMap.put("%sessionaverage%", FormatUtils.formatTimeAmount(MathUtils.averageLong(AnalysisUtils.transformSessionDataToLengths(data.getSessions()))));
|
||||
replaceMap.put("%killstable%", SortableKillsTableCreator.createSortedSessionDataTable10(data.getPlayerKills()));
|
||||
Plan plugin = Plan.getInstance();
|
||||
replaceMap.put("%version%", plugin.getDescription().getVersion());
|
||||
@ -197,7 +197,7 @@ public class PlaceholderUtils {
|
||||
replaceMap.put("%gm1col%", Settings.HCOLOR_GMP_1 + "");
|
||||
replaceMap.put("%gm2col%", Settings.HCOLOR_GMP_2 + "");
|
||||
replaceMap.put("%gm3col%", Settings.HCOLOR_GMP_3 + "");
|
||||
replaceMap.put("%inaccuratedatawarning%", (new Date().getTime() - data.getRegistered() < 180000) ? Html.WARN_INACCURATE.parse() : "");
|
||||
replaceMap.put("%inaccuratedatawarning%", (now - data.getRegistered() < 180000) ? Html.WARN_INACCURATE.parse() : "");
|
||||
String pluginsTabHtml = plugin.getHookHandler().getPluginsTabLayoutForInspect();
|
||||
Map<String, String> additionalReplaceRules = plugin.getHookHandler().getAdditionalInspectReplaceRules(uuid);
|
||||
String replacedOnce = HtmlUtils.replacePlaceholders(pluginsTabHtml, additionalReplaceRules);
|
||||
|
@ -1,12 +1,6 @@
|
||||
/*
|
||||
* 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 test.java.main.java.com.djrapitops.plan;
|
||||
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import static org.junit.Assert.*;
|
||||
@ -24,15 +18,13 @@ import test.java.utils.TestInit;
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest(JavaPlugin.class)
|
||||
public class PhraseTest {
|
||||
|
||||
private Plan plan;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public PhraseTest() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -40,17 +32,16 @@ public class PhraseTest {
|
||||
public void setUp() {
|
||||
TestInit t = new TestInit();
|
||||
assertTrue("Not set up", t.setUp());
|
||||
plan = t.getPlanMock();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testToString() {
|
||||
public void testToString() {
|
||||
Phrase instance = Phrase.REPLACE0;
|
||||
String expResult = "REPLACE0";
|
||||
instance.setText(expResult);
|
||||
instance.setText(expResult);
|
||||
String result = instance.toString();
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ public class SettingsTest {
|
||||
*/
|
||||
@Test
|
||||
public void testToString() {
|
||||
assertEquals("sqlite",Settings.DB_TYPE.toString());
|
||||
assertEquals("sqlite", Settings.DB_TYPE.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -59,7 +59,7 @@ public class SettingsTest {
|
||||
*/
|
||||
@Test
|
||||
public void testGetNumber() {
|
||||
assertEquals(8804,Settings.WEBSERVER_PORT.getNumber());
|
||||
assertEquals(8804, Settings.WEBSERVER_PORT.getNumber());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,8 +1,3 @@
|
||||
/*
|
||||
* 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 test.java.main.java.com.djrapitops.plan.api;
|
||||
|
||||
import main.java.com.djrapitops.plan.api.Gender;
|
||||
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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 test.java.main.java.com.djrapitops.plan.data.additional;
|
||||
|
||||
import main.java.com.djrapitops.plan.data.additional.AnalysisType;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Risto
|
||||
*/
|
||||
public class AnalysisTypeTest {
|
||||
|
||||
public AnalysisTypeTest() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetModifier() {
|
||||
assertEquals("Average ", AnalysisType.INT_AVG.getModifier());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPlaceholderModifier() {
|
||||
assertEquals("totalInt_", AnalysisType.INT_TOTAL.getPlaceholderModifier());
|
||||
}
|
||||
|
||||
}
|
@ -7,7 +7,6 @@ package test.java.main.java.com.djrapitops.plan.data.cache;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@ -18,6 +17,7 @@ import main.java.com.djrapitops.plan.data.cache.DBCallableProcessor;
|
||||
import main.java.com.djrapitops.plan.data.cache.DataCacheHandler;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.junit.After;
|
||||
@ -64,7 +64,7 @@ public class DataCacheHandlerTest {
|
||||
plan = t.getPlanMock();
|
||||
calledSaveCommandUse = false;
|
||||
calledSaveUserData = false;
|
||||
db = new SQLiteDB(plan, "debug" + new Date().getTime()) {
|
||||
db = new SQLiteDB(plan, "debug" + MiscUtils.getTime()) {
|
||||
@Override
|
||||
public void startConnectionPingTask(Plan plugin) {
|
||||
|
||||
|
@ -10,7 +10,6 @@ import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
@ -20,6 +19,7 @@ import main.java.com.djrapitops.plan.data.cache.DBCallableProcessor;
|
||||
import main.java.com.djrapitops.plan.data.cache.queue.DataCacheGetQueue;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@ -61,7 +61,7 @@ public class DataCacheGetQueueTest {
|
||||
TestInit t = new TestInit();
|
||||
assertTrue("Not set up", t.setUp());
|
||||
plan = t.getPlanMock();
|
||||
db = new SQLiteDB(plan, "debug" + new Date().getTime()) {
|
||||
db = new SQLiteDB(plan, "debug" + MiscUtils.getTime()) {
|
||||
@Override
|
||||
public void startConnectionPingTask(Plan plugin) {
|
||||
|
||||
|
@ -6,12 +6,12 @@
|
||||
package test.java.main.java.com.djrapitops.plan.data.cache.queue;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.junit.After;
|
||||
import static org.junit.Assert.*;
|
||||
@ -53,7 +53,7 @@ public class DataCacheSaveQueueTest {
|
||||
plan = t.getPlanMock();
|
||||
calledSaveUserData = false;
|
||||
calledSaveUserData2 = false;
|
||||
db = new SQLiteDB(plan, "debug" + new Date().getTime()) {
|
||||
db = new SQLiteDB(plan, "debug" + MiscUtils.getTime()) {
|
||||
@Override
|
||||
public void startConnectionPingTask(Plan plugin) {
|
||||
|
||||
|
@ -7,7 +7,6 @@ package test.java.main.java.com.djrapitops.plan.data.handling;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.DemographicsData;
|
||||
import main.java.com.djrapitops.plan.data.KillData;
|
||||
@ -15,6 +14,7 @@ import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.data.handling.KillHandling;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.junit.After;
|
||||
@ -55,7 +55,7 @@ public class KillHandlingTest {
|
||||
TestInit t = new TestInit();
|
||||
assertTrue("Not set up", t.setUp());
|
||||
plan = t.getPlanMock();
|
||||
db = new SQLiteDB(plan, "debug" + new Date().getTime()) {
|
||||
db = new SQLiteDB(plan, "debug" + MiscUtils.getTime()) {
|
||||
@Override
|
||||
public void startConnectionPingTask(Plan plugin) {
|
||||
|
||||
|
@ -6,7 +6,6 @@
|
||||
package test.java.main.java.com.djrapitops.plan.data.handling.info;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.DemographicsData;
|
||||
import main.java.com.djrapitops.plan.data.KillData;
|
||||
@ -14,6 +13,7 @@ import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.KillInfo;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.junit.After;
|
||||
@ -51,7 +51,7 @@ public class KillInfoTest {
|
||||
TestInit t = new TestInit();
|
||||
assertTrue("Not set up", t.setUp());
|
||||
Plan plan = t.getPlanMock();
|
||||
db = new SQLiteDB(plan, "debug" + new Date().getTime()) {
|
||||
db = new SQLiteDB(plan, "debug" + MiscUtils.getTime()) {
|
||||
@Override
|
||||
public void startConnectionPingTask(Plan plugin) {
|
||||
|
||||
|
@ -11,7 +11,6 @@ import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@ -25,6 +24,7 @@ import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.database.databases.MySQLDB;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
|
||||
import main.java.com.djrapitops.plan.utilities.ManageUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@ -71,7 +71,7 @@ public class DatabaseTest {
|
||||
TestInit t = new TestInit();
|
||||
assertTrue("Not set up", t.setUp());
|
||||
plan = t.getPlanMock();
|
||||
db = new SQLiteDB(plan, "debug" + new Date().getTime()) {
|
||||
db = new SQLiteDB(plan, "debug" + MiscUtils.getTime()) {
|
||||
@Override
|
||||
public void startConnectionPingTask(Plan plugin) {
|
||||
|
||||
|
@ -7,10 +7,10 @@ package test.java.main.java.com.djrapitops.plan.utilities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import main.java.com.djrapitops.plan.data.SessionData;
|
||||
import main.java.com.djrapitops.plan.utilities.AnalysisUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
@ -48,7 +48,7 @@ public class AnalysisUtilsTest {
|
||||
*/
|
||||
@Test
|
||||
public void testIsActive() {
|
||||
long lastPlayed = new Date().getTime();
|
||||
long lastPlayed = MiscUtils.getTime();
|
||||
long playTime = 12638934876L;
|
||||
int loginTimes = 4;
|
||||
boolean expResult = true;
|
||||
@ -61,7 +61,7 @@ public class AnalysisUtilsTest {
|
||||
*/
|
||||
@Test
|
||||
public void testIsNotActive2() {
|
||||
long lastPlayed = new Date().getTime();
|
||||
long lastPlayed = MiscUtils.getTime();
|
||||
long playTime = 0L;
|
||||
int loginTimes = 4;
|
||||
boolean expResult = false;
|
||||
@ -74,7 +74,7 @@ public class AnalysisUtilsTest {
|
||||
*/
|
||||
@Test
|
||||
public void testIsNotActive3() {
|
||||
long lastPlayed = new Date().getTime();
|
||||
long lastPlayed = MiscUtils.getTime();
|
||||
long playTime = 12638934876L;
|
||||
int loginTimes = 0;
|
||||
boolean expResult = false;
|
||||
@ -137,33 +137,5 @@ public class AnalysisUtilsTest {
|
||||
expResult.add(20L);
|
||||
List<Long> result = AnalysisUtils.transformSessionDataToLengths(data);
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testAverage() {
|
||||
Collection<Long> o = new ArrayList<>();
|
||||
o.add(0L);
|
||||
o.add(1L);
|
||||
o.add(2L);
|
||||
o.add(3L);
|
||||
o.add(4L);
|
||||
long expResult = 2L;
|
||||
long result = AnalysisUtils.average(o);
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testAverageEmpty() {
|
||||
Collection<Long> list = new ArrayList<>();
|
||||
long expResult = 0L;
|
||||
long result = AnalysisUtils.average(list);
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -30,9 +30,9 @@ public class FormatUtilsTest {
|
||||
*/
|
||||
@Test
|
||||
public void testFormatTimeAmount() {
|
||||
String string = "" + 1000L;
|
||||
long second = 1000L;
|
||||
String expResult = "1s";
|
||||
String result = FormatUtils.formatTimeAmount(string);
|
||||
String result = FormatUtils.formatTimeAmount(second);
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ public class FormatUtilsTest {
|
||||
Date before = new Date(300000L);
|
||||
Date now = new Date(310000L);
|
||||
String expResult = "10s";
|
||||
String result = FormatUtils.formatTimeAmountSinceDate(before, now);
|
||||
String result = FormatUtils.formatTimeAmountDifference(before.getTime(), now.getTime());
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
@ -53,21 +53,9 @@ public class FormatUtilsTest {
|
||||
*/
|
||||
@Test
|
||||
public void testFormatTimeStamp() {
|
||||
String string = "0";
|
||||
long epochZero = 0L;
|
||||
String expResult = "Jan 01 02:00:00";
|
||||
String result = FormatUtils.formatTimeStamp(string);
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testFormatTimeAmountSinceString() {
|
||||
String string = "" + new Date(310000L).toInstant().getEpochSecond() * 1000L;
|
||||
Date now = new Date(300000L);
|
||||
String expResult = "10s";
|
||||
String result = FormatUtils.formatTimeAmountSinceString(string, now);
|
||||
String result = FormatUtils.formatTimeStamp(epochZero);
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,127 @@
|
||||
/*
|
||||
* 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 test.java.main.java.com.djrapitops.plan.utilities;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import main.java.com.djrapitops.plan.utilities.MathUtils;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Risto
|
||||
*/
|
||||
public class MathUtilsTest {
|
||||
|
||||
public MathUtilsTest() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAverageInt() {
|
||||
List<Integer> l = new ArrayList<>();
|
||||
double exp = 10;
|
||||
l.add(0);
|
||||
l.add(20);
|
||||
l.add(5);
|
||||
l.add(15);
|
||||
double result = MathUtils.averageInt(l.stream());
|
||||
assertTrue(exp == result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAverageIntEmpty() {
|
||||
List<Integer> l = new ArrayList<>();
|
||||
double exp = 0;
|
||||
double result = MathUtils.averageInt(l.stream());
|
||||
assertTrue(result + "/" + exp, exp == result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAverageLong_Collection() {
|
||||
List<Long> l = new ArrayList<>();
|
||||
double exp = 10;
|
||||
l.add(0L);
|
||||
l.add(20L);
|
||||
l.add(5L);
|
||||
l.add(15L);
|
||||
double result = MathUtils.averageLong(l);
|
||||
assertTrue(result + "/" + exp, exp == result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAverageDouble() {
|
||||
List<Double> l = new ArrayList<>();
|
||||
double exp = 10;
|
||||
l.add(0.0);
|
||||
l.add(20.5);
|
||||
l.add(4.5);
|
||||
l.add(15.0);
|
||||
double result = MathUtils.averageDouble(l.stream());
|
||||
assertTrue(result + "/" + exp, exp == result);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAverage() {
|
||||
double exp = 10;
|
||||
double result = MathUtils.average(40, 4);
|
||||
assertTrue(result + "/" + exp, exp == result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCountTrueBoolean() {
|
||||
List<Boolean> l = new ArrayList<>();
|
||||
int exp = new Random().nextInt(1000);
|
||||
for (int i = 0; i < exp; i++) {
|
||||
l.add(true);
|
||||
}
|
||||
for (int i = exp; i < 1000; i++) {
|
||||
l.add(false);
|
||||
}
|
||||
long result = MathUtils.countTrueBoolean(l.stream());
|
||||
assertTrue(result + "/" + exp, exp == result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSumInt() {
|
||||
List<Serializable> l = new ArrayList<>();
|
||||
double exp = 40;
|
||||
l.add(0);
|
||||
l.add(20);
|
||||
l.add(5);
|
||||
l.add(15);
|
||||
double result = MathUtils.sumInt(l.stream());
|
||||
assertTrue(result + "/" + exp, exp == result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSumLong() {
|
||||
List<Serializable> l = new ArrayList<>();
|
||||
long exp = 40;
|
||||
l.add(0L);
|
||||
l.add(20L);
|
||||
l.add(5L);
|
||||
l.add(15L);
|
||||
long result = MathUtils.sumLong(l.stream());
|
||||
assertTrue(result + "/" + exp, exp == result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSumDouble() {
|
||||
List<Serializable> l = new ArrayList<>();
|
||||
double exp = 100.4531541;
|
||||
l.add(0.0);
|
||||
l.add(50.4);
|
||||
l.add(45.0);
|
||||
l.add(5.0531541);
|
||||
double result = MathUtils.sumDouble(l.stream());
|
||||
assertTrue(result + "/" + exp, exp == result);
|
||||
}
|
||||
|
||||
}
|
@ -5,9 +5,9 @@
|
||||
*/
|
||||
package test.java.main.java.com.djrapitops.plan.utilities;
|
||||
|
||||
import java.util.Date;
|
||||
import main.java.com.djrapitops.plan.data.DemographicsData;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.NewPlayerCreator;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@ -62,7 +62,7 @@ public class NewPlayerCreatorTest {
|
||||
UserData result = NewPlayerCreator.createNewPlayer(p);
|
||||
UserData exp = new UserData(p, new DemographicsData());
|
||||
exp.setLastGamemode(GameMode.SURVIVAL);
|
||||
exp.setLastPlayed(new Date().getTime());
|
||||
exp.setLastPlayed(MiscUtils.getTime());
|
||||
long zero = Long.parseLong("0");
|
||||
exp.setPlayTime(zero);
|
||||
exp.setTimesKicked(0);
|
||||
@ -82,7 +82,7 @@ public class NewPlayerCreatorTest {
|
||||
UserData result = NewPlayerCreator.createNewPlayer(p);
|
||||
UserData exp = new UserData(p, new DemographicsData());
|
||||
exp.setLastGamemode(GameMode.SPECTATOR);
|
||||
exp.setLastPlayed(new Date().getTime());
|
||||
exp.setLastPlayed(MiscUtils.getTime());
|
||||
long zero = Long.parseLong("0");
|
||||
exp.setPlayTime(zero);
|
||||
exp.setTimesKicked(0);
|
||||
@ -102,7 +102,7 @@ public class NewPlayerCreatorTest {
|
||||
UserData result = NewPlayerCreator.createNewPlayer(p, GameMode.CREATIVE);
|
||||
UserData exp = new UserData(p, new DemographicsData());
|
||||
exp.setLastGamemode(GameMode.CREATIVE);
|
||||
exp.setLastPlayed(new Date().getTime());
|
||||
exp.setLastPlayed(MiscUtils.getTime());
|
||||
long zero = Long.parseLong("0");
|
||||
exp.setPlayTime(zero);
|
||||
exp.setTimesKicked(0);
|
||||
|
Loading…
Reference in New Issue
Block a user