package eu.mhsl.minecraft.pixelblocks.commands;

import eu.mhsl.minecraft.pixelblocks.pixelblock.PixelBlock;
import eu.mhsl.minecraft.pixelblocks.pixelblock.PixelBlockWorld;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

public class ExitSubCommand extends SubCommand {
    public ExitSubCommand() {
        super("exit", "pixelblocks.command.exit", "pixelblocks.command.exit.description");
    }

    @Override
    public void execute(@NotNull Player player, @NotNull String[] args) {
        if(!PixelBlockWorld.isPixelWorld(player.getWorld())) {
            player.sendMessage(Component.translatable("pixelblocks.error.not-in-pixelblock").color(NamedTextColor.RED));
            return;
        }

        PixelBlock pixelBlock = PixelBlock.getPixelBlockFromBlockWorld(player.getWorld());
        if(pixelBlock == null) {
            player.sendMessage(Component.translatable("pixelblocks.error.block-not-found").color(NamedTextColor.RED));
            return;
        }

        pixelBlock.exitBlock(player);
    }
}
