Skip to content

Commit

Permalink
feat(version-support): add 1.16.5 support & fix 1.21.4 paperweight is…
Browse files Browse the repository at this point in the history
…sues
  • Loading branch information
StillLutto committed Dec 24, 2024
1 parent 24b41dd commit 7c24950
Show file tree
Hide file tree
Showing 70 changed files with 1,037 additions and 189 deletions.
11 changes: 8 additions & 3 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ version = versionVar
dependencies {
compileOnly("org.spigotmc:spigot-api:1.20.6-R0.1-SNAPSHOT")
implementation(project(":common"))
implementation(project(":v1_16_5"))
implementation(project(":v1_17"))
implementation(project(":v1_17_1:", "reobf"))
implementation(project(":v1_17_1"))
implementation(project(":v1_18_1"))
implementation(project(":v1_18_2"))
implementation(project(":v1_19_2"))
Expand All @@ -30,14 +31,18 @@ dependencies {
implementation(project(":v1_21_1"))
implementation(project(":v1_21_3"))
implementation(project(":v1_21_4"))
implementation(kotlin("reflect"))
}

tasks {
compileKotlin {
kotlinOptions.jvmTarget = "16"
kotlinOptions.jvmTarget = "1.8"
}
compileJava {
options.release.set(8)
}
}

kotlin {
jvmToolchain(16)
jvmToolchain(21)
}
9 changes: 5 additions & 4 deletions api/src/main/kotlin/com/undefined/stellar/StellarCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.undefined.stellar.data.events.StellarCommandRegisterEvent
import com.undefined.stellar.data.requirement.PermissionStellarRequirement
import com.undefined.stellar.exception.UnsupportedVersionException
import com.undefined.stellar.manager.CommandManager
import com.undefined.stellar.registrar.AbstractCommandRegistrar
import com.undefined.stellar.util.NMSVersion
import org.bukkit.Bukkit
import org.bukkit.command.CommandSender
Expand All @@ -25,17 +26,17 @@ class StellarCommand(name: String, permissions: List<String> = listOf()) : Abstr
registered = true
StellarCommands.commands.add(this)
CommandManager.initialize(plugin)
val registrar = CommandManager.registrars[NMSVersion.version] ?: throw UnsupportedVersionException()
registrar.register(this, plugin)
val registrar = (CommandManager.registrars[NMSVersion.version] ?: throw UnsupportedVersionException()).objectInstance
registrar?.register(this, plugin)
for (execution in this.registerExecutions) execution()
Bukkit.getPluginManager().callEvent(StellarCommandRegisterEvent(this))
}

companion object {
@ApiStatus.Internal
fun parseAndReturnCancelled(sender: CommandSender, input: String): Boolean {
val registrar = CommandManager.registrars[NMSVersion.version] ?: throw UnsupportedVersionException()
return registrar.handleCommandFailure(sender, input)
val registrar = (CommandManager.registrars[NMSVersion.version] ?: throw UnsupportedVersionException()).objectInstance
return registrar?.handleCommandFailure(sender, input) ?: false
}
}

Expand Down
48 changes: 25 additions & 23 deletions api/src/main/kotlin/com/undefined/stellar/manager/CommandManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,34 @@ import com.undefined.stellar.registrar.AbstractCommandRegistrar
import org.bukkit.Bukkit
import org.bukkit.plugin.java.JavaPlugin
import org.jetbrains.annotations.ApiStatus
import kotlin.reflect.KClass

