From e5bc9e186e6e9bae6302ba301ad0914f3e62fbf4 Mon Sep 17 00:00:00 2001 From: Snabeldier <79211348+Snabeldier@users.noreply.github.com> Date: Mon, 6 Jan 2025 17:56:34 +0100 Subject: [PATCH 1/5] switch to usage of url instead of string --- src/main/java/minevalley/core/api/Core.java | 3 ++- src/main/java/minevalley/core/api/CoreServer.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/minevalley/core/api/Core.java b/src/main/java/minevalley/core/api/Core.java index 2b8d752..ed03a06 100644 --- a/src/main/java/minevalley/core/api/Core.java +++ b/src/main/java/minevalley/core/api/Core.java @@ -63,6 +63,7 @@ import javax.annotation.Nonnegative; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import java.net.URL; import java.sql.SQLException; import java.text.SimpleDateFormat; import java.time.DayOfWeek; @@ -1179,7 +1180,7 @@ public static Reminder createReminder(@Nonnegative int hours, @Nonnegative int m * @throws IllegalArgumentException if the URL is null */ @Nonnull - public static Webhook createWebhook(@Nonnull String url) throws IllegalArgumentException { + public static Webhook createWebhook(@Nonnull URL url) throws IllegalArgumentException { return server.createWebhook(url); } diff --git a/src/main/java/minevalley/core/api/CoreServer.java b/src/main/java/minevalley/core/api/CoreServer.java index 4b6eb23..03635a0 100644 --- a/src/main/java/minevalley/core/api/CoreServer.java +++ b/src/main/java/minevalley/core/api/CoreServer.java @@ -58,6 +58,7 @@ import javax.annotation.Nonnegative; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import java.net.URL; import java.sql.SQLException; import java.time.DayOfWeek; import java.util.List; @@ -261,7 +262,7 @@ public interface CoreServer { Reminder createReminder(int hours, int minutes, @Nonnull Runnable callback, List weekdays) throws IllegalArgumentException; @Nonnull - Webhook createWebhook(@Nonnull String url) throws IllegalArgumentException; + Webhook createWebhook(@Nonnull URL url) throws IllegalArgumentException; @Nonnull EmbeddedMessage createEmbeddedMessage(); From 7b15a83f1f3651dcb1c9c86a126a97cea4876b19 Mon Sep 17 00:00:00 2001 From: Snabeldier <79211348+Snabeldier@users.noreply.github.com> Date: Mon, 6 Jan 2025 18:11:45 +0100 Subject: [PATCH 2/5] replace setFooter(String) with default method --- .../java/minevalley/core/api/discord/EmbeddedMessage.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/minevalley/core/api/discord/EmbeddedMessage.java b/src/main/java/minevalley/core/api/discord/EmbeddedMessage.java index 71aea1a..c6790d6 100644 --- a/src/main/java/minevalley/core/api/discord/EmbeddedMessage.java +++ b/src/main/java/minevalley/core/api/discord/EmbeddedMessage.java @@ -20,5 +20,7 @@ public interface EmbeddedMessage { EmbeddedMessage setFooter(String footer, String iconUrl); - EmbeddedMessage setFooter(String footer); + default EmbeddedMessage setFooter(String footer) { + return setFooter(footer, null); + } } \ No newline at end of file From 79b12378b77b6d13b861aeba2c36d228be4f835f Mon Sep 17 00:00:00 2001 From: Snabeldier <79211348+Snabeldier@users.noreply.github.com> Date: Mon, 6 Jan 2025 18:15:33 +0100 Subject: [PATCH 3/5] replace null with empty string --- src/main/java/minevalley/core/api/discord/EmbeddedMessage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/minevalley/core/api/discord/EmbeddedMessage.java b/src/main/java/minevalley/core/api/discord/EmbeddedMessage.java index c6790d6..bf89580 100644 --- a/src/main/java/minevalley/core/api/discord/EmbeddedMessage.java +++ b/src/main/java/minevalley/core/api/discord/EmbeddedMessage.java @@ -21,6 +21,6 @@ public interface EmbeddedMessage { EmbeddedMessage setFooter(String footer, String iconUrl); default EmbeddedMessage setFooter(String footer) { - return setFooter(footer, null); + return setFooter(footer, ""); } } \ No newline at end of file From 6bdf8303d9de03f5b7810ef81f883c0ccc6f5987 Mon Sep 17 00:00:00 2001 From: Snabeldier <79211348+Snabeldier@users.noreply.github.com> Date: Mon, 6 Jan 2025 18:58:59 +0100 Subject: [PATCH 4/5] add a lot of javadoc and exception throwing --- .../core/api/discord/EmbeddedMessage.java | 107 ++++++++++++++++-- .../minevalley/core/api/discord/Webhook.java | 37 +++++- 2 files changed, 131 insertions(+), 13 deletions(-) diff --git a/src/main/java/minevalley/core/api/discord/EmbeddedMessage.java b/src/main/java/minevalley/core/api/discord/EmbeddedMessage.java index bf89580..da21c4d 100644 --- a/src/main/java/minevalley/core/api/discord/EmbeddedMessage.java +++ b/src/main/java/minevalley/core/api/discord/EmbeddedMessage.java @@ -1,26 +1,115 @@ package minevalley.core.api.discord; +import org.jetbrains.annotations.Contract; + +import javax.annotation.Nonnull; import java.awt.*; public interface EmbeddedMessage { - EmbeddedMessage setTitle(String title); + /** + * Sets the title of the embedded message. + * + * @param title The title of the embedded message. + * @return The current instance of the embedded message. + * @throws IllegalArgumentException If the title is null. + */ + @Nonnull + @Contract("_ -> this") + EmbeddedMessage setTitle(@Nonnull String title) throws IllegalArgumentException; - EmbeddedMessage setDescription(String description); + /** + * Sets the description of the embedded message. + * + * @param description The description of the embedded message. + * @return The current instance of the embedded message. + * @throws IllegalArgumentException If the description is null. + */ + @Nonnull + @Contract("_ -> this") + EmbeddedMessage setDescription(@Nonnull String description) throws IllegalArgumentException; - EmbeddedMessage setAuthor(String name, String url, String iconUrl); + /** + * Sets the author of the embedded message. + * + * @param name The name of the author. + * @param url The URL of the author. + * @param iconUrl The URL of the author's icon. + * @return The current instance of the embedded message. + * @throws IllegalArgumentException If the name, URL or icon URL is null. + */ + @Nonnull + @Contract("_, _, _ -> this") + EmbeddedMessage setAuthor(@Nonnull String name, @Nonnull String url, @Nonnull String iconUrl) throws IllegalArgumentException; - EmbeddedMessage setThumbnail(String url); + /** + * Sets the thumbnail of the embedded message. + * + * @param url The URL of the thumbnail. + * @return The current instance of the embedded message. + * @throws IllegalArgumentException If the URL is null. + */ + @Nonnull + @Contract("_ -> this") + EmbeddedMessage setThumbnail(@Nonnull String url) throws IllegalArgumentException; - EmbeddedMessage setColor(Color color); + /** + * Sets the color of the embedded message. + * + * @param color The color of the embedded message. + * @return The current instance of the embedded message. + * @throws IllegalArgumentException If the color is null. + */ + @Nonnull + @Contract("_ -> this") + EmbeddedMessage setColor(@Nonnull Color color) throws IllegalArgumentException; - EmbeddedMessage addField(String title, String text, boolean inline); + /** + * Adds a field to the embedded message. + * + * @param title The title of the field. + * @param text The text of the field. + * @param inline Whether the field should be inline or not. + * @return The current instance of the embedded message. + * @throws IllegalArgumentException If the title or text is null. + */ + @Nonnull + @Contract("_, _, _ -> this") + EmbeddedMessage addField(@Nonnull String title, @Nonnull String text, boolean inline) throws IllegalArgumentException; - EmbeddedMessage setImage(String url); + /** + * Sets the image of the embedded message. + * + * @param url The URL of the image. + * @return The current instance of the embedded message. + * @throws IllegalArgumentException If the URL is null. + */ + @Nonnull + @Contract("_ -> this") + EmbeddedMessage setImage(@Nonnull String url) throws IllegalArgumentException; - EmbeddedMessage setFooter(String footer, String iconUrl); + /** + * Sets the footer of the embedded message. + * + * @param footer The footer of the embedded message. + * @param iconUrl The URL of the footer's icon. + * @return The current instance of the embedded message. + * @throws IllegalArgumentException If the footer is null. + */ + @Nonnull + @Contract("_, _ -> this") + EmbeddedMessage setFooter(@Nonnull String footer, @Nonnull String iconUrl) throws IllegalArgumentException; - default EmbeddedMessage setFooter(String footer) { + /** + * Sets the footer of the embedded message. + * + * @param footer The footer of the embedded message. + * @return The current instance of the embedded message. + * @throws IllegalArgumentException If the footer is null. + */ + @Nonnull + @Contract("_ -> this") + default EmbeddedMessage setFooter(@Nonnull String footer) throws IllegalArgumentException { return setFooter(footer, ""); } } \ No newline at end of file diff --git a/src/main/java/minevalley/core/api/discord/Webhook.java b/src/main/java/minevalley/core/api/discord/Webhook.java index 5f68163..9a58ba9 100644 --- a/src/main/java/minevalley/core/api/discord/Webhook.java +++ b/src/main/java/minevalley/core/api/discord/Webhook.java @@ -1,16 +1,45 @@ package minevalley.core.api.discord; +import org.jetbrains.annotations.Contract; + +import javax.annotation.Nonnull; import java.io.IOException; /** * This Webhook-builder is meant to help you to create discord-webhooks. - * You can find helpful information here: ... + * You can find helpful information here. */ public interface Webhook { - Webhook setUsername(String username); + /** + * Sets the username of the webhook. + * + * @param username The username of the webhook. + * @return The current instance of the webhook. + * @throws IllegalArgumentException If the username is null. + */ + @Nonnull + @Contract("_ -> this") + Webhook setUsername(@Nonnull String username); - Webhook setAvatar(String url); + /** + * Sets the avatar of the webhook. + * + * @param url The URL of the avatar. + * @return The current instance of the webhook. + * @throws IllegalArgumentException If the URL is null. + */ + @Nonnull + @Contract("_ -> this") + Webhook setAvatar(@Nonnull String url) throws IllegalArgumentException; - void send(EmbeddedMessage... message) throws IOException; + /** + * Sends the given messages to the discord-webhook. + * + * @param message The messages to send. + * @throws IOException If an I/O error occurs. + * @throws IllegalArgumentException If the message is null, or the given {@code EmbeddedMessage} is another implementation than our internal. + */ + @Contract(pure = true) + void send(@Nonnull EmbeddedMessage... message) throws IOException, IllegalArgumentException; } \ No newline at end of file From bce92816544e8e8c64fdb265cca75a1c8979a694 Mon Sep 17 00:00:00 2001 From: Snabeldier <79211348+Snabeldier@users.noreply.github.com> Date: Mon, 6 Jan 2025 20:19:56 +0100 Subject: [PATCH 5/5] add --- src/main/java/minevalley/core/api/discord/EmbeddedMessage.java | 1 + src/main/java/minevalley/core/api/discord/Webhook.java | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/minevalley/core/api/discord/EmbeddedMessage.java b/src/main/java/minevalley/core/api/discord/EmbeddedMessage.java index da21c4d..ae6ec80 100644 --- a/src/main/java/minevalley/core/api/discord/EmbeddedMessage.java +++ b/src/main/java/minevalley/core/api/discord/EmbeddedMessage.java @@ -5,6 +5,7 @@ import javax.annotation.Nonnull; import java.awt.*; +@SuppressWarnings("unused") public interface EmbeddedMessage { /** diff --git a/src/main/java/minevalley/core/api/discord/Webhook.java b/src/main/java/minevalley/core/api/discord/Webhook.java index 9a58ba9..7698433 100644 --- a/src/main/java/minevalley/core/api/discord/Webhook.java +++ b/src/main/java/minevalley/core/api/discord/Webhook.java @@ -9,6 +9,7 @@ * This Webhook-builder is meant to help you to create discord-webhooks. * You can find helpful information here. */ +@SuppressWarnings("unused") public interface Webhook { /** @@ -20,7 +21,7 @@ public interface Webhook { */ @Nonnull @Contract("_ -> this") - Webhook setUsername(@Nonnull String username); + Webhook setUsername(@Nonnull String username) throws IllegalArgumentException; /** * Sets the avatar of the webhook.