FROM sapmachine:21-jre-headless-ubuntu


ENV WORKDIR_PATH=/workspace
ENV CONFIG_PATH=${WORKDIR_PATH}/config
ENV DATA_PATH=${WORKDIR_PATH}/data

ADD ./src ${CONFIG_PATH}
RUN  mkdir ${DATA_PATH}


# Add symlinks to Minecraft default files
RUN touch ${DATA_PATH}/banned-ips.json && \
        ln -sf ${DATA_PATH}/banned-ips.json ${CONFIG_PATH} && \
    touch ${DATA_PATH}/banned-players.json && \
        ln -sf ${DATA_PATH}/banned-players.json ${CONFIG_PATH} && \
    mkdir ${DATA_PATH}/logs && \
        ln -sf ${DATA_PATH}/logs ${CONFIG_PATH} && \
    touch ${DATA_PATH}/ops.json && \
        ln -sf ${DATA_PATH}/ops.json ${CONFIG_PATH} && \
    touch ${DATA_PATH}/usercache.json && \
        ln -sf ${DATA_PATH}/usercache.json ${CONFIG_PATH} && \
    touch ${DATA_PATH}/whitelist.json && \
        ln -sf ${DATA_PATH}/whitelist.json ${CONFIG_PATH} && \
    mkdir ${DATA_PATH}/world && \
        ln -sf ${DATA_PATH}/world ${CONFIG_PATH} && \
    mkdir ${DATA_PATH}/world_nether && \
        ln -sf ${DATA_PATH}/world_nether ${CONFIG_PATH} && \
    mkdir ${DATA_PATH}/world_the_end && \
        ln -sf ${DATA_PATH}/world_the_end ${CONFIG_PATH}

# Add symlinks to PlasmoVoice files
RUN touch ${DATA_PATH}/pv-voice_mutes.json && \
    ln -sf ${DATA_PATH}/pv-voice_mutes.json \
        ${CONFIG_PATH}/plugins/PlasmoVoice/voice_mutes.json

# Add symlinks to SuperVanish files
RUN mkdir -p ${DATA_PATH}/SuperVanish && \
    touch ${DATA_PATH}/SuperVanish/data.yml && \
    ln -sf ${DATA_PATH}/SuperVanish/data.yml \
        ${CONFIG_PATH}/plugins/SuperVanish/data.yml

# Add symlinks to CarbonChat files
RUN mkdir -p ${DATA_PATH}/CarbonChat/users && \
    ln -sf ${DATA_PATH}/CarbonChat/users \
        ${CONFIG_PATH}/plugins/CarbonChat/users

# Add symlinks to ImageFrame files
RUN mkdir -p ${DATA_PATH}/ImageFrame/data && \
    ln -sf ${DATA_PATH}/ImageFrame/data/ \
        ${CONFIG_PATH}/plugins/ImageFrame/data && \
    mkdir -p ${DATA_PATH}/ImageFrame/players && \
    ln -sf ${DATA_PATH}/ImageFrame/players/ \
        ${CONFIG_PATH}/plugins/ImageFrame/players && \
    mkdir -p ${DATA_PATH}/ImageFrame/upload && \
    ln -sf ${DATA_PATH}/ImageFrame/upload/ \
        ${CONFIG_PATH}/plugins/ImageFrame/upload

# Add symlinks to CusttomPlayerModels files
RUN mkdir -p ${DATA_PATH}/CustomizablePlayerModels && \
    ln -sf ${DATA_PATH}/CustomizablePlayerModels/ \
        ${CONFIG_PATH}/plugins/CustomizablePlayerModels

# Add symlinks to DiscordSRV files
RUN mkdir -p ${DATA_PATH}/DiscordSRV && \
    touch ${DATA_PATH}/DiscordSRV/accounts.aof && \
    ln -sf ${DATA_PATH}/DiscordSRV/accounts.aof \
        ${CONFIG_PATH}/plugins/DiscordSRV/accounts.aof

# Add symlinks to BlueMap files
RUN mkdir -p ${DATA_PATH}/BlueMap/maps && \
    mkdir -p ${DATA_PATH}/BlueMap/logs && \
    ln -sf ${DATA_PATH}/BlueMap/maps \
        ${CONFIG_PATH}/plugins/BlueMap/data/web/maps && \
    ln -sf ${DATA_PATH}/BlueMap/logs \
        ${CONFIG_PATH}/plugins/BlueMap/data/logs
