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
This commit is contained in:
michizhou 2022-10-17 00:31:48 -07:00 committed by GitHub
parent 0ae8fc46b8
commit b8b3098022
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 46 additions and 33 deletions

View File

@ -32,6 +32,7 @@ import com.plotsquared.core.inject.annotations.DefaultGenerator;
import com.plotsquared.core.location.World; import com.plotsquared.core.location.World;
import com.plotsquared.core.permissions.PermissionHandler; import com.plotsquared.core.permissions.PermissionHandler;
import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.expiration.ExpireManager;
import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.queue.GlobalBlockQueue; import com.plotsquared.core.queue.GlobalBlockQueue;
import com.plotsquared.core.util.ChunkManager; import com.plotsquared.core.util.ChunkManager;
@ -284,6 +285,16 @@ public interface PlotPlatform<P> extends LocaleHolder {
return injector().getInstance(ChunkManager.class); 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. * Get the {@link PlotAreaManager} implementation.
* *

View File

@ -290,11 +290,11 @@ public class PlotSquared {
public void startExpiryTasks() { public void startExpiryTasks() {
if (Settings.Enabled_Components.PLOT_EXPIRY) { if (Settings.Enabled_Components.PLOT_EXPIRY) {
ExpireManager.IMP = new ExpireManager(this.eventDispatcher); ExpireManager expireManager = PlotSquared.platform().expireManager();
ExpireManager.IMP.runAutomatedTask(); expireManager.runAutomatedTask();
for (Settings.Auto_Clear settings : Settings.AUTO_CLEAR.getInstances()) { for (Settings.Auto_Clear settings : Settings.AUTO_CLEAR.getInstances()) {
ExpiryTask task = new ExpiryTask(settings, this.getPlotAreaManager()); ExpiryTask task = new ExpiryTask(settings, this.getPlotAreaManager());
ExpireManager.IMP.addTask(task); expireManager.addTask(task);
} }
} }
} }
@ -645,7 +645,8 @@ public class PlotSquared {
} else { } else {
list = new ArrayList<>(input); 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; return list;
} }

View File

@ -19,6 +19,7 @@
package com.plotsquared.core.command; package com.plotsquared.core.command;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.caption.StaticCaption; import com.plotsquared.core.configuration.caption.StaticCaption;
import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.events.PlotFlagRemoveEvent; import com.plotsquared.core.events.PlotFlagRemoveEvent;
@ -139,10 +140,8 @@ public class DebugExec extends SubCommand {
return true; return true;
} }
case "start-expire" -> { case "start-expire" -> {
if (ExpireManager.IMP == null) { ExpireManager expireManager = PlotSquared.platform().expireManager() == null ? new ExpireManager(this.eventDispatcher) : PlotSquared.platform().expireManager();
ExpireManager.IMP = new ExpireManager(this.eventDispatcher); if (expireManager.runAutomatedTask()) {
}
if (ExpireManager.IMP.runAutomatedTask()) {
player.sendMessage(TranslatableCaption.of("debugexec.expiry_started")); player.sendMessage(TranslatableCaption.of("debugexec.expiry_started"));
} else { } else {
player.sendMessage(TranslatableCaption.of("debugexec.expiry_already_started")); player.sendMessage(TranslatableCaption.of("debugexec.expiry_already_started"));
@ -150,7 +149,7 @@ public class DebugExec extends SubCommand {
return true; return true;
} }
case "stop-expire" -> { 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")); player.sendMessage(TranslatableCaption.of("debugexec.task_halted"));
} else { } else {
player.sendMessage(TranslatableCaption.of("debugexec.task_cancelled")); player.sendMessage(TranslatableCaption.of("debugexec.task_cancelled"));

View File

@ -19,6 +19,7 @@
package com.plotsquared.core.command; package com.plotsquared.core.command;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.events.PlotDoneEvent; 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.permissions.Permission;
import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot; 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.expiration.PlotAnalysis;
import com.plotsquared.core.plot.flag.PlotFlag; import com.plotsquared.core.plot.flag.PlotFlag;
import com.plotsquared.core.plot.flag.implementations.DoneFlag; import com.plotsquared.core.plot.flag.implementations.DoneFlag;
@ -94,7 +94,7 @@ public class Done extends SubCommand {
Template.of("plot", plot.getId().toString()) Template.of("plot", plot.getId().toString())
); );
final Settings.Auto_Clear doneRequirements = Settings.AUTO_CLEAR.get("done"); 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); finish(plot, player, true);
plot.removeRunning(); plot.removeRunning();
} else { } else {

View File

@ -30,7 +30,6 @@ import com.plotsquared.core.permissions.Permission;
import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea; 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.DoneFlag;
import com.plotsquared.core.plot.flag.implementations.PriceFlag; import com.plotsquared.core.plot.flag.implementations.PriceFlag;
import com.plotsquared.core.plot.flag.implementations.ServerPlotFlag; import com.plotsquared.core.plot.flag.implementations.ServerPlotFlag;
@ -240,7 +239,7 @@ public class ListCmd extends SubCommand {
); );
return false; return false;
} }
if (ExpireManager.IMP == null) { if (PlotSquared.platform().expireManager() == null) {
plotConsumer.accept(PlotQuery.newQuery().noPlots()); plotConsumer.accept(PlotQuery.newQuery().noPlots());
} else { } else {
plotConsumer.accept(PlotQuery.newQuery().expiredPlots()); plotConsumer.accept(PlotQuery.newQuery().expiredPlots());

View File

@ -25,7 +25,6 @@ import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.location.Location; import com.plotsquared.core.location.Location;
import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.expiration.ExpireManager;
import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.queue.GlobalBlockQueue; import com.plotsquared.core.queue.GlobalBlockQueue;
import com.plotsquared.core.queue.QueueCoordinator; import com.plotsquared.core.queue.QueueCoordinator;
@ -92,8 +91,8 @@ public class Trim extends SubCommand {
} }
TranslatableCaption.of("trim.trim_starting"); TranslatableCaption.of("trim.trim_starting");
final List<Plot> plots = PlotQuery.newQuery().inWorld(world).asList(); final List<Plot> plots = PlotQuery.newQuery().inWorld(world).asList();
if (ExpireManager.IMP != null) { if (PlotSquared.platform().expireManager() != null) {
plots.removeAll(ExpireManager.IMP.getPendingExpired()); plots.removeAll(PlotSquared.platform().expireManager().getPendingExpired());
} }
result.value1 = new HashSet<>(PlotSquared.platform().worldUtil().getChunkChunks(world)); result.value1 = new HashSet<>(PlotSquared.platform().worldUtil().getChunkChunks(world));
result.value2 = new HashSet<>(); result.value2 = new HashSet<>();

View File

@ -36,7 +36,6 @@ import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotTitle; import com.plotsquared.core.plot.PlotTitle;
import com.plotsquared.core.plot.PlotWeather; import com.plotsquared.core.plot.PlotWeather;
import com.plotsquared.core.plot.comment.CommentManager; import com.plotsquared.core.plot.comment.CommentManager;
import com.plotsquared.core.plot.expiration.ExpireManager;
import com.plotsquared.core.plot.flag.GlobalFlagContainer; import com.plotsquared.core.plot.flag.GlobalFlagContainer;
import com.plotsquared.core.plot.flag.PlotFlag; import com.plotsquared.core.plot.flag.PlotFlag;
import com.plotsquared.core.plot.flag.implementations.DenyExitFlag; import com.plotsquared.core.plot.flag.implementations.DenyExitFlag;
@ -163,8 +162,8 @@ public class PlotListener {
if ((last != null) && !last.getId().equals(plot.getId())) { if ((last != null) && !last.getId().equals(plot.getId())) {
plotExit(player, last); plotExit(player, last);
} }
if (ExpireManager.IMP != null) { if (PlotSquared.platform().expireManager() != null) {
ExpireManager.IMP.handleEntry(player, plot); PlotSquared.platform().expireManager().handleEntry(player, plot);
} }
lastPlot.set(plot); lastPlot.set(plot);
} }

