StyleHelper
com.jsmacrosce.jsmacros.client.api.helper.StyleHelper
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().
// 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
Methods
bold
true if this run is bold, false otherwisegetClickAction
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()."custom" for a JsMacros-registered command, or null if this run has no click actiongetClickValue
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.null if there is no click action or the action is "custom" or SHOW_DIALOGgetColorIndex
-1 if no colour is set or it is an arbitrary rgb colourgetColorName
getColorValue
-1.-1 if it doesn't have one.getCustomClickValue
null for other click events. getClickAction() reports "custom" for that event."custom" click, or null if this run's click action is not "custom"getCustomColor
0xRRGGBB, whether custom or legacy, or -1 if unset. Use hasCustomColor() to distinguish custom from legacy.-1 if it has no colourgetFormatting
null; when no colour is set, this method throws NullPointerException.null for an arbitrary rgb colourgetHoverAction
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().null if this run has no hover actiongetHoverValue
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()}`);
}
}));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 actiongetInsertion
hasColor
true if a colour is set, false otherwisehasCustomColor
false when unset; use hasColor() to distinguish unset from a legacy colour.true if this run has a colour that is not one of the legacy named onesitalic
true if this run is italic, false otherwiseobfuscated
true if this run is obfuscated, false otherwisestrikethrough
true if this run is struck through, false otherwisetoString
underlined
true if this run is underlined, false otherwise