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

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

import com.hypixel.hytale.server.core.command.system.arguments.system.Argument;
import com.hypixel.hytale.component.ComponentAccessor;
import com.hypixel.hytale.builtin.buildertools.prefabeditor.PrefabEditorCreationSettings;
import java.util.concurrent.CompletableFuture;
import com.hypixel.hytale.server.core.command.system.AbstractCommand;
import com.hypixel.hytale.server.core.entity.entities.player.pages.CustomUIPage;
import com.hypixel.hytale.builtin.buildertools.prefabeditor.ui.PrefabEditorLoadSettingsPage;
import com.hypixel.hytale.server.core.entity.entities.Player;
import com.hypixel.hytale.builtin.buildertools.BuilderToolsPlugin;
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.basecommands.AbstractPlayerCommand;
import com.hypixel.hytale.server.core.command.system.arguments.system.AbstractOptionalArg;
import com.hypixel.hytale.codec.validation.Validator;
import com.hypixel.hytale.codec.validation.Validators;
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.FlagArg;
import com.hypixel.hytale.server.core.command.system.arguments.system.DefaultArg;
import java.util.List;
import com.hypixel.hytale.server.core.command.system.arguments.system.RequiredArg;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.builtin.buildertools.prefabeditor.enums.PrefabRowSplitMode;
import com.hypixel.hytale.builtin.buildertools.prefabeditor.enums.PrefabRootDirectory;
import com.hypixel.hytale.builtin.buildertools.prefabeditor.enums.PrefabAlignment;
import com.hypixel.hytale.builtin.buildertools.prefabeditor.enums.PrefabStackingAxis;
import javax.annotation.Nonnull;
import com.hypixel.hytale.builtin.buildertools.prefabeditor.enums.WorldGenType;
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractAsyncPlayerCommand;

public class PrefabEditLoadCommand extends AbstractAsyncPlayerCommand
{
    public static final int DEFAULT_PASTE_LEVEL_GOAL = 55;
    public static final int DEFAULT_BLOCKS_BETWEEN_MULTI_PREFABS = 15;
    @Nonnull
    public static final WorldGenType DEFAULT_WORLD_GEN_TYPE;
    public static final int DEFAULT_BLOCKS_ABOVE_SURFACE = 0;
    @Nonnull
    public static final PrefabStackingAxis DEFAULT_PREFAB_STACKING_AXIS;
    @Nonnull
    public static final PrefabAlignment DEFAULT_PREFAB_ALIGNMENT;
    public static final int MAX_BLOCKS_BETWEEN_EACH_PREFAB = 100;
    public static final int MAX_BLOCKS_UNTIL_SURFACE = 120;
    @Nonnull
    public static final PrefabRootDirectory DEFAULT_PREFAB_ROOT_DIRECTORY;
    @Nonnull
    public static final PrefabRowSplitMode DEFAULT_ROW_SPLIT_MODE;
    @Nonnull
    private static final Message MESSAGE_COMMANDS_PREFAB_EDIT_SESSION_MANAGER_EXISTING_EDIT_SESSION;
    @Nonnull
    private static final Message MESSAGE_COMMANDS_EDIT_PREFAB_LOADING;
    @Nonnull
    private final RequiredArg<PrefabRootDirectory> prefabPathArg;
    @Nonnull
    private final RequiredArg<List<String>> prefabNameArg;
    @Nonnull
    private final DefaultArg<Integer> pasteLevelGoalArg;
    @Nonnull
    private final DefaultArg<Integer> blocksBetweenMultiPrefabsArg;
    @Nonnull
    private final DefaultArg<WorldGenType> worldGenTypeArg;
    @Nonnull
    private final DefaultArg<Integer> flatNumBlocksBelowArg;
    @Nonnull
    private final DefaultArg<PrefabStackingAxis> axisArg;
    @Nonnull
    private final DefaultArg<PrefabAlignment> alignmentArg;
    @Nonnull
    private final FlagArg recursiveArg;
    @Nonnull
    private final FlagArg loadChildrenArg;
    @Nonnull
    private final FlagArg loadEntitiesArg;
    
