-
Notifications
You must be signed in to change notification settings - Fork 0
/
moveuser.py
executable file
·56 lines (41 loc) · 1.29 KB
/
moveuser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/python3
import sys
from glob import glob
from nbt import nbt
from datetime import date
datadir = '/home/mc/spigot/worlds/world/playerdata/'
def replace_date(old, new):
oldfile = newfile = None
for f in glob(datadir + '*.dat'):
player = nbt.NBTFile(f, 'rb')
try:
name = player['bukkit']['lastKnownName'].value
# print(name)
except KeyError:
continue
if name == old:
print("old: " + f)
oldfile = player
if newfile:
break
if name == new:
print("new: " + f)
newfile = player
newfilename = f
if oldfile:
break
else:
print("error: player not found")
return
olddate = oldfile['bukkit']['firstPlayed']
newdate = newfile['bukkit']['firstPlayed']
print('olddate:', date.fromtimestamp(olddate.value // 1000))
print('newdate:', date.fromtimestamp(newdate.value // 1000))
if newdate.value > olddate.value:
newdate.value = olddate.value
newfile.write_file(newfilename)
print("succesfully changed the date")
else:
print("error: first user joined later than second")
if __name__ == '__main__':
replace_date(sys.argv[1], sys.argv[2])