public final class MessageSender extends Object implements Cloneable
The MessageSender class represents the action to display a
list of messages to a player using MessageExecutor instances for parse
different message types and format every message type respectively.
// Creating an instance
MessageSender sender = new MessageSender(
Bukkit.getOnlinePlayers(), // can be single or null
Bukkit.getPlayer("Markiplier")
);
// only chat and bossbar messages are allowed with
// these flags, this is optional
sender.setFlags(MessageFlag.CHAT, MessageFlag.BOSSBAR);
// send multiple lists and arrays using the same instance
sender.send(false, plugin.getConfig().getStringList("path"));
sender.send(false,
"[C] <R:1>My message goes here, it's colorful</R>",
"[BOSSBAR] Look, a bossbar message :o"
);
Also, this objects implements the Cloneable interface to allow
cloning an instance, instead of creating new instances separately.
See send(List) and/or send(String...) for more info.
| Modifier and Type | Class and Description |
|---|---|
static class |
MessageSender.KeyValue<T> |
| Constructor and Description |
|---|
MessageSender()
Creates a new sender without any argument defined.
|
MessageSender(Collection<? extends org.bukkit.command.CommandSender> targets,
org.bukkit.entity.Player parser)
Creates a new sender with a defined collection of targets and a player
that parses messages.
|
MessageSender(org.bukkit.command.CommandSender sender)
Creates a new sender with a defined target, and if that sender is a
player, will act as the parser.
|
MessageSender(MessageSender sender) |
| Modifier and Type | Method and Description |
|---|---|
MessageSender |
addFunctions(java.util.function.BiFunction<org.bukkit.entity.Player,String,String>... functions)
Adds new player-string functions to apply them in every string of the list
in
send(List). |
MessageSender |
addFunctions(java.util.function.UnaryOperator<String>... ops)
Adds new string operators to apply them in every string of the list
in
send(List). |
<T> MessageSender |
addKeysValues(String[] keys,
T... values) |
<T> MessageSender |
addKeyValue(MessageSender.KeyValue<T> keyValue) |
<T> MessageSender |
addKeyValue(String key,
T value) |
<T> MessageSender |
addKeyValue(java.util.function.Supplier<MessageSender.KeyValue<T>> supplier) |
@NotNull MessageSender |
clone()
Creates and returns a copy of this sender.
|
static @NotNull MessageSender |
fromLoaded()
Returns a clone of the loaded static MessageSender instance.
|
static <T> MessageSender.KeyValue<T> |
newKeyValue(String key,
T value) |
boolean |
send(List<String> stringList)
Sends a string list to the defined targets of the sender.
|
boolean |
send(String... strings)
Sends a string array to the defined targets of the sender.
|
MessageSender |
setFlags(MessageFlag... flags)
Sets the flags of the displayer to allow certain type of messages.
|
MessageSender |
setKeys(String... keys)
Sets the string keys to be replaced for the input values.
|
static void |
setLoaded(MessageSender sender)
Sets the loaded static MessageSender instance with a new sender.
|
MessageSender |
setTargets(Collection<? extends org.bukkit.command.CommandSender> targets)
The collection or array of targets that messages will be sent.
|
MessageSender |
setTargets(org.bukkit.command.CommandSender... targets)
The collection or array of targets that messages will be sent.
|
<T> MessageSender |
setValues(T... values)
Sets the string values that replaces the input keys with any kind of object.
|
boolean |
singleSend(String string)
Sends an input string to the defined targets of the sender.
|
public MessageSender(Collection<? extends org.bukkit.command.CommandSender> targets, org.bukkit.entity.Player parser)
targets - a collection of targetsparser - a player to parse messagespublic MessageSender(org.bukkit.command.CommandSender sender)
sender - a senderpublic MessageSender()
public MessageSender(MessageSender sender)
public MessageSender setTargets(Collection<? extends org.bukkit.command.CommandSender> targets)
targets - a collection of targetspublic MessageSender setTargets(org.bukkit.command.CommandSender... targets)
targets - an array of targets@SafeVarargs public final MessageSender addFunctions(java.util.function.BiFunction<org.bukkit.entity.Player,String,String>... functions)
send(List).functions - an array of functions@SafeVarargs public final MessageSender addFunctions(java.util.function.UnaryOperator<String>... ops)
send(List).ops - an array of operatorspublic MessageSender setFlags(MessageFlag... flags)
Not invoking this method or invoking it without any arguments, it will imply that all messages types are allowed.
flags - an array of flagspublic <T> MessageSender addKeyValue(MessageSender.KeyValue<T> keyValue)
public <T> MessageSender addKeyValue(java.util.function.Supplier<MessageSender.KeyValue<T>> supplier)
public <T> MessageSender addKeyValue(String key, T value)
@SafeVarargs public final <T> MessageSender addKeysValues(String[] keys, T... values)
public MessageSender setKeys(String... keys)
keys - an array of keys@SafeVarargs public final <T> MessageSender setValues(T... values)
Can detect players and entities to get its names.
T - the clazz of any given valuevalues - an array of values to be replacedpublic boolean singleSend(String string)
string - an input string to sendpublic boolean send(List<String> stringList)
If the list is empty, null or contains only one string and that string is blank/empty, it will not be sent.
stringList - a string list to sendpublic boolean send(String... strings)
If the array is empty, null or contains only one string and that string is blank/empty, it will not be sent.
strings - a string array to send@NotNull public @NotNull MessageSender clone()
public static void setLoaded(MessageSender sender)
sender - a senderNullPointerException - if sender is null@NotNull public static @NotNull MessageSender fromLoaded()
public static <T> MessageSender.KeyValue<T> newKeyValue(String key, T value)
Copyright © 2023. All rights reserved.