diff --git a/src/main/kotlin/io/delilaheve/CustomAnvil.kt b/src/main/kotlin/io/delilaheve/CustomAnvil.kt index 97f8462..291e3ab 100644 --- a/src/main/kotlin/io/delilaheve/CustomAnvil.kt +++ b/src/main/kotlin/io/delilaheve/CustomAnvil.kt @@ -55,6 +55,9 @@ open class CustomAnvil : JavaPlugin() { // Config command name const val commandConfigName = "customanvilconfig" + // Rish name prefix for chat messages + const val namePrefix = "[CustomAnvil]" + // Current plugin instance lateinit var instance: CustomAnvil diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt index e612634..20ffbbb 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt @@ -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} 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} 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} 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} Error while handling the anvil." ) return true } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/util/MiniMessageUtil.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/util/MiniMessageUtil.kt index c989ca0..4b3d552 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/util/MiniMessageUtil.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/util/MiniMessageUtil.kt @@ -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) + } + }