Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/ISSUE_TEMPLATE/bug-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ body:
- type: markdown
attributes:
value: |
Thanks for taking the time to report this issue, if you want to request a feature join our [Discord](https://discord.gg/3T9Atyb6pf).
Thanks for taking the time to report this issue, if you want to request a feature join our [Discord](https://lunarclient.dev/discord).

# Checklist
- type: checkboxes
Expand Down Expand Up @@ -94,6 +94,7 @@ body:
multiple: true
options:
- Spigot / Bukkit
- Folia
- BungeeCord
- Velocity
- Other
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
blank_issues_enabled: false
contact_links:
- name: ❓ Questions & Feature Request
url: https://discord.gg/3T9Atyb6pf
url: https://lunarclient.dev/discord
about: Join our Discord to ask questions and request features for Apollo.
- name: 📄 Documentation
url: https://lunarclient.dev/apollo/introduction
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,4 @@ jobs:
bukkit/build/libs/apollo-bukkit-${{ env.VERSION }}.jar
bungee/build/libs/apollo-bungee-${{ env.VERSION }}.jar
velocity/build/libs/apollo-velocity-${{ env.VERSION }}.jar
folia/build/libs/apollo-folia-${{ env.VERSION }}.jar
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Apollo
[![Discord](https://img.shields.io/discord/1080556677004271666?logo=discord&label=discord)](https://discord.gg/3T9Atyb6pf)
[![Discord](https://img.shields.io/discord/1080556677004271666?logo=discord&label=discord)](https://lunarclient.dev/discord)

Apollo is a powerful tool that allows developers to create custom integrations with Lunar Client.

Expand Down Expand Up @@ -27,6 +27,7 @@ Running the following will compile the Apollo source for Java 8.
The output jars can be found in the `build/libs` directory relative to each platform.

- Bukkit: `bukkit/plugin/build/libs`
- Folia: `folia/build/libs`
- BungeeCord: `bungee/build/libs`
- Velocity: `velocity/build/libs`

Expand All @@ -41,10 +42,10 @@ The Apollo project is split into several modules.

- **API** - The publicly available interface for developers wishing to create custom integrations with Lunar Client.
- **Common** - The abstraction used by platform modules to reduce duplicate code and implement the protocol for Lunar Client.
- **Bukkit, BungeeCord, Velocity** - Are modules that implement the common module for each respective platform.
- **Bukkit, Folia, BungeeCord, Velocity** - Are modules that implement the common module for each respective platform.

Contributions can be made to Apollo by creating a pull request for improvements or fixes. For new feature ideas please consider making a
suggestion by creating an [issue](https://github.com/LunarClient/Apollo/issues) or joining our [discord](https://discord.gg/3T9Atyb6pf).
suggestion by creating an [issue](https://github.com/LunarClient/Apollo/issues) or joining our [discord](https://lunarclient.dev/discord).

## License

Expand Down
4 changes: 4 additions & 0 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ setupPlatforms()
setupPlatformDependency("bukkit", "bukkitJar")
setupPlatformDependency("bungee", "bungeeJar")
setupPlatformDependency("velocity", "velocityJar")
setupPlatformDependency("folia", "foliaJar", 21)

val main by sourceSets

Expand All @@ -25,6 +26,9 @@ dependencies {

"velocity"(main.output)
"velocity"(libs.velocity)

"folia"(main.output)
"folia"(libs.folia)
}

publishShadowJar()
206 changes: 206 additions & 0 deletions api/src/folia/java/com/lunarclient/apollo/FoliaApollo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
/*
* 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;

import com.lunarclient.apollo.common.ApolloEntity;
import com.lunarclient.apollo.common.location.ApolloBlockLocation;
import com.lunarclient.apollo.common.location.ApolloLocation;
import com.lunarclient.apollo.common.location.ApolloPlayerLocation;
import com.lunarclient.apollo.player.ApolloPlayer;
import com.lunarclient.apollo.player.ApolloPlayerManager;
import com.lunarclient.apollo.recipients.Recipients;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import lombok.NonNull;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;

/**
* Utility class for converting objects to and from their corresponding Bukkit
* representations with additional helper methods for easier integration.
*
* @since 1.1.8
*/
public final class FoliaApollo {

/**
* Runs a specified operation for a {@link Player}.
*
* @param player the player
* @param playerConsumer the operation to be performed
* @since 1.1.8
*/
public static void runForPlayer(@NonNull Player player, @NonNull Consumer<ApolloPlayer> playerConsumer) {
runForPlayer(player.getUniqueId(), playerConsumer);
}

/**
* Runs a specified operation for a {@link ApolloPlayer} from the provided {@link UUID}.
*
* @param playerUuid the player
* @param playerConsumer the operation to be performed
* @since 1.1.8
*/
public static void runForPlayer(@NonNull UUID playerUuid, @NonNull Consumer<ApolloPlayer> playerConsumer) {
Apollo.getPlayerManager().getPlayer(playerUuid).ifPresent(playerConsumer);
}

/**
* Converts a {@link Collection} of {@link Player}s to an {@link Recipients}.
*
* @param players the players
* @return the recipients object containing the converted ApolloPlayer objects
* @since 1.1.8
*/
public static Recipients getRecipientsFrom(@NonNull Collection<Player> players) {
ApolloPlayerManager playerManager = Apollo.getPlayerManager();
List<ApolloPlayer> apolloPlayers = players.stream()
.map(player -> playerManager.getPlayer(player.getUniqueId()))
.filter(Optional::isPresent)
.map(Optional::get)
.collect(Collectors.toList());

return Recipients.of(apolloPlayers);
}

/**
* Converts a {@link Location} to an {@link ApolloLocation} object.
*
* @param location the location
* @return the converted apollo location object
* @since 1.1.8
*/
public static ApolloLocation toApolloLocation(@NonNull Location location) {
return ApolloLocation.builder()
.world(location.getWorld().getName())
.x(location.getX())
.y(location.getY())
.z(location.getZ())
.build();
}

/**
* Converts a {@link Location} to an {@link ApolloBlockLocation} object.
*
* @param location the location
* @return the converted apollo block location object
* @since 1.1.8
*/
public static ApolloBlockLocation toApolloBlockLocation(@NonNull Location location) {
return ApolloBlockLocation.builder()
.world(location.getWorld().getName())
.x(location.getBlockX())
.y(location.getBlockY())
.z(location.getBlockZ())
.build();
}

/**
* Converts a {@link Location} to an {@link ApolloPlayerLocation} object.
*
* @param location the location
* @return the converted apollo player location object
* @since 1.1.8
*/
public static ApolloPlayerLocation toApolloPlayerLocation(@NonNull Location location) {
return ApolloPlayerLocation.builder()
.location(FoliaApollo.toApolloLocation(location))
.yaw(location.getYaw())
.pitch(location.getPitch())
.build();
}

/**
* Converts a {@link Entity} to an {@link ApolloEntity} object.
*
* @param entity the entity
* @return the converted apollo entity object
* @since 1.1.8
*/
public static ApolloEntity toApolloEntity(@NonNull Entity entity) {
return new ApolloEntity(entity.getEntityId(), entity.getUniqueId());
}

/**
* Converts a {@link ApolloLocation} to an {@link Location} object.
*
* @param location the apollo location
* @return the converted location object
* @since 1.1.8
*/
public static Location toBukkitLocation(@NonNull ApolloLocation location) {
return new Location(
Bukkit.getWorld(location.getWorld()),
location.getX(),
location.getY(),
location.getZ()
);
}

/**
* Converts a {@link ApolloBlockLocation} to an {@link Location} object.
*
* @param location the apollo block location
* @return the converted location object
* @since 1.1.8
*/
public static Location toBukkitLocation(@NonNull ApolloBlockLocation location) {
return new Location(
Bukkit.getWorld(location.getWorld()),
location.getX(),
location.getY(),
location.getZ()
);
}

/**
* Converts a {@link ApolloPlayerLocation} to an {@link Location} object.
*
* @param location the apollo location
* @return the converted location object
* @since 1.1.8
*/
public static Location toBukkitLocation(@NonNull ApolloPlayerLocation location) {
ApolloLocation apolloLocation = location.getLocation();

return new Location(
Bukkit.getWorld(apolloLocation.getWorld()),
apolloLocation.getX(),
apolloLocation.getY(),
apolloLocation.getZ(),
location.getYaw(),
location.getPitch()
);
}

private FoliaApollo() {
}

}
1 change: 1 addition & 0 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dependencies {
implementation(libs.idea)
implementation(libs.spotless)
implementation(libs.shadow)
implementation(libs.asm)
}

dependencies {
Expand Down
28 changes: 26 additions & 2 deletions build-logic/src/main/kotlin/extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.api.tasks.javadoc.Javadoc
import org.gradle.jvm.tasks.Jar
import org.gradle.jvm.toolchain.JavaLanguageVersion
import org.gradle.kotlin.dsl.*
import org.gradle.jvm.toolchain.JavaToolchainService

fun JavaPluginExtension.javaTarget(version: Int) {
toolchain.languageVersion.set(JavaLanguageVersion.of(version))
Expand Down Expand Up @@ -45,7 +47,9 @@ fun Project.setupPlatforms() {
}
}

fun Project.setupPlatformDependency(configurationName: String, jarTaskName: String) {
fun Project.setupPlatformDependency(configurationName: String,
jarTaskName: String,
javaVersion: Int? = 8) {
extensions.configure<JavaPluginExtension> {
val configuration = configurations.register(configurationName)

Expand All @@ -62,6 +66,17 @@ fun Project.setupPlatformDependency(configurationName: String, jarTaskName: Stri
}
}

if (javaVersion != null) {
val javaToolchains = project.extensions.getByType(JavaToolchainService::class.java)
tasks.named<JavaCompile>(source.compileJavaTaskName) {
javaCompiler.set(javaToolchains.compilerFor {
languageVersion.set(JavaLanguageVersion.of(javaVersion))
})
sourceCompatibility = javaVersion.toString()
targetCompatibility = javaVersion.toString()
}
}

val jarTask by tasks.register(jarTaskName, Jar::class) {
archiveClassifier.set(configurationName)
from(source.output)
Expand Down Expand Up @@ -149,7 +164,14 @@ fun Project.setupDynamicLoader() {
}
}

fun Project.setupDynamicDependency(configurationName: String, shadowTaskName: String, jarPath: String, jarName: String, name: String = configurationName, classifier: String = "all") {
fun Project.setupDynamicDependency(
configurationName: String,
shadowTaskName: String,
jarPath: String,
jarName: String,
name: String = configurationName,
classifier: String = "all"
) {
extensions.configure<JavaPluginExtension> {
val configuration = configurations.findByName(configurationName) ?: configurations.register(configurationName).get()

Expand All @@ -161,6 +183,8 @@ fun Project.setupDynamicDependency(configurationName: String, shadowTaskName: St
archiveClassifier.set("${name}-${classifier}")
configurations = listOf(configuration)

mustRunAfter(":extra:apollo-extra-adventure4:shadowJar")

configureExclusions()
}

Expand Down
5 changes: 5 additions & 0 deletions bukkit-example-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ plugins {
id("apollo.shadow-conventions")
}

java {
javaTarget(21)
}

dependencies {
compileOnly(project(":extra:apollo-extra-adventure4"))
compileOnly(project(path = ":apollo-api", configuration = "bukkit"))
compileOnly(project(path = ":apollo-common", configuration = "shadow"))

compileOnly(libs.folia)
implementation(project(":apollo-bukkit-example-common"))
}
Loading