Keeping reference of a chunk in a List?

Discussion in 'Plugin Development' started by amitlin14, Feb 15, 2013.

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

    amitlin14

    So basically, i want to create a plugin that assigns a chunk to a player, a player can have multiple chunks, so i want to keep them all in a List<Chunk>.

    I understood that chunks load and unload, so im asking if its safe to save chunks to a list, and if not, what is the best way to reference a chunk to a player, so that if a player enters a chunk owned by another player, it will send him a message, or give him a potion effect or what-not
     
  2. Offline

    teunie75

    I think its safe to save chunks in a list, since the chunks themself don't change when they aren't loaded.
     
  3. amitlin14
    A chunk holds a world reference so I would store your data as chunks. Instead I would create a chunk wrapper class and use that. For example.

    Code:java
    1.  
    2. class ChunkWrapper{
    3. private final int x, z;
    4. private final String world;
    5.  
    6. public ChunkWrapper(String world, int x, int z){
    7. this.world = world;
    8. this.x= x;
    9. this.z= z;
    10. }
    11.  
    12. public Chunk getChunk(){
    13. World w = Bukkit.getServer().getWorld(this.world);
    14. if(w == null){
    15. return null; //invalid world
    16. } else {
    17. return w.getChunkAt(this.x, this.z);
    18. }
    19. }
    20. }
     
  4. Offline

    amitlin14

Thread Status:
Not open for further replies.

Share This Page