import nbtlib as n import subprocess as s import sys x1 = int(int(sys.argv[1]) / 16) y1 = int(int(sys.argv[2]) / 16) x2 = int(int(sys.argv[3]) / 16) y2 = int(int(sys.argv[4]) / 16) tx = ty = t1 = t2 = 0 for x in range(x1 + 11, x2 + 11, 22): for y in range(y1 + 11, y2 + 11, 22): tx = abs(x1 - x) ty = abs(y1 - y) t1 = x1 + tx if (t1 + 11 >= x2): t1 = x2 - 12 t1 = t1 * 16 t2 = y1 + ty if (t2 + 11 >= y2): t2 = y2 - 12 t2 = t2 * 16 file = n.load("world/level.dat") file.root["Data"]["SpawnX"] = n.Int(t1) file.root["Data"]["SpawnZ"] = n.Int(t2) file.save() print(t1, "\t", t2) proc = s.Popen(['java', '-jar', 'server.jar', 'nogui'], stdout=s.PIPE, stdin=s.PIPE) while True: a = proc.stdout.readline() print(a) if a.count(b'For help, type "help"') == 1: proc.communicate(b'stop\n') break proc.wait() print("Done")