Skip to content

Instantly share code, notes, and snippets.

@divadsn
Created October 24, 2020 18:46
Show Gist options
  • Save divadsn/967beacf23cf10d3fb6bd3747cd5d6c0 to your computer and use it in GitHub Desktop.
Save divadsn/967beacf23cf10d3fb6bd3747cd5d6c0 to your computer and use it in GitHub Desktop.
import nbt
import os
import requests
import shutil
import uuid
uuids = {}
for file in os.listdir("world/playerdata"):
if file.endswith(".dat"):
nbtfile = nbt.nbt.NBTFile(os.path.join("world/playerdata", file), "rb")
uuids[file.split(".")[0]] = nbtfile["bukkit"]["lastKnownName"].value
if file.endswith(".dat_old"):
os.remove(os.path.join("world/playerdata", file))
for offline_uuid, player_name in uuids.items():
# check if player name is premium
r = requests.get("https://api.mojang.com/users/profiles/minecraft/" + player_name)
r.raise_for_status()
try:
data = r.json()
except:
continue
premium_uuid = uuid.UUID(data["id"])
print(f"Converting offline UUID for player {player_name} with UUID {premium_uuid}")
shutil.move(f"world/playerdata/{offline_uuid}.dat", f"world/playerdata/{premium_uuid}.dat")
shutil.move(f"world/stats/{offline_uuid}.json", f"world/stats/{premium_uuid}.json")
shutil.move(f"world/advancements/{offline_uuid}.json", f"world/advancements/{premium_uuid}.json")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment