Skip to content

Commit

Permalink
Add setColor method to TextComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
srockw authored and mattco98 committed Nov 25, 2023
1 parent 056709d commit 85c6595
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions api/ctjs.api
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,8 @@ public final class com/chattriggers/ctjs/api/message/TextComponent : net/minecra
public final fun setClick (Lnet/minecraft/text/ClickEvent$Action;Ljava/lang/String;)Lcom/chattriggers/ctjs/api/message/TextComponent;
public final fun setClickAction (Ljava/lang/Object;)Lcom/chattriggers/ctjs/api/message/TextComponent;
public final fun setClickValue (Ljava/lang/String;)Lcom/chattriggers/ctjs/api/message/TextComponent;
public final fun setColor (III)Lcom/chattriggers/ctjs/api/message/TextComponent;
public final fun setColor (J)Lcom/chattriggers/ctjs/api/message/TextComponent;
public final fun setFormatted (Z)Lcom/chattriggers/ctjs/api/message/TextComponent;
public final fun setHover (Ljava/lang/String;Ljava/lang/Object;)Lcom/chattriggers/ctjs/api/message/TextComponent;
public final fun setHover (Lnet/minecraft/text/HoverEvent$Action;Ljava/lang/Object;)Lcom/chattriggers/ctjs/api/message/TextComponent;
Expand Down
21 changes: 21 additions & 0 deletions src/main/kotlin/com/chattriggers/ctjs/api/message/TextComponent.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.chattriggers.ctjs.api.message

import com.chattriggers.ctjs.api.render.Renderer
import gg.essential.universal.UChat
import net.minecraft.text.*
import net.minecraft.util.Formatting
Expand Down Expand Up @@ -217,6 +218,26 @@ class TextComponent : Text {
setHover(HoverEvent.Action.byName(action) as HoverEvent.Action<*>, value)
}

/**
* Sets the color of this [TextComponent]
* This won't override your color codes unless &r is explicitly used.
*
* @param color RGB value acquired using [Renderer.getColor]. Alpha values will be ignored
*/
fun setColor(color: Long) = apply {
component.setStyle(component.style.withColor(color.toInt()));
}

/**
* Sets the color of this [TextComponent]
* This won't override your color codes unless &r is explicitly used.
*
* @param red value between 0 and 255
* @param green value between 0 and 255
* @param blue value between 0 and 255
*/
fun setColor(red: Int, green: Int, blue: Int) = setColor(Renderer.getColor(red, green, blue))

/**
* Shows the component in chat as a new [Message]
*/
Expand Down

0 comments on commit 85c6595

Please sign in to comment.