Skip to content

Commit 4b85c2c

Browse files
authored
feat: 1.21.10 support (#17)
1 parent e52f81c commit 4b85c2c

File tree

7 files changed

+570
-2
lines changed

7 files changed

+570
-2
lines changed

build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,14 @@ dependencies {
4444
compileOnly(idofrontLibs.minecraft.mccoroutine)
4545

4646
// Shaded
47-
paperweight.paperDevBundle("1.21.8-R0.1-SNAPSHOT") //NMS
47+
paperweight.paperDevBundle("1.21.10-R0.1-SNAPSHOT") //NMS
4848
implementation(project(path = ":core"))
4949
implementation(project(path = ":v1_21_R1"))
5050
implementation(project(path = ":v1_21_R2"))
5151
implementation(project(path = ":v1_21_R3"))
5252
implementation(project(path = ":v1_21_R4"))
5353
implementation(project(path = ":v1_21_R6"))
54+
implementation(project(path = ":v1_21_R8"))
5455
}
5556

5657
tasks {

core/src/main/kotlin/com/mineinabyss/emojy/nms/EmojyNMSHandlers.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ object EmojyNMSHandlers {
1212
"1.21.4" -> "v1_21_R3"
1313
"1.21.5" -> "v1_21_R4"
1414
"1.21.6", "1.21.7", "1.21.8" -> "v1_21_R6"
15+
"1.21.9", "1.21.10" -> "v1_21_R8"
1516
else -> throw IllegalStateException("Unsupported server version")
1617
}
1718
runCatching {

settings.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ dependencyResolutionManagement {
3535
}
3636
}
3737

38-
include("core", "v1_21_R1", "v1_21_R2", "v1_21_R3", "v1_21_R4", "v1_21_R6")
38+
include("core", "v1_21_R1", "v1_21_R2", "v1_21_R3", "v1_21_R4", "v1_21_R6", "v1_21_R8")

v1_21_R8/build.gradle.kts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import io.papermc.paperweight.userdev.ReobfArtifactConfiguration
2+
3+
plugins {
4+
id("com.mineinabyss.conventions.kotlin.jvm")
5+
id("com.mineinabyss.conventions.autoversion")
6+
id("io.papermc.paperweight.userdev") version "2.0.0-beta.18"
7+
}
8+
9+
repositories {
10+
gradlePluginPortal()
11+
maven("https://repo.mineinabyss.com/releases")
12+
maven("https://repo.mineinabyss.com/snapshots")
13+
maven("https://repo.papermc.io/repository/maven-public/")
14+
google()
15+
}
16+
17+
paperweight.reobfArtifactConfiguration.set(ReobfArtifactConfiguration.MOJANG_PRODUCTION)
18+
19+
dependencies {
20+
// MineInAbyss platform
21+
compileOnly(idofrontLibs.kotlinx.serialization.json)
22+
compileOnly(idofrontLibs.kotlinx.serialization.kaml)
23+
compileOnly(idofrontLibs.kotlinx.coroutines)
24+
compileOnly(idofrontLibs.minecraft.mccoroutine)
25+
26+
// Shaded
27+
implementation(idofrontLibs.bundles.idofront.core)
28+
implementation(project(":core"))
29+
paperweight.paperDevBundle("1.21.10-R0.1-SNAPSHOT") //NMS
30+
}
31+
32+
tasks {
33+
34+
compileJava {
35+
options.encoding = Charsets.UTF_8.name()
36+
options.release.set(21)
37+
}
38+
javadoc {
39+
options.encoding = Charsets.UTF_8.name()
40+
}
41+
processResources {
42+
filteringCharset = Charsets.UTF_8.name()
43+
}
44+
}

v1_21_R8/src/main/kotlin/com/mineinabyss/emojy/nms/v1_21_R8/EmojyChannelHandler.kt

Lines changed: 421 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.mineinabyss.emojy.nms.v1_21_R8
2+
3+
import com.jeff_media.morepersistentdatatypes.DataType
4+
import com.mineinabyss.emojy.ORIGINAL_ITEM_RENAME_TEXT
5+
import com.mineinabyss.emojy.escapeEmoteIDs
6+
import com.mineinabyss.emojy.nms.IEmojyNMSHandler
7+
import com.mineinabyss.emojy.transformEmotes
8+
import com.mineinabyss.emojy.unescapeEmoteIds
9+
import io.papermc.paper.datacomponent.DataComponentTypes
10+
import io.papermc.paper.event.player.AsyncChatCommandDecorateEvent
11+
import io.papermc.paper.event.player.AsyncChatDecorateEvent
12+
import org.bukkit.event.EventHandler
13+
import org.bukkit.event.EventPriority
14+
import org.bukkit.event.Listener
15+
import org.bukkit.event.inventory.PrepareAnvilEvent
16+
import org.bukkit.event.player.PlayerEditBookEvent
17+
import org.bukkit.event.player.PlayerJoinEvent
18+
import org.bukkit.event.player.PlayerQuitEvent
19+
20+
@Suppress("UnstableApiUsage")
21+
class EmojyListener(val handler: IEmojyNMSHandler) : Listener {
22+
23+
@EventHandler
24+
fun PlayerJoinEvent.onJoin() {
25+
handler.inject(player)
26+
}
27+
28+
@EventHandler
29+
fun PlayerQuitEvent.onQuit() {
30+
handler.uninject(player)
31+
}
32+
33+
// Replace with result not original message to avoid borking other chat formatting
34+
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
35+
fun AsyncChatDecorateEvent.onPlayerChat() {
36+
result(result().escapeEmoteIDs(player()))
37+
}
38+
39+
@EventHandler
40+
fun AsyncChatCommandDecorateEvent.onPlayerCommandChat() {
41+
result(result().escapeEmoteIDs(player()))
42+
}
43+
44+
@EventHandler
45+
fun PrepareAnvilEvent.onAnvil() {
46+
result?.editPersistentDataContainer {
47+
if (view.renameText == null || result?.hasData(DataComponentTypes.CUSTOM_NAME) != true)
48+
it.remove(ORIGINAL_ITEM_RENAME_TEXT)
49+
else it.set(ORIGINAL_ITEM_RENAME_TEXT, DataType.STRING, view.renameText!!)
50+
}
51+
}
52+
53+
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
54+
fun PlayerEditBookEvent.onBookEdit() {
55+
if (isSigning) newBookMeta = newBookMeta.apply {
56+
pages(pages().map {
57+
it.escapeEmoteIDs(player).transformEmotes().unescapeEmoteIds()
58+
})
59+
}
60+
}
61+
}
62+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
@file:Suppress("unused")
2+
3+
package com.mineinabyss.emojy.nms.v1_21_R8
4+
5+
import com.mineinabyss.emojy.EmojyPlugin
6+
import com.mineinabyss.emojy.nms.IEmojyNMSHandler
7+
import com.mineinabyss.idofront.plugin.listeners
8+
import net.minecraft.network.Connection
9+
import org.bukkit.craftbukkit.entity.CraftPlayer
10+
import org.bukkit.entity.Player
11+
12+
class EmojyNMSHandler(emojy: EmojyPlugin) : IEmojyNMSHandler {
13+
14+
override fun inject(player: Player) {
15+
val channel = (player as CraftPlayer).handle.connection.connection.channel
16+
val pipeline = channel.pipeline()
17+
18+
val emojyChannelHandler = EmojyChannelHandler(player)
19+
pipeline.toMap().keys.forEach {
20+
if (pipeline.get(it) !is Connection) return@forEach
21+
pipeline.addBefore(it, IEmojyNMSHandler.EMOJY_CHANNEL_HANDLER, emojyChannelHandler)
22+
}
23+
}
24+
25+
override fun uninject(player: Player) {
26+
val channel = (player as CraftPlayer).handle.connection.connection.channel
27+
val pipeline = channel.pipeline()
28+
29+
channel.eventLoop().submit {
30+
pipeline.remove(IEmojyNMSHandler.EMOJY_CHANNEL_HANDLER)
31+
}
32+
}
33+
34+
init {
35+
emojy.listeners(EmojyListener(this))
36+
}
37+
38+
override val supported get() = true
39+
}

0 commit comments

Comments
 (0)