Saving Location to a file from a hashmap?

Discussion in 'Plugin Development' started by CevinWa, Jun 9, 2012.

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

    CevinWa

    I've tried in many ways but im stuck i can just save an arraylist but not a hashmap and i realy need help doing this.
    Thanks for looking at this :D
    //CevinWa
     
  2. You will have to store it as raw data type, eg int's/double's and Strings and then parse it yourself.

    Eg

    Code:java
    1.  
    2. Location loc;
    3. String savedLoc = loc.getWorld.getName() + ":" + loc.getX() + ":" + loc.getY() + ":" + loc.getZ() + ";"
    4.  


    In this case I am using the colon : as the delimeter and the semi colon ; as the end tag. You can then parse these locations yourself by using String.split(":") and then taking the args from that array and passing them into the location constructor.

    Location loc = new Location(world, x, y, z);

    Alternatively you may want to use my serializable Location class from Sync https://github.com/Adamki11s/Sync/blob/master/src/couk/Adamki11s/IO/Serializable/SyncLocation.java

    If you do use that class then please credit me.
     
  3. Then make a custom location class :p it's best that way too since the Bukkit Location has references to worlds and stuff that shouldn't be stored... AFAIK.
     
  4. Offline

    CevinWa

    But i have one problem. How do i save the hashmap itself im pretty new to coding and don't know all about everything so it would be of great help. Could u just not save a hashmap in an arraylist or something cuz i looked at the class u linked and come up with that i have no clue what's in it. Sorry for my noobness.
    Thank you for helping me.
    //CevinWa
     
  5. Offline

    LucasEmanuel

    I use this object whenever i want to save a location :)

    Code:java
    1.  
    2. import java.io.Serializable;
    3.  
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.Location;
    6.  
    7. public class LocationPack implements Serializable {
    8. private static final long serialVersionUID = -8100514952085724461L;
    9.  
    10. private final String worldname;
    11. private final double x;
    12. private final double y;
    13. private final double z;
    14.  
    15. public LocationPack(Location location) {
    16. this.worldname = location.getWorld().getName();
    17. this.x = location.getX();
    18. this.y = location.getY();
    19. this.z = location.getZ();
    20. }
    21.  
    22. public Location unpack() {
    23. Location location = new Location(Bukkit.getWorld(this.worldname), this.x, this.y, this.z);
    24.  
    25. return location;
    26. }
    27. }
     
  6. Yeah that's what I did in Sync. I was suggesting he either copy it or make something similar lol :p
     
Thread Status:
Not open for further replies.

Share This Page