Solved Storing BlockLocations

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

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


    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
    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


    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


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


    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


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


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

    Like so, for example:
          players: OwnerJonny
          players: OwnerJonny
          players: OwnerHarry
          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