@Override public void unloadChunks() { for (Chunk chunk : this.chunks.values()) { this.unloadChunk(chunk.getX(), chunk.getZ(), false); } this.chunks = new HashMap<>(); }
@Override public Chunk next() { Chunk current = next; next = null; final int cx = current.getX() & CHUNKS.MASK; final int cy = current.getY() & CHUNKS.MASK; final int cz = current.getZ() & CHUNKS.MASK; for (int dx = cx; dx < CHUNKS.SIZE; dx++) { for (int dy = cy; dy < CHUNKS.SIZE; dy++) { for (int dz = cz; dz < CHUNKS.SIZE; dz++) { next = getChunk(dx, dy, dz, LoadOption.NO_LOAD); if (next != null && next != current) { return current; } } } } return current; }
private boolean isProtected(Location location) { Chunk chunk = location.getChunk(); World world = location.getWorld(); WorldConfig worldConfig = plugin.getConfig(world); int gridX = (int) (Math.floor(chunk.getX() / 10.0d) * 10); int gridZ = (int) (Math.floor(chunk.getZ() / 10.0d) * 10); DungeonProperties properties = new DungeonProperties(world, worldConfig, gridX, gridZ); if (properties.isInChunk(chunk)) { int yMin = 0; int yMax = 0; for (int y = 0; y < world.getMaxHeight(); ++y) { if ((chunk.getBlock(8, y, 8).getData() & (byte) 0x8) == 0x8) { yMin = y; break; } } for (int y = world.getMaxHeight(); y > 0; --y) { if ((chunk.getBlock(8, y, 8).getData() & (byte) 0x8) == 0x8) { yMax = y; break; } } double y = location.getY(); return (y >= yMin && y <= yMax); } return false; }
private static void checkChunk( Chunk chunk, Tag data, DefaultErrorHandler results, CheckParameters params) { if (data.getType() != TagType.COMPOUND) { results.corruptChunk(chunk, "Chunk data not a compound", EnumSet.of(NONE), NONE); // Fatal, no point performing further checks. return; } CompoundTag dataC = (CompoundTag) data; if (!dataC.containsKey("Level", TagType.COMPOUND)) { results.corruptChunk(chunk, "Chunk data missing \"Level\" compound.", EnumSet.of(NONE), NONE); // Fatal, no point performing further checks. return; } CompoundTag level = dataC.getCompound("Level"); if (!level.containsKey("xPos", TagType.INT)) { results.invalidXPosition(chunk, "xPos tag missing or wrong type.", EnumSet.of(NONE), NONE); } if (level.getInt("xPos") != chunk.getX()) { results.invalidXPosition( chunk, "xPos: " + level.getInt("xPos") + " does not match expected xPos: " + chunk.getX(), EnumSet.of(NONE), NONE); } if (!level.containsKey("zPos", TagType.INT)) { results.invalidZPosition(chunk, "zPos tag missing or wrong type.", EnumSet.of(NONE), NONE); } if (level.getInt("zPos") != chunk.getZ()) { results.invalidZPosition( chunk, "zPos: " + level.getInt("zPos") + " does not match expected zPos: " + chunk.getZ(), EnumSet.of(NONE), NONE); } if (!level.containsKey("Entities", TagType.LIST)) { results.invalidEntities(chunk, "Entities tag missing or wrong type.", EnumSet.of(NONE), NONE); } if (params.isCheckEntityCount()) { ListTag entities = level.getList("Entities"); if (!entities.isEmpty()) { if (entities.getListType() != TagType.COMPOUND) { results.invalidEntities( chunk, "Entities are wrong type: " + entities.getListType().name(), EnumSet.of(NONE), NONE); } else if (entities.size() > params.getMaxEntities()) { results.tooManyEntities( chunk, "Found " + entities.size() + " entities", EnumSet.of(NONE), NONE); } } } if (!level.containsKey("TileEntities", TagType.LIST)) { results.invalidTileEntities( chunk, "TileEntities tag missing or wrong type.", EnumSet.of(NONE), NONE); } else if (params.isCheckTileEntityCount() || params.isCheckTileEntityLocation()) { ListTag tileEntities = level.getList("TileEntities"); if (!tileEntities.isEmpty() && tileEntities.getListType() != TagType.COMPOUND) { results.invalidTileEntities( chunk, "TileEntities are wrong type: " + tileEntities.getListType().name(), EnumSet.of(NONE), NONE); } else { if (params.isCheckTileEntityCount() && tileEntities.size() > params.getMaxTileEntities()) { results.tooManyTileEntities( chunk, "Found " + tileEntities.size() + " tile entities", EnumSet.of(NONE), NONE); } if (params.isCheckTileEntityLocation()) { if (!tileEntities.isEmpty()) { for (CompoundTag tileEntity : (CompoundTag[]) tileEntities.getValue()) { if (!tileEntity.containsKey("x", TagType.INT)) { results.invalidTileEntity( chunk, "Invalid tile entity, no x position", EnumSet.of(NONE), NONE); break; } if (!tileEntity.containsKey("y", TagType.INT)) { results.invalidTileEntity( chunk, "Invalid tile entity, no y position", EnumSet.of(NONE), NONE); break; } if (!tileEntity.containsKey("z", TagType.INT)) { results.invalidTileEntity( chunk, "Invalid tile entity, no z position", EnumSet.of(NONE), NONE); break; } int x = tileEntity.getInt("x"); int y = tileEntity.getInt("y"); int z = tileEntity.getInt("z"); int chunkX = x - chunk.getX(); int chunkZ = z - chunk.getZ(); if (chunkX < 0 || chunkX > 15 || chunkZ < 0 || chunkZ > 15 || y < 0 || y > 255) { results.misplacedTileEntity( chunk, "Invalid tile entity, located outside chunk, relative offset: " + chunkX + ", " + y + ", " + chunkZ, EnumSet.of(NONE), NONE); break; } } } } } } }
@Override public void saveChunks() { for (Chunk chunk : this.chunks.values()) { this.saveChunk(chunk.getX(), chunk.getZ()); } }