Move the caching and static accessors from EconHandler to PlotMain

This commit is contained in:
MeFisto94 2020-06-24 17:33:49 +02:00 committed by Alexander Söderberg
parent 38425a1eae
commit 9c3d2cfb02
4 changed files with 25 additions and 12 deletions

View File

@ -178,6 +178,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
@Getter private BackupManager backupManager;
@Getter private PlatformWorldManager<World> 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;
}

View File

@ -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();

View File

@ -174,11 +174,11 @@ public interface IPlotMain<P> 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.

View File

@ -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;