@ApiStatus.Internal
object CommandManager {
val registrars: Map<String, AbstractCommandRegistrar> = mapOf(
"1.17" to com.undefined.stellar.v1_17.CommandRegistrar,
"1.17.1" to com.undefined.stellar.v1_17_1.CommandRegistrar,
"1.18" to com.undefined.stellar.v1_18_1.CommandRegistrar,
"1.18.1" to com.undefined.stellar.v1_18_1.CommandRegistrar,
"1.18.2" to com.undefined.stellar.v1_18_2.CommandRegistrar,
"1.19" to com.undefined.stellar.v1_19_2.CommandRegistrar,
"1.19.1" to com.undefined.stellar.v1_19_2.CommandRegistrar,
"1.19.2" to com.undefined.stellar.v1_19_2.CommandRegistrar,
"1.19.3" to com.undefined.stellar.v1_19_3.CommandRegistrar,
"1.19.4" to com.undefined.stellar.v1_19_4.CommandRegistrar,
"1.20" to com.undefined.stellar.v1_20.CommandRegistrar,
"1.20.1" to com.undefined.stellar.v1_20_1.CommandRegistrar,
"1.20.2" to com.undefined.stellar.v1_20_2.CommandRegistrar,
"1.20.3" to com.undefined.stellar.v1_20_2.CommandRegistrar,
"1.20.4" to com.undefined.stellar.v1_20_4.CommandRegistrar,
"1.20.5" to com.undefined.stellar.v1_20_6.CommandRegistrar,
"1.20.6" to com.undefined.stellar.v1_20_6.CommandRegistrar,
"1.21" to com.undefined.stellar.v1_21.CommandRegistrar,
"1.21.1" to com.undefined.stellar.v1_21_1.CommandRegistrar,
"1.21.2" to com.undefined.stellar.v1_21_1.CommandRegistrar,
"1.21.3" to com.undefined.stellar.v1_21_3.CommandRegistrar,
"1.21.4" to com.undefined.stellar.v1_21_4.CommandRegistrar,
val registrars: Map<String, KClass<out AbstractCommandRegistrar>> = mapOf(
"1.16.5" to com.undefined.stellar.v1_16_5.CommandRegistrar::class,
"1.17" to com.undefined.stellar.v1_17.CommandRegistrar::class,
"1.17.1" to com.undefined.stellar.v1_17_1.CommandRegistrar::class,
"1.18" to com.undefined.stellar.v1_18_1.CommandRegistrar::class,
"1.18.1" to com.undefined.stellar.v1_18_1.CommandRegistrar::class,
"1.18.2" to com.undefined.stellar.v1_18_2.CommandRegistrar::class,
"1.19" to com.undefined.stellar.v1_19_2.CommandRegistrar::class,
"1.19.1" to com.undefined.stellar.v1_19_2.CommandRegistrar::class,
"1.19.2" to com.undefined.stellar.v1_19_2.CommandRegistrar::class,
"1.19.3" to com.undefined.stellar.v1_19_3.CommandRegistrar::class,
"1.19.4" to com.undefined.stellar.v1_19_4.CommandRegistrar::class,
"1.20" to com.undefined.stellar.v1_20.CommandRegistrar::class,
"1.20.1" to com.undefined.stellar.v1_20_1.CommandRegistrar::class,
"1.20.2" to com.undefined.stellar.v1_20_2.CommandRegistrar::class,
"1.20.3" to com.undefined.stellar.v1_20_2.CommandRegistrar::class,
"1.20.4" to com.undefined.stellar.v1_20_4.CommandRegistrar::class,
"1.20.5" to com.undefined.stellar.v1_20_6.CommandRegistrar::class,
"1.20.6" to com.undefined.stellar.v1_20_6.CommandRegistrar::class,
"1.21" to com.undefined.stellar.v1_21.CommandRegistrar::class,
"1.21.1" to com.undefined.stellar.v1_21_1.CommandRegistrar::class,
"1.21.2" to com.undefined.stellar.v1_21_1.CommandRegistrar::class,
"1.21.3" to com.undefined.stellar.v1_21_3.CommandRegistrar::class,
"1.21.4" to com.undefined.stellar.v1_21_4.CommandRegistrar::class,
)

private val initializedPlugins: MutableList<JavaPlugin> = mutableListOf()
Expand Down
13 changes: 4 additions & 9 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
java
kotlin("jvm") version "1.9.22"
`maven-publish`
id("com.github.johnrengelman.shadow") version "8.1.1"
id("io.papermc.paperweight.userdev") version "2.0.0-beta.8" apply false
}

apply(plugin = "maven-publish")
Expand Down Expand Up @@ -80,6 +79,7 @@ allprojects {
dependencies {
implementation(project(":api"))
implementation(project(":common"))
implementation(project(":v1_16_5"))
implementation(project(":v1_17"))
implementation(project(":v1_17_1:", "reobf"))
implementation(project(":v1_18_1:", "reobf"))
Expand All @@ -99,13 +99,8 @@ dependencies {
}

tasks {
withType<ShadowJar> {
archiveFileName.set("${project.name}-${project.version}.jar")
archiveClassifier.set("mapped")
}

compileKotlin {
kotlinOptions.jvmTarget = "16"
kotlinOptions.jvmTarget = "1.8"
}
}

Expand All @@ -116,5 +111,5 @@ java {
}

kotlin {
jvmToolchain(16)
jvmToolchain(21)
}
7 changes: 5 additions & 2 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ dependencies {

tasks {
compileKotlin {
kotlinOptions.jvmTarget = "16"
kotlinOptions.jvmTarget = "1.8"
}
compileJava {
options.release.set(8)
}
}

kotlin {
jvmToolchain(16)
jvmToolchain(21)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@file:Suppress("UNCHECKED_CAST")
@file:ApiStatus.Internal

package com.undefined.stellar.util

import org.jetbrains.annotations.ApiStatus

object ReflectionUtil {
fun <T : Any> getPrivateField(any: Class<*>, name: String): T =
any::class.java.getDeclaredField(name).apply { isAccessible = true }[this] as T

inline fun <reified T : Any, R> getPrivateMethod(name: String, vararg args: Any?): R =
T::class.java.getDeclaredMethod(name).apply { isAccessible = true }(null, args) as R
}

fun <T : Any> Any.getPrivateField(name: String): T =
javaClass.getDeclaredField(name).apply { isAccessible = true }[this] as T

fun <T : Any> Any.executePrivateMethod(name: String, vararg args: Any?): T =
javaClass.getDeclaredMethod(name).apply { isAccessible = true }(this, args) as T
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
6 changes: 4 additions & 2 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down Expand Up @@ -84,7 +86,7 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
22 changes: 12 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down Expand Up @@ -43,11 +45,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
7 changes: 4 additions & 3 deletions server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ val groupIdVar = "com.undefined"
val artifactIdVar = "stellar"

dependencies {
compileOnly("org.spigotmc:spigot-api:1.17-R0.1-SNAPSHOT")
compileOnly("org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT")

implementation(project(":api"))
implementation(project(":common"))
implementation(project(":v1_16_5"))
implementation(project(":v1_17"))
implementation(project(":v1_17_1:", "reobf"))
implementation(project(":v1_18_1:", "reobf"))
Expand All @@ -29,7 +30,7 @@ dependencies {
implementation(project(":v1_21_1:", "reobf"))
implementation(project(":v1_21_3:", "reobf"))
implementation(project(":v1_21_4:", "reobf"))
implementation(project(":v1_17"))
compileOnly(project(":v1_16_5"))
}

tasks {
Expand All @@ -46,7 +47,7 @@ tasks {
}

runServer {
minecraftVersion("1.17")
minecraftVersion("1.16.5")
jvmArgs("-Xmx2G")
}
}
Expand Down
2 changes: 1 addition & 1 deletion server/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Stellar
version: '${version}'
main: com.undefined.stellar.Main
api-version: '1.17'
api-version: '1.16'
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
rootProject.name = "stellar"
include("server", "api", "common", "v1_17", "v1_17_1", "v1_18_1", "v1_18_2", "v1_19_2", "v1_19_3", "v1_19_4", "v1_20", "v1_20_1", "v1_20_2", "v1_20_4", "v1_20_6", "v1_21", "v1_21_1", "v1_21_3", "v1_21_4")
include("server", "api", "common", "v1_16_5", "v1_17", "v1_17_1", "v1_18_1", "v1_18_2", "v1_19_2", "v1_19_3", "v1_19_4", "v1_20", "v1_20_1", "v1_20_2", "v1_20_4", "v1_20_6", "v1_21", "v1_21_1", "v1_21_3", "v1_21_4")
29 changes: 29 additions & 0 deletions v1_16_5/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
plugins {
kotlin("jvm") version "1.9.22"
}

repositories {
mavenLocal()
}

dependencies {
compileOnly("org.spigotmc:spigot:1.16.5-R0.1-SNAPSHOT")
compileOnly(project(":common"))
}

tasks {
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileJava {
options.release.set(8)
}
}

java {
disableAutoTargetJvm()
}

kotlin {
jvmToolchain(21)
}
Loading

0 comments on commit 7c24950

Please sign in to comment.