-
Notifications
You must be signed in to change notification settings - Fork 0
Using BaseComponents
Felix Naumann edited this page Feb 19, 2022
·
2 revisions
Using BaseComponents is really easy with this library. All you need to do is to implement RicherPrompt
in your custom Prompt
class. Instead of implementing String getPromptText(ConversationContext context
you need to implement BaseComponent getRicherPromptText(ConversationContext context)
. Of course you have to use RicherConversationFactory
when creating the conversation. The underlying implementation will then send the base component if one is given and the user conversing is a player. If it's the console you may still use BaseComponents, but they will be converted to plain text in the console.
Full Example:
A basic prompt using base components that just displays a message.
public class BaseComponentPrompt extends MessagePrompt implements RicherPrompt {
@Override
public BaseComponent getRicherPromptText(ConversationContext context) {
return new TextComponent(new ComponentBuilder()
.append("I'm a ")
.color(ChatColor.of("#C38D9E"))
.append("message created from")
.underlined(true)
.append(" base components")
.color(ChatColor.of("#3FEEE6"))
.underlined(false)
.bold(true)
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(new ComponentBuilder()
.append("Yes, really!")
.color(ChatColor.of("#E8A87C"))
.create())))
.append(" in a conversation prompt.")
.bold(false)
.color(ChatColor.of("#C38D9E"))
.create());
}
@Override
protected Prompt getNextPrompt(ConversationContext context) {
return END_OF_CONVERSATION;
}
}
Creating and initiating the conversation.
Conversation conversation = new RicherConversationFactory(this)
.withLocalEcho(true)
.withModality(true)
.withPrefix(context -> ChatColor.of("#E27D60") + "[" + ChatColor.of("#41B3A3") + "ExamplePlugin" + ChatColor.of("#E27D60") + "] ")
.withFirstPrompt(new BaseComponentPrompt())
.buildConversation(player);
conversation.begin();