From 6f6cb4b63003dec8aeb865dd4263463da8b791a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Sat, 11 Jul 2020 05:29:41 +0200 Subject: [PATCH] More DI progress --- .../bukkit/inject/BukkitModule.java | 10 ++++-- .../plotsquared/bukkit/util/BukkitUtil.java | 2 +- .../com/plotsquared/core/PlotPlatform.java | 24 +++++++++++-- .../com/plotsquared/core/PlotSquared.java | 7 ---- .../core/generator/ClassicPlotManager.java | 21 +++++++----- .../plotsquared/core/generator/HybridGen.java | 4 +-- .../core/generator/HybridPlotManager.java | 15 ++++---- .../core/generator/HybridPlotWorld.java | 34 ++++++++++++------- .../core/generator/SquarePlotManager.java | 7 ++-- .../inject/modules/PlotSquaredModule.java | 2 -- .../core/plot/expiration/ExpireManager.java | 9 +++-- .../plot/world/DefaultPlotAreaManager.java | 3 +- .../core/plot/world/SinglePlot.java | 13 +++---- .../core/plot/world/SinglePlotArea.java | 24 +++++++------ .../plot/world/SinglePlotAreaManager.java | 18 +++++++--- .../core/plot/world/SinglePlotManager.java | 11 +++--- 16 files changed, 123 insertions(+), 81 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/inject/BukkitModule.java b/Bukkit/src/main/java/com/plotsquared/bukkit/inject/BukkitModule.java index efb28505b..e9f0ca13f 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/inject/BukkitModule.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/inject/BukkitModule.java @@ -40,10 +40,12 @@ import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.core.PlotPlatform; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.generator.HybridGen; -import com.plotsquared.core.generator.HybridUtils; import com.plotsquared.core.generator.IndependentPlotGenerator; import com.plotsquared.core.inject.annotations.ConsoleActor; import com.plotsquared.core.inject.annotations.DefaultGenerator; +import com.plotsquared.core.plot.world.DefaultPlotAreaManager; +import com.plotsquared.core.plot.world.PlotAreaManager; +import com.plotsquared.core.plot.world.SinglePlotAreaManager; import com.plotsquared.core.queue.GlobalBlockQueue; import com.plotsquared.core.queue.QueueProvider; import com.plotsquared.core.util.ChunkManager; @@ -76,7 +78,6 @@ import org.jetbrains.annotations.NotNull; @NotNull ConsoleCommandSender console = Bukkit.getServer().getConsoleSender(); WorldEditPlugin wePlugin = ((WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit")); bind(Actor.class).annotatedWith(ConsoleActor.class).toInstance(wePlugin.wrapCommandSender(console)); - bind(HybridUtils.class).to(BukkitHybridUtils.class); bind(InventoryUtil.class).to(BukkitInventoryUtil.class); bind(SetupUtils.class).to(BukkitSetupUtils.class); bind(WorldUtil.class).to(BukkitUtil.class); @@ -87,6 +88,11 @@ import org.jetbrains.annotations.NotNull; bind(SchematicHandler.class).to(BukkitSchematicHandler.class); bind(PermHandler.class).to(BukkitPermHandler.class); bind(EconHandler.class).to(BukkitEconHandler.class); + if (Settings.Enabled_Components.WORLDS) { + bind(PlotAreaManager.class).to(SinglePlotAreaManager.class); + } else { + bind(PlotAreaManager.class).to(DefaultPlotAreaManager.class); + } } } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java index a4b147ff9..d3659b481 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java @@ -137,7 +137,7 @@ import java.util.stream.Stream; final Player player = OfflinePlayerUtil.loadPlayer(op); player.loadData(); return new BukkitPlayer(PlotSquared.get().getPlotAreaManager(), - PlotSquared.get().getEventDispatcher(), player, true); + PlotSquared.get().getEventDispatcher(), player, true, PlotSquared.platform().getEconHandler()); } /** diff --git a/Core/src/main/java/com/plotsquared/core/PlotPlatform.java b/Core/src/main/java/com/plotsquared/core/PlotPlatform.java index 38de6a0db..3eb5983c4 100644 --- a/Core/src/main/java/com/plotsquared/core/PlotPlatform.java +++ b/Core/src/main/java/com/plotsquared/core/PlotPlatform.java @@ -36,8 +36,10 @@ import com.plotsquared.core.location.World; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.queue.GlobalBlockQueue; import com.plotsquared.core.util.ChatManager; +import com.plotsquared.core.util.EconHandler; import com.plotsquared.core.util.PlatformWorldManager; import com.plotsquared.core.util.PlayerManager; +import com.plotsquared.core.util.SetupUtils; import com.plotsquared.core.util.WorldUtil; import com.plotsquared.core.util.logger.ILogger; import org.jetbrains.annotations.NotNull; @@ -218,12 +220,30 @@ public interface PlotPlatform

extends ILogger { } /** - * Get the hybrid utility class + * Get the {@link HybridUtils} implementation for the platform * - * @return Hybrid utility class + * @return Hybrid utils */ @NotNull default HybridUtils getHybridUtils() { return getInjector().getInstance(HybridUtils.class); } + /** + * Get the {@link SetupUtils} implementation for the platform + * + * @return Setup utils + */ + @NotNull default SetupUtils getSetupUtils() { + return getInjector().getInstance(SetupUtils.class); + } + + /** + * Get the {@link EconHandler} implementation for the platform + * + * @return Econ handler + */ + @NotNull default EconHandler getEconHandler() { + return getInjector().getInstance(EconHandler.class); + } + } diff --git a/Core/src/main/java/com/plotsquared/core/PlotSquared.java b/Core/src/main/java/com/plotsquared/core/PlotSquared.java index dfc020d47..fc10ca113 100644 --- a/Core/src/main/java/com/plotsquared/core/PlotSquared.java +++ b/Core/src/main/java/com/plotsquared/core/PlotSquared.java @@ -207,13 +207,6 @@ public class PlotSquared { // Create plot listener this.plotListener = new PlotListener(this.eventDispatcher); - // Setup plotAreaManager - if (Settings.Enabled_Components.WORLDS) { - this.plotAreaManager = new SinglePlotAreaManager(this.eventDispatcher, this.plotListener, this.worldConfiguration); - } else { - this.plotAreaManager = new DefaultPlotAreaManager(); - } - // Database if (Settings.Enabled_Components.DATABASE) { setupDatabase(); diff --git a/Core/src/main/java/com/plotsquared/core/generator/ClassicPlotManager.java b/Core/src/main/java/com/plotsquared/core/generator/ClassicPlotManager.java index 48950c8dd..69b34580b 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/ClassicPlotManager.java +++ b/Core/src/main/java/com/plotsquared/core/generator/ClassicPlotManager.java @@ -25,6 +25,7 @@ */ package com.plotsquared.core.generator; +import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.location.Direction; import com.plotsquared.core.location.Location; @@ -32,7 +33,6 @@ import com.plotsquared.core.plot.BlockBucket; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotAreaTerrainType; import com.plotsquared.core.plot.PlotId; -import com.plotsquared.core.queue.GlobalBlockQueue; import com.plotsquared.core.queue.LocalBlockQueue; import com.plotsquared.core.util.BlockUtil; import com.plotsquared.core.util.MathMan; @@ -40,6 +40,7 @@ import com.plotsquared.core.util.RegionManager; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.world.block.BlockTypes; +import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.Optional; @@ -50,10 +51,13 @@ import java.util.Optional; public class ClassicPlotManager extends SquarePlotManager { private final ClassicPlotWorld classicPlotWorld; + private final RegionManager regionManager; - public ClassicPlotManager(ClassicPlotWorld classicPlotWorld) { - super(classicPlotWorld); + public ClassicPlotManager(@NotNull final ClassicPlotWorld classicPlotWorld, + @NotNull final RegionManager regionManager) { + super(classicPlotWorld, regionManager); this.classicPlotWorld = classicPlotWorld; + this.regionManager = regionManager; } @Override public boolean setComponent(PlotId plotId, String component, Pattern blocks) { @@ -88,13 +92,13 @@ public class ClassicPlotManager extends SquarePlotManager { .equals(classicPlotWorld.CLAIMED_WALL_BLOCK)) { setWall(plot.getId(), classicPlotWorld.WALL_BLOCK.toPattern()); } - return GlobalBlockQueue.IMP.addEmptyTask(whenDone); + return PlotSquared.platform().getGlobalBlockQueue().addEmptyTask(whenDone); } public boolean setFloor(PlotId plotId, Pattern blocks) { Plot plot = classicPlotWorld.getPlotAbs(plotId); if (plot.isBasePlot()) { - return RegionManager.manager.setCuboids(classicPlotWorld, plot.getRegions(), blocks, + return this.regionManager.setCuboids(classicPlotWorld, plot.getRegions(), blocks, classicPlotWorld.PLOT_HEIGHT, classicPlotWorld.PLOT_HEIGHT); } return false; @@ -103,8 +107,7 @@ public class ClassicPlotManager extends SquarePlotManager { public boolean setAll(PlotId plotId, Pattern blocks) { Plot plot = classicPlotWorld.getPlotAbs(plotId); if (plot.isBasePlot()) { - return RegionManager.manager - .setCuboids(classicPlotWorld, plot.getRegions(), blocks, 1, getWorldHeight()); + return this.regionManager.setCuboids(classicPlotWorld, plot.getRegions(), blocks, 1, getWorldHeight()); } return false; } @@ -112,7 +115,7 @@ public class ClassicPlotManager extends SquarePlotManager { public boolean setAir(PlotId plotId, Pattern blocks) { Plot plot = classicPlotWorld.getPlotAbs(plotId); if (plot.isBasePlot()) { - return RegionManager.manager.setCuboids(classicPlotWorld, plot.getRegions(), blocks, + return this.regionManager.setCuboids(classicPlotWorld, plot.getRegions(), blocks, classicPlotWorld.PLOT_HEIGHT + 1, getWorldHeight()); } return false; @@ -121,7 +124,7 @@ public class ClassicPlotManager extends SquarePlotManager { public boolean setMain(PlotId plotId, Pattern blocks) { Plot plot = classicPlotWorld.getPlotAbs(plotId); if (plot.isBasePlot()) { - return RegionManager.manager.setCuboids(classicPlotWorld, plot.getRegions(), blocks, 1, + return this.regionManager.setCuboids(classicPlotWorld, plot.getRegions(), blocks, 1, classicPlotWorld.PLOT_HEIGHT - 1); } return false; diff --git a/Core/src/main/java/com/plotsquared/core/generator/HybridGen.java b/Core/src/main/java/com/plotsquared/core/generator/HybridGen.java index 2d137aa37..3b1739961 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/HybridGen.java +++ b/Core/src/main/java/com/plotsquared/core/generator/HybridGen.java @@ -50,8 +50,8 @@ public class HybridGen extends IndependentPlotGenerator { private final YamlConfiguration worldConfiguration; @Inject public HybridGen(@NotNull final EventDispatcher eventDispatcher, - @NotNull final PlotListener plotListener, - @WorldConfig @NotNull final YamlConfiguration worldConfiguration) { + @NotNull final PlotListener plotListener, + @WorldConfig @NotNull final YamlConfiguration worldConfiguration) { this.eventDispatcher = eventDispatcher; this.plotListener = plotListener; this.worldConfiguration = worldConfiguration; diff --git a/Core/src/main/java/com/plotsquared/core/generator/HybridPlotManager.java b/Core/src/main/java/com/plotsquared/core/generator/HybridPlotManager.java index af992244d..c517f1cd8 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/HybridPlotManager.java +++ b/Core/src/main/java/com/plotsquared/core/generator/HybridPlotManager.java @@ -34,7 +34,6 @@ import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotAreaTerrainType; import com.plotsquared.core.plot.PlotAreaType; import com.plotsquared.core.plot.PlotId; -import com.plotsquared.core.queue.GlobalBlockQueue; import com.plotsquared.core.queue.LocalBlockQueue; import com.plotsquared.core.util.ChunkManager; import com.plotsquared.core.util.FileBytes; @@ -48,6 +47,7 @@ import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockTypes; import lombok.Getter; +import org.jetbrains.annotations.NotNull; import java.io.File; import java.io.IOException; @@ -59,10 +59,13 @@ public class HybridPlotManager extends ClassicPlotManager { public static boolean REGENERATIVE_CLEAR = true; @Getter private final HybridPlotWorld hybridPlotWorld; + private final RegionManager regionManager; - public HybridPlotManager(HybridPlotWorld hybridPlotWorld) { - super(hybridPlotWorld); + public HybridPlotManager(@NotNull final HybridPlotWorld hybridPlotWorld, + @NotNull final RegionManager regionManager) { + super(hybridPlotWorld, regionManager); this.hybridPlotWorld = hybridPlotWorld; + this.regionManager = regionManager; } @Override public void exportTemplate() throws IOException { @@ -199,9 +202,9 @@ public class HybridPlotManager extends ClassicPlotManager { *

*/ @Override public boolean clearPlot(Plot plot, final Runnable whenDone) { - if (RegionManager.manager.notifyClear(this)) { + if (this.regionManager.notifyClear(this)) { //If this returns false, the clear didn't work - if (RegionManager.manager.handleClear(plot, whenDone, this)) { + if (this.regionManager.handleClear(plot, whenDone, this)) { return true; } } @@ -256,7 +259,7 @@ public class HybridPlotManager extends ClassicPlotManager { }, () -> { queue.enqueue(); // And notify whatever called this when plot clearing is done - GlobalBlockQueue.IMP.addEmptyTask(whenDone); + PlotSquared.platform().getGlobalBlockQueue().addEmptyTask(whenDone); }, 10); return true; } diff --git a/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java b/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java index f883eb8a2..fb2fb44c0 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java +++ b/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java @@ -25,6 +25,7 @@ */ package com.plotsquared.core.generator; +import com.google.inject.assistedinject.Assisted; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.inject.annotations.WorldConfig; import com.plotsquared.core.configuration.Captions; @@ -41,6 +42,7 @@ import com.plotsquared.core.plot.schematic.Schematic; import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.MathMan; +import com.plotsquared.core.util.RegionManager; import com.plotsquared.core.util.SchematicHandler; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTagBuilder; @@ -57,6 +59,7 @@ import com.sk89q.worldedit.world.block.BaseBlock; import lombok.Getter; import org.jetbrains.annotations.NotNull; +import javax.inject.Inject; import java.io.File; import java.lang.reflect.Field; import java.util.HashMap; @@ -76,15 +79,22 @@ public class HybridPlotWorld extends ClassicPlotWorld { private Location SIGN_LOCATION; @Getter private File root = null; - public HybridPlotWorld(final String worldName, - final String id, - @NotNull final IndependentPlotGenerator generator, - final PlotId min, - final PlotId max, - @NotNull final EventDispatcher eventDispatcher, - @NotNull final PlotListener plotListener, - @WorldConfig @NotNull final YamlConfiguration worldConfiguration) { + private final RegionManager regionManager; + private final SchematicHandler schematicHandler; + + @Inject public HybridPlotWorld(@Assisted final String worldName, + @Assisted final String id, + @Assisted @NotNull final IndependentPlotGenerator generator, + @Assisted final PlotId min, + @Assisted final PlotId max, + @NotNull final EventDispatcher eventDispatcher, + @NotNull final PlotListener plotListener, + @WorldConfig @NotNull final YamlConfiguration worldConfiguration, + @NotNull final RegionManager regionManager, + @NotNull final SchematicHandler schematicHandler) { super(worldName, id, generator, min, max, eventDispatcher, plotListener, worldConfiguration); + this.regionManager = regionManager; + this.schematicHandler = schematicHandler; } public static byte wrap(byte data, int start) { @@ -135,7 +145,7 @@ public class HybridPlotWorld extends ClassicPlotWorld { } @NotNull @Override protected PlotManager createManager() { - return new HybridPlotManager(this); + return new HybridPlotManager(this, this.regionManager); } public Location getSignLocation(@NotNull Plot plot) { @@ -223,9 +233,9 @@ public class HybridPlotWorld extends ClassicPlotWorld { File schematic3File = new File(root, "plot.schem"); if (!schematic3File.exists()) schematic3File = new File(root, "plot.schematic"); - Schematic schematic1 = SchematicHandler.manager.getSchematic(schematic1File); - Schematic schematic2 = SchematicHandler.manager.getSchematic(schematic2File); - Schematic schematic3 = SchematicHandler.manager.getSchematic(schematic3File); + Schematic schematic1 = this.schematicHandler.getSchematic(schematic1File); + Schematic schematic2 = this.schematicHandler.getSchematic(schematic2File); + Schematic schematic3 = this.schematicHandler.getSchematic(schematic3File); int shift = this.ROAD_WIDTH / 2; int oddshift = (this.ROAD_WIDTH & 1) == 0 ? 0 : 1; diff --git a/Core/src/main/java/com/plotsquared/core/generator/SquarePlotManager.java b/Core/src/main/java/com/plotsquared/core/generator/SquarePlotManager.java index ad030f56c..c73d28246 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/SquarePlotManager.java +++ b/Core/src/main/java/com/plotsquared/core/generator/SquarePlotManager.java @@ -34,6 +34,7 @@ import com.plotsquared.core.plot.PlotId; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.RegionManager; import com.sk89q.worldedit.regions.CuboidRegion; +import org.jetbrains.annotations.NotNull; import java.util.Arrays; import java.util.Iterator; @@ -45,10 +46,12 @@ import java.util.Set; public abstract class SquarePlotManager extends GridPlotManager { private final SquarePlotWorld squarePlotWorld; + private final RegionManager regionManager; - public SquarePlotManager(SquarePlotWorld squarePlotWorld) { + public SquarePlotManager(@NotNull final SquarePlotWorld squarePlotWorld, @NotNull final RegionManager regionManager) { super(squarePlotWorld); this.squarePlotWorld = squarePlotWorld; + this.regionManager = regionManager; } @Override public boolean clearPlot(final Plot plot, final Runnable whenDone) { @@ -64,7 +67,7 @@ public abstract class SquarePlotManager extends GridPlotManager { iterator.remove(); final Location pos1 = Location.at(plot.getWorldName(), region.getMinimumPoint()); final Location pos2 = Location.at(plot.getWorldName(), region.getMaximumPoint()); - RegionManager.manager.regenerateRegion(pos1, pos2, false, this); + regionManager.regenerateRegion(pos1, pos2, false, this); } }; run.run(); diff --git a/Core/src/main/java/com/plotsquared/core/inject/modules/PlotSquaredModule.java b/Core/src/main/java/com/plotsquared/core/inject/modules/PlotSquaredModule.java index 236ef960c..2103602ff 100644 --- a/Core/src/main/java/com/plotsquared/core/inject/modules/PlotSquaredModule.java +++ b/Core/src/main/java/com/plotsquared/core/inject/modules/PlotSquaredModule.java @@ -34,7 +34,6 @@ import com.plotsquared.core.inject.annotations.ImpromptuPipeline; import com.plotsquared.core.inject.annotations.WorldConfig; import com.plotsquared.core.inject.annotations.WorldFile; import com.plotsquared.core.listener.PlotListener; -import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.uuid.UUIDPipeline; import com.sk89q.worldedit.WorldEdit; @@ -48,7 +47,6 @@ public class PlotSquaredModule extends AbstractModule { bind(YamlConfiguration.class).annotatedWith(WorldConfig.class).toInstance(plotSquared.getWorldConfiguration()); bind(File.class).annotatedWith(WorldFile.class).toInstance(plotSquared.getWorldsFile()); bind(File.class).annotatedWith(ConfigFile.class).toInstance(plotSquared.getConfigFile()); - bind(PlotAreaManager.class).toInstance(plotSquared.getPlotAreaManager()); bind(PlotListener.class).toInstance(plotSquared.getPlotListener()); bind(UUIDPipeline.class).annotatedWith(ImpromptuPipeline.class).toInstance(plotSquared.getImpromptuUUIDPipeline()); bind(UUIDPipeline.class).annotatedWith(BackgroundPipeline.class).toInstance(plotSquared.getBackgroundUUIDPipeline()); diff --git a/Core/src/main/java/com/plotsquared/core/plot/expiration/ExpireManager.java b/Core/src/main/java/com/plotsquared/core/plot/expiration/ExpireManager.java index 882bed76f..6eba78367 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/expiration/ExpireManager.java +++ b/Core/src/main/java/com/plotsquared/core/plot/expiration/ExpireManager.java @@ -31,7 +31,6 @@ import com.plotsquared.core.database.DBFunc; import com.plotsquared.core.events.PlotFlagAddEvent; import com.plotsquared.core.events.PlotUnlinkEvent; import com.plotsquared.core.events.Result; -import com.plotsquared.core.generator.HybridUtils; import com.plotsquared.core.player.OfflinePlotPlayer; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; @@ -325,7 +324,7 @@ public class ExpireManager { } for (ExpiryTask expiryTask : expired) { if (!expiryTask.needsAnalysis()) { - expiredTask.run(newPlot, () -> TaskManager.IMP.taskLaterAsync(task, 1), + expiredTask.run(newPlot, () -> TaskManager.getImplementation().taskLaterAsync(task, 1), expiryTask.requiresConfirmation()); return; } @@ -336,7 +335,7 @@ public class ExpireManager { passesComplexity(changed, expired, new RunnableVal() { @Override public void run(Boolean confirmation) { expiredTask.run(newPlot, - () -> TaskManager.IMP.taskLaterAsync(task, 1), + () -> TaskManager.getImplementation().taskLaterAsync(task, 1), confirmation); } }, () -> { @@ -354,7 +353,7 @@ public class ExpireManager { } }; final Runnable doAnalysis = - () -> HybridUtils.manager.analyzePlot(newPlot, handleAnalysis); + () -> PlotSquared.platform().getHybridUtils().analyzePlot(newPlot, handleAnalysis); PlotAnalysis analysis = newPlot.getComplexity(null); if (analysis != null) { @@ -362,7 +361,7 @@ public class ExpireManager { @Override public void run(Boolean value) { doAnalysis.run(); } - }, () -> TaskManager.IMP.taskLaterAsync(task, 1)); + }, () -> TaskManager.getImplementation().taskLaterAsync(task, 1)); } else { doAnalysis.run(); } diff --git a/Core/src/main/java/com/plotsquared/core/plot/world/DefaultPlotAreaManager.java b/Core/src/main/java/com/plotsquared/core/plot/world/DefaultPlotAreaManager.java index 6c3035451..ded21d507 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/world/DefaultPlotAreaManager.java +++ b/Core/src/main/java/com/plotsquared/core/plot/world/DefaultPlotAreaManager.java @@ -25,6 +25,7 @@ */ package com.plotsquared.core.plot.world; +import com.google.inject.Singleton; import com.plotsquared.core.location.Location; import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotAreaType; @@ -41,7 +42,7 @@ import java.util.List; import java.util.Map; import java.util.Set; -public class DefaultPlotAreaManager implements PlotAreaManager { +@Singleton public class DefaultPlotAreaManager implements PlotAreaManager { final PlotArea[] noPlotAreas = new PlotArea[0]; private final Map plotWorlds = new HashMap<>(); diff --git a/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlot.java b/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlot.java index 3434c1ac1..196474280 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlot.java +++ b/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlot.java @@ -25,14 +25,12 @@ */ package com.plotsquared.core.plot.world; -import com.plotsquared.core.listener.PlotListener; import com.plotsquared.core.location.BlockLoc; import com.plotsquared.core.location.Location; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotId; import com.plotsquared.core.plot.flag.PlotFlag; -import com.plotsquared.core.util.EventDispatcher; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; import org.jetbrains.annotations.NotNull; @@ -45,21 +43,20 @@ import java.util.UUID; import java.util.function.Consumer; public class SinglePlot extends Plot { + private Set regions = Collections.singleton( new CuboidRegion(BlockVector3.at(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE), BlockVector3.at(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE))); - public SinglePlot(PlotArea area, PlotId id, @NotNull final EventDispatcher eventDispatcher, @NotNull final - PlotListener plotListener) { - super(area, id, eventDispatcher, plotListener); + public SinglePlot(@NotNull final PlotArea area, @NotNull final PlotId id) { + super(area, id); } public SinglePlot(PlotId id, UUID owner, HashSet trusted, HashSet members, HashSet denied, String alias, BlockLoc position, Collection> flags, - PlotArea area, boolean[] merged, long timestamp, int temp, - @NotNull final EventDispatcher eventDispatcher, @NotNull final PlotListener plotListener) { + PlotArea area, boolean[] merged, long timestamp, int temp) { super(id, owner, trusted, members, denied, alias, position, flags, area, merged, timestamp, - temp, eventDispatcher, plotListener); + temp); } @Override public String getWorldName() { diff --git a/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotArea.java b/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotArea.java index 684da4562..796c8d824 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotArea.java +++ b/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotArea.java @@ -26,13 +26,13 @@ package com.plotsquared.core.plot.world; import com.plotsquared.core.PlotSquared; -import com.plotsquared.core.inject.annotations.WorldConfig; import com.plotsquared.core.configuration.ConfigurationNode; import com.plotsquared.core.configuration.ConfigurationSection; import com.plotsquared.core.configuration.ConfigurationUtil; import com.plotsquared.core.configuration.file.YamlConfiguration; import com.plotsquared.core.generator.GridPlotWorld; import com.plotsquared.core.generator.SingleWorldGenerator; +import com.plotsquared.core.inject.annotations.WorldConfig; import com.plotsquared.core.listener.PlotListener; import com.plotsquared.core.location.Location; import com.plotsquared.core.location.PlotLoc; @@ -42,11 +42,11 @@ import com.plotsquared.core.plot.PlotId; import com.plotsquared.core.plot.PlotManager; import com.plotsquared.core.plot.PlotSettings; import com.plotsquared.core.plot.flag.FlagContainer; +import com.plotsquared.core.queue.GlobalBlockQueue; import com.plotsquared.core.setup.PlotAreaBuilder; import com.plotsquared.core.setup.SettingsNodesWrapper; +import com.plotsquared.core.util.EconHandler; import com.plotsquared.core.util.EventDispatcher; -import com.plotsquared.core.util.SetupUtils; -import com.plotsquared.core.util.WorldUtil; import com.plotsquared.core.util.task.RunnableVal; import com.plotsquared.core.util.task.TaskManager; import org.jetbrains.annotations.NotNull; @@ -66,8 +66,11 @@ public class SinglePlotArea extends GridPlotWorld { public SinglePlotArea(@NotNull final PlotAreaManager plotAreaManager, @NotNull final EventDispatcher eventDispatcher, @NotNull final PlotListener plotListener, - @WorldConfig @NotNull final YamlConfiguration worldConfiguration) { - super("*", null, new SingleWorldGenerator(plotAreaManager), null, null, eventDispatcher, plotListener, worldConfiguration); + @WorldConfig @NotNull final YamlConfiguration worldConfiguration, + @NotNull final GlobalBlockQueue globalBlockQueue, + @NotNull final EconHandler econHandler) { + super("*", null, new SingleWorldGenerator(plotAreaManager), null, null, + eventDispatcher, plotListener, worldConfiguration, globalBlockQueue, econHandler); this.eventDispatcher = eventDispatcher; this.plotListener = plotListener; this.setAllowSigns(false); @@ -88,10 +91,10 @@ public class SinglePlotArea extends GridPlotWorld { public void loadWorld(final PlotId id) { String worldName = id.getX() + "." + id.getY(); - if (WorldUtil.IMP.isWorld(worldName)) { + if (PlotSquared.platform().getWorldUtil().isWorld(worldName)) { return; } - PlotAreaBuilder builder = new PlotAreaBuilder() + PlotAreaBuilder builder = PlotAreaBuilder.newBuilder() .plotManager("PlotSquared:single") .generatorName("PlotSquared:single") .plotAreaType(getType()) @@ -138,14 +141,13 @@ public class SinglePlotArea extends GridPlotWorld { } } - TaskManager.IMP.sync(new RunnableVal() { + TaskManager.getImplementation().sync(new RunnableVal() { @Override public void run(Object value) { String worldName = id.getX() + "." + id.getY(); - if (WorldUtil.IMP.isWorld(worldName)) { + if (PlotSquared.platform().getWorldUtil().isWorld(worldName)) { return; } - - SetupUtils.manager.setupWorld(builder); + PlotSquared.platform().getSetupUtils().setupWorld(builder); } }); // String worldName = plot.getWorldName(); diff --git a/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotAreaManager.java b/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotAreaManager.java index 680b8e9d0..36e53cb73 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotAreaManager.java +++ b/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotAreaManager.java @@ -25,6 +25,7 @@ */ package com.plotsquared.core.plot.world; +import com.google.inject.Singleton; import com.plotsquared.core.inject.annotations.WorldConfig; import com.plotsquared.core.collection.ArrayUtil; import com.plotsquared.core.configuration.file.YamlConfiguration; @@ -32,22 +33,29 @@ import com.plotsquared.core.generator.SingleWorldGenerator; import com.plotsquared.core.listener.PlotListener; import com.plotsquared.core.location.Location; import com.plotsquared.core.plot.PlotArea; +import com.plotsquared.core.queue.GlobalBlockQueue; +import com.plotsquared.core.util.EconHandler; import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.SetupUtils; import com.sk89q.worldedit.regions.CuboidRegion; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public class SinglePlotAreaManager extends DefaultPlotAreaManager { +import javax.inject.Inject; + +@Singleton public class SinglePlotAreaManager extends DefaultPlotAreaManager { private final SinglePlotArea[] array; private SinglePlotArea area; private PlotArea[] all; - public SinglePlotAreaManager(@NotNull final EventDispatcher eventDispatcher, - @NotNull final PlotListener plotListener, - @WorldConfig @NotNull final YamlConfiguration worldConfiguration) { - this.area = new SinglePlotArea(this, eventDispatcher, plotListener, worldConfiguration); + @Inject public SinglePlotAreaManager(@NotNull final EventDispatcher eventDispatcher, + @NotNull final PlotListener plotListener, + @WorldConfig @NotNull final YamlConfiguration worldConfiguration, + @NotNull final GlobalBlockQueue blockQueue, + @NotNull final EconHandler econHandler) { + this.area = new SinglePlotArea(this, eventDispatcher, plotListener, + worldConfiguration, blockQueue, econHandler); this.array = new SinglePlotArea[] {area}; this.all = new PlotArea[] {area}; SetupUtils.generators.put("PlotSquared:single", diff --git a/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotManager.java b/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotManager.java index ecfb756af..dbb54a854 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotManager.java +++ b/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotManager.java @@ -32,7 +32,6 @@ import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotId; import com.plotsquared.core.plot.PlotManager; import com.plotsquared.core.util.MainUtil; -import com.plotsquared.core.util.SetupUtils; import com.plotsquared.core.util.task.TaskManager; import com.sk89q.worldedit.function.pattern.Pattern; import org.jetbrains.annotations.NotNull; @@ -41,7 +40,8 @@ import java.io.File; import java.util.List; public class SinglePlotManager extends PlotManager { - public SinglePlotManager(PlotArea plotArea) { + + public SinglePlotManager(@NotNull final PlotArea plotArea) { super(plotArea); } @@ -62,10 +62,9 @@ public class SinglePlotManager extends PlotManager { } @Override public boolean clearPlot(Plot plot, final Runnable whenDone) { - SetupUtils.manager.unload(plot.getWorldName(), false); - final File worldFolder = - new File(PlotSquared.platform().getWorldContainer(), plot.getWorldName()); - TaskManager.IMP.taskAsync(() -> { + PlotSquared.platform().getSetupUtils().unload(plot.getWorldName(), false); + final File worldFolder = new File(PlotSquared.platform().getWorldContainer(), plot.getWorldName()); + TaskManager.getImplementation().taskAsync(() -> { MainUtil.deleteDirectory(worldFolder); if (whenDone != null) { whenDone.run();