Class XBlock


  • public final class XBlock
    extends Object
    XBlock - MaterialData/BlockData Support
    BlockState (Old): https://hub.spigotmc.org/javadocs/spigot/org/bukkit/block/BlockState.html BlockData (New): https://hub.spigotmc.org/javadocs/spigot/org/bukkit/block/data/BlockData.html MaterialData (Old): https://hub.spigotmc.org/javadocs/spigot/org/bukkit/material/MaterialData.html

    All the parameters are non-null except the ones marked as nullable. This class doesn't and shouldn't support materials that are Material.isLegacy().

    Version:
    2.2.0
    Author:
    Crypto Morin
    See Also:
    Block, BlockState, MaterialData, XMaterial
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  XBlock.BlockMaterial
      An enum with cached legacy materials which can be used when comparing blocks with blocks and blocks with items.
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static int addCakeSlices​(org.bukkit.block.Block block, int slices)  
      static int getAge​(org.bukkit.block.Block block)  
      static org.bukkit.DyeColor getColor​(org.bukkit.block.Block block)
      Wool and Dye.
      static org.bukkit.block.BlockFace getDirection​(org.bukkit.block.Block block)  
      static int getFluidLevel​(org.bukkit.block.Block block)  
      static org.bukkit.block.BlockFace getRotation​(org.bukkit.block.Block block)  
      static XMaterial getType​(org.bukkit.block.Block block)
      Deprecated.
      static boolean isAir​(org.bukkit.Material material)  
      static boolean isBeetroot​(org.bukkit.Material material)  
      static boolean isCake​(org.bukkit.Material material)  
      static boolean isCarrot​(org.bukkit.Material material)  
      static boolean isContainer​(org.bukkit.block.Block block)
      Checks if the block is a container.
      static boolean isCrop​(XMaterial material)
      Any material that can be planted which is from CROPS
      static boolean isDangerous​(XMaterial material)
      Any material that can damage players, usually by interacting with the block.
      static boolean isLava​(org.bukkit.Material material)  
      static boolean isLit​(org.bukkit.block.Block block)  
      static boolean isMelon​(org.bukkit.Material material)  
      static boolean isNetherWart​(org.bukkit.Material material)  
      static boolean isOneOf​(org.bukkit.block.Block block, Collection<String> blocks)  
      static boolean isOpen​(org.bukkit.block.Block block)  
      static boolean isPotato​(org.bukkit.Material material)  
      static boolean isPowered​(org.bukkit.block.Block block)  
      static boolean isSimilar​(org.bukkit.block.Block block, XMaterial material)
      Same as isType(Block, XMaterial) except it also does a simple XMaterial.matchXMaterial(Material) comparison with the given block and material.
      static boolean isSugarCane​(org.bukkit.Material material)  
      static boolean isType​(org.bukkit.block.Block block, XMaterial material)
      Universal Method
      static boolean isWater​(org.bukkit.Material material)  
      static boolean isWaterStationary​(org.bukkit.block.Block block)  
      static boolean isWheat​(org.bukkit.Material material)  
      static void setAge​(org.bukkit.block.Block block, int age)  
      static void setCakeSlices​(org.bukkit.block.Block block, int amount)  
      static boolean setColor​(org.bukkit.block.Block block, org.bukkit.DyeColor color)
      Sets the type of any block that can be colored.
      static boolean setDirection​(org.bukkit.block.Block block, org.bukkit.block.BlockFace facing)  
      static void setEnderPearlOnFrame​(org.bukkit.block.Block endPortalFrame, boolean eye)  
      static boolean setFluidLevel​(org.bukkit.block.Block block, int level)
      Can be used on cauldrons as well.
      static void setLit​(org.bukkit.block.Block block, boolean lit)
      Can be furnaces or redstone lamps.
      static void setOpened​(org.bukkit.block.Block block, boolean opened)  
      static void setPowered​(org.bukkit.block.Block block, boolean powered)  
      static void setRotation​(org.bukkit.block.Block block, org.bukkit.block.BlockFace facing)  
      static boolean setType​(org.bukkit.block.Block block, XMaterial material)  
    • Method Detail

      • isLit

        public static boolean isLit​(org.bukkit.block.Block block)
      • isContainer

        public static boolean isContainer​(@Nullable
                                          org.bukkit.block.Block block)
        Checks if the block is a container. Containers are chests, hoppers, enderchests and everything that has an inventory.
        Parameters:
        block - the block to check.
        Returns:
        true if the block is a container, otherwise false.
      • setLit

        public static void setLit​(org.bukkit.block.Block block,
                                  boolean lit)
        Can be furnaces or redstone lamps.
        Parameters:
        block - the block to change.
        lit - if it should be lit or not.
      • isCrop

        public static boolean isCrop​(XMaterial material)
        Any material that can be planted which is from CROPS
        Parameters:
        material - the material to check.
        Returns:
        true if this material is a crop, otherwise false.
      • isDangerous

        public static boolean isDangerous​(XMaterial material)
        Any material that can damage players, usually by interacting with the block.
        Parameters:
        material - the material to check.
        Returns:
        true if this material is dangerous, otherwise false.
      • getColor

        public static org.bukkit.DyeColor getColor​(org.bukkit.block.Block block)
        Wool and Dye. But Dye is not a block itself.
      • isCake

        public static boolean isCake​(@Nullable
                                     org.bukkit.Material material)
      • isWheat

        public static boolean isWheat​(@Nullable
                                      org.bukkit.Material material)
      • isSugarCane

        public static boolean isSugarCane​(@Nullable
                                          org.bukkit.Material material)
      • isBeetroot

        public static boolean isBeetroot​(@Nullable
                                         org.bukkit.Material material)
      • isNetherWart

        public static boolean isNetherWart​(@Nullable
                                           org.bukkit.Material material)
      • isCarrot

        public static boolean isCarrot​(@Nullable
                                       org.bukkit.Material material)
      • isMelon

        public static boolean isMelon​(@Nullable
                                      org.bukkit.Material material)
      • isPotato

        public static boolean isPotato​(@Nullable
                                       org.bukkit.Material material)
      • getDirection

        public static org.bukkit.block.BlockFace getDirection​(org.bukkit.block.Block block)
      • setDirection

        public static boolean setDirection​(org.bukkit.block.Block block,
                                           org.bukkit.block.BlockFace facing)
      • getAge

        public static int getAge​(org.bukkit.block.Block block)
      • setAge

        public static void setAge​(org.bukkit.block.Block block,
                                  int age)
      • setColor

        public static boolean setColor​(org.bukkit.block.Block block,
                                       org.bukkit.DyeColor color)
        Sets the type of any block that can be colored.
        Parameters:
        block - the block to color.
        color - the color to use.
        Returns:
        true if the block can be colored, otherwise false.
      • setFluidLevel

        public static boolean setFluidLevel​(org.bukkit.block.Block block,
                                            int level)
        Can be used on cauldrons as well.
        Parameters:
        block - the block to set the fluid level of.
        level - the level of fluid.
        Returns:
        true if this block can have a fluid level, otherwise false.
      • getFluidLevel

        public static int getFluidLevel​(org.bukkit.block.Block block)
      • isWaterStationary

        public static boolean isWaterStationary​(org.bukkit.block.Block block)
      • isWater

        public static boolean isWater​(org.bukkit.Material material)
      • isLava

        public static boolean isLava​(org.bukkit.Material material)
      • isOneOf

        public static boolean isOneOf​(org.bukkit.block.Block block,
                                      Collection<String> blocks)
      • setCakeSlices

        public static void setCakeSlices​(org.bukkit.block.Block block,
                                         int amount)
      • addCakeSlices

        public static int addCakeSlices​(org.bukkit.block.Block block,
                                        int slices)
      • setEnderPearlOnFrame

        public static void setEnderPearlOnFrame​(org.bukkit.block.Block endPortalFrame,
                                                boolean eye)
      • isType

        public static boolean isType​(org.bukkit.block.Block block,
                                     XMaterial material)
        Universal Method

        Check if the block type matches the specified XMaterial. Note that this method assumes that you've already tried doing XMaterial.matchXMaterial(Material) using Block.getType() and compared it with the other XMaterial. If not, use isSimilar(Block, XMaterial)

        Parameters:
        block - the block to check.
        material - the XMaterial similar to this block type.
        Returns:
        true if the raw block type matches with the material.
        See Also:
        isSimilar(Block, XMaterial)
      • isAir

        public static boolean isAir​(@Nullable
                                    org.bukkit.Material material)
      • isPowered

        public static boolean isPowered​(org.bukkit.block.Block block)
      • setPowered

        public static void setPowered​(org.bukkit.block.Block block,
                                      boolean powered)
      • isOpen

        public static boolean isOpen​(org.bukkit.block.Block block)
      • setOpened

        public static void setOpened​(org.bukkit.block.Block block,
                                     boolean opened)
      • getRotation

        public static org.bukkit.block.BlockFace getRotation​(org.bukkit.block.Block block)
      • setRotation

        public static void setRotation​(org.bukkit.block.Block block,
                                       org.bukkit.block.BlockFace facing)