diff --git a/Plan/pom.xml b/Plan/pom.xml index b1013bad4..9884b1c70 100644 --- a/Plan/pom.xml +++ b/Plan/pom.xml @@ -11,6 +11,10 @@ spigot-repo https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + destroystokyo-repo + https://repo.destroystokyo.com/repository/maven-public// + @@ -20,6 +24,13 @@ 1.12-R0.1-SNAPSHOT provided + + + com.destroystokyo.paper + paper-api + 1.12-R0.1-SNAPSHOT + provided + com.djrapitops diff --git a/Plan/src/main/java/com/djrapitops/plan/ServerVariableHolder.java b/Plan/src/main/java/com/djrapitops/plan/ServerVariableHolder.java index 15b06112d..785e2ce87 100644 --- a/Plan/src/main/java/com/djrapitops/plan/ServerVariableHolder.java +++ b/Plan/src/main/java/com/djrapitops/plan/ServerVariableHolder.java @@ -13,6 +13,7 @@ public class ServerVariableHolder { private final int maxPlayers; private final String ip; + private final boolean usingPaper; /** * Constructor, grabs the variables. @@ -22,6 +23,7 @@ public class ServerVariableHolder { public ServerVariableHolder(Server server) { maxPlayers = server.getMaxPlayers(); ip = server.getIp(); + usingPaper = server.getName().equals("Paper"); } /** @@ -41,4 +43,13 @@ public class ServerVariableHolder { public String getIp() { return ip; } + + /** + * Returns if the server is using PaperSpigot. + * + * @return if the server is using PaperSpigot. + */ + public boolean isUsingPaper() { + return usingPaper; + } } diff --git a/Plan/src/main/java/com/djrapitops/plan/Settings.java b/Plan/src/main/java/com/djrapitops/plan/Settings.java index 73cd99808..519bb62e1 100644 --- a/Plan/src/main/java/com/djrapitops/plan/Settings.java +++ b/Plan/src/main/java/com/djrapitops/plan/Settings.java @@ -24,6 +24,7 @@ public enum Settings { GATHERGMTIMES("Settings.Data.GamemodeChangeListener"), GATHERCOMMANDS("Settings.Data.GatherCommandUsage"), DO_NOT_LOG_UNKNOWN_COMMANDS("Customization.Data.DoNotLogUnknownCommands"), + COMBINE_COMMAND_ALIASES_TO_MAIN_COMMAND("Customization.Data.CombineCommandAliasesToMainCommand"), SECURITY_IP_UUID("Settings.WebServer.Security.DisplayIPsAndUUIDs"), GRAPH_PLAYERS_USEMAXPLAYERS_SCALE("Customization.Graphs.PlayersOnlineGraph.UseMaxPlayersAsScale"), PLAYERLIST_SHOW_IMAGES("Customization.SmallHeadImagesOnAnalysisPlayerlist"), diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/AnalyzeCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/AnalyzeCommand.java index cba764e6d..2cb49b8aa 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/AnalyzeCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/AnalyzeCommand.java @@ -45,10 +45,10 @@ public class AnalyzeCommand extends SubCommand { @Override public boolean onCommand(ISender sender, String commandLabel, String[] args) { - if (!Check.isTrue(ConditionUtils.pluginHasViewCapability(), Phrase.ERROR_WEBSERVER_OFF_ANALYSIS + "", sender)) { + if (!Check.isTrue(ConditionUtils.pluginHasViewCapability(), Phrase.ERROR_WEBSERVER_OFF_ANALYSIS.toString(), sender)) { return true; } - if (!Check.isTrue(analysisCache.isAnalysisEnabled(), Phrase.ERROR_ANALYSIS_DISABLED_TEMPORARILY + "", sender)) { + if (!Check.isTrue(analysisCache.isAnalysisEnabled(), Phrase.ERROR_ANALYSIS_DISABLED_TEMPORARILY.toString(), sender)) { if (!analysisCache.isCached()) { return true; } @@ -117,13 +117,13 @@ public class AnalyzeCommand extends SubCommand { */ private void sendAnalysisMessage(ISender sender) { boolean textUI = Settings.USE_ALTERNATIVE_UI.isTrue(); - sender.sendMessage(Phrase.CMD_ANALYZE_HEADER + ""); + sender.sendMessage(Phrase.CMD_ANALYZE_HEADER.toString()); if (textUI) { sender.sendMessage(TextUI.getAnalysisMessages()); } else { // Link String url = HtmlUtils.getServerAnalysisUrlWithProtocol(); - String message = Phrase.CMD_LINK + ""; + String message = Phrase.CMD_LINK.toString(); boolean console = !CommandUtils.isPlayer(sender); if (console) { sender.sendMessage(message + url); diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/InfoCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/InfoCommand.java index f55a14564..c4d4d84de 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/InfoCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/InfoCommand.java @@ -25,7 +25,7 @@ public class InfoCommand extends SubCommand { * @param plugin Current instance of Plan */ public InfoCommand(Plan plugin) { - super("info", CommandType.CONSOLE, Permissions.INFO.getPermission(), Phrase.CMD_USG_INFO + ""); + super("info", CommandType.CONSOLE, Permissions.INFO.getPermission(), Phrase.CMD_USG_INFO.toString()); this.plugin = plugin; } @@ -34,11 +34,11 @@ public class InfoCommand extends SubCommand { public boolean onCommand(ISender sender, String commandLabel, String[] args) { ChatColor tColor = Phrase.COLOR_SEC.color(); String[] messages = { - Phrase.CMD_INFO_HEADER + "", + Phrase.CMD_INFO_HEADER.toString(), Phrase.CMD_INFO_VERSION.parse(plugin.getDescription().getVersion()), Phrase.CMD_BALL.toString() + tColor + " " + Version.checkVersion(plugin), Phrase.CMD_MANAGE_STATUS_ACTIVE_DB.parse(plugin.getDB().getConfigName()), - Phrase.CMD_FOOTER + "" + Phrase.CMD_FOOTER.toString() }; sender.sendMessage(messages); return true; diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/InspectCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/InspectCommand.java index 695a0fb14..d6d8383bc 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/InspectCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/InspectCommand.java @@ -7,13 +7,7 @@ import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.command.SubCommand; import com.djrapitops.plugin.task.AbsRunnable; import com.djrapitops.plugin.utilities.Verify; -import java.sql.SQLException; -import java.util.UUID; -import main.java.com.djrapitops.plan.Log; -import main.java.com.djrapitops.plan.Permissions; -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.*; import main.java.com.djrapitops.plan.command.ConditionUtils; import main.java.com.djrapitops.plan.data.cache.InspectCacheHandler; import main.java.com.djrapitops.plan.ui.text.TextUI; @@ -25,6 +19,9 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandException; +import java.sql.SQLException; +import java.util.UUID; + /** * This command is used to cache UserData to InspectCache and display the link. * @@ -42,7 +39,7 @@ public class InspectCommand extends SubCommand { * @param plugin Current instance of Plan */ public InspectCommand(Plan plugin) { - super("inspect", CommandType.CONSOLE_WITH_ARGUMENTS, Permissions.INSPECT.getPermission(), Phrase.CMD_USG_INSPECT + "", Phrase.ARG_PLAYER + ""); + super("inspect", CommandType.CONSOLE_WITH_ARGUMENTS, Permissions.INSPECT.getPermission(), Phrase.CMD_USG_INSPECT.toString(), Phrase.ARG_PLAYER.toString()); this.plugin = plugin; inspectCache = plugin.getInspectCache(); @@ -50,7 +47,7 @@ public class InspectCommand extends SubCommand { @Override public boolean onCommand(ISender sender, String commandLabel, String[] args) { - if (!Check.isTrue(ConditionUtils.pluginHasViewCapability(), Phrase.ERROR_WEBSERVER_OFF_INSPECT + "", sender)) { + if (!Check.isTrue(ConditionUtils.pluginHasViewCapability(), Phrase.ERROR_WEBSERVER_OFF_INSPECT.toString(), sender)) { return true; } diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageBackupCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageBackupCommand.java index c88b9f27d..08e1e4378 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageBackupCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageBackupCommand.java @@ -29,7 +29,7 @@ public class ManageBackupCommand extends SubCommand { * @param plugin Current instance of Plan */ public ManageBackupCommand(Plan plugin) { - super("backup", CommandType.CONSOLE, Permissions.MANAGE.getPermission(), Phrase.CMD_USG_MANAGE_BACKUP + "", ""); + super("backup", CommandType.CONSOLE, Permissions.MANAGE.getPermission(), Phrase.CMD_USG_MANAGE_BACKUP.toString(), ""); this.plugin = plugin; } @@ -37,7 +37,7 @@ public class ManageBackupCommand extends SubCommand { @Override public boolean onCommand(ISender sender, String commandLabel, String[] args) { try { - if (!Check.isTrue(args.length >= 1, Phrase.COMMAND_REQUIRES_ARGUMENTS.parse(Phrase.USE_BACKUP + ""), sender)) { + if (!Check.isTrue(args.length >= 1, Phrase.COMMAND_REQUIRES_ARGUMENTS.parse(Phrase.USE_BACKUP.toString()), sender)) { return true; } String dbName = args[0].toLowerCase(); @@ -49,14 +49,14 @@ public class ManageBackupCommand extends SubCommand { final Database database = ManageUtils.getDB(plugin, dbName); // If DB is null return - if (!Check.isTrue(Verify.notNull(database), Phrase.MANAGE_DATABASE_FAILURE + "", sender)) { + if (!Check.isTrue(Verify.notNull(database), Phrase.MANAGE_DATABASE_FAILURE.toString(), sender)) { Log.error(dbName + " was null!"); return true; } runBackupTask(sender, args, database); } catch (NullPointerException e) { - sender.sendMessage(Phrase.MANAGE_DATABASE_FAILURE + ""); + sender.sendMessage(Phrase.MANAGE_DATABASE_FAILURE.toString()); } return true; } diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageCleanCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageCleanCommand.java index 771103994..4da62da1a 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageCleanCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageCleanCommand.java @@ -29,14 +29,14 @@ public class ManageCleanCommand extends SubCommand { * @param plugin Current instance of Plan */ public ManageCleanCommand(Plan plugin) { - super("clean", CommandType.CONSOLE_WITH_ARGUMENTS, Permissions.MANAGE.getPermission(), Phrase.CMD_USG_MANAGE_CLEAN + "", ""); + super("clean", CommandType.CONSOLE_WITH_ARGUMENTS, Permissions.MANAGE.getPermission(), Phrase.CMD_USG_MANAGE_CLEAN.toString(), ""); this.plugin = plugin; } @Override public boolean onCommand(ISender sender, String commandLabel, String[] args) { - if (!Check.isTrue(args.length != 0, Phrase.COMMAND_REQUIRES_ARGUMENTS_ONE + "", sender)) { + if (!Check.isTrue(args.length != 0, Phrase.COMMAND_REQUIRES_ARGUMENTS_ONE.toString(), sender)) { return true; } String dbName = args[0].toLowerCase(); @@ -49,7 +49,7 @@ public class ManageCleanCommand extends SubCommand { final Database database = ManageUtils.getDB(plugin, dbName); // If DB is null return - if (!Check.isTrue(Verify.notNull(database), Phrase.MANAGE_DATABASE_FAILURE + "", sender)) { + if (!Check.isTrue(Verify.notNull(database), Phrase.MANAGE_DATABASE_FAILURE.toString(), sender)) { Log.error(dbName + " was null!"); return true; } @@ -64,7 +64,7 @@ public class ManageCleanCommand extends SubCommand { public void run() { sender.sendMessage(Phrase.MANAGE_PROCESS_START.parse()); database.clean(); - sender.sendMessage(Phrase.MANAGE_SUCCESS + ""); + sender.sendMessage(Phrase.MANAGE_SUCCESS.toString()); this.cancel(); } }).runTaskAsynchronously(); diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageClearCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageClearCommand.java index 4a4f9c6d7..4bbe0ae39 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageClearCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageClearCommand.java @@ -71,9 +71,9 @@ public class ManageClearCommand extends SubCommand { sender.sendMessage(Phrase.MANAGE_PROCESS_START.parse()); if (database.removeAllData()) { - sender.sendMessage(Phrase.MANAGE_CLEAR_SUCCESS + ""); + sender.sendMessage(Phrase.MANAGE_CLEAR_SUCCESS.toString()); } else { - sender.sendMessage(Phrase.MANAGE_PROCESS_FAIL + ""); + sender.sendMessage(Phrase.MANAGE_PROCESS_FAIL.toString()); } } finally { this.cancel(); diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageHotswapCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageHotswapCommand.java index 197b6c253..b9bf70b64 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageHotswapCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageHotswapCommand.java @@ -29,14 +29,14 @@ public class ManageHotswapCommand extends SubCommand { * @param plugin Current instance of Plan */ public ManageHotswapCommand(Plan plugin) { - super("hotswap", CommandType.CONSOLE_WITH_ARGUMENTS, Permissions.MANAGE.getPermission(), Phrase.CMD_USG_MANAGE_HOTSWAP + "", ""); + super("hotswap", CommandType.CONSOLE_WITH_ARGUMENTS, Permissions.MANAGE.getPermission(), Phrase.CMD_USG_MANAGE_HOTSWAP.toString(), ""); this.plugin = plugin; } @Override public boolean onCommand(ISender sender, String commandLabel, String[] args) { - if (!Check.isTrue(args.length >= 1, Phrase.COMMAND_REQUIRES_ARGUMENTS_ONE + "", sender)) { + if (!Check.isTrue(args.length >= 1, Phrase.COMMAND_REQUIRES_ARGUMENTS_ONE.toString(), sender)) { return true; } String dbName = args[0].toLowerCase(); @@ -53,7 +53,7 @@ public class ManageHotswapCommand extends SubCommand { final Database database = ManageUtils.getDB(plugin, dbName); // If DB is null return - if (!Check.isTrue(Verify.notNull(database), Phrase.MANAGE_DATABASE_FAILURE + "", sender)) { + if (!Check.isTrue(Verify.notNull(database), Phrase.MANAGE_DATABASE_FAILURE.toString(), sender)) { Log.error(dbName + " was null!"); return true; } @@ -62,7 +62,7 @@ public class ManageHotswapCommand extends SubCommand { database.getVersion(); //Test db connection } catch (Exception e) { Log.toLog(this.getClass().getName(), e); - sender.sendMessage(Phrase.MANAGE_DATABASE_FAILURE + ""); + sender.sendMessage(Phrase.MANAGE_DATABASE_FAILURE.toString()); return true; } diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageImportCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageImportCommand.java index b3c1a7e5b..671f422a3 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageImportCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageImportCommand.java @@ -37,7 +37,7 @@ public class ManageImportCommand extends SubCommand { * @param plugin Current instance of Plan */ public ManageImportCommand(Plan plugin) { - super("import", CommandType.CONSOLE, Permissions.MANAGE.getPermission(), Phrase.CMD_USG_MANAGE_IMPORT + "", Phrase.ARG_IMPORT + ""); + super("import", CommandType.CONSOLE, Permissions.MANAGE.getPermission(), Phrase.CMD_USG_MANAGE_IMPORT.toString(), Phrase.ARG_IMPORT.toString()); this.plugin = plugin; } @@ -74,12 +74,12 @@ public class ManageImportCommand extends SubCommand { @Override public void run() { try { - sender.sendMessage(Phrase.MANAGE_IMPORTING + ""); + sender.sendMessage(Phrase.MANAGE_IMPORTING.toString()); List uuids = Fetch.getIOfflinePlayers().stream().map(IOfflinePlayer::getUniqueId).collect(Collectors.toList()); if (importer.importData(uuids, importArguments)) { - sender.sendMessage(Phrase.MANAGE_SUCCESS + ""); + sender.sendMessage(Phrase.MANAGE_SUCCESS.toString()); } else { - sender.sendMessage(Phrase.MANAGE_PROCESS_FAIL + ""); + sender.sendMessage(Phrase.MANAGE_PROCESS_FAIL.toString()); } } finally { this.cancel(); diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageMoveCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageMoveCommand.java index 305e2f608..a91c2a744 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageMoveCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageMoveCommand.java @@ -5,8 +5,6 @@ import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.command.SubCommand; import com.djrapitops.plugin.task.AbsRunnable; import com.djrapitops.plugin.utilities.Verify; -import java.util.Collection; -import java.util.UUID; import main.java.com.djrapitops.plan.Log; import main.java.com.djrapitops.plan.Permissions; import main.java.com.djrapitops.plan.Phrase; @@ -15,6 +13,9 @@ import main.java.com.djrapitops.plan.database.Database; import main.java.com.djrapitops.plan.utilities.Check; import main.java.com.djrapitops.plan.utilities.ManageUtils; +import java.util.Collection; +import java.util.UUID; + /** * This manage subcommand is used to move all data from one database to another. * @@ -33,14 +34,14 @@ public class ManageMoveCommand extends SubCommand { * @param plugin Current instance of Plan */ public ManageMoveCommand(Plan plugin) { - super("move", CommandType.CONSOLE_WITH_ARGUMENTS, Permissions.MANAGE.getPermission(), Phrase.CMD_USG_MANAGE_MOVE + "", Phrase.ARG_MOVE + ""); + super("move", CommandType.CONSOLE_WITH_ARGUMENTS, Permissions.MANAGE.getPermission(), Phrase.CMD_USG_MANAGE_MOVE.toString(), Phrase.ARG_MOVE.toString()); this.plugin = plugin; } @Override public boolean onCommand(ISender sender, String commandLabel, String[] args) { - if (!Check.isTrue(args.length >= 2, Phrase.COMMAND_REQUIRES_ARGUMENTS.parse(Phrase.USE_MOVE + ""), sender)) { + if (!Check.isTrue(args.length >= 2, Phrase.COMMAND_REQUIRES_ARGUMENTS.parse(Phrase.USE_MOVE.toString()), sender)) { return true; } @@ -57,7 +58,7 @@ public class ManageMoveCommand extends SubCommand { if (!Check.isTrue(isCorrectDB, Phrase.MANAGE_ERROR_INCORRECT_DB + toDB, sender)) { return true; } - if (!Check.isTrue(!Verify.equalsIgnoreCase(fromDB, toDB), Phrase.MANAGE_ERROR_SAME_DB + "", sender)) { + if (!Check.isTrue(!Verify.equalsIgnoreCase(fromDB, toDB), Phrase.MANAGE_ERROR_SAME_DB.toString(), sender)) { return true; } if (!Check.isTrue(Verify.contains("-a", args), Phrase.COMMAND_ADD_CONFIRMATION_ARGUMENT.parse(Phrase.WARN_REMOVE.parse(args[1])), sender)) { @@ -66,14 +67,14 @@ public class ManageMoveCommand extends SubCommand { final Database fromDatabase = ManageUtils.getDB(plugin, fromDB); - if (!Check.isTrue(Verify.notNull(fromDatabase), Phrase.MANAGE_DATABASE_FAILURE + "", sender)) { + if (!Check.isTrue(Verify.notNull(fromDatabase), Phrase.MANAGE_DATABASE_FAILURE.toString(), sender)) { Log.error(fromDB + " was null!"); return true; } final Database toDatabase = ManageUtils.getDB(plugin, toDB); - if (!Check.isTrue(Verify.notNull(toDatabase), Phrase.MANAGE_DATABASE_FAILURE + "", sender)) { + if (!Check.isTrue(Verify.notNull(toDatabase), Phrase.MANAGE_DATABASE_FAILURE.toString(), sender)) { Log.error(toDB + " was null!"); return true; } @@ -96,9 +97,9 @@ public class ManageMoveCommand extends SubCommand { sender.sendMessage(Phrase.MANAGE_MOVE_SUCCESS + ""); boolean movedToCurrentDatabase = Verify.equalsIgnoreCase(toDatabase.getConfigName(), plugin.getDB().getConfigName()); - Check.isTrue(!movedToCurrentDatabase, Phrase.MANAGE_DB_CONFIG_REMINDER + "", sender); + Check.isTrue(!movedToCurrentDatabase, Phrase.MANAGE_DB_CONFIG_REMINDER.toString(), sender); } else { - sender.sendMessage(Phrase.MANAGE_PROCESS_FAIL + ""); + sender.sendMessage(Phrase.MANAGE_PROCESS_FAIL.toString()); } } catch (Exception e) { Log.toLog(this.getClass().getName() + " " + getTaskName(), e); diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageRemoveCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageRemoveCommand.java index a710c5dd4..a66b6cc52 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageRemoveCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageRemoveCommand.java @@ -5,8 +5,6 @@ import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.command.SubCommand; import com.djrapitops.plugin.task.AbsRunnable; import com.djrapitops.plugin.utilities.Verify; -import java.sql.SQLException; -import java.util.UUID; import main.java.com.djrapitops.plan.Log; import main.java.com.djrapitops.plan.Permissions; import main.java.com.djrapitops.plan.Phrase; @@ -15,6 +13,9 @@ import main.java.com.djrapitops.plan.utilities.Check; import main.java.com.djrapitops.plan.utilities.MiscUtils; import main.java.com.djrapitops.plan.utilities.uuid.UUIDUtility; +import java.sql.SQLException; +import java.util.UUID; + /** * This manage subcommand is used to remove a single player's data from the * database. @@ -31,14 +32,14 @@ public class ManageRemoveCommand extends SubCommand { * @param plugin Current instance of Plan */ public ManageRemoveCommand(Plan plugin) { - super("remove", CommandType.CONSOLE_WITH_ARGUMENTS, Permissions.MANAGE.getPermission(), Phrase.CMD_USG_MANAGE_REMOVE + "", Phrase.ARG_PLAYER + " [-a]"); + super("remove", CommandType.CONSOLE_WITH_ARGUMENTS, Permissions.MANAGE.getPermission(), Phrase.CMD_USG_MANAGE_REMOVE.toString(), Phrase.ARG_PLAYER + " [-a]"); this.plugin = plugin; } @Override public boolean onCommand(ISender sender, String commandLabel, String[] args) { - if (!Check.isTrue(args.length >= 1, Phrase.COMMAND_REQUIRES_ARGUMENTS_ONE + "", sender)) { + if (!Check.isTrue(args.length >= 1, Phrase.COMMAND_REQUIRES_ARGUMENTS_ONE.toString(), sender)) { return true; } @@ -73,11 +74,11 @@ public class ManageRemoveCommand extends SubCommand { if (plugin.getDB().removeAccount(uuid.toString())) { sender.sendMessage(Phrase.MANAGE_REMOVE_SUCCESS.parse(playerName, plugin.getDB().getConfigName())); } else { - sender.sendMessage(Phrase.MANAGE_PROCESS_FAIL + ""); + sender.sendMessage(Phrase.MANAGE_PROCESS_FAIL.toString()); } } catch (SQLException e) { Log.toLog(this.getClass().getName(), e); - sender.sendMessage(Phrase.MANAGE_PROCESS_FAIL + ""); + sender.sendMessage(Phrase.MANAGE_PROCESS_FAIL.toString()); } } finally { this.cancel(); diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageRestoreCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageRestoreCommand.java index 437a68569..3ef71609f 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageRestoreCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageRestoreCommand.java @@ -5,9 +5,6 @@ import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.command.SubCommand; import com.djrapitops.plugin.task.AbsRunnable; import com.djrapitops.plugin.utilities.Verify; -import java.io.File; -import java.util.Collection; -import java.util.UUID; import main.java.com.djrapitops.plan.Log; import main.java.com.djrapitops.plan.Permissions; import main.java.com.djrapitops.plan.Phrase; @@ -17,6 +14,10 @@ import main.java.com.djrapitops.plan.database.databases.SQLiteDB; import main.java.com.djrapitops.plan.utilities.Check; import main.java.com.djrapitops.plan.utilities.ManageUtils; +import java.io.File; +import java.util.Collection; +import java.util.UUID; + /** * This manage subcommand is used to restore a backup.db file in the * /plugins/Plan folder. @@ -33,14 +34,14 @@ public class ManageRestoreCommand extends SubCommand { * @param plugin Current instance of Plan */ public ManageRestoreCommand(Plan plugin) { - super("restore", CommandType.CONSOLE, Permissions.MANAGE.getPermission(), Phrase.CMD_USG_MANAGE_RESTORE + "", Phrase.ARG_RESTORE + ""); + super("restore", CommandType.CONSOLE, Permissions.MANAGE.getPermission(), Phrase.CMD_USG_MANAGE_RESTORE.toString(), Phrase.ARG_RESTORE.toString()); this.plugin = plugin; } @Override public boolean onCommand(ISender sender, String commandLabel, String[] args) { - if (!Check.isTrue(args.length >= 2, Phrase.COMMAND_REQUIRES_ARGUMENTS.parse(Phrase.USE_RESTORE + ""), sender)) { + if (!Check.isTrue(args.length >= 2, Phrase.COMMAND_REQUIRES_ARGUMENTS.parse(Phrase.USE_RESTORE.toString()), sender)) { return true; } String db = args[1].toLowerCase(); @@ -55,7 +56,7 @@ public class ManageRestoreCommand extends SubCommand { final Database database = ManageUtils.getDB(plugin, db); - if (!Check.isTrue(Verify.notNull(database), Phrase.MANAGE_DATABASE_FAILURE + "", sender)) { + if (!Check.isTrue(Verify.notNull(database), Phrase.MANAGE_DATABASE_FAILURE.toString(), sender)) { Log.error(db + " was null!"); return true; } @@ -82,7 +83,7 @@ public class ManageRestoreCommand extends SubCommand { } SQLiteDB backupDB = new SQLiteDB(plugin, backupDBName); if (!backupDB.init()) { - sender.sendMessage(Phrase.MANAGE_DATABASE_FAILURE + ""); + sender.sendMessage(Phrase.MANAGE_DATABASE_FAILURE.toString()); return; } sender.sendMessage(Phrase.MANAGE_PROCESS_START.parse()); diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageStatusCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageStatusCommand.java index acc32fd3b..149e52d07 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageStatusCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageStatusCommand.java @@ -22,7 +22,7 @@ public class ManageStatusCommand extends SubCommand { * @param plugin Current instance of Plan */ public ManageStatusCommand(Plan plugin) { - super("status", CommandType.CONSOLE, Permissions.MANAGE.getPermission(), Phrase.CMD_USG_MANAGE_STATUS + ""); + super("status", CommandType.CONSOLE, Permissions.MANAGE.getPermission(), Phrase.CMD_USG_MANAGE_STATUS.toString()); this.plugin = plugin; } @@ -30,13 +30,13 @@ public class ManageStatusCommand extends SubCommand { @Override public boolean onCommand(ISender sender, String commandLabel, String[] args) { String[] messages = new String[]{ - Phrase.CMD_MANAGE_STATUS_HEADER + "", + Phrase.CMD_MANAGE_STATUS_HEADER.toString(), Phrase.CMD_MANAGE_STATUS_ACTIVE_DB.parse(plugin.getDB().getConfigName()), Phrase.CMD_MANAGE_STATUS_QUEUE_PROCESS.parse("" + plugin.getHandler().getProcessTask().size()), Phrase.CMD_MANAGE_STATUS_QUEUE_SAVE.parse("" + plugin.getHandler().getSaveTask().size()), Phrase.CMD_MANAGE_STATUS_QUEUE_GET.parse("" + plugin.getHandler().getGetTask().size()), Phrase.CMD_MANAGE_STATUS_QUEUE_CLEAR.parse("" + plugin.getHandler().getClearTask().size()), - Phrase.CMD_FOOTER + "" + Phrase.CMD_FOOTER.toString() }; sender.sendMessage(messages); diff --git a/Plan/src/main/java/com/djrapitops/plan/data/TPS.java b/Plan/src/main/java/com/djrapitops/plan/data/TPS.java index 3915e9924..798bcd821 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/TPS.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/TPS.java @@ -16,6 +16,7 @@ public class TPS { private final long date; private final double tps; private final int players; + private final double cpuUsage; /** * Constructor. @@ -23,11 +24,13 @@ public class TPS { * @param date time of the average calculation. * @param tps average tps for the last minute. * @param players average players for the last minute. + * @param cpuUsage average CPU usage for the last minute. */ - public TPS(long date, double tps, int players) { + public TPS(long date, double tps, int players, double cpuUsage) { this.date = date; this.tps = tps; this.players = players; + this.cpuUsage = cpuUsage; } /** @@ -57,6 +60,15 @@ public class TPS { return players; } + /** + * Get the average CPU Usage for the minute. + * + * @return 0-20 double + */ + public double getCPUUsage() { + return cpuUsage; + } + @Override public int hashCode() { int hash = 3; @@ -80,11 +92,12 @@ public class TPS { final TPS other = (TPS) obj; return this.date == other.date && Double.doubleToLongBits(this.tps) == Double.doubleToLongBits(other.tps) - && this.players == other.players; + && this.players == other.players + && this.cpuUsage == other.cpuUsage; } @Override public String toString() { - return "TPS{" + date + "|" + tps + "|" + players + '}'; + return "TPS{" + date + "|" + tps + "|" + players + "|" + cpuUsage + "}"; } } diff --git a/Plan/src/main/java/com/djrapitops/plan/data/cache/DataCacheHandler.java b/Plan/src/main/java/com/djrapitops/plan/data/cache/DataCacheHandler.java index ac68f111e..8bfc74128 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/cache/DataCacheHandler.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/cache/DataCacheHandler.java @@ -363,11 +363,14 @@ public class DataCacheHandler extends SessionCache { return new ArrayList<>(); } List> copy = new ArrayList<>(unsavedTPSHistory); + for (List history : copy) { final long lastDate = history.get(history.size() - 1).getDate(); final double averageTPS = MathUtils.averageDouble(history.stream().map(TPS::getTps)); final int averagePlayersOnline = (int) MathUtils.averageInt(history.stream().map(TPS::getPlayers)); - averages.add(new TPS(lastDate, averageTPS, averagePlayersOnline)); + final double averageCPUUsage = MathUtils.averageDouble(history.stream().map(TPS::getCPUUsage)); + + averages.add(new TPS(lastDate, averageTPS, averagePlayersOnline, averageCPUUsage)); } unsavedTPSHistory.removeAll(copy); return averages; @@ -516,10 +519,9 @@ public class DataCacheHandler extends SessionCache { * @param command "/command" */ public void handleCommand(String command) { - if (!commandUse.containsKey(command)) { - commandUse.put(command, 0); - } - commandUse.put(command, commandUse.get(command) + 1); + int amount = commandUse.getOrDefault(command, 0); + + commandUse.put(command, amount + 1); } /** diff --git a/Plan/src/main/java/com/djrapitops/plan/data/cache/GeolocationCacheHandler.java b/Plan/src/main/java/com/djrapitops/plan/data/cache/GeolocationCacheHandler.java index 714515fad..1f9b5a453 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/cache/GeolocationCacheHandler.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/cache/GeolocationCacheHandler.java @@ -18,6 +18,7 @@ import java.util.Map; * This cache uses the Google Guava {@link Cache} and has a capacity of 10.000 entries. * * @author Fuzzlemann + * @since 3.5.5 */ public class GeolocationCacheHandler { private static final Cache geolocationCache = CacheBuilder.newBuilder() @@ -33,7 +34,7 @@ public class GeolocationCacheHandler { * @return The name of the country in full length. *

