Skip to content

Commit

Permalink
add jar in jar adventure loading
Browse files Browse the repository at this point in the history
  • Loading branch information
vectrixdevelops committed Sep 7, 2023
1 parent f018958 commit 40f2800
Show file tree
Hide file tree
Showing 27 changed files with 544 additions and 111 deletions.
7 changes: 2 additions & 5 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ val velocitySource by sourceSets.register("velocity") {
}

dependencies {
api(projects.extra.apolloExtraAdventure4)
api(project(":extra:apollo-extra-adventure4"))

api(libs.geantyref)

val bukkit = bukkitConfig.name
Expand Down Expand Up @@ -89,10 +90,6 @@ tasks {
source(sourceSets.map { it.allJava })
classpath += sourceSets.map { it.compileClasspath }.reduce { first, second -> first + second }
}

assemble {
dependsOn(shadowJar)
}
}

artifacts {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import java.util.regex.Pattern
import java.util.stream.Collectors

plugins {
java
`java-library`
id("checkstyle")
id("com.diffplug.spotless")
Expand Down
28 changes: 14 additions & 14 deletions build-logic/src/main/kotlin/apollo.parent-conventions.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ plugins {
id("org.jetbrains.gradle.plugin.idea-ext")
}

eclipse {
val shadowJar = tasks.getByPath(":apollo-api:shadowJar")
synchronizationTasks(shadowJar)
}

idea {
if(project != null) {
(project as ExtensionAware).extensions["settings"].run {
(this as ExtensionAware).extensions.getByType(org.jetbrains.gradle.ext.TaskTriggersConfig::class).run {
afterSync(":apollo-api:shadowJar")
}
}
}
}
//eclipse {
// val shadowJar = tasks.getByPath(":apollo-api:shadowJar")
// synchronizationTasks(shadowJar)
//}
//
//idea {
// if(project != null) {
// (project as ExtensionAware).extensions["settings"].run {
// (this as ExtensionAware).extensions.getByType(org.jetbrains.gradle.ext.TaskTriggersConfig::class).run {
// afterSync(":apollo-api:shadowJar")
// }
// }
// }
//}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@ tasks {
val shadowJar = named<ShadowJar>("shadowJar") {
archiveClassifier.set("")
configureRelocations()
configureExclusions()
}

assemble {
dependsOn(shadowJar)
}
}

fun ShadowJar.configureRelocations() {
relocate("com.google.protobuf", "com.lunarclient.apollo.libs.protobuf")
relocate("org.spongepowered.configurate", "com.lunarclient.apollo.libs.configurate")
}
85 changes: 85 additions & 0 deletions build-logic/src/main/kotlin/extensions.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.publish.PublishingExtension
Expand All @@ -9,6 +11,89 @@ fun JavaPluginExtension.javaTarget(version: Int) {
toolchain.languageVersion.set(JavaLanguageVersion.of(version))
}

fun ShadowJar.configureRelocations() {
relocate("com.google.protobuf", "com.lunarclient.apollo.libs.protobuf")
relocate("org.spongepowered.configurate", "com.lunarclient.apollo.libs.configurate")
}

fun ShadowJar.configureExclusions() {
exclude("META-INF/*.RSA", "META-INF/*.SF", "META-INF/*.DSA")
}

fun Project.setupDynamicLoader() {
extensions.configure<JavaPluginExtension> {
val loaderCompileOnlyConfig = configurations.register("loaderCompileOnly")
val loaderImplementationConfig = configurations.register("loaderImplementation")

val main by sourceSets

val loaderSource by sourceSets.register("platform-loader") {
configurations.named(this.compileOnlyConfigurationName) {
extendsFrom(loaderCompileOnlyConfig.get())
}

configurations.named(this.implementationConfigurationName) {
extendsFrom(loaderImplementationConfig.get())
}
}

configurations.named("compileOnly") {
extendsFrom(loaderCompileOnlyConfig.get())
extendsFrom(loaderImplementationConfig.get())
}

val shadowJar by tasks.named("shadowJar", ShadowJar::class) {
archiveClassifier.set("all")
}

val shadowJarLoader by tasks.creating(ShadowJar::class) {
archiveClassifier.set("")
configurations = listOf(loaderImplementationConfig.get())

dependsOn(shadowJar)

from(loaderSource.output)

into("platform/") {
from(shadowJar.outputs)
rename { "libs.jarinjar" }
}

configureExclusions()
}

tasks.named("assemble") {
dependsOn(shadowJarLoader)
}
}
}

fun Project.setupDynamicDependency(configurationName: String, shadowTaskName: String, jarPath: String, jarName: String) {
extensions.configure<JavaPluginExtension> {
val configuration = configurations.register(configurationName)

configurations.named("compileOnly") {
extendsFrom(configuration.get())
}

val shadowTask by tasks.register(shadowTaskName, ShadowJar::class) {
archiveClassifier.set("${configurationName}-all")
configurations = listOf(configuration.get())

configureExclusions()
}

tasks.named("shadowJarLoader", ShadowJar::class) {
dependsOn(shadowTask)

into(jarPath) {
from(shadowTask.outputs)
rename { "${jarName}.jarinjar" }
}
}
}
}

fun Project.publishJar() {
configurePublication {
from(components["java"])
Expand Down
6 changes: 2 additions & 4 deletions bukkit-example/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ plugins {
dependencies {
compileOnly(libs.bukkit.api)

compileOnlyApi(projects.extra.apolloExtraAdventure4)
compileOnlyApi(projects.apolloApi) {
targetConfiguration = "bukkit"
}
compileOnly(project(":extra:apollo-extra-adventure4"))
compileOnly(project(path = ":apollo-api", configuration = "bukkit"))
}
26 changes: 8 additions & 18 deletions bukkit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,18 @@ plugins {
id("apollo.shadow-conventions")
}

val adventure4Config = configurations.register("adventure4")
setupDynamicLoader()

setupDynamicDependency("adventure4", "shadowJarAdventure4", "adventure/4/", "libs")

dependencies {
compileOnly(libs.bukkit.api)
compileOnly(libs.bukkit)

val adventure4 = adventure4Config.name
adventure4(projects.extra.apolloExtraAdventure4)

api(projects.apolloApi) {
targetConfiguration = "shadow"
}

api(projects.apolloCommon)
}
api(project(path = ":apollo-api", configuration = "shadow"))
api(project(":apollo-common"))

tasks {
shadowJar {
from(sourceSets.main.get().output)
"loaderCompileOnly"(libs.bukkit.api)
"loaderImplementation"(project(":extra:apollo-extra-loader"))

into("adventure/4/") {
from(adventure4Config.get().resolve().map { zipTree(it) })
}
}
"adventure4"(project(":extra:apollo-extra-adventure4"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package com.lunarclient.apollo;

import com.google.protobuf.Any;
import com.lunarclient.apollo.loader.PlatformPlugin;
import com.lunarclient.apollo.module.ApolloModuleManagerImpl;
import com.lunarclient.apollo.module.beam.BeamModule;
import com.lunarclient.apollo.module.beam.BeamModuleImpl;
Expand Down Expand Up @@ -81,16 +82,28 @@
*
* @since 1.0.0
*/
public final class ApolloBukkitPlatform extends JavaPlugin implements ApolloPlatform, Listener {
public final class ApolloBukkitPlatform implements PlatformPlugin, ApolloPlatform, Listener {

@Getter private static ApolloBukkitPlatform instance;

@Getter private final JavaPlugin plugin;

/**
* Constructs a new {@link ApolloBukkitPlatform}.
*
* @param plugin the plugin instance
* @since 1.0.0
*/
public ApolloBukkitPlatform(JavaPlugin plugin) {
this.plugin = plugin;
}

@Override
public void onEnable() {
ApolloBukkitPlatform.instance = this;
ApolloManager.bootstrap(this);

this.getServer().getPluginManager().registerEvents(this, this);
this.plugin.getServer().getPluginManager().registerEvents(this, this.plugin);

((ApolloModuleManagerImpl) Apollo.getModuleManager())
.addModule(BeamModule.class, new BeamModuleImpl())
Expand All @@ -112,13 +125,13 @@ public void onEnable() {
.addModule(VignetteModule.class, new VignetteModuleImpl())
.addModule(WaypointModule.class, new WaypointModuleImpl());

ApolloManager.loadConfiguration(this.getDataFolder().toPath());
ApolloManager.loadConfiguration(this.plugin.getDataFolder().toPath());

((ApolloModuleManagerImpl) Apollo.getModuleManager()).enableModules();

Messenger messenger = this.getServer().getMessenger();
messenger.registerOutgoingPluginChannel(this, ApolloManager.PLUGIN_MESSAGE_CHANNEL);
messenger.registerIncomingPluginChannel(this, ApolloManager.PLUGIN_MESSAGE_CHANNEL,
Messenger messenger = this.plugin.getServer().getMessenger();
messenger.registerOutgoingPluginChannel(this.plugin, ApolloManager.PLUGIN_MESSAGE_CHANNEL);
messenger.registerIncomingPluginChannel(this.plugin, ApolloManager.PLUGIN_MESSAGE_CHANNEL,
(channel, player, bytes) -> this.handlePacket(player, bytes)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public final class TntCountdownModuleImpl extends TntCountdownModule implements

@Override
protected void onEnable() {
Bukkit.getPluginManager().registerEvents(this, ApolloBukkitPlatform.getInstance());
Bukkit.getPluginManager().registerEvents(this, ApolloBukkitPlatform.getInstance().getPlugin());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public boolean hasPermission(String permissionNode) {

@Override
public void sendPacket(byte[] messages) {
this.player.sendPluginMessage(ApolloBukkitPlatform.getInstance(), ApolloManager.PLUGIN_MESSAGE_CHANNEL, messages);
this.player.sendPluginMessage(ApolloBukkitPlatform.getInstance().getPlugin(), ApolloManager.PLUGIN_MESSAGE_CHANNEL, messages);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* This file is part of Apollo, licensed under the MIT License.
*
* Copyright (c) 2023 Moonsworth
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.lunarclient.apollo.loader;

import org.bukkit.plugin.java.JavaPlugin;

/**
* The bukkit loading plugin.
*
* @since 1.0.0
*/
public class BukkitPlatformLoader extends JavaPlugin {
private static final String PLUGIN_CLASS = "com.lunarclient.apollo.ApolloBukkitPlatform";

private final PlatformPlugin plugin;

/**
* Creates a new bukkit platform loader.
*
* @since 1.0.0
*/
public BukkitPlatformLoader() {
DynamicClassLoader classLoader = new DynamicClassLoader(
DynamicDependencies.discoverDependencies(),
this.getClass().getClassLoader()
);

this.plugin = classLoader.createPlugin(JavaPlugin.class, this, BukkitPlatformLoader.PLUGIN_CLASS);
}

@Override
public void onEnable() {
this.plugin.onEnable();
}

@Override
public void onDisable() {
this.plugin.onDisable();
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Apollo-Bukkit
main: com.lunarclient.apollo.ApolloBukkitPlatform
main: com.lunarclient.apollo.loader.BukkitPlatformLoader
version: 0.1.0-SNAPSHOT
author: Moonsworth
Loading

0 comments on commit 40f2800

Please sign in to comment.