// 
// Decompiled by Procyon v0.6.0
// 

package com.hypixel.hytale.builtin.path.commands;

import com.hypixel.hytale.component.Ref;
import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
import com.hypixel.hytale.builtin.path.entities.PatrolPathMarkerEntity;
import com.hypixel.hytale.server.core.util.TargetUtil;
import com.hypixel.hytale.server.core.command.system.exceptions.GeneralCommandException;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.component.ComponentAccessor;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.component.Store;
import com.hypixel.hytale.server.core.universe.world.World;
import com.hypixel.hytale.server.core.command.system.CommandContext;
import com.hypixel.hytale.server.core.command.system.arguments.types.ArgumentType;
import com.hypixel.hytale.server.core.command.system.arguments.types.ArgTypes;
import com.hypixel.hytale.server.core.command.system.arguments.system.RequiredArg;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.command.system.arguments.types.EntityWrappedArg;
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractWorldCommand;

public class PrefabPathUpdatePauseCommand extends AbstractWorldCommand
{
    @Nonnull
    private final EntityWrappedArg entityIdArg;
    @Nonnull
    private final RequiredArg<Double> pauseTimeArg;
    
    public PrefabPathUpdatePauseCommand() {
        super("pause", "server.commands.npcpath.update.pause.desc");
        this.entityIdArg = this.withOptionalArg("entityId", "server.commands.npcpath.update.pause.entityId.desc", ArgTypes.ENTITY_ID);
        this.pauseTimeArg = this.withRequiredArg("pauseTime", "server.commands.npcpath.update.pause.pauseTime.desc", ArgTypes.DOUBLE);
    }
    
    @Override
    protected void execute(@Nonnull final CommandContext context, @Nonnull final World world, @Nonnull final Store<EntityStore> store) {
        final Double pauseTime = this.pauseTimeArg.get(context);
        Ref<EntityStore> ref;
        if (this.entityIdArg.provided(context)) {
            ref = this.entityIdArg.get(store, context);
        }
        else {
            final Ref<EntityStore> playerRef = context.senderAsPlayerRef();
            if (playerRef == null) {
                throw new GeneralCommandException(Message.translation("server.commands.errors.playerOrArg").param("option", "entity"));
            }
            if (!playerRef.isValid()) {
                throw new GeneralCommandException(Message.translation("server.commands.errors.playerNotInWorld").param("option", "entity"));
            }
            final Ref<EntityStore> entityRef = TargetUtil.getTargetEntity(playerRef, store);
            if (entityRef == null) {
                throw new GeneralCommandException(Message.translation("server.commands.errors.no_entity_in_view").param("option", "entity"));
            }
            ref = entityRef;
        }
        final PatrolPathMarkerEntity patrolPathMarkerComponent = store.getComponent(ref, PatrolPathMarkerEntity.getComponentType());
        if (patrolPathMarkerComponent == null) {
            context.sendMessage(Message.translation("server.general.entityNotFound").param("id", ref.getIndex()));
            return;
        }
        patrolPathMarkerComponent.setPauseTime(pauseTime);
        final TransformComponent transformComponent = store.getComponent(ref, TransformComponent.getComponentType());
        assert transformComponent != null;
        transformComponent.markChunkDirty(store);
    }
}
