Count Up Javascript to both pages., javadoc

Fix #107
Added #106 #105
This commit is contained in:
Rsl1122 2017-05-31 12:41:56 +03:00
parent c5d35b4445
commit a92da9a503
38 changed files with 597 additions and 73 deletions

View File

@ -885,26 +885,58 @@ public class AnalysisData {
this.genderData = genderData;
}
/**
* Get the data for the Session Punchcard
*
* @return Array of x y r coordinates: [{x: 4, y: 5, r: 4}]
*/
public String getPunchCardData() {
return punchCardData;
}
/**
* Set the data for the Session Punchcard
*
* @param punchCardData Array of x y r coordinates: [{x: 4, y: 5, r: 4}]
*/
public void setPunchCardData(String punchCardData) {
this.punchCardData = punchCardData;
}
/**
* Get the data and labels for the session distribution barchart.
*
* @return index 0: [0, 5, 4], 1: ["0-5", "5-10", "10-15"]
*/
public String[] getSessionDistributionData() {
return sessionDistributionData;
}
/**
* Set the data and labels for the session distribution barchart.
*
* @param sessionDistributionData index 0: [0, 5, 4], 1: ["0-5", "5-10",
* "10-15"]
*/
public void setSessionDistributionData(String[] sessionDistributionData) {
this.sessionDistributionData = sessionDistributionData;
}
/**
* Get the data and labels for the playtime distribution barchart.
*
* @return index 0: [0, 5, 4], 1: ["0-5", "5-10", "10-15"]
*/
public String[] getPlaytimeDistributionData() {
return playtimeDistributionData;
}
/**
* Set the data and labels for the playtime distribution barchart.
*
* @param playtimeDistributionData index 0: [0, 5, 4], 1: ["0-5", "5-10",
* "10-15"]
*/
public void setPlaytimeDistributionData(String[] playtimeDistributionData) {
this.playtimeDistributionData = playtimeDistributionData;
}

View File

@ -944,10 +944,19 @@ public class UserData {
this.clearAfterSave = clearAfterSave;
}
/**
* Set the banned value.
*
* @param isBanned true/false
*/
public void setBanned(boolean isBanned) {
this.isBanned = isBanned;
}
/**
* Set the online value.
* @param isOnline true/false
*/
public void setOnline(boolean isOnline) {
this.isOnline = isOnline;
}

View File

