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

The following examples show how to use org.bukkit.block.BlockState#setType() . 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: BlockDropsMatchModule.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
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 2
Source File: BlockListener.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onStructureGrow(StructureGrowEvent e) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "BlockListener - Is StructureGrowEvent event");
    if (!RedProtect.get().config.configRoot().region_settings.deny_structure_bypass_regions) {
        return;
    }
    Region rfrom = RedProtect.get().rm.getTopRegion(e.getLocation());
    for (BlockState bstt : e.getBlocks()) {
        Region rto = RedProtect.get().rm.getTopRegion(bstt.getLocation());
        Block bloc = bstt.getLocation().getBlock();
        //deny blocks spread in/out regions
        if (rfrom != null && rto != null && rfrom != rto && !rfrom.sameLeaders(rto)) {
            bstt.setType(bloc.getType());
        }
        if (rfrom == null && rto != null) {
            bstt.setType(bloc.getType());
        }
        if (rfrom != null && rto == null) {
            bstt.setType(bloc.getType());
        }
        bstt.update();
    }
}
 
Example 3
Source File: NetherPortals.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Converts trees to gravel and glowstone
 * 
 * @param e - event
 */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onTreeGrow(final StructureGrowEvent e) {
    if (DEBUG)
        plugin.getLogger().info("DEBUG: " + e.getEventName());

    if (!Settings.netherTrees) {
        return;
    }
    if (!Settings.createNether || ASkyBlock.getNetherWorld() == null) {
        return;
    }
    // Check world
    if (!e.getLocation().getWorld().equals(ASkyBlock.getNetherWorld())) {
        return;
    }
    for (BlockState b : e.getBlocks()) {
        if (b.getType() == Material.LOG || b.getType() == Material.LOG_2) {
            b.setType(Material.GRAVEL);
        } else if (b.getType() == Material.LEAVES || b.getType() == Material.LEAVES_2) {
            b.setType(Material.GLOWSTONE);
        }
    }
}
 
Example 4
Source File: BlockTransformEvent.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 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 5
Source File: BlockTransformListener.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@EventWrapper
public void onBlockFromTo(BlockFromToEvent event) {
  if (event.getToBlock().getType() != event.getBlock().getType()) {
    BlockState oldState = event.getToBlock().getState();
    BlockState newState = event.getToBlock().getState();
    newState.setType(event.getBlock().getType());
    newState.setRawData(event.getBlock().getData());

    // Check for lava ownership
    this.callEvent(event, oldState, newState, Trackers.getOwner(event.getBlock()));
  }
}
 
Example 6
Source File: BlockTransformListener.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@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 7
Source File: CraftEventFactory.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public static boolean handleBlockFormEvent(World world, BlockPos pos, IBlockState block, @Nullable Entity entity) {
    BlockState blockState = world.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ()).getState();
    blockState.setType(CraftMagicNumbers.getMaterial(block.getBlock()));
    blockState.setRawData((byte) block.getBlock().getMetaFromState(block));

    BlockFormEvent event = (entity == null) ? new BlockFormEvent(blockState.getBlock(), blockState) : new EntityBlockFormEvent(entity.getBukkitEntity(), blockState.getBlock(), blockState);
    world.getServer().getPluginManager().callEvent(event);

    if (!event.isCancelled()) {
        blockState.update(true);
    }

    return !event.isCancelled();
}
 
Example 8
Source File: BlockDropsMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
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 9
Source File: BlockTransformEvent.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
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 10
Source File: BlockTransformListener.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@EventWrapper
public void onBlockFromTo(BlockFromToEvent event) {
    if(event.getToBlock().getType() != event.getBlock().getType()) {
        BlockState oldState = event.getToBlock().getState();
        BlockState newState = event.getToBlock().getState();
        newState.setType(event.getBlock().getType());
        newState.setRawData(event.getBlock().getData());

        // Check for lava ownership
        this.callEvent(event, oldState, newState, blockResolver.getOwner(event.getBlock()));
    }
}
 
Example 11
Source File: BlockTransformListener.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@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 12
Source File: BlockStateUtils.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public static BlockState cloneWithMaterial(Block block, Material material, byte data) {
    BlockState state = block.getState();
    state.setType(material);
    state.setRawData(data);
    return state;
}
 
Example 13
Source File: MagicBlockCompat.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public BlockState fallingBlockToState(FallingBlock entity) {
	BlockState state = entity.getWorld().getBlockAt(0, 0, 0).getState();
	state.setType(entity.getMaterial());
	try {
		setRawDataMethod.invokeExact(state, (byte) getBlockDataMethod.invokeExact(entity));
	} catch (Throwable e) {
		Skript.exception(e);
	}
	return state;
}
 
Example 14
Source File: BlockStates.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
static BlockState toAir(Block block) {
  BlockState newState = block.getState(); // this creates a new copy of the state
  newState.setType(Material.AIR);
  newState.setRawData((byte) 0);
  return newState;
}
 
Example 15
Source File: BlockStates.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
static BlockState cloneWithMaterial(Block block, Material material, byte data) {
  BlockState state = block.getState();
  state.setType(material);
  state.setRawData(data);
  return state;
}
 
Example 16
Source File: BlockStateUtils.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public static BlockState toAir(Block block) {
    BlockState newState = block.getState(); // this creates a new copy of the state
    newState.setType(Material.AIR);
    newState.setRawData((byte) 0);
    return newState;
}