9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2025-12-19 15:09:24 +00:00
This commit is contained in:
XiaoMoMi
2024-02-20 04:26:41 +08:00
parent 93066daced
commit 05d36445b4
4 changed files with 100 additions and 60 deletions

View File

@@ -7,7 +7,7 @@ plugins {
allprojects { allprojects {
version = "2.1.0" version = "2.1.0.1"
apply<JavaPlugin>() apply<JavaPlugin>()
apply(plugin = "java") apply(plugin = "java")

View File

@@ -106,7 +106,10 @@ public class CustomFishingPluginImpl extends CustomFishingPlugin {
Dependency.SQLITE_DRIVER, Dependency.SQLITE_DRIVER,
Dependency.BSTATS_BASE, Dependency.BSTATS_BASE,
Dependency.HIKARI, Dependency.HIKARI,
Dependency.BSTATS_BUKKIT Dependency.BSTATS_BUKKIT,
Dependency.INV_UI,
Dependency.INV_UI_ACCESS,
Dependency.INV_UI_NMS
) )
)); ));
} }
@@ -232,50 +235,6 @@ public class CustomFishingPluginImpl extends CustomFishingPlugin {
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
} }
/**
* Load plugin dependencies
*/
private void loadDependencies() {
// String mavenRepo = TimeZone.getDefault().getID().startsWith("Asia") ?
// "https://maven.aliyun.com/repository/public/" : "https://repo.maven.apache.org/maven2/";
// LibraryLoader.loadDependencies(
// "org.apache.commons:commons-pool2:2.12.0", mavenRepo,
// "redis.clients:jedis:5.1.0", mavenRepo,
// "dev.dejvokep:boosted-yaml:1.3.2", mavenRepo,
// "com.zaxxer:HikariCP:5.0.1", mavenRepo,
// "net.objecthunter:exp4j:0.4.8", mavenRepo,
// "org.mariadb.jdbc:mariadb-java-client:3.3.2", mavenRepo,
// "com.mysql:mysql-connector-j:8.3.0", mavenRepo,
// "commons-io:commons-io:2.14.0", mavenRepo,
// "com.google.code.gson:gson:2.10.1", mavenRepo,
// "com.h2database:h2:2.2.224", mavenRepo,
// "org.mongodb:mongodb-driver-sync:4.11.1", mavenRepo,
// "org.mongodb:mongodb-driver-core:4.11.1", mavenRepo,
// "org.mongodb:bson:4.11.1", mavenRepo,
// "org.xerial:sqlite-jdbc:3.45.1.0", mavenRepo,
// "dev.jorel:commandapi-bukkit-shade:9.3.0", mavenRepo
// );
// String version = getServer().getClass().getPackage().getName().split("\\.")[3];
// String artifact = "";
// switch (version) {
// case "v1_17_R1" -> artifact = "r9";
// case "v1_18_R1" -> artifact = "r10";
// case "v1_18_R2" -> artifact = "r11";
// case "v1_19_R1" -> artifact = "r12";
// case "v1_19_R2" -> artifact = "r13";
// case "v1_19_R3" -> artifact = "r15";
// case "v1_20_R1" -> artifact = "r16";
// case "v1_20_R2" -> artifact = "r17";
// case "v1_20_R3" -> artifact = "r18";
// }
// LibraryLoader.loadDependencies(
// "xyz.xenondevs.invui:invui-core:1.25", "https://repo.xenondevs.xyz/releases/",
// "xyz.xenondevs.invui:inventory-access:1.25", "https://repo.xenondevs.xyz/releases/",
// String.format("xyz.xenondevs.invui:inventory-access-%s:1.25", artifact), "https://repo.xenondevs.xyz/releases/"
// );
}
/** /**
* Disable NBT API logs * Disable NBT API logs
*/ */

View File

