Java Code Examples for org.bukkit.block.BlockState#setData()

The following examples show how to use org.bukkit.block.BlockState#setData() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
@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
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 Project: Crazy-Crates   File: QuadCrateSession.java    License: MIT License 6 votes vote down vote up
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 4
Source Project: AnnihilationPro   File: GameMap.java    License: MIT License 6 votes vote down vote up
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 5
@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 6
@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 7
/**
 * 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
@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 9
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 10
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 11
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 12
@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 13
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 14
@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 15
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 16
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 17
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 18
@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);
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
}