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


    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
  2. Offline


    You will have to store it as raw data type, eg int's/double's and Strings and then parse it yourself.


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

    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

    If you do use that class then please credit me.
  3. Offline


  4. Offline


  5. Offline


    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.
  6. Offline


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


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

    2. import;
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.Location;
    7. public class LocationPack implements Serializable {
    8. private static final long serialVersionUID = -8100514952085724461L;
    10. private final String worldname;
    11. private final double x;
    12. private final double y;
    13. private final double z;
    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. }
    22. public Location unpack() {
    23. Location location = new Location(Bukkit.getWorld(this.worldname), this.x, this.y, this.z);
    25. return location;
    26. }
    27. }
  8. Offline


    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