diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java index cfa3c55e8..a46a4919c 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java @@ -180,10 +180,11 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl private boolean metricsStarted; @Getter private BackupManager backupManager; @Getter private PlatformWorldManager worldManager; - private final BukkitPlayerManager playerManager = new BukkitPlayerManager(); + private BukkitPlayerManager playerManager; private EconHandler econ; private PermHandler perm; - + private PlotAreaManager plotAreaManager; + @Override public int[] getServerVersion() { if (this.version == null) { try { @@ -213,7 +214,9 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl this.pluginName = getDescription().getName(); PlotPlayer.registerConverter(Player.class, BukkitUtil::getPlayer); - new PlotSquared(this, "Bukkit"); + final PlotSquared plotSquared = new PlotSquared(this, "Bukkit"); + this.plotAreaManager = plotSquared.getPlotAreaManager(); + this.playerManager = new BukkitPlayerManager(this.plotAreaManager); if (PlotSquared.platform().getServerVersion()[1] < 13) { System.out.println( @@ -427,10 +430,10 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl event.printStackTrace(); } } - final PlotAreaManager manager = PlotSquared.get().getPlotAreaManager(); - if (manager instanceof SinglePlotAreaManager) { + + if (this.plotAreaManager instanceof SinglePlotAreaManager) { long start = System.currentTimeMillis(); - final SinglePlotArea area = ((SinglePlotAreaManager) manager).getArea(); + final SinglePlotArea area = ((SinglePlotAreaManager) this.plotAreaManager).getArea(); outer: for (final World world : Bukkit.getWorlds()) { @@ -624,7 +627,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl @Override @SuppressWarnings("deprecation") public void runEntityTask() { PlotSquared.log(Captions.PREFIX + "KillAllEntities started."); - TaskManager.runTaskRepeat(() -> PlotSquared.get().getPlotAreaManager().forEachPlotArea(plotArea -> { + TaskManager.runTaskRepeat(() -> this.plotAreaManager.forEachPlotArea(plotArea -> { final World world = Bukkit.getWorld(plotArea.getWorldName()); try { if (world == null) { @@ -883,7 +886,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl final String id) { final IndependentPlotGenerator result; if (id != null && id.equalsIgnoreCase("single")) { - result = new SingleWorldGenerator(); + result = new SingleWorldGenerator(this.plotAreaManager); } else { result = PlotSquared.platform().getDefaultGenerator(); if (!PlotSquared.get().setupPlotWorld(worldName, id, result)) { @@ -894,11 +897,11 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl } @Override public void registerPlayerEvents() { - final PlayerEvents main = new PlayerEvents(); + final PlayerEvents main = new PlayerEvents(this.plotAreaManager); getServer().getPluginManager().registerEvents(main, this); getServer().getPluginManager().registerEvents(new EntitySpawnListener(), this); if (PaperLib.isPaper() && Settings.Paper_Components.PAPER_LISTENERS) { - getServer().getPluginManager().registerEvents(new PaperListener(), this); + getServer().getPluginManager().registerEvents(new PaperListener(this.plotAreaManager), this); } PlotListener.startRunnable(); } @@ -982,18 +985,18 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl if (gen instanceof GeneratorWrapper) { return (GeneratorWrapper) gen; } - return new BukkitPlotGenerator(world, gen); + return new BukkitPlotGenerator(world, gen, this.plotAreaManager); } else { - return new BukkitPlotGenerator(world, PlotSquared.platform().getDefaultGenerator()); + return new BukkitPlotGenerator(world, PlotSquared.platform().getDefaultGenerator(), this.plotAreaManager); } } @Override public HybridUtils initHybridUtils() { - return new BukkitHybridUtils(); + return new BukkitHybridUtils(this.plotAreaManager); } @Override public SetupUtils initSetupUtils() { - return new BukkitSetupUtils(); + return new BukkitSetupUtils(this.plotAreaManager); } @Override public void startMetrics() { @@ -1011,7 +1014,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl } map.put(plotAreaType.name().toLowerCase(), terrainTypes); } - for (final PlotArea plotArea : PlotSquared.get().getPlotAreaManager().getAllPlotAreas()) { + for (final PlotArea plotArea : this.plotAreaManager.getAllPlotAreas()) { final Map terrainTypeMap = map.get(plotArea.getType().name().toLowerCase()); terrainTypeMap.put(plotArea.getTerrain().name().toLowerCase(), @@ -1040,11 +1043,11 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl } @Override public void registerChunkProcessor() { - getServer().getPluginManager().registerEvents(new ChunkListener(), this); + getServer().getPluginManager().registerEvents(new ChunkListener(this.plotAreaManager), this); } @Override public void registerWorldEvents() { - getServer().getPluginManager().registerEvents(new WorldEvents(), this); + getServer().getPluginManager().registerEvents(new WorldEvents(this.plotAreaManager), this); } @NotNull @Override public IndependentPlotGenerator getDefaultGenerator() { @@ -1072,7 +1075,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl world = Bukkit.getWorld(worldName); } else { try { - if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(worldName)) { + if (!this.plotAreaManager.hasPlotArea(worldName)) { SetGenCB.setGenerator(BukkitUtil.getWorld(worldName)); } } catch (Exception e) { @@ -1086,7 +1089,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl if (gen instanceof BukkitPlotGenerator) { PlotSquared.get().loadWorld(worldName, (BukkitPlotGenerator) gen); } else if (gen != null) { - PlotSquared.get().loadWorld(worldName, new BukkitPlotGenerator(worldName, gen)); + PlotSquared.get().loadWorld(worldName, new BukkitPlotGenerator(worldName, gen, this.plotAreaManager)); } else if (PlotSquared.get().worlds.contains("worlds." + worldName)) { PlotSquared.get().loadWorld(worldName, null); } @@ -1144,7 +1147,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl @Override public GeneratorWrapper wrapPlotGenerator(@Nullable final String world, @NonNull final IndependentPlotGenerator generator) { - return new BukkitPlotGenerator(world, generator); + return new BukkitPlotGenerator(world, generator, this.plotAreaManager); } @Override public List, Boolean>> getPluginIds() { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BlockStatePopulator.java b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BlockStatePopulator.java index 8359d1e61..0dc7e943f 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BlockStatePopulator.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BlockStatePopulator.java @@ -25,10 +25,10 @@ */ package com.plotsquared.bukkit.generator; -import com.plotsquared.core.PlotSquared; import com.plotsquared.core.generator.IndependentPlotGenerator; import com.plotsquared.core.location.ChunkWrapper; import com.plotsquared.core.plot.PlotArea; +import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.queue.GlobalBlockQueue; import com.plotsquared.core.queue.LocalBlockQueue; import com.plotsquared.core.queue.ScopedLocalBlockQueue; @@ -42,10 +42,14 @@ import java.util.Random; final class BlockStatePopulator extends BlockPopulator { private final IndependentPlotGenerator plotGenerator; + private final PlotAreaManager plotAreaManager; + private LocalBlockQueue queue; - public BlockStatePopulator(IndependentPlotGenerator plotGenerator) { + public BlockStatePopulator(@NotNull final IndependentPlotGenerator plotGenerator, + @NotNull final PlotAreaManager plotAreaManager) { this.plotGenerator = plotGenerator; + this.plotAreaManager = plotAreaManager; } @Override @@ -54,7 +58,7 @@ final class BlockStatePopulator extends BlockPopulator { if (this.queue == null) { this.queue = GlobalBlockQueue.IMP.getNewQueue(world.getName(), false); } - final PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotArea(world.getName(), null); + final PlotArea area = this.plotAreaManager.getPlotArea(world.getName(), null); if (area == null) { return; } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitHybridUtils.java b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitHybridUtils.java index 2cf4a3b8b..4c9b40d85 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitHybridUtils.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitHybridUtils.java @@ -26,8 +26,13 @@ package com.plotsquared.bukkit.generator; import com.plotsquared.core.generator.HybridUtils; +import com.plotsquared.core.plot.world.PlotAreaManager; +import org.jetbrains.annotations.NotNull; public class BukkitHybridUtils extends HybridUtils { + public BukkitHybridUtils(@NotNull PlotAreaManager plotAreaManager) { + super(plotAreaManager); + } } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java index 70688f4c7..09aaa0ea6 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java @@ -33,6 +33,7 @@ import com.plotsquared.core.generator.IndependentPlotGenerator; import com.plotsquared.core.generator.SingleWorldGenerator; import com.plotsquared.core.location.ChunkWrapper; import com.plotsquared.core.plot.PlotArea; +import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.queue.ScopedLocalBlockQueue; import com.plotsquared.core.util.ChunkManager; import com.plotsquared.core.util.MainUtil; @@ -54,6 +55,7 @@ public class BukkitPlotGenerator extends ChunkGenerator @SuppressWarnings("unused") public final boolean PAPER_ASYNC_SAFE = true; + private final PlotAreaManager plotAreaManager; private final IndependentPlotGenerator plotGenerator; private final ChunkGenerator platformGenerator; private final boolean full; @@ -62,24 +64,24 @@ public class BukkitPlotGenerator extends ChunkGenerator @Getter private final String levelName; - public BukkitPlotGenerator(String name, IndependentPlotGenerator generator) { - if (generator == null) { - throw new IllegalArgumentException("Generator may not be null!"); - } + public BukkitPlotGenerator(@NotNull final String name, + @NotNull final IndependentPlotGenerator generator, @NotNull final PlotAreaManager plotAreaManager) { + this.plotAreaManager = plotAreaManager; this.levelName = name; this.plotGenerator = generator; this.platformGenerator = this; this.populators = new ArrayList<>(); - this.populators.add(new BlockStatePopulator(this.plotGenerator)); + this.populators.add(new BlockStatePopulator(this.plotGenerator, this.plotAreaManager)); this.full = true; MainUtil.initCache(); } - public BukkitPlotGenerator(final String world, final ChunkGenerator cg) { + public BukkitPlotGenerator(final String world, final ChunkGenerator cg, @NotNull final PlotAreaManager plotAreaManager) { if (cg instanceof BukkitPlotGenerator) { throw new IllegalArgumentException("ChunkGenerator: " + cg.getClass().getName() + " is already a BukkitPlotGenerator!"); } + this.plotAreaManager = plotAreaManager; this.levelName = world; this.full = false; this.platformGenerator = cg; @@ -108,7 +110,7 @@ public class BukkitPlotGenerator extends ChunkGenerator if (!this.loaded) { String name = world.getName(); PlotSquared.get().loadWorld(name, this); - final Set areas = PlotSquared.get().getPlotAreaManager().getPlotAreasSet(name); + final Set areas = this.plotAreaManager.getPlotAreasSet(name); if (!areas.isEmpty()) { PlotArea area = areas.iterator().next(); if (!area.isMobSpawning()) { @@ -198,8 +200,8 @@ public class BukkitPlotGenerator extends ChunkGenerator if (ChunkManager.preProcessChunk(loc, result)) { return; } - PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotArea(world.getName(), null); - if (area == null && (area = PlotSquared.get().getPlotAreaManager().getPlotArea(this.levelName, null)) == null) { + PlotArea area = this.plotAreaManager.getPlotArea(world.getName(), null); + if (area == null && (area = this.plotAreaManager.getPlotArea(this.levelName, null)) == null) { throw new IllegalStateException( "Cannot regenerate chunk that does not belong to a plot area." + " Location: " + loc + ", world: " + world); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ChunkListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ChunkListener.java index bbecc56c2..29f06a263 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ChunkListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ChunkListener.java @@ -29,6 +29,7 @@ import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.location.Location; import com.plotsquared.core.plot.Plot; +import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.util.ReflectionUtils.RefClass; import com.plotsquared.core.util.ReflectionUtils.RefField; import com.plotsquared.core.util.ReflectionUtils.RefMethod; @@ -51,6 +52,7 @@ import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.ItemSpawnEvent; import org.bukkit.event.world.ChunkLoadEvent; import org.bukkit.event.world.ChunkUnloadEvent; +import org.jetbrains.annotations.NotNull; import java.lang.reflect.Method; import java.util.HashSet; @@ -60,12 +62,15 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass; @SuppressWarnings("unused") public class ChunkListener implements Listener { + private final PlotAreaManager plotAreaManager; + private RefMethod methodGetHandleChunk; private RefField mustSave; private Chunk lastChunk; private boolean ignoreUnload = false; - - public ChunkListener() { + + public ChunkListener(@NotNull final PlotAreaManager plotAreaManager) { + this.plotAreaManager = plotAreaManager; if (Settings.Chunk_Processor.AUTO_TRIM) { try { RefClass classChunk = getRefClass("{nms}.Chunk"); @@ -90,7 +95,7 @@ public class ChunkListener implements Listener { HashSet toUnload = new HashSet<>(); for (World world : Bukkit.getWorlds()) { String worldName = world.getName(); - if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(worldName)) { + if (!this.plotAreaManager.hasPlotArea(worldName)) { continue; } Object w = world.getClass().getDeclaredMethod("getHandle").invoke(world); @@ -177,7 +182,7 @@ public class ChunkListener implements Listener { Chunk chunk = event.getChunk(); if (Settings.Chunk_Processor.AUTO_TRIM) { String world = chunk.getWorld().getName(); - if (PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) { + if (this.plotAreaManager.hasPlotArea(world)) { if (unloadChunk(world, chunk, true)) { return; } @@ -200,7 +205,7 @@ public class ChunkListener implements Listener { event.setCancelled(true); return; } - if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(chunk.getWorld().getName())) { + if (!this.plotAreaManager.hasPlotArea(chunk.getWorld().getName())) { return; } Entity[] entities = chunk.getEntities(); @@ -230,7 +235,7 @@ public class ChunkListener implements Listener { event.setCancelled(true); return; } - if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(chunk.getWorld().getName())) { + if (!this.plotAreaManager.hasPlotArea(chunk.getWorld().getName())) { return; } Entity[] entities = chunk.getEntities(); @@ -281,7 +286,7 @@ public class ChunkListener implements Listener { } public boolean processChunk(Chunk chunk, boolean unload) { - if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(chunk.getWorld().getName())) { + if (!this.plotAreaManager.hasPlotArea(chunk.getWorld().getName())) { return false; } Entity[] entities = chunk.getEntities(); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java index ed116f051..023e72624 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java @@ -33,7 +33,6 @@ import com.destroystokyo.paper.event.entity.SlimePathfindEvent; import com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent; import com.destroystokyo.paper.event.server.AsyncTabCompleteEvent; import com.plotsquared.bukkit.util.BukkitUtil; -import com.plotsquared.core.PlotSquared; import com.plotsquared.core.command.Command; import com.plotsquared.core.command.MainCommand; import com.plotsquared.core.configuration.Captions; @@ -43,6 +42,7 @@ import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.flag.implementations.DoneFlag; +import com.plotsquared.core.plot.world.PlotAreaManager; import org.bukkit.Chunk; import org.bukkit.block.Block; import org.bukkit.block.TileState; @@ -58,6 +58,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.projectiles.ProjectileSource; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Collection; @@ -71,8 +72,13 @@ import java.util.regex.Pattern; @SuppressWarnings("unused") public class PaperListener implements Listener { + private final PlotAreaManager plotAreaManager; private Chunk lastChunk; + public PaperListener(@NotNull final PlotAreaManager plotAreaManager) { + this.plotAreaManager = plotAreaManager; + } + @EventHandler public void onEntityPathfind(EntityPathfindEvent event) { if (!Settings.Paper_Components.ENTITY_PATHING) { return; @@ -305,7 +311,7 @@ public class PaperListener implements Listener { return; } Location location = BukkitUtil.getLocation(entity); - if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorldName())) { + if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) { return; } PlotPlayer pp = BukkitUtil.getPlayer((Player) shooter); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java index 0989605de..92b3fc99d 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java @@ -99,6 +99,7 @@ import com.plotsquared.core.plot.flag.implementations.VillagerInteractFlag; import com.plotsquared.core.plot.flag.implementations.VineGrowFlag; import com.plotsquared.core.plot.flag.types.BlockTypeWrapper; import com.plotsquared.core.plot.message.PlotMessage; +import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.util.EntityUtil; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.MathMan; @@ -210,6 +211,7 @@ import org.bukkit.plugin.Plugin; import org.bukkit.projectiles.BlockProjectileSource; import org.bukkit.projectiles.ProjectileSource; import org.bukkit.util.Vector; +import org.jetbrains.annotations.NotNull; import java.lang.reflect.Field; import java.util.ArrayList; @@ -224,12 +226,13 @@ import java.util.regex.Pattern; /** * Player Events involving plots. */ -@SuppressWarnings("unused") -public class PlayerEvents extends PlotListener implements Listener { +@SuppressWarnings("unused") public class PlayerEvents extends PlotListener implements Listener { public static final com.sk89q.worldedit.world.entity.EntityType FAKE_ENTITY_TYPE = new com.sk89q.worldedit.world.entity.EntityType("plotsquared:fake"); + private final PlotAreaManager plotAreaManager; + private boolean pistonBlocks = true; private float lastRadius; // To prevent recursion @@ -237,8 +240,9 @@ public class PlayerEvents extends PlotListener implements Listener { private Field fieldPlayer; private PlayerMoveEvent moveTmp; private String internalVersion; - - { + + public PlayerEvents(@NotNull final PlotAreaManager plotAreaManager) { + this.plotAreaManager = plotAreaManager; try { fieldPlayer = PlayerEvent.class.getDeclaredField("player"); fieldPlayer.setAccessible(true); @@ -246,7 +250,7 @@ public class PlayerEvents extends PlotListener implements Listener { e.printStackTrace(); } } - + public static void sendBlockChange(final org.bukkit.Location bloc, final BlockData data) { TaskManager.runTaskLater(() -> { String world = bloc.getWorld().getName(); @@ -254,7 +258,8 @@ public class PlayerEvents extends PlotListener implements Listener { int z = bloc.getBlockZ(); int distance = Bukkit.getViewDistance() * 16; - for (final PlotPlayer player : PlotSquared.platform().getPlayerManager().getPlayers()) { + for (final PlotPlayer player : PlotSquared.platform().getPlayerManager() + .getPlayers()) { Location location = player.getLocation(); if (location.getWorldName().equals(world)) { if (16 * Math.abs(location.getX() - x) / 16 > distance @@ -359,19 +364,21 @@ public class PlayerEvents extends PlotListener implements Listener { if (plot.isMerged()) { disable = true; for (UUID owner : plot.getOwners()) { - if (PlotSquared.platform().getPlayerManager().getPlayerIfExists(owner) != null) { + if (PlotSquared.platform().getPlayerManager().getPlayerIfExists(owner) + != null) { disable = false; break; } } } else { - disable = PlotSquared.platform().getPlayerManager().getPlayerIfExists(plot.getOwnerAbs()) - == null; + disable = PlotSquared.platform().getPlayerManager() + .getPlayerIfExists(plot.getOwnerAbs()) == null; } } if (disable) { for (UUID trusted : plot.getTrusted()) { - if (PlotSquared.platform().getPlayerManager().getPlayerIfExists(trusted) != null) { + if (PlotSquared.platform().getPlayerManager().getPlayerIfExists(trusted) + != null) { disable = false; break; } @@ -385,7 +392,8 @@ public class PlayerEvents extends PlotListener implements Listener { } } if (Settings.Redstone.DISABLE_UNOCCUPIED) { - for (final PlotPlayer player : PlotSquared.platform().getPlayerManager().getPlayers()) { + for (final PlotPlayer player : PlotSquared.platform().getPlayerManager() + .getPlayers()) { if (plot.equals(player.getCurrentPlot())) { return; } @@ -490,7 +498,7 @@ public class PlayerEvents extends PlotListener implements Listener { return; } Location location = BukkitUtil.getLocation(entity); - if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorldName())) { + if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) { return; } PlotPlayer pp = BukkitUtil.getPlayer((Player) shooter); @@ -504,7 +512,7 @@ public class PlayerEvents extends PlotListener implements Listener { @EventHandler public boolean onProjectileHit(ProjectileHitEvent event) { Projectile entity = event.getEntity(); Location location = BukkitUtil.getLocation(entity); - if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorldName())) { + if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) { return true; } PlotArea area = location.getPlotArea(); @@ -1078,7 +1086,7 @@ public class PlayerEvents extends PlotListener implements Listener { PlotArea area = location.getPlotArea(); boolean plotArea = location.isPlotArea(); if (!plotArea) { - if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorldName())) { + if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) { return; } return; @@ -1174,7 +1182,7 @@ public class PlayerEvents extends PlotListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onEntityBlockForm(EntityBlockFormEvent event) { String world = event.getBlock().getWorld().getName(); - if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) { + if (!this.plotAreaManager.hasPlotArea(world)) { return; } Location location = BukkitUtil.getLocation(event.getBlock().getLocation()); @@ -1505,7 +1513,7 @@ public class PlayerEvents extends PlotListener implements Listener { Vector relative = new Vector(face.getModX(), face.getModY(), face.getModZ()); PlotArea area = location.getPlotArea(); if (area == null) { - if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorldName())) { + if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) { return; } for (Block block1 : event.getBlocks()) { @@ -1542,7 +1550,7 @@ public class PlayerEvents extends PlotListener implements Listener { Location location = BukkitUtil.getLocation(block.getLocation()); PlotArea area = location.getPlotArea(); if (area == null) { - if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorldName())) { + if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) { return; } if (this.pistonBlocks) { @@ -1635,7 +1643,7 @@ public class PlayerEvents extends PlotListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onStructureGrow(StructureGrowEvent event) { - if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(event.getWorld().getName())) { + if (!this.plotAreaManager.hasPlotArea(event.getWorld().getName())) { return; } List blocks = event.getBlocks(); @@ -1698,7 +1706,7 @@ public class PlayerEvents extends PlotListener implements Listener { return; }*/ HumanEntity entity = event.getWhoClicked(); - if (!(entity instanceof Player) || !PlotSquared.get().getPlotAreaManager() + if (!(entity instanceof Player) || !this.plotAreaManager .hasPlotArea(entity.getWorld().getName())) { return; } @@ -1840,7 +1848,7 @@ public class PlayerEvents extends PlotListener implements Listener { public void onPotionSplash(LingeringPotionSplashEvent event) { Projectile entity = event.getEntity(); Location location = BukkitUtil.getLocation(entity); - if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorldName())) { + if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) { return; } if (!this.onProjectileHit(event)) { @@ -1863,8 +1871,8 @@ public class PlayerEvents extends PlotListener implements Listener { Plot plot = location.getPlotAbs(); BukkitPlayer pp = BukkitUtil.getPlayer(e.getPlayer()); if (plot == null) { - if (!area.isRoadFlags() && !area.getRoadFlag(MiscInteractFlag.class) - && !Permissions.hasPermission(pp, "plots.admin.interact.road")) { + if (!area.isRoadFlags() && !area.getRoadFlag(MiscInteractFlag.class) && !Permissions + .hasPermission(pp, "plots.admin.interact.road")) { MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, "plots.admin.interact.road"); e.setCancelled(true); } @@ -1908,7 +1916,7 @@ public class PlayerEvents extends PlotListener implements Listener { Block block = event.getBlock(); Location location = BukkitUtil.getLocation(block.getLocation()); String world = location.getWorldName(); - if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) { + if (!this.plotAreaManager.hasPlotArea(world)) { return; } PlotArea area = location.getPlotArea(); @@ -2182,7 +2190,7 @@ public class PlayerEvents extends PlotListener implements Listener { Block block = event.getBlock(); World world = block.getWorld(); String worldName = world.getName(); - if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(worldName)) { + if (!this.plotAreaManager.hasPlotArea(worldName)) { return; } Location location = BukkitUtil.getLocation(block.getLocation()); @@ -2600,8 +2608,7 @@ public class PlayerEvents extends PlotListener implements Listener { Captions.PERMISSION_ADMIN_INTERACT_UNOWNED); event.setCancelled(true); } - } else if ((plot != null && !plot.isAdded(pp.getUUID())) || area - .isRoadFlags()) { + } else if ((plot != null && !plot.isAdded(pp.getUUID())) || area.isRoadFlags()) { final Entity entity = event.getRightClicked(); final com.sk89q.worldedit.world.entity.EntityType entityType = BukkitAdapter.adapt(entity.getType()); @@ -2707,7 +2714,7 @@ public class PlayerEvents extends PlotListener implements Listener { public void onPotionSplash(PotionSplashEvent event) { ThrownPotion damager = event.getPotion(); Location location = BukkitUtil.getLocation(damager); - if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorldName())) { + if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) { return; } int count = 0; @@ -2737,7 +2744,7 @@ public class PlayerEvents extends PlotListener implements Listener { public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) { Entity damager = event.getDamager(); Location location = BukkitUtil.getLocation(damager); - if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorldName())) { + if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) { return; } Entity victim = event.getEntity(); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/WorldEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/WorldEvents.java index 59e1fb2ec..157ea9e3a 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/WorldEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/WorldEvents.java @@ -36,17 +36,23 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.world.WorldInitEvent; import org.bukkit.generator.ChunkGenerator; +import org.jetbrains.annotations.NotNull; @SuppressWarnings("unused") public class WorldEvents implements Listener { + private final PlotAreaManager plotAreaManager; + + public WorldEvents(@NotNull final PlotAreaManager plotAreaManager) { + this.plotAreaManager = plotAreaManager; + } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onWorldInit(WorldInitEvent event) { World world = event.getWorld(); String name = world.getName(); - PlotAreaManager manager = PlotSquared.get().getPlotAreaManager(); - if (manager instanceof SinglePlotAreaManager) { - SinglePlotAreaManager single = (SinglePlotAreaManager) manager; + if (this.plotAreaManager instanceof SinglePlotAreaManager) { + final SinglePlotAreaManager single = (SinglePlotAreaManager) this.plotAreaManager; if (single.isWorld(name)) { world.setKeepSpawnInMemory(false); return; @@ -56,7 +62,7 @@ public class WorldEvents implements Listener { if (gen instanceof GeneratorWrapper) { PlotSquared.get().loadWorld(name, (GeneratorWrapper) gen); } else { - PlotSquared.get().loadWorld(name, new BukkitPlotGenerator(name, gen)); + PlotSquared.get().loadWorld(name, new BukkitPlotGenerator(name, gen, this.plotAreaManager)); } } } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java index 9e069adf9..7210778a9 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java @@ -34,6 +34,7 @@ import com.plotsquared.core.events.TeleportCause; import com.plotsquared.core.location.Location; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.PlotWeather; +import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.util.EconHandler; import com.plotsquared.core.util.MathMan; import com.plotsquared.core.util.StringMan; @@ -76,15 +77,16 @@ public class BukkitPlayer extends PlotPlayer { * * @param player Bukkit player instance */ - public BukkitPlayer(@NotNull final Player player) { - this(player, false); + public BukkitPlayer(@NotNull final PlotAreaManager plotAreaManager, @NotNull final Player player) { + this(plotAreaManager, player, false); } - public BukkitPlayer(@NotNull final Player player, final boolean offline) { - this(player, offline, true); + public BukkitPlayer(@NotNull final PlotAreaManager plotAreaManager, @NotNull final Player player, final boolean offline) { + this(plotAreaManager, player, offline, true); } - public BukkitPlayer(@NotNull final Player player, final boolean offline, final boolean realPlayer) { + public BukkitPlayer(@NotNull final PlotAreaManager plotAreaManager, @NotNull final Player player, final boolean offline, final boolean realPlayer) { + super(plotAreaManager); this.player = player; this.offline = offline; if (realPlayer) { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayerManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayerManager.java index a15718a5f..fb023ed8f 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayerManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayerManager.java @@ -25,6 +25,7 @@ */ package com.plotsquared.bukkit.player; +import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.util.PlayerManager; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -38,11 +39,17 @@ import java.util.UUID; */ public class BukkitPlayerManager extends PlayerManager { + private final PlotAreaManager plotAreaManager; + + public BukkitPlayerManager(@NotNull final PlotAreaManager plotAreaManager) { + this.plotAreaManager = plotAreaManager; + } + @NotNull @Override public BukkitPlayer getPlayer(@NotNull final Player object) { try { return getPlayer(object.getUniqueId()); } catch (final NoSuchPlayerException exception) { - return new BukkitPlayer(object, object.isOnline(), false); + return new BukkitPlayer(this.plotAreaManager, object, object.isOnline(), false); } } @@ -51,7 +58,7 @@ public class BukkitPlayerManager extends PlayerManager { if (player == null || !player.isOnline()) { throw new NoSuchPlayerException(uuid); } - return new BukkitPlayer(player); + return new BukkitPlayer(this.plotAreaManager, player); } @Nullable @Override public BukkitOfflinePlayer getOfflinePlayer(@Nullable final UUID uuid) { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java index b79e82250..809a93c72 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java @@ -33,6 +33,7 @@ import com.plotsquared.core.generator.GeneratorWrapper; import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotAreaType; import com.plotsquared.core.plot.SetupObject; +import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.setup.PlotAreaBuilder; import com.plotsquared.core.util.SetupUtils; import io.papermc.lib.PaperLib; @@ -42,6 +43,7 @@ import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.generator.ChunkGenerator; import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; import java.io.IOException; import java.util.HashMap; @@ -50,6 +52,12 @@ import java.util.Objects; public class BukkitSetupUtils extends SetupUtils { + private final PlotAreaManager plotAreaManager; + + public BukkitSetupUtils(@NotNull final PlotAreaManager plotAreaManager) { + this.plotAreaManager = plotAreaManager; + } + @Override public void updateGenerators() { if (!SetupUtils.generators.isEmpty()) { return; @@ -66,7 +74,7 @@ public class BukkitSetupUtils extends SetupUtils { if (generator instanceof GeneratorWrapper) { wrapped = (GeneratorWrapper) generator; } else { - wrapped = new BukkitPlotGenerator(testWorld, generator); + wrapped = new BukkitPlotGenerator(testWorld, generator, this.plotAreaManager); } SetupUtils.generators.put(name, wrapped); } 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 8ace34d92..1c4dd1f45 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java @@ -129,7 +129,7 @@ public class BukkitUtil extends WorldUtil { } final Player player = OfflinePlayerUtil.loadPlayer(op); player.loadData(); - return new BukkitPlayer(player, true); + return new BukkitPlayer(PlotSquared.get().getPlotAreaManager(), player, true); } /** diff --git a/Core/src/main/java/com/plotsquared/core/PlotSquared.java b/Core/src/main/java/com/plotsquared/core/PlotSquared.java index fb77cb6d5..ab9fd2472 100644 --- a/Core/src/main/java/com/plotsquared/core/PlotSquared.java +++ b/Core/src/main/java/com/plotsquared/core/PlotSquared.java @@ -131,7 +131,6 @@ import java.util.zip.ZipInputStream; @SuppressWarnings({"WeakerAccess"}) public class PlotSquared { - private static final Set EMPTY_SET = Collections.unmodifiableSet(Collections.emptySet()); private static PlotSquared instance; // Implementation @@ -285,7 +284,7 @@ public class PlotSquared { PlotSquared.log(Captions.PREFIX.getTranslated() + "&6" + this.platform.getPluginName() + " hooked into WorldEdit."); this.worldedit = WorldEdit.getInstance(); - WorldEdit.getInstance().getEventBus().register(new WESubscriber()); + WorldEdit.getInstance().getEventBus().register(new WESubscriber(this.plotAreaManager)); if (Settings.Enabled_Components.COMMANDS) { new WE_Anywhere(); } @@ -431,7 +430,7 @@ public class PlotSquared { ExpireManager.IMP = new ExpireManager(); ExpireManager.IMP.runAutomatedTask(); for (Settings.Auto_Clear settings : Settings.AUTO_CLEAR.getInstances()) { - ExpiryTask task = new ExpiryTask(settings); + ExpiryTask task = new ExpiryTask(settings, this.plotAreaManager); ExpireManager.IMP.addTask(task); } } 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 9ebfca78b..2c6c1d51f 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Area.java +++ b/Core/src/main/java/com/plotsquared/core/command/Area.java @@ -40,6 +40,7 @@ import com.plotsquared.core.plot.PlotAreaTerrainType; import com.plotsquared.core.plot.PlotAreaType; 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.MainUtil; import com.plotsquared.core.util.MathMan; @@ -65,6 +66,7 @@ import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.Region; +import org.jetbrains.annotations.NotNull; import java.io.File; import java.io.FileOutputStream; @@ -85,6 +87,12 @@ import java.util.Set; confirmation = true) public class Area extends SubCommand { + private final PlotAreaManager plotAreaManager; + + public Area(@NotNull final PlotAreaManager plotAreaManager) { + this.plotAreaManager = plotAreaManager; + } + @Override public boolean onCommand(final PlotPlayer player, String[] args) { if (args.length == 0) { Captions.COMMAND_SYNTAX.send(player, getUsage()); @@ -104,7 +112,7 @@ public class Area extends SubCommand { MainUtil.sendMessage(player, Captions.SINGLE_AREA_NEEDS_NAME); return false; } - final PlotArea existingArea = PlotSquared.get().getPlotAreaManager().getPlotArea(player.getLocation().getWorldName(), args[1]); + final PlotArea existingArea = this.plotAreaManager.getPlotArea(player.getLocation().getWorldName(), args[1]); if (existingArea != null && existingArea.getId().equalsIgnoreCase(args[1])) { MainUtil.sendMessage(player, Captions.SINGLE_AREA_NAME_TAKEN); return false; @@ -126,7 +134,7 @@ public class Area extends SubCommand { MainUtil.sendMessage(player, Captions.SINGLE_AREA_NOT_SQUARE); return false; } - if (PlotSquared.get().getPlotAreaManager().getPlotAreas( + if (this.plotAreaManager.getPlotAreas( Objects.requireNonNull(playerSelectedRegion.getWorld()).getName(), CuboidRegion.makeCuboid(playerSelectedRegion)).length != 0) { MainUtil.sendMessage(player, Captions.SINGLE_AREA_OVERLAPPING); } @@ -276,7 +284,7 @@ public class Area extends SubCommand { final int offsetX = bx - (area.ROAD_WIDTH == 0 ? 0 : lower); final int offsetZ = bz - (area.ROAD_WIDTH == 0 ? 0 : lower); final CuboidRegion region = RegionUtil.createRegion(bx, tx, bz, tz); - final Set areas = PlotSquared.get().getPlotAreaManager() + final Set areas = this.plotAreaManager .getPlotAreasSet(area.getWorldName(), region); if (!areas.isEmpty()) { Captions.CLUSTER_INTERSECTION @@ -342,12 +350,12 @@ public class Area extends SubCommand { builder.worldName(split[0]); final HybridPlotWorld pa = new HybridPlotWorld(builder.worldName(), id, PlotSquared.platform().getDefaultGenerator(), null, null); - PlotArea other = PlotSquared.get().getPlotAreaManager().getPlotArea(pa.getWorldName(), id); + 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()); return false; } - Set areas = PlotSquared.get().getPlotAreaManager().getPlotAreasSet(pa.getWorldName()); + Set areas = this.plotAreaManager.getPlotAreasSet(pa.getWorldName()); if (!areas.isEmpty()) { PlotArea area = areas.iterator().next(); pa.setType(area.getType()); @@ -492,7 +500,7 @@ public class Area extends SubCommand { area = player.getApplicablePlotArea(); break; case 2: - area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(args[1]); + area = this.plotAreaManager.getPlotAreaByString(args[1]); break; default: Captions.COMMAND_SYNTAX.send(player, getCommandString() + " info [area]"); @@ -554,7 +562,7 @@ public class Area extends SubCommand { Captions.COMMAND_SYNTAX.send(player, getCommandString() + " list [#]"); return false; } - final List areas = new ArrayList<>(Arrays.asList(PlotSquared.get().getPlotAreaManager().getAllPlotAreas())); + final List areas = new ArrayList<>(Arrays.asList(this.plotAreaManager.getAllPlotAreas())); paginate(player, areas, 8, page, new RunnableVal3() { @Override public void run(Integer i, PlotArea area, PlotMessage message) { @@ -637,7 +645,7 @@ public class Area extends SubCommand { Captions.COMMAND_SYNTAX.send(player, "/plot visit [area]"); return false; } - PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(args[1]); + PlotArea area = this.plotAreaManager.getPlotAreaByString(args[1]); if (area == null) { Captions.NOT_VALID_PLOT_WORLD.send(player, args[1]); return false; diff --git a/Core/src/main/java/com/plotsquared/core/command/Auto.java b/Core/src/main/java/com/plotsquared/core/command/Auto.java index 4c75de3f8..41f08b187 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Auto.java +++ b/Core/src/main/java/com/plotsquared/core/command/Auto.java @@ -40,6 +40,7 @@ import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotAreaType; import com.plotsquared.core.plot.PlotId; +import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.util.EconHandler; import com.plotsquared.core.util.Expression; import com.plotsquared.core.util.MainUtil; @@ -47,6 +48,7 @@ import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.task.AutoClaimFinishTask; import com.plotsquared.core.util.task.RunnableVal; import com.plotsquared.core.util.task.TaskManager; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; @@ -61,6 +63,12 @@ import java.util.Set; usage = "/plot auto [length,width]") public class Auto extends SubCommand { + private final PlotAreaManager plotAreaManager; + + public Auto(@NotNull final PlotAreaManager plotAreaManager) { + this.plotAreaManager = plotAreaManager; + } + @Deprecated public static PlotId getNextPlotId(PlotId id, int step) { return id.getNextId(step); } @@ -158,7 +166,7 @@ public class Auto extends SubCommand { PlotArea plotarea = player.getApplicablePlotArea(); if (plotarea == null) { if (EconHandler.getEconHandler() != null) { - for (PlotArea area : PlotSquared.get().getPlotAreaManager().getAllPlotAreas()) { + for (PlotArea area : this.plotAreaManager.getAllPlotAreas()) { if (EconHandler.getEconHandler() .hasPermission(area.getWorldName(), player.getName(), "plots.auto")) { if (plotarea != null) { @@ -169,8 +177,8 @@ public class Auto extends SubCommand { } } } - if (PlotSquared.get().getPlotAreaManager().getAllPlotAreas().length == 1) { - plotarea = PlotSquared.get().getPlotAreaManager().getAllPlotAreas()[0]; + if (this.plotAreaManager.getAllPlotAreas().length == 1) { + plotarea = this.plotAreaManager.getAllPlotAreas()[0]; } if (plotarea == null) { MainUtil.sendMessage(player, Captions.NOT_IN_PLOT_WORLD); diff --git a/Core/src/main/java/com/plotsquared/core/command/Condense.java b/Core/src/main/java/com/plotsquared/core/command/Condense.java index d18322888..1f78d9bc5 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Condense.java +++ b/Core/src/main/java/com/plotsquared/core/command/Condense.java @@ -25,15 +25,16 @@ */ package com.plotsquared.core.command; -import com.plotsquared.core.PlotSquared; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotId; +import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.MathMan; import com.plotsquared.core.util.WorldUtil; import com.plotsquared.core.util.task.TaskManager; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Collection; @@ -54,12 +55,18 @@ public class Condense extends SubCommand { public static boolean TASK = false; + private final PlotAreaManager plotAreaManager; + + public Condense(@NotNull final PlotAreaManager plotAreaManager) { + this.plotAreaManager = plotAreaManager; + } + @Override public boolean onCommand(final PlotPlayer player, String[] args) { if (args.length != 2 && args.length != 3) { MainUtil.sendMessage(player, getUsage()); return false; } - PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(args[0]); + PlotArea area = this.plotAreaManager.getPlotAreaByString(args[0]); if (area == null || !WorldUtil.IMP.isWorld(area.getWorldName())) { MainUtil.sendMessage(player, "INVALID AREA"); return false; diff --git a/Core/src/main/java/com/plotsquared/core/command/DatabaseCommand.java b/Core/src/main/java/com/plotsquared/core/command/DatabaseCommand.java index 89f89f4e7..a1f40039f 100644 --- a/Core/src/main/java/com/plotsquared/core/command/DatabaseCommand.java +++ b/Core/src/main/java/com/plotsquared/core/command/DatabaseCommand.java @@ -35,10 +35,12 @@ import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotId; +import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.plot.world.SinglePlotArea; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.query.PlotQuery; import com.plotsquared.core.util.task.TaskManager; +import org.jetbrains.annotations.NotNull; import java.io.File; import java.sql.SQLException; @@ -57,6 +59,12 @@ import java.util.Map.Entry; usage = "/plot database [area] ") public class DatabaseCommand extends SubCommand { + private final PlotAreaManager plotAreaManager; + + public DatabaseCommand(@NotNull final PlotAreaManager plotAreaManager) { + this.plotAreaManager = plotAreaManager; + } + public static void insertPlots(final SQLManager manager, final List plots, final PlotPlayer player) { TaskManager.runTaskAsync(() -> { @@ -81,7 +89,7 @@ public class DatabaseCommand extends SubCommand { return false; } List plots; - PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(args[0]); + PlotArea area = this.plotAreaManager.getPlotAreaByString(args[0]); if (area != null) { plots = PlotSquared.get().sortPlotsByTemp(area.getPlots()); args = Arrays.copyOfRange(args, 1, args.length); @@ -117,7 +125,7 @@ public class DatabaseCommand extends SubCommand { plots = new ArrayList<>(); for (Entry> entry : map.entrySet()) { String areaName = entry.getKey(); - PlotArea pa = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(areaName); + PlotArea pa = this.plotAreaManager.getPlotAreaByString(areaName); if (pa != null) { for (Entry entry2 : entry.getValue().entrySet()) { Plot plot = entry2.getValue(); diff --git a/Core/src/main/java/com/plotsquared/core/command/Debug.java b/Core/src/main/java/com/plotsquared/core/command/Debug.java index c35ae415d..3b912231d 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Debug.java +++ b/Core/src/main/java/com/plotsquared/core/command/Debug.java @@ -28,6 +28,7 @@ package com.plotsquared.core.command; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.player.PlotPlayer; +import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.RegionManager; import com.plotsquared.core.util.StringMan; @@ -37,6 +38,7 @@ import com.plotsquared.core.util.query.PlotQuery; import com.plotsquared.core.util.task.TaskManager; import com.plotsquared.core.uuid.UUIDMapping; import com.sk89q.worldedit.world.entity.EntityType; +import org.jetbrains.annotations.NotNull; import java.util.Collection; import java.util.Comparator; @@ -49,6 +51,12 @@ import java.util.Map; permission = "plots.admin") public class Debug extends SubCommand { + private final PlotAreaManager plotAreaManager; + + public Debug(@NotNull final PlotAreaManager plotAreaManager) { + this.plotAreaManager = plotAreaManager; + } + @Override public boolean onCommand(PlotPlayer player, String[] args) { if (args.length > 0) { if ("player".equalsIgnoreCase(args[0])) { @@ -119,7 +127,7 @@ public class Debug extends SubCommand { information.append(header); information.append(getSection(section, "PlotArea")); information.append( - getLine(line, "Plot Worlds", StringMan.join(PlotSquared.get().getPlotAreaManager().getAllPlotAreas(), ", "))); + getLine(line, "Plot Worlds", StringMan.join(this.plotAreaManager.getAllPlotAreas(), ", "))); information.append(getLine(line, "Owned Plots", PlotQuery.newQuery().allPlots().count())); information.append(getSection(section, "Messages")); information.append(getLine(line, "Total Messages", Captions.values().length)); diff --git a/Core/src/main/java/com/plotsquared/core/command/DebugExec.java b/Core/src/main/java/com/plotsquared/core/command/DebugExec.java index 1f4967734..481699a3c 100644 --- a/Core/src/main/java/com/plotsquared/core/command/DebugExec.java +++ b/Core/src/main/java/com/plotsquared/core/command/DebugExec.java @@ -44,6 +44,7 @@ import com.plotsquared.core.plot.expiration.PlotAnalysis; import com.plotsquared.core.plot.flag.GlobalFlagContainer; import com.plotsquared.core.plot.flag.PlotFlag; import com.plotsquared.core.plot.message.PlotMessage; +import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.queue.GlobalBlockQueue; import com.plotsquared.core.util.ChunkManager; import com.plotsquared.core.util.EconHandler; @@ -59,6 +60,7 @@ import com.plotsquared.core.util.task.RunnableVal2; import com.plotsquared.core.util.task.RunnableVal3; import com.plotsquared.core.util.task.TaskManager; import com.sk89q.worldedit.world.block.BlockState; +import org.jetbrains.annotations.NotNull; import javax.script.Bindings; import javax.script.ScriptContext; @@ -81,10 +83,13 @@ import java.util.concurrent.CompletableFuture; aliases = {"exec", "$"}, category = CommandCategory.DEBUG) public class DebugExec extends SubCommand { + + private final PlotAreaManager plotAreaManager; private ScriptEngine engine; private Bindings scope; - public DebugExec() { + public DebugExec(@NotNull final PlotAreaManager plotAreaManager) { + this.plotAreaManager = plotAreaManager; init(); /* try { @@ -259,7 +264,7 @@ public class DebugExec extends SubCommand { "&cInvalid syntax: /plot debugexec start-rgar "); return false; } - PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(args[1]); + PlotArea area = this.plotAreaManager.getPlotAreaByString(args[1]); if (area == null) { MainUtil.sendMessage(player, Captions.NOT_VALID_PLOT_WORLD, args[1]); return false; diff --git a/Core/src/main/java/com/plotsquared/core/command/DebugImportWorlds.java b/Core/src/main/java/com/plotsquared/core/command/DebugImportWorlds.java index 832a8d5ea..1a24a97c9 100644 --- a/Core/src/main/java/com/plotsquared/core/command/DebugImportWorlds.java +++ b/Core/src/main/java/com/plotsquared/core/command/DebugImportWorlds.java @@ -36,6 +36,7 @@ import com.plotsquared.core.plot.world.SinglePlotAreaManager; import com.plotsquared.core.util.WorldUtil; import com.plotsquared.core.util.task.RunnableVal2; import com.plotsquared.core.util.task.RunnableVal3; +import org.jetbrains.annotations.NotNull; import java.io.File; import java.util.UUID; @@ -47,8 +48,12 @@ import java.util.concurrent.CompletableFuture; requiredType = RequiredType.CONSOLE, category = CommandCategory.TELEPORT) public class DebugImportWorlds extends Command { - public DebugImportWorlds() { + + private final PlotAreaManager plotAreaManager; + + public DebugImportWorlds(@NotNull final PlotAreaManager plotAreaManager) { super(MainCommand.getInstance(), true); + this.plotAreaManager = plotAreaManager; } @Override @@ -56,12 +61,11 @@ public class DebugImportWorlds extends Command { RunnableVal3 confirm, RunnableVal2 whenDone) throws CommandException { // UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8)) - PlotAreaManager pam = PlotSquared.get().getPlotAreaManager(); - if (!(pam instanceof SinglePlotAreaManager)) { + if (!(this.plotAreaManager instanceof SinglePlotAreaManager)) { player.sendMessage("Must be a single plot area!"); return CompletableFuture.completedFuture(false); } - SinglePlotArea area = ((SinglePlotAreaManager) pam).getArea(); + SinglePlotArea area = ((SinglePlotAreaManager) this.plotAreaManager).getArea(); PlotId id = new PlotId(0, 0); File container = PlotSquared.platform().getWorldContainer(); if (container.equals(new File("."))) { 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 25a0c7b4b..3e92def05 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Deny.java +++ b/Core/src/main/java/com/plotsquared/core/command/Deny.java @@ -31,11 +31,13 @@ import com.plotsquared.core.database.DBFunc; import com.plotsquared.core.location.Location; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; +import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.TabCompletions; import com.plotsquared.core.util.WorldUtil; import com.sk89q.worldedit.world.gamemode.GameModes; +import org.jetbrains.annotations.NotNull; import java.util.Collection; import java.util.Collections; @@ -50,8 +52,11 @@ import java.util.concurrent.TimeoutException; requiredType = RequiredType.PLAYER) public class Deny extends SubCommand { - public Deny() { + private final PlotAreaManager plotAreaManager; + + public Deny(@NotNull final PlotAreaManager plotAreaManager) { super(Argument.PlayerName); + this.plotAreaManager = plotAreaManager; } @Override public boolean onCommand(PlotPlayer player, String[] args) { @@ -136,8 +141,7 @@ public class Deny extends SubCommand { Location spawn = WorldUtil.IMP.getSpawn(location.getWorldName()); MainUtil.sendMessage(player, Captions.YOU_GOT_DENIED); if (plot.equals(spawn.getPlot())) { - Location newSpawn = - WorldUtil.IMP.getSpawn(PlotSquared.get().getPlotAreaManager().getAllWorlds()[0]); + Location newSpawn = WorldUtil.IMP.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/Download.java b/Core/src/main/java/com/plotsquared/core/command/Download.java index 57e3d07c0..9245b3b85 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Download.java +++ b/Core/src/main/java/com/plotsquared/core/command/Download.java @@ -25,12 +25,12 @@ */ package com.plotsquared.core.command; -import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.flag.implementations.DoneFlag; +import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.SchematicHandler; @@ -38,6 +38,7 @@ import com.plotsquared.core.util.StringMan; import com.plotsquared.core.util.WorldUtil; import com.plotsquared.core.util.task.RunnableVal; import com.sk89q.jnbt.CompoundTag; +import org.jetbrains.annotations.NotNull; import java.net.URL; @@ -50,9 +51,15 @@ import java.net.URL; permission = "plots.download") public class Download extends SubCommand { + private final PlotAreaManager plotAreaManager; + + public Download(@NotNull final PlotAreaManager plotAreaManager) { + this.plotAreaManager = plotAreaManager; + } + @Override public boolean onCommand(final PlotPlayer player, String[] args) { String world = player.getLocation().getWorldName(); - if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) { + if (!this.plotAreaManager.hasPlotArea(world)) { return !sendMessage(player, Captions.NOT_IN_PLOT_WORLD); } final Plot plot = player.getCurrentPlot(); diff --git a/Core/src/main/java/com/plotsquared/core/command/HomeCommand.java b/Core/src/main/java/com/plotsquared/core/command/HomeCommand.java index 08b150ec2..7f58a5730 100644 --- a/Core/src/main/java/com/plotsquared/core/command/HomeCommand.java +++ b/Core/src/main/java/com/plotsquared/core/command/HomeCommand.java @@ -25,13 +25,13 @@ */ package com.plotsquared.core.command; -import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.events.TeleportCause; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotId; +import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.MathMan; import com.plotsquared.core.util.Permissions; @@ -55,8 +55,12 @@ import java.util.concurrent.CompletableFuture; requiredType = RequiredType.PLAYER, category = CommandCategory.TELEPORT) public class HomeCommand extends Command { - public HomeCommand() { + + private final PlotAreaManager plotAreaManager; + + public HomeCommand(@NotNull final PlotAreaManager plotAreaManager) { super(MainCommand.getInstance(), true); + this.plotAreaManager = plotAreaManager; } private void home(@NotNull final PlotPlayer player, @@ -132,7 +136,7 @@ public class HomeCommand extends Command { break; case 2: // we assume args[0] is a plot area and args[1] an identifier - PlotArea plotArea = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(args[0]); + final PlotArea plotArea = this.plotAreaManager.getPlotAreaByString(args[0]); identifier = args[1]; if (plotArea == null) { // invalid command, therefore no plots 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 2c7c9a9e3..076eb93dd 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Kick.java +++ b/Core/src/main/java/com/plotsquared/core/command/Kick.java @@ -31,10 +31,12 @@ import com.plotsquared.core.database.DBFunc; import com.plotsquared.core.location.Location; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; +import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.TabCompletions; import com.plotsquared.core.util.WorldUtil; +import org.jetbrains.annotations.NotNull; import java.util.Collection; import java.util.Collections; @@ -52,8 +54,11 @@ import java.util.concurrent.TimeoutException; requiredType = RequiredType.PLAYER) public class Kick extends SubCommand { - public Kick() { + private final PlotAreaManager plotAreaManager; + + public Kick(@NotNull final PlotAreaManager plotAreaManager) { super(Argument.PlayerName); + this.plotAreaManager = plotAreaManager; } @Override public boolean onCommand(PlotPlayer player, String[] args) { @@ -108,8 +113,7 @@ public class Kick extends SubCommand { Location spawn = WorldUtil.IMP.getSpawn(location.getWorldName()); Captions.YOU_GOT_KICKED.send(player2); if (plot.equals(spawn.getPlot())) { - Location newSpawn = WorldUtil.IMP - .getSpawn(PlotSquared.get().getPlotAreaManager().getAllWorlds()[0]); + Location newSpawn = WorldUtil.IMP.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 0687d2160..0b9cb6d16 100644 --- a/Core/src/main/java/com/plotsquared/core/command/ListCmd.java +++ b/Core/src/main/java/com/plotsquared/core/command/ListCmd.java @@ -36,6 +36,7 @@ import com.plotsquared.core.plot.expiration.ExpireManager; import com.plotsquared.core.plot.flag.implementations.DoneFlag; import com.plotsquared.core.plot.flag.implementations.PriceFlag; import com.plotsquared.core.plot.message.PlotMessage; +import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.util.EconHandler; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.MathMan; @@ -47,6 +48,7 @@ import com.plotsquared.core.util.query.PlotQuery; 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 java.util.ArrayList; import java.util.Arrays; @@ -69,6 +71,12 @@ import java.util.stream.Collectors; usage = "/plot list > [#]") public class ListCmd extends SubCommand { + private final PlotAreaManager plotAreaManager; + + public ListCmd(@NotNull final PlotAreaManager plotAreaManager) { + this.plotAreaManager = plotAreaManager; + } + private String[] getArgumentList(PlotPlayer player) { List args = new ArrayList<>(); if (EconHandler.getEconHandler() != null && Permissions @@ -297,7 +305,7 @@ public class ListCmd extends SubCommand { plotConsumer.accept(PlotQuery.newQuery().plotsBySearch(term)); break; default: - if (PlotSquared.get().getPlotAreaManager().hasPlotArea(args[0])) { + if (this.plotAreaManager.hasPlotArea(args[0])) { if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_WORLD)) { MainUtil.sendMessage(player, Captions.NO_PERMISSION, Captions.PERMISSION_LIST_WORLD); 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 59388d657..60aebfa60 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Load.java +++ b/Core/src/main/java/com/plotsquared/core/command/Load.java @@ -25,7 +25,6 @@ */ package com.plotsquared.core.command; -import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.player.PlotPlayer; @@ -33,11 +32,13 @@ import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotId; import com.plotsquared.core.plot.schematic.Schematic; +import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.SchematicHandler; import com.plotsquared.core.util.task.RunnableVal; import com.plotsquared.core.util.task.TaskManager; +import org.jetbrains.annotations.NotNull; import java.net.MalformedURLException; import java.net.URL; @@ -52,9 +53,15 @@ import java.util.List; usage = "/plot load") public class Load extends SubCommand { - @Override public boolean onCommand(final PlotPlayer player, String[] args) { - String world = player.getLocation().getWorldName(); - if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) { + private final PlotAreaManager plotAreaManager; + + public Load(@NotNull final PlotAreaManager plotAreaManager) { + this.plotAreaManager = plotAreaManager; + } + + @Override public boolean onCommand(final PlotPlayer player, final String[] args) { + final String world = player.getLocation().getWorldName(); + if (!this.plotAreaManager.hasPlotArea(world)) { return !sendMessage(player, Captions.NOT_IN_PLOT_WORLD); } final Plot plot = player.getCurrentPlot(); 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 0df008815..811d0d37d 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.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.location.Location; @@ -32,6 +33,7 @@ import com.plotsquared.core.player.ConsolePlayer; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; +import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.util.EconHandler; import com.plotsquared.core.util.Expression; import com.plotsquared.core.util.Permissions; @@ -60,61 +62,62 @@ public class MainCommand extends Command { public static MainCommand getInstance() { if (instance == null) { instance = new MainCommand(); + final PlotAreaManager plotAreaManager = PlotSquared.get().getPlotAreaManager(); new Caps(); new Buy(); - new Save(); - new Load(); + new Save(plotAreaManager); + new Load(plotAreaManager); new Confirm(); - new Template(); - new Download(); - new Template(); + new Template(plotAreaManager); + new Download(plotAreaManager); + new Template(plotAreaManager); new Setup(); - new Area(); + new Area(plotAreaManager); new DebugSaveTest(); new DebugLoadTest(); new CreateRoadSchematic(); new DebugAllowUnsafe(); - new RegenAllRoads(); + new RegenAllRoads(plotAreaManager); new Claim(); - new Auto(); - new HomeCommand(); - new Visit(); + new Auto(plotAreaManager); + new HomeCommand(plotAreaManager); + new Visit(plotAreaManager); new Set(); new Clear(); new Delete(); new Trust(); new Add(); new Leave(); - new Deny(); + new Deny(plotAreaManager); new Remove(); new Info(); new Near(); - new ListCmd(); - new Debug(); - new SchematicCmd(); + new ListCmd(plotAreaManager); + new Debug(plotAreaManager); + new SchematicCmd(plotAreaManager); new PluginCmd(); - new Purge(); - new Reload(); + new Purge(plotAreaManager); + new Reload(plotAreaManager); new Relight(); new Merge(); new DebugPaste(); new Unlink(); - new Kick(); + new Kick(plotAreaManager); new Inbox(); new Comment(); - new DatabaseCommand(); + new DatabaseCommand(plotAreaManager); new Swap(); new Music(); new DebugRoadRegen(); new Trust(); - new DebugExec(); + new DebugExec(plotAreaManager); new FlagCommand(); new Target(); - new Move(); - new Condense(); + new Move(plotAreaManager); + new Condense(plotAreaManager); new Copy(); new Chat(); - new Trim(); + new Trim(plotAreaManager); new Done(); new Continue(); new Middle(); @@ -126,7 +129,7 @@ public class MainCommand extends Command { new Alias(); new SetHome(); new Cluster(); - new DebugImportWorlds(); + new DebugImportWorlds(plotAreaManager); new Backup(); if (Settings.Ratings.USE_LIKES) { @@ -143,7 +146,7 @@ public class MainCommand extends Command { return instance; } - public static boolean onCommand(final PlotPlayer player, String... args) { + public static boolean onCommand(final PlotPlayer player, String... args) { if (args.length >= 1 && args[0].contains(":")) { String[] split2 = args[0].split(":"); if (split2.length == 2) { diff --git a/Core/src/main/java/com/plotsquared/core/command/Move.java b/Core/src/main/java/com/plotsquared/core/command/Move.java index f6debe194..aa5cc7afa 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Move.java +++ b/Core/src/main/java/com/plotsquared/core/command/Move.java @@ -25,16 +25,17 @@ */ package com.plotsquared.core.command; -import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.location.Location; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; +import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.task.RunnableVal2; import com.plotsquared.core.util.task.RunnableVal3; +import org.jetbrains.annotations.NotNull; import java.util.concurrent.CompletableFuture; @@ -46,6 +47,12 @@ import java.util.concurrent.CompletableFuture; requiredType = RequiredType.PLAYER) public class Move extends SubCommand { + private final PlotAreaManager plotAreaManager; + + public Move(@NotNull final PlotAreaManager plotAreaManager) { + this.plotAreaManager = plotAreaManager; + } + @Override public CompletableFuture execute(PlotPlayer player, String[] args, RunnableVal3 confirm, @@ -70,7 +77,7 @@ public class Move extends SubCommand { Captions.COMMAND_SYNTAX.send(player, getUsage()); return CompletableFuture.completedFuture(false); } - PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(args[0]); + PlotArea area = this.plotAreaManager.getPlotAreaByString(args[0]); Plot plot2; if (area == null) { plot2 = MainUtil.getPlotFromString(player, args[0], true); diff --git a/Core/src/main/java/com/plotsquared/core/command/Purge.java b/Core/src/main/java/com/plotsquared/core/command/Purge.java index 764825ca7..7dc8c55bc 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Purge.java +++ b/Core/src/main/java/com/plotsquared/core/command/Purge.java @@ -34,8 +34,10 @@ import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotId; +import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.util.StringMan; import com.plotsquared.core.util.task.TaskManager; +import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.HashSet; @@ -53,6 +55,12 @@ import java.util.concurrent.atomic.AtomicBoolean; confirmation = true) public class Purge extends SubCommand { + private final PlotAreaManager plotAreaManager; + + public Purge(@NotNull final PlotAreaManager plotAreaManager) { + this.plotAreaManager = plotAreaManager; + } + @Override public boolean onCommand(final PlotPlayer player, String[] args) { if (args.length == 0) { Captions.COMMAND_SYNTAX.send(player, getUsage()); @@ -78,7 +86,7 @@ public class Purge extends SubCommand { break; case "area": case "a": - area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(split[1]); + area = this.plotAreaManager.getPlotAreaByString(split[1]); if (area == null) { Captions.NOT_VALID_PLOT_WORLD.send(player, split[1]); return false; 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 5f87a131a..c89c46bed 100644 --- a/Core/src/main/java/com/plotsquared/core/command/RegenAllRoads.java +++ b/Core/src/main/java/com/plotsquared/core/command/RegenAllRoads.java @@ -25,14 +25,15 @@ */ package com.plotsquared.core.command; -import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.generator.HybridPlotManager; import com.plotsquared.core.generator.HybridUtils; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotManager; +import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.util.MainUtil; +import org.jetbrains.annotations.NotNull; @CommandDeclaration(command = "regenallroads", description = "Regenerate all roads in the map using the set road schematic", @@ -43,6 +44,12 @@ import com.plotsquared.core.util.MainUtil; permission = "plots.regenallroads") public class RegenAllRoads extends SubCommand { + private final PlotAreaManager plotAreaManager; + + public RegenAllRoads(@NotNull final PlotAreaManager plotAreaManager) { + this.plotAreaManager = plotAreaManager; + } + @Override public boolean onCommand(PlotPlayer player, String[] args) { int height = 0; if (args.length == 2) { @@ -59,7 +66,7 @@ public class RegenAllRoads extends SubCommand { "/plot regenallroads [height]"); return false; } - PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(args[0]); + PlotArea area = this.plotAreaManager.getPlotAreaByString(args[0]); if (area == null) { Captions.NOT_VALID_PLOT_WORLD.send(player, args[0]); return false; diff --git a/Core/src/main/java/com/plotsquared/core/command/Reload.java b/Core/src/main/java/com/plotsquared/core/command/Reload.java index de126cdd5..05067c837 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Reload.java +++ b/Core/src/main/java/com/plotsquared/core/command/Reload.java @@ -32,7 +32,9 @@ import com.plotsquared.core.configuration.MemorySection; import com.plotsquared.core.configuration.file.YamlConfiguration; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.PlotAreaType; +import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.util.MainUtil; +import org.jetbrains.annotations.NotNull; import java.io.IOException; import java.util.Objects; @@ -45,13 +47,19 @@ import java.util.Objects; category = CommandCategory.ADMINISTRATION) public class Reload extends SubCommand { + private final PlotAreaManager plotAreaManager; + + public Reload(@NotNull final PlotAreaManager plotAreaManager) { + this.plotAreaManager = plotAreaManager; + } + @Override public boolean onCommand(PlotPlayer player, String[] args) { try { // The following won't affect world generation, as that has to be // loaded during startup unfortunately. PlotSquared.get().setupConfigs(); Captions.load(PlotSquared.get().translationFile); - PlotSquared.get().getPlotAreaManager().forEachPlotArea(area -> { + this.plotAreaManager.forEachPlotArea(area -> { ConfigurationSection worldSection = PlotSquared.get().worlds .getConfigurationSection("worlds." + area.getWorldName()); if (worldSection == null) { diff --git a/Core/src/main/java/com/plotsquared/core/command/Save.java b/Core/src/main/java/com/plotsquared/core/command/Save.java index 86cc68487..483a29ce6 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Save.java +++ b/Core/src/main/java/com/plotsquared/core/command/Save.java @@ -25,18 +25,19 @@ */ package com.plotsquared.core.command; -import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.location.Location; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotId; +import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.SchematicHandler; import com.plotsquared.core.util.task.RunnableVal; import com.plotsquared.core.util.task.TaskManager; import com.sk89q.jnbt.CompoundTag; +import org.jetbrains.annotations.NotNull; import java.net.URL; import java.util.List; @@ -49,9 +50,15 @@ import java.util.UUID; permission = "plots.save") public class Save extends SubCommand { - @Override public boolean onCommand(final PlotPlayer player, String[] args) { - String world = player.getLocation().getWorldName(); - if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) { + private final PlotAreaManager plotAreaManager; + + public Save(@NotNull final PlotAreaManager plotAreaManager) { + this.plotAreaManager = plotAreaManager; + } + + @Override public boolean onCommand(final PlotPlayer player, final String[] args) { + final String world = player.getLocation().getWorldName(); + if (!this.plotAreaManager.hasPlotArea(world)) { return !sendMessage(player, Captions.NOT_IN_PLOT_WORLD); } final Plot plot = player.getCurrentPlot(); 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 f6c971911..ffcbf0b74 100644 --- a/Core/src/main/java/com/plotsquared/core/command/SchematicCmd.java +++ b/Core/src/main/java/com/plotsquared/core/command/SchematicCmd.java @@ -26,7 +26,6 @@ package com.plotsquared.core.command; import com.google.common.collect.Lists; -import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.location.Location; @@ -35,12 +34,14 @@ import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.schematic.Schematic; +import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.SchematicHandler; import com.plotsquared.core.util.StringMan; import com.plotsquared.core.util.task.RunnableVal; import com.plotsquared.core.util.task.TaskManager; +import org.jetbrains.annotations.NotNull; import java.net.URL; import java.util.ArrayList; @@ -55,8 +56,13 @@ import java.util.UUID; usage = "/plot schematic ") public class SchematicCmd extends SubCommand { + private final PlotAreaManager plotAreaManager; private boolean running = false; + public SchematicCmd(@NotNull final PlotAreaManager plotAreaManager) { + this.plotAreaManager = plotAreaManager; + } + @Override public boolean onCommand(final PlotPlayer player, String[] args) { if (args.length < 1) { sendMessage(player, Captions.SCHEMATIC_MISSING_ARG); @@ -150,7 +156,7 @@ public class SchematicCmd extends SubCommand { MainUtil.sendMessage(player, Captions.SCHEMATIC_EXPORTALL_WORLD_ARGS); return false; } - PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(args[1]); + PlotArea area = this.plotAreaManager.getPlotAreaByString(args[1]); if (area == null) { Captions.NOT_VALID_PLOT_WORLD.send(player, args[1]); return false; 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 8234e7226..311927565 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Template.java +++ b/Core/src/main/java/com/plotsquared/core/command/Template.java @@ -36,6 +36,7 @@ import com.plotsquared.core.events.TeleportCause; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotManager; +import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.queue.GlobalBlockQueue; import com.plotsquared.core.setup.PlotAreaBuilder; import com.plotsquared.core.setup.SettingsNodesWrapper; @@ -44,6 +45,7 @@ import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.SetupUtils; import com.plotsquared.core.util.WorldUtil; import com.plotsquared.core.util.task.TaskManager; +import org.jetbrains.annotations.NotNull; import java.io.File; import java.io.FileInputStream; @@ -61,6 +63,12 @@ import java.util.zip.ZipOutputStream; category = CommandCategory.ADMINISTRATION) public class Template extends SubCommand { + private final PlotAreaManager plotAreaManager; + + public Template(@NotNull final PlotAreaManager plotAreaManager) { + this.plotAreaManager = plotAreaManager; + } + public static boolean extractAllFiles(String world, String template) { try { File folder = @@ -159,7 +167,7 @@ public class Template extends SubCommand { "/plot template import