Skip to content

Commit f344512

Browse files
committed
feat: prepare other misc changes
1 parent fe70685 commit f344512

File tree

4 files changed

+89
-1
lines changed

4 files changed

+89
-1
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Minecraft Development for IntelliJ
3+
*
4+
* https://mcdev.io/
5+
*
6+
* Copyright (C) 2025 minecraft-dev
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Lesser General Public License as published
10+
* by the Free Software Foundation, version 3.0 only.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public License
18+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
package com.demonwav.mcdev.creator.custom.derivation
22+
23+
import com.demonwav.mcdev.creator.custom.PropertyDerivation
24+
import com.demonwav.mcdev.creator.custom.TemplateValidationReporter
25+
import com.demonwav.mcdev.creator.custom.types.CreatorProperty
26+
import com.demonwav.mcdev.util.SemanticVersion
27+
28+
class ExtractPaperApiVersionPropertyDerivation : ExtractVersionMajorMinorPropertyDerivation() {
29+
30+
override fun derive(parentValues: List<Any?>): Any {
31+
val from = parentValues[0] as SemanticVersion
32+
if (from.parts.size < 2) {
33+
return SemanticVersion(emptyList())
34+
}
35+
36+
if (from.parts.size == 3) {
37+
val (part1, part2, part3) = from.parts
38+
if (part1 is SemanticVersion.Companion.VersionPart.ReleasePart &&
39+
part2 is SemanticVersion.Companion.VersionPart.ReleasePart &&
40+
part3 is SemanticVersion.Companion.VersionPart.ReleasePart
41+
) {
42+
// From Minecraft version 1.20.5 onwards, the Paper API version also contains the 'minor' number.
43+
if (part1.version >= 26 || (part2.version >= 21) || (part2.version == 20 && part3.version >= 5)) {
44+
return SemanticVersion(listOf(part1, part2, part3))
45+
}
46+
}
47+
}
48+
49+
val (part1, part2) = from.parts
50+
if (part1 is SemanticVersion.Companion.VersionPart.ReleasePart &&
51+
part2 is SemanticVersion.Companion.VersionPart.ReleasePart
52+
) {
53+
return SemanticVersion(listOf(part1, part2))
54+
}
55+
56+
return SemanticVersion(emptyList())
57+
}
58+
59+
companion object : PropertyDerivationFactory {
60+
61+
override fun create(
62+
reporter: TemplateValidationReporter,
63+
parents: List<CreatorProperty<*>?>?,
64+
derivation: PropertyDerivation
65+
): PreparedDerivation? {
66+
if (parents.isNullOrEmpty()) {
67+
reporter.error("Expected a parent")
68+
return null
69+
}
70+
71+
if (!parents[0]!!.acceptsType(SemanticVersion::class.java)) {
72+
reporter.error("First parent must produce a semantic version")
73+
return null
74+
}
75+
76+
return ExtractPaperApiVersionPropertyDerivation()
77+
}
78+
}
79+
}

src/main/kotlin/creator/custom/derivation/ExtractVersionMajorMinorPropertyDerivation.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import com.demonwav.mcdev.creator.custom.TemplateValidationReporter
2525
import com.demonwav.mcdev.creator.custom.types.CreatorProperty
2626
import com.demonwav.mcdev.util.SemanticVersion
2727

28-
class ExtractVersionMajorMinorPropertyDerivation : PreparedDerivation {
28+
open class ExtractVersionMajorMinorPropertyDerivation : PreparedDerivation {
2929

3030
override fun derive(parentValues: List<Any?>): Any? {
3131
val from = parentValues[0] as SemanticVersion

src/main/kotlin/creator/custom/model/StringList.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,7 @@ data class StringList(val values: List<String>) : List<String> by values {
2828
@JvmOverloads
2929
fun toString(separator: String, prefix: String = "", postfix: String = ""): String =
3030
values.joinToString(separator, prefix, postfix)
31+
32+
fun toStringQuoted(): String =
33+
values.joinToString(", ", transform = { '"' + it + '"' })
3134
}

src/main/kotlin/creator/custom/types/SemanticVersionCreatorProperty.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import com.demonwav.mcdev.creator.custom.CreatorContext
2424
import com.demonwav.mcdev.creator.custom.PropertyDerivation
2525
import com.demonwav.mcdev.creator.custom.TemplatePropertyDescriptor
2626
import com.demonwav.mcdev.creator.custom.TemplateValidationReporter
27+
import com.demonwav.mcdev.creator.custom.derivation.ExtractPaperApiVersionPropertyDerivation
2728
import com.demonwav.mcdev.creator.custom.derivation.ExtractVersionMajorMinorPropertyDerivation
2829
import com.demonwav.mcdev.creator.custom.derivation.PreparedDerivation
2930
import com.demonwav.mcdev.creator.custom.derivation.SelectPropertyDerivation
@@ -64,6 +65,11 @@ open class SemanticVersionCreatorProperty(
6465
ExtractVersionMajorMinorPropertyDerivation.create(reporter, parents, derives)
6566
}
6667

68+
"extractPaperApiVersion" -> {
69+
val parents = collectDerivationParents(reporter)
70+
ExtractPaperApiVersionPropertyDerivation.create(reporter, parents, derives)
71+
}
72+
6773
null -> {
6874
SelectPropertyDerivation.create(reporter, emptyList(), derives)
6975
}

0 commit comments

Comments
 (0)