Skip to content
Draft
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
1 change: 1 addition & 0 deletions buildSrc/src/main/kotlin/core-convention.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ version = findProperty("version") as String + if (snapshot) "-SNAPSHOT" else ""
repositories {
mavenCentral()
maven("https://reposilite.slne.dev/public") { name = "slne-repository-public" }
maven("https://repo.opencollab.dev/main/") { name = "OpenCollab" }
}

dependencies {
Expand Down
6 changes: 6 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ placeholder-api = "2.12.3"
# McCoroutine
mccoroutine = "2.23.1"

# Bedrock
floodgate-api = "2.2.5-SNAPSHOT"

# Miscellaneous Libraries
asm = "9.10.1"
slf4j = "2.0.17"
Expand Down Expand Up @@ -142,6 +145,9 @@ mccoroutine-folia-core = { module = "dev.slne.forks.mccoroutine:mccoroutine-foli
mccoroutine-velocity-api = { module = "dev.slne.forks.mccoroutine:mccoroutine-velocity-api", version.ref = "mccoroutine" }
mccoroutine-velocity-core = { module = "dev.slne.forks.mccoroutine:mccoroutine-velocity-core", version.ref = "mccoroutine" }

# Bedrock
floodgate-api = { module = "org.geysermc.floodgate:api", version.ref = "floodgate-api" }

# Miscellaneous Libraries
asm = { module = "org.ow2.asm:asm", version.ref = "asm" }
slf4j = { module = "org.slf4j:slf4j-api", version.ref = "slf4j" }
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ val ci = System.getenv("CI")?.toBoolean() ?: false
if (!ci) {
include(":surf-api-paper:surf-api-paper-plugin-test")
include("surf-api-generator")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import dev.slne.surf.api.gradle.platform.SurfApiPlatform
import dev.slne.surf.api.gradle.platform.common.testing.SurfTestingConfigurer
import dev.slne.surf.api.gradle.platform.core.AbstractCoreSurfPlugin
import dev.slne.surf.api.gradle.util.canvasMaven
import dev.slne.surf.api.gradle.util.openCollabMaven
import org.gradle.api.Project
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.repositories
Expand All @@ -19,6 +20,9 @@ internal abstract class AbstractPaperSurfPlugin<E : AbstractPaperSurfExtension>(
}

override fun Project.configure0() {
repositories {
openCollabMaven()
}
}

final override fun Project.afterEvaluated1(extension: E) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ inline fun RepositoryHandler.canvasMaven(crossinline block: MavenArtifactReposit
block()
}

inline fun RepositoryHandler.openCollabMaven(crossinline block: MavenArtifactRepository.() -> Unit = {}) =
maven("https://repo.opencollab.dev/main/") {
name = "OpenCollab"
block()
}

inline fun RepositoryHandler.slneReleases(crossinline block: MavenArtifactRepository.() -> Unit = {}) =
maven("https://reposilite.slne.dev/releases/") {
name = "slne-repository-releases"
Expand Down
1 change: 1 addition & 0 deletions surf-api-paper/surf-api-paper-server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ paper {
registerSoft("ViaBackwards")
registerSoft("ViaRewind")
registerSoft("Geyser-Spigot")
registerSoft("floodgate")
registerSoft("PlaceholderAPI")

register("CommandAPI") {
Expand Down
265 changes: 265 additions & 0 deletions surf-api-paper/surf-api-paper/api/surf-api-paper.api

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion surf-api-paper/surf-api-paper/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {

dependencies {
api(projects.surfApiCore.surfApiCore)
compileOnly(libs.paper.api)
compileOnlyApi(libs.paper.api)
compileOnlyApi(libs.packetevents.spigot)
compileOnlyApi(libs.commandapi.paper)
compileOnlyApi(libs.reflection.remapper)
Expand All @@ -15,6 +15,7 @@ dependencies {
api(libs.commandapi.bukkit.kotlin)
compileOnlyApi(libs.mccoroutine.folia.api)
api(libs.wyck)
compileOnlyApi(libs.floodgate.api)

testImplementation(libs.mockbukkit)
testImplementation(libs.paper.api)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package dev.slne.surf.api.paper.bedrock

import org.bukkit.Bukkit

/**
* Checks whether Floodgate, which is required for the Bedrock API, is installed.
*
* Floodgate is an optional dependency, so every entry point of the Bedrock API
* checks this before touching any Floodgate class.
*/
object BedrockSupport {
const val FLOODGATE_PLUGIN_NAME = "floodgate"

/**
* `true` if Floodgate is installed and enabled.
*/
val isAvailable: Boolean
get() = Bukkit.getPluginManager().isPluginEnabled(FLOODGATE_PLUGIN_NAME)

/**
* Throws an [IllegalStateException] if Floodgate is not installed.
*/
fun requireAvailable() {
check(isAvailable) { "Floodgate ($FLOODGATE_PLUGIN_NAME) is not installed or enabled" }
}
}

/**
* Runs [block] if Floodgate is installed, otherwise returns [default].
*/
internal inline fun <T> ifBedrockAvailable(default: T, block: () -> T): T =
if (BedrockSupport.isAvailable) block() else default
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package dev.slne.surf.api.paper.bedrock.floodgate

import dev.slne.surf.api.paper.bedrock.BedrockSupport
import dev.slne.surf.api.paper.bedrock.ifBedrockAvailable
import org.bukkit.Bukkit
import org.bukkit.entity.Player
import org.geysermc.floodgate.api.FloodgateApi
import org.geysermc.floodgate.api.player.FloodgatePlayer

/**
* The Floodgate API instance.
*
* @throws IllegalStateException if Floodgate is not installed.
*/
val floodgateApi: FloodgateApi
get() {
BedrockSupport.requireAvailable()
return FloodgateApi.getInstance()
}

/**
* The Floodgate player of this player, or `null` if this player is not a Bedrock player
* or Floodgate is not installed.
*/
val Player.floodgatePlayer: FloodgatePlayer?
get() = ifBedrockAvailable(null) { floodgateApi.getPlayer(uniqueId) }

/**
* Returns `true` if this player is a Bedrock player.
* Returns `false` if Floodgate is not installed.
*/
fun Player.isBedrockPlayer() = ifBedrockAvailable(false) { floodgateApi.isFloodgatePlayer(uniqueId) }

/**
* The Xbox user id of this player, or `null` if this player is not a Bedrock player
* or Floodgate is not installed.
*/
val Player.xuid: String? get() = floodgatePlayer?.xuid

val FloodgatePlayer.bukkitPlayer get() = Bukkit.getPlayer(this.javaUniqueId)

/**
* Returns `true` if this player is a Floodgate player.
* Returns `false` if Floodgate is not installed.
*/
fun FloodgatePlayer.isFloodgatePlayer() =
ifBedrockAvailable(false) { floodgateApi.isFloodgatePlayer(this.javaUniqueId) }
Loading
Loading