package ca.recrown.islandsurvivalcraft.world;

import java.util.HashMap;
import java.util.Random;
import java.util.UUID;

import org.bukkit.World;

import ca.recrown.islandsurvivalcraft.world.generation.IslandBiomeGenerator;
import ca.recrown.islandsurvivalcraft.world.generation.IslandWorldGenerator;

/**
 * Alternates the data used on a per world basis.
 * Uses IslandWorldGenerator as the container for each world.
 */
public class IslandWorldGeneratorAlternator {
    private HashMap<UUID, IslandWorldGenerator> chunkGenerator;
    private IslandBiomeGenerator islandBiomeGenerator;

    public IslandWorldGeneratorAlternator(IslandBiomeGenerator biomeGenerator) {
        chunkGenerator = new HashMap<>();
        this.islandBiomeGenerator = biomeGenerator;
    }

    public synchronized IslandWorldGenerator getIslandChunkGeneratorSystemForWorld(World world, Random random) {
        if (!chunkGenerator.containsKey(world.getUID())) {
            chunkGenerator.put(world.getUID(), new IslandWorldGenerator(world, islandBiomeGenerator.getInstance(), random));
        }
        return chunkGenerator.get(world.getUID());
    }
}