What would be the proper way of Saving Block Information

Discussion in 'Spigot Plugin Development' started by Kozs, Dec 27, 2016.

  1. So lets say a user places a block, and I want to save information on the block, my current idea was to make an object for the block (CustomBlock.java) and then serialize the instance and save it in MySQL. Or create a parent class and serialize that so it saves all of it's children.

    Is there a better way to do this? Haven't explored this sector yet, looking for ideas.


    Thanks.
     
  2. Why would you need a new object for blocks ? There is already a class Block in bukkit.
    You can do it this way:
    Create a table in your MySQL database with the following columns: Type, X, Y, Z and save the info from the Block instance into those columns.
    If you have a Block you can easily call for getType(), getX(), getZ() and then store these values in the table.
    There is no need to serialize the data, just save the minimum amount of info that you need for further use.