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

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

import com.hypixel.hytale.builtin.buildertools.BuilderToolsPlugin;
import com.hypixel.hytale.math.vector.Vector3i;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType;
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.server.core.command.system.arguments.types.ArgumentType;
import com.hypixel.hytale.server.core.command.system.arguments.types.ArgTypes;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.command.system.arguments.system.RequiredArg;
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractPlayerCommand;
import com.hypixel.hytale.server.core.command.system.AbstractCommand;
import com.hypixel.hytale.protocol.GameMode;
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractCommandCollection;

public class ExtendFaceCommand extends AbstractCommandCollection
{
    public ExtendFaceCommand() {
        super("extendface", "server.commands.extendface.desc");
        this.setPermissionGroup(GameMode.Creative);
        this.addUsageVariant(new ExtendFaceBasicCommand());
        this.addUsageVariant(new ExtendFaceWithRegionCommand());
    }
    
    private static class ExtendFaceBasicCommand extends AbstractPlayerCommand
    {
        @Nonnull
        private final RequiredArg<Integer> xArg;
        @Nonnull
        private final RequiredArg<Integer> yArg;
        @Nonnull
        private final RequiredArg<Integer> zArg;
        @Nonnull
        private final RequiredArg<Integer> normalXArg;
        @Nonnull
        private final RequiredArg<Integer> normalYArg;
        @Nonnull
        private final RequiredArg<Integer> normalZArg;
        @Nonnull
        private final RequiredArg<Integer> toolParamArg;
        @Nonnull
        private final RequiredArg<Integer> shapeRangeArg;
        @Nonnull
        private final RequiredArg<String> blockTypeArg;
        
        public ExtendFaceBasicCommand() {
            super("server.commands.extendface.desc");
            this.xArg = this.withRequiredArg("x", "server.commands.extendface.x.desc", ArgTypes.INTEGER);
            this.yArg = this.withRequiredArg("y", "server.commands.extendface.y.desc", ArgTypes.INTEGER);
            this.zArg = this.withRequiredArg("z", "server.commands.extendface.z.desc", ArgTypes.INTEGER);
            this.normalXArg = this.withRequiredArg("normalX", "server.commands.extendface.normalX.desc", ArgTypes.INTEGER);
            this.normalYArg = this.withRequiredArg("normalY", "server.commands.extendface.normalY.desc", ArgTypes.INTEGER);
            this.normalZArg = this.withRequiredArg("normalZ", "server.commands.extendface.normalZ.desc", ArgTypes.INTEGER);
            this.toolParamArg = this.withRequiredArg("toolParam", "server.commands.extendface.toolParam.desc", ArgTypes.INTEGER);
            this.shapeRangeArg = this.withRequiredArg("shapeRange", "server.commands.extendface.shapeRange.desc", ArgTypes.INTEGER);
            this.blockTypeArg = this.withRequiredArg("blockType", "server.commands.extendface.blockType.desc", ArgTypes.STRING);
        }
        
