Check for chests in a area.

Discussion in 'Spigot Plugin Development' started by ItzScorp, Jun 2, 2015.

  1. How can i check for the chests in a area? Like a cuboid or something

    Position one: X: 255, Y: 249, Z: -226
    Position two: X: -176 Y:2 Z: 255
  2. You have to check every blocks id between those positions. If you don't know how to do this, go out, think 10 minutes and then code it. If you dont know anything of the bukkit api, this is the wrong place to ask. Sry, no spoonfeeding here.
  3. It's WAY more efficient to grab all the chunks that are between these two locations and loop through the tile entities.
    • Agree Agree x 1
  4. Nvm already found a way :p. Just check for player interact than check if chest is empty and not used yet (hashmap saving) then add random shit. xd
  5. Okay now im stuck again. Maybe because im tired. but how would i check if the hashmap contains the chests location and check if the boolean is false? And after that how to set it to true?
  6. Why not just make an arraylist? And just check if it contains it?
  7. hashmap.contains(chest) --> returns if chest is already in
    hashmap.get(chest) --> returns if chest is assigned true
    hashmap.put(chest, true) --> assigns value "true" to the chest
  8. There's no 'contains' method for a HashMap. Use 'containsKey' instead.
    Also, you don't have to store booleans in a HashMap — use an ArrayList instead. If the ArrayList contains the specified object, it equals true.
  9. Sry.

    Yeah, when a chest hasn't been opened yet, you havent filled it yet. So when the ArrayList does not contain your chest, add it in there and fill it :)
  10. Don't use an ArrayList, use a HashSet - much more efficient for searching.
  11. I think unless he inserts 100000 objects a tick, he doesn't have to worry about performance, as it is simple negligible.
    • Agree Agree x 1
  12. It's good to practice efficient coding whether it matters or not.

    The way I read the question, he's going to be storing chests he's "used" forever. It doesn't matter how *often* he does this- over time that list is going to grow and grow. Even iterating over 1,000 entries you will feel the hit of slowness.

    Personally, I feel if you are *ever* calling .contains on a List (either LinkedList or ArrayList), you should re-evaluate your data models and/or algorithms.
  13. ALready know a way. Using arraylist and storing the chests location :p