def recover_initial_blockmap(old_workdir): """Given a logdir containing a logging.bin, regenerate the initial blockmap and return the directory with the region (.mca) files. """ workdir = tempfile.mkdtemp() print("Workdir:", workdir, flush=True) repo_home = os.path.join(os.path.dirname(os.path.realpath(__file__)), "../../") # Copy files from old workdir paths = ["Plugins", "settings.ini", "blocks.json", "world/world.ini"] for p in paths: src = os.path.join(old_workdir, p) dst = os.path.join(workdir, p) if os.path.isfile(src): os.makedirs(os.path.dirname(dst), exist_ok=True) shutil.copy(src, dst) elif os.path.isdir(src): shutil.copytree(src, dst) # Remove logging plugin, add recovery plugin settings_ini = os.path.join(workdir, "settings.ini") plugins_dir = os.path.join(workdir, "Plugins") recovery_plugin_dir = os.path.join(plugins_dir, PLUGIN_NAME) edit_cuberite_config.remove_plugin(settings_ini, "logging") edit_cuberite_config.add_plugin(settings_ini, PLUGIN_NAME) if not os.path.isdir(recovery_plugin_dir): shutil.copytree( os.path.join(repo_home, "server/cuberite_plugins", PLUGIN_NAME), recovery_plugin_dir) # Read logging.bin to get chunks available, and rewrite recovery plugin chunks = get_chunks_avail(old_workdir) chunks_lua = tuple_list_to_lua(chunks) with open(os.path.join(recovery_plugin_dir, "recover_initial.lua"), "r") as f: recovery_lua = f.read() recovery_lua = recovery_lua.replace("__CHUNKS_TO_LOAD__", chunks_lua) with open(os.path.join(recovery_plugin_dir, "recover_initial.lua"), "w") as f: f.write(recovery_lua) # Start craftassist_cuberite_utils and wait until the plugin kills it p = subprocess.Popen( [repo_home + "/server/craftassist_cuberite_utils/Server/Cuberite"], cwd=workdir) p.wait() # Return folder containing region files return os.path.join(workdir, "world/region")
def generate_place_blocks_plugin(workdir, place_blocks_yzx): # Generate place_blocks.lua plugin plugin_dir = workdir + "/Plugins/place_blocks" plugin_template = plugin_dir + "/place_blocks.lua.template" # Read plugin template with open(plugin_template, "r") as f: template = f.read() # Generate lua code if type(place_blocks_yzx) == list: dicts = place_blocks_yzx else: dicts = place_blocks.yzx_to_dicts(place_blocks_yzx) blocks_to_place = place_blocks.dicts_to_lua(dicts) out = template.replace("__BLOCKS_TO_PLACE__", blocks_to_place) # Write lua code with open(plugin_dir + "/place_blocks.lua", "w") as f: f.write(out) # Add place_blocks lua plugin to config edit_cuberite_config.add_plugin(workdir + "/settings.ini", "place_blocks")
def add_plugins(workdir, plugins): """Add plugins to cuberite's config""" for p in plugins: edit_cuberite_config.add_plugin(workdir + "/settings.ini", p)