Forge's maven repository has different directory structure.
This commit is contained in:
parent
29b1a450f3
commit
8d52ba70a5
|
@ -15,7 +15,7 @@ public abstract class PhantomEntity_AttackPlayerGoalMixin {
|
|||
@Shadow(aliases = {"this$0", "field_203141_a"}, remap = false) private PhantomEntity outerThis;
|
||||
|
||||
@SuppressWarnings("UnresolvedMixinReference")
|
||||
@Inject(method = "shouldExecute", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/monster/PhantomEntity;func_70624_b(Lnet/minecraft/entity/LivingEntity;)V"))
|
||||
@Inject(method = "shouldExecute", at = @At(value = "INVOKE", remap = false, target = "Lnet/minecraft/entity/monster/PhantomEntity;func_70624_b(Lnet/minecraft/entity/LivingEntity;)V"))
|
||||
private void arclight$reason(CallbackInfoReturnable<Boolean> cir) {
|
||||
((MobEntityBridge) outerThis).bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.CLOSEST_PLAYER, true);
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import java.net.HttpURLConnection;
|
|||
import java.net.SocketTimeoutException;
|
||||
import java.net.URL;
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.file.AccessDeniedException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
|
@ -64,6 +65,8 @@ public class FileDownloader implements Supplier<Path> {
|
|||
} else {
|
||||
throw LocalizedException.checked("downloader.not-found", url);
|
||||
}
|
||||
} catch (AccessDeniedException e) {
|
||||
throw LocalizedException.unchecked("downloader.access-denied", e.getFile(), e);
|
||||
} catch (Exception e) {
|
||||
Unsafe.throwException(e);
|
||||
return null;
|
||||
|
|
|
@ -22,8 +22,10 @@ import java.nio.file.FileSystems;
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
@ -56,7 +58,7 @@ public class ForgeInstaller {
|
|||
public static void install() throws Throwable {
|
||||
InputStream stream = ForgeInstaller.class.getResourceAsStream("/META-INF/installer.json");
|
||||
InstallInfo installInfo = new Gson().fromJson(new InputStreamReader(stream), InstallInfo.class);
|
||||
List<Supplier<Path>> suppliers = checkMaven(installInfo.libraries);
|
||||
List<Supplier<Path>> suppliers = checkMavenNoSource(installInfo.libraries);
|
||||
Path path = Paths.get(String.format("forge-%s-%s.jar", installInfo.installer.minecraft, installInfo.installer.forge));
|
||||
if (!suppliers.isEmpty() || !Files.exists(path)) {
|
||||
ArclightLocale.info("downloader.info");
|
||||
|
@ -68,6 +70,7 @@ public class ForgeInstaller {
|
|||
ArclightLocale.info("downloader.forge-install");
|
||||
ProcessBuilder builder = new ProcessBuilder();
|
||||
builder.command("java", "-jar", String.format("forge-%s-%s-installer.jar", installInfo.installer.minecraft, installInfo.installer.forge), "--installServer", ".");
|
||||
builder.inheritIO();
|
||||
Process process = builder.start();
|
||||
process.waitFor();
|
||||
}
|
||||
|
@ -91,7 +94,7 @@ public class ForgeInstaller {
|
|||
CompletableFuture<?> installerFuture = reportSupply(pool).apply(fd).thenAccept(path -> {
|
||||
try {
|
||||
FileSystem system = FileSystems.newFileSystem(path, null);
|
||||
Map<String, String> map = new HashMap<>();
|
||||
Map<String, Map.Entry<String, String>> map = new HashMap<>();
|
||||
Path profile = system.getPath("install_profile.json");
|
||||
map.putAll(profileLibraries(profile));
|
||||
Path version = system.getPath("version.json");
|
||||
|
@ -126,8 +129,8 @@ public class ForgeInstaller {
|
|||
}
|
||||
}
|
||||
|
||||
private static Map<String, String> profileLibraries(Path path) throws IOException {
|
||||
Map<String, String> ret = new HashMap<>();
|
||||
private static Map<String, Map.Entry<String, String>> profileLibraries(Path path) throws IOException {
|
||||
Map<String, Map.Entry<String, String>> ret = new HashMap<>();
|
||||
JsonArray array = new JsonParser().parse(Files.newBufferedReader(path)).getAsJsonObject().getAsJsonArray("libraries");
|
||||
for (JsonElement element : array) {
|
||||
String name = element.getAsJsonObject().get("name").getAsString();
|
||||
|
@ -135,27 +138,37 @@ public class ForgeInstaller {
|
|||
String hash = artifact.get("sha1").getAsString();
|
||||
String url = artifact.get("url").getAsString();
|
||||
if (url == null || url.trim().isEmpty()) continue;
|
||||
ret.put(name, hash);
|
||||
ret.put(name, new AbstractMap.SimpleImmutableEntry<>(hash, url));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
private static List<Supplier<Path>> checkMaven(Map<String, String> map) {
|
||||
List<Supplier<Path>> incomplete = new ArrayList<>();
|
||||
private static List<Supplier<Path>> checkMavenNoSource(Map<String, String> map) {
|
||||
LinkedHashMap<String, Map.Entry<String, String>> hashMap = new LinkedHashMap<>(map.size());
|
||||
for (Map.Entry<String, String> entry : map.entrySet()) {
|
||||
hashMap.put(entry.getKey(), new AbstractMap.SimpleImmutableEntry<>(entry.getValue(), null));
|
||||
}
|
||||
return checkMaven(hashMap);
|
||||
}
|
||||
|
||||
private static List<Supplier<Path>> checkMaven(Map<String, Map.Entry<String, String>> map) {
|
||||
List<Supplier<Path>> incomplete = new ArrayList<>();
|
||||
for (Map.Entry<String, Map.Entry<String, String>> entry : map.entrySet()) {
|
||||
String maven = entry.getKey();
|
||||
String hash = entry.getValue().getKey();
|
||||
String url = entry.getValue().getValue();
|
||||
String path = "libraries/" + Util.mavenToPath(maven);
|
||||
if (new File(path).exists()) {
|
||||
try {
|
||||
String hash = Util.hash(path);
|
||||
if (!hash.equals(entry.getValue())) {
|
||||
incomplete.add(new MavenDownloader(MAVEN_REPO, maven, path, entry.getValue()));
|
||||
String fileHash = Util.hash(path);
|
||||
if (!fileHash.equals(hash)) {
|
||||
incomplete.add(new MavenDownloader(MAVEN_REPO, maven, path, hash, url));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
incomplete.add(new MavenDownloader(MAVEN_REPO, maven, path, entry.getValue()));
|
||||
incomplete.add(new MavenDownloader(MAVEN_REPO, maven, path, hash, url));
|
||||
}
|
||||
} else {
|
||||
incomplete.add(new MavenDownloader(MAVEN_REPO, maven, path, entry.getValue()));
|
||||
incomplete.add(new MavenDownloader(MAVEN_REPO, maven, path, hash, url));
|
||||
}
|
||||
}
|
||||
return incomplete;
|
||||
|
|
|
@ -5,31 +5,47 @@ import io.izzel.arclight.i18n.LocalizedException;
|
|||
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class MavenDownloader implements Supplier<Path> {
|
||||
|
||||
private final String[] repos;
|
||||
private static final Function<String, String> FORGE_TO_BMCLAPI =
|
||||
s -> s.replace("https://files.minecraftforge.net/maven/", "https://bmclapi2.bangbang93.com/maven/");
|
||||
|
||||
private final LinkedList<String> urls;
|
||||
private final String coord;
|
||||
private final String target;
|
||||
private final String hash;
|
||||
|
||||
public MavenDownloader(String[] repos, String coord, String target, String hash) {
|
||||
this.repos = repos;
|
||||
this.urls = new LinkedList<>();
|
||||
this.coord = coord;
|
||||
this.target = target;
|
||||
this.hash = hash;
|
||||
String path = Util.mavenToPath(coord);
|
||||
for (String repo : repos) {
|
||||
this.urls.add(repo + path);
|
||||
}
|
||||
}
|
||||
|
||||
public MavenDownloader(String[] repos, String coord, String target, String hash, String sourceUrl) {
|
||||
this(repos, coord, target, hash);
|
||||
if (sourceUrl != null && !this.urls.contains(sourceUrl)) {
|
||||
this.urls.addFirst(sourceUrl);
|
||||
this.urls.addFirst(FORGE_TO_BMCLAPI.apply(sourceUrl));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path get() {
|
||||
String path = Util.mavenToPath(coord);
|
||||
List<Exception> exceptions = new ArrayList<>();
|
||||
for (String repo : repos) {
|
||||
for (String url : this.urls) {
|
||||
try {
|
||||
return new FileDownloader(repo + path, target, hash).get();
|
||||
return new FileDownloader(url, target, hash).get();
|
||||
} catch (Exception e) {
|
||||
exceptions.add(e);
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ downloader {
|
|||
maven-fail = "{0} failed to download: {1}"
|
||||
complete = "{0} complete"
|
||||
forge-install = "Forge installation is starting, please wait... "
|
||||
access-denied = "Access denied for file {0}: {1}"
|
||||
}
|
||||
|
||||
i18n {
|
||||
|
|
|
@ -27,6 +27,7 @@ downloader {
|
|||
maven-fail = "{0} 下载失败 {1}"
|
||||
complete = "{0} 下载完成"
|
||||
forge-install = "即将开始 Forge 安装,请等待一段时间"
|
||||
access-denied = "没有对 {0} 操作的权限: {1}"
|
||||
}
|
||||
|
||||
i18n {
|
||||
|
|
Loading…
Reference in New Issue
Block a user