From 9c3d2cfb0212dc5d3b463c0dc15642701df7603b Mon Sep 17 00:00:00 2001 From: MeFisto94 Date: Wed, 24 Jun 2020 17:33:49 +0200 Subject: [PATCH] Move the caching and static accessors from EconHandler to PlotMain --- .../com/plotsquared/bukkit/BukkitMain.java | 11 +++++++++- .../bukkit/util/BukkitEconHandler.java | 1 + .../java/com/plotsquared/core/IPlotMain.java | 4 ++-- .../plotsquared/core/util/EconHandler.java | 21 +++++++++++-------- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java index 1a40c51d5..a0f19cb6e 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -178,6 +178,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< @Getter private BackupManager backupManager; @Getter private PlatformWorldManager worldManager; private final BukkitPlayerManager playerManager = new BukkitPlayerManager(); + private EconHandler econ; @Override public int[] getServerVersion() { if (this.version == null) { @@ -902,8 +903,16 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< } @Override public EconHandler getEconomyHandler() { + if (econ != null) { + if (econ.init() /* is inited*/) { + return econ; + } else { + return null; + } + } + try { - BukkitEconHandler econ = new BukkitEconHandler(); + econ = new BukkitEconHandler(); if (econ.init()) { return econ; } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java index b8387efed..642ed3c63 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java @@ -40,6 +40,7 @@ public class BukkitEconHandler extends EconHandler { private Economy econ; private Permission perms; + @Override public boolean init() { if (this.econ == null || this.perms == null) { setupPermissions(); diff --git a/Core/src/main/java/com/plotsquared/core/IPlotMain.java b/Core/src/main/java/com/plotsquared/core/IPlotMain.java index eb70402f6..4dc293c6d 100644 --- a/Core/src/main/java/com/plotsquared/core/IPlotMain.java +++ b/Core/src/main/java/com/plotsquared/core/IPlotMain.java @@ -174,11 +174,11 @@ public interface IPlotMain

extends ILogger { boolean initWorldEdit(); /** - * Gets the economy provider. + * Gets the economy provider, if there is one * * @return the PlotSquared economy manager */ - EconHandler getEconomyHandler(); + @Nullable EconHandler getEconomyHandler(); /** * Gets the {@link QueueProvider} class. diff --git a/Core/src/main/java/com/plotsquared/core/util/EconHandler.java b/Core/src/main/java/com/plotsquared/core/util/EconHandler.java index bedbda228..1064b0800 100644 --- a/Core/src/main/java/com/plotsquared/core/util/EconHandler.java +++ b/Core/src/main/java/com/plotsquared/core/util/EconHandler.java @@ -35,18 +35,17 @@ import org.jetbrains.annotations.Nullable; public abstract class EconHandler { /** - * @deprecated This will be made private in the future + * @deprecated This will be removed in the future, + * call {@link IPlotMain#getEconomyHandler()} instead. */ - @Deprecated public static EconHandler manager; + @Deprecated @Nullable public static EconHandler manager; /** - * Initialize the economy handler using - * {@link IPlotMain#getEconomyHandler()} + * Initialize the economy handler using {@link IPlotMain#getEconomyHandler()} + * @deprecated Call {@link #init} instead or use {@link IPlotMain#getEconomyHandler()} + * which does this already. */ - public static void initializeEconHandler() { - if (manager != null) { - return; - } + @Deprecated public static void initializeEconHandler() { manager = PlotSquared.get().IMP.getEconomyHandler(); } @@ -54,11 +53,15 @@ public abstract class EconHandler { * Return the econ handler instance, if one exists * * @return Economy handler instance + * @deprecated Call {@link IPlotMain#getEconomyHandler()} instead */ - @Nullable public static EconHandler getEconHandler() { + @Deprecated @Nullable public static EconHandler getEconHandler() { + manager = PlotSquared.get().IMP.getEconomyHandler(); return manager; } + public abstract boolean init(); + public double getMoney(PlotPlayer player) { if (player instanceof ConsolePlayer) { return Double.MAX_VALUE;