Question Don't understand Components

allene50

New member
Aug 30, 2022
5
0
1
I am new to paper development and i want to use the newer chat functions that require Components.

is there any way to use them easily to send like "A player has joined!" for example?

i tried looking on the java docs but i confused me even more.
 
Solution
For the example you mentioned, you can use Component.text(String) to create a component which has that text in it verbatim. There are also several overloads of this method which allow you to specify a style and color if you want to do this. Then with Component#append(Component) you can combine multiple of these pieces of text together if you wish to. For just the basic message you mentioned, the first method should suffice however.

stefvanschie

Moderator
Staff member
Dec 17, 2021
96
3
16
8
For the example you mentioned, you can use Component.text(String) to create a component which has that text in it verbatim. There are also several overloads of this method which allow you to specify a style and color if you want to do this. Then with Component#append(Component) you can combine multiple of these pieces of text together if you wish to. For just the basic message you mentioned, the first method should suffice however.
 
Solution

stefvanschie

Moderator
Staff member
Dec 17, 2021
96
3
16
8
This depends on how you want to compare item names. If you want an exact match, you should check the equality using Object#equals(Object). If you only want the text to match, then you want to first convert it to plain text via a PlainTextComponentSerializer and then compare the resulting `String`s via Object#equals(Object).
 

Noah

Paper Developer
Staff member
Jan 4, 2022
44
6
16
8
The Netherlands
If you're using the item name to compare custom items / custom item abilities, you should use the PersistentDataContainer instead. It allows you to easily change the name of the item later down the line (or let players rename it), since you're not matching it by display name, which can break relatively easily.