# Components, KubeJS and you!

In 1.18.2 and beyond KubeJS uses Components in a lot of places. It returns them for entity names, item names and accepts them for everything from tooltips to sending messages to players.

<p class="callout info">All examples use `event.player.tell` from the `player.chat` event to output their example, but they will with anywhere that accepts a Component!</p>

Making your own Components starts from the ComponentWrapper class, invokable with just `Component` or `Text` from anywhere. The examples all use `Component` but `Text` works just the same.

#### ComponentWrapper methods:

<table border="1" id="bkmrk-name-return-type-inf" style="border-collapse: collapse; width: 100%; height: 435px;"><thead><tr style="height: 29px;"><td style="width: 6.9444%; height: 29px;">Name

</td><td style="width: 8.2716%; height: 29px;">Return Type</td><td style="width: 9.78395%; height: 29px;">Info</td></tr></thead><tbody><tr style="height: 29px;"><td style="width: 6.9444%; height: 29px;">of(Object o)</td><td style="width: 8.2716%; height: 29px;">MutableComponent</td><td style="width: 9.78395%; height: 29px;">Returns a component based on what was input. Accepts strings, primitives like numbers, snbt/nbt format of Components and a couple others.</td></tr><tr style="height: 29px;"><td style="width: 6.9444%; height: 29px;">clickEventOf(Object o)</td><td style="width: 8.2716%; height: 29px;">ClickEvent</td><td style="width: 9.78395%; height: 29px;">Returns a ClickEvent based on what was input. See examples below</td></tr><tr style="height: 29px;"><td style="width: 6.9444%; height: 29px;">prettyPrintNbt(Tag tag)</td><td style="width: 8.2716%; height: 29px;">Component</td><td style="width: 9.78395%; height: 29px;">Returns a component with a prettified version of the input NBT.</td></tr><tr style="height: 29px;"><td style="width: 6.9444%; height: 29px;">join(MutableComponent seperator, Iterable&lt;? extends Component&gt; texts)</td><td style="width: 8.2716%; height: 29px;">MutableComponent</td><td style="width: 9.78395%; height: 29px;">Returns the result of looping through `texts` and joining them, separating each one with `seperator`.</td></tr><tr style="height: 29px;"><td style="width: 6.9444%; height: 29px;">string(String text)</td><td style="width: 8.2716%; height: 29px;">MutableComponent</td><td style="width: 9.78395%; height: 29px;">Returns a basic unformatted TextComponent with just the input text</td></tr><tr style="height: 29px;"><td style="width: 6.9444%; height: 29px;">translate(String key)</td><td style="width: 8.2716%; height: 29px;">MutableComponent</td><td style="width: 9.78395%; height: 29px;">Returns a basic unformatted TranslatableComponent with the input key.</td></tr><tr style="height: 29px;"><td style="width: 6.9444%; height: 29px;">translate(String key, Object... objects)</td><td style="width: 8.2716%; height: 29px;">MutableComponent</td><td style="width: 9.78395%; height: 29px;">Returns an unformatted TranslatableComponent with `objects` as the replacements for %s in the translation output. </td></tr><tr style="height: 29px;"><td style="width: 6.9444%; height: 29px;">keybind(String keybind)</td><td style="width: 8.2716%; height: 29px;">MutableComponent</td><td style="width: 9.78395%; height: 29px;">Returns a basic unformatted KeybindComponent with the specified keybind.</td></tr><tr style="height: 29px;"><td style="width: 6.9444%; height: 29px;">&lt;color&gt;(Object text)</td><td style="width: 8.2716%; height: 29px;">MutableComponent</td><td style="width: 9.78395%; height: 29px;">Returns a basic Component with the specified color for text coloring. Valid colors are in the list below. Do not include the &lt;&gt; brackets.

</td></tr></tbody></table>

A list of colors accepted in various places:

- black
- darkBlue
- darkGreen
- darkAqua
- darkRed
- darkPurple
- gold
- gray
- darkGray
- blue
- green
- aqua
- red
- lightPurple
- yellow
- white

