Skip to content

Commit

Permalink
Update advancement displays for 1.20.4 (closes #202)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpenilla committed Feb 23, 2024
1 parent 1e63fad commit 53735e3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
15 changes: 7 additions & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ dependencies {
isTransitive = false
}
compileOnly("me.clip", "placeholderapi", "2.11.5")
compileOnly("com.mojang:datafixerupper:6.0.8")

implementation(platform("net.kyori:adventure-bom:4.15.0"))
implementation("net.kyori", "adventure-extra-kotlin")
Expand Down Expand Up @@ -66,7 +67,7 @@ java {

kotlin {
jvmToolchain {
languageVersion.set(JavaLanguageVersion.of(8))
languageVersion = JavaLanguageVersion.of(8)
}
}

Expand All @@ -75,7 +76,7 @@ tasks {
kotlinOptions.jvmTarget = "1.8"
}
jar {
archiveClassifier.set("not-shadowed")
archiveClassifier = "not-shadowed"
}
shadowJar {
from(rootProject.file("license.txt")) {
Expand Down Expand Up @@ -111,14 +112,12 @@ tasks {
dependsOn(shadowJar)
}
runServer {
minecraftVersion("1.20.2")
minecraftVersion("1.20.4")
}
withType<RunServer> {
javaLauncher.set(
project.javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(17))
}
)
javaLauncher = project.javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
register("format") {
group = "formatting"
Expand Down
28 changes: 26 additions & 2 deletions src/main/kotlin/xyz/jpenilla/announcerplus/task/ToastTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ package xyz.jpenilla.announcerplus.task

import com.google.gson.Gson
import com.google.gson.JsonObject
import com.mojang.serialization.Codec
import com.mojang.serialization.JsonOps
import io.papermc.lib.PaperLib.getMinecraftPatchVersion
import io.papermc.lib.PaperLib.getMinecraftVersion
import org.bukkit.entity.Player
Expand All @@ -38,6 +40,7 @@ import xyz.jpenilla.announcerplus.util.schedule
import xyz.jpenilla.pluginbase.legacy.Crafty
import xyz.jpenilla.reflectionremapper.ReflectionRemapper
import java.lang.reflect.Constructor
import java.lang.reflect.Field
import java.lang.reflect.Method
import java.lang.reflect.Modifier
import java.util.UUID
Expand Down Expand Up @@ -113,8 +116,7 @@ class ToastTask : KoinComponent {
)
val json = advancementJson(player)
if (USE_ADVANCEMENT_HOLDER) {
return AdvancementHolder_ctr!!(
resourceLocation,
val advancement = if (Advancement_CODEC == null) {
Advancement_fromJson(
null,
json,
Expand All @@ -123,6 +125,15 @@ class ToastTask : KoinComponent {
MinecraftServer_getPredicateManager(MinecraftServer_getServer())
)
)
} else {
(Advancement_CODEC.get(null) as Codec<*>)
.parse(JsonOps.INSTANCE, json)
.result()
.orElseThrow { IllegalStateException() }
}
return AdvancementHolder_ctr!!(
resourceLocation,
advancement
) to resourceLocation
}
val advancementBuilder = if (getMinecraftVersion() >= 16) {
Expand Down Expand Up @@ -230,6 +241,7 @@ class ToastTask : KoinComponent {
// start 1.20.2+
val USE_ADVANCEMENT_HOLDER: Boolean = (getMinecraftVersion() == 20 && getMinecraftPatchVersion() >= 2) || getMinecraftVersion() > 20

// 1.20.2 only
val Advancement_fromJson by lazy {
Advancement_class.declaredMethods.find { method ->
method.returnType == Advancement_class &&
Expand Down Expand Up @@ -266,6 +278,10 @@ class ToastTask : KoinComponent {
val AdvancementTree_remove: Method?
// end 1.20.2+

// start 1.20.4+
val Advancement_CODEC: Field?
// end 1.20.4+

val PlayerAdvancements_award: Method
val PlayerAdvancements_revoke: Method
val AdvancementProgress_remainingCriteria: Method
Expand All @@ -283,8 +299,16 @@ class ToastTask : KoinComponent {
AdvancementProgress_completedCriteria = AdvancementProgress_class.getDeclaredMethod("getAwardedCriteria")
AdvancementTree_addAll = null
AdvancementTree_remove = null
Advancement_CODEC = null
} else {
val reflectionRemapper = ReflectionRemapper.forReobfMappingsInPaperJar()
if (getMinecraftVersion() == 20 && getMinecraftPatchVersion() >= 4 || getMinecraftVersion() > 20) {
Advancement_CODEC = Advancement_class.getDeclaredField(
reflectionRemapper.remapFieldName(Advancement_class, "CODEC")
)
} else {
Advancement_CODEC = null
}

PlayerAdvancements_award = PlayerAdvancements_class.getDeclaredMethod(
reflectionRemapper.remapMethodName(PlayerAdvancements_class, "award", advancementOrHolderCls(), String::class.java),
Expand Down

0 comments on commit 53735e3

Please sign in to comment.