Save Entity Position into Hashmap

Discussion in 'Plugin Development' started by LordVakar, Nov 16, 2013.

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

    LordVakar

    How would I put an entity's position into a hashmap
    So I would do:
    npc.getLocation();
    What would I add to that line to save it into a hashmap?

    This is my hashmap:
    HashMap<Integer,String> guideVillagers = new HashMap<Integer,String>();

    Is an Integer, String hashmap correct?

    This is what I'm using to save and load my hashmaps (From the tut!)
    Code:java
    1.  
    2. public void save(HashMap<Integer, String> guideVillagers2, String path)
    3. {
    4. try
    5. {
    6. oos.writeObject(guideVillagers2);
    7. oos.flush();
    8. oos.close();
    9. }
    10. catch(Exception e)
    11. {
    12. e.printStackTrace();
    13. }
    14. }
    15.  
    16. public HashMap<Integer, String> load(String path)
    17. {
    18. try
    19. {
    20. Object result = ois.readObject();
    21. return (HashMap<Integer, String>)result;
    22. }
    23. catch(Exception e)
    24. {
    25. e.printStackTrace();
    26. }
    27. return null;
    28. }
     
  2. Offline

    GusGold

    LordVakar
    It would be a lot easier to be a <Integer, Location> map. That way, you key the entity id to the location of the entity.
     
  3. Offline

    CubieX

    When using a Loaction object, keep in mind that this will Bukkit to not unload the affected chunk or world, unless you delete this location from the map. So it may cause a memory leak.
    To prevent this, better store the location in a concaternated string.
    Like:
    Code:
    world_x_y_z
    in your HashMap. So use a HashMap<Integer, String> for it to store the entities ID and location.
     
  4. Offline

    jacklin213

Thread Status:
Not open for further replies.

Share This Page