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

The following examples show how to use org.bukkit.block.BlockState#getData() . 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: DoorEvent.java    From BetonQuest with GNU General Public License v3.0 6 votes vote down vote up
@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 2
Source File: XBlock.java    From XSeries with MIT License 6 votes vote down vote up
public static XMaterial getType(Block block) {
    if (ISFLAT) return XMaterial.matchXMaterial(block.getType());
    String type = block.getType().name();
    BlockState state = block.getState();
    MaterialData data = state.getData();

    if (data instanceof Wood) {
        TreeSpecies species = ((Wood) data).getSpecies();
        return XMaterial.matchXMaterial(species.name() + block.getType().name())
                .orElseThrow(() -> new IllegalArgumentException("Unsupported material from tree species " + species.name() + ": " + block.getType().name()));
    }
    if (data instanceof Colorable) {
        Colorable color = (Colorable) data;
        return XMaterial.matchXMaterial(color.getColor().name() + '_' + type).orElseThrow(() -> new IllegalArgumentException("Unsupported colored material"));
    }
    return XMaterial.matchXMaterial(block.getType());
}
 
Example 3
Source File: BukkitHandler1_12.java    From AreaShop with GNU General Public License v3.0 6 votes vote down vote up
@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: XBlock.java    From XSeries with MIT License 6 votes vote down vote up
public static boolean setDirection(Block block, BlockFace facing) {
    if (ISFLAT) {
        if (!(block.getBlockData() instanceof Directional)) return false;
        Directional direction = (Directional) block.getBlockData();
        direction.setFacing(facing);
        return true;
    }

    BlockState state = block.getState();
    MaterialData data = state.getData();
    if (data instanceof org.bukkit.material.Directional) {
        ((org.bukkit.material.Directional) data).setFacingDirection(facing);
        state.update(true);
        return true;
    }
    return false;
}
 
Example 5
Source File: XBlock.java    From XSeries with MIT License 6 votes vote down vote up
/**
 * Wool and Dye. But Dye is not a block itself.
 */
public static DyeColor getColor(Block block) {
    if (ISFLAT) {
        if (!(block.getBlockData() instanceof Colorable)) return null;
        Colorable colorable = (Colorable) block.getBlockData();
        return colorable.getColor();
    }

    BlockState state = block.getState();
    MaterialData data = state.getData();
    if (data instanceof Wool) {
        Wool wool = (Wool) data;
        return wool.getColor();
    }
    return null;
}
 
Example 6
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 7
Source File: VersionHelper18.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
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 8
Source File: XBlock.java    From XSeries with MIT License 5 votes vote down vote up
public static boolean setWooden(Block block, XMaterial species) {
    block.setType(species.parseMaterial());
    if (ISFLAT) return true;

    TreeSpecies type = species == XMaterial.SPRUCE_LOG ? TreeSpecies.REDWOOD :
            TreeSpecies.valueOf(species.name().substring(0, species.name().indexOf('_')));

    BlockState state = block.getState();
    MaterialData data = state.getData();
    ((Wood) data).setSpecies(type);
    state.update(true);
    return true;
}
 
Example 9
Source File: XBlock.java    From XSeries with MIT License 5 votes vote down vote up
public static int getFluidLevel(Block block) {
    if (ISFLAT) {
        if (!(block.getBlockData() instanceof Levelled)) return -1;
        Levelled levelled = (Levelled) block.getBlockData();
        return levelled.getLevel();
    }

    BlockState state = block.getState();
    MaterialData data = state.getData();
    return data.getData();
}
 
Example 10
Source File: XBlock.java    From XSeries with MIT License 5 votes vote down vote up
/**
 * Can be used on cauldron.
 */
public static boolean setFluidLevel(Block block, int level) {
    if (ISFLAT) {
        if (!(block.getBlockData() instanceof Levelled)) return false;
        Levelled levelled = (Levelled) block.getBlockData();
        levelled.setLevel(level);
        return true;
    }

    BlockState state = block.getState();
    MaterialData data = state.getData();
    data.setData((byte) level);
    state.update(true);
    return false;
}
 
Example 11
Source File: XBlock.java    From XSeries with MIT License 5 votes vote down vote up
public static int getAge(Block block) {
    if (ISFLAT) {
        if (!(block.getBlockData() instanceof Ageable)) return 0;
        Ageable ageable = (Ageable) block.getBlockData();
        return ageable.getAge();
    }

    BlockState state = block.getState();
    MaterialData data = state.getData();
    return data.getData();
}
 