* An exception from that rule is when the country is unknown or the retrieval of the country failed in any way, - * if that happens, the phrase for unknown country set in the config will be returned. + * if that happens, "Not Known" will be returned. * @see #getUncachedCountry(String) */ public static String getCountry(String ipAddress) { @@ -64,7 +65,7 @@ public class GeolocationCacheHandler { * @return The name of the country in full length. *

* An exception from that rule is when the country is unknown or the retrieval of the country failed in any way, - * if that happens, the phrase for unknown country set in the config will be returned. + * if that happens, "Not Known" will be returned. * @see http://freegeoip.net * @see #getCountry(String) */ diff --git a/Plan/src/main/java/com/djrapitops/plan/data/cache/InspectCacheHandler.java b/Plan/src/main/java/com/djrapitops/plan/data/cache/InspectCacheHandler.java index 6a3d3c384..e1c454255 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/cache/InspectCacheHandler.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/cache/InspectCacheHandler.java @@ -55,6 +55,7 @@ public class InspectCacheHandler { } } }; + handler.getUserDataForProcessing(cacher, uuid, false); } @@ -103,10 +104,7 @@ public class InspectCacheHandler { * @return -1 when not cached or Epoch millisecond. */ public long getCacheTime(UUID uuid) { - if (cacheTimes.containsKey(uuid)) { - return cacheTimes.get(uuid); - } - return -1; + return cacheTimes.getOrDefault(uuid, -1L); } /** diff --git a/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanCommandPreprocessListener.java b/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanCommandPreprocessListener.java index 855d7f8a2..143997743 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanCommandPreprocessListener.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanCommandPreprocessListener.java @@ -5,12 +5,12 @@ import main.java.com.djrapitops.plan.Permissions; import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.Settings; import main.java.com.djrapitops.plan.data.cache.DataCacheHandler; +import org.bukkit.command.Command; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.help.HelpMap; /** * Event Listener for PlayerCommandPreprocessEvents. @@ -43,13 +43,20 @@ public class PlanCommandPreprocessListener implements Listener { return; } - String cmd = event.getMessage().split(" ")[0].toLowerCase(); + String commandName = event.getMessage().split(" ")[0].toLowerCase(); - if (Settings.DO_NOT_LOG_UNKNOWN_COMMANDS.isTrue()) { - HelpMap helpMap = plugin.getServer().getHelpMap(); - if (helpMap.getHelpTopic(cmd) == null) { - Log.debug("Ignored command, command is unknown"); - return; + boolean doNotLogUnknownCommands = Settings.DO_NOT_LOG_UNKNOWN_COMMANDS.isTrue(); + boolean combineCommandAliasesToMainCommand = Settings.COMBINE_COMMAND_ALIASES_TO_MAIN_COMMAND.isTrue(); + + if (doNotLogUnknownCommands || combineCommandAliasesToMainCommand) { + Command command = plugin.getServer().getPluginCommand(commandName); + if (command == null) { + if (doNotLogUnknownCommands) { + Log.debug("Ignored command, command is unknown"); + return; + } + } else if (combineCommandAliasesToMainCommand) { + commandName = command.getName(); } } @@ -59,6 +66,6 @@ public class PlanCommandPreprocessListener implements Listener { Log.debug("Ignored command, player had ignore permission."); return; } - handler.handleCommand(cmd); + handler.handleCommand(commandName); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/data/listeners/TPSCountTimer.java b/Plan/src/main/java/com/djrapitops/plan/data/listeners/TPSCountTimer.java index 6bb384504..ce848b8d2 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/listeners/TPSCountTimer.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/listeners/TPSCountTimer.java @@ -7,7 +7,10 @@ import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.data.TPS; import main.java.com.djrapitops.plan.data.cache.DataCacheHandler; import main.java.com.djrapitops.plan.utilities.MiscUtils; +import main.java.com.djrapitops.plan.utilities.analysis.MathUtils; +import java.lang.management.ManagementFactory; +import java.lang.management.OperatingSystemMXBean; import java.util.ArrayList; import java.util.List; @@ -36,32 +39,87 @@ public class TPSCountTimer extends AbsRunnable { long nanoTime = System.nanoTime(); long now = MiscUtils.getTime(); long diff = nanoTime - lastCheckNano; + lastCheckNano = nanoTime; + if (diff > nanoTime) { // First run's diff = nanoTime + 1, no calc possible. Log.debug("First run of TPSCountTimer Task."); return; } - diff -= TimeAmount.MILLISECOND.ns() * 40L; // 40ms removed because the run appears to take 40-50ms, screwing the tps. + TPS tps = calculateTPS(diff, now); history.add(tps); + if (history.size() >= 60) { handler.addTPSLastMinute(history); history.clear(); } } - public TPS calculateTPS(long diff, long now) { + /** + * Calculates the TPS + * + * @param diff The time difference between the last run and the new run + * @param now The time right now + * @return the TPS + */ + private TPS calculateTPS(long diff, long now) { + OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean(); + int availableProcessors = ManagementFactory.getOperatingSystemMXBean().getAvailableProcessors(); + final double averageCPUUsage = MathUtils.round(operatingSystemMXBean.getSystemLoadAverage() / availableProcessors * 100.0); + + int playersOnline = plugin.getServer().getOnlinePlayers().size(); + + if (plugin.getVariable().isUsingPaper()) { + return getTPSPaper(now, averageCPUUsage, playersOnline); + } else { + diff -= TimeAmount.MILLISECOND.ns() * 40L; // 40ms removed because the run appears to take 40-50ms, screwing the tps. + return getTPS(diff, now, averageCPUUsage, playersOnline); + } + } + + /** + * Gets the TPS for Paper + * + * @param now The time right now + * @param cpuUsage The usage of the CPU + * @param playersOnline The amount of players that are online + * @return the TPS + */ + private TPS getTPSPaper(long now, double cpuUsage, int playersOnline) { + double tps = plugin.getServer().getTPS()[0]; + + if (tps > 20) { + tps = 20; + } + + tps = MathUtils.round(tps); + + return new TPS(now, tps, playersOnline, cpuUsage); + } + + /** + * Gets the TPS for a Spigot / Bukkit + * + * @param diff The difference between the last run and this run + * @param now The time right now + * @param cpuUsage The usage of the CPU + * @param playersOnline The amount of players that are online + * @return the TPS + */ + private TPS getTPS(long diff, long now, double cpuUsage, int playersOnline) { if (diff < TimeAmount.SECOND.ns()) { // No tick count above 20 diff = TimeAmount.SECOND.ns(); } - int playersOnline = plugin.getServer().getOnlinePlayers().size(); + long twentySeconds = 20L * TimeAmount.SECOND.ns(); while (diff > twentySeconds) { - history.add(new TPS(now, 0, playersOnline)); + history.add(new TPS(now, 0, playersOnline, cpuUsage)); diff -= twentySeconds; } + double tpsN = twentySeconds / diff; - return new TPS(now, tpsN, playersOnline); + return new TPS(now, tpsN, playersOnline, cpuUsage); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/database/tables/TPSTable.java b/Plan/src/main/java/com/djrapitops/plan/database/tables/TPSTable.java index 2bcfa3fe5..e387c26bc 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/tables/TPSTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/tables/TPSTable.java @@ -1,11 +1,6 @@ package main.java.com.djrapitops.plan.database.tables; import com.djrapitops.plugin.api.TimeAmount; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; import main.java.com.djrapitops.plan.Log; import main.java.com.djrapitops.plan.data.TPS; import main.java.com.djrapitops.plan.database.DBUtils; @@ -13,6 +8,12 @@ import main.java.com.djrapitops.plan.database.databases.SQLDB; import main.java.com.djrapitops.plan.utilities.Benchmark; import main.java.com.djrapitops.plan.utilities.MiscUtils; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + /** * Class representing database table plan_tps * @@ -24,6 +25,7 @@ public class TPSTable extends Table { private final String columnDate; private final String columnTPS; private final String columnPlayers; + private final String columnCPUUsage; /** * @@ -35,6 +37,7 @@ public class TPSTable extends Table { columnDate = "date"; columnTPS = "tps"; columnPlayers = "players_online"; + columnCPUUsage = "cpu_usage"; } @Override @@ -43,7 +46,8 @@ public class TPSTable extends Table { execute("CREATE TABLE IF NOT EXISTS " + tableName + " (" + columnDate + " bigint NOT NULL, " + columnTPS + " double NOT NULL, " - + columnPlayers + " integer NOT NULL" + + columnPlayers + " integer NOT NULL, " + + columnCPUUsage + " double NOT NULL" + ")" ); return true; @@ -69,7 +73,8 @@ public class TPSTable extends Table { long date = set.getLong(columnDate); double tps = set.getDouble(columnTPS); int players = set.getInt(columnPlayers); - data.add(new TPS(date, tps, players)); + double cpuUsage = set.getDouble(columnCPUUsage); + data.add(new TPS(date, tps, players, cpuUsage)); } return data; } finally { @@ -97,8 +102,9 @@ public class TPSTable extends Table { statement = prepareStatement("INSERT INTO " + tableName + " (" + columnDate + ", " + columnTPS + ", " - + columnPlayers - + ") VALUES (?, ?, ?)"); + + columnPlayers + ", " + + columnCPUUsage + + ") VALUES (?, ?, ?, ?)"); boolean commitRequired = false; int i = 0; @@ -106,6 +112,7 @@ public class TPSTable extends Table { statement.setLong(1, tps.getDate()); statement.setDouble(2, tps.getTps()); statement.setInt(3, tps.getPlayers()); + statement.setDouble(4, tps.getCPUUsage()); statement.addBatch(); commitRequired = true; i++; diff --git a/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/PunchCardGraphCreator.java b/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/PunchCardGraphCreator.java index c64d64887..07ac32a9a 100644 --- a/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/PunchCardGraphCreator.java +++ b/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/PunchCardGraphCreator.java @@ -47,7 +47,7 @@ public class PunchCardGraphCreator { continue; } arrayBuilder.append("{").append("x:").append(j).append(", y:").append(i).append(", r:").append(value).append("}"); - if (!(i == 6 && j == 23)) { + if (i != 6 || j != 23) { arrayBuilder.append(","); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/ui/text/TextUI.java b/Plan/src/main/java/com/djrapitops/plan/ui/text/TextUI.java index c3d8667a7..d6b37c168 100644 --- a/Plan/src/main/java/com/djrapitops/plan/ui/text/TextUI.java +++ b/Plan/src/main/java/com/djrapitops/plan/ui/text/TextUI.java @@ -1,16 +1,10 @@ package main.java.com.djrapitops.plan.ui.text; -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.AnalysisData; import main.java.com.djrapitops.plan.data.UserData; -import main.java.com.djrapitops.plan.data.analysis.ActivityPart; -import main.java.com.djrapitops.plan.data.analysis.JoinInfoPart; -import main.java.com.djrapitops.plan.data.analysis.KillPart; -import main.java.com.djrapitops.plan.data.analysis.PlayerCountPart; -import main.java.com.djrapitops.plan.data.analysis.PlaytimePart; -import main.java.com.djrapitops.plan.data.analysis.TPSPart; +import main.java.com.djrapitops.plan.data.analysis.*; import main.java.com.djrapitops.plan.data.cache.AnalysisCacheHandler; import main.java.com.djrapitops.plan.data.cache.InspectCacheHandler; import main.java.com.djrapitops.plan.utilities.FormatUtils; @@ -19,6 +13,8 @@ import main.java.com.djrapitops.plan.utilities.analysis.AnalysisUtils; import main.java.com.djrapitops.plan.utilities.analysis.MathUtils; import org.bukkit.ChatColor; +import java.util.UUID; + /** * * @author Rsl1122 @@ -68,7 +64,6 @@ public class TextUI { AnalysisData d = analysisCache.getData(); ChatColor main = Phrase.COLOR_MAIN.color(); ChatColor sec = Phrase.COLOR_SEC.color(); - ChatColor ter = Phrase.COLOR_TER.color(); String ball = sec + " " + Phrase.BALL + main; final ActivityPart activity = d.getActivityPart(); final JoinInfoPart join = d.getJoinInfoPart(); diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/AnalysisUtils.java b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/AnalysisUtils.java index ff26d3894..b745e775b 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/AnalysisUtils.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/AnalysisUtils.java @@ -247,10 +247,10 @@ public class AnalysisUtils { continue; } } + int day = getDayOfYear(session); - if (!uniqueJoins.containsKey(day)) { - uniqueJoins.put(day, new HashSet<>()); - } + + uniqueJoins.computeIfAbsent(day, computedDay -> new HashSet<>()); uniqueJoins.get(day).add(uuid); } }); diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/MathUtils.java b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/MathUtils.java index 7a37ba76e..1381e7551 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/MathUtils.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/MathUtils.java @@ -8,89 +8,104 @@ import java.util.OptionalLong; import java.util.stream.Stream; /** - * * @author Rsl1122 */ public class MathUtils { /** + * Gets the average of a Stream of Integers. + * If there are no components in the Stream, it will return 0. * - * @param values - * @return + * @param values The Stream of Integers. + * @return The average */ public static double averageInt(Stream values) { OptionalDouble average = values.mapToInt(i -> i).average(); - if (average.isPresent()) { - return average.getAsDouble(); - } else { - return 0; - } + + return average.isPresent() ? average.getAsDouble() : 0; } /** + * Gets the average of a Collection with Long as Entry. + * If the collection is empty, it will return 0. * - * @param values - * @return + * @param values The Collection with Long as the Entry. + * @return The average + * @see #averageLong(Stream) */ public static long averageLong(Collection values) { return averageLong(values.stream()); } /** + * Gets the average of a Stream of Longs. + * If there are no components in the Stream, it will return 0. * - * @param values - * @return + * @param values The Stream of Longs. + * @return The average + * @see #averageLong(Collection) */ public static long averageLong(Stream values) { OptionalDouble average = values.mapToLong(i -> i).average(); - if (average.isPresent()) { - return (long) average.getAsDouble(); - } else { - return 0L; - } + + return average.isPresent() ? (long) average.getAsDouble() : 0L; + } /** + * Gets the average of a Stream of Double. + * If there are no components in the Stream, it will return 0. * - * @param values - * @return + * @param values The Stream of Double. + * @return The average */ public static double averageDouble(Stream values) { OptionalDouble average = values.mapToDouble(i -> i).average(); - if (average.isPresent()) { - return average.getAsDouble(); - } else { - return 0; - } + + return average.isPresent() ? average.getAsDouble() : 0; } /** + * Calculates the average * - * @param total - * @param size - * @return + * @param total The total summed amount of all Integers + * @param size The amount of all Integers that were summed + * @return The average + * @see #averageLong(long, long) */ public static double average(int total, int size) { - return 1.0 * total / size; + return (double) total / size; } + /** + * Calculates the average + * + * @param total The total summed amount of all Longs + * @param size The amount of all Longs that were summed + * @return The average + * @see #average(int, int) + */ public static long averageLong(long total, long size) { return total / size; } /** + * Counts all Booleans that are true in the Stream of Booleans * - * @param values - * @return + * @param values The Stream of Booleans + * @return The amount of Booleans that are true */ public static long countTrueBoolean(Stream values) { - return values.filter(i -> i).count(); + return values.filter(value -> value).count(); } /** + * Sums all Integers in a Stream of Serializable * - * @param values - * @return + * @param values The Stream of Serializable + * @return The sum + * @see #sumLong(Stream) + * @see #sumDouble(Stream) */ public static int sumInt(Stream values) { return values @@ -99,9 +114,12 @@ public class MathUtils { } /** + * Sums all Longs in a Stream of Serializable * - * @param values - * @return + * @param values The Stream of Serializable + * @return The sum + * @see #sumInt(Stream) + * @see #sumDouble(Stream) */ public static long sumLong(Stream values) { return values @@ -110,9 +128,12 @@ public class MathUtils { } /** + * Sums all Doubles in a Stream of Serializable * - * @param values - * @return + * @param values The Stream of Serializable + * @return The sum + * @see #sumLong(Stream) + * @see #sumInt(Stream) */ public static double sumDouble(Stream values) { return values @@ -121,32 +142,41 @@ public class MathUtils { } /** + * Gets the biggest Integer in a Collection with Integer as Entry + * If the Collection is empty, it will return 0. * - * @param values - * @return + * @param values The Collection with Integer as the Entry + * @return The biggest Integer + * @see #getBiggestLong(Collection) */ public static int getBiggest(Collection values) { OptionalInt biggest = values.stream().mapToInt(i -> i).max(); - if (biggest.isPresent()) { - return biggest.getAsInt(); - } else { - return 1; - } + return biggest.isPresent() ? biggest.getAsInt() : 1; } /** + * Gets the biggest Long in a Collection with Long as Entry + * If the Collection is empty, it will return 0. * - * @param values - * @return + * @param values The Collection with Long as the Entry + * @return The biggest Integer + * @see #getBiggest(Collection) */ public static long getBiggestLong(Collection values) { OptionalLong biggest = values.stream().mapToLong(i -> i).max(); - if (biggest.isPresent()) { - return biggest.getAsLong(); - } else { - return 1; - } + return biggest.isPresent() ? biggest.getAsLong() : 1; + } + + /** + * Rounds the double to a double with two digits at the end. + * Output: #.## + * + * @param number The number that's rounded + * @return The rounded number + */ + public static double round(double number) { + return Math.round(number * 100.0) / 100.0; } } diff --git a/Plan/src/main/resources/config.yml b/Plan/src/main/resources/config.yml index ba75d7203..0c7a184b8 100644 --- a/Plan/src/main/resources/config.yml +++ b/Plan/src/main/resources/config.yml @@ -43,6 +43,7 @@ Customization: SmallHeadImagesOnAnalysisPlayerlist: true Data: DoNotLogUnknownCommands: false + CombineCommandAliasesToMainCommand: false Graphs: PlayersOnlineGraph: UseMaxPlayersAsScale: true diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/database/DatabaseTest.java b/Plan/src/test/java/main/java/com/djrapitops/plan/database/DatabaseTest.java index 274449595..d41791af3 100644 --- a/Plan/src/test/java/main/java/com/djrapitops/plan/database/DatabaseTest.java +++ b/Plan/src/test/java/main/java/com/djrapitops/plan/database/DatabaseTest.java @@ -17,6 +17,7 @@ import main.java.com.djrapitops.plan.database.databases.SQLiteDB; import main.java.com.djrapitops.plan.database.tables.TPSTable; import main.java.com.djrapitops.plan.utilities.ManageUtils; import main.java.com.djrapitops.plan.utilities.MiscUtils; +import main.java.com.djrapitops.plan.utilities.analysis.MathUtils; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitRunnable; @@ -33,6 +34,8 @@ import test.java.utils.TestInit; import java.io.File; import java.io.IOException; +import java.lang.management.ManagementFactory; +import java.lang.management.OperatingSystemMXBean; import java.net.InetAddress; import java.net.UnknownHostException; import java.nio.charset.Charset; @@ -398,10 +401,13 @@ public class DatabaseTest { TPSTable tpsTable = db.getTpsTable(); List expected = new ArrayList<>(); Random r = new Random(); - expected.add(new TPS(r.nextLong(), r.nextDouble(), r.nextInt(100000000))); - expected.add(new TPS(r.nextLong(), r.nextDouble(), r.nextInt(100000000))); - expected.add(new TPS(r.nextLong(), r.nextDouble(), r.nextInt(100000000))); - expected.add(new TPS(r.nextLong(), r.nextDouble(), r.nextInt(100000000))); + OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean(); + int availableProcessors = ManagementFactory.getOperatingSystemMXBean().getAvailableProcessors(); + final double averageCPUUsage = MathUtils.round(operatingSystemMXBean.getSystemLoadAverage() / availableProcessors * 100.0); + expected.add(new TPS(r.nextLong(), r.nextDouble(), r.nextInt(100000000), averageCPUUsage)); + expected.add(new TPS(r.nextLong(), r.nextDouble(), r.nextInt(100000000), averageCPUUsage)); + expected.add(new TPS(r.nextLong(), r.nextDouble(), r.nextInt(100000000), averageCPUUsage)); + expected.add(new TPS(r.nextLong(), r.nextDouble(), r.nextInt(100000000), averageCPUUsage)); tpsTable.saveTPSData(expected); assertEquals(expected, tpsTable.getTPSData()); } @@ -414,11 +420,14 @@ public class DatabaseTest { List expected = new ArrayList<>(); Random r = new Random(); long now = System.currentTimeMillis(); - expected.add(new TPS(now, r.nextDouble(), r.nextInt(100000000))); - expected.add(new TPS(now - 1000L, r.nextDouble(), r.nextInt(100000000))); - expected.add(new TPS(now - 3000L, r.nextDouble(), r.nextInt(100000000))); - expected.add(new TPS(now - (690000L * 1000L), r.nextDouble(), r.nextInt(100000000))); - TPS tooOldTPS = new TPS(now - (691400L * 1000L), r.nextDouble(), r.nextInt(100000000)); + OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean(); + int availableProcessors = ManagementFactory.getOperatingSystemMXBean().getAvailableProcessors(); + final double averageCPUUsage = MathUtils.round(operatingSystemMXBean.getSystemLoadAverage() / availableProcessors * 100.0); + expected.add(new TPS(now, r.nextDouble(), r.nextInt(100000000), averageCPUUsage)); + expected.add(new TPS(now - 1000L, r.nextDouble(), r.nextInt(100000000), averageCPUUsage)); + expected.add(new TPS(now - 3000L, r.nextDouble(), r.nextInt(100000000), averageCPUUsage)); + expected.add(new TPS(now - (690000L * 1000L), r.nextDouble(), r.nextInt(100000000), averageCPUUsage)); + TPS tooOldTPS = new TPS(now - (691400L * 1000L), r.nextDouble(), r.nextInt(100000000), averageCPUUsage); expected.add(tooOldTPS); tpsTable.saveTPSData(expected); tpsTable.clean();