Skip to content

Instantly share code, notes, and snippets.

@AdamG100
Last active September 17, 2025 13:23
Show Gist options
  • Select an option

  • Save AdamG100/ac1906d53194796db44dd86234ff184c to your computer and use it in GitHub Desktop.

Select an option

Save AdamG100/ac1906d53194796db44dd86234ff184c to your computer and use it in GitHub Desktop.
This script is used in TCAdmin it is designed to fetch all bedrock stable and preview builds from the mcjarfiles API
import re, urllib2, json
import clr
clr.AddReference('TCAdmin.GameHosting.SDK')
from TCAdmin.GameHosting.SDK.Objects import GameUpdate, GameScript, ServiceEvent
gameID = 193
scripts = [
{
"Name": "Backup server.properties",
"Event": ServiceEvent.BeforeUpdateInstall,
'Contents': "from os import path, rename, remove\nserverproperties = path.join(ThisService.RootDirectory, 'server.properties')\nif path.isfile(serverproperties):\n if path.isfile(serverproperties+'.backup'):\n remove(serverproperties+'.backup')\n rename(serverproperties, serverproperties+'.backup')"
},
{
"Name": "Delete new server.properties, use old file instead",
"Event": ServiceEvent.AfterUpdateInstall,
"Contents": "from os import path, rename, remove\nserverproperties = path.join(ThisService.RootDirectory, 'server.properties')\nif path.isfile(serverproperties):\n remove(serverproperties)\nrename(serverproperties+'.backup', serverproperties)"
}
]
updates = GameUpdate.GetUpdates(gameID)
# Fetch versions from your API
try:
versions_response = urllib2.urlopen('https://mcjarfiles.com/api/get-versions/bedrock/latest')
versions_list = json.loads(versions_response.read())
if versions_list and isinstance(versions_list, list):
for version in versions_list:
#Generate view order
parts = version.split('.')
# Ensure we have 4 parts for consistent ordering
while len(parts) < 4:
parts.append('0')
for i in range(len(parts)):
parts[i] = parts[i].zfill(3)
view_order = -int(''.join(parts))
#Skip if an update already exists with the same name
skip = False
for gameUpdate in updates:
if gameUpdate.Name == "Bedrock Edition " + version:
Script.WriteToConsole('Skipping version {}'.format(version))
skip = True
break
if not skip:
update = GameUpdate()
update.Name = "Bedrock Edition " + version
update.Comments = ""
update.ImageUrl = "https://media.hyperlayer.net/creeper-icon.png"
update.GameId = gameID
update.GroupName = "Minecraft: Bedrock Edition Latest"
update.ExtractPath = "/"
update.WindowsFileName = "https://mcjarfiles.com/api/get-jar/bedrock/latest/windows/{}".format(version)
update.LinuxFileName = "https://mcjarfiles.com/api/get-jar/bedrock/latest/linux/{}".format(version)
update.Reinstallable = True
update.DefaultInstall = False
update.UserAccess = True
update.SubAdminAccess = True
update.ResellerAccess = True
update.ViewOrder = view_order
update.GenerateKey()
update.Save()
Script.WriteToConsole("Added update for Minecraft: Bedrock Edition v{}".format(version))
#Add custom scripts
for script in scripts:
updateScript = GameScript()
updateScript.Description = script["Name"]
updateScript.ScriptContents = script["Contents"]
updateScript.ServiceEvent = script["Event"]
updateScript.ExecuteAsServiceUser = False
updateScript.ExecuteInPopup = False
updateScript.ExecutionOrder = 0
updateScript.GameId = gameID
updateScript.IgnoreErrors = False
updateScript.OperatingSystem = 0 #0 = Any, 2 = Windows, 4 = Linux
updateScript.PromptVariables = False
updateScript.UserAccess = True
updateScript.SubAdminAccess = True
updateScript.ResellerAccess = True
updateScript.ScriptEngineId = 1 #IronPython
updateScript.UpdateId = update.UpdateId
updateScript.GenerateKey()
updateScript.Save()
# Update the "Latest" update with the first version in the list (most recent)
if len(versions_list) > 0:
latest_version = versions_list[0]
gameUpdates = set(updates)
for latestUpdate in gameUpdates:
if 'Latest Bedrock Update' in latestUpdate.Notes:
Script.WriteToConsole('Changing the links for the latest Bedrock update to version {}'.format(latest_version))
latestUpdate.WindowsFileName = "https://mcjarfiles.com/api/get-jar/bedrock/latest/windows/{}".format(latest_version)
latestUpdate.LinuxFileName = "https://mcjarfiles.com/api/get-jar/bedrock/latest/linux/{}".format(latest_version)
latestUpdate.Save()
break
else:
Script.WriteToConsole('No versions found in API response')
except Exception as e:
Script.WriteToConsole('Error fetching versions from API: {}'.format(str(e)))
@YawnyNZ
Copy link
Copy Markdown

YawnyNZ commented Apr 5, 2025

Fandom wiki is no longer regularly updated.
Unfortunately the other wiki blocks urllib2: https://minecraft.wiki/w/Bedrock_Dedicated_Server
You can use the official site and replace urllib2 with .NET HttpWebRequest