RUN mkdir -p ${DATA_PATH}/BMMarker/data && \
    ln -sf ${DATA_PATH}/BMMarker/data \
        ${CONFIG_PATH}/plugins/BMMarker/data

# Add symlinks to Chunky files
RUN mkdir -p ${DATA_PATH}/Chunky/tasks && \
    ln -sf ${DATA_PATH}/Chunky/tasks \
        ${CONFIG_PATH}/plugins/Chunky/tasks

# Generate unicode locale so that cyrillic characters display properly
RUN apt-get update -y && apt-get install -y locales && \
    echo en_US.UTF-8 UTF-8 > /etc/locale.gen && \
    dpkg-reconfigure --frontend=noninteractive locales
ENV LANG en_US.UTF-8


VOLUME ${DATA_PATH}


ENV MEMORY=4G
ENV PROXY_SECRET=00000000-0000-0000-0000-000000000000

ENV VOICE_SECRET=00000000-0000-0000-0000-000000000000

ENV LUCKPERMS_DB_HOST=127.0.0.1
ENV LUCKPERMS_DB_PORT=3306
ENV LUCKPERMS_DB_NAME=luckperms_db
ENV LUCKPERMS_DB_USERNAME=luckperms
ENV LUCKPERMS_DB_PASSWORD=0000

ENV SKINSRESTORER_DB_HOST=127.0.0.1
ENV SKINSRESTORER_DB_PORT=3306
ENV SKINSRESTORER_DB_NAME=skinsrestorer_db
ENV SKINSRESTORER_DB_USERNAME=skinsrestorer
ENV SKINSRESTORER_DB_PASSWORD=0000

ENV COREPROTECT_DB_HOST=127.0.0.1
ENV COREPROTECT_DB_PORT=3306
ENV COREPROTECT_DB_NAME=coreprotect_db
ENV COREPROTECT_DB_USERNAME=coreprotect
ENV COREPROTECT_DB_PASSWORD=0000

ENV LIBERTYBANS_DB_HOST=127.0.0.1
ENV LIBERTYBANS_DB_PORT=3306
ENV LIBERTYBANS_DB_NAME=libertybans_db
ENV LIBERTYBANS_DB_USERNAME=libertybans
ENV LIBERTYBANS_DB_PASSWORD=0000

ENV GRIM_DB_HOST=127.0.0.1
ENV GRIM_DB_PORT=3306
ENV GRIM_DB_NAME=luckperms
ENV GRIM_DB_USERNAME=luckperms
ENV GRIM_DB_PASSWORD=0000

ENV DISCORDSRV_BOT_TOKEN=dummy-token

ENV DISCORDSRV_DB_HOST=127.0.0.1
ENV DISCORDSRV_DB_PORT=3306
ENV DISCORDSRV_DB_NAME=discordsrv_db
ENV DISCORDSRV_DB_USERNAME=discordsrv
ENV DISCORDSRV_DB_PASSWORD=0000

WORKDIR ${WORKDIR_PATH}/config

# Minecraft
EXPOSE 25565/tcp
# BlueMap
EXPOSE 8100/tcp 

