mirror of
https://github.com/Minestom/Minestom.git
synced 2024-09-25 13:13:14 +02:00
Cleanup Messenger, fix uuid
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
7d930ee28d
commit
e4c1c9fe8d
@ -15,26 +15,26 @@ import java.util.UUID;
|
|||||||
/**
|
/**
|
||||||
* Utility class to handle client chat settings.
|
* Utility class to handle client chat settings.
|
||||||
*/
|
*/
|
||||||
public class Messenger {
|
public final class Messenger {
|
||||||
/**
|
/**
|
||||||
* The message sent to the client if they send a chat message but it is rejected by the server.
|
* The message sent to the client if they send a chat message but it is rejected by the server.
|
||||||
*/
|
*/
|
||||||
public static final Component CANNOT_SEND_MESSAGE = Component.translatable("chat.cannotSend", NamedTextColor.RED);
|
public static final Component CANNOT_SEND_MESSAGE = Component.translatable("chat.cannotSend", NamedTextColor.RED);
|
||||||
|
private static final UUID NO_SENDER = new UUID(0, 0);
|
||||||
private static final ChatMessagePacket CANNOT_SEND_PACKET = new ChatMessagePacket(CANNOT_SEND_MESSAGE, ChatPosition.SYSTEM_MESSAGE, null);
|
private static final ChatMessagePacket CANNOT_SEND_PACKET = new ChatMessagePacket(CANNOT_SEND_MESSAGE, ChatPosition.SYSTEM_MESSAGE, NO_SENDER);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a message to a player, respecting their chat settings.
|
* Sends a message to a player, respecting their chat settings.
|
||||||
*
|
*
|
||||||
* @param player the player
|
* @param player the player
|
||||||
* @param message the message
|
* @param message the message
|
||||||
* @param position the position
|
* @param position the position
|
||||||
* @param uuid the UUID of the sender, if any
|
* @param uuid the UUID of the sender, if any
|
||||||
* @return if the message was sent
|
* @return if the message was sent
|
||||||
*/
|
*/
|
||||||
public static boolean sendMessage(@NotNull Player player, @NotNull Component message, @NotNull ChatPosition position, @Nullable UUID uuid) {
|
public static boolean sendMessage(@NotNull Player player, @NotNull Component message, @NotNull ChatPosition position, @Nullable UUID uuid) {
|
||||||
if (getChatMessageType(player).accepts(position)) {
|
if (getChatMessageType(player).accepts(position)) {
|
||||||
player.sendPacket(new ChatMessagePacket(message, position, uuid));
|
player.sendPacket(new ChatMessagePacket(message, position, Objects.requireNonNullElse(uuid, NO_SENDER)));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -43,14 +43,14 @@ public class Messenger {
|
|||||||
/**
|
/**
|
||||||
* Sends a message to some players, respecting their chat settings.
|
* Sends a message to some players, respecting their chat settings.
|
||||||
*
|
*
|
||||||
* @param players the players
|
* @param players the players
|
||||||
* @param message the message
|
* @param message the message
|
||||||
* @param position the position
|
* @param position the position
|
||||||
* @param uuid the UUID of the sender, if any
|
* @param uuid the UUID of the sender, if any
|
||||||
*/
|
*/
|
||||||
public static void sendMessage(@NotNull Collection<Player> players, @NotNull Component message,
|
public static void sendMessage(@NotNull Collection<Player> players, @NotNull Component message,
|
||||||
@NotNull ChatPosition position, @Nullable UUID uuid) {
|
@NotNull ChatPosition position, @Nullable UUID uuid) {
|
||||||
PacketUtils.sendGroupedPacket(players, new ChatMessagePacket(message, position, uuid),
|
PacketUtils.sendGroupedPacket(players, new ChatMessagePacket(message, position, Objects.requireNonNullElse(uuid, NO_SENDER)),
|
||||||
player -> getChatMessageType(player).accepts(position));
|
player -> getChatMessageType(player).accepts(position));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user