[FIX] Paper installAuthlib

This commit is contained in:
Gravita 2022-10-17 00:47:24 +07:00
parent df04b459be
commit c74f430129
2 changed files with 30 additions and 0 deletions

View file

@ -20,6 +20,7 @@ public class InstallAuthlib {
modifierMap.put("META-INF/libraries.list", new LibrariesLstModifier());
modifierMap.put("patch.properties", new PatchPropertiesModifier());
modifierMap.put("META-INF/download-context", new DownloadContextModifier());
modifierMap.put("META-INF/patches.list", new PatchesLstModifier());
}
public void run(String... args) throws Exception {
boolean deleteAuthlibAfterInstall = false;

View file

@ -0,0 +1,29 @@
package pro.gravit.launcher.server.authlib;
import pro.gravit.utils.helper.LogHelper;
import pro.gravit.utils.helper.SecurityHelper;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
public class PatchesLstModifier implements LibrariesHashFileModifier {
@Override
public byte[] apply(byte[] data, InstallAuthlib.InstallAuthlibContext context) throws IOException {
String[] lines = new String(data).split("\n");
for(int i=0;i<lines.length;++i) {
if(lines[i].contains("paper-")) {
String[] separated = lines[i].split("\t");
Path path = context.workdir.resolve("versions").resolve(separated[6]);
if(Files.notExists(path)) {
LogHelper.warning("Unable to find %s. Maybe you should start the server at least once?", path);
return data;
}
separated[3] = SecurityHelper.toHex(SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA256, path));
lines[i] = String.join("\t", separated);
}
}
return String.join("\n", lines).getBytes(StandardCharsets.UTF_8);
}
}