From b8b3098022302908e34bea203071dfd5cc6cf61d Mon Sep 17 00:00:00 2001 From: michizhou <33012425+michizhou@users.noreply.github.com> Date: Mon, 17 Oct 2022 00:31:48 -0700 Subject: [PATCH] feat: Move ExpireManager to Guice by removing legacy IMP references (#3845) * feat: Move ExpireManager to Guice by removing legacy IMP references * Mark ExpireManager IMP as deprecated and add comments * Add import for PlotPlatform for function reference * Add ExpireManager instance call and optimize performance --- .../main/java/com/plotsquared/core/PlotPlatform.java | 11 +++++++++++ .../main/java/com/plotsquared/core/PlotSquared.java | 9 +++++---- .../java/com/plotsquared/core/command/DebugExec.java | 9 ++++----- .../main/java/com/plotsquared/core/command/Done.java | 4 ++-- .../java/com/plotsquared/core/command/ListCmd.java | 3 +-- .../main/java/com/plotsquared/core/command/Trim.java | 5 ++--- .../com/plotsquared/core/listener/PlotListener.java | 5 ++--- .../java/com/plotsquared/core/player/PlotPlayer.java | 5 ++--- .../src/main/java/com/plotsquared/core/plot/Plot.java | 9 ++++----- .../core/plot/expiration/ExpireManager.java | 5 +++++ .../plotsquared/core/plot/expiration/ExpiryTask.java | 4 +++- .../com/plotsquared/core/util/EventDispatcher.java | 6 +++--- .../core/util/query/ExpiredPlotProvider.java | 4 ++-- 13 files changed, 46 insertions(+), 33 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/PlotPlatform.java b/Core/src/main/java/com/plotsquared/core/PlotPlatform.java index 020c3c740..b601140f6 100644 --- a/Core/src/main/java/com/plotsquared/core/PlotPlatform.java +++ b/Core/src/main/java/com/plotsquared/core/PlotPlatform.java @@ -32,6 +32,7 @@ import com.plotsquared.core.inject.annotations.DefaultGenerator; import com.plotsquared.core.location.World; import com.plotsquared.core.permissions.PermissionHandler; import com.plotsquared.core.player.PlotPlayer; +import com.plotsquared.core.plot.expiration.ExpireManager; import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.queue.GlobalBlockQueue; import com.plotsquared.core.util.ChunkManager; @@ -284,6 +285,16 @@ public interface PlotPlatform
extends LocaleHolder {
return injector().getInstance(ChunkManager.class);
}
+ /**
+ * Get the {@link ExpireManager} implementation for the platform
+ *
+ * @return Expire manager
+ * @since TODO
+ */
+ default @NonNull ExpireManager expireManager() {
+ return injector().getInstance(ExpireManager.class);
+ }
+
/**
* Get the {@link PlotAreaManager} implementation.
*
diff --git a/Core/src/main/java/com/plotsquared/core/PlotSquared.java b/Core/src/main/java/com/plotsquared/core/PlotSquared.java
index 5f89c69c1..76156fc21 100644
--- a/Core/src/main/java/com/plotsquared/core/PlotSquared.java
+++ b/Core/src/main/java/com/plotsquared/core/PlotSquared.java
@@ -290,11 +290,11 @@ public class PlotSquared {
public void startExpiryTasks() {
if (Settings.Enabled_Components.PLOT_EXPIRY) {
- ExpireManager.IMP = new ExpireManager(this.eventDispatcher);
- ExpireManager.IMP.runAutomatedTask();
+ ExpireManager expireManager = PlotSquared.platform().expireManager();
+ expireManager.runAutomatedTask();
for (Settings.Auto_Clear settings : Settings.AUTO_CLEAR.getInstances()) {
ExpiryTask task = new ExpiryTask(settings, this.getPlotAreaManager());
- ExpireManager.IMP.addTask(task);
+ expireManager.addTask(task);
}
}
}
@@ -645,7 +645,8 @@ public class PlotSquared {
} else {
list = new ArrayList<>(input);
}
- list.sort(Comparator.comparingLong(a -> ExpireManager.IMP.getTimestamp(a.getOwnerAbs())));
+ ExpireManager expireManager = PlotSquared.platform().expireManager();
+ list.sort(Comparator.comparingLong(a -> expireManager.getTimestamp(a.getOwnerAbs())));
return list;
}
diff --git a/Core/src/main/java/com/plotsquared/core/command/DebugExec.java b/Core/src/main/java/com/plotsquared/core/command/DebugExec.java
index 7290a544c..9566bbc3c 100644
--- a/Core/src/main/java/com/plotsquared/core/command/DebugExec.java
+++ b/Core/src/main/java/com/plotsquared/core/command/DebugExec.java
@@ -19,6 +19,7 @@
package com.plotsquared.core.command;
import com.google.inject.Inject;
+import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.caption.StaticCaption;
import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.events.PlotFlagRemoveEvent;
@@ -139,10 +140,8 @@ public class DebugExec extends SubCommand {
return true;
}
case "start-expire" -> {
- if (ExpireManager.IMP == null) {
- ExpireManager.IMP = new ExpireManager(this.eventDispatcher);
- }
- if (ExpireManager.IMP.runAutomatedTask()) {
+ ExpireManager expireManager = PlotSquared.platform().expireManager() == null ? new ExpireManager(this.eventDispatcher) : PlotSquared.platform().expireManager();
+ if (expireManager.runAutomatedTask()) {
player.sendMessage(TranslatableCaption.of("debugexec.expiry_started"));
} else {
player.sendMessage(TranslatableCaption.of("debugexec.expiry_already_started"));
@@ -150,7 +149,7 @@ public class DebugExec extends SubCommand {
return true;
}
case "stop-expire" -> {
- if (ExpireManager.IMP == null || !ExpireManager.IMP.cancelTask()) {
+ if (PlotSquared.platform().expireManager() == null || !PlotSquared.platform().expireManager().cancelTask()) {
player.sendMessage(TranslatableCaption.of("debugexec.task_halted"));
} else {
player.sendMessage(TranslatableCaption.of("debugexec.task_cancelled"));
diff --git a/Core/src/main/java/com/plotsquared/core/command/Done.java b/Core/src/main/java/com/plotsquared/core/command/Done.java
index 6537daeef..c50bdfce9 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Done.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Done.java
@@ -19,6 +19,7 @@
package com.plotsquared.core.command;
import com.google.inject.Inject;
+import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.events.PlotDoneEvent;
@@ -29,7 +30,6 @@ import com.plotsquared.core.location.Location;
import com.plotsquared.core.permissions.Permission;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
-import com.plotsquared.core.plot.expiration.ExpireManager;
import com.plotsquared.core.plot.expiration.PlotAnalysis;
import com.plotsquared.core.plot.flag.PlotFlag;
import com.plotsquared.core.plot.flag.implementations.DoneFlag;
@@ -94,7 +94,7 @@ public class Done extends SubCommand {
Template.of("plot", plot.getId().toString())
);
final Settings.Auto_Clear doneRequirements = Settings.AUTO_CLEAR.get("done");
- if (ExpireManager.IMP == null || doneRequirements == null) {
+ if (PlotSquared.platform().expireManager() == null || doneRequirements == null) {
finish(plot, player, true);
plot.removeRunning();
} else {
diff --git a/Core/src/main/java/com/plotsquared/core/command/ListCmd.java b/Core/src/main/java/com/plotsquared/core/command/ListCmd.java
index b47a99e25..fcb161926 100644
--- a/Core/src/main/java/com/plotsquared/core/command/ListCmd.java
+++ b/Core/src/main/java/com/plotsquared/core/command/ListCmd.java
@@ -30,7 +30,6 @@ import com.plotsquared.core.permissions.Permission;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
-import com.plotsquared.core.plot.expiration.ExpireManager;
import com.plotsquared.core.plot.flag.implementations.DoneFlag;
import com.plotsquared.core.plot.flag.implementations.PriceFlag;
import com.plotsquared.core.plot.flag.implementations.ServerPlotFlag;
@@ -240,7 +239,7 @@ public class ListCmd extends SubCommand {
);
return false;
}
- if (ExpireManager.IMP == null) {
+ if (PlotSquared.platform().expireManager() == null) {
plotConsumer.accept(PlotQuery.newQuery().noPlots());
} else {
plotConsumer.accept(PlotQuery.newQuery().expiredPlots());
diff --git a/Core/src/main/java/com/plotsquared/core/command/Trim.java b/Core/src/main/java/com/plotsquared/core/command/Trim.java
index 09a5ff925..ca4603bd3 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Trim.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Trim.java
@@ -25,7 +25,6 @@ import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
-import com.plotsquared.core.plot.expiration.ExpireManager;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.queue.GlobalBlockQueue;
import com.plotsquared.core.queue.QueueCoordinator;
@@ -92,8 +91,8 @@ public class Trim extends SubCommand {
}
TranslatableCaption.of("trim.trim_starting");
final List implements CommandCaller, OfflinePlotPlayer,
LOGGER.info("Plot {} was deleted + cleared due to {} getting banned", owned.getId(), getName());
}
}
- if (ExpireManager.IMP != null) {
- ExpireManager.IMP.storeDate(getUUID(), System.currentTimeMillis());
+ if (PlotSquared.platform().expireManager() != null) {
+ PlotSquared.platform().expireManager().storeDate(getUUID(), System.currentTimeMillis());
}
PlotSquared.platform().playerManager().removePlayer(this);
PlotSquared.platform().unregister(this);
diff --git a/Core/src/main/java/com/plotsquared/core/plot/Plot.java b/Core/src/main/java/com/plotsquared/core/plot/Plot.java
index 757f89012..098b95656 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/Plot.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/Plot.java
@@ -40,7 +40,6 @@ import com.plotsquared.core.location.Location;
import com.plotsquared.core.permissions.Permission;
import com.plotsquared.core.player.ConsolePlayer;
import com.plotsquared.core.player.PlotPlayer;
-import com.plotsquared.core.plot.expiration.ExpireManager;
import com.plotsquared.core.plot.expiration.PlotAnalysis;
import com.plotsquared.core.plot.flag.FlagContainer;
import com.plotsquared.core.plot.flag.GlobalFlagContainer;
@@ -1105,8 +1104,8 @@ public class Plot {
* @return A boolean indicating whether or not the operation succeeded
*/
public