Solved Best way to keep track of a block's location?

Discussion in 'Plugin Development' started by Debels, Nov 20, 2013.

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

    Debels

    What would be the best way to keep track of a location?, Should I just keep the block and get the location or keep the location or keep a vector of the location?

    It will end up being something like:

    HashMap<Location|Block|Vector, String>....

    Of course only putting location, block or vector as the first argument. I'm thinking of going with Vector, is it the best choice?

    PS: I'm asking this since I don't know if this can cause a memory leak somewhere (like storing a player does)
     
  2. Offline

    Chinwe

    You can save it to a String (x,y,z,world), and then get the Location back when you need it, like this :)
     
  3. Offline

    NathanWolf

    I *think* that hashing by Location is OK. I believe they only reference Worlds, which are always all loaded anyway. I also think Location implements Comparable and hashId so I think that's the way to go. (Someone please correct me if I'm wrong on any of this!)

    If you were to go with Vector you would also need to add in the world name somehow to avoid the same location in multiple worlds mapping to the same place.
     
  4. Offline

    adam753

    None can cause memory leaks, they would all work. There are a few things to keep in mind though:
    -Location stores an exact location (doubles as opposed to ints) as well as yaw and pitch, so if it's just a block location you need then don't use this.
    -Unlike the other two, a Vector wouldn't remember which world it's in, so it may lose meaning if you store it as this.
    -Locations and Blocks aren't serializable, so you'll need a more creative solution if you want to store this hashmap in a file.
     
  5. Offline

    Debels

    Chinwe I don't think I would go with strings, btw Nice signature :)

    NathanWolf thanks, forgot Vector didn't store the world.

    adam753 Thanks for the information, now I'm sure I'll use Location.
     
Thread Status:
Not open for further replies.

Share This Page