From 9c4bb0df0e22f6ec35d2dc7cf455ec715e2ca4a9 Mon Sep 17 00:00:00 2001 From: Yannick Lamprecht <1420893+yannicklamprecht@users.noreply.github.com> Date: Sun, 3 Mar 2024 19:59:22 +0100 Subject: [PATCH] add rich message component support to configuration (#10225) --- patches/api/0006-Adventure.patch | 108 +++++++++++++++++- ...low-plugins-to-use-SLF4J-for-logging.patch | 4 +- 2 files changed, 108 insertions(+), 4 deletions(-) diff --git a/patches/api/0006-Adventure.patch b/patches/api/0006-Adventure.patch index 7689102526..6e3f2c5ebd 100644 --- a/patches/api/0006-Adventure.patch +++ b/patches/api/0006-Adventure.patch @@ -5,16 +5,17 @@ Subject: [PATCH] Adventure Co-authored-by: zml Co-authored-by: Jake Potrebic +Co-authored-by: Yannick Lamprecht diff --git a/build.gradle.kts b/build.gradle.kts -index b3df8cf8d32a4cc99a3a3950f146cdab65826e1b..b577114c2b89fe2053123d1a542d37dff7fa8d5a 100644 +index b3df8cf8d32a4cc99a3a3950f146cdab65826e1b..9011451c6a60db08dcc255a84470f8ce92f7b2a4 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -11,12 +11,28 @@ java { val annotationsVersion = "24.0.1" val bungeeCordChatVersion = "1.20-R0.2" -+val adventureVersion = "4.15.0" ++val adventureVersion = "4.16.0" +val apiAndDocs: Configuration by configurations.creating { + attributes { + attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION)) @@ -2054,6 +2055,109 @@ index fcc34b640265f4dccb46b9f09466ab8e1d96043e..5c813ac024f675951159a59d88d8baa0 + } + // Paper end } +diff --git a/src/main/java/org/bukkit/configuration/ConfigurationSection.java b/src/main/java/org/bukkit/configuration/ConfigurationSection.java +index b6b00af08f12f838411845e4f4e29e62826dfc7f..d168b1e58b4b4ad00466fab60232d516551668e0 100644 +--- a/src/main/java/org/bukkit/configuration/ConfigurationSection.java ++++ b/src/main/java/org/bukkit/configuration/ConfigurationSection.java +@@ -1058,4 +1058,98 @@ public interface ConfigurationSection { + * one line. + */ + public void setInlineComments(@NotNull String path, @Nullable List comments); ++ ++ // Paper start - add rich message component support to configuration ++ /** ++ * Gets the requested MiniMessage formatted String as Component by path. ++ *

++ * If the Component does not exist but a default value has been specified, ++ * this will return the default value. If the Component does not exist and no ++ * default value was specified, this will return null. ++ * ++ * @param path Path of the Component to get. ++ * @return Requested Component. ++ */ ++ default net.kyori.adventure.text.@Nullable Component getRichMessage(final @NotNull String path) { ++ return this.getRichMessage(path, null); ++ } ++ ++ /** ++ * Gets the requested MiniMessage formatted String as Component by path. ++ *

++ * If the Component does not exist but a default value has been specified, ++ * this will return the default value. If the Component does not exist and no ++ * default value was specified, this will return null. ++ * ++ * @param path Path of the Component to get. ++ * @param fallback component that will be used as fallback ++ * @return Requested Component. ++ */ ++ @Contract("_, !null -> !null") ++ default net.kyori.adventure.text.@Nullable Component getRichMessage(final @NotNull String path, final net.kyori.adventure.text.@Nullable Component fallback) { ++ return this.getComponent(path, net.kyori.adventure.text.minimessage.MiniMessage.miniMessage(), fallback); ++ } ++ ++ /** ++ * Sets the specified path to the given value. ++ *

++ * If value is null, the entry will be removed. Any existing entry will be ++ * replaced, regardless of what the new value is. ++ * ++ * @param path Path of the object to set. ++ * @param value New value to set the path to. ++ */ ++ default void setRichMessage(final @NotNull String path, final net.kyori.adventure.text.@Nullable Component value) { ++ this.setComponent(path, net.kyori.adventure.text.minimessage.MiniMessage.miniMessage(), value); ++ } ++ ++ /** ++ * Gets the requested formatted String as Component by path deserialized by the ComponentDecoder. ++ *

++ * If the Component does not exist but a default value has been specified, ++ * this will return the default value. If the Component does not exist and no ++ * default value was specified, this will return null. ++ * ++ * @param path Path of the Component to get. ++ * @param decoder ComponentDecoder instance used for deserialization ++ * @return Requested Component. ++ */ ++ default @Nullable C getComponent(final @NotNull String path, final net.kyori.adventure.text.serializer.@NotNull ComponentDecoder decoder) { ++ return this.getComponent(path, decoder, null); ++ } ++ ++ /** ++ * Gets the requested formatted String as Component by path deserialized by the ComponentDecoder. ++ *

++ * If the Component does not exist but a default value has been specified, ++ * this will return the default value. If the Component does not exist and no ++ * default value was specified, this will return null. ++ * ++ * @param path Path of the Component to get. ++ * @param decoder ComponentDecoder instance used for deserialization ++ * @param fallback component that will be used as fallback ++ * @return Requested Component. ++ */ ++ @Contract("_, _, !null -> !null") ++ default @Nullable C getComponent(final @NotNull String path, final net.kyori.adventure.text.serializer.@NotNull ComponentDecoder decoder, final @Nullable C fallback) { ++ java.util.Objects.requireNonNull(decoder, "decoder"); ++ final String value = this.getString(path); ++ return decoder.deserializeOr(value, fallback); ++ } ++ ++ /** ++ * Sets the specified path to the given value. ++ *

++ * If value is null, the entry will be removed. Any existing entry will be ++ * replaced, regardless of what the new value is. ++ * ++ * @param path Path of the object to set. ++ * @param encoder the encoder used to transform the value ++ * @param value New value to set the path to. ++ */ ++ default void setComponent(final @NotNull String path, final net.kyori.adventure.text.serializer.@NotNull ComponentEncoder encoder, final @Nullable C value) { ++ java.util.Objects.requireNonNull(encoder, "encoder"); ++ this.set(path, encoder.serializeOrNull(value)); ++ } ++ // Paper end - add rich message component support to configuration + } diff --git a/src/main/java/org/bukkit/conversations/Conversable.java b/src/main/java/org/bukkit/conversations/Conversable.java index b7d8dd30360a38dbdc7bbce40c8e6ced7261f833..0817f2395c2b18828565435568ce651f5ba99a99 100644 --- a/src/main/java/org/bukkit/conversations/Conversable.java diff --git a/patches/api/0070-Allow-plugins-to-use-SLF4J-for-logging.patch b/patches/api/0070-Allow-plugins-to-use-SLF4J-for-logging.patch index 89ff44d81e..1cddb59cda 100644 --- a/patches/api/0070-Allow-plugins-to-use-SLF4J-for-logging.patch +++ b/patches/api/0070-Allow-plugins-to-use-SLF4J-for-logging.patch @@ -14,13 +14,13 @@ it without having to shade it in the plugin and going through several layers of logging abstraction. diff --git a/build.gradle.kts b/build.gradle.kts -index f9ff7e3692d448e2a1e38d0aa26c2d934442e247..50dd795c67557c7d2668068af0bba87a1ec8dc43 100644 +index ddc89dfd6911d85aab7c37fe3ca54eb1b80f99d6..66bcd8f9a8fce8f920a0f1dd7ae0a2937da68e80 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -12,6 +12,8 @@ java { val annotationsVersion = "24.0.1" val bungeeCordChatVersion = "1.20-R0.2" - val adventureVersion = "4.15.0" + val adventureVersion = "4.16.0" +val slf4jVersion = "2.0.9" +val log4jVersion = "2.17.1" val apiAndDocs: Configuration by configurations.creating {