Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to paper plugin over platforms, command executor auto registry #66

Merged
merged 7 commits into from
Oct 22, 2023
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
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Helper functions for finding annotated classes at runtime, we use it to register
Gradle [version catalog](https://docs.gradle.org/current/userguide/platforms.html#sub:version-catalog) containing our commonly used dependencies, including all idofront projects.

[**`idofront-catalog-shaded`**](https://wiki.mineinabyss.com/idofront/platforms/) -
Packaged version of our catalog. Used with our platform loader to load dependencies at runtime.
A Paper plugin with all the dependencies shaded, intended to be used by our other plugins using Paper's `join-classpath` option.

[**`idofront-commands`**](https://wiki.mineinabyss.com/idofront/command-dsl/) -
A DSL for quickly building Minecraft commands.
Expand All @@ -40,9 +40,6 @@ Super simple logging functions with MiniMessage support.
[**`idofront-nms`**](https://wiki.mineinabyss.com/idofront/nms/) -
TypeAliases and `toNMS()`, `toBukkit()` functions for many NMS classes

[**`idofront-platform-loader`**](https://wiki.mineinabyss.com/idofront/platforms/) -
Loads dependencies from a jar file, isolating them from other plugins.

[**`idofront-serializers`**](https://wiki.mineinabyss.com/idofront/serialization/) -
Config-centric serializers for many Bukkit classes for kotlinx.serialization, including ItemStack, Recipes, or Components (via MiniMessage.)

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
group=com.mineinabyss
version=0.19
version=0.20
13 changes: 6 additions & 7 deletions idofront-catalog-shaded/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
plugins {
id("com.mineinabyss.conventions.kotlin.jvm")
id("com.mineinabyss.conventions.copyjar")
id("com.mineinabyss.conventions.papermc")
}

dependencies {
val libs = rootProject.extensions.getByType<VersionCatalogsExtension>().named("libs")
libs.findBundle("platform").get().get().forEach {
implementation(it)
}
}

tasks {
shadowJar {
archiveBaseName.set("mineinabyss")
archiveClassifier.set("")
archiveExtension.set("platform")
}
rootProject.subprojects
.filter { it.name.startsWith("idofront-") }
.filter { it.name !in setOf("idofront-catalog", "idofront-catalog-shaded") }
.forEach {implementation(project(it.path)) }
}

copyJar {
jarName.set("idofront-$version.jar")
excludePlatformDependencies.set(false)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.mineinabyss.idofront;

import org.bukkit.plugin.java.JavaPlugin;

public class IdofrontPlugin extends JavaPlugin {
}
6 changes: 6 additions & 0 deletions idofront-catalog-shaded/src/main/resources/paper-plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: Idofront
version: ${plugin_version}
author: Offz
load: STARTUP
main: com.mineinabyss.idofront.IdofrontPlugin
api-version: '1.20'
1 change: 0 additions & 1 deletion idofront-catalog/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ catalog {
"idofront-features",
"idofront-fonts",
"idofront-logging",
"idofront-platform-loader",
"idofront-serializers",
"idofront-text-components",
"idofront-util",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.mineinabyss.idofront.commands.execution.CommandExecutionFailedExcepti
import com.mineinabyss.idofront.commands.execution.IdofrontCommandExecutor
import com.mineinabyss.idofront.messaging.error
import org.bukkit.command.CommandSender
import org.bukkit.command.TabCompleter
import org.bukkit.plugin.java.JavaPlugin

//TODO allow for holding arguments here. The current limitation is that only one instance of the command holder is
Expand Down Expand Up @@ -40,16 +41,27 @@ class CommandDSLEntrypoint(
}
}


override fun command(vararg names: String, desc: String, init: Command.() -> Unit): Command? {
val pluginName: String = plugin.name.lowercase()
val name = names.first()
// register command with bukkit as a top-level command
plugin.server.commandMap.register(name, pluginName,
object : org.bukkit.command.Command(name, desc, "/$name", names.drop(1)) {
override fun execute(sender: CommandSender, commandLabel: String, args: Array<String>): Boolean {
return commandExecutor.onCommand(sender, this, commandLabel, args)
}

// For each command name, register it with bukkit as it is a top-level command
for (name in names) {
plugin.getCommand(name)
?.setExecutor(commandExecutor)
?: plugin.logger.warning("Error registering command $name. Make sure it is defined in your plugin.yml")
}
override fun tabComplete(
sender: CommandSender,
alias: String,
args: Array<out String>?
): List<String> {
if(commandExecutor is TabCompleter)
return commandExecutor.onTabComplete(sender, this, alias, args) ?: emptyList()
return emptyList()
}
})

// Add as a subcommand
subcommands.getOrPut(names.toList()) { mutableListOf() } += { sender, arguments ->
Expand Down
31 changes: 19 additions & 12 deletions idofront-gradle/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import org.jetbrains.kotlin.util.*
import java.util.*

// Load properties from root gradle.properties
Expand All @@ -12,20 +13,22 @@ plugins {

//TODO duplicated code, try to get version from other project somehow
val releaseVersion: String? = System.getenv("RELEASE_VERSION")
val extVersion = project.ext["version"] as String
val isSnapshot = System.getenv("IS_SNAPSHOT") == "true"
version = project.ext["version"] as String

fun getNextVersion(): String {
if (releaseVersion != null) {
val (majorTarget, minorTarget) = extVersion.split(".")
try {
val (major, minor, patch) = releaseVersion.removePrefix("v").split(".")
if (majorTarget == major && minorTarget == minor) {
return "$major.$minor.${patch.toInt() + 1}"
}
} catch (_: Exception) {
if (isSnapshot) return "$version".suffixIfNot("-SNAPSHOT")
if (releaseVersion == null) return "$version"

val (majorTarget, minorTarget) = version.toString().split(".")
try {
val (major, minor, patch) = releaseVersion.removePrefix("v").removeSuffix("-SNAPSHOT").split(".")
if (majorTarget == major && minorTarget == minor) {
return "$major.$minor.${patch.toInt() + 1}"
}
return "$majorTarget.$minorTarget.0"
} else return extVersion
} catch (_: Exception) {
}
return "$majorTarget.$minorTarget.0"
}

version = getNextVersion()
Expand All @@ -46,7 +49,11 @@ dependencies {

publishing {
repositories {
maven("https://repo.mineinabyss.com/releases") {
maven {
val repo = "https://repo.mineinabyss.com/"
val isSnapshot = System.getenv("IS_SNAPSHOT") == "true"
val url = if (isSnapshot) repo + "snapshots" else repo + "releases"
setUrl(url)
credentials {
username = project.findProperty("mineinabyssMavenUsername") as String?
password = project.findProperty("mineinabyssMavenPassword") as String?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import kotlin.jvm.optionals.getOrNull

plugins {
java
com.github.johnrengelman.shadow
Expand Down Expand Up @@ -42,11 +44,15 @@ tasks.assemble {
configurations {
findByName("runtimeClasspath")?.apply {
val libs = rootProject.extensions.getByType<VersionCatalogsExtension>().named("libs")
val deps = libs.findBundle("platform").get().get()
deps.forEach {
exclude(group = it.group, module = it.name)
val deps = libs.findBundle("platform").getOrNull()?.getOrNull() ?: emptyList()
val idoDeps = libs.findBundle("idofront-core").getOrNull()?.getOrNull() ?: emptyList()

val unwanted = (deps + idoDeps).map { it.group to it.name }
unwanted.forEach {
exclude(group = it.first, module = it.second)
}
println("Excluding ${deps.size} dependencies from runtimeClasspath that are present in mineinabyss.platform")

println("Excluded ${unwanted.size} platform dependencies from runtimeClasspath")
}
runtimeClasspath {
exclude(group = "org.jetbrains.kotlin")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ dependencies {

tasks {
processResources {
filesMatching("plugin.yml") {
filesMatching(setOf("plugin.yml", "paper-plugin.yml")) {
expand(mutableMapOf("plugin_version" to version))
}
}
Expand Down
5 changes: 0 additions & 5 deletions idofront-platform-loader/build.gradle.kts

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading