From 2e0f05a289e2eaf6527235ccf312ee06151ed156 Mon Sep 17 00:00:00 2001 From: Kieran Wallbanks Date: Wed, 8 Jun 2022 14:17:02 +0100 Subject: [PATCH 01/21] feature: New chat-related objects --- .../kyori/adventure/audience/MessageType.java | 31 ++++- .../net/kyori/adventure/chat/ChatType.java | 114 ++++++++++++++++++ .../kyori/adventure/chat/ChatTypeImpl.java | 46 +++++++ .../kyori/adventure/chat/SignedMessage.java | 68 +++++++++++ .../kyori/adventure/chat/package-info.java | 27 +++++ .../adventure/identity/PlayerIdentified.java | 48 ++++++++ .../adventure/identity/PlayerIdentity.java | 94 +++++++++++++++ .../identity/PlayerIdentityImpl.java | 79 ++++++++++++ 8 files changed, 504 insertions(+), 3 deletions(-) create mode 100644 api/src/main/java/net/kyori/adventure/chat/ChatType.java create mode 100644 api/src/main/java/net/kyori/adventure/chat/ChatTypeImpl.java create mode 100644 api/src/main/java/net/kyori/adventure/chat/SignedMessage.java create mode 100644 api/src/main/java/net/kyori/adventure/chat/package-info.java create mode 100644 api/src/main/java/net/kyori/adventure/identity/PlayerIdentified.java create mode 100644 api/src/main/java/net/kyori/adventure/identity/PlayerIdentity.java create mode 100644 api/src/main/java/net/kyori/adventure/identity/PlayerIdentityImpl.java diff --git a/api/src/main/java/net/kyori/adventure/audience/MessageType.java b/api/src/main/java/net/kyori/adventure/audience/MessageType.java index d55016621..97ede93d3 100644 --- a/api/src/main/java/net/kyori/adventure/audience/MessageType.java +++ b/api/src/main/java/net/kyori/adventure/audience/MessageType.java @@ -23,22 +23,47 @@ */ package net.kyori.adventure.audience; +import net.kyori.adventure.chat.ChatType; +import net.kyori.adventure.key.Key; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; + /** * Message types. * * @since 4.0.0 + * @deprecated for removal since 4.12.0, use corresponding {@link ChatType} instead */ -public enum MessageType { +@ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") +@Deprecated +public enum MessageType implements ChatType { /** * Chat message type. * * @since 4.0.0 + * @deprecated for removal since 4.12.0, use {@link ChatType#CHAT} instead */ - CHAT, + @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") + @Deprecated + CHAT(ChatType.CHAT), /** * System message type. * * @since 4.0.0 + * @deprecated for removal since 4.12.0, use {@link ChatType#SYSTEM} instead */ - SYSTEM; + @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") + @Deprecated + SYSTEM(ChatType.SYSTEM); + + private final ChatType chatType; + + MessageType(final @NotNull ChatType chatType) { + this.chatType = chatType; + } + + @Override + public final @NotNull Key key() { + return this.chatType.key(); + } } diff --git a/api/src/main/java/net/kyori/adventure/chat/ChatType.java b/api/src/main/java/net/kyori/adventure/chat/ChatType.java new file mode 100644 index 000000000..802778286 --- /dev/null +++ b/api/src/main/java/net/kyori/adventure/chat/ChatType.java @@ -0,0 +1,114 @@ +/* + * This file is part of adventure, licensed under the MIT License. + * + * Copyright (c) 2017-2022 KyoriPowered + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package net.kyori.adventure.chat; + +import java.util.Objects; +import java.util.stream.Stream; +import net.kyori.adventure.key.Key; +import net.kyori.adventure.key.Keyed; +import net.kyori.examination.Examinable; +import net.kyori.examination.ExaminableProperty; +import org.jetbrains.annotations.NotNull; + +/** + * A type of chat. + * + * @since 4.12.0 + * @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. + * + * @since 4.12.0 + * @sinceMinecraft 1.19 + */ + ChatType CHAT = new ChatTypeImpl(Key.key("chat")); + + /** + * A chat message from the "system" or server. + * + * @since 4.12.0 + * @sinceMinecraft 1.19 + */ + ChatType SYSTEM = new ChatTypeImpl(Key.key("system")); + + /** + * A game information message, displaying in the action bar. + * + * @since 4.12.0 + * @sinceMinecraft 1.19 + */ + ChatType GAME_INFO = new ChatTypeImpl(Key.key("game_info")); + + /** + * A message sent as a result of using the {@code /msg} command. + * + * @since 4.12.0 + * @sinceMinecraft 1.19 + */ + ChatType MSG_COMMAND = new ChatTypeImpl(Key.key("say_command")); + + /** + * A message sent as a result of using the {@code /teammsg} command. + * + * @since 4.12.0 + * @sinceMinecraft 1.19 + */ + ChatType TEAM_MSG_COMMAND = new ChatTypeImpl(Key.key("team_msg_command")); + + /** + * A message sent as a result of using the {@code /me} command. + * + * @since 4.12.0 + * @sinceMinecraft 1.19 + */ + ChatType EMOTE_COMMAND = new ChatTypeImpl(Key.key("emote_command")); + + /** + * A message sent as a result of using the {@code /tellraw} command. + * + * @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")); + + /** + * Creates a new chat type with a given key. + * + * @param key the key + * @return the chat type + * @since 4.12.0 + */ + static @NotNull ChatType chatType(final @NotNull Key key) { + return new ChatTypeImpl(Objects.requireNonNull(key, "key")); + } + + @Override + default @NotNull Stream examinableProperties() { + return Stream.of(ExaminableProperty.of("key", this.key())); + } +} diff --git a/api/src/main/java/net/kyori/adventure/chat/ChatTypeImpl.java b/api/src/main/java/net/kyori/adventure/chat/ChatTypeImpl.java new file mode 100644 index 000000000..3d607ec76 --- /dev/null +++ b/api/src/main/java/net/kyori/adventure/chat/ChatTypeImpl.java @@ -0,0 +1,46 @@ +/* + * This file is part of adventure, licensed under the MIT License. + * + * Copyright (c) 2017-2022 KyoriPowered + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package net.kyori.adventure.chat; + +import net.kyori.adventure.internal.Internals; +import net.kyori.adventure.key.Key; +import org.jetbrains.annotations.NotNull; + +final class ChatTypeImpl implements ChatType { + private final Key key; + + ChatTypeImpl(final @NotNull Key key) { + this.key = key; + } + + @Override + public @NotNull Key key() { + return this.key; + } + + @Override + public String toString() { + return Internals.toString(this); + } +} diff --git a/api/src/main/java/net/kyori/adventure/chat/SignedMessage.java b/api/src/main/java/net/kyori/adventure/chat/SignedMessage.java new file mode 100644 index 000000000..c8aaba4fd --- /dev/null +++ b/api/src/main/java/net/kyori/adventure/chat/SignedMessage.java @@ -0,0 +1,68 @@ +/* + * This file is part of adventure, licensed under the MIT License. + * + * Copyright (c) 2017-2022 KyoriPowered + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package net.kyori.adventure.chat; + +import java.time.Instant; +import net.kyori.adventure.identity.PlayerIdentified; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +/** + * A signed chat message. + * + * @since 4.12.0 + * @sinceMinecraft 1.19 + */ +@ApiStatus.NonExtendable // todo do we want this? realistically nobody but platforms should be making these.. +public interface SignedMessage extends PlayerIdentified { + /** + * The time that the message was sent. + * + * @return the timestamp + * @since 4.12.0 + * @sinceMinecraft 1.19 + */ + @Contract(pure = true) + @NotNull Instant timeStamp(); + + /** + * The salt. + * + * @return the salt + * @since 4.12.0 + * @sinceMinecraft 1.19 + */ + @Contract(pure = true) + long salt(); + + /** + * The signature of the message. + * + * @return the signature + * @since 4.12.0 + * @sinceMinecraft 1.19 + */ + byte[] signature(); +} diff --git a/api/src/main/java/net/kyori/adventure/chat/package-info.java b/api/src/main/java/net/kyori/adventure/chat/package-info.java new file mode 100644 index 000000000..af45343ca --- /dev/null +++ b/api/src/main/java/net/kyori/adventure/chat/package-info.java @@ -0,0 +1,27 @@ +/* + * This file is part of adventure, licensed under the MIT License. + * + * Copyright (c) 2017-2022 KyoriPowered + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/** + * Chat-related data. + */ +package net.kyori.adventure.chat; diff --git a/api/src/main/java/net/kyori/adventure/identity/PlayerIdentified.java b/api/src/main/java/net/kyori/adventure/identity/PlayerIdentified.java new file mode 100644 index 000000000..f1a3d8981 --- /dev/null +++ b/api/src/main/java/net/kyori/adventure/identity/PlayerIdentified.java @@ -0,0 +1,48 @@ +/* + * This file is part of adventure, licensed under the MIT License. + * + * Copyright (c) 2017-2022 KyoriPowered + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package net.kyori.adventure.identity; + +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +/** + * Something that can be identified with a {@link PlayerIdentity}. + * + * @since 4.12.0 + */ +public interface PlayerIdentified extends Identified { + /** + * Gets the player identity. + * + * @return the player identity + * @since 4.12.0 + */ + @Contract(pure = true) + @NotNull PlayerIdentity playerIdentity(); + + @Override + default @NotNull Identity identity() { + return this.playerIdentity(); + } +} diff --git a/api/src/main/java/net/kyori/adventure/identity/PlayerIdentity.java b/api/src/main/java/net/kyori/adventure/identity/PlayerIdentity.java new file mode 100644 index 000000000..28ce4eb6c --- /dev/null +++ b/api/src/main/java/net/kyori/adventure/identity/PlayerIdentity.java @@ -0,0 +1,94 @@ +/* + * This file is part of adventure, licensed under the MIT License. + * + * Copyright (c) 2017-2022 KyoriPowered + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package net.kyori.adventure.identity; + +import java.util.Objects; +import java.util.UUID; +import java.util.stream.Stream; +import net.kyori.adventure.text.Component; +import net.kyori.examination.Examinable; +import net.kyori.examination.ExaminableProperty; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * An identity for a specific player. + * + * @since 4.12.0 + */ +public interface PlayerIdentity extends Examinable, Identity { + // todo do we want identity/identified overloads here? + /** + * Creates a new player identity. + * + * @param uuid the uuid + * @param name the name + * @return the player identity + * @since 4.12.0 + */ + static @NotNull PlayerIdentity playerIdentity(final @NotNull UUID uuid, final @NotNull Component name) { + return playerIdentity(uuid, name, null); + } + + /** + * Creates a new player identity. + * + * @param uuid the uuid + * @param name the name + * @param teamName the optional team name + * @return the player identity + * @since 4.12.0 + */ + static @NotNull PlayerIdentity playerIdentity(final @NotNull UUID uuid, final @NotNull Component name, final @Nullable Component teamName) { + return new PlayerIdentityImpl(Objects.requireNonNull(uuid, "uuid"), Objects.requireNonNull(name, "name"), teamName); + } + + /** + * The name of the player. + * + * @return the name + * @since 4.12.0 + */ + @Contract(pure = true) + @NotNull Component name(); + + /** + * The team name of the player. + * + * @return the team name + * @since 4.12.0 + */ + @Contract(pure = true) + @Nullable Component teamName(); + + @Override + default @NotNull Stream examinableProperties() { + return Stream.of( + ExaminableProperty.of("uuid", this.uuid()), + ExaminableProperty.of("name", this.name()), + ExaminableProperty.of("teamName", this.teamName()) + ); + } +} diff --git a/api/src/main/java/net/kyori/adventure/identity/PlayerIdentityImpl.java b/api/src/main/java/net/kyori/adventure/identity/PlayerIdentityImpl.java new file mode 100644 index 000000000..fef037d4e --- /dev/null +++ b/api/src/main/java/net/kyori/adventure/identity/PlayerIdentityImpl.java @@ -0,0 +1,79 @@ +/* + * This file is part of adventure, licensed under the MIT License. + * + * Copyright (c) 2017-2022 KyoriPowered + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package net.kyori.adventure.identity; + +import java.util.Objects; +import java.util.UUID; +import net.kyori.adventure.internal.Internals; +import net.kyori.adventure.text.Component; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +final class PlayerIdentityImpl implements PlayerIdentity { + private final UUID uuid; + private final Component name; + private final @Nullable Component teamName; + + PlayerIdentityImpl(final @NotNull UUID uuid, final @NotNull Component name, final @Nullable Component teamName) { + this.uuid = uuid; + this.name = name; + this.teamName = teamName; + } + + @Override + public @NotNull UUID uuid() { + return this.uuid; + } + + @Override + public @NotNull Component name() { + return this.name; + } + + @Override + public @Nullable Component teamName() { + return this.teamName; + } + + @Override + public boolean equals(final @Nullable Object other) { + if (this == other) return true; + if (!(other instanceof PlayerIdentity)) return false; + final PlayerIdentity that = (PlayerIdentity) other; + return this.uuid == that.uuid() && this.name == that.name() && this.teamName == that.teamName(); + } + + @Override + public int hashCode() { + int result = this.uuid.hashCode(); + result = 31 * result + this.name.hashCode(); + result = 31 * result + Objects.hashCode(this.teamName); + return result; + } + + @Override + public String toString() { + return Internals.toString(this); + } +} From c7d914c35ea3811f62d90d0ca8b079e58f70d5f1 Mon Sep 17 00:00:00 2001 From: Kieran Wallbanks Date: Wed, 8 Jun 2022 18:17:03 +0100 Subject: [PATCH 02/21] chore: Remove duplicate method for identity override --- .../net/kyori/adventure/identity/PlayerIdentified.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/api/src/main/java/net/kyori/adventure/identity/PlayerIdentified.java b/api/src/main/java/net/kyori/adventure/identity/PlayerIdentified.java index f1a3d8981..f5aea6747 100644 --- a/api/src/main/java/net/kyori/adventure/identity/PlayerIdentified.java +++ b/api/src/main/java/net/kyori/adventure/identity/PlayerIdentified.java @@ -23,7 +23,6 @@ */ package net.kyori.adventure.identity; -import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; /** @@ -38,11 +37,6 @@ public interface PlayerIdentified extends Identified { * @return the player identity * @since 4.12.0 */ - @Contract(pure = true) - @NotNull PlayerIdentity playerIdentity(); - @Override - default @NotNull Identity identity() { - return this.playerIdentity(); - } + @NotNull PlayerIdentity identity(); } From 18020dcc33fad3e7361c39ae00ca046400ef6aac Mon Sep 17 00:00:00 2001 From: Kieran Wallbanks Date: Thu, 9 Jun 2022 10:08:33 +0100 Subject: [PATCH 03/21] feature: Resolve todos, add/deprecate Audience methods for new chat system --- .../kyori/adventure/audience/Audience.java | 191 ++++++++++++++++-- .../adventure/audience/EmptyAudience.java | 31 ++- .../audience/ForwardingAudience.java | 48 ++++- .../net/kyori/adventure/chat/ChatType.java | 2 - .../kyori/adventure/chat/SignedMessage.java | 3 +- .../adventure/identity/PlayerIdentity.java | 11 +- 6 files changed, 257 insertions(+), 29 deletions(-) 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 57dbbdf3b..344c10657 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 719c11c22..78737a9cb 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 3bd50c7e1..989de3efd 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 802778286..e00931021 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 c8aaba4fd..9fecfef22 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 28ce4eb6c..7f23a82fa 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. * From d2f5e801876020b2eb073feee32f3e9f50ba5cc0 Mon Sep 17 00:00:00 2001 From: Kieran Wallbanks Date: Thu, 9 Jun 2022 11:22:36 +0100 Subject: [PATCH 04/21] fix: Remove unintended forwarding audience override annotation removal and fix deprecation message inconsistency --- .../java/net/kyori/adventure/audience/Audience.java | 5 +++-- .../kyori/adventure/audience/ForwardingAudience.java | 10 ---------- 2 files changed, 3 insertions(+), 12 deletions(-) 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 344c10657..34bfea660 100644 --- a/api/src/main/java/net/kyori/adventure/audience/Audience.java +++ b/api/src/main/java/net/kyori/adventure/audience/Audience.java @@ -200,7 +200,7 @@ default void sendMessage(final @NotNull ComponentLike 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 since 4.12.0, the client errors on 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 @@ -215,7 +215,7 @@ default void sendMessage(final @NotNull Identified source, final @NotNull Compon * @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 since 4.12.0, the client errors on 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 @@ -247,6 +247,7 @@ default void sendMessage(final @NotNull Component message) { * @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 */ @Deprecated + @ForwardingAudienceOverrideNotRequired default void sendMessage(final @NotNull Identified source, final @NotNull Component message) { this.sendMessage(source, message, MessageType.SYSTEM); } 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 989de3efd..cee53c81b 100644 --- a/api/src/main/java/net/kyori/adventure/audience/ForwardingAudience.java +++ b/api/src/main/java/net/kyori/adventure/audience/ForwardingAudience.java @@ -99,11 +99,6 @@ default void forEachAudience(final @NotNull Consumer action) { for (final Audience audience : this.audiences()) audience.forEachAudience(action); } - @Override - 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); @@ -260,11 +255,6 @@ 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); From db4848b143111a8483d7476e8344e4f5d48a34f4 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Tue, 2 Aug 2022 11:36:38 -0700 Subject: [PATCH 05/21] Updating chat changes for 1.19.1 --- .../kyori/adventure/audience/Audience.java | 154 ++++-------------- .../adventure/audience/EmptyAudience.java | 18 +- .../audience/ForwardingAudience.java | 24 +-- .../kyori/adventure/audience/MessageType.java | 19 +-- .../net/kyori/adventure/chat/ChatType.java | 56 +++++-- .../kyori/adventure/chat/ChatTypeImpl.java | 34 ++++ .../kyori/adventure/chat/SignedMessage.java | 101 +++++++++++- .../chat/UnsignedSignedMessageImpl.java | 55 +++++++ 8 files changed, 281 insertions(+), 180 deletions(-) create mode 100644 api/src/main/java/net/kyori/adventure/chat/UnsignedSignedMessageImpl.java 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 34bfea660..ce4d95583 100644 --- a/api/src/main/java/net/kyori/adventure/audience/Audience.java +++ b/api/src/main/java/net/kyori/adventure/audience/Audience.java @@ -180,7 +180,7 @@ default void forEachAudience(final @NotNull Consumer action) { } /** - * Sends a system chat message with to this {@link Audience} with the {@link ChatType#SYSTEM system} chat type. + * Sends a system chat message to this {@link Audience}. * * @param message a message * @see Component @@ -190,17 +190,17 @@ default void forEachAudience(final @NotNull Consumer action) { */ @ForwardingAudienceOverrideNotRequired default void sendMessage(final @NotNull ComponentLike message) { - this.sendMessage(message, ChatType.SYSTEM); + this.sendMessage(message.asComponent()); } /** - * Sends a player chat message from the given {@link Identified} to this {@link Audience} with the {@link ChatType#SYSTEM system} chat type. + * Sends a player chat message from the given {@link Identified} to this {@link Audience} with the {@link ChatType#CHAT 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 and can reject identified messages without {@link SignedMessage} data, this may be unsupported in the future, use {@link #sendMessage(ComponentLike, SignedMessage, PlayerIdentified)} instead + * @deprecated since 4.12.0, the client errors on and can reject identified messages without {@link SignedMessage} data, this may be unsupported in the future, use {@link #sendMessage(SignedMessage, ChatType.Bound)} instead */ @Deprecated @ForwardingAudienceOverrideNotRequired @@ -209,13 +209,13 @@ default void sendMessage(final @NotNull Identified source, final @NotNull Compon } /** - * 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. + * Sends a player chat message from the entity represented by the given {@link Identity} to this {@link Audience} with the {@link ChatType#CHAT 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 and can reject identified messages without {@link SignedMessage} data, this may be unsupported in the future, use {@link #sendMessage(ComponentLike, SignedMessage, PlayerIdentified)} instead + * @deprecated since 4.12.0, the client errors on and can reject identified messages without {@link SignedMessage} data, this may be unsupported in the future, use {@link #sendMessage(SignedMessage, ChatType.Bound)} instead */ @Deprecated @ForwardingAudienceOverrideNotRequired @@ -224,7 +224,7 @@ default void sendMessage(final @NotNull Identity source, final @NotNull Componen } /** - * Sends a system chat message with to this {@link Audience} with the {@link ChatType#SYSTEM system} chat type. + * Sends a system chat message to this {@link Audience}. * * @param message a message * @see Component @@ -232,43 +232,41 @@ default void sendMessage(final @NotNull Identity source, final @NotNull Componen * @see #sendMessage(Identity, Component) * @since 4.1.0 */ - @ForwardingAudienceOverrideNotRequired default void sendMessage(final @NotNull Component message) { - this.sendMessage(message, ChatType.SYSTEM); } /** - * Sends a player chat message from the given {@link Identified} to this {@link Audience} with the {@link ChatType#SYSTEM system} chat type. + * Sends a player chat message from the given {@link Identified} to this {@link Audience} with the {@link ChatType#CHAT 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 + * @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(SignedMessage, PlayerIdentified)} instead */ @Deprecated @ForwardingAudienceOverrideNotRequired default void sendMessage(final @NotNull Identified source, final @NotNull Component message) { - this.sendMessage(source, message, MessageType.SYSTEM); + this.sendMessage(source, message, MessageType.CHAT); } /** - * 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. + * Sends a player chat message from the entity represented by the given {@link Identity} to this {@link Audience} with the {@link ChatType#CHAT 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 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(SignedMessage, PlayerIdentity)} instead */ @Deprecated @ForwardingAudienceOverrideNotRequired default void sendMessage(final @NotNull Identity source, final @NotNull Component message) { - this.sendMessage(source, message, MessageType.SYSTEM); + this.sendMessage(source, message, MessageType.CHAT); } /** - * Sends a system chat message this {@link Audience} with the {@link ChatType} corresponding to the provided {@link MessageType}. + * Sends a system chat message to this {@link Audience} ignoring the provided {@link MessageType}. * * @param message a message * @param type the type @@ -276,13 +274,13 @@ 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)} + * @deprecated for removal since 4.12.0, {@link MessageType} is deprecated for removal, use {@link #sendMessage(ComponentLike)} */ @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") @Deprecated @ForwardingAudienceOverrideNotRequired default void sendMessage(final @NotNull ComponentLike message, final @NotNull MessageType type) { - this.sendMessage(message, (ChatType) type); + this.sendMessage(message); } /** @@ -293,7 +291,7 @@ default void sendMessage(final @NotNull ComponentLike message, final @NotNull Me * @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 + * @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(SignedMessage, ChatType.Bound)} instead */ @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") @Deprecated @@ -303,14 +301,14 @@ default void sendMessage(final @NotNull Identified source, final @NotNull Compon } /** - * 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. + * Sends a player chat message from the entity represented by the given {@link Identity} to this {@link Audience}. * * @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 + * @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(SignedMessage, ChatType.Bound)} instead */ @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") @Deprecated @@ -320,7 +318,7 @@ default void sendMessage(final @NotNull Identity source, final @NotNull Componen } /** - * Sends a system chat message to this {@link Audience} with the {@link ChatType} corresponding to the provided {@link MessageType}. + * Sends a system chat message to this {@link Audience} ignoring the provided {@link MessageType}. * * @param message a message * @param type the type @@ -328,13 +326,13 @@ 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 + * @deprecated for removal since 4.12.0, {@link MessageType} is deprecated for removal, use {@link #sendMessage(Component)} instead */ @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") @Deprecated @ForwardingAudienceOverrideNotRequired default void sendMessage(final @NotNull Component message, final @NotNull MessageType type) { - this.sendMessage(message, (ChatType) type); + this.sendMessage(message); } /** @@ -345,7 +343,7 @@ default void sendMessage(final @NotNull Component message, final @NotNull Messag * @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 + * @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(SignedMessage, ChatType.Bound)} instead */ @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") @Deprecated @@ -360,137 +358,45 @@ default void sendMessage(final @NotNull Identified source, final @NotNull Compon * @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 + * @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(SignedMessage, ChatType.Bound)} 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); + default void sendMessage(final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentified source) { + this.sendMessage(signedMessage, source.identity()); } /** * 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); + default void sendMessage(final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentity source) { + this.sendMessage(signedMessage, ChatType.CHAT.bind(source.name())); } /** * 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 + * @param boundChatType the bound 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) { + default void sendMessage(final @NotNull SignedMessage signedMessage, final ChatType.Bound boundChatType) { } /** 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 78737a9cb..3989a0577 100644 --- a/api/src/main/java/net/kyori/adventure/audience/EmptyAudience.java +++ b/api/src/main/java/net/kyori/adventure/audience/EmptyAudience.java @@ -79,27 +79,15 @@ public void sendMessage(final @NotNull Component message) { } @Override - public void sendMessage(final @NotNull ComponentLike message, final @NotNull ChatType chatType) { + public void sendMessage(final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentified source) { } @Override - public void sendMessage(final @NotNull ComponentLike message, final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentified source) { + public void sendMessage(final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentity source) { } @Override - public void sendMessage(final @NotNull Component message, final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentified source) { - } - - @Override - 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) { + public void sendMessage(final @NotNull SignedMessage signedMessage, final ChatType.Bound boundChatType) { } @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 cee53c81b..d93aed787 100644 --- a/api/src/main/java/net/kyori/adventure/audience/ForwardingAudience.java +++ b/api/src/main/java/net/kyori/adventure/audience/ForwardingAudience.java @@ -100,18 +100,18 @@ default void forEachAudience(final @NotNull Consumer action) { } @Override - default void sendMessage(final @NotNull Component message, final @NotNull ChatType chatType) { - for (final Audience audience : this.audiences()) audience.sendMessage(message, chatType); + default void sendMessage(final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentified source) { + for (final Audience audience : this.audiences()) audience.sendMessage(signedMessage, source); } @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); + default void sendMessage(final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentity source) { + for (final Audience audience : this.audiences()) audience.sendMessage(signedMessage, source); } @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); + default void sendMessage(final @NotNull SignedMessage signedMessage, final ChatType.Bound boundChatType) { + for (final Audience audience : this.audiences()) audience.sendMessage(signedMessage, boundChatType); } @Override @@ -256,18 +256,18 @@ default void forEachAudience(final @NotNull Consumer action) { } @Override - default void sendMessage(final @NotNull Component message, final @NotNull ChatType chatType) { - this.audience().sendMessage(message, chatType); + default void sendMessage(final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentified source) { + this.audience().sendMessage(signedMessage, source); } @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); + default void sendMessage(final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentity source) { + this.audience().sendMessage(signedMessage, source); } @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); + default void sendMessage(final @NotNull SignedMessage signedMessage, final ChatType.Bound boundChatType) { + this.audience().sendMessage(signedMessage, boundChatType); } @Override diff --git a/api/src/main/java/net/kyori/adventure/audience/MessageType.java b/api/src/main/java/net/kyori/adventure/audience/MessageType.java index 97ede93d3..88f873f99 100644 --- a/api/src/main/java/net/kyori/adventure/audience/MessageType.java +++ b/api/src/main/java/net/kyori/adventure/audience/MessageType.java @@ -36,7 +36,7 @@ */ @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") @Deprecated -public enum MessageType implements ChatType { +public enum MessageType { /** * Chat message type. * @@ -45,25 +45,14 @@ public enum MessageType implements ChatType { */ @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") @Deprecated - CHAT(ChatType.CHAT), + CHAT, /** * System message type. * * @since 4.0.0 - * @deprecated for removal since 4.12.0, use {@link ChatType#SYSTEM} instead + * @deprecated for removal since 4.12.0 */ @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") @Deprecated - SYSTEM(ChatType.SYSTEM); - - private final ChatType chatType; - - MessageType(final @NotNull ChatType chatType) { - this.chatType = chatType; - } - - @Override - public final @NotNull Key key() { - return this.chatType.key(); - } + SYSTEM; } 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 e00931021..aaba7a6e8 100644 --- a/api/src/main/java/net/kyori/adventure/chat/ChatType.java +++ b/api/src/main/java/net/kyori/adventure/chat/ChatType.java @@ -27,9 +27,12 @@ import java.util.stream.Stream; import net.kyori.adventure.key.Key; import net.kyori.adventure.key.Keyed; +import net.kyori.adventure.text.Component; import net.kyori.examination.Examinable; import net.kyori.examination.ExaminableProperty; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * A type of chat. @@ -47,20 +50,20 @@ public interface ChatType extends Examinable, Keyed { ChatType CHAT = new ChatTypeImpl(Key.key("chat")); /** - * A chat message from the "system" or server. + * A message send as a result of using the {@code /say} command. * * @since 4.12.0 * @sinceMinecraft 1.19 */ - ChatType SYSTEM = new ChatTypeImpl(Key.key("system")); + ChatType SAY_COMMAND = new ChatTypeImpl(Key.key("say_command")); /** - * A game information message, displaying in the action bar. + * A message received as a result of using the {@code /msg} command. * * @since 4.12.0 * @sinceMinecraft 1.19 */ - ChatType GAME_INFO = new ChatTypeImpl(Key.key("game_info")); + ChatType MSG_COMMAND_INCOMING = new ChatTypeImpl(Key.key("msg_command_incoming")); /** * A message sent as a result of using the {@code /msg} command. @@ -68,31 +71,31 @@ public interface ChatType extends Examinable, Keyed { * @since 4.12.0 * @sinceMinecraft 1.19 */ - ChatType MSG_COMMAND = new ChatTypeImpl(Key.key("say_command")); + ChatType MSG_COMMAND_OUTGOING = new ChatTypeImpl(Key.key("msg_command_outgoing")); /** - * A message sent as a result of using the {@code /teammsg} command. + * A message received as a result of using the {@code /teammsg} command. * * @since 4.12.0 * @sinceMinecraft 1.19 */ - ChatType TEAM_MSG_COMMAND = new ChatTypeImpl(Key.key("team_msg_command")); + ChatType TEAM_MSG_COMMAND_INCOMING = new ChatTypeImpl(Key.key("team_msg_command_incoming")); /** - * A message sent as a result of using the {@code /me} command. + * A message sent as a result of using the {@code /teammsg} command. * * @since 4.12.0 * @sinceMinecraft 1.19 */ - ChatType EMOTE_COMMAND = new ChatTypeImpl(Key.key("emote_command")); + ChatType TEAM_MSG_COMMAND_OUTGOING = new ChatTypeImpl(Key.key("team_msg_command_outgoing")); /** - * A message sent as a result of using the {@code /tellraw} command. + * A message sent as a result of using the {@code /me} command. * * @since 4.12.0 * @sinceMinecraft 1.19 */ - ChatType TELL_RAW_COMMAND = new ChatTypeImpl(Key.key("tellraw_command")); + ChatType EMOTE_COMMAND = new ChatTypeImpl(Key.key("emote_command")); /** * Creates a new chat type with a given key. @@ -105,8 +108,39 @@ public interface ChatType extends Examinable, Keyed { return new ChatTypeImpl(Objects.requireNonNull(key, "key")); } + default ChatType.Bound bind(@NotNull final Component sender) { + return this.bind(sender, null); + } + + default ChatType.Bound bind(@NotNull final Component sender, final @Nullable Component target) { + return new ChatTypeImpl.BoundImpl(this, sender, target); + } + + @Override default @NotNull Stream examinableProperties() { return Stream.of(ExaminableProperty.of("key", this.key())); } + + interface Bound extends Examinable { + + @Contract(pure = true) + @NotNull ChatType chatType(); + + @Contract(pure = true) + @NotNull Component sender(); + + @Contract(pure = true) + @Nullable Component target(); + + @Override + @NotNull + default Stream examinableProperties() { + return Stream.of( + ExaminableProperty.of("chatType", this.chatType()), + ExaminableProperty.of("sender", this.sender()), + ExaminableProperty.of("target", this.target()) + ); + } + } } diff --git a/api/src/main/java/net/kyori/adventure/chat/ChatTypeImpl.java b/api/src/main/java/net/kyori/adventure/chat/ChatTypeImpl.java index 3d607ec76..88755ae8f 100644 --- a/api/src/main/java/net/kyori/adventure/chat/ChatTypeImpl.java +++ b/api/src/main/java/net/kyori/adventure/chat/ChatTypeImpl.java @@ -25,7 +25,9 @@ import net.kyori.adventure.internal.Internals; import net.kyori.adventure.key.Key; +import net.kyori.adventure.text.Component; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; final class ChatTypeImpl implements ChatType { private final Key key; @@ -43,4 +45,36 @@ final class ChatTypeImpl implements ChatType { public String toString() { return Internals.toString(this); } + + static final class BoundImpl implements ChatType.Bound { + private final ChatType chatType; + private final Component sender; + private final @Nullable Component target; + + BoundImpl(final ChatType chatType, final Component sender, final @Nullable Component target) { + this.chatType = chatType; + this.sender = sender; + this.target = target; + } + + @Override + public @NotNull ChatType chatType() { + return this.chatType; + } + + @Override + public @NotNull Component sender() { + return this.sender; + } + + @Override + public @Nullable Component target() { + return this.target; + } + + @Override + public String toString() { + return Internals.toString(this); + } + } } 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 9fecfef22..2ac1c3373 100644 --- a/api/src/main/java/net/kyori/adventure/chat/SignedMessage.java +++ b/api/src/main/java/net/kyori/adventure/chat/SignedMessage.java @@ -24,10 +24,14 @@ package net.kyori.adventure.chat; import java.time.Instant; -import net.kyori.adventure.identity.PlayerIdentified; +import net.kyori.adventure.identity.Identified; +import net.kyori.adventure.identity.Identity; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.ComponentLike; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * A signed chat message. @@ -36,7 +40,51 @@ * @sinceMinecraft 1.19 */ @ApiStatus.NonExtendable -public interface SignedMessage extends PlayerIdentified { +public interface SignedMessage extends Identified, ComponentLike { + + /** + * Creates a signature wrapper. + * + * @param signature the signature + * @return a new signature + * @since 4.12.0 + * @sinceMinecraft 1.19 + */ + @Contract(value = "_ -> new", pure = true) + static @NotNull Signature signature(final byte[] signature) { + return new Signature(signature); + } + + /** + * Creates an unsigned {@link SignedMessage} for an {@link Identity}. + * + * @param component the message component + * @param plain the plain text message + * @param identity the identity for the signed message header + * @return a new unsigned {@link SignedMessage} + * @since 4.12.0 + * @sinceMinecraft 1.19 + */ + @Contract(value = "_, _, _ -> new", pure = true) + static @NotNull SignedMessage unsigned(final @NotNull Component component, final @NotNull String plain, final @NotNull Identity identity) { + return new UnsignedSignedMessageImpl(component, plain, identity); + } + + /** + * Creates an unsigned {@link SignedMessage} for an {@link Identity}. + * + * @param component the message component + * @param plain the plain text message + * @param identified the identity for the signed message header + * @return a new unsigned {@link SignedMessage} + * @since 4.12.0 + * @sinceMinecraft 1.19 + */ + @Contract(value = "_, _, _ -> new", pure = true) + static @NotNull SignedMessage unsigned(final @NotNull Component component, final @NotNull String plain, final @NotNull Identified identified) { + return new UnsignedSignedMessageImpl(component, plain, identified.identity()); + } + /** * The time that the message was sent. * @@ -65,5 +113,52 @@ public interface SignedMessage extends PlayerIdentified { * @sinceMinecraft 1.19 */ @Contract(pure = true) - byte[] signature(); + @Nullable Signature signature(); + + /** + * The signed component. + * + * @return the component + * @since 4.12.0 + * @sinceMinecraft 1.19 + */ + @Contract(pure = true) + @NotNull Component message(); + + @Override + @NotNull + default Component asComponent() { + return this.message(); + } + + /** + * The plain string message. + * + * @return the plain string message + * @since 4.12.0 + * @sinceMinecraft 1.19 + */ + @Contract(pure = true) + @NotNull String plain(); + + final class Signature { + + final byte[] signature; + + private Signature(final byte[] signature) { + this.signature = signature; + } + + /** + * Gets the bytes for this signature. + * + * @return the bytes + * @since 4.12.0 + * @sinceMinecraft 1.19 + */ + @Contract(pure = true) + public byte[] bytes() { + return this.signature; + } + } } diff --git a/api/src/main/java/net/kyori/adventure/chat/UnsignedSignedMessageImpl.java b/api/src/main/java/net/kyori/adventure/chat/UnsignedSignedMessageImpl.java new file mode 100644 index 000000000..1ed3438a2 --- /dev/null +++ b/api/src/main/java/net/kyori/adventure/chat/UnsignedSignedMessageImpl.java @@ -0,0 +1,55 @@ +package net.kyori.adventure.chat; + +import java.security.SecureRandom; +import java.time.Instant; +import net.kyori.adventure.identity.Identity; +import net.kyori.adventure.text.Component; +import org.jetbrains.annotations.NotNull; + +final class UnsignedSignedMessageImpl implements SignedMessage { + static final SecureRandom RANDOM = new SecureRandom(); + + private final Instant instant; + private final long salt; + private final Component message; + private final String plain; + private final Identity identity; + + UnsignedSignedMessageImpl(final Component message, final String plain, final Identity identity) { + this.instant = Instant.now(); + this.salt = RANDOM.nextLong(); + this.message = message; + this.plain = plain; + this.identity = identity; + } + + @Override + public @NotNull Instant timeStamp() { + return this.instant; + } + + @Override + public long salt() { + return this.salt; + } + + @Override + public Signature signature() { + return null; + } + + @Override + public @NotNull Component message() { + return this.message; + } + + @Override + public @NotNull String plain() { + return this.plain; + } + + @Override + public @NotNull Identity identity() { + return this.identity; + } +} From fc1ba319bc20823f46800ac35ae87e2185ad0f80 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Tue, 2 Aug 2022 12:22:15 -0700 Subject: [PATCH 06/21] move some audience methods around --- .../kyori/adventure/audience/Audience.java | 116 ++++++++++-------- .../net/kyori/adventure/chat/ChatType.java | 4 +- .../kyori/adventure/chat/ChatTypeImpl.java | 2 +- 3 files changed, 67 insertions(+), 55 deletions(-) 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 ce4d95583..773b48503 100644 --- a/api/src/main/java/net/kyori/adventure/audience/Audience.java +++ b/api/src/main/java/net/kyori/adventure/audience/Audience.java @@ -179,6 +179,7 @@ default void forEachAudience(final @NotNull Consumer action) { action.accept(this); } + /* Start: system messages */ /** * Sends a system chat message to this {@link Audience}. * @@ -194,116 +195,119 @@ default void sendMessage(final @NotNull ComponentLike message) { } /** - * Sends a player chat message from the given {@link Identified} to this {@link Audience} with the {@link ChatType#CHAT system} chat type. + * Sends a system chat message to this {@link Audience}. * - * @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 and can reject identified messages without {@link SignedMessage} data, this may be unsupported in the future, use {@link #sendMessage(SignedMessage, ChatType.Bound)} instead + * @see #sendMessage(Identified, Component) + * @see #sendMessage(Identity, Component) + * @since 4.1.0 */ - @Deprecated - @ForwardingAudienceOverrideNotRequired - default void sendMessage(final @NotNull Identified source, final @NotNull ComponentLike message) { - this.sendMessage(source, message.asComponent()); + default void sendMessage(final @NotNull Component message) { } /** - * Sends a player chat message from the entity represented by the given {@link Identity} to this {@link Audience} with the {@link ChatType#CHAT system} chat type. + * Sends a system chat message to this {@link Audience} ignoring 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 since 4.12.0, the client errors on and can reject identified messages without {@link SignedMessage} data, this may be unsupported in the future, use {@link #sendMessage(SignedMessage, ChatType.Bound)} instead + * @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)} */ + @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") @Deprecated @ForwardingAudienceOverrideNotRequired - default void sendMessage(final @NotNull Identity source, final @NotNull ComponentLike message) { - this.sendMessage(source, message.asComponent()); + default void sendMessage(final @NotNull ComponentLike message, final @NotNull MessageType type) { + this.sendMessage(message); } /** - * Sends a system chat message to this {@link Audience}. + * Sends a system chat message to this {@link Audience} ignoring the provided {@link MessageType}. * * @param message a message + * @param type the type * @see Component - * @see #sendMessage(Identified, Component) - * @see #sendMessage(Identity, Component) + * @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)} instead */ - default void sendMessage(final @NotNull Component message) { + @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") + @Deprecated + @ForwardingAudienceOverrideNotRequired + default void sendMessage(final @NotNull Component message, final @NotNull MessageType type) { + this.sendMessage(message); } + /* End: system messages */ + /* Start: unsigned player messages */ /** - * Sends a player chat message from the given {@link Identified} to this {@link Audience} with the {@link ChatType#CHAT system} chat type. + * Sends an unsigned player chat message from the given {@link Identified} to this {@link Audience} with the {@link ChatType#CHAT 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(SignedMessage, PlayerIdentified)} instead + * @deprecated since 4.12.0, the client errors on and can reject identified messages without {@link SignedMessage} data, this may be unsupported in the future, use {@link #sendMessage(SignedMessage, ChatType.Bound)} instead */ @Deprecated @ForwardingAudienceOverrideNotRequired - default void sendMessage(final @NotNull Identified source, final @NotNull Component message) { - this.sendMessage(source, message, MessageType.CHAT); + default void sendMessage(final @NotNull Identified source, final @NotNull ComponentLike message) { + this.sendMessage(source, message.asComponent()); } /** - * Sends a player chat message from the entity represented by the given {@link Identity} to this {@link Audience} with the {@link ChatType#CHAT system} chat type. + * Sends an unsigned player chat message from the entity represented by the given {@link Identity} to this {@link Audience} with the {@link ChatType#CHAT 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(SignedMessage, PlayerIdentity)} instead + * @deprecated since 4.12.0, the client errors on and can reject identified messages without {@link SignedMessage} data, this may be unsupported in the future, use {@link #sendMessage(SignedMessage, ChatType.Bound)} instead */ @Deprecated @ForwardingAudienceOverrideNotRequired - default void sendMessage(final @NotNull Identity source, final @NotNull Component message) { - this.sendMessage(source, message, MessageType.CHAT); + default void sendMessage(final @NotNull Identity source, final @NotNull ComponentLike message) { + this.sendMessage(source, message.asComponent()); } /** - * Sends a system chat message to this {@link Audience} ignoring the provided {@link MessageType}. + * Sends an unsigned player chat message from the given {@link Identified} to this {@link Audience} with the {@link ChatType#CHAT system} chat type. * + * @param source the source of the message * @param message a message - * @param type the type * @see Component - * @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)} + * @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(SignedMessage, PlayerIdentified)} instead */ - @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") @Deprecated @ForwardingAudienceOverrideNotRequired - default void sendMessage(final @NotNull ComponentLike message, final @NotNull MessageType type) { - this.sendMessage(message); + default void sendMessage(final @NotNull Identified source, final @NotNull Component message) { + this.sendMessage(source, message, MessageType.CHAT); } /** - * Sends a player chat message from the given {@link Identified} to this {@link Audience} with the {@link ChatType} corresponding to the provided {@link MessageType}. + * Sends an unsigned player chat message from the entity represented by the given {@link Identity} to this {@link Audience} with the {@link ChatType#CHAT system} chat type. * - * @param source the source of the message + * @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(SignedMessage, ChatType.Bound)} instead + * @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(SignedMessage, PlayerIdentity)} 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); + default void sendMessage(final @NotNull Identity source, final @NotNull Component message) { + this.sendMessage(source, message, MessageType.CHAT); } /** - * Sends a player chat message from the entity represented by the given {@link Identity} to this {@link Audience}. + * Sends an unsigned 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 identity of the source of the message + * @param source the source of the message * @param message a message * @param type the type * @see Component @@ -313,26 +317,25 @@ default void sendMessage(final @NotNull Identified source, final @NotNull Compon @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") @Deprecated @ForwardingAudienceOverrideNotRequired - default void sendMessage(final @NotNull Identity source, final @NotNull ComponentLike message, final @NotNull MessageType type) { + default void sendMessage(final @NotNull Identified source, final @NotNull ComponentLike message, final @NotNull MessageType type) { this.sendMessage(source, message.asComponent(), type); } /** - * Sends a system chat message to this {@link Audience} ignoring the provided {@link MessageType}. + * Sends an unsigned player chat message from the entity represented by the given {@link Identity} to this {@link Audience}. * + * @param source the identity of the source of the message * @param message a message * @param type the type * @see Component - * @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)} instead + * @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(SignedMessage, ChatType.Bound)} instead */ @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") @Deprecated @ForwardingAudienceOverrideNotRequired - default void sendMessage(final @NotNull Component message, final @NotNull MessageType type) { - this.sendMessage(message); + default void sendMessage(final @NotNull Identity source, final @NotNull ComponentLike message, final @NotNull MessageType type) { + this.sendMessage(source, message.asComponent(), type); } /** @@ -348,6 +351,9 @@ default void sendMessage(final @NotNull Component message, final @NotNull Messag @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") @Deprecated default void sendMessage(final @NotNull Identified source, final @NotNull Component message, final @NotNull MessageType type) { + if (source.identity() == Identity.nil()) { + this.sendMessage(message); + } } /** @@ -363,8 +369,13 @@ default void sendMessage(final @NotNull Identified source, final @NotNull Compon @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") @Deprecated default void sendMessage(final @NotNull Identity source, final @NotNull Component message, final @NotNull MessageType type) { + if (source == Identity.nil()) { + this.sendMessage(message); + } } + /* End: unsigned player messages */ + /* Start: signed player messages */ /** * Sends a signed player chat message from the given {@link PlayerIdentified} to this {@link Audience} with the {@link ChatType#CHAT chat} chat type. * @@ -398,6 +409,7 @@ default void sendMessage(final @NotNull SignedMessage signedMessage, final @NotN */ default void sendMessage(final @NotNull SignedMessage signedMessage, final ChatType.Bound boundChatType) { } + /* End: signed player messages */ /** * Sends a message on the action bar. 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 aaba7a6e8..e14578669 100644 --- a/api/src/main/java/net/kyori/adventure/chat/ChatType.java +++ b/api/src/main/java/net/kyori/adventure/chat/ChatType.java @@ -125,7 +125,7 @@ default ChatType.Bound bind(@NotNull final Component sender, final @Nullable Com interface Bound extends Examinable { @Contract(pure = true) - @NotNull ChatType chatType(); + @NotNull ChatType type(); @Contract(pure = true) @NotNull Component sender(); @@ -137,7 +137,7 @@ interface Bound extends Examinable { @NotNull default Stream examinableProperties() { return Stream.of( - ExaminableProperty.of("chatType", this.chatType()), + ExaminableProperty.of("type", this.type()), ExaminableProperty.of("sender", this.sender()), ExaminableProperty.of("target", this.target()) ); diff --git a/api/src/main/java/net/kyori/adventure/chat/ChatTypeImpl.java b/api/src/main/java/net/kyori/adventure/chat/ChatTypeImpl.java index 88755ae8f..e352e43a2 100644 --- a/api/src/main/java/net/kyori/adventure/chat/ChatTypeImpl.java +++ b/api/src/main/java/net/kyori/adventure/chat/ChatTypeImpl.java @@ -58,7 +58,7 @@ static final class BoundImpl implements ChatType.Bound { } @Override - public @NotNull ChatType chatType() { + public @NotNull ChatType type() { return this.chatType; } From 1f27da5a8ab40f90e2dec84d4cae72fa31f0a5aa Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Tue, 2 Aug 2022 13:04:40 -0700 Subject: [PATCH 07/21] fix checkstyle issues and address test failures --- .../audience/ForwardingAudience.java | 10 ++++ .../kyori/adventure/audience/MessageType.java | 2 - .../net/kyori/adventure/chat/ChatType.java | 51 +++++++++++++++++-- .../kyori/adventure/chat/SignedMessage.java | 6 +++ .../chat/UnsignedSignedMessageImpl.java | 23 +++++++++ 5 files changed, 87 insertions(+), 5 deletions(-) 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 d93aed787..0b08c4596 100644 --- a/api/src/main/java/net/kyori/adventure/audience/ForwardingAudience.java +++ b/api/src/main/java/net/kyori/adventure/audience/ForwardingAudience.java @@ -99,6 +99,11 @@ default void forEachAudience(final @NotNull Consumer action) { for (final Audience audience : this.audiences()) audience.forEachAudience(action); } + @Override + default void sendMessage(final @NotNull Component message) { + for (final Audience audience : this.audiences()) audience.sendMessage(message); + } + @Override default void sendMessage(final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentified source) { for (final Audience audience : this.audiences()) audience.sendMessage(signedMessage, source); @@ -255,6 +260,11 @@ default void forEachAudience(final @NotNull Consumer action) { return this.audience().pointers(); } + @Override + default void sendMessage(final @NotNull Component message) { + this.audience().sendMessage(message); + } + @Override default void sendMessage(final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentified source) { this.audience().sendMessage(signedMessage, source); diff --git a/api/src/main/java/net/kyori/adventure/audience/MessageType.java b/api/src/main/java/net/kyori/adventure/audience/MessageType.java index 88f873f99..5c05755fe 100644 --- a/api/src/main/java/net/kyori/adventure/audience/MessageType.java +++ b/api/src/main/java/net/kyori/adventure/audience/MessageType.java @@ -24,9 +24,7 @@ package net.kyori.adventure.audience; import net.kyori.adventure.chat.ChatType; -import net.kyori.adventure.key.Key; import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.NotNull; /** * Message types. 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 e14578669..5de029599 100644 --- a/api/src/main/java/net/kyori/adventure/chat/ChatType.java +++ b/api/src/main/java/net/kyori/adventure/chat/ChatType.java @@ -108,28 +108,73 @@ public interface ChatType extends Examinable, Keyed { return new ChatTypeImpl(Objects.requireNonNull(key, "key")); } - default ChatType.Bound bind(@NotNull final Component sender) { + /** + * Creates a bound chat type with a sender {@link Component}. + * + * @param sender the sender component + * @return a new bound chat type + * @since 4.12.0 + * @sinceMinecraft 1.19 + */ + @Contract(value = "_ -> new", pure = true) + default @NotNull ChatType.Bound bind(@NotNull final Component sender) { return this.bind(sender, null); } - default ChatType.Bound bind(@NotNull final Component sender, final @Nullable Component target) { + /** + * Creates a bound chat type with a sender and target {@link Component}. + * + * @param sender the sender component + * @param target the optional target component + * @return a new bound chat type + * @since 4.12.0 + * @sinceMinecraft 1.19 + */ + @Contract(value = "_, _ -> new", pure = true) + default @NotNull ChatType.Bound bind(@NotNull final Component sender, final @Nullable Component target) { return new ChatTypeImpl.BoundImpl(this, sender, target); } - @Override default @NotNull Stream examinableProperties() { return Stream.of(ExaminableProperty.of("key", this.key())); } + /** + * A bound {@link ChatType}. + * + * @since 4.12.0 + * @sinceMinecraft 1.19 + */ interface Bound extends Examinable { + /** + * Gets the chat type. + * + * @return the chat type + * @since 4.12.0 + * @sinceMinecraft 1.19 + */ @Contract(pure = true) @NotNull ChatType type(); + /** + * Get the sender component. + * + * @return the sender component + * @since 4.12.0 + * @sinceMinecraft 1.19 + */ @Contract(pure = true) @NotNull Component sender(); + /** + * Get the target component. + * + * @return the target component or null + * @since 4.12.0 + * @sinceMinecraft 1.19 + */ @Contract(pure = true) @Nullable Component target(); 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 2ac1c3373..9c82b2256 100644 --- a/api/src/main/java/net/kyori/adventure/chat/SignedMessage.java +++ b/api/src/main/java/net/kyori/adventure/chat/SignedMessage.java @@ -141,6 +141,12 @@ default Component asComponent() { @Contract(pure = true) @NotNull String plain(); + /** + * A signature wrapper type. + * + * @since 4.12.0 + * @sinceMinecraft 1.19 + */ final class Signature { final byte[] signature; diff --git a/api/src/main/java/net/kyori/adventure/chat/UnsignedSignedMessageImpl.java b/api/src/main/java/net/kyori/adventure/chat/UnsignedSignedMessageImpl.java index 1ed3438a2..0f162a776 100644 --- a/api/src/main/java/net/kyori/adventure/chat/UnsignedSignedMessageImpl.java +++ b/api/src/main/java/net/kyori/adventure/chat/UnsignedSignedMessageImpl.java @@ -1,3 +1,26 @@ +/* + * This file is part of adventure, licensed under the MIT License. + * + * Copyright (c) 2017-2022 KyoriPowered + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package net.kyori.adventure.chat; import java.security.SecureRandom; From 5b46c8726ce8729071bc5ba930e19ec60eb8a886 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Tue, 2 Aug 2022 14:56:37 -0700 Subject: [PATCH 08/21] Add system SignedMessage impl --- .../kyori/adventure/audience/Audience.java | 40 ++++++++++++++++ .../adventure/audience/EmptyAudience.java | 9 ++++ .../audience/ForwardingAudience.java | 38 +++++++++++++++ .../kyori/adventure/chat/SignedMessage.java | 48 +++++++++++-------- ...essageImpl.java => SignedMessageImpl.java} | 9 ++-- 5 files changed, 119 insertions(+), 25 deletions(-) rename api/src/main/java/net/kyori/adventure/chat/{UnsignedSignedMessageImpl.java => SignedMessageImpl.java} (89%) 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 773b48503..d23042959 100644 --- a/api/src/main/java/net/kyori/adventure/audience/Audience.java +++ b/api/src/main/java/net/kyori/adventure/audience/Audience.java @@ -409,6 +409,46 @@ default void sendMessage(final @NotNull SignedMessage signedMessage, final @NotN */ default void sendMessage(final @NotNull SignedMessage signedMessage, final ChatType.Bound boundChatType) { } + + /** + * Requests deletion of a message with the provided {@link SignedMessage}'s signature. + * + * @param signedMessage the message to delete + * @return true if the signedMessage supports being deleted + * @see SignedMessage#canDelete() + * @since 4.12.0 + * @sinceMinecraft 1.19 + */ + @ForwardingAudienceOverrideNotRequired + default boolean deleteMessage(final @NotNull SignedMessage signedMessage) { + if (signedMessage.canDelete()) { + this.deleteMessage(Objects.requireNonNull(signedMessage.signature(), "signedMessage must have a signature")); + return true; + } + return false; + } + + /** + * Requests deletion of a message with the provided {@link SignedMessage.Signature}. + * + * @param signature the signature + * @since 4.12.0 + * @sinceMinecraft 1.19 + */ + default void deleteMessage(final SignedMessage.@NotNull Signature signature) { + } + + /** + * Sends the signed message's header to this audience. + * + * @param signedMessage the signed message + * @return true if successfully sent + * @since 4.12.0 + * @sinceMinecraft 1.19 + */ + default boolean sendMessageHeader(final @NotNull SignedMessage signedMessage) { + return false; + } /* End: signed player messages */ /** 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 3989a0577..165a817ea 100644 --- a/api/src/main/java/net/kyori/adventure/audience/EmptyAudience.java +++ b/api/src/main/java/net/kyori/adventure/audience/EmptyAudience.java @@ -90,6 +90,15 @@ public void sendMessage(final @NotNull SignedMessage signedMessage, final @NotNu public void sendMessage(final @NotNull SignedMessage signedMessage, final ChatType.Bound boundChatType) { } + @Override + public void deleteMessage(final SignedMessage.@NotNull Signature signature) { + } + + @Override + public boolean sendMessageHeader(final @NotNull SignedMessage signedMessage) { + return false; + } + @Override public void sendMessage(final @NotNull Identified source, final @NotNull Component message, final @NotNull MessageType type) { } 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 0b08c4596..3e2698758 100644 --- a/api/src/main/java/net/kyori/adventure/audience/ForwardingAudience.java +++ b/api/src/main/java/net/kyori/adventure/audience/ForwardingAudience.java @@ -119,6 +119,29 @@ default void sendMessage(final @NotNull SignedMessage signedMessage, final ChatT for (final Audience audience : this.audiences()) audience.sendMessage(signedMessage, boundChatType); } + @Override + default boolean deleteMessage(final @NotNull SignedMessage signedMessage) { + boolean result = true; + for (final Audience audience : this.audiences()) { + result &= audience.deleteMessage(signedMessage); + } + return result; + } + + @Override + default void deleteMessage(final SignedMessage.@NotNull Signature signature) { + for (final Audience audience : this.audiences()) audience.deleteMessage(signature); + } + + @Override + default boolean sendMessageHeader(final @NotNull SignedMessage signedMessage) { + boolean result = true; + for (final Audience audience : this.audiences()) { + result &= audience.sendMessageHeader(signedMessage); + } + return result; + } + @Override default void sendMessage(@NotNull Identified source, @NotNull Component message, @NotNull MessageType type) { for (final Audience audience : this.audiences()) audience.sendMessage(source, message, type); @@ -280,6 +303,21 @@ default void sendMessage(final @NotNull SignedMessage signedMessage, final ChatT this.audience().sendMessage(signedMessage, boundChatType); } + @Override + default boolean deleteMessage(final @NotNull SignedMessage signedMessage) { + return this.audience().deleteMessage(signedMessage); + } + + @Override + default void deleteMessage(final SignedMessage.@NotNull Signature signature) { + this.audience().deleteMessage(signature); + } + + @Override + default boolean sendMessageHeader(final @NotNull SignedMessage signedMessage) { + return this.audience().sendMessageHeader(signedMessage); + } + @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/SignedMessage.java b/api/src/main/java/net/kyori/adventure/chat/SignedMessage.java index 9c82b2256..e4cfa7c36 100644 --- a/api/src/main/java/net/kyori/adventure/chat/SignedMessage.java +++ b/api/src/main/java/net/kyori/adventure/chat/SignedMessage.java @@ -56,33 +56,17 @@ public interface SignedMessage extends Identified, ComponentLike { } /** - * Creates an unsigned {@link SignedMessage} for an {@link Identity}. + * Creates a system {@link SignedMessage}. * * @param component the message component * @param plain the plain text message - * @param identity the identity for the signed message header * @return a new unsigned {@link SignedMessage} * @since 4.12.0 * @sinceMinecraft 1.19 */ - @Contract(value = "_, _, _ -> new", pure = true) - static @NotNull SignedMessage unsigned(final @NotNull Component component, final @NotNull String plain, final @NotNull Identity identity) { - return new UnsignedSignedMessageImpl(component, plain, identity); - } - - /** - * Creates an unsigned {@link SignedMessage} for an {@link Identity}. - * - * @param component the message component - * @param plain the plain text message - * @param identified the identity for the signed message header - * @return a new unsigned {@link SignedMessage} - * @since 4.12.0 - * @sinceMinecraft 1.19 - */ - @Contract(value = "_, _, _ -> new", pure = true) - static @NotNull SignedMessage unsigned(final @NotNull Component component, final @NotNull String plain, final @NotNull Identified identified) { - return new UnsignedSignedMessageImpl(component, plain, identified.identity()); + @Contract(value = "_, _ -> new", pure = true) + static @NotNull SignedMessage system(final @NotNull Component component, final @NotNull String plain) { + return new SignedMessageImpl(component, plain); } /** @@ -141,6 +125,30 @@ default Component asComponent() { @Contract(pure = true) @NotNull String plain(); + /** + * Checks if this message is a system message. + * + * @return true if system + * @since 4.12.0 + * @sinceMinecraft 1.19 + */ + @Contract(pure = true) + default boolean isSystem() { + return this.identity() == Identity.nil(); + } + + /** + * Checks if this message can be deleted via {@link net.kyori.adventure.audience.Audience#deleteMessage(SignedMessage)}. + * + * @return true if supports deletion + * @since 4.12.0 + * @sinceMinecraft 1.19 + */ + @Contract(pure = true) + default boolean canDelete() { + return this.signature() != null; + } + /** * A signature wrapper type. * diff --git a/api/src/main/java/net/kyori/adventure/chat/UnsignedSignedMessageImpl.java b/api/src/main/java/net/kyori/adventure/chat/SignedMessageImpl.java similarity index 89% rename from api/src/main/java/net/kyori/adventure/chat/UnsignedSignedMessageImpl.java rename to api/src/main/java/net/kyori/adventure/chat/SignedMessageImpl.java index 0f162a776..cc3f0059e 100644 --- a/api/src/main/java/net/kyori/adventure/chat/UnsignedSignedMessageImpl.java +++ b/api/src/main/java/net/kyori/adventure/chat/SignedMessageImpl.java @@ -29,21 +29,20 @@ import net.kyori.adventure.text.Component; import org.jetbrains.annotations.NotNull; -final class UnsignedSignedMessageImpl implements SignedMessage { +// Used for system messages +final class SignedMessageImpl implements SignedMessage { static final SecureRandom RANDOM = new SecureRandom(); private final Instant instant; private final long salt; private final Component message; private final String plain; - private final Identity identity; - UnsignedSignedMessageImpl(final Component message, final String plain, final Identity identity) { + SignedMessageImpl(final Component message, final String plain) { this.instant = Instant.now(); this.salt = RANDOM.nextLong(); this.message = message; this.plain = plain; - this.identity = identity; } @Override @@ -73,6 +72,6 @@ public Signature signature() { @Override public @NotNull Identity identity() { - return this.identity; + return Identity.nil(); } } From 3e9221116e415de938d50e6a2cd6df29b88826ff Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Tue, 2 Aug 2022 15:00:51 -0700 Subject: [PATCH 09/21] some javadoc fixes --- .../main/java/net/kyori/adventure/audience/Audience.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 d23042959..06fd689aa 100644 --- a/api/src/main/java/net/kyori/adventure/audience/Audience.java +++ b/api/src/main/java/net/kyori/adventure/audience/Audience.java @@ -339,7 +339,7 @@ default void sendMessage(final @NotNull Identity source, final @NotNull Componen } /** - * Sends a player chat message from the given {@link Identified} to this {@link Audience} with the {@link ChatType} corresponding to the provided {@link MessageType}. + * Sends an unsigned 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 @@ -389,7 +389,7 @@ default void sendMessage(final @NotNull SignedMessage signedMessage, final @NotN } /** - * 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. + * Sends a signed player chat message from the player identified by the provided {@link PlayerIdentity} to this {@link Audience} with the {@link ChatType#CHAT chat} chat type. * * @param signedMessage the signed message data * @param source the identity of the source of the message @@ -401,7 +401,7 @@ default void sendMessage(final @NotNull SignedMessage signedMessage, final @NotN } /** - * Sends a signed player chat message from the given {@link PlayerIdentified} to this {@link Audience} with the provided {@link ChatType} chat type. + * Sends a signed player chat message to this {@link Audience} with the provided {@link ChatType.Bound} bound chat type. * * @param signedMessage the signed message data * @param boundChatType the bound chat type From 6faf29e96aa9138050a899a4577fe09bcbe01620 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Tue, 2 Aug 2022 15:23:51 -0700 Subject: [PATCH 10/21] change some return types to void in Audience --- .../kyori/adventure/audience/Audience.java | 10 +++---- .../adventure/audience/EmptyAudience.java | 3 +-- .../audience/ForwardingAudience.java | 26 +++---------------- .../kyori/adventure/chat/SignedMessage.java | 10 +++++++ .../adventure/chat/SignedMessageImpl.java | 5 ++++ 5 files changed, 23 insertions(+), 31 deletions(-) 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 06fd689aa..1364aa874 100644 --- a/api/src/main/java/net/kyori/adventure/audience/Audience.java +++ b/api/src/main/java/net/kyori/adventure/audience/Audience.java @@ -414,18 +414,15 @@ default void sendMessage(final @NotNull SignedMessage signedMessage, final ChatT * Requests deletion of a message with the provided {@link SignedMessage}'s signature. * * @param signedMessage the message to delete - * @return true if the signedMessage supports being deleted * @see SignedMessage#canDelete() * @since 4.12.0 * @sinceMinecraft 1.19 */ @ForwardingAudienceOverrideNotRequired - default boolean deleteMessage(final @NotNull SignedMessage signedMessage) { + default void deleteMessage(final @NotNull SignedMessage signedMessage) { if (signedMessage.canDelete()) { this.deleteMessage(Objects.requireNonNull(signedMessage.signature(), "signedMessage must have a signature")); - return true; } - return false; } /** @@ -442,12 +439,11 @@ default void deleteMessage(final SignedMessage.@NotNull Signature signature) { * Sends the signed message's header to this audience. * * @param signedMessage the signed message - * @return true if successfully sent + * @see SignedMessage#canSendAsHeader() * @since 4.12.0 * @sinceMinecraft 1.19 */ - default boolean sendMessageHeader(final @NotNull SignedMessage signedMessage) { - return false; + default void sendMessageHeader(final @NotNull SignedMessage signedMessage) { } /* End: signed player messages */ 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 165a817ea..b8d11ea6a 100644 --- a/api/src/main/java/net/kyori/adventure/audience/EmptyAudience.java +++ b/api/src/main/java/net/kyori/adventure/audience/EmptyAudience.java @@ -95,8 +95,7 @@ public void deleteMessage(final SignedMessage.@NotNull Signature signature) { } @Override - public boolean sendMessageHeader(final @NotNull SignedMessage signedMessage) { - return false; + public void sendMessageHeader(final @NotNull SignedMessage signedMessage) { } @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 3e2698758..562b8bca3 100644 --- a/api/src/main/java/net/kyori/adventure/audience/ForwardingAudience.java +++ b/api/src/main/java/net/kyori/adventure/audience/ForwardingAudience.java @@ -119,27 +119,14 @@ default void sendMessage(final @NotNull SignedMessage signedMessage, final ChatT for (final Audience audience : this.audiences()) audience.sendMessage(signedMessage, boundChatType); } - @Override - default boolean deleteMessage(final @NotNull SignedMessage signedMessage) { - boolean result = true; - for (final Audience audience : this.audiences()) { - result &= audience.deleteMessage(signedMessage); - } - return result; - } - @Override default void deleteMessage(final SignedMessage.@NotNull Signature signature) { for (final Audience audience : this.audiences()) audience.deleteMessage(signature); } @Override - default boolean sendMessageHeader(final @NotNull SignedMessage signedMessage) { - boolean result = true; - for (final Audience audience : this.audiences()) { - result &= audience.sendMessageHeader(signedMessage); - } - return result; + default void sendMessageHeader(final @NotNull SignedMessage signedMessage) { + for (final Audience audience : this.audiences()) audience.sendMessageHeader(signedMessage); } @Override @@ -303,19 +290,14 @@ default void sendMessage(final @NotNull SignedMessage signedMessage, final ChatT this.audience().sendMessage(signedMessage, boundChatType); } - @Override - default boolean deleteMessage(final @NotNull SignedMessage signedMessage) { - return this.audience().deleteMessage(signedMessage); - } - @Override default void deleteMessage(final SignedMessage.@NotNull Signature signature) { this.audience().deleteMessage(signature); } @Override - default boolean sendMessageHeader(final @NotNull SignedMessage signedMessage) { - return this.audience().sendMessageHeader(signedMessage); + default void sendMessageHeader(final @NotNull SignedMessage signedMessage) { + this.audience().sendMessageHeader(signedMessage); } @Override 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 e4cfa7c36..603d349f4 100644 --- a/api/src/main/java/net/kyori/adventure/chat/SignedMessage.java +++ b/api/src/main/java/net/kyori/adventure/chat/SignedMessage.java @@ -149,6 +149,16 @@ default boolean canDelete() { return this.signature() != null; } + /** + * Checks if this message can be sent as a header via {@link net.kyori.adventure.audience.Audience#sendMessageHeader(SignedMessage)}. + * + * @return true if supports sending as a header + * @since 4.12.0 + * @sinceMinecraft 1.19 + */ + @Contract(pure = true) + boolean canSendAsHeader(); + /** * A signature wrapper type. * diff --git a/api/src/main/java/net/kyori/adventure/chat/SignedMessageImpl.java b/api/src/main/java/net/kyori/adventure/chat/SignedMessageImpl.java index cc3f0059e..e2c10436d 100644 --- a/api/src/main/java/net/kyori/adventure/chat/SignedMessageImpl.java +++ b/api/src/main/java/net/kyori/adventure/chat/SignedMessageImpl.java @@ -70,6 +70,11 @@ public Signature signature() { return this.plain; } + @Override + public boolean canSendAsHeader() { + return false; + } + @Override public @NotNull Identity identity() { return Identity.nil(); From 99dccb86b11c78c89b882b45dbfb65878427a795 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Sat, 5 Nov 2022 22:05:08 -0700 Subject: [PATCH 11/21] make Signature an interface + impl --- .../net/kyori/adventure/audience/MessageType.java | 2 +- .../net/kyori/adventure/chat/SignedMessage.java | 14 +++----------- .../kyori/adventure/chat/SignedMessageImpl.java | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/api/src/main/java/net/kyori/adventure/audience/MessageType.java b/api/src/main/java/net/kyori/adventure/audience/MessageType.java index 5c05755fe..6de8dec58 100644 --- a/api/src/main/java/net/kyori/adventure/audience/MessageType.java +++ b/api/src/main/java/net/kyori/adventure/audience/MessageType.java @@ -30,7 +30,7 @@ * Message types. * * @since 4.0.0 - * @deprecated for removal since 4.12.0, use corresponding {@link ChatType} instead + * @deprecated for removal since 4.12.0, use separate methods on {@link Audience} for sending player or system messages */ @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") @Deprecated 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 603d349f4..671893789 100644 --- a/api/src/main/java/net/kyori/adventure/chat/SignedMessage.java +++ b/api/src/main/java/net/kyori/adventure/chat/SignedMessage.java @@ -52,7 +52,7 @@ public interface SignedMessage extends Identified, ComponentLike { */ @Contract(value = "_ -> new", pure = true) static @NotNull Signature signature(final byte[] signature) { - return new Signature(signature); + return new SignedMessageImpl.SignatureImpl(signature); } /** @@ -165,13 +165,7 @@ default boolean canDelete() { * @since 4.12.0 * @sinceMinecraft 1.19 */ - final class Signature { - - final byte[] signature; - - private Signature(final byte[] signature) { - this.signature = signature; - } + interface Signature { /** * Gets the bytes for this signature. @@ -181,8 +175,6 @@ private Signature(final byte[] signature) { * @sinceMinecraft 1.19 */ @Contract(pure = true) - public byte[] bytes() { - return this.signature; - } + byte[] bytes(); } } diff --git a/api/src/main/java/net/kyori/adventure/chat/SignedMessageImpl.java b/api/src/main/java/net/kyori/adventure/chat/SignedMessageImpl.java index e2c10436d..a461cd095 100644 --- a/api/src/main/java/net/kyori/adventure/chat/SignedMessageImpl.java +++ b/api/src/main/java/net/kyori/adventure/chat/SignedMessageImpl.java @@ -79,4 +79,18 @@ public boolean canSendAsHeader() { public @NotNull Identity identity() { return Identity.nil(); } + + static final class SignatureImpl implements Signature { + + final byte[] signature; + + SignatureImpl(final byte[] signature) { + this.signature =signature; + } + + @Override + public byte[] bytes() { + return this.signature; + } + } } From ac9c4cdd591cdcfbae3d824541d929bb5e996731 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Sat, 5 Nov 2022 23:19:12 -0700 Subject: [PATCH 12/21] update for 1.19.3 chat changes --- .../kyori/adventure/audience/Audience.java | 69 ++++++++++++++++--- .../adventure/audience/EmptyAudience.java | 16 ++--- .../audience/ForwardingAudience.java | 18 ++--- .../kyori/adventure/chat/SignedMessage.java | 27 +++----- .../adventure/chat/SignedMessageImpl.java | 21 +++--- 5 files changed, 91 insertions(+), 60 deletions(-) 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 1364aa874..d31b1edce 100644 --- a/api/src/main/java/net/kyori/adventure/audience/Audience.java +++ b/api/src/main/java/net/kyori/adventure/audience/Audience.java @@ -281,7 +281,7 @@ default void sendMessage(final @NotNull Identity source, final @NotNull Componen * @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(SignedMessage, PlayerIdentified)} instead + * @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 #sendChatMessage(SignedMessage, PlayerIdentified)} instead */ @Deprecated @ForwardingAudienceOverrideNotRequired @@ -296,7 +296,7 @@ default void sendMessage(final @NotNull Identified source, final @NotNull Compon * @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(SignedMessage, PlayerIdentity)} instead + * @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 #sendChatMessage(SignedMessage, PlayerIdentity)} instead */ @Deprecated @ForwardingAudienceOverrideNotRequired @@ -375,39 +375,87 @@ default void sendMessage(final @NotNull Identity source, final @NotNull Componen } /* End: unsigned player messages */ + /* Start: disguised player messages */ + /** + * Sends a chat message from the given {@link PlayerIdentified} to this {@link Audience} with the {@link ChatType#CHAT} chat type. + * + * @param component the component content + * @param source the source of the message + * @see #sendMessage(Component, ChatType.Bound) + * @since 4.12.0 + * @sinceMinecraft 1.19 + */ + @ForwardingAudienceOverrideNotRequired + default void sendChatMessage(final @NotNull Component component, final @NotNull PlayerIdentified source) { + this.sendChatMessage(component, source.identity()); + } + + /** + * Sends a chat message from the given {@link PlayerIdentity} to this {@link Audience} with the {@link ChatType#CHAT} chat type. + * + * @param component the component content + * @param source the source of the message + * @see #sendMessage(Component, ChatType.Bound) + * @since 4.12.0 + * @sinceMinecraft 1.19 + */ + @ForwardingAudienceOverrideNotRequired + default void sendChatMessage(final @NotNull Component component, final @NotNull PlayerIdentity source) { + this.sendMessage(component, ChatType.CHAT.bind(source.name())); + } + + /** + * Sends a message to this {@link Audience} with the provided {@link ChatType.Bound bound chat type}. + * + * @param message the component content + * @param boundChatType the bound chat type + * @sinceMinecraft 1.19 + */ + default void sendMessage(final @NotNull Component message, final @NotNull ChatType.Bound boundChatType) { + } + /* End: disguised player messages + /* Start: signed player messages */ /** - * Sends a signed player chat message from the given {@link PlayerIdentified} to this {@link Audience} with the {@link ChatType#CHAT chat} chat type. + * Sends a signed player chat message from the given {@link PlayerIdentified} to this {@link Audience} with the {@link ChatType#CHAT} chat type. * * @param signedMessage the signed message data * @param source the source of the message + * @see #sendMessage(SignedMessage, ChatType.Bound) * @since 4.12.0 + * @sinceMinecraft 1.19 */ @ForwardingAudienceOverrideNotRequired - default void sendMessage(final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentified source) { - this.sendMessage(signedMessage, source.identity()); + default void sendChatMessage(final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentified source) { + this.sendChatMessage(signedMessage, source.identity()); } /** - * Sends a signed player chat message from the player identified by the provided {@link PlayerIdentity} to this {@link Audience} with the {@link ChatType#CHAT chat} chat type. + * Sends a signed player chat message from the player identified by the provided {@link PlayerIdentity} to this {@link Audience} with the {@link ChatType#CHAT} chat type. * * @param signedMessage the signed message data * @param source the identity of the source of the message + * @see #sendMessage(SignedMessage, ChatType.Bound) * @since 4.12.0 + * @sinceMinecraft 1.19 */ @ForwardingAudienceOverrideNotRequired - default void sendMessage(final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentity source) { + default void sendChatMessage(final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentity source) { this.sendMessage(signedMessage, ChatType.CHAT.bind(source.name())); } /** - * Sends a signed player chat message to this {@link Audience} with the provided {@link ChatType.Bound} bound chat type. + * Sends a signed player message to this {@link Audience} with the provided {@link ChatType.Bound bound chat type}. * * @param signedMessage the signed message data * @param boundChatType the bound chat type * @since 4.12.0 + * @sinceMinecraft 1.19 */ default void sendMessage(final @NotNull SignedMessage signedMessage, final ChatType.Bound boundChatType) { + if (signedMessage.isSystem()) { + this.sendMessage(signedMessage.unsignedContent() != null ? signedMessage.unsignedContent() : Component.text(signedMessage.message()), boundChatType); + } } /** @@ -421,7 +469,7 @@ default void sendMessage(final @NotNull SignedMessage signedMessage, final ChatT @ForwardingAudienceOverrideNotRequired default void deleteMessage(final @NotNull SignedMessage signedMessage) { if (signedMessage.canDelete()) { - this.deleteMessage(Objects.requireNonNull(signedMessage.signature(), "signedMessage must have a signature")); + this.deleteMessage(Objects.requireNonNull(signedMessage.signature())); } } @@ -435,6 +483,9 @@ default void deleteMessage(final @NotNull SignedMessage signedMessage) { default void deleteMessage(final SignedMessage.@NotNull Signature signature) { } + // todo, the delete message packet also supports an int identifier that has something + // to do with the message chain, unsure if that should be exposed + /** * Sends the signed message's header to this audience. * 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 b8d11ea6a..182608860 100644 --- a/api/src/main/java/net/kyori/adventure/audience/EmptyAudience.java +++ b/api/src/main/java/net/kyori/adventure/audience/EmptyAudience.java @@ -79,31 +79,27 @@ public void sendMessage(final @NotNull Component message) { } @Override - public void sendMessage(final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentified source) { - } - - @Override - public void sendMessage(final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentity source) { + public void sendMessage(final @NotNull Identified source, final @NotNull Component message, final @NotNull MessageType type) { } @Override - public void sendMessage(final @NotNull SignedMessage signedMessage, final ChatType.Bound boundChatType) { + public void sendMessage(final @NotNull Identity source, final @NotNull Component message, final @NotNull MessageType type) { } @Override - public void deleteMessage(final SignedMessage.@NotNull Signature signature) { + public void sendMessage(final @NotNull Component message, final ChatType.@NotNull Bound boundChatType) { } @Override - public void sendMessageHeader(final @NotNull SignedMessage signedMessage) { + public void sendMessage(final @NotNull SignedMessage signedMessage, final ChatType.Bound boundChatType) { } @Override - public void sendMessage(final @NotNull Identified source, final @NotNull Component message, final @NotNull MessageType type) { + public void deleteMessage(final SignedMessage.@NotNull Signature signature) { } @Override - public void sendMessage(final @NotNull Identity source, final @NotNull Component message, final @NotNull MessageType type) { + public void sendMessageHeader(final @NotNull SignedMessage signedMessage) { } @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 562b8bca3..a3030c451 100644 --- a/api/src/main/java/net/kyori/adventure/audience/ForwardingAudience.java +++ b/api/src/main/java/net/kyori/adventure/audience/ForwardingAudience.java @@ -105,13 +105,8 @@ default void sendMessage(final @NotNull Component message) { } @Override - default void sendMessage(final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentified source) { - for (final Audience audience : this.audiences()) audience.sendMessage(signedMessage, source); - } - - @Override - default void sendMessage(final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentity source) { - for (final Audience audience : this.audiences()) audience.sendMessage(signedMessage, source); + default void sendMessage(final @NotNull Component message, final ChatType.@NotNull Bound boundChatType) { + for (final Audience audience : this.audiences()) audience.sendMessage(message, boundChatType); } @Override @@ -276,13 +271,8 @@ default void sendMessage(final @NotNull Component message) { } @Override - default void sendMessage(final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentified source) { - this.audience().sendMessage(signedMessage, source); - } - - @Override - default void sendMessage(final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentity source) { - this.audience().sendMessage(signedMessage, source); + default void sendMessage(final @NotNull Component message, final ChatType.@NotNull Bound boundChatType) { + this.audience().sendMessage(message, boundChatType); } @Override 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 671893789..a5cc9377c 100644 --- a/api/src/main/java/net/kyori/adventure/chat/SignedMessage.java +++ b/api/src/main/java/net/kyori/adventure/chat/SignedMessage.java @@ -27,7 +27,6 @@ import net.kyori.adventure.identity.Identified; import net.kyori.adventure.identity.Identity; import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.ComponentLike; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -40,7 +39,7 @@ * @sinceMinecraft 1.19 */ @ApiStatus.NonExtendable -public interface SignedMessage extends Identified, ComponentLike { +public interface SignedMessage extends Identified { /** * Creates a signature wrapper. @@ -58,15 +57,15 @@ public interface SignedMessage extends Identified, ComponentLike { /** * Creates a system {@link SignedMessage}. * - * @param component the message component - * @param plain the plain text message - * @return a new unsigned {@link SignedMessage} + * @param message the message + * @param unsignedContent the optional unsigned component content + * @return a new system {@link SignedMessage} * @since 4.12.0 * @sinceMinecraft 1.19 */ @Contract(value = "_, _ -> new", pure = true) - static @NotNull SignedMessage system(final @NotNull Component component, final @NotNull String plain) { - return new SignedMessageImpl(component, plain); + static @NotNull SignedMessage system(final @NotNull String message, final @Nullable Component unsignedContent) { + return new SignedMessageImpl(message, unsignedContent); } /** @@ -100,20 +99,14 @@ public interface SignedMessage extends Identified, ComponentLike { @Nullable Signature signature(); /** - * The signed component. + * The unsigned component content. * - * @return the component + * @return the component or null * @since 4.12.0 * @sinceMinecraft 1.19 */ @Contract(pure = true) - @NotNull Component message(); - - @Override - @NotNull - default Component asComponent() { - return this.message(); - } + @Nullable Component unsignedContent(); /** * The plain string message. @@ -123,7 +116,7 @@ default Component asComponent() { * @sinceMinecraft 1.19 */ @Contract(pure = true) - @NotNull String plain(); + @NotNull String message(); /** * Checks if this message is a system message. diff --git a/api/src/main/java/net/kyori/adventure/chat/SignedMessageImpl.java b/api/src/main/java/net/kyori/adventure/chat/SignedMessageImpl.java index a461cd095..c7af1befb 100644 --- a/api/src/main/java/net/kyori/adventure/chat/SignedMessageImpl.java +++ b/api/src/main/java/net/kyori/adventure/chat/SignedMessageImpl.java @@ -28,21 +28,22 @@ import net.kyori.adventure.identity.Identity; import net.kyori.adventure.text.Component; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -// Used for system messages +// Used for system messages ONLY final class SignedMessageImpl implements SignedMessage { static final SecureRandom RANDOM = new SecureRandom(); private final Instant instant; private final long salt; - private final Component message; - private final String plain; + private final String message; + private final Component unsignedContent; - SignedMessageImpl(final Component message, final String plain) { + SignedMessageImpl(final String message, final Component unsignedContent) { this.instant = Instant.now(); this.salt = RANDOM.nextLong(); this.message = message; - this.plain = plain; + this.unsignedContent = unsignedContent; } @Override @@ -61,13 +62,13 @@ public Signature signature() { } @Override - public @NotNull Component message() { - return this.message; + public @Nullable Component unsignedContent() { + return this.unsignedContent; } @Override - public @NotNull String plain() { - return this.plain; + public @NotNull String message() { + return this.message; } @Override @@ -85,7 +86,7 @@ static final class SignatureImpl implements Signature { final byte[] signature; SignatureImpl(final byte[] signature) { - this.signature =signature; + this.signature = signature; } @Override From ff45155214f4c290d9209900e8b8e474d94c361c Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Sat, 5 Nov 2022 23:42:50 -0700 Subject: [PATCH 13/21] improve some naming --- .../net/kyori/adventure/chat/ChatType.java | 24 +++++++++---------- .../kyori/adventure/chat/ChatTypeImpl.java | 10 ++++---- .../kyori/adventure/chat/SignedMessage.java | 24 +++++++++++++++++-- 3 files changed, 39 insertions(+), 19 deletions(-) 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 5de029599..3e2a25dea 100644 --- a/api/src/main/java/net/kyori/adventure/chat/ChatType.java +++ b/api/src/main/java/net/kyori/adventure/chat/ChatType.java @@ -109,30 +109,30 @@ public interface ChatType extends Examinable, Keyed { } /** - * Creates a bound chat type with a sender {@link Component}. + * Creates a bound chat type with a name {@link Component}. * - * @param sender the sender component + * @param name the name component * @return a new bound chat type * @since 4.12.0 * @sinceMinecraft 1.19 */ @Contract(value = "_ -> new", pure = true) - default @NotNull ChatType.Bound bind(@NotNull final Component sender) { - return this.bind(sender, null); + default ChatType.@NotNull Bound bind(final @NotNull Component name) { + return this.bind(name, null); } /** - * Creates a bound chat type with a sender and target {@link Component}. + * Creates a bound chat type with a name and target {@link Component}. * - * @param sender the sender component + * @param name the name component * @param target the optional target component * @return a new bound chat type * @since 4.12.0 * @sinceMinecraft 1.19 */ @Contract(value = "_, _ -> new", pure = true) - default @NotNull ChatType.Bound bind(@NotNull final Component sender, final @Nullable Component target) { - return new ChatTypeImpl.BoundImpl(this, sender, target); + default ChatType.@NotNull Bound bind(final @NotNull Component name, final @Nullable Component target) { + return new ChatTypeImpl.BoundImpl(this, name, target); } @Override @@ -159,14 +159,14 @@ interface Bound extends Examinable { @NotNull ChatType type(); /** - * Get the sender component. + * Get the name component. * - * @return the sender component + * @return the name component * @since 4.12.0 * @sinceMinecraft 1.19 */ @Contract(pure = true) - @NotNull Component sender(); + @NotNull Component name(); /** * Get the target component. @@ -183,7 +183,7 @@ interface Bound extends Examinable { default Stream examinableProperties() { return Stream.of( ExaminableProperty.of("type", this.type()), - ExaminableProperty.of("sender", this.sender()), + ExaminableProperty.of("name", this.name()), ExaminableProperty.of("target", this.target()) ); } diff --git a/api/src/main/java/net/kyori/adventure/chat/ChatTypeImpl.java b/api/src/main/java/net/kyori/adventure/chat/ChatTypeImpl.java index e352e43a2..d2d46d98f 100644 --- a/api/src/main/java/net/kyori/adventure/chat/ChatTypeImpl.java +++ b/api/src/main/java/net/kyori/adventure/chat/ChatTypeImpl.java @@ -48,12 +48,12 @@ public String toString() { static final class BoundImpl implements ChatType.Bound { private final ChatType chatType; - private final Component sender; + private final Component name; private final @Nullable Component target; - BoundImpl(final ChatType chatType, final Component sender, final @Nullable Component target) { + BoundImpl(final ChatType chatType, final Component name, final @Nullable Component target) { this.chatType = chatType; - this.sender = sender; + this.name = name; this.target = target; } @@ -63,8 +63,8 @@ static final class BoundImpl implements ChatType.Bound { } @Override - public @NotNull Component sender() { - return this.sender; + public @NotNull Component name() { + return this.name; } @Override 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 a5cc9377c..2d54093de 100644 --- a/api/src/main/java/net/kyori/adventure/chat/SignedMessage.java +++ b/api/src/main/java/net/kyori/adventure/chat/SignedMessage.java @@ -24,9 +24,12 @@ package net.kyori.adventure.chat; import java.time.Instant; +import java.util.stream.Stream; import net.kyori.adventure.identity.Identified; import net.kyori.adventure.identity.Identity; import net.kyori.adventure.text.Component; +import net.kyori.examination.Examinable; +import net.kyori.examination.ExaminableProperty; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -39,7 +42,7 @@ * @sinceMinecraft 1.19 */ @ApiStatus.NonExtendable -public interface SignedMessage extends Identified { +public interface SignedMessage extends Identified, Examinable { /** * Creates a signature wrapper. @@ -152,13 +155,24 @@ default boolean canDelete() { @Contract(pure = true) boolean canSendAsHeader(); + @Override + default @NotNull Stream examinableProperties() { + return Stream.of( + ExaminableProperty.of("timeStamp", this.timeStamp()), + ExaminableProperty.of("salt", this.salt()), + ExaminableProperty.of("signature", this.signature()), + ExaminableProperty.of("unsignedContent", this.unsignedContent()), + ExaminableProperty.of("message", this.message()) + ); + } + /** * A signature wrapper type. * * @since 4.12.0 * @sinceMinecraft 1.19 */ - interface Signature { + interface Signature extends Examinable { /** * Gets the bytes for this signature. @@ -169,5 +183,11 @@ interface Signature { */ @Contract(pure = true) byte[] bytes(); + + @Override + @NotNull + default Stream examinableProperties() { + return Stream.of(ExaminableProperty.of("bytes", this.bytes())); + } } } From 90c2cbc3691c1e2786973fea5ee424c1425305d8 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Sat, 5 Nov 2022 23:54:37 -0700 Subject: [PATCH 14/21] checkstyle fixes --- api/src/main/java/net/kyori/adventure/audience/Audience.java | 1 + .../main/java/net/kyori/adventure/audience/EmptyAudience.java | 2 -- .../java/net/kyori/adventure/audience/ForwardingAudience.java | 2 -- 3 files changed, 1 insertion(+), 4 deletions(-) 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 d31b1edce..a6695c9b2 100644 --- a/api/src/main/java/net/kyori/adventure/audience/Audience.java +++ b/api/src/main/java/net/kyori/adventure/audience/Audience.java @@ -409,6 +409,7 @@ default void sendChatMessage(final @NotNull Component component, final @NotNull * * @param message the component content * @param boundChatType the bound chat type + * @since 4.12.0 * @sinceMinecraft 1.19 */ default void sendMessage(final @NotNull Component message, final @NotNull ChatType.Bound boundChatType) { 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 182608860..16d19a8d1 100644 --- a/api/src/main/java/net/kyori/adventure/audience/EmptyAudience.java +++ b/api/src/main/java/net/kyori/adventure/audience/EmptyAudience.java @@ -31,8 +31,6 @@ 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; 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 a3030c451..d488726ff 100644 --- a/api/src/main/java/net/kyori/adventure/audience/ForwardingAudience.java +++ b/api/src/main/java/net/kyori/adventure/audience/ForwardingAudience.java @@ -35,8 +35,6 @@ 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; From cc73ff0aa7d4f92eaff811e1964185a44ffdbe28 Mon Sep 17 00:00:00 2001 From: zml Date: Sat, 12 Nov 2022 19:09:56 -0800 Subject: [PATCH 15/21] api: delete PlayerIdentified --- .../kyori/adventure/audience/Audience.java | 64 +---------- .../adventure/identity/PlayerIdentified.java | 42 ------- .../adventure/identity/PlayerIdentity.java | 103 ------------------ .../identity/PlayerIdentityImpl.java | 79 -------------- 4 files changed, 3 insertions(+), 285 deletions(-) delete mode 100644 api/src/main/java/net/kyori/adventure/identity/PlayerIdentified.java delete mode 100644 api/src/main/java/net/kyori/adventure/identity/PlayerIdentity.java delete mode 100644 api/src/main/java/net/kyori/adventure/identity/PlayerIdentityImpl.java 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 a6695c9b2..6c2c625da 100644 --- a/api/src/main/java/net/kyori/adventure/audience/Audience.java +++ b/api/src/main/java/net/kyori/adventure/audience/Audience.java @@ -33,8 +33,6 @@ 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; @@ -281,7 +279,7 @@ default void sendMessage(final @NotNull Identity source, final @NotNull Componen * @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 #sendChatMessage(SignedMessage, PlayerIdentified)} instead + * @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(SignedMessage, ChatType.Bound)} instead */ @Deprecated @ForwardingAudienceOverrideNotRequired @@ -296,7 +294,7 @@ default void sendMessage(final @NotNull Identified source, final @NotNull Compon * @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 #sendChatMessage(SignedMessage, PlayerIdentity)} instead + * @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(SignedMessage, ChatType.Bound)} instead */ @Deprecated @ForwardingAudienceOverrideNotRequired @@ -376,34 +374,6 @@ default void sendMessage(final @NotNull Identity source, final @NotNull Componen /* End: unsigned player messages */ /* Start: disguised player messages */ - /** - * Sends a chat message from the given {@link PlayerIdentified} to this {@link Audience} with the {@link ChatType#CHAT} chat type. - * - * @param component the component content - * @param source the source of the message - * @see #sendMessage(Component, ChatType.Bound) - * @since 4.12.0 - * @sinceMinecraft 1.19 - */ - @ForwardingAudienceOverrideNotRequired - default void sendChatMessage(final @NotNull Component component, final @NotNull PlayerIdentified source) { - this.sendChatMessage(component, source.identity()); - } - - /** - * Sends a chat message from the given {@link PlayerIdentity} to this {@link Audience} with the {@link ChatType#CHAT} chat type. - * - * @param component the component content - * @param source the source of the message - * @see #sendMessage(Component, ChatType.Bound) - * @since 4.12.0 - * @sinceMinecraft 1.19 - */ - @ForwardingAudienceOverrideNotRequired - default void sendChatMessage(final @NotNull Component component, final @NotNull PlayerIdentity source) { - this.sendMessage(component, ChatType.CHAT.bind(source.name())); - } - /** * Sends a message to this {@link Audience} with the provided {@link ChatType.Bound bound chat type}. * @@ -412,39 +382,11 @@ default void sendChatMessage(final @NotNull Component component, final @NotNull * @since 4.12.0 * @sinceMinecraft 1.19 */ - default void sendMessage(final @NotNull Component message, final @NotNull ChatType.Bound boundChatType) { + default void sendMessage(final @NotNull Component message, final ChatType.@NotNull Bound boundChatType) { } /* End: disguised player messages /* Start: signed player messages */ - /** - * Sends a signed player chat message from the given {@link PlayerIdentified} to this {@link Audience} with the {@link ChatType#CHAT} chat type. - * - * @param signedMessage the signed message data - * @param source the source of the message - * @see #sendMessage(SignedMessage, ChatType.Bound) - * @since 4.12.0 - * @sinceMinecraft 1.19 - */ - @ForwardingAudienceOverrideNotRequired - default void sendChatMessage(final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentified source) { - this.sendChatMessage(signedMessage, source.identity()); - } - - /** - * Sends a signed player chat message from the player identified by the provided {@link PlayerIdentity} to this {@link Audience} with the {@link ChatType#CHAT} chat type. - * - * @param signedMessage the signed message data - * @param source the identity of the source of the message - * @see #sendMessage(SignedMessage, ChatType.Bound) - * @since 4.12.0 - * @sinceMinecraft 1.19 - */ - @ForwardingAudienceOverrideNotRequired - default void sendChatMessage(final @NotNull SignedMessage signedMessage, final @NotNull PlayerIdentity source) { - this.sendMessage(signedMessage, ChatType.CHAT.bind(source.name())); - } - /** * Sends a signed player message to this {@link Audience} with the provided {@link ChatType.Bound bound chat type}. * diff --git a/api/src/main/java/net/kyori/adventure/identity/PlayerIdentified.java b/api/src/main/java/net/kyori/adventure/identity/PlayerIdentified.java deleted file mode 100644 index f5aea6747..000000000 --- a/api/src/main/java/net/kyori/adventure/identity/PlayerIdentified.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * This file is part of adventure, licensed under the MIT License. - * - * Copyright (c) 2017-2022 KyoriPowered - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package net.kyori.adventure.identity; - -import org.jetbrains.annotations.NotNull; - -/** - * Something that can be identified with a {@link PlayerIdentity}. - * - * @since 4.12.0 - */ -public interface PlayerIdentified extends Identified { - /** - * Gets the player identity. - * - * @return the player identity - * @since 4.12.0 - */ - @Override - @NotNull PlayerIdentity identity(); -} diff --git a/api/src/main/java/net/kyori/adventure/identity/PlayerIdentity.java b/api/src/main/java/net/kyori/adventure/identity/PlayerIdentity.java deleted file mode 100644 index 7f23a82fa..000000000 --- a/api/src/main/java/net/kyori/adventure/identity/PlayerIdentity.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * This file is part of adventure, licensed under the MIT License. - * - * Copyright (c) 2017-2022 KyoriPowered - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package net.kyori.adventure.identity; - -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; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * An identity for a specific player. - * - * @since 4.12.0 - */ -public interface PlayerIdentity extends Examinable, Identity { - /** - * 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. - * - * @param uuid the uuid - * @param name the name - * @return the player identity - * @since 4.12.0 - */ - static @NotNull PlayerIdentity playerIdentity(final @NotNull UUID uuid, final @NotNull Component name) { - return playerIdentity(uuid, name, null); - } - - /** - * Creates a new player identity. - * - * @param uuid the uuid - * @param name the name - * @param teamName the optional team name - * @return the player identity - * @since 4.12.0 - */ - static @NotNull PlayerIdentity playerIdentity(final @NotNull UUID uuid, final @NotNull Component name, final @Nullable Component teamName) { - return new PlayerIdentityImpl(Objects.requireNonNull(uuid, "uuid"), Objects.requireNonNull(name, "name"), teamName); - } - - /** - * The name of the player. - * - * @return the name - * @since 4.12.0 - */ - @Contract(pure = true) - @NotNull Component name(); - - /** - * The team name of the player. - * - * @return the team name - * @since 4.12.0 - */ - @Contract(pure = true) - @Nullable Component teamName(); - - @Override - default @NotNull Stream examinableProperties() { - return Stream.of( - ExaminableProperty.of("uuid", this.uuid()), - ExaminableProperty.of("name", this.name()), - ExaminableProperty.of("teamName", this.teamName()) - ); - } -} diff --git a/api/src/main/java/net/kyori/adventure/identity/PlayerIdentityImpl.java b/api/src/main/java/net/kyori/adventure/identity/PlayerIdentityImpl.java deleted file mode 100644 index fef037d4e..000000000 --- a/api/src/main/java/net/kyori/adventure/identity/PlayerIdentityImpl.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * This file is part of adventure, licensed under the MIT License. - * - * Copyright (c) 2017-2022 KyoriPowered - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package net.kyori.adventure.identity; - -import java.util.Objects; -import java.util.UUID; -import net.kyori.adventure.internal.Internals; -import net.kyori.adventure.text.Component; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -final class PlayerIdentityImpl implements PlayerIdentity { - private final UUID uuid; - private final Component name; - private final @Nullable Component teamName; - - PlayerIdentityImpl(final @NotNull UUID uuid, final @NotNull Component name, final @Nullable Component teamName) { - this.uuid = uuid; - this.name = name; - this.teamName = teamName; - } - - @Override - public @NotNull UUID uuid() { - return this.uuid; - } - - @Override - public @NotNull Component name() { - return this.name; - } - - @Override - public @Nullable Component teamName() { - return this.teamName; - } - - @Override - public boolean equals(final @Nullable Object other) { - if (this == other) return true; - if (!(other instanceof PlayerIdentity)) return false; - final PlayerIdentity that = (PlayerIdentity) other; - return this.uuid == that.uuid() && this.name == that.name() && this.teamName == that.teamName(); - } - - @Override - public int hashCode() { - int result = this.uuid.hashCode(); - result = 31 * result + this.name.hashCode(); - result = 31 * result + Objects.hashCode(this.teamName); - return result; - } - - @Override - public String toString() { - return Internals.toString(this); - } -} From da0f99b42dc115e84ec529043ca75ad6cfc793f0 Mon Sep 17 00:00:00 2001 From: zml Date: Tue, 22 Nov 2022 12:12:19 -0800 Subject: [PATCH 16/21] chore(api): Fix style and fill in deprecated annotations --- .../main/java/net/kyori/adventure/audience/Audience.java | 3 --- .../java/net/kyori/adventure/audience/EmptyAudience.java | 2 ++ .../net/kyori/adventure/audience/ForwardingAudience.java | 8 ++++++-- api/src/main/java/net/kyori/adventure/chat/ChatType.java | 3 +-- .../main/java/net/kyori/adventure/chat/SignedMessage.java | 3 +-- 5 files changed, 10 insertions(+), 9 deletions(-) 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 6c2c625da..d1c3eede0 100644 --- a/api/src/main/java/net/kyori/adventure/audience/Audience.java +++ b/api/src/main/java/net/kyori/adventure/audience/Audience.java @@ -426,9 +426,6 @@ default void deleteMessage(final @NotNull SignedMessage signedMessage) { default void deleteMessage(final SignedMessage.@NotNull Signature signature) { } - // todo, the delete message packet also supports an int identifier that has something - // to do with the message chain, unsure if that should be exposed - /** * Sends the signed message's header to this audience. * 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 16d19a8d1..7515b3dbc 100644 --- a/api/src/main/java/net/kyori/adventure/audience/EmptyAudience.java +++ b/api/src/main/java/net/kyori/adventure/audience/EmptyAudience.java @@ -77,10 +77,12 @@ public void sendMessage(final @NotNull Component message) { } @Override + @Deprecated public void sendMessage(final @NotNull Identified source, final @NotNull Component message, final @NotNull MessageType type) { } @Override + @Deprecated public void sendMessage(final @NotNull Identity source, final @NotNull Component message, final @NotNull MessageType type) { } 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 d488726ff..dd49b86ac 100644 --- a/api/src/main/java/net/kyori/adventure/audience/ForwardingAudience.java +++ b/api/src/main/java/net/kyori/adventure/audience/ForwardingAudience.java @@ -123,12 +123,14 @@ default void sendMessageHeader(final @NotNull SignedMessage signedMessage) { } @Override - default void sendMessage(@NotNull Identified source, @NotNull Component message, @NotNull MessageType type) { + @Deprecated + default void sendMessage(final @NotNull Identified source, final @NotNull Component message, final @NotNull MessageType type) { for (final Audience audience : this.audiences()) audience.sendMessage(source, message, type); } @Override - default void sendMessage(@NotNull Identity source, @NotNull Component message, @NotNull MessageType type) { + @Deprecated + default void sendMessage(final @NotNull Identity source, final @NotNull Component message, final @NotNull MessageType type) { for (final Audience audience : this.audiences()) audience.sendMessage(source, message, type); } @@ -289,11 +291,13 @@ default void sendMessageHeader(final @NotNull SignedMessage signedMessage) { } @Override + @Deprecated default void sendMessage(final @NotNull Identified source, final @NotNull Component message, final @NotNull MessageType type) { this.audience().sendMessage(source, message, type); } @Override + @Deprecated default void sendMessage(final @NotNull Identity 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 3e2a25dea..5db37733c 100644 --- a/api/src/main/java/net/kyori/adventure/chat/ChatType.java +++ b/api/src/main/java/net/kyori/adventure/chat/ChatType.java @@ -179,8 +179,7 @@ interface Bound extends Examinable { @Nullable Component target(); @Override - @NotNull - default Stream examinableProperties() { + default @NotNull Stream examinableProperties() { return Stream.of( ExaminableProperty.of("type", this.type()), ExaminableProperty.of("name", this.name()), 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 2d54093de..978d7f6fb 100644 --- a/api/src/main/java/net/kyori/adventure/chat/SignedMessage.java +++ b/api/src/main/java/net/kyori/adventure/chat/SignedMessage.java @@ -185,8 +185,7 @@ interface Signature extends Examinable { byte[] bytes(); @Override - @NotNull - default Stream examinableProperties() { + default @NotNull Stream examinableProperties() { return Stream.of(ExaminableProperty.of("bytes", this.bytes())); } } From 802bd28a2fdcc9ccba4e57f50876b0efce5dce74 Mon Sep 17 00:00:00 2001 From: zml Date: Tue, 22 Nov 2022 14:27:02 -0800 Subject: [PATCH 17/21] api: Remove message headers 1.19.3 does not support these --- .../kyori/adventure/audience/Audience.java | 21 +++---------------- .../adventure/audience/EmptyAudience.java | 6 +----- .../audience/ForwardingAudience.java | 14 ++----------- .../kyori/adventure/chat/SignedMessage.java | 10 --------- .../adventure/chat/SignedMessageImpl.java | 5 ----- 5 files changed, 6 insertions(+), 50 deletions(-) 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 d1c3eede0..52b3ba861 100644 --- a/api/src/main/java/net/kyori/adventure/audience/Audience.java +++ b/api/src/main/java/net/kyori/adventure/audience/Audience.java @@ -349,9 +349,7 @@ default void sendMessage(final @NotNull Identity source, final @NotNull Componen @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") @Deprecated default void sendMessage(final @NotNull Identified source, final @NotNull Component message, final @NotNull MessageType type) { - if (source.identity() == Identity.nil()) { - this.sendMessage(message); - } + this.sendMessage(message); } /** @@ -367,9 +365,7 @@ default void sendMessage(final @NotNull Identified source, final @NotNull Compon @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") @Deprecated default void sendMessage(final @NotNull Identity source, final @NotNull Component message, final @NotNull MessageType type) { - if (source == Identity.nil()) { - this.sendMessage(message); - } + this.sendMessage(message); } /* End: unsigned player messages */ @@ -395,7 +391,7 @@ default void sendMessage(final @NotNull Component message, final ChatType.@NotNu * @since 4.12.0 * @sinceMinecraft 1.19 */ - default void sendMessage(final @NotNull SignedMessage signedMessage, final ChatType.Bound boundChatType) { + default void sendMessage(final @NotNull SignedMessage signedMessage, final ChatType.@NotNull Bound boundChatType) { if (signedMessage.isSystem()) { this.sendMessage(signedMessage.unsignedContent() != null ? signedMessage.unsignedContent() : Component.text(signedMessage.message()), boundChatType); } @@ -425,17 +421,6 @@ default void deleteMessage(final @NotNull SignedMessage signedMessage) { */ default void deleteMessage(final SignedMessage.@NotNull Signature signature) { } - - /** - * Sends the signed message's header to this audience. - * - * @param signedMessage the signed message - * @see SignedMessage#canSendAsHeader() - * @since 4.12.0 - * @sinceMinecraft 1.19 - */ - default void sendMessageHeader(final @NotNull SignedMessage signedMessage) { - } /* End: signed player messages */ /** 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 7515b3dbc..921e8fa46 100644 --- a/api/src/main/java/net/kyori/adventure/audience/EmptyAudience.java +++ b/api/src/main/java/net/kyori/adventure/audience/EmptyAudience.java @@ -91,17 +91,13 @@ public void sendMessage(final @NotNull Component message, final ChatType.@NotNul } @Override - public void sendMessage(final @NotNull SignedMessage signedMessage, final ChatType.Bound boundChatType) { + public void sendMessage(final @NotNull SignedMessage signedMessage, final ChatType.@NotNull Bound boundChatType) { } @Override public void deleteMessage(final SignedMessage.@NotNull Signature signature) { } - @Override - public void sendMessageHeader(final @NotNull SignedMessage signedMessage) { - } - @Override public void sendActionBar(final @NotNull ComponentLike message) { } 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 dd49b86ac..a728ebc1d 100644 --- a/api/src/main/java/net/kyori/adventure/audience/ForwardingAudience.java +++ b/api/src/main/java/net/kyori/adventure/audience/ForwardingAudience.java @@ -108,7 +108,7 @@ default void sendMessage(final @NotNull Component message, final ChatType.@NotNu } @Override - default void sendMessage(final @NotNull SignedMessage signedMessage, final ChatType.Bound boundChatType) { + default void sendMessage(final @NotNull SignedMessage signedMessage, final ChatType.@NotNull Bound boundChatType) { for (final Audience audience : this.audiences()) audience.sendMessage(signedMessage, boundChatType); } @@ -117,11 +117,6 @@ default void deleteMessage(final SignedMessage.@NotNull Signature signature) { for (final Audience audience : this.audiences()) audience.deleteMessage(signature); } - @Override - default void sendMessageHeader(final @NotNull SignedMessage signedMessage) { - for (final Audience audience : this.audiences()) audience.sendMessageHeader(signedMessage); - } - @Override @Deprecated default void sendMessage(final @NotNull Identified source, final @NotNull Component message, final @NotNull MessageType type) { @@ -276,7 +271,7 @@ default void sendMessage(final @NotNull Component message, final ChatType.@NotNu } @Override - default void sendMessage(final @NotNull SignedMessage signedMessage, final ChatType.Bound boundChatType) { + default void sendMessage(final @NotNull SignedMessage signedMessage, final ChatType.@NotNull Bound boundChatType) { this.audience().sendMessage(signedMessage, boundChatType); } @@ -285,11 +280,6 @@ default void deleteMessage(final SignedMessage.@NotNull Signature signature) { this.audience().deleteMessage(signature); } - @Override - default void sendMessageHeader(final @NotNull SignedMessage signedMessage) { - this.audience().sendMessageHeader(signedMessage); - } - @Override @Deprecated default void sendMessage(final @NotNull Identified source, final @NotNull Component message, final @NotNull MessageType type) { 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 978d7f6fb..d44600000 100644 --- a/api/src/main/java/net/kyori/adventure/chat/SignedMessage.java +++ b/api/src/main/java/net/kyori/adventure/chat/SignedMessage.java @@ -145,16 +145,6 @@ default boolean canDelete() { return this.signature() != null; } - /** - * Checks if this message can be sent as a header via {@link net.kyori.adventure.audience.Audience#sendMessageHeader(SignedMessage)}. - * - * @return true if supports sending as a header - * @since 4.12.0 - * @sinceMinecraft 1.19 - */ - @Contract(pure = true) - boolean canSendAsHeader(); - @Override default @NotNull Stream examinableProperties() { return Stream.of( diff --git a/api/src/main/java/net/kyori/adventure/chat/SignedMessageImpl.java b/api/src/main/java/net/kyori/adventure/chat/SignedMessageImpl.java index c7af1befb..1869175a9 100644 --- a/api/src/main/java/net/kyori/adventure/chat/SignedMessageImpl.java +++ b/api/src/main/java/net/kyori/adventure/chat/SignedMessageImpl.java @@ -71,11 +71,6 @@ public Signature signature() { return this.message; } - @Override - public boolean canSendAsHeader() { - return false; - } - @Override public @NotNull Identity identity() { return Identity.nil(); From e00ef14ec5055a817cd37e44ca20c12dc7afe0d7 Mon Sep 17 00:00:00 2001 From: zml Date: Tue, 22 Nov 2022 21:00:55 -0800 Subject: [PATCH 18/21] api: SignedMessage --- api/src/main/java/net/kyori/adventure/chat/SignedMessage.java | 1 + 1 file changed, 1 insertion(+) 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 d44600000..38cf24158 100644 --- a/api/src/main/java/net/kyori/adventure/chat/SignedMessage.java +++ b/api/src/main/java/net/kyori/adventure/chat/SignedMessage.java @@ -162,6 +162,7 @@ default boolean canDelete() { * @since 4.12.0 * @sinceMinecraft 1.19 */ + @ApiStatus.NonExtendable interface Signature extends Examinable { /** From ad9937881b44fcd1b0054037e6b4591e3ded9a89 Mon Sep 17 00:00:00 2001 From: zml Date: Sat, 26 Nov 2022 17:13:17 -0800 Subject: [PATCH 19/21] api: Tidy up overloads of methods on new API --- .../kyori/adventure/audience/Audience.java | 29 ++++++++++++++++--- .../net/kyori/adventure/chat/ChatType.java | 14 +++++---- .../kyori/adventure/chat/SignedMessage.java | 5 ++-- 3 files changed, 36 insertions(+), 12 deletions(-) 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 52b3ba861..bce9fc4a4 100644 --- a/api/src/main/java/net/kyori/adventure/audience/Audience.java +++ b/api/src/main/java/net/kyori/adventure/audience/Audience.java @@ -201,7 +201,9 @@ default void sendMessage(final @NotNull ComponentLike message) { * @see #sendMessage(Identity, Component) * @since 4.1.0 */ + @SuppressWarnings("deprecation") default void sendMessage(final @NotNull Component message) { + this.sendMessage(message, MessageType.SYSTEM); } /** @@ -219,7 +221,7 @@ default void sendMessage(final @NotNull Component message) { @Deprecated @ForwardingAudienceOverrideNotRequired default void sendMessage(final @NotNull ComponentLike message, final @NotNull MessageType type) { - this.sendMessage(message); + this.sendMessage(message.asComponent(), type); } /** @@ -237,7 +239,7 @@ default void sendMessage(final @NotNull ComponentLike message, final @NotNull Me @Deprecated @ForwardingAudienceOverrideNotRequired default void sendMessage(final @NotNull Component message, final @NotNull MessageType type) { - this.sendMessage(message); + this.sendMessage(Identity.nil(), message, type); } /* End: system messages */ @@ -365,7 +367,7 @@ default void sendMessage(final @NotNull Identified source, final @NotNull Compon @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") @Deprecated default void sendMessage(final @NotNull Identity source, final @NotNull Component message, final @NotNull MessageType type) { - this.sendMessage(message); + // implementation required } /* End: unsigned player messages */ @@ -378,7 +380,22 @@ default void sendMessage(final @NotNull Identity source, final @NotNull Componen * @since 4.12.0 * @sinceMinecraft 1.19 */ + @SuppressWarnings("deprecation") default void sendMessage(final @NotNull Component message, final ChatType.@NotNull Bound boundChatType) { + this.sendMessage(message, MessageType.CHAT); + } + + /** + * Sends a message to this {@link Audience} with the provided {@link ChatType.Bound bound chat type}. + * + * @param message the component content + * @param boundChatType the bound chat type + * @since 4.12.0 + * @sinceMinecraft 1.19 + */ + @ForwardingAudienceOverrideNotRequired + default void sendMessage(final @NotNull ComponentLike message, final ChatType.@NotNull Bound boundChatType) { + this.sendMessage(message.asComponent(), boundChatType); } /* End: disguised player messages @@ -391,9 +408,13 @@ default void sendMessage(final @NotNull Component message, final ChatType.@NotNu * @since 4.12.0 * @sinceMinecraft 1.19 */ + @SuppressWarnings("deprecation") default void sendMessage(final @NotNull SignedMessage signedMessage, final ChatType.@NotNull Bound boundChatType) { + final Component content = signedMessage.unsignedContent() != null ? signedMessage.unsignedContent() : Component.text(signedMessage.message()); if (signedMessage.isSystem()) { - this.sendMessage(signedMessage.unsignedContent() != null ? signedMessage.unsignedContent() : Component.text(signedMessage.message()), boundChatType); + this.sendMessage(content); + } else { + this.sendMessage(signedMessage.identity(), content, MessageType.CHAT); } } 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 5db37733c..8e5af1824 100644 --- a/api/src/main/java/net/kyori/adventure/chat/ChatType.java +++ b/api/src/main/java/net/kyori/adventure/chat/ChatType.java @@ -23,17 +23,19 @@ */ package net.kyori.adventure.chat; -import java.util.Objects; import java.util.stream.Stream; import net.kyori.adventure.key.Key; import net.kyori.adventure.key.Keyed; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.ComponentLike; import net.kyori.examination.Examinable; import net.kyori.examination.ExaminableProperty; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import static java.util.Objects.requireNonNull; + /** * A type of chat. * @@ -104,8 +106,8 @@ public interface ChatType extends Examinable, Keyed { * @return the chat type * @since 4.12.0 */ - static @NotNull ChatType chatType(final @NotNull Key key) { - return new ChatTypeImpl(Objects.requireNonNull(key, "key")); + static @NotNull ChatType chatType(final @NotNull Keyed key) { + return key instanceof ChatType ? (ChatType) key : new ChatTypeImpl(requireNonNull(key, "key").key()); } /** @@ -117,7 +119,7 @@ public interface ChatType extends Examinable, Keyed { * @sinceMinecraft 1.19 */ @Contract(value = "_ -> new", pure = true) - default ChatType.@NotNull Bound bind(final @NotNull Component name) { + default ChatType.@NotNull Bound bind(final @NotNull ComponentLike name) { return this.bind(name, null); } @@ -131,8 +133,8 @@ public interface ChatType extends Examinable, Keyed { * @sinceMinecraft 1.19 */ @Contract(value = "_, _ -> new", pure = true) - default ChatType.@NotNull Bound bind(final @NotNull Component name, final @Nullable Component target) { - return new ChatTypeImpl.BoundImpl(this, name, target); + default ChatType.@NotNull Bound bind(final @NotNull ComponentLike name, final @Nullable ComponentLike target) { + return new ChatTypeImpl.BoundImpl(this, requireNonNull(name.asComponent(), "name"), ComponentLike.unbox(target)); } @Override 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 38cf24158..98f0671fe 100644 --- a/api/src/main/java/net/kyori/adventure/chat/SignedMessage.java +++ b/api/src/main/java/net/kyori/adventure/chat/SignedMessage.java @@ -28,6 +28,7 @@ import net.kyori.adventure.identity.Identified; import net.kyori.adventure.identity.Identity; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.ComponentLike; import net.kyori.examination.Examinable; import net.kyori.examination.ExaminableProperty; import org.jetbrains.annotations.ApiStatus; @@ -67,8 +68,8 @@ public interface SignedMessage extends Identified, Examinable { * @sinceMinecraft 1.19 */ @Contract(value = "_, _ -> new", pure = true) - static @NotNull SignedMessage system(final @NotNull String message, final @Nullable Component unsignedContent) { - return new SignedMessageImpl(message, unsignedContent); + static @NotNull SignedMessage system(final @NotNull String message, final @Nullable ComponentLike unsignedContent) { + return new SignedMessageImpl(message, ComponentLike.unbox(unsignedContent)); } /** From 94bd9c90cc284cdafa7fd581b5e1a6f67e8002d9 Mon Sep 17 00:00:00 2001 From: zml Date: Sat, 26 Nov 2022 17:15:07 -0800 Subject: [PATCH 20/21] api: one missed method --- api/src/main/java/net/kyori/adventure/audience/Audience.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 bce9fc4a4..7546fdbcd 100644 --- a/api/src/main/java/net/kyori/adventure/audience/Audience.java +++ b/api/src/main/java/net/kyori/adventure/audience/Audience.java @@ -351,7 +351,7 @@ default void sendMessage(final @NotNull Identity source, final @NotNull Componen @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") @Deprecated default void sendMessage(final @NotNull Identified source, final @NotNull Component message, final @NotNull MessageType type) { - this.sendMessage(message); + this.sendMessage(source.identity(), message, type); } /** From 729c9cd65ca3951997a895467811c3bf19a5f773 Mon Sep 17 00:00:00 2001 From: zml Date: Sun, 27 Nov 2022 09:41:53 -0800 Subject: [PATCH 21/21] api: timeStamp -> timestamp --- api/src/main/java/net/kyori/adventure/chat/SignedMessage.java | 4 ++-- .../main/java/net/kyori/adventure/chat/SignedMessageImpl.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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 98f0671fe..3b1e216d0 100644 --- a/api/src/main/java/net/kyori/adventure/chat/SignedMessage.java +++ b/api/src/main/java/net/kyori/adventure/chat/SignedMessage.java @@ -80,7 +80,7 @@ public interface SignedMessage extends Identified, Examinable { * @sinceMinecraft 1.19 */ @Contract(pure = true) - @NotNull Instant timeStamp(); + @NotNull Instant timestamp(); /** * The salt. @@ -149,7 +149,7 @@ default boolean canDelete() { @Override default @NotNull Stream examinableProperties() { return Stream.of( - ExaminableProperty.of("timeStamp", this.timeStamp()), + ExaminableProperty.of("timestamp", this.timestamp()), ExaminableProperty.of("salt", this.salt()), ExaminableProperty.of("signature", this.signature()), ExaminableProperty.of("unsignedContent", this.unsignedContent()), diff --git a/api/src/main/java/net/kyori/adventure/chat/SignedMessageImpl.java b/api/src/main/java/net/kyori/adventure/chat/SignedMessageImpl.java index 1869175a9..0e75f0edb 100644 --- a/api/src/main/java/net/kyori/adventure/chat/SignedMessageImpl.java +++ b/api/src/main/java/net/kyori/adventure/chat/SignedMessageImpl.java @@ -47,7 +47,7 @@ final class SignedMessageImpl implements SignedMessage { } @Override - public @NotNull Instant timeStamp() { + public @NotNull Instant timestamp() { return this.instant; }