From 10729c27022c3dc5afc09f7e0d3173d7cc4d9ca0 Mon Sep 17 00:00:00 2001 From: Jim Shepich III Date: Tue, 18 Feb 2025 01:57:42 -0500 Subject: [PATCH] Initial commit --- .version | 1 + Containerfile | 17 ++++++++++++++++ README.md | 28 +++++++++++++++++++++++++ build.sh | 3 +++ minecraft-plugin-proxy.py | 43 +++++++++++++++++++++++++++++++++++++++ push.sh | 0 requirements.txt | 2 ++ 7 files changed, 94 insertions(+) create mode 100644 .version create mode 100644 Containerfile create mode 100644 README.md create mode 100644 build.sh create mode 100644 minecraft-plugin-proxy.py create mode 100644 push.sh create mode 100644 requirements.txt diff --git a/.version b/.version new file mode 100644 index 0000000..f120bd5 --- /dev/null +++ b/.version @@ -0,0 +1 @@ +0.0.1-dev1 \ No newline at end of file diff --git a/Containerfile b/Containerfile new file mode 100644 index 0000000..11ee7e1 --- /dev/null +++ b/Containerfile @@ -0,0 +1,17 @@ +FROM python:3.13-slim + +# Set the working directory +WORKDIR /app + +# Copy the current directory contents into the container at /app +COPY minecraft-plugin-proxy.py /app +COPY requirements.txt /app + +# Install any needed packages specified in requirements.txt +RUN pip install --no-cache-dir -r requirements.txt + +# Make port 8000 available to the world outside this container. +EXPOSE 8000 + +# Serve the API +CMD ['fastapi', 'run', '--port', '8000', '/app/minecraft-plugin-proxy.py'] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..92ad7e3 --- /dev/null +++ b/README.md @@ -0,0 +1,28 @@ +# Minecraft Plugin Proxy + +Are you a Minecraft sysadmin using a containerized setup? Are you sick of dealing with plugins that don't support downloading the latest version via REST API? Then this is the project for you! + +This project is a proxy server that will find the latest version of a plugin and redirect you to the download link. + +All of the plugins have custom hard-coded logic that will find the latest version of the plugin and redirect you to the download link. + +## Usage + +Include the minecraft-plugin-proxy as a service in your compose unit: + +```yaml +services: + minecraft-plugin-proxy: + image: ghcr.io/epicshepich/minecraft-plugin-proxy:latest +``` + +Services in your compose unit can access the proxy server at `http://minecraft-plugin-proxy:8080` with the following query parameters: + + +## Endpoints + +The following endpoints are currently available: + +- `/viabackwards/velocity`: ViaBackwards for the Velocity proxy container. +- `/luckperms/{server_type}`: LuckPerms for the specified server type (e.g. `bukkit`, `bungeecord`, `velocity`). +- `/tribufu-velocityrcon`: Tribufu's VelocityRcon plugin for the Velocity proxy container. \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..119dd0f --- /dev/null +++ b/build.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +podman build -t minecraft-plugin-proxy:latest -t minecraft-plugin-proxy:$(cat ./.version) . \ No newline at end of file diff --git a/minecraft-plugin-proxy.py b/minecraft-plugin-proxy.py new file mode 100644 index 0000000..9fa3edb --- /dev/null +++ b/minecraft-plugin-proxy.py @@ -0,0 +1,43 @@ +''' +A proxy built on FastAPI to find the most recent version of a Minecraft plugin. +''' + +import requests +from fastapi import FastAPI +from fastapi.responses import RedirectResponse + +from xml.etree import ElementTree as ET + +api = FastAPI() + +@api.get('/viabackwards/velocity') +async def viabackwards_velocity(): + + latest_release = requests.get( + 'https://hangar.papermc.io/api/v1/projects/ViaVersion/ViaBackwards/latestrelease' + ).text.strip() + return RedirectResponse( + f'https://hangar.papermc.io/api/v1/projects/ViaVersion/ViaBackwards/versions/{latest_release}/Velocity/download' + ) + +@api.get('/luckperms/{server_type}') +async def luckperms_velocity(server_type): + + luckperms_metadata = requests.get('https://metadata.luckperms.net/data/all').json() + + return RedirectResponse( + luckperms_metadata['downloads'][server_type] + ) + + +@api.get('/tribufu-velocityrcon') +async def tribufu_velocityrcon(): + + velocityrcon_metadata = requests.get('https://mvn.tribufu.com/releases/com/tribufu/Tribufu-VelocityRcon/maven-metadata.xml').text + + root = ET.fromstring(velocityrcon_metadata) + version = root.find('.//versioning/latest').text + + return RedirectResponse( + f'https://mvn.tribufu.com/releases/com/tribufu/Tribufu-VelocityRcon/{version}/Tribufu-VelocityRcon-{version}.jar' + ) \ No newline at end of file diff --git a/push.sh b/push.sh new file mode 100644 index 0000000..e69de29 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..735558d --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +requests +fastapi[standard] \ No newline at end of file