def api_maps_index(): """Returns a list of existing maps with all of their fields except for the actual colors.""" ret = {} for map_file in (minecraft.World().world_path / 'data').iterdir(): match = re.match('map_([0-9]+).dat', map_file.name) if not match: continue map_id = int(match.group(1)) nbt_dict = nbtfile_to_dict(map_file)['data'] del nbt_dict['colors'] ret[str(map_id)] = nbt_dict return ret
def playernames(): """Returns all player names it can find""" try: data = [entry['name'] for entry in json.loads(api_whitelist())] except: data = [] directory = minecraft.World().world_path / 'players' for root, dirs, files in os.walk(str(directory)): for file in files: if file.endswith('.dat'): name = os.path.splitext(file)[0] data.append(name) return data
def decorated(*args, **kwargs): for param, arg in zip(inspect.signature(f).parameters.values(), args): if param.name not in kwargs: kwargs[param.name] = arg decoded_args = {} for param in inspect.signature(f).parameters.values(): arg = kwargs[param.name] if param.kind is not inspect.Parameter.POSITIONAL_OR_KEYWORD: raise ValueError( 'The decode_args function only works for POSITIONAL_OR_KEYWORD parameters, but a {} parameter was found' .format(param.kind)) if param.annotation is inspect.Parameter.empty or not isinstance( arg, str): # no annotation or a direct function call decoded_args[param.name] = arg elif param.annotation is Dimension: try: int(arg) except: decoded_args[param.name] = Dimension[arg] else: decoded_args[param.name] = Dimension(int(arg)) elif param.annotation is Player: decoded_args[param.name] = Player(arg) elif param.annotation is int: decoded_args[param.name] = int(arg) elif param.annotation is minecraft.World: decoded_args[param.name] = minecraft.World(arg) elif param.annotation == 'color': decoded_args[param.name] = (int(arg[:2], 16), int(arg[2:4], 16), int(arg[4:6], 16)) elif isinstance(param.annotation, range): if int(arg) not in param.annotation: bottle.abort( 403, 'Parameter {} must be in {}'.format( param.name, param.annotation)) decoded_args[param.name] = int(arg) else: raise TypeError( 'The decode_args function is not implemented for the argument type {:?}' .format(param.annotation)) return f(**decoded_args)
def latest(cls, world=None): if world is None: world = minecraft.World() return cls(world, files=[world.path / 'logs' / 'latest.log'])
def api_villages(): """Returns the villages.dat of the main world's Overworld, encoded as JSON""" nbt_file = minecraft.World().world_path / 'data' / 'villages.dat' return nbtfile_to_dict(nbt_file)
def api_whitelist(): """For UUID-based Minecraft servers (1.7.6 and later), returns the whitelist. For older servers, the behavior is undefined.""" with (minecraft.World().path / 'whitelist.json').open() as whitelist: return whitelist.read()
def api_scoreboard(): """Returns the scoreboard data encoded as JSON""" nbt_file = minecraft.World().world_path / 'data' / 'scoreboard.dat' return nbtfile_to_dict(nbt_file)
def api_map_render_png(identifier): """Returns the map item with damage value :identifier, rendered as a PNG image file.""" return api.v2.api_map_render_png(minecraft.World().name, identifier)
def api_map_by_id(identifier): """Returns info about the map item with damage value :identifier, see http://minecraft.gamepedia.com/Map_Item_Format for documentation""" nbt_file = minecraft.World().world_path / 'data' / 'map_{}.dat'.format( identifier) return nbtfile_to_dict(nbt_file)
def api_level(): """Returns the level.dat encoded as JSON""" nbt_file = minecraft.World().world_path / 'level.dat' return nbtfile_to_dict(nbt_file)
def api_deaths(): """Returns JSON containing information about all recorded player deaths""" return api.v2.api_deaths(minecraft.World())
def api_latest_deaths(): """Returns JSON containing information about the most recent death of each player""" return api.v2.api_latest_deaths(minecraft.World())
def api_achievement_winners(): """Returns a list of Wurstmineberg IDs of all players who have completed all achievements, ordered chronologically by the time they got their last achievement. This list is emptied each time a new achievement is added to Minecraft.""" return json.dumps(list( api.v2.api_achievement_winners(minecraft.World()).keys()), sort_keys=True, indent=4)