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

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

import com.hypixel.hytale.math.vector.Vector3i;
import com.hypixel.hytale.builtin.buildertools.prefabeditor.PrefabEditingMetadata;
import com.hypixel.hytale.builtin.buildertools.prefabeditor.PrefabEditSession;
import com.hypixel.hytale.builtin.buildertools.prefabeditor.PrefabEditSessionManager;
import java.util.UUID;
import com.hypixel.hytale.builtin.buildertools.BuilderToolsPlugin;
import com.hypixel.hytale.server.core.entity.UUIDComponent;
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 javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractPlayerCommand;

public class PrefabEditInfoCommand extends AbstractPlayerCommand
{
    @Nonnull
    private static final Message MESSAGE_COMMANDS_EDIT_PREFAB_NOT_IN_EDIT_SESSION;
    @Nonnull
    private static final Message MESSAGE_COMMANDS_EDIT_PREFAB_NO_PREFAB_SELECTED;
    
    public PrefabEditInfoCommand() {
        super("info", "server.commands.editprefab.info.desc");
    }
    
    @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 UUIDComponent uuidComponent = store.getComponent(ref, UUIDComponent.getComponentType());
        assert uuidComponent != null;
        final UUID playerUUID = uuidComponent.getUuid();
        final PrefabEditSessionManager prefabEditSessionManager = BuilderToolsPlugin.get().getPrefabEditSessionManager();
        final PrefabEditSession prefabEditSession = prefabEditSessionManager.getPrefabEditSession(playerUUID);
        if (prefabEditSession == null) {
            context.sendMessage(PrefabEditInfoCommand.MESSAGE_COMMANDS_EDIT_PREFAB_NOT_IN_EDIT_SESSION);
            return;
        }
        final PrefabEditingMetadata selectedPrefab = prefabEditSession.getSelectedPrefab(playerUUID);
        if (selectedPrefab == null) {
            context.sendMessage(PrefabEditInfoCommand.MESSAGE_COMMANDS_EDIT_PREFAB_NO_PREFAB_SELECTED);
            return;
        }
        final Vector3i minPoint = selectedPrefab.getMinPoint();
        final Vector3i maxPoint = selectedPrefab.getMaxPoint();
        final int xWidth = maxPoint.getX() - minPoint.getX();
        final int zWidth = maxPoint.getZ() - minPoint.getZ();
        final int yHeight = maxPoint.getY() - minPoint.getY();
        context.sendMessage(Message.translation("server.commands.editprefab.info.format").param("path", selectedPrefab.getPrefabPath().toString()).param("dimensions", "X: " + xWidth + ", Y: " + yHeight + ", Z: " + zWidth).param("dirty", selectedPrefab.isDirty() ? Message.translation("server.commands.editprefab.info.dirty.yes") : Message.translation("server.commands.editprefab.info.dirty.no")));
    }
    
    static {
        MESSAGE_COMMANDS_EDIT_PREFAB_NOT_IN_EDIT_SESSION = Message.translation("server.commands.editprefab.notInEditSession");
        MESSAGE_COMMANDS_EDIT_PREFAB_NO_PREFAB_SELECTED = Message.translation("server.commands.editprefab.noPrefabSelected");
    }
}
