From 916675fb08a509d1f371d729c3737a0de7cda2e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Sat, 11 Jul 2020 17:19:19 +0200 Subject: [PATCH] Guice progress --- .../bukkit/inject/BukkitModule.java | 3 + .../com/plotsquared/core/PlotSquared.java | 11 +- .../com/plotsquared/core/command/Area.java | 75 +++++---- .../com/plotsquared/core/command/Buy.java | 13 +- .../com/plotsquared/core/command/Claim.java | 15 +- .../com/plotsquared/core/command/Clear.java | 10 +- .../core/command/CreateRoadSchematic.java | 10 +- .../core/command/DebugRoadRegen.java | 11 +- .../com/plotsquared/core/command/Delete.java | 13 +- .../com/plotsquared/core/command/Deny.java | 11 +- .../com/plotsquared/core/command/Kick.java | 10 +- .../com/plotsquared/core/command/ListCmd.java | 13 +- .../com/plotsquared/core/command/Load.java | 13 +- .../plotsquared/core/command/MainCommand.java | 159 +++++++++--------- .../com/plotsquared/core/command/Merge.java | 27 +-- .../com/plotsquared/core/command/Music.java | 11 +- .../core/command/RegenAllRoads.java | 8 +- .../core/command/SchematicCmd.java | 20 ++- .../plotsquared/core/command/Template.java | 26 ++- .../core/generator/ClassicPlotWorld.java | 14 +- .../core/generator/GridPlotWorld.java | 9 +- .../plotsquared/core/generator/HybridGen.java | 20 +-- .../core/generator/HybridPlotWorld.java | 15 +- .../core/generator/SquarePlotWorld.java | 20 ++- .../core/inject/annotations/ConsoleActor.java | 25 +++ .../inject/annotations/DefaultGenerator.java | 25 +++ .../factory/HybridPlotWorldFactory.java | 39 +++++ .../factory/PlayerBackupProfileFactory.java | 27 ++- .../com/plotsquared/core/plot/PlotArea.java | 11 +- 29 files changed, 427 insertions(+), 237 deletions(-) create mode 100644 Core/src/main/java/com/plotsquared/core/inject/factory/HybridPlotWorldFactory.java 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 e9f0ca13f..01f450316 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/inject/BukkitModule.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/inject/BukkitModule.java @@ -26,6 +26,7 @@ package com.plotsquared.bukkit.inject; import com.google.inject.AbstractModule; +import com.google.inject.assistedinject.FactoryModuleBuilder; import com.plotsquared.bukkit.BukkitPlatform; import com.plotsquared.bukkit.player.BukkitPlayerManager; import com.plotsquared.bukkit.queue.BukkitLocalQueue; @@ -43,6 +44,7 @@ import com.plotsquared.core.generator.HybridGen; import com.plotsquared.core.generator.IndependentPlotGenerator; import com.plotsquared.core.inject.annotations.ConsoleActor; import com.plotsquared.core.inject.annotations.DefaultGenerator; +import com.plotsquared.core.inject.factory.HybridPlotWorldFactory; import com.plotsquared.core.plot.world.DefaultPlotAreaManager; import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.plot.world.SinglePlotAreaManager; @@ -93,6 +95,7 @@ import org.jetbrains.annotations.NotNull; } else { bind(PlotAreaManager.class).to(DefaultPlotAreaManager.class); } + install(new FactoryModuleBuilder().build(HybridPlotWorldFactory.class)); } } diff --git a/Core/src/main/java/com/plotsquared/core/PlotSquared.java b/Core/src/main/java/com/plotsquared/core/PlotSquared.java index fc10ca113..2c9bbdeec 100644 --- a/Core/src/main/java/com/plotsquared/core/PlotSquared.java +++ b/Core/src/main/java/com/plotsquared/core/PlotSquared.java @@ -44,6 +44,7 @@ import com.plotsquared.core.generator.GeneratorWrapper; import com.plotsquared.core.generator.HybridPlotWorld; import com.plotsquared.core.generator.HybridUtils; import com.plotsquared.core.generator.IndependentPlotGenerator; +import com.plotsquared.core.inject.factory.HybridPlotWorldFactory; import com.plotsquared.core.listener.PlotListener; import com.plotsquared.core.location.Location; import com.plotsquared.core.player.ConsolePlayer; @@ -58,7 +59,6 @@ import com.plotsquared.core.plot.PlotManager; import com.plotsquared.core.plot.comment.CommentManager; import com.plotsquared.core.plot.expiration.ExpireManager; import com.plotsquared.core.plot.expiration.ExpiryTask; -import com.plotsquared.core.plot.world.DefaultPlotAreaManager; import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.plot.world.SinglePlotArea; import com.plotsquared.core.plot.world.SinglePlotAreaManager; @@ -1097,8 +1097,9 @@ public class PlotSquared { split = combinedArgs; } - HybridPlotWorld plotworld = new HybridPlotWorld(world, null, generator, - null, null, this.eventDispatcher, this.plotListener, this.worldConfiguration); + final HybridPlotWorldFactory hybridPlotWorldFactory = this.platform.getInjector().getInstance(HybridPlotWorldFactory.class); + final HybridPlotWorld plotWorld = hybridPlotWorldFactory.create(world, null, generator, null, null); + for (String element : split) { String[] pair = element.split("="); if (pair.length != 2) { @@ -1162,8 +1163,8 @@ public class PlotSquared { try { ConfigurationSection section = this.worldConfiguration.getConfigurationSection("worlds." + world); - plotworld.saveConfiguration(section); - plotworld.loadDefaultConfiguration(section); + plotWorld.saveConfiguration(section); + plotWorld.loadDefaultConfiguration(section); this.worldConfiguration.save(this.worldsFile); } catch (IOException e) { e.printStackTrace(); diff --git a/Core/src/main/java/com/plotsquared/core/command/Area.java b/Core/src/main/java/com/plotsquared/core/command/Area.java index 9fa17910f..784022f07 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Area.java +++ b/Core/src/main/java/com/plotsquared/core/command/Area.java @@ -25,6 +25,7 @@ */ package com.plotsquared.core.command; +import com.google.inject.Inject; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.inject.annotations.WorldConfig; import com.plotsquared.core.inject.annotations.WorldFile; @@ -35,7 +36,7 @@ import com.plotsquared.core.configuration.file.YamlConfiguration; import com.plotsquared.core.events.TeleportCause; import com.plotsquared.core.generator.AugmentedUtils; import com.plotsquared.core.generator.HybridPlotWorld; -import com.plotsquared.core.listener.PlotListener; +import com.plotsquared.core.inject.factory.HybridPlotWorldFactory; import com.plotsquared.core.location.Location; import com.plotsquared.core.player.ConsolePlayer; import com.plotsquared.core.player.PlotPlayer; @@ -46,7 +47,6 @@ import com.plotsquared.core.plot.PlotId; import com.plotsquared.core.plot.message.PlotMessage; import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.setup.PlotAreaBuilder; -import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.MathMan; import com.plotsquared.core.util.Permissions; @@ -93,21 +93,27 @@ import java.util.Set; public class Area extends SubCommand { private final PlotAreaManager plotAreaManager; - private final EventDispatcher eventDispatcher; - private final PlotListener plotListener; private final YamlConfiguration worldConfiguration; private final File worldFile; + private final HybridPlotWorldFactory hybridPlotWorldFactory; + private final SetupUtils setupUtils; + private final WorldUtil worldUtil; + private final RegionManager regionManager; - public Area(@NotNull final PlotAreaManager plotAreaManager, - @NotNull final EventDispatcher eventDispatcher, - @NotNull final PlotListener plotListener, - @WorldConfig @NotNull final YamlConfiguration worldConfiguration, - @WorldFile @NotNull final File worldFile) { + @Inject public Area(@NotNull final PlotAreaManager plotAreaManager, + @WorldConfig @NotNull final YamlConfiguration worldConfiguration, + @WorldFile @NotNull final File worldFile, + @NotNull final HybridPlotWorldFactory hybridPlotWorldFactory, + @NotNull final SetupUtils setupUtils, + @NotNull final WorldUtil worldUtil, + @NotNull final RegionManager regionManager) { this.plotAreaManager = plotAreaManager; - this.eventDispatcher = eventDispatcher; - this.plotListener = plotListener; this.worldConfiguration = worldConfiguration; this.worldFile = worldFile; + this.hybridPlotWorldFactory = hybridPlotWorldFactory; + this.setupUtils = setupUtils; + this.worldUtil = worldUtil; + this.regionManager = regionManager; } @Override public boolean onCommand(final PlotPlayer player, String[] args) { @@ -164,9 +170,8 @@ public class Area extends SubCommand { BlockVector3.at(playerSelectionMax.getX(), 255, playerSelectionMax.getZ())); // There's only one plot in the area... final PlotId plotId = new PlotId(1, 1); - final HybridPlotWorld hybridPlotWorld = new HybridPlotWorld(player.getLocation().getWorldName(), args[1], - Objects.requireNonNull(PlotSquared.platform()).getDefaultGenerator(), plotId, plotId, - this.eventDispatcher, this.plotListener, this.worldConfiguration); + final HybridPlotWorld hybridPlotWorld = this.hybridPlotWorldFactory.create(player.getLocation().getWorldName(), args[1], + Objects.requireNonNull(PlotSquared.platform()).getDefaultGenerator(), plotId, plotId); // Plot size is the same as the region width hybridPlotWorld.PLOT_WIDTH = hybridPlotWorld.SIZE = (short) selectedRegion.getWidth(); // We use a schematic generator @@ -231,8 +236,8 @@ public class Area extends SubCommand { if (offsetZ != 0) { this.worldConfiguration.set(path + ".road.offset.z", offsetZ); } - final String world = SetupUtils.manager.setupWorld(singleBuilder); - if (WorldUtil.IMP.isWorld(world)) { + final String world = this.setupUtils.setupWorld(singleBuilder); + if (this.worldUtil.isWorld(world)) { PlotSquared.get().loadWorld(world, null); MainUtil.sendMessage(player, Captions.SINGLE_AREA_CREATED); } else { @@ -322,14 +327,14 @@ public class Area extends SubCommand { if (offsetZ != 0) { this.worldConfiguration.set(path + ".road.offset.z", offsetZ); } - final String world = SetupUtils.manager.setupWorld(builder); - if (WorldUtil.IMP.isWorld(world)) { + final String world = this.setupUtils.setupWorld(builder); + if (this.worldUtil.isWorld(world)) { PlotSquared.get().loadWorld(world, null); Captions.SETUP_FINISHED.send(player); - player.teleport(WorldUtil.IMP.getSpawn(world), + player.teleport(this.worldUtil.getSpawn(world), TeleportCause.COMMAND); if (area.getTerrain() != PlotAreaTerrainType.ALL) { - RegionManager.largeRegionTask(world, region, + this.regionManager.largeRegionTask(world, region, new RunnableVal() { @Override public void run(BlockVector2 value) { AugmentedUtils @@ -360,11 +365,10 @@ public class Area extends SubCommand { } else { id = null; } - PlotAreaBuilder builder = new PlotAreaBuilder(); + PlotAreaBuilder builder = PlotAreaBuilder.newBuilder(); builder.worldName(split[0]); - final HybridPlotWorld pa = new HybridPlotWorld(builder.worldName(), id, - PlotSquared.platform().getDefaultGenerator(), null, null, this.eventDispatcher, - this.plotListener, this.worldConfiguration); + final HybridPlotWorld pa = this.hybridPlotWorldFactory.create(builder.worldName(), + id, PlotSquared.platform().getDefaultGenerator(), null, null); PlotArea other = this.plotAreaManager.getPlotArea(pa.getWorldName(), id); if (other != null && Objects.equals(pa.getId(), other.getId())) { Captions.SETUP_WORLD_TAKEN.send(player, pa.toString()); @@ -440,7 +444,7 @@ public class Area extends SubCommand { } } if (pa.getType() != PlotAreaType.PARTIAL) { - if (WorldUtil.IMP.isWorld(pa.getWorldName())) { + if (this.worldUtil.isWorld(pa.getWorldName())) { Captions.SETUP_WORLD_TAKEN.send(player, pa.getWorldName()); return false; } @@ -454,10 +458,10 @@ public class Area extends SubCommand { pa.loadConfiguration(section); builder.plotManager(PlotSquared.platform().getPluginName()); builder.generatorName(PlotSquared.platform().getPluginName()); - String world = SetupUtils.manager.setupWorld(builder); - if (WorldUtil.IMP.isWorld(world)) { + String world = this.setupUtils.setupWorld(builder); + if (this.worldUtil.isWorld(world)) { Captions.SETUP_FINISHED.send(player); - player.teleport(WorldUtil.IMP.getSpawn(world), + player.teleport(this.worldUtil.getSpawn(world), TeleportCause.COMMAND); } else { MainUtil.sendMessage(player, @@ -483,16 +487,16 @@ public class Area extends SubCommand { + " create [world[:id]] [=]..."); return false; } - if (WorldUtil.IMP.isWorld(pa.getWorldName())) { + if (this.worldUtil.isWorld(pa.getWorldName())) { if (!player.getLocation().getWorldName().equals(pa.getWorldName())) { - player.teleport(WorldUtil.IMP.getSpawn(pa.getWorldName()), + player.teleport(this.worldUtil.getSpawn(pa.getWorldName()), TeleportCause.COMMAND); } } else { builder.terrainType(PlotAreaTerrainType.NONE); builder.plotAreaType(PlotAreaType.NORMAL); - SetupUtils.manager.setupWorld(builder); - player.teleport(WorldUtil.IMP.getSpawn(pa.getWorldName()), + this.setupUtils.setupWorld(builder); + player.teleport(this.worldUtil.getSpawn(pa.getWorldName()), TeleportCause.COMMAND); } player.setMeta("area_create_area", pa); @@ -636,7 +640,7 @@ public class Area extends SubCommand { "$4Stop the server and delete: " + area.getWorldName() + "/region"); return false; } - RegionManager.largeRegionTask(area.getWorldName(), area.getRegion(), + this.regionManager.largeRegionTask(area.getWorldName(), area.getRegion(), new RunnableVal() { @Override public void run(BlockVector2 value) { AugmentedUtils @@ -666,7 +670,7 @@ public class Area extends SubCommand { } Location center; if (area.getType() != PlotAreaType.PARTIAL) { - center = WorldUtil.IMP.getSpawn(area.getWorldName()); + center = this.worldUtil.getSpawn(area.getWorldName()); player.teleport(center, TeleportCause.COMMAND); } else { CuboidRegion region = area.getRegion(); @@ -674,8 +678,7 @@ public class Area extends SubCommand { + (region.getMaximumPoint().getX() - region.getMinimumPoint().getX()) / 2, 0, region.getMinimumPoint().getZ() + (region.getMaximumPoint().getZ() - region.getMinimumPoint().getZ()) / 2); - WorldUtil.IMP - .getHighestBlock(area.getWorldName(), center.getX(), center.getZ(), y -> + this.worldUtil.getHighestBlock(area.getWorldName(), center.getX(), center.getZ(), y -> player.teleport(center.withY(1 + y), TeleportCause.COMMAND)); } return true; diff --git a/Core/src/main/java/com/plotsquared/core/command/Buy.java b/Core/src/main/java/com/plotsquared/core/command/Buy.java index b8535a312..934a6e684 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Buy.java +++ b/Core/src/main/java/com/plotsquared/core/command/Buy.java @@ -25,6 +25,7 @@ */ package com.plotsquared.core.command; +import com.google.inject.Inject; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.events.PlotFlagRemoveEvent; @@ -39,6 +40,7 @@ import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.task.RunnableVal2; import com.plotsquared.core.util.task.RunnableVal3; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Set; import java.util.concurrent.CompletableFuture; @@ -52,10 +54,13 @@ import java.util.concurrent.CompletableFuture; public class Buy extends Command { private final EventDispatcher eventDispatcher; - - public Buy(@NotNull final EventDispatcher eventDispatcher) { + private final EconHandler econHandler; + + @Inject public Buy(@NotNull final EventDispatcher eventDispatcher, + @Nullable final EconHandler econHandler) { super(MainCommand.getInstance(), true); this.eventDispatcher = eventDispatcher; + this.econHandler = econHandler; } @Override @@ -63,7 +68,7 @@ public class Buy extends Command { RunnableVal3 confirm, final RunnableVal2 whenDone) { - check(EconHandler.getEconHandler(), Captions.ECON_DISABLED); + check(this.econHandler, Captions.ECON_DISABLED); final Plot plot; if (args.length != 0) { checkTrue(args.length == 1, Captions.COMMAND_SYNTAX, getUsage()); @@ -87,7 +92,7 @@ public class Buy extends Command { confirm.run(this, () -> { Captions.REMOVED_BALANCE.send(player, price); - EconHandler.getEconHandler().depositMoney(PlotSquared.platform().getPlayerManager().getOfflinePlayer(plot.getOwnerAbs()), price); + this.econHandler.depositMoney(PlotSquared.platform().getPlayerManager().getOfflinePlayer(plot.getOwnerAbs()), price); PlotPlayer owner = PlotSquared.platform().getPlayerManager().getPlayerIfExists(plot.getOwnerAbs()); if (owner != null) { diff --git a/Core/src/main/java/com/plotsquared/core/command/Claim.java b/Core/src/main/java/com/plotsquared/core/command/Claim.java index 4677362fd..e79f085c3 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Claim.java +++ b/Core/src/main/java/com/plotsquared/core/command/Claim.java @@ -26,6 +26,7 @@ package com.plotsquared.core.command; import com.google.common.primitives.Ints; +import com.google.inject.Inject; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.CaptionUtility; import com.plotsquared.core.configuration.Captions; @@ -46,6 +47,7 @@ import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.task.RunnableVal; import com.plotsquared.core.util.task.TaskManager; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; @CommandDeclaration(command = "claim", aliases = "c", @@ -57,9 +59,12 @@ import org.jetbrains.annotations.NotNull; public class Claim extends SubCommand { private final EventDispatcher eventDispatcher; + private final EconHandler econHandler; - public Claim(@NotNull final EventDispatcher eventDispatcher) { + @Inject public Claim(@NotNull final EventDispatcher eventDispatcher, + @Nullable final EconHandler econHandler) { this.eventDispatcher = eventDispatcher; + this.econHandler = econHandler; } @Override public boolean onCommand(final PlotPlayer player, String[] args) { @@ -112,14 +117,14 @@ public class Claim extends SubCommand { } } } - if ((EconHandler.getEconHandler() != null) && area.useEconomy() && !force) { + if ((this.econHandler != null) && area.useEconomy() && !force) { Expression costExr = area.getPrices().get("claim"); double cost = costExr.evaluate((double) currentPlots); if (cost > 0d) { - if (EconHandler.getEconHandler().getMoney(player) < cost) { + if (this.econHandler.getMoney(player) < cost) { return sendMessage(player, Captions.CANNOT_AFFORD_PLOT, "" + cost); } - EconHandler.getEconHandler().withdrawMoney(player, cost); + this.econHandler.withdrawMoney(player, cost); sendMessage(player, Captions.REMOVED_BALANCE, cost + ""); } } @@ -137,7 +142,7 @@ public class Claim extends SubCommand { } plot.setOwnerAbs(player.getUUID()); final String finalSchematic = schematic; - DBFunc.createPlotSafe(plot, () -> TaskManager.IMP.sync(new RunnableVal() { + DBFunc.createPlotSafe(plot, () -> TaskManager.getImplementation().sync(new RunnableVal() { @Override public void run(Object value) { if (!plot.claim(player, true, finalSchematic, false)) { PlotSquared.get().getLogger().log(Captions.PREFIX.getTranslated() + String diff --git a/Core/src/main/java/com/plotsquared/core/command/Clear.java b/Core/src/main/java/com/plotsquared/core/command/Clear.java index 821483629..a68254904 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Clear.java +++ b/Core/src/main/java/com/plotsquared/core/command/Clear.java @@ -25,6 +25,7 @@ */ package com.plotsquared.core.command; +import com.google.inject.Inject; import com.plotsquared.core.backup.BackupManager; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Settings; @@ -58,10 +59,13 @@ import static com.plotsquared.core.command.SubCommand.sendMessage; public class Clear extends Command { private final EventDispatcher eventDispatcher; - - public Clear(@NotNull final EventDispatcher eventDispatcher) { + private final GlobalBlockQueue blockQueue; + + @Inject public Clear(@NotNull final EventDispatcher eventDispatcher, + @NotNull final GlobalBlockQueue blockQueue) { super(MainCommand.getInstance(), true); this.eventDispatcher = eventDispatcher; + this.blockQueue = blockQueue; } @Override @@ -87,7 +91,7 @@ public class Clear extends Command { final long start = System.currentTimeMillis(); boolean result = plot.clear(true, false, () -> { plot.unlink(); - GlobalBlockQueue.IMP.addEmptyTask(() -> { + this.blockQueue.addEmptyTask(() -> { plot.removeRunning(); // If the state changes, then mark it as no longer done if (DoneFlag.isDone(plot)) { diff --git a/Core/src/main/java/com/plotsquared/core/command/CreateRoadSchematic.java b/Core/src/main/java/com/plotsquared/core/command/CreateRoadSchematic.java index d5800896a..acee18881 100644 --- a/Core/src/main/java/com/plotsquared/core/command/CreateRoadSchematic.java +++ b/Core/src/main/java/com/plotsquared/core/command/CreateRoadSchematic.java @@ -25,6 +25,7 @@ */ package com.plotsquared.core.command; +import com.google.inject.Inject; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.generator.HybridPlotWorld; import com.plotsquared.core.generator.HybridUtils; @@ -32,6 +33,7 @@ import com.plotsquared.core.location.Location; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.util.MainUtil; +import org.jetbrains.annotations.NotNull; @CommandDeclaration(command = "createroadschematic", aliases = {"crs"}, @@ -42,6 +44,12 @@ import com.plotsquared.core.util.MainUtil; usage = "/plot createroadschematic") public class CreateRoadSchematic extends SubCommand { + private final HybridUtils hybridUtils; + + @Inject public CreateRoadSchematic(@NotNull final HybridUtils hybridUtils) { + this.hybridUtils = hybridUtils; + } + @Override public boolean onCommand(PlotPlayer player, String[] args) { Location location = player.getLocation(); Plot plot = location.getPlotAbs(); @@ -51,7 +59,7 @@ public class CreateRoadSchematic extends SubCommand { if (!(location.getPlotArea() instanceof HybridPlotWorld)) { return sendMessage(player, Captions.NOT_IN_PLOT_WORLD); } - HybridUtils.manager.setupRoadSchematic(plot); + this.hybridUtils.setupRoadSchematic(plot); MainUtil.sendMessage(player, Captions.SCHEMATIC_ROAD_CREATED); return true; } diff --git a/Core/src/main/java/com/plotsquared/core/command/DebugRoadRegen.java b/Core/src/main/java/com/plotsquared/core/command/DebugRoadRegen.java index b20924586..baa494029 100644 --- a/Core/src/main/java/com/plotsquared/core/command/DebugRoadRegen.java +++ b/Core/src/main/java/com/plotsquared/core/command/DebugRoadRegen.java @@ -25,6 +25,7 @@ */ package com.plotsquared.core.command; +import com.google.inject.Inject; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.generator.HybridPlotManager; import com.plotsquared.core.generator.HybridUtils; @@ -34,6 +35,7 @@ import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotManager; import com.plotsquared.core.util.MainUtil; +import org.jetbrains.annotations.NotNull; import java.util.Arrays; @@ -44,8 +46,15 @@ import java.util.Arrays; category = CommandCategory.DEBUG, permission = "plots.debugroadregen") public class DebugRoadRegen extends SubCommand { + public static final String USAGE = "/plot debugroadregen "; + private final HybridUtils hybridUtils; + + @Inject public DebugRoadRegen(@NotNull final HybridUtils hybridUtils) { + this.hybridUtils = hybridUtils; + } + @Override public boolean onCommand(PlotPlayer player, String[] args) { if (args.length < 1) { MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX, DebugRoadRegen.USAGE); @@ -117,7 +126,7 @@ public class DebugRoadRegen extends SubCommand { MainUtil.sendMessage(player, "&7 - To set a schematic, stand in a plot and use &c/plot createroadschematic"); MainUtil.sendMessage(player, "&cTo regenerate all roads: /plot regenallroads"); - boolean result = HybridUtils.manager.scheduleSingleRegionRoadUpdate(plot, height); + boolean result = this.hybridUtils.scheduleSingleRegionRoadUpdate(plot, height); if (!result) { MainUtil.sendMessage(player, "&cCannot schedule mass schematic update! (Is one already in progress?)"); diff --git a/Core/src/main/java/com/plotsquared/core/command/Delete.java b/Core/src/main/java/com/plotsquared/core/command/Delete.java index 3404172c4..ccb6dedf5 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Delete.java +++ b/Core/src/main/java/com/plotsquared/core/command/Delete.java @@ -25,6 +25,7 @@ */ package com.plotsquared.core.command; +import com.google.inject.Inject; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.events.Result; @@ -39,6 +40,7 @@ import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.task.TaskManager; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; @CommandDeclaration(command = "delete", @@ -52,9 +54,12 @@ import org.jetbrains.annotations.NotNull; public class Delete extends SubCommand { private final EventDispatcher eventDispatcher; - - public Delete(@NotNull final EventDispatcher eventDispatcher) { + private final EconHandler econHandler; + + @Inject public Delete(@NotNull final EventDispatcher eventDispatcher, + @Nullable final EconHandler econHandler) { this.eventDispatcher = eventDispatcher; + this.econHandler = econHandler; } @Override public boolean onCommand(final PlotPlayer player, String[] args) { @@ -89,11 +94,11 @@ public class Delete extends SubCommand { final long start = System.currentTimeMillis(); boolean result = plot.deletePlot(() -> { plot.removeRunning(); - if ((EconHandler.getEconHandler() != null) && plotArea.useEconomy()) { + if ((this.econHandler != null) && plotArea.useEconomy()) { Expression valueExr = plotArea.getPrices().get("sell"); double value = plots.size() * valueExr.evaluate((double) currentPlots); if (value > 0d) { - EconHandler.getEconHandler().depositMoney(player, value); + this.econHandler.depositMoney(player, value); sendMessage(player, Captions.ADDED_BALANCE, String.valueOf(value)); } } diff --git a/Core/src/main/java/com/plotsquared/core/command/Deny.java b/Core/src/main/java/com/plotsquared/core/command/Deny.java index db91083e1..ed91fcfe9 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Deny.java +++ b/Core/src/main/java/com/plotsquared/core/command/Deny.java @@ -25,6 +25,7 @@ */ package com.plotsquared.core.command; +import com.google.inject.Inject; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.database.DBFunc; @@ -55,11 +56,15 @@ public class Deny extends SubCommand { private final PlotAreaManager plotAreaManager; private final EventDispatcher eventDispatcher; + private final WorldUtil worldUtil; - public Deny(@NotNull final PlotAreaManager plotAreaManager, @NotNull final EventDispatcher eventDispatcher) { + @Inject public Deny(@NotNull final PlotAreaManager plotAreaManager, + @NotNull final EventDispatcher eventDispatcher, + @NotNull final WorldUtil worldUtil) { super(Argument.PlayerName); this.plotAreaManager = plotAreaManager; this.eventDispatcher = eventDispatcher; + this.worldUtil = worldUtil; } @Override public boolean onCommand(PlotPlayer player, String[] args) { @@ -141,10 +146,10 @@ public class Deny extends SubCommand { player.stopSpectating(); } Location location = player.getLocation(); - Location spawn = WorldUtil.IMP.getSpawn(location.getWorldName()); + Location spawn = this.worldUtil.getSpawn(location.getWorldName()); MainUtil.sendMessage(player, Captions.YOU_GOT_DENIED); if (plot.equals(spawn.getPlot())) { - Location newSpawn = WorldUtil.IMP.getSpawn(this.plotAreaManager.getAllWorlds()[0]); + Location newSpawn = this.worldUtil.getSpawn(this.plotAreaManager.getAllWorlds()[0]); if (plot.equals(newSpawn.getPlot())) { // Kick from server if you can't be teleported to spawn player.kick(Captions.YOU_GOT_DENIED.getTranslated()); diff --git a/Core/src/main/java/com/plotsquared/core/command/Kick.java b/Core/src/main/java/com/plotsquared/core/command/Kick.java index 076eb93dd..8c2ede600 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Kick.java +++ b/Core/src/main/java/com/plotsquared/core/command/Kick.java @@ -25,6 +25,7 @@ */ package com.plotsquared.core.command; +import com.google.inject.Inject; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.database.DBFunc; @@ -55,10 +56,13 @@ import java.util.concurrent.TimeoutException; public class Kick extends SubCommand { private final PlotAreaManager plotAreaManager; + private final WorldUtil worldUtil; - public Kick(@NotNull final PlotAreaManager plotAreaManager) { + @Inject public Kick(@NotNull final PlotAreaManager plotAreaManager, + @NotNull final WorldUtil worldUtil) { super(Argument.PlayerName); this.plotAreaManager = plotAreaManager; + this.worldUtil = worldUtil; } @Override public boolean onCommand(PlotPlayer player, String[] args) { @@ -110,10 +114,10 @@ public class Kick extends SubCommand { Captions.CANNOT_KICK_PLAYER.send(player, player2.getName()); return; } - Location spawn = WorldUtil.IMP.getSpawn(location.getWorldName()); + Location spawn = this.worldUtil.getSpawn(location.getWorldName()); Captions.YOU_GOT_KICKED.send(player2); if (plot.equals(spawn.getPlot())) { - Location newSpawn = WorldUtil.IMP.getSpawn(this.plotAreaManager.getAllWorlds()[0]); + Location newSpawn = this.worldUtil.getSpawn(this.plotAreaManager.getAllWorlds()[0]); if (plot.equals(newSpawn.getPlot())) { // Kick from server if you can't be teleported to spawn player2.kick(Captions.YOU_GOT_KICKED.getTranslated()); diff --git a/Core/src/main/java/com/plotsquared/core/command/ListCmd.java b/Core/src/main/java/com/plotsquared/core/command/ListCmd.java index 0b9cb6d16..e1ba7afbf 100644 --- a/Core/src/main/java/com/plotsquared/core/command/ListCmd.java +++ b/Core/src/main/java/com/plotsquared/core/command/ListCmd.java @@ -25,6 +25,7 @@ */ package com.plotsquared.core.command; +import com.google.inject.Inject; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.CaptionUtility; import com.plotsquared.core.configuration.Captions; @@ -49,6 +50,7 @@ import com.plotsquared.core.util.query.SortingStrategy; import com.plotsquared.core.util.task.RunnableVal3; import com.plotsquared.core.uuid.UUIDMapping; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Arrays; @@ -72,14 +74,17 @@ import java.util.stream.Collectors; public class ListCmd extends SubCommand { private final PlotAreaManager plotAreaManager; + private final EconHandler econHandler; - public ListCmd(@NotNull final PlotAreaManager plotAreaManager) { + @Inject public ListCmd(@NotNull final PlotAreaManager plotAreaManager, + @Nullable final EconHandler econHandler) { this.plotAreaManager = plotAreaManager; + this.econHandler = econHandler; } private String[] getArgumentList(PlotPlayer player) { List args = new ArrayList<>(); - if (EconHandler.getEconHandler() != null && Permissions + if (this.econHandler != null && Permissions .hasPermission(player, Captions.PERMISSION_LIST_FOR_SALE)) { args.add("forsale"); } @@ -272,7 +277,7 @@ public class ListCmd extends SubCommand { Captions.PERMISSION_LIST_FOR_SALE); return false; } - if (EconHandler.getEconHandler() == null) { + if (this.econHandler == null) { break; } plotConsumer.accept(PlotQuery.newQuery().allPlots().thatPasses(plot -> plot.getFlag(PriceFlag.class) > 0)); @@ -412,7 +417,7 @@ public class ListCmd extends SubCommand { @Override public Collection tab(PlotPlayer player, String[] args, boolean space) { final List completions = new LinkedList<>(); - if (EconHandler.getEconHandler() != null && Permissions + if (this.econHandler != null && Permissions .hasPermission(player, Captions.PERMISSION_LIST_FOR_SALE)) { completions.add("forsale"); } diff --git a/Core/src/main/java/com/plotsquared/core/command/Load.java b/Core/src/main/java/com/plotsquared/core/command/Load.java index 60aebfa60..df18fc8a7 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Load.java +++ b/Core/src/main/java/com/plotsquared/core/command/Load.java @@ -25,6 +25,7 @@ */ package com.plotsquared.core.command; +import com.google.inject.Inject; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.player.PlotPlayer; @@ -54,9 +55,12 @@ import java.util.List; public class Load extends SubCommand { private final PlotAreaManager plotAreaManager; + private final SchematicHandler schematicHandler; - public Load(@NotNull final PlotAreaManager plotAreaManager) { + @Inject public Load(@NotNull final PlotAreaManager plotAreaManager, + @NotNull final SchematicHandler schematicHandler) { this.plotAreaManager = plotAreaManager; + this.schematicHandler = schematicHandler; } @Override public boolean onCommand(final PlotPlayer player, final String[] args) { @@ -110,7 +114,7 @@ public class Load extends SubCommand { plot.addRunning(); MainUtil.sendMessage(player, Captions.GENERATING_COMPONENT); TaskManager.runTaskAsync(() -> { - Schematic taskSchematic = SchematicHandler.manager.getSchematic(url); + Schematic taskSchematic = this.schematicHandler.getSchematic(url); if (taskSchematic == null) { plot.removeRunning(); sendMessage(player, Captions.SCHEMATIC_INVALID, @@ -118,8 +122,7 @@ public class Load extends SubCommand { return; } PlotArea area = plot.getArea(); - SchematicHandler.manager - .paste(taskSchematic, plot, 0, area.getMinBuildHeight(), 0, false, + this.schematicHandler.paste(taskSchematic, plot, 0, area.getMinBuildHeight(), 0, false, new RunnableVal() { @Override public void run(Boolean value) { plot.removeRunning(); @@ -144,7 +147,7 @@ public class Load extends SubCommand { if (schematics == null) { plot.addRunning(); TaskManager.runTaskAsync(() -> { - List schematics1 = SchematicHandler.manager.getSaves(player.getUUID()); + List schematics1 = this.schematicHandler.getSaves(player.getUUID()); plot.removeRunning(); if ((schematics1 == null) || schematics1.isEmpty()) { MainUtil.sendMessage(player, Captions.LOAD_FAILED); diff --git a/Core/src/main/java/com/plotsquared/core/command/MainCommand.java b/Core/src/main/java/com/plotsquared/core/command/MainCommand.java index 80692cca6..0ebf362f0 100644 --- a/Core/src/main/java/com/plotsquared/core/command/MainCommand.java +++ b/Core/src/main/java/com/plotsquared/core/command/MainCommand.java @@ -25,6 +25,7 @@ */ package com.plotsquared.core.command; +import com.google.inject.Injector; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Settings; @@ -46,6 +47,8 @@ import com.sk89q.worldedit.WorldEdit; import java.io.File; import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; import java.util.concurrent.CompletableFuture; /** @@ -68,92 +71,88 @@ public class MainCommand extends Command { if (instance == null) { instance = new MainCommand(); - final PlotAreaManager plotAreaManager = PlotSquared.get().getPlotAreaManager(); - final EventDispatcher eventDispatcher = PlotSquared.get().getEventDispatcher(); - final PlotListener plotListener = PlotSquared.get().getPlotListener(); - final YamlConfiguration worldconfiguration = PlotSquared.get().getWorldConfiguration(); - final File worldFile = PlotSquared.get().getWorldsFile(); - final WorldEdit worldEdit = PlotSquared.get().getWorldedit(); - - new Caps(); - new Buy(eventDispatcher); - new Save(plotAreaManager); - new Load(plotAreaManager); - new Confirm(); - new Template(plotAreaManager, worldconfiguration, worldFile); - new Download(plotAreaManager); - new Template(plotAreaManager, worldconfiguration, worldFile); - new Setup(); - new Area(plotAreaManager, eventDispatcher, plotListener, worldconfiguration, worldFile); - new DebugSaveTest(); - new DebugLoadTest(); - new CreateRoadSchematic(); - new DebugAllowUnsafe(); - new RegenAllRoads(plotAreaManager); - new Claim(eventDispatcher); - new Auto(plotAreaManager, eventDispatcher); - new HomeCommand(plotAreaManager); - new Visit(plotAreaManager); - new Set(); - new Clear(eventDispatcher); - new Delete(eventDispatcher); - new Trust(eventDispatcher); - new Add(eventDispatcher); - new Leave(eventDispatcher); - new Deny(plotAreaManager, eventDispatcher); - new Remove(eventDispatcher); - new Info(); - new Near(); - new ListCmd(plotAreaManager); - new Debug(plotAreaManager); - new SchematicCmd(plotAreaManager); - new PluginCmd(); - new Purge(plotAreaManager, plotListener); - new Reload(plotAreaManager, worldconfiguration, worldFile); - new Relight(); - new Merge(eventDispatcher); - new DebugPaste(PlotSquared.get().getConfigFile(), PlotSquared.get().getWorldsFile()); - new Unlink(eventDispatcher); - new Kick(plotAreaManager); - new Inbox(); - new Comment(); - new DatabaseCommand(plotAreaManager, eventDispatcher, plotListener, worldconfiguration); - new Swap(); - new Music(); - new DebugRoadRegen(); - new Trust(eventDispatcher); - new DebugExec(plotAreaManager, eventDispatcher, worldEdit); - new FlagCommand(); - new Target(); - new Move(plotAreaManager); - new Condense(plotAreaManager); - new Copy(); - new Chat(); - new Trim(plotAreaManager); - new Done(eventDispatcher); - new Continue(eventDispatcher); - new Middle(); - new Grant(); - // Set commands - new Owner(eventDispatcher); - new Desc(eventDispatcher); - new Biome(); - new Alias(); - new SetHome(); - new Cluster(); - new DebugImportWorlds(plotAreaManager); - new Backup(); + private final Injector injector = PlotSquared.platform().getInjector(); + final List> commands = new LinkedList<>(); + commands.add(Caps.class); + commands.add(Buy.class); + commands.add(Save.class); + commands.add(Load.class); + commands.add(Confirm.class); + commands.add(Template.class); + commands.add(Download.class); + commands.add(Setup.class); + commands.add(Area.class); + commands.add(DebugSaveTest.class); + commands.add(DebugLoadTest.class); + commands.add(CreateRoadSchematic.class); + commands.add(DebugAllowUnsafe.class); + commands.add(RegenAllRoads.class); + commands.add(Claim.class); + commands.add(Auto.class); + commands.add(HomeCommand.class); + commands.add(Visit.class); + commands.add(Set.class); + commands.add(Clear.class); + commands.add(Delete.class); + commands.add(Trust.class); + commands.add(Add.class); + commands.add(Leave.class); + commands.add(Deny.class); + commands.add(Remove.class); + commands.add(Info.class); + commands.add(Near.class); + commands.add(ListCmd.class); + commands.add(Debug.class); + commands.add(SchematicCmd.class); + commands.add(PluginCmd.class); + commands.add(Purge.class); + commands.add(Reload.class); + commands.add(Relight.class); + commands.add(Merge.class); + commands.add(DebugPaste.class); + commands.add(Unlink.class); + commands.add(Kick.class); + commands.add(Inbox.class); + commands.add(Comment.class); + commands.add(DatabaseCommand.class); + commands.add(Swap.class); + commands.add(Music.class); + commands.add(DebugRoadRegen.class); + commands.add(DebugExec.class); + commands.add(FlagCommand.class); + commands.add(Target.class); + commands.add(Move.class); + commands.add(Condense.class); + commands.add(Copy.class); + commands.add(Chat.class); + commands.add(Trim.class); + commands.add(Done.class); + commands.add(Continue.class); + commands.add(Middle.class); + commands.add(Grant.class); + commands.add(Owner.class); + commands.add(Desc.class); + commands.add(Biome.class); + commands.add(Alias.class); + commands.add(SetHome.class); + commands.add(Cluster.class); + commands.add(DebugImportWorlds.class); + commands.add(Backup.class); if (Settings.Ratings.USE_LIKES) { - final Like like = new Like(eventDispatcher); - new Dislike(like); + commands.add(Like.class); + commands.add(Dislike.class); } else { - new Rate(eventDispatcher); + commands.add(Rate.class); + } + + for (final Class command : commands) { + injector.getInstance(command); } // Referenced commands - instance.toggle = new Toggle(); - instance.help = new Help(instance); + instance.toggle = injector.getInstance(Toggle.class); + instance.help = injector.getInstance(Help.class); } return instance; } diff --git a/Core/src/main/java/com/plotsquared/core/command/Merge.java b/Core/src/main/java/com/plotsquared/core/command/Merge.java index 1b23bd10c..148b2c137 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Merge.java +++ b/Core/src/main/java/com/plotsquared/core/command/Merge.java @@ -25,6 +25,7 @@ */ package com.plotsquared.core.command; +import com.google.inject.Inject; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Settings; @@ -42,6 +43,7 @@ import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.StringMan; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.UUID; @@ -59,9 +61,12 @@ public class Merge extends SubCommand { public static final String[] aliases = new String[] {"n", "e", "s", "w"}; private final EventDispatcher eventDispatcher; - - public Merge(@NotNull final EventDispatcher eventDispatcher) { + private final EconHandler econHandler; + + @Inject public Merge(@NotNull final EventDispatcher eventDispatcher, + @Nullable final EconHandler econHandler) { this.eventDispatcher = eventDispatcher; + this.econHandler = econHandler; } public static String direction(float yaw) { @@ -164,8 +169,8 @@ public class Merge extends SubCommand { return true; } if (plot.autoMerge(Direction.ALL, maxSize, uuid, terrain)) { - if (EconHandler.getEconHandler() != null && plotArea.useEconomy() && price > 0d) { - EconHandler.getEconHandler().withdrawMoney(player, price); + if (this.econHandler != null && plotArea.useEconomy() && price > 0d) { + this.econHandler.withdrawMoney(player, price); sendMessage(player, Captions.REMOVED_BALANCE, String.valueOf(price)); } MainUtil.sendMessage(player, Captions.SUCCESS_MERGE); @@ -182,8 +187,8 @@ public class Merge extends SubCommand { uuid = plot.getOwnerAbs(); } } - if (!force && EconHandler.getEconHandler() != null && plotArea.useEconomy() && price > 0d - && EconHandler.getEconHandler().getMoney(player) < price) { + if (!force && this.econHandler != null && plotArea.useEconomy() && price > 0d + && this.econHandler.getMoney(player) < price) { sendMessage(player, Captions.CANNOT_AFFORD_MERGE, String.valueOf(price)); return false; } @@ -200,8 +205,8 @@ public class Merge extends SubCommand { return true; } if (plot.autoMerge(direction, maxSize - size, uuid, terrain)) { - if (EconHandler.getEconHandler() != null && plotArea.useEconomy() && price > 0d) { - EconHandler.getEconHandler().withdrawMoney(player, price); + if (this.econHandler != null && plotArea.useEconomy() && price > 0d) { + this.econHandler.withdrawMoney(player, price); sendMessage(player, Captions.REMOVED_BALANCE, String.valueOf(price)); } MainUtil.sendMessage(player, Captions.SUCCESS_MERGE); @@ -234,12 +239,12 @@ public class Merge extends SubCommand { sendMessage(accepter, Captions.MERGE_NOT_VALID); return; } - if (EconHandler.getEconHandler() != null && plotArea.useEconomy() && price > 0d) { - if (!force && EconHandler.getEconHandler().getMoney(player) < price) { + if (this.econHandler != null && plotArea.useEconomy() && price > 0d) { + if (!force && this.econHandler.getMoney(player) < price) { sendMessage(player, Captions.CANNOT_AFFORD_MERGE, String.valueOf(price)); return; } - EconHandler.getEconHandler().withdrawMoney(player, price); + this.econHandler.withdrawMoney(player, price); sendMessage(player, Captions.REMOVED_BALANCE, String.valueOf(price)); } MainUtil.sendMessage(player, Captions.SUCCESS_MERGE); diff --git a/Core/src/main/java/com/plotsquared/core/command/Music.java b/Core/src/main/java/com/plotsquared/core/command/Music.java index 91b756a81..989393fff 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Music.java +++ b/Core/src/main/java/com/plotsquared/core/command/Music.java @@ -25,6 +25,7 @@ */ package com.plotsquared.core.command; +import com.google.inject.Inject; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.events.PlotFlagAddEvent; import com.plotsquared.core.events.PlotFlagRemoveEvent; @@ -36,7 +37,9 @@ import com.plotsquared.core.plot.PlotInventory; import com.plotsquared.core.plot.PlotItemStack; import com.plotsquared.core.plot.flag.PlotFlag; import com.plotsquared.core.plot.flag.implementations.MusicFlag; +import com.plotsquared.core.util.InventoryUtil; import com.sk89q.worldedit.world.item.ItemTypes; +import org.jetbrains.annotations.Nullable; import java.util.Arrays; import java.util.Collection; @@ -55,6 +58,12 @@ public class Music extends SubCommand { "music_disc_far", "music_disc_mall", "music_disc_mellohi", "music_disc_stal", "music_disc_strad", "music_disc_ward", "music_disc_11", "music_disc_wait"); + private final InventoryUtil inventoryUtil; + + @Inject public Music(@Nullable final InventoryUtil inventoryUtil) { + this.inventoryUtil = inventoryUtil; + } + @Override public boolean onCommand(PlotPlayer player, String[] args) { Location location = player.getLocation(); final Plot plot = location.getPlotAbs(); @@ -65,7 +74,7 @@ public class Music extends SubCommand { sendMessage(player, Captions.NO_PLOT_PERMS); return true; } - PlotInventory inv = new PlotInventory(player, 2, "Plot Jukebox") { + PlotInventory inv = new PlotInventory(this.inventoryUtil, player, 2, "Plot Jukebox") { @Override public boolean onClick(int index) { PlotItemStack item = getItem(index); if (item == null) { diff --git a/Core/src/main/java/com/plotsquared/core/command/RegenAllRoads.java b/Core/src/main/java/com/plotsquared/core/command/RegenAllRoads.java index c89c46bed..7ed15a943 100644 --- a/Core/src/main/java/com/plotsquared/core/command/RegenAllRoads.java +++ b/Core/src/main/java/com/plotsquared/core/command/RegenAllRoads.java @@ -25,6 +25,7 @@ */ package com.plotsquared.core.command; +import com.google.inject.Inject; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.generator.HybridPlotManager; import com.plotsquared.core.generator.HybridUtils; @@ -45,9 +46,12 @@ import org.jetbrains.annotations.NotNull; public class RegenAllRoads extends SubCommand { private final PlotAreaManager plotAreaManager; + private final HybridUtils hybridUtils; - public RegenAllRoads(@NotNull final PlotAreaManager plotAreaManager) { + @Inject public RegenAllRoads(@NotNull final PlotAreaManager plotAreaManager, + @NotNull final HybridUtils hybridUtils) { this.plotAreaManager = plotAreaManager; + this.hybridUtils = hybridUtils; } @Override public boolean onCommand(PlotPlayer player, String[] args) { @@ -84,7 +88,7 @@ public class RegenAllRoads extends SubCommand { "&7 - To set a schematic, stand in a plot and use &c/plot createroadschematic"); //MainUtil.sendMessage(player, "&6Potential chunks to update: &7" + (chunks.size() * 1024)); //MainUtil.sendMessage(player, "&6Estimated time: &7" + chunks.size() + " seconds"); - boolean result = HybridUtils.manager.scheduleRoadUpdate(area, height); + boolean result = this.hybridUtils.scheduleRoadUpdate(area, height); if (!result) { MainUtil.sendMessage(player, "&cCannot schedule mass schematic update! (Is one already in progress?)"); diff --git a/Core/src/main/java/com/plotsquared/core/command/SchematicCmd.java b/Core/src/main/java/com/plotsquared/core/command/SchematicCmd.java index ffcbf0b74..66e76604e 100644 --- a/Core/src/main/java/com/plotsquared/core/command/SchematicCmd.java +++ b/Core/src/main/java/com/plotsquared/core/command/SchematicCmd.java @@ -26,6 +26,7 @@ package com.plotsquared.core.command; import com.google.common.collect.Lists; +import com.google.inject.Inject; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.location.Location; @@ -57,10 +58,13 @@ import java.util.UUID; public class SchematicCmd extends SubCommand { private final PlotAreaManager plotAreaManager; + private final SchematicHandler schematicHandler; private boolean running = false; - public SchematicCmd(@NotNull final PlotAreaManager plotAreaManager) { + @Inject public SchematicCmd(@NotNull final PlotAreaManager plotAreaManager, + @NotNull final SchematicHandler schematicHandler) { this.plotAreaManager = plotAreaManager; + this.schematicHandler = schematicHandler; } @Override public boolean onCommand(final PlotPlayer player, String[] args) { @@ -111,7 +115,7 @@ public class SchematicCmd extends SubCommand { UUID uuid = UUID.fromString(location.substring(4)); URL base = new URL(Settings.Web.URL); URL url = new URL(base, "uploads/" + uuid + ".schematic"); - schematic = SchematicHandler.manager.getSchematic(url); + schematic = this.schematicHandler.getSchematic(url); } catch (Exception e) { e.printStackTrace(); sendMessage(player, Captions.SCHEMATIC_INVALID, @@ -121,7 +125,7 @@ public class SchematicCmd extends SubCommand { } } else { try { - schematic = SchematicHandler.manager.getSchematic(location); + schematic = this.schematicHandler.getSchematic(location); } catch (SchematicHandler.UnsupportedFormatException e) { e.printStackTrace(); } @@ -132,8 +136,7 @@ public class SchematicCmd extends SubCommand { "non-existent or not in gzip format"); return; } - SchematicHandler.manager - .paste(schematic, plot, 0, 1, 0, false, new RunnableVal() { + this.schematicHandler.paste(schematic, plot, 0, 1, 0, false, new RunnableVal() { @Override public void run(Boolean value) { SchematicCmd.this.running = false; if (value) { @@ -166,7 +169,7 @@ public class SchematicCmd extends SubCommand { MainUtil.sendMessage(player, Captions.SCHEMATIC_EXPORTALL_WORLD); return false; } - boolean result = SchematicHandler.manager.exportAll(plots, null, null, + boolean result = this.schematicHandler.exportAll(plots, null, null, () -> MainUtil.sendMessage(player, Captions.SCHEMATIC_EXPORTALL_FINISHED)); if (!result) { MainUtil.sendMessage(player, Captions.TASK_IN_PROCESS); @@ -204,7 +207,7 @@ public class SchematicCmd extends SubCommand { return false; } ArrayList plots = Lists.newArrayList(plot); - boolean result = SchematicHandler.manager.exportAll(plots, null, null, () -> { + boolean result = this.schematicHandler.exportAll(plots, null, null, () -> { MainUtil.sendMessage(player, Captions.SCHEMATIC_EXPORTALL_SINGLE_FINISHED); SchematicCmd.this.running = false; }); @@ -221,8 +224,7 @@ public class SchematicCmd extends SubCommand { Captions.PERMISSION_SCHEMATIC_LIST); return false; } - final String string = - StringMan.join(SchematicHandler.manager.getSchematicNames(), "$2, $1"); + final String string = StringMan.join(this.schematicHandler.getSchematicNames(), "$2, $1"); Captions.SCHEMATIC_LIST.send(player, string); } break; diff --git a/Core/src/main/java/com/plotsquared/core/command/Template.java b/Core/src/main/java/com/plotsquared/core/command/Template.java index e8a1515ef..ab9785a01 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Template.java +++ b/Core/src/main/java/com/plotsquared/core/command/Template.java @@ -25,6 +25,7 @@ */ package com.plotsquared.core.command; +import com.google.inject.Inject; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.inject.annotations.WorldConfig; import com.plotsquared.core.inject.annotations.WorldFile; @@ -68,13 +69,22 @@ public class Template extends SubCommand { private final PlotAreaManager plotAreaManager; private final YamlConfiguration worldConfiguration; private final File worldFile; + private final SetupUtils setupUtils; + private final GlobalBlockQueue globalBlockQueue; + private final WorldUtil worldUtil; - public Template(@NotNull final PlotAreaManager plotAreaManager, - @WorldConfig @NotNull final YamlConfiguration worldConfiguration, - @WorldFile @NotNull final File worldFile) { + @Inject public Template(@NotNull final PlotAreaManager plotAreaManager, + @WorldConfig @NotNull final YamlConfiguration worldConfiguration, + @WorldFile @NotNull final File worldFile, + @NotNull final SetupUtils setupUtils, + @NotNull final GlobalBlockQueue globalBlockQueue, + @NotNull final WorldUtil worldUtil) { this.plotAreaManager = plotAreaManager; this.worldConfiguration = worldConfiguration; this.worldFile = worldFile; + this.setupUtils = setupUtils; + this.globalBlockQueue = globalBlockQueue; + this.worldUtil = worldUtil; } public static boolean extractAllFiles(String world, String template) { @@ -123,7 +133,7 @@ public class Template extends SubCommand { public static byte[] getBytes(PlotArea plotArea) { ConfigurationSection section = PlotSquared.get().getWorldConfiguration().getConfigurationSection("worlds." + plotArea.getWorldName()); YamlConfiguration config = new YamlConfiguration(); - String generator = SetupUtils.manager.getGenerator(plotArea); + String generator = PlotSquared.platform().getSetupUtils().getGenerator(plotArea); if (generator != null) { config.set("generator.plugin", generator); } @@ -197,7 +207,7 @@ public class Template extends SubCommand { String manager = worldConfig.getString("generator.plugin", PlotSquared.platform().getPluginName()); String generator = worldConfig.getString("generator.init", manager); - PlotAreaBuilder builder = new PlotAreaBuilder() + PlotAreaBuilder builder = PlotAreaBuilder.newBuilder() .plotAreaType(MainUtil.getType(worldConfig)) .terrainType(MainUtil.getTerrain(worldConfig)) .plotManager(manager) @@ -205,10 +215,10 @@ public class Template extends SubCommand { .settingsNodesWrapper(new SettingsNodesWrapper(new ConfigurationNode[0], null)) .worldName(world); - SetupUtils.manager.setupWorld(builder); - GlobalBlockQueue.IMP.addEmptyTask(() -> { + this.setupUtils.setupWorld(builder); + this.globalBlockQueue.addEmptyTask(() -> { MainUtil.sendMessage(player, "Done!"); - player.teleport(WorldUtil.IMP.getSpawn(world), TeleportCause.COMMAND); + player.teleport(this.worldUtil.getSpawn(world), TeleportCause.COMMAND); }); return true; } diff --git a/Core/src/main/java/com/plotsquared/core/generator/ClassicPlotWorld.java b/Core/src/main/java/com/plotsquared/core/generator/ClassicPlotWorld.java index 4536aaa74..4ea893678 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/ClassicPlotWorld.java +++ b/Core/src/main/java/com/plotsquared/core/generator/ClassicPlotWorld.java @@ -25,15 +25,15 @@ */ package com.plotsquared.core.generator; -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.listener.PlotListener; +import com.plotsquared.core.inject.annotations.WorldConfig; import com.plotsquared.core.plot.BlockBucket; import com.plotsquared.core.plot.PlotId; -import com.plotsquared.core.util.EventDispatcher; +import com.plotsquared.core.queue.GlobalBlockQueue; +import com.plotsquared.core.util.EconHandler; import com.sk89q.worldedit.world.block.BlockTypes; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -63,10 +63,10 @@ public abstract class ClassicPlotWorld extends SquarePlotWorld { @NotNull final IndependentPlotGenerator generator, @NotNull final PlotId min, @NotNull final PlotId max, - @NotNull final EventDispatcher eventDispatcher, - @NotNull final PlotListener plotListener, - @WorldConfig @NotNull final YamlConfiguration worldConfiguration) { - super(worldName, id, generator, min, max, eventDispatcher, plotListener, worldConfiguration); + @WorldConfig @NotNull final YamlConfiguration worldConfiguration, + @NotNull final GlobalBlockQueue blockQueue, + @Nullable final EconHandler econHandler) { + super(worldName, id, generator, min, max, worldConfiguration, blockQueue, econHandler); } /** diff --git a/Core/src/main/java/com/plotsquared/core/generator/GridPlotWorld.java b/Core/src/main/java/com/plotsquared/core/generator/GridPlotWorld.java index aa4023d27..935ce6145 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/GridPlotWorld.java +++ b/Core/src/main/java/com/plotsquared/core/generator/GridPlotWorld.java @@ -25,14 +25,12 @@ */ package com.plotsquared.core.generator; -import com.plotsquared.core.inject.annotations.WorldConfig; import com.plotsquared.core.configuration.file.YamlConfiguration; -import com.plotsquared.core.listener.PlotListener; +import com.plotsquared.core.inject.annotations.WorldConfig; import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotId; import com.plotsquared.core.queue.GlobalBlockQueue; import com.plotsquared.core.util.EconHandler; -import com.plotsquared.core.util.EventDispatcher; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -41,10 +39,9 @@ public abstract class GridPlotWorld extends PlotArea { public short SIZE; public GridPlotWorld(String worldName, String id, @NotNull IndependentPlotGenerator generator, - PlotId min, PlotId max, @NotNull final EventDispatcher eventDispatcher, @NotNull final - PlotListener plotListener, @WorldConfig @NotNull final YamlConfiguration worldConfiguration, + PlotId min, PlotId max, @WorldConfig @NotNull final YamlConfiguration worldConfiguration, @NotNull final GlobalBlockQueue blockQueue, @Nullable final EconHandler econHandler) { - super(worldName, id, generator, min, max, eventDispatcher, plotListener, worldConfiguration, blockQueue, econHandler); + super(worldName, id, generator, min, max, worldConfiguration, blockQueue, econHandler); } } 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 3b1739961..c3f238470 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/HybridGen.java +++ b/Core/src/main/java/com/plotsquared/core/generator/HybridGen.java @@ -28,15 +28,12 @@ package com.plotsquared.core.generator; import com.google.common.base.Preconditions; import com.google.inject.Inject; import com.plotsquared.core.PlotSquared; -import com.plotsquared.core.inject.annotations.WorldConfig; import com.plotsquared.core.configuration.Settings; -import com.plotsquared.core.configuration.file.YamlConfiguration; -import com.plotsquared.core.listener.PlotListener; +import com.plotsquared.core.inject.factory.HybridPlotWorldFactory; import com.plotsquared.core.location.Location; import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotId; import com.plotsquared.core.queue.ScopedLocalBlockQueue; -import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.MathMan; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; @@ -45,16 +42,10 @@ import org.jetbrains.annotations.NotNull; public class HybridGen extends IndependentPlotGenerator { - private final EventDispatcher eventDispatcher; - private final PlotListener plotListener; - private final YamlConfiguration worldConfiguration; + private final HybridPlotWorldFactory hybridPlotWorldFactory; - @Inject public HybridGen(@NotNull final EventDispatcher eventDispatcher, - @NotNull final PlotListener plotListener, - @WorldConfig @NotNull final YamlConfiguration worldConfiguration) { - this.eventDispatcher = eventDispatcher; - this.plotListener = plotListener; - this.worldConfiguration = worldConfiguration; + @Inject public HybridGen(@NotNull final HybridPlotWorldFactory hybridPlotWorldFactory) { + this.hybridPlotWorldFactory = hybridPlotWorldFactory; } @Override public String getName() { @@ -238,8 +229,7 @@ public class HybridGen extends IndependentPlotGenerator { } @Override public PlotArea getNewPlotArea(String world, String id, PlotId min, PlotId max) { - return new HybridPlotWorld(world, id, this, min, max, this.eventDispatcher, - this.plotListener, this.worldConfiguration); + return this.hybridPlotWorldFactory.create(world, id, this, min, max); } @Override public void initialize(PlotArea area) { 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 fb2fb44c0..fa1e7965b 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java +++ b/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java @@ -27,19 +27,19 @@ 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; import com.plotsquared.core.configuration.ConfigurationSection; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.file.YamlConfiguration; -import com.plotsquared.core.listener.PlotListener; +import com.plotsquared.core.inject.annotations.WorldConfig; 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.PlotManager; import com.plotsquared.core.plot.schematic.Schematic; -import com.plotsquared.core.util.EventDispatcher; +import com.plotsquared.core.queue.GlobalBlockQueue; +import com.plotsquared.core.util.EconHandler; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.MathMan; import com.plotsquared.core.util.RegionManager; @@ -58,6 +58,7 @@ import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; import lombok.Getter; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.inject.Inject; import java.io.File; @@ -87,12 +88,12 @@ public class HybridPlotWorld extends ClassicPlotWorld { @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); + @NotNull final SchematicHandler schematicHandler, + @NotNull final GlobalBlockQueue blockQueue, + @Nullable final EconHandler econHandler) { + super(worldName, id, generator, min, max, worldConfiguration, blockQueue, econHandler); this.regionManager = regionManager; this.schematicHandler = schematicHandler; } diff --git a/Core/src/main/java/com/plotsquared/core/generator/SquarePlotWorld.java b/Core/src/main/java/com/plotsquared/core/generator/SquarePlotWorld.java index b293558f9..940669fb0 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/SquarePlotWorld.java +++ b/Core/src/main/java/com/plotsquared/core/generator/SquarePlotWorld.java @@ -26,13 +26,14 @@ package com.plotsquared.core.generator; import com.plotsquared.core.PlotSquared; -import com.plotsquared.core.inject.annotations.WorldConfig; import com.plotsquared.core.configuration.ConfigurationSection; import com.plotsquared.core.configuration.file.YamlConfiguration; -import com.plotsquared.core.listener.PlotListener; +import com.plotsquared.core.inject.annotations.WorldConfig; import com.plotsquared.core.plot.PlotId; -import com.plotsquared.core.util.EventDispatcher; +import com.plotsquared.core.queue.GlobalBlockQueue; +import com.plotsquared.core.util.EconHandler; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public abstract class SquarePlotWorld extends GridPlotWorld { @@ -41,10 +42,15 @@ public abstract class SquarePlotWorld extends GridPlotWorld { public int ROAD_OFFSET_X = 0; public int ROAD_OFFSET_Z = 0; - public SquarePlotWorld(String worldName, String id, @NotNull IndependentPlotGenerator generator, - PlotId min, PlotId max, @NotNull final EventDispatcher eventDispatcher, @NotNull final - PlotListener plotListener, @WorldConfig @NotNull final YamlConfiguration worldConfiguration) { - super(worldName, id, generator, min, max, eventDispatcher, plotListener, worldConfiguration); + public SquarePlotWorld(final String worldName, + @Nullable final String id, + @NotNull final IndependentPlotGenerator generator, + @Nullable final PlotId min, + @Nullable final PlotId max, + @WorldConfig @NotNull final YamlConfiguration worldConfiguration, + @NotNull final GlobalBlockQueue blockQueue, + @Nullable final EconHandler econHandler) { + super(worldName, id, generator, min, max, worldConfiguration, blockQueue, econHandler); } @Override public void loadConfiguration(ConfigurationSection config) { diff --git a/Core/src/main/java/com/plotsquared/core/inject/annotations/ConsoleActor.java b/Core/src/main/java/com/plotsquared/core/inject/annotations/ConsoleActor.java index 6c0288673..74ed7e2af 100644 --- a/Core/src/main/java/com/plotsquared/core/inject/annotations/ConsoleActor.java +++ b/Core/src/main/java/com/plotsquared/core/inject/annotations/ConsoleActor.java @@ -1,3 +1,28 @@ +/* + * _____ _ _ _____ _ + * | __ \| | | | / ____| | | + * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| | + * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` | + * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| | + * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_| + * | | + * |_| + * PlotSquared plot management system for Minecraft + * Copyright (C) 2020 IntellectualSites + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package com.plotsquared.core.inject.annotations; import java.lang.annotation.ElementType; diff --git a/Core/src/main/java/com/plotsquared/core/inject/annotations/DefaultGenerator.java b/Core/src/main/java/com/plotsquared/core/inject/annotations/DefaultGenerator.java index 6a5842ec5..69d1c0192 100644 --- a/Core/src/main/java/com/plotsquared/core/inject/annotations/DefaultGenerator.java +++ b/Core/src/main/java/com/plotsquared/core/inject/annotations/DefaultGenerator.java @@ -1,3 +1,28 @@ +/* + * _____ _ _ _____ _ + * | __ \| | | | / ____| | | + * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| | + * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` | + * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| | + * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_| + * | | + * |_| + * PlotSquared plot management system for Minecraft + * Copyright (C) 2020 IntellectualSites + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package com.plotsquared.core.inject.annotations; import java.lang.annotation.ElementType; diff --git a/Core/src/main/java/com/plotsquared/core/inject/factory/HybridPlotWorldFactory.java b/Core/src/main/java/com/plotsquared/core/inject/factory/HybridPlotWorldFactory.java new file mode 100644 index 000000000..9dd2223dd --- /dev/null +++ b/Core/src/main/java/com/plotsquared/core/inject/factory/HybridPlotWorldFactory.java @@ -0,0 +1,39 @@ +/* + * _____ _ _ _____ _ + * | __ \| | | | / ____| | | + * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| | + * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` | + * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| | + * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_| + * | | + * |_| + * PlotSquared plot management system for Minecraft + * Copyright (C) 2020 IntellectualSites + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.plotsquared.core.inject.factory; + +import com.plotsquared.core.generator.HybridPlotWorld; +import com.plotsquared.core.generator.IndependentPlotGenerator; +import com.plotsquared.core.plot.PlotId; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public interface HybridPlotWorldFactory { + + @NotNull HybridPlotWorld create(@NotNull String worldName, @Nullable String id, + @NotNull IndependentPlotGenerator plotGenerator, @Nullable PlotId min, @Nullable PlotId max); + +} diff --git a/Core/src/main/java/com/plotsquared/core/inject/factory/PlayerBackupProfileFactory.java b/Core/src/main/java/com/plotsquared/core/inject/factory/PlayerBackupProfileFactory.java index 67411d76f..b9497aa02 100644 --- a/Core/src/main/java/com/plotsquared/core/inject/factory/PlayerBackupProfileFactory.java +++ b/Core/src/main/java/com/plotsquared/core/inject/factory/PlayerBackupProfileFactory.java @@ -1,3 +1,28 @@ +/* + * _____ _ _ _____ _ + * | __ \| | | | / ____| | | + * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| | + * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` | + * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| | + * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_| + * | | + * |_| + * PlotSquared plot management system for Minecraft + * Copyright (C) 2020 IntellectualSites + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package com.plotsquared.core.inject.factory; import com.plotsquared.core.backup.PlayerBackupProfile; @@ -8,6 +33,6 @@ import java.util.UUID; public interface PlayerBackupProfileFactory { - PlayerBackupProfile create(@NotNull UUID uuid, @NotNull Plot plot); + @NotNull PlayerBackupProfile create(@NotNull UUID uuid, @NotNull Plot plot); } diff --git a/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java b/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java index f722327a9..920b9b650 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java +++ b/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java @@ -28,7 +28,6 @@ package com.plotsquared.core.plot; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.plotsquared.core.PlotSquared; -import com.plotsquared.core.inject.annotations.WorldConfig; import com.plotsquared.core.collection.QuadMap; import com.plotsquared.core.configuration.CaptionUtility; import com.plotsquared.core.configuration.Captions; @@ -39,7 +38,7 @@ import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.file.YamlConfiguration; import com.plotsquared.core.generator.GridPlotWorld; import com.plotsquared.core.generator.IndependentPlotGenerator; -import com.plotsquared.core.listener.PlotListener; +import com.plotsquared.core.inject.annotations.WorldConfig; import com.plotsquared.core.location.Direction; import com.plotsquared.core.location.Location; import com.plotsquared.core.location.PlotLoc; @@ -52,7 +51,6 @@ import com.plotsquared.core.plot.flag.implementations.DoneFlag; import com.plotsquared.core.queue.GlobalBlockQueue; import com.plotsquared.core.queue.LocalBlockQueue; import com.plotsquared.core.util.EconHandler; -import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.Expression; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.MathMan; @@ -137,16 +135,13 @@ public abstract class PlotArea { @Getter private final FlagContainer roadFlagContainer = new FlagContainer(GlobalFlagContainer.getInstance()); - private final EventDispatcher eventDispatcher; - private final PlotListener plotListener; private final YamlConfiguration worldConfiguration; private final GlobalBlockQueue globalBlockQueue; private final EconHandler econHandler; public PlotArea(@NotNull final String worldName, @Nullable final String id, @NotNull IndependentPlotGenerator generator, @Nullable final PlotId min, - @Nullable final PlotId max, @NotNull final EventDispatcher eventDispatcher, - @NotNull final PlotListener plotListener, + @Nullable final PlotId max, @WorldConfig @Nullable final YamlConfiguration worldConfiguration, @NotNull final GlobalBlockQueue blockQueue, @Nullable final EconHandler econHandler) { @@ -167,8 +162,6 @@ public abstract class PlotArea { this.max = max; } this.worldHash = worldName.hashCode(); - this.eventDispatcher = eventDispatcher; - this.plotListener = plotListener; this.worldConfiguration = worldConfiguration; this.econHandler = econHandler; }