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