add method for direct invocation

This commit is contained in:
moehreag 2024-05-13 12:07:25 +02:00
parent 70117f8873
commit ff6ce3210b
2 changed files with 21 additions and 17 deletions

View file

@ -5,7 +5,7 @@ plugins {
} }
group = "org.ecorous.esnesnon" group = "org.ecorous.esnesnon"
version = "1.0-SNAPSHOT" version = "1.0.0-SNAPSHOT"
repositories { repositories {
mavenCentral() mavenCentral()

View file

@ -14,28 +14,17 @@ import java.nio.file.attribute.BasicFileAttributes;
public class MojMapPatcher { public class MojMapPatcher {
public static void main(String[] args) throws IOException { public static void run(String minecraftVersion, Path inputJar, Path outputJar) throws IOException {
// temporary
if (args.length != 3) {
System.err.println("Usage: [minecraft-version] [minecraft.jar] [out.jar]");
return;
}
String minecraftVersion = args[0];
String minecraftJar = args[1];
String outJar = args[2];
MappingData data = ProguardParser.read(MojmapProvider.get(minecraftVersion).orElseThrow()).reverse(); MappingData data = ProguardParser.read(MojmapProvider.get(minecraftVersion).orElseThrow()).reverse();
Mapper mapper = new Mapper(data); Mapper mapper = new Mapper(data);
Path out = Paths.get(outJar); if (!Files.exists(outputJar)){
if (!Files.exists(out)){ Files.createFile(outputJar);
Files.createFile(out);
} }
try (FileSystem inFs = FileSystems.newFileSystem(Paths.get(minecraftJar)); try (FileSystem inFs = FileSystems.newFileSystem(inputJar);
FileSystem outFs = FileSystems.newFileSystem(out)){ FileSystem outFs = FileSystems.newFileSystem(outputJar)){
Files.walkFileTree(inFs.getPath(""), new SimpleFileVisitor<>() { Files.walkFileTree(inFs.getPath(""), new SimpleFileVisitor<>() {
@Override @Override
public FileVisitResult visitFile(Path path, BasicFileAttributes basicFileAttributes) throws IOException { public FileVisitResult visitFile(Path path, BasicFileAttributes basicFileAttributes) throws IOException {
@ -57,4 +46,19 @@ public class MojMapPatcher {
}); });
} }
} }
public static void main(String[] args) throws IOException {
// temporary
if (args.length != 3) {
System.err.println("Usage: [minecraft-version] [minecraft.jar] [out.jar]");
return;
}
String minecraftVersion = args[0];
String minecraftJar = args[1];
String outJar = args[2];
run(minecraftVersion, Paths.get(minecraftJar), Paths.get(outJar));
}
} }