Basic examples:

```JavaScript
onEvent('player.chat', event => {
  // Tell the player a normal message
  event.player.tell(Component.string('Hello world'))
  // Now in black
  event.player.tell(Component.black('Welcome to the dark side, we have cookies!'))
  // Tell them the diamond item, in whatever language they have set
  event.player.tell(Component.translate('item.minecraft.diamond'))
  // Now tell them whatever key they have crouching set to
  event.player.tell(Component.keybind('key.sneak'))
  // And finally show them the nbt data of the item they are holding
  event.player.tell(Component.prettyPrintNbt(event.player.mainHandItem.nbt))
})
```

### MutableComponent

These are methods you can call on any MutableComponent. This includes ComponentKJS, which is a KubeJS extension for vanilla's components and is injected into vanillas code on runtime. All methods from ComponentKJS are included, but only relevant ones from vanilla are included.

<table border="1" id="bkmrk-name-return-type-inf-0" style="border-collapse: collapse; width: 100%; height: 702px;"><thead><tr style="height: 29px;"><td style="width: 33.3333%; height: 35px;">Name

</td><td style="width: 33.3333%; height: 35px;">Return Type</td><td style="width: 33.3333%; height: 35px;">Info</td></tr></thead><tbody><tr style="height: 29px;"><td style="width: 33.3333%; height: 29px;">iterator()</td><td style="width: 33.3333%; height: 29px;">Iterator&lt;Component&gt;</td><td style="width: 33.3333%; height: 29px;">Returns an Iterator for the components contained in this component, useful for when multiple have been joined or appended. From ComponentKJS.</td></tr><tr style="height: 29px;"><td style="width: 33.3333%; height: 29px;">self()</td><td style="width: 33.3333%; height: 29px;">MutableComponent</td><td style="width: 33.3333%; height: 29px;">Returns the component you ran it on. From ComponentKJS.</td></tr><tr style="height: 29px;"><td style="width: 33.3333%; height: 29px;">toJson()</td><td style="width: 33.3333%; height: 29px;">JsonElement</td><td style="width: 33.3333%; height: 29px;">Returns the Json representation of this Component. From ComponentKJS.</td></tr><tr style="height: 29px;"><td style="width: 33.3333%; height: 29px;">&lt;color&gt;()</td><td style="width: 33.3333%; height: 29px;">MutableComponent</td><td style="width: 33.3333%; height: 29px;">Modifies the Component with the specified color applied as formatting, and returns itself. Do not include the &lt;&gt; brackets. From ComponentKJS.</td></tr><tr style="height: 29px;"><td style="width: 33.3333%; height: 29px;">color(Color c)</td><td style="width: 33.3333%; height: 29px;">MutableComponent</td><td style="width: 33.3333%; height: 29px;">Modifies the Component to have the input Color, and returns itself. (Color is a Rhino color). From ComponentKJS.</td></tr><tr style="height: 29px;"><td style="width: 33.3333%; height: 29px;">noColor()</td><td style="width: 33.3333%; height: 29px;">MutableComponent</td><td style="width: 33.3333%; height: 29px;">Modifies the Component to have no color, and returns itself. From ComponentKJS.</td></tr><tr style="height: 29px;"><td style="width: 33.3333%; height: 29px;">bold()

italic()

underlined()

strikethrough()

obfuscated()

</td><td style="width: 33.3333%; height: 29px;">MutableComponent</td><td style="width: 33.3333%; height: 29px;">Modifies the Component to have said formatting and returns itself. From ComponentKJS.</td></tr><tr style="height: 29px;"><td style="width: 33.3333%; height: 29px;">bold(<span class="pl-c1">@</span><span class="pl-c1">Nullable</span> <span class="pl-smi">Boolean</span> <span class="pl-s1">value</span>)

italic(<span class="pl-c1">@</span><span class="pl-c1">Nullable</span> <span class="pl-smi">Boolean</span> <span class="pl-s1">value</span>)

