package net.cobem.grizzly.communication.events.rooms;

import net.cobem.grizzly.Grizzly;
import net.cobem.grizzly.communication.EventRequest;
import net.cobem.grizzly.communication.GameEvent;
import net.cobem.grizzly.communication.composers.rooms.SendRoomChatComposer;
import net.cobem.grizzly.communication.composers.rooms.SendRoomWhisperComposer;
import net.cobem.grizzly.habbohotel.sessions.Session;

public class SayEvent implements GameEvent {
    @Override
    public void compose(Session Session, EventRequest Request) {
        if (!Session.getActor().inRoom()) {
            return;
        }

        String Str = Request.readString().trim();
        int Color = Request.readInt();

        if (Str.startsWith(":") && Grizzly.getHabboHotel().getCommands().parse(Session, Str.replace(":", ""))) {
            return;
        }

        if (Session.getActor().CurrentRoom.getWiredUtility().onUserTalk(Session, Str))  {
            Session.sendResponse(SendRoomWhisperComposer.compose(Session.getHabbo().getID(), Str, 0));
        } else {
            Session.getActor().CurrentRoom.sendMessage(SendRoomChatComposer.compose(Session.getHabbo().getID(), Str, Grizzly.getHabboHotel().parseSmile(Str), Color));
        }
    }
}
