Address some deprecations for regions and biome setting

This commit is contained in:
dordsor21 2022-02-07 13:57:10 +00:00 committed by Jordan
parent c4db968830
commit c8327bfa40
11 changed files with 40 additions and 96 deletions

View File

@ -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);

View File

@ -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<BlockState>().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));

View File

@ -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);
}

View File

@ -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<PlotArea> areas = this.plotAreaManager.getPlotAreasSet(area.getWorldName(), region);
if (!areas.isEmpty()) {
player.sendMessage(

View File

@ -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;
}

View File

@ -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<PlotArea> areas = PlotSquared.get().getPlotAreaManager().getPlotAreasSet(world, region);
if (areas.isEmpty()) {

View File

@ -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);
}
}

View File

@ -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;
}

View File

@ -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());

View File

@ -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();

View File

@ -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