-
-
Notifications
You must be signed in to change notification settings - Fork 2
Bungee
Henri Schubin edited this page Jul 5, 2024
·
6 revisions
Due to Bungee not exposing a way to load dependencies in during runtime, we need to have our own ClassLoader load them in, for that we'll need that ClassLoader to load in our plugin's code (that's going to use those dependencies) as well.
This guide is for Gradle, that is also the only way to use the DependencyDownload metadata generation plugin
plugins {
id 'java'
id 'com.github.johnrengerlman.shadow' version '7.0.0'
}
repositories {
mavenCentral()
maven {
url 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/'
}
maven {
url = 'https://oss.sonatype.org/content/groups/public/'
}
}
dependencies {
compileOnly 'net.md-5:bungeecord-api:1.16-R0.4'
+ implementation 'dev.vankka:minecraftdependencydownload-bungee-loader:VERSION'
}
jar {
finalizedBy shadowJar
}
shadowJar {
+ from {
+ findProject(':bungee').tasks.shadowJar.archiveFile
+ }
}
If the main part of the plugin is the root project, you can use rootProject
instead of findProject(':bungee')
package com.example.bungee.loader;
...
-public class BungeeLoader extends Plugin {
+public class BungeeLoader extends dev.vankka.mcruntimedependencydownload.bungee.loader.BungeeLoader {
+ @Override
+ public String getBootstrapClassName() {
+ return "com.example.bungee.bootstrap.BungeeBootstrap";
+ }
+ @Override
+ public URL getJarInJarResource() {
+ return getClassLoader().getResource("bungee.jarinjar");
+ }
- @Override
- public void onEnable() {
- // plugin enable logic
- }
}
name: ExamplePlugin
version: 1.0
+main: com.example.bungee.loader.BungeeLoader
plugins {
id 'java'
id 'com.github.johnrengerlman.shadow' version '7.0.0'
+ id 'dev.vankka.dependencydownload.plugin' version 'VERSION'
}
repositories {
mavenCentral()
maven {
url 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/'
}
maven {
url = 'https://oss.sonatype.org/content/groups/public/'
}
}
dependencies {
compileOnly 'net.md-5:bungeecord-api:1.16-R0.4'
+ implementation 'dev.vankka:minecraftdependencydownload-bungee:VERSION'
}
jar {
+ dependsOn generateRuntimeDownloadResourceForRuntimeDownload
finalizedBy shadowJar
}
shadowJar {
+ archiveFileName = 'bungee.jarinjar'
}
package com.example.bungee.bootstrap;
...
public class BungeeBootstrap extends dev.vankka.mcruntimedependencydownload.bungee.bootstrap.BungeeBootstrap {
// Do not change the parameters on this constructor
public BungeeBootstrap(JarInJarClassLoader classLoader, Plugin plugin) {
super(classLoader, plugin);
}
@Override
public void onLoad() {
// Download dependencies from the file generated by the gradle plugin
try {
Executor executor = Executors.newCachedThreadPool();
DependencyManager manager = new DependencyManager(new File(getPlugin().getDataFolder(), "cache").toPath());
dependencyManager.loadFromResource(getClassLoader().getResource("runtimeDownload.txt"));
dependencyManager.downloadAll(executor, Collections.singletonList(new StandardRepository("https://repo.example.com/maven2"))).join();
dependencyManager.relocateAll(executor).join();
dependencyManager.loadAll(executor, getClasspathAppender()).join();
} catch (Throwable t) {
getPlugin().getLogger().severe("Failed to load dependencies");
e.printStackTrace();
}
}
@Override
public void onEnable() {
// plugin enable logic
}
}