Example 12
Source File: XBlock.java    From XSeries with MIT License 5 votes vote down vote up
public static BlockFace getDirection(Block block) {
    if (ISFLAT) {
        if (!(block.getBlockData() instanceof Directional)) return BlockFace.SELF;
        Directional direction = (Directional) block.getBlockData();
        return direction.getFacing();
    }

    BlockState state = block.getState();
    MaterialData data = state.getData();
    if (data instanceof org.bukkit.material.Directional) {
        return ((org.bukkit.material.Directional) data).getFacing();
    }
    return null;
}
 
Example 13
Source File: XBlock.java    From IridiumSkyblock with GNU General Public License v2.0 5 votes vote down vote up
public static boolean setWooden(Block block, XMaterial species) {
    block.setType(species.parseMaterial());
    if (XMaterial.ISFLAT) return true;

    TreeSpecies type = species == XMaterial.SPRUCE_LOG ? TreeSpecies.REDWOOD :
            TreeSpecies.valueOf(species.name().substring(0, species.name().indexOf('_')));

    BlockState state = block.getState();
    MaterialData data = state.getData();
    ((Wood) data).setSpecies(type);
    state.update(true);
    return true;
}
 
Example 14
Source File: XBlock.java    From IridiumSkyblock with GNU General Public License v2.0 5 votes vote down vote up
public static int getFluidLevel(Block block) {
    if (XMaterial.ISFLAT) {
        if (!(block.getBlockData() instanceof Levelled)) return -1;
        Levelled levelled = (Levelled) block.getBlockData();
        return levelled.getLevel();
    }

    BlockState state = block.getState();
    MaterialData data = state.getData();
    return data.getData();
}
 
Example 15
Source File: XBlock.java    From IridiumSkyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Can be used on cauldron.
 */
public static boolean setFluidLevel(Block block, int level) {
    if (XMaterial.ISFLAT) {
        if (!(block.getBlockData() instanceof Levelled)) return false;
        Levelled levelled = (Levelled) block.getBlockData();
        levelled.setLevel(level);
        return true;
    }

    BlockState state = block.getState();
    MaterialData data = state.getData();
    data.setData((byte) level);
    state.update(true);
    return false;
}
 
Example 16
Source File: XBlock.java    From IridiumSkyblock with GNU General Public License v2.0 5 votes vote down vote up
public static void setAge(Block block, int age) {
    if (XMaterial.ISFLAT) {
        if (!(block.getBlockData() instanceof Ageable)) return;
        Ageable ageable = (Ageable) block.getBlockData();
        ageable.setAge(age);
    }

    BlockState state = block.getState();
    MaterialData data = state.getData();
    data.setData((byte) age);
    state.update(true);
}
 
Example 17
Source File: XBlock.java    From IridiumSkyblock with GNU General Public License v2.0 5 votes vote down vote up
public static int getAge(Block block) {
    if (XMaterial.ISFLAT) {
        if (!(block.getBlockData() instanceof Ageable)) return 0;
        Ageable ageable = (Ageable) block.getBlockData();
        return ageable.getAge();
    }

    BlockState state = block.getState();
    MaterialData data = state.getData();
    return data.getData();
}
 
Example 18
Source File: XBlock.java    From IridiumSkyblock with GNU General Public License v2.0 5 votes vote down vote up
public static BlockFace getDirection(Block block) {
    if (XMaterial.ISFLAT) {
        if (!(block.getBlockData() instanceof Directional)) return BlockFace.SELF;
        Directional direction = (Directional) block.getBlockData();
        return direction.getFacing();
    }

    BlockState state = block.getState();
    MaterialData data = state.getData();
    if (data instanceof org.bukkit.material.Directional) {
        return ((org.bukkit.material.Directional) data).getFacing();
    }
    return null;
}
 
Example 19
Source File: LegacyRegion.java    From BedWars with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean isBedBlock(BlockState block) {
    return block.getData() instanceof Bed;
}
 
Example 20
Source File: LegacyRegion.java    From BedWars with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean isBedBlock(BlockState block) {
    return block.getData() instanceof Bed;
}