Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added chat name color override functionality #663

Draft
wants to merge 27 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
32077bc
Added 'setchatnamecolor' command
dmccoystephenson Apr 6, 2024
095932a
Added dev container
dmccoystephenson Apr 6, 2024
b4cc9f5
Merge remote-tracking branch 'origin/docker/dev-container' into featu…
dmccoystephenson May 18, 2024
bfce3fc
Added devcontainer.json file to allow VSCode integration
dmccoystephenson May 18, 2024
4853de5
Added README for dev container
dmccoystephenson May 18, 2024
89c9723
Added Java extension to `devcontainer.json`
dmccoystephenson May 18, 2024
b6cabdc
Added Gradle extension to `devcontainer.json`
dmccoystephenson May 18, 2024
e1d3377
Merge branch 'docker/dev-container' into feature/setchatnamecolor-new
dmccoystephenson May 19, 2024
3e99e6e
Added Kotlin extension to `devcontainer.json`
dmccoystephenson May 20, 2024
3d3a3c0
Merge branch 'docker/dev-container' into feature/setchatnamecolor-new
dmccoystephenson May 25, 2024
ea1aaa1
Moved chat name color code to overridden `toChatComponents()` method …
dmccoystephenson Jun 3, 2024
5a0326b
Copied chat name color code to overridden `toChatComponents()` method…
dmccoystephenson Jun 3, 2024
77e9d67
Removed unused import statement in RPKChatChannelImpl
dmccoystephenson Jun 9, 2024
1273495
Reverted mutability of color variable in GenericTextPart
dmccoystephenson Jun 9, 2024
8794bc9
Removed length check in SetChatNameColorCommand
dmccoystephenson Jun 9, 2024
fa9f973
Condensed two log statements into one in SetChatNameColorCommand class
dmccoystephenson Jun 12, 2024
8d788fd
Added primary key to SQL scripts for `rpkit_chat_name_color` table
dmccoystephenson Jun 12, 2024
5c1ef50
Added config option for chat name color override functionality
dmccoystephenson Jun 14, 2024
216e672
Corrected config path for chatNameColorOverrideEnabled
dmccoystephenson Jun 15, 2024
8842c12
Added chat name color override functionality for profile names
dmccoystephenson Jun 15, 2024
a96329a
Imported `supplyAsync` in RPKChatNameColorTable class
dmccoystephenson Jun 16, 2024
7b661c9
Added setchatnamecolor messages to `ChatMessages.kt`
dmccoystephenson Jun 20, 2024
07dcb70
Created chat name color service
dmccoystephenson Jul 1, 2024
c3a6376
Corrected some typos in `RPKSnooperService.kt`
dmccoystephenson Jul 1, 2024
c5ac390
Added upsert function to `RPKChatNameColorTable` class
dmccoystephenson Jul 3, 2024
3edc436
Allowed operators to set the chat name colors of others
dmccoystephenson Jul 4, 2024
98e47ce
Made messages configurable in `set chat name color` command
dmccoystephenson Aug 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM eclipse-temurin:17-jdk-jammy

USER root

# set working directory
WORKDIR /workspaces/RPKit
33 changes: 33 additions & 0 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
@@ -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
```
32 changes: 32 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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": {
"vscode": {
"extensions": [
"vscjava.vscode-java-pack",
"vscjava.vscode-gradle",
"fwcd.kotlin"
]
}
},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
"remoteUser": "root"
}
4 changes: 4 additions & 0 deletions .devcontainer/start_dev_container.bat
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions .devcontainer/start_dev_container.sh
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand All @@ -55,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
Expand Down Expand Up @@ -182,6 +185,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
Expand All @@ -207,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)
Expand All @@ -233,6 +238,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())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ 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
Expand Down Expand Up @@ -189,5 +190,4 @@ class RPKChatChannelImpl(
}
})
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ 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.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
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(
Expand Down Expand Up @@ -94,4 +98,52 @@ 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

if (plugin.config.getBoolean("misc.characterChatNameColorOverrideEnabled")) {
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
}

private fun getChatNameColor(context: DirectedPreFormatMessageContext): ChatColor {
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 getConfiguredChatPartColorOrDefault()
}

private fun getConfiguredChatPartColorOrDefault(): ChatColor {
return if (color != null) {
ChatColor.of(color)
} else {
ChatColor.WHITE
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,17 @@ 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
import com.rpkit.chat.bukkit.chatnamecolor.RPKChatNameColorService
import com.rpkit.core.service.Services

@SerializableAs("ReceiverProfileNamePart")
class ReceiverProfileNamePart(
plugin: RPKChatBukkit,
private val plugin: RPKChatBukkit,
font: String? = null,
color: String? = null,
isBold: Boolean? = null,
Expand Down Expand Up @@ -84,4 +91,52 @@ 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
}

private fun getChatNameColor(context: DirectedPreFormatMessageContext): ChatColor {
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 getConfiguredChatPartColorOrDefault()
}

private fun getConfiguredChatPartColorOrDefault(): ChatColor {
return if (color != null) {
ChatColor.of(color)
} else {
ChatColor.WHITE
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ 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.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
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(
Expand Down Expand Up @@ -98,4 +102,52 @@ 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

if (plugin.config.getBoolean("misc.characterChatNameColorOverrideEnabled")) {
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
}

private fun getChatNameColor(context: DirectedPreFormatMessageContext): ChatColor {
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 getConfiguredChatPartColorOrDefault()
}

private fun getConfiguredChatPartColorOrDefault(): ChatColor {
return if (color != null) {
ChatColor.of(color)
} else {
ChatColor.WHITE
}
}
}
Loading