Skip to content

Commit

Permalink
add a lot of javadoc and exception throwing
Browse files Browse the repository at this point in the history
  • Loading branch information
Snabeldier committed Jan 6, 2025
1 parent 79b1237 commit 6bdf830
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 13 deletions.
107 changes: 98 additions & 9 deletions src/main/java/minevalley/core/api/discord/EmbeddedMessage.java
Original file line number Diff line number Diff line change
@@ -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, "");
}
}
37 changes: 33 additions & 4 deletions src/main/java/minevalley/core/api/discord/Webhook.java
Original file line number Diff line number Diff line change
@@ -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: <a href="https://birdie0.github.io/discord-webhooks-guide/discord_webhook.html">...</a>
* You can find helpful information <a href="https://birdie0.github.io/discord-webhooks-guide/discord_webhook.html">here</a>.
*/
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;
}

0 comments on commit 6bdf830

Please sign in to comment.