PlowmanPlow

Python Parse LoTR Title

Nov 1st, 2018 (edited)
191
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python3
  2.  
  3. import sys, os
  4. import json
  5. from nbtlib import nbt
  6. from nbtlib.tag import *
  7. from pprint import pprint
  8.  
  9. selfPath = os.path.dirname(sys.argv[0]) + "/"
  10.  
  11. # Black, Blue, Green, Cyan, Red, Magenta, Yellow, LightGray, Gray, LightBlue, LightGreen, LightCyan, LightRed, LightMagenta, LightYellow, White
  12. lotrToMCColors = {48: "0", 49: "1", 50: "2", 51: "3", 52: "4", 53: "5", 54: "6", 55: "7", 56: "8", 57: "9", 97: "a", 98: "b", 99: "c", 100: "d", 101: "e", 102: "f"}
  13.  
  14. dataFileName = "LoTRCircles/LOTR/players/" + sys.argv[1] + ".dat"
  15.  
  16. with open('pyscripts/titles.json', 'r') as fp:
  17.     titleMap = json.load(fp)
  18.  
  19. #
  20. # Load the main player data file
  21. nbtfile = nbt.load(dataFileName)
  22.  
  23. title = ""
  24. color = "f"
  25. if 'PlayerTitle' in nbtfile['']:
  26.     title = titleMap[nbtfile['']['PlayerTitle']]
  27.     color = lotrToMCColors[nbtfile['']['PlayerTitleColor']]
  28.  
  29. #if title == "":
  30. #    title = "Untitled"
  31. print(title + "_" + color, end='', flush=True)
  32. sys.exit(0)
  33.  
RAW Paste Data