Interface PersistentBlockData


public interface PersistentBlockData
This class allows you to obtain, store and restore a blocks data.

This class is pretty similar to todays Bukkit's BlockData API. The reason this exists is to add the same or similar functionality to older versions of spigot, as they don't have that functionality.

  • Method Details

    • getMaterial

      Material getMaterial()
      Returns the material of the block.
      Returns:
      The material of the block
    • place

      default void place(Block block)
      Places the data for a block at a specific location with applying phyics.
      Parameters:
      block - The block that shall be replaced with this data
    • place

      void place(Block block, boolean applyPhysics)
      Places the data for a block at a specific location.
      Parameters:
      block - The block that shall be replaced with this data
      applyPhysics - Doesn't calculate physics for this and surrounding blocks. May safe performance
    • getAsString

      String getAsString()
      Transforms the data into a string which later can be reloaded with parse(String).

      Keep in mind that it's likely possible that you want be able to load a parsed string in 1.8 - 1.12 within 1.13+ and vice versa.

      Returns:
      A string representing all daa stored in this instance
    • matches

      boolean matches(PersistentBlockData data)
      Returns if the given instance is similar to this one.
      Parameters:
      data - The other instance we want to compare with
      Returns:
      true when they match
    • matches

      boolean matches(Block block)
      Returns whether the stored data matches the current data of the given block.
      Parameters:
      block - The block that we want to match
      Returns:
      true when they are basically the same
    • getDyedData

      PersistentBlockData getDyedData(DyeColor color)
      Tries to dye this block and possibly returns a new instance with the blocked dyed in the given color.
      Parameters:
      color - The new color we want it to have
      Returns:
      A new instance with the new color, or this one
    • parse

      @Nullable static @Nullable PersistentBlockData parse(String str)
      Tries to parse a previously encoded string using getAsString().

      Keep in mind that it's likely possible that you want be able to load a parsed string in 1.8 - 1.12 within 1.13+ and vice versa.

      Parameters:
      str - The string we want to parse
      Returns:
      The parsed instance. null if it failed
    • fromBlock

      static PersistentBlockData fromBlock(Block block)
      Fetches all the data from the block and constructs a new instance from that
      Parameters:
      block - The block we want to read from
      Returns:
      The instance representing the data of the block at this given moment
    • fromMaterial

      static PersistentBlockData fromMaterial(Material mat)
      Constructs a new instance given by a material
      Parameters:
      mat - The material
      Returns:
      A new instance with only the given material at its containing data