@ -11,6 +11,9 @@ import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
*/
public abstract class Hook {
/**
* Is the plugin being hooked properly enabled?
*/
protected boolean enabled;
/**

View File

@ -2,7 +2,6 @@ package main.java.com.djrapitops.plan.data.additional.jobs;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.PlayerManager;
import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobProgression;
import java.io.Serializable;
import java.util.Arrays;
@ -29,6 +28,9 @@ import static org.bukkit.Bukkit.getOfflinePlayers;
*/
public class JobsAnalysisJobTable extends PluginData {
/**
* Class Constructor, sets the parameters of the PluginData object.
*/
public JobsAnalysisJobTable() {
super("Jobs", "analysistable", AnalysisType.HTML);
final String job = Html.FONT_AWESOME_ICON.parse("suitcase") + " Job";

View File

@ -22,6 +22,9 @@ import main.java.com.djrapitops.plan.ui.Html;
*/
public class JobsInspectJobTable extends PluginData {
/**
* Class Constructor, sets the parameters of the PluginData object.
*/
public JobsInspectJobTable() {
super("Jobs", "inspecttable");
super.setAnalysisOnly(false);
@ -33,19 +36,22 @@ public class JobsInspectJobTable extends PluginData {
@Override
public String getHtmlReplaceValue(String modifierPrefix, UUID uuid) {
try {
PlayerManager pm = Jobs.getPlayerManager();
PlayerInfo info = pm.getPlayerInfo(uuid);
JobsPlayer player = pm.getJobsPlayerOffline(info);
List<JobProgression> progression = player.getJobProgression();
if (progression.isEmpty()) {
return parseContainer("", Html.TABLELINE_2.parse("No Jobs.", ""));
}
if (!progression.isEmpty()) {
StringBuilder html = new StringBuilder();
for (JobProgression job : progression) {
html.append(Html.TABLELINE_2.parse(job.getJob().getName(), "" + job.getLevel()));
}
return parseContainer("", html.toString());
}
} catch (NullPointerException e) {
}
return parseContainer("", Html.TABLELINE_2.parse("No Jobs.", ""));
}
@Override
public Serializable getValue(UUID uuid) {

View File

@ -6,7 +6,6 @@ import com.gmail.nossr50.util.player.UserManager;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
@ -17,7 +16,6 @@ import main.java.com.djrapitops.plan.utilities.FormatUtils;
import main.java.com.djrapitops.plan.utilities.MathUtils;
import org.apache.commons.lang.StringUtils;
import static org.bukkit.Bukkit.getOnlinePlayers;
import org.bukkit.entity.Player;
/**
* PluginData class for McMMO-plugin.
@ -30,6 +28,9 @@ import org.bukkit.entity.Player;
*/
public class McmmoAnalysisSkillTable extends PluginData {
/**
* Class Constructor, sets the parameters of the PluginData object.
*/
public McmmoAnalysisSkillTable() {
super("McMMO", "analysistable", AnalysisType.HTML);
final String skill = Html.FONT_AWESOME_ICON.parse("star") + " Skill";

View File

@ -32,6 +32,9 @@ import static org.bukkit.Bukkit.getOfflinePlayer;
*/
public class McmmoInspectSkillTable extends PluginData {
/**
* Class Constructor, sets the parameters of the PluginData object.
*/
public McmmoInspectSkillTable() {
super("McMMO", "inspectskilltable");
super.setAnalysisOnly(false);

View File

@ -5,12 +5,14 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import main.java.com.djrapitops.plan.Log;
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.utilities.MiscUtils;
/**
* This class stores UserData objects used for displaying the Html pages.
@ -22,7 +24,8 @@ public class InspectCacheHandler {
private DataCacheHandler handler;
private Plan plugin;
private HashMap<UUID, UserData> cache;
private Map<UUID, UserData> cache;
private Map<UUID, Long> cacheTimes;
/**
* Class constructor.
@ -33,6 +36,7 @@ public class InspectCacheHandler {
this.handler = plugin.getHandler();
this.plugin = plugin;
this.cache = new HashMap<>();
cacheTimes = new HashMap<>();
}
/**
@ -48,11 +52,19 @@ public class InspectCacheHandler {
@Override
public void process(UserData data) {
cache.put(uuid, new UserData(data));
cacheTimes.put(uuid, MiscUtils.getTime());
}
};
handler.getUserDataForProcessing(cacher, uuid, false);
}
/**
* Used to cache all UserData to the InspectCache from the cache and
* provided database.
*
* @param db Database to cache from if data is not in the cache.
* @throws SQLException If Database is not properly enabled
*/
public void cacheAllUserData(Database db) throws SQLException {
Set<UUID> cachedUserData = handler.getDataCache().keySet();
for (UUID uuid : cachedUserData) {
@ -66,8 +78,11 @@ public class InspectCacheHandler {
}
savedUUIDs.removeAll(cachedUserData);
List<UserData> userDataForUUIDS = db.getUserDataForUUIDS(savedUUIDs);
long time = MiscUtils.getTime();
for (UserData uData : userDataForUUIDS) {
cache.put(uData.getUuid(), uData);
UUID uuid = uData.getUuid();
cache.put(uuid, uData);
cacheTimes.put(uuid, time);
}
}
@ -81,6 +96,13 @@ public class InspectCacheHandler {
return cache.get(uuid);
}
public long getCacheTime(UUID uuid) {
if (cacheTimes.containsKey(uuid)) {
return cacheTimes.get(uuid);
}
return -1;
}
/**
* Check if the data of a player is in the inspect cache.
*
@ -91,6 +113,11 @@ public class InspectCacheHandler {
return cache.containsKey(uuid);
}
/**
* Used to get all cached userdata objects.
*
* @return List of cached userdata objects.
*/
public List<UserData> getCachedUserData() {
return new ArrayList<>(cache.values());
}

View File

@ -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 main.java.com.djrapitops.plan.data.handling.importing;
import java.util.HashMap;
@ -10,14 +5,28 @@ import java.util.Map;
import static org.bukkit.Bukkit.getPluginManager;
/**
* This class is responsible for static utility methods used for importing.
*
* @author Risto
* @since 3.2.0
*/
public class ImportUtils {
/**
* Checks if a plugin is enabled.
*
* @param pluginName Name of the plugin
* @return true/false
*/
public static boolean isPluginEnabled(String pluginName) {
return getPluginManager().isPluginEnabled(pluginName);
}
/**
* Used to get all importers for different plugins.
*
* @return Map of importers with pluginname in lowercase as key.
*/
public static Map<String, Importer> getImporters() {
Map<String, Importer> importers = new HashMap<>();
importers.put("ontime", new OnTimeImporter());

View File

@ -6,8 +6,6 @@ import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.data.cache.DataCacheHandler;
@ -17,15 +15,28 @@ import static org.bukkit.Bukkit.getOfflinePlayer;
import org.bukkit.OfflinePlayer;
/**
* Abstract class used for importing data from other plugins.
*
* @author Rsl1122
* @since 3.2.0
*/
public abstract class Importer {
/**
* Constructor.
*/
public Importer() {
}
/**
* Method used for the import.
*
* Creates UserData for players that have not been saved to the database.
*
* @param uuids UUIDs to be imported
* @return success
*/
public boolean importData(Collection<UUID> uuids) {
Plan plan = Plan.getInstance();
DataCacheHandler handler = plan.getHandler();
@ -49,5 +60,12 @@ public abstract class Importer {
return true;
}
/**
* Method used for getting the HandlingInfo object for the import data.
*
* @param uuid UUID of the player
* @return HandlingInfo object that modifies the UserData so that the data
* is imported.
*/
public abstract HandlingInfo importData(UUID uuid);
}

View File

@ -1,31 +1,38 @@
package main.java.com.djrapitops.plan.data.handling.importing;
import java.util.HashMap;
import java.util.Set;
import java.util.UUID;
import main.java.com.djrapitops.plan.data.UserData;
import main.java.com.djrapitops.plan.data.handling.info.HandlingInfo;
import main.java.com.djrapitops.plan.data.handling.info.InfoType;
import me.edge209.OnTime.OnTimeAPI;
import me.edge209.OnTime.OnTimeAPI.data;
import org.bukkit.Bukkit;
import static org.bukkit.Bukkit.getOfflinePlayer;
import org.bukkit.GameMode;
import org.bukkit.OfflinePlayer;
import static org.bukkit.Bukkit.getOfflinePlayer;
/**
* Class responsible for importing data from OnTime plugin.
*
* Imports playtime
*
* @author Rsl1122
* @since 3.2.0
*/
public class OnTimeImporter extends Importer {
/**
*
* Constructor.
*/
public OnTimeImporter() {
}
/**
* Imports playtime from Ontime.
*
* Resets Gamemode times to survival because it is playtime dependent.
*
* @param uuid UUID of the player
* @return HandlingInfo object
*/
@Override
public HandlingInfo importData(UUID uuid) {
OfflinePlayer p = getOfflinePlayer(uuid);

View File

@ -24,15 +24,54 @@ import org.bukkit.World;
*/
public abstract class Database {
/**
* Instance of Plan used with this database.
*/
protected final Plan plugin;
/**
* Table representing plan_users in the database.
*/
protected UsersTable usersTable;
/**
* Table representing plan_gamemodetimes in the database.
*/
protected GMTimesTable gmTimesTable;
/**
* Table representing plan_kills in the database.
*/
protected KillsTable killsTable;
/**
* Table representing plan_locations in the database.
*/
protected LocationsTable locationsTable;
/**
* Table representing plan_nicknames in the database.
*/
protected NicknamesTable nicknamesTable;
/**
* Table representing plan_sessions in the database.
*/
protected SessionsTable sessionsTable;
/**
* Table representing plan_ips in the database.
*/
protected IPsTable ipsTable;
/**
* Table representing plan_commandusages in the database.
*/
protected CommandUseTable commandUseTable;
/**
* Table representing plan_version in the database.
*/
protected VersionTable versionTable;
/**
@ -81,6 +120,15 @@ public abstract class Database {
*/
public abstract void giveUserDataToProcessors(UUID uuid, Collection<DBCallableProcessor> processors) throws SQLException;
/**
* Used to get all UserData for multiple UUIDs.
*
* Should only be called from async thread.
*
* @param uuids UUIDs to fetch data for.
* @return Data for matching UUIDs.
* @throws SQLException If database error occurs.
*/
public abstract List<UserData> getUserDataForUUIDS(Collection<UUID> uuids) throws SQLException;
/**
@ -239,6 +287,14 @@ public abstract class Database {
return getLocations(Integer.parseInt(userId), worlds);
}
/**
*
* @param userId
* @param worlds
* @return
* @throws SQLException
* @deprecated
*/
@Deprecated
public List<Location> getLocations(int userId, HashMap<String, World> worlds) throws SQLException {
return locationsTable.getLocations(userId, worlds);

View File

@ -146,6 +146,9 @@ public abstract class SQLDB extends Database {
return true;
}
/**
*
*/
public void convertBukkitDataToDB() {
new BukkitRunnable() {
@Override
@ -316,6 +319,12 @@ public abstract class SQLDB extends Database {
Benchmark.stop("DB Give userdata to processors");
}
/**
*
* @param uuidsCol
* @return
* @throws SQLException
*/
@Override
public List<UserData> getUserDataForUUIDS(Collection<UUID> uuidsCol) throws SQLException {
if (uuidsCol == null || uuidsCol.isEmpty()) {

View File

@ -146,6 +146,12 @@ public class IPsTable extends Table {
}
}
/**
*
* @param ids
* @return
* @throws SQLException
*/
public Map<Integer, Set<InetAddress>> getIPList(Collection<Integer> ids) throws SQLException {
if (ids == null || ids.isEmpty()) {
return new HashMap<>();
@ -178,6 +184,11 @@ public class IPsTable extends Table {
}
}
/**
*
* @param ips
* @throws SQLException
*/
public void saveIPList(Map<Integer, Set<InetAddress>> ips) throws SQLException {
if (ips == null || ips.isEmpty()) {
return;

View File

@ -156,6 +156,13 @@ public class KillsTable extends Table {
}
}
/**
*
* @param ids
* @param uuids
* @return
* @throws SQLException
*/
public Map<Integer, List<KillData>> getPlayerKills(Collection<Integer> ids, Map<Integer, UUID> uuids) throws SQLException {
if (ids == null || ids.isEmpty()) {
return new HashMap<>();
@ -187,6 +194,12 @@ public class KillsTable extends Table {
}
}
/**
*
* @param kills
* @param uuids
* @throws SQLException
*/
public void savePlayerKills(Map<Integer, List<KillData>> kills, Map<Integer, UUID> uuids) throws SQLException {
if (kills == null || kills.isEmpty()) {
return;

View File

@ -157,6 +157,11 @@ public class LocationsTable extends Table {
}
}
/**
*
* @param locations
* @throws SQLException
*/
public void saveAdditionalLocationsLists(Map<Integer, List<Location>> locations) throws SQLException {
if (locations == null || locations.isEmpty()) {
return;

View File

@ -173,6 +173,12 @@ public class NicknamesTable extends Table {
}
}
/**
*
* @param ids
* @return
* @throws SQLException
*/
public Map<Integer, List<String>> getNicknames(Collection<Integer> ids) throws SQLException {
if (ids == null || ids.isEmpty()) {
return new HashMap<>();
@ -218,6 +224,12 @@ public class NicknamesTable extends Table {
}
}
/**
*
* @param nicknames
* @param lastNicks
* @throws SQLException
*/
public void saveNickLists(Map<Integer, Set<String>> nicknames, Map<Integer, String> lastNicks) throws SQLException {
if (nicknames == null || nicknames.isEmpty()) {
return;

View File

@ -151,6 +151,12 @@ public class SessionsTable extends Table {
}
}
/**
*
* @param ids
* @return
* @throws SQLException
*/
public Map<Integer, List<SessionData>> getSessionData(Collection<Integer> ids) throws SQLException {
if (ids == null || ids.isEmpty()) {
return new HashMap<>();
@ -183,6 +189,11 @@ public class SessionsTable extends Table {
}
}
/**
*
* @param sessions
* @throws SQLException
*/
public void saveSessionData(Map<Integer, List<SessionData>> sessions) throws SQLException {
if (sessions == null || sessions.isEmpty()) {
return;

View File

@ -284,6 +284,12 @@ public class UsersTable extends Table {
}
}
/**
*
* @param uuid
* @return
* @throws SQLException
*/
public UserData getUserData(UUID uuid) throws SQLException {
Benchmark.start(uuid + " Get UserData");
boolean containsBukkitData = getContainsBukkitData(uuid);
@ -317,6 +323,12 @@ public class UsersTable extends Table {
return containsBukkitData;
}
/**
*
* @param uuids
* @return
* @throws SQLException
*/
public List<UserData> getUserData(Collection<UUID> uuids) throws SQLException {
Benchmark.start("Get UserData Multiple " + uuids.size());
List<UUID> containsBukkitData = getContainsBukkitData(uuids);
@ -337,6 +349,12 @@ public class UsersTable extends Table {
return datas;
}
/**
*
* @param uuids
* @return
* @throws SQLException
*/
public List<UUID> getContainsBukkitData(Collection<UUID> uuids) throws SQLException {
PreparedStatement statement = null;
ResultSet set = null;
@ -473,6 +491,11 @@ public class UsersTable extends Table {
}
}
/**
*
* @param data
* @throws SQLException
*/
public void addUserInformationToUserData(List<UserData> data) throws SQLException {
Benchmark.start("addUserInformationToUserData Multiple " + data.size());
PreparedStatement statement = null;
@ -704,6 +727,12 @@ public class UsersTable extends Table {
}
}
/**
*
* @param uuids
* @return
* @throws SQLException
*/
public Map<UUID, Integer> getUserIds(Collection<UUID> uuids) throws SQLException {
Benchmark.start("Get User IDS " + uuids.size());
PreparedStatement statement = null;
@ -728,6 +757,11 @@ public class UsersTable extends Table {
}
}
/**
*
* @return
* @throws SQLException
*/
public Map<UUID, Integer> getAllUserIds() throws SQLException {
Benchmark.start("Get User IDS ALL");
PreparedStatement statement = null;

View File

@ -19,6 +19,11 @@ import main.java.com.djrapitops.plan.data.SessionData;
*/
public class PunchCardGraphCreator {
/**
*
* @param data
* @return
*/
public static String generateDataArray(Collection<SessionData> data) {
// Initialize dataset
List<Long> sessionStarts = getSessionStarts(data);

View File

@ -22,11 +22,21 @@ import main.java.com.djrapitops.plan.utilities.MathUtils;
*/
public class SessionLengthDistributionGraphCreator {
/**
*
* @param data
* @return
*/
public static String[] generateDataArraySessions(Collection<SessionData> data) {
List<Long> lengths = AnalysisUtils.transformSessionDataToLengths(data);
return generateDataArray(lengths);
}
/**
*
* @param lengths
* @return
*/
public static String[] generateDataArray(Collection<Long> lengths) {
Map<Long, Integer> values = getValues(lengths);
Map<Long, Integer> scaled = scale(values);

View File

@ -258,16 +258,9 @@ public class Analysis {
Benchmark.stop("Analysis Activity Visualization");
}
// TODO Refactor
private void analyzeAverageAge(List<Integer> ages, AnalysisData data) {
int totalAge = 0;
for (int age : ages) {
totalAge += age;
}
double averageAge;
if (!ages.isEmpty()) {
averageAge = totalAge * 1.0 / ages.size();
} else {
double averageAge = MathUtils.averageInt(ages.stream());
if (averageAge == 0) {
averageAge = -1;
}
data.setAverageAge(averageAge);

View File

@ -30,6 +30,14 @@ public class AnalysisUtils {
return isActive(MiscUtils.getTime(), lastPlayed, playTime, loginTimes);
}
/**
*
* @param now
* @param lastPlayed
* @param playTime
* @param loginTimes
* @return
*/
public static boolean isActive(long now, long lastPlayed, long playTime, int loginTimes) {
int timeToActive = Settings.ANALYSIS_MINUTES_FOR_ACTIVE.getNumber();
if (timeToActive < 0) {
@ -162,6 +170,13 @@ public class AnalysisUtils {
}
}
/**
*
* @param analysisType
* @param source
* @param uuids
* @return
*/
public static String getBooleanPercentage(AnalysisType analysisType, PluginData source, List<UUID> uuids) {
if (analysisType == AnalysisType.BOOLEAN_PERCENTAGE) {
try {
@ -177,6 +192,13 @@ public class AnalysisUtils {
return source.parseContainer("Err ", "Wrong Analysistype specified: " + analysisType.name());
}
/**
*
* @param analysisType
* @param source
* @param uuids
* @return
*/
public static String getBooleanTotal(AnalysisType analysisType, PluginData source, List<UUID> uuids) {
if (analysisType == AnalysisType.BOOLEAN_TOTAL) {
try {

View File

@ -12,11 +12,20 @@ public class Benchmark {
private static Map<String, Long> starts = new HashMap<>();
/**
*
* @param source
*/
public static void start(String source) {
starts.put(source, System.nanoTime());
Log.debug(source);
}
/**
*
* @param source
* @return
*/
public static long stop(String source) {
Long s = starts.get(source);
if (s != null) {

View File

@ -11,14 +11,30 @@ import org.bukkit.Location;
*/
public class FormatUtils {
/**
*
* @param ms
* @return
*/
public static String formatTimeAmount(long ms) {
return formatMilliseconds(ms);
}
/**
*
* @param before
* @param after
* @return
*/
public static String formatTimeAmountDifference(long before, long after) {
return formatMilliseconds(Math.abs(after - before));
}
/**
*
* @param epochMs
* @return
*/
public static String formatTimeStamp(long epochMs) {
Date sfd = new Date(epochMs);
return ("" + sfd).substring(4, 19);

View File

@ -145,6 +145,11 @@ public class HtmlUtils {
return html.toString();
}
/**
*
* @param string
* @return
*/
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,

View File

@ -11,6 +11,11 @@ import java.util.stream.Stream;
*/
public class MathUtils {
/**
*
* @param values
* @return
*/
public static double averageInt(Stream<Integer> values) {
OptionalDouble average = values.mapToInt(i -> i).average();
if (average.isPresent()) {
@ -20,10 +25,20 @@ public class MathUtils {
}
}
/**
*
* @param values
* @return
*/
public static long averageLong(Collection<Long> values) {
return averageLong(values.stream());
}
/**
*
* @param values
* @return
*/
public static long averageLong(Stream<Long> values) {
OptionalDouble average = values.mapToLong(i -> i).average();
if (average.isPresent()) {
@ -33,6 +48,11 @@ public class MathUtils {
}
}
/**
*
* @param values
* @return
*/
public static double averageDouble(Stream<Double> values) {
OptionalDouble average = values.mapToDouble(i -> i).average();
if (average.isPresent()) {
@ -42,32 +62,63 @@ public class MathUtils {
}
}
/**
*
* @param total
* @param size
* @return
*/
public static double average(int total, int size) {
return 1.0 * total / size;
}
/**
*
* @param values
* @return
*/
public static long countTrueBoolean(Stream<Boolean> values) {
return values.filter(i -> i).count();
}
/**
*
* @param values
* @return
*/
public static int sumInt(Stream<Serializable> values) {
return values
.mapToInt(value -> (Integer) value)
.sum();
}
/**
*
* @param values
* @return
*/
public static long sumLong(Stream<Serializable> values) {
return values
.mapToLong(value -> (Long) value)
.sum();
}
/**
*
* @param values
* @return
*/
public static double sumDouble(Stream<Serializable> values) {
return values
.mapToDouble(value -> (Double) value)
.sum();
}
/**
*
* @param values
* @return
*/
public static int getBiggest(Collection<Integer> values) {
int biggest = 1;
for (Integer value : values) {
@ -77,6 +128,12 @@ public class MathUtils {
}
return biggest;
}
/**
*
* @param values
* @return
*/
public static long getBiggestLong(Collection<Long> values) {
long biggest = 1;
for (Long value : values) {

View File

@ -4,13 +4,10 @@ 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.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.stream.Collectors;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.Permissions;
import main.java.com.djrapitops.plan.Phrase;
@ -21,13 +18,20 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
* Utility method class containing various static methods.
*
* @author Rsl1122
* @since 2.0.0
*/
public class MiscUtils {
/**
* Used to get the current time as milliseconds.
*
* @return Epoch ms.
*/
public static long getTime() {
return new Date().getTime();
return System.currentTimeMillis();
}
/**
@ -40,7 +44,11 @@ public class MiscUtils {
Plan plugin = Plan.getInstance();
String cVersion = plugin.getDescription().getVersion();
String gitVersion = getGitVersion();
return checkVersion(cVersion, gitVersion);
if (checkVersion(cVersion, gitVersion)) {
return Phrase.VERSION_NEW_AVAILABLE.parse(gitVersion);
} else {
return Phrase.VERSION_LATEST + "";
}
} catch (IOException | NumberFormatException e) {
Log.error(Phrase.VERSION_CHECK_ERROR + "");
}
@ -68,14 +76,10 @@ public class MiscUtils {
* @return
* @throws NumberFormatException
*/
public static String checkVersion(String currentVersion, String gitVersion) throws NumberFormatException {
public static boolean checkVersion(String currentVersion, String gitVersion) throws NumberFormatException {
int newestVersionNumber = FormatUtils.parseVersionNumber(gitVersion);
int currentVersionNumber = FormatUtils.parseVersionNumber(currentVersion);
if (newestVersionNumber > currentVersionNumber) {
return Phrase.VERSION_NEW_AVAILABLE.parse(gitVersion);
} else {
return Phrase.VERSION_LATEST + "";
}
return newestVersionNumber > currentVersionNumber;
}
/**
@ -93,6 +97,7 @@ public class MiscUtils {
*
* @param args Arguments of a command, must not be empty if console sender.
* @param sender Command sender
* @param perm
* @return The name of the player (first argument or sender)
*/
public static String getPlayerName(String[] args, CommandSender sender, Permissions perm) {

View File

@ -33,6 +33,7 @@ public class PlaceholderUtils {
public static Map<String, String> getAnalysisReplaceRules(AnalysisData data) {
Benchmark.start("Replace Placeholders Anaysis");
HashMap<String, String> replaceMap = new HashMap<>();
replaceMap.put("%currenttime%", MiscUtils.getTime()+"");
replaceMap.put("%gm0%", (int) (data.getGm0Perc() * 100) + "%");
replaceMap.put("%gm1%", (int) (data.getGm1Perc() * 100) + "%");
replaceMap.put("%gm2%", (int) (data.getGm2Perc() * 100) + "%");
@ -128,6 +129,7 @@ public class PlaceholderUtils {
replaceMap.put("#" + defaultCols[i], "#" + colors[i]);
}
}
replaceMap.put("%refreshlong%", data.getRefreshDate()+"");
replaceMap.put("%servername%", Settings.SERVER_NAME.toString());
Benchmark.stop("Replace Placeholders Anaysis");
return replaceMap;
@ -142,6 +144,7 @@ public class PlaceholderUtils {
*/
public static Map<String, String> getInspectReplaceRules(UserData data) throws FileNotFoundException {
Benchmark.start("Replace Placeholders Inspect");
HashMap<String, String> replaceMap = new HashMap<>();
boolean showIPandUUID = Settings.SECURITY_IP_UUID.isTrue();
UUID uuid = data.getUuid();
@ -222,6 +225,8 @@ public class PlaceholderUtils {
replaceMap.put("#" + defaultCols[i], "#" + colors[i]);
}
}
replaceMap.put("%refreshlong%", plugin.getInspectCache().getCacheTime(uuid)+"");
replaceMap.put("%currenttime%", MiscUtils.getTime()+"");
replaceMap.put("%servername%", Settings.SERVER_NAME.toString());
String pluginsTabHtml = plugin.getHookHandler().getPluginsTabLayoutForInspect();
Map<String, String> additionalReplaceRules = plugin.getHookHandler().getAdditionalInspectReplaceRules(uuid);

View File

@ -279,7 +279,7 @@ header p {
}
</style>
</head>
<body>
<body onload="countUpTimer()">
<header>
<div class="header-content">
<img src="http://puu.sh/tJZUb/c2e0ab220f.png" alt="Player Analytics | Analysis">
@ -290,7 +290,7 @@ header p {
<div id="content" class="content">
<div id="sidenav" class="sidenav">
<p>Last Refresh: <br>%refresh% ago</p>
<p>Last Refresh: <br><span id="divTime">%refresh%</span> ago</p>
<a href="javascript:void(0)" class="nav-button">
<i class="fa fa-info-circle" aria-hidden="true"></i> Information
</a>
@ -823,6 +823,7 @@ for (i=0; i < navButtons.length; i++) {
}
x.style.opacity = "1";
openFunc(slideIndex)();
countUpTimer();
function openFunc(i) {
return function() {
@ -849,6 +850,42 @@ function openFunc(i) {
x.style.transform = "translate3d("+value+"%,0px,0)";
};
}
var serverTime = new Date(%currenttime%);
var now = new Date();
var timediff = serverTime.getTime()-now.getTime();
function countUpTimer() {
var now = new Date();
var begin = new Date(%refreshlong%-timediff);
var out = "";
var seconds = now.getTime() - begin.getTime();
seconds = Math.floor(seconds / 1000);
var dd = Math.floor(seconds / 86400);
seconds -= (dd * 86400);
var dh = Math.floor(seconds / 3600);
seconds -= (dh * 3600);
var dm = Math.floor(seconds / 60);
seconds -= (dm * 60);
seconds = Math.floor(seconds);
if (dd != 0) {
out += dd.toString() + "d ";
}
if (dh != 0) {
out += dh.toString() + "h ";
}
if (dm != 0) {
out += dm.toString() + "m ";
}
out += seconds.toString() + "s ";
document.getElementById('divTime').innerHTML = out;
setTimeout('countUpTimer()', 1000);
}
</script>
<script src="http://www.kryogenix.org/code/browser/sorttable/sorttable.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.bundle.js"></script>

View File

@ -326,7 +326,7 @@ table.sortable th:not(.sorttable_sorted):not(.sorttable_sorted_reverse):not(.sor
</header>
<div id="content" class="content">
<div id="sidenav" class="sidenav">
<p>Has Connected from ips:<br>%ips%</p>
<p>Last Refresh: <br><span id="divTime">%refresh%</span> ago</p>
<a href="javascript:void(0)" class="nav-button">
<i class="fa fa-info-circle" aria-hidden="true"></i> Information
</a>
@ -370,7 +370,8 @@ table.sortable th:not(.sorttable_sorted):not(.sorttable_sorted_reverse):not(.sor
<br/>
<i class="fa fa-globe" aria-hidden="true"></i> Geolocation: %geoloc%<br/>
<i class="fa fa-play" aria-hidden="true"></i> Age: %age% | <i class="fa fa-male" aria-hidden="true"></i><i class="fa fa-female" aria-hidden="true"></i> Gender: %gender%<br/>
<i class="fa fa-tag" aria-hidden="true"></i> UUID: %uuid%</p>
<i class="fa fa-tag" aria-hidden="true"></i> UUID: %uuid%<br/>
<i class="fa fa-globe" aria-hidden="true"></i> Has Connected from ips: %ips%</p>
</div>
<div class="about box column">
<div class="headerbox">
@ -574,6 +575,7 @@ for (i=0; i < navButtons.length; i++) {
}
x.style.opacity = "1";
openFunc(slideIndex)();
countUpTimer();
function openFunc(i) {
return function() {
@ -600,6 +602,43 @@ function openFunc(i) {
x.style.transform = "translate3d("+value+"%,0px,0)";
};
}
var serverTime = new Date(%currenttime%);
var now = new Date();
var timediff = serverTime.getTime()-now.getTime();
function countUpTimer() {
var now = new Date();
var begin = new Date(%refreshlong%-timediff);
var out = "";
var seconds = now.getTime() - begin.getTime();
seconds = Math.floor(seconds / 1000);
var dd = Math.floor(seconds / 86400);
seconds -= (dd * 86400);
var dh = Math.floor(seconds / 3600);
seconds -= (dh * 3600);
var dm = Math.floor(seconds / 60);
seconds -= (dm * 60);
seconds = Math.floor(seconds);
if (dd != 0) {
out += dd.toString() + "d ";
}
if (dh != 0) {
out += dh.toString() + "h ";
}
if (dm != 0) {
out += dm.toString() + "m ";
}
out += seconds.toString() + "s ";
document.getElementById('divTime').innerHTML = out;
setTimeout('countUpTimer()', 1000);
}
</script>
<script src="http://www.kryogenix.org/code/browser/sorttable/sorttable.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.bundle.js"></script>

View File

@ -18,14 +18,23 @@ import test.java.utils.MockUtils;
*/
public class PermissionsTest {
/**
*
*/
public PermissionsTest() {
}
/**
*
*/
@Test
public void testUserHasThisPermission() {
assertTrue(Permissions.INSPECT_OTHER.userHasThisPermission(MockUtils.mockPlayer()));
}
/**
*
*/
@Test
public void testGetPermission() {
assertEquals("plan.inspect.other", Permissions.INSPECT_OTHER.getPermission());

View File

@ -64,6 +64,9 @@ public class SettingsTest {
assertEquals(8804, Settings.WEBSERVER_PORT.getNumber());
}
/**
*
*/
@Test
public void testGetStringList() {
List<String> exp = new ArrayList<>();

View File

@ -15,14 +15,23 @@ import static org.junit.Assert.*;
*/
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());

View File

@ -23,6 +23,9 @@ import test.java.utils.TestInit;
@PrepareForTest(JavaPlugin.class)
public class PlayerActivityGraphCreatorTest {
/**
*
*/
@Before
public void setUp() {
TestInit t = new TestInit();

View File

@ -26,6 +26,9 @@ import test.java.utils.*;
@PrepareForTest(JavaPlugin.class)
public class FormatUtilsTest {
/**
*
*/
@Before
public void setUp() {
TestInit t = new TestInit();

View File

@ -19,9 +19,15 @@ import org.junit.Test;
*/
public class MathUtilsTest {
/**
*
*/
public MathUtilsTest() {
}
/**
*
*/
@Test
public void testAverageInt() {
List<Integer> l = new ArrayList<>();
@ -34,6 +40,9 @@ public class MathUtilsTest {
assertTrue(exp == result);
}
/**
*
*/
@Test
public void testAverageIntEmpty() {
List<Integer> l = new ArrayList<>();
@ -42,6 +51,9 @@ public class MathUtilsTest {
assertTrue(result + "/" + exp, exp == result);
}
/**
*
*/
@Test
public void testAverageLong_Collection() {
List<Long> l = new ArrayList<>();
@ -54,6 +66,9 @@ public class MathUtilsTest {
assertTrue(result + "/" + exp, exp == result);
}
/**
*
*/
@Test
public void testAverageDouble() {
List<Double> l = new ArrayList<>();
@ -67,6 +82,9 @@ public class MathUtilsTest {
}
/**
*
*/
@Test
public void testAverage() {
double exp = 10;
@ -74,6 +92,9 @@ public class MathUtilsTest {
assertTrue(result + "/" + exp, exp == result);
}
/**
*
*/
@Test
public void testCountTrueBoolean() {
List<Boolean> l = new ArrayList<>();
@ -88,6 +109,9 @@ public class MathUtilsTest {
assertTrue(result + "/" + exp, exp == result);
}
/**
*
*/
@Test
public void testSumInt() {
List<Serializable> l = new ArrayList<>();
@ -100,6 +124,9 @@ public class MathUtilsTest {
assertTrue(result + "/" + exp, exp == result);
}
/**
*
*/
@Test
public void testSumLong() {
List<Serializable> l = new ArrayList<>();
@ -112,6 +139,9 @@ public class MathUtilsTest {
assertTrue(result + "/" + exp, exp == result);
}
/**
*
*/
@Test
public void testSumDouble() {
List<Serializable> l = new ArrayList<>();

View File

@ -6,7 +6,6 @@
package test.java.main.java.com.djrapitops.plan.utilities;
import java.util.Set;
import main.java.com.djrapitops.plan.Phrase;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
@ -59,9 +58,7 @@ public class MiscUtilsTest {
@Test
public void testCheckVersion() {
String versionG = "2.10.9";
String result = MiscUtils.checkVersion("2.0.0", versionG);
String exp = Phrase.VERSION_NEW_AVAILABLE.parse(versionG);
assertEquals(exp, result);
assertTrue(MiscUtils.checkVersion("2.0.0", versionG));
}
/**
@ -69,9 +66,12 @@ public class MiscUtilsTest {
*/
@Test
public void testCheckVersion2() {
String result = MiscUtils.checkVersion("3.0.0", "2.10.9");
String exp = Phrase.VERSION_LATEST + "";
assertEquals(exp, result);
assertTrue(!MiscUtils.checkVersion("3.0.0", "2.10.9"));
}
@Test
public void testCheckVersion5() {
assertTrue(MiscUtils.checkVersion("2.10.9", "3.0.0"));
}
/**
@ -79,9 +79,7 @@ public class MiscUtilsTest {
*/
@Test
public void testCheckVersion3() {
String result = MiscUtils.checkVersion("2.11.0", "2.10.9");
String exp = Phrase.VERSION_LATEST + "";
assertEquals(exp, result);
assertTrue(!MiscUtils.checkVersion("2.11.0", "2.10.9"));
}
/**
@ -89,9 +87,7 @@ public class MiscUtilsTest {
*/
@Test
public void testCheckVersion4() {
String result = MiscUtils.checkVersion("2.11.0", "2.11.0");
String exp = Phrase.VERSION_LATEST + "";
assertEquals(exp, result);
assertTrue(!MiscUtils.checkVersion("2.11.0", "2.11.0"));
}
/**
@ -181,7 +177,7 @@ public class MiscUtilsTest {
boolean equalToExp1 = r.getName().equals(exp1.getName());
boolean equalToExp2 = r.getName().equals(exp2.getName());
if (!(equalToExp1 || equalToExp2)) {
fail("Unknown result!: "+r.getName());
fail("Unknown result!: " + r.getName());
}
}
}
@ -197,7 +193,7 @@ public class MiscUtilsTest {
assertEquals(1, result.size());
for (OfflinePlayer r : result) {
if (!r.getName().equals(exp2.getName())) {
fail("Unknown result!: "+r.getName());
fail("Unknown result!: " + r.getName());
}
}
}