public class FancyMessage extends java.lang.Object implements java.lang.Cloneable, java.lang.Iterable<MessagePart>, org.bukkit.configuration.serialization.ConfigurationSerializable
This class follows the builder pattern, allowing for method chaining.
It is set up such that invocations of property-setting methods will affect the current editing component,
and a call to then()
or then(String)
will append a new editing component to the end of the message,
optionally initializing it with text. Further property-setting method calls will affect that editing component.
Constructor and Description |
---|
FancyMessage()
Creates a JSON message without text.
|
FancyMessage(java.lang.String firstPartText)
Creates a JSON message with text.
|
FancyMessage(TextualComponent firstPartText) |
Modifier and Type | Method and Description |
---|---|
FancyMessage |
achievementTooltip(java.lang.String name)
Set the behavior of the current editing component to display information about an achievement when the client hovers over the text.
|
FancyMessage |
clone() |
FancyMessage |
color(org.bukkit.ChatColor color)
Sets the color of the current editing component to a value.
|
FancyMessage |
command(java.lang.String command)
Set the behavior of the current editing component to instruct the client to send the specified string to the server as a chat message when the currently edited part of the
FancyMessage is clicked. |
static FancyMessage |
deserialize(java.util.Map<java.lang.String,java.lang.Object> serialized)
Deserializes a JSON-represented message from a mapping of key-value pairs.
|
static FancyMessage |
deserialize(java.lang.String json)
Deserializes a fancy message from its JSON representation.
|
FancyMessage |
file(java.lang.String path)
Set the behavior of the current editing component to instruct the client to open a file on the client side filesystem when the currently edited part of the
FancyMessage is clicked. |
FancyMessage |
formattedTooltip(FancyMessage... lines)
Set the behavior of the current editing component to display the specified lines of formatted text when the client hovers over the text.
|
FancyMessage |
formattedTooltip(FancyMessage text)
Set the behavior of the current editing component to display formatted text when the client hovers over the text.
|
FancyMessage |
formattedTooltip(java.lang.Iterable<FancyMessage> lines)
Set the behavior of the current editing component to display the specified lines of formatted text when the client hovers over the text.
|
FancyMessage |
insert(java.lang.String command)
Set the behavior of the current editing component to instruct the client to append the chat input box content with the specified string when the currently edited part of the
FancyMessage is SHIFT-CLICKED. |
java.util.Iterator<MessagePart> |
iterator()
Internally called method.
|
FancyMessage |
link(java.lang.String url)
Set the behavior of the current editing component to instruct the client to open a webpage in the client's web browser when the currently edited part of the
FancyMessage is clicked. |
void |
send(org.bukkit.command.CommandSender sender)
Sends this message to a command sender.
|
void |
send(java.lang.Iterable<? extends org.bukkit.command.CommandSender> senders)
Sends this message to multiple command senders.
|
void |
send(org.bukkit.entity.Player player)
Sends this message to a player.
|
java.util.Map<java.lang.String,java.lang.Object> |
serialize() |
FancyMessage |
style(org.bukkit.ChatColor... styles)
Sets the stylization of the current editing component.
|
FancyMessage |
suggest(java.lang.String command)
Set the behavior of the current editing component to instruct the client to replace the chat input box content with the specified string when the currently edited part of the
FancyMessage is clicked. |
FancyMessage |
text(java.lang.String text)
Sets the text of the current editing component to a value.
|
FancyMessage |
text(TextualComponent text)
Sets the text of the current editing component to a value.
|
FancyMessage |
then()
Terminate construction of the current editing component, and begin construction of a new message component.
|
FancyMessage |
then(java.lang.String text)
Terminate construction of the current editing component, and begin construction of a new message component.
|
FancyMessage |
then(TextualComponent text)
Terminate construction of the current editing component, and begin construction of a new message component.
|
java.lang.String |
toJSONString()
Serialize this fancy message, converting it into syntactically-valid JSON using a
JsonWriter . |
java.lang.String |
toOldMessageFormat()
Convert this message to a human-readable string with limited formatting.
|
FancyMessage |
tooltip(java.lang.Iterable<java.lang.String> lines)
Set the behavior of the current editing component to display raw text when the client hovers over the text.
|
FancyMessage |
tooltip(java.lang.String... lines)
Set the behavior of the current editing component to display raw text when the client hovers over the text.
|
FancyMessage |
tooltip(java.lang.String text)
Set the behavior of the current editing component to display raw text when the client hovers over the text.
|
FancyMessage |
translationReplacements(FancyMessage... replacements)
If the text is a translatable key, and it has replaceable values, this function can be used to set the replacements that will be used in the message.
|
FancyMessage |
translationReplacements(java.lang.Iterable<FancyMessage> replacements)
If the text is a translatable key, and it has replaceable values, this function can be used to set the replacements that will be used in the message.
|
FancyMessage |
translationReplacements(java.lang.String... replacements)
If the text is a translatable key, and it has replaceable values, this function can be used to set the replacements that will be used in the message.
|
void |
writeJson(JsonWriter writer)
Writes the JSON representation of this object to the specified writer.
|
public FancyMessage(java.lang.String firstPartText)
firstPartText
- The existing text in the message.public FancyMessage(TextualComponent firstPartText)
public FancyMessage()
public FancyMessage clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
public FancyMessage text(java.lang.String text)
text
- The new text of the current editing component.public FancyMessage text(TextualComponent text)
text
- The new text of the current editing component.public FancyMessage color(org.bukkit.ChatColor color)
color
- The new color of the current editing component.java.lang.IllegalArgumentException
- If the specified ChatColor
enumeration value is not a color (but a format value).public FancyMessage style(org.bukkit.ChatColor... styles)
styles
- The array of styles to apply to the editing component.java.lang.IllegalArgumentException
- If any of the enumeration values in the array do not represent formatters.public FancyMessage file(java.lang.String path)
FancyMessage
is clicked.path
- The path of the file on the client filesystem.public FancyMessage link(java.lang.String url)
FancyMessage
is clicked.url
- The URL of the page to open when the link is clicked.public FancyMessage suggest(java.lang.String command)
FancyMessage
is clicked.
The client will not immediately send the command to the server to be executed unless the client player submits the command/chat message, usually with the enter key.command
- The text to display in the chat bar of the client.public FancyMessage insert(java.lang.String command)
FancyMessage
is SHIFT-CLICKED.
The client will not immediately send the command to the server to be executed unless the client player submits the command/chat message, usually with the enter key.command
- The text to append to the chat bar of the client.public FancyMessage command(java.lang.String command)
FancyMessage
is clicked.
The client will immediately send the command to the server to be executed when the editing component is clicked.command
- The text to display in the chat bar of the client.public FancyMessage achievementTooltip(java.lang.String name)
Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.
name
- The name of the achievement to display, excluding the "achievement." prefix.public FancyMessage tooltip(java.lang.String text)
Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.
text
- The text, which supports newlines, which will be displayed to the client upon hovering.public FancyMessage tooltip(java.lang.Iterable<java.lang.String> lines)
Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.
lines
- The lines of text which will be displayed to the client upon hovering. The iteration order of this object will be the order in which the lines of the tooltip are created.public FancyMessage tooltip(java.lang.String... lines)
Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.
lines
- The lines of text which will be displayed to the client upon hovering.public FancyMessage formattedTooltip(FancyMessage text)
Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.
text
- The formatted text which will be displayed to the client upon hovering.public FancyMessage formattedTooltip(FancyMessage... lines)
Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.
lines
- The lines of formatted text which will be displayed to the client upon hovering.public FancyMessage formattedTooltip(java.lang.Iterable<FancyMessage> lines)
Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.
lines
- The lines of text which will be displayed to the client upon hovering. The iteration order of this object will be the order in which the lines of the tooltip are created.public FancyMessage translationReplacements(java.lang.String... replacements)
replacements
- The replacements, in order, that will be used in the language-specific message.public FancyMessage translationReplacements(FancyMessage... replacements)
replacements
- The replacements, in order, that will be used in the language-specific message.public FancyMessage translationReplacements(java.lang.Iterable<FancyMessage> replacements)
replacements
- The replacements, in order, that will be used in the language-specific message.public FancyMessage then(java.lang.String text)
text
- The text which will populate the new message component.public FancyMessage then(TextualComponent text)
text
- The text which will populate the new message component.public FancyMessage then()
public void writeJson(JsonWriter writer) throws java.io.IOException
writer
- The JSON writer which will receive the object.java.io.IOException
- If an error occurs writing to the stream.public java.lang.String toJSONString()
JsonWriter
.
This JSON should be compatible with vanilla formatter commands such as /tellraw
.public void send(org.bukkit.entity.Player player)
player
- The player who will receive the message.public void send(org.bukkit.command.CommandSender sender)
sender
- The command sender who will receive the message.toOldMessageFormat()
public void send(java.lang.Iterable<? extends org.bukkit.command.CommandSender> senders)
senders
- The command senders who will receive the message.send(CommandSender)
public java.lang.String toOldMessageFormat()
Serialization of this message by using this message will include (in this order for each message part):
The primary omissions are tooltips and clickable actions. Consequently, this method should be used only as a last resort.
Color and formatting can be removed from the returned string by using ChatColor.stripColor(String)
.
public java.util.Map<java.lang.String,java.lang.Object> serialize()
serialize
in interface org.bukkit.configuration.serialization.ConfigurationSerializable
public static FancyMessage deserialize(java.util.Map<java.lang.String,java.lang.Object> serialized)
serialized
- The key-value mapping which represents a fancy message.public java.util.Iterator<MessagePart> iterator()
iterator
in interface java.lang.Iterable<MessagePart>
public static FancyMessage deserialize(java.lang.String json) throws java.io.IOException
toJSONString()
, and is compatible with vanilla inputs.json
- The JSON string which represents a fancy message.FancyMessage
representing the parameterized JSON message.java.io.IOException