View File

@ -42,7 +42,6 @@ import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotCluster; import com.plotsquared.core.plot.PlotCluster;
import com.plotsquared.core.plot.PlotId; import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.plot.PlotWeather; import com.plotsquared.core.plot.PlotWeather;
import com.plotsquared.core.plot.expiration.ExpireManager;
import com.plotsquared.core.plot.flag.implementations.DoneFlag; import com.plotsquared.core.plot.flag.implementations.DoneFlag;
import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.plot.world.SinglePlotArea; import com.plotsquared.core.plot.world.SinglePlotArea;
@ -618,8 +617,8 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer,
LOGGER.info("Plot {} was deleted + cleared due to {} getting banned", owned.getId(), getName()); LOGGER.info("Plot {} was deleted + cleared due to {} getting banned", owned.getId(), getName());
} }
} }
if (ExpireManager.IMP != null) { if (PlotSquared.platform().expireManager() != null) {
ExpireManager.IMP.storeDate(getUUID(), System.currentTimeMillis()); PlotSquared.platform().expireManager().storeDate(getUUID(), System.currentTimeMillis());
} }
PlotSquared.platform().playerManager().removePlayer(this); PlotSquared.platform().playerManager().removePlayer(this);
PlotSquared.platform().unregister(this); PlotSquared.platform().unregister(this);

