mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 21:26:45 +01:00
Various
Close #966 Close #953 (duplicates) Changes to chunk copying etc to interfere less with world generation
This commit is contained in:
parent
16dac99fed
commit
f9db269813
@ -234,6 +234,8 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
|
|||||||
// Set the result data
|
// Set the result data
|
||||||
result.cd = createChunkData(world);
|
result.cd = createChunkData(world);
|
||||||
result.grid = grid;
|
result.grid = grid;
|
||||||
|
result.result = null;
|
||||||
|
result.result_data = null;
|
||||||
// Catch any exceptions (as exceptions usually thrown
|
// Catch any exceptions (as exceptions usually thrown
|
||||||
try {
|
try {
|
||||||
// Fill the result data if necessary
|
// Fill the result data if necessary
|
||||||
@ -259,9 +261,7 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
|
|||||||
// Set random seed
|
// Set random seed
|
||||||
this.random.state = (cx << 16) | (cz & 0xFFFF);
|
this.random.state = (cx << 16) | (cz & 0xFFFF);
|
||||||
// Process the chunk
|
// Process the chunk
|
||||||
result.modified = false;
|
if (ChunkManager.preProcessChunk(result)) {
|
||||||
ChunkManager.preProcessChunk(result);
|
|
||||||
if (result.modified) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PlotArea area = PS.get().getPlotArea(world.getName(), null);
|
PlotArea area = PS.get().getPlotArea(world.getName(), null);
|
||||||
@ -279,6 +279,7 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
|
|||||||
result.result = new short[16][];
|
result.result = new short[16][];
|
||||||
result.result_data = new byte[16][];
|
result.result_data = new byte[16][];
|
||||||
result.grid = grid;
|
result.grid = grid;
|
||||||
|
result.cd = null;
|
||||||
// Catch any exceptions (as exceptions usually thrown
|
// Catch any exceptions (as exceptions usually thrown
|
||||||
try {
|
try {
|
||||||
// Fill the result data
|
// Fill the result data
|
||||||
|
@ -534,7 +534,7 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final PlotLoc loc = new PlotLoc(x, z);
|
final PlotLoc loc = new PlotLoc(x + offset_x, z + offset_z);
|
||||||
allblocks.put(loc, ids);
|
allblocks.put(loc, ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -633,133 +633,48 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
public boolean copyRegion(final Location pos1, final Location pos2, final Location newPos, final Runnable whenDone) {
|
public boolean copyRegion(final Location pos1, final Location pos2, final Location newPos, final Runnable whenDone) {
|
||||||
final int relX = newPos.getX() - pos1.getX();
|
final int relX = newPos.getX() - pos1.getX();
|
||||||
final int relZ = newPos.getZ() - pos1.getZ();
|
final int relZ = newPos.getZ() - pos1.getZ();
|
||||||
|
final Location pos4 = new Location(newPos.getWorld(), newPos.getX() + relX, 256, newPos.getZ() + relZ);
|
||||||
final int relCX = relX >> 4;
|
|
||||||
final int relCZ = relZ >> 4;
|
|
||||||
|
|
||||||
final RegionWrapper region = new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ());
|
final RegionWrapper region = new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ());
|
||||||
final World oldWorld = Bukkit.getWorld(pos1.getWorld());
|
final World oldWorld = Bukkit.getWorld(pos1.getWorld());
|
||||||
final World newWorld = Bukkit.getWorld(newPos.getWorld());
|
final World newWorld = Bukkit.getWorld(newPos.getWorld());
|
||||||
final String newWorldname = newWorld.getName();
|
final String newWorldname = newWorld.getName();
|
||||||
final List<ChunkLoc> chunks = new ArrayList<>();
|
final List<ChunkLoc> chunks = new ArrayList<>();
|
||||||
|
initMaps();
|
||||||
ChunkManager.chunkTask(pos1, pos2, new RunnableVal<int[]>() {
|
ChunkManager.chunkTask(pos1, pos2, new RunnableVal<int[]>() {
|
||||||
@Override
|
@Override
|
||||||
public void run(int[] value) {
|
public void run(int[] value) {
|
||||||
initMaps();
|
|
||||||
|
|
||||||
final int bx = value[2];
|
final int bx = value[2];
|
||||||
final int bz = value[3];
|
final int bz = value[3];
|
||||||
|
|
||||||
final int tx = value[4];
|
final int tx = value[4];
|
||||||
final int tz = value[5];
|
final int tz = value[5];
|
||||||
|
final ChunkLoc loc = new ChunkLoc(value[0], value[1]);
|
||||||
// Load chunks
|
final int cxx = loc.x << 4;
|
||||||
final ChunkLoc loc1 = new ChunkLoc(value[0], value[1]);
|
final int czz = loc.z << 4;
|
||||||
final ChunkLoc loc2 = new ChunkLoc(loc1.x + relCX, loc1.z + relCZ);
|
final Chunk chunk = oldWorld.getChunkAt(loc.x, loc.z);
|
||||||
final Chunk c1 = oldWorld.getChunkAt(loc1.x, loc1.z);
|
saveEntitiesIn(chunk, region);
|
||||||
final Chunk c2 = newWorld.getChunkAt(loc2.x, loc2.z);
|
|
||||||
c1.load(true);
|
|
||||||
c2.load(true);
|
|
||||||
chunks.add(loc2);
|
|
||||||
// entities
|
|
||||||
saveEntitiesIn(c1, region);
|
|
||||||
// copy chunk
|
|
||||||
setChunkInPlotArea(null, new RunnableVal<PlotChunk<?>>() {
|
|
||||||
@Override
|
|
||||||
public void run(PlotChunk<?> value) {
|
|
||||||
for (int x = bx & 15; x <= (tx & 15); x++) {
|
for (int x = bx & 15; x <= (tx & 15); x++) {
|
||||||
for (int z = bz & 15; z <= (tz & 15); z++) {
|
for (int z = bz & 15; z <= (tz & 15); z++) {
|
||||||
for (int y = 1; y < 256; y++) {
|
saveBlocks(oldWorld, 256, cxx + x, czz + z, relX, relZ, true);
|
||||||
Block block = c1.getBlock(x, y, z);
|
|
||||||
Material id = block.getType();
|
|
||||||
switch (id) {
|
|
||||||
case AIR:
|
|
||||||
case GRASS:
|
|
||||||
case COBBLESTONE:
|
|
||||||
case GRAVEL:
|
|
||||||
case GOLD_ORE:
|
|
||||||
case IRON_ORE:
|
|
||||||
case GLASS:
|
|
||||||
case LAPIS_ORE:
|
|
||||||
case LAPIS_BLOCK:
|
|
||||||
case WEB:
|
|
||||||
case DEAD_BUSH:
|
|
||||||
case YELLOW_FLOWER:
|
|
||||||
case BROWN_MUSHROOM:
|
|
||||||
case RED_MUSHROOM:
|
|
||||||
case GOLD_BLOCK:
|
|
||||||
case IRON_BLOCK:
|
|
||||||
case BRICK:
|
|
||||||
case TNT:
|
|
||||||
case BOOKSHELF:
|
|
||||||
case MOSSY_COBBLESTONE:
|
|
||||||
case OBSIDIAN:
|
|
||||||
case FIRE:
|
|
||||||
case REDSTONE_WIRE:
|
|
||||||
case DIAMOND_ORE:
|
|
||||||
case DIAMOND_BLOCK:
|
|
||||||
case WORKBENCH:
|
|
||||||
case SOIL:
|
|
||||||
case BEDROCK:
|
|
||||||
case WATER:
|
|
||||||
case STATIONARY_WATER:
|
|
||||||
case LAVA:
|
|
||||||
case STATIONARY_LAVA:
|
|
||||||
case REDSTONE_ORE:
|
|
||||||
case GLOWING_REDSTONE_ORE:
|
|
||||||
case SNOW:
|
|
||||||
case ICE:
|
|
||||||
case SNOW_BLOCK:
|
|
||||||
case CACTUS:
|
|
||||||
case CLAY:
|
|
||||||
case SUGAR_CANE_BLOCK:
|
|
||||||
case FENCE:
|
|
||||||
case NETHERRACK:
|
|
||||||
case SOUL_SAND:
|
|
||||||
case IRON_FENCE:
|
|
||||||
case THIN_GLASS:
|
|
||||||
case MELON_BLOCK:
|
|
||||||
case MYCEL:
|
|
||||||
case NETHER_BRICK:
|
|
||||||
case NETHER_FENCE:
|
|
||||||
case ENDER_STONE:
|
|
||||||
case DRAGON_EGG:
|
|
||||||
case EMERALD_ORE:
|
|
||||||
case EMERALD_BLOCK:
|
|
||||||
case SLIME_BLOCK:
|
|
||||||
case BARRIER:
|
|
||||||
case SEA_LANTERN:
|
|
||||||
case HAY_BLOCK:
|
|
||||||
case HARD_CLAY:
|
|
||||||
case COAL_BLOCK:
|
|
||||||
case PACKED_ICE:
|
|
||||||
case DOUBLE_STONE_SLAB2:
|
|
||||||
case STONE_SLAB2:
|
|
||||||
case SPRUCE_FENCE:
|
|
||||||
case BIRCH_FENCE:
|
|
||||||
case JUNGLE_FENCE:
|
|
||||||
case DARK_OAK_FENCE:
|
|
||||||
case ACACIA_FENCE:
|
|
||||||
value.setBlock(x, y, z, id.getId(), (byte) 0);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
value.setBlock(x, y, z, id.getId(), block.getData());
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}, newWorldname, loc2);
|
|
||||||
// restore chunk
|
|
||||||
restoreBlocks(newWorld, relX, relZ);
|
|
||||||
restoreEntities(newWorld, relX, relZ);
|
|
||||||
}
|
|
||||||
}, new Runnable() {
|
}, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
SetQueue.IMP.queue.sendChunk(newWorldname, chunks);
|
for (Entry<PlotLoc, PlotBlock[]> entry : allblocks.entrySet()) {
|
||||||
|
PlotLoc loc = entry.getKey();
|
||||||
|
PlotBlock[] blocks = entry.getValue();
|
||||||
|
for (int y = 0; y < blocks.length; y++) {
|
||||||
|
PlotBlock block = blocks[y];
|
||||||
|
if (block != null) {
|
||||||
|
SetQueue.IMP.setBlock(newWorldname, loc.x, y, loc.z, block);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (SetQueue.IMP.forceChunkSet());
|
||||||
|
restoreBlocks(newWorld, 0, 0);
|
||||||
|
restoreEntities(newWorld, relX, relZ);
|
||||||
TaskManager.runTask(whenDone);
|
TaskManager.runTask(whenDone);
|
||||||
}
|
}
|
||||||
}, 5);
|
}, 5);
|
||||||
|
@ -17,7 +17,6 @@ public class GenChunk extends PlotChunk<Chunk> {
|
|||||||
public short[][] result;
|
public short[][] result;
|
||||||
public byte[][] result_data;
|
public byte[][] result_data;
|
||||||
public ChunkData cd;
|
public ChunkData cd;
|
||||||
public boolean modified = false;
|
|
||||||
public BiomeGrid grid;
|
public BiomeGrid grid;
|
||||||
|
|
||||||
public GenChunk(Chunk chunk, ChunkWrapper wrap) {
|
public GenChunk(Chunk chunk, ChunkWrapper wrap) {
|
||||||
@ -42,7 +41,6 @@ public class GenChunk extends PlotChunk<Chunk> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setBiome(int x, int z, int biome) {
|
public void setBiome(int x, int z, int biome) {
|
||||||
modified = true;
|
|
||||||
grid.setBiome(x, z, biomes[biome]);
|
grid.setBiome(x, z, biomes[biome]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,14 +53,12 @@ public class GenChunk extends PlotChunk<Chunk> {
|
|||||||
@Override
|
@Override
|
||||||
public void setBlock(int x, int y, int z, int id, byte data) {
|
public void setBlock(int x, int y, int z, int id, byte data) {
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
modified = true;
|
|
||||||
cd.setBlock(x, y, z, id, data);
|
cd.setBlock(x, y, z, id, data);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int i = MainUtil.CACHE_I[y][x][z];
|
int i = MainUtil.CACHE_I[y][x][z];
|
||||||
short[] v = result[i];
|
short[] v = result[i];
|
||||||
if (v == null) {
|
if (v == null) {
|
||||||
modified = true;
|
|
||||||
result[i] = v = new short[4096];
|
result[i] = v = new short[4096];
|
||||||
}
|
}
|
||||||
int j = MainUtil.CACHE_J[y][x][z];
|
int j = MainUtil.CACHE_J[y][x][z];
|
||||||
|
@ -2789,7 +2789,7 @@ public class Plot {
|
|||||||
// copy data
|
// copy data
|
||||||
for (final Plot plot : plots) {
|
for (final Plot plot : plots) {
|
||||||
final Plot other = plot.getRelative(offset.x, offset.y);
|
final Plot other = plot.getRelative(offset.x, offset.y);
|
||||||
other.create(other.owner, false);
|
other.create(plot.owner, false);
|
||||||
if (!plot.getFlags().isEmpty()) {
|
if (!plot.getFlags().isEmpty()) {
|
||||||
other.getSettings().flags = plot.getFlags();
|
other.getSettings().flags = plot.getFlags();
|
||||||
DBFunc.setFlags(other, plot.getFlags().values());
|
DBFunc.setFlags(other, plot.getFlags().values());
|
||||||
@ -2799,19 +2799,19 @@ public class Plot {
|
|||||||
}
|
}
|
||||||
if ((plot.members != null) && !plot.members.isEmpty()) {
|
if ((plot.members != null) && !plot.members.isEmpty()) {
|
||||||
other.members = plot.members;
|
other.members = plot.members;
|
||||||
for (final UUID member : other.members) {
|
for (final UUID member : plot.members) {
|
||||||
DBFunc.setMember(other, member);
|
DBFunc.setMember(other, member);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((plot.trusted != null) && !plot.trusted.isEmpty()) {
|
if ((plot.trusted != null) && !plot.trusted.isEmpty()) {
|
||||||
other.trusted = plot.trusted;
|
other.trusted = plot.trusted;
|
||||||
for (final UUID trusted : other.trusted) {
|
for (final UUID trusted : plot.trusted) {
|
||||||
DBFunc.setTrusted(other, trusted);
|
DBFunc.setTrusted(other, trusted);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((plot.denied != null) && !plot.denied.isEmpty()) {
|
if ((plot.denied != null) && !plot.denied.isEmpty()) {
|
||||||
other.denied = plot.denied;
|
other.denied = plot.denied;
|
||||||
for (final UUID denied : other.denied) {
|
for (final UUID denied : plot.denied) {
|
||||||
DBFunc.setDenied(other, denied);
|
DBFunc.setDenied(other, denied);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,11 @@ public class PlotLoc {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return x + "," + z;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(final Object obj) {
|
public boolean equals(final Object obj) {
|
||||||
if (this == obj) {
|
if (this == obj) {
|
||||||
|
@ -49,18 +49,22 @@ public abstract class ChunkManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void preProcessChunk(PlotChunk<?> chunk) {
|
public static boolean preProcessChunk(PlotChunk<?> chunk) {
|
||||||
if (CURRENT_FORCE_CHUNK != null) {
|
if (CURRENT_FORCE_CHUNK != null) {
|
||||||
CURRENT_FORCE_CHUNK.run(chunk);
|
CURRENT_FORCE_CHUNK.run(chunk);
|
||||||
CURRENT_FORCE_CHUNK = null;
|
CURRENT_FORCE_CHUNK = null;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void postProcessChunk(PlotChunk<?> chunk) {
|
public static boolean postProcessChunk(PlotChunk<?> chunk) {
|
||||||
if (CURRENT_ADD_CHUNK != null) {
|
if (CURRENT_ADD_CHUNK != null) {
|
||||||
CURRENT_ADD_CHUNK.run(chunk);
|
CURRENT_ADD_CHUNK.run(chunk);
|
||||||
CURRENT_ADD_CHUNK = null;
|
CURRENT_ADD_CHUNK = null;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void largeRegionTask(final String world, final RegionWrapper region, final RunnableVal<ChunkLoc> task, final Runnable whenDone) {
|
public static void largeRegionTask(final String world, final RegionWrapper region, final RunnableVal<ChunkLoc> task, final Runnable whenDone) {
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
package com.plotsquared.sponge.util.block;
|
package com.plotsquared.sponge.util.block;
|
||||||
|
|
||||||
import org.spongepowered.api.world.Chunk;
|
|
||||||
import org.spongepowered.api.world.extent.MutableBiomeArea;
|
|
||||||
import org.spongepowered.api.world.extent.MutableBlockVolume;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.util.PlotChunk;
|
import com.intellectualcrafters.plot.util.PlotChunk;
|
||||||
import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper;
|
import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper;
|
||||||
import com.plotsquared.sponge.util.SpongeUtil;
|
import com.plotsquared.sponge.util.SpongeUtil;
|
||||||
|
import org.spongepowered.api.world.Chunk;
|
||||||
|
import org.spongepowered.api.world.extent.MutableBiomeArea;
|
||||||
|
import org.spongepowered.api.world.extent.MutableBlockVolume;
|
||||||
|
|
||||||
public class GenChunk extends PlotChunk<Chunk> {
|
public class GenChunk extends PlotChunk<Chunk> {
|
||||||
|
|
||||||
@ -42,6 +41,11 @@ public class GenChunk extends PlotChunk<Chunk> {
|
|||||||
terain.setBlock(bx + x, y, bz + z, SpongeUtil.getBlockState(id, data));
|
terain.setBlock(bx + x, y, bz + z, SpongeUtil.getBlockState(id, data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setChunkWrapper(ChunkWrapper loc) {
|
||||||
|
super.setChunkWrapper(loc);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlotChunk clone() {
|
public PlotChunk clone() {
|
||||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||||
|
Loading…
Reference in New Issue
Block a user