diff --git a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyCommands.kt b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyCommands.kt index aa3f04f..df55455 100644 --- a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyCommands.kt +++ b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyCommands.kt @@ -15,9 +15,7 @@ import com.mineinabyss.idofront.commands.extensions.actions.ensureSenderIsPlayer import com.mineinabyss.idofront.commands.extensions.actions.playerAction import com.mineinabyss.idofront.entities.toPlayer import com.mineinabyss.idofront.events.call -import com.mineinabyss.idofront.messaging.broadcast import com.mineinabyss.idofront.textcomponents.miniMsg -import com.mineinabyss.idofront.textcomponents.serialize import io.papermc.paper.event.player.AsyncChatDecorateEvent import kotlinx.coroutines.Job import kotlinx.coroutines.delay @@ -53,7 +51,7 @@ class ChattyCommands : IdofrontCommandExecutor(), TabCompleter { playerAction { val gearyPlayer = player.toGeary() val oldData = gearyPlayer.get() ?: return@playerAction - if (soundName in getAlternativePingSounds) { + if (soundName in alternativePingSounds) { gearyPlayer.setPersisting(oldData.copy(pingSound = soundName)) player.sendFormattedMessage(chatty.messages.ping.changedPingSound) } else player.sendFormattedMessage(chatty.messages.ping.invalidPingSound) @@ -83,7 +81,7 @@ class ChattyCommands : IdofrontCommandExecutor(), TabCompleter { } arguments.first().startsWith(chatty.config.nicknames.nickNameOtherPrefix) -> { - val otherPlayer = arguments.getPlayerToNick() + val otherPlayer = arguments.playerToNick() val otherNick = nick.removePlayerToNickFromString() when { @@ -173,19 +171,19 @@ class ChattyCommands : IdofrontCommandExecutor(), TabCompleter { ("global" / "g") { ensureSenderIsPlayer() action { - (sender as? Player)?.shortcutCommand(getGlobalChat(), arguments) + (sender as? Player)?.shortcutCommand(globalChannel(), arguments) } } ("local" / "l") { ensureSenderIsPlayer() action { - (sender as? Player)?.shortcutCommand(getRadiusChannel(), arguments) + (sender as? Player)?.shortcutCommand(radiusChannel(), arguments) } } ("admin" / "a") { ensureSenderIsPlayer() action { - (sender as? Player)?.shortcutCommand(getAdminChannel(), arguments) + (sender as? Player)?.shortcutCommand(adminChannel(), arguments) } } ("message" / "msg")(desc = "Private message another player") { @@ -241,7 +239,7 @@ class ChattyCommands : IdofrontCommandExecutor(), TabCompleter { 3 -> when { args[0] == "ping" && args[1] == "sound" -> - getAlternativePingSounds.filter { s -> s.startsWith(args[2], true) } + alternativePingSounds.filter { s -> s.startsWith(args[2], true) } args[0] == "nickname" -> args[1].drop(1).takeIf { args[1].startsWith(otherPrefix) && it.isNotEmpty() }?.toPlayer()?.let { player -> listOf(player.chattyNickname ?: player.name).filter { s -> s.startsWith(args[2], true) } diff --git a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/components/ChannelData.kt b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/components/ChannelData.kt index 60d9b2c..4b41689 100644 --- a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/components/ChannelData.kt +++ b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/components/ChannelData.kt @@ -2,7 +2,7 @@ package com.mineinabyss.chatty.components import com.mineinabyss.chatty.ChattyChannel import com.mineinabyss.chatty.chatty -import com.mineinabyss.chatty.helpers.getDefaultChat +import com.mineinabyss.chatty.helpers.defaultChannel import com.mineinabyss.idofront.serialization.UUIDSerializer import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -11,7 +11,7 @@ import java.util.* @Serializable @SerialName("chatty:chatty_data") data class ChannelData( - val channelId: String = getDefaultChat().key, + val channelId: String = defaultChannel().key, val lastChannelUsedId: String = channelId, val disablePingSound: Boolean = false, val pingSound: String? = null, @@ -22,7 +22,7 @@ data class ChannelData( fun withChannelVerified(): ChannelData { if (channelId !in chatty.config.channels) - return copy(channelId = getDefaultChat().key) + return copy(channelId = defaultChannel().key) return this } } diff --git a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/ChatHelpers.kt b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/ChatHelpers.kt index 09347fa..1392b21 100644 --- a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/ChatHelpers.kt +++ b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/ChatHelpers.kt @@ -1,28 +1,20 @@ package com.mineinabyss.chatty.helpers -import com.combimagnetron.imageloader.Avatar -import com.combimagnetron.imageloader.Image.ColorType -import com.combimagnetron.imageloader.ImageUtils import com.mineinabyss.chatty.ChattyChannel -import com.mineinabyss.chatty.ChattyConfig +import com.mineinabyss.chatty.ChattyConfig.Chat.FilterFormat import com.mineinabyss.chatty.chatty import com.mineinabyss.chatty.components.ChannelData -import com.mineinabyss.chatty.ChattyConfig.Chat.* -import com.mineinabyss.chatty.ChattyMessages import com.mineinabyss.chatty.components.ChannelType import com.mineinabyss.chatty.components.chattyNickname import com.mineinabyss.chatty.placeholders.chattyPlaceholderTags import com.mineinabyss.chatty.tags.ChattyTags import com.mineinabyss.geary.papermc.tracking.entities.toGearyOrNull -import com.mineinabyss.idofront.messaging.warn import com.mineinabyss.idofront.textcomponents.miniMsg import com.mineinabyss.idofront.textcomponents.serialize import me.clip.placeholderapi.PlaceholderAPI import net.kyori.adventure.audience.Audience import net.kyori.adventure.chat.SignedMessage -import net.kyori.adventure.key.Key import net.kyori.adventure.text.Component -import net.kyori.adventure.text.TextComponent import net.kyori.adventure.text.TextReplacementConfig import net.kyori.adventure.text.event.ClickEvent import net.kyori.adventure.text.event.HoverEvent @@ -31,28 +23,23 @@ import net.kyori.adventure.text.format.NamedTextColor import net.kyori.adventure.text.format.Style import net.kyori.adventure.text.format.TextDecoration import net.kyori.adventure.text.minimessage.MiniMessage -import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer import org.bukkit.Bukkit -import org.bukkit.OfflinePlayer import org.bukkit.Sound -import org.bukkit.SoundCategory import org.bukkit.entity.Player -import org.bukkit.inventory.ItemStack -import org.bukkit.profile.PlayerTextures.SkinModel import java.util.regex.Pattern -val getAlternativePingSounds: List = +val alternativePingSounds: List = chatty.config.ping.let { ping -> if ("*" in ping.alternativePingSounds || "all" in ping.alternativePingSounds) Sound.entries.map { it.key.toString() }.toList() else ping.alternativePingSounds } -val getPingEnabledChannels: List = - chatty.config.ping.let { ping -> if ("*" in ping.enabledChannels || "all" in ping.enabledChannels) getAllChannelNames() else ping.enabledChannels } +val pingEnabledChannels: List = + chatty.config.ping.let { ping -> if ("*" in ping.enabledChannels || "all" in ping.enabledChannels) channelNames() else ping.enabledChannels } fun String.checkForPlayerPings(channelId: String): Player? { val ping = chatty.config.ping - if (channelId !in getPingEnabledChannels || ping.pingPrefix.isEmpty() || ping.pingPrefix !in this) return null + if (channelId !in pingEnabledChannels || ping.pingPrefix.isEmpty() || ping.pingPrefix !in this) return null val pingedName = this.substringAfter(ping.pingPrefix).substringBefore(" ") return Bukkit.getOnlinePlayers().firstOrNull { it.name == pingedName } } @@ -87,21 +74,21 @@ fun Component.parseTags(player: Player? = null, ignorePermissions: Boolean = fal fun Component.removeTrailingSpaces() = this.replaceText(TextReplacementConfig.builder().match(" +\$").replacement("").build()) -fun getGlobalChat() = +fun globalChannel() = chatty.config.channels.entries.firstOrNull { it.value.channelType == ChannelType.GLOBAL } -fun getRadiusChannel() = +fun radiusChannel() = chatty.config.channels.entries.firstOrNull { it.value.channelType == ChannelType.RADIUS } -fun getAdminChannel() = +fun adminChannel() = chatty.config.channels.entries.firstOrNull { it.value.isStaffChannel } -fun getDefaultChat() = +fun defaultChannel() = chatty.config.channels.entries.firstOrNull { it.value.isDefaultChannel } - ?: getGlobalChat() + ?: globalChannel() ?: throw IllegalStateException("No Default or Global channel found") -fun getAllChannelNames() = chatty.config.channels.keys.toList() +fun channelNames() = chatty.config.channels.keys.toList() fun translatePlaceholders(player: Player?, message: String) = if (chatty.isPlaceholderApiLoaded) PlaceholderAPI.setPlaceholders(player, message) else message @@ -109,11 +96,6 @@ fun String.fixSerializedTags(): String = this.replaceAll("\\\\(?!u)(?!\")(?!:)", fun String.replaceAll(regex: String, replacement: String): String = Pattern.compile(regex).matcher(this).replaceAll(replacement) -fun String.fixLegacy(): Component { - return if ("ยง" in this) legacy.deserialize(this) - else this.fixSerializedTags().miniMsg() -} - fun List.toSentence() = this.joinToString(" ") fun String.toPlayer() = Bukkit.getPlayer(this) diff --git a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/NicknameHelpers.kt b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/NicknameHelpers.kt index ed3f89b..8cec7cb 100644 --- a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/NicknameHelpers.kt +++ b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/NicknameHelpers.kt @@ -2,7 +2,6 @@ package com.mineinabyss.chatty.helpers import com.mineinabyss.chatty.chatty import net.kyori.adventure.text.minimessage.MiniMessage -import org.bukkit.Bukkit import org.bukkit.entity.Player fun String.stripTags() = MiniMessage.miniMessage().stripTags(this) fun String.verifyNickLength(): Boolean { @@ -12,7 +11,7 @@ fun String.verifyNickLength(): Boolean { } } -fun List.getPlayerToNick(): Player? = +fun List.playerToNick(): Player? = this.first().replace(chatty.config.nicknames.nickNameOtherPrefix.toString(), "").toPlayer() fun String.removePlayerToNickFromString(): String = diff --git a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/PluginHelpers.kt b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/PluginHelpers.kt index 380763c..2b42cba 100644 --- a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/PluginHelpers.kt +++ b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/PluginHelpers.kt @@ -11,7 +11,6 @@ import net.kyori.adventure.text.Component import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer import org.bukkit.entity.Player -val legacy = LegacyComponentSerializer.builder().useUnusualXRepeatedCharacterHexFormat().build() fun GenericChattyDecorateEvent(player: Player, msg: Component) = AsyncChatDecorateEvent(true, player, msg, msg) fun GenericChattyChatEvent(player: Player, msg: Component) = diff --git a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/SkinHelpers.kt b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/SkinHelpers.kt index 7811f66..1586fc3 100644 --- a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/SkinHelpers.kt +++ b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/SkinHelpers.kt @@ -14,7 +14,7 @@ import org.bukkit.profile.PlayerTextures val playerHeadMapCache = mutableMapOf() fun OfflinePlayer.translatePlayerHeadComponent(): Component { if (this !in playerHeadMapCache || playerHeadMapCache[this]!!.font() != Key.key(chatty.config.playerHeadFont)) { - playerHeadMapCache[this] = runCatching { getPlayerHeadTexture(ascent = -5) }.getOrDefault(Component.empty()) + playerHeadMapCache[this] = runCatching { playerHeadTexture(ascent = -5) }.getOrDefault(Component.empty()) } return playerHeadMapCache[this] ?: Component.empty() } @@ -26,12 +26,12 @@ fun Player.refreshSkinInCaches() { } fun OfflinePlayer.translateFullPlayerSkinComponent(): Component { if (this !in playerBodyMapCache || playerBodyMapCache[this]!!.font() != Key.key(chatty.config.playerHeadFont)) { - playerBodyMapCache[this] = runCatching { getFullPlayerBodyTexture(ascent = -5) }.getOrDefault(Component.empty()) + playerBodyMapCache[this] = runCatching { fullPlayerBodyTexture(ascent = -5) }.getOrDefault(Component.empty()) } return playerBodyMapCache[this] ?: Component.empty() } -fun OfflinePlayer.getPlayerHeadTexture( +fun OfflinePlayer.playerHeadTexture( scale: Int = 1, ascent: Int = 0, colorType: Image.ColorType = Image.ColorType.MINIMESSAGE, @@ -41,7 +41,7 @@ fun OfflinePlayer.getPlayerHeadTexture( return "${ImageUtils.generateStringFromImage(image, colorType, ascent)}".miniMsg() } -fun OfflinePlayer.getFullPlayerBodyTexture( +fun OfflinePlayer.fullPlayerBodyTexture( scale: Int = 1, ascent: Int = 0, colorType: Image.ColorType = Image.ColorType.MINIMESSAGE, diff --git a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/placeholders/Placeholders.kt b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/placeholders/Placeholders.kt index a67d15b..6646269 100644 --- a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/placeholders/Placeholders.kt +++ b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/placeholders/Placeholders.kt @@ -4,7 +4,7 @@ import com.mineinabyss.chatty.chatty import com.mineinabyss.chatty.components.ChannelData import com.mineinabyss.chatty.components.SpyOnChannels import com.mineinabyss.chatty.components.chattyNickname -import com.mineinabyss.chatty.helpers.getAllChannelNames +import com.mineinabyss.chatty.helpers.channelNames import com.mineinabyss.chatty.helpers.translateFullPlayerSkinComponent import com.mineinabyss.chatty.helpers.translatePlayerHeadComponent import com.mineinabyss.geary.papermc.tracking.entities.toGeary @@ -22,7 +22,7 @@ fun chattyPlaceholders(player: Player?, string: String? = null): Map