Commits
md_5 authored 9d9ebf6ce53
239 239 | for ( File file : patchDir.listFiles() ) |
240 240 | { |
241 241 | String targetFile = "net/minecraft/server/" + file.getName().replaceAll( ".patch", ".java" ); |
242 242 | |
243 243 | File clean = new File( decompileDir, targetFile ); |
244 244 | File t = new File( nmsDir.getParentFile(), targetFile ); |
245 245 | t.getParentFile().mkdirs(); |
246 246 | |
247 247 | System.out.println( "Patching with " + file.getName() ); |
248 248 | |
249 - | Patch parsedPatch = DiffUtils.parseUnifiedDiff( Files.readLines( file, Charsets.UTF_8 ) ); |
249 + | List<String> readFile = Files.readLines( file, Charsets.UTF_8 ); |
250 + | |
251 + | // Manually append prelude if it is not found in the first few lines. |
252 + | boolean preludeFound = false; |
253 + | for ( int i = 0; i < Math.min( 3, readFile.size() ); i++ ) |
254 + | { |
255 + | if ( readFile.get( i ).startsWith( "+++" ) ) |
256 + | { |
257 + | preludeFound = true; |
258 + | break; |
259 + | } |
260 + | } |
261 + | if ( !preludeFound ) |
262 + | { |
263 + | readFile.add( 0, "+++" ); |
264 + | } |
265 + | |
266 + | Patch parsedPatch = DiffUtils.parseUnifiedDiff( readFile ); |
250 267 | List<?> modifiedLines = DiffUtils.patch( Files.readLines( clean, Charsets.UTF_8 ), parsedPatch ); |
251 268 | |
252 269 | BufferedWriter bw = new BufferedWriter( new FileWriter( t ) ); |
253 270 | for ( String line : (List<String>) modifiedLines ) |
254 271 | { |
255 272 | bw.write( line ); |
256 273 | bw.newLine(); |
257 274 | } |
258 275 | bw.close(); |
259 276 | } |