1.11.2 Issue with a HashMap<Player, HashMap<Integer, ArrayList<Block>>>

Discussion in 'Spigot Plugin Development' started by PCPSells, Jan 26, 2020.

  1. This specific code is for a plugin that will support 1.7.10 - 1.12.2.

    Basically, it shouldn't be telling me I have nothing left to undo.
    The 1st 10x Sea lanterns were ID 1000, after doing `/undo` the 1st time, it removes properly (ID 1001), but afterwards it's like ID 1000 just gets removed or set to null, when it should contain those 1st 10x Sea lanterns.
    Any help would be greatly appreciated.
    • Optimistic Optimistic x 2
  2. There's not gonna be a lot of people that are willing to try and find a solution for your problem for the simple reason that no one wants to figure out what kind of list inside a map inside a map (2 times!) there is and how these are working together. First, try to simplify your structure (by using Objects that might effectively hold a HashMap but have better semantics and are thus way more readable) and then come back. Probably, you are going to find your error during that process.
    • Agree Agree x 2
  3. Store Locations instead of Blocks or you’re gonna cause a memory leak.
  4. FrostedSnowman

    Resource Staff

    Or better yet, vectors
  5. replace Player key for UUID variable and use oop
  6. A memory leak that exists if you are storing blocks will still leak memory from storing locations all the same. The pure fact that a block is being stored cannot cause a memory leak.
  7. Blocks aren’t meant to be stored long-term. Locations are. Storing blocks is bad practice and wastes more memory than locations.
    • Agree Agree x 1
  8. I didn’t say you shouldn’t store Locations (in fact, you should), I’m simply stating that it is incorrect to say that replacing Block objects with Location objects is any less prone to leaking memory.
    • Optimistic Optimistic x 1
  9. I tried the UUID. Same issues.
    #9 PCPSells, Jan 26, 2020
    Last edited: Jan 27, 2020
  10. Already tried that, doesn't work for what I'm doing.
  11. FrostedSnowman

    Resource Staff

    • Agree Agree x 2
  12. NEVER do that kind of stuff when you can use OOP class
  13. Well in that case, I'm absolutely clueless on how to fix this code. :cry:
  14. Any object that I create, I honestly can't think of a way to do that without HashMap's inside of HashMaps.
    The HashMap has to have a key of a player, which has an ArrayList of blocks, but said blocks have to have an ID so the plugin knows exactly which blocks to grab.
  15. You have to choose the non-lazy route and write all the necessary data structures your plugin needs. Sadly that's how things go when you want to write something that's a bit more complex than a teleportation plugin. :)
  16. Yeah, I get that. Especially after spending literally over 12 hours trying to understand why these methods don't work when they should.
    My issue is that I unfortunately don't know what I need to do with making that necessary data coded properly.
  17. Look up object oriented data modelling.
  18. Okay, so I've narrowed down the issue...
    For some reason, it clears the previous set of ArrayList<Block> from the previous ID