From 32077bc9c1ccda5174e212bebbf5931e4cd7d6db Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Sat, 6 Apr 2024 09:59:33 -0600 Subject: [PATCH 01/24] Added 'setchatnamecolor' command --- .../com/rpkit/chat/bukkit/RPKChatBukkit.kt | 3 + .../bukkit/chatchannel/RPKChatChannelImpl.kt | 26 ++++ .../format/part/GenericTextPart.kt | 2 +- .../SetChatNameColorCommand.kt | 126 ++++++++++++++++++ .../database/table/RPKChatNameColorTable.kt | 92 +++++++++++++ .../migrations/mysql/V2__Chat_name_colors.sql | 22 +++ .../sqlite/V2__Chat_name_colors.sql | 22 +++ .../src/main/resources/messages.yml | 8 +- .../src/main/resources/plugin.yml | 6 + 9 files changed, 305 insertions(+), 2 deletions(-) create mode 100644 bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/command/setchatnamecolor/SetChatNameColorCommand.kt create mode 100644 bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/database/table/RPKChatNameColorTable.kt create mode 100644 bukkit/rpk-chat-bukkit/src/main/resources/com/rpkit/chat/migrations/mysql/V2__Chat_name_colors.sql create mode 100644 bukkit/rpk-chat-bukkit/src/main/resources/com/rpkit/chat/migrations/sqlite/V2__Chat_name_colors.sql diff --git a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/RPKChatBukkit.kt b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/RPKChatBukkit.kt index 296a28c13..bca831433 100644 --- a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/RPKChatBukkit.kt +++ b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/RPKChatBukkit.kt @@ -37,6 +37,7 @@ import com.rpkit.chat.bukkit.command.listchatchannels.ListChatChannelsCommand import com.rpkit.chat.bukkit.command.message.MessageCommand import com.rpkit.chat.bukkit.command.mute.MuteCommand import com.rpkit.chat.bukkit.command.reply.ReplyCommand +import com.rpkit.chat.bukkit.command.setchatnamecolor.SetChatNameColorCommand import com.rpkit.chat.bukkit.command.snoop.SnoopCommand import com.rpkit.chat.bukkit.command.unmute.UnmuteCommand import com.rpkit.chat.bukkit.database.table.* @@ -182,6 +183,7 @@ class RPKChatBukkit : JavaPlugin(), RPKPlugin { database.addTable(RPKChatGroupMemberTable(database, this)) database.addTable(RPKLastUsedChatGroupTable(database, this)) database.addTable(RPKSnooperTable(database, this)) + database.addTable(RPKChatNameColorTable(database, this)) // Class loader needs to be the plugin's class loader in order for ServiceLoader in slf4j to be able to find // the SLF4JLoggerProvider implementation, as the remapped slf4j-jdk14 is loaded by the plugin's class loader @@ -233,6 +235,7 @@ class RPKChatBukkit : JavaPlugin(), RPKPlugin { getCommand("message")?.setExecutor(MessageCommand(this)) getCommand("reply")?.setExecutor(ReplyCommand(this)) getCommand("snoop")?.setExecutor(SnoopCommand(this)) + getCommand("setchatnamecolor")?.setExecutor(SetChatNameColorCommand(this)) Services[RPKChatChannelService::class.java]?.chatChannels?.forEach { chatChannel -> getDynamicCommand(chatChannel.name.value).setExecutor(QuickChatChannelCommand(this, chatChannel).toBukkit()) } diff --git a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/RPKChatChannelImpl.kt b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/RPKChatChannelImpl.kt index 0023580fc..15764136f 100644 --- a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/RPKChatChannelImpl.kt +++ b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/RPKChatChannelImpl.kt @@ -21,12 +21,14 @@ import com.rpkit.chat.bukkit.chatchannel.context.DirectedPostFormatMessageContex import com.rpkit.chat.bukkit.chatchannel.context.DirectedPreFormatMessageContextImpl import com.rpkit.chat.bukkit.chatchannel.context.UndirectedMessageContextImpl import com.rpkit.chat.bukkit.chatchannel.format.FormatPart +import com.rpkit.chat.bukkit.chatchannel.format.part.SenderCharacterNamePart import com.rpkit.chat.bukkit.chatchannel.pipeline.DirectedPostFormatPipelineComponent import com.rpkit.chat.bukkit.chatchannel.pipeline.DirectedPreFormatPipelineComponent import com.rpkit.chat.bukkit.chatchannel.pipeline.UndirectedPipelineComponent import com.rpkit.chat.bukkit.context.DirectedPostFormatMessageContext import com.rpkit.chat.bukkit.context.DirectedPreFormatMessageContext import com.rpkit.chat.bukkit.context.UndirectedMessageContext +import com.rpkit.chat.bukkit.database.table.RPKChatNameColorTable import com.rpkit.chat.bukkit.event.chatchannel.RPKBukkitChatChannelMessageEvent import com.rpkit.chat.bukkit.mute.RPKChatChannelMuteService import com.rpkit.chat.bukkit.speaker.RPKChatChannelSpeakerService @@ -169,6 +171,9 @@ class RPKChatChannelImpl( format.flatMap { part -> part.toChatComponents(preFormatContext).join().toList() }.toTypedArray(), preFormatContext.isCancelled ) + if (senderMinecraftProfile != null) { + setSenderCharacterNamePartColor(senderMinecraftProfile) + }; directedPostFormatPipeline.forEach { component -> postFormatContext = component.process(postFormatContext).join() } @@ -190,4 +195,25 @@ class RPKChatChannelImpl( }) } + private fun setSenderCharacterNamePartColor(senderMinecraftProfile: RPKMinecraftProfile) { + val minecraftProfileId = senderMinecraftProfile.id ?: return + val recordExists = plugin.database.getTable(RPKChatNameColorTable::class.java)[minecraftProfileId].join() != null + if (recordExists) { + val senderCharacterNamePart = getSenderCharacterNamePart() ?: return + val chatNameColorRecord = plugin.database.getTable(RPKChatNameColorTable::class.java)[minecraftProfileId].join() + if (chatNameColorRecord != null) { + senderCharacterNamePart.color = chatNameColorRecord.chatNameColor + } + } + } + + private fun getSenderCharacterNamePart(): SenderCharacterNamePart? { + for (part in format) { + if (part is SenderCharacterNamePart) { + return part + } + } + return null + } + } \ No newline at end of file diff --git a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/GenericTextPart.kt b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/GenericTextPart.kt index 5d75c4aad..7f4bf80a1 100644 --- a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/GenericTextPart.kt +++ b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/GenericTextPart.kt @@ -30,7 +30,7 @@ import java.util.logging.Level abstract class GenericTextPart( private val plugin: RPKChatBukkit, val font: String? = null, - val color: String? = null, + var color: String? = null, val isBold: Boolean? = null, val isItalic: Boolean? = null, val isUnderlined: Boolean? = null, diff --git a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/command/setchatnamecolor/SetChatNameColorCommand.kt b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/command/setchatnamecolor/SetChatNameColorCommand.kt new file mode 100644 index 000000000..6b0f0b613 --- /dev/null +++ b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/command/setchatnamecolor/SetChatNameColorCommand.kt @@ -0,0 +1,126 @@ +/* + * Copyright 2020 Ren Binden + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.rpkit.chat.bukkit.command.setchatnamecolor + +import com.rpkit.chat.bukkit.RPKChatBukkit +import com.rpkit.chat.bukkit.database.table.RPKChatNameColorTable +import com.rpkit.core.service.Services +import com.rpkit.players.bukkit.profile.minecraft.RPKMinecraftProfileId +import com.rpkit.players.bukkit.profile.minecraft.RPKMinecraftProfileService +import org.bukkit.command.Command +import org.bukkit.command.CommandExecutor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player +import java.util.concurrent.CompletableFuture +import java.util.concurrent.CompletableFuture.runAsync + +/** + * SetChatNameColor command. + * Sets the chat color name for a player. + */ +class SetChatNameColorCommand(private val plugin: RPKChatBukkit) : CommandExecutor { + + override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array): Boolean { + if (!sender.hasPermission("rpkit.chat.command.setchatnamecolor")) { + sender.sendMessage(plugin.messages["no-permission-setchatnamecolor"]) + return true + } + if (sender !is Player) { + sender.sendMessage(plugin.messages["not-from-console"]) + return true + } + val minecraftProfileService = Services[RPKMinecraftProfileService::class.java] + if (minecraftProfileService == null) { + sender.sendMessage(plugin.messages["no-minecraft-profile-service"]) + return true + } + val minecraftProfile = minecraftProfileService.getPreloadedMinecraftProfile(sender) + if (minecraftProfile == null) { + sender.sendMessage(plugin.messages["no-minecraft-profile"]) + return true + } + + // if no arguments + if (args.isEmpty()) { + sender.sendMessage(plugin.messages["setchatnamecolor-usage"]) + return true + } + + // retrieve desired chat name color + val chatNameColor = args[0] + if (isInputTooLong(chatNameColor)) { + sender.sendMessage(plugin.messages["setchatnamecolor-too-long"]) + return true + } + + if (!isHexColorCodeValid(chatNameColor)) { + sender.sendMessage(plugin.messages["setchatnamecolor-invalid-color-code"]) + return true + } + + val minecraftProfileId = minecraftProfile.id + if (minecraftProfileId == null) { + sender.sendMessage(plugin.messages["no-minecraft-profile"]) + return true + } + + setChatNameColorAsync(minecraftProfileId, chatNameColor).thenRun { + sender.sendMessage(plugin.messages["setchatnamecolor-chat-name-color-has-been-set"]) + }.exceptionally { exception -> + plugin.logger.severe("Failed to set chat name color for ${minecraftProfile.name}") + plugin.logger.severe(exception.message) + sender.sendMessage(plugin.messages["setchatnamecolor-something-went-wrong"]) + return@exceptionally null + } + return true + } + + /** + * Checks if the input is too long. The maximum length for a chat name color is 16 characters. + * @param name the input to check + * @return true if the input is too long, false otherwise + */ + private fun isInputTooLong(name: String): Boolean { + return name.length > 16 + } + + /** + * Checks if the input is a valid hex color code. A valid hex color code is a string that starts with a '#' followed by 6 characters that are either digits or letters from a to f. + * @param colorCode the color code to check + * @return true if the color code is valid, false otherwise + */ + private fun isHexColorCodeValid(colorCode: String): Boolean { + return colorCode.matches(Regex("#[0-9a-fA-F]{6}")) + } + + /** + * Sets the chat name color for a player asynchronously. + * @param minecraftProfileId the ID of the player's Minecraft profile + * @param chatNameColor the chat name color to set + * @return a string indicating the result of the operation + */ + private fun setChatNameColorAsync(minecraftProfileId: RPKMinecraftProfileId, chatNameColor: String) : CompletableFuture { + return runAsync { + val recordExists = plugin.database.getTable(RPKChatNameColorTable::class.java)[minecraftProfileId].join() != null + if (recordExists) { + plugin.database.getTable(RPKChatNameColorTable::class.java).update(minecraftProfileId, chatNameColor) + } else { + plugin.database.getTable(RPKChatNameColorTable::class.java).insert(minecraftProfileId, chatNameColor) + } + } + } +} \ No newline at end of file diff --git a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/database/table/RPKChatNameColorTable.kt b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/database/table/RPKChatNameColorTable.kt new file mode 100644 index 000000000..ad3b1dd14 --- /dev/null +++ b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/database/table/RPKChatNameColorTable.kt @@ -0,0 +1,92 @@ +/* + * Copyright 2021 Ren Binden + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.rpkit.chat.bukkit.database.table + +import com.rpkit.chat.bukkit.RPKChatBukkit +import com.rpkit.chat.bukkit.database.create +import com.rpkit.chat.bukkit.database.jooq.Tables.RPKIT_CHAT_NAME_COLOR +import com.rpkit.core.database.Database +import com.rpkit.core.database.Table +import java.util.concurrent.CompletableFuture +import com.rpkit.chat.bukkit.database.jooq.tables.records.RpkitChatNameColorRecord +import com.rpkit.players.bukkit.profile.minecraft.RPKMinecraftProfileId +import java.util.concurrent.CompletableFuture.runAsync +import java.util.logging.Level.SEVERE + +/** + * Represents the chat name color table. + */ +class RPKChatNameColorTable(private val database: Database, private val plugin: RPKChatBukkit) : Table { + + fun insert(id: RPKMinecraftProfileId?, chatNameColor: String): CompletableFuture { + // insert id -> chat name color record into database + return runAsync { + database.create + .insertInto( + RPKIT_CHAT_NAME_COLOR, + RPKIT_CHAT_NAME_COLOR.MINECRAFT_PROFILE_ID, + RPKIT_CHAT_NAME_COLOR.CHAT_NAME_COLOR + ) + .values( + id?.value, + chatNameColor + ) + .execute() + }.exceptionally { e -> + plugin.logger.log(SEVERE, "Failed to insert chat name color record for Minecraft profile ${id?.value} and chat name color $chatNameColor", e) + throw e + } + } + + fun update(minecraftProfileId: RPKMinecraftProfileId, chatNameColor: String): CompletableFuture { + // update chat name color record in database + return runAsync { + database.create + .update(RPKIT_CHAT_NAME_COLOR) + .set(RPKIT_CHAT_NAME_COLOR.CHAT_NAME_COLOR, chatNameColor) + .where(RPKIT_CHAT_NAME_COLOR.MINECRAFT_PROFILE_ID.eq(minecraftProfileId.value)) + .execute() + }.exceptionally { e -> + plugin.logger.log(SEVERE, "Failed to update chat name color record for Minecraft profile ${minecraftProfileId.value} and chat name color $chatNameColor", e) + throw e + } + } + + operator fun get(id: RPKMinecraftProfileId): CompletableFuture { + // get chat name color record from database by id + return CompletableFuture.supplyAsync { + database.create + .selectFrom(RPKIT_CHAT_NAME_COLOR) + .where(RPKIT_CHAT_NAME_COLOR.MINECRAFT_PROFILE_ID.eq(id.value)) + .fetchOne() + }.exceptionally { e -> + plugin.logger.log(SEVERE, "Failed to get chat name color record for Minecraft profile ${id.value}", e) + null + } + } + + fun delete(): CompletableFuture { + // delete chat name color record from database + return runAsync { + database.create + .deleteFrom(RPKIT_CHAT_NAME_COLOR) + .execute() + }.exceptionally { e -> + plugin.logger.log(SEVERE, "Failed to delete chat name color records", e) + throw e + } + } +} \ No newline at end of file diff --git a/bukkit/rpk-chat-bukkit/src/main/resources/com/rpkit/chat/migrations/mysql/V2__Chat_name_colors.sql b/bukkit/rpk-chat-bukkit/src/main/resources/com/rpkit/chat/migrations/mysql/V2__Chat_name_colors.sql new file mode 100644 index 000000000..5d97870ee --- /dev/null +++ b/bukkit/rpk-chat-bukkit/src/main/resources/com/rpkit/chat/migrations/mysql/V2__Chat_name_colors.sql @@ -0,0 +1,22 @@ +/* + * Copyright 2020 Ren Binden + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +-- table to keep track of profile id -> chat name color +CREATE TABLE `rpkit_chat_name_color` +( + `minecraft_profile_id` int NOT NULL, + `chat_name_color` varchar(256) NOT NULL +); \ No newline at end of file diff --git a/bukkit/rpk-chat-bukkit/src/main/resources/com/rpkit/chat/migrations/sqlite/V2__Chat_name_colors.sql b/bukkit/rpk-chat-bukkit/src/main/resources/com/rpkit/chat/migrations/sqlite/V2__Chat_name_colors.sql new file mode 100644 index 000000000..85bb37c85 --- /dev/null +++ b/bukkit/rpk-chat-bukkit/src/main/resources/com/rpkit/chat/migrations/sqlite/V2__Chat_name_colors.sql @@ -0,0 +1,22 @@ +/* + * Copyright 2020 Ren Binden + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +-- table to keep track of profile id -> chat name color +CREATE TABLE `rpkit_chat_name_color` +( + `minecraft_profile_id` int NOT NULL, + `chat_name_color` varchar(256) NOT NULL +); \ No newline at end of file diff --git a/bukkit/rpk-chat-bukkit/src/main/resources/messages.yml b/bukkit/rpk-chat-bukkit/src/main/resources/messages.yml index 02e9f864e..07f8dbe0c 100644 --- a/bukkit/rpk-chat-bukkit/src/main/resources/messages.yml +++ b/bukkit/rpk-chat-bukkit/src/main/resources/messages.yml @@ -99,4 +99,10 @@ plugin-website: 'Website: ${website}' plugin-author: 'Author: ${author}' plugin-authors: 'Authors: ${authors}' plugin-contributors: 'Contributors: ${contributors}' -server-version: 'This server is running ${name} version ${version} (Implementing API version ${api_version})' \ No newline at end of file +server-version: 'This server is running ${name} version ${version} (Implementing API version ${api_version})' +no-permission-setchatnamecolor: '&cYou do not have permission to set the color of your name in chat.' +setchatnamecolor-usage: '&cUsage: /setchatnamecolor [color]' +setchatnamecolor-too-long: '&cThat color is too long. Expected something like #ffffff.' +setchatnamecolor-invalid-color-code: '&cThat color is not a valid color code. Expected something like #ffffff.' +setchatnamecolor-chat-name-color-has-been-set: '&aYour chat name color has been set.' +setchatnamecolor-something-went-wrong: '&cSomething went wrong while setting your chat name color.' \ No newline at end of file diff --git a/bukkit/rpk-chat-bukkit/src/main/resources/plugin.yml b/bukkit/rpk-chat-bukkit/src/main/resources/plugin.yml index 5f9732344..736efc0e5 100644 --- a/bukkit/rpk-chat-bukkit/src/main/resources/plugin.yml +++ b/bukkit/rpk-chat-bukkit/src/main/resources/plugin.yml @@ -54,6 +54,9 @@ commands: description: Reply to the last private message or chat group message sent to you aliases: [r] usage: / [message] + setchatnamecolor: + description: Sets the color of your name in chat + usage: / [color] permissions: rpkit.chat.command.listchatchannels: description: Allows listing chat channels @@ -100,3 +103,6 @@ permissions: rpkit.chat.command.reply: description: Allows replying to private messages default: true + rpkit.chat.command.setchatnamecolor: + description: Allows setting the color of your name in chat + default: true From 095932a566e40a97e9fcc0aba49cf874bed6f2aa Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Sat, 6 Apr 2024 09:47:08 -0600 Subject: [PATCH 02/24] Added dev container --- .devcontainer/Dockerfile | 6 ++++++ .devcontainer/start_dev_container.bat | 4 ++++ .devcontainer/start_dev_container.sh | 4 ++++ 3 files changed, 14 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/start_dev_container.bat create mode 100644 .devcontainer/start_dev_container.sh diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 000000000..a7aeec6f2 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,6 @@ +FROM eclipse-temurin:17-jdk-jammy + +USER root + +# set working directory +WORKDIR /workspaces/RPKit \ No newline at end of file diff --git a/.devcontainer/start_dev_container.bat b/.devcontainer/start_dev_container.bat new file mode 100644 index 000000000..ffac4fd0a --- /dev/null +++ b/.devcontainer/start_dev_container.bat @@ -0,0 +1,4 @@ +REM This script is meant to be run from the .devcontainer directory. + +docker build . -t rpk-dev-container +docker run -it -v %cd%\..\:/workspaces/RPKit rpk-dev-container /bin/bash \ No newline at end of file diff --git a/.devcontainer/start_dev_container.sh b/.devcontainer/start_dev_container.sh new file mode 100644 index 000000000..7f482714d --- /dev/null +++ b/.devcontainer/start_dev_container.sh @@ -0,0 +1,4 @@ +# This script is meant to be run from the .devcontainer directory. + +docker build . -t rpk-dev-container +docker run -it -v %cd%\..\:/workspaces/RPKit rpk-dev-container /bin/bash \ No newline at end of file From bfce3fc88dbb8b767afbfdb14c82128a136926de Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Sat, 18 May 2024 16:50:40 -0600 Subject: [PATCH 03/24] Added devcontainer.json file to allow VSCode integration --- .devcontainer/devcontainer.json | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000..3459c418a --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,24 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu +{ + "name": "rpkdevcontainer", + "build": { + // Path is relative to the devcontainer.json file. + "dockerfile": "Dockerfile" + }, + + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "uname -a", + + // Configure tool-specific properties. + // "customizations": {}, + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + "remoteUser": "root" +} From 4853de5e8ecfc7099382f9484d5fc0639ca76b6b Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Sat, 18 May 2024 17:00:26 -0600 Subject: [PATCH 04/24] Added README for dev container --- .devcontainer/README.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .devcontainer/README.md diff --git a/.devcontainer/README.md b/.devcontainer/README.md new file mode 100644 index 000000000..520baaf3c --- /dev/null +++ b/.devcontainer/README.md @@ -0,0 +1,33 @@ +# Dev Container +This directory contains files related to the dev container for the project, which is a defined environment with the dependencies for compilation pre-installed. + +## Install Docker +If you do not already have Docker installed, download it [here](https://www.docker.com/get-started/)_. + +## Entering Dev Container Environment via VSCode +To enter the dev container environment using VSCode, follow these steps: +1. Click on the "Open a Remote Window" button in the bottom left of VSCode +1. Click "Reopen in Container" + +## Entering Dev Container Environment via Command Line +### Windows +To enter the dev container environment via the command line on Windows, run the following commands: +``` +cd .\.devcontainer +.\start_dev_container.bat +``` + +### Linux +To enter the dev container environment via the command line on Linux, run the following commands: +``` +cd ./.devcontainer +./start_dev_container.sh +``` + +## Compiling +To compile the project in the provided dev container, follow these steps: +1. Make sure the End of Line (EOF) Sequence for the `gradlew` script is set to LF. If it is set to CRLF, the script will fail to run. +1. Run the following command: +``` +./gradlew clean build +``` \ No newline at end of file From 89c972309bcc3a5654425cf4501c968b21312463 Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Sat, 18 May 2024 17:39:34 -0600 Subject: [PATCH 05/24] Added Java extension to `devcontainer.json` --- .devcontainer/devcontainer.json | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 3459c418a..c6f0a69ec 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -17,7 +17,13 @@ // "postCreateCommand": "uname -a", // Configure tool-specific properties. - // "customizations": {}, + "customizations": { + "vscode": { + "extensions": [ + "vscjava.vscode-java-pack" + ] + } + }, // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. "remoteUser": "root" From b6cabdc8428db1ff8c7615e6053c5854b25132f9 Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Sat, 18 May 2024 17:54:20 -0600 Subject: [PATCH 06/24] Added Gradle extension to `devcontainer.json` --- .devcontainer/devcontainer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index c6f0a69ec..2006adf34 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -20,7 +20,8 @@ "customizations": { "vscode": { "extensions": [ - "vscjava.vscode-java-pack" + "vscjava.vscode-java-pack", + "vscjava.vscode-gradle" ] } }, From 3e99e6e1f6711d203a58a8668da82e01686944ad Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Sun, 19 May 2024 18:59:55 -0600 Subject: [PATCH 07/24] Added Kotlin extension to `devcontainer.json` --- .devcontainer/devcontainer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 2006adf34..99b37e85c 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -21,7 +21,8 @@ "vscode": { "extensions": [ "vscjava.vscode-java-pack", - "vscjava.vscode-gradle" + "vscjava.vscode-gradle", + "fwcd.kotlin" ] } }, From ea1aaa124eefcacfbfa20312347628f94ca70bcf Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Sun, 2 Jun 2024 22:11:56 -0600 Subject: [PATCH 08/24] Moved chat name color code to overridden `toChatComponents()` method in SenderCharacterNamePart --- .../bukkit/chatchannel/RPKChatChannelImpl.kt | 25 ---------- .../format/part/SenderCharacterNamePart.kt | 46 +++++++++++++++++++ 2 files changed, 46 insertions(+), 25 deletions(-) diff --git a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/RPKChatChannelImpl.kt b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/RPKChatChannelImpl.kt index 15764136f..fb0a0a46a 100644 --- a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/RPKChatChannelImpl.kt +++ b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/RPKChatChannelImpl.kt @@ -171,9 +171,6 @@ class RPKChatChannelImpl( format.flatMap { part -> part.toChatComponents(preFormatContext).join().toList() }.toTypedArray(), preFormatContext.isCancelled ) - if (senderMinecraftProfile != null) { - setSenderCharacterNamePartColor(senderMinecraftProfile) - }; directedPostFormatPipeline.forEach { component -> postFormatContext = component.process(postFormatContext).join() } @@ -194,26 +191,4 @@ class RPKChatChannelImpl( } }) } - - private fun setSenderCharacterNamePartColor(senderMinecraftProfile: RPKMinecraftProfile) { - val minecraftProfileId = senderMinecraftProfile.id ?: return - val recordExists = plugin.database.getTable(RPKChatNameColorTable::class.java)[minecraftProfileId].join() != null - if (recordExists) { - val senderCharacterNamePart = getSenderCharacterNamePart() ?: return - val chatNameColorRecord = plugin.database.getTable(RPKChatNameColorTable::class.java)[minecraftProfileId].join() - if (chatNameColorRecord != null) { - senderCharacterNamePart.color = chatNameColorRecord.chatNameColor - } - } - } - - private fun getSenderCharacterNamePart(): SenderCharacterNamePart? { - for (part in format) { - if (part is SenderCharacterNamePart) { - return part - } - } - return null - } - } \ No newline at end of file diff --git a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/SenderCharacterNamePart.kt b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/SenderCharacterNamePart.kt index 228bcec85..7e653e657 100644 --- a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/SenderCharacterNamePart.kt +++ b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/SenderCharacterNamePart.kt @@ -21,7 +21,10 @@ import com.rpkit.chat.bukkit.RPKChatBukkit import com.rpkit.chat.bukkit.chatchannel.format.click.ClickAction import com.rpkit.chat.bukkit.chatchannel.format.hover.HoverAction import com.rpkit.chat.bukkit.context.DirectedPreFormatMessageContext +import com.rpkit.chat.bukkit.database.table.RPKChatNameColorTable import com.rpkit.core.service.Services +import net.md_5.bungee.api.ChatColor +import net.md_5.bungee.api.chat.TextComponent import org.bukkit.Bukkit import org.bukkit.configuration.serialization.ConfigurationSerializable import org.bukkit.configuration.serialization.SerializableAs @@ -98,4 +101,47 @@ class SenderCharacterNamePart( serialized["click"] as? ClickAction ) } + + override fun toChatComponents(context: DirectedPreFormatMessageContext) = supplyAsync { + TextComponent.fromLegacyText(getText(context).join()).also { + for (component in it) { + + if (font != null) component.font = font + component.color = getChatNameColor(context) + if (isBold != null) component.isBold = isBold + if (isItalic != null) component.isItalic = isItalic + if (isUnderlined != null) component.isUnderlined = isUnderlined + if (isStrikethrough != null) component.isStrikethrough = isStrikethrough + if (isObfuscated != null) component.isObfuscated = isObfuscated + if (insertion != null) component.insertion = insertion + if (hover != null) component.hoverEvent = hover.toHoverEvent(context).join() + if (click != null) component.clickEvent = click.toClickEvent(context).join() + } + } + }.exceptionally { exception -> + plugin.logger.log(Level.SEVERE, "Failed to convert text part to chat components", exception) + throw exception + } + + // method to get chat name color + private fun getChatNameColor(context: DirectedPreFormatMessageContext): ChatColor { + // try to use chat name color from database + val minecraftProfile = context.senderMinecraftProfile + if (minecraftProfile != null) { + val minecraftProfileId = minecraftProfile.id + if (minecraftProfileId != null) { + val chatNameColorRecord = plugin.database.getTable(RPKChatNameColorTable::class.java)[minecraftProfileId].join() + if (chatNameColorRecord != null) { + return ChatColor.of(chatNameColorRecord.chatNameColor) + } + } + } + return if (color == null) { + // default color + ChatColor.WHITE + } else { + // color from configuration + ChatColor.of(color) + } + } } \ No newline at end of file From 5a0326bd9df3bbd5998ab001dbe736329637d97e Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Sun, 2 Jun 2024 23:18:31 -0600 Subject: [PATCH 09/24] Copied chat name color code to overridden `toChatComponents()` method in ReceiverCharacterNamePart --- .../format/part/ReceiverCharacterNamePart.kt | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/ReceiverCharacterNamePart.kt b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/ReceiverCharacterNamePart.kt index 28d59de06..887e827e8 100644 --- a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/ReceiverCharacterNamePart.kt +++ b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/ReceiverCharacterNamePart.kt @@ -21,7 +21,10 @@ import com.rpkit.chat.bukkit.RPKChatBukkit import com.rpkit.chat.bukkit.chatchannel.format.click.ClickAction import com.rpkit.chat.bukkit.chatchannel.format.hover.HoverAction import com.rpkit.chat.bukkit.context.DirectedPreFormatMessageContext +import com.rpkit.chat.bukkit.database.table.RPKChatNameColorTable import com.rpkit.core.service.Services +import net.md_5.bungee.api.ChatColor +import net.md_5.bungee.api.chat.TextComponent import org.bukkit.Bukkit import org.bukkit.configuration.serialization.ConfigurationSerializable import org.bukkit.configuration.serialization.SerializableAs @@ -94,4 +97,47 @@ class ReceiverCharacterNamePart( serialized["click"] as? ClickAction ) } + + override fun toChatComponents(context: DirectedPreFormatMessageContext) = supplyAsync { + TextComponent.fromLegacyText(getText(context).join()).also { + for (component in it) { + + if (font != null) component.font = font + component.color = getChatNameColor(context) + if (isBold != null) component.isBold = isBold + if (isItalic != null) component.isItalic = isItalic + if (isUnderlined != null) component.isUnderlined = isUnderlined + if (isStrikethrough != null) component.isStrikethrough = isStrikethrough + if (isObfuscated != null) component.isObfuscated = isObfuscated + if (insertion != null) component.insertion = insertion + if (hover != null) component.hoverEvent = hover.toHoverEvent(context).join() + if (click != null) component.clickEvent = click.toClickEvent(context).join() + } + } + }.exceptionally { exception -> + plugin.logger.log(Level.SEVERE, "Failed to convert text part to chat components", exception) + throw exception + } + + // method to get chat name color + private fun getChatNameColor(context: DirectedPreFormatMessageContext): ChatColor { + // try to use chat name color from database + val minecraftProfile = context.senderMinecraftProfile + if (minecraftProfile != null) { + val minecraftProfileId = minecraftProfile.id + if (minecraftProfileId != null) { + val chatNameColorRecord = plugin.database.getTable(RPKChatNameColorTable::class.java)[minecraftProfileId].join() + if (chatNameColorRecord != null) { + return ChatColor.of(chatNameColorRecord.chatNameColor) + } + } + } + return if (color == null) { + // default color + ChatColor.WHITE + } else { + // color from configuration + ChatColor.of(color) + } + } } \ No newline at end of file From 77e9d6759af58e1ed460fd87fa2958f3329fbc6f Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Sun, 9 Jun 2024 11:18:25 -0600 Subject: [PATCH 10/24] Removed unused import statement in RPKChatChannelImpl --- .../com/rpkit/chat/bukkit/chatchannel/RPKChatChannelImpl.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/RPKChatChannelImpl.kt b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/RPKChatChannelImpl.kt index fb0a0a46a..98169a437 100644 --- a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/RPKChatChannelImpl.kt +++ b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/RPKChatChannelImpl.kt @@ -28,7 +28,6 @@ import com.rpkit.chat.bukkit.chatchannel.pipeline.UndirectedPipelineComponent import com.rpkit.chat.bukkit.context.DirectedPostFormatMessageContext import com.rpkit.chat.bukkit.context.DirectedPreFormatMessageContext import com.rpkit.chat.bukkit.context.UndirectedMessageContext -import com.rpkit.chat.bukkit.database.table.RPKChatNameColorTable import com.rpkit.chat.bukkit.event.chatchannel.RPKBukkitChatChannelMessageEvent import com.rpkit.chat.bukkit.mute.RPKChatChannelMuteService import com.rpkit.chat.bukkit.speaker.RPKChatChannelSpeakerService From 127349503cf79d0d0b04c3b0558612a45105eabc Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Sun, 9 Jun 2024 11:19:16 -0600 Subject: [PATCH 11/24] Reverted mutability of color variable in GenericTextPart --- .../chat/bukkit/chatchannel/format/part/GenericTextPart.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/GenericTextPart.kt b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/GenericTextPart.kt index 7f4bf80a1..5d75c4aad 100644 --- a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/GenericTextPart.kt +++ b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/GenericTextPart.kt @@ -30,7 +30,7 @@ import java.util.logging.Level abstract class GenericTextPart( private val plugin: RPKChatBukkit, val font: String? = null, - var color: String? = null, + val color: String? = null, val isBold: Boolean? = null, val isItalic: Boolean? = null, val isUnderlined: Boolean? = null, From 8794bc949a78b132d27888a8bee89ccf1c8f3196 Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Sun, 9 Jun 2024 11:21:43 -0600 Subject: [PATCH 12/24] Removed length check in SetChatNameColorCommand --- .../setchatnamecolor/SetChatNameColorCommand.kt | 14 -------------- .../src/main/resources/messages.yml | 1 - 2 files changed, 15 deletions(-) diff --git a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/command/setchatnamecolor/SetChatNameColorCommand.kt b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/command/setchatnamecolor/SetChatNameColorCommand.kt index 6b0f0b613..8077c7553 100644 --- a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/command/setchatnamecolor/SetChatNameColorCommand.kt +++ b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/command/setchatnamecolor/SetChatNameColorCommand.kt @@ -62,11 +62,6 @@ class SetChatNameColorCommand(private val plugin: RPKChatBukkit) : CommandExecut // retrieve desired chat name color val chatNameColor = args[0] - if (isInputTooLong(chatNameColor)) { - sender.sendMessage(plugin.messages["setchatnamecolor-too-long"]) - return true - } - if (!isHexColorCodeValid(chatNameColor)) { sender.sendMessage(plugin.messages["setchatnamecolor-invalid-color-code"]) return true @@ -89,15 +84,6 @@ class SetChatNameColorCommand(private val plugin: RPKChatBukkit) : CommandExecut return true } - /** - * Checks if the input is too long. The maximum length for a chat name color is 16 characters. - * @param name the input to check - * @return true if the input is too long, false otherwise - */ - private fun isInputTooLong(name: String): Boolean { - return name.length > 16 - } - /** * Checks if the input is a valid hex color code. A valid hex color code is a string that starts with a '#' followed by 6 characters that are either digits or letters from a to f. * @param colorCode the color code to check diff --git a/bukkit/rpk-chat-bukkit/src/main/resources/messages.yml b/bukkit/rpk-chat-bukkit/src/main/resources/messages.yml index 07f8dbe0c..cccbb34bf 100644 --- a/bukkit/rpk-chat-bukkit/src/main/resources/messages.yml +++ b/bukkit/rpk-chat-bukkit/src/main/resources/messages.yml @@ -102,7 +102,6 @@ plugin-contributors: 'Contributors: ${contributors}' server-version: 'This server is running ${name} version ${version} (Implementing API version ${api_version})' no-permission-setchatnamecolor: '&cYou do not have permission to set the color of your name in chat.' setchatnamecolor-usage: '&cUsage: /setchatnamecolor [color]' -setchatnamecolor-too-long: '&cThat color is too long. Expected something like #ffffff.' setchatnamecolor-invalid-color-code: '&cThat color is not a valid color code. Expected something like #ffffff.' setchatnamecolor-chat-name-color-has-been-set: '&aYour chat name color has been set.' setchatnamecolor-something-went-wrong: '&cSomething went wrong while setting your chat name color.' \ No newline at end of file From fa9f9731d5ac375be4fd99789b810921e7ffaa20 Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Wed, 12 Jun 2024 07:17:59 -0600 Subject: [PATCH 13/24] Condensed two log statements into one in SetChatNameColorCommand class --- .../command/setchatnamecolor/SetChatNameColorCommand.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/command/setchatnamecolor/SetChatNameColorCommand.kt b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/command/setchatnamecolor/SetChatNameColorCommand.kt index 8077c7553..cf7bef032 100644 --- a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/command/setchatnamecolor/SetChatNameColorCommand.kt +++ b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/command/setchatnamecolor/SetChatNameColorCommand.kt @@ -27,6 +27,7 @@ import org.bukkit.command.CommandSender import org.bukkit.entity.Player import java.util.concurrent.CompletableFuture import java.util.concurrent.CompletableFuture.runAsync +import java.util.logging.Level.SEVERE /** * SetChatNameColor command. @@ -76,8 +77,7 @@ class SetChatNameColorCommand(private val plugin: RPKChatBukkit) : CommandExecut setChatNameColorAsync(minecraftProfileId, chatNameColor).thenRun { sender.sendMessage(plugin.messages["setchatnamecolor-chat-name-color-has-been-set"]) }.exceptionally { exception -> - plugin.logger.severe("Failed to set chat name color for ${minecraftProfile.name}") - plugin.logger.severe(exception.message) + plugin.logger.log(SEVERE, "Failed to set chat name color for ${minecraftProfile.name}", exception) sender.sendMessage(plugin.messages["setchatnamecolor-something-went-wrong"]) return@exceptionally null } From 8d788fd4cecbb9cf85553d02a21d03d7d4864794 Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Wed, 12 Jun 2024 07:24:43 -0600 Subject: [PATCH 14/24] Added primary key to SQL scripts for `rpkit_chat_name_color` table --- .../com/rpkit/chat/migrations/mysql/V2__Chat_name_colors.sql | 3 ++- .../com/rpkit/chat/migrations/sqlite/V2__Chat_name_colors.sql | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/bukkit/rpk-chat-bukkit/src/main/resources/com/rpkit/chat/migrations/mysql/V2__Chat_name_colors.sql b/bukkit/rpk-chat-bukkit/src/main/resources/com/rpkit/chat/migrations/mysql/V2__Chat_name_colors.sql index 5d97870ee..4ce2a4e59 100644 --- a/bukkit/rpk-chat-bukkit/src/main/resources/com/rpkit/chat/migrations/mysql/V2__Chat_name_colors.sql +++ b/bukkit/rpk-chat-bukkit/src/main/resources/com/rpkit/chat/migrations/mysql/V2__Chat_name_colors.sql @@ -18,5 +18,6 @@ CREATE TABLE `rpkit_chat_name_color` ( `minecraft_profile_id` int NOT NULL, - `chat_name_color` varchar(256) NOT NULL + `chat_name_color` varchar(256) NOT NULL, + PRIMARY KEY (`minecraft_profile_id`) ); \ No newline at end of file diff --git a/bukkit/rpk-chat-bukkit/src/main/resources/com/rpkit/chat/migrations/sqlite/V2__Chat_name_colors.sql b/bukkit/rpk-chat-bukkit/src/main/resources/com/rpkit/chat/migrations/sqlite/V2__Chat_name_colors.sql index 85bb37c85..658d709a2 100644 --- a/bukkit/rpk-chat-bukkit/src/main/resources/com/rpkit/chat/migrations/sqlite/V2__Chat_name_colors.sql +++ b/bukkit/rpk-chat-bukkit/src/main/resources/com/rpkit/chat/migrations/sqlite/V2__Chat_name_colors.sql @@ -18,5 +18,6 @@ CREATE TABLE `rpkit_chat_name_color` ( `minecraft_profile_id` int NOT NULL, - `chat_name_color` varchar(256) NOT NULL + `chat_name_color` varchar(256) NOT NULL, + PRIMARY KEY (`minecraft_profile_id`) ); \ No newline at end of file From 5c1ef50b1abcecaa93c34f4a77236c33dd1f7cd2 Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Thu, 13 Jun 2024 22:20:19 -0600 Subject: [PATCH 15/24] Added config option for chat name color override functionality --- .../chatchannel/format/part/ReceiverCharacterNamePart.kt | 9 ++++++++- .../chatchannel/format/part/SenderCharacterNamePart.kt | 9 ++++++++- bukkit/rpk-chat-bukkit/src/main/resources/config.yml | 3 ++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/ReceiverCharacterNamePart.kt b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/ReceiverCharacterNamePart.kt index 887e827e8..e201cd066 100644 --- a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/ReceiverCharacterNamePart.kt +++ b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/ReceiverCharacterNamePart.kt @@ -103,7 +103,14 @@ class ReceiverCharacterNamePart( for (component in it) { if (font != null) component.font = font - component.color = getChatNameColor(context) + + if (plugin.config.getBoolean("misc.chatNameColorOverrideEnabled")) { + component.color = getChatNameColor(context) + } + else { + if (color != null) component.color = ChatColor.of(color) + } + if (isBold != null) component.isBold = isBold if (isItalic != null) component.isItalic = isItalic if (isUnderlined != null) component.isUnderlined = isUnderlined diff --git a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/SenderCharacterNamePart.kt b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/SenderCharacterNamePart.kt index 7e653e657..7564ac9bc 100644 --- a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/SenderCharacterNamePart.kt +++ b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/SenderCharacterNamePart.kt @@ -107,7 +107,14 @@ class SenderCharacterNamePart( for (component in it) { if (font != null) component.font = font - component.color = getChatNameColor(context) + + if (plugin.config.getBoolean("misc.chatNameColorOverrideEnabled")) { + component.color = getChatNameColor(context) + } + else { + if (color != null) component.color = ChatColor.of(color) + } + if (isBold != null) component.isBold = isBold if (isItalic != null) component.isItalic = isItalic if (isUnderlined != null) component.isUnderlined = isUnderlined diff --git a/bukkit/rpk-chat-bukkit/src/main/resources/config.yml b/bukkit/rpk-chat-bukkit/src/main/resources/config.yml index bb1db814f..033f86d61 100644 --- a/bukkit/rpk-chat-bukkit/src/main/resources/config.yml +++ b/bukkit/rpk-chat-bukkit/src/main/resources/config.yml @@ -392,4 +392,5 @@ caching: minecraft_profile_id: enabled: true size: 20 - +chat-names: + chatNameColorOverrideEnabled: true \ No newline at end of file From 216e672378f3951abbe3a3497870a6b86b67972a Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Fri, 14 Jun 2024 22:25:57 -0600 Subject: [PATCH 16/24] Corrected config path for chatNameColorOverrideEnabled --- bukkit/rpk-chat-bukkit/src/main/resources/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bukkit/rpk-chat-bukkit/src/main/resources/config.yml b/bukkit/rpk-chat-bukkit/src/main/resources/config.yml index 033f86d61..1723122e2 100644 --- a/bukkit/rpk-chat-bukkit/src/main/resources/config.yml +++ b/bukkit/rpk-chat-bukkit/src/main/resources/config.yml @@ -392,5 +392,5 @@ caching: minecraft_profile_id: enabled: true size: 20 -chat-names: +misc: chatNameColorOverrideEnabled: true \ No newline at end of file From 8842c12bf22012739df4de6b7a8188e450096291 Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Sat, 15 Jun 2024 10:10:36 -0600 Subject: [PATCH 17/24] Added chat name color override functionality for profile names --- .../format/part/ReceiverCharacterNamePart.kt | 2 +- .../format/part/ReceiverProfileNamePart.kt | 57 ++++++++++++++++++- .../format/part/SenderCharacterNamePart.kt | 2 +- .../format/part/SenderProfileNamePart.kt | 57 ++++++++++++++++++- .../src/main/resources/config.yml | 3 +- 5 files changed, 116 insertions(+), 5 deletions(-) diff --git a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/ReceiverCharacterNamePart.kt b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/ReceiverCharacterNamePart.kt index e201cd066..b98fb3d9a 100644 --- a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/ReceiverCharacterNamePart.kt +++ b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/ReceiverCharacterNamePart.kt @@ -104,7 +104,7 @@ class ReceiverCharacterNamePart( if (font != null) component.font = font - if (plugin.config.getBoolean("misc.chatNameColorOverrideEnabled")) { + if (plugin.config.getBoolean("misc.characterChatNameColorOverrideEnabled")) { component.color = getChatNameColor(context) } else { diff --git a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/ReceiverProfileNamePart.kt b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/ReceiverProfileNamePart.kt index e9fd9b61a..09b6708fc 100644 --- a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/ReceiverProfileNamePart.kt +++ b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/ReceiverProfileNamePart.kt @@ -24,10 +24,15 @@ import org.bukkit.Bukkit import org.bukkit.configuration.serialization.ConfigurationSerializable import org.bukkit.configuration.serialization.SerializableAs import java.util.concurrent.CompletableFuture.completedFuture +import net.md_5.bungee.api.chat.TextComponent +import java.util.concurrent.CompletableFuture.supplyAsync +import net.md_5.bungee.api.ChatColor +import java.util.logging.Level +import com.rpkit.chat.bukkit.database.table.RPKChatNameColorTable @SerializableAs("ReceiverProfileNamePart") class ReceiverProfileNamePart( - plugin: RPKChatBukkit, + private val plugin: RPKChatBukkit, font: String? = null, color: String? = null, isBold: Boolean? = null, @@ -84,4 +89,54 @@ class ReceiverProfileNamePart( serialized["click"] as? ClickAction ) } + + override fun toChatComponents(context: DirectedPreFormatMessageContext) = supplyAsync { + TextComponent.fromLegacyText(getText(context).join()).also { + for (component in it) { + + if (font != null) component.font = font + + if (plugin.config.getBoolean("misc.profileChatNameColorOverrideEnabled")) { + component.color = getChatNameColor(context) + } + else { + if (color != null) component.color = ChatColor.of(color) + } + + if (isBold != null) component.isBold = isBold + if (isItalic != null) component.isItalic = isItalic + if (isUnderlined != null) component.isUnderlined = isUnderlined + if (isStrikethrough != null) component.isStrikethrough = isStrikethrough + if (isObfuscated != null) component.isObfuscated = isObfuscated + if (insertion != null) component.insertion = insertion + if (hover != null) component.hoverEvent = hover.toHoverEvent(context).join() + if (click != null) component.clickEvent = click.toClickEvent(context).join() + } + } + }.exceptionally { exception -> + plugin.logger.log(Level.SEVERE, "Failed to convert text part to chat components", exception) + throw exception + } + + // method to get chat name color + private fun getChatNameColor(context: DirectedPreFormatMessageContext): ChatColor { + // try to use chat name color from database + val minecraftProfile = context.senderMinecraftProfile + if (minecraftProfile != null) { + val minecraftProfileId = minecraftProfile.id + if (minecraftProfileId != null) { + val chatNameColorRecord = plugin.database.getTable(RPKChatNameColorTable::class.java)[minecraftProfileId].join() + if (chatNameColorRecord != null) { + return ChatColor.of(chatNameColorRecord.chatNameColor) + } + } + } + return if (color == null) { + // default color + ChatColor.WHITE + } else { + // color from configuration + ChatColor.of(color) + } + } } \ No newline at end of file diff --git a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/SenderCharacterNamePart.kt b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/SenderCharacterNamePart.kt index 7564ac9bc..f457247af 100644 --- a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/SenderCharacterNamePart.kt +++ b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/SenderCharacterNamePart.kt @@ -108,7 +108,7 @@ class SenderCharacterNamePart( if (font != null) component.font = font - if (plugin.config.getBoolean("misc.chatNameColorOverrideEnabled")) { + if (plugin.config.getBoolean("misc.characterChatNameColorOverrideEnabled")) { component.color = getChatNameColor(context) } else { diff --git a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/SenderProfileNamePart.kt b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/SenderProfileNamePart.kt index e54817720..503e77288 100644 --- a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/SenderProfileNamePart.kt +++ b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/SenderProfileNamePart.kt @@ -24,10 +24,15 @@ import org.bukkit.Bukkit import org.bukkit.configuration.serialization.ConfigurationSerializable import org.bukkit.configuration.serialization.SerializableAs import java.util.concurrent.CompletableFuture.completedFuture +import net.md_5.bungee.api.chat.TextComponent +import java.util.concurrent.CompletableFuture.supplyAsync +import net.md_5.bungee.api.ChatColor +import java.util.logging.Level +import com.rpkit.chat.bukkit.database.table.RPKChatNameColorTable @SerializableAs("SenderProfileNamePart") class SenderProfileNamePart( - plugin: RPKChatBukkit, + private val plugin: RPKChatBukkit, font: String? = null, color: String? = null, isBold: Boolean? = null, @@ -83,4 +88,54 @@ class SenderProfileNamePart( serialized["click"] as? ClickAction ) } + + override fun toChatComponents(context: DirectedPreFormatMessageContext) = supplyAsync { + TextComponent.fromLegacyText(getText(context).join()).also { + for (component in it) { + + if (font != null) component.font = font + + if (plugin.config.getBoolean("misc.profileChatNameColorOverrideEnabled")) { + component.color = getChatNameColor(context) + } + else { + if (color != null) component.color = ChatColor.of(color) + } + + if (isBold != null) component.isBold = isBold + if (isItalic != null) component.isItalic = isItalic + if (isUnderlined != null) component.isUnderlined = isUnderlined + if (isStrikethrough != null) component.isStrikethrough = isStrikethrough + if (isObfuscated != null) component.isObfuscated = isObfuscated + if (insertion != null) component.insertion = insertion + if (hover != null) component.hoverEvent = hover.toHoverEvent(context).join() + if (click != null) component.clickEvent = click.toClickEvent(context).join() + } + } + }.exceptionally { exception -> + plugin.logger.log(Level.SEVERE, "Failed to convert text part to chat components", exception) + throw exception + } + + // method to get chat name color + private fun getChatNameColor(context: DirectedPreFormatMessageContext): ChatColor { + // try to use chat name color from database + val minecraftProfile = context.senderMinecraftProfile + if (minecraftProfile != null) { + val minecraftProfileId = minecraftProfile.id + if (minecraftProfileId != null) { + val chatNameColorRecord = plugin.database.getTable(RPKChatNameColorTable::class.java)[minecraftProfileId].join() + if (chatNameColorRecord != null) { + return ChatColor.of(chatNameColorRecord.chatNameColor) + } + } + } + return if (color == null) { + // default color + ChatColor.WHITE + } else { + // color from configuration + ChatColor.of(color) + } + } } \ No newline at end of file diff --git a/bukkit/rpk-chat-bukkit/src/main/resources/config.yml b/bukkit/rpk-chat-bukkit/src/main/resources/config.yml index 1723122e2..083b3f126 100644 --- a/bukkit/rpk-chat-bukkit/src/main/resources/config.yml +++ b/bukkit/rpk-chat-bukkit/src/main/resources/config.yml @@ -393,4 +393,5 @@ caching: enabled: true size: 20 misc: - chatNameColorOverrideEnabled: true \ No newline at end of file + characterChatNameColorOverrideEnabled: true + profileChatNameColorOverrideEnabled: true \ No newline at end of file From a96329aea3b0f71559f2efc28a67556a7b932b21 Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Sat, 15 Jun 2024 23:43:00 -0600 Subject: [PATCH 18/24] Imported `supplyAsync` in RPKChatNameColorTable class --- .../rpkit/chat/bukkit/database/table/RPKChatNameColorTable.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/database/table/RPKChatNameColorTable.kt b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/database/table/RPKChatNameColorTable.kt index ad3b1dd14..2e05e2873 100644 --- a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/database/table/RPKChatNameColorTable.kt +++ b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/database/table/RPKChatNameColorTable.kt @@ -24,6 +24,7 @@ import java.util.concurrent.CompletableFuture import com.rpkit.chat.bukkit.database.jooq.tables.records.RpkitChatNameColorRecord import com.rpkit.players.bukkit.profile.minecraft.RPKMinecraftProfileId import java.util.concurrent.CompletableFuture.runAsync +import java.util.concurrent.CompletableFuture.supplyAsync import java.util.logging.Level.SEVERE /** @@ -67,7 +68,7 @@ class RPKChatNameColorTable(private val database: Database, private val plugin: operator fun get(id: RPKMinecraftProfileId): CompletableFuture { // get chat name color record from database by id - return CompletableFuture.supplyAsync { + return supplyAsync { database.create .selectFrom(RPKIT_CHAT_NAME_COLOR) .where(RPKIT_CHAT_NAME_COLOR.MINECRAFT_PROFILE_ID.eq(id.value)) From 7b661c91552a11c74f113f146f4c814be30f45f8 Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Wed, 19 Jun 2024 21:42:14 -0600 Subject: [PATCH 19/24] Added setchatnamecolor messages to `ChatMessages.kt` --- .../SetChatNameColorCommand.kt | 18 +++++++++--------- .../rpkit/chat/bukkit/messages/ChatMessages.kt | 5 +++++ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/command/setchatnamecolor/SetChatNameColorCommand.kt b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/command/setchatnamecolor/SetChatNameColorCommand.kt index cf7bef032..e4f436033 100644 --- a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/command/setchatnamecolor/SetChatNameColorCommand.kt +++ b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/command/setchatnamecolor/SetChatNameColorCommand.kt @@ -37,48 +37,48 @@ class SetChatNameColorCommand(private val plugin: RPKChatBukkit) : CommandExecut override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array): Boolean { if (!sender.hasPermission("rpkit.chat.command.setchatnamecolor")) { - sender.sendMessage(plugin.messages["no-permission-setchatnamecolor"]) + sender.sendMessage(plugin.messages.noPermissionSetchatnamecolor) return true } if (sender !is Player) { - sender.sendMessage(plugin.messages["not-from-console"]) + sender.sendMessage(plugin.messages.notFromConsole) return true } val minecraftProfileService = Services[RPKMinecraftProfileService::class.java] if (minecraftProfileService == null) { - sender.sendMessage(plugin.messages["no-minecraft-profile-service"]) + sender.sendMessage(plugin.messages.noMinecraftProfileService) return true } val minecraftProfile = minecraftProfileService.getPreloadedMinecraftProfile(sender) if (minecraftProfile == null) { - sender.sendMessage(plugin.messages["no-minecraft-profile"]) + sender.sendMessage(plugin.messages.noMinecraftProfile) return true } // if no arguments if (args.isEmpty()) { - sender.sendMessage(plugin.messages["setchatnamecolor-usage"]) + sender.sendMessage(plugin.messages.setchatnamecolorUsage) return true } // retrieve desired chat name color val chatNameColor = args[0] if (!isHexColorCodeValid(chatNameColor)) { - sender.sendMessage(plugin.messages["setchatnamecolor-invalid-color-code"]) + sender.sendMessage(plugin.messages.setchatnamecolorInvalidColorCode) return true } val minecraftProfileId = minecraftProfile.id if (minecraftProfileId == null) { - sender.sendMessage(plugin.messages["no-minecraft-profile"]) + sender.sendMessage(plugin.messages.noMinecraftProfile) return true } setChatNameColorAsync(minecraftProfileId, chatNameColor).thenRun { - sender.sendMessage(plugin.messages["setchatnamecolor-chat-name-color-has-been-set"]) + sender.sendMessage(plugin.messages.setchatnamecolorChatNameColorHasBeenSet) }.exceptionally { exception -> plugin.logger.log(SEVERE, "Failed to set chat name color for ${minecraftProfile.name}", exception) - sender.sendMessage(plugin.messages["setchatnamecolor-something-went-wrong"]) + sender.sendMessage(plugin.messages.setchatnamecolorSomethingWentWrong) return@exceptionally null } return true diff --git a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/messages/ChatMessages.kt b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/messages/ChatMessages.kt index 6e38471f5..dc9c6f109 100644 --- a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/messages/ChatMessages.kt +++ b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/messages/ChatMessages.kt @@ -278,4 +278,9 @@ class ChatMessages(plugin: RPKChatBukkit) : BukkitMessages(plugin) { val pluginAuthors = getParameterized("plugin-authors").let(::PluginAuthorsMessage) val pluginContributors = getParameterized("plugin-contributors").let(::PluginContributorsMessage) val serverVersion = getParameterized("server-version").let(::ServerVersionMessage) + val noPermissionSetchatnamecolor = get("no-permission-setchatnamecolor") + val setchatnamecolorUsage = get("setchatnamecolor-usage") + val setchatnamecolorInvalidColorCode = get("setchatnamecolor-invalid-color-code") + val setchatnamecolorChatNameColorHasBeenSet = get("setchatnamecolor-chat-name-color-has-been-set") + val setchatnamecolorSomethingWentWrong = get("setchatnamecolor-something-went-wrong") } \ No newline at end of file From 07dcb707587fcf0753966711a3a1bcf59b1c23e4 Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Sun, 30 Jun 2024 22:10:50 -0600 Subject: [PATCH 20/24] Created chat name color service --- .../com/rpkit/chat/bukkit/RPKChatBukkit.kt | 3 ++ .../format/part/ReceiverCharacterNamePart.kt | 33 +++++++++-------- .../format/part/ReceiverProfileNamePart.kt | 30 ++++++++-------- .../format/part/SenderCharacterNamePart.kt | 33 +++++++++-------- .../format/part/SenderProfileNamePart.kt | 30 ++++++++-------- .../RPKChatNameColorServiceImpl.kt | 22 ++++++++++++ .../chatnamecolor/RPKChatNameColorService.kt | 36 +++++++++++++++++++ 7 files changed, 123 insertions(+), 64 deletions(-) create mode 100644 bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatnamecolor/RPKChatNameColorServiceImpl.kt create mode 100644 bukkit/rpk-chat-lib-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatnamecolor/RPKChatNameColorService.kt diff --git a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/RPKChatBukkit.kt b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/RPKChatBukkit.kt index bca831433..b5bbb52aa 100644 --- a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/RPKChatBukkit.kt +++ b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/RPKChatBukkit.kt @@ -56,6 +56,8 @@ import com.rpkit.chat.bukkit.prefix.RPKPrefixServiceImpl import com.rpkit.chat.bukkit.snooper.RPKSnooperService import com.rpkit.chat.bukkit.snooper.RPKSnooperServiceImpl import com.rpkit.chat.bukkit.speaker.RPKChatChannelSpeakerService +import com.rpkit.chat.bukkit.chatnamecolor.RPKChatNameColorService +import com.rpkit.chat.bukkit.chatnamecolor.RPKChatNameColorServiceImpl import com.rpkit.core.bukkit.command.toBukkit import com.rpkit.core.bukkit.listener.registerListeners import com.rpkit.core.database.Database @@ -209,6 +211,7 @@ class RPKChatBukkit : JavaPlugin(), RPKPlugin { Services[RPKChatChannelSpeakerService::class.java] = RPKChatChannelSpeakerService(this) Services[RPKChatGroupService::class.java] = RPKChatGroupServiceImpl(this) Services[RPKSnooperService::class.java] = RPKSnooperServiceImpl(this) + Services[RPKChatNameColorService::class.java] = RPKChatNameColorServiceImpl(this) registerChatChannelPermissions(chatChannelService) registerPrefixPermissions(prefixService) diff --git a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/ReceiverCharacterNamePart.kt b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/ReceiverCharacterNamePart.kt index b98fb3d9a..f7ace1fd8 100644 --- a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/ReceiverCharacterNamePart.kt +++ b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/ReceiverCharacterNamePart.kt @@ -21,8 +21,6 @@ import com.rpkit.chat.bukkit.RPKChatBukkit import com.rpkit.chat.bukkit.chatchannel.format.click.ClickAction import com.rpkit.chat.bukkit.chatchannel.format.hover.HoverAction import com.rpkit.chat.bukkit.context.DirectedPreFormatMessageContext -import com.rpkit.chat.bukkit.database.table.RPKChatNameColorTable -import com.rpkit.core.service.Services import net.md_5.bungee.api.ChatColor import net.md_5.bungee.api.chat.TextComponent import org.bukkit.Bukkit @@ -30,6 +28,9 @@ import org.bukkit.configuration.serialization.ConfigurationSerializable import org.bukkit.configuration.serialization.SerializableAs import java.util.concurrent.CompletableFuture.supplyAsync import java.util.logging.Level +import com.rpkit.chat.bukkit.database.table.RPKChatNameColorTable +import com.rpkit.chat.bukkit.chatnamecolor.RPKChatNameColorService +import com.rpkit.core.service.Services @SerializableAs("ReceiverCharacterNamePart") class ReceiverCharacterNamePart( @@ -126,25 +127,23 @@ class ReceiverCharacterNamePart( throw exception } - // method to get chat name color private fun getChatNameColor(context: DirectedPreFormatMessageContext): ChatColor { - // try to use chat name color from database - val minecraftProfile = context.senderMinecraftProfile - if (minecraftProfile != null) { - val minecraftProfileId = minecraftProfile.id - if (minecraftProfileId != null) { - val chatNameColorRecord = plugin.database.getTable(RPKChatNameColorTable::class.java)[minecraftProfileId].join() - if (chatNameColorRecord != null) { - return ChatColor.of(chatNameColorRecord.chatNameColor) - } + val chatNameColorService = Services[RPKChatNameColorService::class.java] + val senderMinecraftProfile = context.senderMinecraftProfile + if (senderMinecraftProfile != null) { + val overriddenChatNameColor = chatNameColorService?.getChatNameColor(senderMinecraftProfile) + if (overriddenChatNameColor != null) { + return ChatColor.of(overriddenChatNameColor) } } - return if (color == null) { - // default color - ChatColor.WHITE - } else { - // color from configuration + return getConfiguredChatPartColorOrDefault() + } + + private fun getConfiguredChatPartColorOrDefault(): ChatColor { + return if (color != null) { ChatColor.of(color) + } else { + ChatColor.WHITE } } } \ No newline at end of file diff --git a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/ReceiverProfileNamePart.kt b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/ReceiverProfileNamePart.kt index 09b6708fc..ed526b132 100644 --- a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/ReceiverProfileNamePart.kt +++ b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/ReceiverProfileNamePart.kt @@ -29,6 +29,8 @@ import java.util.concurrent.CompletableFuture.supplyAsync import net.md_5.bungee.api.ChatColor import java.util.logging.Level import com.rpkit.chat.bukkit.database.table.RPKChatNameColorTable +import com.rpkit.chat.bukkit.chatnamecolor.RPKChatNameColorService +import com.rpkit.core.service.Services @SerializableAs("ReceiverProfileNamePart") class ReceiverProfileNamePart( @@ -118,25 +120,23 @@ class ReceiverProfileNamePart( throw exception } - // method to get chat name color private fun getChatNameColor(context: DirectedPreFormatMessageContext): ChatColor { - // try to use chat name color from database - val minecraftProfile = context.senderMinecraftProfile - if (minecraftProfile != null) { - val minecraftProfileId = minecraftProfile.id - if (minecraftProfileId != null) { - val chatNameColorRecord = plugin.database.getTable(RPKChatNameColorTable::class.java)[minecraftProfileId].join() - if (chatNameColorRecord != null) { - return ChatColor.of(chatNameColorRecord.chatNameColor) - } + val chatNameColorService = Services[RPKChatNameColorService::class.java] + val senderMinecraftProfile = context.senderMinecraftProfile + if (senderMinecraftProfile != null) { + val overriddenChatNameColor = chatNameColorService?.getChatNameColor(senderMinecraftProfile) + if (overriddenChatNameColor != null) { + return ChatColor.of(overriddenChatNameColor) } } - return if (color == null) { - // default color - ChatColor.WHITE - } else { - // color from configuration + return getConfiguredChatPartColorOrDefault() + } + + private fun getConfiguredChatPartColorOrDefault(): ChatColor { + return if (color != null) { ChatColor.of(color) + } else { + ChatColor.WHITE } } } \ No newline at end of file diff --git a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/SenderCharacterNamePart.kt b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/SenderCharacterNamePart.kt index f457247af..66664afdb 100644 --- a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/SenderCharacterNamePart.kt +++ b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/SenderCharacterNamePart.kt @@ -21,8 +21,6 @@ import com.rpkit.chat.bukkit.RPKChatBukkit import com.rpkit.chat.bukkit.chatchannel.format.click.ClickAction import com.rpkit.chat.bukkit.chatchannel.format.hover.HoverAction import com.rpkit.chat.bukkit.context.DirectedPreFormatMessageContext -import com.rpkit.chat.bukkit.database.table.RPKChatNameColorTable -import com.rpkit.core.service.Services import net.md_5.bungee.api.ChatColor import net.md_5.bungee.api.chat.TextComponent import org.bukkit.Bukkit @@ -30,6 +28,9 @@ import org.bukkit.configuration.serialization.ConfigurationSerializable import org.bukkit.configuration.serialization.SerializableAs import java.util.concurrent.CompletableFuture.supplyAsync import java.util.logging.Level +import com.rpkit.chat.bukkit.database.table.RPKChatNameColorTable +import com.rpkit.chat.bukkit.chatnamecolor.RPKChatNameColorService +import com.rpkit.core.service.Services @SerializableAs("SenderCharacterNamePart") class SenderCharacterNamePart( @@ -130,25 +131,23 @@ class SenderCharacterNamePart( throw exception } - // method to get chat name color private fun getChatNameColor(context: DirectedPreFormatMessageContext): ChatColor { - // try to use chat name color from database - val minecraftProfile = context.senderMinecraftProfile - if (minecraftProfile != null) { - val minecraftProfileId = minecraftProfile.id - if (minecraftProfileId != null) { - val chatNameColorRecord = plugin.database.getTable(RPKChatNameColorTable::class.java)[minecraftProfileId].join() - if (chatNameColorRecord != null) { - return ChatColor.of(chatNameColorRecord.chatNameColor) - } + val chatNameColorService = Services[RPKChatNameColorService::class.java] + val senderMinecraftProfile = context.senderMinecraftProfile + if (senderMinecraftProfile != null) { + val overriddenChatNameColor = chatNameColorService?.getChatNameColor(senderMinecraftProfile) + if (overriddenChatNameColor != null) { + return ChatColor.of(overriddenChatNameColor) } } - return if (color == null) { - // default color - ChatColor.WHITE - } else { - // color from configuration + return getConfiguredChatPartColorOrDefault() + } + + private fun getConfiguredChatPartColorOrDefault(): ChatColor { + return if (color != null) { ChatColor.of(color) + } else { + ChatColor.WHITE } } } \ No newline at end of file diff --git a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/SenderProfileNamePart.kt b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/SenderProfileNamePart.kt index 503e77288..4cb3ebbfc 100644 --- a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/SenderProfileNamePart.kt +++ b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatchannel/format/part/SenderProfileNamePart.kt @@ -29,6 +29,8 @@ import java.util.concurrent.CompletableFuture.supplyAsync import net.md_5.bungee.api.ChatColor import java.util.logging.Level import com.rpkit.chat.bukkit.database.table.RPKChatNameColorTable +import com.rpkit.chat.bukkit.chatnamecolor.RPKChatNameColorService +import com.rpkit.core.service.Services @SerializableAs("SenderProfileNamePart") class SenderProfileNamePart( @@ -117,25 +119,23 @@ class SenderProfileNamePart( throw exception } - // method to get chat name color private fun getChatNameColor(context: DirectedPreFormatMessageContext): ChatColor { - // try to use chat name color from database - val minecraftProfile = context.senderMinecraftProfile - if (minecraftProfile != null) { - val minecraftProfileId = minecraftProfile.id - if (minecraftProfileId != null) { - val chatNameColorRecord = plugin.database.getTable(RPKChatNameColorTable::class.java)[minecraftProfileId].join() - if (chatNameColorRecord != null) { - return ChatColor.of(chatNameColorRecord.chatNameColor) - } + val chatNameColorService = Services[RPKChatNameColorService::class.java] + val senderMinecraftProfile = context.senderMinecraftProfile + if (senderMinecraftProfile != null) { + val overriddenChatNameColor = chatNameColorService?.getChatNameColor(senderMinecraftProfile) + if (overriddenChatNameColor != null) { + return ChatColor.of(overriddenChatNameColor) } } - return if (color == null) { - // default color - ChatColor.WHITE - } else { - // color from configuration + return getConfiguredChatPartColorOrDefault() + } + + private fun getConfiguredChatPartColorOrDefault(): ChatColor { + return if (color != null) { ChatColor.of(color) + } else { + ChatColor.WHITE } } } \ No newline at end of file diff --git a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatnamecolor/RPKChatNameColorServiceImpl.kt b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatnamecolor/RPKChatNameColorServiceImpl.kt new file mode 100644 index 000000000..1c02ad287 --- /dev/null +++ b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatnamecolor/RPKChatNameColorServiceImpl.kt @@ -0,0 +1,22 @@ +package com.rpkit.chat.bukkit.chatnamecolor + +import com.rpkit.chat.bukkit.RPKChatBukkit +import com.rpkit.players.bukkit.profile.minecraft.RPKMinecraftProfile +import com.rpkit.chat.bukkit.database.table.RPKChatNameColorTable + +/** + * Chat name color service implementation + */ +class RPKChatNameColorServiceImpl(override val plugin: RPKChatBukkit) : RPKChatNameColorService { + + override fun getChatNameColor(minecraftProfile: RPKMinecraftProfile?): String? { + val minecraftProfileId = minecraftProfile?.id + if (minecraftProfileId != null) { + val chatNameColorRecord = plugin.database.getTable(RPKChatNameColorTable::class.java)[minecraftProfileId].join() + if (chatNameColorRecord != null) { + return chatNameColorRecord.chatNameColor + } + } + return null + } +} \ No newline at end of file diff --git a/bukkit/rpk-chat-lib-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatnamecolor/RPKChatNameColorService.kt b/bukkit/rpk-chat-lib-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatnamecolor/RPKChatNameColorService.kt new file mode 100644 index 000000000..79263f767 --- /dev/null +++ b/bukkit/rpk-chat-lib-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/chatnamecolor/RPKChatNameColorService.kt @@ -0,0 +1,36 @@ +/* + * Copyright 2020 Ren Binden + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + package com.rpkit.chat.bukkit.chatnamecolor + + import com.rpkit.core.service.Service + import com.rpkit.players.bukkit.profile.minecraft.RPKMinecraftProfile + + /** + * Provides operations related to overridden chat name colors + */ + interface RPKChatNameColorService : Service { + + /** + * Gets the chat name color for a player. + * If the player has no chat name color, null is returned. + * + * @param minecraftProfile The player to get the chat name color of + * @return The chat name color, or null if the player has no chat name color + */ + fun getChatNameColor(minecraftProfile: RPKMinecraftProfile?): String? + } + \ No newline at end of file From c3a637675e4d100142ef2d7c0a048507d807170b Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Sun, 30 Jun 2024 22:11:13 -0600 Subject: [PATCH 21/24] Corrected some typos in `RPKSnooperService.kt` --- .../kotlin/com/rpkit/chat/bukkit/snooper/RPKSnooperService.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bukkit/rpk-chat-lib-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/snooper/RPKSnooperService.kt b/bukkit/rpk-chat-lib-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/snooper/RPKSnooperService.kt index 1a5d73d5a..dc347b7d2 100644 --- a/bukkit/rpk-chat-lib-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/snooper/RPKSnooperService.kt +++ b/bukkit/rpk-chat-lib-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/snooper/RPKSnooperService.kt @@ -27,12 +27,12 @@ interface RPKSnooperService : Service { /** * A list of all Minecraft profiles who are currently snooping. - * THis list is immutable, so Minecraft profiles should be added or removed with [addSnooper] and [removeSnooper] respectively. + * This list is immutable, so Minecraft profiles should be added or removed with [addSnooper] and [removeSnooper] respectively. */ val snoopers: CompletableFuture> /** - * Adds a snooper. This Minecraft profile is then abel to see messages they would not otherwise see. + * Adds a snooper. This Minecraft profile is then able to see messages they would not otherwise see. * * @param minecraftProfile The Minecraft profile to enable snooping for */ From c5ac390b5c4178804c070a6dde3e4b2828807742 Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Tue, 2 Jul 2024 21:54:09 -0600 Subject: [PATCH 22/24] Added upsert function to `RPKChatNameColorTable` class --- .../setchatnamecolor/SetChatNameColorCommand.kt | 7 +------ .../bukkit/database/table/RPKChatNameColorTable.kt | 10 ++++++++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/command/setchatnamecolor/SetChatNameColorCommand.kt b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/command/setchatnamecolor/SetChatNameColorCommand.kt index e4f436033..6e7a995d4 100644 --- a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/command/setchatnamecolor/SetChatNameColorCommand.kt +++ b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/command/setchatnamecolor/SetChatNameColorCommand.kt @@ -101,12 +101,7 @@ class SetChatNameColorCommand(private val plugin: RPKChatBukkit) : CommandExecut */ private fun setChatNameColorAsync(minecraftProfileId: RPKMinecraftProfileId, chatNameColor: String) : CompletableFuture { return runAsync { - val recordExists = plugin.database.getTable(RPKChatNameColorTable::class.java)[minecraftProfileId].join() != null - if (recordExists) { - plugin.database.getTable(RPKChatNameColorTable::class.java).update(minecraftProfileId, chatNameColor) - } else { - plugin.database.getTable(RPKChatNameColorTable::class.java).insert(minecraftProfileId, chatNameColor) - } + plugin.database.getTable(RPKChatNameColorTable::class.java).upsert(minecraftProfileId, chatNameColor) } } } \ No newline at end of file diff --git a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/database/table/RPKChatNameColorTable.kt b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/database/table/RPKChatNameColorTable.kt index 2e05e2873..f88dd1653 100644 --- a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/database/table/RPKChatNameColorTable.kt +++ b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/database/table/RPKChatNameColorTable.kt @@ -66,6 +66,16 @@ class RPKChatNameColorTable(private val database: Database, private val plugin: } } + fun upsert(id: RPKMinecraftProfileId, chatNameColor: String): CompletableFuture { + return get(id).thenAcceptAsync { existingChatNameColor -> + if (existingChatNameColor == null) { + insert(id, chatNameColor) + } else { + update(id, chatNameColor) + } + } + } + operator fun get(id: RPKMinecraftProfileId): CompletableFuture { // get chat name color record from database by id return supplyAsync { From 3edc4369095fe5c5428198b826a7fb7dce9fe8db Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Thu, 4 Jul 2024 12:46:36 -0600 Subject: [PATCH 23/24] Allowed operators to set the chat name colors of others --- .../SetChatNameColorCommand.kt | 39 +++++++++++++++++++ .../src/main/resources/plugin.yml | 3 ++ 2 files changed, 42 insertions(+) diff --git a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/command/setchatnamecolor/SetChatNameColorCommand.kt b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/command/setchatnamecolor/SetChatNameColorCommand.kt index 6e7a995d4..05625f7fe 100644 --- a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/command/setchatnamecolor/SetChatNameColorCommand.kt +++ b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/command/setchatnamecolor/SetChatNameColorCommand.kt @@ -68,6 +68,45 @@ class SetChatNameColorCommand(private val plugin: RPKChatBukkit) : CommandExecut return true } + // if a second argument is provided + if (args.size > 1) { + // check that sender has permission to set the chat name colors of other players + if (!sender.hasPermission("rpkit.chat.command.setchatnamecolor.others")) { + sender.sendMessage("You do not have permission to set the chat name color of other players.") + return true + } + + val targetPlayerName = args[1] + val targetPlayer = plugin.server.getPlayer(targetPlayerName) + if (targetPlayer == null) { + sender.sendMessage("Player not found.") + return true + } + + val targetMinecraftProfile = minecraftProfileService.getPreloadedMinecraftProfile(targetPlayer) + if (targetMinecraftProfile == null) { + sender.sendMessage(plugin.messages["no-minecraft-profile"]) + return true + } + + val targetMinecraftProfileId = targetMinecraftProfile.id + if (targetMinecraftProfileId == null) { + sender.sendMessage(plugin.messages["no-minecraft-profile"]) + return true + } + + setChatNameColorAsync(targetMinecraftProfileId, chatNameColor).thenRun { + sender.sendMessage("Chat color name set to $chatNameColor for ${targetPlayer.name}") + }.exceptionally { exception -> + plugin.logger.severe("Failed to set chat name color for ${targetPlayer.name}") + plugin.logger.severe(exception.message) + sender.sendMessage("Failed to set chat name color.") + return@exceptionally null + } + return true + + } + val minecraftProfileId = minecraftProfile.id if (minecraftProfileId == null) { sender.sendMessage(plugin.messages.noMinecraftProfile) diff --git a/bukkit/rpk-chat-bukkit/src/main/resources/plugin.yml b/bukkit/rpk-chat-bukkit/src/main/resources/plugin.yml index 736efc0e5..21def9d96 100644 --- a/bukkit/rpk-chat-bukkit/src/main/resources/plugin.yml +++ b/bukkit/rpk-chat-bukkit/src/main/resources/plugin.yml @@ -106,3 +106,6 @@ permissions: rpkit.chat.command.setchatnamecolor: description: Allows setting the color of your name in chat default: true + rpkit.chat.command.setchatnamecolor.others: + description: Allows setting the color of other players' names in chat + default: op \ No newline at end of file From 98e47ce291471bbf8722779271f7ef42b17cd872 Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Tue, 13 Aug 2024 23:12:22 -0600 Subject: [PATCH 24/24] Made messages configurable in `set chat name color` command --- .../command/setchatnamecolor/SetChatNameColorCommand.kt | 8 +++++--- .../kotlin/com/rpkit/chat/bukkit/messages/ChatMessages.kt | 3 +++ bukkit/rpk-chat-bukkit/src/main/resources/messages.yml | 6 +++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/command/setchatnamecolor/SetChatNameColorCommand.kt b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/command/setchatnamecolor/SetChatNameColorCommand.kt index 05625f7fe..5fe07329e 100644 --- a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/command/setchatnamecolor/SetChatNameColorCommand.kt +++ b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/command/setchatnamecolor/SetChatNameColorCommand.kt @@ -72,14 +72,14 @@ class SetChatNameColorCommand(private val plugin: RPKChatBukkit) : CommandExecut if (args.size > 1) { // check that sender has permission to set the chat name colors of other players if (!sender.hasPermission("rpkit.chat.command.setchatnamecolor.others")) { - sender.sendMessage("You do not have permission to set the chat name color of other players.") + sender.sendMessage(plugin.messages.noPermissionSetchatnamecolorOthers) return true } val targetPlayerName = args[1] val targetPlayer = plugin.server.getPlayer(targetPlayerName) if (targetPlayer == null) { - sender.sendMessage("Player not found.") + sender.sendMessage(plugin.messages.playerNotFound) return true } @@ -96,7 +96,7 @@ class SetChatNameColorCommand(private val plugin: RPKChatBukkit) : CommandExecut } setChatNameColorAsync(targetMinecraftProfileId, chatNameColor).thenRun { - sender.sendMessage("Chat color name set to $chatNameColor for ${targetPlayer.name}") + sender.sendMessage(plugin.messages.setchatnamecolorChatNameColorHasBeenSetOthers) }.exceptionally { exception -> plugin.logger.severe("Failed to set chat name color for ${targetPlayer.name}") plugin.logger.severe(exception.message) @@ -120,6 +120,8 @@ class SetChatNameColorCommand(private val plugin: RPKChatBukkit) : CommandExecut sender.sendMessage(plugin.messages.setchatnamecolorSomethingWentWrong) return@exceptionally null } + + sender.sendMessage(plugin.messages.setchatnamecolorChatNameColorHasBeenSet) return true } diff --git a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/messages/ChatMessages.kt b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/messages/ChatMessages.kt index dc9c6f109..c8afc5434 100644 --- a/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/messages/ChatMessages.kt +++ b/bukkit/rpk-chat-bukkit/src/main/kotlin/com/rpkit/chat/bukkit/messages/ChatMessages.kt @@ -283,4 +283,7 @@ class ChatMessages(plugin: RPKChatBukkit) : BukkitMessages(plugin) { val setchatnamecolorInvalidColorCode = get("setchatnamecolor-invalid-color-code") val setchatnamecolorChatNameColorHasBeenSet = get("setchatnamecolor-chat-name-color-has-been-set") val setchatnamecolorSomethingWentWrong = get("setchatnamecolor-something-went-wrong") + val noPermissionSetchatnamecolorOthers = get("no-permission-setchatnamecolor-others") + val playerNotFound = get("player-not-found") + val setchatnamecolorChatNameColorHasBeenSetOthers = get("setchatnamecolor-chat-name-color-has-been-set-others") } \ No newline at end of file diff --git a/bukkit/rpk-chat-bukkit/src/main/resources/messages.yml b/bukkit/rpk-chat-bukkit/src/main/resources/messages.yml index cccbb34bf..2687053eb 100644 --- a/bukkit/rpk-chat-bukkit/src/main/resources/messages.yml +++ b/bukkit/rpk-chat-bukkit/src/main/resources/messages.yml @@ -104,4 +104,8 @@ no-permission-setchatnamecolor: '&cYou do not have permission to set the color o setchatnamecolor-usage: '&cUsage: /setchatnamecolor [color]' setchatnamecolor-invalid-color-code: '&cThat color is not a valid color code. Expected something like #ffffff.' setchatnamecolor-chat-name-color-has-been-set: '&aYour chat name color has been set.' -setchatnamecolor-something-went-wrong: '&cSomething went wrong while setting your chat name color.' \ No newline at end of file +setchatnamecolor-something-went-wrong: '&cSomething went wrong while setting your chat name color.' +no-permission-setchatnamecolor-others: '&cYou do not have permission to set the color of other players\' names in chat.' +player-not-found: '&cNo player by that name was found.' +setchatnamecolor-chat-name-color-has-been-set: 'Your chat name color has been set.' +setchatnamecolor-chat-name-color-has-been-set-others: 'The chat name color of the specified player has been set.' \ No newline at end of file