Skip to content

StyleHelper ​

com.jsmacrosce.jsmacros.client.api.helper.StyleHelper

Since1.6.5

Exposes the formatting and click/hover events stored on a text style.

TextHelper.visit(com.jsmacrosce.jsmacros.core.MethodWrapper) supplies a style for each visited text run. These accessors report properties stored on that style, not formatting inherited from surrounding text.

Decoration accessors return booleans. For colours, getColorIndex() and getColorValue() return -1 when there is no legacy named colour; use getCustomColor() for the packed RGB of either colour kind, or -1 when unset.
hasColor() and hasCustomColor() distinguish unset, legacy, and custom colours.

Click and hover accessors expose the action separately from its value. JsMacros-registered clicks report "custom"; retrieve their runnable with getCustomClickValue().

js
// a style is per run, so visit walks the text and gives one to each run
const text = Chat.createTextHelperFromString("some styled line");  
text.visit(JavaWrapper.methodToJava(function (style, run) {
 if (style.hasColor()) {
   if (style.hasCustomColor()) {
     // an arbitrary rgb colour, packed as 0xRRGGBB
     Chat.log(`${run} is colour #${style.getCustomColor().toString(16)}`);  
   } else {
     // one of the sixteen legacy named colours
     Chat.log(`${run} is ${style.getColorName()}, index ${style.getColorIndex()}`);  
   }
 }
 if (style.underlined()) {
   Chat.log(`${run} is underlined`);  
 }
 const click = style.getClickAction();  
 if (click !== null) {
   Chat.log(`${run} click does ${click} ${style.getClickValue()}`);  
 }
}));

Constructors ​

new StyleHelper ​

new StyleHelper(Style base)#
Wraps the supplied raw text style reference without copying or parsing it.

Parameters:

  • base: raw text style to wrap

Methods ​

bold ​

bold(): booleanSince1.6.5#
Returns whether this style has its bold flag set; inherited formatting is not included.
Returns: true if this run is bold, false otherwise

getClickAction ​

getClickAction(): StringSince1.6.5#
Returns the click action's enum name, or null when no click event is set. Built-in action names are uppercase; JsMacros-registered clicks return "custom" and their runnable is available from getCustomClickValue(). Other action values are available from getClickValue().
Returns: the click action's enum constant name in upper case, "custom" for a JsMacros-registered command, or null if this run has no click action

getClickValue ​

getClickValue(): StringSince1.6.5#
the text argument for a click action, or null when the action has no text value. getClickAction() identifies the action. A page number is returned as a decimal string; the "custom" and SHOW_DIALOG actions have no text value.
Returns: the click action's argument as a string, or null if there is no click action or the action is "custom" or SHOW_DIALOG

getColorIndex ​

getColorIndex(): intSince1.8.4#
Returns this style's legacy colour index. Custom RGB colours are not assigned a legacy index.
Returns: the legacy colour index, or -1 if no colour is set or it is an arbitrary rgb colour

getColorName ​

getColorName(): StringSince1.8.4#
Returns the serialized colour of this style, or null if unset. Legacy colours serialize by name and custom colours as hash-prefixed hexadecimal RGB.
Returns: the color name of this style or null if it has no color.

getColorValue ​

getColorValue(): intSince1.8.4#
Returns the RGB value associated with a legacy named colour; custom RGB colours and unset colours return -1.
Returns: the color value of this style or -1 if it doesn't have one.

getCustomClickValue ​

getCustomClickValue(): RunnableSince1.6.5#
the runnable stored by a JsMacros-registered click, or null for other click events. getClickAction() reports "custom" for that event.
Returns: the runnable to call for a "custom" click, or null if this run's click action is not "custom"

getCustomColor ​

getCustomColor(): intSince1.6.5#
Returns this style's colour as packed 0xRRGGBB, whether custom or legacy, or -1 if unset. Use hasCustomColor() to distinguish custom from legacy.
Returns: the packed rgb value of this run's colour, or -1 if it has no colour

getFormatting ​

getFormatting(): FormattingHelperSince1.8.4#
Returns the legacy formatting for this style's colour. An arbitrary RGB colour returns null; when no colour is set, this method throws NullPointerException.
Returns: the legacy formatting, or null for an arbitrary rgb colour

getHoverAction ​

getHoverAction(): StringSince1.6.5#
the serialized name of this run's hover action, or null if it has no hover event. Unlike getClickAction(), this name is lowercase (for example, show_item). The action's value is returned by getHoverValue().
Returns: the hover action's name, or null if this run has no hover action

getHoverValue ​

getHoverValue(): ObjectSince1.6.5#
the value shown by this run's hover event, or null when there is no recognized event. The type of the answer depends on what getHoverAction() said, and there are three shapes: a show_text hover gives a TextHelper for the text shown; a show_item hover gives an ItemStackHelper for the item shown; and a show_entity hover gives a list of TextHelper, one per line of the entity tooltip. A run with no hover gives null, as does any hover action the game does not recognise. The result has different shapes, so use getHoverAction() to distinguish them. For show_item, it is an ItemStackHelper wrapping the item value.
const text = Chat.createTextHelperFromString("hover me");
text.visit(JavaWrapper.methodToJava(function (style, run) {
  const action = style.getHoverAction();
  if (action === null) {
    return;
  }
  const value = style.getHoverValue();
  if (value === null) {
    return;
  }
  if (action === "show_text") {
    // a single text helper
    Chat.log(`hover text: ${value.getString()}`);
  } else if (action === "show_entity") {
    // a list of text helpers, one per tooltip line
    for (const line of value) {
      Chat.log(`tooltip: ${line.getString()}`);
    }
  } else {
    // a single item helper
    Chat.log(`hover item: ${value.getItemId()}`);
  }
}));
Returns: a TextHelper for a show_text hover, an ItemStackHelper for a show_item hover, a list of TextHelper for a show_entity hover, or null if there is no recognized hover action

getInsertion ​

getInsertion(): StringSince1.6.5#
the text inserted for this run, or null if it has no insertion.
Returns: the insertion text, or null if this run has none

hasColor ​

hasColor(): booleanSince1.6.5#
Whether this style has a colour set.
Returns: true if a colour is set, false otherwise

hasCustomColor ​

hasCustomColor(): booleanSince1.6.5#
Returns whether this style has a custom RGB colour. Returns false when unset; use hasColor() to distinguish unset from a legacy colour.
Returns: true if this run has a colour that is not one of the legacy named ones

italic ​

italic(): booleanSince1.6.5#
Returns whether this style has its italic flag set; inherited formatting is not included.
Returns: true if this run is italic, false otherwise

obfuscated ​

obfuscated(): booleanSince1.6.5#
Returns whether this style has its obfuscated flag set; inherited formatting is not included.
Returns: true if this run is obfuscated, false otherwise

strikethrough ​

strikethrough(): booleanSince1.6.5#
Returns whether this style has its strikethrough flag set; inherited formatting is not included.
Returns: true if this run is struck through, false otherwise

toString ​

toString(): String#
Returns a diagnostic summary of the wrapped style's stored properties.
Returns: a diagnostic representation of the wrapped style

underlined ​

underlined(): booleanSince1.6.5#
Returns whether this style has its underline flag set; inherited formatting is not included.
Returns: true if this run is underlined, false otherwise