def handlePlayers(rset, render, worldpath): if not hasattr(rset, "_pois"): rset._pois = dict(TileEntities=[], Entities=[]) # only handle this region set once if 'Players' in rset._pois: return dimension = { 'overworld': 0, 'nether': -1, 'end': 1, 'default': 0 }[render['dimension']] playerdir = os.path.join(worldpath, "players") if os.path.isdir(playerdir): playerfiles = os.listdir(playerdir) playerfiles = [x for x in playerfiles if x.endswith(".dat")] isSinglePlayer = False else: playerfiles = [os.path.join(worldpath, "level.dat")] isSinglePlayer = True rset._pois['Players'] = [] for playerfile in playerfiles: try: data = nbt.load(os.path.join(playerdir, playerfile))[1] if isSinglePlayer: data = data['Data']['Player'] except IOError: logging.warning("Skipping bad player dat file %r", playerfile) continue playername = playerfile.split(".")[0] if isSinglePlayer: playername = 'Player' if data['Dimension'] == dimension: # Position at last logout data['id'] = "Player" data['EntityId'] = playername data['x'] = int(data['Pos'][0]) data['y'] = int(data['Pos'][1]) data['z'] = int(data['Pos'][2]) rset._pois['Players'].append(data) if "SpawnX" in data and dimension == 0: # Spawn position (bed or main spawn) spawn = { "id": "PlayerSpawn", "EntityId": playername, "x": data['SpawnX'], "y": data['SpawnY'], "z": data['SpawnZ'] } rset._pois['Players'].append(spawn)
def handlePlayers(rset, render, worldpath): if not hasattr(rset, "_pois"): rset._pois = dict(TileEntities=[], Entities=[]) # only handle this region set once if 'Players' in rset._pois: return dimension = {'overworld': 0, 'nether': -1, 'end': 1, 'default': 0}[render['dimension']] playerdir = os.path.join(worldpath, "players") if os.path.isdir(playerdir): playerfiles = os.listdir(playerdir) playerfiles = [x for x in playerfiles if x.endswith(".dat")] isSinglePlayer = False else: playerfiles = [os.path.join(worldpath, "level.dat")] isSinglePlayer = True rset._pois['Players'] = [] for playerfile in playerfiles: try: data = nbt.load(os.path.join(playerdir, playerfile))[1] if isSinglePlayer: data = data['Data']['Player'] except IOError: logging.warning("Skipping bad player dat file %r", playerfile) continue playername = playerfile.split(".")[0] if isSinglePlayer: playername = 'Player' if data['Dimension'] == dimension: # Position at last logout data['id'] = "Player" data['EntityId'] = playername data['x'] = int(data['Pos'][0]) data['y'] = int(data['Pos'][1]) data['z'] = int(data['Pos'][2]) rset._pois['Players'].append(data) if "SpawnX" in data and dimension == 0: # Spawn position (bed or main spawn) spawn = {"id": "PlayerSpawn", "EntityId": playername, "x": data['SpawnX'], "y": data['SpawnY'], "z": data['SpawnZ']} rset._pois['Players'].append(spawn)
def handlePlayers(rset, render, worldpath): if not hasattr(rset, "_pois"): rset._pois = dict(TileEntities=[], Entities=[]) # only handle this region set once if "Players" in rset._pois: return dimension = {"overworld": 0, "nether": -1, "end": 1, "default": 0}[render["dimension"]] playerdir = os.path.join(worldpath, "players") if os.path.isdir(playerdir): playerfiles = os.listdir(playerdir) isSinglePlayer = False else: playerfiles = [os.path.join(worldpath, "level.dat")] isSinglePlayer = True rset._pois["Players"] = [] for playerfile in playerfiles: try: data = nbt.load(os.path.join(playerdir, playerfile))[1] if isSinglePlayer: data = data["Data"]["Player"] except IOError: logging.warning("Skipping bad player dat file %r", playerfile) continue playername = playerfile.split(".")[0] if isSinglePlayer: playername = "Player" if data["Dimension"] == dimension: # Position at last logout data["id"] = "Player" data["EntityId"] = playername data["x"] = int(data["Pos"][0]) data["y"] = int(data["Pos"][1]) data["z"] = int(data["Pos"][2]) rset._pois["Players"].append(data) if "SpawnX" in data and dimension == 0: # Spawn position (bed or main spawn) spawn = { "id": "PlayerSpawn", "EntityId": playername, "x": data["SpawnX"], "y": data["SpawnY"], "z": data["SpawnZ"], } rset._pois["Players"].append(spawn)
def handlePlayers(rset, render, worldpath, outputdir): if not hasattr(rset, "_pois"): rset._pois = dict(TileEntities=[], Entities=[]) # only handle this region set once if 'Players' in rset._pois: return if rset.get_type(): dimension = int( re.match(r"^DIM(_MYST)?(-?\d+)$", rset.get_type()).group(2)) else: dimension = 0 playerdir = os.path.join(worldpath, "playerdata") useUUIDs = True if not os.path.isdir(playerdir): playerdir = os.path.join(worldpath, "players") useUUIDs = False if os.path.isdir(playerdir): playerfiles = os.listdir(playerdir) playerfiles = [x for x in playerfiles if x.endswith(".dat")] isSinglePlayer = False else: playerfiles = [os.path.join(worldpath, "level.dat")] isSinglePlayer = True rset._pois['Players'] = [] for playerfile in playerfiles: try: data = PlayerDict(nbt.load(os.path.join(playerdir, playerfile))[1]) data.use_uuid = useUUIDs if isSinglePlayer: data = data['Data']['Player'] except IOError: logging.warning("Skipping bad player dat file %r", playerfile) continue playername = playerfile.split(".")[0] if isSinglePlayer: playername = 'Player' data._name = playername if data['Dimension'] == dimension: # Position at last logout data['id'] = "Player" data['x'] = int(data['Pos'][0]) data['y'] = int(data['Pos'][1]) data['z'] = int(data['Pos'][2]) # Time at last logout, calculated from last time the player's file was modified data['time'] = time.localtime( os.path.getmtime(os.path.join(playerdir, playerfile))) rset._pois['Players'].append(data) if "SpawnX" in data and dimension == 0: # Spawn position (bed or main spawn) spawn = PlayerDict() spawn._name = playername spawn["id"] = "PlayerSpawn" spawn["x"] = data['SpawnX'] spawn["y"] = data['SpawnY'] spawn["z"] = data['SpawnZ'] rset._pois['Players'].append(spawn)
else: raise playerdir = os.path.join(worldpath, "players") if os.path.isdir(playerdir): playerfiles = os.listdir(playerdir) playerfiles = [x for x in playerfiles if x.endswith(".dat")] isSinglePlayer = False else: playerfiles = [os.path.join(worldpath, "level.dat")] isSinglePlayer = True rset._pois['Players'] = [] for playerfile in playerfiles: try: data = nbt.load(os.path.join(playerdir, playerfile))[1] if isSinglePlayer: data = data['Data']['Player'] except IOError: logging.warning("Skipping bad player dat file %r", playerfile) continue playername = playerfile.split(".")[0] if isSinglePlayer: playername = 'Player' if data['Dimension'] == dimension: # Position at last logout data['id'] = "Player" data['EntityId'] = playername data['x'] = int(data['Pos'][0]) data['y'] = int(data['Pos'][1]) data['z'] = int(data['Pos'][2])
def handlePlayers(worldpath, filters, markers): """ Add markers for players to the list of markers. For this the player files under the given `worldpath` are parsed and filtered. This function will not return anything, but it will update the parameter `markers`. """ playerdir = os.path.join(worldpath, "playerdata") useUUIDs = True if not os.path.isdir(playerdir): playerdir = os.path.join(worldpath, "players") useUUIDs = False if os.path.isdir(playerdir): playerfiles = os.listdir(playerdir) playerfiles = [x for x in playerfiles if x.endswith(".dat")] isSinglePlayer = False else: playerfiles = [os.path.join(worldpath, "level.dat")] isSinglePlayer = True for playerfile in playerfiles: try: data = PlayerDict(nbt.load(os.path.join(playerdir, playerfile))[1]) data.use_uuid = useUUIDs if isSinglePlayer: data = data['Data']['Player'] except (IOError, TypeError): logging.warning("Skipping bad player dat file %r", playerfile) continue playername = playerfile.split(".")[0] if isSinglePlayer: playername = 'Player' data._name = playername # Position at last logout data['id'] = "Player" data['x'] = int(data['Pos'][0]) data['y'] = int(data['Pos'][1]) data['z'] = int(data['Pos'][2]) # Time at last logout, calculated from last time the player's file was modified data['time'] = time.localtime(os.path.getmtime(os.path.join(playerdir, playerfile))) # Spawn position (bed or main spawn) if "SpawnX" in data: # Spawn position (bed or main spawn) spawn = PlayerDict() spawn.use_uuid = useUUIDs spawn._name = playername spawn["id"] = "PlayerSpawn" spawn["x"] = data['SpawnX'] spawn["y"] = data['SpawnY'] spawn["z"] = data['SpawnZ'] for name, __, filter_function, rset, __, __ in filters: # get the dimension for the filter # This has do be done every time, because we have filters for # different regionsets. if rset.get_type(): dimension = int(re.match(r"^DIM(_MYST)?(-?\d+)$", rset.get_type()).group(2)) else: dimension = 0 if data['Dimension'] == dimension: result = filter_function(data) if result: d = create_marker_from_filter_result(data, result) markers[name]['raw'].append(d) if dimension == 0 and "SpawnX" in data: result = filter_function(spawn) if result: d = create_marker_from_filter_result(spawn, result) markers[name]['raw'].append(d)
def handlePlayers(worldpath, filters, markers): """ Add markers for players to the list of markers. For this the player files under the given `worldpath` are parsed and filtered. This function will not return anything, but it will update the parameter `markers`. """ playerdir = os.path.join(worldpath, "playerdata") useUUIDs = True if not os.path.isdir(playerdir): playerdir = os.path.join(worldpath, "players") useUUIDs = False if os.path.isdir(playerdir): playerfiles = os.listdir(playerdir) playerfiles = [x for x in playerfiles if x.endswith(".dat")] isSinglePlayer = False else: playerfiles = [os.path.join(worldpath, "level.dat")] isSinglePlayer = True for playerfile in playerfiles: try: data = PlayerDict(nbt.load(os.path.join(playerdir, playerfile))[1]) data.use_uuid = useUUIDs if isSinglePlayer: data = data['Data']['Player'] except (IOError, TypeError): logging.warning("Skipping bad player dat file %r", playerfile) continue playername = playerfile.split(".")[0] if isSinglePlayer: playername = 'Player' data._name = playername # Position at last logout data['id'] = "Player" data['x'] = int(data['Pos'][0]) data['y'] = int(data['Pos'][1]) data['z'] = int(data['Pos'][2]) # Time at last logout, calculated from last time the player's file was modified data['time'] = time.localtime( os.path.getmtime(os.path.join(playerdir, playerfile))) # Spawn position (bed or main spawn) if "SpawnX" in data: # Spawn position (bed or main spawn) spawn = PlayerDict() spawn.use_uuid = useUUIDs spawn._name = playername spawn["id"] = "PlayerSpawn" spawn["x"] = data['SpawnX'] spawn["y"] = data['SpawnY'] spawn["z"] = data['SpawnZ'] for name, __, filter_function, rset, __, __ in filters: # get the dimension for the filter # This has do be done every time, because we have filters for # different regionsets. if rset.get_type(): dimension = int( re.match(r"^DIM(_MYST)?(-?\d+)$", rset.get_type()).group(2)) else: dimension = 0 if data['Dimension'] == dimension: result = filter_function(data) if result: d = create_marker_from_filter_result(data, result) markers[name]['raw'].append(d) if dimension == 0 and "SpawnX" in data: result = filter_function(spawn) if result: d = create_marker_from_filter_result(spawn, result) markers[name]['raw'].append(d)
def handlePlayers(rset, render, worldpath, outputdir): if not hasattr(rset, "_pois"): rset._pois = dict(TileEntities=[], Entities=[]) # only handle this region set once if 'Players' in rset._pois: return if rset.get_type(): dimension = int(re.match(r"^DIM(_MYST)?(-?\d+)$", rset.get_type()).group(2)) else: dimension = 0 playerdir = os.path.join(worldpath, "playerdata") useUUIDs = True if not os.path.isdir(playerdir): playerdir = os.path.join(worldpath, "players") useUUIDs = False if os.path.isdir(playerdir): playerfiles = os.listdir(playerdir) playerfiles = [x for x in playerfiles if x.endswith(".dat")] isSinglePlayer = False else: playerfiles = [os.path.join(worldpath, "level.dat")] isSinglePlayer = True rset._pois['Players'] = [] for playerfile in playerfiles: try: data = PlayerDict(nbt.load(os.path.join(playerdir, playerfile))[1]) data.use_uuid = useUUIDs if isSinglePlayer: data = data['Data']['Player'] except IOError: logging.warning("Skipping bad player dat file %r", playerfile) continue playername = playerfile.split(".")[0] if isSinglePlayer: playername = 'Player' data._name = playername if data['Dimension'] == dimension: # Position at last logout data['id'] = "Player" data['x'] = int(data['Pos'][0]) data['y'] = int(data['Pos'][1]) data['z'] = int(data['Pos'][2]) # Time at last logout, calculated from last time the player's file was modified data['time'] = time.localtime(os.path.getmtime(os.path.join(playerdir, playerfile))) rset._pois['Players'].append(data) if "SpawnX" in data and dimension == 0: # Spawn position (bed or main spawn) spawn = PlayerDict() spawn._name = playername spawn["id"] = "PlayerSpawn" spawn["x"] = data['SpawnX'] spawn["y"] = data['SpawnY'] spawn["z"] = data['SpawnZ'] rset._pois['Players'].append(spawn)
""" Very basic player.dat inspection script """ import sys, os # incantation to be able to import overviewer_core if not hasattr(sys, "frozen"): sys.path.insert(0, os.path.abspath(os.path.join(os.path.split(__file__)[0], '..'))) from overviewer_core.nbt import load from overviewer_core import items print "Inspecting %s" % sys.argv[1] data = load(sys.argv[1])[1] print "Position: %r" % data['Pos'] print "Health: %s" % data['Health'] print "Inventory: %d items" % len(data['Inventory']) for item in data['Inventory']: print " %-3d %s" % (item['Count'], items.id2item(item['id']))
pass print "%sHealth:\t%i\tLevel:\t\t%i\t\tGameType:\t%i" % (indent, data['Health'], data['XpLevel'], data['playerGameType']) print "%sFood:\t%i\tTotal XP:\t%i" % (indent, data['foodLevel'], data['XpTotal']) print "%sInventory: %d items" % (indent, len(data['Inventory'])) if not sub_entry: for item in data['Inventory']: print " %-3d %s" % (item['Count'], items.id2item(item['id'])) if __name__ == '__main__': print "Inspecting %s" % sys.argv[1] if os.path.isdir(sys.argv[1]): directory = sys.argv[1] if len(sys.argv) > 2: selected_player = sys.argv[2] else: selected_player = None for player_file in os.listdir(directory): player = player_file.split(".")[0] if selected_player in [None, player]: print print player data = load(os.path.join(directory, player_file))[1] print_player(data, sub_entry=(selected_player is None)) else: data = load(sys.argv[1])[1] print_player(data)
def load_and_output_player(player_file_path, player, sub_entry=False): with player_file_path.open('rb') as f: player_data = load(f)[1] print("") print(player) print_player(player_data, sub_entry=sub_entry)
pass print "%sHealth:\t%i\tLevel:\t\t%i\t\tGameType:\t%i" % ( indent, data['Health'], data['XpLevel'], data['playerGameType']) print "%sFood:\t%i\tTotal XP:\t%i" % (indent, data['foodLevel'], data['XpTotal']) print "%sInventory: %d items" % (indent, len(data['Inventory'])) if not sub_entry: for item in data['Inventory']: print " %-3d %s" % (item['Count'], items.id2item(item['id'])) if __name__ == '__main__': print "Inspecting %s" % sys.argv[1] if os.path.isdir(sys.argv[1]): directory = sys.argv[1] if len(sys.argv) > 2: selected_player = sys.argv[2] else: selected_player = None for player_file in os.listdir(directory): player = player_file.split(".")[0] if selected_player in [None, player]: print print player data = load(os.path.join(directory, player_file))[1] print_player(data, sub_entry=(selected_player is None)) else: data = load(sys.argv[1])[1] print_player(data)