Solved Storing BlockLocations

Discussion in 'Plugin Development' started by jacklin213, Apr 30, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    jacklin213

    Hey all , I've looked for some ways of storing Blocks and i see a lot of posts saying you shouldn't store blocks but BlockLocations.

    I'm having trouble with Storing BlockLocations , mainly i don't know where to start off.

    What im trying to do is
    Code:java
    1. public void blockPlace(BlockPlaceEvent event){
    2. Player player = event.getPlayer();
    3. if (player.hasPermission("protection.protect")){
    4. Block block = event.getBlockPlaced();
    5. Location location = block.getLocation();
    6. int x = location.getBlockX();
    7. int y = location.getBlockY();
    8. int z = location.getBlockZ();
    9. //Store the blocklocation <<<<< NEED HELP HERE
    10. }
    11. }


    Thanks in advance
     
  2. Offline

    CubieX

    Best way seems to be using a database for this.
    Kind of like LWC does it with a SQLite DB.

    You could also use a separate yml file to store those block locations.
    This would be easier for you, if you have no expierience with using DBs.
    But I would not really recommend that for such kind of plugin.
     
  3. Offline

    jacklin213

    Cant i store it in a hashmap or something?
     
  4. Offline

    CubieX

    A Hashmap will not suffice. Because as soon as the server shuts down, your HashMap is gone forever.
    You need to store this on your hard disk.

    You may have to store it temporarely in a suiting data structure to handle it better.
    But your back-end has to be a file or database where you store the data remanently, whenever something changes.
     
  5. Offline

    jacklin213

    could i store it onto a file , one block each line eg
    Code:
    180, 98, 278
    217, 76, 365
    126, 186, 150
    and then when the plugin starts , put them all back into the hashmap
     
  6. Offline

    CubieX

    You could. But extracting it that way would be a bit unpractical.
    Better use yml-sytle.

    Like so, for example:
    Code:
    blocks:
      worldA:
        180_89_278:
          players: OwnerJonny
        1150_64_-455:
          players: OwnerJonny
      worldB:
        5456_45_-4156:
          players: OwnerHarry
        123_78_1578:
          players: [OwnerJonny, OwnerHarry, OwnerSally]
    Saving the world is probably a good idea to make it multi-world capable.

    Also you don't have to put them all in a HashMap.
    Just read them from your config as needed.
     
Thread Status:
Not open for further replies.

Share This Page