package electrosphere.server.player;

import electrosphere.client.item.ItemActions;
import electrosphere.entity.Entity;
import electrosphere.entity.state.block.ServerBlockTree;
import electrosphere.net.parser.net.message.InventoryMessage;
import electrosphere.net.server.ServerConnectionHandler;
import electrosphere.server.datacell.utils.EntityLookupUtils;

/**
 * Class for handling 
 */
public class PlayerActions {

    /**
     * Attempts to perform an action a player requested
     * @param connectionHandler The player's connection handler
     * @param message The network message that encapsulates the requested action
     */
    public static void attemptPlayerAction(ServerConnectionHandler connectionHandler, InventoryMessage message){
        Entity playerEntity = EntityLookupUtils.getEntityById(connectionHandler.getPlayerEntityId());

        if(message.getitemActionCode() == ItemActions.ITEM_ACTION_CODE_SECONDARY){
            ServerBlockTree serverBlockTree = ServerBlockTree.getServerBlockTree(playerEntity);
            if(serverBlockTree != null){
                if(message.getitemActionCodeState() == ItemActions.ITEM_ACTION_CODE_STATE_ON){
                    serverBlockTree.start();
                } else {
                    serverBlockTree.stop();
                }
            }
        }
    }
    
}
