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

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

import com.hypixel.hytale.math.vector.Vector3i;
import com.hypixel.hytale.builtin.buildertools.BuilderToolsPlugin;
import com.hypixel.hytale.server.core.modules.entity.component.HeadRotation;
import com.hypixel.hytale.component.ComponentAccessor;
import com.hypixel.hytale.builtin.buildertools.PrototypePlayerBuilderToolSettings;
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.EnumArgumentType;
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.math.Axis;
import com.hypixel.hytale.server.core.command.system.arguments.system.OptionalArg;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.command.system.arguments.system.DefaultArg;
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractPlayerCommand;

public class ExpandCommand extends AbstractPlayerCommand
{
    @Nonnull
    private final DefaultArg<Integer> distanceArg;
    @Nonnull
    private final OptionalArg<Axis> axisArg;
    
    public ExpandCommand() {
        super("expand", "server.commands.expand.desc");
        this.distanceArg = this.withDefaultArg("distance", "server.commands.expand.distance.desc", ArgTypes.INTEGER, 1, "1");
        this.axisArg = this.withOptionalArg("axis", "server.commands.expand.axis.desc", new EnumArgumentType<Axis>("server.commands.parsing.argtype.axis.name", Axis.class));
        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;
        if (!PrototypePlayerBuilderToolSettings.isOkayToDoCommandsOnSelection(ref, playerComponent, store)) {
            return;
        }
        final Integer distance = this.distanceArg.get(context);
        Vector3i direction;
        if (this.axisArg.provided(context)) {
            direction = this.axisArg.get(context).getDirection().scale(distance);
        }
        else {
            final HeadRotation headRotationComponent = store.getComponent(ref, HeadRotation.getComponentType());
            assert headRotationComponent != null;
            direction = headRotationComponent.getAxisDirection().scale(distance);
        }
        BuilderToolsPlugin.addToQueue(playerComponent, playerRef, (r, s, componentAccessor) -> s.expand(r, direction, componentAccessor));
    }
}
