From cef7f71a8998fcbb2c5ff5ba2f22c8e7c57638ce Mon Sep 17 00:00:00 2001 From: NFRCG Date: Thu, 23 May 2024 14:19:19 -0500 Subject: [PATCH] feat: Add convenience formatting caption methods. --- .../incendo/cloud/context/CommandContext.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/cloud-core/src/main/java/org/incendo/cloud/context/CommandContext.java b/cloud-core/src/main/java/org/incendo/cloud/context/CommandContext.java index e2b50d5ec..3e74baa84 100644 --- a/cloud-core/src/main/java/org/incendo/cloud/context/CommandContext.java +++ b/cloud-core/src/main/java/org/incendo/cloud/context/CommandContext.java @@ -171,6 +171,54 @@ public CommandContext( ); } + /** + * Formats a {@code caption} using the given {@code formatter} and {@code recipient}. + * + * @param the message type produced by the formatter + * @param formatter the formatter + * @param recipient the recipient of the message. + * @param caption the caption key + * @param variables the variables to use during formatting + * @return the formatted caption + */ + public @NonNull T formatCaption( + final @NonNull CaptionFormatter formatter, + final @NonNull C recipient, + final @NonNull Caption caption, + final @NonNull CaptionVariable @NonNull... variables + ) { + return formatter.formatCaption( + caption, + recipient, + this.captionRegistry.caption(caption, recipient), + variables + ); + } + + /** + * Formats a {@code caption} using the given {@code formatter} and {@code recipient}. + * + * @param the message type produced by the formatter + * @param formatter the formatter + * @param recipient the recipient of the message. + * @param caption the caption key + * @param variables the variables to use during formatting + * @return the formatted caption + */ + public @NonNull T formatCaption( + final @NonNull CaptionFormatter formatter, + final @NonNull C recipient, + final @NonNull Caption caption, + final @NonNull List<@NonNull CaptionVariable> variables + ) { + return formatter.formatCaption( + caption, + recipient, + this.captionRegistry.caption(caption, recipient), + variables + ); + } + /** * Returns the sender that executed the command. *