From 9fefe57c90c0a77d6b19ba9547537f761984a58c Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Fri, 17 Jul 2020 15:41:06 +0100 Subject: [PATCH] Switch to using QueueCoordinators everywhere --- .../plotsquared/bukkit/BukkitPlatform.java | 99 +++++++----- .../bukkit/generator/BlockStatePopulator.java | 10 +- .../bukkit/generator/BukkitPlotGenerator.java | 4 +- .../generator/DelegatePlotGenerator.java | 9 +- .../bukkit/inject/BukkitModule.java | 20 ++- .../bukkit/queue/BukkitQueueCoordinator.java | 142 +++++++++--------- .../plotsquared/bukkit/queue/GenChunk.java | 17 ++- .../schematic/BukkitSchematicHandler.java | 6 +- .../bukkit/util/BukkitChunkManager.java | 11 +- .../bukkit/util/BukkitRegionManager.java | 65 ++++---- .../com/plotsquared/core/command/Relight.java | 9 +- .../com/plotsquared/core/command/Trim.java | 4 +- .../core/generator/AugmentedUtils.java | 29 ++-- .../core/generator/ClassicPlotManager.java | 22 +-- .../plotsquared/core/generator/HybridGen.java | 6 +- .../core/generator/HybridPlotManager.java | 38 ++--- .../core/generator/HybridUtils.java | 16 +- .../generator/IndependentPlotGenerator.java | 12 +- .../core/generator/SingleWorldGenerator.java | 4 +- .../java/com/plotsquared/core/plot/Plot.java | 114 +++++++------- .../com/plotsquared/core/plot/PlotArea.java | 5 +- .../AreaBoundDelegateQueueCoordinator.java | 7 + .../core/queue/BasicQueueCoordinator.java | 11 +- .../core/queue/ChunkQueueCoordinator.java | 34 +++-- .../core/queue/DelegateQueueCoordinator.java | 8 + .../core/queue/GlobalBlockQueue.java | 11 ++ ...ocationOffsetDelegateQueueCoordinator.java | 13 +- .../core/queue/OffsetQueueCoordinator.java | 8 +- .../core/queue/QueueCoordinator.java | 13 +- .../core/queue/ScopedQueueCoordinator.java | 13 +- .../plotsquared/core/util/ChunkManager.java | 32 ++-- .../plotsquared/core/util/RegionManager.java | 23 ++- .../core/util/SchematicHandler.java | 25 +-- 33 files changed, 485 insertions(+), 355 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java index e40b6698e..60a49bc27 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java @@ -90,7 +90,6 @@ import com.plotsquared.core.plot.message.PlainChatManager; import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.plot.world.SinglePlotArea; import com.plotsquared.core.plot.world.SinglePlotAreaManager; -import com.plotsquared.core.queue.GlobalBlockQueue; import com.plotsquared.core.setup.PlotAreaBuilder; import com.plotsquared.core.setup.SettingsNodesWrapper; import com.plotsquared.core.util.ChatManager; @@ -156,9 +155,11 @@ import static com.plotsquared.core.util.PremiumVerification.getResourceID; import static com.plotsquared.core.util.PremiumVerification.getUserID; import static com.plotsquared.core.util.ReflectionUtils.getRefClass; -@SuppressWarnings("unused") public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPlatform { +@SuppressWarnings("unused") +public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPlatform { - private static final Logger logger = LoggerFactory.getLogger("P2/" + BukkitPlatform.class.getSimpleName()); + private static final Logger logger = + LoggerFactory.getLogger("P2/" + BukkitPlatform.class.getSimpleName()); private static final int BSTATS_ID = 1404; static { @@ -233,8 +234,9 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass; // We create the injector after PlotSquared has been initialized, so that we have access // to generated instances and settings - this.injector = Guice.createInjector(Stage.PRODUCTION, new WorldManagerModule(), new PlotSquaredModule(), - new BukkitModule(this), new BackupModule()); + this.injector = Guice + .createInjector(Stage.PRODUCTION, new WorldManagerModule(), new PlotSquaredModule(), + new BukkitModule(this), new BackupModule()); this.injector.injectMembers(this); if (PremiumVerification.isPremium() && Settings.Enabled_Components.UPDATE_NOTIFICATIONS) { @@ -288,34 +290,37 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass; if (Settings.Enabled_Components.WORLDEDIT_RESTRICTIONS) { try { logger.info("[P2] {} hooked into WorldEdit", this.getPluginName()); - WorldEdit.getInstance().getEventBus().register(this.getInjector().getInstance(WESubscriber.class)); + WorldEdit.getInstance().getEventBus() + .register(this.getInjector().getInstance(WESubscriber.class)); if (Settings.Enabled_Components.COMMANDS) { new WE_Anywhere(); } } catch (Throwable e) { - logger.error("[P2] Incompatible version of WorldEdit, please upgrade: http://builds.enginehub.org/job/worldedit?branch=master"); + logger.error( + "[P2] Incompatible version of WorldEdit, please upgrade: http://builds.enginehub.org/job/worldedit?branch=master"); } } if (Settings.Enabled_Components.EVENTS) { - getServer().getPluginManager().registerEvents(getInjector().getInstance(PlayerEvents.class), this); - getServer().getPluginManager().registerEvents(getInjector().getInstance(EntitySpawnListener.class), this); + getServer().getPluginManager() + .registerEvents(getInjector().getInstance(PlayerEvents.class), this); + getServer().getPluginManager() + .registerEvents(getInjector().getInstance(EntitySpawnListener.class), this); if (PaperLib.isPaper() && Settings.Paper_Components.PAPER_LISTENERS) { - getServer().getPluginManager().registerEvents(getInjector().getInstance(PaperListener.class), this); + getServer().getPluginManager() + .registerEvents(getInjector().getInstance(PaperListener.class), this); } this.plotListener.startRunnable(); } // Required - getServer().getPluginManager().registerEvents(getInjector().getInstance(WorldEvents.class), this); + getServer().getPluginManager() + .registerEvents(getInjector().getInstance(WorldEvents.class), this); if (Settings.Enabled_Components.CHUNK_PROCESSOR) { - getServer().getPluginManager().registerEvents(getInjector().getInstance(ChunkListener.class), this); + getServer().getPluginManager() + .registerEvents(getInjector().getInstance(ChunkListener.class), this); } - // Start the global block queue - final GlobalBlockQueue globalBlockQueue = this.injector.getInstance(GlobalBlockQueue.class); - globalBlockQueue.runTask(); - // Commands if (Settings.Enabled_Components.COMMANDS) { this.registerCommands(); @@ -344,7 +349,8 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass; } // World generators: - final ConfigurationSection section = this.worldConfiguration.getConfigurationSection("worlds"); + final ConfigurationSection section = + this.worldConfiguration.getConfigurationSection("worlds"); final WorldUtil worldUtil = getInjector().getInstance(WorldUtil.class); if (section != null) { @@ -362,11 +368,15 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass; continue; } if (!worldUtil.isWorld(world) && !world.equals("*")) { - logger.warn("[P2] `{}` was not properly loaded - {} will now try to load it properly", + logger.warn( + "[P2] `{}` was not properly loaded - {} will now try to load it properly", world, this.getPluginName()); - logger.warn("[P2] - Are you trying to delete this world? Remember to remove it from the worlds.yml, bukkit.yml and multiverse worlds.yml"); - logger.warn("[P2] - Your world management plugin may be faulty (or non existent)"); - logger.warn("[P2] This message may also be a false positive and could be ignored."); + logger.warn( + "[P2] - Are you trying to delete this world? Remember to remove it from the worlds.yml, bukkit.yml and multiverse worlds.yml"); + logger.warn( + "[P2] - Your world management plugin may be faulty (or non existent)"); + logger.warn( + "[P2] This message may also be a false positive and could be ignored."); this.setGenerator(world); } } @@ -374,7 +384,8 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass; } // Services are accessed in order - final CacheUUIDService cacheUUIDService = new CacheUUIDService(Settings.UUID.UUID_CACHE_SIZE); + final CacheUUIDService cacheUUIDService = + new CacheUUIDService(Settings.UUID.UUID_CACHE_SIZE); this.impromptuPipeline.registerService(cacheUUIDService); this.backgroundPipeline.registerService(cacheUUIDService); this.impromptuPipeline.registerConsumer(cacheUUIDService); @@ -390,7 +401,8 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass; } if (Settings.UUID.SERVICE_BUKKIT) { - final OfflinePlayerUUIDService offlinePlayerUUIDService = new OfflinePlayerUUIDService(); + final OfflinePlayerUUIDService offlinePlayerUUIDService = + new OfflinePlayerUUIDService(); this.impromptuPipeline.registerService(offlinePlayerUUIDService); this.backgroundPipeline.registerService(offlinePlayerUUIDService); } @@ -406,8 +418,8 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass; } final LuckPermsUUIDService luckPermsUUIDService; - if (Settings.UUID.SERVICE_LUCKPERMS && - Bukkit.getPluginManager().getPlugin("LuckPerms") != null) { + if (Settings.UUID.SERVICE_LUCKPERMS + && Bukkit.getPluginManager().getPlugin("LuckPerms") != null) { luckPermsUUIDService = new LuckPermsUUIDService(); logger.info("[P2] (UUID) Using LuckPerms as a complementary UUID service"); } else { @@ -415,8 +427,8 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass; } final BungeePermsUUIDService bungeePermsUUIDService; - if (Settings.UUID.SERVICE_BUNGEE_PERMS && - Bukkit.getPluginManager().getPlugin("BungeePerms") != null) { + if (Settings.UUID.SERVICE_BUNGEE_PERMS + && Bukkit.getPluginManager().getPlugin("BungeePerms") != null) { bungeePermsUUIDService = new BungeePermsUUIDService(); logger.info("[P2] (UUID) Using BungeePerms as a complementary UUID service"); } else { @@ -424,7 +436,8 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass; } final EssentialsUUIDService essentialsUUIDService; - if (Settings.UUID.SERVICE_ESSENTIALSX && Bukkit.getPluginManager().getPlugin("Essentials") != null) { + if (Settings.UUID.SERVICE_ESSENTIALSX + && Bukkit.getPluginManager().getPlugin("Essentials") != null) { essentialsUUIDService = new EssentialsUUIDService(); logger.info("[P2] (UUID) Using EssentialsX as a complementary UUID service"); } else { @@ -511,8 +524,10 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass; // Clean up potential memory leak Bukkit.getScheduler().runTaskTimer(this, () -> { try { - for (final PlotPlayer player : this.getPlayerManager().getPlayers()) { - if (player.getPlatformPlayer() == null || !player.getPlatformPlayer().isOnline()) { + for (final PlotPlayer player : this.getPlayerManager() + .getPlayers()) { + if (player.getPlatformPlayer() == null || !player.getPlatformPlayer() + .isOnline()) { this.getPlayerManager().removePlayer(player); } } @@ -626,7 +641,8 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass; // Now fetch names for all known UUIDs final int totalSize = uuidQueue.size(); int read = 0; - logger.info("[P2] (UUID) PlotSquared will fetch UUIDs in groups of {}", Settings.UUID.BACKGROUND_LIMIT); + logger.info("[P2] (UUID) PlotSquared will fetch UUIDs in groups of {}", + Settings.UUID.BACKGROUND_LIMIT); final List uuidList = new ArrayList<>(Settings.UUID.BACKGROUND_LIMIT); // Used to indicate that the second retrieval has been attempted @@ -659,7 +675,8 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass; // Print progress final double percentage = ((double) read / (double) totalSize) * 100.0D; if (Settings.DEBUG) { - logger.info("[P2] (UUID) PlotSquared has cached {} of UUIDs", String.format("%.1f%%", percentage)); + logger.info("[P2] (UUID) PlotSquared has cached {} of UUIDs", + String.format("%.1f%%", percentage)); } } catch (final InterruptedException | ExecutionException e) { logger.error("[P2] (UUID) Failed to retrieve last batch. Will try again", e); @@ -845,7 +862,8 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass; if (currentPlotId != null) { entity.setMetadata("shulkerPlot", new FixedMetadataValue( - (Plugin) PlotSquared.platform(), currentPlotId)); + (Plugin) PlotSquared.platform(), + currentPlotId)); } } } @@ -970,7 +988,8 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass; if (id != null && id.equalsIgnoreCase("single")) { result = getInjector().getInstance(SingleWorldGenerator.class); } else { - result = getInjector().getInstance(Key.get(IndependentPlotGenerator.class, DefaultGenerator.class)); + result = getInjector() + .getInstance(Key.get(IndependentPlotGenerator.class, DefaultGenerator.class)); if (!PlotSquared.get().setupPlotWorld(worldName, id, result)) { return null; } @@ -992,7 +1011,8 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass; return new BukkitPlotGenerator(world, gen, this.plotAreaManager); } else { return new BukkitPlotGenerator(world, getInjector() - .getInstance(Key.get(IndependentPlotGenerator.class, DefaultGenerator.class)), this.plotAreaManager); + .getInstance(Key.get(IndependentPlotGenerator.class, DefaultGenerator.class)), + this.plotAreaManager); } } @@ -1035,7 +1055,8 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass; World world = BukkitUtil.getWorld(worldName); if (world == null) { // create world - ConfigurationSection worldConfig = this.worldConfiguration.getConfigurationSection("worlds." + worldName); + ConfigurationSection worldConfig = + this.worldConfiguration.getConfigurationSection("worlds." + worldName); String manager = worldConfig.getString("generator.plugin", getPluginName()); PlotAreaBuilder builder = PlotAreaBuilder.newBuilder().plotManager(manager) .generatorName(worldConfig.getString("generator.init", manager)) @@ -1061,7 +1082,8 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass; if (gen instanceof BukkitPlotGenerator) { PlotSquared.get().loadWorld(worldName, (BukkitPlotGenerator) gen); } else if (gen != null) { - PlotSquared.get().loadWorld(worldName, new BukkitPlotGenerator(worldName, gen, this.plotAreaManager)); + PlotSquared.get().loadWorld(worldName, + new BukkitPlotGenerator(worldName, gen, this.plotAreaManager)); } else if (this.worldConfiguration.contains("worlds." + worldName)) { PlotSquared.get().loadWorld(worldName, null); } @@ -1128,7 +1150,8 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass; return names; } - @Override public com.plotsquared.core.location.World getPlatformWorld(@Nonnull final String worldName) { + @Override public com.plotsquared.core.location.World getPlatformWorld( + @Nonnull final String worldName) { return BukkitWorld.of(worldName); } 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 3e3b74938..c61e97e0f 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BlockStatePopulator.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BlockStatePopulator.java @@ -30,8 +30,8 @@ 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.LocalBlockQueue; -import com.plotsquared.core.queue.ScopedLocalBlockQueue; +import com.plotsquared.core.queue.QueueCoordinator; +import com.plotsquared.core.queue.ScopedQueueCoordinator; import org.bukkit.Chunk; import org.bukkit.World; import org.bukkit.generator.BlockPopulator; @@ -44,7 +44,7 @@ final class BlockStatePopulator extends BlockPopulator { private final IndependentPlotGenerator plotGenerator; private final PlotAreaManager plotAreaManager; - private LocalBlockQueue queue; + private QueueCoordinator queue; public BlockStatePopulator(@Nonnull final IndependentPlotGenerator plotGenerator, @Nonnull final PlotAreaManager plotAreaManager) { @@ -65,9 +65,9 @@ final class BlockStatePopulator extends BlockPopulator { } final ChunkWrapper wrap = new ChunkWrapper(area.getWorldName(), source.getX(), source.getZ()); - final ScopedLocalBlockQueue chunk = this.queue.getForChunk(wrap.x, wrap.z); + final ScopedQueueCoordinator chunk = this.queue.getForChunk(wrap.x, wrap.z); if (this.plotGenerator.populateChunk(chunk, area)) { - this.queue.flush(); + this.queue.enqueue(); } } 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 60bb34b9a..4322eaec9 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java @@ -34,7 +34,7 @@ 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.queue.ScopedQueueCoordinator; import com.plotsquared.core.util.ChunkManager; import com.plotsquared.core.util.MainUtil; import com.sk89q.worldedit.math.BlockVector2; @@ -190,7 +190,7 @@ public class BukkitPlotGenerator extends ChunkGenerator return result.getChunkData(); } - private void generate(BlockVector2 loc, World world, ScopedLocalBlockQueue result) { + private void generate(BlockVector2 loc, World world, ScopedQueueCoordinator result) { // Load if improperly loaded if (!this.loaded) { String name = world.getName(); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/DelegatePlotGenerator.java b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/DelegatePlotGenerator.java index 6452941a2..e155f03bd 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/DelegatePlotGenerator.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/DelegatePlotGenerator.java @@ -31,16 +31,16 @@ import com.plotsquared.core.generator.IndependentPlotGenerator; 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.queue.ScopedQueueCoordinator; import com.plotsquared.core.util.MathMan; import com.sk89q.worldedit.bukkit.BukkitAdapter; import org.bukkit.World; import org.bukkit.block.Biome; import org.bukkit.generator.BlockPopulator; import org.bukkit.generator.ChunkGenerator; -import javax.annotation.Nonnull; import org.jetbrains.annotations.Range; +import javax.annotation.Nonnull; import java.util.Random; final class DelegatePlotGenerator extends IndependentPlotGenerator { @@ -64,7 +64,7 @@ final class DelegatePlotGenerator extends IndependentPlotGenerator { return PlotSquared.platform().getDefaultGenerator().getNewPlotArea(world, id, min, max); } - @Override public void generateChunk(final ScopedLocalBlockQueue result, PlotArea settings) { + @Override public void generateChunk(final ScopedQueueCoordinator result, PlotArea settings) { World world = BukkitUtil.getWorld(this.world); Location min = result.getMin(); int chunkX = min.getX() >> 4; @@ -72,8 +72,7 @@ final class DelegatePlotGenerator extends IndependentPlotGenerator { Random random = new Random(MathMan.pair((short) chunkX, (short) chunkZ)); try { ChunkGenerator.BiomeGrid grid = new ChunkGenerator.BiomeGrid() { - @Override - public void setBiome(@Range(from = 0, to = 15) int x, + @Override public void setBiome(@Range(from = 0, to = 15) int x, @Range(from = 0, to = 15) int z, @Nonnull Biome biome) { result.setBiome(x, z, BukkitAdapter.adapt(biome)); } 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 c6fe99ba7..b7eda2e6b 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/inject/BukkitModule.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/inject/BukkitModule.java @@ -30,7 +30,7 @@ import com.google.inject.assistedinject.FactoryModuleBuilder; import com.google.inject.util.Providers; import com.plotsquared.bukkit.BukkitPlatform; import com.plotsquared.bukkit.player.BukkitPlayerManager; -import com.plotsquared.bukkit.queue.BukkitLocalQueue; +import com.plotsquared.bukkit.queue.BukkitQueueCoordinator; import com.plotsquared.bukkit.schematic.BukkitSchematicHandler; import com.plotsquared.bukkit.util.BukkitChunkManager; import com.plotsquared.bukkit.util.BukkitEconHandler; @@ -66,9 +66,11 @@ import lombok.RequiredArgsConstructor; import org.bukkit.Bukkit; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.plugin.java.JavaPlugin; + import javax.annotation.Nonnull; -@RequiredArgsConstructor public class BukkitModule extends AbstractModule { +@RequiredArgsConstructor +public class BukkitModule extends AbstractModule { private final BukkitPlatform bukkitPlatform; @@ -76,16 +78,19 @@ import javax.annotation.Nonnull; bind(PlayerManager.class).to(BukkitPlayerManager.class); bind(JavaPlugin.class).toInstance(bukkitPlatform); bind(PlotPlatform.class).toInstance(bukkitPlatform); - bind(IndependentPlotGenerator.class).annotatedWith(DefaultGenerator.class).to(HybridGen.class); + bind(IndependentPlotGenerator.class).annotatedWith(DefaultGenerator.class) + .to(HybridGen.class); // Console actor @Nonnull ConsoleCommandSender console = Bukkit.getServer().getConsoleSender(); - WorldEditPlugin wePlugin = ((WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit")); - bind(Actor.class).annotatedWith(ConsoleActor.class).toInstance(wePlugin.wrapCommandSender(console)); + WorldEditPlugin wePlugin = + ((WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit")); + bind(Actor.class).annotatedWith(ConsoleActor.class) + .toInstance(wePlugin.wrapCommandSender(console)); bind(InventoryUtil.class).to(BukkitInventoryUtil.class); bind(SetupUtils.class).to(BukkitSetupUtils.class); bind(WorldUtil.class).to(BukkitUtil.class); bind(GlobalBlockQueue.class).toInstance(new GlobalBlockQueue( - QueueProvider.of(BukkitLocalQueue.class, BukkitLocalQueue.class), 1, Settings.QUEUE.TARGET_TIME)); + QueueProvider.of(BukkitQueueCoordinator.class, BukkitQueueCoordinator.class))); bind(ChunkManager.class).to(BukkitChunkManager.class); bind(RegionManager.class).to(BukkitRegionManager.class); bind(SchematicHandler.class).to(BukkitSchematicHandler.class); @@ -108,7 +113,8 @@ import javax.annotation.Nonnull; bind(PermHandler.class).toProvider(Providers.of(null)); } try { - final BukkitEconHandler bukkitEconHandler = new BukkitEconHandler(bukkitPermHandler); + final BukkitEconHandler bukkitEconHandler = + new BukkitEconHandler(bukkitPermHandler); bind(EconHandler.class).toInstance(bukkitEconHandler); } catch (final Exception ignored) { bind(EconHandler.class).toProvider(Providers.of(null)); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/queue/BukkitQueueCoordinator.java b/Bukkit/src/main/java/com/plotsquared/bukkit/queue/BukkitQueueCoordinator.java index b356bea11..64fa07c0a 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/queue/BukkitQueueCoordinator.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/queue/BukkitQueueCoordinator.java @@ -53,6 +53,7 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator { private final World world; private final SideEffectSet sideEffectSet; + private Runnable whenDone; public BukkitQueueCoordinator(World world) { super(world); @@ -74,91 +75,96 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator { @Override public boolean enqueue() { BukkitChunkCoordinator.builder().inWorld(BukkitAdapter.adapt(world)) .withChunks(getBlockChunks().keySet()).withInitialBatchSize(3).withMaxIterationTime(40) - .withThrowableConsumer(Throwable::printStackTrace).withConsumer(chunk -> { - LocalChunk localChunk = - getBlockChunks().get(BlockVector2.at(chunk.getX(), chunk.getZ())); - if (localChunk == null) { - throw new NullPointerException( - "LocalChunk cannot be null when accessed from ChunkCoordinator"); - } - World worldObj = getWorld(); - int sx = chunk.getX() << 4; - int sz = chunk.getX() << 4; - for (int layer = 0; layer < localChunk.getBaseblocks().length; layer++) { - BaseBlock[] blocksLayer = localChunk.getBaseblocks()[layer]; - if (blocksLayer == null) { - continue; + .withThrowableConsumer(Throwable::printStackTrace).withFinalAction(whenDone) + .withConsumer(chunk -> { + LocalChunk localChunk = + getBlockChunks().get(BlockVector2.at(chunk.getX(), chunk.getZ())); + if (localChunk == null) { + throw new NullPointerException( + "LocalChunk cannot be null when accessed from ChunkCoordinator"); } - for (int j = 0; j < blocksLayer.length; j++) { - if (blocksLayer[j] == null) { + World worldObj = getWorld(); + int sx = chunk.getX() << 4; + int sz = chunk.getX() << 4; + for (int layer = 0; layer < localChunk.getBaseblocks().length; layer++) { + BaseBlock[] blocksLayer = localChunk.getBaseblocks()[layer]; + if (blocksLayer == null) { continue; } - BaseBlock block = blocksLayer[j]; - int x = sx + MainUtil.x_loc[layer][j]; - int y = MainUtil.y_loc[layer][j]; - int z = sz + MainUtil.z_loc[layer][j]; - try { - worldObj.setBlock(BlockVector3.at(x, y, z), block, sideEffectSet); - } catch (WorldEditException ignored) { - // Fallback to not so nice method - BlockData blockData = BukkitAdapter.adapt(block); - - Block existing = chunk.getBlock(x, y, z); - final BlockState existingBaseBlock = - BukkitAdapter.adapt(existing.getBlockData()); - if (BukkitBlockUtil.get(existing).equals(existingBaseBlock) && existing - .getBlockData().matches(blockData)) { + for (int j = 0; j < blocksLayer.length; j++) { + if (blocksLayer[j] == null) { continue; } + BaseBlock block = blocksLayer[j]; + int x = sx + MainUtil.x_loc[layer][j]; + int y = MainUtil.y_loc[layer][j]; + int z = sz + MainUtil.z_loc[layer][j]; + try { + worldObj.setBlock(BlockVector3.at(x, y, z), block, sideEffectSet); + } catch (WorldEditException ignored) { + // Fallback to not so nice method + BlockData blockData = BukkitAdapter.adapt(block); - if (existing.getState() instanceof Container) { - ((Container) existing.getState()).getInventory().clear(); - } + Block existing = chunk.getBlock(x, y, z); + final BlockState existingBaseBlock = + BukkitAdapter.adapt(existing.getBlockData()); + if (BukkitBlockUtil.get(existing).equals(existingBaseBlock) && existing + .getBlockData().matches(blockData)) { + continue; + } - existing.setType(BukkitAdapter.adapt(block.getBlockType()), false); - existing.setBlockData(blockData, false); - if (block.hasNbtData()) { - CompoundTag tag = block.getNbtData(); - StateWrapper sw = new StateWrapper(tag); + if (existing.getState() instanceof Container) { + ((Container) existing.getState()).getInventory().clear(); + } - sw.restoreTag(worldObj.getName(), existing.getX(), existing.getY(), - existing.getZ()); + existing.setType(BukkitAdapter.adapt(block.getBlockType()), false); + existing.setBlockData(blockData, false); + if (block.hasNbtData()) { + CompoundTag tag = block.getNbtData(); + StateWrapper sw = new StateWrapper(tag); + + sw.restoreTag(worldObj.getName(), existing.getX(), existing.getY(), + existing.getZ()); + } } } } - } - for (int layer = 0; layer < localChunk.getBaseblocks().length; layer++) { - BiomeType[] biomesLayer = localChunk.getBiomes()[layer]; - if (biomesLayer == null) { - continue; - } - for (int j = 0; j < biomesLayer.length; j++) { - if (biomesLayer[j] == null) { + for (int layer = 0; layer < localChunk.getBaseblocks().length; layer++) { + BiomeType[] biomesLayer = localChunk.getBiomes()[layer]; + if (biomesLayer == null) { continue; } - BiomeType biome = biomesLayer[j]; - int x = sx + MainUtil.x_loc[layer][j]; - int y = MainUtil.y_loc[layer][j]; - int z = sz + MainUtil.z_loc[layer][j]; - worldObj.setBiome(BlockVector3.at(x, y, z), biome); - } - } - if (localChunk.getTiles().size() > 0) { - localChunk.getTiles().forEach(((blockVector3, tag) -> { - try { - BaseBlock block = worldObj.getBlock(blockVector3).toBaseBlock(tag); - worldObj.setBlock(blockVector3, block, sideEffectSet); - } catch (WorldEditException ignored) { - StateWrapper sw = new StateWrapper(tag); - sw.restoreTag(worldObj.getName(), blockVector3.getX(), blockVector3.getY(), - blockVector3.getZ()); + for (int j = 0; j < biomesLayer.length; j++) { + if (biomesLayer[j] == null) { + continue; + } + BiomeType biome = biomesLayer[j]; + int x = sx + MainUtil.x_loc[layer][j]; + int y = MainUtil.y_loc[layer][j]; + int z = sz + MainUtil.z_loc[layer][j]; + worldObj.setBiome(BlockVector3.at(x, y, z), biome); } - })); - } - }); + } + if (localChunk.getTiles().size() > 0) { + localChunk.getTiles().forEach(((blockVector3, tag) -> { + try { + BaseBlock block = worldObj.getBlock(blockVector3).toBaseBlock(tag); + worldObj.setBlock(blockVector3, block, sideEffectSet); + } catch (WorldEditException ignored) { + StateWrapper sw = new StateWrapper(tag); + sw.restoreTag(worldObj.getName(), blockVector3.getX(), + blockVector3.getY(), blockVector3.getZ()); + } + })); + } + }); return super.enqueue(); } + @Override public void setCompleteTask(Runnable whenDone) { + this.whenDone = whenDone; + } + private void setMaterial(@Nonnull final BlockState plotBlock, @Nonnull final Block block) { Material material = BukkitAdapter.adapt(plotBlock.getBlockType()); block.setType(material, false); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/queue/GenChunk.java b/Bukkit/src/main/java/com/plotsquared/bukkit/queue/GenChunk.java index 3a18ec355..6a67c83e1 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/queue/GenChunk.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/queue/GenChunk.java @@ -30,7 +30,7 @@ import com.plotsquared.bukkit.util.BukkitBlockUtil; import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.core.location.ChunkWrapper; import com.plotsquared.core.location.Location; -import com.plotsquared.core.queue.ScopedLocalBlockQueue; +import com.plotsquared.core.queue.ScopedQueueCoordinator; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.PatternUtil; import com.sk89q.worldedit.bukkit.BukkitAdapter; @@ -41,16 +41,17 @@ import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockTypes; import lombok.Getter; import lombok.Setter; +import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.World; import org.bukkit.block.Biome; import org.bukkit.generator.ChunkGenerator.BiomeGrid; import org.bukkit.generator.ChunkGenerator.ChunkData; -import javax.annotation.Nonnull; +import javax.annotation.Nonnull; import java.util.Arrays; -public class GenChunk extends ScopedLocalBlockQueue { +public class GenChunk extends ScopedQueueCoordinator { public final Biome[] biomes; public BlockState[][] result; @@ -191,16 +192,18 @@ public class GenChunk extends ScopedLocalBlockQueue { return chunk == null ? chunkZ : chunk.getZ(); } - @Override public String getWorld() { - return chunk == null ? world : chunk.getWorld().getName(); + @Override public com.sk89q.worldedit.world.World getWorld() { + return chunk == null ? + BukkitAdapter.adapt(Bukkit.getWorld(world)) : + BukkitAdapter.adapt(chunk.getWorld()); } @Override public Location getMax() { - return Location.at(getWorld(), 15 + (getX() << 4), 255, 15 + (getZ() << 4)); + return Location.at(getWorld().getName(), 15 + (getX() << 4), 255, 15 + (getZ() << 4)); } @Override public Location getMin() { - return Location.at(getWorld(), getX() << 4, 0, getZ() << 4); + return Location.at(getWorld().getName(), getX() << 4, 0, getZ() << 4); } public GenChunk clone() { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/schematic/BukkitSchematicHandler.java b/Bukkit/src/main/java/com/plotsquared/bukkit/schematic/BukkitSchematicHandler.java index e2e22ed3c..b3dff7e2d 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/schematic/BukkitSchematicHandler.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/schematic/BukkitSchematicHandler.java @@ -27,7 +27,7 @@ package com.plotsquared.bukkit.schematic; import com.google.inject.Inject; import com.google.inject.Singleton; -import com.plotsquared.core.queue.LocalBlockQueue; +import com.plotsquared.core.queue.QueueCoordinator; import com.plotsquared.core.util.SchematicHandler; import com.plotsquared.core.util.WorldUtil; import com.sk89q.jnbt.CompoundTag; @@ -43,7 +43,7 @@ import javax.annotation.Nonnull; } @Override - public boolean restoreTile(LocalBlockQueue queue, CompoundTag ct, int x, int y, int z) { - return new StateWrapper(ct).restoreTag(queue.getWorld(), x, y, z); + public boolean restoreTile(QueueCoordinator queue, CompoundTag ct, int x, int y, int z) { + return new StateWrapper(ct).restoreTag(queue.getWorld().getName(), x, y, z); } } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java index 325d47544..24551aadb 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java @@ -28,7 +28,7 @@ package com.plotsquared.bukkit.util; import com.google.inject.Singleton; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.listener.WEExtent; -import com.plotsquared.core.queue.LocalBlockQueue; +import com.plotsquared.core.queue.QueueCoordinator; import com.plotsquared.core.util.ChunkManager; import com.plotsquared.core.util.entity.EntityCategories; import com.plotsquared.core.util.task.TaskManager; @@ -54,7 +54,8 @@ import static com.plotsquared.core.util.entity.EntityCategories.CAP_MOB; import static com.plotsquared.core.util.entity.EntityCategories.CAP_MONSTER; import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE; -@Singleton public class BukkitChunkManager extends ChunkManager { +@Singleton +public class BukkitChunkManager extends ChunkManager { public static boolean isIn(CuboidRegion region, int x, int z) { return x >= region.getMinimumPoint().getX() && x <= region.getMaximumPoint().getX() @@ -79,8 +80,10 @@ import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE; BukkitWorld bukkitWorld1 = new BukkitWorld(world1); BukkitWorld bukkitWorld2 = new BukkitWorld(world2); - LocalBlockQueue queue1 = PlotSquared.platform().getGlobalBlockQueue().getNewQueue(worldName1, false); - LocalBlockQueue queue2 = PlotSquared.platform().getGlobalBlockQueue().getNewQueue(worldName2, false); + QueueCoordinator queue1 = + PlotSquared.platform().getGlobalBlockQueue().getNewQueue(worldName1, false); + QueueCoordinator queue2 = + PlotSquared.platform().getGlobalBlockQueue().getNewQueue(worldName2, false); for (int x = Math.max(r1.getMinimumPoint().getX(), sx); x <= Math.min(r1.getMaximumPoint().getX(), sx + 15); x++) { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitRegionManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitRegionManager.java index 55dc45512..e95f469af 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitRegionManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitRegionManager.java @@ -35,8 +35,8 @@ import com.plotsquared.core.location.PlotLoc; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotManager; -import com.plotsquared.core.queue.LocalBlockQueue; -import com.plotsquared.core.queue.ScopedLocalBlockQueue; +import com.plotsquared.core.queue.QueueCoordinator; +import com.plotsquared.core.queue.ScopedQueueCoordinator; import com.plotsquared.core.util.ChunkManager; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.RegionManager; @@ -78,9 +78,11 @@ import static com.plotsquared.core.util.entity.EntityCategories.CAP_MOB; import static com.plotsquared.core.util.entity.EntityCategories.CAP_MONSTER; import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE; -@Singleton public class BukkitRegionManager extends RegionManager { +@Singleton +public class BukkitRegionManager extends RegionManager { - private static final Logger logger = LoggerFactory.getLogger("P2/" + BukkitRegionManager.class.getSimpleName()); + private static final Logger logger = + LoggerFactory.getLogger("P2/" + BukkitRegionManager.class.getSimpleName()); @Inject public BukkitRegionManager(@Nonnull final ChunkManager chunkManager) { super(chunkManager); @@ -102,14 +104,16 @@ import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE; final Semaphore semaphore = new Semaphore(1); try { semaphore.acquire(); - Bukkit.getScheduler().runTask(BukkitPlatform.getPlugin(BukkitPlatform.class), () -> { - for (Chunk chunk : Objects.requireNonNull(Bukkit.getWorld(world)) - .getLoadedChunks()) { - BlockVector2 loc = BlockVector2.at(chunk.getX() >> 5, chunk.getZ() >> 5); - chunks.add(loc); - } - semaphore.release(); - }); + Bukkit.getScheduler() + .runTask(BukkitPlatform.getPlugin(BukkitPlatform.class), () -> { + for (Chunk chunk : Objects.requireNonNull(Bukkit.getWorld(world)) + .getLoadedChunks()) { + BlockVector2 loc = + BlockVector2.at(chunk.getX() >> 5, chunk.getZ() >> 5); + chunks.add(loc); + } + semaphore.release(); + }); semaphore.acquireUninterruptibly(); } catch (final Exception e) { e.printStackTrace(); @@ -198,8 +202,7 @@ import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE; return count; } - @Override - public boolean copyRegion(Location pos1, Location pos2, Location newPos, + @Override public boolean copyRegion(Location pos1, Location pos2, Location newPos, final Runnable whenDone) { final int relX = newPos.getX() - pos1.getX(); final int relZ = newPos.getZ() - pos1.getZ(); @@ -213,7 +216,8 @@ import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE; assert oldWorld != null; final String newWorldName = newWorld.getName(); final ContentMap map = new ContentMap(); - final LocalBlockQueue queue = PlotSquared.platform().getGlobalBlockQueue().getNewQueue(newWorldName, false); + final QueueCoordinator queue = + PlotSquared.platform().getGlobalBlockQueue().getNewQueue(newWorldName, false); ChunkManager.chunkTask(pos1, pos2, new RunnableVal() { @Override public void run(int[] value) { int bx = value[2]; @@ -243,18 +247,17 @@ import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE; } } } - queue.enqueue(); - PlotSquared.platform().getGlobalBlockQueue().addEmptyTask(() -> { + queue.setCompleteTask(() -> { //map.restoreBlocks(newWorld, 0, 0); map.restoreEntities(newWorld, relX, relZ); TaskManager.runTask(whenDone); }); + queue.enqueue(); }, 5); return true; } - @Override - public boolean regenerateRegion(final Location pos1, final Location pos2, + @Override public boolean regenerateRegion(final Location pos1, final Location pos2, final boolean ignoreAugment, final Runnable whenDone) { final String world = pos1.getWorldName(); @@ -292,8 +295,8 @@ import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE; if (chunkObj == null) { return; } - final LocalBlockQueue queue = PlotSquared.platform().getGlobalBlockQueue() - .getNewQueue(world, false); + final QueueCoordinator queue = + PlotSquared.platform().getGlobalBlockQueue().getNewQueue(world, false); if (xxb >= p1x && xxt <= p2x && zzb >= p1z && zzt <= p2z) { AugmentedUtils.bypass(ignoreAugment, () -> queue.regenChunkSafe(chunk.getX(), chunk.getZ())); @@ -362,8 +365,8 @@ import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE; .createRegion(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ()); map.saveEntitiesOut(chunkObj, currentPlotClear); AugmentedUtils.bypass(ignoreAugment, () -> ChunkManager - .setChunkInPlotArea(null, new RunnableVal() { - @Override public void run(ScopedLocalBlockQueue value) { + .setChunkInPlotArea(null, new RunnableVal() { + @Override public void run(ScopedQueueCoordinator value) { Location min = value.getMin(); int bx = min.getX(); int bz = min.getZ(); @@ -429,8 +432,7 @@ import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE; } } - @Override - public void swap(Location bot1, Location top1, Location bot2, Location top2, + @Override public void swap(Location bot1, Location top1, Location bot2, Location top2, final Runnable whenDone) { CuboidRegion region1 = RegionUtil.createRegion(bot1.getX(), top1.getX(), bot1.getZ(), top1.getZ()); @@ -468,16 +470,17 @@ import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE; region.getMinimumPoint().getY(), region.getMinimumPoint().getZ() - extendBiome); Location pos2 = Location.at(world, region.getMaximumPoint().getX() + extendBiome, region.getMaximumPoint().getY(), region.getMaximumPoint().getZ() + extendBiome); - final LocalBlockQueue queue = PlotSquared.platform().getGlobalBlockQueue() - .getNewQueue(world, false); + final QueueCoordinator queue = + PlotSquared.platform().getGlobalBlockQueue().getNewQueue(world, false); ChunkManager.chunkTask(pos1, pos2, new RunnableVal() { @Override public void run(int[] value) { BlockVector2 loc = BlockVector2.at(value[0], value[1]); - PlotSquared.platform().getChunkManager().loadChunk(world, loc, false).thenRun(() -> { - MainUtil.setBiome(world, value[2], value[3], value[4], value[5], biome); - queue.refreshChunk(value[0], value[1]); - }); + PlotSquared.platform().getChunkManager().loadChunk(world, loc, false) + .thenRun(() -> { + MainUtil.setBiome(world, value[2], value[3], value[4], value[5], biome); + queue.refreshChunk(value[0], value[1]); + }); } }, whenDone, 5); } diff --git a/Core/src/main/java/com/plotsquared/core/command/Relight.java b/Core/src/main/java/com/plotsquared/core/command/Relight.java index 4a2475b5f..308e7d451 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Relight.java +++ b/Core/src/main/java/com/plotsquared/core/command/Relight.java @@ -28,7 +28,7 @@ package com.plotsquared.core.command; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; -import com.plotsquared.core.queue.LocalBlockQueue; +import com.plotsquared.core.queue.QueueCoordinator; import com.plotsquared.core.util.ChunkManager; import com.plotsquared.core.util.task.RunnableVal; import com.plotsquared.core.util.task.RunnableVal2; @@ -50,12 +50,13 @@ public class Relight extends Command { public CompletableFuture execute(final PlotPlayer player, String[] args, RunnableVal3 confirm, RunnableVal2 whenDone) { - final Plot plot = player.getCurrentPlot(); + player.sendMessage("Not implemented."); +/* final Plot plot = player.getCurrentPlot(); if (plot == null) { Captions.NOT_IN_PLOT.send(player); return CompletableFuture.completedFuture(false); } - final LocalBlockQueue queue = plot.getArea().getQueue(false); + final QueueCoordinator queue = plot.getArea().getQueue(false); ChunkManager.chunkTask(plot, new RunnableVal() { @Override public void run(int[] value) { queue.fixChunkLighting(value[0], value[1]); @@ -63,7 +64,7 @@ public class Relight extends Command { }, () -> { plot.refreshChunks(); Captions.SET_BLOCK_ACTION_FINISHED.send(player); - }, 5); + }, 5);*/ return CompletableFuture.completedFuture(true); } diff --git a/Core/src/main/java/com/plotsquared/core/command/Trim.java b/Core/src/main/java/com/plotsquared/core/command/Trim.java index abdfb0a23..346eb17ab 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Trim.java +++ b/Core/src/main/java/com/plotsquared/core/command/Trim.java @@ -34,7 +34,7 @@ import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.expiration.ExpireManager; import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.queue.GlobalBlockQueue; -import com.plotsquared.core.queue.LocalBlockQueue; +import com.plotsquared.core.queue.QueueCoordinator; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.RegionManager; import com.plotsquared.core.util.RegionUtil; @@ -188,7 +188,7 @@ public class Trim extends SubCommand { } } } - final LocalBlockQueue queue = blockQueue.getNewQueue(world, false); + final QueueCoordinator queue = blockQueue.getNewQueue(world, false); TaskManager.objectTask(chunks, new RunnableVal() { @Override public void run(BlockVector2 value) { queue.regenChunk(value.getX(), value.getZ()); diff --git a/Core/src/main/java/com/plotsquared/core/generator/AugmentedUtils.java b/Core/src/main/java/com/plotsquared/core/generator/AugmentedUtils.java index e672a1fdf..b40e718af 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/AugmentedUtils.java +++ b/Core/src/main/java/com/plotsquared/core/generator/AugmentedUtils.java @@ -31,17 +31,17 @@ import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotAreaTerrainType; import com.plotsquared.core.plot.PlotAreaType; import com.plotsquared.core.plot.PlotManager; -import com.plotsquared.core.queue.AreaBoundDelegateLocalBlockQueue; -import com.plotsquared.core.queue.LocalBlockQueue; -import com.plotsquared.core.queue.LocationOffsetDelegateLocalBlockQueue; -import com.plotsquared.core.queue.ScopedLocalBlockQueue; +import com.plotsquared.core.queue.AreaBoundDelegateQueueCoordinator; +import com.plotsquared.core.queue.LocationOffsetDelegateQueueCoordinator; +import com.plotsquared.core.queue.QueueCoordinator; +import com.plotsquared.core.queue.ScopedQueueCoordinator; import com.plotsquared.core.util.RegionUtil; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockTypes; + import javax.annotation.Nonnull; import javax.annotation.Nullable; - import java.util.Set; public class AugmentedUtils { @@ -55,7 +55,7 @@ public class AugmentedUtils { } public static boolean generate(@Nullable Object chunkObject, @Nonnull final String world, - final int chunkX, final int chunkZ, LocalBlockQueue queue) { + final int chunkX, final int chunkZ, QueueCoordinator queue) { if (!enabled) { return false; } @@ -67,7 +67,8 @@ public class AugmentedUtils { // entire chunk CuboidRegion region = RegionUtil.createRegion(blockX, blockX + 15, blockZ, blockZ + 15); // Query for plot areas in the chunk - final Set areas = PlotSquared.get().getPlotAreaManager().getPlotAreasSet(world, region); + final Set areas = + PlotSquared.get().getPlotAreaManager().getPlotAreasSet(world, region); if (areas.isEmpty()) { return false; } @@ -89,7 +90,7 @@ public class AugmentedUtils { queue = PlotSquared.platform().getGlobalBlockQueue().getNewQueue(world, false); queue.setChunkObject(chunkObject); } - LocalBlockQueue primaryMask; + QueueCoordinator primaryMask; // coordinates int relativeBottomX; int relativeBottomZ; @@ -102,14 +103,14 @@ public class AugmentedUtils { relativeTopX = Math.min(15, area.getRegion().getMaximumPoint().getX() - blockX); relativeTopZ = Math.min(15, area.getRegion().getMaximumPoint().getZ() - blockZ); - primaryMask = new AreaBoundDelegateLocalBlockQueue(area, queue); + primaryMask = new AreaBoundDelegateQueueCoordinator(area, queue); } else { relativeBottomX = relativeBottomZ = 0; relativeTopX = relativeTopZ = 15; primaryMask = queue; } - LocalBlockQueue secondaryMask; + QueueCoordinator secondaryMask; BlockState air = BlockTypes.AIR.getDefaultState(); if (area.getTerrain() == PlotAreaTerrainType.ROAD) { PlotManager manager = area.getPlotManager(); @@ -133,7 +134,7 @@ public class AugmentedUtils { continue; } generationResult = true; - secondaryMask = new LocationOffsetDelegateLocalBlockQueue(canPlace, blockX, blockZ, + secondaryMask = new LocationOffsetDelegateQueueCoordinator(canPlace, blockX, blockZ, primaryMask); } else { secondaryMask = primaryMask; @@ -151,15 +152,15 @@ public class AugmentedUtils { secondaryMask.setChunkObject(chunkObject); secondaryMask.setForceSync(true); - ScopedLocalBlockQueue scoped = - new ScopedLocalBlockQueue(secondaryMask, Location.at(world, blockX, 0, blockZ), + ScopedQueueCoordinator scoped = + new ScopedQueueCoordinator(secondaryMask, Location.at(world, blockX, 0, blockZ), Location.at(world, blockX + 15, 255, blockZ + 15)); generator.generateChunk(scoped, area); generator.populateChunk(scoped, area); } if (queue != null) { queue.setForceSync(true); - queue.flush(); + queue.enqueue(); } return generationResult; } diff --git a/Core/src/main/java/com/plotsquared/core/generator/ClassicPlotManager.java b/Core/src/main/java/com/plotsquared/core/generator/ClassicPlotManager.java index ac6aca214..b046da010 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/ClassicPlotManager.java +++ b/Core/src/main/java/com/plotsquared/core/generator/ClassicPlotManager.java @@ -33,7 +33,7 @@ import com.plotsquared.core.plot.BlockBucket; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotAreaTerrainType; import com.plotsquared.core.plot.PlotId; -import com.plotsquared.core.queue.LocalBlockQueue; +import com.plotsquared.core.queue.QueueCoordinator; import com.plotsquared.core.util.BlockUtil; import com.plotsquared.core.util.MathMan; import com.plotsquared.core.util.RegionManager; @@ -136,7 +136,7 @@ public class ClassicPlotManager extends SquarePlotManager { return false; } Location[] corners = plot.getCorners(); - LocalBlockQueue queue = classicPlotWorld.getQueue(false); + QueueCoordinator queue = classicPlotWorld.getQueue(false); int x = MathMan.average(corners[0].getX(), corners[1].getX()); int z = MathMan.average(corners[0].getZ(), corners[1].getZ()); @@ -157,7 +157,7 @@ public class ClassicPlotManager extends SquarePlotManager { Plot plot = classicPlotWorld.getPlotAbs(plotId); Location bottom = plot.getBottomAbs(); Location top = plot.getExtendedTopAbs(); - LocalBlockQueue queue = classicPlotWorld.getQueue(false); + QueueCoordinator queue = classicPlotWorld.getQueue(false); int maxY = classicPlotWorld.getPlotManager().getWorldHeight(); if (!plot.getMerged(Direction.NORTH)) { int z = bottom.getZ(); @@ -221,7 +221,7 @@ public class ClassicPlotManager extends SquarePlotManager { .subtract(plot.getMerged(Direction.WEST) ? 0 : 1, 0, plot.getMerged(Direction.NORTH) ? 0 : 1); Location top = plot.getExtendedTopAbs().add(1, 0, 1); - LocalBlockQueue queue = classicPlotWorld.getQueue(false); + QueueCoordinator queue = classicPlotWorld.getQueue(false); if (!plot.getMerged(Direction.NORTH)) { int z = bot.getZ(); for (int x = bot.getX(); x < top.getX(); x++) { @@ -274,7 +274,7 @@ public class ClassicPlotManager extends SquarePlotManager { .subtract(plot.getMerged(Direction.WEST) ? 0 : 1, 0, plot.getMerged(Direction.NORTH) ? 0 : 1); Location top = plot.getExtendedTopAbs().add(1, 0, 1); - LocalBlockQueue queue = classicPlotWorld.getQueue(false); + QueueCoordinator queue = classicPlotWorld.getQueue(false); int y = classicPlotWorld.WALL_HEIGHT + 1; if (!plot.getMerged(Direction.NORTH)) { int z = bot.getZ(); @@ -315,7 +315,7 @@ public class ClassicPlotManager extends SquarePlotManager { int ex = sx + classicPlotWorld.ROAD_WIDTH - 1; int sz = pos1.getZ() - 2; int ez = pos2.getZ() + 2; - LocalBlockQueue queue = classicPlotWorld.getQueue(false); + QueueCoordinator queue = classicPlotWorld.getQueue(false); int maxY = getWorldHeight(); queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx, Math.min(classicPlotWorld.WALL_HEIGHT, classicPlotWorld.ROAD_HEIGHT) + 1, sz + 1), @@ -353,7 +353,7 @@ public class ClassicPlotManager extends SquarePlotManager { int ez = sz + classicPlotWorld.ROAD_WIDTH - 1; int sx = pos1.getX() - 2; int ex = pos2.getX() + 2; - LocalBlockQueue queue = classicPlotWorld.getQueue(false); + QueueCoordinator queue = classicPlotWorld.getQueue(false); queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx + 1, Math.min(classicPlotWorld.WALL_HEIGHT, classicPlotWorld.ROAD_HEIGHT) + 1, sz), Location.at(classicPlotWorld.getWorldName(), ex - 1, @@ -390,7 +390,7 @@ public class ClassicPlotManager extends SquarePlotManager { int ex = sx + classicPlotWorld.ROAD_WIDTH - 1; int sz = pos2.getZ() + 1; int ez = sz + classicPlotWorld.ROAD_WIDTH - 1; - LocalBlockQueue queue = classicPlotWorld.getQueue(false); + QueueCoordinator queue = classicPlotWorld.getQueue(false); queue.setCuboid( Location.at(classicPlotWorld.getWorldName(), sx + 1, classicPlotWorld.ROAD_HEIGHT + 1, sz + 1), Location.at(classicPlotWorld.getWorldName(), ex - 1, @@ -412,7 +412,7 @@ public class ClassicPlotManager extends SquarePlotManager { int ex = sx + classicPlotWorld.ROAD_WIDTH - 1; int sz = pos1.getZ() - 1; int ez = pos2.getZ() + 1; - LocalBlockQueue queue = classicPlotWorld.getQueue(false); + QueueCoordinator queue = classicPlotWorld.getQueue(false); queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx, Math.min(classicPlotWorld.PLOT_HEIGHT, classicPlotWorld.ROAD_HEIGHT) + 1, sz), Location.at(classicPlotWorld.getWorldName(), ex, @@ -435,7 +435,7 @@ public class ClassicPlotManager extends SquarePlotManager { int ez = sz + classicPlotWorld.ROAD_WIDTH - 1; int sx = pos1.getX() - 1; int ex = pos2.getX() + 1; - LocalBlockQueue queue = classicPlotWorld.getQueue(false); + QueueCoordinator queue = classicPlotWorld.getQueue(false); queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx, Math.min(classicPlotWorld.PLOT_HEIGHT, classicPlotWorld.ROAD_HEIGHT) + 1, sz), Location.at(classicPlotWorld.getWorldName(), ex, @@ -457,7 +457,7 @@ public class ClassicPlotManager extends SquarePlotManager { int ex = sx + classicPlotWorld.ROAD_WIDTH - 1; int sz = location.getZ() + 1; int ez = sz + classicPlotWorld.ROAD_WIDTH - 1; - LocalBlockQueue queue = classicPlotWorld.getQueue(false); + QueueCoordinator queue = classicPlotWorld.getQueue(false); queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx, Math.min(classicPlotWorld.PLOT_HEIGHT, classicPlotWorld.ROAD_HEIGHT) + 1, sz), Location.at(classicPlotWorld.getWorldName(), ex, 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 2560981ab..e91d3104d 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/HybridGen.java +++ b/Core/src/main/java/com/plotsquared/core/generator/HybridGen.java @@ -33,7 +33,7 @@ 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.queue.ScopedQueueCoordinator; import com.plotsquared.core.util.MathMan; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; @@ -52,7 +52,7 @@ public class HybridGen extends IndependentPlotGenerator { return PlotSquared.platform().getPluginName(); } - private void placeSchem(HybridPlotWorld world, ScopedLocalBlockQueue result, short relativeX, + private void placeSchem(HybridPlotWorld world, ScopedQueueCoordinator result, short relativeX, short relativeZ, int x, int z, boolean isRoad) { int minY; // Math.min(world.PLOT_HEIGHT, world.ROAD_HEIGHT); if ((isRoad && Settings.Schematics.PASTE_ROAD_ON_TOP) || (!isRoad @@ -76,7 +76,7 @@ public class HybridGen extends IndependentPlotGenerator { } @Override - public void generateChunk(@Nonnull ScopedLocalBlockQueue result, @Nonnull PlotArea settings) { + public void generateChunk(@Nonnull ScopedQueueCoordinator result, @Nonnull PlotArea settings) { Preconditions.checkNotNull(result, "result cannot be null"); Preconditions.checkNotNull(settings, "settings cannot be null"); diff --git a/Core/src/main/java/com/plotsquared/core/generator/HybridPlotManager.java b/Core/src/main/java/com/plotsquared/core/generator/HybridPlotManager.java index e7fd298a0..93351b314 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/HybridPlotManager.java +++ b/Core/src/main/java/com/plotsquared/core/generator/HybridPlotManager.java @@ -34,7 +34,7 @@ import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotAreaTerrainType; import com.plotsquared.core.plot.PlotAreaType; import com.plotsquared.core.plot.PlotId; -import com.plotsquared.core.queue.LocalBlockQueue; +import com.plotsquared.core.queue.QueueCoordinator; import com.plotsquared.core.util.ChunkManager; import com.plotsquared.core.util.FileBytes; import com.plotsquared.core.util.MainUtil; @@ -47,8 +47,8 @@ import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockTypes; import lombok.Getter; -import javax.annotation.Nonnull; +import javax.annotation.Nonnull; import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -62,7 +62,7 @@ public class HybridPlotManager extends ClassicPlotManager { private final RegionManager regionManager; public HybridPlotManager(@Nonnull final HybridPlotWorld hybridPlotWorld, - @Nonnull final RegionManager regionManager) { + @Nonnull final RegionManager regionManager) { super(hybridPlotWorld, regionManager); this.hybridPlotWorld = hybridPlotWorld; this.regionManager = regionManager; @@ -106,20 +106,22 @@ public class HybridPlotManager extends ClassicPlotManager { PlotId id2 = new PlotId(id.x + 1, id.y); Location bot = getPlotBottomLocAbs(id2); Location top = getPlotTopLocAbs(id); - Location pos1 = Location.at(hybridPlotWorld.getWorldName(), top.getX() + 1, 0, bot.getZ() - 1); - Location pos2 = Location.at(hybridPlotWorld.getWorldName(), bot.getX(), - Math.min(getWorldHeight(), 255), top.getZ() + 1); + Location pos1 = + Location.at(hybridPlotWorld.getWorldName(), top.getX() + 1, 0, bot.getZ() - 1); + Location pos2 = Location + .at(hybridPlotWorld.getWorldName(), bot.getX(), Math.min(getWorldHeight(), 255), + top.getZ() + 1); MainUtil.resetBiome(hybridPlotWorld, pos1, pos2); if (!hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) { return true; } - LocalBlockQueue queue = hybridPlotWorld.getQueue(false); + QueueCoordinator queue = hybridPlotWorld.getQueue(false); createSchemAbs(queue, pos1, pos2, true); queue.enqueue(); return true; } - private void createSchemAbs(LocalBlockQueue queue, Location pos1, Location pos2, + private void createSchemAbs(QueueCoordinator queue, Location pos1, Location pos2, boolean isRoad) { int size = hybridPlotWorld.SIZE; int minY; @@ -167,14 +169,16 @@ public class HybridPlotManager extends ClassicPlotManager { PlotId id2 = new PlotId(id.x, id.y + 1); Location bot = getPlotBottomLocAbs(id2); Location top = getPlotTopLocAbs(id); - Location pos1 = Location.at(hybridPlotWorld.getWorldName(), bot.getX() - 1, 0, top.getZ() + 1); - Location pos2 = Location.at(hybridPlotWorld.getWorldName(), top.getX() + 1, - Math.min(getWorldHeight(), 255), bot.getZ()); + Location pos1 = + Location.at(hybridPlotWorld.getWorldName(), bot.getX() - 1, 0, top.getZ() + 1); + Location pos2 = Location + .at(hybridPlotWorld.getWorldName(), top.getX() + 1, Math.min(getWorldHeight(), 255), + bot.getZ()); MainUtil.resetBiome(hybridPlotWorld, pos1, pos2); if (!hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) { return true; } - LocalBlockQueue queue = hybridPlotWorld.getQueue(false); + QueueCoordinator queue = hybridPlotWorld.getQueue(false); createSchemAbs(queue, pos1, pos2, true); queue.enqueue(); return true; @@ -186,7 +190,7 @@ public class HybridPlotManager extends ClassicPlotManager { PlotId id2 = new PlotId(id.x + 1, id.y + 1); Location pos1 = getPlotTopLocAbs(id).add(1, 0, 1).withY(0); Location pos2 = getPlotBottomLocAbs(id2).withY(Math.min(getWorldHeight(), 255)); - LocalBlockQueue queue = hybridPlotWorld.getQueue(false); + QueueCoordinator queue = hybridPlotWorld.getQueue(false); createSchemAbs(queue, pos1, pos2, true); if (hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) { createSchemAbs(queue, pos1, pos2, true); @@ -228,7 +232,7 @@ public class HybridPlotManager extends ClassicPlotManager { } final BiomeType biome = hybridPlotWorld.getPlotBiome(); - final LocalBlockQueue queue = hybridPlotWorld.getQueue(false); + final QueueCoordinator queue = hybridPlotWorld.getQueue(false); ChunkManager.chunkTask(pos1, pos2, new RunnableVal() { @Override public void run(int[] value) { // If the chunk isn't near the edge and it isn't an augmented world we can just regen the whole chunk @@ -257,14 +261,14 @@ public class HybridPlotManager extends ClassicPlotManager { pastePlotSchematic(queue, bot, top); } }, () -> { - queue.enqueue(); // And notify whatever called this when plot clearing is done - PlotSquared.platform().getGlobalBlockQueue().addEmptyTask(whenDone); + queue.setCompleteTask(whenDone); + queue.enqueue(); }, 10); return true; } - public void pastePlotSchematic(LocalBlockQueue queue, Location bottom, Location top) { + public void pastePlotSchematic(QueueCoordinator queue, Location bottom, Location top) { if (!hybridPlotWorld.PLOT_SCHEMATIC) { return; } diff --git a/Core/src/main/java/com/plotsquared/core/generator/HybridUtils.java b/Core/src/main/java/com/plotsquared/core/generator/HybridUtils.java index 30586db05..46ba52cf7 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/HybridUtils.java +++ b/Core/src/main/java/com/plotsquared/core/generator/HybridUtils.java @@ -42,9 +42,9 @@ import com.plotsquared.core.plot.flag.GlobalFlagContainer; import com.plotsquared.core.plot.flag.PlotFlag; import com.plotsquared.core.plot.flag.implementations.AnalysisFlag; import com.plotsquared.core.plot.world.PlotAreaManager; -import com.plotsquared.core.queue.ChunkBlockQueue; +import com.plotsquared.core.queue.ChunkQueueCoordinator; import com.plotsquared.core.queue.GlobalBlockQueue; -import com.plotsquared.core.queue.LocalBlockQueue; +import com.plotsquared.core.queue.QueueCoordinator; import com.plotsquared.core.util.ChunkManager; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.MathMan; @@ -128,7 +128,7 @@ public class HybridUtils { * */ TaskManager.runTaskAsync(() -> { - final LocalBlockQueue queue = blockQueue.getNewQueue(world, false); + final QueueCoordinator queue = blockQueue.getNewQueue(world, false); final BlockVector3 bot = region.getMinimumPoint(); final BlockVector3 top = region.getMaximumPoint(); @@ -152,7 +152,7 @@ public class HybridUtils { } HybridPlotWorld hpw = (HybridPlotWorld) area; - ChunkBlockQueue chunk = new ChunkBlockQueue(bot, top, false); + ChunkQueueCoordinator chunk = new ChunkQueueCoordinator(bot, top, false); hpw.getGenerator().generateChunk(chunk, hpw); final BlockState[][][] oldBlocks = chunk.getBlocks(); @@ -374,7 +374,7 @@ public class HybridUtils { run.run(); } - public int checkModified(LocalBlockQueue queue, int x1, int x2, int y1, int y2, int z1, int z2, + public int checkModified(QueueCoordinator queue, int x1, int x2, int y1, int y2, int z1, int z2, BlockState[] blocks) { int count = 0; for (int y = y1; y <= y2; y++) { @@ -521,7 +521,7 @@ public class HybridUtils { public boolean setupRoadSchematic(Plot plot) { final String world = plot.getWorldName(); - final LocalBlockQueue queue = blockQueue.getNewQueue(world, false); + final QueueCoordinator queue = blockQueue.getNewQueue(world, false); Location bot = plot.getBottomAbs().subtract(1, 0, 1); Location top = plot.getTopAbs(); final HybridPlotWorld plotworld = (HybridPlotWorld) plot.getArea(); @@ -564,7 +564,7 @@ public class HybridUtils { return true; } - public int get_ey(final PlotManager pm, LocalBlockQueue queue, int sx, int ex, int sz, int ez, + public int get_ey(final PlotManager pm, QueueCoordinator queue, int sx, int ex, int sz, int ez, int sy) { int ey = sy; for (int x = sx; x <= ex; x++) { @@ -608,7 +608,7 @@ public class HybridUtils { z -= plotWorld.ROAD_OFFSET_Z; final int finalX = x; final int finalZ = z; - LocalBlockQueue queue = this.blockQueue.getNewQueue(plotWorld.getWorldName(), false); + QueueCoordinator queue = this.blockQueue.getNewQueue(plotWorld.getWorldName(), false); if (id1 == null || id2 == null || id1 != id2) { this.chunkManager.loadChunk(area.getWorldName(), chunk, false).thenRun(() -> { if (id1 != null) { diff --git a/Core/src/main/java/com/plotsquared/core/generator/IndependentPlotGenerator.java b/Core/src/main/java/com/plotsquared/core/generator/IndependentPlotGenerator.java index c42e54546..f3675ab40 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/IndependentPlotGenerator.java +++ b/Core/src/main/java/com/plotsquared/core/generator/IndependentPlotGenerator.java @@ -29,7 +29,7 @@ import com.plotsquared.core.PlotSquared; import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotId; import com.plotsquared.core.plot.SetupObject; -import com.plotsquared.core.queue.ScopedLocalBlockQueue; +import com.plotsquared.core.queue.ScopedQueueCoordinator; import com.plotsquared.core.setup.PlotAreaBuilder; /** @@ -52,9 +52,9 @@ public abstract class IndependentPlotGenerator { * @param result * @param settings */ - public abstract void generateChunk(ScopedLocalBlockQueue result, PlotArea settings); + public abstract void generateChunk(ScopedQueueCoordinator result, PlotArea settings); - public boolean populateChunk(ScopedLocalBlockQueue result, PlotArea setting) { + public boolean populateChunk(ScopedQueueCoordinator result, PlotArea setting) { return false; } @@ -75,8 +75,7 @@ public abstract class IndependentPlotGenerator { * * @param setup */ - @Deprecated - public void processSetup(SetupObject setup) { + @Deprecated public void processSetup(SetupObject setup) { } /** @@ -85,7 +84,8 @@ public abstract class IndependentPlotGenerator { * * @param builder the area builder to modify */ - public void processAreaSetup(PlotAreaBuilder builder) { } + public void processAreaSetup(PlotAreaBuilder builder) { + } /** * It is preferred for the PlotArea object to do most of the initialization necessary. diff --git a/Core/src/main/java/com/plotsquared/core/generator/SingleWorldGenerator.java b/Core/src/main/java/com/plotsquared/core/generator/SingleWorldGenerator.java index 7e2f164d3..60552ac74 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/SingleWorldGenerator.java +++ b/Core/src/main/java/com/plotsquared/core/generator/SingleWorldGenerator.java @@ -32,7 +32,7 @@ import com.plotsquared.core.plot.PlotId; import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.plot.world.SinglePlotArea; import com.plotsquared.core.plot.world.SinglePlotAreaManager; -import com.plotsquared.core.queue.ScopedLocalBlockQueue; +import com.plotsquared.core.queue.ScopedQueueCoordinator; import com.sk89q.worldedit.world.biome.BiomeTypes; import com.sk89q.worldedit.world.block.BlockTypes; import javax.annotation.Nonnull; @@ -56,7 +56,7 @@ public class SingleWorldGenerator extends IndependentPlotGenerator { return "PlotSquared:single"; } - @Override public void generateChunk(ScopedLocalBlockQueue result, PlotArea settings) { + @Override public void generateChunk(ScopedQueueCoordinator result, PlotArea settings) { SinglePlotArea area = (SinglePlotArea) settings; if (area.VOID) { Location min = result.getMin(); diff --git a/Core/src/main/java/com/plotsquared/core/plot/Plot.java b/Core/src/main/java/com/plotsquared/core/plot/Plot.java index 70f39aa08..3fa208228 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/Plot.java +++ b/Core/src/main/java/com/plotsquared/core/plot/Plot.java @@ -56,7 +56,7 @@ import com.plotsquared.core.plot.flag.PlotFlag; import com.plotsquared.core.plot.flag.implementations.KeepFlag; import com.plotsquared.core.plot.schematic.Schematic; import com.plotsquared.core.queue.GlobalBlockQueue; -import com.plotsquared.core.queue.LocalBlockQueue; +import com.plotsquared.core.queue.QueueCoordinator; import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.MathMan; @@ -75,11 +75,11 @@ import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BlockTypes; import lombok.Getter; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; import java.awt.geom.Area; import java.awt.geom.PathIterator; import java.awt.geom.Rectangle2D; @@ -123,24 +123,13 @@ import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE; */ public class Plot { - private static final Logger logger = LoggerFactory.getLogger("P2/" + Plot.class.getSimpleName()); - public static final int MAX_HEIGHT = 256; - + private static final Logger logger = + LoggerFactory.getLogger("P2/" + Plot.class.getSimpleName()); private static Set connected_cache; private static Set regions_cache; @Nonnull private final PlotId id; - - // These will be injected - @Inject private EventDispatcher eventDispatcher; - @Inject private PlotListener plotListener; - @Inject private RegionManager regionManager; - @Inject private GlobalBlockQueue blockQueue; - @Inject private WorldUtil worldUtil; - @Inject private SchematicHandler schematicHandler; - @Inject @ImpromptuPipeline private UUIDPipeline impromptuPipeline; - /** * Plot flag container */ @@ -149,7 +138,6 @@ public class Plot { * Has the plot changed since the last save cycle? */ public boolean countsTowardsMax = true; - /** * Represents whatever the database manager needs it to:
* - A value of -1 usually indicates the plot will not be stored in the DB
@@ -158,6 +146,14 @@ public class Plot { * @deprecated magical */ @Deprecated public int temp; + // These will be injected + @Inject private EventDispatcher eventDispatcher; + @Inject private PlotListener plotListener; + @Inject private RegionManager regionManager; + @Inject private GlobalBlockQueue blockQueue; + @Inject private WorldUtil worldUtil; + @Inject private SchematicHandler schematicHandler; + @Inject @ImpromptuPipeline private UUIDPipeline impromptuPipeline; /** * plot owner * (Merged plots can have multiple owners) @@ -945,9 +941,8 @@ public class Plot { if (isDelete) { this.removeSign(); } - PlotUnlinkEvent event = this.eventDispatcher - .callUnlink(getArea(), this, true, !isDelete, - isDelete ? PlotUnlinkEvent.REASON.DELETE : PlotUnlinkEvent.REASON.CLEAR); + PlotUnlinkEvent event = this.eventDispatcher.callUnlink(getArea(), this, true, !isDelete, + isDelete ? PlotUnlinkEvent.REASON.DELETE : PlotUnlinkEvent.REASON.CLEAR); if (event.getEventResult() != Result.DENY) { this.unlinkPlot(event.isCreateRoad(), event.isCreateSign()); } @@ -975,7 +970,8 @@ public class Plot { Plot current = queue.poll(); if (Plot.this.area.getTerrain() != PlotAreaTerrainType.NONE) { try { - regionManager.regenerateRegion(current.getBottomAbs(), current.getTopAbs(), false, + regionManager + .regenerateRegion(current.getBottomAbs(), current.getTopAbs(), false, this); } catch (UnsupportedOperationException exception) { MainUtil.sendMessage(null, @@ -1099,7 +1095,8 @@ public class Plot { "%plr%", name), Captions.OWNER_SIGN_LINE_4.formatted().replaceAll("%id%", id).replaceAll( "%plr%", name)}; - this.worldUtil.setSign(this.getWorldName(), location.getX(), location.getY(), location.getZ(), + this.worldUtil + .setSign(this.getWorldName(), location.getX(), location.getY(), location.getZ(), lines); } } @@ -1348,8 +1345,8 @@ public class Plot { if (Settings.Backup.DELETE_ON_UNCLAIM) { // Destroy all backups when the plot is unclaimed - Objects.requireNonNull(PlotSquared.platform()).getBackupManager().getProfile(current) - .destroy(); + Objects.requireNonNull(PlotSquared.platform()).getBackupManager() + .getProfile(current).destroy(); } getArea().removePlot(getId()); @@ -1377,7 +1374,8 @@ public class Plot { Location[] corners = getCorners(); Location top = corners[0]; Location bot = corners[1]; - Location location = Location.at(this.getWorldName(), MathMan.average(bot.getX(), top.getX()), + Location location = Location + .at(this.getWorldName(), MathMan.average(bot.getX(), top.getX()), MathMan.average(bot.getY(), top.getY()), MathMan.average(bot.getZ(), top.getZ())); if (!isLoaded()) { result.accept(location); @@ -1399,12 +1397,14 @@ public class Plot { Location[] corners = getCorners(); Location top = corners[0]; Location bot = corners[1]; - Location location = Location.at(this.getWorldName(), MathMan.average(bot.getX(), top.getX()), - MathMan.average(bot.getY(), top.getY()), MathMan.average(bot.getZ(), top.getZ())); + Location location = Location + .at(this.getWorldName(), MathMan.average(bot.getX(), top.getX()), + MathMan.average(bot.getY(), top.getY()), MathMan.average(bot.getZ(), top.getZ())); if (!isLoaded()) { return location; } - int y = this.worldUtil.getHighestBlockSynchronous(getWorldName(), location.getX(), location.getZ()); + int y = this.worldUtil + .getHighestBlockSynchronous(getWorldName(), location.getX(), location.getZ()); if (area.allowSigns()) { y = Math.max(y, getManager().getSignLoc(this).getY()); } @@ -1459,14 +1459,16 @@ public class Plot { return this.getDefaultHomeSynchronous(true); } else { Location bottom = this.getBottomAbs(); - Location location = Location.at(bottom.getWorldName(), bottom.getX() + home.getX(), - bottom.getY() + home.getY(), bottom.getZ() + home.getZ(), home.getYaw(), - home.getPitch()); + Location location = Location + .at(bottom.getWorldName(), bottom.getX() + home.getX(), bottom.getY() + home.getY(), + bottom.getZ() + home.getZ(), home.getYaw(), home.getPitch()); if (!isLoaded()) { return location; } - if (!this.worldUtil.getBlockSynchronous(location).getBlockType().getMaterial().isAir()) { - location = location.withY(Math.max(1 + this.worldUtil.getHighestBlockSynchronous(this.getWorldName(), location.getX(), + if (!this.worldUtil.getBlockSynchronous(location).getBlockType().getMaterial() + .isAir()) { + location = location.withY(Math.max(1 + this.worldUtil + .getHighestBlockSynchronous(this.getWorldName(), location.getX(), location.getZ()), bottom.getY())); } return location; @@ -1482,16 +1484,17 @@ public class Plot { this.getDefaultHome(result); } else { Location bottom = this.getBottomAbs(); - Location location = Location.at(bottom.getWorldName(), bottom.getX() + home.getX(), - bottom.getY() + home.getY(), bottom.getZ() + home.getZ(), home.getYaw(), - home.getPitch()); + Location location = Location + .at(bottom.getWorldName(), bottom.getX() + home.getX(), bottom.getY() + home.getY(), + bottom.getZ() + home.getZ(), home.getYaw(), home.getPitch()); if (!isLoaded()) { result.accept(location); return; } this.worldUtil.getBlock(location, block -> { if (!block.getBlockType().getMaterial().isAir()) { - this.worldUtil.getHighestBlock(this.getWorldName(), location.getX(), location.getZ(), + this.worldUtil + .getHighestBlock(this.getWorldName(), location.getX(), location.getZ(), y -> result.accept(location.withY(Math.max(1 + y, bottom.getY())))); } else { result.accept(location); @@ -1683,7 +1686,7 @@ public class Plot { * This should not need to be called */ public void refreshChunks() { - LocalBlockQueue queue = this.blockQueue.getNewQueue(getWorldName(), false); + QueueCoordinator queue = this.blockQueue.getNewQueue(getWorldName(), false); HashSet chunks = new HashSet<>(); for (CuboidRegion region : Plot.this.getRegions()) { for (int x = region.getMinimumPoint().getX() >> 4; @@ -1707,10 +1710,10 @@ public class Plot { return; } Location location = manager.getSignLoc(this); - LocalBlockQueue queue = this.blockQueue.getNewQueue(getWorldName(), false); + QueueCoordinator queue = this.blockQueue.getNewQueue(getWorldName(), false); queue.setBlock(location.getX(), location.getY(), location.getZ(), BlockTypes.AIR.getDefaultState()); - queue.flush(); + queue.enqueue(); } /** @@ -1721,8 +1724,8 @@ public class Plot { this.setSign("unknown"); return; } - this.impromptuPipeline.getSingle(this.getOwnerAbs(), (username, sign) -> - this.setSign(username)); + this.impromptuPipeline + .getSingle(this.getOwnerAbs(), (username, sign) -> this.setSign(username)); } /** @@ -1749,7 +1752,8 @@ public class Plot { if (updateDB) { if (!create(player.getUUID(), true)) { - logger.error("[P2] Player {} attempted to claim plot {}, but the database failed to update", + logger.error( + "[P2] Player {} attempted to claim plot {}, but the database failed to update", player.getName(), this.getId().toCommaSeparatedString()); return false; } @@ -2919,13 +2923,16 @@ public class Plot { return; } final String string = - Captions.PLOT_DEBUG.getTranslated().replace("%plot%", this.toString()).replace("%message%", message); + Captions.PLOT_DEBUG.getTranslated().replace("%plot%", this.toString()) + .replace("%message%", message); for (final PlotPlayer player : players) { - if (isOwner(player.getUUID()) || Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_DEBUG_OTHER)) { + if (isOwner(player.getUUID()) || Permissions + .hasPermission(player, Captions.PERMISSION_ADMIN_DEBUG_OTHER)) { player.sendMessage(string); } } - } catch (final Exception ignored) {} + } catch (final Exception ignored) { + } } /** @@ -2977,8 +2984,7 @@ public class Plot { Consumer resultConsumer) { Plot plot = this.getBasePlot(false); Result result = - this.eventDispatcher.callTeleport(player, player.getLocation(), plot) - .getEventResult(); + this.eventDispatcher.callTeleport(player, player.getLocation(), plot).getEventResult(); if (result == Result.DENY) { sendMessage(player, Captions.EVENT_DENIED, "Teleport"); resultConsumer.accept(false); @@ -3214,8 +3220,10 @@ public class Plot { Location[] corners = MainUtil.getCorners(getWorldName(), region); Location pos1 = corners[0]; Location pos2 = corners[1]; - Location pos3 = pos1.add(offsetX, 0, offsetZ).withWorld(destination.getWorldName()); - Location pos4 = pos2.add(offsetX, 0, offsetZ).withWorld(destination.getWorldName()); + Location pos3 = + pos1.add(offsetX, 0, offsetZ).withWorld(destination.getWorldName()); + Location pos4 = + pos2.add(offsetX, 0, offsetZ).withWorld(destination.getWorldName()); regionManager.swap(pos1, pos2, pos3, pos4, this); } } @@ -3246,7 +3254,8 @@ public class Plot { Location[] corners = MainUtil.getCorners(getWorldName(), region); final Location pos1 = corners[0]; final Location pos2 = corners[1]; - Location newPos = pos1.add(offsetX, 0, offsetZ).withWorld(destination.getWorldName()); + Location newPos = + pos1.add(offsetX, 0, offsetZ).withWorld(destination.getWorldName()); regionManager.copyRegion(pos1, pos2, newPos, task); } }.run(); @@ -3340,7 +3349,8 @@ public class Plot { Location[] corners = MainUtil.getCorners(getWorldName(), region); Location pos1 = corners[0]; Location pos2 = corners[1]; - Location newPos = pos1 .add(offsetX, 0, offsetZ).withWorld(destination.getWorldName()); + Location newPos = + pos1.add(offsetX, 0, offsetZ).withWorld(destination.getWorldName()); regionManager.copyRegion(pos1, pos2, newPos, this); } }; 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 9ad26c0aa..4aecc38d9 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java +++ b/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java @@ -27,7 +27,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.collection.QuadMap; import com.plotsquared.core.configuration.CaptionUtility; import com.plotsquared.core.configuration.Captions; @@ -49,7 +48,7 @@ import com.plotsquared.core.plot.flag.GlobalFlagContainer; import com.plotsquared.core.plot.flag.PlotFlag; import com.plotsquared.core.plot.flag.implementations.DoneFlag; import com.plotsquared.core.queue.GlobalBlockQueue; -import com.plotsquared.core.queue.LocalBlockQueue; +import com.plotsquared.core.queue.QueueCoordinator; import com.plotsquared.core.util.EconHandler; import com.plotsquared.core.util.Expression; import com.plotsquared.core.util.MainUtil; @@ -172,7 +171,7 @@ public abstract class PlotArea { @Nonnull protected abstract PlotManager createManager(); - public LocalBlockQueue getQueue(final boolean autoQueue) { + public QueueCoordinator getQueue(final boolean autoQueue) { return this.globalBlockQueue.getNewQueue(worldName, autoQueue); } diff --git a/Core/src/main/java/com/plotsquared/core/queue/AreaBoundDelegateQueueCoordinator.java b/Core/src/main/java/com/plotsquared/core/queue/AreaBoundDelegateQueueCoordinator.java index ac427471d..2d13a70e3 100644 --- a/Core/src/main/java/com/plotsquared/core/queue/AreaBoundDelegateQueueCoordinator.java +++ b/Core/src/main/java/com/plotsquared/core/queue/AreaBoundDelegateQueueCoordinator.java @@ -75,6 +75,13 @@ public class AreaBoundDelegateQueueCoordinator extends DelegateQueueCoordinator return false; } + @Override public boolean setBiome(int x, int y, int z, BiomeType biome) { + if (area.contains(x, z)) { + return super.setBiome(x, y, z, biome); + } + return false; + } + @Override public boolean setTile(int x, int y, int z, CompoundTag tag) { if (area.contains(x, z)) { return super.setTile(x, y, z, tag); diff --git a/Core/src/main/java/com/plotsquared/core/queue/BasicQueueCoordinator.java b/Core/src/main/java/com/plotsquared/core/queue/BasicQueueCoordinator.java index 3b20d17c6..3e3e8c4cf 100644 --- a/Core/src/main/java/com/plotsquared/core/queue/BasicQueueCoordinator.java +++ b/Core/src/main/java/com/plotsquared/core/queue/BasicQueueCoordinator.java @@ -99,7 +99,16 @@ public abstract class BasicQueueCoordinator extends QueueCoordinator { @Override public final boolean setBiome(int x, int z, BiomeType biomeType) { LocalChunk chunk = getChunk(x >> 4, z >> 4); - chunk.setBiome(x & 15, z & 15, biomeType); + for (int y = 0; y < 256; y++) { + chunk.setBiome(x & 15, y, z & 15, biomeType); + } + settingBiomes = true; + return true; + } + + @Override public final boolean setBiome(int x, int y, int z, BiomeType biomeType) { + LocalChunk chunk = getChunk(x >> 4, z >> 4); + chunk.setBiome(x & 15, y, z & 15, biomeType); settingBiomes = true; return true; } diff --git a/Core/src/main/java/com/plotsquared/core/queue/ChunkQueueCoordinator.java b/Core/src/main/java/com/plotsquared/core/queue/ChunkQueueCoordinator.java index e221ee7ad..820cffa61 100644 --- a/Core/src/main/java/com/plotsquared/core/queue/ChunkQueueCoordinator.java +++ b/Core/src/main/java/com/plotsquared/core/queue/ChunkQueueCoordinator.java @@ -35,11 +35,10 @@ import com.sk89q.worldedit.world.block.BlockState; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.util.Arrays; public class ChunkQueueCoordinator extends ScopedQueueCoordinator { - public final BiomeType[] biomeGrid; + public final BiomeType[][][] biomeResult; public final BlockState[][][] result; private final int width; private final int length; @@ -51,7 +50,7 @@ public class ChunkQueueCoordinator extends ScopedQueueCoordinator { this.width = top.getX() - bot.getX() + 1; this.length = top.getZ() - bot.getZ() + 1; this.result = new BlockState[256][][]; - this.biomeGrid = biomes ? new BiomeType[width * length] : null; + this.biomeResult = biomes ? new BiomeType[256][][] : null; this.bot = bot; this.top = top; } @@ -60,16 +59,19 @@ public class ChunkQueueCoordinator extends ScopedQueueCoordinator { return result; } - @Override public void fillBiome(BiomeType biomeType) { - if (biomeGrid == null) { - return; + @Override public boolean setBiome(int x, int z, BiomeType biomeType) { + if (this.biomeResult != null) { + for (int y = 0; y < 256; y++) { + this.storeCacheBiome(x, y, z, biomeType); + } + return true; } - Arrays.fill(biomeGrid, biomeType); + return false; } - @Override public boolean setBiome(int x, int z, BiomeType biomeType) { - if (this.biomeGrid != null) { - biomeGrid[(z * width) + x] = biomeType; + @Override public boolean setBiome(int x, int y, int z, BiomeType biomeType) { + if (this.biomeResult != null) { + this.storeCacheBiome(x, y, z, biomeType); return true; } return false; @@ -97,6 +99,18 @@ public class ChunkQueueCoordinator extends ScopedQueueCoordinator { resultYZ[x] = id; } + private void storeCacheBiome(final int x, final int y, final int z, final BiomeType id) { + BiomeType[][] resultY = biomeResult[y]; + if (resultY == null) { + biomeResult[y] = resultY = new BiomeType[length][]; + } + BiomeType[] resultYZ = resultY[z]; + if (resultYZ == null) { + resultY[z] = resultYZ = new BiomeType[width]; + } + resultYZ[x] = id; + } + @Override public boolean setBlock(int x, int y, int z, BaseBlock id) { this.storeCache(x, y, z, id.toImmutableState()); return true; diff --git a/Core/src/main/java/com/plotsquared/core/queue/DelegateQueueCoordinator.java b/Core/src/main/java/com/plotsquared/core/queue/DelegateQueueCoordinator.java index 9e4826f32..790ad2a51 100644 --- a/Core/src/main/java/com/plotsquared/core/queue/DelegateQueueCoordinator.java +++ b/Core/src/main/java/com/plotsquared/core/queue/DelegateQueueCoordinator.java @@ -81,6 +81,10 @@ public class DelegateQueueCoordinator extends QueueCoordinator { return parent.setBiome(x, z, biome); } + @Override public boolean setBiome(int x, int y, int z, BiomeType biome) { + return parent.setBiome(x, y, z, biome); + } + @Override public boolean isSettingBiomes() { return parent.isSettingBiomes(); } @@ -103,4 +107,8 @@ public class DelegateQueueCoordinator extends QueueCoordinator { } return false; } + + @Override public void setCompleteTask(Runnable whenDone) { + parent.setCompleteTask(whenDone); + } } diff --git a/Core/src/main/java/com/plotsquared/core/queue/GlobalBlockQueue.java b/Core/src/main/java/com/plotsquared/core/queue/GlobalBlockQueue.java index a450ef045..db80e90b1 100644 --- a/Core/src/main/java/com/plotsquared/core/queue/GlobalBlockQueue.java +++ b/Core/src/main/java/com/plotsquared/core/queue/GlobalBlockQueue.java @@ -25,6 +25,7 @@ */ package com.plotsquared.core.queue; +import com.plotsquared.core.PlotSquared; import lombok.Getter; import lombok.Setter; @@ -42,6 +43,16 @@ public class GlobalBlockQueue { this.activeQueues = new ConcurrentLinkedDeque<>(); } + public QueueCoordinator getNewQueue(String world, boolean autoQueue) { + QueueCoordinator queue = provider.getNewQueue(world); + // Auto-inject into the queue + PlotSquared.platform().getInjector().injectMembers(queue); + if (autoQueue) { + queue.enqueue(); + } + return queue; + } + /** * TODO Documentation needed. * diff --git a/Core/src/main/java/com/plotsquared/core/queue/LocationOffsetDelegateQueueCoordinator.java b/Core/src/main/java/com/plotsquared/core/queue/LocationOffsetDelegateQueueCoordinator.java index 3b067e8ca..e9766a53c 100644 --- a/Core/src/main/java/com/plotsquared/core/queue/LocationOffsetDelegateQueueCoordinator.java +++ b/Core/src/main/java/com/plotsquared/core/queue/LocationOffsetDelegateQueueCoordinator.java @@ -31,16 +31,11 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import javax.annotation.Nullable; public class LocationOffsetDelegateQueueCoordinator extends DelegateQueueCoordinator { - private static final Logger logger = LoggerFactory - .getLogger("P2/" + LocationOffsetDelegateQueueCoordinator.class.getSimpleName()); - private final boolean[][] canPlace; private final int blockX; private final int blockZ; @@ -76,8 +71,12 @@ public class LocationOffsetDelegateQueueCoordinator extends DelegateQueueCoordin return this.setBlock(x, y, z, pattern.apply(blockVector3)); } - @Override public boolean setBiome(int x, int y, BiomeType biome) { - return super.setBiome(x, y, biome); + @Override public boolean setBiome(int x, int z, BiomeType biome) { + return super.setBiome(x, z, biome); + } + + @Override public boolean setBiome(int x, int y, int z, BiomeType biome) { + return super.setBiome(x, y, z, biome); } @Override public boolean setTile(int x, int y, int z, CompoundTag tag) { diff --git a/Core/src/main/java/com/plotsquared/core/queue/OffsetQueueCoordinator.java b/Core/src/main/java/com/plotsquared/core/queue/OffsetQueueCoordinator.java index 78b945c7b..e69ea308b 100644 --- a/Core/src/main/java/com/plotsquared/core/queue/OffsetQueueCoordinator.java +++ b/Core/src/main/java/com/plotsquared/core/queue/OffsetQueueCoordinator.java @@ -42,8 +42,12 @@ public class OffsetQueueCoordinator extends DelegateQueueCoordinator { this.oz = oz; } - @Override public boolean setBiome(int x, int y, BiomeType biome) { - return super.setBiome(ox + x, oy + y, biome); + @Override public boolean setBiome(int x, int z, BiomeType biome) { + return super.setBiome(ox + x, oz + z, biome); + } + + @Override public boolean setBiome(int x, int y, int z, BiomeType biome) { + return super.setBiome(ox + x, oy + y, oz + z, biome); } @Override public boolean setBlock(int x, int y, int z, BaseBlock id) { diff --git a/Core/src/main/java/com/plotsquared/core/queue/QueueCoordinator.java b/Core/src/main/java/com/plotsquared/core/queue/QueueCoordinator.java index 7a2c8e86c..ca8b3a7c9 100644 --- a/Core/src/main/java/com/plotsquared/core/queue/QueueCoordinator.java +++ b/Core/src/main/java/com/plotsquared/core/queue/QueueCoordinator.java @@ -52,6 +52,13 @@ public abstract class QueueCoordinator { PlotSquared.platform().getInjector().injectMembers(this); } + public ScopedQueueCoordinator getForChunk(int x, int z) { + int bx = x << 4; + int bz = z << 4; + return new ScopedQueueCoordinator(this, Location.at(getWorld().getName(), bx, 0, bz), + Location.at(getWorld().getName(), bx + 15, 255, bz + 255)); + } + public abstract int size(); public abstract void setModified(long modified); @@ -78,7 +85,9 @@ public abstract class QueueCoordinator { public abstract BlockState getBlock(int x, int y, int z); - public abstract boolean setBiome(int x, int z, BiomeType biome); + @Deprecated public abstract boolean setBiome(int x, int z, BiomeType biome); + + public abstract boolean setBiome(int x, int y, int z, BiomeType biome); public abstract boolean isSettingBiomes(); @@ -92,6 +101,8 @@ public abstract class QueueCoordinator { return blockQueue.enqueue(this); } + public abstract void setCompleteTask(Runnable whenDone); + public void setCuboid(Location pos1, Location pos2, BlockState block) { int yMin = Math.min(pos1.getY(), pos2.getY()); int yMax = Math.min(255, Math.max(pos1.getY(), pos2.getY())); diff --git a/Core/src/main/java/com/plotsquared/core/queue/ScopedQueueCoordinator.java b/Core/src/main/java/com/plotsquared/core/queue/ScopedQueueCoordinator.java index f19b7caaf..6a4589b4f 100644 --- a/Core/src/main/java/com/plotsquared/core/queue/ScopedQueueCoordinator.java +++ b/Core/src/main/java/com/plotsquared/core/queue/ScopedQueueCoordinator.java @@ -64,10 +64,17 @@ public class ScopedQueueCoordinator extends DelegateQueueCoordinator { return x >= 0 && x <= dx && z >= 0 && z <= dz && super.setBiome(x + minX, z + minZ, biome); } + @Override public boolean setBiome(int x, int y, int z, BiomeType biome) { + return x >= 0 && x <= dx && y >= 0 && y <= dy && z >= 0 && z <= dz && super + .setBiome(x + minX, y + minY, z + minZ, biome); + } + public void fillBiome(BiomeType biome) { - for (int x = 0; x <= dx; x++) { - for (int z = 0; z < dz; z++) { - setBiome(x, z, biome); + for (int y = 0; y <= dy; y++) { + for (int x = 0; x <= dx; x++) { + for (int z = 0; z < dz; z++) { + setBiome(x, y, z, biome); + } } } } diff --git a/Core/src/main/java/com/plotsquared/core/util/ChunkManager.java b/Core/src/main/java/com/plotsquared/core/util/ChunkManager.java index f9809840f..7012b8fa6 100644 --- a/Core/src/main/java/com/plotsquared/core/util/ChunkManager.java +++ b/Core/src/main/java/com/plotsquared/core/util/ChunkManager.java @@ -28,8 +28,8 @@ package com.plotsquared.core.util; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.location.Location; import com.plotsquared.core.plot.Plot; -import com.plotsquared.core.queue.LocalBlockQueue; -import com.plotsquared.core.queue.ScopedLocalBlockQueue; +import com.plotsquared.core.queue.QueueCoordinator; +import com.plotsquared.core.queue.ScopedQueueCoordinator; import com.plotsquared.core.util.task.RunnableVal; import com.plotsquared.core.util.task.TaskManager; import com.sk89q.worldedit.math.BlockVector2; @@ -42,19 +42,21 @@ import java.util.concurrent.ConcurrentHashMap; public abstract class ChunkManager { - private static final Map> forceChunks = + private static final Map> forceChunks = new ConcurrentHashMap<>(); - private static final Map> addChunks = + private static final Map> addChunks = new ConcurrentHashMap<>(); - public static void setChunkInPlotArea(RunnableVal force, - RunnableVal add, String world, BlockVector2 loc) { - LocalBlockQueue queue = PlotSquared.platform().getGlobalBlockQueue().getNewQueue(world, false); - if (PlotSquared.get().getPlotAreaManager().isAugmented(world) && PlotSquared.get().isNonStandardGeneration(world, loc)) { + public static void setChunkInPlotArea(RunnableVal force, + RunnableVal add, String world, BlockVector2 loc) { + QueueCoordinator queue = + PlotSquared.platform().getGlobalBlockQueue().getNewQueue(world, false); + if (PlotSquared.get().getPlotAreaManager().isAugmented(world) && PlotSquared.get() + .isNonStandardGeneration(world, loc)) { int blockX = loc.getX() << 4; int blockZ = loc.getZ() << 4; - ScopedLocalBlockQueue scoped = - new ScopedLocalBlockQueue(queue, Location.at(world, blockX, 0, blockZ), + ScopedQueueCoordinator scoped = + new ScopedQueueCoordinator(queue, Location.at(world, blockX, 0, blockZ), Location.at(world, blockX + 15, 255, blockZ + 15)); if (force != null) { force.run(scoped); @@ -64,7 +66,7 @@ public abstract class ChunkManager { add.run(scoped); } } - queue.flush(); + queue.enqueue(); } else { if (force != null) { forceChunks.put(loc, force); @@ -76,8 +78,8 @@ public abstract class ChunkManager { } } - public static boolean preProcessChunk(BlockVector2 loc, ScopedLocalBlockQueue queue) { - final RunnableVal forceChunk = forceChunks.get(loc); + public static boolean preProcessChunk(BlockVector2 loc, ScopedQueueCoordinator queue) { + final RunnableVal forceChunk = forceChunks.get(loc); if (forceChunk != null) { forceChunk.run(queue); forceChunks.remove(loc); @@ -86,8 +88,8 @@ public abstract class ChunkManager { return false; } - public static boolean postProcessChunk(BlockVector2 loc, ScopedLocalBlockQueue queue) { - final RunnableVal addChunk = forceChunks.get(loc); + public static boolean postProcessChunk(BlockVector2 loc, ScopedQueueCoordinator queue) { + final RunnableVal addChunk = forceChunks.get(loc); if (addChunk != null) { addChunk.run(queue); addChunks.remove(loc); diff --git a/Core/src/main/java/com/plotsquared/core/util/RegionManager.java b/Core/src/main/java/com/plotsquared/core/util/RegionManager.java index 743395523..dd8a99c8d 100644 --- a/Core/src/main/java/com/plotsquared/core/util/RegionManager.java +++ b/Core/src/main/java/com/plotsquared/core/util/RegionManager.java @@ -30,7 +30,7 @@ import com.plotsquared.core.location.Location; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotManager; -import com.plotsquared.core.queue.LocalBlockQueue; +import com.plotsquared.core.queue.QueueCoordinator; import com.plotsquared.core.util.task.RunnableVal; import com.plotsquared.core.util.task.TaskManager; import com.sk89q.worldedit.function.pattern.Pattern; @@ -39,8 +39,8 @@ import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.world.biome.BiomeType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.annotation.Nonnull; +import javax.annotation.Nonnull; import java.io.File; import java.util.Collection; import java.util.HashSet; @@ -48,9 +48,15 @@ import java.util.Set; public abstract class RegionManager { - private static final Logger logger = LoggerFactory.getLogger("P2/" + RegionManager.class.getSimpleName()); + private static final Logger logger = + LoggerFactory.getLogger("P2/" + RegionManager.class.getSimpleName()); public static RegionManager manager = null; + private final ChunkManager chunkManager; + + public RegionManager(@Nonnull final ChunkManager chunkManager) { + this.chunkManager = chunkManager; + } public static BlockVector2 getRegion(Location location) { int x = location.getX() >> 9; @@ -58,12 +64,6 @@ public abstract class RegionManager { return BlockVector2.at(x, z); } - private final ChunkManager chunkManager; - - public RegionManager(@Nonnull final ChunkManager chunkManager) { - this.chunkManager = chunkManager; - } - public void largeRegionTask(final String world, final CuboidRegion region, final RunnableVal task, final Runnable whenDone) { TaskManager.runTaskAsync(() -> { @@ -96,8 +96,7 @@ public abstract class RegionManager { } TaskManager.objectTask(chunks, new RunnableVal() { @Override public void run(BlockVector2 value) { - chunkManager.loadChunk(world, value, false) - .thenRun(() -> task.run(value)); + chunkManager.loadChunk(world, value, false).thenRun(() -> task.run(value)); } }, whenDone); }); @@ -164,7 +163,7 @@ public abstract class RegionManager { public boolean setCuboids(final PlotArea area, final Set regions, final Pattern blocks, int minY, int maxY) { - LocalBlockQueue queue = area.getQueue(false); + QueueCoordinator queue = area.getQueue(false); for (CuboidRegion region : regions) { Location pos1 = Location.at(area.getWorldName(), region.getMinimumPoint().getX(), minY, region.getMinimumPoint().getZ()); diff --git a/Core/src/main/java/com/plotsquared/core/util/SchematicHandler.java b/Core/src/main/java/com/plotsquared/core/util/SchematicHandler.java index 7f933df24..07cc0c618 100644 --- a/Core/src/main/java/com/plotsquared/core/util/SchematicHandler.java +++ b/Core/src/main/java/com/plotsquared/core/util/SchematicHandler.java @@ -32,7 +32,7 @@ import com.plotsquared.core.location.Location; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.schematic.Schematic; -import com.plotsquared.core.queue.LocalBlockQueue; +import com.plotsquared.core.queue.QueueCoordinator; import com.plotsquared.core.util.task.RunnableVal; import com.plotsquared.core.util.task.TaskManager; import com.sk89q.jnbt.ByteArrayTag; @@ -58,12 +58,12 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; -import javax.annotation.Nonnull; import org.json.JSONArray; import org.json.JSONException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.annotation.Nonnull; import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.File; @@ -96,12 +96,11 @@ import java.util.zip.GZIPOutputStream; public abstract class SchematicHandler { - private static final Logger logger = LoggerFactory.getLogger("P2/" + SchematicHandler.class.getSimpleName()); + private static final Logger logger = + LoggerFactory.getLogger("P2/" + SchematicHandler.class.getSimpleName()); public static SchematicHandler manager; - - private boolean exportAll = false; - private final WorldUtil worldUtil; + private boolean exportAll = false; public SchematicHandler(@Nonnull final WorldUtil worldUtil) { this.worldUtil = worldUtil; @@ -158,7 +157,8 @@ public abstract class SchematicHandler { @Override public void run(final CompoundTag value) { if (value != null) { TaskManager.runTaskAsync(() -> { - boolean result = save(value, directory + File.separator + name + ".schem"); + boolean result = + save(value, directory + File.separator + name + ".schem"); if (!result) { logger.error("[P2] Failed to save {}", plot.getId()); } @@ -193,7 +193,7 @@ public abstract class SchematicHandler { return; } try { - final LocalBlockQueue queue = plot.getArea().getQueue(false); + final QueueCoordinator queue = plot.getArea().getQueue(false); BlockVector3 dimension = schematic.getClipboard().getDimensions(); final int WIDTH = dimension.getX(); final int LENGTH = dimension.getZ(); @@ -219,7 +219,7 @@ public abstract class SchematicHandler { if (pw instanceof ClassicPlotWorld) { y_offset_actual = yOffset + ((ClassicPlotWorld) pw).PLOT_HEIGHT; } else { - y_offset_actual = yOffset + 1 + this.worldUtil + y_offset_actual = yOffset + 1 + this.worldUtil .getHighestBlockSynchronous(plot.getWorldName(), region.getMinimumPoint().getX() + 1, region.getMinimumPoint().getZ() + 1); @@ -229,8 +229,9 @@ public abstract class SchematicHandler { y_offset_actual = yOffset; } - final Location pos1 = Location.at(plot.getWorldName(), region.getMinimumPoint().getX() + xOffset, y_offset_actual, - region.getMinimumPoint().getZ() + zOffset); + final Location pos1 = Location + .at(plot.getWorldName(), region.getMinimumPoint().getX() + xOffset, + y_offset_actual, region.getMinimumPoint().getZ() + zOffset); final Location pos2 = pos1.add(WIDTH - 1, HEIGHT - 1, LENGTH - 1); final int p1x = pos1.getX(); @@ -300,7 +301,7 @@ public abstract class SchematicHandler { }); } - public abstract boolean restoreTile(LocalBlockQueue queue, CompoundTag tag, int x, int y, + public abstract boolean restoreTile(QueueCoordinator queue, CompoundTag tag, int x, int y, int z); /**