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

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

import com.hypixel.hytale.builtin.path.path.IPrefabPath;
import java.util.UUID;
import com.hypixel.hytale.builtin.path.WorldPathData;
import com.hypixel.hytale.server.core.command.system.exceptions.GeneralCommandException;
import com.hypixel.hytale.builtin.buildertools.BuilderToolsPlugin;
import com.hypixel.hytale.server.core.entity.entities.Player;
import com.hypixel.hytale.server.core.universe.world.World;
import com.hypixel.hytale.server.core.universe.PlayerRef;
import com.hypixel.hytale.component.Ref;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.component.Store;
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.DefaultArg;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractPlayerCommand;

public class PrefabPathAddCommand extends AbstractPlayerCommand
{
    @Nonnull
    private static final Message MESSAGE_COMMANDS_NPC_PATH_ADD_NO_ACTIVE_PATH;
    @Nonnull
    private final DefaultArg<Double> pauseTimeArg;
    @Nonnull
    private final DefaultArg<Float> observationAngleArg;
    @Nonnull
    private final DefaultArg<Integer> indexArg;
    
    public PrefabPathAddCommand() {
        super("add", "server.commands.npcpath.add.desc");
        this.pauseTimeArg = this.withDefaultArg("pauseTime", "server.commands.npcpath.add.pauseTime.desc", ArgTypes.DOUBLE, 0.0, "0.0");
        this.observationAngleArg = this.withDefaultArg("observationAngleDegrees", "server.commands.npcpath.add.observationAngleDegrees.desc", ArgTypes.FLOAT, 0.0f, "0.0");
        this.indexArg = this.withDefaultArg("index", "server.commands.npcpath.add.index.desc", ArgTypes.INTEGER, -1, "-1");
    }
    
    @Override
    protected void execute(@Nonnull final CommandContext context, @Nonnull final Store<EntityStore> store, @Nonnull final Ref<EntityStore> ref, @Nonnull final PlayerRef playerRef, @Nonnull final World world) {
        final Player playerComponent = store.getComponent(ref, Player.getComponentType());
        assert playerComponent != null;
        final UUID path = BuilderToolsPlugin.getState(playerComponent, playerRef).getActivePrefabPath();
        if (path == null) {
            throw new GeneralCommandException(PrefabPathAddCommand.MESSAGE_COMMANDS_NPC_PATH_ADD_NO_ACTIVE_PATH);
        }
        final Double pauseTime = this.pauseTimeArg.get(context);
        final Float obsvAngle = this.observationAngleArg.get(context);
        final short targetIndex = this.indexArg.get(context).shortValue();
        final WorldPathData worldPathData = store.getResource(WorldPathData.getResourceType());
        final IPrefabPath parentPath = worldPathData.getPrefabPath(0, path, false);
        if (parentPath == null || !parentPath.isFullyLoaded()) {
            context.sendMessage(Message.translation("server.npc.npcpath.pathMustBeLoaded").param("path", path.toString()));
            return;
        }
        PrefabPathHelper.addMarker(store, ref, path, parentPath.getName(), pauseTime, obsvAngle, targetIndex, parentPath.getWorldGenId());
    }
    
    static {
        MESSAGE_COMMANDS_NPC_PATH_ADD_NO_ACTIVE_PATH = Message.translation("server.commands.npcpath.add.noActivePath");
    }
}