import re, clr
clr.AddReference('System')
clr.AddReference('TCAdmin.GameHosting.SDK')
from System.Net import HttpWebRequest
from System.IO import StreamReader
from TCAdmin.GameHosting.SDK.Objects import GameUpdate, GameScript, ServiceEvent

gameID = 193
scripts = [
    {
        "Name": "Backup server.properties",
        "Event": ServiceEvent.BeforeUpdateInstall,
        'Contents': (
            "from os import path, rename, remove\n"
            "serverproperties = path.join(ThisService.RootDirectory, 'server.properties')\n"
            "if path.isfile(serverproperties):\n"
            "  if path.isfile(serverproperties+'.backup'):\n"
            "    remove(serverproperties+'.backup')\n"
            "  rename(serverproperties, serverproperties+'.backup')"
        )
    },
    {
        "Name": "Delete new server.properties, use old file instead",
        "Event": ServiceEvent.AfterUpdateInstall,
        "Contents": (
            "from os import path, rename, remove\n"
            "serverproperties = path.join(ThisService.RootDirectory, 'server.properties')\n"
            "if path.isfile(serverproperties):\n"
            "  remove(serverproperties)\n"
            "rename(serverproperties+'.backup', serverproperties)"
        )
    }
]

# Fetch existing updates
updates = GameUpdate.GetUpdates(gameID)

# Fetch version page using .NET HttpWebRequest
try:
    url = "https://www.minecraft.net/en-us/download/server/bedrock"
    request = HttpWebRequest.Create(url)
    request.UserAgent = "Mozilla/5.0"
    response = request.GetResponse()
    stream = response.GetResponseStream()
    reader = StreamReader(stream)
    html = reader.ReadToEnd()
except Exception as ex:
    Script.WriteToConsole("Failed to fetch update page: {}".format(str(ex)))
    raise

# Extract versions from the HTML
regex_pattern = r'https://www\.minecraft\.net/bedrockdedicatedserver/bin-win/bedrock-server-(?P<version>[\d\.]+)\.zip'
matches = re.findall(regex_pattern, html)

if len(matches) > 0:
    for version in matches:
        release = ''  # No preview flag in this format

        # Generate view order
        parts = version.split('.')
        for i in range(4):
            parts[i] = parts[i].zfill(3)
        view_order = -int(''.join(parts))

        # Check if update already exists
        skip = False
        for gameUpdate in updates:
            if gameUpdate.Name == "Bedrock Edition " + version:
                Script.WriteToConsole('Skipping version {}'.format(version))
                skip = True
                break

        if not skip:
            update = GameUpdate()
            update.Name = "Bedrock Edition " + version
            update.Comments = ""
            update.ImageUrl = "https://www.minecraft.net/etc.clientlibs/minecraft/clientlibs/main/resources/img/header/logo.png"
            update.GameId = gameID
            update.GroupName = "Minecraft: Bedrock Edition"
            update.ExtractPath = "/"
            update.WindowsFileName = "https://www.minecraft.net/bedrockdedicatedserver/bin-win/bedrock-server-{}.zip".format(version)
            update.LinuxFileName = "https://www.minecraft.net/bedrockdedicatedserver/bin-linux/bedrock-server-{}.zip".format(version)
            update.Reinstallable = True
            update.DefaultInstall = False
            update.UserAccess = True
            update.SubAdminAccess = True
            update.ResellerAccess = True
            update.ViewOrder = view_order
            update.GenerateKey()
            update.Save()
            Script.WriteToConsole("Added update for Minecraft: Bedrock Edition v{}".format(version))

            # Attach the event scripts
            for script in scripts:
                updateScript = GameScript()
                updateScript.Description = script["Name"]
                updateScript.ScriptContents = script["Contents"]
                updateScript.ServiceEvent = script["Event"]
                updateScript.ExecuteAsServiceUser = False
                updateScript.ExecuteInPopup = False
                updateScript.ExecutionOrder = 0
                updateScript.GameId = gameID
                updateScript.IgnoreErrors = False
                updateScript.OperatingSystem = 0  # 0 = Any
                updateScript.PromptVariables = False
                updateScript.UserAccess = True
                updateScript.SubAdminAccess = True
                updateScript.ResellerAccess = True
                updateScript.ScriptEngineId = 1  # IronPython
                updateScript.UpdateId = update.UpdateId
                updateScript.GenerateKey()
                updateScript.Save()

            # Update latest pointer if needed
            for existing in updates:
                if 'Latest Bedrock Update' in existing.Notes:
                    Script.WriteToConsole('Changing the links for the latest Bedrock update')
                    existing.WindowsFileName = "https://www.minecraft.net/bedrockdedicatedserver/bin-win/bedrock-server-{}.zip".format(version)
                    existing.LinuxFileName = "https://www.minecraft.net/bedrockdedicatedserver/bin-linux/bedrock-server-{}.zip".format(version)
                    existing.Save()
else:
    Script.WriteToConsole("No versions found.")

@AdamG100
Copy link
Copy Markdown
Author

AdamG100 commented Aug 8, 2025

updated script to use https://mcjarfiles.com/ API instead of scraping data from wiki

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment