Skip to content

Commit

Permalink
feat: 1.21.3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Nov 17, 2024
1 parent a382ebb commit 27dd011
Show file tree
Hide file tree
Showing 9 changed files with 347 additions and 18 deletions.
7 changes: 4 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ plugins {
id("com.mineinabyss.conventions.copyjar")
id("com.mineinabyss.conventions.publication")
id("com.mineinabyss.conventions.autoversion")
id("xyz.jpenilla.run-paper") version "2.0.1" // Adds runServer and runMojangMappedServer tasks for testing
id("xyz.jpenilla.run-paper") version "2.3.1" // Adds runServer and runMojangMappedServer tasks for testing
id("net.minecrell.plugin-yml.paper") version "0.6.0"
id("io.papermc.paperweight.userdev") version "1.7.1"
id("io.papermc.paperweight.userdev") version "1.7.4"
}

paperweight.reobfArtifactConfiguration.set(ReobfArtifactConfiguration.MOJANG_PRODUCTION)
Expand Down Expand Up @@ -39,10 +39,11 @@ dependencies {
compileOnly(idofrontLibs.minecraft.mccoroutine)

// Shaded
paperweight.paperDevBundle("1.21-R0.1-SNAPSHOT") //NMS
paperweight.paperDevBundle("1.21.1-R0.1-SNAPSHOT") //NMS
implementation(project(path = ":core"))
implementation(project(path = ":v1_20_R4"))
implementation(project(path = ":v1_21_R1"))
implementation(project(path = ":v1_21_R2"))
}

