Java Code Examples for org.bukkit.block.BlockState#setData()
The following examples show how to use
org.bukkit.block.BlockState#setData() .
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: BlockGrowListener.java From IridiumSkyblock with GNU General Public License v2.0 | 6 votes |
@EventHandler public void onBlockGrow(BlockGrowEvent event) { try { final Block block = event.getBlock(); final Location location = block.getLocation(); final IslandManager islandManager = IridiumSkyblock.getIslandManager(); final Island island = islandManager.getIslandViaLocation(location); if (island == null) return; if (island.getFarmingBooster() == 0) return; final Material material = block.getType(); if (!XBlock.isCrops(material)) return; event.setCancelled(true); final Crops crops = new Crops(CropState.RIPE); final BlockState blockState = block.getState(); blockState.setData(crops); blockState.update(); } catch (Exception e) { IridiumSkyblock.getInstance().sendErrorMessage(e); } }
Example 2
Source File: BlockDropsMatchModule.java From PGM with GNU Affero General Public License v3.0 | 6 votes |
private void replaceBlock(BlockDrops drops, Block block, MatchPlayer player) { if (drops.replacement != null) { EntityChangeBlockEvent event = new EntityChangeBlockEvent( player.getBukkit(), block, drops.replacement.getItemType(), drops.replacement.getData()); match.callEvent(event); if (!event.isCancelled()) { BlockState state = block.getState(); state.setType(drops.replacement.getItemType()); state.setData(drops.replacement); state.update(true, true); } } }
Example 3
Source File: BukkitHandler1_12.java From AreaShop with GNU General Public License v3.0 | 6 votes |
@Override public boolean setSignFacing(Block block, BlockFace facing) { if (block == null || facing == null) { return false; } BlockState blockState = block.getState(); if (blockState == null) { return false; } org.bukkit.material.Sign signData = (org.bukkit.material.Sign) blockState.getData(); if (signData == null) { return false; } signData.setFacingDirection(facing); blockState.setData(signData); blockState.update(true, true); return true; }
Example 4
Source File: DoorEvent.java From BetonQuest with GNU General Public License v3.0 | 6 votes |
@Override protected Void execute(String playerID) throws QuestRuntimeException { Block block = loc.getLocation(playerID).getBlock(); BlockState state = block.getState(); MaterialData data = state.getData(); if (data instanceof Openable) { Openable openable = (Openable) data; switch (type) { case ON: openable.setOpen(true); break; case OFF: openable.setOpen(false); break; case TOGGLE: openable.setOpen(!openable.isOpen()); break; } state.setData((MaterialData) openable); state.update(); } return null; }
Example 5
Source File: QuadCrateSession.java From Crazy-Crates with MIT License | 6 votes |
private void rotateChest(Block chest, Integer direction) { BlockFace blockFace; switch (direction) { case 0://East blockFace = BlockFace.WEST; break; case 1://South blockFace = BlockFace.NORTH; break; case 2://West blockFace = BlockFace.EAST; break; case 3://North blockFace = BlockFace.SOUTH; break; default: blockFace = BlockFace.DOWN; break; } BlockState state = chest.getState(); state.setData(new Chest(blockFace)); state.update(); }
Example 6
Source File: GameMap.java From AnnihilationPro with MIT License | 6 votes |
public void addEnderFurnace(FacingObject furnace) { MapKey key = MapKey.getKey(furnace.getLocation()); if(!enderFurnaces.containsKey(key)) { try { Block block = furnace.getLocation().toLocation().getBlock(); if(block.getType() != Material.FURNACE && block.getType() != Material.BURNING_FURNACE) block.setType(Material.BURNING_FURNACE); Furnace f = new Furnace(Material.BURNING_FURNACE); f.setFacingDirection(furnace.getFacingDirection()); BlockState s = block.getState(); s.setData(f); s.update(true); } catch(Exception e) { } enderFurnaces.put(key, furnace); } }
Example 7
Source File: BlockTransformEvent.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
/** * Get the {@link BlockState} after the {@link Block} was transformed. * * @return The current {@link BlockState}. */ public final BlockState getNewState() { if (drops == null || drops.replacement == null) { return newState; } else { final BlockState state = newState.getBlock().getState(); state.setType(drops.replacement.getItemType()); state.setData(drops.replacement); return state; } }
Example 8
Source File: VersionHelper113.java From RedProtect with GNU General Public License v3.0 | 5 votes |
public void toggleDoor(Block b) { BlockState state = b.getState(); if (state instanceof Door) { Door op = (Door) state.getData(); if (!op.isOpen()) op.setOpen(true); else op.setOpen(false); state.setData(op); state.update(); } }
Example 9
Source File: VersionHelper112.java From RedProtect with GNU General Public License v3.0 | 5 votes |
public void toggleDoor(Block b) { BlockState state = b.getState(); if (state instanceof Door) { Door op = (Door) state.getData(); op.setOpen(!op.isOpen()); state.setData(op); state.update(); } }
Example 10
Source File: VersionHelper18.java From RedProtect with GNU General Public License v3.0 | 5 votes |
public void toggleDoor(Block b) { BlockState state = b.getState(); if (state instanceof Door) { Door op = (Door) state.getData(); if (!op.isOpen()) op.setOpen(true); else op.setOpen(false); state.setData(op); state.update(); } }
Example 11
Source File: BlockAdapterMagicValues.java From DungeonsXL with GNU General Public License v3.0 | 5 votes |
@Override public void setFacing(Block block, BlockFace facing) { BlockState state = block.getState(); MaterialData data = state.getData(); if (!(data instanceof Directional)) { throw new IllegalArgumentException("Block is not Directional"); } ((Directional) data).setFacingDirection(facing); state.setData(data); state.update(); }
Example 12
Source File: StructureGrowDelegate.java From Thermos with GNU General Public License v3.0 | 5 votes |
public boolean setRawTypeIdAndData(int x, int y, int z, int type, int data) { BlockState state = world.getBlockAt(x, y, z).getState(); state.setTypeId(type); state.setData(new MaterialData(type, (byte) data)); blocks.add(state); return true; }
Example 13
Source File: BlockTransformListener.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@EventWrapper public void onBlockPistonExtend(final BlockPistonExtendEvent event) { Map<Block, BlockState> newStates = new HashMap<>(); // Add the arm of the piston, which will extend into the adjacent block. PistonExtensionMaterial pistonExtension = new PistonExtensionMaterial(Material.PISTON_EXTENSION); pistonExtension.setFacingDirection(event.getDirection()); BlockState pistonExtensionState = event.getBlock().getRelative(event.getDirection()).getState(); pistonExtensionState.setType(pistonExtension.getItemType()); pistonExtensionState.setData(pistonExtension); newStates.put(event.getBlock(), pistonExtensionState); this.onPistonMove(event, event.getBlocks(), newStates); }
Example 14
Source File: BlockTransformEvent.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
public BlockState getNewState() { if(this.drops == null || this.drops.replacement == null) { return this.newState; } else { BlockState state = this.newState.getBlock().getState(); state.setType(this.drops.replacement.getItemType()); state.setData(this.drops.replacement); return state; } }
Example 15
Source File: BlockDropsMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
private void replaceBlock(BlockDrops drops, Block block, MatchPlayer player) { if(drops.replacement != null) { EntityChangeBlockEvent event = new EntityChangeBlockEvent(player.getBukkit(), block, drops.replacement); getMatch().callEvent(event); if(!event.isCancelled()) { BlockState state = block.getState(); state.setType(drops.replacement.getItemType()); state.setData(drops.replacement); state.update(true, true); } } }
Example 16
Source File: StructureGrowDelegate.java From Kettle with GNU General Public License v3.0 | 5 votes |
public boolean setRawTypeIdAndData(int x, int y, int z, int type, int data) { BlockState state = world.getBlockAt(x, y, z).getState(); state.setTypeId(type); state.setData(new MaterialData(type, (byte) data)); blocks.add(state); return true; }
Example 17
Source File: BlockTransformListener.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
@EventWrapper public void onBlockPistonExtend(final BlockPistonExtendEvent event) { Map<Block, BlockState> newStates = new HashMap<>(); // Add the arm of the piston, which will extend into the adjacent block. PistonExtensionMaterial pistonExtension = new PistonExtensionMaterial(Material.PISTON_EXTENSION); pistonExtension.setFacingDirection(event.getDirection()); BlockState pistonExtensionState = event.getBlock().getRelative(event.getDirection()).getState(); pistonExtensionState.setType(pistonExtension.getItemType()); pistonExtensionState.setData(pistonExtension); newStates.put(event.getBlock(), pistonExtensionState); this.onPistonMove(event, event.getBlocks(), newStates); }
Example 18
Source File: BlockFire.java From Carbon with GNU Lesser General Public License v3.0 | 4 votes |
@SuppressWarnings("deprecation") @Override public void a(World world, int i, int j, int k, Random random) { if(world.getGameRules().getBoolean("doFireTick")) { boolean flag = world.getType(i, j - 1, k) == Blocks.NETHERRACK; if(((world.worldProvider instanceof WorldProviderTheEnd)) && (world.getType(i, j - 1, k) == Blocks.BEDROCK)) { flag = true; } if(!canPlace(world, i, j, k)) { fireExtinguished(world, i, j, k); } if((!flag) && (world.Q()) && ((world.isRainingAt(i, j, k)) || (world.isRainingAt(i - 1, j, k)) || (world.isRainingAt(i + 1, j, k)) || (world.isRainingAt(i, j, k - 1)) || (world.isRainingAt(i, j, k + 1)))) { fireExtinguished(world, i, j, k); } else { int l = world.getData(i, j, k); if(l < 15) { world.setData(i, j, k, l + random.nextInt(3) / 2, 4); } world.a(i, j, k, this, a(world) + random.nextInt(10)); if((!flag) && (!e(world, i, j, k))) { if((!World.a(world, i, j - 1, k)) || (l > 3)) { fireExtinguished(world, i, j, k); } } else if((!flag) && (!e(world, i, j - 1, k)) && (l == 15) && (random.nextInt(4) == 0)) { fireExtinguished(world, i, j, k); } else { boolean flag1 = world.z(i, j, k); byte b0 = 0; if(flag1) { b0 = -50; } a(world, i + 1, j, k, 300 + b0, random, l); a(world, i - 1, j, k, 300 + b0, random, l); a(world, i, j - 1, k, 250 + b0, random, l); a(world, i, j + 1, k, 250 + b0, random, l); a(world, i, j, k - 1, 300 + b0, random, l); a(world, i, j, k + 1, 300 + b0, random, l); for(int i1 = i - 1; i1 <= i + 1; i1++) { for(int j1 = k - 1; j1 <= k + 1; j1++) { for(int k1 = j - 1; k1 <= j + 4; k1++) { if((i1 != i) || (k1 != j) || (j1 != k)) { int l1 = 100; if(k1 > j + 1) { l1 += (k1 - (j + 1)) * 100; } int i2 = m(world, i1, k1, j1); if(i2 > 0) { int j2 = (i2 + 40 + world.difficulty.a() * 7) / (l + 30); if(flag1) { j2 /= 2; } if((j2 > 0) && (random.nextInt(l1) <= j2) && ((!world.Q()) || (!world.isRainingAt(i1, k1, j1))) && (!world.isRainingAt(i1 - 1, k1, k)) && (!world.isRainingAt(i1 + 1, k1, j1)) && (!world.isRainingAt(i1, k1, j1 - 1)) && (!world.isRainingAt(i1, k1, j1 + 1))) { int k2 = l + random.nextInt(5) / 4; if(k2 > 15) { k2 = 15; } if((world.getType(i1, k1, j1) != this) && (!CraftEventFactory.callBlockIgniteEvent(world, i1, k1, j1, i, j, k).isCancelled())) { Server server = world.getServer(); org.bukkit.World bworld = world.getWorld(); BlockState blockState = bworld.getBlockAt(i1, k1, j1).getState(); blockState.setTypeId(Block.getId(this)); blockState.setData(new MaterialData(Block.getId(this), (byte) k2)); BlockSpreadEvent spreadEvent = new BlockSpreadEvent(blockState.getBlock(), bworld.getBlockAt(i, j, k), blockState); server.getPluginManager().callEvent(spreadEvent); if(!spreadEvent.isCancelled()) { blockState.update(true); } } } } } } } } } } } }