// • ▌ ▄ ·.  ▄▄▄·  ▄▄ • ▪   ▄▄· ▄▄▄▄·  ▄▄▄·  ▐▄▄▄  ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀  █▪▀▀▀ ▀  ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀  ▀  ▀ ▀▀  █▪ ▀▀▀
//      Magicbane Emulator Project © 2013 - 2022
//                www.magicbane.com

package engine.net.client.handlers;

import engine.job.JobContainer;
import engine.job.JobScheduler;
import engine.jobs.StuckJob;
import engine.net.client.ClientConnection;
import engine.net.client.msg.ClientNetMsg;
import engine.net.client.msg.StuckMsg;
import engine.objects.PlayerCharacter;

import java.util.concurrent.ConcurrentHashMap;

public class StuckMsgHandler extends AbstractClientMsgHandler {

    public StuckMsgHandler() {
        super();
    }

    @Override
    protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) {

        PlayerCharacter playerCharacter = origin.getPlayerCharacter();

        // Member variable declaration

        StuckMsg msg;

        // Member variable assignment

        msg = (StuckMsg) baseMsg;

        if (playerCharacter == null)
            return true;

        if (playerCharacter.getTimers().containsKey("Stuck"))
            return true;

        StuckJob sj = new StuckJob(playerCharacter);
        JobContainer jc = JobScheduler.getInstance().scheduleJob(sj, 10000); // Convert
        ConcurrentHashMap<String, JobContainer> timers = playerCharacter.getTimers();

        if (timers != null) {
            if (timers.containsKey("Stuck")) {
                timers.get("Stuck").cancelJob();
                timers.remove("Stuck");
            }
            timers.put("Stuck", jc);
        }
        return true;
    }

}