tasks {
Expand Down
19 changes: 8 additions & 11 deletions core/src/main/kotlin/com/mineinabyss/emojy/EmojyHelpers.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.mineinabyss.emojy

import com.mineinabyss.emojy.config.Emotes
import com.mineinabyss.emojy.config.SPACE_PERMISSION
import com.mineinabyss.idofront.font.Space
import com.mineinabyss.idofront.textcomponents.miniMsg
Expand Down Expand Up @@ -32,6 +31,12 @@ val ORIGINAL_ITEM_RENAME_TEXT = NamespacedKey.fromString("emojy:original_item_re
fun spaceString(space: Int) = "<font:${emojyConfig.spaceFont.asMinimalString()}>${Space.of(space)}</font>"
fun spaceComponent(space: Int) = Component.textOfChildren(Component.text(Space.of(space)).font(emojyConfig.spaceFont))

val SPACE_REPLACEMENT_CONFIG = TextReplacementConfig.builder()
.match(spaceRegex.pattern)
.replacement { matchResult, _ ->
spaceComponent(matchResult.group(1).toIntOrNull() ?: return@replacement null)
}.build()

private fun Component.asFlatTextContent(): String {
var flattened = ""
val flatText = (this@asFlatTextContent as? TextComponent) ?: return flattened
Expand Down Expand Up @@ -111,16 +116,8 @@ fun Component.transformEmotes(locale: Locale? = null, insert: Boolean = false):
)
}

spaceRegex.findAll(serialized).forEach { match ->
val space = match.groupValues[1].toIntOrNull() ?: return@forEach
val spaceRegex = "(?<!\\\\):space_(-?$space+):".toRegex()
component = component.replaceText(
TextReplacementConfig.builder()
.match(spaceRegex.pattern).once()
.replacement(spaceComponent(space))
.build()
)
}

component = component.replaceText(SPACE_REPLACEMENT_CONFIG)

return component
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ object EmojyNMSHandlers {
val nmsPackage = when (Bukkit.getMinecraftVersion()) {
"1.20.5", "1.20.6" -> "v1_20_R4"
"1.21", "1.21.1" -> "v1_21_R1"
"1.21.2", "1.21.3" -> "v1_21_R2"
else -> throw IllegalStateException("Unsupported server version")
}
runCatching {
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ dependencyResolutionManagement {
}
}

include("core", "v1_20_R4", "v1_21_R1")
include("core", "v1_20_R4", "v1_21_R1", "v1_21_R2")
2 changes: 1 addition & 1 deletion v1_20_R4/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import io.papermc.paperweight.userdev.ReobfArtifactConfiguration
plugins {
id("com.mineinabyss.conventions.kotlin.jvm")
id("com.mineinabyss.conventions.autoversion")
id("io.papermc.paperweight.userdev") version "1.7.1"
id("io.papermc.paperweight.userdev") version "1.7.4"
}

repositories {
Expand Down
4 changes: 2 additions & 2 deletions v1_21_R1/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import io.papermc.paperweight.userdev.ReobfArtifactConfiguration
plugins {
id("com.mineinabyss.conventions.kotlin.jvm")
id("com.mineinabyss.conventions.autoversion")
id("io.papermc.paperweight.userdev") version "1.7.1"
id("io.papermc.paperweight.userdev") version "1.7.4"
}

repositories {
Expand All @@ -26,7 +26,7 @@ dependencies {
// Shaded
implementation(idofrontLibs.bundles.idofront.core)
implementation(project(":core"))
paperweight.paperDevBundle("1.21-R0.1-SNAPSHOT") //NMS
paperweight.paperDevBundle("1.21.1-R0.1-SNAPSHOT") //NMS
}

tasks {
Expand Down
48 changes: 48 additions & 0 deletions v1_21_R2/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import io.papermc.paperweight.userdev.ReobfArtifactConfiguration

plugins {
id("com.mineinabyss.conventions.kotlin.jvm")
id("com.mineinabyss.conventions.autoversion")
id("io.papermc.paperweight.userdev") version "1.7.4"
}

repositories {
gradlePluginPortal()
maven("https://repo.mineinabyss.com/releases")
maven("https://repo.mineinabyss.com/snapshots")
maven("https://repo.papermc.io/repository/maven-public/")
google()
}

paperweight.reobfArtifactConfiguration.set(ReobfArtifactConfiguration.MOJANG_PRODUCTION)

dependencies {
// MineInAbyss platform
compileOnly(idofrontLibs.kotlinx.serialization.json)
compileOnly(idofrontLibs.kotlinx.serialization.kaml)
compileOnly(idofrontLibs.kotlinx.coroutines)
compileOnly(idofrontLibs.minecraft.mccoroutine)

// Shaded
implementation(idofrontLibs.bundles.idofront.core)
implementation(project(":core"))
paperweight.paperDevBundle("1.21.3-R0.1-SNAPSHOT") //NMS
}

tasks {

build {
dependsOn(reobfJar)
}

compileJava {
options.encoding = Charsets.UTF_8.name()
options.release.set(21)
}
javadoc {
options.encoding = Charsets.UTF_8.name()
}
processResources {
filteringCharset = Charsets.UTF_8.name()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package com.mineinabyss.emojy.nms.v1_21_R2

import com.github.shynixn.mccoroutine.bukkit.launch
import com.github.shynixn.mccoroutine.bukkit.ticks
import com.jeff_media.morepersistentdatatypes.DataType
import com.mineinabyss.emojy.*
import com.mineinabyss.idofront.items.editItemMeta
import com.mineinabyss.idofront.textcomponents.miniMsg
import com.mineinabyss.idofront.textcomponents.serialize
import io.papermc.paper.event.player.AsyncChatDecorateEvent
import io.papermc.paper.event.player.PlayerOpenSignEvent
import kotlinx.coroutines.delay
import net.minecraft.core.BlockPos
import net.minecraft.world.level.block.entity.BlockEntityType
import org.bukkit.block.Sign
import org.bukkit.block.sign.Side
import org.bukkit.craftbukkit.entity.CraftPlayer
import org.bukkit.event.EventHandler
import org.bukkit.event.EventPriority
import org.bukkit.event.Listener
import org.bukkit.event.block.SignChangeEvent
import org.bukkit.event.inventory.PrepareAnvilEvent
import org.bukkit.event.player.PlayerEditBookEvent

@Suppress("UnstableApiUsage")
class EmojyListener : Listener {

// Replace with result not original message to avoid borking other chat formatting
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
fun AsyncChatDecorateEvent.onPlayerChat() {
result(result().escapeEmoteIDs(player()))
}

@EventHandler
fun SignChangeEvent.onSign() {
val state = (block.state as Sign)
val type = DataType.asList(DataType.STRING)
val sideLines = lines().map { it.serialize() }.toList()
val frontLines = if (side == Side.FRONT) sideLines else state.persistentDataContainer.getOrDefault(
ORIGINAL_SIGN_FRONT_LINES,
type,
mutableListOf("", "", "", "")
)
val backLines = if (side == Side.BACK) sideLines else state.persistentDataContainer.getOrDefault(
ORIGINAL_SIGN_BACK_LINES,
type,
mutableListOf("", "", "", "")
)

state.persistentDataContainer.set(ORIGINAL_SIGN_FRONT_LINES, type, frontLines)
state.persistentDataContainer.set(ORIGINAL_SIGN_BACK_LINES, type, backLines)
state.update(true)

lines().forEachIndexed { index, s ->
line(index, s?.escapeEmoteIDs(player)?.transformEmotes())
}
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
fun PlayerOpenSignEvent.onSignEdit() {
if (cause == PlayerOpenSignEvent.Cause.PLACE) return

sign.persistentDataContainer.get(
when (sign.getInteractableSideFor(player)) {
Side.FRONT -> ORIGINAL_SIGN_FRONT_LINES
Side.BACK -> ORIGINAL_SIGN_BACK_LINES
}, DataType.asList(DataType.STRING)
)?.forEachIndexed { index, s ->
sign.getSide(side).line(index, s.miniMsg())
}
sign.update(true)
isCancelled = true
emojy.plugin.launch {
delay(2.ticks)
(player as CraftPlayer).handle.level()
.getBlockEntity(BlockPos(sign.x, sign.y, sign.z), BlockEntityType.SIGN).ifPresent {
it.setAllowedPlayerEditor(player.uniqueId)
(player as CraftPlayer).handle.openTextEdit(it, side == Side.FRONT)
}
}
}

@EventHandler
fun PrepareAnvilEvent.onAnvil() {
result = result?.editItemMeta {
if (view.renameText == null || result?.itemMeta?.hasDisplayName() != true) {
persistentDataContainer.remove(ORIGINAL_ITEM_RENAME_TEXT)
} else persistentDataContainer.set(ORIGINAL_ITEM_RENAME_TEXT, DataType.STRING, view.renameText!!)
}
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
fun PlayerEditBookEvent.onBookEdit() {
if (isSigning) newBookMeta = newBookMeta.apply {
pages(pages().map {
it.escapeEmoteIDs(player).transformEmotes().unescapeEmoteIds()
})
}
}
}

Loading

0 comments on commit 27dd011

Please sign in to comment.