package org.geysermc.connector.utils; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import org.geysermc.connector.GeyserConnector; import java.io.*; import java.util.function.Function; public class FileUtils { public static T loadConfig(File src, Class valueType) throws IOException { ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory()); return objectMapper.readValue(src, valueType); } public static File fileOrCopiedFromResource(String name, Function s) throws IOException { File file = new File(name); if (!file.exists()) { FileOutputStream fos = new FileOutputStream(file); InputStream input = GeyserConnector.class.getResourceAsStream("/" + name); // resources need leading "/" prefix byte[] bytes = new byte[input.available()]; input.read(bytes); for(char c : s.apply(new String(bytes)).toCharArray()) { fos.write(c); } fos.flush(); input.close(); fos.close(); } return file; } }