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

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

import com.hypixel.hytale.math.vector.Vector3d;
import com.hypixel.hytale.builtin.buildertools.BuilderToolsPlugin;
import com.hypixel.hytale.math.util.MathUtil;
import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
import com.hypixel.hytale.math.vector.Vector3i;
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.OptionalArg;
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractPlayerCommand;

public class Pos2Command extends AbstractPlayerCommand
{
    @Nonnull
    private final OptionalArg<Integer> xArg;
    @Nonnull
    private final OptionalArg<Integer> yArg;
    @Nonnull
    private final OptionalArg<Integer> zArg;
    
    public Pos2Command() {
        super("pos2", "server.commands.pos2.desc");
        this.xArg = this.withOptionalArg("x", "server.commands.pos2.x.desc", ArgTypes.INTEGER);
        this.yArg = this.withOptionalArg("y", "server.commands.pos2.y.desc", ArgTypes.INTEGER);
        this.zArg = this.withOptionalArg("z", "server.commands.pos2.z.desc", ArgTypes.INTEGER);
        this.setPermissionGroup(GameMode.Creative);
        this.requirePermission("hytale.editor.selection.use");
    }
    
    @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;
        }
        Vector3i intTriple;
        if (this.xArg.provided(context) && this.yArg.provided(context) && this.zArg.provided(context)) {
            intTriple = new Vector3i(this.xArg.get(context), this.yArg.get(context), this.zArg.get(context));
        }
        else {
            final TransformComponent transformComponent = store.getComponent(ref, TransformComponent.getComponentType());
            assert transformComponent != null;
            final Vector3d position = transformComponent.getPosition();
            intTriple = new Vector3i(MathUtil.floor(position.getX()), MathUtil.floor(position.getY()), MathUtil.floor(position.getZ()));
        }
        BuilderToolsPlugin.addToQueue(playerComponent, playerRef, (r, s, componentAccessor) -> s.pos2(intTriple, componentAccessor));
    }
}
