9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-23 00:49:31 +00:00
Files
Leaf/leaf-api/paper-patches/features/0016-Configurable-LibraryLoader-maven-repos.patch
Dreeam f5b95a6716 Updated Upstream (Paper)
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
PaperMC/Paper@b0da38c2 Repository details in RuntimeException for MavenLibraryResolver#addRepository (#12939)
PaperMC/Paper@1922be90 Update custom tags (#12183)
PaperMC/Paper@79cf1353 Ignore HopperInventorySearchEvent when it has no listeners (#13009)
PaperMC/Paper@ea014f7a feat: add stuckEntityPoiRetryDelay config (#12949)
PaperMC/Paper@a9e76749 Support for showNotification in PlayerRecipeDiscoverEvent (#12992)
PaperMC/Paper@5622c9dd Expose attribute sentiment (#12974)
PaperMC/Paper@42b653b1 Expose more argument types (#12665)
PaperMC/Paper@52d9a221 [ci/skip] Fix typo in Display javadoc (#13010)
PaperMC/Paper@614e9acf Improve APIs around riptide tridents (#12996)
PaperMC/Paper@51706e5a Fixed DyeItem sheep dye hunk
2025-08-25 15:52:00 -04:00

104 lines
5.9 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
Date: Sat, 3 Feb 2024 18:45:53 -0500
Subject: [PATCH] Configurable LibraryLoader maven repos
Add JVM flag `-DLeaf.library-download-repo=link` to choose library download repo link.
e.g. `-DLeaf.library-download-repo=https://maven.aliyun.com/repository/public`
diff --git a/src/main/java/io/papermc/paper/plugin/loader/library/impl/MavenLibraryResolver.java b/src/main/java/io/papermc/paper/plugin/loader/library/impl/MavenLibraryResolver.java
index bb715d2ee5b0c548ac2d2d07bfaa2cb456794bb9..91fcd904bc01be3e05e64023e31ce08cc2a836c9 100644
--- a/src/main/java/io/papermc/paper/plugin/loader/library/impl/MavenLibraryResolver.java
+++ b/src/main/java/io/papermc/paper/plugin/loader/library/impl/MavenLibraryResolver.java
@@ -59,12 +59,25 @@ public class MavenLibraryResolver implements ClassPathLibrary {
* <p>This repository is also used by the legacy {@link org.bukkit.plugin.java.LibraryLoader}.</p>
*/
public static final String MAVEN_CENTRAL_DEFAULT_MIRROR = getDefaultMavenCentralMirror();
- private static final List<String> MAVEN_CENTRAL_URLS = List.of(
+ // Leaf start - Configurable LibraryLoader maven repos
+ @org.jspecify.annotations.Nullable
+ public static final RemoteRepository CUSTOM_MAVEN_CENTRAL_MIRROR_REPO = getCustomCentralMirrorRepo();
+ private static final String[] MAVEN_CENTRAL_URLS = new String[]{
"https://repo1.maven.org/maven2",
"http://repo1.maven.org/maven2",
"https://repo.maven.apache.org/maven2",
"http://repo.maven.apache.org/maven2"
- );
+ };
+ // From https://storage-download.googleapis.com/maven-central/index.html
+ private static final String[] MAVEN_CENTRAL_GOOGLE_MIRROR_URLS = new String[]{
+ "https://maven-central.storage-download.googleapis.com/maven2",
+ "http://maven-central.storage-download.googleapis.com/maven2",
+ "https://maven-central-eu.storage-download.googleapis.com/maven2",
+ "http://maven-central-eu.storage-download.googleapis.com/maven2",
+ "https://maven-central-asia.storage-download.googleapis.com/maven2",
+ "http://maven-central-asia.storage-download.googleapis.com/maven2"
+ };
+ // Leaf end - Configurable LibraryLoader maven repos
private static final Logger LOGGER = LoggerFactory.getLogger("MavenLibraryResolver");
private final RepositorySystem repository;
@@ -120,12 +133,33 @@ public class MavenLibraryResolver implements ClassPathLibrary {
* dependencies from
*/
public void addRepository(final RemoteRepository remoteRepository) {
- if (MAVEN_CENTRAL_URLS.stream().anyMatch(remoteRepository.getUrl()::startsWith)) {
+ // Leaf start - Configurable LibraryLoader maven repos
+ for (String url : MAVEN_CENTRAL_URLS) {
+ if (remoteRepository.getUrl().startsWith(url)) {
+ RemoteRepository mirrorRepo = CUSTOM_MAVEN_CENTRAL_MIRROR_REPO;
+ if (mirrorRepo != null) {
+ this.repositories.add(mirrorRepo);
+ return;
+ }
+ // Leaf end - Configurable LibraryLoader maven repos
LOGGER.warn(
"Use of Maven Central as a CDN is against the Maven Central Terms of Service. Use MavenLibraryResolver.MAVEN_CENTRAL_DEFAULT_MIRROR instead. DO NOT report this to Paper or Leaf! Please contact plugin's support to adapt this change.", // Leaf - Better warning message for discouraging Maven Central as CDN
new RuntimeException("Plugin used Maven Central for library resolution (%s)".formatted(remoteRepository.toString()))
);
+ // Leaf start - Configurable LibraryLoader maven repos
+ }
+ }
+ // Match google api maven central mirror urls
+ for (String url : MAVEN_CENTRAL_GOOGLE_MIRROR_URLS) {
+ if (remoteRepository.getUrl().startsWith(url)) {
+ RemoteRepository mirrorRepo = CUSTOM_MAVEN_CENTRAL_MIRROR_REPO;
+ if (mirrorRepo != null) {
+ this.repositories.add(mirrorRepo);
+ return;
+ }
+ }
}
+ // Leaf end - Configurable LibraryLoader maven repos
this.repositories.add(remoteRepository);
}
@@ -162,4 +196,15 @@ public class MavenLibraryResolver implements ClassPathLibrary {
}
return central;
}
+
+ // Leaf start - Configurable LibraryLoader maven repos
+ @org.jspecify.annotations.Nullable
+ private static RemoteRepository getCustomCentralMirrorRepo() {
+ String mirrorAddr = System.getProperty("Leaf.library-download-repo");
+ if (mirrorAddr != null) {
+ return new RemoteRepository.Builder("central", "default", mirrorAddr).build();
+ }
+ return null;
+ }
+ // Leaf end - Configurable LibraryLoader maven repos
}
diff --git a/src/main/java/org/bukkit/plugin/java/LibraryLoader.java b/src/main/java/org/bukkit/plugin/java/LibraryLoader.java
index 70d57e6abbd876d7f3087905d5277777162d317c..15992c275ae143af5b140a787f921658de58e05a 100644
--- a/src/main/java/org/bukkit/plugin/java/LibraryLoader.java
+++ b/src/main/java/org/bukkit/plugin/java/LibraryLoader.java
@@ -47,6 +47,7 @@ public class LibraryLoader {
public static java.util.function.Function<List<java.nio.file.Path>, List<java.nio.file.Path>> REMAPPER; // Paper - remap libraries
private static List<RemoteRepository> getRepositories() {
+ if (io.papermc.paper.plugin.loader.library.impl.MavenLibraryResolver.CUSTOM_MAVEN_CENTRAL_MIRROR_REPO != null) return List.of(io.papermc.paper.plugin.loader.library.impl.MavenLibraryResolver.CUSTOM_MAVEN_CENTRAL_MIRROR_REPO ); // Leaf - Configurable LibraryLoader maven repos
return List.of(new RemoteRepository.Builder("central", "default", MavenLibraryResolver.MAVEN_CENTRAL_DEFAULT_MIRROR).build());
}