#!/bin/bash
set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
LAUNCHER_JAR="$SCRIPT_DIR/app/slayora-launcher-all.jar"
DOWNLOADED_JAVA="$HOME/.slayora/jre/Contents/Home/bin/java"

if [ ! -f "$LAUNCHER_JAR" ]; then
  echo "Missing launcher jar:"
  echo "$LAUNCHER_JAR"
  exit 1
fi

if [ -x "$DOWNLOADED_JAVA" ]; then
  exec "$DOWNLOADED_JAVA" -jar "$LAUNCHER_JAR"
fi

if command -v java >/dev/null 2>&1; then
  exec java -jar "$LAUNCHER_JAR"
fi

echo "Java was not found."
echo "Install Java 21 on macOS, then run this launcher again."
exit 1
