Created
August 16, 2023 01:11
-
-
Save CanadianBaconBoi/aa19a308402db9500eaf436b10b4602b to your computer and use it in GitHub Desktop.
VaultLurker cleanup tool, moves players from vaults that are disconnected for long periods of time
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
| ''' | |
| Copyright (c) 2023 CanadianBacon | |
| Permission is hereby granted, free of charge, to any person obtaining a copy | |
| of this software and associated documentation files (the "Software"), to deal | |
| in the Software without restriction, including without limitation the rights | |
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| copies of the Software, and to permit persons to whom the Software is | |
| furnished to do so, subject to the following conditions: | |
| The above copyright notice and this permission notice shall be included in all | |
| copies or substantial portions of the Software. | |
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
| SOFTWARE. | |
| ''' | |
| import os, resource, sys, threading, time, json, datetime, dateutil.parser | |
| from nbt import nbt | |
| from nbt.nbt import * | |
| from multiprocessing.pool import ThreadPool | |
| # VARIABLES | |
| spawnPos = [-23, 232, -27] | |
| spawnWorld = "minecraft:overworld" | |
| retentionDays = 44 | |
| manualCleanupUsers = [ | |
| '0a2cfc65-8796-4ccf-99e8-dc50311290e4', | |
| '5f8e81af-d799-4844-a4a0-616d94bf90ff', | |
| '6d7e3dea-b0f7-485d-ac1e-405e55e9f0c6', | |
| '015bf2aa-ae26-446d-86cc-069c8eea67a7', | |
| 'aaaca080-e3c5-46b8-80e4-cc045cd3bc55', | |
| '20e8d2d6-b0e3-40ad-b8d5-8d4f11da4528', | |
| 'b5f9ba1c-c2da-4c5b-b83a-c55ffd3d825a' | |
| ] | |
| counter_lock = threading.Lock() | |
| processed_counter = 0 | |
| nbt_files = [] | |
| nbt_objects = dict() | |
| def counterTask(): | |
| while processed_counter < len(nbt_files): | |
| print("\r{out}/{of} loaded".format(out=processed_counter, of=len(nbt_files)), end="") | |
| time.sleep(0.5) | |
| def loadNbtTask(file): | |
| global processed_counter | |
| try: | |
| nbt_file = nbt.NBTFile(file,'rb') | |
| nbt_objects[file] = nbt_file | |
| except Exception: | |
| pass | |
| with counter_lock: | |
| processed_counter += 1 | |
| print("CanadianBacon's VaultLurker Cleanup Tool") | |
| print("A utility to remove those pesky players keeping") | |
| print("vaults loaded for more than ["+str(retentionDays)+"] days.") | |
| print("This tool is licensed under The MIT License") | |
| print("===========================================") | |
| for (root, dirs, filenames) in os.walk("./playerdata"): | |
| for name in filenames: | |
| if os.path.splitext(name)[1] == ".dat": | |
| nbt_files.append(os.path.join(root, name)) | |
| pool = ThreadPool(processes=65) | |
| pool.apply_async(counterTask) | |
| pool.map(loadNbtTask, nbt_files) | |
| usercache = None | |
| with open("usercache.json", 'r') as file: | |
| usercache = json.load(file) | |
| users_in_vault = [] | |
| for nbt_path, nbt_object in nbt_objects.items(): | |
| if nbt_object["Dimension"].value.startswith("the_vault"): | |
| users_in_vault.append(os.path.basename(os.path.splitext(nbt_path)[0])) | |
| vault_user_entries = [] | |
| for user in usercache: | |
| for vault_user in users_in_vault: | |
| if user["uuid"] == vault_user: | |
| vault_user_entries.append(user) | |
| users_in_vault.remove(vault_user) | |
| break | |
| print("\n\nBelow users were not found in the usercache, leaving them as is!") | |
| print("================================================================") | |
| print(users_in_vault) | |
| for to_clean in manualCleanupUsers: | |
| vault_user_entries.append({'uuid':to_clean, 'expiresOn':'19691231T190000-0500'}) | |
| time_threshold = datetime.date.today() - datetime.timedelta(days=(retentionDays-30)) | |
| to_remove = [] | |
| print("\nUsers moved to spawn:") | |
| for user in vault_user_entries: | |
| if(dateutil.parser.parse(user["expiresOn"]).date() < time_threshold): | |
| print(user.get("name", user["uuid"])) | |
| nbt_file = nbt.NBTFile("./playerdata/"+user["uuid"]+".dat", 'rb') | |
| nbt_file["Dimension"].value = spawnWorld | |
| nbt_file["Pos"].tags.clear() | |
| nbt_file["Pos"].tags.extend([TAG_Double(spawnPos[0]), TAG_Double(spawnPos[1]), TAG_Double(spawnPos[2])]) | |
| nbt_file.write_file("./playerdata/"+user["uuid"]+".dat") | |
| to_remove.append(user) | |
| # -23, 232, -27 minecraft:overworld | |
| vault_user_entries = filter(lambda i : i not in to_remove, vault_user_entries) | |
| print("\n\nUsers not moved:") | |
| for user in vault_user_entries: | |
| print(user.get("name", user["uuid"])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment