3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-12-26 19:02:36 +01:00

Adding a try-catch for some edge scenario Fawe failing to grab Mojang assets

Dieser Commit ist enthalten in:
NotMyFault 2021-03-22 18:17:46 +01:00
Ursprung d224d6ea32
Commit 51487135bb
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 158F5701A6AAD00C

Datei anzeigen

@ -36,6 +36,7 @@ import java.net.URL;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.security.AccessControlException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
@ -353,19 +354,25 @@ public class TextureUtil implements TextureHolder {
public TextureUtil(File folder) throws FileNotFoundException { public TextureUtil(File folder) throws FileNotFoundException {
this.folder = folder; this.folder = folder;
if (!folder.exists()) { if (!folder.exists()) {
log.info("Downloading asset jar from Mojang, please wait..."); try {
new File(Fawe.imp().getDirectory() + "/" + Settings.IMP.PATHS.TEXTURES + "/" + "/.minecraft/versions/").mkdirs(); log.info("Downloading asset jar from Mojang, please wait...");
try (BufferedInputStream in = new BufferedInputStream(new URL("https://launcher.mojang.com/v1/objects/37fd3c903861eeff3bc24b71eed48f828b5269c8/client.jar").openStream()); new File(Fawe.imp().getDirectory() + "/" + Settings.IMP.PATHS.TEXTURES + "/" + "/.minecraft/versions/").mkdirs();
FileOutputStream fileOutputStream = new FileOutputStream(Fawe.imp().getDirectory() + "/" + Settings.IMP.PATHS.TEXTURES + "/" + "/.minecraft/versions/1.16.5.jar")) { try (BufferedInputStream in = new BufferedInputStream(new URL("https://launcher.mojang.com/v1/objects/37fd3c903861eeff3bc24b71eed48f828b5269c8/client.jar").openStream());
byte[] dataBuffer = new byte[1024]; FileOutputStream fileOutputStream = new FileOutputStream(Fawe.imp().getDirectory() + "/" + Settings.IMP.PATHS.TEXTURES + "/" + "/.minecraft/versions/1.16.5.jar")) {
int bytesRead; byte[] dataBuffer = new byte[1024];
while ((bytesRead = in.read(dataBuffer, 0, 1024)) != -1) { int bytesRead;
fileOutputStream.write(dataBuffer, 0, bytesRead); while ((bytesRead = in.read(dataBuffer, 0, 1024)) != -1) {
fileOutputStream.write(dataBuffer, 0, bytesRead);
}
log.info("Asset jar down has been downloaded successfully.");
} catch (IOException e) {
log.error("Could not download version jar. Please do so manually by creating a `FastAsyncWorldEdit/textures` folder with `.minecraft/versions` jar in it.");
log.error("If the file exists, please make sure the server has read access to the directory.");
} }
log.info("Asset jar down has been downloaded successfully."); } catch (AccessControlException e) {
} catch (IOException e) { log.error("Could not download asset jar. It's likely your file permission are setup improperly and do not allow fetching data from the Mojang servers.");
log.error("Could not download version jar. Please do so manually by creating a `FastAsyncWorldEdit/textures` folder with `.minecraft/versions` jar or mods in it."); log.error("Please create the following folder manually: `FastAsyncWorldEdit/textures` with `.minecraft/versions` jar in it.");
log.error("If the file exists, please make sure the server has read access to the directory.");
} }
} }
} }