diff --git a/src/main/kotlin/com/rose/gateway/discord/bot/extensions/chat/processing/ChannelMentionTokenProcessor.kt b/src/main/kotlin/com/rose/gateway/discord/bot/extensions/chat/processing/ChannelMentionTokenProcessor.kt index 90eed7a4..d4a89f2e 100644 --- a/src/main/kotlin/com/rose/gateway/discord/bot/extensions/chat/processing/ChannelMentionTokenProcessor.kt +++ b/src/main/kotlin/com/rose/gateway/discord/bot/extensions/chat/processing/ChannelMentionTokenProcessor.kt @@ -1,7 +1,8 @@ package com.rose.gateway.discord.bot.extensions.chat.processing import com.rose.gateway.config.PluginConfig -import com.rose.gateway.config.extensions.primaryColor +import com.rose.gateway.minecraft.component.component +import com.rose.gateway.minecraft.component.primaryComponent import com.rose.gateway.shared.parsing.TokenProcessor import dev.kord.common.entity.Snowflake import dev.kord.core.event.message.MessageCreateEvent @@ -28,8 +29,8 @@ class ChannelMentionTokenProcessor : TokenProcessor ") + "> ".component() ) } @@ -66,9 +68,9 @@ object DiscordMessageProcessor : KoinComponent { val referenceComponent = componentForReferencedMessage(event) ?: return Component.empty() return join( - ColorComponent.primary("(Replying to ").italic(), + "(Replying to ".primaryComponent().italic(), referenceComponent, - ColorComponent.primary(") ").italic() + ") ".primaryComponent().italic() ) } @@ -140,15 +142,15 @@ object DiscordMessageProcessor : KoinComponent { if (event.message.attachments.isEmpty()) return Component.empty() return join( - ColorComponent.primary(" (Attachments: ").italic(), - Component.join( - JoinConfiguration.separator(ColorComponent.primary(", ").italic()), + " (Attachments: ".primaryComponent().italic(), + join( + JoinConfiguration.separator(", ".primaryComponent().italic()), event.message.attachments.mapIndexed { index, attachment -> - ColorComponent.tertiary("Attachment$index").italic().underlined() - .showTextOnHover(Component.text("Open attachment link")).openUrlOnClick(attachment.url) + "Attachment$index".tertiaryComponent().italic().underlined() + .showTextOnHover("Open attachment link".component()).openUrlOnClick(attachment.url) } ), - ColorComponent.primary(")").italic() + ")".primaryComponent().italic() ) } } diff --git a/src/main/kotlin/com/rose/gateway/discord/bot/extensions/chat/processing/RoleMentionTokenProcessor.kt b/src/main/kotlin/com/rose/gateway/discord/bot/extensions/chat/processing/RoleMentionTokenProcessor.kt index ab208be6..d8578e0f 100644 --- a/src/main/kotlin/com/rose/gateway/discord/bot/extensions/chat/processing/RoleMentionTokenProcessor.kt +++ b/src/main/kotlin/com/rose/gateway/discord/bot/extensions/chat/processing/RoleMentionTokenProcessor.kt @@ -1,7 +1,8 @@ package com.rose.gateway.discord.bot.extensions.chat.processing import com.rose.gateway.config.PluginConfig -import com.rose.gateway.config.extensions.primaryColor +import com.rose.gateway.minecraft.component.component +import com.rose.gateway.minecraft.component.primaryComponent import com.rose.gateway.shared.parsing.TokenProcessor import dev.kord.common.entity.Snowflake import dev.kord.core.event.message.MessageCreateEvent @@ -32,8 +33,8 @@ class RoleMentionTokenProcessor : TokenProcessor, override suspend fun process(token: LixyToken, additionalData: MessageCreateEvent): Component { val snowflakeString = token.string.substring(SNOWFLAKE_START_INDEX until token.string.length - 1) val id = Snowflake(snowflakeString) - val role = additionalData.getGuild()!!.getRoleOrNull(id) ?: return Component.text(token.string) + val role = additionalData.getGuild()!!.getRoleOrNull(id) ?: return token.string.component() - return Component.text("@${role.name}", config.primaryColor()) + return "@${role.name}".primaryComponent() } } diff --git a/src/main/kotlin/com/rose/gateway/discord/bot/extensions/chat/processing/TextTokenProcessor.kt b/src/main/kotlin/com/rose/gateway/discord/bot/extensions/chat/processing/TextTokenProcessor.kt index 14aece7f..56238928 100644 --- a/src/main/kotlin/com/rose/gateway/discord/bot/extensions/chat/processing/TextTokenProcessor.kt +++ b/src/main/kotlin/com/rose/gateway/discord/bot/extensions/chat/processing/TextTokenProcessor.kt @@ -1,5 +1,6 @@ package com.rose.gateway.discord.bot.extensions.chat.processing +import com.rose.gateway.minecraft.component.component import com.rose.gateway.shared.parsing.TokenProcessor import dev.kord.core.event.message.MessageCreateEvent import guru.zoroark.lixy.LixyToken @@ -19,6 +20,6 @@ class TextTokenProcessor : TokenProcessor { override fun regexPattern(): String = ".[^<]*" override suspend fun process(token: LixyToken, additionalData: MessageCreateEvent): Component { - return Component.text(token.string) + return token.string.component() } } diff --git a/src/main/kotlin/com/rose/gateway/discord/bot/extensions/chat/processing/UrlTokenProcessor.kt b/src/main/kotlin/com/rose/gateway/discord/bot/extensions/chat/processing/UrlTokenProcessor.kt index 5c561f64..5296016c 100644 --- a/src/main/kotlin/com/rose/gateway/discord/bot/extensions/chat/processing/UrlTokenProcessor.kt +++ b/src/main/kotlin/com/rose/gateway/discord/bot/extensions/chat/processing/UrlTokenProcessor.kt @@ -1,13 +1,14 @@ package com.rose.gateway.discord.bot.extensions.chat.processing +import com.rose.gateway.minecraft.component.component +import com.rose.gateway.minecraft.component.openUrlOnClick +import com.rose.gateway.minecraft.component.showTextOnHover +import com.rose.gateway.minecraft.component.underlined import com.rose.gateway.shared.parsing.TokenProcessor import dev.kord.core.event.message.MessageCreateEvent import guru.zoroark.lixy.LixyToken import guru.zoroark.lixy.LixyTokenType import net.kyori.adventure.text.Component -import net.kyori.adventure.text.event.ClickEvent -import net.kyori.adventure.text.event.HoverEvent -import net.kyori.adventure.text.format.TextDecoration import org.intellij.lang.annotations.Language /** @@ -24,9 +25,8 @@ class UrlTokenProcessor : TokenProcessor { override suspend fun process(token: LixyToken, additionalData: MessageCreateEvent): Component { val url = token.string - return Component.text(url) - .decorate(TextDecoration.UNDERLINED) - .hoverEvent(HoverEvent.showText(Component.text("Click to open url"))) - .clickEvent(ClickEvent.openUrl(url)) + return url.component().underlined() + .showTextOnHover("Click to open url".component()) + .openUrlOnClick(url) } } diff --git a/src/main/kotlin/com/rose/gateway/discord/bot/extensions/chat/processing/UserMentionTokenProcessor.kt b/src/main/kotlin/com/rose/gateway/discord/bot/extensions/chat/processing/UserMentionTokenProcessor.kt index 95c407ab..40b4178b 100644 --- a/src/main/kotlin/com/rose/gateway/discord/bot/extensions/chat/processing/UserMentionTokenProcessor.kt +++ b/src/main/kotlin/com/rose/gateway/discord/bot/extensions/chat/processing/UserMentionTokenProcessor.kt @@ -3,6 +3,7 @@ package com.rose.gateway.discord.bot.extensions.chat.processing import com.rose.gateway.config.PluginConfig import com.rose.gateway.config.extensions.primaryColor import com.rose.gateway.minecraft.component.atMember +import com.rose.gateway.minecraft.component.component import com.rose.gateway.shared.parsing.TokenProcessor import dev.kord.common.entity.Snowflake import dev.kord.core.event.message.MessageCreateEvent @@ -33,7 +34,7 @@ class UserMentionTokenProcessor : TokenProcessor, override suspend fun process(token: LixyToken, additionalData: MessageCreateEvent): Component { val snowflakeString = token.string.substring(SNOWFLAKE_START_INDEX until token.string.length - 1) val id = Snowflake(snowflakeString) - val member = additionalData.getGuild()!!.getMemberOrNull(id) ?: return Component.text(token.string) + val member = additionalData.getGuild()!!.getMemberOrNull(id) ?: return token.string.component() return atMember(member, config.primaryColor()) } diff --git a/src/main/kotlin/com/rose/gateway/minecraft/CommandRegistry.kt b/src/main/kotlin/com/rose/gateway/minecraft/CommandRegistry.kt index 0212faf8..d316b966 100644 --- a/src/main/kotlin/com/rose/gateway/minecraft/CommandRegistry.kt +++ b/src/main/kotlin/com/rose/gateway/minecraft/CommandRegistry.kt @@ -11,7 +11,7 @@ import com.rose.gateway.minecraft.commands.framework.subcommand.subcommand import com.rose.gateway.minecraft.commands.runners.BotCommands import com.rose.gateway.minecraft.commands.runners.ConfigCommands import com.rose.gateway.minecraft.commands.runners.ConfigMonitoringRunner -import com.rose.gateway.minecraft.commands.runners.GeneralCommands +import com.rose.gateway.minecraft.commands.runners.DiscordCommands import org.koin.core.component.KoinComponent import org.koin.core.component.inject @@ -32,7 +32,7 @@ object CommandRegistry : KoinComponent { command("discord") { subcommand("help") { runner { context -> - GeneralCommands.discordHelp(context) + DiscordCommands.help(context) } } } diff --git a/src/main/kotlin/com/rose/gateway/minecraft/chat/processing/tokens/TextTokenProcessor.kt b/src/main/kotlin/com/rose/gateway/minecraft/chat/processing/tokens/TextTokenProcessor.kt index ff1c9f5e..0a6b3de3 100644 --- a/src/main/kotlin/com/rose/gateway/minecraft/chat/processing/tokens/TextTokenProcessor.kt +++ b/src/main/kotlin/com/rose/gateway/minecraft/chat/processing/tokens/TextTokenProcessor.kt @@ -1,10 +1,10 @@ package com.rose.gateway.minecraft.chat.processing.tokens import com.rose.gateway.minecraft.chat.processing.tokens.result.TokenProcessingResult +import com.rose.gateway.minecraft.component.component import com.rose.gateway.shared.parsing.TokenProcessor import guru.zoroark.lixy.LixyToken import guru.zoroark.lixy.LixyTokenType -import net.kyori.adventure.text.Component import org.intellij.lang.annotations.Language /** @@ -25,6 +25,6 @@ class TextTokenProcessor : TokenProcessor { override suspend fun process(token: LixyToken, additionalData: Unit): TokenProcessingResult { val text = token.string - return TokenProcessingResult(Component.text(text), text) + return TokenProcessingResult(text.component(), text) } } diff --git a/src/main/kotlin/com/rose/gateway/minecraft/chat/processing/tokens/UrlTokenProcessor.kt b/src/main/kotlin/com/rose/gateway/minecraft/chat/processing/tokens/UrlTokenProcessor.kt index 9b675b20..278d00aa 100644 --- a/src/main/kotlin/com/rose/gateway/minecraft/chat/processing/tokens/UrlTokenProcessor.kt +++ b/src/main/kotlin/com/rose/gateway/minecraft/chat/processing/tokens/UrlTokenProcessor.kt @@ -1,13 +1,13 @@ package com.rose.gateway.minecraft.chat.processing.tokens import com.rose.gateway.minecraft.chat.processing.tokens.result.TokenProcessingResult +import com.rose.gateway.minecraft.component.component +import com.rose.gateway.minecraft.component.openUrlOnClick +import com.rose.gateway.minecraft.component.showTextOnHover +import com.rose.gateway.minecraft.component.underlined import com.rose.gateway.shared.parsing.TokenProcessor import guru.zoroark.lixy.LixyToken import guru.zoroark.lixy.LixyTokenType -import net.kyori.adventure.text.Component -import net.kyori.adventure.text.event.ClickEvent -import net.kyori.adventure.text.event.HoverEvent -import net.kyori.adventure.text.format.TextDecoration import org.intellij.lang.annotations.Language /** @@ -27,10 +27,9 @@ class UrlTokenProcessor : TokenProcessor { override suspend fun process(token: LixyToken, additionalData: Unit): TokenProcessingResult { val url = token.string - val component = Component.text(url) - .decorate(TextDecoration.UNDERLINED) - .hoverEvent(HoverEvent.showText(Component.text("Click to open url"))) - .clickEvent(ClickEvent.openUrl(url)) + val component = url.component().underlined() + .showTextOnHover("Click to open url".component()) + .openUrlOnClick(url) return TokenProcessingResult(component, url) } diff --git a/src/main/kotlin/com/rose/gateway/minecraft/chat/processing/tokens/result/MentionResult.kt b/src/main/kotlin/com/rose/gateway/minecraft/chat/processing/tokens/result/MentionResult.kt index 9b0343a4..8178167c 100644 --- a/src/main/kotlin/com/rose/gateway/minecraft/chat/processing/tokens/result/MentionResult.kt +++ b/src/main/kotlin/com/rose/gateway/minecraft/chat/processing/tokens/result/MentionResult.kt @@ -4,8 +4,8 @@ import com.rose.gateway.config.PluginConfig import com.rose.gateway.config.extensions.primaryColor import com.rose.gateway.discord.bot.DiscordBot import com.rose.gateway.discord.bot.DiscordBotConstants -import com.rose.gateway.minecraft.component.ColorComponent import com.rose.gateway.minecraft.component.atMember +import com.rose.gateway.minecraft.component.primaryComponent import dev.kord.common.annotation.KordExperimental import kotlinx.coroutines.flow.firstOrNull import kotlinx.coroutines.flow.toSet @@ -28,7 +28,7 @@ object MentionResult : KoinComponent { */ fun mention(minecraftText: String, discordText: String): TokenProcessingResult { return TokenProcessingResult( - ColorComponent.primary(minecraftText), + minecraftText.primaryComponent(), discordText ) } diff --git a/src/main/kotlin/com/rose/gateway/minecraft/chat/processing/tokens/result/TokenProcessingResult.kt b/src/main/kotlin/com/rose/gateway/minecraft/chat/processing/tokens/result/TokenProcessingResult.kt index 8014d1b2..2794187a 100644 --- a/src/main/kotlin/com/rose/gateway/minecraft/chat/processing/tokens/result/TokenProcessingResult.kt +++ b/src/main/kotlin/com/rose/gateway/minecraft/chat/processing/tokens/result/TokenProcessingResult.kt @@ -1,6 +1,6 @@ package com.rose.gateway.minecraft.chat.processing.tokens.result -import com.rose.gateway.minecraft.component.ColorComponent +import com.rose.gateway.minecraft.component.warningComponent import net.kyori.adventure.text.Component /** @@ -23,7 +23,7 @@ data class TokenProcessingResult( */ fun error(text: String): TokenProcessingResult { return TokenProcessingResult( - ColorComponent.warning(text), + text.warningComponent(), text ) } diff --git a/src/main/kotlin/com/rose/gateway/minecraft/commands/runners/BotCommands.kt b/src/main/kotlin/com/rose/gateway/minecraft/commands/runners/BotCommands.kt index a8756903..554b0642 100644 --- a/src/main/kotlin/com/rose/gateway/minecraft/commands/runners/BotCommands.kt +++ b/src/main/kotlin/com/rose/gateway/minecraft/commands/runners/BotCommands.kt @@ -1,16 +1,16 @@ package com.rose.gateway.minecraft.commands.runners import com.rose.gateway.config.PluginConfig -import com.rose.gateway.config.extensions.primaryColor import com.rose.gateway.discord.bot.BotStatus import com.rose.gateway.discord.bot.DiscordBot import com.rose.gateway.minecraft.commands.framework.data.context.CommandExecuteContext import com.rose.gateway.minecraft.commands.framework.runner.NoArgs +import com.rose.gateway.minecraft.component.component +import com.rose.gateway.minecraft.component.joinSpace +import com.rose.gateway.minecraft.component.primaryComponent import com.rose.gateway.minecraft.logging.Logger import com.rose.gateway.shared.concurrency.PluginCoroutineScope import kotlinx.coroutines.launch -import net.kyori.adventure.text.Component -import net.kyori.adventure.text.JoinConfiguration import org.bukkit.command.CommandSender import org.koin.core.component.KoinComponent import org.koin.core.component.inject @@ -68,11 +68,10 @@ object BotCommands : KoinComponent { fun botStatus(context: CommandExecuteContext): Boolean { val status = bot.botStatus context.bukkit.sender.sendMessage( - Component.join( - JoinConfiguration.separator(Component.text(" ")), - Component.text("Bot Status:", config.primaryColor()), - Component.text(status.status), - Component.text(if (status.reason.isEmpty()) "" else "(${status.reason})") + joinSpace( + "Bot Status:".primaryComponent(), + status.status.component(), + (if (status.reason.isEmpty()) "" else "(${status.reason})").component() ) ) diff --git a/src/main/kotlin/com/rose/gateway/minecraft/commands/runners/ConfigCommands.kt b/src/main/kotlin/com/rose/gateway/minecraft/commands/runners/ConfigCommands.kt index 9b1937f0..83011f7b 100644 --- a/src/main/kotlin/com/rose/gateway/minecraft/commands/runners/ConfigCommands.kt +++ b/src/main/kotlin/com/rose/gateway/minecraft/commands/runners/ConfigCommands.kt @@ -6,10 +6,11 @@ import com.rose.gateway.minecraft.commands.arguments.ConfigListArgs import com.rose.gateway.minecraft.commands.framework.data.context.CommandExecuteContext import com.rose.gateway.minecraft.commands.framework.runner.ArgParser import com.rose.gateway.minecraft.commands.parsers.StringParser -import com.rose.gateway.minecraft.component.ColorComponent +import com.rose.gateway.minecraft.component.component import com.rose.gateway.minecraft.component.italic import com.rose.gateway.minecraft.component.joinSpace -import net.kyori.adventure.text.Component +import com.rose.gateway.minecraft.component.secondaryComponent +import com.rose.gateway.minecraft.component.tertiaryComponent import org.bukkit.command.CommandSender /** @@ -19,17 +20,14 @@ object ConfigCommands { /** * Command that sets the value of a config item * - * @param ConfigValueType The type of the config value to modify - * @param ArgsType The type of the config args in the command context - * @param ValueParserType The type of the parser for the config value + * @param T The type of the config value to modify + * @param A The type of the config args in the command context + * @param P The type of the parser for the config value * @param context The command context with the config args * @return Whether the command succeeded */ - fun < - ConfigValueType, - ArgsType : ConfigArgs, - ValueParserType : ArgParser> setConfig( - context: CommandExecuteContext + fun , P : ArgParser> setConfig( + context: CommandExecuteContext ): Boolean { val args = context.args val item = args.item @@ -52,10 +50,10 @@ object ConfigCommands { private fun sendConfirmation(sender: CommandSender, item: Item, value: T) { sender.sendMessage( joinSpace( - ColorComponent.tertiary(item.path).italic(), - Component.text("set to"), - ColorComponent.secondary(value.toString()).italic(), - Component.text("successfully!") + item.path.tertiaryComponent().italic(), + "set to".component(), + value.toString().secondaryComponent().italic(), + "successfully!".component() ) ) } @@ -63,17 +61,14 @@ object ConfigCommands { /** * Command that adds value to a config list item * - * @param ConfigValueType The type of the config item - * @param ListArgsType The type of the list args in the command context - * @param ValueParserType The type of the parser for the config values + * @param T The type of the config item + * @param A The type of the list args in the command context + * @param P The type of the parser for the config values * @param context The command context with the config list args * @return Whether the command succeeded */ - fun < - ConfigValueType, - ListArgsType : ConfigListArgs, - ValueParserType : StringParser> addConfiguration( - context: CommandExecuteContext + fun , P : StringParser> addConfiguration( + context: CommandExecuteContext ): Boolean { val configItem = context.args.item val values = context.args.value @@ -109,10 +104,10 @@ object ConfigCommands { private fun sendAddConfirmation(sender: CommandSender, item: Item, values: T) { sender.sendMessage( joinSpace( - ColorComponent.secondary(values.toString()).italic(), - Component.text("added to"), - ColorComponent.tertiary(item.path).italic(), - Component.text("successfully!") + values.toString().secondaryComponent().italic(), + "added to".component(), + item.path.tertiaryComponent().italic(), + "successfully!".component() ) ) } @@ -120,17 +115,14 @@ object ConfigCommands { /** * Command that removes values from a config list item * - * @param ConfigValueType The type of the config item - * @param ListArgsType The type of the list args in the command context - * @param ValueParserType The type of the parser for the config values + * @param T The type of the config item + * @param A The type of the list args in the command context + * @param P The type of the parser for the config values * @param context The command context with the config list args * @return Whether the command succeeded */ - fun < - ConfigValueType, - ListArgsType : ConfigListArgs, - ValueParserType : StringParser> removeConfiguration( - context: CommandExecuteContext + fun , P : StringParser> removeConfiguration( + context: CommandExecuteContext ): Boolean { val configItem = context.args.item val values = context.args.value @@ -166,10 +158,10 @@ object ConfigCommands { private fun sendRemoveConfirmation(sender: CommandSender, item: Item, values: T) { sender.sendMessage( joinSpace( - ColorComponent.secondary(values.toString()).italic(), - Component.text("removed from"), - ColorComponent.tertiary(item.path).italic(), - Component.text("successfully!") + values.toString().secondaryComponent().italic(), + "removed from".component(), + item.path.tertiaryComponent().italic(), + "successfully!".component() ) ) } diff --git a/src/main/kotlin/com/rose/gateway/minecraft/commands/runners/ConfigMonitoringRunner.kt b/src/main/kotlin/com/rose/gateway/minecraft/commands/runners/ConfigMonitoringRunner.kt index da16e878..f5b4fc12 100644 --- a/src/main/kotlin/com/rose/gateway/minecraft/commands/runners/ConfigMonitoringRunner.kt +++ b/src/main/kotlin/com/rose/gateway/minecraft/commands/runners/ConfigMonitoringRunner.kt @@ -6,16 +6,20 @@ import com.rose.gateway.config.PluginConfig import com.rose.gateway.minecraft.commands.arguments.ConfigItemArgs import com.rose.gateway.minecraft.commands.framework.data.context.CommandExecuteContext import com.rose.gateway.minecraft.commands.framework.runner.NoArgs -import com.rose.gateway.minecraft.component.ColorComponent +import com.rose.gateway.minecraft.component.component import com.rose.gateway.minecraft.component.italic import com.rose.gateway.minecraft.component.item import com.rose.gateway.minecraft.component.join import com.rose.gateway.minecraft.component.joinNewLine import com.rose.gateway.minecraft.component.joinSpace import com.rose.gateway.minecraft.component.plus +import com.rose.gateway.minecraft.component.primaryComponent import com.rose.gateway.minecraft.component.runCommandOnClick +import com.rose.gateway.minecraft.component.secondaryComponent import com.rose.gateway.minecraft.component.showTextOnHover +import com.rose.gateway.minecraft.component.tertiaryComponent import com.rose.gateway.minecraft.component.underlined +import com.rose.gateway.minecraft.component.warningComponent import com.rose.gateway.shared.concurrency.PluginCoroutineScope import com.rose.gateway.shared.reflection.simpleName import kotlinx.coroutines.launch @@ -52,12 +56,12 @@ object ConfigMonitoringRunner : KoinComponent { */ private fun sendConfigListHelp(sender: CommandSender, items: List) { val configs = items.map { config -> - Component.text("* ") + item(config) + "* ".component() + item(config) } sender.sendMessage( joinNewLine( - ColorComponent.primary("Available Configurations: "), + "Available Configurations: ".primaryComponent(), joinNewLine(configs) ) ) @@ -111,8 +115,8 @@ object ConfigMonitoringRunner : KoinComponent { sender.sendMessage( joinSpace( - ColorComponent.primary("Config Status:"), - Component.text(configStatus) + "Config Status:".primaryComponent(), + configStatus.component() ) ) @@ -141,17 +145,17 @@ object ConfigMonitoringRunner : KoinComponent { */ private fun itemHelpMessage(item: Item<*>): Component { return joinNewLine( - ColorComponent.primary("Configuration Help:"), - ColorComponent.primary("Name: ") + ColorComponent.tertiary(item.path).italic(), + "Configuration Help:".primaryComponent(), + "Name: ".primaryComponent() + item.path.tertiaryComponent().italic(), join( - ColorComponent.primary("Type: "), - Component.text(item.type.simpleName), - ColorComponent.warning(if (item.type.isMarkedNullable) "?" else "") + "Type: ".primaryComponent(), + item.type.simpleName.component(), + (if (item.type.isMarkedNullable) "?" else "").warningComponent() ), - ColorComponent.primary("Current Value: ") + Component.text(item.value.toString()), - ColorComponent.primary("Description: ") + Component.text(item.description), - ColorComponent.secondary("View All Configurations").underlined().italic() - .showTextOnHover(Component.text("Click to view all configurations.")) + "Current Value: ".primaryComponent() + item.value.toString().component(), + "Description: ".primaryComponent() + item.description.component(), + "View All Configurations".secondaryComponent().underlined().italic() + .showTextOnHover("Click to view all configurations.".component()) .runCommandOnClick("/gateway config help") ) } diff --git a/src/main/kotlin/com/rose/gateway/minecraft/commands/runners/DiscordCommands.kt b/src/main/kotlin/com/rose/gateway/minecraft/commands/runners/DiscordCommands.kt new file mode 100644 index 00000000..11486af4 --- /dev/null +++ b/src/main/kotlin/com/rose/gateway/minecraft/commands/runners/DiscordCommands.kt @@ -0,0 +1,53 @@ +package com.rose.gateway.minecraft.commands.runners + +import com.rose.gateway.minecraft.commands.framework.data.context.CommandExecuteContext +import com.rose.gateway.minecraft.commands.framework.runner.NoArgs +import com.rose.gateway.minecraft.component.component +import com.rose.gateway.minecraft.component.joinNewLine +import com.rose.gateway.minecraft.component.joinSpace +import com.rose.gateway.minecraft.component.plus +import com.rose.gateway.minecraft.component.primaryComponent +import com.rose.gateway.minecraft.component.secondaryComponent +import com.rose.gateway.minecraft.component.showTextOnHover + +/** + * General plugin commands + */ +object DiscordCommands { + private val USER_HELP_MESSAGE = "Mention the closest matching Discord user".component() + private val USER_QUOTE_HELP_MESSAGE = USER_HELP_MESSAGE + " and allow spaces in their name".component() + + private val ROLE_HELP_MESSAGE = "Mention a Discord role".component() + private val ROLE_QUOTE_HELP_MESSAGE = ROLE_HELP_MESSAGE + " and allow spaces in its name".component() + + private val TEXT_CHANNEL_HELP_MESSAGE = "Mention a Discord text channel".component() + private val VOICE_CHANNEL_HELP_MESSAGE = "Mention a Discord voice channel".component() + + /** + * Sends the sender help for chat messages in Discord + * + * @param context A command context without arguments + * @return Whether the command succeeded + */ + fun help(context: CommandExecuteContext): Boolean { + context.bukkit.sender.sendMessage( + joinNewLine( + "Discord mentions:".primaryComponent(), + joinSpace( + "@USER".secondaryComponent().showTextOnHover(USER_HELP_MESSAGE), + "or".component(), + "@\"USER\"".secondaryComponent().showTextOnHover(USER_QUOTE_HELP_MESSAGE) + ), + joinSpace( + "@R=ROLE".secondaryComponent().showTextOnHover(ROLE_HELP_MESSAGE), + "or".component(), + "@R=\"ROLE\"".secondaryComponent().showTextOnHover(ROLE_QUOTE_HELP_MESSAGE) + ), + "@C=TEXT_CHANNEL".secondaryComponent().showTextOnHover(TEXT_CHANNEL_HELP_MESSAGE), + "@V=VOICE_CHANNEL".secondaryComponent().showTextOnHover(VOICE_CHANNEL_HELP_MESSAGE) + ) + ) + + return true + } +} diff --git a/src/main/kotlin/com/rose/gateway/minecraft/commands/runners/GeneralCommands.kt b/src/main/kotlin/com/rose/gateway/minecraft/commands/runners/GeneralCommands.kt deleted file mode 100644 index 40b23109..00000000 --- a/src/main/kotlin/com/rose/gateway/minecraft/commands/runners/GeneralCommands.kt +++ /dev/null @@ -1,30 +0,0 @@ -package com.rose.gateway.minecraft.commands.runners - -import com.rose.gateway.minecraft.commands.framework.data.context.CommandExecuteContext -import com.rose.gateway.minecraft.commands.framework.runner.NoArgs - -/** - * General plugin commands - */ -object GeneralCommands { - /** - * Command that sends the sender help for sending messages to Discord - * - * @param context A command context without arguments - * @return Whether the command succeeded - */ - fun discordHelp(context: CommandExecuteContext): Boolean { - context.bukkit.sender.sendMessage( - """ - You can mention in Discord in the following ways: - Include @USER or @"USER" to mention a user. - ^ Matches closest user. - Include @R=ROLE or @R="ROLE" to mention a role. - Include @C=TEXT_CHANNEL to mention a text channel. - Include @V=VOICE_CHANNEL to mention a voice channel. - """.trimIndent() - ) - - return true - } -} diff --git a/src/main/kotlin/com/rose/gateway/minecraft/component/Color.kt b/src/main/kotlin/com/rose/gateway/minecraft/component/Color.kt new file mode 100644 index 00000000..a72a6eb8 --- /dev/null +++ b/src/main/kotlin/com/rose/gateway/minecraft/component/Color.kt @@ -0,0 +1,45 @@ +package com.rose.gateway.minecraft.component + +import com.rose.gateway.config.PluginConfig +import com.rose.gateway.config.extensions.primaryColor +import com.rose.gateway.config.extensions.secondaryColor +import com.rose.gateway.config.extensions.tertiaryColor +import com.rose.gateway.config.extensions.warningColor +import net.kyori.adventure.text.Component +import org.koin.core.component.KoinComponent +import org.koin.core.component.inject + +/** + * Contains functions for modifying components with configured plugin colors + */ +object Color : KoinComponent { + private val config: PluginConfig by inject() + + /** + * Apply the primary color to the component + * + * @return The colored component + */ + public fun Component.primary(): Component = this.color(config.primaryColor()) + + /** + * Apply the secondary color to the component + * + * @return The colored component + */ + public fun Component.secondary(): Component = this.color(config.secondaryColor()) + + /** + * Apply the tertiary color to the component + * + * @return The colored component + */ + public fun Component.tertiary(): Component = this.color(config.tertiaryColor()) + + /** + * Apply the warning color to the component + * + * @return The colored component + */ + public fun Component.warning(): Component = this.color(config.warningColor()) +} diff --git a/src/main/kotlin/com/rose/gateway/minecraft/component/ColorComponent.kt b/src/main/kotlin/com/rose/gateway/minecraft/component/ColorComponent.kt deleted file mode 100644 index b67602ba..00000000 --- a/src/main/kotlin/com/rose/gateway/minecraft/component/ColorComponent.kt +++ /dev/null @@ -1,57 +0,0 @@ -package com.rose.gateway.minecraft.component - -import com.rose.gateway.config.PluginConfig -import com.rose.gateway.config.extensions.primaryColor -import com.rose.gateway.config.extensions.secondaryColor -import com.rose.gateway.config.extensions.tertiaryColor -import com.rose.gateway.config.extensions.warningColor -import net.kyori.adventure.text.Component -import org.koin.core.component.KoinComponent -import org.koin.core.component.inject - -/** - * Provides functions that create colored [Component]s based on the plugin config - */ -object ColorComponent : KoinComponent { - private val config: PluginConfig by inject() - - /** - * Creates a text [Component] with the configured primary color - * - * @param text The text to create the [Component] with - * @return The colored [Component] - */ - fun primary(text: String): Component { - return Component.text(text, config.primaryColor()) - } - - /** - * Creates a text [Component] with the configured secondary color - * - * @param text The text to create the [Component] with - * @return The colored [Component] - */ - fun secondary(text: String): Component { - return Component.text(text, config.secondaryColor()) - } - - /** - * Creates a text [Component] with the configured tertiary color - * - * @param text The text to create the [Component] with - * @return The colored [Component] - */ - fun tertiary(text: String): Component { - return Component.text(text, config.tertiaryColor()) - } - - /** - * Creates a text [Component] with the configured warning color - * - * @param text The text to create the [Component] with - * @return The colored [Component] - */ - fun warning(text: String): Component { - return Component.text(text, config.warningColor()) - } -} diff --git a/src/main/kotlin/com/rose/gateway/minecraft/component/ComponentJoiner.kt b/src/main/kotlin/com/rose/gateway/minecraft/component/ComponentJoiner.kt index 945bec7d..c156c90e 100644 --- a/src/main/kotlin/com/rose/gateway/minecraft/component/ComponentJoiner.kt +++ b/src/main/kotlin/com/rose/gateway/minecraft/component/ComponentJoiner.kt @@ -9,9 +9,7 @@ import net.kyori.adventure.text.JoinConfiguration * @param secondComponent The [Component] to append to the first * @return The first [Component] with the second appended */ -operator fun Component.plus(secondComponent: Component): Component { - return this.append(secondComponent) -} +operator fun Component.plus(secondComponent: Component): Component = join(this, secondComponent) /** * Joins multiple [Component]s into one without separators @@ -19,9 +17,20 @@ operator fun Component.plus(secondComponent: Component): Component { * @param components The [Component]s to combine * @return The new, joined [Component] */ -fun join(vararg components: Component): Component = Component.join( +fun join(vararg components: Component): Component = join( JoinConfiguration.noSeparators(), - *components + components.toList() +) + +/** + * Joins multiple [Component]s into one with given separators + * + * @param components The [Component]s to combine + * @return The new, joined [Component] + */ +fun join(joinConfig: JoinConfiguration, components: Collection): Component = Component.join( + joinConfig, + components ) /** @@ -30,20 +39,31 @@ fun join(vararg components: Component): Component = Component.join( * @param components The [Component]s to combine * @return The new, joined [Component] */ -fun join(components: Collection): Component = Component.join( +fun join(components: Collection): Component = join( JoinConfiguration.noSeparators(), components ) +/** + * Joins multiple [Component]s into one without separators + * + * @param components The [Component]s to combine + * @return The new, joined [Component] + */ +fun join(joinConfig: JoinConfiguration, vararg components: Component): Component = join( + joinConfig, + components.asList() +) + /** * Joins multiple [Component]s into one with new lines as separators * * @param components The [Component]s to combine * @return The new, joined [Component] */ -fun joinNewLine(vararg components: Component): Component = Component.join( +fun joinNewLine(vararg components: Component): Component = join( JoinConfiguration.newlines(), - *components + components.asList() ) /** @@ -52,7 +72,7 @@ fun joinNewLine(vararg components: Component): Component = Component.join( * @param components The [Component]s to combine * @return The new, joined [Component] */ -fun joinNewLine(components: Collection): Component = Component.join( +fun joinNewLine(components: Collection): Component = join( JoinConfiguration.newlines(), components ) @@ -63,7 +83,7 @@ fun joinNewLine(components: Collection): Component = Component.join( * @param components The [Component]s to combine * @return The new, joined [Component] */ -fun joinSpace(vararg components: Component): Component = Component.join( - JoinConfiguration.separator(Component.text(" ")), - *components +fun joinSpace(vararg components: Component): Component = join( + JoinConfiguration.separator(" ".component()), + components.asList() ) diff --git a/src/main/kotlin/com/rose/gateway/minecraft/component/DiscordComponent.kt b/src/main/kotlin/com/rose/gateway/minecraft/component/DiscordComponent.kt index f5cee64c..3cee16cc 100644 --- a/src/main/kotlin/com/rose/gateway/minecraft/component/DiscordComponent.kt +++ b/src/main/kotlin/com/rose/gateway/minecraft/component/DiscordComponent.kt @@ -12,7 +12,7 @@ import net.kyori.adventure.text.format.TextColor * @return The at [Component] */ fun atMember(user: Member, userColor: TextColor): Component { - return ColorComponent.primary("@") + member(user).color(userColor) + return "@".primaryComponent() + member(user).color(userColor) } /** @@ -22,6 +22,6 @@ fun atMember(user: Member, userColor: TextColor): Component { * @return The member [Component] */ fun member(user: Member): Component { - return ColorComponent.secondary(user.displayName) - .showTextOnHover(Component.text("Username: ") + ColorComponent.primary(user.username).italic()) + return user.displayName.secondaryComponent() + .showTextOnHover("Username: ".component() + user.username.primaryComponent().italic()) } diff --git a/src/main/kotlin/com/rose/gateway/minecraft/component/Item.kt b/src/main/kotlin/com/rose/gateway/minecraft/component/Item.kt index af3268d5..5696dc1b 100644 --- a/src/main/kotlin/com/rose/gateway/minecraft/component/Item.kt +++ b/src/main/kotlin/com/rose/gateway/minecraft/component/Item.kt @@ -9,7 +9,7 @@ import net.kyori.adventure.text.Component * @return The config item [Component] */ fun item(itemName: String): Component { - return ColorComponent.tertiary(itemName).italic().showTextOnHover( - Component.text("Get help for ") + ColorComponent.tertiary(itemName).italic() + return itemName.tertiaryComponent().italic().showTextOnHover( + "Get help for ".component() + itemName.tertiaryComponent().italic() ).runCommandOnClick("/gateway config help $itemName") } diff --git a/src/main/kotlin/com/rose/gateway/minecraft/component/TextComponent.kt b/src/main/kotlin/com/rose/gateway/minecraft/component/TextComponent.kt new file mode 100644 index 00000000..c8eba1e6 --- /dev/null +++ b/src/main/kotlin/com/rose/gateway/minecraft/component/TextComponent.kt @@ -0,0 +1,42 @@ +package com.rose.gateway.minecraft.component + +import com.rose.gateway.minecraft.component.Color.primary +import com.rose.gateway.minecraft.component.Color.secondary +import com.rose.gateway.minecraft.component.Color.tertiary +import com.rose.gateway.minecraft.component.Color.warning +import net.kyori.adventure.text.Component + +/** + * Creates a [Component] for this string + * + * @return The created [Component] + */ +fun String.component(): Component = Component.text(this) + +/** + * Creates a [Component] in the configured primary color + * + * @return The created [Component] + */ +fun String.primaryComponent(): Component = this.component().primary() + +/** + * Creates a [Component] in the configured secondary color + * + * @return The created [Component] + */ +fun String.secondaryComponent(): Component = this.component().secondary() + +/** + * Creates a [Component] in the configured tertiary color + * + * @return The created [Component] + */ +fun String.tertiaryComponent(): Component = this.component().tertiary() + +/** + * Creates a [Component] in the configured warning color + * + * @return The created [Component] + */ +fun String.warningComponent(): Component = this.component().warning() diff --git a/src/main/kotlin/com/rose/gateway/minecraft/whitelist/Whitelist.kt b/src/main/kotlin/com/rose/gateway/minecraft/whitelist/Whitelist.kt index 3f43f4cf..bf3b5264 100644 --- a/src/main/kotlin/com/rose/gateway/minecraft/whitelist/Whitelist.kt +++ b/src/main/kotlin/com/rose/gateway/minecraft/whitelist/Whitelist.kt @@ -1,8 +1,8 @@ package com.rose.gateway.minecraft.whitelist +import com.rose.gateway.minecraft.component.component import com.rose.gateway.minecraft.server.Console import com.rose.gateway.minecraft.server.Scheduler -import net.kyori.adventure.text.Component import org.bukkit.Bukkit import org.bukkit.OfflinePlayer @@ -57,7 +57,7 @@ object Whitelist { // Preventing an op from being kicked // because the whitelist always allows ops when they join the game if (!player.isOp) { - player.player?.kick(Component.text("Removed from whitelist.")) + player.player?.kick("Removed from whitelist.".component()) } }