package net.cobem.grizzly.habbohotel.rooms;

import net.cobem.grizzly.Grizzly;

import java.util.ArrayList;
import java.util.List;

public class RoomMonitor implements Runnable {
    private boolean Running;
    private Thread RoomZ;

    public RoomMonitor() {
        RoomZ = new Thread(this);
        RoomZ.start();
        Running = true;
    }

    @Override
    public void run() {
        while (Running) {
            List<Room> EmptyRooms = new ArrayList<Room>();

            for (Room mRoom : Grizzly.getHabboHotel().getRooms().getPopulated().values()) {
                if (mRoom.getParty().size() <= 0) {
                    EmptyRooms.add(mRoom);
                } else {
                    mRoom.process();
                }
            }

            while (EmptyRooms.iterator().hasNext()) {
                Room mRoom = EmptyRooms.iterator().next();

                mRoom.removeAllRobots();

                Grizzly.getHabboHotel().getRooms().getPopulated().values().remove(mRoom);
            }

            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
            }
        }
    }

    public void Stop() {
        Running = false;
    }
}
