Skip to content

Commit

Permalink
modernized format
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt-MX committed Jul 25, 2024
1 parent 5893215 commit 623c9a7
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 40 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 49 additions & 28 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,40 +1,35 @@
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.archivesName
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.io.BufferedReader
import java.io.InputStreamReader

plugins {
kotlin("jvm") version "1.7.10"
id("com.github.johnrengelman.shadow") version "7.0.0"
id("org.ajoberstar.grgit") version "4.1.0"
alias(libs.plugins.runPaper)
alias(libs.plugins.paperweight) apply true
alias(libs.plugins.kotlinJvm) apply true
alias(libs.plugins.shadow) apply true

// Check for new versions at https://plugins.gradle.org/plugin/io.papermc.paperweight.userdev
id("io.papermc.paperweight.userdev") version "1.7.1"
`maven-publish`
}

val group_name: String by project
group = group_name
version = project.properties["version"].toString()
val id: String by project
runPaper.folia.registerTask()

val plugin_name: String by project
val plugin_main_class_name: String by project
val plugin_author: String by project
val include_commit_hash: String by project

val ktgui_version: String by project
val paper_version: String by project
val id = findProperty("id").toString()
val pluginName = findProperty("plugin_name")

repositories {
mavenLocal()
mavenCentral()
maven("https://repo.papermc.io/repository/maven-public/")
maven("https://maven.pvphub.me/releases")
maven("https://repo.dmulloy2.net/repository/public/")
maven("https://jitpack.io")
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/")
}

dependencies {
testImplementation(kotlin("test"))
compileOnly(kotlin("stdlib"))
paperweight.paperDevBundle(libs.versions.paperApi.get())

compileOnly("com.mattmx:ktgui:${ktgui_version}")
paperweight.paperDevBundle(paper_version)
compileOnly(libs.ktgui)
compileOnly(libs.placeholder.api)
}

tasks {
Expand All @@ -44,10 +39,12 @@ tasks {

withType<ProcessResources> {
val props = mapOf(
"name" to plugin_name,
"main" to "${group_name}.${id}.${plugin_main_class_name}",
"author" to plugin_author,
"version" to if (include_commit_hash.toBoolean()) "${rootProject.version}-commit-${grgit.head().abbreviatedId}" else rootProject.version.toString()
"name" to pluginName,
"main" to "${findProperty("group_name")}.${id}.${findProperty("plugin_main_class_name")}",
"author" to findProperty("plugin_author"),
"version" to if (findProperty("include_commit_hash")
.toString().toBoolean()
) "${rootProject.version}-commit-${getCurrentCommitHash()}" else rootProject.version.toString()
)
inputs.properties(props)
filteringCharset = "UTF-8"
Expand All @@ -68,8 +65,15 @@ tasks {
dependsOn("reobfJar")
}

withType<KotlinCompile> {
kotlinOptions.jvmTarget = "17"
runServer {
val mcVersion = libs.versions.paperApi.get().split("-")[0]
minecraftVersion(mcVersion)

downloadPlugins {
hangar("ViaVersion", "5.0.1")
hangar("ViaBackwards", "5.0.1")
hangar("PlaceholderAPI", "2.11.6")
}
}
}

Expand All @@ -78,6 +82,10 @@ java {
withSourcesJar()
}

kotlin {
jvmToolchain(17)
}

sourceSets["main"].resources.srcDir("src/resources/")

publishing {
Expand All @@ -99,4 +107,17 @@ publishing {
version = rootProject.version.toString()
}
}
}

fun getCurrentCommitHash(): String {
val process = ProcessBuilder("git", "rev-parse", "HEAD").start()
val reader = BufferedReader(InputStreamReader(process.inputStream))
val commitHash = reader.readLine()
reader.close()
process.waitFor()
if (process.exitValue() == 0) {
return commitHash?.substring(0, 7) ?: ""
} else {
throw IllegalStateException("Failed to retrieve the commit hash.")
}
}
6 changes: 1 addition & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,4 @@ plugin_name = Template
plugin_main_class_name = TemplatePlugin
plugin_author = MattMX

include_commit_hash = true

# Dependenices
paper_version = 1.20.4-R0.1-SNAPSHOT
ktgui_version = 2.4.0
include_commit_hash = true
26 changes: 26 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[versions]

paperweight = "1.7.1"
kotlin = "2.0.0"
updateVersions = "0.51.0"
shadow = "8.1.8"
paperApi = "1.20.4-R0.1-SNAPSHOT"
placeholderapi = "2.11.6"
ktgui = "2.4.2-alpha"
runPaper = "2.2.4"

[libraries]

kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" }
kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" }
paper-api = { module = "io.papermc.paper:paper-api", version.ref = "paperApi" }
placeholder-api = { module = "me.clip:placeholderapi", version.ref = "placeholderapi" }
ktgui = { module = "com.mattmx:ktgui", version.ref = "ktgui" }

[plugins]

kotlinJvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
updateDeps = { id = "com.github.ben-manes.versions", version.ref = "updateVersions" }
shadow = { id = "io.github.goooler.shadow", version.ref = "shadow" }
paperweight = { id = "io.papermc.paperweight.userdev", version.ref = "paperweight" }
runPaper = { id = "xyz.jpenilla.run-paper", version.ref = "runPaper" }
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
5 changes: 1 addition & 4 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pluginManagement {
}

plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
id("com.gradle.enterprise") version("3.15")
}

Expand All @@ -19,6 +18,4 @@ gradleEnterprise {
termsOfServiceAgree = "yes"
}
}
}

//rootProject.name = "Template"
}
9 changes: 8 additions & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,11 @@ name: ${name}
main: ${main}
version: ${version}
author: ${author}
api-version: 1.17
api-version: 1.17

softdepend:
- PlaceholderAPI
- MCKotlin-Paper

libraries:
- org.jetbrains.kotlin:kotlin-stdlib:2.0.0

0 comments on commit 623c9a7

Please sign in to comment.