Skip to content

Commit

Permalink
fix: bunch of RP and other fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Jan 5, 2025
1 parent 71fe1d6 commit abe8dcf
Show file tree
Hide file tree
Showing 15 changed files with 57 additions and 55 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
id("com.mineinabyss.conventions.autoversion")
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.6"
id("io.papermc.paperweight.userdev") version "2.0.0-beta.11"
}

paperweight.reobfArtifactConfiguration.set(ReobfArtifactConfiguration.MOJANG_PRODUCTION)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object EmojyCommands {
val gifs = emojy.gifs.filter { it.checkPermission(sender as? Player) && it !in emojyConfig.emojyList.ignoredGifs }.toSet()

val emoteList = when (sender) {
is Player -> Component.textOfChildren(*emotes.map { it.formattedUnicode(true) }.toTypedArray())
is Player -> Component.textOfChildren(*emotes.map { it.formattedComponent(true) }.toTypedArray())
else -> emotes.joinToString(", ") { it.id }.miniMsg()
}

Expand Down
28 changes: 11 additions & 17 deletions core/src/main/kotlin/com/mineinabyss/emojy/EmojyGenerator.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package com.mineinabyss.emojy

import com.aaaaahhhhhhh.bananapuncher714.gifconverter.GifConverter
import com.mineinabyss.emojy.config.Gif
import com.mineinabyss.emojy.config.Gifs
import com.mineinabyss.idofront.font.Space
import com.mineinabyss.idofront.font.Space.Companion.toNumber
import com.mineinabyss.idofront.messaging.broadcastVal
import com.mineinabyss.idofront.resourcepacks.ResourcePacks
import net.kyori.adventure.key.Key
import team.unnamed.creative.ResourcePack
Expand All @@ -16,17 +12,12 @@ import team.unnamed.creative.font.FontProvider
import team.unnamed.creative.font.SpaceFontProvider
import team.unnamed.creative.serialize.minecraft.MinecraftResourcePackWriter
import team.unnamed.creative.texture.Texture
import java.awt.image.BufferedImage
import java.io.File
import javax.imageio.ImageIO
import kotlin.io.path.Path
import kotlin.math.ceil
import kotlin.math.sqrt

object EmojyGenerator {
val gifFolder = emojy.plugin.dataFolder.resolve("gifs").apply { mkdirs() }
private val emotesFolder = emojy.plugin.dataFolder.resolve("emotes").apply { mkdirs() }
private val spaceProvider = FontProvider.space(Space.entries.asSequence().filterNot(Space.NULL::equals).associate { it.unicode to it.toNumber() })
private val unknownTexture by lazy { ResourcePacks.defaultVanillaResourcePack?.texture(Key.key("gui/sprites/icon/unseen_notification.png")) }

fun generateResourcePack() {
val resourcePack = ResourcePack.resourcePack()
Expand All @@ -35,7 +26,7 @@ object EmojyGenerator {
val textureFiles = emotesFolder.walkTopDown().filter { it.isFile }.associateBy { it.name }
val fontSpaceProvider = FontProvider.space().advance("\uE101", -1).build()
emojy.emotes.forEach { emote ->
resourcePack.font(emote.font)?.takeIf { emote.isMultiBitmap }?.let { font ->
resourcePack.font(emote.font)?.takeIf { emote.isMultiBitmap }?.also { font ->
when {
// Add a -1 advance to the font for ease of use
// Mainly needed for ESC menu and default font due to no other font being supported
Expand All @@ -44,15 +35,18 @@ object EmojyGenerator {
// If the font has already added an entry for the emote, skip it
font.providers().any { it is BitMapFontProvider && it.file() == emote.texture } ->
return@forEach emojy.logger.w("Skipping ${emote.id}-font because it is a bitmap and already added")
.let { null }
}
}

emote.appendFont(resourcePack).addTo(resourcePack)
val texture = textureFiles[emote.texture.value().substringAfterLast("/")]
if (texture == null && ResourcePacks.defaultVanillaResourcePack?.texture(emote.texture) == null)
emojy.logger.w("Could not find texture for ${emote.id}")
Texture.texture(emote.texture, texture?.let(Writable::file) ?: Writable.EMPTY).addTo(resourcePack)
val texture = textureFiles[emote.texture.value().substringAfterLast("/").removeSuffix(".png").plus(".png")]
val vanillaTexture = ResourcePacks.defaultVanillaResourcePack?.texture(emote.texture)

if (texture == null && vanillaTexture == null)
return@forEach emojy.logger.w("Could not find texture for ${emote.id}")

texture?.also { Texture.texture(emote.texture, Writable.file(it)).addTo(resourcePack) }
emote.appendFont(resourcePack)

}

emojy.gifs.forEach {
Expand Down
17 changes: 2 additions & 15 deletions core/src/main/kotlin/com/mineinabyss/emojy/EmojyHelpers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fun String.transformEmotes(insert: Boolean = false): String {
val bitmapIndex = bitmapIndexRegex.find(match.value)?.groupValues?.get(1)?.toIntOrNull() ?: -1

content = content.replaceFirst(
emote.baseRegex, emote.formattedUnicode(
emote.baseRegex, emote.formattedComponent(
insert = insert,
colorable = colorable,
bitmapIndex = bitmapIndex
Expand Down Expand Up @@ -91,20 +91,7 @@ fun Component.transformEmotes(locale: Locale? = null, insert: Boolean = false):
val colorable = colorableRegex in match.value
val bitmapIndex = bitmapIndexRegex.find(match.value)?.groupValues?.get(1)?.toIntOrNull() ?: -1

component = component.replaceText(
TextReplacementConfig.builder()
.match(emote.baseRegex.pattern).once()
.replacement(
Component.textOfChildren(
emote.formattedUnicode(
insert = insert,
colorable = colorable,
bitmapIndex = bitmapIndex
)
)
)
.build()
)
component = component.replaceText(emote.replacementConfig(false, insert, colorable, bitmapIndex))
}

for (gif in emojy.gifs) gif.baseRegex.findAll(serialized).forEach { _ ->
Expand Down
35 changes: 23 additions & 12 deletions core/src/main/kotlin/com/mineinabyss/emojy/config/Emote.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
import net.kyori.adventure.key.Key
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.TextReplacementConfig
import net.kyori.adventure.text.event.HoverEvent
import net.kyori.adventure.text.event.HoverEvent.hoverEvent
import net.kyori.adventure.text.format.NamedTextColor
Expand All @@ -29,9 +30,8 @@ data class Emote(

@EncodeDefault(NEVER) val font: @Serializable(KeySerializer::class) Key =
template?.font ?: emojyConfig.defaultFont,
@EncodeDefault(NEVER) val texture: @Serializable(KeySerializer::class) Key =
template?.texture
?: Key.key("${emojyConfig.defaultNamespace}:${emojyConfig.defaultFolder}/${id.lowercase()}.png"),
@SerialName("texture") @EncodeDefault(NEVER) private val _texture: @Serializable(KeySerializer::class) Key =
template?.texture ?: Key.key("${emojyConfig.defaultNamespace}:${emojyConfig.defaultFolder}/${id.lowercase()}.png"),
@EncodeDefault(NEVER) val height: Int = template?.height ?: emojyConfig.defaultHeight,
@EncodeDefault(NEVER) val ascent: Int = template?.ascent ?: emojyConfig.defaultAscent,
@EncodeDefault(NEVER) val bitmapWidth: Int = template?.bitmapWidth ?: 1,
Expand All @@ -43,6 +43,8 @@ data class Emote(
val baseRegex = "(?<!\\\\):$id(\\|(c|colorable|\\d+))*:".toRegex()
@Transient
val escapedRegex = "\\\\:$id(\\|(c|colorable|\\d+))*:".toRegex()
@Transient
val texture = Key.key(_texture.asString().removeSuffix(".png").plus(".png"))

// Beginning of Private Use Area \uE000 -> uF8FF
// Option: (Character.toCodePoint('\uE000', '\uFF8F')/37 + getIndex())
Expand Down Expand Up @@ -73,16 +75,27 @@ data class Emote(

private val permission get() = "emojy.emote.$id"
private val fontPermission get() = "emojy.font.$font"
private fun fontProvider() = FontProvider.bitMap(texture, height, ascent, unicodes)
private val fontProvider by lazy { FontProvider.bitMap(texture, height, ascent, unicodes) }
fun appendFont(resourcePack: ResourcePack) =
(resourcePack.font(font)?.toBuilder() ?: Font.font().key(font)).addProvider(fontProvider()).build()
(resourcePack.font(font)?.toBuilder() ?: Font.font().key(font)).addProvider(fontProvider).build().addTo(resourcePack)

fun checkPermission(player: Player?) =
!emojyConfig.requirePermissions || player == null || player.hasPermission(permission) || player.hasPermission(
fontPermission
)
!emojyConfig.requirePermissions || player?.hasPermission(permission) != false || player.hasPermission(fontPermission)

fun formattedUnicode(
fun replacementConfig(
appendSpace: Boolean = false,
insert: Boolean = true,
colorable: Boolean = false,
bitmapIndex: Int = -1
): TextReplacementConfig {
return if (!appendSpace && insert && !colorable && bitmapIndex == -1) defaultReplacementConfig
else TextReplacementConfig.builder().match(baseRegex.pattern).once().replacement(formattedComponent(appendSpace, insert, colorable, bitmapIndex)).build()
}
private val defaultReplacementConfig by lazy {
TextReplacementConfig.builder().match(baseRegex.pattern).once().replacement(defaultComponent).build()
}
private val defaultComponent by lazy { formattedComponent() }
fun formattedComponent(
appendSpace: Boolean = false,
insert: Boolean = true,
colorable: Boolean = false,
Expand Down Expand Up @@ -115,8 +128,6 @@ data class Emote(
)
)

if (appendSpace) bitmap.append(spaceComponent(2))

return bitmap
return if (appendSpace) bitmap.append(spaceComponent(2)) else bitmap
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package com.mineinabyss.emojy.nms

import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer

interface IEmojyNMSHandler {

companion object {
val legacyHandler = LegacyComponentSerializer.legacy('§')
}

val supported get() = false
}
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.11-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
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.6"
id("io.papermc.paperweight.userdev") version "2.0.0-beta.11"
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ class EmojyNMSHandler(emojy: EmojyPlugin) : IEmojyNMSHandler {
fun Component.transformEmotes(locale: Locale? = null, insert: Boolean = false): Component {
return when {
// Sometimes a NMS component is partially Literal, so ensure entire thing is just one LiteralContent with no extra data
contents is LiteralContents && style.isEmpty && siblings.isEmpty() -> (contents as LiteralContents).text.miniMsg()
contents is LiteralContents && style.isEmpty && siblings.isEmpty() ->
(contents as LiteralContents).text.let { it.takeUnless { "§" in it }?.miniMsg() ?: IEmojyNMSHandler.legacyHandler.deserialize(it) }
else -> PaperAdventure.asAdventure(this)
}.transformEmotes(locale, insert).let(PaperAdventure::asVanilla)
}
Expand Down
2 changes: 1 addition & 1 deletion 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.6"
id("io.papermc.paperweight.userdev") version "2.0.0-beta.11"
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ class EmojyNMSHandler(emojy: EmojyPlugin) : IEmojyNMSHandler {
fun Component.transformEmotes(locale: Locale? = null, insert: Boolean = false): Component {
return when {
// Sometimes a NMS component is partially Literal, so ensure entire thing is just one LiteralContent with no extra data
contents is LiteralContents && style.isEmpty && siblings.isEmpty() -> (contents as LiteralContents).text.miniMsg()
contents is LiteralContents && style.isEmpty && siblings.isEmpty() ->
(contents as LiteralContents).text.let { it.takeUnless { "§" in it }?.miniMsg() ?: IEmojyNMSHandler.legacyHandler.deserialize(it) }
else -> PaperAdventure.asAdventure(this)
}.transformEmotes(locale, insert).let(PaperAdventure::asVanilla)
}
Expand Down
2 changes: 1 addition & 1 deletion v1_21_R2/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.6"
id("io.papermc.paperweight.userdev") version "2.0.0-beta.11"
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ class EmojyNMSHandler(emojy: EmojyPlugin) : IEmojyNMSHandler {
fun Component.transformEmotes(locale: Locale? = null, insert: Boolean = false): Component {
return when {
// Sometimes a NMS component is partially Literal, so ensure entire thing is just one LiteralContent with no extra data
contents is LiteralContents && style.isEmpty && siblings.isEmpty() -> (contents as LiteralContents).text.miniMsg()
contents is LiteralContents && style.isEmpty && siblings.isEmpty() ->
(contents as LiteralContents).text.let { it.takeUnless { "§" in it }?.miniMsg() ?: IEmojyNMSHandler.legacyHandler.deserialize(it) }
else -> PaperAdventure.asAdventure(this)
}.transformEmotes(locale, insert).let(PaperAdventure::asVanilla)
}
Expand Down
2 changes: 1 addition & 1 deletion v1_21_R3/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.6"
id("io.papermc.paperweight.userdev") version "2.0.0-beta.11"
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ class EmojyNMSHandler(emojy: EmojyPlugin) : IEmojyNMSHandler {
fun Component.transformEmotes(locale: Locale? = null, insert: Boolean = false): Component {
return when {
// Sometimes a NMS component is partially Literal, so ensure entire thing is just one LiteralContent with no extra data
contents is LiteralContents && style.isEmpty && siblings.isEmpty() -> (contents as LiteralContents).text.miniMsg()
contents is LiteralContents && style.isEmpty && siblings.isEmpty() ->
(contents as LiteralContents).text.let { it.takeUnless { "§" in it }?.miniMsg() ?: IEmojyNMSHandler.legacyHandler.deserialize(it) }
else -> PaperAdventure.asAdventure(this)
}.transformEmotes(locale, insert).let(PaperAdventure::asVanilla)
}
Expand Down

0 comments on commit abe8dcf

Please sign in to comment.