diff --git a/Plan/src/main/java/com/djrapitops/plan/Log.java b/Plan/src/main/java/com/djrapitops/plan/Log.java index a9ab50ece..a57cd76f8 100644 --- a/Plan/src/main/java/com/djrapitops/plan/Log.java +++ b/Plan/src/main/java/com/djrapitops/plan/Log.java @@ -16,7 +16,7 @@ public class Log { * @param message "Message" will show up as [INFO][Plan]: Message */ public static void info(String message) { - Plan.getPluginInstance().getPluginLogger().info(message); + Plan.getInstance().getPluginLogger().info(message); } /** diff --git a/Plan/src/main/java/com/djrapitops/plan/Plan.java b/Plan/src/main/java/com/djrapitops/plan/Plan.java index 7ff995996..faf4d917e 100644 --- a/Plan/src/main/java/com/djrapitops/plan/Plan.java +++ b/Plan/src/main/java/com/djrapitops/plan/Plan.java @@ -22,6 +22,7 @@ package main.java.com.djrapitops.plan; import com.djrapitops.javaplugin.api.ColorScheme; import com.djrapitops.javaplugin.RslPlugin; import com.djrapitops.javaplugin.task.RslBukkitRunnable; +import com.djrapitops.javaplugin.task.RslRunnable; import com.djrapitops.javaplugin.task.RslTask; import java.io.File; import java.io.FileNotFoundException; @@ -114,7 +115,7 @@ public class Plan extends RslPlugin { this.inspectCache = new InspectCacheHandler(this); this.analysisCache = new AnalysisCacheHandler(this); registerListeners(); - new TPSCountTimer(this).runTaskTimer(1000, 20); + getRunnableFactory().createNew(new TPSCountTimer(this)).runTaskTimer(1000, 20); registerCommand(new PlanCommand(this)); @@ -231,7 +232,7 @@ public class Plan extends RslPlugin { } private void startAnalysisRefreshTask(int analysisRefreshMinutes) throws IllegalStateException, IllegalArgumentException { - RslTask task = new RslBukkitRunnable("PeriodicalAnalysisTask") { + RslTask task = getRunnableFactory().createNew("PeriodicalAnalysisTask", new RslRunnable() { @Override public void run() { if (!analysisCache.isCached()) { @@ -240,19 +241,19 @@ public class Plan extends RslPlugin { analysisCache.updateCache(); } } - }.runTaskTimerAsynchronously(analysisRefreshMinutes * 60 * 20, analysisRefreshMinutes * 60 * 20); + }).runTaskTimerAsynchronously(analysisRefreshMinutes * 60 * 20, analysisRefreshMinutes * 60 * 20); } private void startBootAnalysisTask() throws IllegalStateException, IllegalArgumentException { Log.info(Phrase.ANALYSIS_BOOT_NOTIFY + ""); - RslTask bootAnalysisTask = new RslBukkitRunnable("BootAnalysisTask") { + RslTask bootAnalysisTask = getRunnableFactory().createNew("BootAnalysisTask", new RslRunnable() { @Override public void run() { Log.info(Phrase.ANALYSIS_BOOT + ""); analysisCache.updateCache(); this.cancel(); } - }.runTaskLaterAsynchronously(30 * 20); + }).runTaskLaterAsynchronously(30 * 20); bootAnalysisTaskID = bootAnalysisTask.getTaskId(); } @@ -429,6 +430,6 @@ public class Plan extends RslPlugin { * @return this object. */ public static Plan getInstance() { - return (Plan) getPluginInstance(); + return (Plan) getPluginInstance(Plan.class); } } 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 7f8d790fb..9f1431b02 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 @@ -3,7 +3,7 @@ package main.java.com.djrapitops.plan.command.commands; import com.djrapitops.javaplugin.command.CommandType; import com.djrapitops.javaplugin.command.SubCommand; import com.djrapitops.javaplugin.command.sender.ISender; -import com.djrapitops.javaplugin.task.RslBukkitRunnable; +import com.djrapitops.javaplugin.task.RslRunnable; import com.djrapitops.javaplugin.task.RslTask; import main.java.com.djrapitops.plan.Log; import main.java.com.djrapitops.plan.Permissions; @@ -61,7 +61,7 @@ public class AnalyzeCommand extends SubCommand { } analysisCache.updateCache(); } - final RslTask task = new RslBukkitRunnable("AnalysisMessageSenderTask") { + final RslTask task = plugin.getRunnableFactory().createNew("AnalysisMessageSenderTask", new RslRunnable() { private int timesrun = 0; @Override @@ -78,7 +78,7 @@ public class AnalyzeCommand extends SubCommand { this.cancel(); } } - }.runTaskTimer(1 * 20, 5 * 20); + }).runTaskTimer(1 * 20, 5 * 20); 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 3771550d8..2e5af04b9 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 @@ -4,6 +4,7 @@ import com.djrapitops.javaplugin.command.CommandType; import com.djrapitops.javaplugin.command.SubCommand; import com.djrapitops.javaplugin.command.sender.ISender; import com.djrapitops.javaplugin.task.RslBukkitRunnable; +import com.djrapitops.javaplugin.task.RslRunnable; import com.djrapitops.javaplugin.task.RslTask; import main.java.com.djrapitops.plan.command.ConditionUtils; import java.util.UUID; @@ -50,7 +51,7 @@ public class InspectCommand extends SubCommand { return true; } String playerName = MiscUtils.getPlayerName(args, sender); - final RslTask inspectTask = new RslBukkitRunnable("InspectTask") { + final RslTask inspectTask = plugin.getRunnableFactory().createNew(new RslRunnable("InspectTask") { @Override public void run() { UUID uuid = ConditionUtils.getUUID(playerName); @@ -69,7 +70,7 @@ public class InspectCommand extends SubCommand { } sender.sendMessage(Phrase.GRABBING_DATA_MESSAGE + ""); inspectCache.cache(uuid); - final RslTask inspectMessageSenderTask = new RslBukkitRunnable("InspectMessageSenderTask") { + final RslTask inspectMessageSenderTask = plugin.getRunnableFactory().createNew(new RslRunnable("InspectMessageSenderTask") { private int timesrun = 0; @Override @@ -87,10 +88,10 @@ public class InspectCommand extends SubCommand { } } - }.runTaskTimer(1 * 20, 5 * 20); + }).runTaskTimer(1 * 20, 5 * 20); this.cancel(); } - }.runTaskAsynchronously(); + }).runTaskAsynchronously(); return true; } diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/QuickAnalyzeCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/QuickAnalyzeCommand.java index ba02e2c9f..b279ee811 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/QuickAnalyzeCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/QuickAnalyzeCommand.java @@ -4,6 +4,7 @@ import com.djrapitops.javaplugin.command.CommandType; import com.djrapitops.javaplugin.command.SubCommand; import com.djrapitops.javaplugin.command.sender.ISender; import com.djrapitops.javaplugin.task.RslBukkitRunnable; +import com.djrapitops.javaplugin.task.RslRunnable; import com.djrapitops.javaplugin.task.RslTask; import main.java.com.djrapitops.plan.Log; import main.java.com.djrapitops.plan.Permissions; @@ -56,7 +57,7 @@ public class QuickAnalyzeCommand extends SubCommand { analysisCache.updateCache(); } - RslTask analysisMessageSenderTask = new RslBukkitRunnable("QanalysisMessageSenderTask") { + RslTask analysisMessageSenderTask = plugin.getRunnableFactory().createNew(new RslRunnable("QanalysisMessageSenderTask") { private int timesrun = 0; @Override @@ -74,7 +75,7 @@ public class QuickAnalyzeCommand extends SubCommand { this.cancel(); } } - }.runTaskTimer(1 * 20, 5 * 20); + }).runTaskTimer(1 * 20, 5 * 20); return true; } } diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/QuickInspectCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/QuickInspectCommand.java index 0120472ae..430ad0e33 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/QuickInspectCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/QuickInspectCommand.java @@ -4,6 +4,7 @@ import com.djrapitops.javaplugin.command.CommandType; import com.djrapitops.javaplugin.command.SubCommand; import com.djrapitops.javaplugin.command.sender.ISender; import com.djrapitops.javaplugin.task.RslBukkitRunnable; +import com.djrapitops.javaplugin.task.RslRunnable; import com.djrapitops.javaplugin.task.RslTask; import java.util.UUID; import main.java.com.djrapitops.plan.Log; @@ -45,7 +46,7 @@ public class QuickInspectCommand extends SubCommand { @Override public boolean onCommand(ISender sender, String commandLabel, String[] args) { String playerName = MiscUtils.getPlayerName(args, sender, Permissions.QUICK_INSPECT_OTHER); - final RslTask inspectTask = new RslBukkitRunnable("QinspectTask") { + final RslTask inspectTask = plugin.getRunnableFactory().createNew(new RslRunnable("QinspectTask") { @Override public void run() { UUID uuid = ConditionUtils.getUUID(playerName); @@ -64,7 +65,7 @@ public class QuickInspectCommand extends SubCommand { } sender.sendMessage(Phrase.GRABBING_DATA_MESSAGE + ""); inspectCache.cache(uuid); - final RslTask inspectMessageSenderTask = new RslBukkitRunnable("QinspectMessageSenderTask") { + final RslTask inspectMessageSenderTask = plugin.getRunnableFactory().createNew(new RslRunnable("QinspectMessageSenderTask") { private int timesrun = 0; @Override @@ -82,10 +83,10 @@ public class QuickInspectCommand extends SubCommand { this.cancel(); } } - }.runTaskTimer(1 * 20, 5 * 20); + }).runTaskTimer(1 * 20, 5 * 20); this.cancel(); } - }.runTaskAsynchronously(); + }).runTaskAsynchronously(); return true; } } diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/SearchCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/SearchCommand.java index 08bcce13a..5695e3c59 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/SearchCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/SearchCommand.java @@ -4,6 +4,7 @@ import com.djrapitops.javaplugin.command.CommandType; import com.djrapitops.javaplugin.command.SubCommand; import com.djrapitops.javaplugin.command.sender.ISender; import com.djrapitops.javaplugin.task.RslBukkitRunnable; +import com.djrapitops.javaplugin.task.RslRunnable; import com.djrapitops.javaplugin.task.RslTask; import com.djrapitops.javaplugin.utilities.FormattingUtils; import java.util.Arrays; @@ -18,8 +19,6 @@ import main.java.com.djrapitops.plan.command.Condition; import main.java.com.djrapitops.plan.data.cache.InspectCacheHandler; import main.java.com.djrapitops.plan.utilities.MiscUtils; import org.bukkit.OfflinePlayer; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; /** * This subcommand is used to search for a user, and to view all matches' data. @@ -51,7 +50,7 @@ public class SearchCommand extends SubCommand { return true; } sender.sendMessage(Phrase.CMD_SEARCH_SEARCHING + ""); - final RslTask searchTask = new RslBukkitRunnable("SearchTask: " + Arrays.toString(args)) { + final RslTask searchTask =plugin.getRunnableFactory().createNew(new RslRunnable("SearchTask: " + Arrays.toString(args)) { @Override public void run() { try { @@ -70,7 +69,7 @@ public class SearchCommand extends SubCommand { this.cancel(); } } - }.runTaskAsynchronously(); + }).runTaskAsynchronously(); 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 3b54d6e39..79795f867 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 @@ -4,14 +4,13 @@ import com.djrapitops.javaplugin.command.CommandType; import com.djrapitops.javaplugin.command.SubCommand; import com.djrapitops.javaplugin.command.sender.ISender; import com.djrapitops.javaplugin.task.RslBukkitRunnable; +import com.djrapitops.javaplugin.task.RslRunnable; 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.database.Database; import main.java.com.djrapitops.plan.utilities.ManageUtils; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; /** * This manage subcommand is used to backup a database to a .db file. @@ -62,7 +61,7 @@ public class ManageBackupCommand extends SubCommand { return true; } final Database copyFromDB = database; - (new RslBukkitRunnable("BackupTask") { + plugin.getRunnableFactory().createNew(new RslRunnable("BackupTask") { @Override public void run() { sender.sendMessage(Phrase.MANAGE_PROCESS_START.parse()); 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 79e1ffcdc..5d9a23f1c 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 @@ -4,6 +4,7 @@ import com.djrapitops.javaplugin.command.CommandType; import com.djrapitops.javaplugin.command.SubCommand; import com.djrapitops.javaplugin.command.sender.ISender; import com.djrapitops.javaplugin.task.RslBukkitRunnable; +import com.djrapitops.javaplugin.task.RslRunnable; import main.java.com.djrapitops.plan.Log; import main.java.com.djrapitops.plan.Permissions; import main.java.com.djrapitops.plan.Phrase; @@ -59,7 +60,7 @@ public class ManageCleanCommand extends SubCommand { } final Database clearThisDB = clearDB; - (new RslBukkitRunnable("DBCleanTask") { + plugin.getRunnableFactory().createNew(new RslRunnable("DBCleanTask") { @Override public void run() { sender.sendMessage(Phrase.MANAGE_PROCESS_START.parse()); 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 e59ed03b3..f7e77774d 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 @@ -4,6 +4,7 @@ import com.djrapitops.javaplugin.command.CommandType; import com.djrapitops.javaplugin.command.SubCommand; import com.djrapitops.javaplugin.command.sender.ISender; import com.djrapitops.javaplugin.task.RslBukkitRunnable; +import com.djrapitops.javaplugin.task.RslRunnable; import java.sql.SQLException; import java.util.Arrays; import main.java.com.djrapitops.plan.Log; @@ -11,8 +12,6 @@ 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.database.Database; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; /** * This manage subcommand is used to clear a database of all data. @@ -65,7 +64,7 @@ public class ManageClearCommand extends SubCommand { } final Database clearThisDB = clearDB; - (new RslBukkitRunnable("DBClearTask") { + plugin.getRunnableFactory().createNew(new RslRunnable("DBClearTask") { @Override public void run() { sender.sendMessage(Phrase.MANAGE_PROCESS_START.parse()); 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 68b7d7444..ddac4f65d 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 @@ -3,7 +3,7 @@ package main.java.com.djrapitops.plan.command.commands.manage; import com.djrapitops.javaplugin.command.CommandType; import com.djrapitops.javaplugin.command.SubCommand; import com.djrapitops.javaplugin.command.sender.ISender; -import com.djrapitops.javaplugin.task.RslBukkitRunnable; +import com.djrapitops.javaplugin.task.RslRunnable; import com.djrapitops.javaplugin.task.RslTask; import java.util.Arrays; import java.util.List; @@ -63,12 +63,12 @@ public class ManageImportCommand extends SubCommand { return true; } - String[] arguments = new String[args.length-1]; + String[] arguments = new String[args.length - 1]; for (int i = 1; i < args.length; i++) { - arguments[i-1] = args[i]; + arguments[i - 1] = args[i]; } final Importer importer = importPlugins.get(importFromPlugin); - RslTask asyncImportTask = new RslBukkitRunnable("ImportTask") { + RslTask asyncImportTask = plugin.getRunnableFactory().createNew(new RslRunnable("ImportTask") { @Override public void run() { sender.sendMessage(Phrase.MANAGE_IMPORTING + ""); @@ -80,7 +80,7 @@ public class ManageImportCommand extends SubCommand { } this.cancel(); } - }.runTaskAsynchronously(); + }).runTaskAsynchronously(); return true; } @@ -88,7 +88,7 @@ public class ManageImportCommand extends SubCommand { sender.sendMessage(Phrase.CMD_FOOTER.parse()); Map importers = ImportUtils.getImporters(); for (String key : importers.keySet()) { - sender.sendMessage(Phrase.CMD_BALL+" "+key+": "+importers.get(key).getInfo()); + sender.sendMessage(Phrase.CMD_BALL + " " + key + ": " + importers.get(key).getInfo()); } sender.sendMessage(Phrase.CMD_FOOTER.parse()); } 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 cd68bee77..4679fff36 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 @@ -4,6 +4,7 @@ import com.djrapitops.javaplugin.command.CommandType; import com.djrapitops.javaplugin.command.SubCommand; import com.djrapitops.javaplugin.command.sender.ISender; import com.djrapitops.javaplugin.task.RslBukkitRunnable; +import com.djrapitops.javaplugin.task.RslRunnable; import java.util.Arrays; import java.util.Collection; import java.util.UUID; @@ -13,8 +14,6 @@ import main.java.com.djrapitops.plan.Phrase; import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.database.Database; import main.java.com.djrapitops.plan.utilities.ManageUtils; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; /** * This manage subcommand is used to move all data from one database to another. @@ -89,7 +88,7 @@ public class ManageMoveCommand extends SubCommand { final Database moveFromDB = fromDatabase; final Database moveToDB = toDatabase; - (new RslBukkitRunnable("DBMoveTask") { + plugin.getRunnableFactory().createNew(new RslRunnable("DBMoveTask") { @Override public void run() { final Collection uuids = ManageUtils.getUUIDS(moveFromDB); 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 07bdba5e9..f75dfc933 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 @@ -3,7 +3,7 @@ package main.java.com.djrapitops.plan.command.commands.manage; import com.djrapitops.javaplugin.command.CommandType; import com.djrapitops.javaplugin.command.SubCommand; import com.djrapitops.javaplugin.command.sender.ISender; -import com.djrapitops.javaplugin.task.RslBukkitRunnable; +import com.djrapitops.javaplugin.task.RslRunnable; import java.sql.SQLException; import java.util.Arrays; import java.util.UUID; @@ -13,8 +13,6 @@ import main.java.com.djrapitops.plan.Phrase; import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.utilities.MiscUtils; import main.java.com.djrapitops.plan.utilities.uuid.UUIDUtility; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; /** * This manage subcommand is used to remove a single player's data from the @@ -46,7 +44,7 @@ public class ManageRemoveCommand extends SubCommand { String playerName = MiscUtils.getPlayerName(args, sender, Permissions.MANAGE); - (new RslBukkitRunnable("DBRemoveTask " + playerName) { + plugin.getRunnableFactory().createNew(new RslRunnable("DBRemoveTask " + playerName) { @Override public void run() { UUID uuid; @@ -85,7 +83,7 @@ public class ManageRemoveCommand extends SubCommand { } this.cancel(); } - }).runTaskAsynchronously(plugin); + }).runTaskAsynchronously(); return true; } } 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 e64f2095f..cdd33ece1 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 @@ -4,6 +4,7 @@ import com.djrapitops.javaplugin.command.CommandType; import com.djrapitops.javaplugin.command.SubCommand; import com.djrapitops.javaplugin.command.sender.ISender; import com.djrapitops.javaplugin.task.RslBukkitRunnable; +import com.djrapitops.javaplugin.task.RslRunnable; import com.djrapitops.javaplugin.task.RslTask; import java.io.File; import java.util.Arrays; @@ -16,8 +17,6 @@ import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.database.Database; import main.java.com.djrapitops.plan.database.databases.SQLiteDB; import main.java.com.djrapitops.plan.utilities.ManageUtils; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; /** * This manage subcommand is used to restore a backup.db file in the @@ -72,7 +71,7 @@ public class ManageRestoreCommand extends SubCommand { return true; } final Database copyToDB = database; - RslTask asyncRestoreTask = new RslBukkitRunnable("RestoreTask") { + RslTask asyncRestoreTask = plugin.getRunnableFactory().createNew(new RslRunnable("RestoreTask") { @Override public void run() { String backupDBName = args[0]; @@ -109,7 +108,7 @@ public class ManageRestoreCommand extends SubCommand { } this.cancel(); } - }.runTaskAsynchronously(); + }).runTaskAsynchronously(); } catch (NullPointerException e) { sender.sendMessage(Phrase.MANAGE_DATABASE_FAILURE + ""); } 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 9a534d683..69ebab22f 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 @@ -1,6 +1,7 @@ package main.java.com.djrapitops.plan.data.cache; import com.djrapitops.javaplugin.task.RslBukkitRunnable; +import com.djrapitops.javaplugin.task.RslRunnable; import com.djrapitops.javaplugin.task.RslTask; import java.sql.SQLException; import java.util.ArrayList; @@ -34,6 +35,13 @@ import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; import static org.bukkit.Bukkit.getOfflinePlayer; +import static org.bukkit.Bukkit.getOfflinePlayer; +import static org.bukkit.Bukkit.getOfflinePlayer; +import static org.bukkit.Bukkit.getOfflinePlayer; +import static org.bukkit.Bukkit.getOfflinePlayer; +import static org.bukkit.Bukkit.getOfflinePlayer; +import static org.bukkit.Bukkit.getOfflinePlayer; +import static org.bukkit.Bukkit.getOfflinePlayer; /** * This Class contains the Cache. @@ -115,7 +123,7 @@ public class DataCacheHandler extends LocationCache { */ public void startQueues() { clearTask = new DataCacheClearQueue(this); - saveTask = new DataCacheSaveQueue(plugin, clearTask); + saveTask = new DataCacheSaveQueue(plugin, this); getTask = new DataCacheGetQueue(plugin); processTask = new DataCacheProcessQueue(this); } @@ -139,7 +147,7 @@ public class DataCacheHandler extends LocationCache { } else { clearAfterXsaves = configValue; } - RslTask asyncPeriodicCacheSaveTask = new RslBukkitRunnable("PeriodicCacheSaveTask") { + RslTask asyncPeriodicCacheSaveTask = plugin.getRunnableFactory().createNew(new RslRunnable("PeriodicCacheSaveTask") { private int timesSaved = 0; @Override @@ -159,12 +167,12 @@ public class DataCacheHandler extends LocationCache { saveUnsavedTPSHistory(); timesSaved++; } catch (Exception e) { - Log.toLog(this.getClass().getName() + "(" + this.getTaskName() + ")", e); + Log.toLog(this.getClass().getName() + "(" + this.getName() + ")", e); } finally { periodicTaskIsSaving = false; } } - }.runTaskTimerAsynchronously(60 * 20 * minutes, 60 * 20 * minutes); + }).runTaskTimerAsynchronously(60 * 20 * minutes, 60 * 20 * minutes); } /** @@ -518,7 +526,7 @@ public class DataCacheHandler extends LocationCache { * Calls all the methods that are ran when PlayerJoinEvent is fired */ public void handleReload() { - RslTask asyncReloadCacheUpdateTask = (new RslBukkitRunnable("ReloadCacheUpdateTask") { + RslTask asyncReloadCacheUpdateTask = plugin.getRunnableFactory().createNew(new RslRunnable("ReloadCacheUpdateTask") { @Override public void run() { for (Player player : Bukkit.getOnlinePlayers()) { diff --git a/Plan/src/main/java/com/djrapitops/plan/data/cache/queue/Consumer.java b/Plan/src/main/java/com/djrapitops/plan/data/cache/queue/Consumer.java index cd393662d..e1dc36160 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/cache/queue/Consumer.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/cache/queue/Consumer.java @@ -1,8 +1,7 @@ package main.java.com.djrapitops.plan.data.cache.queue; -import com.djrapitops.javaplugin.task.RslBukkitRunnable; +import com.djrapitops.javaplugin.task.RslRunnable; import java.util.concurrent.BlockingQueue; -import main.java.com.djrapitops.plan.Plan; /** * Abstract class representing a queue consumer. @@ -10,7 +9,7 @@ import main.java.com.djrapitops.plan.Plan; * @author Rsl1122 * @param */ -public abstract class Consumer extends RslBukkitRunnable { +public abstract class Consumer extends RslRunnable { boolean run; final BlockingQueue queue; diff --git a/Plan/src/main/java/com/djrapitops/plan/data/cache/queue/DataCacheGetQueue.java b/Plan/src/main/java/com/djrapitops/plan/data/cache/queue/DataCacheGetQueue.java index d2dd7b7ab..9fe06e129 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/cache/queue/DataCacheGetQueue.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/cache/queue/DataCacheGetQueue.java @@ -46,15 +46,19 @@ public class DataCacheGetQueue extends Queue Log.debug(uuid + ": Scheduling for get"); try { Map> map = new HashMap<>(); - if (map.get(uuid) == null) { - map.put(uuid, new ArrayList<>()); - } - map.get(uuid).addAll(Arrays.asList(processors)); + map.put(uuid, Arrays.asList(processors)); queue.add(map); } catch (IllegalStateException e) { Log.error(Phrase.ERROR_TOO_SMALL_QUEUE.parse("Get Queue", Settings.PROCESS_GET_LIMIT.getNumber() + "")); } } + + public boolean containsUUIDtoBeCached(UUID uuid) { + if (uuid == null) { + return false; + } + return new ArrayList<>(queue).stream().anyMatch((map) -> (map.get(uuid) != null && map.get(uuid).size() >= 2)); // Map has 2 processors if being cached + } } class GetConsumer extends Consumer>> { diff --git a/Plan/src/main/java/com/djrapitops/plan/data/cache/queue/DataCacheProcessQueue.java b/Plan/src/main/java/com/djrapitops/plan/data/cache/queue/DataCacheProcessQueue.java index b0988894b..8b1389fbf 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/cache/queue/DataCacheProcessQueue.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/cache/queue/DataCacheProcessQueue.java @@ -66,7 +66,10 @@ public class DataCacheProcessQueue extends Queue { * @return true/false */ public boolean containsUUID(UUID uuid) { - return new ArrayList<>(queue).stream().map(d -> d.getUuid()).collect(Collectors.toList()).contains(uuid); + if (uuid == null) { + return false; + } + return new ArrayList<>(queue).stream().anyMatch(info -> info.getUuid().equals(uuid)); } } @@ -84,6 +87,10 @@ class ProcessConsumer extends Consumer { if (handler == null) { return; } + if (handler.getGetTask().containsUUIDtoBeCached(info.getUuid())) { // Wait for get queue. + queue.add(info); + return; + } Log.debug(info.getUuid() + ": Processing type: " + info.getType().name()); DBCallableProcessor p = new DBCallableProcessor() { @Override @@ -105,6 +112,7 @@ class ProcessConsumer extends Consumer { } class ProcessSetup extends Setup { + ProcessSetup(BlockingQueue q, DataCacheHandler h) { super(new ProcessConsumer(q, h), new ProcessConsumer(q, h)); } diff --git a/Plan/src/main/java/com/djrapitops/plan/data/cache/queue/DataCacheSaveQueue.java b/Plan/src/main/java/com/djrapitops/plan/data/cache/queue/DataCacheSaveQueue.java index aaf458007..55aeebd6b 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/cache/queue/DataCacheSaveQueue.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/cache/queue/DataCacheSaveQueue.java @@ -12,6 +12,7 @@ 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.UserData; +import main.java.com.djrapitops.plan.data.cache.DataCacheHandler; import main.java.com.djrapitops.plan.database.Database; /** @@ -20,18 +21,17 @@ import main.java.com.djrapitops.plan.database.Database; * @author Rsl1122 * @since 3.0.0 */ -public class DataCacheSaveQueue extends Queue{ +public class DataCacheSaveQueue extends Queue { /** * Class constructor, starts the new Thread for saving. * * @param plugin current instance of Plan - * @param clear current instance of the Clear task to schedule clear if - * UserData.clearAfterSave() is true + * @param handler DataCacheHandler */ - public DataCacheSaveQueue(Plan plugin, DataCacheClearQueue clear) { + public DataCacheSaveQueue(Plan plugin, DataCacheHandler handler) { super(new ArrayBlockingQueue(Settings.PROCESS_SAVE_LIMIT.getNumber())); - setup = new SaveSetup(queue, clear, plugin.getDB()); + setup = new SaveSetup(queue, handler, plugin.getDB()); setup.go(); } @@ -84,19 +84,22 @@ public class DataCacheSaveQueue extends Queue{ * @return true/false */ public boolean containsUUID(UUID uuid) { - return new ArrayList<>(queue).stream().map(d -> d.getUuid()).collect(Collectors.toList()).contains(uuid); + if (uuid == null) { + return false; + } + return new ArrayList<>(queue).stream().anyMatch(d -> d.getUuid().equals(uuid)); } } class SaveConsumer extends Consumer { private Database db; - private DataCacheClearQueue clear; + private DataCacheHandler handler; - SaveConsumer(BlockingQueue q, DataCacheClearQueue clear, Database db) { + SaveConsumer(BlockingQueue q, DataCacheHandler handler, Database db) { super(q, "SaveQueueConsumer"); this.db = db; - this.clear = clear; + this.handler = handler; run = true; } @@ -106,14 +109,18 @@ class SaveConsumer extends Consumer { return; } UUID uuid = data.getUuid(); + if (handler.getProcessTask().containsUUID(uuid)) { // Wait for process queue. + queue.add(data); + return; + } Log.debug(uuid + ": Saving: " + uuid); try { db.saveUserData(data); data.stopAccessing(); Log.debug(uuid + ": Saved!"); if (data.shouldClearAfterSave()) { - if (clear != null) { - clear.scheduleForClear(uuid); + if (handler != null) { + handler.getClearTask().scheduleForClear(uuid); } } } catch (SQLException ex) { @@ -127,14 +134,15 @@ class SaveConsumer extends Consumer { if (db != null) { db = null; } - if (clear != null) { - clear = null; + if (handler != null) { + handler = null; } } } -class SaveSetup extends Setup{ - SaveSetup(BlockingQueue q, DataCacheClearQueue clear, Database db) { - super(new SaveConsumer(q, clear, db), new SaveConsumer(q, clear, db)); +class SaveSetup extends Setup { + + SaveSetup(BlockingQueue q, DataCacheHandler handler, Database db) { + super(new SaveConsumer(q, handler, db), new SaveConsumer(q, handler, db)); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/data/cache/queue/Setup.java b/Plan/src/main/java/com/djrapitops/plan/data/cache/queue/Setup.java index 5744cd753..153819e3f 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/cache/queue/Setup.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/cache/queue/Setup.java @@ -1,6 +1,5 @@ package main.java.com.djrapitops.plan.data.cache.queue; -import com.djrapitops.javaplugin.task.RslBukkitRunnable; import main.java.com.djrapitops.plan.Plan; /** @@ -10,7 +9,7 @@ import main.java.com.djrapitops.plan.Plan; * @param Object this queue consumes. */ public abstract class Setup { - + private final Consumer[] consumers; /** @@ -21,13 +20,13 @@ public abstract class Setup { public Setup(Consumer... consumers) { this.consumers = consumers; } - + void go() { for (Consumer consumer : consumers) { - consumer.runTaskAsynchronously(); + Plan.getInstance().getRunnableFactory().createNew(consumer).runTaskAsynchronously(); } } - + void stop() { for (Consumer consumer : consumers) { consumer.stop(); diff --git a/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanPlayerListener.java b/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanPlayerListener.java index fb710ad5a..9d9228056 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanPlayerListener.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanPlayerListener.java @@ -1,6 +1,7 @@ package main.java.com.djrapitops.plan.data.listeners; import com.djrapitops.javaplugin.task.RslBukkitRunnable; +import com.djrapitops.javaplugin.task.RslRunnable; import com.djrapitops.javaplugin.task.RslTask; import java.util.UUID; import main.java.com.djrapitops.plan.Log; @@ -57,7 +58,7 @@ public class PlanPlayerListener implements Listener { UUID uuid = player.getUniqueId(); handler.startSession(uuid); Log.debug(uuid + ": PlayerJoinEvent"); - RslTask asyncNewPlayerCheckTask = new RslBukkitRunnable("NewPlayerCheckTask") { + RslTask asyncNewPlayerCheckTask = plugin.getRunnableFactory().createNew(new RslRunnable("NewPlayerCheckTask") { @Override public void run() { LoginInfo loginInfo = new LoginInfo(uuid, MiscUtils.getTime(), player.getAddress().getAddress(), player.isBanned(), player.getDisplayName(), player.getGameMode(), 1); @@ -72,7 +73,7 @@ public class PlanPlayerListener implements Listener { Log.debug(uuid + ": PlayerJoinEvent_AsyncTask_END, New:" + isNewPlayer); this.cancel(); } - }.runTaskAsynchronously(); + }).runTaskAsynchronously(); Log.debug(uuid + ": PlayerJoinEvent_END"); } 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 0e7dcdb9d..5008ae9fd 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 @@ -1,7 +1,7 @@ package main.java.com.djrapitops.plan.data.listeners; import com.djrapitops.javaplugin.api.TimeAmount; -import com.djrapitops.javaplugin.task.RslBukkitRunnable; +import com.djrapitops.javaplugin.task.RslRunnable; import java.util.ArrayList; import java.util.List; import main.java.com.djrapitops.plan.Plan; @@ -14,7 +14,7 @@ import main.java.com.djrapitops.plan.utilities.MiscUtils; * * @author Rsl1122 */ -public class TPSCountTimer extends RslBukkitRunnable { +public class TPSCountTimer extends RslRunnable { private long lastCheckNano; private final Plan plugin; diff --git a/Plan/src/main/java/com/djrapitops/plan/database/databases/SQLDB.java b/Plan/src/main/java/com/djrapitops/plan/database/databases/SQLDB.java index 92675f5dd..807f48916 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/databases/SQLDB.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/databases/SQLDB.java @@ -1,6 +1,7 @@ package main.java.com.djrapitops.plan.database.databases; import com.djrapitops.javaplugin.task.RslBukkitRunnable; +import com.djrapitops.javaplugin.task.RslRunnable; import java.net.InetAddress; import java.sql.Connection; import java.sql.SQLException; @@ -67,7 +68,7 @@ public abstract class SQLDB extends Database { */ public void startConnectionPingTask(Plan plugin) throws IllegalArgumentException, IllegalStateException { // Maintains Connection. - new RslBukkitRunnable("DBConnectionPingTask " + getName()) { + plugin.getRunnableFactory().createNew(new RslRunnable("DBConnectionPingTask " + getName()) { @Override public void run() { try { @@ -78,7 +79,7 @@ public abstract class SQLDB extends Database { connection = getNewConnection(); } } - }.runTaskTimerAsynchronously(60 * 20, 60 * 20); + }).runTaskTimerAsynchronously(60 * 20, 60 * 20); } /** @@ -150,7 +151,7 @@ public abstract class SQLDB extends Database { * */ public void convertBukkitDataToDB() { - new RslBukkitRunnable("BukkitDataConversionTask") { + plugin.getRunnableFactory().createNew(new RslRunnable("BukkitDataConversionTask") { @Override public void run() { try { @@ -177,7 +178,7 @@ public abstract class SQLDB extends Database { this.cancel(); } } - }.runTaskAsynchronously(); + }).runTaskAsynchronously(); } /** diff --git a/Plan/src/main/java/com/djrapitops/plan/ui/webserver/WebSocketServer.java b/Plan/src/main/java/com/djrapitops/plan/ui/webserver/WebSocketServer.java index e6a20d558..b7afefbac 100644 --- a/Plan/src/main/java/com/djrapitops/plan/ui/webserver/WebSocketServer.java +++ b/Plan/src/main/java/com/djrapitops/plan/ui/webserver/WebSocketServer.java @@ -1,6 +1,7 @@ package main.java.com.djrapitops.plan.ui.webserver; import com.djrapitops.javaplugin.task.RslBukkitRunnable; +import com.djrapitops.javaplugin.task.RslRunnable; import java.io.Closeable; import java.io.IOException; import java.io.InputStream; @@ -60,7 +61,7 @@ public class WebSocketServer { System.exit(1); } //Run server in seperate thread - (new RslBukkitRunnable("WebServerTask") { + plugin.getRunnableFactory().createNew(new RslRunnable("WebServerTask") { @Override public void run() { while (!shutdown) { diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java index 33691f35b..0db1f6376 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java @@ -2,6 +2,7 @@ package main.java.com.djrapitops.plan.utilities.analysis; import com.djrapitops.javaplugin.api.TimeAmount; import com.djrapitops.javaplugin.task.RslBukkitRunnable; +import com.djrapitops.javaplugin.task.RslRunnable; import com.djrapitops.javaplugin.task.RslTask; import java.util.ArrayList; import main.java.com.djrapitops.plan.data.additional.HookHandler; @@ -77,7 +78,7 @@ public class Analysis { plugin.processStatus().startExecution("Analysis"); log(Phrase.ANALYSIS_START + ""); // Async task for Analysis - RslTask asyncAnalysisTask = (new RslBukkitRunnable("AnalysisTask") { + RslTask asyncAnalysisTask = plugin.getRunnableFactory().createNew(new RslRunnable("AnalysisTask") { @Override public void run() { taskId = this.getTaskId(); diff --git a/Plan/src/test/java/utils/TestInit.java b/Plan/src/test/java/utils/TestInit.java index a879bd99e..9c5e05554 100644 --- a/Plan/src/test/java/utils/TestInit.java +++ b/Plan/src/test/java/utils/TestInit.java @@ -75,7 +75,7 @@ public class TestInit { when(planMock.processStatus()).thenReturn(process); BenchmarkUtil bench = new BenchmarkUtil(); when(planMock.benchmark()).thenReturn(bench); - Plan.setInstance(planMock); + Plan.setInstance(Plan.class, planMock); // Mockito.doReturn("0.0.0.0").when(planMock).getServer().getIp(); Settings.DEBUG.setValue(true); return true;