package io.gitlab.jfronny.respackopts.filters.util; import io.gitlab.jfronny.respackopts.Respackopts; import meteordevelopment.starscript.Script; import net.minecraft.resource.ResourcePack; import java.io.*; import java.util.Map; public class FileExpansionProvider { public static synchronized InputStream replace(InputStream is, Map expansions) throws IOException { String s = new String(is.readAllBytes()); for (Map.Entry entry : expansions.entrySet()) { s = s.replace("${" + entry.getKey() + "}", Respackopts.STAR_SCRIPT.run(entry.getValue())); } return new ByteArrayInputStream(s.getBytes()); } public static InputStream replace(InputStream inputStream, ResourcePack pack, String name) { return FileRpoSearchProvider.modifyWithRpo(name, pack, rpo -> { if (rpo.expansions == null || rpo.expansions.isEmpty()) return inputStream; try { return replace(inputStream, rpo.expansions); } catch (IOException e) { Respackopts.LOGGER.error("Could not perform file expansion on " + name, e); return inputStream; } }, inputStream); } }