mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-06 07:02:18 -07:00
add rich message component support to configuration (#10225)
This commit is contained in:
@@ -5,6 +5,7 @@ Subject: [PATCH] Adventure
|
|||||||
|
|
||||||
Co-authored-by: zml <zml@stellardrift.ca>
|
Co-authored-by: zml <zml@stellardrift.ca>
|
||||||
Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
|
Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
|
||||||
|
Co-authored-by: Yannick Lamprecht <yannicklamprecht@live.de>
|
||||||
|
|
||||||
diff --git a/build.gradle.kts b/build.gradle.kts
|
diff --git a/build.gradle.kts b/build.gradle.kts
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
@@ -14,7 +15,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
|
|
||||||
val annotationsVersion = "24.0.1"
|
val annotationsVersion = "24.0.1"
|
||||||
val bungeeCordChatVersion = "1.20-R0.2"
|
val bungeeCordChatVersion = "1.20-R0.2"
|
||||||
+val adventureVersion = "4.15.0"
|
+val adventureVersion = "4.16.0"
|
||||||
+val apiAndDocs: Configuration by configurations.creating {
|
+val apiAndDocs: Configuration by configurations.creating {
|
||||||
+ attributes {
|
+ attributes {
|
||||||
+ attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION))
|
+ attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION))
|
||||||
@@ -2054,6 +2055,109 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+ }
|
+ }
|
||||||
+ // Paper end
|
+ // Paper end
|
||||||
}
|
}
|
||||||
|
diff --git a/src/main/java/org/bukkit/configuration/ConfigurationSection.java b/src/main/java/org/bukkit/configuration/ConfigurationSection.java
|
||||||
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
|
--- a/src/main/java/org/bukkit/configuration/ConfigurationSection.java
|
||||||
|
+++ b/src/main/java/org/bukkit/configuration/ConfigurationSection.java
|
||||||
|
@@ -0,0 +0,0 @@ public interface ConfigurationSection {
|
||||||
|
* one line.
|
||||||
|
*/
|
||||||
|
public void setInlineComments(@NotNull String path, @Nullable List<String> comments);
|
||||||
|
+
|
||||||
|
+ // Paper start - add rich message component support to configuration
|
||||||
|
+ /**
|
||||||
|
+ * Gets the requested MiniMessage formatted String as Component by path.
|
||||||
|
+ * <p>
|
||||||
|
+ * 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.
|
||||||
|
+ * <p>
|
||||||
|
+ * 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.
|
||||||
|
+ * <p>
|
||||||
|
+ * 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.
|
||||||
|
+ * <p>
|
||||||
|
+ * 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 <C extends net.kyori.adventure.text.Component> @Nullable C getComponent(final @NotNull String path, final net.kyori.adventure.text.serializer.@NotNull ComponentDecoder<? super String, C> decoder) {
|
||||||
|
+ return this.getComponent(path, decoder, null);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ /**
|
||||||
|
+ * Gets the requested formatted String as Component by path deserialized by the ComponentDecoder.
|
||||||
|
+ * <p>
|
||||||
|
+ * 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 <C extends net.kyori.adventure.text.Component> @Nullable C getComponent(final @NotNull String path, final net.kyori.adventure.text.serializer.@NotNull ComponentDecoder<? super String, C> 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.
|
||||||
|
+ * <p>
|
||||||
|
+ * 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 <C extends net.kyori.adventure.text.Component> void setComponent(final @NotNull String path, final net.kyori.adventure.text.serializer.@NotNull ComponentEncoder<C, String> 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
|
diff --git a/src/main/java/org/bukkit/conversations/Conversable.java b/src/main/java/org/bukkit/conversations/Conversable.java
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
--- a/src/main/java/org/bukkit/conversations/Conversable.java
|
--- a/src/main/java/org/bukkit/conversations/Conversable.java
|
||||||
|
@@ -20,7 +20,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
@@ -0,0 +0,0 @@ java {
|
@@ -0,0 +0,0 @@ java {
|
||||||
val annotationsVersion = "24.0.1"
|
val annotationsVersion = "24.0.1"
|
||||||
val bungeeCordChatVersion = "1.20-R0.2"
|
val bungeeCordChatVersion = "1.20-R0.2"
|
||||||
val adventureVersion = "4.15.0"
|
val adventureVersion = "4.16.0"
|
||||||
+val slf4jVersion = "2.0.9"
|
+val slf4jVersion = "2.0.9"
|
||||||
+val log4jVersion = "2.17.1"
|
+val log4jVersion = "2.17.1"
|
||||||
val apiAndDocs: Configuration by configurations.creating {
|
val apiAndDocs: Configuration by configurations.creating {
|
||||||
|
Reference in New Issue
Block a user