underlined(<span class="pl-c1">@</span><span class="pl-c1">Nullable</span> <span class="pl-smi">Boolean</span> <span class="pl-s1">value</span>)

strikethrough(<span class="pl-c1">@</span><span class="pl-c1">Nullable</span> <span class="pl-smi">Boolean</span> <span class="pl-s1">value</span>)

obfuscated(<span class="pl-c1">@</span><span class="pl-c1">Nullable</span> <span class="pl-smi">Boolean</span> <span class="pl-s1">value</span>)

</td><td style="width: 33.3333%; height: 29px;">MutableComponent</td><td style="width: 33.3333%; height: 29px;">Modifies the Component to have said formatting and returns itself. From ComponentKJS.</td></tr><tr style="height: 29px;"><td style="width: 33.3333%; height: 29px;"><span class="pl-en"><span class="pl-token" data-hydro-click="{"event_type":"code_navigation.click_on_symbol","payload":{"action":"click_on_symbol","repository_id":46427577,"ref":"1.18/main","language":"Java","backend":"ALEPH_FUZZY","code_nav_context":"BLOB_VIEW","retry_backend":"","originating_url":"https://github.com/KubeJS-Mods/KubeJS/find-definition?q=insertion&blob_path=common%2Fsrc%2Fmain%2Fjava%2Fdev%2Flatvian%2Fmods%2Fkubejs%2Fcore%2FComponentKJS.java&ref=1.18%2Fmain&language=Java&row=153&col=26&code_nav_context=BLOB_VIEW","user_id":73862885}}" data-hydro-click-hmac="5c12c47eec7f01b276e23682fb85a56cc0d4f03635890ff6e9722498b43585b3">insertion</span></span>(<span class="pl-c1">@</span><span class="pl-c1">Nullable</span> <span class="pl-smi">String</span> <span class="pl-s1">s)</span></td><td style="width: 33.3333%; height: 29px;">MutableComponent</td><td style="width: 33.3333%; height: 29px;">Makes the Component insert the specified string into the players chat box when shift clicked (does not send it) and returns itself. From ComponentKJS.</td></tr><tr style="height: 29px;"><td style="width: 33.3333%; height: 29px;"><span class="pl-en"><span class="pl-token" data-hydro-click="{"event_type":"code_navigation.click_on_symbol","payload":{"action":"click_on_symbol","repository_id":46427577,"ref":"1.18/main","language":"Java","backend":"ALEPH_FUZZY","code_nav_context":"BLOB_VIEW","retry_backend":"","originating_url":"https://github.com/KubeJS-Mods/KubeJS/find-definition?q=font&blob_path=common%2Fsrc%2Fmain%2Fjava%2Fdev%2Flatvian%2Fmods%2Fkubejs%2Fcore%2FComponentKJS.java&ref=1.18%2Fmain&language=Java&row=157&col=26&code_nav_context=BLOB_VIEW","user_id":73862885}}" data-hydro-click-hmac="276f1ba53a07fc4f1b441a2c7b26cd61a67e923d93dee734be42ef4503735a65">font</span></span>(<span class="pl-c1">@</span><span class="pl-c1">Nullable</span> <span class="pl-smi">ResourceLocation</span> <span class="pl-s1">s</span>)</td><td style="width: 33.3333%; height: 29px;">MutableComponent</td><td style="width: 33.3333%; height: 29px;">Changes the Components font to the specified font and returns itself. For more information on adding fonts see the [Minecraft Wiki's Resource packs page.](https://minecraft.fandom.com/wiki/Resource_Pack#Fonts) From ComponentKJS.</td></tr><tr style="height: 29px;"><td style="width: 33.3333%; height: 29px;"><span class="pl-en"><span class="pl-token" data-hydro-click="{"event_type":"code_navigation.click_on_symbol","payload":{"action":"click_on_symbol","repository_id":46427577,"ref":"1.18/main","language":"Java","backend":"ALEPH_FUZZY","code_nav_context":"BLOB_VIEW","retry_backend":"","originating_url":"https://github.com/KubeJS-Mods/KubeJS/find-definition?q=click&blob_path=common%2Fsrc%2Fmain%2Fjava%2Fdev%2Flatvian%2Fmods%2Fkubejs%2Fcore%2FComponentKJS.java&ref=1.18%2Fmain&language=Java&row=161&col=26&code_nav_context=BLOB_VIEW","user_id":73862885}}" data-hydro-click-hmac="bbd9d948e199cbf55c2bb4aeed654147503a1e31b4d79981eb8b3d38483f03e6">click</span></span>(<span class="pl-c1">@</span><span class="pl-c1">Nullable</span> <span class="pl-smi">ClickEvent</span> <span class="pl-s1">s)</span></td><td style="width: 33.3333%; height: 29px;">MutableComponent</td><td style="width: 33.3333%; height: 29px;">Sets this components ClickEvent to the specified ClickEvent. From ComponentKJS.</td></tr><tr style="height: 29px;"><td style="width: 33.3333%; height: 29px;"><span class="pl-en"><span class="pl-token" data-hydro-click="{"event_type":"code_navigation.click_on_symbol","payload":{"action":"click_on_symbol","repository_id":46427577,"ref":"1.18/main","language":"Java","backend":"ALEPH_FUZZY","code_nav_context":"BLOB_VIEW","retry_backend":"","originating_url":"https://github.com/KubeJS-Mods/KubeJS/find-definition?q=hover&blob_path=common%2Fsrc%2Fmain%2Fjava%2Fdev%2Flatvian%2Fmods%2Fkubejs%2Fcore%2FComponentKJS.java&ref=1.18%2Fmain&language=Java&row=165&col=26&code_nav_context=BLOB_VIEW","user_id":73862885}}" data-hydro-click-hmac="d27c550e46a885d9524d27dba04d8adf0cea0b657f93851ea2de0fbad01a39d4">hover</span></span>(<span class="pl-c1">@</span><span class="pl-c1">Nullable</span> <span class="pl-smi">Component</span> <span class="pl-s1">s</span>)</td><td style="width: 33.3333%; height: 29px;">MutableComponent</td><td style="width: 33.3333%; height: 29px;">Sets the hover tooltip for this Component to the input Component. From ComponentKJS.</td></tr><tr style="height: 29px;"><td style="width: 33.3333%; height: 29px;"><span class="pl-en"><span class="pl-token" data-hydro-click="{"event_type":"code_navigation.click_on_symbol","payload":{"action":"click_on_symbol","repository_id":46427577,"ref":"1.18/main","language":"Java","backend":"ALEPH_FUZZY","code_nav_context":"BLOB_VIEW","retry_backend":"","originating_url":"https://github.com/KubeJS-Mods/KubeJS/find-definition?q=hover&blob_path=common%2Fsrc%2Fmain%2Fjava%2Fdev%2Flatvian%2Fmods%2Fkubejs%2Fcore%2FComponentKJS.java&ref=1.18%2Fmain&language=Java&row=165&col=26&code_nav_context=BLOB_VIEW","user_id":73862885}}" data-hydro-click-hmac="d27c550e46a885d9524d27dba04d8adf0cea0b657f93851ea2de0fbad01a39d4">setStyle(Style style)</span></span></td><td style="width: 33.3333%; height: 29px;">MutableComponent</td><td style="width: 33.3333%; height: 29px;">Sets the style to the input Style (net.minecraft.network.chat.Style) and returns itself. Not recommended for use, use the specific methods added by CompontentKJS instead.</td></tr><tr style="height: 29px;"><td style="width: 33.3333%; height: 29px;"><span class="pl-en"><span class="pl-token" data-hydro-click="{"event_type":"code_navigation.click_on_symbol","payload":{"action":"click_on_symbol","repository_id":46427577,"ref":"1.18/main","language":"Java","backend":"ALEPH_FUZZY","code_nav_context":"BLOB_VIEW","retry_backend":"","originating_url":"https://github.com/KubeJS-Mods/KubeJS/find-definition?q=hover&blob_path=common%2Fsrc%2Fmain%2Fjava%2Fdev%2Flatvian%2Fmods%2Fkubejs%2Fcore%2FComponentKJS.java&ref=1.18%2Fmain&language=Java&row=165&col=26&code_nav_context=BLOB_VIEW","user_id":73862885}}" data-hydro-click-hmac="d27c550e46a885d9524d27dba04d8adf0cea0b657f93851ea2de0fbad01a39d4">append(String string)</span></span></td><td style="width: 33.3333%; height: 29px;">MutableComponent</td><td style="width: 33.3333%; height: 29px;">Appends the input string as a basic TextComponent to this Component then returns itself.</td></tr><tr style="height: 29px;"><td style="width: 33.3333%; height: 29px;"><span class="pl-en"><span class="pl-token" data-hydro-click="{"event_type":"code_navigation.click_on_symbol","payload":{"action":"click_on_symbol","repository_id":46427577,"ref":"1.18/main","language":"Java","backend":"ALEPH_FUZZY","code_nav_context":"BLOB_VIEW","retry_backend":"","originating_url":"https://github.com/KubeJS-Mods/KubeJS/find-definition?q=hover&blob_path=common%2Fsrc%2Fmain%2Fjava%2Fdev%2Flatvian%2Fmods%2Fkubejs%2Fcore%2FComponentKJS.java&ref=1.18%2Fmain&language=Java&row=165&col=26&code_nav_context=BLOB_VIEW","user_id":73862885}}" data-hydro-click-hmac="d27c550e46a885d9524d27dba04d8adf0cea0b657f93851ea2de0fbad01a39d4">append(Component component)</span></span></td><td style="width: 33.3333%; height: 29px;">MutableComponent</td><td style="width: 33.3333%; height: 29px;">Appends the input Component to this Component then returns itself.</td></tr><tr style="height: 29px;"><td style="width: 33.3333%; height: 29px;"><span class="pl-en"><span class="pl-token" data-hydro-click="{"event_type":"code_navigation.click_on_symbol","payload":{"action":"click_on_symbol","repository_id":46427577,"ref":"1.18/main","language":"Java","backend":"ALEPH_FUZZY","code_nav_context":"BLOB_VIEW","retry_backend":"","originating_url":"https://github.com/KubeJS-Mods/KubeJS/find-definition?q=hover&blob_path=common%2Fsrc%2Fmain%2Fjava%2Fdev%2Flatvian%2Fmods%2Fkubejs%2Fcore%2FComponentKJS.java&ref=1.18%2Fmain&language=Java&row=165&col=26&code_nav_context=BLOB_VIEW","user_id":73862885}}" data-hydro-click-hmac="d27c550e46a885d9524d27dba04d8adf0cea0b657f93851ea2de0fbad01a39d4">withStyle(Style style)</span></span></td><td style="width: 33.3333%; height: 29px;">MutableComponent</td><td style="width: 33.3333%; height: 29px;">Merges the input style with the current style, preffering properties from the new style if a conflict exists.</td></tr><tr style="height: 29px;"><td style="width: 33.3333%; height: 29px;"><span class="pl-en"><span class="pl-token" data-hydro-click="{"event_type":"code_navigation.click_on_symbol","payload":{"action":"click_on_symbol","repository_id":46427577,"ref":"1.18/main","language":"Java","backend":"ALEPH_FUZZY","code_nav_context":"BLOB_VIEW","retry_backend":"","originating_url":"https://github.com/KubeJS-Mods/KubeJS/find-definition?q=hover&blob_path=common%2Fsrc%2Fmain%2Fjava%2Fdev%2Flatvian%2Fmods%2Fkubejs%2Fcore%2FComponentKJS.java&ref=1.18%2Fmain&language=Java&row=165&col=26&code_nav_context=BLOB_VIEW","user_id":73862885}}" data-hydro-click-hmac="d27c550e46a885d9524d27dba04d8adf0cea0b657f93851ea2de0fbad01a39d4">getStyle()</span></span></td><td style="width: 33.3333%; height: 29px;">Style</td><td style="width: 33.3333%; height: 29px;">Returns this Components current Style.</td></tr><tr style="height: 29px;"><td style="width: 33.3333%; height: 29px;"><span class="pl-en"><span class="pl-token" data-hydro-click="{"event_type":"code_navigation.click_on_symbol","payload":{"action":"click_on_symbol","repository_id":46427577,"ref":"1.18/main","language":"Java","backend":"ALEPH_FUZZY","code_nav_context":"BLOB_VIEW","retry_backend":"","originating_url":"https://github.com/KubeJS-Mods/KubeJS/find-definition?q=hover&blob_path=common%2Fsrc%2Fmain%2Fjava%2Fdev%2Flatvian%2Fmods%2Fkubejs%2Fcore%2FComponentKJS.java&ref=1.18%2Fmain&language=Java&row=165&col=26&code_nav_context=BLOB_VIEW","user_id":73862885}}" data-hydro-click-hmac="d27c550e46a885d9524d27dba04d8adf0cea0b657f93851ea2de0fbad01a39d4">getContents()</span></span></td><td style="width: 33.3333%; height: 29px;">MutableComponent</td><td style="width: 33.3333%; height: 29px;">Returns this Components contents. Will return the text for TextComponents, the pattern for SelectorComponents and an empty string for all other Components.</td></tr><tr style="height: 29px;"><td style="width: 33.3333%; height: 29px;"><span class="pl-en"><span class="pl-token" data-hydro-click="{"event_type":"code_navigation.click_on_symbol","payload":{"action":"click_on_symbol","repository_id":46427577,"ref":"1.18/main","language":"Java","backend":"ALEPH_FUZZY","code_nav_context":"BLOB_VIEW","retry_backend":"","originating_url":"https://github.com/KubeJS-Mods/KubeJS/find-definition?q=hover&blob_path=common%2Fsrc%2Fmain%2Fjava%2Fdev%2Flatvian%2Fmods%2Fkubejs%2Fcore%2FComponentKJS.java&ref=1.18%2Fmain&language=Java&row=165&col=26&code_nav_context=BLOB_VIEW","user_id":73862885}}" data-hydro-click-hmac="d27c550e46a885d9524d27dba04d8adf0cea0b657f93851ea2de0fbad01a39d4">getSiblings()</span></span></td><td style="width: 33.3333%; height: 29px;"><span class="pl-en"><span class="pl-token" data-hydro-click="{"event_type":"code_navigation.click_on_symbol","payload":{"action":"click_on_symbol","repository_id":46427577,"ref":"1.18/main","language":"Java","backend":"ALEPH_FUZZY","code_nav_context":"BLOB_VIEW","retry_backend":"","originating_url":"https://github.com/KubeJS-Mods/KubeJS/find-definition?q=hover&blob_path=common%2Fsrc%2Fmain%2Fjava%2Fdev%2Flatvian%2Fmods%2Fkubejs%2Fcore%2FComponentKJS.java&ref=1.18%2Fmain&language=Java&row=165&col=26&code_nav_context=BLOB_VIEW","user_id":73862885}}" data-hydro-click-hmac="d27c550e46a885d9524d27dba04d8adf0cea0b657f93851ea2de0fbad01a39d4">List&lt;Component&gt; </span></span></td><td style="width: 33.3333%; height: 29px;">Returns a list of all Components which have been append()ed to this Component </td></tr><tr style="height: 29px;"><td style="width: 33.3333%; height: 29px;"><span class="pl-en"><span class="pl-token" data-hydro-click="{"event_type":"code_navigation.click_on_symbol","payload":{"action":"click_on_symbol","repository_id":46427577,"ref":"1.18/main","language":"Java","backend":"ALEPH_FUZZY","code_nav_context":"BLOB_VIEW","retry_backend":"","originating_url":"https://github.com/KubeJS-Mods/KubeJS/find-definition?q=hover&blob_path=common%2Fsrc%2Fmain%2Fjava%2Fdev%2Flatvian%2Fmods%2Fkubejs%2Fcore%2FComponentKJS.java&ref=1.18%2Fmain&language=Java&row=165&col=26&code_nav_context=BLOB_VIEW","user_id":73862885}}" data-hydro-click-hmac="d27c550e46a885d9524d27dba04d8adf0cea0b657f93851ea2de0fbad01a39d4">plainCopy()</span></span></td><td style="width: 33.3333%; height: 29px;">BaseComponent</td><td style="width: 33.3333%; height: 29px;">Returns a basic copy of this, preserving only the contents and not the style or siblings.</td></tr><tr style="height: 29px;"><td style="width: 33.3333%; height: 29px;"><span class="pl-en"><span class="pl-token" data-hydro-click="{"event_type":"code_navigation.click_on_symbol","payload":{"action":"click_on_symbol","repository_id":46427577,"ref":"1.18/main","language":"Java","backend":"ALEPH_FUZZY","code_nav_context":"BLOB_VIEW","retry_backend":"","originating_url":"https://github.com/KubeJS-Mods/KubeJS/find-definition?q=hover&blob_path=common%2Fsrc%2Fmain%2Fjava%2Fdev%2Flatvian%2Fmods%2Fkubejs%2Fcore%2FComponentKJS.java&ref=1.18%2Fmain&language=Java&row=165&col=26&code_nav_context=BLOB_VIEW","user_id":73862885}}" data-hydro-click-hmac="d27c550e46a885d9524d27dba04d8adf0cea0b657f93851ea2de0fbad01a39d4">copy()</span></span></td><td style="width: 33.3333%; height: 29px;">MutableComponent</td><td style="width: 33.3333%; height: 29px;">Returns a full copy of this Component, preserving style and siblings</td></tr><tr><td style="width: 33.3333%;"><span class="pl-en"><span class="pl-token" data-hydro-click="{"event_type":"code_navigation.click_on_symbol","payload":{"action":"click_on_symbol","repository_id":46427577,"ref":"1.18/main","language":"Java","backend":"ALEPH_FUZZY","code_nav_context":"BLOB_VIEW","retry_backend":"","originating_url":"https://github.com/KubeJS-Mods/KubeJS/find-definition?q=hover&blob_path=common%2Fsrc%2Fmain%2Fjava%2Fdev%2Flatvian%2Fmods%2Fkubejs%2Fcore%2FComponentKJS.java&ref=1.18%2Fmain&language=Java&row=165&col=26&code_nav_context=BLOB_VIEW","user_id":73862885}}" data-hydro-click-hmac="d27c550e46a885d9524d27dba04d8adf0cea0b657f93851ea2de0fbad01a39d4">getString()</span></span></td><td style="width: 33.3333%;">String</td><td style="width: 33.3333%;">Returns this components text as a String. Will return a blank string for any non-text component</td></tr></tbody></table>

More complex examples:

```JavaScript
// First a prefix, like a rank. This won't be changing so we can just declare it up here.
const prefix = Component.darkRed('[Admin]').underlined()

onEvent('player.chat', event => {
  
  // First cancel the event because we are going to be sending the message ourselves
  event.cancel()
  
  // The main Component we will be adding stuff to. It is just a copy of the prefix component for now
  let component = prefix.copy() // If we didn't copy it all the modifications we made to it would be applied to the original as well!
  
  // Make a component of the players name and then surround with < > and make it white again. Then append it our main copmponent.
  // A component will inherit any styiling it doesnt have from whatever it has been .append()ed to, so you need to apply formatting	rather liberally some times!
  let playerName = Component.string(event.getUsername())
  // Doing it this way means we only have to apply the white formatting and no underline once to the name
  let nameComponent = Component.white(' <').underlined(false).append(playerName).append('> ')
  component.append(nameComponent)
  
  // Finnally add the message (obfuscated, of course) and send it!
  // We make sure to set its color and underline though, otherwise it will end up inheriting the red and underline from the prefix!
  component.append(Component.string(event.message).obfuscated().white().underlined(false))
  event.server.tell(component)
  
})	
```