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 Default Minecraft files
RUN touch ${DATA_PATH}/banned-ips.json && \
    ln -sf ${DATA_PATH}/banned-ips.json ${CONFIG_PATH}
RUN touch ${DATA_PATH}/banned-players.json && \
    ln -sf ${DATA_PATH}/banned-players.json ${CONFIG_PATH}
RUN mkdir ${DATA_PATH}/logs && \
    ln -sf ${DATA_PATH}/logs ${CONFIG_PATH}
RUN touch ${DATA_PATH}/ops.json && \
    ln -sf ${DATA_PATH}/ops.json ${CONFIG_PATH}
RUN touch ${DATA_PATH}/usercache.json && \
    ln -sf ${DATA_PATH}/usercache.json ${CONFIG_PATH}
RUN touch ${DATA_PATH}/whitelist.json && \
    ln -sf ${DATA_PATH}/whitelist.json ${CONFIG_PATH}
RUN mkdir ${DATA_PATH}/world && \
    ln -sf ${DATA_PATH}/world ${CONFIG_PATH}
RUN mkdir ${DATA_PATH}/world_nether && \
    ln -sf ${DATA_PATH}/world_nether ${CONFIG_PATH}
RUN mkdir ${DATA_PATH}/world_the_end && \
    ln -sf ${DATA_PATH}/world_the_end ${CONFIG_PATH}

# Add symlinks to Plasmo Voice files
RUN touch ${DATA_PATH}/pv-voice_mutes.json && \
    ln -sf ${DATA_PATH}/pv-voice_mutes.json \
        ${CONFIG_PATH}/plugins/PlasmoVoice/voice_mutes.json
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
RUN mkdir -p ${DATA_PATH}/CarbonChat/users && \
    ln -sf ${DATA_PATH}/CarbonChat/users \
        ${CONFIG_PATH}/plugins/CarbonChat/users

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

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

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

# 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 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


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
ENV LUCKPERMS_DB_USERNAME=luckperms
ENV LUCKPERMS_DB_PASSWORD=0000

ENV DISCORDSRV_BOT_TOKEN=token


WORKDIR ${WORKDIR_PATH}/config

EXPOSE 25565/tcp

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

    # 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 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 DiscordSRV secrets
    sed -i "s/_DISCORDSRV_BOT_TOKEN_/${DISCORDSRV_BOT_TOKEN}/g" plugins/DiscordSRV/config.yml && \

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