Java Code Examples for org.bukkit.block.BlockState#getBlockData()
The following examples show how to use
org.bukkit.block.BlockState#getBlockData() .
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: DoubleChestMatcher.java From Modern-LWC with MIT License | 6 votes |
public boolean matches(ProtectionFinder finder) { // get the block state if it's a chest BlockState baseBlockState = finder.getBaseBlock(); Chest baseBlockData = null; try { baseBlockData = (Chest) baseBlockState.getBlockData(); } catch (ClassCastException e) { return false; } // get the block face for the neighboring chest if there is one BlockFace neighboringBlockFace = getNeighboringChestBlockFace(baseBlockData); if (neighboringBlockFace == null) { return false; } // if the neighboring block is a chest as well, we have a match Block neighboringBlock = baseBlockState.getBlock().getRelative(neighboringBlockFace); if (baseBlockState.getType() == neighboringBlock.getType()) { finder.addBlock(neighboringBlock); return true; } return false; }
Example 2
Source File: BukkitHandler1_13.java From AreaShop with GNU General Public License v3.0 | 6 votes |
@Override public BlockFace getSignFacing(Block block) { if (block == null) { return null; } BlockState blockState = block.getState(); if (blockState == null) { return null; } BlockData blockData = blockState.getBlockData(); if (blockData == null) { return null; } if(blockData instanceof WallSign) { return ((WallSign) blockData).getFacing(); } else if(blockData instanceof Sign) { return ((Sign) blockData).getRotation(); } return null; }
Example 3
Source File: BukkitHandler1_13.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; } BlockData blockData = blockState.getBlockData(); if (blockData == null) { return false; } if(blockData instanceof WallSign) { ((WallSign) blockData).setFacing(facing); } else if(blockData instanceof Sign) { ((Sign) blockData).setRotation(facing); } else { return false; } block.setBlockData(blockData); return true; }
Example 4
Source File: BukkitHandler1_13.java From AreaShop with GNU General Public License v3.0 | 6 votes |
@Override public Block getSignAttachedTo(Block block) { if (block == null) { return null; } BlockState blockState = block.getState(); if (blockState == null) { return null; } org.bukkit.block.data.BlockData blockData = blockState.getBlockData(); if (blockData == null) { return null; } if(blockData instanceof WallSign) { return block.getRelative(((WallSign) blockData).getFacing().getOppositeFace()); } else if(blockData instanceof Sign) { return block.getRelative(BlockFace.DOWN); } return null; }
Example 5
Source File: XBlock.java From XSeries with MIT License | 5 votes |
public static void setEnderPearlOnFrame(Block endPortalFrame, boolean eye) { BlockState state = endPortalFrame.getState(); if (ISFLAT) { BlockData data = state.getBlockData(); EndPortalFrame frame = (EndPortalFrame) data; frame.setEye(eye); state.setBlockData(frame); } else { state.setRawData((byte) (eye ? 4 : 0)); } state.update(true); }
Example 6
Source File: LWC.java From Modern-LWC with MIT License | 5 votes |
/** * Look for a double chest adjacent to a chest * * @param block * @return */ public Block findAdjacentDoubleChest(Block block) { if (!DoubleChestMatcher.PROTECTABLES_CHESTS.contains(block.getType())) { throw new UnsupportedOperationException( "findAdjacentDoubleChest() cannot be called on a: " + block.getType()); } BlockState baseBlockState = block.getState(); Chest baseBlockData = null; try { baseBlockData = (Chest) baseBlockState.getBlockData(); } catch (ClassCastException e) { return null; } // get the block face for the neighboring chest if there is one BlockFace neighboringBlockFace = DoubleChestMatcher.getNeighboringChestBlockFace(baseBlockData); if (neighboringBlockFace == null) { return null; } // if the neighboring block is a chest as well, we have a match Block neighboringBlock = baseBlockState.getBlock().getRelative(neighboringBlockFace); if (baseBlockState.getType() == neighboringBlock.getType()) { return block; } return null; }
Example 7
Source File: NewBlockCompat.java From Skript with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("null") @Nullable @Override public BlockValues getBlockValues(BlockState block) { // If block doesn't have useful data, data field of type is MaterialData if (block.getType().isBlock()) return new NewBlockValues(block.getType(), block.getBlockData(), false); return null; }
Example 8
Source File: FlatteningRegion.java From BedWars with GNU Lesser General Public License v3.0 | 4 votes |
@Override public boolean isBedBlock(BlockState block) { return block.getBlockData() instanceof Bed; }
Example 9
Source File: ShopManager.java From QuickShop-Reremake with GNU General Public License v3.0 | 4 votes |
/** * Create a shop use Shop and Info object. * * @param shop The shop object * @param info The info object */ public void createShop(@NotNull Shop shop, @NotNull Info info) { Player player = Bukkit.getPlayer(shop.getOwner()); if (player == null) { throw new IllegalStateException("The owner creating the shop is offline or not exist"); } ShopCreateEvent shopCreateEvent = new ShopCreateEvent(shop, player); if (Util.fireCancellableEvent(shopCreateEvent)) { Util.debugLog("Cancelled by plugin"); return; } if (info.getSignBlock() != null && autoSign) { if (Util.isAir(info.getSignBlock().getType()) || info.getSignBlock().getType() == Material.WATER) { info.getSignBlock().setType(Util.getSignMaterial()); BlockState bs = info.getSignBlock().getState(); if (info.getSignBlock().getType() == Material.WATER && (bs.getBlockData() instanceof Waterlogged)) { Waterlogged waterable = (Waterlogged) bs.getBlockData(); waterable.setWaterlogged(true); // Looks like sign directly put in water } if (bs.getBlockData() instanceof WallSign) { WallSign signBlockDataType = (WallSign) bs.getBlockData(); BlockFace bf = info.getLocation().getBlock().getFace(info.getSignBlock()); if (bf != null) { signBlockDataType.setFacing(bf); bs.setBlockData(signBlockDataType); } } else { plugin.getLogger().warning("Sign material " + bs.getType().name() + " not a WallSign, make sure you using correct sign material."); } bs.update(true); } else { if (!plugin.getConfig().getBoolean("shop.allow-shop-without-space-for-sign")) { MsgUtil.sendMessage(player, MsgUtil.getMessage("failed-to-put-sign", player)); Util.debugLog("Sign cannot placed cause no enough space(Not air block)"); return; } } } //load the shop finally shop.onLoad(); //first init shop.setSignText(); //sync add to prevent compete issue addShop(shop.getLocation().getWorld().getName(), shop); //save to database plugin.getDatabaseHelper().createShop( shop, null, e -> Bukkit.getScheduler().runTask(plugin, () -> { //also remove from memory when failed shop.delete(true); plugin.getLogger().warning("Shop create failed, trying to auto fix the database..."); boolean backupSuccess = Util.backupDatabase(); if (backupSuccess) { plugin.getDatabaseHelper().removeShop(shop); } else { plugin.getLogger().warning("Failed to backup the database, all changes will revert after a reboot."); } })); }
Example 10
Source File: FlatteningRegion.java From BedWars with GNU Lesser General Public License v3.0 | 4 votes |
@Override public boolean isBedBlock(BlockState block) { return block.getBlockData() instanceof Bed; }