Bugfixes & Some javadoc

- Fixed all issues with saving, data is now saved accurately.
- Ready for pull request
This commit is contained in:
Rsl1122 2017-04-28 15:05:47 +03:00
parent 58ca5f9d2c
commit d6a6d5e20b
91 changed files with 2088 additions and 214 deletions

View File

@ -1,15 +1,11 @@
/*
* 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;
import org.bukkit.command.CommandSender;
/**
* Permissions class is used easily check every permission node.
*
* @author Risto
* @author Rsl1122
*/
public enum Permissions {
@ -32,10 +28,22 @@ public enum Permissions {
this.permission = permission;
}
/**
* Checks if the CommandSender has the permission.
*
* @param p entity sending the command (console/player/other)
* @return CommandSender#hasPermission
* @see CommandSender
*/
public boolean userHasThisPermission(CommandSender p) {
return p.hasPermission(permission);
}
/**
* Returns the string of the permission node in plugin.yml
*
* @return line of the permission eg. plan.inspect
*/
public String getPermission() {
return permission;
}

View File

@ -9,6 +9,9 @@ import org.bukkit.ChatColor;
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
/**
* Phrase contains every message that is used in placeholders or commands. The
* contents for each message can be changed. Every message can contain a String
* or ChatColor.
*
* @author Rsl1122
*/
@ -173,10 +176,21 @@ public enum Phrase {
return text;
}
/**
* Alternative for toString.
*
* @return toString()
*/
public String parse() {
return this.toString();
}
/**
* Replaces all REPLACE{x} strings with the given parameters.
*
* @param p Strings to replace REPLACE{x}:s with
* @return String with placeholders replaced.
*/
public String parse(String... p) {
String returnValue = this.toString();
for (int i = 0; i < p.length; i++) {
@ -192,10 +206,18 @@ public enum Phrase {
return color;
}
/**
*
* @param text
*/
public void setText(String text) {
this.text = text;
}
/**
*
* @param colorCode
*/
public void setColor(char colorCode) {
this.color = ChatColor.getByChar(colorCode);
}

View File

@ -1,6 +1,6 @@
/*
* Player Analytics Bukkit plugin for monitoring server activity.
* Copyright (C) 2016 Risto Lahtela / Rsl1122
* Copyright (C) 2017 Risto Lahtela / Rsl1122
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Plan License. (licence.yml)
@ -52,6 +52,8 @@ import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
/**
* Javaplugin class that contains methods for starting the plugin, logging to
* the Bukkit console & various get methods.
*
* @author Rsl1122
*/
@ -132,7 +134,7 @@ public class Plan extends JavaPlugin {
}
hookHandler = new HookHandler(this);
log(Phrase.ENABLED + "");
}
@ -147,7 +149,7 @@ public class Plan extends JavaPlugin {
uiServer.stop();
}
Bukkit.getScheduler().cancelTasks(this);
if (handler != null) {
if (handler != null) {
log(Phrase.CACHE_SAVE + "");
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
scheduler.execute(() -> {
@ -162,7 +164,7 @@ public class Plan extends JavaPlugin {
/**
* Logs the message to the console.
*
* @param message
* @param message "Message" will show up as [INFO][Plan]: Message
*/
public void log(String message) {
getLogger().info(message);
@ -171,7 +173,7 @@ public class Plan extends JavaPlugin {
/**
* Logs an error message to the console.
*
* @param message
* @param message "Message" will show up as [ERROR][Plan]: Message
*/
public void logError(String message) {
getLogger().severe(message);
@ -207,7 +209,7 @@ public class Plan extends JavaPlugin {
/**
* Logs a message to the Errors.txt with a timestamp.
*
* @param message Message to log to Errors.txt
* @param message Message to log to Errors.txt [timestamp] Message
*/
public void toLog(String message) {
File folder = getDataFolder();
@ -231,6 +233,8 @@ public class Plan extends JavaPlugin {
}
/**
* Used to access the API.
*
* @return Plan API
*/
public API getAPI() {
@ -307,13 +311,17 @@ public class Plan extends JavaPlugin {
}
/**
* @return Currnet instance of the AnalysisCacheHandler
* Used to access AnalysisCache.
*
* @return Current instance of the AnalysisCacheHandler
*/
public AnalysisCacheHandler getAnalysisCache() {
return analysisCache;
}
/**
* Used to access InspectCache.
*
* @return Current instance of the InspectCacheHandler
*/
public InspectCacheHandler getInspectCache() {
@ -321,13 +329,17 @@ public class Plan extends JavaPlugin {
}
/**
* Used to access Cache.
*
* @return Current instance of the DataCacheHandler
*/
public DataCacheHandler getHandler() {
return handler;
}
/**
* Used to access active Database.
*
* @return the Current Database
*/
public Database getDB() {
@ -335,6 +347,8 @@ public class Plan extends JavaPlugin {
}
/**
* Used to access Webserver.
*
* @return the Webserver
*/
public WebSocketServer getUiServer() {
@ -342,6 +356,8 @@ public class Plan extends JavaPlugin {
}
/**
* Used to access HookHandler.
*
* @return HookHandler that manages Hooks to other plugins.
*/
public HookHandler getHookHandler() {
@ -349,13 +365,19 @@ public class Plan extends JavaPlugin {
}
/**
* @return Set containing the SqLite & MySQL classes.
* Used to get all possible database objects.
*
* #init() might need to be called in order for the object to function.
*
* @return Set containing the SqLite & MySQL objects.
*/
public HashSet<Database> getDatabases() {
return databases;
}
/**
* Used to get the ID of the BootAnalysisTask, so that it can be disabled.
*
* @return ID of the bootAnalysisTask
*/
public int getBootAnalysisTaskID() {

View File

@ -3,6 +3,8 @@ package main.java.com.djrapitops.plan;
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
/**
* This enum contains all of the config settings used by the plugin for easier
* access.
*
* @author Rsl1122
*/
@ -60,18 +62,27 @@ public enum Settings {
}
/**
* @return Boolean value of the config setting
* If the settings is a boolean, this method should be used.
*
* @return Boolean value of the config setting, false if not boolean.
*/
public boolean isTrue() {
return getPlugin(Plan.class).getConfig().getBoolean(configPath);
}
/**
* If the settings is a String, this method should be used.
*
* @return String value of the config setting.
*/
@Override
public String toString() {
return getPlugin(Plan.class).getConfig().getString(configPath);
}
/**
* If the settings is a number, this method should be used.
*
* @return Integer value of the config setting
*/
public int getNumber() {
@ -79,6 +90,9 @@ public enum Settings {
}
/**
* Used to get the String path of a the config setting eg.
* Settings.WebServer.Enabled
*
* @return Path of the config setting.
*/
public String getPath() {

View File

@ -1,10 +1,16 @@
package main.java.com.djrapitops.plan.api;
/**
* This class contains Genders used by the plugin.
*
* @author Rsl1122
*/
public enum Gender {
MALE, FEMALE, OTHER, UNKNOWN;
/**
* Gets the Enum that corresponds to the name.
*
* @param name name of the gender enum.
* @return Gender Enum
*/

View File

@ -1,5 +1,13 @@
package main.java.com.djrapitops.plan.command;
/**
* This enum contains different types of commands.
*
* CONSOLE can be used always, PLAYER can only be used as a player,
* CONSOLE_WITH_ARGUMENTS can be used always, except with arguments on console.
*
* @author Rsl1122
*/
public enum CommandType {
CONSOLE,
PLAYER,

View File

@ -12,6 +12,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
* CommandExecutor for the /plan command, and all subcommands.
*
* @author Rsl1122
*/
@ -20,7 +21,7 @@ public class PlanCommand implements CommandExecutor {
private final List<SubCommand> commands;
/**
* Class Constructor.
* CommandExecutor class Constructor.
*
* Initializes Subcommands
*
@ -28,7 +29,6 @@ public class PlanCommand implements CommandExecutor {
*/
public PlanCommand(Plan plugin) {
commands = new ArrayList<>();
commands.add(new HelpCommand(plugin, this));
commands.add(new InspectCommand(plugin));
commands.add(new AnalyzeCommand(plugin));
@ -39,6 +39,8 @@ public class PlanCommand implements CommandExecutor {
}
/**
* Used to get the list of all subcommands.
*
* @return Initialized SubCommands
*/
public List<SubCommand> getCommands() {
@ -76,11 +78,11 @@ public class PlanCommand implements CommandExecutor {
* Checks if Sender has rights to run the command and executes matching
* subcommand.
*
* @param sender
* @param cmd
* @param commandLabel
* @param args
* @return true in all cases.
* @param sender source of the command.
* @param cmd command.
* @param commandLabel
* @param args arguments of the command
* @return true
*/
@Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {

View File

@ -5,6 +5,8 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
/**
* Abstract subcommand class that stores all the required information of a
* command.
*
* @author Rsl1122
*/
@ -18,6 +20,7 @@ public abstract class SubCommand {
/**
* Class constructor, called with super(...) in subcommands.
*
* @param name Name(s) (aliases) of the command
* @param permission Required permission
* @param usage Usage information
@ -33,6 +36,8 @@ public abstract class SubCommand {
}
/**
* Used to get a string format of required arguments.
*
* @return Additional possible arguments the command requires
*/
public String getArguments() {
@ -40,6 +45,8 @@ public abstract class SubCommand {
}
/**
* Used to get the first alias.
*
* @return First alias of the command
*/
public String getFirstName() {
@ -47,13 +54,17 @@ public abstract class SubCommand {
}
/**
* @return All aliases
* Used to get all aliases.
*
* @return All aliases separated with ','
*/
public String getName() {
return name;
}
/**
* Used to get the permission required by the command.
*
* @return Required permission
*/
public Permissions getPermission() {
@ -61,6 +72,8 @@ public abstract class SubCommand {
}
/**
* Used to get the info about usage of the command.
*
* @return Usage information
*/
public String getUsage() {
@ -68,6 +81,8 @@ public abstract class SubCommand {
}
/**
* Used to get the command type.
*
* @return CommandType Enum.
*/
public CommandType getCommandType() {
@ -76,11 +91,12 @@ public abstract class SubCommand {
/**
* The Command Execution method.
*
* @param sender
* @param cmd
* @param commandLabel
* @param args
* @return
* @return Was the execution successful?
*/
public abstract boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args);
}

View File

@ -18,6 +18,7 @@ import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
/**
* This subcommand is used to run the analysis and access the /server link.
*
* @author Rsl1122
*/
@ -41,7 +42,7 @@ public class AnalyzeCommand extends SubCommand {
* Subcommand analyze.
*
* Updates AnalysisCache if last refresh was over 60 seconds ago and sends
* player the link that views cache.
* player the link that views cache with a delayed timer task.
*
* @param sender
* @param cmd

View File

@ -12,6 +12,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
* This subcommand is used to view the subcommands.
*
* @author Rsl1122
*/
@ -34,33 +35,20 @@ public class HelpCommand extends SubCommand {
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
public boolean onCommand(CommandSender sender, Command comd, String commandLabel, String[] args) {
boolean isConsole = !(sender instanceof Player);
ChatColor oColor = Phrase.COLOR_MAIN.color();
ChatColor tColor = Phrase.COLOR_SEC.color();
// Header
sender.sendMessage(Phrase.CMD_HELP_HEADER + "");
// Help results
for (SubCommand command : this.command.getCommands()) {
if (command.getName().equalsIgnoreCase(getName())) {
continue;
}
if (!command.getPermission().userHasThisPermission(sender)) {
continue;
}
if (!(sender instanceof Player) && command.getCommandType() == CommandType.PLAYER) {
continue;
}
sender.sendMessage(tColor + " " + Phrase.BALL.toString() + oColor
+ " /plan " + command.getFirstName() + " " + command.getArguments() + tColor + " - " + command.getUsage());
}
// Footer
this.command.getCommands().stream()
.filter(cmd -> !cmd.getName().equalsIgnoreCase(getName()))
.filter(cmd -> cmd.getPermission().userHasThisPermission(sender))
.filter(cmd -> !(isConsole && cmd.getCommandType() == CommandType.PLAYER))
.map(cmd -> tColor + " " + Phrase.BALL.toString() + oColor + " /plan " + cmd.getFirstName() + " " + cmd.getArguments() + tColor + " - " + cmd.getUsage())
.forEach(msg -> sender.sendMessage(msg));
sender.sendMessage(Phrase.CMD_FOOTER + "");
return true;
}
}

View File

@ -11,7 +11,8 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
/**
*
* This subcommand is used to view the version & the database type in use.
*
* @author Rsl1122
*/
public class InfoCommand extends SubCommand {

View File

@ -20,6 +20,7 @@ import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
/**
* This command is used to cache UserData to InspectCache and display the link.
*
* @author Rsl1122
*/
@ -43,11 +44,9 @@ public class InspectCommand extends SubCommand {
/**
* Subcommand inspect.
*
* Adds player's data from DataCache/DB to the InspectCache for amount of
* time specified in the config, and clears the data from Cache with a timer
* task.
* Adds player's data from DataCache/DB to the InspectCache
*
* @param sender
* @param sender args is empty, can not be Console.
* @param cmd
* @param commandLabel
* @param args Player's name or nothing - if empty sender's name is used.

View File

@ -11,7 +11,6 @@ import main.java.com.djrapitops.plan.Phrase;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.command.CommandType;
import main.java.com.djrapitops.plan.command.SubCommand;
import main.java.com.djrapitops.plan.data.cache.DataCacheHandler;
import main.java.com.djrapitops.plan.data.importing.Importer;
import main.java.com.djrapitops.plan.data.importing.OnTimeImporter;
import main.java.com.djrapitops.plan.utilities.ManageUtils;

View File

@ -10,14 +10,11 @@ import main.java.com.djrapitops.plan.command.CommandType;
import main.java.com.djrapitops.plan.command.SubCommand;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
import main.java.com.djrapitops.plan.utilities.UUIDFetcher;
import static org.bukkit.Bukkit.getOfflinePlayer;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.scheduler.BukkitRunnable;
import static org.bukkit.Bukkit.getOfflinePlayer;
import static org.bukkit.Bukkit.getOfflinePlayer;
import static org.bukkit.Bukkit.getOfflinePlayer;
import static org.bukkit.Bukkit.getOfflinePlayer;
/**
*

View File

@ -182,26 +182,50 @@ public class AnalysisData {
return true;
}
/**
*
* @return
*/
public String getGeomapCountries() {
return geomapCountries;
}
/**
*
* @param geomapCountries
*/
public void setGeomapCountries(String geomapCountries) {
this.geomapCountries = geomapCountries;
}
/**
*
* @return
*/
public String getGeomapZ() {
return geomapZ;
}
/**
*
* @param geomapZ
*/
public void setGeomapZ(String geomapZ) {
this.geomapZ = geomapZ;
}
/**
*
* @return
*/
public String getGeomapCodes() {
return geomapCodes;
}
/**
*
* @param geomapCodes
*/
public void setGeomapCodes(String geomapCodes) {
this.geomapCodes = geomapCodes;
}
@ -644,10 +668,18 @@ public class AnalysisData {
this.sessionAverage = sessionAverage;
}
/**
*
* @return
*/
public int[] getGenderData() {
return genderData;
}
/**
*
* @param genderData
*/
public void setGenderData(int[] genderData) {
this.genderData = genderData;
}

View File

@ -63,6 +63,10 @@ public class RawAnalysisData {
genders = new int[]{0, 0, 0};
}
/**
*
* @param country
*/
public void addGeoloc(String country) {
if (geolocations.get(country) == null) {
return;
@ -70,6 +74,9 @@ public class RawAnalysisData {
geolocations.put(country, geolocations.get(country) + 1);
}
/**
*
*/
public void fillGeolocations() {
String[] countries = new String[]{"Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Anguilla", "Antigua and Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas, The", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", "Bosnia and Herzegovina", "Botswana", "Brazil", "British Virgin Islands", "Brunei", "Bulgaria", "Burkina Faso", "Burma", "Burundi", "Cabo Verde", "Cambodia", "Cameroon", "Canada", "Cayman Islands", "Central African Republic", "Chad", "Chile", "China", "Colombia", "Comoros", "Congo, Democratic Republic of the", "Congo, Republic of the", "Cook Islands", "Costa Rica", "Cote d'Ivoire", "Croatia", "Cuba", "Curacao", "Cyprus", "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Falkland Islands (Islas Malvinas)", "Faroe Islands", "Fiji", "Finland", "France", "French Polynesia", "Gabon", "Gambia, The", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada", "Guam", "Guatemala", "Guernsey", "Guinea-Bissau", "Guinea", "Guyana", "Haiti", "Honduras", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Isle of Man", "Israel", "Italy", "Jamaica", "Japan", "Jersey", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Korea, North", "Korea, South", "Kosovo", "Kuwait", "Kyrgyzstan", "Laos", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg", "Macau", "Macedonia", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Mauritania", "Mauritius", "Mexico", "Micronesia, Federated States of", "Moldova", "Monaco", "Mongolia", "Montenegro", "Morocco", "Mozambique", "Namibia", "Nepal", "Netherlands", "New Caledonia", "New Zealand", "Nicaragua", "Nigeria", "Niger", "Niue", "Northern Mariana Islands", "Norway", "Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Poland", "Portugal", "Puerto Rico", "Qatar", "Romania", "Russia", "Rwanda", "Saint Kitts and Nevis", "Saint Lucia", "Saint Martin", "Saint Pierre and Miquelon", "Saint Vincent and the Grenadines", "Samoa", "San Marino", "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia", "Seychelles", "Sierra Leone", "Singapore", "Sint Maarten", "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "South Sudan", "Spain", "Sri Lanka", "Sudan", "Suriname", "Swaziland", "Sweden", "Switzerland", "Syria", "Taiwan", "Tajikistan", "Tanzania", "Thailand", "Timor-Leste", "Togo", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United States", "Uruguay", "Uzbekistan", "Vanuatu", "Venezuela", "Vietnam", "Virgin Islands", "West Bank", "Yemen", "Zambia", "Zimbabwe"};
String[] codes = new String[]{"AFG", "ALB", "DZA", "ASM", "AND", "AGO", "AIA", "ATG", "ARG", "ARM", "ABW", "AUS", "AUT", "AZE", "BHM", "BHR", "BGD", "BRB", "BLR", "BEL", "BLZ", "BEN", "BMU", "BTN", "BOL", "BIH", "BWA", "BRA", "VGB", "BRN", "BGR", "BFA", "MMR", "BDI", "CPV", "KHM", "CMR", "CAN", "CYM", "CAF", "TCD", "CHL", "CHN", "COL", "COM", "COD", "COG", "COK", "CRI", "CIV", "HRV", "CUB", "CUW", "CYP", "CZE", "DNK", "DJI", "DMA", "DOM", "ECU", "EGY", "SLV", "GNQ", "ERI", "EST", "ETH", "FLK", "FRO", "FJI", "FIN", "FRA", "PYF", "GAB", "GMB", "GEO", "DEU", "GHA", "GIB", "GRC", "GRL", "GRD", "GUM", "GTM", "GGY", "GNB", "GIN", "GUY", "HTI", "HND", "HKG", "HUN", "ISL", "IND", "IDN", "IRN", "IRQ", "IRL", "IMN", "ISR", "ITA", "JAM", "JPN", "JEY", "JOR", "KAZ", "KEN", "KIR", "KOR", "PRK", "KSV", "KWT", "KGZ", "LAO", "LVA", "LBN", "LSO", "LBR", "LBY", "LIE", "LTU", "LUX", "MAC", "MKD", "MDG", "MWI", "MYS", "MDV", "MLI", "MLT", "MHL", "MRT", "MUS", "MEX", "FSM", "MDA", "MCO", "MNG", "MNE", "MAR", "MOZ", "NAM", "NPL", "NLD", "NCL", "NZL", "NIC", "NGA", "NER", "NIU", "MNP", "NOR", "OMN", "PAK", "PLW", "PAN", "PNG", "PRY", "PER", "PHL", "POL", "PRT", "PRI", "QAT", "ROU", "RUS", "RWA", "KNA", "LCA", "MAF", "SPM", "VCT", "WSM", "SMR", "STP", "SAU", "SEN", "SRB", "SYC", "SLE", "SGP", "SXM", "SVK", "SVN", "SLB", "SOM", "ZAF", "SSD", "ESP", "LKA", "SDN", "SUR", "SWZ", "SWE", "CHE", "SYR", "TWN", "TJK", "TZA", "THA", "TLS", "TGO", "TON", "TTO", "TUN", "TUR", "TKM", "TUV", "UGA", "UKR", "ARE", "GBR", "USA", "URY", "UZB", "VUT", "VEN", "VNM", "VGB", "WBG", "YEM", "ZMB", "ZWE"};
@ -84,10 +91,18 @@ public class RawAnalysisData {
}
}
/**
*
* @return
*/
public Map<String, Integer> getGeolocations() {
return geolocations;
}
/**
*
* @return
*/
public Map<String, String> getGeocodes() {
return geocodes;
}
@ -372,14 +387,27 @@ public class RawAnalysisData {
return registered;
}
/**
*
* @return
*/
public int[] getGenders() {
return genders;
}
/**
*
* @param gender
*/
public void setGenders(int[] gender) {
this.genders = gender;
}
/**
*
* @param i
* @param amount
*/
public void addToGender(int i, int amount) {
this.genders[i] = this.genders[i] + amount;
}

View File

@ -52,6 +52,10 @@ public class SessionData {
return sessionEnd;
}
/**
*
* @return
*/
public long getLength() {
return sessionEnd-sessionStart;
}
@ -61,7 +65,34 @@ public class SessionData {
return "s:" + sessionStart + " e:" + sessionEnd;
}
/**
*
* @return
*/
public boolean isValid() {
return sessionStart <= sessionEnd;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final SessionData other = (SessionData) obj;
if (this.sessionStart != other.sessionStart) {
return false;
}
if (this.sessionEnd != other.sessionEnd) {
return false;
}
return true;
}
}

View File

@ -52,6 +52,17 @@ public class UserData {
private SessionData currentSession;
private List<SessionData> sessions;
/**
*
* @param uuid
* @param reg
* @param loc
* @param op
* @param lastGM
* @param demData
* @param name
* @param online
*/
public UserData(UUID uuid, long reg, Location loc, boolean op, GameMode lastGM, DemographicsData demData, String name, boolean online) {
accessing = 0;
this.uuid = uuid;
@ -289,6 +300,10 @@ public class UserData {
currentSession = session;
}
/**
*
* @return
*/
public SessionData getCurrentSession() {
return currentSession;
}

View File

@ -1,9 +1,5 @@
package main.java.com.djrapitops.plan.data.cache;
import main.java.com.djrapitops.plan.data.cache.queue.DataCacheGetQueue;
import main.java.com.djrapitops.plan.data.cache.queue.DataCacheSaveQueue;
import main.java.com.djrapitops.plan.data.cache.queue.DataCacheClearQueue;
import main.java.com.djrapitops.plan.utilities.NewPlayerCreator;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
@ -15,10 +11,14 @@ import main.java.com.djrapitops.plan.Phrase;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.Settings;
import main.java.com.djrapitops.plan.data.*;
import main.java.com.djrapitops.plan.data.cache.queue.DataCacheClearQueue;
import main.java.com.djrapitops.plan.data.cache.queue.DataCacheGetQueue;
import main.java.com.djrapitops.plan.data.cache.queue.DataCacheProcessQueue;
import main.java.com.djrapitops.plan.data.cache.queue.DataCacheSaveQueue;
import main.java.com.djrapitops.plan.data.handling.info.HandlingInfo;
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.NewPlayerCreator;
import main.java.com.djrapitops.plan.utilities.comparators.HandlingInfoTimeComparator;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
@ -79,6 +79,10 @@ public class DataCacheHandler extends LocationCache {
startAsyncPeriodicSaveTask();
}
/**
*
* @return
*/
public boolean getCommandUseFromDb() {
try {
commandUse = db.getCommandUse();
@ -89,6 +93,9 @@ public class DataCacheHandler extends LocationCache {
return false;
}
/**
*
*/
public void startQueues() {
getTask = new DataCacheGetQueue(plugin);
clearTask = new DataCacheClearQueue(plugin, this);
@ -96,6 +103,11 @@ public class DataCacheHandler extends LocationCache {
saveTask = new DataCacheSaveQueue(plugin);
}
/**
*
* @throws IllegalArgumentException
* @throws IllegalStateException
*/
public void startAsyncPeriodicSaveTask() throws IllegalArgumentException, IllegalStateException {
int minutes = Settings.SAVE_CACHE_MIN.getNumber();
if (minutes <= 0) {
@ -182,6 +194,10 @@ public class DataCacheHandler extends LocationCache {
}
}
/**
*
* @param i
*/
public void addToPool(HandlingInfo i) {
processTask.addToPool(i);
}
@ -198,7 +214,6 @@ public class DataCacheHandler extends LocationCache {
Collections.sort(toProcess, new HandlingInfoTimeComparator());
processUnprocessedHandlingInfo(toProcess);
List<UserData> data = new ArrayList<>();
data.addAll(dataCache.values());
data.parallelStream()
.forEach((userData) -> {
@ -247,6 +262,7 @@ public class DataCacheHandler extends LocationCache {
data.addLocations(getLocationsForSaving(uuid));
clearLocations(uuid);
// addSession(data);
data.access();
saveTask.scheduleForSave(data);
scheludeForClear(uuid);
}
@ -266,6 +282,9 @@ public class DataCacheHandler extends LocationCache {
}
}
/**
*
*/
public void saveHandlerDataToCache() {
Bukkit.getServer().getOnlinePlayers().parallelStream().forEach((p) -> {
saveHandlerDataToCache(p);
@ -308,7 +327,7 @@ public class DataCacheHandler extends LocationCache {
* @param uuid
* @return
*/
public boolean isDataAccessed(UUID uuid) {
public boolean isDataAccessed(UUID uuid) {
UserData userData = dataCache.get(uuid);
return (userData != null && userData.isAccessed()) || saveTask.containsUUID(uuid) || processTask.containsUUID(uuid);
}
@ -330,6 +349,10 @@ public class DataCacheHandler extends LocationCache {
newPlayer(NewPlayerCreator.createNewPlayer(player));
}
/**
*
* @param data
*/
public void newPlayer(UserData data) {
saveTask.scheduleNewPlayer(data);
}
@ -379,6 +402,7 @@ public class DataCacheHandler extends LocationCache {
if (isNewPlayer) {
newPlayer(player);
}
startSession(uuid);
saveHandlerDataToCache(player);
}
this.cancel();
@ -395,6 +419,10 @@ public class DataCacheHandler extends LocationCache {
return maxPlayers;
}
/**
*
* @param command
*/
public void handleCommand(String command) {
if (!commandUse.containsKey(command)) {
commandUse.put(command, 0);

View File

@ -1,13 +1,9 @@
package main.java.com.djrapitops.plan.data.cache;
import java.util.Date;
import java.util.HashMap;
import java.util.UUID;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.Settings;
import main.java.com.djrapitops.plan.data.UserData;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
/**
*

View File

@ -24,6 +24,11 @@ public class LocationCache extends SessionCache{
locations = new HashMap<>();
}
/**
*
* @param uuid
* @param loc
*/
public void addLocation(UUID uuid, Location loc) {
if (!locations.containsKey(uuid)) {
locations.put(uuid, new ArrayList<>());
@ -31,6 +36,11 @@ public class LocationCache extends SessionCache{
locations.get(uuid).add(loc);
}
/**
*
* @param uuid
* @param locs
*/
public void addLocations(UUID uuid, Collection<Location> locs) {
if (!locations.containsKey(uuid)) {
locations.put(uuid, new ArrayList<>());
@ -38,6 +48,11 @@ public class LocationCache extends SessionCache{
locations.get(uuid).addAll(locs);
}
/**
*
* @param uuid
* @return
*/
public List<Location> getLocationsForSaving(UUID uuid) {
if (!locations.containsKey(uuid)) {
return new ArrayList<>();
@ -45,6 +60,10 @@ public class LocationCache extends SessionCache{
return locations.get(uuid);
}
/**
*
* @param uuid
*/
public void clearLocations(UUID uuid) {
locations.remove(uuid);
}

View File

@ -4,10 +4,8 @@ package main.java.com.djrapitops.plan.data.cache;
import java.util.Date;
import java.util.HashMap;
import java.util.UUID;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.data.SessionData;
import main.java.com.djrapitops.plan.data.UserData;
import main.java.com.djrapitops.plan.data.cache.DataCacheHandler;
/**
*
@ -33,6 +31,10 @@ public class SessionCache {
activeSessions.put(uuid, session);
}
/**
*
* @param uuid
*/
public void endSession(UUID uuid) {
SessionData currentSession = activeSessions.get(uuid);
if (currentSession != null) {
@ -41,6 +43,11 @@ public class SessionCache {
}
}
/**
*
* @param uuid
* @return
*/
public SessionData getSession(UUID uuid) {
return activeSessions.get(uuid);
}
@ -52,12 +59,16 @@ public class SessionCache {
public void addSession(UserData data) {
UUID uuid = data.getUuid();
SessionData currentSession = activeSessions.get(uuid);
if (currentSession != null && currentSession.isValid()) {
if (currentSession != null && currentSession.isValid() && !data.getSessions().contains(currentSession)) {
data.addSession(currentSession);
activeSessions.remove(uuid);
}
}
/**
*
* @return
*/
public HashMap<UUID, SessionData> getActiveSessions() {
return activeSessions;
}

View File

@ -8,8 +8,8 @@ import main.java.com.djrapitops.plan.Phrase;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.Settings;
import main.java.com.djrapitops.plan.data.cache.DataCacheHandler;
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
import static org.bukkit.Bukkit.getOfflinePlayer;
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
/**
*

View File

@ -7,12 +7,10 @@ import java.util.UUID;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.stream.Collectors;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.data.UserData;
import main.java.com.djrapitops.plan.data.cache.DBCallableProcessor;
import main.java.com.djrapitops.plan.data.cache.DataCacheHandler;
import main.java.com.djrapitops.plan.data.handling.info.HandlingInfo;
import main.java.com.djrapitops.plan.database.Database;
/**
*
@ -59,6 +57,11 @@ public class DataCacheProcessQueue {
}
}
/**
*
* @param uuid
* @return
*/
public boolean containsUUID(UUID uuid) {
return new ArrayList<>(q).stream().map(d -> d.getUuid()).collect(Collectors.toList()).contains(uuid);
}

View File

@ -69,6 +69,11 @@ public class DataCacheSaveQueue {
}
}
/**
*
* @param uuid
* @return
*/
public boolean containsUUID(UUID uuid) {
return new ArrayList<>(q).stream().map(d -> d.getUuid()).collect(Collectors.toList()).contains(uuid);
}
@ -105,7 +110,7 @@ class SaveConsumer implements Runnable {
void consume(UserData data) {
try {
data.access();
db.saveUserData(data.getUuid(), data);
data.stopAccessing();
} catch (SQLException ex) {

View File

@ -13,14 +13,26 @@ import main.java.com.djrapitops.plan.data.UserData;
/**
*
* @author Risto
* @author Rsl1122
*/
public class ChatHandling {
/**
*
* @param data
* @param nickname
* @param msg
*/
public static void processChatInfo(UserData data, String nickname, String msg) {
data.addNickname(nickname);
updateDemographicInformation(msg, data);
}
/**
*
* @param msg
* @param data
*/
public static void updateDemographicInformation(String msg, UserData data) {
List<String> triggers = Arrays.asList(Settings.DEM_TRIGGERS.toString().split(", "));
List<String> female = Arrays.asList(Settings.DEM_FEMALE.toString().split(", "));

View File

@ -11,9 +11,16 @@ import org.bukkit.GameMode;
/**
*
* @author Risto
* @author Rsl1122
*/
public class GamemodeHandling {
/**
*
* @param data
* @param time
* @param newGM
*/
public static void processGamemodeInfo(UserData data, long time, GameMode newGM) {
if (newGM == null) {
return;

View File

@ -16,10 +16,17 @@ import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
/**
*
* @author Risto
* @author Rsl1122
*/
public class KillHandling {
/**
*
* @param data
* @param time
* @param dead
* @param weaponName
*/
public static void processKillInfo(UserData data, long time, LivingEntity dead, String weaponName) {
Plan plugin = getPlugin(Plan.class);
if (dead instanceof Player) {

View File

@ -15,10 +15,19 @@ import main.java.com.djrapitops.plan.data.UserData;
/**
*
* @author Risto
* @author Rsl1122
*/
public class LoginHandling {
/**
*
* @param data
* @param time
* @param ip
* @param banned
* @param nickname
* @param loginTimes
*/
public static void processLoginInfo(UserData data, long time, InetAddress ip, boolean banned, String nickname, int loginTimes) {
data.setLastPlayed(time);
data.updateBanned(banned);
@ -28,6 +37,11 @@ public class LoginHandling {
updateGeolocation(ip, data);
}
/**
*
* @param ip
* @param data
*/
public static void updateGeolocation(InetAddress ip, UserData data) {
DemographicsData demData = data.getDemData();
try {

View File

@ -9,9 +9,16 @@ import main.java.com.djrapitops.plan.data.UserData;
/**
*
* @author Risto
* @author Rsl1122
*/
public class LogoutHandling {
/**
*
* @param data
* @param time
* @param banned
*/
public static void processLogoutInfo(UserData data, long time, boolean banned) {
data.setPlayTime(data.getPlayTime() + (time - data.getLastPlayed()));
data.setLastPlayed(time);

View File

@ -12,20 +12,39 @@ public class ChatInfo extends HandlingInfo {
private String nickname;
private String message;
/**
*
* @param uuid
* @param nickname
* @param message
*/
public ChatInfo(UUID uuid, String nickname, String message) {
super(uuid, InfoType.CHAT, 0L);
this.nickname = nickname;
this.message = message;
}
/**
*
* @return
*/
public String getNickname() {
return nickname;
}
/**
*
* @return
*/
public String getMessage() {
return message;
}
/**
*
* @param uData
* @return
*/
@Override
public boolean process(UserData uData) {
if (!uData.getUuid().equals(uuid)) {

View File

@ -10,14 +10,23 @@ import main.java.com.djrapitops.plan.data.UserData;
/**
*
* @author Risto
* @author Rsl1122
*/
public class DeathInfo extends HandlingInfo{
/**
*
* @param uuid
*/
public DeathInfo(UUID uuid) {
super(uuid, InfoType.DEATH, 0L);
}
/**
*
* @param uData
* @return
*/
@Override
public boolean process(UserData uData) {
if (!uData.getUuid().equals(uuid)) {

View File

@ -12,16 +12,27 @@ import org.bukkit.GameMode;
/**
*
* @author Risto
* @author Rsl1122
*/
public class GamemodeInfo extends HandlingInfo{
private GameMode currentGamemode;
/**
*
* @param uuid
* @param time
* @param gm
*/
public GamemodeInfo(UUID uuid, long time, GameMode gm) {
super(uuid, InfoType.GM, time);
currentGamemode = gm;
}
/**
*
* @param uData
* @return
*/
@Override
public boolean process(UserData uData) {
if (currentGamemode == null) {

View File

@ -13,23 +13,46 @@ public abstract class HandlingInfo {
InfoType type;
long time;
/**
*
* @param uuid
* @param type
* @param time
*/
public HandlingInfo(UUID uuid, InfoType type, long time) {
this.uuid = uuid;
this.type = type;
this.time = time;
}
/**
*
* @return
*/
public UUID getUuid() {
return uuid;
}
/**
*
* @return
*/
public InfoType getType() {
return type;
}
/**
*
* @return
*/
public long getTime() {
return time;
}
/**
*
* @param uData
* @return
*/
public abstract boolean process(UserData uData);
}

View File

@ -7,8 +7,47 @@ package main.java.com.djrapitops.plan.data.handling.info;
/**
*
* @author Risto
* @author Rsl1122
*/
public enum InfoType {
CHAT, DEATH, KILL, GM, LOGIN, LOGOUT, KICK, RELOAD
/**
*
*/
CHAT,
/**
*
*/
DEATH,
/**
*
*/
KILL,
/**
*
*/
GM,
/**
*
*/
LOGIN,
/**
*
*/
LOGOUT,
/**
*
*/
KICK,
/**
*
*/
RELOAD
}

View File

@ -10,14 +10,23 @@ import main.java.com.djrapitops.plan.data.UserData;
/**
*
* @author Risto
* @author Rsl1122
*/
public class KickInfo extends HandlingInfo {
/**
*
* @param uuid
*/
public KickInfo(UUID uuid) {
super(uuid, InfoType.KICK, 0L);
}
/**
*
* @param uData
* @return
*/
@Override
public boolean process(UserData uData) {
if (!uData.getUuid().equals(uuid)) {

View File

@ -19,12 +19,24 @@ public class KillInfo extends HandlingInfo {
private LivingEntity dead;
private String weaponName;
/**
*
* @param uuid
* @param time
* @param dead
* @param weaponName
*/
public KillInfo(UUID uuid, long time, LivingEntity dead, String weaponName) {
super(uuid, InfoType.KILL, time);
this.dead = dead;
this.weaponName = weaponName;
}
/**
*
* @param uData
* @return
*/
@Override
public boolean process(UserData uData) {
if (!uData.getUuid().equals(uuid)) {

View File

@ -13,7 +13,7 @@ import org.bukkit.GameMode;
/**
*
* @author Risto
* @author Rsl1122
*/
public class LoginInfo extends HandlingInfo{
private InetAddress ip;
@ -22,6 +22,16 @@ public class LoginInfo extends HandlingInfo{
private GamemodeInfo gmInfo;
private int loginTimes;
/**
*
* @param uuid
* @param time
* @param ip
* @param banned
* @param nickname
* @param gm
* @param loginTimes
*/
public LoginInfo(UUID uuid, long time, InetAddress ip, boolean banned, String nickname, GameMode gm, int loginTimes) {
super(uuid, InfoType.LOGIN, time);
this.ip = ip;
@ -31,10 +41,24 @@ public class LoginInfo extends HandlingInfo{
this.loginTimes = loginTimes;
}
/**
*
* @param uuid
* @param time
* @param ip
* @param banned
* @param nickname
* @param gm
*/
public LoginInfo(UUID uuid, long time, InetAddress ip, boolean banned, String nickname, GameMode gm) {
this(uuid, time, ip, banned, nickname, gm, 0);
}
/**
*
* @param uData
* @return
*/
@Override
public boolean process(UserData uData) {
if (!uData.getUuid().equals(uuid)) {

View File

@ -13,7 +13,7 @@ import org.bukkit.GameMode;
/**
*
* @author Risto
* @author Rsl1122
*/
public class LogoutInfo extends HandlingInfo {
@ -21,6 +21,14 @@ public class LogoutInfo extends HandlingInfo {
private SessionData sData;
private GamemodeInfo gmInfo;
/**
*
* @param uuid
* @param time
* @param banned
* @param gm
* @param sData
*/
public LogoutInfo(UUID uuid, long time, boolean banned, GameMode gm, SessionData sData) {
super(uuid, InfoType.LOGOUT, time);
this.banned = banned;
@ -28,6 +36,11 @@ public class LogoutInfo extends HandlingInfo {
this.gmInfo = new GamemodeInfo(uuid, time, gm);
}
/**
*
* @param uData
* @return
*/
@Override
public boolean process(UserData uData) {
if (!uData.getUuid().equals(uuid)) {

View File

@ -12,17 +12,31 @@ import org.bukkit.GameMode;
/**
*
* @author Risto
* @author Rsl1122
*/
public class ReloadInfo extends HandlingInfo {
private LoginInfo info;
/**
*
* @param uuid
* @param time
* @param ip
* @param banned
* @param nickname
* @param gm
*/
public ReloadInfo(UUID uuid, long time, InetAddress ip, boolean banned, String nickname, GameMode gm) {
super(uuid, InfoType.RELOAD, time);
info = new LoginInfo(uuid, time, ip, banned, nickname, gm);
}
/**
*
* @param uData
* @return
*/
@Override
public boolean process(UserData uData) {
if (!uData.getUuid().equals(uuid)) {

View File

@ -3,7 +3,6 @@ package main.java.com.djrapitops.plan.data.listeners;
import java.util.UUID;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.data.cache.DataCacheHandler;
import main.java.com.djrapitops.plan.data.cache.LocationCache;
import org.bukkit.Location;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;

View File

@ -166,5 +166,13 @@ public abstract class Database {
* @throws SQLException
*/
public abstract int getUserId(String uuid) throws SQLException;
/**
*
* @param userId
* @param worlds
* @return
* @throws SQLException
*/
public abstract List<Location> getLocations(String userId, HashMap<String, World> worlds) throws SQLException;
}

View File

@ -19,11 +19,11 @@ import main.java.com.djrapitops.plan.data.*;
import main.java.com.djrapitops.plan.data.cache.DBCallableProcessor;
import main.java.com.djrapitops.plan.database.Database;
import main.java.com.djrapitops.plan.utilities.UUIDFetcher;
import static org.bukkit.Bukkit.getOfflinePlayer;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.scheduler.BukkitRunnable;
import static org.bukkit.Bukkit.getOfflinePlayer;
/**
*
@ -164,6 +164,12 @@ public abstract class SQLDB extends Database {
startConnectionPingTask(plugin);
}
/**
*
* @param plugin
* @throws IllegalArgumentException
* @throws IllegalStateException
*/
public void startConnectionPingTask(Plan plugin) throws IllegalArgumentException, IllegalStateException {
// Maintains Connection.
(new BukkitRunnable() {
@ -715,6 +721,13 @@ public abstract class SQLDB extends Database {
return nicknames;
}
/**
*
* @param userId
* @param worlds
* @return
* @throws SQLException
*/
@Override
public List<Location> getLocations(String userId, HashMap<String, World> worlds) throws SQLException {
PreparedStatement statement;

View File

@ -14,80 +14,379 @@ import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
*/
public enum Html {
/**
*
*/
REPLACE0("REPLACE0"),
/**
*
*/
REPLACE1("REPLACE1"),
/**
*
*/
WARN_INACCURATE("<div class=\"warn\">Data might be inaccurate, player has just registered.</div>"),
/**
*
*/
COLOR_0("<span class=\"black\">"),
/**
*
*/
COLOR_1("<span class=\"darkblue\">"),
/**
*
*/
COLOR_2("<span class=\"darkgreen\">"),
/**
*
*/
COLOR_3("<span class=\"darkaqua\">"),
/**
*
*/
COLOR_4("<span class=\"darkred\">"),
/**
*
*/
COLOR_5("<span class=\"darkpurple\">"),
/**
*
*/
COLOR_6("<span class=\"gold\">"),
/**
*
*/
COLOR_7("<span class=\"gray\">"),
/**
*
*/
COLOR_8("<span class=\"darkgray\">"),
/**
*
*/
COLOR_9("<span class=\"blue\">"),
/**
*
*/
COLOR_a("<span class=\"green\">"),
/**
*
*/
COLOR_b("<span class=\"aqua\">"),
/**
*
*/
COLOR_c("<span class=\"red\">"),
/**
*
*/
COLOR_d("<span class=\"pink\">"),
/**
*
*/
COLOR_e("<span class=\"yellow\">"),
/**
*
*/
COLOR_f("<span class=\"white\">"),
/**
*
*/
SPAN("" + REPLACE0 + "</span>"),
/**
*
*/
BUTTON("<a class=\"button\" href=\"" + REPLACE0 + "\">" + REPLACE1 + "</a>"),
/**
*
*/
BUTTON_CLASS("class=\"button\""),
/**
*
*/
LINK("<a class=\"link\" href=\"" + REPLACE0 + "\">" + REPLACE1 + "</a>"),
/**
*
*/
LINK_CLASS("class=\"link\""),
/**
*
*/
IMG("<img src=\"" + REPLACE0 + "\">"),
/**
*
*/
TOP_TOWNS("<p><b>Top 20 Towns</b></p>"),
/**
*
*/
TOP_FACTIONS("<p><b>Top 20 Factions</b></p>"),
/**
*
*/
TOTAL_BALANCE("<p>Server Total Balance: " + REPLACE0 + "</p>"),
/**
*
*/
TOTAL_VOTES("<p>Players have voted total of " + REPLACE0 + " times.</p>"),
/**
*
*/
PLOT_OPTIONS("<p>Plot options: " + REPLACE0 + "</p>"),
/**
*
*/
FRIENDS("<p>Friends with " + REPLACE0 + "</p>"),
/**
*
*/
BALANCE("<p>Balance: " + REPLACE0 + "</p>"),
/**
*
*/
BANNED("| " + SPAN.parse(COLOR_4.parse() + "Banned")),
/**
*
*/
OPERATOR(", Operator (Op)"),
/**
*
*/
ONLINE("| " + SPAN.parse(COLOR_2.parse() + "Online")),
/**
*
*/
OFFLINE("| " + SPAN.parse(COLOR_4.parse() + "Offline")),
/**
*
*/
ACTIVE("Player is Active"),
/**
*
*/
INACTIVE("Player is inactive"),
/**
*
*/
ERROR_LIST("Error Creating List</p>"),
/**
*
*/
HIDDEN("Hidden (config)"),
/**
*
*/
ERROR_NOT_SET("Error: Replace rule was not set"),
/**
*
*/
FACTION_NOT_FOUND("Faction not found"),
/**
*
*/
FACTION_NO_LEADER("No leader"),
/**
*
*/
FACTION_NO_FACTIONS("No Factions"),
/**
*
*/
WARPS("<br/>Warps: " + REPLACE0),
/**
*
*/
ACHIEVEMENTS("<br/>Achievements: " + REPLACE0 + "/" + REPLACE1),
/**
*
*/
JAILED("| Jailed"),
/**
*
*/
MUTED("| Muted"),
/**
*
*/
VOTES("<br/>Has voted " + REPLACE0 + "times"),
/**
*
*/
FACTION("<br/>Faction: " + REPLACE0 + " | Power: " + REPLACE1 + "/REPLACE2"),
/**
*
*/
TOWN("<br/>Town: " + REPLACE0),
/**
*
*/
TOWN_NO_TOWNS("No Towns"),
/**
*
*/
GRAPH_BANNED("Banned"),
/**
*
*/
GRAPH_UNKNOWN("Unknown"),
/**
*
*/
GRAPH_INACTIVE("Inactive"),
/**
*
*/
GRAPH_ACTIVE("Active"),
/**
*
*/
GRAPH_ONLINE("Players Online"),
/**
*
*/
GRAPH_PLAYERS("Players"),
/**
*
*/
GRAPH_DATE("Date"),
/**
*
*/
TABLE_START_3("<table class=\"sortable table\"><thead><tr><th>REPLACE0</th><th>REPLACE1</th><th>REPLACE2</th></tr></thead><tbody>"),
/**
*
*/
TABLE_START_4("<table class=\"sortable table\"><thead><tr><th>REPLACE0</th><th>REPLACE1</th><th>REPLACE2</th><th>REPLACE3</th></tr></thead><tbody>"),
/**
*
*/
TABLE_SESSIONS_START(TABLE_START_3.parse("Session Started", "Session Ended", "Session Length")),
/**
*
*/
TABLE_KILLS_START(TABLE_START_3.parse("Date", "Killed", "With")),
/**
*
*/
TABLE_FACTIONS_START(TABLE_START_4.parse("Faction", "Power", "Land", "Leader")),
/**
*
*/
TABLE_TOWNS_START(TABLE_START_4.parse("Town", "Residents", "Land", "Mayor")),
/**
*
*/
TABLELINE_2("<tr><td><b>" + REPLACE0 + "</b></td><td>" + REPLACE1 + "</td></tr>"),
/**
*
*/
TABLELINE_3("<tr><td><b>" + REPLACE0 + "</b></td><td>" + REPLACE1 + "</td><td>REPLACE2</td></tr>"),
/**
*
*/
TABLELINE_4("<tr><td><b>" + REPLACE0 + "</b></td><td>" + REPLACE1 + "</td><td>REPLACE2</td><td>REPLACE3</td></tr>"),
/**
*
*/
TABLELINE_PLAYERS("<tr><td>REPLACE0</td><td>REPLACE1</td><td sorttable_customkey=\"REPLACE2\">REPLACE3</td><td>REPLACE4</td><td sorttable_customkey=\"REPLACE5\">REPLACE6</td>" + "<td sorttable_customkey=\"REPLACE7\">REPLACE8</td><td>REPLACE9</td></tr>"),
/**
*
*/
TABLELINE_3_CUSTOMKEY("<tr><td sorttable_customkey=\"REPLACE0\">REPLACE1</td><td sorttable_customkey=\"REPLACE2\">REPLACE3</td><td sorttable_customkey=\"REPLACE4\">REPLACE5</td></tr>"),
/**
*
*/
TABLELINE_3_CUSTOMKEY_1("<tr><td sorttable_customkey=\"REPLACE0\">REPLACE1</td><td>REPLACE2</td><td>REPLACE3</td></tr>"),
/**
*
*/
ERROR_TABLE_2(TABLELINE_2.parse("No data", "No data")),
/**
*
*/
TABLE_END("</tbody></table>"),
/**
*
*/
SESSIONDATA_NONE("No Session Data available"),
/**
*
*/
KILLDATA_NONE("No Kills"),;
private String html;
@ -96,10 +395,19 @@ public enum Html {
this.html = html;
}
/**
*
* @return
*/
public String parse() {
return html;
}
/**
*
* @param p
* @return
*/
public String parse(String... p) {
String returnValue = this.html;
for (int i = 0; i < p.length; i++) {
@ -108,10 +416,18 @@ public enum Html {
return returnValue;
}
/**
*
* @param html
*/
public void setHtml(String html) {
this.html = html;
}
/**
*
* @param localeFile
*/
public static void loadLocale(File localeFile) {
try {
Scanner localeScanner = new Scanner(localeFile, "UTF-8");

View File

@ -5,8 +5,8 @@ import main.java.com.djrapitops.plan.data.KillData;
import main.java.com.djrapitops.plan.ui.Html;
import main.java.com.djrapitops.plan.utilities.FormatUtils;
import main.java.com.djrapitops.plan.utilities.HtmlUtils;
import org.bukkit.OfflinePlayer;
import static org.bukkit.Bukkit.getOfflinePlayer;
import org.bukkit.OfflinePlayer;
/**
*

View File

@ -24,11 +24,10 @@ 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 static org.bukkit.Bukkit.getOfflinePlayer;
import org.bukkit.GameMode;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import static org.bukkit.Bukkit.getOfflinePlayer;
import static org.bukkit.Bukkit.getOfflinePlayer;
/**
*
@ -135,6 +134,13 @@ public class Analysis {
return analyzeData(rawData, uuids, analysisCache);
}
/**
*
* @param rawData
* @param uuids
* @param analysisCache
* @return
*/
public boolean analyzeData(List<UserData> rawData, List<UUID> uuids, AnalysisCacheHandler analysisCache) {
// Create empty Dataset
final RawAnalysisData sorted = new RawAnalysisData();

View File

@ -48,6 +48,13 @@ public class AnalysisUtils {
return SortablePlayersTableCreator.createSortablePlayersTable(data);
}
/**
*
* @param registered
* @param scale
* @param now
* @return
*/
public static int getNewPlayers(List<Long> registered, long scale, long now) {
int newPlayers = 0;
if (!registered.isEmpty()) {
@ -61,6 +68,11 @@ public class AnalysisUtils {
return newPlayers;
}
/**
*
* @param data
* @return
*/
public static List<Long> transformSessionDataToLengths(Collection<SessionData> data) {
List<Long> list = data.stream()
.filter(session -> session != null)
@ -70,6 +82,11 @@ public class AnalysisUtils {
return list;
}
/**
*
* @param list
* @return
*/
public static long average(Collection<Long> list) {
if (list.isEmpty()) {
return 0;

View File

@ -81,6 +81,11 @@ public class HtmlUtils {
return url;
}
/**
*
* @param string
* @return
*/
public static String removeXSS(String string) {
return string.replace("<!--", "")
.replace("-->", "")

View File

@ -15,10 +15,10 @@ 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 static org.bukkit.Bukkit.getOfflinePlayer;
import org.bukkit.GameMode;
import org.bukkit.OfflinePlayer;
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
import static org.bukkit.Bukkit.getOfflinePlayer;
/**
*

View File

@ -54,6 +54,13 @@ public class MiscUtils {
return lineWithVersion.split(": ")[1];
}
/**
*
* @param currentVersion
* @param gitVersion
* @return
* @throws NumberFormatException
*/
public static String checkVersion(String currentVersion, String gitVersion) throws NumberFormatException {
int newestVersionNumber = FormatUtils.parseVersionNumber(gitVersion);
int currentVersionNumber = FormatUtils.parseVersionNumber(currentVersion);
@ -64,6 +71,12 @@ public class MiscUtils {
}
}
/**
*
* @param args
* @param sender
* @return
*/
public static String getPlayerName(String[] args, CommandSender sender) {
return getPlayerName(args, sender, Permissions.INSPECT_OTHER);
}

View File

@ -33,6 +33,10 @@ import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
/**
*
* @author Rsl1122
*/
public class UUIDFetcher implements Callable<Map<String, UUID>> {
private static final double PROFILES_PER_REQUEST = 100;
@ -41,11 +45,20 @@ public class UUIDFetcher implements Callable<Map<String, UUID>> {
private final List<String> names;
private final boolean rateLimiting;
/**
*
* @param names
* @param rateLimiting
*/
public UUIDFetcher(List<String> names, boolean rateLimiting) {
this.names = ImmutableList.copyOf(names);
this.rateLimiting = rateLimiting;
}
/**
*
* @param names
*/
public UUIDFetcher(List<String> names) {
this(names, true);
}
@ -97,6 +110,11 @@ public class UUIDFetcher implements Callable<Map<String, UUID>> {
return UUID.fromString(id.substring(0, 8) + "-" + id.substring(8, 12) + "-" + id.substring(12, 16) + "-" + id.substring(16, 20) + "-" + id.substring(20, 32));
}
/**
*
* @param uuid
* @return
*/
public static byte[] toBytes(UUID uuid) {
ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[16]);
byteBuffer.putLong(uuid.getMostSignificantBits());
@ -104,6 +122,11 @@ public class UUIDFetcher implements Callable<Map<String, UUID>> {
return byteBuffer.array();
}
/**
*
* @param array
* @return
*/
public static UUID fromBytes(byte[] array) {
if (array.length != 16) {
throw new IllegalArgumentException("Illegal byte array length: " + array.length);
@ -114,6 +137,12 @@ public class UUIDFetcher implements Callable<Map<String, UUID>> {
return new UUID(mostSignificant, leastSignificant);
}
/**
*
* @param name
* @return
* @throws Exception
*/
public static UUID getUUIDOf(String name) throws Exception {
return new UUIDFetcher(Arrays.asList(name)).call().get(name);
}

View File

@ -10,7 +10,7 @@ import main.java.com.djrapitops.plan.data.handling.info.HandlingInfo;
/**
*
* @author Risto
* @author Rsl1122
*/
public class HandlingInfoTimeComparator implements Comparator<HandlingInfo> {

View File

@ -8,20 +8,20 @@ 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.junit.Test;
import static org.junit.Assert.*;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.bukkit.plugin.java.JavaPlugin;
import org.easymock.EasyMock;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import test.java.utils.TestInit;
/**
*
* @author Risto
* @author Rsl1122
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest(JavaPlugin.class)
@ -29,9 +29,15 @@ public class PhraseTest {
private Plan plan;
/**
*
*/
public PhraseTest() {
}
/**
*
*/
@Before
public void setUp() {
TestInit t = new TestInit();
@ -45,6 +51,9 @@ public class PhraseTest {
// PowerMock.verify(JavaPlugin.class);
}
/**
*
*/
@Test
public void testToString() {
Phrase instance = Phrase.REPLACE0;
@ -54,6 +63,9 @@ public class PhraseTest {
assertEquals(expResult, result);
}
/**
*
*/
@Test
public void testParse_0args() {
Phrase instance = Phrase.DEM_UNKNOWN;
@ -62,6 +74,9 @@ public class PhraseTest {
assertEquals(expResult, result);
}
/**
*
*/
@Test
public void testParse_StringArr() {
Phrase instance = Phrase.REPLACE0;
@ -70,6 +85,9 @@ public class PhraseTest {
assertEquals(expResult, result);
}
/**
*
*/
@Test
public void testColor() {
Phrase instance = Phrase.COLOR_MAIN;
@ -79,6 +97,9 @@ public class PhraseTest {
assertEquals(expResult, result);
}
/**
*
*/
@Test
public void testSetText() {
Phrase instance = Phrase.REPLACE0;

View File

@ -9,9 +9,9 @@ import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.Settings;
import org.bukkit.plugin.java.JavaPlugin;
import org.easymock.EasyMock;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
@ -20,15 +20,21 @@ import test.java.utils.TestInit;
/**
*
* @author Risto
* @author Rsl1122
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest(JavaPlugin.class)
public class SettingsTest {
/**
*
*/
public SettingsTest() {
}
/**
*
*/
@Before
public void setUp() {
TestInit t = new TestInit();
@ -40,21 +46,33 @@ public class SettingsTest {
// PowerMock.verify(JavaPlugin.class);
}
/**
*
*/
@Test
public void testIsTrue() {
assertTrue("Webserver supposed to be enabled by default", Settings.WEBSERVER_ENABLED.isTrue());
}
/**
*
*/
@Test
public void testToString() {
assertEquals("sqlite",Settings.DB_TYPE.toString());
}
/**
*
*/
@Test
public void testGetNumber() {
assertEquals(8804,Settings.WEBSERVER_PORT.getNumber());
}
/**
*
*/
@Test
public void testGetPath() {
assertEquals("Settings.WebServer.Enabled", Settings.WEBSERVER_ENABLED.getPath());

View File

@ -6,18 +6,24 @@
package test.java.main.java.com.djrapitops.plan.api;
import main.java.com.djrapitops.plan.api.Gender;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Test;
/**
*
* @author Risto
* @author Rsl1122
*/
public class GenderTest {
/**
*
*/
public GenderTest() {
}
/**
*
*/
@Test
public void testParse() {
String name = "male";
@ -26,6 +32,9 @@ public class GenderTest {
assertEquals(expResult, result);
}
/**
*
*/
@Test
public void testParse2() {
String name = "female";
@ -34,6 +43,9 @@ public class GenderTest {
assertEquals(expResult, result);
}
/**
*
*/
@Test
public void testParse3() {
String name = "other";
@ -42,6 +54,9 @@ public class GenderTest {
assertEquals(expResult, result);
}
/**
*
*/
@Test
public void testParse4() {
String name = "noeanroe";

View File

@ -11,9 +11,9 @@ import main.java.com.djrapitops.plan.api.Gender;
import main.java.com.djrapitops.plan.data.DemographicsData;
import org.bukkit.plugin.java.JavaPlugin;
import org.easymock.EasyMock;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
@ -22,15 +22,21 @@ import test.java.utils.TestInit;
/**
*
* @author Risto
* @author Rsl1122
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest(JavaPlugin.class)
public class DemographicsDataTest {
/**
*
*/
public DemographicsDataTest() {
}
/**
*
*/
@Before
public void setUp() {
TestInit t = new TestInit();
@ -44,6 +50,9 @@ public class DemographicsDataTest {
// PowerMock.verify(JavaPlugin.class);
}
/**
*
*/
@Test
public void testGetAge() {
DemographicsData instance = new DemographicsData();
@ -52,6 +61,9 @@ public class DemographicsDataTest {
assertEquals(expResult, result);
}
/**
*
*/
@Test
public void testGetAge2() {
DemographicsData instance = new DemographicsData(10, Gender.OTHER, "None");
@ -60,6 +72,9 @@ public class DemographicsDataTest {
assertEquals(expResult, result);
}
/**
*
*/
@Test
public void testGetGender() {
DemographicsData instance = new DemographicsData();
@ -68,6 +83,9 @@ public class DemographicsDataTest {
assertEquals(expResult, result);
}
/**
*
*/
@Test
public void testGetGender2() {
DemographicsData instance = new DemographicsData(10, Gender.OTHER, "None");
@ -76,6 +94,9 @@ public class DemographicsDataTest {
assertEquals(expResult, result);
}
/**
*
*/
@Test
public void testGetGeoLocation() {
DemographicsData instance = new DemographicsData();
@ -84,6 +105,9 @@ public class DemographicsDataTest {
assertEquals(expResult, result);
}
/**
*
*/
@Test
public void testGetGeoLocation2() {
DemographicsData instance = new DemographicsData(10, Gender.OTHER, "None");
@ -92,6 +116,9 @@ public class DemographicsDataTest {
assertEquals(expResult, result);
}
/**
*
*/
@Test
public void testSetAge() {
int age = 10;
@ -101,6 +128,9 @@ public class DemographicsDataTest {
assertEquals(age, result);
}
/**
*
*/
@Test
public void testSetGender() {
Gender gender = Gender.MALE;
@ -110,6 +140,9 @@ public class DemographicsDataTest {
assertEquals(gender, result);
}
/**
*
*/
@Test
public void testSetGeoLocation() {
String geoLocation = "None";
@ -119,6 +152,9 @@ public class DemographicsDataTest {
assertEquals(geoLocation, result);
}
/**
*
*/
@Test
public void testToString() {
DemographicsData instance = new DemographicsData();

View File

@ -7,18 +7,24 @@ package test.java.main.java.com.djrapitops.plan.data;
import java.util.UUID;
import main.java.com.djrapitops.plan.data.KillData;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Test;
/**
*
* @author Risto
* @author Rsl1122
*/
public class KillDataTest {
/**
*
*/
public KillDataTest() {
}
/**
*
*/
@Test
public void testGetVictim() {
UUID uuid = UUID.fromString("71cfb6f0-c3ef-4954-8abe-13fa07afc340");
@ -26,6 +32,9 @@ public class KillDataTest {
assertEquals(k.getVictim(), uuid);
}
/**
*
*/
@Test
public void testGetDate() {
UUID uuid = UUID.fromString("71cfb6f0-c3ef-4954-8abe-13fa07afc340");
@ -33,6 +42,9 @@ public class KillDataTest {
assertEquals(k.getDate(), 100L);
}
/**
*
*/
@Test
public void testGetWeapon() {
UUID uuid = UUID.fromString("71cfb6f0-c3ef-4954-8abe-13fa07afc340");
@ -40,6 +52,9 @@ public class KillDataTest {
assertEquals(k.getWeapon(), "TestWeapon");
}
/**
*
*/
@Test
public void testGetVictimUserID() {
UUID uuid = UUID.fromString("71cfb6f0-c3ef-4954-8abe-13fa07afc340");

View File

@ -7,47 +7,68 @@ package test.java.main.java.com.djrapitops.plan.data;
import main.java.com.djrapitops.plan.data.SessionData;
import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.Before;
import org.junit.Test;
/**
*
* @author Risto
* @author Rsl1122
*/
public class SessionDataTest {
private SessionData test;
/**
*
*/
public SessionDataTest() {
}
/**
*
*/
@Before
public void setUp() {
test = new SessionData(0);
}
/**
*
*/
@Test
public void testEndSession() {
test.endSession(1L);
assertTrue("End not 1", test.getSessionEnd() == 1L);
}
/**
*
*/
@Test
public void testGetSessionStart() {
assertTrue("Start not 0", test.getSessionStart() == 0L);
}
/**
*
*/
@Test
public void testIsValid() {
test.endSession(1L);
assertTrue("Supposed to be valid.", test.isValid());
}
/**
*
*/
@Test
public void testInvalid() {
assertTrue("Supposed to be invalid.", !test.isValid());
}
/**
*
*/
@Test
public void testInvalid2() {
test = new SessionData(3);
@ -55,6 +76,9 @@ public class SessionDataTest {
assertTrue("Supposed to be invalid.", !test.isValid());
}
/**
*
*/
@Test
public void testValid2() {
test = new SessionData(3);
@ -62,6 +86,9 @@ public class SessionDataTest {
assertTrue("Supposed to be valid.", test.isValid());
}
/**
*
*/
@Test
public void testToString() {
String exp = "s:0 e:-1";
@ -69,6 +96,9 @@ public class SessionDataTest {
assertEquals(exp, result);
}
/**
*
*/
@Test
public void testGetLength() {
long exp = 5L;
@ -77,6 +107,9 @@ public class SessionDataTest {
assertEquals(exp, result);
}
/**
*
*/
@Test
public void testGetLength2() {
long exp = 5L;

View File

@ -5,7 +5,6 @@
*/
package test.java.main.java.com.djrapitops.plan.data;
import org.bukkit.OfflinePlayer;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
@ -19,13 +18,14 @@ import main.java.com.djrapitops.plan.data.SessionData;
import main.java.com.djrapitops.plan.data.UserData;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.plugin.java.JavaPlugin;
import org.easymock.EasyMock;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
@ -35,7 +35,7 @@ import test.java.utils.TestInit;
/**
*
* @author Risto
* @author Rsl1122
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest(JavaPlugin.class)
@ -44,9 +44,15 @@ public class UserDataTest {
private UserData test;
private Plan plan;
/**
*
*/
public UserDataTest() {
}
/**
*
*/
@Before
public void setUp() {
TestInit t = new TestInit();
@ -63,6 +69,10 @@ public class UserDataTest {
test = new UserData(UUID.fromString("7f8149a0-b5a5-4fcd-80b5-6cff083a99f1"), 0, null, true, GameMode.CREATIVE, demData, "Testname", true);
}
/**
*
* @throws UnknownHostException
*/
@Test
public void testAddIpAddress() throws UnknownHostException {
InetAddress ip = InetAddress.getByName("247.183.163.155");
@ -77,6 +87,10 @@ public class UserDataTest {
assertTrue("Added multiples", test.getIps().size() == 2);
}
/**
*
* @throws UnknownHostException
*/
@Test
public void testAddIpAddresses() throws UnknownHostException {
List<InetAddress> ips = new ArrayList<>();
@ -93,6 +107,9 @@ public class UserDataTest {
assertTrue("Added multiples", test.getIps().size() == 2);
}
/**
*
*/
@Test
public void testAddIpAddressesEmpty() {
List<InetAddress> ips = new ArrayList<>();
@ -100,6 +117,9 @@ public class UserDataTest {
assertTrue("Added something", test.getIps().isEmpty());
}
/**
*
*/
@Test
public void testAddLocation() {
World mockWorld = MockUtils.mockWorld();
@ -108,12 +128,18 @@ public class UserDataTest {
assertTrue("Didn't add location", !test.getLocations().isEmpty());
}
/**
*
*/
@Test
public void testAddNullLocation() {
test.addLocation(null);
assertTrue("Added location", test.getLocations().isEmpty());
}
/**
*
*/
@Test
public void testAddLocations() {
World mockWorld = MockUtils.mockWorld();
@ -130,6 +156,9 @@ public class UserDataTest {
assertTrue("Added null", !locations.contains(null));
}
/**
*
*/
@Test
public void testAddNickname() {
String one = "Test1";
@ -148,6 +177,9 @@ public class UserDataTest {
assertTrue("Last nickname was not one", test.getLastNick().equals(one));
}
/**
*
*/
@Test
public void testAddNicknames() {
String one = "Test1";
@ -164,6 +196,9 @@ public class UserDataTest {
assertTrue("Added multiples", test.getNicknames().size() == 2);
}
/**
*
*/
@Test
public void testAddNicknamesEmpty() {
List<String> o = new ArrayList<>();
@ -171,12 +206,18 @@ public class UserDataTest {
assertTrue("Added something", test.getNicknames().isEmpty());
}
/**
*
*/
@Test
public void testSetGMTime() {
test.setGMTime(GameMode.SURVIVAL, 1L);
assertTrue("" + test.getGmTimes().get(GameMode.SURVIVAL), test.getGmTimes().get(GameMode.SURVIVAL) == 1L);
}
/**
*
*/
@Test
public void testSetGMTimeWhenGMTimesNull() {
test.setGmTimes(null);
@ -184,12 +225,18 @@ public class UserDataTest {
assertTrue("" + test.getGmTimes().get(GameMode.SURVIVAL), test.getGmTimes().get(GameMode.SURVIVAL) == 1L);
}
/**
*
*/
@Test
public void testSetGMTimeNull() {
test.setGMTime(null, 0L);
assertTrue("Added null", !test.getGmTimes().containsKey(null));
}
/**
*
*/
@Test
public void testSetAllGMTimes() {
HashMap<GameMode, Long> gmTimes = new HashMap<>();
@ -204,6 +251,9 @@ public class UserDataTest {
assertTrue("Not equal 3", times.get(GameMode.SPECTATOR) == 4L);
}
/**
*
*/
@Test
public void testAddSession() {
SessionData correct = new SessionData(0, 1);
@ -211,6 +261,9 @@ public class UserDataTest {
assertTrue("Didn't add correct one", test.getSessions().contains(correct));
}
/**
*
*/
@Test
public void testAddSessionIncorrect() {
SessionData incorrect = new SessionData(0);
@ -218,6 +271,9 @@ public class UserDataTest {
assertTrue("Added incorrect one", !test.getSessions().contains(incorrect));
}
/**
*
*/
@Test
public void testAddSessionNull() {
SessionData incorrect = null;
@ -225,6 +281,9 @@ public class UserDataTest {
assertTrue("Added null", !test.getSessions().contains(incorrect));
}
/**
*
*/
@Test
public void testAddSessions() {
SessionData correct = new SessionData(0, 1);
@ -239,6 +298,9 @@ public class UserDataTest {
assertTrue("Added null", !test.getSessions().contains(incorrect));
}
/**
*
*/
@Test
public void testAddSessionsEmpty() {
List<SessionData> o = new ArrayList<>();
@ -246,6 +308,9 @@ public class UserDataTest {
assertTrue("Added something", test.getSessions().isEmpty());
}
/**
*
*/
@Test
public void testSetCurrentSession() {
SessionData s = new SessionData(0);
@ -253,6 +318,9 @@ public class UserDataTest {
assertEquals(test.getCurrentSession(), s);
}
/**
*
*/
@Test
public void testUpdateBanned() {
test.updateBanned(true);
@ -261,6 +329,9 @@ public class UserDataTest {
assertTrue("True", !test.isBanned());
}
/**
*
*/
@Test
public void testIsAccessed() {
test.access();
@ -272,12 +343,18 @@ public class UserDataTest {
assertTrue("Accessed, even though not accessing", !test.isAccessed());
}
/**
*
*/
@Test
public void testAccess() {
test.access();
assertTrue("Not accessed, even though accessing", test.isAccessed());
}
/**
*
*/
@Test
public void testStopAccessing() {
test.access();
@ -285,29 +362,44 @@ public class UserDataTest {
assertTrue("Accessed, even though not accessing", !test.isAccessed());
}
/**
*
*/
@Test
public void testEquals() {
assertTrue("Not Equals!", test.equals(new UserData(UUID.fromString("7f8149a0-b5a5-4fcd-80b5-6cff083a99f1"), 0, null, true, GameMode.CREATIVE, null, "Testname", true)));
}
/**
*
*/
@Test
public void testEqualsNot() {
UserData notEqual = new UserData(UUID.fromString("7f8149a0-b5a5-4fcd-80b5-6cff083a99f1"), 0, null, true, GameMode.CREATIVE, null, "WRONG", true);
assertTrue("Equals!", !notEqual.equals(test));
}
/**
*
*/
@Test
public void testEqualsNot2() {
Object o = "NOT";
assertTrue("Equals!", !test.equals(o));
}
/**
*
*/
@Test
public void testCopyConstructor() {
UserData copy = new UserData(test);
assertTrue("Not copied properly", test.equals(copy));
}
/**
*
*/
@Test
public void testPlayerConstructor() {
test = new UserData(MockUtils.mockPlayer(), new DemographicsData());
@ -316,6 +408,10 @@ public class UserDataTest {
assertTrue("Not equal!", test.equals(expected));
}
/**
*
* @throws IOException
*/
@Test
public void testPlayerConstructorBrokenBanned() throws IOException {
test = new UserData(MockUtils.mockBrokenPlayer(), new DemographicsData());
@ -324,6 +420,9 @@ public class UserDataTest {
assertTrue("Not equal!", test.equals(expected));
}
/**
*
*/
@Test
public void testOfflinePlayerConstructor() {
test = new UserData((OfflinePlayer) MockUtils.mockPlayer(), new DemographicsData());
@ -332,6 +431,10 @@ public class UserDataTest {
assertTrue("Not equal!", test.equals(expected));
}
/**
*
* @throws IOException
*/
@Test
public void testOfflinePlayerConstructorBrokenBanned() throws IOException {
test = new UserData((OfflinePlayer) MockUtils.mockBrokenPlayer(), new DemographicsData());
@ -340,6 +443,9 @@ public class UserDataTest {
assertTrue("Not equal!", test.equals(expected));
}
/**
*
*/
@Test
public void testGetUUID() {
assertEquals(test.getUuid(), UUID.fromString("7f8149a0-b5a5-4fcd-80b5-6cff083a99f1"));

View File

@ -6,23 +6,31 @@
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;
import main.java.com.djrapitops.plan.Phrase;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.data.DemographicsData;
import main.java.com.djrapitops.plan.data.UserData;
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 org.bukkit.OfflinePlayer;
import org.bukkit.plugin.java.JavaPlugin;
import org.easymock.EasyMock;
import static org.easymock.EasyMock.anyString;
import org.junit.After;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import static org.powermock.api.mockito.PowerMockito.when;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@ -31,7 +39,7 @@ import test.java.utils.TestInit;
/**
*
* @author Risto
* @author Rsl1122
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest(JavaPlugin.class)
@ -44,9 +52,15 @@ public class DataCacheHandlerTest {
private boolean calledSaveUserData;
private boolean calledSaveMultiple;
public DataCacheHandlerTest() {
/**
*
*/
public DataCacheHandlerTest() {
}
/**
*
*/
@Before
public void setUp() {
TestInit t = new TestInit();
@ -60,6 +74,28 @@ public class DataCacheHandlerTest {
}
@Override
public HashMap<String, Integer> getCommandUse() {
return new HashMap<>();
}
@Override
public void giveUserDataToProcessors(UUID uuid, Collection<DBCallableProcessor> processors) {
if (uuid.equals(MockUtils.getPlayerUUID())) {
OfflinePlayer op = MockUtils.mockPlayer();
UserData d = new UserData(op, new DemographicsData());
for (DBCallableProcessor p : processors) {
p.process(d);
}
} else if (uuid.equals(MockUtils.getPlayer2UUID())) {
OfflinePlayer op = MockUtils.mockPlayer2();
UserData d = new UserData(op, new DemographicsData());
for (DBCallableProcessor p : processors) {
p.process(d);
}
}
}
@Override
public void saveCommandUse(HashMap<String, Integer> c) {
calledSaveCommandUse = true;
@ -76,73 +112,135 @@ public class DataCacheHandlerTest {
}
};
when(plan.getDB()).thenReturn(db);
handler = new DataCacheHandler(plan) {
@Override
public boolean getCommandUseFromDb() {
return true;
}
@Override
public void startQueues() {
}
PowerMock.mockStatic(JavaPlugin.class);
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
PowerMock.replay(JavaPlugin.class);
handler = new DataCacheHandler(plan) {
@Override
public void startAsyncPeriodicSaveTask() throws IllegalArgumentException, IllegalStateException {
}
};
}
/**
*
*/
@After
public void tearDown() {
public void tearDown() throws SQLException {
// db.close();
}
/**
*
*/
@Test
public void testGetUserDataForProcessingCache() throws SQLException, InterruptedException {
// db.init();
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
db.saveUserData(data.getUuid(), data);
handler.getUserDataForProcessing(new DBCallableProcessor() {
@Override
public void process(UserData d) {
assertTrue(d.equals(data));
}
}, data.getUuid());
Thread.sleep(1000);
assertTrue(handler.getDataCache().containsKey(data.getUuid()));
assertTrue(handler.getDataCache().get(data.getUuid()).equals(data));
}
/**
*
*/
@Ignore
@Test
public void testGetUserDataForProcessing_3args() {
}
@Ignore
@Test
public void testGetUserDataForProcessing_DBCallableProcessor_UUID() {
public void testGetUserDataForProcessingDontCache() throws SQLException, InterruptedException {
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
db.saveUserData(data.getUuid(), data);
handler.getUserDataForProcessing(new DBCallableProcessor() {
@Override
public void process(UserData d) {
assertTrue(d.equals(data));
}
}, data.getUuid(), false);
Thread.sleep(1000);
assertTrue(!handler.getDataCache().containsKey(data.getUuid()));
assertTrue(handler.getDataCache().get(data.getUuid()) == null);
}
/**
*
*/
@Test
public void testSaveCachedUserData() {
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
handler.getDataCache().put(data.getUuid(), data);
handler.saveCachedUserData();
assertTrue("Didn't call saveMultiple", calledSaveMultiple);
}
/**
*
*/
@Ignore
@Test
public void testAddToPool() {
}
/**
*
*/
@Ignore
@Test
public void testSaveCacheOnDisable() {
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
handler.getDataCache().put(data.getUuid(), data);
handler.startSession(data.getUuid());
handler.saveCacheOnDisable();
assertTrue(calledSaveMultiple);
}
/**
*
*/
@Ignore
@Test
public void testSaveCachedData() {
}
/**
*
*/
@Test
public void testSaveCommandUse() {
handler.saveCommandUse();
assertTrue("Didn't call saveCMDUse for db", calledSaveCommandUse);
}
/**
*
*/
@Ignore
@Test
public void testSaveHandlerDataToCache() {
}
/**
*
*/
@Ignore
@Test
public void testClearCache() {
}
/**
*
*/
@Ignore("mock log")
@Test
public void testClearFromCache() {
@ -150,46 +248,74 @@ public class DataCacheHandlerTest {
handler.getDataCache().put(uuid, null);
handler.clearFromCache(uuid);
assertTrue("Found uuid", !handler.getDataCache().containsKey(uuid));
assertTrue("Not empty", handler.getDataCache().isEmpty());
}
/**
*
*/
@Test
public void testScheludeForClear() {
}
/**
*
*/
@Test
public void testIsDataAccessed() {
}
/**
*
*/
@Ignore
@Test
public void testNewPlayer_Player() {
}
/**
*
*/
@Ignore
@Test
public void testNewPlayer_OfflinePlayer() {
}
/**
*
*/
@Ignore
@Test
public void testNewPlayer_UserData() {
}
/**
*
*/
@Test
public void testGetDataCache() {
assertTrue("Cache was null", handler.getDataCache() != null);
}
/**
*
*/
@Ignore
@Test
public void testHandleReload() {
}
/**
*
*/
@Test
public void testGetMaxPlayers() {
assertEquals(20, handler.getMaxPlayers());
}
/**
*
*/
@Test
public void testHandleCommand() {
handler.handleCommand("/plan");

View File

@ -11,26 +11,35 @@ import java.util.UUID;
import main.java.com.djrapitops.plan.data.cache.LocationCache;
import org.bukkit.Location;
import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.Before;
import org.junit.Test;
import test.java.utils.MockUtils;
/**
*
* @author Risto
* @author Rsl1122
*/
public class LocationCacheTest {
private LocationCache test;
/**
*
*/
public LocationCacheTest() {
}
/**
*
*/
@Before
public void setUp() {
test = new LocationCache();
}
/**
*
*/
@Test
public void testAddLocation() {
Location loc = new Location(MockUtils.mockWorld(), 0, 0, 0);
@ -39,6 +48,9 @@ public class LocationCacheTest {
assertTrue("Didn't contain location", test.getLocationsForSaving(uuid).contains(loc));
}
/**
*
*/
@Test
public void testAddLocations() {
Location loc = new Location(MockUtils.mockWorld(), 0, 0, 0);
@ -50,6 +62,9 @@ public class LocationCacheTest {
assertTrue("Didn't contain location", result.contains(loc2));
}
/**
*
*/
@Test
public void testClearLocations() {
Location loc = new Location(MockUtils.mockWorld(), 0, 0, 0);

View File

@ -14,8 +14,8 @@ import main.java.com.djrapitops.plan.data.cache.SessionCache;
import org.bukkit.plugin.java.JavaPlugin;
import org.easymock.EasyMock;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
@ -25,7 +25,7 @@ import test.java.utils.TestInit;
/**
*
* @author Risto
* @author Rsl1122
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest(JavaPlugin.class)
@ -33,14 +33,23 @@ public class SessionCacheTest {
private SessionCache test;
/**
*
*/
public SessionCacheTest() {
}
/**
*
*/
@Before
public void setUp() {
test = new SessionCache();
}
/**
*
*/
@Test
public void testStartSession() {
UUID uuid = MockUtils.getPlayerUUID();
@ -48,6 +57,9 @@ public class SessionCacheTest {
assertTrue("Didn't contain new session", test.getActiveSessions().containsKey(uuid));
}
/**
*
*/
@Test
public void testEndSession() {
UUID uuid = MockUtils.getPlayerUUID();
@ -59,6 +71,9 @@ public class SessionCacheTest {
assertTrue("Session not valid", testSession.isValid());
}
/**
*
*/
@Test
public void testAddSession() {
UUID uuid = MockUtils.getPlayerUUID();

View File

@ -22,7 +22,7 @@ import test.java.utils.TestInit;
/**
*
* @author Risto
* @author Rsl1122
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({JavaPlugin.class})
@ -31,9 +31,15 @@ public class DataCacheClearQueueTest {
private Plan plan;
private DataCacheHandler handler;
/**
*
*/
public DataCacheClearQueueTest() {
}
/**
*
*/
@Before
public void setUp() {
TestInit t = new TestInit();
@ -64,18 +70,30 @@ public class DataCacheClearQueueTest {
};
}
/**
*
*/
@After
public void tearDown() {
}
/**
*
*/
@Test
public void testScheduleForClear_UUID() {
}
/**
*
*/
@Test
public void testScheduleForClear_Collection() {
}
/**
*
*/
@Test
public void testStop() {
}

View File

@ -25,9 +25,9 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.plugin.java.JavaPlugin;
import org.easymock.EasyMock;
import org.junit.After;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
@ -37,7 +37,7 @@ import test.java.utils.TestInit;
/**
*
* @author Risto
* @author Rsl1122
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({JavaPlugin.class, Bukkit.class})
@ -47,9 +47,17 @@ public class DataCacheGetQueueTest {
private Database db;
private int rows;
/**
*
*/
public DataCacheGetQueueTest() {
}
/**
*
* @throws IOException
* @throws Exception
*/
@Before
public void setUp() throws IOException, Exception {
TestInit t = new TestInit();
@ -93,6 +101,11 @@ public class DataCacheGetQueueTest {
}
}
/**
*
* @throws IOException
* @throws SQLException
*/
@After
public void tearDown() throws IOException, SQLException {
db.close();
@ -104,6 +117,9 @@ public class DataCacheGetQueueTest {
assertTrue("Errors were caught.", rows == rowsAgain);
}
/**
*
*/
@Test
public void testScheduleForGet() {
OfflinePlayer op = MockUtils.mockPlayer2();
@ -118,6 +134,9 @@ public class DataCacheGetQueueTest {
});
}
/**
*
*/
@Test
public void testStop() {
DataCacheGetQueue instance = new DataCacheGetQueue(plan);

View File

@ -20,9 +20,10 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.plugin.java.JavaPlugin;
import org.easymock.EasyMock;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
@ -32,7 +33,7 @@ import test.java.utils.TestInit;
/**
*
* @author Risto
* @author Rsl1122
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({JavaPlugin.class})
@ -40,9 +41,15 @@ public class DataCacheProcessQueueTest {
private DataCacheHandler handler;
/**
*
*/
public DataCacheProcessQueueTest() {
}
/**
*
*/
@Before
public void setUp() {
TestInit t = new TestInit();
@ -85,10 +92,17 @@ public class DataCacheProcessQueueTest {
};
}
/**
*
*/
@After
public void tearDown() {
}
/**
*
* @throws InterruptedException
*/
@Test
public void testAddToPool_HandlingInfo() throws InterruptedException {
DataCacheProcessQueue q = new DataCacheProcessQueue(handler);
@ -105,6 +119,10 @@ public class DataCacheProcessQueueTest {
}
/**
*
* @throws InterruptedException
*/
@Test
public void testAddToPool_Collection() throws InterruptedException {
DataCacheProcessQueue q = new DataCacheProcessQueue(handler);
@ -125,7 +143,11 @@ public class DataCacheProcessQueueTest {
assertTrue(q.stop().isEmpty());
}
@Test
/**
*
* @throws InterruptedException
*/
@Ignore @Test
public void testContainsUUID() throws InterruptedException {
DataCacheProcessQueue q = new DataCacheProcessQueue(handler);
UUID uuid = MockUtils.getPlayerUUID();

View File

@ -19,9 +19,10 @@ import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
import org.bukkit.plugin.java.JavaPlugin;
import org.easymock.EasyMock;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import static org.powermock.api.mockito.PowerMockito.when;
@ -32,7 +33,7 @@ import test.java.utils.TestInit;
/**
*
* @author Risto
* @author Rsl1122
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({JavaPlugin.class})
@ -43,9 +44,15 @@ public class DataCacheSaveQueueTest {
private boolean calledSaveUserData;
private boolean calledSaveUserData2;
/**
*
*/
public DataCacheSaveQueueTest() {
}
/**
*
*/
@Before
public void setUp() {
TestInit t = new TestInit();
@ -77,10 +84,17 @@ public class DataCacheSaveQueueTest {
when(plan.getDB()).thenReturn(db);
}
/**
*
*/
@After
public void tearDown() {
}
/**
*
* @throws InterruptedException
*/
@Test
public void testScheduleForSave_UserData() throws InterruptedException {
DataCacheSaveQueue q = new DataCacheSaveQueue(plan);
@ -90,6 +104,10 @@ public class DataCacheSaveQueueTest {
assertTrue(calledSaveUserData);
}
/**
*
* @throws InterruptedException
*/
@Test
public void testScheduleForSave_Collection() throws InterruptedException {
DataCacheSaveQueue q = new DataCacheSaveQueue(plan);
@ -104,6 +122,10 @@ public class DataCacheSaveQueueTest {
assertTrue(calledSaveUserData2);
}
/**
*
* @throws InterruptedException
*/
@Test
public void testScheduleNewPlayer() throws InterruptedException {
DataCacheSaveQueue q = new DataCacheSaveQueue(plan);
@ -113,6 +135,9 @@ public class DataCacheSaveQueueTest {
assertTrue(calledSaveUserData);
}
/**
*
*/
@Test
public void testContainsUUID() {
DataCacheSaveQueue q = new DataCacheSaveQueue(plan);
@ -122,7 +147,11 @@ public class DataCacheSaveQueueTest {
assertTrue(q.containsUUID(data.getUuid()));
}
@Test
/**
*
* @throws InterruptedException
*/
@Ignore @Test
public void testStop() throws InterruptedException {
DataCacheSaveQueue q = new DataCacheSaveQueue(plan);
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());

View File

@ -10,12 +10,11 @@ import main.java.com.djrapitops.plan.api.Gender;
import main.java.com.djrapitops.plan.data.DemographicsData;
import main.java.com.djrapitops.plan.data.UserData;
import main.java.com.djrapitops.plan.data.handling.ChatHandling;
import org.bukkit.GameMode;
import org.bukkit.plugin.java.JavaPlugin;
import org.easymock.EasyMock;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
@ -25,15 +24,21 @@ import test.java.utils.TestInit;
/**
*
* @author Risto
* @author Rsl1122
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest(JavaPlugin.class)
public class ChatHandlingTest {
/**
*
*/
public ChatHandlingTest() {
}
/**
*
*/
@Before
public void setUp() {
TestInit t = new TestInit();
@ -51,6 +56,9 @@ public class ChatHandlingTest {
// PowerMock.verify(JavaPlugin.class);
}
/**
*
*/
@Test
public void testProcessChatInfoAddedNickname() {
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
@ -59,6 +67,9 @@ public class ChatHandlingTest {
assertTrue("Didn't add nickname", data.getNicknames().contains(expected));
}
/**
*
*/
@Test
public void testUpdateDemographicInformationMale() {
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
@ -66,6 +77,9 @@ public class ChatHandlingTest {
assertTrue("Didn't update gender", data.getDemData().getGender() == Gender.MALE);
}
/**
*
*/
@Test
public void testUpdateDemographicInformationNoInfo() {
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
@ -74,6 +88,9 @@ public class ChatHandlingTest {
assertTrue("Updated age", data.getDemData().getAge() == -1);
}
/**
*
*/
@Test
public void testUpdateDemographicInformation100Age() {
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
@ -81,6 +98,9 @@ public class ChatHandlingTest {
assertTrue("Updated age", data.getDemData().getAge() == -1);
}
/**
*
*/
@Test
public void testUpdateDemographicInformationNoTrigger() {
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
@ -89,6 +109,9 @@ public class ChatHandlingTest {
assertTrue("Updated age", data.getDemData().getAge() == -1);
}
/**
*
*/
@Test
public void testUpdateDemographicInformationIgnore() {
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
@ -97,6 +120,9 @@ public class ChatHandlingTest {
assertTrue("Updated age", data.getDemData().getAge() == -1);
}
/**
*
*/
@Test
public void testUpdateDemographicInformationAge() {
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());

View File

@ -12,9 +12,9 @@ import main.java.com.djrapitops.plan.data.handling.GamemodeHandling;
import org.bukkit.GameMode;
import org.bukkit.plugin.java.JavaPlugin;
import org.easymock.EasyMock;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
@ -24,15 +24,21 @@ import test.java.utils.TestInit;
/**
*
* @author Risto
* @author Rsl1122
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest(JavaPlugin.class)
public class GamemodeHandlingTest {
/**
*
*/
public GamemodeHandlingTest() {
}
/**
*
*/
@Before
public void setUp() {
TestInit t = new TestInit();
@ -46,6 +52,9 @@ public class GamemodeHandlingTest {
// PowerMock.verify(JavaPlugin.class);
}
/**
*
*/
@Test
public void testProcessGamemodeInfo() {
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
@ -67,6 +76,9 @@ public class GamemodeHandlingTest {
assertTrue("Last swaptime was "+result, result == 1100L);
}
/**
*
*/
@Test
public void testProcessGamemodeInfoSameGM() {
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
@ -88,6 +100,9 @@ public class GamemodeHandlingTest {
assertTrue("Last swaptime was "+result, result == 1100L);
}
/**
*
*/
@Test
public void testProcessGamemodeInfoNullNewGM() {
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
@ -109,6 +124,9 @@ public class GamemodeHandlingTest {
assertTrue("Last swaptime was "+result, result == 50L);
}
/**
*
*/
@Test
public void testProcessGamemodeInfoNullOldGM() {
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
@ -130,6 +148,9 @@ public class GamemodeHandlingTest {
assertTrue("Last swaptime was "+result, result == 1100L);
}
/**
*
*/
@Test
public void testProcessGamemodeInfoNullGMTimes() {
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());

View File

@ -34,7 +34,7 @@ import test.java.utils.TestInit;
/**
*
* @author Risto
* @author Rsl1122
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest(JavaPlugin.class)
@ -43,9 +43,15 @@ public class KillHandlingTest {
private Database db;
private Plan plan;
/**
*
*/
public KillHandlingTest() {
}
/**
*
*/
@Before
public void setUp() {
TestInit t = new TestInit();
@ -71,11 +77,19 @@ public class KillHandlingTest {
PowerMock.replay(JavaPlugin.class);
}
/**
*
* @throws SQLException
*/
@After
public void tearDown() throws SQLException {
db.close();
}
/**
*
* @throws SQLException
*/
@Test
public void testProcessKillInfoPlayer() throws SQLException {
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
@ -91,6 +105,11 @@ public class KillHandlingTest {
assertEquals(expected.getWeapon(), result.getWeapon());
}
/**
*
* @throws SQLException
* @throws IOException
*/
@Ignore
@Test
public void testProcessKillInfoException() throws SQLException, IOException {
@ -100,6 +119,10 @@ public class KillHandlingTest {
assertTrue("Added the kill", data.getPlayerKills().isEmpty());
}
/**
*
* @throws SQLException
*/
@Test
public void testProcessKillInfoMob() throws SQLException {
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());

View File

@ -13,9 +13,9 @@ import main.java.com.djrapitops.plan.data.UserData;
import main.java.com.djrapitops.plan.data.handling.LoginHandling;
import org.bukkit.plugin.java.JavaPlugin;
import org.easymock.EasyMock;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
@ -25,15 +25,21 @@ import test.java.utils.TestInit;
/**
*
* @author Risto
* @author Rsl1122
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest(JavaPlugin.class)
public class LoginHandlingTest {
/**
*
*/
public LoginHandlingTest() {
}
/**
*
*/
@Before
public void setUp() {
TestInit t = new TestInit();
@ -47,6 +53,10 @@ public class LoginHandlingTest {
// PowerMock.verify(JavaPlugin.class);
}
/**
*
* @throws UnknownHostException
*/
@Test
public void testProcessLoginInfo() throws UnknownHostException {
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
@ -66,6 +76,10 @@ public class LoginHandlingTest {
assertTrue("Wrong location " + geo, geo.equals("United States"));
}
/**
*
* @throws UnknownHostException
*/
@Test
public void testUpdateGeolocation() throws UnknownHostException {
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());

View File

@ -11,9 +11,9 @@ import main.java.com.djrapitops.plan.data.UserData;
import main.java.com.djrapitops.plan.data.handling.LogoutHandling;
import org.bukkit.plugin.java.JavaPlugin;
import org.easymock.EasyMock;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
@ -23,15 +23,21 @@ import test.java.utils.TestInit;
/**
*
* @author Risto
* @author Rsl1122
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest(JavaPlugin.class)
public class LogoutHandlingTest {
/**
*
*/
public LogoutHandlingTest() {
}
/**
*
*/
@Before
public void setUp() {
TestInit t = new TestInit();
@ -46,6 +52,9 @@ public class LogoutHandlingTest {
// PowerMock.verify(JavaPlugin.class);
}
/**
*
*/
@Test
public void testProcessLogoutInfo() {
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());

View File

@ -9,13 +9,12 @@ import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.api.Gender;
import main.java.com.djrapitops.plan.data.DemographicsData;
import main.java.com.djrapitops.plan.data.UserData;
import main.java.com.djrapitops.plan.data.handling.ChatHandling;
import main.java.com.djrapitops.plan.data.handling.info.ChatInfo;
import org.bukkit.plugin.java.JavaPlugin;
import org.easymock.EasyMock;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
@ -25,12 +24,15 @@ import test.java.utils.TestInit;
/**
*
* @author Risto
* @author Rsl1122
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest(JavaPlugin.class)
public class ChatInfoTest {
/**
*
*/
@Before
public void setUp() {
TestInit t = new TestInit();
@ -48,21 +50,33 @@ public class ChatInfoTest {
// PowerMock.verify(JavaPlugin.class);
}
/**
*
*/
public ChatInfoTest() {
}
/**
*
*/
@Test
public void testGetNickname() {
ChatInfo i = new ChatInfo(null, "Test", "Message");
assertTrue("Nick get wrong", i.getNickname().equals("Test"));
}
/**
*
*/
@Test
public void testGetMessage() {
ChatInfo i = new ChatInfo(null, "Test", "Message");
assertTrue("Message get wrong", i.getMessage().equals("Message"));
}
/**
*
*/
@Test
public void testProcessNick() {
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
@ -73,6 +87,9 @@ public class ChatInfoTest {
assertTrue("Didn't update gender", data.getDemData().getGender() == Gender.MALE);
}
/**
*
*/
@Test
public void testProcessAge() {
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
@ -82,6 +99,9 @@ public class ChatInfoTest {
assertTrue("Didn't update age", data.getDemData().getAge() == 18);
}
/**
*
*/
@Test
public void testProcessGender() {
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
@ -91,6 +111,9 @@ public class ChatInfoTest {
assertTrue("Didn't update gender", data.getDemData().getGender() == Gender.MALE);
}
/**
*
*/
@Test
public void testProcessWrongUUID() {
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());

View File

@ -11,9 +11,9 @@ import main.java.com.djrapitops.plan.data.UserData;
import main.java.com.djrapitops.plan.data.handling.info.DeathInfo;
import org.bukkit.plugin.java.JavaPlugin;
import org.easymock.EasyMock;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
@ -23,15 +23,21 @@ import test.java.utils.TestInit;
/**
*
* @author Risto
* @author Rsl1122
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest(JavaPlugin.class)
public class DeathInfoTest {
/**
*
*/
public DeathInfoTest() {
}
/**
*
*/
@Before
public void setUp() {
TestInit t = new TestInit();
@ -45,6 +51,9 @@ public class DeathInfoTest {
// PowerMock.verify(JavaPlugin.class);
}
/**
*
*/
@Test
public void testProcess() {
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
@ -53,6 +62,9 @@ public class DeathInfoTest {
assertEquals(1, data.getDeaths());
}
/**
*
*/
@Test
public void testProcessWrongUUID() {
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());

View File

@ -12,9 +12,9 @@ import main.java.com.djrapitops.plan.data.handling.info.GamemodeInfo;
import org.bukkit.GameMode;
import org.bukkit.plugin.java.JavaPlugin;
import org.easymock.EasyMock;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
@ -24,15 +24,21 @@ import test.java.utils.TestInit;
/**
*
* @author Risto
* @author Rsl1122
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest(JavaPlugin.class)
public class GamemodeInfoTest {
/**
*
*/
public GamemodeInfoTest() {
}
/**
*
*/
@Before
public void setUp() {
TestInit t = new TestInit();
@ -46,6 +52,9 @@ public class GamemodeInfoTest {
// PowerMock.verify(JavaPlugin.class);
}
/**
*
*/
@Test
public void testProcess() {
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
@ -68,6 +77,9 @@ public class GamemodeInfoTest {
assertTrue("Last swaptime was "+result, result == 1100L);
}
/**
*
*/
@Test
public void testProcessWrongUUID() {
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
@ -90,6 +102,9 @@ public class GamemodeInfoTest {
assertTrue("Last swaptime was "+result, result == 50L);
}
/**
*
*/
@Test
public void testProcessNullGM() {
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());

View File

@ -14,13 +14,19 @@ import org.junit.Test;
/**
*
* @author Risto
* @author Rsl1122
*/
public class HandlingInfoTest {
/**
*
*/
public HandlingInfoTest() {
}
/**
*
*/
@Test
public void testGetUuid() {
UUID uuid = UUID.fromString("45b0dfdb-f71d-4cf3-8c21-27c9d4c651db");
@ -33,6 +39,9 @@ public class HandlingInfoTest {
assertEquals(uuid,i.getUuid());
}
/**
*
*/
@Test
public void testGetType() {
UUID uuid = UUID.fromString("45b0dfdb-f71d-4cf3-8c21-27c9d4c651db");
@ -45,6 +54,9 @@ public class HandlingInfoTest {
assertEquals(InfoType.CHAT,i.getType());
}
/**
*
*/
@Test
public void testGetTime() {
UUID uuid = UUID.fromString("45b0dfdb-f71d-4cf3-8c21-27c9d4c651db");

View File

@ -11,9 +11,9 @@ import main.java.com.djrapitops.plan.data.UserData;
import main.java.com.djrapitops.plan.data.handling.info.KickInfo;
import org.bukkit.plugin.java.JavaPlugin;
import org.easymock.EasyMock;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
@ -23,15 +23,21 @@ import test.java.utils.TestInit;
/**
*
* @author Risto
* @author Rsl1122
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest(JavaPlugin.class)
public class KickInfoTest {
/**
*
*/
public KickInfoTest() {
}
/**
*
*/
@Before
public void setUp() {
TestInit t = new TestInit();
@ -45,6 +51,9 @@ public class KickInfoTest {
// PowerMock.verify(JavaPlugin.class);
}
/**
*
*/
@Test
public void testProcess() {
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());

View File

@ -7,7 +7,6 @@ package test.java.main.java.com.djrapitops.plan.data.handling.info;
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.DemographicsData;
import main.java.com.djrapitops.plan.data.KillData;
@ -19,9 +18,9 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.easymock.EasyMock;
import org.junit.After;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import static org.powermock.api.mockito.PowerMockito.when;
@ -32,7 +31,7 @@ import test.java.utils.TestInit;
/**
*
* @author Risto
* @author Rsl1122
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest(JavaPlugin.class)
@ -40,9 +39,15 @@ public class KillInfoTest {
private Database db;
/**
*
*/
public KillInfoTest() {
}
/**
*
*/
@Before
public void setUp() {
TestInit t = new TestInit();
@ -68,11 +73,19 @@ public class KillInfoTest {
PowerMock.replay(JavaPlugin.class);
}
/**
*
* @throws SQLException
*/
@After
public void tearDown() throws SQLException {
db.close();
}
/**
*
* @throws SQLException
*/
@Test
public void testProcess() throws SQLException {
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
@ -89,6 +102,10 @@ public class KillInfoTest {
assertEquals(expected.getWeapon(), result.getWeapon());
}
/**
*
* @throws SQLException
*/
@Test
public void testProcessMobKill() throws SQLException {
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
@ -98,6 +115,10 @@ public class KillInfoTest {
assertEquals(1, data.getMobKills());
}
/**
*
* @throws SQLException
*/
@Test
public void testProcessMobKillWrongUUID() throws SQLException {
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());

View File

@ -14,9 +14,9 @@ import main.java.com.djrapitops.plan.data.handling.info.LoginInfo;
import org.bukkit.GameMode;
import org.bukkit.plugin.java.JavaPlugin;
import org.easymock.EasyMock;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
@ -26,15 +26,21 @@ import test.java.utils.TestInit;
/**
*
* @author Risto
* @author Rsl1122
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest(JavaPlugin.class)
public class LoginInfoTest {
/**
*
*/
public LoginInfoTest() {
}
/**
*
*/
@Before
public void setUp() {
TestInit t = new TestInit();
@ -48,6 +54,10 @@ public class LoginInfoTest {
// PowerMock.verify(JavaPlugin.class);
}
/**
*
* @throws UnknownHostException
*/
@Test
public void testProcess() throws UnknownHostException {
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
@ -67,6 +77,10 @@ public class LoginInfoTest {
assertTrue("Didn't process gamemode", data.getLastGamemode() == GameMode.CREATIVE);
}
/**
*
* @throws UnknownHostException
*/
@Test
public void testProcessWrongUUID() throws UnknownHostException {
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());

View File

@ -13,9 +13,9 @@ import main.java.com.djrapitops.plan.data.handling.info.LogoutInfo;
import org.bukkit.GameMode;
import org.bukkit.plugin.java.JavaPlugin;
import org.easymock.EasyMock;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
@ -25,15 +25,21 @@ import test.java.utils.TestInit;
/**
*
* @author Risto
* @author Rsl1122
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest(JavaPlugin.class)
public class LogoutInfoTest {
/**
*
*/
public LogoutInfoTest() {
}
/**
*
*/
@Before
public void setUp() {
TestInit t = new TestInit();
@ -48,6 +54,9 @@ public class LogoutInfoTest {
// PowerMock.verify(JavaPlugin.class);
}
/**
*
*/
@Test
public void testProcess() {
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
@ -65,6 +74,9 @@ public class LogoutInfoTest {
assertEquals(1, data.getSessions().size());
}
/**
*
*/
@Test
public void testProcessWrongUUID() {
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());

View File

@ -14,9 +14,9 @@ import main.java.com.djrapitops.plan.data.handling.info.ReloadInfo;
import org.bukkit.GameMode;
import org.bukkit.plugin.java.JavaPlugin;
import org.easymock.EasyMock;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
@ -26,15 +26,22 @@ import test.java.utils.TestInit;
/**
*
* @author Risto
* @author Rsl1122
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest(JavaPlugin.class)
public class ReloadInfoTest {
/**
*
*/
public ReloadInfoTest() {
}
@Before
/**
*
*/
@Before
public void setUp() {
TestInit t = new TestInit();
assertTrue("Not set up", t.setUp());
@ -46,6 +53,11 @@ public class ReloadInfoTest {
PowerMock.replay(JavaPlugin.class);
// PowerMock.verify(JavaPlugin.class);
}
/**
*
* @throws UnknownHostException
*/
@Test
public void testProcess() throws UnknownHostException {
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
@ -65,6 +77,10 @@ public class ReloadInfoTest {
assertTrue("Didn't process gamemode", data.getLastGamemode() == GameMode.CREATIVE);
}
/**
*
* @throws UnknownHostException
*/
@Test
public void testProcessWrongUUID() throws UnknownHostException {
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());

View File

@ -13,7 +13,6 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
@ -26,27 +25,26 @@ 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 org.bukkit.plugin.java.JavaPlugin;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.powermock.api.easymock.PowerMock;
import test.java.utils.TestInit;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.*;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.bukkit.scheduler.BukkitScheduler;
import org.easymock.EasyMock;
import org.junit.After;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import test.java.utils.MockUtils;
import test.java.utils.TestInit;
/**
*
* @author Risto
* @author Rsl1122
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({JavaPlugin.class, Bukkit.class, BukkitScheduler.class, BukkitRunnable.class})
@ -57,9 +55,17 @@ public class DatabaseTest {
private Database backup;
private int rows;
/**
*
*/
public DatabaseTest() {
}
/**
*
* @throws IOException
* @throws Exception
*/
@Before
public void setUp() throws IOException, Exception {
TestInit t = new TestInit();
@ -103,6 +109,11 @@ public class DatabaseTest {
// EasyMock.expect(Bukkit.getScheduler()).andReturn(mockScheduler);
}
/**
*
* @throws IOException
* @throws SQLException
*/
@After
public void tearDown() throws IOException, SQLException {
db.close();
@ -117,21 +128,33 @@ public class DatabaseTest {
assertTrue("Errors were caught.", rows == rowsAgain);
}
/**
*
*/
@Test
public void testInit() {
assertTrue("Database failed to init.", db.init());
}
/**
*
*/
@Test
public void testSqLiteGetConfigName() {
assertEquals("sqlite", db.getConfigName());
}
/**
*
*/
@Test
public void testSqLiteGetgName() {
assertEquals("SQLite", db.getName());
}
/**
*
*/
@Test
public void testMysqlGetConfigName() {
assertEquals("mysql", new MySQLDB(plan) {
@ -142,6 +165,9 @@ public class DatabaseTest {
}.getConfigName());
}
/**
*
*/
@Test
public void testMysqlGetName() {
assertEquals("MySQL", new MySQLDB(plan) {
@ -152,6 +178,10 @@ public class DatabaseTest {
}.getName());
}
/**
*
* @throws SQLException
*/
@Test
public void testRemoveAll() throws SQLException {
db.init();
@ -169,6 +199,10 @@ public class DatabaseTest {
assertTrue("Contains commandUse", db.getCommandUse().isEmpty());
}
/**
*
* @throws SQLException
*/
@Test
public void testSaveCommandUse() throws SQLException {
db.init();
@ -186,6 +220,10 @@ public class DatabaseTest {
assertTrue("Contains too long cmd", !db.getCommandUse().containsKey("/roiergbnougbierubieugbeigubeigubgierbgeugeg"));
}
/**
*
* @throws SQLException
*/
@Test
public void testSaveUserData() throws SQLException {
db.init();
@ -202,6 +240,10 @@ public class DatabaseTest {
db.giveUserDataToProcessors(data.getUuid(), process);
}
/**
*
* @throws SQLException
*/
@Test
public void testNicknameInjection() throws SQLException {
db.init();
@ -213,6 +255,10 @@ public class DatabaseTest {
assertTrue("Removed Users table.", db.getUserId(data2.getUuid().toString()) != -1);
}
/**
*
* @throws SQLException
*/
@Test
public void testSaveMultipleUserData() throws SQLException {
db.init();
@ -240,6 +286,10 @@ public class DatabaseTest {
db.giveUserDataToProcessors(data2.getUuid(), process2);
}
/**
*
* @throws SQLException
*/
@Test
public void testRemove() throws SQLException {
db.init();
@ -249,6 +299,10 @@ public class DatabaseTest {
assertTrue("Contains the user", !db.wasSeenBefore(data.getUuid()));
}
/**
*
* @throws SQLException
*/
@Test
public void testBackup() throws SQLException {
db.init();
@ -271,6 +325,10 @@ public class DatabaseTest {
assertTrue("Didn't contain 2", savedUUIDs.contains(data2.getUuid()));
}
/**
*
* @throws SQLException
*/
@Test
public void testRestore() throws SQLException {
db.init();

View File

@ -6,18 +6,24 @@
package test.java.main.java.com.djrapitops.plan.ui;
import main.java.com.djrapitops.plan.ui.Html;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Test;
/**
*
* @author Risto
* @author Rsl1122
*/
public class HtmlTest {
/**
*
*/
public HtmlTest() {
}
/**
*
*/
@Test
public void testParse_0args() {
Html instance = Html.REPLACE0;
@ -26,6 +32,9 @@ public class HtmlTest {
assertEquals(expResult, result);
}
/**
*
*/
@Test
public void testParse_StringArr() {
Html instance = Html.REPLACE0;
@ -34,6 +43,9 @@ public class HtmlTest {
assertEquals(expResult, result);
}
/**
*
*/
@Test
public void testSetHtml() {
Html instance = Html.REPLACE0;
@ -43,6 +55,9 @@ public class HtmlTest {
assertEquals(expResult, result);
}
/**
*
*/
@Test
public void testNoBackSlash() {
assertTrue("Null for some reason", Html.TABLELINE_2.parse("/\\", "0") != null);

View File

@ -11,18 +11,24 @@ import java.util.List;
import java.util.Random;
import main.java.com.djrapitops.plan.data.SessionData;
import main.java.com.djrapitops.plan.ui.graphs.PlayerActivityGraphCreator;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Test;
/**
*
* @author Risto
* @author Rsl1122
*/
public class PlayerActivityGraphCreatorTest {
/**
*
*/
public PlayerActivityGraphCreatorTest() {
}
/**
*
*/
@Test
public void testGenerateDataArray() {
List<SessionData> sessionData = createRandomSessionDataList();
@ -31,6 +37,10 @@ public class PlayerActivityGraphCreatorTest {
assertTrue("0", 0 < result.length());
}
/**
*
* @return
*/
public static List<SessionData> createRandomSessionDataList() {
List<SessionData> list = new ArrayList<>();
Random r = new Random();

View File

@ -14,9 +14,9 @@ import main.java.com.djrapitops.plan.data.SessionData;
import main.java.com.djrapitops.plan.utilities.AnalysisUtils;
import org.bukkit.plugin.java.JavaPlugin;
import org.easymock.EasyMock;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
@ -25,15 +25,21 @@ import test.java.utils.TestInit;
/**
*
* @author Risto
* @author Rsl1122
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest(JavaPlugin.class)
public class AnalysisUtilsTest {
/**
*
*/
public AnalysisUtilsTest() {
}
/**
*
*/
@Before
public void setUp() {
TestInit t = new TestInit();
@ -47,6 +53,9 @@ public class AnalysisUtilsTest {
// PowerMock.verify(JavaPlugin.class);
}
/**
*
*/
@Test
public void testIsActive() {
long lastPlayed = new Date().getTime();
@ -57,6 +66,9 @@ public class AnalysisUtilsTest {
assertEquals(expResult, result);
}
/**
*
*/
@Test
public void testIsNotActive2() {
long lastPlayed = new Date().getTime();
@ -67,6 +79,9 @@ public class AnalysisUtilsTest {
assertEquals(expResult, result);
}
/**
*
*/
@Test
public void testIsNotActive3() {
long lastPlayed = new Date().getTime();
@ -77,6 +92,9 @@ public class AnalysisUtilsTest {
assertEquals(expResult, result);
}
/**
*
*/
@Test
public void testIsNotActive() {
long lastPlayed = 0L;
@ -87,6 +105,9 @@ public class AnalysisUtilsTest {
assertEquals(expResult, result);
}
/**
*
*/
@Test
public void testGetNewPlayers() {
List<Long> registered = new ArrayList<>();
@ -99,6 +120,9 @@ public class AnalysisUtilsTest {
assertEquals(expResult, result);
}
/**
*
*/
@Test
public void testGetNewPlayersEmpty() {
List<Long> registered = new ArrayList<>();
@ -109,6 +133,9 @@ public class AnalysisUtilsTest {
assertEquals(expResult, result);
}
/**
*
*/
@Test
public void testTransformSessionDataToLengths() {
Collection<SessionData> data = new ArrayList<>();
@ -122,6 +149,9 @@ public class AnalysisUtilsTest {
assertEquals(expResult, result);
}
/**
*
*/
@Test
public void testAverage() {
Collection<Long> o = new ArrayList<>();
@ -135,6 +165,9 @@ public class AnalysisUtilsTest {
assertEquals(expResult, result);
}
/**
*
*/
@Test
public void testAverageEmpty() {
Collection<Long> list = new ArrayList<>();

View File

@ -8,20 +8,26 @@ package test.java.main.java.com.djrapitops.plan.utilities;
import java.util.Date;
import main.java.com.djrapitops.plan.utilities.FormatUtils;
import org.bukkit.Location;
import org.junit.Test;
import static org.junit.Assert.*;
import org.bukkit.World;
import static org.junit.Assert.*;
import org.junit.Test;
import test.java.utils.*;
/**
*
* @author Risto
* @author Rsl1122
*/
public class FormatUtilsTest {
/**
*
*/
public FormatUtilsTest() {
}
/**
*
*/
@Test
public void testFormatTimeAmount() {
String string = "" + 1000L;
@ -30,6 +36,9 @@ public class FormatUtilsTest {
assertEquals(expResult, result);
}
/**
*
*/
@Test
public void testFormatTimeAmountSinceDate() {
Date before = new Date(300000L);
@ -39,6 +48,9 @@ public class FormatUtilsTest {
assertEquals(expResult, result);
}
/**
*
*/
@Test
public void testFormatTimeStamp() {
String string = "0";
@ -47,6 +59,9 @@ public class FormatUtilsTest {
assertEquals(expResult, result);
}
/**
*
*/
@Test
public void testFormatTimeAmountSinceString() {
String string = "" + new Date(310000L).toInstant().getEpochSecond() * 1000L;
@ -56,6 +71,9 @@ public class FormatUtilsTest {
assertEquals(expResult, result);
}
/**
*
*/
@Test
public void testRemoveLetters() {
String dataPoint = "435729847jirggu.eiwb¤#¤%¤#";
@ -64,6 +82,9 @@ public class FormatUtilsTest {
assertEquals(expResult, result);
}
/**
*
*/
@Test
public void testParseVersionNumber() {
String versionString = "2.10.2";
@ -72,6 +93,9 @@ public class FormatUtilsTest {
assertEquals(expResult, result);
}
/**
*
*/
@Test
public void testVersionNumber() {
String versionString = "2.10.2";
@ -81,6 +105,9 @@ public class FormatUtilsTest {
assertTrue("Higher version not higher", result > result2);
}
/**
*
*/
@Test
public void testMergeArrays() {
String[][] arrays = new String[][]{new String[]{"Test", "One"}, new String[]{"Test", "Two"}};
@ -89,6 +116,9 @@ public class FormatUtilsTest {
assertArrayEquals(expResult, result);
}
/**
*
*/
@Test
public void testFormatLocation() {
World mockWorld = MockUtils.mockWorld();
@ -98,6 +128,9 @@ public class FormatUtilsTest {
assertEquals(expResult, result);
}
/**
*
*/
@Test
public void testCutDecimals() {
double d = 0.05234;
@ -105,6 +138,10 @@ public class FormatUtilsTest {
String result = FormatUtils.cutDecimals(d);
assertEquals(expResult, result);
}
/**
*
*/
@Test
public void testCutDecimals2() {
double d = 0.05634;

View File

@ -11,9 +11,9 @@ import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.utilities.HtmlUtils;
import org.bukkit.plugin.java.JavaPlugin;
import org.easymock.EasyMock;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
@ -22,15 +22,21 @@ import test.java.utils.TestInit;
/**
*
* @author Risto
* @author Rsl1122
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest(JavaPlugin.class)
public class HtmlUtilsTest {
/**
*
*/
public HtmlUtilsTest() {
}
/**
*
*/
@Before
public void setUp() {
TestInit t = new TestInit();
@ -45,6 +51,10 @@ public class HtmlUtilsTest {
// PowerMock.verify(JavaPlugin.class);
}
/**
*
* @throws Exception
*/
@Test
public void testGetHtmlStringFromResource() throws Exception {
String fileName = "player.html";
@ -53,6 +63,9 @@ public class HtmlUtilsTest {
assertTrue("Result empty", !result.isEmpty());
}
/**
*
*/
@Test
public void testReplacePlaceholders() {
String html = "%test%";
@ -63,6 +76,9 @@ public class HtmlUtilsTest {
assertEquals(expResult, result);
}
/**
*
*/
@Test
public void testReplacePlaceholdersBackslash() {
HashMap<String, String> replace = new HashMap<>();
@ -72,6 +88,10 @@ public class HtmlUtilsTest {
assertEquals(result, exp);
}
/**
*
* @throws FileNotFoundException
*/
@Test
public void testGetServerAnalysisUrl() throws FileNotFoundException {
String result = HtmlUtils.getServerAnalysisUrl();
@ -79,6 +99,9 @@ public class HtmlUtilsTest {
assertEquals(exp, result);
}
/**
*
*/
@Test
public void testGetInspectUrl() {
String playerName = "Test";
@ -87,6 +110,9 @@ public class HtmlUtilsTest {
assertEquals(expResult, result);
}
/**
*
*/
@Test
public void testRemoveXSS() {
String xss = "<script></script><!--";

View File

@ -5,7 +5,6 @@
*/
package test.java.main.java.com.djrapitops.plan.utilities;
import java.util.HashSet;
import java.util.Set;
import main.java.com.djrapitops.plan.Phrase;
import main.java.com.djrapitops.plan.Plan;
@ -13,12 +12,11 @@ import main.java.com.djrapitops.plan.utilities.MiscUtils;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.easymock.EasyMock;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
@ -28,15 +26,21 @@ import test.java.utils.TestInit;
/**
*
* @author Risto
* @author Rsl1122
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({JavaPlugin.class, Bukkit.class})
public class MiscUtilsTest {
/**
*
*/
public MiscUtilsTest() {
}
/**
*
*/
@Before
public void setUp() {
TestInit t = new TestInit();
@ -56,6 +60,9 @@ public class MiscUtilsTest {
PowerMock.replay(Bukkit.class);
}
/**
*
*/
@Test
public void testCheckVersion() {
String versionG = "2.10.9";
@ -64,6 +71,9 @@ public class MiscUtilsTest {
assertEquals(exp, result);
}
/**
*
*/
@Test
public void testCheckVersion2() {
String result = MiscUtils.checkVersion("3.0.0", "2.10.9");
@ -71,6 +81,9 @@ public class MiscUtilsTest {
assertEquals(exp, result);
}
/**
*
*/
@Test
public void testCheckVersion3() {
String result = MiscUtils.checkVersion("2.11.0", "2.10.9");
@ -78,6 +91,9 @@ public class MiscUtilsTest {
assertEquals(exp, result);
}
/**
*
*/
@Test
public void testCheckVersion4() {
String result = MiscUtils.checkVersion("2.11.0", "2.11.0");
@ -85,6 +101,9 @@ public class MiscUtilsTest {
assertEquals(exp, result);
}
/**
*
*/
@Test
public void testGetPlayerDisplaynameArgsPerm() {
String[] args = new String[]{"Rsl1122", "Test"};
@ -94,6 +113,9 @@ public class MiscUtilsTest {
assertEquals(expResult, result);
}
/**
*
*/
@Test
public void testGetPlayerDisplaynameArgsNoPerm() {
String[] args = new String[]{"Rsl1122", "Test"};
@ -103,6 +125,9 @@ public class MiscUtilsTest {
assertEquals(expResult, result);
}
/**
*
*/
@Test
public void testGetPlayerDisplaynameNoArgsPerm() {
String[] args = new String[]{};
@ -112,6 +137,9 @@ public class MiscUtilsTest {
assertEquals(expResult, result);
}
/**
*
*/
@Test
public void testGetPlayerDisplaynameNoArgsNoPerm() {
String[] args = new String[]{};
@ -121,6 +149,9 @@ public class MiscUtilsTest {
assertEquals(expResult, result);
}
/**
*
*/
@Test
public void testGetPlayerDisplaynameOwnNameNoPerm() {
String[] args = new String[]{"testname2"};
@ -130,6 +161,9 @@ public class MiscUtilsTest {
assertEquals(expResult, result);
}
/**
*
*/
@Test
public void testGetPlayerDisplaynameConsole() {
String[] args = new String[]{"TestConsoleSender"};
@ -139,6 +173,9 @@ public class MiscUtilsTest {
assertEquals(expResult, result);
}
/**
*
*/
@Test
public void testGetMatchingDisplaynames() {
String search = "testname";
@ -155,6 +192,9 @@ public class MiscUtilsTest {
}
}
/**
*
*/
@Test
public void testGetMatchingDisplaynames2() {
String search = "2";

View File

@ -28,15 +28,21 @@ import test.java.utils.TestInit;
/**
*
* @author Risto
* @author Rsl1122
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest(JavaPlugin.class)
public class NewPlayerCreatorTest {
/**
*
*/
public NewPlayerCreatorTest() {
}
/**
*
*/
@Before
public void setUp() {
TestInit t = new TestInit();
@ -52,10 +58,16 @@ public class NewPlayerCreatorTest {
PowerMock.replay(JavaPlugin.class);
}
/**
*
*/
@After
public void tearDown() {
}
/**
*
*/
@Test
public void testCreateNewPlayer_Player() {
OfflinePlayer p = MockUtils.mockPlayer2();
@ -73,6 +85,9 @@ public class NewPlayerCreatorTest {
assertTrue(exp.equals(result));
}
/**
*
*/
@Test
public void testCreateNewPlayer_OfflinePlayer() {
Player p = MockUtils.mockPlayer2();
@ -90,6 +105,9 @@ public class NewPlayerCreatorTest {
assertTrue(exp.equals(result));
}
/**
*
*/
@Test
public void testCreateNewPlayer_OfflinePlayer_GameMode() {
Player p = MockUtils.mockPlayer();

View File

@ -17,13 +17,19 @@ import org.junit.Test;
/**
*
* @author Risto
* @author Rsl1122
*/
public class HandlingInfoTimeComparatorTest {
/**
*
*/
public HandlingInfoTimeComparatorTest() {
}
/**
*
*/
@Test
public void testCompare() {
List<HandlingInfo> i = new ArrayList<>();

View File

@ -1,12 +1,12 @@
package test.java.utils;
import java.util.UUID;
import org.bukkit.World;
import org.mockito.Mockito;
import org.bukkit.entity.Player;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import static org.powermock.api.mockito.PowerMockito.when;
@ -16,12 +16,20 @@ import static org.powermock.api.mockito.PowerMockito.when;
*/
public class MockUtils {
/**
*
* @return
*/
public static World mockWorld() {
World mockWorld = Mockito.mock(World.class);
Mockito.doReturn("World").when(mockWorld).toString();
return mockWorld;
}
/**
*
* @return
*/
public static Player mockPlayer() {
Player p = PowerMockito.mock(Player.class);
when(p.getGameMode()).thenReturn(GameMode.SURVIVAL);
@ -37,10 +45,18 @@ public class MockUtils {
return p;
}
/**
*
* @return
*/
public static UUID getPlayerUUID() {
return UUID.fromString("45b0dfdb-f71d-4cf3-8c21-27c9d4c651db");
}
/**
*
* @return
*/
public static Player mockPlayer2() {
Player p = PowerMockito.mock(Player.class);
when(p.getGameMode()).thenReturn(GameMode.SPECTATOR);
@ -56,10 +72,18 @@ public class MockUtils {
return p;
}
/**
*
* @return
*/
public static UUID getPlayer2UUID() {
return UUID.fromString("ec94a954-1fa1-445b-b09b-9b698519af80");
}
/**
*
* @return
*/
public static Player mockBrokenPlayer() {
Player p = PowerMockito.mock(Player.class);
when(p.getGameMode()).thenReturn(GameMode.SURVIVAL);
@ -74,6 +98,10 @@ public class MockUtils {
return p;
}
/**
*
* @return
*/
public static CommandSender mockConsoleSender() {
CommandSender s = PowerMockito.mock(CommandSender.class);
return s;

View File

@ -9,22 +9,29 @@ import java.io.File;
import java.io.FileInputStream;
import java.nio.file.Files;
import main.java.com.djrapitops.plan.Plan;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.Server;
import org.bukkit.configuration.file.YamlConfiguration;
import org.powermock.api.mockito.PowerMockito;
import static org.powermock.api.mockito.PowerMockito.when;
/**
*
* @author Risto
* @author Rsl1122
*/
public class TestInit {
private Plan planMock;
/**
*
*/
public TestInit() {
}
/**
*
* @return
*/
public boolean setUp() {
try {
planMock = PowerMockito.mock(Plan.class);
@ -65,6 +72,10 @@ public class TestInit {
}
}
/**
*
* @return
*/
public Plan getPlanMock() {
return planMock;
}