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