Chunk X and Chunk Z Saving to a file

Discussion in 'Plugin Development' started by samus1221, Jan 14, 2014.

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

    samus1221

    Hello, I am trying to save Chunk X and Z to a file, I don't know what the most efficient way of doing this so I am asking for any help I can get. I would be saving the locations to a file like this:

    Chunks:
    - 11, 12
    - 13. 12

    (X, Z)
     
  2. Offline

    Compressions

  3. Offline

    samus1221

    Hashmaps, plus I have tried doing something like this:

    ChunkX:
    - 12

    ChunkZ:
    - 11

    But then i found out this is completely useless. I need the integers as a grouping like so (X, Z)

    How would i go about doing something like this?
     
  4. Offline

    Compressions

    samus1221 Create a string out of it(e.g. "x, z").
    Code:
    String xz = x + ", " + z;
    Save that to the config.
    When you want to get it from the config, split the string.
    Code:
    int x = Integer.parseInt(configString.split(", ")[0]);
    int z = Integer.parseInt(configString.split(", ")[1]);
     
  5. Offline

    samus1221

    Dude, I thank you so much...
     
  6. Offline

    Compressions

  7. Offline

    Maurdekye

    To save the chunks to a file, use this;
    Code:java
    1. try {
    2. PrintWriter file = new PrintWriter(new BufferedWriter(new FileWriter("chunks.txt")));
    3. } catch (IOException e) {};


    And to load them back up, use this;
    Code:java
    1. ArrayList<Chunk> chunks = new ArrayList<Chunk>();
    2. try {
    3. BufferedReader file = new BufferedReader(new FileReader("chunks.txt"));
    4. while (file.ready()) {
    5. String[] line = file.readLine().split(":");
    6. int[] pos = {1, 1};
    7. for (int i=0;i<1;i++) {
    8. try {
    9. pos[i] = Integer.parseInt(line[i]);
    10. } catch (NumberFormatException e) {}
    11. }
    12. chunks.add(world.getChunkAt(pos[0], pos[1]));
    13. }
    14.  
    15. } catch (IOException e) {};[/i][/i]
     
  8. Offline

    Compressions

    Maurdekye That's a little much when you have FileConfiguration...
     
  9. Offline

    Maurdekye

    Compressions what's FileConfiguration? This is what I've always done. Does bukkit have a built in method of dealing with files or something?
     
  10. Offline

    Compressions

  11. Offline

    Maurdekye

Thread Status:
Not open for further replies.

Share This Page