        @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 int x = this.xArg.get(context);
            final int y = this.yArg.get(context);
            final int z = this.zArg.get(context);
            final int normalX = this.normalXArg.get(context);
            final int normalY = this.normalYArg.get(context);
            final int normalZ = this.normalZArg.get(context);
            final int toolParam = this.toolParamArg.get(context);
            final int shapeRange = this.shapeRangeArg.get(context);
            final String key = this.blockTypeArg.get(context);
            if (BlockType.getAssetMap().getAsset(key) == null) {
                context.sendMessage(Message.translation("server.builderTools.invalidBlockType").param("name", key).param("key", key));
                return;
            }
            final int index = BlockType.getAssetMap().getIndex(key);
            if (index == Integer.MIN_VALUE) {
                context.sendMessage(Message.translation("server.builderTools.invalidBlockType").param("name", key).param("key", key));
                return;
            }
            BuilderToolsPlugin.addToQueue(playerComponent, playerRef, (r, s, componentAccessor) -> s.extendFace(x, y, z, normalX, normalY, normalZ, toolParam, shapeRange, index, null, null, componentAccessor));
        }
    }
    
    private static class ExtendFaceWithRegionCommand extends AbstractPlayerCommand
    {
        @Nonnull
        private final RequiredArg<Integer> xArg;
        @Nonnull
        private final RequiredArg<Integer> yArg;
        @Nonnull
        private final RequiredArg<Integer> zArg;
        @Nonnull
        private final RequiredArg<Integer> normalXArg;
        @Nonnull
        private final RequiredArg<Integer> normalYArg;
        @Nonnull
        private final RequiredArg<Integer> normalZArg;
        @Nonnull
        private final RequiredArg<Integer> toolParamArg;
        @Nonnull
        private final RequiredArg<Integer> shapeRangeArg;
        @Nonnull
        private final RequiredArg<String> blockTypeArg;
        @Nonnull
        private final RequiredArg<Integer> xMinArg;
        @Nonnull
        private final RequiredArg<Integer> yMinArg;
        @Nonnull
        private final RequiredArg<Integer> zMinArg;
        @Nonnull
        private final RequiredArg<Integer> xMaxArg;
        @Nonnull
        private final RequiredArg<Integer> yMaxArg;
        @Nonnull
        private final RequiredArg<Integer> zMaxArg;
        
        public ExtendFaceWithRegionCommand() {
            super("server.commands.extendface.desc");
            this.xArg = this.withRequiredArg("x", "server.commands.extendface.x.desc", ArgTypes.INTEGER);
            this.yArg = this.withRequiredArg("y", "server.commands.extendface.y.desc", ArgTypes.INTEGER);
            this.zArg = this.withRequiredArg("z", "server.commands.extendface.z.desc", ArgTypes.INTEGER);
            this.normalXArg = this.withRequiredArg("normalX", "server.commands.extendface.normalX.desc", ArgTypes.INTEGER);
            this.normalYArg = this.withRequiredArg("normalY", "server.commands.extendface.normalY.desc", ArgTypes.INTEGER);
            this.normalZArg = this.withRequiredArg("normalZ", "server.commands.extendface.normalZ.desc", ArgTypes.INTEGER);
            this.toolParamArg = this.withRequiredArg("toolParam", "server.commands.extendface.toolParam.desc", ArgTypes.INTEGER);
            this.shapeRangeArg = this.withRequiredArg("shapeRange", "server.commands.extendface.shapeRange.desc", ArgTypes.INTEGER);
            this.blockTypeArg = this.withRequiredArg("blockType", "server.commands.extendface.blockType.desc", ArgTypes.STRING);
            this.xMinArg = this.withRequiredArg("xMin", "server.commands.extendface.xMin.desc", ArgTypes.INTEGER);
            this.yMinArg = this.withRequiredArg("yMin", "server.commands.extendface.yMin.desc", ArgTypes.INTEGER);
            this.zMinArg = this.withRequiredArg("zMin", "server.commands.extendface.zMin.desc", ArgTypes.INTEGER);
            this.xMaxArg = this.withRequiredArg("xMax", "server.commands.extendface.xMax.desc", ArgTypes.INTEGER);
            this.yMaxArg = this.withRequiredArg("yMax", "server.commands.extendface.yMax.desc", ArgTypes.INTEGER);
            this.zMaxArg = this.withRequiredArg("zMax", "server.commands.extendface.zMax.desc", ArgTypes.INTEGER);
        }
        
        @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 int x = this.xArg.get(context);
            final int y = this.yArg.get(context);
            final int z = this.zArg.get(context);
            final int normalX = this.normalXArg.get(context);
            final int normalY = this.normalYArg.get(context);
            final int normalZ = this.normalZArg.get(context);
            final int toolParam = this.toolParamArg.get(context);
            final int shapeRange = this.shapeRangeArg.get(context);
            final String key = this.blockTypeArg.get(context);
            if (BlockType.getAssetMap().getAsset(key) == null) {
                context.sendMessage(Message.translation("server.builderTools.invalidBlockType").param("name", key).param("key", key));
                return;
            }
            final int index = BlockType.getAssetMap().getIndex(key);
            if (index == Integer.MIN_VALUE) {
                context.sendMessage(Message.translation("server.builderTools.invalidBlockType").param("name", key).param("key", key));
                return;
            }
            final int xMin = this.xMinArg.get(context);
            final int yMin = this.yMinArg.get(context);
            final int zMin = this.zMinArg.get(context);
            final int xMax = this.xMaxArg.get(context);
            final int yMax = this.yMaxArg.get(context);
            final int zMax = this.zMaxArg.get(context);
            final Vector3i min = new Vector3i(xMin, yMin, zMin);
            final Vector3i max = new Vector3i(xMax, yMax, zMax);
            BuilderToolsPlugin.addToQueue(playerComponent, playerRef, (r, s, componentAccessor) -> s.extendFace(x, y, z, normalX, normalY, normalZ, toolParam, shapeRange, index, min, max, componentAccessor));
        }
    }
}
