org.bukkit.material.Directional Java Examples

The following examples show how to use org.bukkit.material.Directional. 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: Region.java    From BedwarsRel with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
public void addBreakedBlock(Block bedBlock) {
  if (bedBlock.getState().getData() instanceof Directional) {
    this.breakedBlockFace.put(bedBlock,
        ((Directional) bedBlock.getState().getData()).getFacing());
  }

  this.breakedBlockTypes.put(bedBlock, bedBlock.getTypeId());
  this.breakedBlockData.put(bedBlock, bedBlock.getData());

  if (bedBlock.getState().getData() instanceof Redstone) {
    this.breakedBlockPower.put(bedBlock, ((Redstone) bedBlock.getState().getData()).isPowered());
  }

  this.breakedBlocks.add(bedBlock);
}
 
Example #2
Source File: Region.java    From BedwarsRel with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
public void addPlacedUnbreakableBlock(Block placed, BlockState replaced) {
  this.placedUnbreakableBlocks.add(placed);
  if (replaced != null) {
    if (replaced.getData() instanceof Directional) {
      this.breakedBlockFace.put(replaced.getBlock(),
          ((Directional) replaced.getData()).getFacing());
    }

    this.breakedBlockTypes.put(replaced.getBlock(), replaced.getTypeId());
    this.breakedBlockData.put(replaced.getBlock(), replaced.getData().getData());
    this.breakedBlocks.add(replaced.getBlock());

    if (replaced.getData() instanceof Redstone) {
      this.breakedBlockPower.put(placed, ((Redstone) replaced.getData()).isPowered());
    }
  }
}
 
Example #3
Source File: Direction.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public Vector getDirection(final Block b) {
	if (!relative)
		return new Vector(pitchOrX, yawOrY, lengthOrZ);
	final Material m = b.getType();
	if (!Directional.class.isAssignableFrom(m.getData()))
		return new Vector();
	final BlockFace f = ((Directional) m.getNewData(b.getData())).getFacing();
	return getDirection(pitchOrX == IGNORE_PITCH ? 0 : f.getModZ() * Math.PI / 2 /* only up and down have a z mod */, Math.atan2(f.getModZ(), f.getModX()));
}
 
Example #4
Source File: Direction.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param b
 * @return The facing of the block or {@link BlockFace#SELF} if the block doesn't have a facing.
 */
@SuppressWarnings({"deprecation", "null"})
public static BlockFace getFacing(final Block b) {
	final Material m = b.getType();
	if (!Directional.class.isAssignableFrom(m.getData()))
		return BlockFace.SELF;
	return ((Directional) m.getNewData(b.getData())).getFacing();
}
 
Example #5
Source File: Region.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public void addPlacedBlock(Block placeBlock, BlockState replacedBlock) {
  this.placedBlocks.add(placeBlock);
  if (replacedBlock != null) {
    if (replacedBlock.getData() instanceof Directional) {
      this.breakedBlockFace.put(replacedBlock.getBlock(),
          ((Directional) replacedBlock.getData()).getFacing());
    }

    this.breakedBlockTypes.put(replacedBlock.getBlock(), replacedBlock.getTypeId());
    this.breakedBlockData.put(replacedBlock.getBlock(), replacedBlock.getData().getData());

    this.breakedBlocks.add(replacedBlock.getBlock());
  }
}
 
Example #6
Source File: BlockAdapterMagicValues.java    From DungeonsXL with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BlockFace getFacing(Block block) {
    MaterialData data = block.getState().getData();
    if (!(data instanceof Directional)) {
        throw new IllegalArgumentException("Block is not Directional");
    }
    return ((Directional) data).getFacing();
}
 
Example #7
Source File: BlockAdapterMagicValues.java    From DungeonsXL with GNU General Public License v3.0 5 votes vote down vote up
@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();
}