    public PrefabEditLoadCommand() {
        super("load", "server.commands.editprefab.load.desc");
        this.prefabPathArg = this.withRequiredArg("prefabPath", "server.commands.editprefab.load.path.desc", ArgTypes.forEnum("PrefabPath", PrefabRootDirectory.class));
        this.prefabNameArg = this.withListRequiredArg("prefabName", "server.commands.editprefab.load.name.desc", ArgTypes.STRING);
        this.pasteLevelGoalArg = this.withDefaultArg("pasteLevelGoal", "server.commands.editprefab.load.pasteLevelGoal.desc", ArgTypes.INTEGER, 55, "server.commands.editprefab.load.pasteLevelGoal.default.desc").addValidator((Validator<Integer>)Validators.range(0, (DataType)320));
        this.blocksBetweenMultiPrefabsArg = this.withDefaultArg("spacing", "server.commands.editprefab.load.spacing.desc", ArgTypes.INTEGER, 15, "server.commands.editprefab.load.spacing.default.desc").addValidator((Validator<Integer>)Validators.range(0, (DataType)100));
        this.worldGenTypeArg = this.withDefaultArg("worldgen", "server.commands.editprefab.load.worldGenType.desc", ArgTypes.forEnum("WorldGenType", WorldGenType.class), PrefabEditLoadCommand.DEFAULT_WORLD_GEN_TYPE, "server.commands.editprefab.load.worldGenType.default.desc");
        this.flatNumBlocksBelowArg = (DefaultArg)this.withDefaultArg("blocksAboveSurface", "server.commands.editprefab.load.numBlocksToSurface.desc", ArgTypes.INTEGER, 0, "server.commands.editprefab.load.numBlocksToSurface.default.desc").addValidator((Validator<Integer>)Validators.range(0, (DataType)120)).availableOnlyIfAll(this.worldGenTypeArg);
        this.axisArg = this.withDefaultArg("stackingAxis", "server.commands.editprefab.load.axis.desc", ArgTypes.forEnum("Stacking Axis", PrefabStackingAxis.class), PrefabEditLoadCommand.DEFAULT_PREFAB_STACKING_AXIS, "server.commands.editprefab.load.axis.default.desc").addAliases("axis");
        this.alignmentArg = this.withDefaultArg("alignment", "server.commands.editprefab.load.alignment.desc", ArgTypes.forEnum("Alignment", PrefabAlignment.class), PrefabAlignment.ANCHOR, "server.commands.editprefab.load.alignment.default.desc");
        this.recursiveArg = this.withFlagArg("recursive", "server.commands.editprefab.load.recursive.desc");
        this.loadChildrenArg = ((AbstractOptionalArg<FlagArg, DataType>)this.withFlagArg("loadChildren", "server.commands.editprefab.load.loadChildren.desc")).addAliases("children");
        this.loadEntitiesArg = ((AbstractOptionalArg<FlagArg, DataType>)this.withFlagArg("loadEntities", "server.commands.editprefab.load.loadEntities.desc")).addAliases("entities");
        this.addUsageVariant(new AbstractPlayerCommand(this, "server.commands.editprefab.load.desc") {
            @Nonnull
            private static final Message MESSAGE_COMMANDS_PREFAB_EDIT_SESSION_MANAGER_EXISTING_EDIT_SESSION;
            
            @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) {
                if (BuilderToolsPlugin.get().getPrefabEditSessionManager().isEditingAPrefab(playerRef.getUuid())) {
                    context.sendMessage(PrefabEditLoadCommand$1.MESSAGE_COMMANDS_PREFAB_EDIT_SESSION_MANAGER_EXISTING_EDIT_SESSION);
                    return;
                }
                final Player playerComponent = store.getComponent(ref, Player.getComponentType());
                assert playerComponent != null;
                playerComponent.getPageManager().openCustomPage(ref, store, new PrefabEditorLoadSettingsPage(playerRef));
            }
            
            static {
                MESSAGE_COMMANDS_PREFAB_EDIT_SESSION_MANAGER_EXISTING_EDIT_SESSION = Message.translation("server.commands.prefabeditsessionmanager.existingEditSession");
            }
        });
    }
    
    @Nonnull
    @Override
    protected CompletableFuture<Void> executeAsync(@Nonnull final CommandContext context, @Nonnull final Store<EntityStore> store, @Nonnull final Ref<EntityStore> ref, @Nonnull final PlayerRef playerRef, @Nonnull final World world) {
        if (BuilderToolsPlugin.get().getPrefabEditSessionManager().isEditingAPrefab(playerRef.getUuid())) {
            context.sendMessage(PrefabEditLoadCommand.MESSAGE_COMMANDS_PREFAB_EDIT_SESSION_MANAGER_EXISTING_EDIT_SESSION);
            return CompletableFuture.completedFuture((Void)null);
        }
        final PrefabEditorCreationSettings prefabEditorLoadCommandSettings = new PrefabEditorCreationSettings(this.prefabPathArg.get(context), this.prefabNameArg.get(context), this.pasteLevelGoalArg.get(context), this.blocksBetweenMultiPrefabsArg.get(context), this.worldGenTypeArg.get(context), this.flatNumBlocksBelowArg.get(context), this.axisArg.get(context), this.alignmentArg.get(context), ((Argument<Arg, Boolean>)this.recursiveArg).get(context), ((Argument<Arg, Boolean>)this.loadChildrenArg).get(context), ((Argument<Arg, Boolean>)this.loadEntitiesArg).get(context), false, PrefabEditLoadCommand.DEFAULT_ROW_SPLIT_MODE, "Env_Zone1_Plains", "#5B9E28");
        final Player playerComponent = store.getComponent(ref, Player.getComponentType());
        assert playerComponent != null;
        context.sendMessage(PrefabEditLoadCommand.MESSAGE_COMMANDS_EDIT_PREFAB_LOADING);
        return BuilderToolsPlugin.get().getPrefabEditSessionManager().loadPrefabAndCreateEditSession(ref, playerComponent, prefabEditorLoadCommandSettings, store);
    }
    
    static {
        DEFAULT_WORLD_GEN_TYPE = WorldGenType.FLAT;
        DEFAULT_PREFAB_STACKING_AXIS = PrefabStackingAxis.X;
        DEFAULT_PREFAB_ALIGNMENT = PrefabAlignment.ANCHOR;
        DEFAULT_PREFAB_ROOT_DIRECTORY = PrefabRootDirectory.ASSET;
        DEFAULT_ROW_SPLIT_MODE = PrefabRowSplitMode.BY_ALL_SUBFOLDERS;
        MESSAGE_COMMANDS_PREFAB_EDIT_SESSION_MANAGER_EXISTING_EDIT_SESSION = Message.translation("server.commands.prefabeditsessionmanager.existingEditSession");
        MESSAGE_COMMANDS_EDIT_PREFAB_LOADING = Message.translation("server.commands.editprefab.loading");
    }
}
