Skip to content

Commit

Permalink
fix: default to first lang if one isnt supported
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Feb 9, 2025
1 parent fe95674 commit 8fa07e3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,13 @@ import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver
import java.util.*


class EmojyArgumentTag(argumentComponents: List<ComponentLike?>) : TagResolver {
private val argumentComponents: List<ComponentLike?>

init {
this.argumentComponents = Objects.requireNonNull(argumentComponents, "argumentComponents")
}
class EmojyArgumentTag(private val argumentComponents: List<ComponentLike>) : TagResolver {

@Throws(ParsingException::class)
override fun resolve(name: String, arguments: ArgumentQueue, ctx: Context): Tag {
val index = arguments.popOr("No argument number provided").asInt().orElseThrow {
ctx.newException(
"Invalid argument number",
arguments
)
}
if (index < 0 || index >= argumentComponents.size) {
throw ctx.newException("Invalid argument number", arguments)
}
return Tag.inserting(argumentComponents[index]!!)
val index = arguments.popOr("No argument number provided").asInt().orElse(-1).takeUnless { it < 0 || it >= argumentComponents.size }
?: throw ctx.newException("Invalid argument number", arguments)
return Tag.inserting(argumentComponents[index])
}

override fun has(name: String): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ class EmojyTranslator : Translator {
override fun translate(key: String, locale: Locale) = null

override fun translate(component: TranslatableComponent, locale: Locale): Component? {
val mmString = emojy.languages.firstOrNull { it.locale == locale }?.keys?.get(component.key()) ?: return null
val resultingComponent = mmString.miniMsg(EmojyArgumentTag(component.arguments()).takeIf { component.arguments().isNotEmpty() } ?: IdofrontTextComponents.globalResolver)
val lang = emojy.languages.firstOrNull { it.locale == locale } ?: emojy.languages.firstOrNull() ?: return null
val mmString = lang.keys[component.key()] ?: return null
val tagResolver = component.arguments().takeUnless { it.isEmpty() }?.let(::EmojyArgumentTag) ?: IdofrontTextComponents.globalResolver
return when {
component.children().isEmpty() -> resultingComponent
else -> resultingComponent.children(component.children())
component.children().isEmpty() -> mmString.miniMsg(tagResolver)
else -> mmString.miniMsg(tagResolver).children(component.children())
}
}

Expand Down

0 comments on commit 8fa07e3

Please # to comment.