Skip to content

Commit

Permalink
add version reading for older versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ableytner committed Mar 12, 2024
1 parent fa2fb32 commit 2cd58b2
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions mcserverwrapper/src/server/server_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import json
import pathlib
import os
import re
from zipfile import ZipFile

from .base_server import BaseServer
Expand Down Expand Up @@ -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

0 comments on commit 2cd58b2

Please sign in to comment.