I’m trying to create a command to send a message to a Players but i want to display the message with a Title to the tagerted player. My problem is that the doc is uncomprehensible and i don’t know how to process to create this ( i’m a beginner as sponge plugin programming).
public class MsgTitleExecutor implements CommandExecutor {
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
String msg = args.<String>getOne("Message").get();
Player player = args.<Player>getOne("Joueur").get();
// I DON'T HAVE ANY IDEA
player.sendTitle(title(Text, msg));
return CommandResult.success();
}
// This function come from hte JD but i don't understand what it does
public Text title(@Nullable Text msg) {
return msg;
}
}
What can i do to solve this problem ? How to read to understand the sponge javadoc ?
What you need to do is create a Title object.
The simplest way is to use the Titles helper class
So to create the title, you call Titles.of(message);
The message parameter is a Text object which stores the formatting and content of the title.
To create a Text object, use the Texts.of method
Your public Text title method is not needed.
Try something like this:
Hello everyone, sorry for bringing this post back to life, but I would like to know how would one implement a .stay(Integer stay) into a title. Any ideas?
Right, but I’m trying to implement it into player.sendTitle(Title.of(Text.of(),Text.of("TestTitle:"))); I’ve tried to add a .stay(10) in all parts of the line, but I’ve had no success.
Title title = Title.builder().title(Text.of("Title")).stay(100).build();
player.sendTitle(title);
You can only use Title.of() if you only want a title and optionally a subtitle. If you want to add any other properties you need to use Title.builder()
Thank you @RysingDragon and @JBYoshi for you help! I originally had the extra Title.of() in my code because I did not know how to send out just a subtitle, but I have solved my problem, base on the code provided.