From 2cd58b27ed837ced4193d140647ecf7655468342 Mon Sep 17 00:00:00 2001 From: Ableytner Date: Tue, 12 Mar 2024 21:32:57 +0100 Subject: [PATCH] add version reading for older versions --- mcserverwrapper/src/server/server_builder.py | 22 ++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/mcserverwrapper/src/server/server_builder.py b/mcserverwrapper/src/server/server_builder.py index f75bab2..025b656 100644 --- a/mcserverwrapper/src/server/server_builder.py +++ b/mcserverwrapper/src/server/server_builder.py @@ -5,6 +5,7 @@ import json import pathlib import os +import re from zipfile import ZipFile from .base_server import BaseServer @@ -131,11 +132,24 @@ def _check_jar_fabric(jar_file: str) -> McVersion | None: @staticmethod def _check_jar_vanilla(jar_file: str) -> McVersion | None: - version_json = None with ZipFile(jar_file, "r") as zf: + # for Minecraft 1.14+ + version_json = None for zip_fileinfo in zf.filelist: if zip_fileinfo.filename == "version.json": version_json = json.loads(zf.read(zip_fileinfo)) - if version_json is None: - return None - return McVersion(version_json["name"], McVersionType.VANILLA) + if version_json is not None: + return McVersion(version_json["name"], McVersionType.VANILLA) + + # for Mineraft 1.13.2- + mcs_class = None + for zip_fileinfo in zf.filelist: + if zip_fileinfo.filename == "net/minecraft/server/MinecraftServer.class": + mcs_class = zf.read(zip_fileinfo) + if mcs_class is not None: + vers = [x.group() for x in re.finditer(r"1\.[1-2]{0,1}[0-9](\.[0-9]{1,2})?", mcs_class.decode("ANSI"))] + if len(vers) != 0: + return McVersion(vers[0], McVersionType.VANILLA) + + # no version was found + return None