CMD \
    # Add proxy secret
    sed -i "s/_PROXY_SECRET_/${PROXY_SECRET}/g" config/paper-global.yml && \

    # Add Plasmo Voice secret
    cat plugins/PlasmoVoice/forwarding-secret | sed "s/00000000-0000-0000-0000-000000000000/${VOICE_SECRET}/g" | tr -d '\n' > plugins/PlasmoVoice/forwarding-secret.tmp && mv -T -f plugins/PlasmoVoice/forwarding-secret.tmp plugins/PlasmoVoice/forwarding-secret && \

    # Add luckperms database secrets
    sed -i "s/_LUCKPERMS_DB_HOST_/${LUCKPERMS_DB_HOST}/g" plugins/LuckPerms/config.yml && \
    sed -i "s/_LUCKPERMS_DB_PORT_/${LUCKPERMS_DB_PORT}/g" plugins/LuckPerms/config.yml && \
    sed -i "s/_LUCKPERMS_DB_NAME_/${LUCKPERMS_DB_NAME}/g" plugins/LuckPerms/config.yml && \
    sed -i "s/_LUCKPERMS_DB_USERNAME_/${LUCKPERMS_DB_USERNAME}/g" plugins/LuckPerms/config.yml && \
    sed -i "s/_LUCKPERMS_DB_PASSWORD_/${LUCKPERMS_DB_PASSWORD}/g" plugins/LuckPerms/config.yml && \

    # Add database info to skinsrestorer config
    sed -i "s/_SKINSRESTORER_DB_HOST_/${SKINSRESTORER_DB_HOST}/g" plugins/SkinsRestorer/config.yml && \
    sed -i "s/_SKINSRESTORER_DB_PORT_/${SKINSRESTORER_DB_PORT}/g" plugins/SkinsRestorer/config.yml && \
    sed -i "s/_SKINSRESTORER_DB_NAME_/${SKINSRESTORER_DB_NAME}/g" plugins/SkinsRestorer/config.yml && \
    sed -i "s/_SKINSRESTORER_DB_USERNAME_/${SKINSRESTORER_DB_USERNAME}/g" plugins/SkinsRestorer/config.yml && \
    sed -i "s/_SKINSRESTORER_DB_PASSWORD_/${SKINSRESTORER_DB_PASSWORD}/g" plugins/SkinsRestorer/config.yml && \

    # Add coreprotect database secrets
    sed -i "s/_COREPROTECT_DB_HOST_/${COREPROTECT_DB_HOST}/g" plugins/CoreProtect/config.yml && \
    sed -i "s/_COREPROTECT_DB_PORT_/${COREPROTECT_DB_PORT}/g" plugins/CoreProtect/config.yml && \
    sed -i "s/_COREPROTECT_DB_NAME_/${COREPROTECT_DB_NAME}/g" plugins/CoreProtect/config.yml && \
    sed -i "s/_COREPROTECT_DB_USERNAME_/${COREPROTECT_DB_USERNAME}/g" plugins/CoreProtect/config.yml && \
    sed -i "s/_COREPROTECT_DB_PASSWORD_/${COREPROTECT_DB_PASSWORD}/g" plugins/CoreProtect/config.yml && \

    # Add grim database secrets
    sed -i "s/_GRIM_DB_HOST_/${GRIM_DB_HOST}/g" plugins/GrimAC/config.yml && \
    sed -i "s/_GRIM_DB_PORT_/${GRIM_DB_PORT}/g" plugins/GrimAC/config.yml && \
    sed -i "s/_GRIM_DB_NAME_/${GRIM_DB_NAME}/g" plugins/GrimAC/config.yml && \
    sed -i "s/_GRIM_DB_USERNAME_/${GRIM_DB_USERNAME}/g" plugins/GrimAC/config.yml && \
    sed -i "s/_GRIM_DB_PASSWORD_/${GRIM_DB_PASSWORD}/g" plugins/GrimAC/config.yml && \

    # Add libertybans database secrets
    sed -i "s/_LIBERTYBANS_DB_HOST_/${LIBERTYBANS_DB_HOST}/g" plugins/LibertyBans/sql.yml && \
    sed -i "s/_LIBERTYBANS_DB_PORT_/${LIBERTYBANS_DB_PORT}/g" plugins/LibertyBans/sql.yml && \
    sed -i "s/_LIBERTYBANS_DB_NAME_/${LIBERTYBANS_DB_NAME}/g" plugins/LibertyBans/sql.yml && \
    sed -i "s/_LIBERTYBANS_DB_USERNAME_/${LIBERTYBANS_DB_USERNAME}/g" plugins/LibertyBans/sql.yml && \
    sed -i "s/_LIBERTYBANS_DB_PASSWORD_/${LIBERTYBANS_DB_PASSWORD}/g" plugins/LibertyBans/sql.yml && \

    # Add DiscordSRV bot token
    sed -i "s/_DISCORDSRV_BOT_TOKEN_/${DISCORDSRV_BOT_TOKEN}/g" plugins/DiscordSRV/config.yml && \
    # Add database info to DiscordSRV config
    sed -i "s/_DISCORDSRV_DB_HOST_/${DISCORDSRV_DB_HOST}/g" plugins/DiscordSRV/config.yml && \
    sed -i "s/_DISCORDSRV_DB_PORT_/${DISCORDSRV_DB_PORT}/g" plugins/DiscordSRV/config.yml && \
    sed -i "s/_DISCORDSRV_DB_NAME_/${DISCORDSRV_DB_NAME}/g" plugins/DiscordSRV/config.yml && \
    sed -i "s/_DISCORDSRV_DB_USERNAME_/${DISCORDSRV_DB_USERNAME}/g" plugins/DiscordSRV/config.yml && \
    sed -i "s/_DISCORDSRV_DB_PASSWORD_/${DISCORDSRV_DB_PASSWORD}/g" plugins/DiscordSRV/config.yml && \

    # Launch
    java -Xms${MEMORY} -Xmx${MEMORY} -jar *.jar -nogui
