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

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

import com.hypixel.hytale.math.vector.Vector3i;
import com.hypixel.hytale.math.vector.Vector3d;
import com.hypixel.hytale.builtin.buildertools.BuilderToolsPlugin;
import com.hypixel.hytale.component.ComponentAccessor;
import com.hypixel.hytale.protocol.packets.buildertools.BrushOrigin;
import com.hypixel.hytale.protocol.packets.buildertools.BrushShape;
import com.hypixel.hytale.server.core.prefab.selection.mask.BlockPattern;
import com.hypixel.hytale.math.util.MathUtil;
import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
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.protocol.GameMode;
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.command.system.arguments.types.RelativeVector3i;
import com.hypixel.hytale.server.core.command.system.arguments.system.RequiredArg;
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractPlayerCommand;

public class EditLineCommand extends AbstractPlayerCommand
{
    @Nonnull
    private final RequiredArg<RelativeVector3i> startArg;
    @Nonnull
    private final RequiredArg<RelativeVector3i> endArg;
    @Nonnull
    private final RequiredArg<String> materialArg;
    @Nonnull
    private final DefaultArg<Integer> widthArg;
    @Nonnull
    private final DefaultArg<Integer> heightArg;
    @Nonnull
    private final DefaultArg<Integer> wallThicknessArg;
    @Nonnull
    private final DefaultArg<String> shapeArg;
    @Nonnull
    private final DefaultArg<String> originArg;
    @Nonnull
    private final DefaultArg<Integer> spacingArg;
    @Nonnull
    private final DefaultArg<Integer> densityArg;
    
    public EditLineCommand() {
        super("editline", "server.commands.editline.desc");
        this.startArg = this.withRequiredArg("start", "server.commands.editline.start.desc", ArgTypes.RELATIVE_VECTOR3I);
        this.endArg = this.withRequiredArg("end", "server.commands.editline.end.desc", ArgTypes.RELATIVE_VECTOR3I);
        this.materialArg = this.withRequiredArg("material", "server.commands.editline.material.desc", ArgTypes.STRING);
        this.widthArg = this.withDefaultArg("width", "server.commands.editline.width.desc", ArgTypes.INTEGER, 1, "1");
        this.heightArg = this.withDefaultArg("height", "server.commands.editline.height.desc", ArgTypes.INTEGER, 1, "1");
        this.wallThicknessArg = this.withDefaultArg("wallThickness", "server.commands.editline.wallThickness.desc", ArgTypes.INTEGER, 0, "0");
        this.shapeArg = this.withDefaultArg("shape", "server.commands.editline.shape.desc", ArgTypes.STRING, "Cube", "Cube");
        this.originArg = this.withDefaultArg("origin", "server.commands.editline.origin.desc", ArgTypes.STRING, "Center", "Center");
        this.spacingArg = this.withDefaultArg("spacing", "server.commands.editline.spacing.desc", ArgTypes.INTEGER, 1, "1");
        this.densityArg = this.withDefaultArg("density", "server.commands.editline.density.desc", ArgTypes.INTEGER, 100, "100");
        this.setPermissionGroup(GameMode.Creative);
    }
    
    @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 TransformComponent transformComponent = store.getComponent(ref, TransformComponent.getComponentType());
        assert transformComponent != null;
        final Vector3d playerPos = transformComponent.getPosition();
        final int baseX = MathUtil.floor(playerPos.getX());
        final int baseY = MathUtil.floor(playerPos.getY());
        final int baseZ = MathUtil.floor(playerPos.getZ());
        final Vector3i start = this.startArg.get(context).resolve(baseX, baseY, baseZ);
        final Vector3i end = this.endArg.get(context).resolve(baseX, baseY, baseZ);
        final BlockPattern material = BlockPattern.parse(this.materialArg.get(context));
        final int width = this.widthArg.get(context);
        final int height = this.heightArg.get(context);
        final int wallThickness = this.wallThicknessArg.get(context);
        final BrushShape shape = BrushShape.valueOf(this.shapeArg.get(context));
        final BrushOrigin origin = BrushOrigin.valueOf(this.originArg.get(context));
        final int spacing = this.spacingArg.get(context);
        final int density = this.densityArg.get(context);
        BuilderToolsPlugin.addToQueue(playerComponent, playerRef, (r, s, componentAccessor) -> s.editLine(start.x, start.y, start.z, end.x, end.y, end.z, material, width, height, wallThickness, shape, origin, spacing, density, s.getGlobalMask(), componentAccessor));
    }
}
