package net.sf.l2j.gameserver.instancemanager;

import javolution.util.FastList;
import net.sf.l2j.gameserver.model.L2Character;
import net.sf.l2j.gameserver.model.L2Object;
import net.sf.l2j.gameserver.model.zone.type.L2CustomZone;

public class CustomZoneManager
{
    private static CustomZoneManager _instance;
    public static final CustomZoneManager getInstance()
    {
        if (_instance == null)
        {
    		System.out.println("Initializing CustomZoneManager");
        	_instance = new CustomZoneManager();
        }
        return _instance;
    }
    private FastList<L2CustomZone> _zones;
    
    public CustomZoneManager()
    {
    }
    
    public void addZone(L2CustomZone zone)
    {
    	if (_zones == null)
    		_zones = new FastList<L2CustomZone>();
    	
    	_zones.add(zone);
    }

    public final L2CustomZone getZone(L2Character character)
    {
    	for (L2CustomZone temp : _zones)
    		if (temp.isCharacterInZone(character)) return temp;
    	return null;
    }
    
    public final L2CustomZone getZone(int x, int y, int z)
    {
        for (L2CustomZone temp : _zones)
        	if (temp.isInsideZone(x, y, z)) return temp;
        return null;
    }
    
    public boolean checkIfInZone(String zoneType, L2Object obj)
    {
    	L2CustomZone temp = getZone(obj.getX(), obj.getY(), obj.getZ());
    	if (temp == null) return false;
        return temp.getZoneName().equalsIgnoreCase(zoneType);
    }
    
}
