Skip to content

Commit

Permalink
Improvements & Fix #147
Browse files Browse the repository at this point in the history
- RslPlugin v1.4.0
- RunnableFactory
- Prevented a collision if multiple RslPlugin implementations are
installed.
- Queues now wait for each other.
  • Loading branch information
AuroraLS3 committed Jul 4, 2017
1 parent b004507 commit 8cf22de
Show file tree
Hide file tree
Showing 26 changed files with 122 additions and 94 deletions.
2 changes: 1 addition & 1 deletion Plan/src/main/java/com/djrapitops/plan/Log.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
13 changes: 7 additions & 6 deletions Plan/src/main/java/com/djrapitops/plan/Plan.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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;
Expand Down Expand Up @@ -114,7 +115,7 @@ public void onEnable() {
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));

Expand Down Expand Up @@ -231,7 +232,7 @@ public boolean initDatabase() {
}

private void startAnalysisRefreshTask(int analysisRefreshMinutes) throws IllegalStateException, IllegalArgumentException {
RslTask task = new RslBukkitRunnable<Plan>("PeriodicalAnalysisTask") {
RslTask task = getRunnableFactory().createNew("PeriodicalAnalysisTask", new RslRunnable() {
@Override
public void run() {
if (!analysisCache.isCached()) {
Expand All @@ -240,19 +241,19 @@ public void run() {
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<Plan>("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();
}

Expand Down Expand Up @@ -429,6 +430,6 @@ public static API getPlanAPI() throws IllegalStateException {
* @return this object.
*/
public static Plan getInstance() {
return (Plan) getPluginInstance();
return (Plan) getPluginInstance(Plan.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,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;
Expand Down Expand Up @@ -61,7 +61,7 @@ public boolean onCommand(ISender sender, String commandLabel, String[] args) {
}
analysisCache.updateCache();
}
final RslTask task = new RslBukkitRunnable<Plan>("AnalysisMessageSenderTask") {
final RslTask task = plugin.getRunnableFactory().createNew("AnalysisMessageSenderTask", new RslRunnable() {
private int timesrun = 0;

@Override
Expand All @@ -78,7 +78,7 @@ public void run() {
this.cancel();
}
}
}.runTaskTimer(1 * 20, 5 * 20);
}).runTaskTimer(1 * 20, 5 * 20);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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;
Expand Down Expand Up @@ -50,7 +51,7 @@ public boolean onCommand(ISender sender, String commandLabel, String[] args) {
return true;
}
String playerName = MiscUtils.getPlayerName(args, sender);
final RslTask inspectTask = new RslBukkitRunnable<Plan>("InspectTask") {
final RslTask inspectTask = plugin.getRunnableFactory().createNew(new RslRunnable("InspectTask") {
@Override
public void run() {
UUID uuid = ConditionUtils.getUUID(playerName);
Expand All @@ -69,7 +70,7 @@ public void run() {
}
sender.sendMessage(Phrase.GRABBING_DATA_MESSAGE + "");
inspectCache.cache(uuid);
final RslTask inspectMessageSenderTask = new RslBukkitRunnable<Plan>("InspectMessageSenderTask") {
final RslTask inspectMessageSenderTask = plugin.getRunnableFactory().createNew(new RslRunnable("InspectMessageSenderTask") {
private int timesrun = 0;

@Override
Expand All @@ -87,10 +88,10 @@ public void run() {
}
}

}.runTaskTimer(1 * 20, 5 * 20);
}).runTaskTimer(1 * 20, 5 * 20);
this.cancel();
}
}.runTaskAsynchronously();
}).runTaskAsynchronously();
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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;
Expand Down Expand Up @@ -56,7 +57,7 @@ public boolean onCommand(ISender sender, String commandLabel, String[] args) {
analysisCache.updateCache();
}

RslTask analysisMessageSenderTask = new RslBukkitRunnable<Plan>("QanalysisMessageSenderTask") {
RslTask analysisMessageSenderTask = plugin.getRunnableFactory().createNew(new RslRunnable("QanalysisMessageSenderTask") {
private int timesrun = 0;

@Override
Expand All @@ -74,7 +75,7 @@ public void run() {
this.cancel();
}
}
}.runTaskTimer(1 * 20, 5 * 20);
}).runTaskTimer(1 * 20, 5 * 20);
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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;
Expand Down Expand Up @@ -45,7 +46,7 @@ public QuickInspectCommand(Plan plugin) {
@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<Plan>("QinspectTask") {
final RslTask inspectTask = plugin.getRunnableFactory().createNew(new RslRunnable("QinspectTask") {
@Override
public void run() {
UUID uuid = ConditionUtils.getUUID(playerName);
Expand All @@ -64,7 +65,7 @@ public void run() {
}
sender.sendMessage(Phrase.GRABBING_DATA_MESSAGE + "");
inspectCache.cache(uuid);
final RslTask inspectMessageSenderTask = new RslBukkitRunnable<Plan>("QinspectMessageSenderTask") {
final RslTask inspectMessageSenderTask = plugin.getRunnableFactory().createNew(new RslRunnable("QinspectMessageSenderTask") {
private int timesrun = 0;

@Override
Expand All @@ -82,10 +83,10 @@ public void run() {
this.cancel();
}
}
}.runTaskTimer(1 * 20, 5 * 20);
}).runTaskTimer(1 * 20, 5 * 20);
this.cancel();
}
}.runTaskAsynchronously();
}).runTaskAsynchronously();
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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;
Expand All @@ -18,8 +19,6 @@
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.
Expand Down Expand Up @@ -51,7 +50,7 @@ public boolean onCommand(ISender sender, String commandLabel, String[] args) {
return true;
}
sender.sendMessage(Phrase.CMD_SEARCH_SEARCHING + "");
final RslTask searchTask = new RslBukkitRunnable<Plan>("SearchTask: " + Arrays.toString(args)) {
final RslTask searchTask =plugin.getRunnableFactory().createNew(new RslRunnable("SearchTask: " + Arrays.toString(args)) {
@Override
public void run() {
try {
Expand All @@ -70,7 +69,7 @@ public void run() {
this.cancel();
}
}
}.runTaskAsynchronously();
}).runTaskAsynchronously();
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
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.
Expand Down Expand Up @@ -62,7 +61,7 @@ public boolean onCommand(ISender sender, String commandLabel, String[] args) {
return true;
}
final Database copyFromDB = database;
(new RslBukkitRunnable<Plan>("BackupTask") {
plugin.getRunnableFactory().createNew(new RslRunnable("BackupTask") {
@Override
public void run() {
sender.sendMessage(Phrase.MANAGE_PROCESS_START.parse());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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;
Expand Down Expand Up @@ -59,7 +60,7 @@ public boolean onCommand(ISender sender, String commandLabel, String[] args) {
}

final Database clearThisDB = clearDB;
(new RslBukkitRunnable<Plan>("DBCleanTask") {
plugin.getRunnableFactory().createNew(new RslRunnable("DBCleanTask") {
@Override
public void run() {
sender.sendMessage(Phrase.MANAGE_PROCESS_START.parse());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
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;
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.
Expand Down Expand Up @@ -65,7 +64,7 @@ public boolean onCommand(ISender sender, String commandLabel, String[] args) {
}

final Database clearThisDB = clearDB;
(new RslBukkitRunnable<Plan>("DBClearTask") {
plugin.getRunnableFactory().createNew(new RslRunnable("DBClearTask") {
@Override
public void run() {
sender.sendMessage(Phrase.MANAGE_PROCESS_START.parse());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,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.Arrays;
import java.util.List;
Expand Down Expand Up @@ -63,12 +63,12 @@ public boolean onCommand(ISender sender, String commandLabel, String[] args) {
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<Plan>("ImportTask") {
RslTask asyncImportTask = plugin.getRunnableFactory().createNew(new RslRunnable("ImportTask") {
@Override
public void run() {
sender.sendMessage(Phrase.MANAGE_IMPORTING + "");
Expand All @@ -80,15 +80,15 @@ public void run() {
}
this.cancel();
}
}.runTaskAsynchronously();
}).runTaskAsynchronously();
return true;
}

private void list(ISender sender) {
sender.sendMessage(Phrase.CMD_FOOTER.parse());
Map<String, Importer> 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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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;
Expand All @@ -13,8 +14,6 @@
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.
Expand Down Expand Up @@ -89,7 +88,7 @@ public boolean onCommand(ISender sender, String commandLabel, String[] args) {

final Database moveFromDB = fromDatabase;
final Database moveToDB = toDatabase;
(new RslBukkitRunnable<Plan>("DBMoveTask") {
plugin.getRunnableFactory().createNew(new RslRunnable("DBMoveTask") {
@Override
public void run() {
final Collection<UUID> uuids = ManageUtils.getUUIDS(moveFromDB);
Expand Down
Loading

0 comments on commit 8cf22de

Please sign in to comment.