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

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

import com.hypixel.hytale.builtin.buildertools.BuilderToolsPlugin;
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.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;

public class UpdateSelectionCommand extends AbstractPlayerCommand
{
    @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 UpdateSelectionCommand() {
        super("updateselection", "server.commands.updateselection.desc");
        this.xMinArg = this.withRequiredArg("xMin", "server.commands.updateselection.xMin.desc", ArgTypes.INTEGER);
        this.yMinArg = this.withRequiredArg("yMin", "server.commands.updateselection.yMin.desc", ArgTypes.INTEGER);
        this.zMinArg = this.withRequiredArg("zMin", "server.commands.updateselection.zMin.desc", ArgTypes.INTEGER);
        this.xMaxArg = this.withRequiredArg("xMax", "server.commands.updateselection.xMax.desc", ArgTypes.INTEGER);
        this.yMaxArg = this.withRequiredArg("yMax", "server.commands.updateselection.yMax.desc", ArgTypes.INTEGER);
        this.zMaxArg = this.withRequiredArg("zMax", "server.commands.updateselection.zMax.desc", ArgTypes.INTEGER);
        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 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);
        BuilderToolsPlugin.addToQueue(playerComponent, playerRef, (r, s, componentAccessor) -> s.update(xMin, yMin, zMin, xMax, yMax, zMax));
    }
}
