From c8327bfa4024361b2be576a48d8f2d6b1c19e248 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Mon, 7 Feb 2022 13:57:10 +0000 Subject: [PATCH] Address some deprecations for regions and biome setting --- .../bukkit/util/BukkitRegionManager.java | 5 ++- .../plotsquared/bukkit/util/BukkitUtil.java | 23 ------------ .../plotsquared/bukkit/util/ContentMap.java | 21 ++++------- .../com/plotsquared/core/command/Area.java | 3 +- .../com/plotsquared/core/command/Trim.java | 4 +-- .../core/generator/AugmentedUtils.java | 2 +- .../core/generator/HybridPlotManager.java | 2 +- .../plotsquared/core/plot/PlotCluster.java | 6 +++- .../plotsquared/core/util/RegionManager.java | 28 ++------------- .../com/plotsquared/core/util/WEManager.java | 6 ++-- .../com/plotsquared/core/util/WorldUtil.java | 36 +++++++++---------- 11 files changed, 40 insertions(+), 96 deletions(-) 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 c36f1db5e..0855de4bc 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitRegionManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitRegionManager.java @@ -40,7 +40,6 @@ import com.plotsquared.core.queue.QueueCoordinator; import com.plotsquared.core.queue.ScopedQueueCoordinator; import com.plotsquared.core.util.ChunkManager; import com.plotsquared.core.util.RegionManager; -import com.plotsquared.core.util.RegionUtil; import com.plotsquared.core.util.WorldUtil; import com.plotsquared.core.util.entity.EntityCategories; import com.plotsquared.core.util.task.RunnableVal; @@ -261,7 +260,7 @@ public class BukkitRegionManager extends RegionManager { if (checkX2 && checkZ2) { map.saveRegion(world, xxt2, xxt, zzt2, zzt); // } - CuboidRegion currentPlotClear = RegionUtil.createRegion(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ()); + CuboidRegion currentPlotClear = new CuboidRegion(pos1.getBlockVector3(), pos2.getBlockVector3()); map.saveEntitiesOut(Bukkit.getWorld(world.getName()).getChunkAt(x, z), currentPlotClear); AugmentedUtils.bypass( ignoreAugment, @@ -300,7 +299,7 @@ public class BukkitRegionManager extends RegionManager { }, world.getName(), chunk) ); //map.restoreBlocks(worldObj, 0, 0); - map.restoreEntities(Bukkit.getWorld(world.getName()), 0, 0); + map.restoreEntities(Bukkit.getWorld(world.getName())); }); regenQueue.setCompleteTask(whenDone); queue.setCompleteTask(regenQueue::enqueue); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java index 63638d541..e22fa5f9d 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java @@ -44,7 +44,6 @@ import com.plotsquared.core.util.task.TaskManager; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.BukkitWorld; import com.sk89q.worldedit.math.BlockVector2; -import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BlockCategories; import com.sk89q.worldedit.world.block.BlockState; @@ -61,7 +60,6 @@ import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Material; import org.bukkit.World; -import org.bukkit.block.Biome; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.Sign; @@ -386,27 +384,6 @@ public class BukkitUtil extends WorldUtil { return new StringComparison().new ComparisonResult(1, state); } - @Override - public void setBiomes( - final @NonNull String worldName, - final @NonNull CuboidRegion region, - final @NonNull BiomeType biomeType - ) { - final World world = getWorld(worldName); - if (world == null) { - LOGGER.warn("An error occurred while setting the biome because the world was null", new RuntimeException()); - return; - } - final Biome biome = BukkitAdapter.adapt(biomeType); - for (int x = region.getMinimumPoint().getX(); x <= region.getMaximumPoint().getX(); x++) { - for (int z = region.getMinimumPoint().getZ(); z <= region.getMaximumPoint().getZ(); z++) { - if (world.getBiome(x, z) != biome) { - world.setBiome(x, z, biome); - } - } - } - } - @Override public com.sk89q.worldedit.world.@NonNull World getWeWorld(final @NonNull String world) { return new BukkitWorld(Bukkit.getWorld(world)); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/ContentMap.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/ContentMap.java index 0a9130e0c..b4b63abcb 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/ContentMap.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/ContentMap.java @@ -70,7 +70,7 @@ public class ContentMap { } for (int x = x1; x <= x2; x++) { for (int z = z1; z <= z2; z++) { - saveBlocks(world, x, z, 0, 0); + saveBlocks(world, x, z); } } } @@ -92,14 +92,7 @@ public class ContentMap { } } - void saveEntitiesIn(Chunk chunk, CuboidRegion region) { - saveEntitiesIn(chunk, region, 0, 0, false); - } - - void saveEntitiesIn( - Chunk chunk, CuboidRegion region, int offsetX, int offsetZ, - boolean delete - ) { + void saveEntitiesIn(Chunk chunk, CuboidRegion region, boolean delete) { for (Entity entity : chunk.getEntities()) { Location location = BukkitUtil.adapt(entity.getLocation()); int x = location.getX(); @@ -111,8 +104,6 @@ public class ContentMap { continue; } EntityWrapper wrap = new ReplicatingEntityWrapper(entity, (short) 2); - wrap.x += offsetX; - wrap.z += offsetZ; wrap.saveEntity(); this.entities.add(wrap); if (delete) { @@ -123,10 +114,10 @@ public class ContentMap { } } - void restoreEntities(World world, int xOffset, int zOffset) { + void restoreEntities(World world) { for (EntityWrapper entity : this.entities) { try { - entity.spawn(world, xOffset, zOffset); + entity.spawn(world, 0, 0); } catch (Exception e) { LOGGER.error("Failed to restore entity", e); } @@ -134,13 +125,13 @@ public class ContentMap { this.entities.clear(); } - private void saveBlocks(BukkitWorld world, int x, int z, int offsetX, int offsetZ) { + private void saveBlocks(BukkitWorld world, int x, int z) { BaseBlock[] ids = new BaseBlock[world.getMaxY() - world.getMinY() + 1]; for (short yIndex = 0; yIndex <= world.getMaxY() - world.getMinY(); yIndex++) { BaseBlock block = world.getFullBlock(BlockVector3.at(x, yIndex + world.getMinY(), z)); ids[yIndex] = block; } - PlotLoc loc = new PlotLoc(x + offsetX, z + offsetZ); + PlotLoc loc = new PlotLoc(x, z); this.allBlocks.put(loc, ids); } diff --git a/Core/src/main/java/com/plotsquared/core/command/Area.java b/Core/src/main/java/com/plotsquared/core/command/Area.java index e43f472b2..57552048d 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Area.java +++ b/Core/src/main/java/com/plotsquared/core/command/Area.java @@ -371,7 +371,8 @@ public class Area extends SubCommand { int lower = (area.ROAD_WIDTH & 1) == 0 ? area.ROAD_WIDTH / 2 - 1 : area.ROAD_WIDTH / 2; final int offsetX = bx - (area.ROAD_WIDTH == 0 ? 0 : lower); final int offsetZ = bz - (area.ROAD_WIDTH == 0 ? 0 : lower); - final CuboidRegion region = RegionUtil.createRegion(bx, tx, bz, tz); + // Height doesn't matter for this region + final CuboidRegion region = RegionUtil.createRegion(bx, tx, 0, 0, bz, tz); final Set areas = this.plotAreaManager.getPlotAreasSet(area.getWorldName(), region); if (!areas.isEmpty()) { player.sendMessage( 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 01c7b8ff5..c31f020cd 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Trim.java +++ b/Core/src/main/java/com/plotsquared/core/command/Trim.java @@ -180,12 +180,12 @@ public class Trim extends SubCommand { int bx = cbx << 4; int bz = cbz << 4; CuboidRegion region = - RegionUtil.createRegion(bx, bx + 511, bz, bz + 511); + RegionUtil.createRegion(bx, bx + 511, 0, 0, bz, bz + 511); for (Plot plot : PlotQuery.newQuery().inWorld(world)) { Location bot = plot.getBottomAbs(); Location top = plot.getExtendedTopAbs(); CuboidRegion plotReg = RegionUtil - .createRegion(bot.getX(), top.getX(), bot.getZ(), top.getZ()); + .createRegion(bot.getX(), top.getX(), 0, 0, bot.getZ(), top.getZ()); if (!RegionUtil.intersects(region, plotReg)) { continue; } 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 965b61a43..42609669e 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/AugmentedUtils.java +++ b/Core/src/main/java/com/plotsquared/core/generator/AugmentedUtils.java @@ -70,7 +70,7 @@ public class AugmentedUtils { final int blockZ = chunkZ << 4; // Create a region that contains the // entire chunk - CuboidRegion region = RegionUtil.createRegion(blockX, blockX + 15, blockZ, blockZ + 15); + CuboidRegion region = RegionUtil.createRegion(blockX, blockX + 15, 0, 0, blockZ, blockZ + 15); // Query for plot areas in the chunk final Set areas = PlotSquared.get().getPlotAreaManager().getPlotAreasSet(world, region); if (areas.isEmpty()) { 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 1d1fcc71b..2f8cc16ec 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/HybridPlotManager.java +++ b/Core/src/main/java/com/plotsquared/core/generator/HybridPlotManager.java @@ -148,7 +148,7 @@ public class HybridPlotManager extends ClassicPlotManager { (pos1.getX() + pos2.getX()) / 2, (pos1.getZ() + pos2.getZ()) / 2 ), biome)) { - WorldUtil.setBiome(hybridPlotWorld, pos1.getX(), pos1.getZ(), pos2.getX(), pos2.getZ(), biome); + WorldUtil.setBiome(hybridPlotWorld.getWorldName(), new CuboidRegion(pos1.getBlockVector3(), pos2.getBlockVector3()), biome); } } diff --git a/Core/src/main/java/com/plotsquared/core/plot/PlotCluster.java b/Core/src/main/java/com/plotsquared/core/plot/PlotCluster.java index faa2fd16b..294ebc715 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/PlotCluster.java +++ b/Core/src/main/java/com/plotsquared/core/plot/PlotCluster.java @@ -89,11 +89,15 @@ public class PlotCluster { } private void setRegion() { - this.region = RegionUtil.createRegion(this.pos1.getX(), this.pos2.getX(), + this.region = RegionUtil.createRegion(this.pos1.getX(), this.pos2.getX(), 0, 0, this.pos1.getY(), this.pos2.getY() ); } + /** + * Returns a region of PlotIDs + */ + @Deprecated public CuboidRegion getRegion() { return this.region; } 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 606809291..87ca3708e 100644 --- a/Core/src/main/java/com/plotsquared/core/util/RegionManager.java +++ b/Core/src/main/java/com/plotsquared/core/util/RegionManager.java @@ -407,36 +407,12 @@ public abstract class RegionManager { final PlotArea area, final Runnable whenDone ) { - Location pos1 = Location - .at( - area.getWorldName(), - region.getMinimumPoint().getX() - extendBiome, - region.getMinimumPoint().getY(), - region.getMinimumPoint().getZ() - extendBiome - ); - Location pos2 = Location - .at( - area.getWorldName(), - region.getMaximumPoint().getX() + extendBiome, - region.getMaximumPoint().getY(), - region.getMaximumPoint().getZ() + extendBiome - ); final QueueCoordinator queue = blockQueue.getNewQueue(worldUtil.getWeWorld(area.getWorldName())); - - final int minX = pos1.getX(); - final int minZ = pos1.getZ(); - final int maxX = pos2.getX(); - final int maxZ = pos2.getZ(); queue.addReadChunks(region.getChunks()); queue.setChunkConsumer(blockVector2 -> { - final int cx = blockVector2.getX() << 4; - final int cz = blockVector2.getZ() << 4; WorldUtil.setBiome( - area, - Math.max(minX, cx), - Math.max(minZ, cz), - Math.min(maxX, cx + 15), - Math.min(maxZ, cz + 15), + area.getWorldName(), + region, biome ); worldUtil.refreshChunk(blockVector2.getBlockX(), blockVector2.getBlockZ(), area.getWorldName()); diff --git a/Core/src/main/java/com/plotsquared/core/util/WEManager.java b/Core/src/main/java/com/plotsquared/core/util/WEManager.java index 2ae4e38b7..9ef38e1f4 100644 --- a/Core/src/main/java/com/plotsquared/core/util/WEManager.java +++ b/Core/src/main/java/com/plotsquared/core/util/WEManager.java @@ -25,6 +25,7 @@ */ package com.plotsquared.core.util; +import com.fastasyncworldedit.core.regions.RegionWrapper; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.location.Location; @@ -91,10 +92,7 @@ public class WEManager { Location location = player.getLocation(); String world = location.getWorldName(); if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) { - regions.add(RegionUtil - .createRegion(Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE, - Integer.MAX_VALUE - )); + regions.add(RegionWrapper.GLOBAL()); return regions; } PlotArea area = player.getApplicablePlotArea(); diff --git a/Core/src/main/java/com/plotsquared/core/util/WorldUtil.java b/Core/src/main/java/com/plotsquared/core/util/WorldUtil.java index b5102c2c3..a26f43793 100644 --- a/Core/src/main/java/com/plotsquared/core/util/WorldUtil.java +++ b/Core/src/main/java/com/plotsquared/core/util/WorldUtil.java @@ -30,7 +30,6 @@ import com.plotsquared.core.configuration.caption.Caption; import com.plotsquared.core.location.Location; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; -import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.util.task.RunnableVal; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.IntTag; @@ -40,6 +39,7 @@ import com.sk89q.jnbt.Tag; import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; +import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; @@ -79,12 +79,13 @@ public abstract class WorldUtil { * @param p2x Max X * @param p2z Max Z * @param biome Biome - * @deprecated use {@link WorldUtil#setBiome(PlotArea, int, int, int, int, BiomeType)} + * @deprecated use {@link WorldUtil#setBiome(String, CuboidRegion, BiomeType)} */ @Deprecated(forRemoval = true) public static void setBiome(String world, int p1x, int p1z, int p2x, int p2z, BiomeType biome) { - BlockVector3 pos1 = BlockVector2.at(p1x, p1z).toBlockVector3(); - BlockVector3 pos2 = BlockVector2.at(p2x, p2z).toBlockVector3(255); + World weWorld = PlotSquared.platform().worldUtil().getWeWorld(world); + BlockVector3 pos1 = BlockVector2.at(p1x, p1z).toBlockVector3(weWorld.getMinY()); + BlockVector3 pos2 = BlockVector2.at(p2x, p2z).toBlockVector3(weWorld.getMaxY()); CuboidRegion region = new CuboidRegion(pos1, pos2); PlotSquared.platform().worldUtil().setBiomes(world, region, biome); } @@ -92,19 +93,13 @@ public abstract class WorldUtil { /** * Set the biome in a region * - * @param area Plot area - * @param p1x Min X - * @param p1z Min Z - * @param p2x Max X - * @param p2z Max Z - * @param biome Biome + * @param world World name + * @param region Region + * @param biome Biome * @since TODO */ - public static void setBiome(PlotArea area, int p1x, int p1z, int p2x, int p2z, BiomeType biome) { - BlockVector3 pos1 = BlockVector2.at(p1x, p1z).toBlockVector3(area.getMinGenHeight()); - BlockVector3 pos2 = BlockVector2.at(p2x, p2z).toBlockVector3(area.getMaxGenHeight()); - CuboidRegion region = new CuboidRegion(pos1, pos2); - PlotSquared.platform().worldUtil().setBiomes(area.getWorldName(), region, biome); + public static void setBiome(String world, final CuboidRegion region, BiomeType biome) { + PlotSquared.platform().worldUtil().setBiomes(world, region, biome); } /** @@ -238,11 +233,14 @@ public abstract class WorldUtil { /** * Set the biome in a region * - * @param world World name - * @param region Region - * @param biome New biome + * @param worldName World name + * @param region Region + * @param biome New biome */ - public abstract void setBiomes(@NonNull String world, @NonNull CuboidRegion region, @NonNull BiomeType biome); + public void setBiomes(@NonNull String worldName, @NonNull CuboidRegion region, @NonNull BiomeType biome) { + final World world = getWeWorld(worldName); + region.iterator().forEachRemaining(bv -> world.setBiome(bv, biome)); + } /** * Get the WorldEdit {@link com.sk89q.worldedit.world.World} corresponding to a world name