mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 21:26:45 +01:00
chunk manager error catching
This commit is contained in:
parent
e7733e749d
commit
df5167813a
@ -290,8 +290,8 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
final Integer task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
long start = System.currentTimeMillis();
|
||||
while (System.currentTimeMillis() - start < 20) {
|
||||
final long start = System.currentTimeMillis();
|
||||
while ((System.currentTimeMillis() - start) < 20) {
|
||||
if (chunks.size() == 0) {
|
||||
TaskManager.runTaskLater(whenDone, 1);
|
||||
Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
|
||||
@ -403,7 +403,7 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
saveEntitiesIn(chunk, region, 0, 0, false);
|
||||
}
|
||||
|
||||
public static void saveEntitiesIn(final Chunk chunk, final RegionWrapper region, int offset_x, int offset_z, boolean delete) {
|
||||
public static void saveEntitiesIn(final Chunk chunk, final RegionWrapper region, final int offset_x, final int offset_z, final boolean delete) {
|
||||
for (final Entity entity : chunk.getEntities()) {
|
||||
final Location loc = BukkitUtil.getLocation(entity);
|
||||
final int x = loc.getX();
|
||||
@ -439,6 +439,7 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
|
||||
public static void restoreBlocks(final World world, final int x_offset, final int z_offset) {
|
||||
for (final BlockLoc loc : chestContents.keySet()) {
|
||||
try {
|
||||
final Block block = world.getBlockAt(loc.x + x_offset, loc.y, loc.z + z_offset);
|
||||
final BlockState state = block.getState();
|
||||
if (state instanceof Chest) {
|
||||
@ -448,8 +449,12 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
} else {
|
||||
PlotSquared.log("&c[WARN] Plot clear failed to regenerate chest: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
PlotSquared.log("&c[WARN] Plot clear failed to regenerate chest: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset);
|
||||
}
|
||||
}
|
||||
for (final BlockLoc loc : signContents.keySet()) {
|
||||
try {
|
||||
final Block block = world.getBlockAt(loc.x + x_offset, loc.y, loc.z + z_offset);
|
||||
final BlockState state = block.getState();
|
||||
if (state instanceof Sign) {
|
||||
@ -463,8 +468,12 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
} else {
|
||||
PlotSquared.log("&c[WARN] Plot clear failed to regenerate sign: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
PlotSquared.log("&c[WARN] Plot clear failed to regenerate sign: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset);
|
||||
}
|
||||
}
|
||||
for (final BlockLoc loc : dispenserContents.keySet()) {
|
||||
try {
|
||||
final Block block = world.getBlockAt(loc.x + x_offset, loc.y, loc.z + z_offset);
|
||||
final BlockState state = block.getState();
|
||||
if (state instanceof Dispenser) {
|
||||
@ -473,8 +482,12 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
} else {
|
||||
PlotSquared.log("&c[WARN] Plot clear failed to regenerate dispenser: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
PlotSquared.log("&c[WARN] Plot clear failed to regenerate dispenser: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset);
|
||||
}
|
||||
}
|
||||
for (final BlockLoc loc : dropperContents.keySet()) {
|
||||
try {
|
||||
final Block block = world.getBlockAt(loc.x + x_offset, loc.y, loc.z + z_offset);
|
||||
final BlockState state = block.getState();
|
||||
if (state instanceof Dropper) {
|
||||
@ -483,8 +496,12 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
} else {
|
||||
PlotSquared.log("&c[WARN] Plot clear failed to regenerate dispenser: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
PlotSquared.log("&c[WARN] Plot clear failed to regenerate dispenser: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset);
|
||||
}
|
||||
}
|
||||
for (final BlockLoc loc : beaconContents.keySet()) {
|
||||
try {
|
||||
final Block block = world.getBlockAt(loc.x + x_offset, loc.y, loc.z + z_offset);
|
||||
final BlockState state = block.getState();
|
||||
if (state instanceof Beacon) {
|
||||
@ -493,8 +510,12 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
} else {
|
||||
PlotSquared.log("&c[WARN] Plot clear failed to regenerate beacon: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
PlotSquared.log("&c[WARN] Plot clear failed to regenerate beacon: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset);
|
||||
}
|
||||
}
|
||||
for (final BlockLoc loc : jukeDisc.keySet()) {
|
||||
try {
|
||||
final Block block = world.getBlockAt(loc.x + x_offset, loc.y, loc.z + z_offset);
|
||||
final BlockState state = block.getState();
|
||||
if (state instanceof Jukebox) {
|
||||
@ -503,8 +524,12 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
} else {
|
||||
PlotSquared.log("&c[WARN] Plot clear failed to restore jukebox: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
PlotSquared.log("&c[WARN] Plot clear failed to regenerate jukebox: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset);
|
||||
}
|
||||
}
|
||||
for (final BlockLoc loc : skullData.keySet()) {
|
||||
try {
|
||||
final Block block = world.getBlockAt(loc.x + x_offset, loc.y, loc.z + z_offset);
|
||||
final BlockState state = block.getState();
|
||||
if (state instanceof Skull) {
|
||||
@ -520,10 +545,14 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
}
|
||||
state.update(true);
|
||||
} else {
|
||||
PlotSquared.log("&c[WARN] Plot clear failed to restore jukebox: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset);
|
||||
PlotSquared.log("&c[WARN] Plot clear failed to restore skull: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
PlotSquared.log("&c[WARN] Plot clear failed to regenerate skull: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset);
|
||||
}
|
||||
}
|
||||
for (final BlockLoc loc : hopperContents.keySet()) {
|
||||
try {
|
||||
final Block block = world.getBlockAt(loc.x + x_offset, loc.y, loc.z + z_offset);
|
||||
final BlockState state = block.getState();
|
||||
if (state instanceof Hopper) {
|
||||
@ -532,8 +561,12 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
} else {
|
||||
PlotSquared.log("&c[WARN] Plot clear failed to regenerate hopper: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
PlotSquared.log("&c[WARN] Plot clear failed to regenerate hopper: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset);
|
||||
}
|
||||
}
|
||||
for (final BlockLoc loc : noteBlockContents.keySet()) {
|
||||
try {
|
||||
final Block block = world.getBlockAt(loc.x + x_offset, loc.y, loc.z + z_offset);
|
||||
final BlockState state = block.getState();
|
||||
if (state instanceof NoteBlock) {
|
||||
@ -542,8 +575,12 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
} else {
|
||||
PlotSquared.log("&c[WARN] Plot clear failed to regenerate note block: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
PlotSquared.log("&c[WARN] Plot clear failed to regenerate note block: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset);
|
||||
}
|
||||
}
|
||||
for (final BlockLoc loc : brewTime.keySet()) {
|
||||
try {
|
||||
final Block block = world.getBlockAt(loc.x + x_offset, loc.y, loc.z + z_offset);
|
||||
final BlockState state = block.getState();
|
||||
if (state instanceof BrewingStand) {
|
||||
@ -551,8 +588,12 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
} else {
|
||||
PlotSquared.log("&c[WARN] Plot clear failed to restore brewing stand cooking: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
PlotSquared.log("&c[WARN] Plot clear failed to restore brewing stand cooking: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset);
|
||||
}
|
||||
}
|
||||
for (final BlockLoc loc : spawnerData.keySet()) {
|
||||
try {
|
||||
final Block block = world.getBlockAt(loc.x + x_offset, loc.y, loc.z + z_offset);
|
||||
final BlockState state = block.getState();
|
||||
if (state instanceof CreatureSpawner) {
|
||||
@ -561,8 +602,12 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
} else {
|
||||
PlotSquared.log("&c[WARN] Plot clear failed to restore spawner type: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
PlotSquared.log("&c[WARN] Plot clear failed to restore spawner type: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset);
|
||||
}
|
||||
}
|
||||
for (final BlockLoc loc : cmdData.keySet()) {
|
||||
try {
|
||||
final Block block = world.getBlockAt(loc.x + x_offset, loc.y, loc.z + z_offset);
|
||||
final BlockState state = block.getState();
|
||||
if (state instanceof CommandBlock) {
|
||||
@ -571,8 +616,12 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
} else {
|
||||
PlotSquared.log("&c[WARN] Plot clear failed to restore command block: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
PlotSquared.log("&c[WARN] Plot clear failed to restore command block: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset);
|
||||
}
|
||||
}
|
||||
for (final BlockLoc loc : brewingStandContents.keySet()) {
|
||||
try {
|
||||
final Block block = world.getBlockAt(loc.x + x_offset, loc.y, loc.z + z_offset);
|
||||
final BlockState state = block.getState();
|
||||
if (state instanceof BrewingStand) {
|
||||
@ -581,8 +630,12 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
} else {
|
||||
PlotSquared.log("&c[WARN] Plot clear failed to regenerate brewing stand: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
PlotSquared.log("&c[WARN] Plot clear failed to regenerate brewing stand: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset);
|
||||
}
|
||||
}
|
||||
for (final BlockLoc loc : furnaceTime.keySet()) {
|
||||
try {
|
||||
final Block block = world.getBlockAt(loc.x + x_offset, loc.y, loc.z + z_offset);
|
||||
final BlockState state = block.getState();
|
||||
if (state instanceof Furnace) {
|
||||
@ -592,8 +645,12 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
} else {
|
||||
PlotSquared.log("&c[WARN] Plot clear failed to restore furnace cooking: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
PlotSquared.log("&c[WARN] Plot clear failed to restore furnace cooking: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset);
|
||||
}
|
||||
}
|
||||
for (final BlockLoc loc : furnaceContents.keySet()) {
|
||||
try {
|
||||
final Block block = world.getBlockAt(loc.x + x_offset, loc.y, loc.z + z_offset);
|
||||
final BlockState state = block.getState();
|
||||
if (state instanceof Furnace) {
|
||||
@ -602,8 +659,12 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
} else {
|
||||
PlotSquared.log("&c[WARN] Plot clear failed to regenerate furnace: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
PlotSquared.log("&c[WARN] Plot clear failed to regenerate furnace: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset);
|
||||
}
|
||||
}
|
||||
for (final BlockLoc loc : bannerBase.keySet()) {
|
||||
try {
|
||||
final Block block = world.getBlockAt(loc.x + x_offset, loc.y, loc.z + z_offset);
|
||||
final BlockState state = block.getState();
|
||||
if (state instanceof Banner) {
|
||||
@ -618,6 +679,9 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
} else {
|
||||
PlotSquared.log("&c[WARN] Plot clear failed to regenerate banner: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
PlotSquared.log("&c[WARN] Plot clear failed to regenerate banner: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -625,7 +689,7 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
saveBlocks(world, maxY, x, z, 0, 0);
|
||||
}
|
||||
|
||||
public static void saveBlocks(final World world, final int maxY, int x, int z, int offset_x, int offset_z) {
|
||||
public static void saveBlocks(final World world, final int maxY, final int x, final int z, final int offset_x, final int offset_z) {
|
||||
final HashMap<Short, Short> ids = new HashMap<>();
|
||||
final HashMap<Short, Byte> datas = new HashMap<>();
|
||||
for (short y = 0; y < maxY; y++) {
|
||||
@ -775,7 +839,7 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
if (plot.id.equals(id)) {
|
||||
if (entity instanceof Player) {
|
||||
final Player player = (Player) entity;
|
||||
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||
final PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||
pp.teleport(MainUtil.getDefaultHome(plot));
|
||||
APlotListener.manager.plotExit(pp, plot);
|
||||
} else {
|
||||
@ -795,50 +859,47 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
return BukkitUtil.getWorld(world).getChunkAt(loc.x, loc.z).unload(true, true);
|
||||
}
|
||||
|
||||
public static void swapChunk(World world, Chunk pos1, Chunk pos2, RegionWrapper r1, RegionWrapper r2) {
|
||||
public static void swapChunk(final World world, final Chunk pos1, final Chunk pos2, final RegionWrapper r1, final RegionWrapper r2) {
|
||||
initMaps();
|
||||
int relX = (r2.minX - r1.minX);
|
||||
int relZ = (r2.minZ - r1.minZ);
|
||||
final int relX = (r2.minX - r1.minX);
|
||||
final int relZ = (r2.minZ - r1.minZ);
|
||||
|
||||
saveEntitiesIn(pos1, r1, relX, relZ, true);
|
||||
saveEntitiesIn(pos2, r2, -relX, -relZ, true);
|
||||
|
||||
int sx = pos1.getX() << 4;
|
||||
int sz = pos1.getZ() << 4;
|
||||
final int sx = pos1.getX() << 4;
|
||||
final int sz = pos1.getZ() << 4;
|
||||
|
||||
int maxY = world.getMaxHeight();
|
||||
final int maxY = world.getMaxHeight();
|
||||
|
||||
for (int x = Math.max(r1.minX, sx); x <= Math.min(r1.maxX, sx + 15); x++) {
|
||||
for (int z = Math.max(r1.minZ, sz); z <= Math.min(r1.maxZ, sz + 15); z++) {
|
||||
saveBlocks(world, maxY, sx, sz, relX, relZ);
|
||||
for (int y = 0; y < maxY; y++) {
|
||||
Block block1 = world.getBlockAt(x, y, z);
|
||||
int id1 = block1.getTypeId();
|
||||
byte data1 = block1.getData();
|
||||
int xx = x + relX;
|
||||
int zz = z + relZ;
|
||||
Block block2 = world.getBlockAt(xx, y, zz);
|
||||
int id2 = block2.getTypeId();
|
||||
byte data2 = block2.getData();
|
||||
final Block block1 = world.getBlockAt(x, y, z);
|
||||
final int id1 = block1.getTypeId();
|
||||
final byte data1 = block1.getData();
|
||||
final int xx = x + relX;
|
||||
final int zz = z + relZ;
|
||||
final Block block2 = world.getBlockAt(xx, y, zz);
|
||||
final int id2 = block2.getTypeId();
|
||||
final byte data2 = block2.getData();
|
||||
if (id1 == 0) {
|
||||
if (id2 != 0) {
|
||||
BukkitSetBlockManager.setBlockManager.set(world, x, y, z, id2, data2);
|
||||
BukkitSetBlockManager.setBlockManager.set(world, xx, y, zz, 0, (byte) 0);
|
||||
}
|
||||
}
|
||||
else if (id2 == 0) {
|
||||
} else if (id2 == 0) {
|
||||
if (id1 != 0) {
|
||||
BukkitSetBlockManager.setBlockManager.set(world, xx, y, zz, id1, data1);
|
||||
BukkitSetBlockManager.setBlockManager.set(world, x, y, z, 0, (byte) 0);
|
||||
}
|
||||
}
|
||||
else if (id1 == id2) {
|
||||
} else if (id1 == id2) {
|
||||
if (data1 != data2) {
|
||||
block1.setData(data2);
|
||||
block2.setData(data1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
BukkitSetBlockManager.setBlockManager.set(world, x, y, z, id2, data2);
|
||||
BukkitSetBlockManager.setBlockManager.set(world, xx, y, zz, id1, data1);
|
||||
}
|
||||
@ -852,11 +913,11 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
|
||||
@Override
|
||||
public void swap(final String worldname, final PlotId pos1, final PlotId pos2) {
|
||||
Location bot1 = MainUtil.getPlotBottomLoc(worldname, pos1).add(1, 0, 1);
|
||||
Location top1 = MainUtil.getPlotTopLoc(worldname, pos1);
|
||||
final Location bot1 = MainUtil.getPlotBottomLoc(worldname, pos1).add(1, 0, 1);
|
||||
final Location top1 = MainUtil.getPlotTopLoc(worldname, pos1);
|
||||
|
||||
Location bot2 = MainUtil.getPlotBottomLoc(worldname, pos2).add(1, 0, 1);
|
||||
Location top2 = MainUtil.getPlotTopLoc(worldname, pos2);
|
||||
final Location bot2 = MainUtil.getPlotBottomLoc(worldname, pos2).add(1, 0, 1);
|
||||
final Location top2 = MainUtil.getPlotTopLoc(worldname, pos2);
|
||||
swap(worldname, bot1, top1, bot2, top2);
|
||||
|
||||
clearAllEntities(MainUtil.getPlot(worldname, pos1));
|
||||
@ -864,7 +925,7 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void swap(final String worldname, final Location bot1, final Location top1, Location bot2, Location top2) {
|
||||
public void swap(final String worldname, final Location bot1, final Location top1, final Location bot2, final Location top2) {
|
||||
final RegionWrapper region1 = new RegionWrapper(bot1.getX(), top1.getX(), bot1.getZ(), top1.getZ());
|
||||
final RegionWrapper region2 = new RegionWrapper(bot2.getX(), top2.getX(), bot2.getZ(), top2.getZ());
|
||||
final World world = Bukkit.getWorld(bot1.getWorld());
|
||||
@ -872,10 +933,10 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
final int relX = bot2.getX() - bot1.getX();
|
||||
final int relZ = bot2.getZ() - bot1.getZ();
|
||||
|
||||
for (int x = bot1.getX() >> 4; x <= top1.getX() >> 4; x++) {
|
||||
for (int z = bot1.getZ() >> 4; z <= top1.getZ() >> 4; z++) {
|
||||
Chunk chunk1 = world.getChunkAt(x, z);
|
||||
Chunk chunk2 = world.getChunkAt(x + (relX >> 4), z + (relZ >> 4));
|
||||
for (int x = bot1.getX() >> 4; x <= (top1.getX() >> 4); x++) {
|
||||
for (int z = bot1.getZ() >> 4; z <= (top1.getZ() >> 4); z++) {
|
||||
final Chunk chunk1 = world.getChunkAt(x, z);
|
||||
final Chunk chunk2 = world.getChunkAt(x + (relX >> 4), z + (relZ >> 4));
|
||||
swapChunk(world, chunk1, chunk2, region1, region2);
|
||||
}
|
||||
}
|
||||
@ -883,24 +944,24 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] countEntities(Plot plot) {
|
||||
int[] count = new int[5];
|
||||
World world = BukkitUtil.getWorld(plot.world);
|
||||
public int[] countEntities(final Plot plot) {
|
||||
final int[] count = new int[5];
|
||||
final World world = BukkitUtil.getWorld(plot.world);
|
||||
|
||||
Location bot = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1);
|
||||
Location top = MainUtil.getPlotTopLoc(plot.world, plot.id);
|
||||
int bx = bot.getX() >> 4;
|
||||
int bz = bot.getZ() >> 4;
|
||||
final Location bot = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1);
|
||||
final Location top = MainUtil.getPlotTopLoc(plot.world, plot.id);
|
||||
final int bx = bot.getX() >> 4;
|
||||
final int bz = bot.getZ() >> 4;
|
||||
|
||||
int tx = top.getX() >> 4;
|
||||
int tz = top.getZ() >> 4;
|
||||
final int tx = top.getX() >> 4;
|
||||
final int tz = top.getZ() >> 4;
|
||||
|
||||
int size = (tx-bx) << 4;
|
||||
final int size = (tx - bx) << 4;
|
||||
|
||||
HashSet<Chunk> chunks = new HashSet<>();
|
||||
final HashSet<Chunk> chunks = new HashSet<>();
|
||||
for (int X = bx; X <= tx; X++) {
|
||||
for (int Z = bz; Z <= tz; Z++) {
|
||||
chunks.add(world.getChunkAt(X,Z));
|
||||
chunks.add(world.getChunkAt(X, Z));
|
||||
}
|
||||
}
|
||||
|
||||
@ -908,25 +969,24 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
List<Entity> entities = null;
|
||||
if (size > 200) {
|
||||
entities = world.getEntities();
|
||||
if (entities.size() < 16 + (size * size / 64)) {
|
||||
if (entities.size() < (16 + ((size * size) / 64))) {
|
||||
doWhole = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (doWhole) {
|
||||
for (final Entity entity : entities) {
|
||||
if (!(entity instanceof Creature || entity instanceof Vehicle)) {
|
||||
if (!((entity instanceof Creature) || (entity instanceof Vehicle))) {
|
||||
continue;
|
||||
}
|
||||
org.bukkit.Location loc = entity.getLocation();
|
||||
Chunk chunk = loc.getChunk();
|
||||
final org.bukkit.Location loc = entity.getLocation();
|
||||
final Chunk chunk = loc.getChunk();
|
||||
if (chunks.contains(chunk)) {
|
||||
int X = chunk.getX();
|
||||
int Z = chunk.getX();
|
||||
if (X > bx && X < tx && Z > bz && Z < tz) {
|
||||
final int X = chunk.getX();
|
||||
final int Z = chunk.getX();
|
||||
if ((X > bx) && (X < tx) && (Z > bz) && (Z < tz)) {
|
||||
count(count, entity);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
final PlotId id = MainUtil.getPlotId(BukkitUtil.getLocation(loc));
|
||||
if (plot.id.equals(id)) {
|
||||
count(count, entity);
|
||||
@ -934,23 +994,21 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (Chunk chunk : chunks) {
|
||||
int X = chunk.getX();
|
||||
int Z = chunk.getX();
|
||||
Entity[] ents = chunk.getEntities();
|
||||
} else {
|
||||
for (final Chunk chunk : chunks) {
|
||||
final int X = chunk.getX();
|
||||
final int Z = chunk.getX();
|
||||
final Entity[] ents = chunk.getEntities();
|
||||
for (final Entity entity : ents) {
|
||||
if (!(entity instanceof Creature || entity instanceof Vehicle)) {
|
||||
if (!((entity instanceof Creature) || (entity instanceof Vehicle))) {
|
||||
continue;
|
||||
}
|
||||
if (X == bx || X == tx || Z == bz || Z == tz) {
|
||||
if ((X == bx) || (X == tx) || (Z == bz) || (Z == tz)) {
|
||||
final PlotId id = MainUtil.getPlotId(BukkitUtil.getLocation(entity));
|
||||
if (plot.id.equals(id)) {
|
||||
count(count, entity);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
count(count, entity);
|
||||
}
|
||||
}
|
||||
@ -959,27 +1017,25 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
return count;
|
||||
}
|
||||
|
||||
private void count(int[] count, Entity entity) {
|
||||
private void count(final int[] count, final Entity entity) {
|
||||
count[0]++;
|
||||
if (entity instanceof Creature) {
|
||||
count[3]++;
|
||||
if (entity instanceof Animals) {
|
||||
count[1]++;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
count[2]++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
count[4]++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChunk(ChunkWrapper loc, PlotBlock[][] blocks) {
|
||||
CURRENT_PLOT_CLEAR = new RegionWrapper(0,0,0,0);
|
||||
World world = Bukkit.getWorld(loc.world);
|
||||
Chunk chunk = world.getChunkAt(loc.x, loc.z);
|
||||
public void setChunk(final ChunkWrapper loc, final PlotBlock[][] blocks) {
|
||||
CURRENT_PLOT_CLEAR = new RegionWrapper(0, 0, 0, 0);
|
||||
final World world = Bukkit.getWorld(loc.world);
|
||||
final Chunk chunk = world.getChunkAt(loc.x, loc.z);
|
||||
final int cx = chunk.getX();
|
||||
final int cz = chunk.getZ();
|
||||
if (!chunk.isLoaded()) {
|
||||
@ -988,20 +1044,20 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
initMaps();
|
||||
final int absX = cx << 4;
|
||||
final int absZ = cz << 4;
|
||||
boolean save = false;
|
||||
final boolean save = false;
|
||||
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
saveBlocks(world, 255, absX + x, absZ + z);
|
||||
PlotLoc pl = new PlotLoc(absX + x, absZ + z);
|
||||
HashMap<Short, Short> ids = GENERATE_BLOCKS.get(pl);
|
||||
HashMap<Short, Short> datas = GENERATE_BLOCKS.get(pl);
|
||||
final PlotLoc pl = new PlotLoc(absX + x, absZ + z);
|
||||
final HashMap<Short, Short> ids = GENERATE_BLOCKS.get(pl);
|
||||
final HashMap<Short, Short> datas = GENERATE_BLOCKS.get(pl);
|
||||
for (int i = 0; i < blocks.length; i++) {
|
||||
if (blocks[i] != null) {
|
||||
short y0 = (short) (i << 4);
|
||||
for (short y = y0; y < y0 + 16; y++) {
|
||||
int j = ((y & 0xF) << 8) | (z << 4) | x;
|
||||
PlotBlock block = blocks[i][j];
|
||||
final short y0 = (short) (i << 4);
|
||||
for (short y = y0; y < (y0 + 16); y++) {
|
||||
final int j = ((y & 0xF) << 8) | (z << 4) | x;
|
||||
final PlotBlock block = blocks[i][j];
|
||||
if (block != null) {
|
||||
ids.put(y, block.id);
|
||||
if (block.data != 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user