@Override public void setBlock(String playerName, Block block, Location loc1, Location loc2) { Area area = new Area(loc1, loc2); List<Block> blocks = new LinkedList<Block>(); int chX1 = area.getX1() >> 4; int chZ1 = area.getZ1() >> 4; int chX2 = area.getX2() >> 4; int chZ2 = area.getZ2() >> 4; Clipboard undo = Clipboard.createUndoClipBoard(playerName); for (int chX = chX1; chX <= chX2; chX++) for (int chZ = chZ1; chZ <= chZ2; chZ++) { for (int x = 0; x < 16; x++) for (int z = 0; z < 16; z++) { int blockX = x + (chX << 4); int blockZ = z + (chZ << 4); if (blockX < area.getX1() || blockX > area.getX2()) continue; if (blockZ < area.getZ1() || blockZ > area.getZ2()) continue; for (int y = area.getY1(); y <= area.getY2(); y++) { Position position = new Position(blockX, y, blockZ, area.getLevel()); if (undo != null) undo.add(position.getLevel().getBlock(position)); blocks.add(Block.get(block.getId(), block.getDamage(), position)); } } } if (undo != null) getUndoManager().add(undo); Message.debugMessage( "setBlock:", "blocks:", blocks.size(), "undo:", undo == null ? "null" : undo.getVolume()); setBlock(playerName, blocks); }
@Override public void replaceBlock( String playerName, Block b1, Block b2, boolean compareData, Location loc1, Location loc2) { Area area = new Area(loc1, loc2); List<Block> blocks = new LinkedList<Block>(); ChunkCoord ch1 = new ChunkCoord(area.getLoc1()); ChunkCoord ch2 = new ChunkCoord(area.getLoc1()); int chX1 = area.getX1() >> 4; int chZ1 = area.getZ1() >> 4; int chX2 = area.getX2() >> 4; int chZ2 = area.getZ2() >> 4; Clipboard undo = Clipboard.createUndoClipBoard(playerName); for (int chX = chX1; chX <= chX2; chX++) for (int chZ = chZ1; chZ <= chZ2; chZ++) for (int x = 0; x < 16; x++) for (int z = 0; z < 16; z++) { int blockX = x + (chX << 4); int blockZ = z + (chZ << 4); if (blockX < area.getX1() || blockX > area.getX2()) continue; if (blockZ < area.getZ1() || blockZ > area.getZ2()) continue; for (int y = area.getY1(); y <= area.getY2(); y++) { Position position = new Position(blockX, y, blockZ, area.getLevel()); Block block = position.getLevel().getBlock(position); if (b1 == null) if (block.getId() != 0) continue; else { if (block.getId() != b1.getId()) continue; if (compareData && block.getDamage() != b1.getDamage()) continue; } if (undo != null) undo.add(position.getLevel().getBlock(position)); setBlock(playerName, Block.get(b2.getId(), b2.getDamage(), position)); } } if (undo != null) getUndoManager().add(undo); }
@Override public void setBlockBox(String playerName, Block block, Location l1, Location l2) { Area area = new Area(l1, l2); List<Block> blocks = new LinkedList<Block>(); Clipboard undo = Clipboard.createUndoClipBoard(playerName); for (int x = area.getX1(); x <= area.getX2(); x++) for (int z = area.getZ1(); z <= area.getZ2(); z++) for (int y = area.getY1(); y <= area.getY2(); y++) { if (x != l1.getFloorX() && x != l2.getFloorX() && z != l1.getFloorZ() && z != l2.getFloorZ() && y != l1.getFloorY() && y != l2.getFloorY()) continue; Position position = new Position(x, y, z, area.getLevel()); if (undo != null) undo.add(position.getLevel().getBlock(position)); setBlock(playerName, Block.get(block.getId(), block.getDamage(), position)); } if (undo != null) Regions.getUndoManager().add(undo); }
@Override public void setBlockWall(String playerName, Block block, Location l1, Location l2) { Area area = new Area(l1, l2); Clipboard undo = Clipboard.createUndoClipBoard(playerName); for (int y = area.getY1(); y <= area.getY2(); y++) { for (int x = area.getX1(); x <= area.getX2(); x++) { Position p1 = new Position(x, y, area.getZ1(), area.getLevel()); Position p2 = new Position(x, y, area.getZ1(), area.getLevel()); if (undo != null) undo.add(p1.getLevel().getBlock(p1), p1.getLevel().getBlock(p2)); setBlock(playerName, Block.get(block.getId(), block.getDamage(), p1)); setBlock(playerName, Block.get(block.getId(), block.getDamage(), p2)); } for (int z = area.getZ1(); z <= area.getZ2(); z++) { Position p1 = new Position(area.getX1(), area.getY1(), z, area.getLevel()); Position p2 = new Position(area.getX2(), area.getY2(), z, area.getLevel()); if (undo != null) undo.add(p1.getLevel().getBlock(p1), p1.getLevel().getBlock(p2)); setBlock(playerName, Block.get(block.getId(), block.getDamage(), p1)); setBlock(playerName, Block.get(block.getId(), block.getDamage(), p2)); } } if (undo != null) Regions.getUndoManager().add(undo); }
public boolean isInBox(Position position) { return ((position.getX() >= minX) && (position.getX() <= maxX)) && ((position.getY() >= minY) && (position.getY() <= maxY)) && ((position.getZ() >= minZ) && (position.getZ() <= maxZ)) && Objects.equals(position.getLevel().getName(), getLevelName()); }
@Override protected void finalize() throws Throwable { super.finalize(); this.close(); }
public Position getSide(int side, int step) { if (!this.isValid()) { throw new LevelException("Undefined Level reference"); } return Position.fromObject(super.getSide(side, step), this.level); }