-
-
Notifications
You must be signed in to change notification settings - Fork 3
Velocity
Henri Schubin edited this page Jul 5, 2024
·
10 revisions
Since Velocity has exposed a API to append classes to the classpath, we don't need to have our own ClassLoader, and the setup is simple
plugins {
id 'java'
id 'com.github.johnrengelman.shadow' version '7.0.0'
+ id 'dev.vankka.dependencydownload.plugin' version 'VERSION'
}
repositories {
mavenCentral()
maven {
name = 'velocitypowered-repo'
url = 'https://repo.velocitypowered.com/releases/'
}
maven {
name = 'minecraft-libraries'
url = 'https://libraries.minecraft.net/'
}
maven {
name = 'spongepowered-repo'
url = 'https://repo.spongepowered.org/maven'
}
}
dependencies {
compileOnly 'com.velocitypowered:velocity-api:1.1.0'
annotationProcessor 'com.velocitypowered:velocity-api:1.1.0'
+ implementation 'dev.vankka:minecraftdependencydownload-velocity:VERSION'
}
jar {
+ dependsOn generateRuntimeDownloadResourceForRuntimeDownload
finalizedBy shadowJar
}
package com.example.velocity;
...
@Plugin(
id = "example-plugin",
name = "ExamplePlugin",
version = "1.0.0"
)
public class VelocityPlugin {
@Inject
private Logger logger;
@Inject
private ProxyServer proxyServer;
@Inject
@DataDirectory
private Path pluginDirectory;
@Subscribe
public void onProxyInitialization(ProxyInitializeEvent event) {
try {
DependencyManager manager = new DependencyManager(pluginDirectory.resolve("cache"));
manager.loadFromResource(getClass().getClassLoader().getResource("runtimeDownload.txt"));
Executor executor = Executors.newCachedThreadPool();
manager.downloadAll(executor, Collections.singletonList(new StandardRepository("https://repo.example.com/maven2"))).join();
manager.relocateAll(executor).join();
manager.loadAll(executor, new VelocityClasspathAppender(this, proxyServer)).join();
} catch (Throwable t) {
logger.error("Failed to load dependencies", t);
return;
}
}
}