mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-25 22:56:45 +01:00
Convert all PlotBlocks to BaseBlocks in the BasicLocalBlockQueue
The `BukkitLocalQueue` only supports using one of the sets (the removed `baseBlocks` variable in `BasicLocalBlockQueue` was the deciding factor for which one won out) which led to issues with missing blocks when trying to use both types at the same time, such as in the `HybridPlotManager`s `clearPlot` method, where `PlotBlock` is used to fill in the various layers, while the`createSchemAbs` method uses `BaseBlock` for its data.
This commit is contained in:
parent
427523644c
commit
941821e453
@ -70,11 +70,7 @@ public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> {
|
||||
}
|
||||
|
||||
@Override public final void setComponents(LocalChunk<T> lc) {
|
||||
if (isBaseBlocks()) {
|
||||
setBaseBlocks(lc);
|
||||
} else {
|
||||
setBlocks(lc);
|
||||
}
|
||||
setBaseBlocks(lc);
|
||||
}
|
||||
|
||||
public World getBukkitWorld() {
|
||||
@ -85,30 +81,6 @@ public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> {
|
||||
return getBukkitWorld().getChunkAt(x, z);
|
||||
}
|
||||
|
||||
public void setBlocks(LocalChunk<T> lc) {
|
||||
World worldObj = Bukkit.getWorld(getWorld());
|
||||
Chunk chunk = worldObj.getChunkAt(lc.getX(), lc.getZ());
|
||||
chunk.load(true);
|
||||
for (int layer = 0; layer < lc.blocks.length; layer++) {
|
||||
PlotBlock[] blocksLayer = (PlotBlock[]) lc.blocks[layer];
|
||||
if (blocksLayer != null) {
|
||||
for (int j = 0; j < blocksLayer.length; j++) {
|
||||
if (blocksLayer[j] != null) {
|
||||
PlotBlock block = blocksLayer[j];
|
||||
int x = MainUtil.x_loc[layer][j];
|
||||
int y = MainUtil.y_loc[layer][j];
|
||||
int z = MainUtil.z_loc[layer][j];
|
||||
Block existing = chunk.getBlock(x, y, z);
|
||||
if (equals(block, existing)) {
|
||||
continue;
|
||||
}
|
||||
setMaterial(block, existing);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setBaseBlocks(LocalChunk<T> lc) {
|
||||
World worldObj = Bukkit.getWorld(getWorld());
|
||||
Chunk chunk = worldObj.getChunkAt(lc.getX(), lc.getZ());
|
||||
|
@ -1,11 +1,15 @@
|
||||
package com.github.intellectualsites.plotsquared.plot.util.block;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.plot.object.LegacyPlotBlock;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotBlock;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.StringPlotBlock;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.MathMan;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@ -20,7 +24,6 @@ public abstract class BasicLocalBlockQueue<T> extends LocalBlockQueue {
|
||||
private LocalChunk lastWrappedChunk;
|
||||
private int lastX = Integer.MIN_VALUE;
|
||||
private int lastZ = Integer.MIN_VALUE;
|
||||
@Getter private boolean baseBlocks = false;
|
||||
|
||||
public BasicLocalBlockQueue(String world) {
|
||||
super(world);
|
||||
@ -91,13 +94,12 @@ public abstract class BasicLocalBlockQueue<T> extends LocalBlockQueue {
|
||||
if ((y > 255) || (y < 0)) {
|
||||
return false;
|
||||
}
|
||||
baseBlocks = true;
|
||||
int chunkX = x >> 4;
|
||||
int chunkZ = z >> 4;
|
||||
if (chunkX != lastX || chunkZ != lastZ) {
|
||||
lastX = chunkX;
|
||||
lastZ = chunkZ;
|
||||
long pair = (long) (chunkX) << 32 | (chunkZ) & 0xFFFFFFFFL;
|
||||
int cx = x >> 4;
|
||||
int cz = z >> 4;
|
||||
if (cx != lastX || cz != lastZ) {
|
||||
lastX = cx;
|
||||
lastZ = cz;
|
||||
long pair = (long) (cx) << 32 | (cz) & 0xFFFFFFFFL;
|
||||
lastWrappedChunk = this.blockChunks.get(pair);
|
||||
if (lastWrappedChunk == null) {
|
||||
lastWrappedChunk = this.getLocalChunk(x >> 4, z >> 4);
|
||||
@ -116,32 +118,18 @@ public abstract class BasicLocalBlockQueue<T> extends LocalBlockQueue {
|
||||
}
|
||||
|
||||
@Override public boolean setBlock(int x, int y, int z, PlotBlock id) {
|
||||
if (y > 255) {
|
||||
return false;
|
||||
} else if (y < 0) {
|
||||
return false;
|
||||
// Trying to mix PlotBlock and BaseBlock leads to all kinds of issues.
|
||||
// Since BaseBlock has more features than PlotBlock, simply convert
|
||||
// all PlotBlocks to BaseBlocks
|
||||
if (id instanceof StringPlotBlock) {
|
||||
StringPlotBlock stringPlotBlock = (StringPlotBlock) id;
|
||||
return setBlock(x, y, z, BlockTypes.get(stringPlotBlock.getItemId()).getDefaultState().toBaseBlock());
|
||||
} else if (id instanceof LegacyPlotBlock) {
|
||||
LegacyPlotBlock legacyPlotBlock = (LegacyPlotBlock) id;
|
||||
return setBlock(x, y, z, LegacyMapper.getInstance().getBlockFromLegacy(legacyPlotBlock.getId(), legacyPlotBlock.getData()).toBaseBlock());
|
||||
} else {
|
||||
throw new RuntimeException("Unknown PlotBock class: " + id.getClass().getName());
|
||||
}
|
||||
int chunkX = x >> 4;
|
||||
int chunkZ = z >> 4;
|
||||
if (chunkX != lastX || chunkZ != lastZ) {
|
||||
lastX = chunkX;
|
||||
lastZ = chunkZ;
|
||||
long pair = (long) (chunkX) << 32 | (chunkZ) & 0xFFFFFFFFL;
|
||||
lastWrappedChunk = this.blockChunks.get(pair);
|
||||
if (lastWrappedChunk == null) {
|
||||
lastWrappedChunk = this.getLocalChunk(x >> 4, z >> 4);
|
||||
lastWrappedChunk.setBlock(x & 15, y, z & 15, id);
|
||||
LocalChunk previous = this.blockChunks.put(pair, lastWrappedChunk);
|
||||
if (previous == null) {
|
||||
chunks.add(lastWrappedChunk);
|
||||
return true;
|
||||
}
|
||||
this.blockChunks.put(pair, previous);
|
||||
lastWrappedChunk = previous;
|
||||
}
|
||||
}
|
||||
lastWrappedChunk.setBlock(x & 15, y, z & 15, id);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public final boolean setBiome(int x, int z, String biome) {
|
||||
@ -186,7 +174,6 @@ public abstract class BasicLocalBlockQueue<T> extends LocalBlockQueue {
|
||||
public final int z;
|
||||
public final int x;
|
||||
|
||||
public B[] blocks;
|
||||
public BaseBlock[][] baseblocks;
|
||||
public String[][] biomes;
|
||||
|
||||
@ -213,8 +200,6 @@ public abstract class BasicLocalBlockQueue<T> extends LocalBlockQueue {
|
||||
return z;
|
||||
}
|
||||
|
||||
public abstract void setBlock(final int x, final int y, final int z, final PlotBlock block);
|
||||
|
||||
public abstract void setBlock(final int x, final int y, final int z, final BaseBlock block);
|
||||
|
||||
public void setBiome(int x, int z, String biome) {
|
||||
@ -241,24 +226,9 @@ public abstract class BasicLocalBlockQueue<T> extends LocalBlockQueue {
|
||||
public class BasicLocalChunk extends LocalChunk<PlotBlock[]> {
|
||||
public BasicLocalChunk(BasicLocalBlockQueue parent, int x, int z) {
|
||||
super(parent, x, z);
|
||||
blocks = new PlotBlock[16][];
|
||||
baseblocks = new BaseBlock[16][];
|
||||
}
|
||||
|
||||
@Override public void setBlock(int x, int y, int z, PlotBlock block) {
|
||||
this.setInternal(x, y, z, block);
|
||||
}
|
||||
|
||||
private void setInternal(final int x, final int y, final int z, final PlotBlock plotBlock) {
|
||||
final int i = MainUtil.CACHE_I[y][x][z];
|
||||
final int j = MainUtil.CACHE_J[y][x][z];
|
||||
PlotBlock[] array = blocks[i];
|
||||
if (array == null) {
|
||||
array = (blocks[i] = new PlotBlock[4096]);
|
||||
}
|
||||
array[j] = plotBlock;
|
||||
}
|
||||
|
||||
@Override public void setBlock(int x, int y, int z, BaseBlock block) {
|
||||
this.setInternal(x, y, z, block);
|
||||
}
|
||||
@ -272,10 +242,5 @@ public abstract class BasicLocalBlockQueue<T> extends LocalBlockQueue {
|
||||
}
|
||||
array[j] = baseBlock;
|
||||
}
|
||||
|
||||
public void setBlock(final int x, final int y, final int z, final int id, final int data) {
|
||||
final PlotBlock block = PlotBlock.get(id, data);
|
||||
this.setInternal(x, y, z, block);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user