@@ -26,7 +26,9 @@
package net.momirealms.customfishing.libraries.dependencies; package net.momirealms.customfishing.libraries.dependencies;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import net.momirealms.customfishing.api.CustomFishingPlugin;
import net.momirealms.customfishing.libraries.dependencies.relocation.Relocation; import net.momirealms.customfishing.libraries.dependencies.relocation.Relocation;
import org.bukkit.Bukkit;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.security.MessageDigest; import java.security.MessageDigest;
@@ -43,25 +45,29 @@ public enum Dependency {
"org.ow2.asm", "org.ow2.asm",
"asm", "asm",
"9.1", "9.1",
null null,
"asm"
), ),
ASM_COMMONS( ASM_COMMONS(
"org.ow2.asm", "org.ow2.asm",
"asm-commons", "asm-commons",
"9.1", "9.1",
null null,
"asm-commons"
), ),
JAR_RELOCATOR( JAR_RELOCATOR(
"me.lucko", "me.lucko",
"jar-relocator", "jar-relocator",
"1.7", "1.7",
null null,
"jar-relocator"
), ),
KYORI_OPTION( KYORI_OPTION(
"net{}kyori", "net{}kyori",
"option", "option",
"1.0.0", "1.0.0",
null, null,
"kyori-option",
Relocation.of("option", "net{}kyori{}option") Relocation.of("option", "net{}kyori{}option")
), ),
ADVENTURE_API( ADVENTURE_API(
@@ -69,6 +75,7 @@ public enum Dependency {
"adventure-api", "adventure-api",
"4.15.0", "4.15.0",
null, null,
"adventure-api",
Relocation.of("adventure", "net{}kyori{}adventure") Relocation.of("adventure", "net{}kyori{}adventure")
), ),
ADVENTURE_KEY( ADVENTURE_KEY(
@@ -76,6 +83,7 @@ public enum Dependency {
"adventure-key", "adventure-key",
"4.15.0", "4.15.0",
null, null,
"adventure-key",
Relocation.of("adventure", "net{}kyori{}adventure") Relocation.of("adventure", "net{}kyori{}adventure")
), ),
ADVENTURE_NBT( ADVENTURE_NBT(
@@ -83,6 +91,7 @@ public enum Dependency {
"adventure-nbt", "adventure-nbt",
"4.15.0", "4.15.0",
null, null,
"adventure-nbt",
Relocation.of("adventure", "net{}kyori{}adventure") Relocation.of("adventure", "net{}kyori{}adventure")
), ),
ADVENTURE_LEGACY_SERIALIZER( ADVENTURE_LEGACY_SERIALIZER(
@@ -90,6 +99,7 @@ public enum Dependency {
"adventure-text-serializer-legacy", "adventure-text-serializer-legacy",
"4.15.0", "4.15.0",
null, null,
"adventure-text-serializer-legacy",
Relocation.of("adventure", "net{}kyori{}adventure") Relocation.of("adventure", "net{}kyori{}adventure")
), ),
ADVENTURE_TEXT_LOGGER( ADVENTURE_TEXT_LOGGER(
@@ -97,6 +107,7 @@ public enum Dependency {
"adventure-text-logger-slf4j", "adventure-text-logger-slf4j",
"4.15.0", "4.15.0",
null, null,
"adventure-text-logger-slf4j",
Relocation.of("adventure", "net{}kyori{}adventure") Relocation.of("adventure", "net{}kyori{}adventure")
), ),
ADVENTURE_GSON( ADVENTURE_GSON(
@@ -104,6 +115,7 @@ public enum Dependency {
"adventure-text-serializer-gson", "adventure-text-serializer-gson",
"4.15.0", "4.15.0",
null, null,
"adventure-text-serializer-gson",
Relocation.of("adventure", "net{}kyori{}adventure") Relocation.of("adventure", "net{}kyori{}adventure")
), ),
ADVENTURE_GSON_LEGACY( ADVENTURE_GSON_LEGACY(
@@ -111,6 +123,7 @@ public enum Dependency {
"adventure-text-serializer-gson-legacy-impl", "adventure-text-serializer-gson-legacy-impl",
"4.15.0", "4.15.0",
null, null,
"adventure-text-serializer-gson-legacy-impl",
Relocation.of("adventure", "net{}kyori{}adventure") Relocation.of("adventure", "net{}kyori{}adventure")
), ),
ADVENTURE_PLATFORM( ADVENTURE_PLATFORM(
@@ -118,6 +131,7 @@ public enum Dependency {
"adventure-platform-api", "adventure-platform-api",
"4.3.2", "4.3.2",
null, null,
"adventure-platform-api",
Relocation.of("adventure", "net{}kyori{}adventure") Relocation.of("adventure", "net{}kyori{}adventure")
), ),
ADVENTURE_PLATFORM_BUKKIT( ADVENTURE_PLATFORM_BUKKIT(
@@ -125,6 +139,7 @@ public enum Dependency {
"adventure-platform-bukkit", "adventure-platform-bukkit",
"4.3.2", "4.3.2",
null, null,
"adventure-platform-bukkit",
Relocation.of("adventure", "net{}kyori{}adventure") Relocation.of("adventure", "net{}kyori{}adventure")
), ),
ADVENTURE_PLATFORM_FACET( ADVENTURE_PLATFORM_FACET(
@@ -132,6 +147,7 @@ public enum Dependency {
"adventure-platform-facet", "adventure-platform-facet",
"4.3.2", "4.3.2",
null, null,
"adventure-platform-facet",
Relocation.of("adventure", "net{}kyori{}adventure") Relocation.of("adventure", "net{}kyori{}adventure")
), ),
ADVENTURE_TEXT_MINIMESSAGE( ADVENTURE_TEXT_MINIMESSAGE(
@@ -139,6 +155,7 @@ public enum Dependency {
"adventure-text-minimessage", "adventure-text-minimessage",
"4.15.0", "4.15.0",
null, null,
"adventure-text-minimessage",
Relocation.of("adventure", "net{}kyori{}adventure") Relocation.of("adventure", "net{}kyori{}adventure")
), ),
COMMAND_API( COMMAND_API(
@@ -146,6 +163,7 @@ public enum Dependency {
"commandapi-bukkit-shade", "commandapi-bukkit-shade",
"9.3.0", "9.3.0",
null, null,
"commandapi-bukkit",
Relocation.of("commandapi", "dev{}jorel{}commandapi") Relocation.of("commandapi", "dev{}jorel{}commandapi")
), ),
MARIADB_DRIVER( MARIADB_DRIVER(
@@ -153,6 +171,7 @@ public enum Dependency {
"mariadb-java-client", "mariadb-java-client",
"3.3.2", "3.3.2",
null, null,
"mariadb-java-client",
Relocation.of("mariadb", "org{}mariadb") Relocation.of("mariadb", "org{}mariadb")
), ),
BOOSTED_YAML( BOOSTED_YAML(
@@ -160,6 +179,7 @@ public enum Dependency {
"boosted-yaml", "boosted-yaml",
"1.3.2", "1.3.2",
null, null,
"boosted-yaml",
Relocation.of("boostedyaml", "dev{}dejvokep{}boostedyaml") Relocation.of("boostedyaml", "dev{}dejvokep{}boostedyaml")
), ),
NBT_API( NBT_API(
@@ -167,6 +187,7 @@ public enum Dependency {
"item-nbt-api", "item-nbt-api",
"2.12.2", "2.12.2",
"codemc", "codemc",
"item-nbt-api",
Relocation.of("changeme", "de{}tr7zw{}changeme") Relocation.of("changeme", "de{}tr7zw{}changeme")
), ),
EXP4J( EXP4J(
@@ -174,6 +195,7 @@ public enum Dependency {
"exp4j", "exp4j",
"0.4.8", "0.4.8",
null, null,
"exp4j",
Relocation.of("exp4j", "net{}objecthunter{}exp4j") Relocation.of("exp4j", "net{}objecthunter{}exp4j")
), ),
MYSQL_DRIVER( MYSQL_DRIVER(
@@ -181,44 +203,51 @@ public enum Dependency {
"mysql-connector-j", "mysql-connector-j",
"8.3.0", "8.3.0",
null, null,
"mysql-connector-j",
Relocation.of("mysql", "com{}mysql") Relocation.of("mysql", "com{}mysql")
), ),
H2_DRIVER( H2_DRIVER(
"com.h2database", "com.h2database",
"h2", "h2",
"2.2.224", "2.2.224",
null null,
"h2database"
), ),
SQLITE_DRIVER( SQLITE_DRIVER(
"org.xerial", "org.xerial",
"sqlite-jdbc", "sqlite-jdbc",
"3.45.1.0", "3.45.1.0",
null null,
"sqlite-jdbc"
), ),
HIKARI( HIKARI(
"com{}zaxxer", "com{}zaxxer",
"HikariCP", "HikariCP",
"5.0.1", "5.0.1",
null, null,
"HikariCP",
Relocation.of("hikari", "com{}zaxxer{}hikari") Relocation.of("hikari", "com{}zaxxer{}hikari")
), ),
SLF4J_SIMPLE( SLF4J_SIMPLE(
"org.slf4j", "org.slf4j",
"slf4j-simple", "slf4j-simple",
"2.0.12", "2.0.12",
null null,
"slf4j-simple"
), ),
SLF4J_API( SLF4J_API(
"org.slf4j", "org.slf4j",
"slf4j-api", "slf4j-api",
"2.0.12", "2.0.12",
null null,
"slf4j-api"
), ),
MONGODB_DRIVER_CORE( MONGODB_DRIVER_CORE(
"org{}mongodb", "org{}mongodb",
"mongodb-driver-core", "mongodb-driver-core",
"4.11.1", "4.11.1",
null, null,
"mongodb-driver-core",
Relocation.of("mongodb", "com{}mongodb"), Relocation.of("mongodb", "com{}mongodb"),
Relocation.of("bson", "org{}bson") Relocation.of("bson", "org{}bson")
), ),
@@ -227,6 +256,7 @@ public enum Dependency {
"mongodb-driver-sync", "mongodb-driver-sync",
"4.11.1", "4.11.1",
null, null,
"mongodb-driver-sync",
Relocation.of("mongodb", "com{}mongodb"), Relocation.of("mongodb", "com{}mongodb"),
Relocation.of("bson", "org{}bson") Relocation.of("bson", "org{}bson")
), ),
@@ -235,6 +265,7 @@ public enum Dependency {
"bson", "bson",
"4.11.1", "4.11.1",
null, null,
"mongodb-bson",
Relocation.of("mongodb", "com{}mongodb"), Relocation.of("mongodb", "com{}mongodb"),
Relocation.of("bson", "org{}bson") Relocation.of("bson", "org{}bson")
), ),
@@ -243,6 +274,7 @@ public enum Dependency {
"jedis", "jedis",
"5.1.0", "5.1.0",
null, null,
"jedis",
Relocation.of("jedis", "redis{}clients{}jedis"), Relocation.of("jedis", "redis{}clients{}jedis"),
Relocation.of("commonspool2", "org{}apache{}commons{}pool2") Relocation.of("commonspool2", "org{}apache{}commons{}pool2")
), ),
@@ -251,6 +283,7 @@ public enum Dependency {
"bstats-base", "bstats-base",
"3.0.2", "3.0.2",
null, null,
"bstats-base",
Relocation.of("bstats", "org{}bstats") Relocation.of("bstats", "org{}bstats")
), ),
BSTATS_BUKKIT( BSTATS_BUKKIT(
@@ -258,34 +291,59 @@ public enum Dependency {
"bstats-bukkit", "bstats-bukkit",
"3.0.2", "3.0.2",
null, null,
"bstats-bukkit",
Relocation.of("bstats", "org{}bstats") Relocation.of("bstats", "org{}bstats")
), ),
COMMONS_POOL_2( COMMONS_POOL_2(
"org.apache.commons", "org{}apache{}commons",
"commons-pool2", "commons-pool2",
"2.11.0", "2.11.0",
null, null,
"commons-pool2",
Relocation.of("commonspool2", "org{}apache{}commons{}pool2") Relocation.of("commonspool2", "org{}apache{}commons{}pool2")
), ),
INV_UI(
"xyz{}xenondevs{}invui",
"invui-core",
"1.25",
"xenondevs",
"invui-core"
),
INV_UI_ACCESS(
"xyz{}xenondevs{}invui",
"inventory-access",
"1.25",
"xenondevs",
"inventory-access"
),
INV_UI_NMS(
"xyz{}xenondevs{}invui",
getInvUINms(),
"1.25",
"xenondevs",
getInvUINms()
),
GSON( GSON(
"com.google.code.gson", "com.google.code.gson",
"gson", "gson",
"2.10.1", "2.10.1",
null null,
"gson"
),; ),;
private final String mavenRepoPath; private final String mavenRepoPath;
private final String version; private final String version;
private final List<Relocation> relocations; private final List<Relocation> relocations;
private final String repo; private final String repo;
private final String artifact;
private static final String MAVEN_FORMAT = "%s/%s/%s/%s-%s.jar"; private static final String MAVEN_FORMAT = "%s/%s/%s/%s-%s.jar";
Dependency(String groupId, String artifactId, String version, String repo) { Dependency(String groupId, String artifactId, String version, String repo, String artifact) {
this(groupId, artifactId, version, repo, new Relocation[0]); this(groupId, artifactId, version, repo, artifact, new Relocation[0]);
} }
Dependency(String groupId, String artifactId, String version, String repo, Relocation... relocations) { Dependency(String groupId, String artifactId, String version, String repo, String artifact, Relocation... relocations) {
this.mavenRepoPath = String.format(MAVEN_FORMAT, this.mavenRepoPath = String.format(MAVEN_FORMAT,
rewriteEscaping(groupId).replace(".", "/"), rewriteEscaping(groupId).replace(".", "/"),
rewriteEscaping(artifactId), rewriteEscaping(artifactId),
@@ -296,6 +354,7 @@ public enum Dependency {
this.version = version; this.version = version;
this.relocations = ImmutableList.copyOf(relocations); this.relocations = ImmutableList.copyOf(relocations);
this.repo = repo; this.repo = repo;
this.artifact = artifact;
} }
private static String rewriteEscaping(String s) { private static String rewriteEscaping(String s) {
@@ -303,7 +362,7 @@ public enum Dependency {
} }
public String getFileName(String classifier) { public String getFileName(String classifier) {
String name = name().toLowerCase(Locale.ROOT).replace('_', '-'); String name = artifact.toLowerCase(Locale.ROOT).replace('_', '-');
String extra = classifier == null || classifier.isEmpty() String extra = classifier == null || classifier.isEmpty()
? "" ? ""
: "-" + classifier; : "-" + classifier;
@@ -337,4 +396,22 @@ public enum Dependency {
public String getRepo() { public String getRepo() {
return repo; return repo;
} }
private static String getInvUINms() {
String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
String artifact;
switch (version) {
case "v1_17_R1" -> artifact = "r9";
case "v1_18_R1" -> artifact = "r10";
case "v1_18_R2" -> artifact = "r11";
case "v1_19_R1" -> artifact = "r12";
case "v1_19_R2" -> artifact = "r13";
case "v1_19_R3" -> artifact = "r15";
case "v1_20_R1" -> artifact = "r16";
case "v1_20_R2" -> artifact = "r17";
case "v1_20_R3" -> artifact = "r18";
default -> artifact = "r18";
}
return String.format("inventory-access-%s", artifact);
}
} }

View File

@@ -57,7 +57,11 @@ public enum DependencyRepository {
/** /**
* Code MC * Code MC
*/ */
CODE_MC("codemc", "https://repo.codemc.io/repository/maven-public/"); CODE_MC("codemc", "https://repo.codemc.io/repository/maven-public/"),
/**
* xenondevs
*/
XENONDEVS("xenondevs", "https://repo.xenondevs.xyz/releases/");
private final String url; private final String url;
private final String id; private final String id;