diff --git a/api/src/main/java/net/kyori/adventure/audience/Audience.java b/api/src/main/java/net/kyori/adventure/audience/Audience.java index bb934e07b1..68ddfb536e 100644 --- a/api/src/main/java/net/kyori/adventure/audience/Audience.java +++ b/api/src/main/java/net/kyori/adventure/audience/Audience.java @@ -29,8 +29,12 @@ import java.util.function.Predicate; import java.util.stream.Collector; import net.kyori.adventure.bossbar.BossBar; +import net.kyori.adventure.chat.ChatType; +import net.kyori.adventure.chat.SignedMessage; import net.kyori.adventure.identity.Identified; import net.kyori.adventure.identity.Identity; +import net.kyori.adventure.identity.PlayerIdentified; +import net.kyori.adventure.identity.PlayerIdentity; import net.kyori.adventure.inventory.Book; import net.kyori.adventure.pointer.Pointered; import net.kyori.adventure.sound.Sound; @@ -39,6 +43,7 @@ import net.kyori.adventure.text.ComponentLike; import net.kyori.adventure.title.Title; import net.kyori.adventure.title.TitlePart; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; /** @@ -175,7 +180,7 @@ default void forEachAudience(final @NotNull Consumer action) { } /** - * Sends a chat message with a {@link Identity#nil() nil} identity to this {@link Audience}. + * Sends a system chat message with to this {@link Audience} with the {@link ChatType#SYSTEM system} chat type. * * @param message a message * @see Component @@ -185,37 +190,41 @@ default void forEachAudience(final @NotNull Consumer action) { */ @ForwardingAudienceOverrideNotRequired default void sendMessage(final @NotNull ComponentLike message) { - this.sendMessage(Identity.nil(), message); + this.sendMessage(message, ChatType.SYSTEM); } /** - * Sends a chat message from the given {@link Identified} to this {@link Audience}. + * Sends a player chat message from the given {@link Identified} to this {@link Audience} with the {@link ChatType#SYSTEM system} chat type. * * @param source the source of the message * @param message a message * @see Component * @since 4.0.0 + * @deprecated since 4.12.0, client errors and can reject identified messages without {@link SignedMessage} data, this may be unsupported in the future, use {@link #sendMessage(ComponentLike, SignedMessage, PlayerIdentified)} instead */ + @Deprecated @ForwardingAudienceOverrideNotRequired default void sendMessage(final @NotNull Identified source, final @NotNull ComponentLike message) { this.sendMessage(source, message.asComponent()); } /** - * Sends a chat message from the entity represented by the given {@link Identity} (or the game using {@link Identity#nil()}) to this {@link Audience}. + * Sends a player chat message from the entity represented by the given {@link Identity} to this {@link Audience} with the {@link ChatType#SYSTEM system} chat type. * * @param source the identity of the source of the message * @param message a message * @see Component * @since 4.0.0 + * @deprecated since 4.12.0, client errors and can reject identified messages without {@link SignedMessage} data, this may be unsupported in the future, use {@link #sendMessage(ComponentLike, SignedMessage, PlayerIdentified)} instead */ + @Deprecated @ForwardingAudienceOverrideNotRequired default void sendMessage(final @NotNull Identity source, final @NotNull ComponentLike message) { this.sendMessage(source, message.asComponent()); } /** - * Sends a chat message with a {@link Identity#nil() nil} identity to this {@link Audience}. + * Sends a system chat message with to this {@link Audience} with the {@link ChatType#SYSTEM system} chat type. * * @param message a message * @see Component @@ -225,37 +234,40 @@ default void sendMessage(final @NotNull Identity source, final @NotNull Componen */ @ForwardingAudienceOverrideNotRequired default void sendMessage(final @NotNull Component message) { - this.sendMessage(Identity.nil(), message); + this.sendMessage(message, ChatType.SYSTEM); } /** - * Sends a chat message from the given {@link Identified} to this {@link Audience}. + * Sends a player chat message from the given {@link Identified} to this {@link Audience} with the {@link ChatType#SYSTEM system} chat type. * * @param source the source of the message * @param message a message * @see Component * @since 4.0.0 + * @deprecated since 4.12.0, the client errors on receiving and can reject identified messages without {@link SignedMessage} data, this may be unsupported in the future, use {@link #sendMessage(Component, SignedMessage, PlayerIdentified)} instead */ - @ForwardingAudienceOverrideNotRequired + @Deprecated default void sendMessage(final @NotNull Identified source, final @NotNull Component message) { this.sendMessage(source, message, MessageType.SYSTEM); } /** - * Sends a chat message from the entity represented by the given {@link Identity} (or the game using {@link Identity#nil()}) to this {@link Audience}. + * Sends a player chat message from the entity represented by the given {@link Identity} to this {@link Audience} with the {@link ChatType#SYSTEM system} chat type. * * @param source the identity of the source of the message * @param message a message * @see Component * @since 4.0.0 + * @deprecated since 4.12.0, the client errors on receiving and can reject identified messages without {@link SignedMessage} data, this may be unsupported in the future, use {@link #sendMessage(Component, SignedMessage, PlayerIdentity)} instead */ + @Deprecated @ForwardingAudienceOverrideNotRequired default void sendMessage(final @NotNull Identity source, final @NotNull Component message) { this.sendMessage(source, message, MessageType.SYSTEM); } /** - * Sends a chat message with a {@link Identity#nil() nil} identity to this {@link Audience}. + * Sends a system chat message this {@link Audience} with the {@link ChatType} corresponding to the provided {@link MessageType}. * * @param message a message * @param type the type @@ -263,42 +275,51 @@ default void sendMessage(final @NotNull Identity source, final @NotNull Componen * @see #sendMessage(Identified, ComponentLike, MessageType) * @see #sendMessage(Identity, ComponentLike, MessageType) * @since 4.1.0 + * @deprecated for removal since 4.12.0, {@link MessageType} is deprecated for removal, use {@link #sendMessage(ComponentLike, ChatType)} */ + @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") + @Deprecated @ForwardingAudienceOverrideNotRequired default void sendMessage(final @NotNull ComponentLike message, final @NotNull MessageType type) { - this.sendMessage(Identity.nil(), message, type); + this.sendMessage(message, (ChatType) type); } /** - * Sends a chat message from the given {@link Identified} to this {@link Audience}. + * Sends a player chat message from the given {@link Identified} to this {@link Audience} with the {@link ChatType} corresponding to the provided {@link MessageType}. * * @param source the source of the message * @param message a message * @param type the type * @see Component * @since 4.0.0 + * @deprecated for removal since 4.12.0, {@link MessageType} is deprecated for removal and the client errors on receiving and can reject identified messages without {@link SignedMessage} data, use {@link #sendMessage(Component, SignedMessage, PlayerIdentified, ChatType)} instead */ + @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") + @Deprecated @ForwardingAudienceOverrideNotRequired default void sendMessage(final @NotNull Identified source, final @NotNull ComponentLike message, final @NotNull MessageType type) { this.sendMessage(source, message.asComponent(), type); } /** - * Sends a chat message from the entity represented by the given {@link Identity} (or the game using {@link Identity#nil()}) to this {@link Audience}. + * Sends a player chat message from the entity represented by the given {@link Identity} to this {@link Audience} with the {@link ChatType#SYSTEM system} chat type. * * @param source the identity of the source of the message * @param message a message * @param type the type * @see Component * @since 4.0.0 + * @deprecated for removal since 4.12.0, {@link MessageType} is deprecated for removal and the client errors on receiving and can reject identified messages without {@link SignedMessage} data, use {@link #sendMessage(Component, SignedMessage, PlayerIdentity, ChatType)} instead */ + @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") + @Deprecated @ForwardingAudienceOverrideNotRequired default void sendMessage(final @NotNull Identity source, final @NotNull ComponentLike message, final @NotNull MessageType type) { this.sendMessage(source, message.asComponent(), type); } /** - * Sends a chat message with a {@link Identity#nil() nil} identity to this {@link Audience}. + * Sends a system chat message to this {@link Audience} with the {@link ChatType} corresponding to the provided {@link MessageType}. * * @param message a message * @param type the type @@ -306,37 +327,171 @@ default void sendMessage(final @NotNull Identity source, final @NotNull Componen * @see #sendMessage(Identified, Component, MessageType) * @see #sendMessage(Identity, Component, MessageType) * @since 4.1.0 + * @deprecated for removal since 4.12.0, {@link MessageType} is deprecated for removal, use {@link #sendMessage(Component, ChatType)} instead */ + @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") + @Deprecated @ForwardingAudienceOverrideNotRequired default void sendMessage(final @NotNull Component message, final @NotNull MessageType type) { - this.sendMessage(Identity.nil(), message, type); + this.sendMessage(message, (ChatType) type); } /** - * Sends a chat message. + * Sends a player chat message from the given {@link Identified} to this {@link Audience} with the {@link ChatType} corresponding to the provided {@link MessageType}. * * @param source the source of the message * @param message a message * @param type the type * @see Component * @since 4.0.0 + * @deprecated for removal since 4.12.0, {@link MessageType} is deprecated for removal and the client errors on receiving and can reject identified messages without {@link SignedMessage} data, use {@link #sendMessage(Component, SignedMessage, PlayerIdentified, ChatType)} instead */ + @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") + @Deprecated default void sendMessage(final @NotNull Identified source, final @NotNull Component message, final @NotNull MessageType type) { - this.sendMessage(source.identity(), message, type); } /** - * Sends a chat message. + * Sends a player chat message from the entity represented by the given {@link Identity} to this {@link Audience} with the {@link ChatType} corresponding to the provided {@link MessageType}. * * @param source the identity of the source of the message * @param message a message * @param type the type * @see Component * @since 4.0.0 + * @deprecated for removal since 4.12.0, {@link MessageType} is deprecated for removal and the client errors on receiving and can reject identified messages without {@link SignedMessage} data, use use {@link #sendMessage(Component, SignedMessage, PlayerIdentity, ChatType)} instead */ + @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") + @Deprecated default void sendMessage(final @NotNull Identity source, final @NotNull Component message, final @NotNull MessageType type) { } + /** + * Sends a system chat message to this {@link Audience} with the provided {@link ChatType}. + * + * @param message the message + * @param chatType the chat type + * @since 4.12.0 + */ + @ForwardingAudienceOverrideNotRequired + default void sendMessage(final @NotNull ComponentLike message, final @NotNull ChatType chatType) { + this.sendMessage(message.asComponent(), chatType); + } + + /** + * Sends a system chat message to this {@link Audience} with the provided {@link ChatType}. + * + * @param message the message + * @param chatType the chat type + * @since 4.12.0 + */ + default void sendMessage(final @NotNull Component message, final @NotNull ChatType chatType) { + } + + /** + * Sends a signed player chat message from the given {@link PlayerIdentified} to this {@link Audience} with the {@link ChatType#CHAT chat} chat type. + * + * @param message the message + * @param signedMessage the signed message data + * @param source the source of the message + * @since 4.12.0 + */ + @ForwardingAudienceOverrideNotRequired + default void sendMessage(final @NotNull ComponentLike message, final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentified source) { + this.sendMessage(message.asComponent(), signedMessage, source); + } + + /** + * Sends a signed player chat message from the given {@link PlayerIdentified} to this {@link Audience} with the {@link ChatType#CHAT chat} chat type. + * + * @param message the message + * @param signedMessage the signed message data + * @param source the source of the message + * @since 4.12.0 + */ + @ForwardingAudienceOverrideNotRequired + default void sendMessage(final @NotNull Component message, final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentified source) { + this.sendMessage(message, signedMessage, source, ChatType.CHAT); + } + + /** + * Sends a signed player chat message from player identified by the provided {@link PlayerIdentity} to this {@link Audience} with the {@link ChatType#CHAT chat} chat type. + * + * @param message the message + * @param signedMessage the signed message data + * @param source the identity of the source of the message + * @since 4.12.0 + */ + @ForwardingAudienceOverrideNotRequired + default void sendMessage(final @NotNull ComponentLike message, final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentity source) { + this.sendMessage(message.asComponent(), signedMessage, source); + } + + /** + * Sends a signed player chat message from player identified by the provided {@link PlayerIdentity} to this {@link Audience} with the {@link ChatType#CHAT chat} chat type. + * + * @param message the message + * @param signedMessage the signed message data + * @param source the identity of the source of the message + * @since 4.12.0 + */ + @ForwardingAudienceOverrideNotRequired + default void sendMessage(final @NotNull Component message, final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentity source) { + this.sendMessage(message, signedMessage, source, ChatType.CHAT); + } + + /** + * Sends a signed player chat message from the given {@link PlayerIdentified} to this {@link Audience} with the provided {@link ChatType}. + * + * @param message the message + * @param signedMessage the signed message data + * @param source the source of the message + * @param chatType the chat type + * @since 4.12.0 + */ + @ForwardingAudienceOverrideNotRequired + default void sendMessage(final @NotNull ComponentLike message, final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentified source, final @NotNull ChatType chatType) { + this.sendMessage(message.asComponent(), signedMessage, source, chatType); + } + + /** + * Sends a signed player chat message from the given {@link PlayerIdentified} to this {@link Audience} with the provided {@link ChatType} chat type. + * + * @param message the message + * @param signedMessage the signed message data + * @param source the source of the message + * @param chatType the chat type + * @since 4.12.0 + */ + default void sendMessage(final @NotNull Component message, final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentified source, final @NotNull ChatType chatType) { + } + + /** + * Sends a signed player chat message from player identified by the provided {@link PlayerIdentity} to this {@link Audience} with the provided {@link ChatType}. + * + * @param message the message + * @param signedMessage the signed message data + * @param source the identity of the source of the message + * @param chatType the chat type + * @since 4.12.0 + */ + @ForwardingAudienceOverrideNotRequired + default void sendMessage(final @NotNull ComponentLike message, final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentity source, final @NotNull ChatType chatType) { + this.sendMessage(message.asComponent(), signedMessage, source, chatType); + } + + /** + * Sends a signed player chat message from player identified by the provided {@link PlayerIdentity} to this {@link Audience} with the provided {@link ChatType}. + * + * @param message the message + * @param signedMessage the signed message data + * @param source the identity of the source of the message + * @param chatType the chat type + * @since 4.12.0 + */ + default void sendMessage(final @NotNull Component message, final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentity source, final @NotNull ChatType chatType) { + } + /** * Sends a message on the action bar. * diff --git a/api/src/main/java/net/kyori/adventure/audience/EmptyAudience.java b/api/src/main/java/net/kyori/adventure/audience/EmptyAudience.java index 719c11c220..78737a9cb4 100644 --- a/api/src/main/java/net/kyori/adventure/audience/EmptyAudience.java +++ b/api/src/main/java/net/kyori/adventure/audience/EmptyAudience.java @@ -27,10 +27,15 @@ import java.util.function.Consumer; import java.util.function.Predicate; import java.util.function.Supplier; +import net.kyori.adventure.chat.ChatType; +import net.kyori.adventure.chat.SignedMessage; import net.kyori.adventure.identity.Identified; import net.kyori.adventure.identity.Identity; +import net.kyori.adventure.identity.PlayerIdentified; +import net.kyori.adventure.identity.PlayerIdentity; import net.kyori.adventure.inventory.Book; import net.kyori.adventure.pointer.Pointer; +import net.kyori.adventure.text.Component; import net.kyori.adventure.text.ComponentLike; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -70,23 +75,39 @@ public void sendMessage(final @NotNull ComponentLike message) { } @Override - public void sendMessage(final @NotNull Identified source, final @NotNull ComponentLike message) { + public void sendMessage(final @NotNull Component message) { } @Override - public void sendMessage(final @NotNull Identity source, final @NotNull ComponentLike message) { + public void sendMessage(final @NotNull ComponentLike message, final @NotNull ChatType chatType) { } @Override - public void sendMessage(final @NotNull ComponentLike message, final @NotNull MessageType type) { + public void sendMessage(final @NotNull ComponentLike message, final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentified source) { } @Override - public void sendMessage(final @NotNull Identified source, final @NotNull ComponentLike message, final @NotNull MessageType type) { + public void sendMessage(final @NotNull Component message, final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentified source) { } @Override - public void sendMessage(final @NotNull Identity source, final @NotNull ComponentLike message, final @NotNull MessageType type) { + public void sendMessage(final @NotNull ComponentLike message, final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentity source) { + } + + @Override + public void sendMessage(final @NotNull ComponentLike message, final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentified source, final @NotNull ChatType chatType) { + } + + @Override + public void sendMessage(final @NotNull ComponentLike message, final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentity source, final @NotNull ChatType chatType) { + } + + @Override + public void sendMessage(final @NotNull Identified source, final @NotNull Component message, final @NotNull MessageType type) { + } + + @Override + public void sendMessage(final @NotNull Identity source, final @NotNull Component message, final @NotNull MessageType type) { } @Override diff --git a/api/src/main/java/net/kyori/adventure/audience/ForwardingAudience.java b/api/src/main/java/net/kyori/adventure/audience/ForwardingAudience.java index 3bd50c7e1f..989de3efd9 100644 --- a/api/src/main/java/net/kyori/adventure/audience/ForwardingAudience.java +++ b/api/src/main/java/net/kyori/adventure/audience/ForwardingAudience.java @@ -31,8 +31,12 @@ import java.util.function.Predicate; import java.util.function.Supplier; import net.kyori.adventure.bossbar.BossBar; +import net.kyori.adventure.chat.ChatType; +import net.kyori.adventure.chat.SignedMessage; import net.kyori.adventure.identity.Identified; import net.kyori.adventure.identity.Identity; +import net.kyori.adventure.identity.PlayerIdentified; +import net.kyori.adventure.identity.PlayerIdentity; import net.kyori.adventure.inventory.Book; import net.kyori.adventure.pointer.Pointer; import net.kyori.adventure.pointer.Pointers; @@ -96,12 +100,32 @@ default void forEachAudience(final @NotNull Consumer action) { } @Override - default void sendMessage(final @NotNull Identified source, final @NotNull Component message, final @NotNull MessageType type) { + default void sendMessage(final @NotNull Identified source, final @NotNull Component message) { + for (final Audience audience : this.audiences()) audience.sendMessage(source, message); + } + + @Override + default void sendMessage(final @NotNull Component message, final @NotNull ChatType chatType) { + for (final Audience audience : this.audiences()) audience.sendMessage(message, chatType); + } + + @Override + default void sendMessage(final @NotNull Component message, final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentified source, final @NotNull ChatType chatType) { + for (final Audience audience : this.audiences()) audience.sendMessage(message, signedMessage, source, chatType); + } + + @Override + default void sendMessage(final @NotNull Component message, final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentity source, final @NotNull ChatType chatType) { + for (final Audience audience : this.audiences()) audience.sendMessage(message, signedMessage, source, chatType); + } + + @Override + default void sendMessage(@NotNull Identified source, @NotNull Component message, @NotNull MessageType type) { for (final Audience audience : this.audiences()) audience.sendMessage(source, message, type); } @Override - default void sendMessage(final @NotNull Identity source, final @NotNull Component message, final @NotNull MessageType type) { + default void sendMessage(@NotNull Identity source, @NotNull Component message, @NotNull MessageType type) { for (final Audience audience : this.audiences()) audience.sendMessage(source, message, type); } @@ -236,6 +260,26 @@ default void forEachAudience(final @NotNull Consumer action) { return this.audience().pointers(); } + @Override + default void sendMessage(final @NotNull Identified source, final @NotNull Component message) { + this.audience().sendMessage(source, message); + } + + @Override + default void sendMessage(final @NotNull Component message, final @NotNull ChatType chatType) { + this.audience().sendMessage(message, chatType); + } + + @Override + default void sendMessage(final @NotNull Component message, final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentified source, final @NotNull ChatType chatType) { + this.audience().sendMessage(message, signedMessage, source, chatType); + } + + @Override + default void sendMessage(final @NotNull Component message, final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentity source, final @NotNull ChatType chatType) { + this.audience().sendMessage(message, signedMessage, source, chatType); + } + @Override default void sendMessage(final @NotNull Identified source, final @NotNull Component message, final @NotNull MessageType type) { this.audience().sendMessage(source, message, type); diff --git a/api/src/main/java/net/kyori/adventure/chat/ChatType.java b/api/src/main/java/net/kyori/adventure/chat/ChatType.java index 8027782867..e009310217 100644 --- a/api/src/main/java/net/kyori/adventure/chat/ChatType.java +++ b/api/src/main/java/net/kyori/adventure/chat/ChatType.java @@ -38,7 +38,6 @@ * @sinceMinecraft 1.19 */ public interface ChatType extends Examinable, Keyed { - // todo should these be in another class/interface so as not to conflict with any implementations? /** * A chat message from a player. * @@ -93,7 +92,6 @@ public interface ChatType extends Examinable, Keyed { * @since 4.12.0 * @sinceMinecraft 1.19 */ - // todo TELLRAW or TELL_RAW? mc is inconsistent here (see teammsg) ChatType TELL_RAW_COMMAND = new ChatTypeImpl(Key.key("tellraw_command")); /** diff --git a/api/src/main/java/net/kyori/adventure/chat/SignedMessage.java b/api/src/main/java/net/kyori/adventure/chat/SignedMessage.java index c8aaba4fd9..9fecfef221 100644 --- a/api/src/main/java/net/kyori/adventure/chat/SignedMessage.java +++ b/api/src/main/java/net/kyori/adventure/chat/SignedMessage.java @@ -35,7 +35,7 @@ * @since 4.12.0 * @sinceMinecraft 1.19 */ -@ApiStatus.NonExtendable // todo do we want this? realistically nobody but platforms should be making these.. +@ApiStatus.NonExtendable public interface SignedMessage extends PlayerIdentified { /** * The time that the message was sent. @@ -64,5 +64,6 @@ public interface SignedMessage extends PlayerIdentified { * @since 4.12.0 * @sinceMinecraft 1.19 */ + @Contract(pure = true) byte[] signature(); } diff --git a/api/src/main/java/net/kyori/adventure/identity/PlayerIdentity.java b/api/src/main/java/net/kyori/adventure/identity/PlayerIdentity.java index 28ce4eb6c2..7f23a82faf 100644 --- a/api/src/main/java/net/kyori/adventure/identity/PlayerIdentity.java +++ b/api/src/main/java/net/kyori/adventure/identity/PlayerIdentity.java @@ -26,6 +26,9 @@ import java.util.Objects; import java.util.UUID; import java.util.stream.Stream; +import net.kyori.adventure.Adventure; +import net.kyori.adventure.key.Key; +import net.kyori.adventure.pointer.Pointer; import net.kyori.adventure.text.Component; import net.kyori.examination.Examinable; import net.kyori.examination.ExaminableProperty; @@ -39,7 +42,13 @@ * @since 4.12.0 */ public interface PlayerIdentity extends Examinable, Identity { - // todo do we want identity/identified overloads here? + /** + * A pointer to a team name. + * + * @since 4.12.0 + */ + Pointer TEAM_NAME = Pointer.pointer(Component.class, Key.key(Adventure.NAMESPACE, "team_name")); + /** * Creates a new player identity. *