mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
less use of chat color
This commit is contained in:
parent
0f071443da
commit
1700e8b630
3 changed files with 27 additions and 12 deletions
|
|
@ -55,6 +55,9 @@ open class CustomAnvil : JavaPlugin() {
|
||||||
// Config command name
|
// Config command name
|
||||||
const val commandConfigName = "customanvilconfig"
|
const val commandConfigName = "customanvilconfig"
|
||||||
|
|
||||||
|
// Rish name prefix for chat messages
|
||||||
|
const val namePrefix = "[<yellow>CustomAnvil<white>]"
|
||||||
|
|
||||||
// Current plugin instance
|
// Current plugin instance
|
||||||
lateinit var instance: CustomAnvil
|
lateinit var instance: CustomAnvil
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import com.willfp.eco.core.gui.player
|
||||||
import io.delilaheve.CustomAnvil
|
import io.delilaheve.CustomAnvil
|
||||||
import net.kyori.adventure.text.Component
|
import net.kyori.adventure.text.Component
|
||||||
import org.bukkit.Bukkit
|
import org.bukkit.Bukkit
|
||||||
import org.bukkit.ChatColor
|
|
||||||
import org.bukkit.entity.HumanEntity
|
import org.bukkit.entity.HumanEntity
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent
|
import org.bukkit.event.inventory.InventoryClickEvent
|
||||||
import org.bukkit.event.inventory.PrepareAnvilEvent
|
import org.bukkit.event.inventory.PrepareAnvilEvent
|
||||||
|
|
@ -145,9 +144,8 @@ object DependencyManager {
|
||||||
event.inventory.setItem(ANVIL_OUTPUT_SLOT, null)
|
event.inventory.setItem(ANVIL_OUTPUT_SLOT, null)
|
||||||
|
|
||||||
// Finally, warn the player, maybe a lot of time but better warn than do nothing
|
// Finally, warn the player, maybe a lot of time but better warn than do nothing
|
||||||
event.view.player.sendMessage(
|
event.view.player.sendRichMessage(
|
||||||
"[" + ChatColor.YELLOW.toString() + "CustomAnvil" + ChatColor.WHITE.toString() + "] " +
|
"${CustomAnvil.namePrefix} <red>Error while handling the anvil."
|
||||||
ChatColor.RED.toString() + "Error while handling the anvil."
|
|
||||||
)
|
)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
@ -185,8 +183,7 @@ object DependencyManager {
|
||||||
|
|
||||||
// Finally, warn the player, maybe a lot of time but better warn than do nothing
|
// Finally, warn the player, maybe a lot of time but better warn than do nothing
|
||||||
event.view.player.sendMessage(
|
event.view.player.sendMessage(
|
||||||
"[" + ChatColor.YELLOW.toString() + "CustomAnvil" + ChatColor.WHITE.toString() + "] " +
|
"${CustomAnvil.namePrefix} <red>Error while handling the anvil."
|
||||||
ChatColor.RED.toString() + "Error while handling the anvil."
|
|
||||||
)
|
)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
@ -222,7 +219,7 @@ object DependencyManager {
|
||||||
val treatEvent = CATreatAnvilResultEvent(event, useType, result, cost)
|
val treatEvent = CATreatAnvilResultEvent(event, useType, result, cost)
|
||||||
try {
|
try {
|
||||||
unsafeTryTreatAnvilResult(treatEvent)
|
unsafeTryTreatAnvilResult(treatEvent)
|
||||||
return treatEvent;
|
return treatEvent
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
CustomAnvil.instance.logger.log(
|
CustomAnvil.instance.logger.log(
|
||||||
Level.SEVERE,
|
Level.SEVERE,
|
||||||
|
|
@ -235,8 +232,7 @@ object DependencyManager {
|
||||||
|
|
||||||
// Finally, warn the player, maybe a lot of time but better warn than do nothing
|
// Finally, warn the player, maybe a lot of time but better warn than do nothing
|
||||||
event.view.player.sendMessage(
|
event.view.player.sendMessage(
|
||||||
"[" + ChatColor.YELLOW.toString() + "CustomAnvil" + ChatColor.WHITE.toString() + "] " +
|
"${CustomAnvil.namePrefix} <red>Error while handling the anvil."
|
||||||
ChatColor.RED.toString() + "Error while handling the anvil."
|
|
||||||
)
|
)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
@ -264,8 +260,7 @@ object DependencyManager {
|
||||||
|
|
||||||
// Finally, warn the player, maybe a lot of time but better warn than do nothing
|
// Finally, warn the player, maybe a lot of time but better warn than do nothing
|
||||||
event.whoClicked.sendMessage(
|
event.whoClicked.sendMessage(
|
||||||
"[" + ChatColor.YELLOW.toString() + "CustomAnvil" + ChatColor.WHITE.toString() + "] " +
|
"[${CustomAnvil.namePrefix} <red>Error while handling the anvil."
|
||||||
ChatColor.RED.toString() + "Error while handling the anvil."
|
|
||||||
)
|
)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,13 @@
|
||||||
package xyz.alexcrea.cuanvil.util
|
package xyz.alexcrea.cuanvil.util
|
||||||
|
|
||||||
|
import net.kyori.adventure.text.Component
|
||||||
import net.kyori.adventure.text.TextComponent
|
import net.kyori.adventure.text.TextComponent
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage
|
import net.kyori.adventure.text.minimessage.MiniMessage
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver
|
||||||
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags
|
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags
|
||||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer
|
||||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer
|
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer
|
||||||
import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil
|
import org.jetbrains.annotations.Contract
|
||||||
|
|
||||||
object MiniMessageUtil {
|
object MiniMessageUtil {
|
||||||
|
|
||||||
|
|
@ -29,4 +30,20 @@ object MiniMessageUtil {
|
||||||
return legacy_mm.deserialize(legacyText)
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue