Last active
September 17, 2025 13:23
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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