View File

@ -40,7 +40,6 @@ import com.plotsquared.core.location.Location;
import com.plotsquared.core.permissions.Permission; import com.plotsquared.core.permissions.Permission;
import com.plotsquared.core.player.ConsolePlayer; import com.plotsquared.core.player.ConsolePlayer;
import com.plotsquared.core.player.PlotPlayer; 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.expiration.PlotAnalysis;
import com.plotsquared.core.plot.flag.FlagContainer; import com.plotsquared.core.plot.flag.FlagContainer;
import com.plotsquared.core.plot.flag.GlobalFlagContainer; import com.plotsquared.core.plot.flag.GlobalFlagContainer;
@ -1105,8 +1104,8 @@ public class Plot {
* @return A boolean indicating whether or not the operation succeeded * @return A boolean indicating whether or not the operation succeeded
*/ */
public <V> boolean setFlag(final @NonNull PlotFlag<V, ?> flag) { public <V> boolean setFlag(final @NonNull PlotFlag<V, ?> flag) {
if (flag instanceof KeepFlag && ExpireManager.IMP != null) { if (flag instanceof KeepFlag && PlotSquared.platform().expireManager() != null) {
ExpireManager.IMP.updateExpired(this); PlotSquared.platform().expireManager().updateExpired(this);
} }
for (final Plot plot : this.getConnectedPlots()) { for (final Plot plot : this.getConnectedPlots()) {
plot.getFlagContainer().addFlag(flag); plot.getFlagContainer().addFlag(flag);
@ -2831,11 +2830,11 @@ public class Plot {
Component members = PlayerManager.getPlayerList(this.getMembers(), player); Component members = PlayerManager.getPlayerList(this.getMembers(), player);
Component denied = PlayerManager.getPlayerList(this.getDenied(), player); Component denied = PlayerManager.getPlayerList(this.getDenied(), player);
String seen; String seen;
if (Settings.Enabled_Components.PLOT_EXPIRY && ExpireManager.IMP != null) { if (Settings.Enabled_Components.PLOT_EXPIRY && PlotSquared.platform().expireManager() != null) {
if (this.isOnline()) { if (this.isOnline()) {
seen = TranslatableCaption.of("info.now").getComponent(player); seen = TranslatableCaption.of("info.now").getComponent(player);
} else { } else {
int time = (int) (ExpireManager.IMP.getAge(this, false) / 1000); int time = (int) (PlotSquared.platform().expireManager().getAge(this, false) / 1000);
if (time != 0) { if (time != 0) {
seen = TimeUtil.secToTime(time); seen = TimeUtil.secToTime(time);
} else { } else {

View File

@ -18,6 +18,7 @@
*/ */
package com.plotsquared.core.plot.expiration; package com.plotsquared.core.plot.expiration;
import com.plotsquared.core.PlotPlatform;
import com.plotsquared.core.PlotSquared; import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.caption.Caption; import com.plotsquared.core.configuration.caption.Caption;
import com.plotsquared.core.configuration.caption.Templates; import com.plotsquared.core.configuration.caption.Templates;
@ -60,6 +61,10 @@ import java.util.concurrent.ConcurrentLinkedDeque;
public class ExpireManager { public class ExpireManager {
/**
* @deprecated Use {@link PlotPlatform#expireManager()} instead
*/
@Deprecated(forRemoval = true, since = "TODO")
public static ExpireManager IMP; public static ExpireManager IMP;
private final ConcurrentHashMap<UUID, Long> dates_cache; private final ConcurrentHashMap<UUID, Long> dates_cache;
private final ConcurrentHashMap<UUID, Long> account_age_cache; private final ConcurrentHashMap<UUID, Long> account_age_cache;

View File

@ -18,6 +18,7 @@
*/ */
package com.plotsquared.core.plot.expiration; package com.plotsquared.core.plot.expiration;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotArea;
@ -72,8 +73,9 @@ public class ExpiryTask {
min = false; min = false;
diff = plots.size() - settings.REQUIRED_PLOTS; diff = plots.size() - settings.REQUIRED_PLOTS;
} }
ExpireManager expireManager = PlotSquared.platform().expireManager();
List<Long> entireList = List<Long> entireList =
plots.stream().map(plot -> ExpireManager.IMP.getAge(plot, settings.DELETE_IF_OWNER_IS_UNKNOWN)) plots.stream().map(plot -> expireManager.getAge(plot, settings.DELETE_IF_OWNER_IS_UNKNOWN))
.collect(Collectors.toList()); .collect(Collectors.toList());
List<Long> top = new ArrayList<>(diff + 1); List<Long> top = new ArrayList<>(diff + 1);
if (diff > 1000) { if (diff > 1000) {

View File

@ -20,6 +20,7 @@ package com.plotsquared.core.util;
import com.google.common.eventbus.EventBus; import com.google.common.eventbus.EventBus;
import com.intellectualsites.annotations.DoNotUse; import com.intellectualsites.annotations.DoNotUse;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.events.PlayerAutoPlotEvent; import com.plotsquared.core.events.PlayerAutoPlotEvent;
@ -59,7 +60,6 @@ import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotId; import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.plot.Rating; import com.plotsquared.core.plot.Rating;
import com.plotsquared.core.plot.expiration.ExpireManager;
import com.plotsquared.core.plot.flag.PlotFlag; import com.plotsquared.core.plot.flag.PlotFlag;
import com.plotsquared.core.plot.flag.implementations.DeviceInteractFlag; import com.plotsquared.core.plot.flag.implementations.DeviceInteractFlag;
import com.plotsquared.core.plot.flag.implementations.MiscPlaceFlag; import com.plotsquared.core.plot.flag.implementations.MiscPlaceFlag;
@ -300,8 +300,8 @@ public class EventDispatcher {
if (player == null) { if (player == null) {
return; //possible future warning message to figure out where we are retrieving null return; //possible future warning message to figure out where we are retrieving null
} }
if (ExpireManager.IMP != null) { if (PlotSquared.platform().expireManager() != null) {
ExpireManager.IMP.handleJoin(player); PlotSquared.platform().expireManager().handleJoin(player);
} }
if (this.worldEdit != null) { if (this.worldEdit != null) {
if (player.getAttribute("worldedit")) { if (player.getAttribute("worldedit")) {

View File

@ -18,8 +18,8 @@
*/ */
package com.plotsquared.core.util.query; package com.plotsquared.core.util.query;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.expiration.ExpireManager;
import java.util.Collection; import java.util.Collection;
@ -27,7 +27,7 @@ class ExpiredPlotProvider implements PlotProvider {
@Override @Override
public Collection<Plot> getPlots() { public Collection<Plot> getPlots() {
return ExpireManager.IMP.getPendingExpired(); return PlotSquared.platform().expireManager().getPendingExpired();
} }
} }