mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-25 10:14:42 +02:00
Add wna block setting, use WorldEdit worlds rather than Strings.
This commit is contained in:
@ -28,26 +28,31 @@ package com.plotsquared.core.queue;
|
||||
import com.plotsquared.core.util.PatternUtil;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import lombok.Getter;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public abstract class BasicQueueCoordinator extends QueueCoordinator {
|
||||
|
||||
private final String world;
|
||||
private final ConcurrentHashMap<Long, LocalChunk> blockChunks = new ConcurrentHashMap<>();
|
||||
private final World world;
|
||||
@Getter private final ConcurrentHashMap<BlockVector2, LocalChunk> blockChunks =
|
||||
new ConcurrentHashMap<>();
|
||||
private long modified;
|
||||
private LocalChunk lastWrappedChunk;
|
||||
private int lastX = Integer.MIN_VALUE;
|
||||
private int lastZ = Integer.MIN_VALUE;
|
||||
private boolean setbiome = false;
|
||||
@Getter private boolean settingBiomes = false;
|
||||
@Getter private boolean settingTiles = false;
|
||||
|
||||
private GlobalBlockQueue globalBlockQueue;
|
||||
|
||||
public BasicQueueCoordinator(String world) {
|
||||
public BasicQueueCoordinator(World world) {
|
||||
this.world = world;
|
||||
this.modified = System.currentTimeMillis();
|
||||
}
|
||||
@ -60,7 +65,7 @@ public abstract class BasicQueueCoordinator extends QueueCoordinator {
|
||||
|
||||
@Override public abstract BlockState getBlock(int x, int y, int z);
|
||||
|
||||
@Override public final String getWorld() {
|
||||
@Override public final World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
@ -95,32 +100,29 @@ 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);
|
||||
setbiome = true;
|
||||
settingBiomes = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public final boolean setTile(int x, int y, int z, CompoundTag tag) {
|
||||
LocalChunk chunk = getChunk(x >> 4, z >> 4);
|
||||
chunk.setTile(x, y, z, tag);
|
||||
settingTiles = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public final boolean settingBiome() {
|
||||
return setbiome;
|
||||
}
|
||||
|
||||
public final void setChunk(LocalChunk chunk) {
|
||||
this.blockChunks.put(chunk.longHash(), chunk);
|
||||
this.blockChunks.put(BlockVector2.at(chunk.getX(), chunk.getZ()), chunk);
|
||||
}
|
||||
|
||||
private LocalChunk getChunk(final int chunkX, final int ChunkZ) {
|
||||
if (chunkX != lastX || ChunkZ != lastZ) {
|
||||
private LocalChunk getChunk(final int chunkX, final int chunkZ) {
|
||||
if (chunkX != lastX || chunkZ != lastZ) {
|
||||
lastX = chunkX;
|
||||
lastZ = ChunkZ;
|
||||
long pair = (long) (chunkX) << 32 | (ChunkZ) & 0xFFFFFFFFL;
|
||||
lastZ = chunkZ;
|
||||
BlockVector2 pair = BlockVector2.at(chunkX, chunkZ);
|
||||
lastWrappedChunk = this.blockChunks.get(pair);
|
||||
if (lastWrappedChunk == null) {
|
||||
lastWrappedChunk = this.getLocalChunk(chunkX, ChunkZ);
|
||||
lastWrappedChunk = this.getLocalChunk(chunkX, chunkZ);
|
||||
LocalChunk previous = this.blockChunks.put(pair, lastWrappedChunk);
|
||||
if (previous == null) {
|
||||
return lastWrappedChunk;
|
||||
|
@ -28,6 +28,7 @@ package com.plotsquared.core.queue;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
@ -112,15 +113,15 @@ public class ChunkQueueCoordinator extends ScopedQueueCoordinator {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override @Nonnull public String getWorld() {
|
||||
return "";
|
||||
@Override @Nonnull public World getWorld() {
|
||||
return super.getWorld();
|
||||
}
|
||||
|
||||
@Override public Location getMax() {
|
||||
return Location.at(getWorld(), top.getX(), top.getY(), top.getZ());
|
||||
return Location.at(getWorld().getName(), top.getX(), top.getY(), top.getZ());
|
||||
}
|
||||
|
||||
@Override public Location getMin() {
|
||||
return Location.at(getWorld(), bot.getX(), bot.getY(), bot.getZ());
|
||||
return Location.at(getWorld().getName(), bot.getX(), bot.getY(), bot.getZ());
|
||||
}
|
||||
}
|
||||
|
@ -27,13 +27,10 @@ package com.plotsquared.core.queue;
|
||||
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class DelegateQueueCoordinator extends QueueCoordinator {
|
||||
|
||||
@ -84,11 +81,11 @@ public class DelegateQueueCoordinator extends QueueCoordinator {
|
||||
return parent.setBiome(x, z, biome);
|
||||
}
|
||||
|
||||
@Override public boolean settingBiome() {
|
||||
return parent.settingBiome();
|
||||
@Override public boolean isSettingBiomes() {
|
||||
return parent.isSettingBiomes();
|
||||
}
|
||||
|
||||
@Override public String getWorld() {
|
||||
@Override public World getWorld() {
|
||||
return parent.getWorld();
|
||||
}
|
||||
|
||||
@ -96,6 +93,10 @@ public class DelegateQueueCoordinator extends QueueCoordinator {
|
||||
return parent.setTile(x, y, z, tag);
|
||||
}
|
||||
|
||||
@Override public boolean isSettingTiles() {
|
||||
return parent.isSettingTiles();
|
||||
}
|
||||
|
||||
@Override public boolean enqueue() {
|
||||
if (parent != null) {
|
||||
return parent.enqueue();
|
||||
|
@ -6,55 +6,35 @@ import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class LocalChunk {
|
||||
public final BasicQueueCoordinator parent;
|
||||
public final int z;
|
||||
public final int x;
|
||||
@Getter private final BasicQueueCoordinator parent;
|
||||
@Getter private final int z;
|
||||
@Getter private final int x;
|
||||
|
||||
public BaseBlock[][] baseblocks;
|
||||
public BiomeType[][] biomes;
|
||||
public HashMap<BlockVector3, CompoundTag> tiles = null;
|
||||
@Getter private final BaseBlock[][] baseblocks;
|
||||
@Getter private final BiomeType[][] biomes;
|
||||
@Getter private final HashMap<BlockVector3, CompoundTag> tiles = new HashMap<>();
|
||||
|
||||
public LocalChunk(BasicQueueCoordinator parent, int x, int z) {
|
||||
this.parent = parent;
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
baseblocks = new BaseBlock[16][];
|
||||
biomes = new BiomeType[16][];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the parent queue this chunk belongs to
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public BasicQueueCoordinator getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public void setBiome(int x, int z, BiomeType biomeType) {
|
||||
if (this.biomes == null) {
|
||||
this.biomes = new BiomeType[16][];
|
||||
public void setBiome(final int x, final int y, final int z, final BiomeType biomeType) {
|
||||
final int i = MainUtil.CACHE_I[y][x][z];
|
||||
final int j = MainUtil.CACHE_J[y][x][z];
|
||||
BiomeType[] array = this.biomes[i];
|
||||
if (array == null) {
|
||||
array = this.biomes[i] = new BiomeType[4096];
|
||||
}
|
||||
BiomeType[] index = this.biomes[x];
|
||||
if (index == null) {
|
||||
index = this.biomes[x] = new BiomeType[16];
|
||||
}
|
||||
index[z] = biomeType;
|
||||
}
|
||||
|
||||
public long longHash() {
|
||||
return MathMan.pairInt(x, z);
|
||||
array[j] = biomeType;
|
||||
}
|
||||
|
||||
@Override public int hashCode() {
|
||||
@ -72,9 +52,6 @@ public class LocalChunk {
|
||||
}
|
||||
|
||||
public void setTile(final int x, final int y, final int z, final CompoundTag tag) {
|
||||
if (tiles == null) {
|
||||
tiles = new HashMap<>();
|
||||
}
|
||||
tiles.put(BlockVector3.at(x, y, z), tag);
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.util.PatternUtil;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
@ -73,20 +74,22 @@ public abstract class QueueCoordinator {
|
||||
|
||||
public abstract boolean setTile(int x, int y, int z, CompoundTag tag);
|
||||
|
||||
public abstract boolean isSettingTiles();
|
||||
|
||||
public abstract BlockState getBlock(int x, int y, int z);
|
||||
|
||||
public abstract boolean setBiome(int x, int z, BiomeType biome);
|
||||
|
||||
public abstract boolean settingBiome();
|
||||
public abstract boolean isSettingBiomes();
|
||||
|
||||
public abstract String getWorld();
|
||||
public abstract World getWorld();
|
||||
|
||||
public final void setModified() {
|
||||
setModified(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public boolean enqueue() {
|
||||
return this.blockQueue.enqueue(this);
|
||||
return blockQueue.enqueue(this);
|
||||
}
|
||||
|
||||
public void setCuboid(Location pos1, Location pos2, BlockState block) {
|
||||
|
@ -93,11 +93,11 @@ public class ScopedQueueCoordinator extends DelegateQueueCoordinator {
|
||||
}
|
||||
|
||||
public Location getMin() {
|
||||
return Location.at(this.getWorld(), this.minX, this.minY, this.minZ);
|
||||
return Location.at(this.getWorld().getName(), this.minX, this.minY, this.minZ);
|
||||
}
|
||||
|
||||
public Location getMax() {
|
||||
return Location.at(this.getWorld(), this.maxX, this.maxY, this.maxZ);
|
||||
return Location.at(this.getWorld().getName(), this.maxX, this.maxY, this.maxZ);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user