BlockStore 1.5.0

Developer tool - adds persistent block metadata and checking whether a block is placed by a player

  1. sothatsit
    Tested Minecraft Versions:
    • 1.8
    • 1.9
    • 1.10
    • 1.11
    • 1.12
    Contributors:
    sothatsit
    [​IMG]


    [​IMG]
    BlockStore allows plugins to store information about blocks that is saved across restarts. This is incredibly useful as managing persistence yourself on a large scale is a big job.

    Some useful things you could do with BlockStore:

    • Create machines with custom inventories
    • Remember who placed a block
    • Remember the name of placed player heads
    • Create fortune for gold ore that only works on gold not placed by players

    [​IMG]
    Open the spoiler below to learn about:

    • Commands for checking BlockStore
    • Configuration for changing memory usage and efficiency of BlockStore
    • Developer's Guide for using BlockStore in your plugin
    • Source Code of BlockStore
    [​IMG]
    /blockstore check
    - Check whether a block was placed by a human and check a block's metadata
    permission: blockstore.check

    /blockstore info
    - Get info on the loaded chunks
    permission: blockstore.info

    /blockstore reload

    - Reload the configuration of BlockStore
    permission: blockstore.reload


    [​IMG]
    The default config is as follows, with the values you can give specified in comments:
    Code (Text):
    # All - If a chunk is loaded in game, it will be preloaded by BlockStore
    # Close - If a chunk is next to a player in the game, it will be preloaded by BlockStore
    # None - No chunks will be preloaded by BlockStore, chunks will be loaded as they are used
    preload: 'Close'

    # The time in seconds to wait after a chunk store is used to unload it
    unload-time: 60
    [​IMG]
    If you are using a newer version of WorldEdit, this plugin will be able to hook into it and will mark any blocks changed by WorldEdit as natural.

    [​IMG]
    Ok, so how do we use it?

    Well, its quite simple actually, you can either:

    a) add the plugin as a dependency in your plugin.yml
    b) check whether the api is available to you using
    Code (Text):
    Bukkit.getPluginManager().getPlugin("BlockStore") != null;
    Then you can use the api, which contains the methods:
    Code (Text):
    boolean isPlaced(Block block)
    boolean isPlaced(Location loc)
    retrieveIsPlaced(Plugin callingPlugin, Block block, Consumer<Boolean> consumer)
    retrieveIsPlaced(Plugin callingPlugin, Location loc, Consumer<Boolean> consumer)

    setPlaced(Block block, boolean placed)
    setPlaced(Location loc, boolean placed)

    Object getBlockMeta(Block block, Plugin plugin, String key)
    Object getBlockMeta(Location loc, Plugin plugin, String key)
    retrieveBlockMeta(Plugin callingPlugin, Block block, Plugin plugin, String key, Consumer<Object> consumer)
    retrieveBlockMeta(Plugin callingPlugin, Location loc, Plugin plugin, String key, Consumer<Object> consumer)

    Map<String, Object> getAllBlockMeta(Block block, Plugin plugin)
    Map<String, Object> getAllBlockMeta(Location loc, Plugin plugin)
    retrieveAllBlockMeta(Plugin callingPlugin, Block block, Plugin plugin, Consumer<Map<String, Object>> consumer)
    retrieveAllBlockMeta(Plugin callingPlugin, Location loc, Plugin plugin, Consumer<Map<String, Object>> consumer)

    Map<String, Object> getAllBlockMeta(Block block)
    Map<String, Object> getAllBlockMeta(Location loc)
    retrieveAllBlockMeta(Plugin callingPlugin, Block block, Consumer<Map<String, Map<String, Object>>> consumer)
    retrieveAllBlockMeta(Plugin callingPlugin, Location loc, Consumer<Map<String, Map<String, Object>>> consumer)

    boolean containsBlockMeta(Block block, Plugin plugin, String key)
    boolean containsBlockMeta(Location loc, Plugin plugin, String key)
    retrieveContainsBlockMeta(Plugin callingPlugin, Block block, Plugin plugin, String key, Consumer<Boolean> consumer)
    retrieveContainsBlockMeta(Plugin callingPlugin, Location loc, Plugin plugin, String key, Consumer<Boolean> consumer)

    setBlockMeta(Block block, Plugin plugin, String key, Object value)
    setBlockMeta(Location loc, Plugin plugin, String key, Object value)

    removeBlockMeta(Block block, Plugin plugin, String key)
    removeBlockMeta(Location loc, Plugin plugin, String key)
    All these methods are static members of the class BlockStoreApi and can be used as such:
    Code (Text):
    String name = (String) BlockStoreApi.getBlockMeta(myBlock, myPlugin, "name");

    Metadata Restrictions:
    Block Metadata must be of the type
    - String
    - boolean

    - byte
    - short
    - int
    - long
    - float
    - double

    and all the array subclasses of these, such as
    String[] or int[][]

    Note: Getting block's state during the ChunkLoadEvent or before chunks have loaded will cause the thread to block if the chunk has not already been preloaded by BlockStore. This can be fixed by running this logic asynchronously or using the retrieve methods of the API, which will handle waiting until the chunk is loaded for you.


    [​IMG]

    The source code for BlockStore is available on GitHub.

    [​IMG]

    [​IMG]
    A small, $5 donation helps me support my coding habits and provide you with awesome plugins such as this one, completely for free!

    Although this plugin may appear simple (as it has been designed to be!), a huge amount of work has gone into its backend to make sure it uses CPU, memory and storage as efficiently as possible!

    If this plugin helps you with your projects or servers, a small donation would be hugely appreciated!

    You can donate here :)


    [​IMG]
    [​IMG] [​IMG] [​IMG]
    ChristopherMoore and ZeeZee like this.

Recent Reviews

  1. MindBurned
    MindBurned
    5/5,
    Version: 1.5.0
    good work again friend keep your plugins like even if you do not take any updates but still everything is work great greetings
  2. Sataniel
    Sataniel
    5/5,
    Version: 1.2
    This is an amazing resource. Simple to use, yet as powerful as it needs to be. I haven't found any bugs or other issues since I use it.
  3. Freestylegamer3
    Freestylegamer3
    5/5,
    Version: 1.13
    looks really good but havent tried it yet but dose it work with 1.11? and if it dose i will try it and if i like it will keep useing it :)
  4. BlackBeltPanda
    BlackBeltPanda
    5/5,
    Version: 1.12
    Super useful for adding permanent metadata to objects or finding out if an object was placed by a player.
    Using this for enabling/disabling machines I've created for my Skyblock server, as well as for tracking placed spawners vs naturally generated spawners. =)