less use of chat color

This commit is contained in:
alexcrea 2025-12-30 15:50:49 +01:00
parent 0f071443da
commit 1700e8b630
Signed by: alexcrea
GPG key ID: E346CD16413450E3
3 changed files with 27 additions and 12 deletions

View file

@ -55,6 +55,9 @@ open class CustomAnvil : JavaPlugin() {
// Config command name
const val commandConfigName = "customanvilconfig"
// Rish name prefix for chat messages
const val namePrefix = "[<yellow>CustomAnvil<white>]"
// Current plugin instance
lateinit var instance: CustomAnvil

View file

@ -4,7 +4,6 @@ import com.willfp.eco.core.gui.player
import io.delilaheve.CustomAnvil
import net.kyori.adventure.text.Component
import org.bukkit.Bukkit
import org.bukkit.ChatColor
import org.bukkit.entity.HumanEntity
import org.bukkit.event.inventory.InventoryClickEvent
import org.bukkit.event.inventory.PrepareAnvilEvent
@ -145,9 +144,8 @@ object DependencyManager {
event.inventory.setItem(ANVIL_OUTPUT_SLOT, null)
// Finally, warn the player, maybe a lot of time but better warn than do nothing
event.view.player.sendMessage(
"[" + ChatColor.YELLOW.toString() + "CustomAnvil" + ChatColor.WHITE.toString() + "] " +
ChatColor.RED.toString() + "Error while handling the anvil."
event.view.player.sendRichMessage(
"${CustomAnvil.namePrefix} <red>Error while handling the anvil."
)
return true
}
@ -185,8 +183,7 @@ object DependencyManager {
// Finally, warn the player, maybe a lot of time but better warn than do nothing
event.view.player.sendMessage(
"[" + ChatColor.YELLOW.toString() + "CustomAnvil" + ChatColor.WHITE.toString() + "] " +
ChatColor.RED.toString() + "Error while handling the anvil."
"${CustomAnvil.namePrefix} <red>Error while handling the anvil."
)
return true
}
@ -222,7 +219,7 @@ object DependencyManager {
val treatEvent = CATreatAnvilResultEvent(event, useType, result, cost)
try {
unsafeTryTreatAnvilResult(treatEvent)
return treatEvent;
return treatEvent
} catch (e: Exception) {
CustomAnvil.instance.logger.log(
Level.SEVERE,
@ -235,8 +232,7 @@ object DependencyManager {
// Finally, warn the player, maybe a lot of time but better warn than do nothing
event.view.player.sendMessage(
"[" + ChatColor.YELLOW.toString() + "CustomAnvil" + ChatColor.WHITE.toString() + "] " +
ChatColor.RED.toString() + "Error while handling the anvil."
"${CustomAnvil.namePrefix} <red>Error while handling the anvil."
)
return null
}
@ -264,8 +260,7 @@ object DependencyManager {
// Finally, warn the player, maybe a lot of time but better warn than do nothing
event.whoClicked.sendMessage(
"[" + ChatColor.YELLOW.toString() + "CustomAnvil" + ChatColor.WHITE.toString() + "] " +
ChatColor.RED.toString() + "Error while handling the anvil."
"[${CustomAnvil.namePrefix} <red>Error while handling the anvil."
)
return true
}

View file

@ -1,12 +1,13 @@
package xyz.alexcrea.cuanvil.util
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.TextComponent
import net.kyori.adventure.text.minimessage.MiniMessage
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer
import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil
import org.jetbrains.annotations.Contract
object MiniMessageUtil {
@ -29,4 +30,20 @@ object MiniMessageUtil {
return legacy_mm.deserialize(legacyText)
}
@Contract("!null -> !null; null -> null")
fun stripTags(text: String?): String? {
if(text == null) return null
val partial = legacy_mm.deserialize(text)
return plain_text_mm.serialize(partial)
}
@Contract("!null -> !null; null -> null")
fun stripTags(component: Component?): Component? {
if(component == null) return null
val partial = plain_text_mm.serialize(component)
return plain_text_mm.deserialize(partial)
}
}