Java Code Examples for cn.nukkit.event.block.BlockUpdateEvent#isCancelled()
The following examples show how to use
cn.nukkit.event.block.BlockUpdateEvent#isCancelled() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Level.java From Jupiter with GNU General Public License v3.0 | 5 votes |
public void updateAround(Vector3 pos) { BlockUpdateEvent ev; for (BlockFace face : BlockFace.values()) { this.server.getPluginManager().callEvent( ev = new BlockUpdateEvent(this.getBlock(pos.getSide(face)))); if (!ev.isCancelled()) { ev.getBlock().onUpdate(BLOCK_UPDATE_NORMAL); } } }
Example 2
Source File: Level.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public void updateAround(int x, int y, int z) { BlockUpdateEvent ev; this.server.getPluginManager().callEvent( ev = new BlockUpdateEvent(this.getBlock(x, y - 1, z))); if (!ev.isCancelled()) { normalUpdateQueue.add(ev.getBlock()); } this.server.getPluginManager().callEvent( ev = new BlockUpdateEvent(this.getBlock(x, y + 1, z))); if (!ev.isCancelled()) { normalUpdateQueue.add(ev.getBlock()); } this.server.getPluginManager().callEvent( ev = new BlockUpdateEvent(this.getBlock(x - 1, y, z))); if (!ev.isCancelled()) { normalUpdateQueue.add(ev.getBlock()); } this.server.getPluginManager().callEvent( ev = new BlockUpdateEvent(this.getBlock(x + 1, y, z))); if (!ev.isCancelled()) { normalUpdateQueue.add(ev.getBlock()); } this.server.getPluginManager().callEvent( ev = new BlockUpdateEvent(this.getBlock(x, y, z - 1))); if (!ev.isCancelled()) { normalUpdateQueue.add(ev.getBlock()); } this.server.getPluginManager().callEvent( ev = new BlockUpdateEvent(this.getBlock(x, y, z + 1))); if (!ev.isCancelled()) { normalUpdateQueue.add(ev.getBlock()); } }
Example 3
Source File: Level.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public void updateAround(int x, int y, int z) { BlockUpdateEvent ev; this.server.getPluginManager().callEvent( ev = new BlockUpdateEvent(this.getBlock(x, y - 1, z))); if (!ev.isCancelled()) { ev.getBlock().onUpdate(BLOCK_UPDATE_NORMAL); } this.server.getPluginManager().callEvent( ev = new BlockUpdateEvent(this.getBlock(x, y + 1, z))); if (!ev.isCancelled()) { ev.getBlock().onUpdate(BLOCK_UPDATE_NORMAL); } this.server.getPluginManager().callEvent( ev = new BlockUpdateEvent(this.getBlock(x - 1, y, z))); if (!ev.isCancelled()) { ev.getBlock().onUpdate(BLOCK_UPDATE_NORMAL); } this.server.getPluginManager().callEvent( ev = new BlockUpdateEvent(this.getBlock(x + 1, y, z))); if (!ev.isCancelled()) { ev.getBlock().onUpdate(BLOCK_UPDATE_NORMAL); } this.server.getPluginManager().callEvent( ev = new BlockUpdateEvent(this.getBlock(x, y, z - 1))); if (!ev.isCancelled()) { ev.getBlock().onUpdate(BLOCK_UPDATE_NORMAL); } this.server.getPluginManager().callEvent( ev = new BlockUpdateEvent(this.getBlock(x, y, z + 1))); if (!ev.isCancelled()) { ev.getBlock().onUpdate(BLOCK_UPDATE_NORMAL); } }
Example 4
Source File: Level.java From Jupiter with GNU General Public License v3.0 | 4 votes |
public boolean setBlock(Vector3 pos, Block block, boolean direct, boolean update) { if (pos.y < 0 || pos.y >= 256) { return false; } if (this.getChunk((int) pos.x >> 4, (int) pos.z >> 4, true).setBlock((int) pos.x & 0x0f, (int) pos.y & 0xff, (int) pos.z & 0x0f, block.getId(), block.getDamage())) { Position position; if (!(pos instanceof Position)) { position = this.temporalPosition.setComponents(pos.x, pos.y, pos.z); } else { position = (Position) pos; } block.position(position); this.blockCache.remove(Level.blockHash((int) position.x, (int) position.y, (int) position.z)); Long index = Level.chunkHash((int) position.x >> 4, (int) position.z >> 4); if (direct) { this.sendBlocks(this.getChunkPlayers((int) position.x >> 4, (int) position.z >> 4).values().stream() .toArray(Player[]::new), new Block[]{block}, UpdateBlockPacket.FLAG_ALL_PRIORITY); this.chunkCache.remove(index); } else { addBlockChange(index, (int) block.x, (int) block.y, (int) block.z); } for (ChunkLoader loader : this.getChunkLoaders((int) position.x >> 4, (int) position.z >> 4)) { loader.onBlockChanged(block); } if (update) { this.updateAllLight(block); BlockUpdateEvent ev = new BlockUpdateEvent(block); this.server.getPluginManager().callEvent(ev); if (!ev.isCancelled()) { for (Entity entity : this.getNearbyEntities(new AxisAlignedBB(block.x - 1, block.y - 1, block.z - 1, block.x + 1, block.y + 1, block.z + 1))) { entity.scheduleUpdate(); } ev.getBlock().onUpdate(BLOCK_UPDATE_NORMAL); } this.updateAround(position); } return true; } return false; }
Example 5
Source File: Level.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public synchronized boolean setBlock(int x, int y, int z, Block block, boolean direct, boolean update) { if (y < 0 || y >= 256) { return false; } BaseFullChunk chunk = this.getChunk(x >> 4, z >> 4, true); Block blockPrevious; // synchronized (chunk) { blockPrevious = chunk.getAndSetBlock(x & 0xF, y, z & 0xF, block); if (blockPrevious.getFullId() == block.getFullId()) { return false; } // } block.x = x; block.y = y; block.z = z; block.level = this; int cx = x >> 4; int cz = z >> 4; long index = Level.chunkHash(cx, cz); if (direct) { this.sendBlocks(this.getChunkPlayers(cx, cz).values().toArray(new Player[0]), new Block[]{block}, UpdateBlockPacket.FLAG_ALL_PRIORITY); this.sendBlocks(this.getChunkPlayers(cx, cz).values().toArray(new Player[0]), new Block[]{Block.get(Block.AIR, 0, block)}, UpdateBlockPacket.FLAG_ALL_PRIORITY, 1); } else { addBlockChange(index, x, y, z); } for (ChunkLoader loader : this.getChunkLoaders(cx, cz)) { loader.onBlockChanged(block); } if (update) { if (blockPrevious.isTransparent() != block.isTransparent() || blockPrevious.getLightLevel() != block.getLightLevel()) { addLightUpdate(x, y, z); } BlockUpdateEvent ev = new BlockUpdateEvent(block); this.server.getPluginManager().callEvent(ev); if (!ev.isCancelled()) { for (Entity entity : this.getNearbyEntities(new SimpleAxisAlignedBB(x - 1, y - 1, z - 1, x + 1, y + 1, z + 1))) { entity.scheduleUpdate(); } block = ev.getBlock(); block.onUpdate(BLOCK_UPDATE_NORMAL); this.updateAround(x, y, z); } } return true; }
Example 6
Source File: Level.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public boolean setBlock(int x, int y, int z, Block block, boolean direct, boolean update) { if (y < 0 || y >= 256) { return false; } BaseFullChunk chunk = this.getChunk(x >> 4, z >> 4, true); Block blockPrevious; // synchronized (chunk) { blockPrevious = chunk.getAndSetBlock(x & 0xF, y, z & 0xF, block); if (blockPrevious.getFullId() == block.getFullId()) { return false; } // } block.x = x; block.y = y; block.z = z; block.level = this; int cx = x >> 4; int cz = z >> 4; long index = Level.chunkHash(cx, cz); if (direct) { this.sendBlocks(this.getChunkPlayers(cx, cz).values().stream().toArray(Player[]::new), new Block[]{block}, UpdateBlockPacket.FLAG_ALL_PRIORITY); } else { addBlockChange(index, x, y, z); } for (ChunkLoader loader : this.getChunkLoaders(cx, cz)) { loader.onBlockChanged(block); } if (update) { if (blockPrevious.isTransparent() != block.isTransparent() || blockPrevious.getLightLevel() != block.getLightLevel()) { addLightUpdate(x, y, z); } BlockUpdateEvent ev = new BlockUpdateEvent(block); this.server.getPluginManager().callEvent(ev); if (!ev.isCancelled()) { for (Entity entity : this.getNearbyEntities(new SimpleAxisAlignedBB(x - 1, y - 1, z - 1, x + 1, y + 1, z + 1))) { entity.scheduleUpdate(); } block = ev.getBlock(); block.onUpdate(BLOCK_UPDATE_NORMAL); this.updateAround(x, y, z); } } return true; }