From 4c9a6302a1135747b77b32a9a271752e56df1177 Mon Sep 17 00:00:00 2001 From: broccolai Date: Thu, 8 Aug 2024 03:47:02 +0100 Subject: [PATCH] feat: add method to command meta for adding a key with no value --- .../main/java/org/incendo/cloud/Command.java | 21 +++++++++++++++++++ .../cloud/meta/CommandMetaBuilder.java | 13 ++++++++++++ 2 files changed, 34 insertions(+) diff --git a/cloud-core/src/main/java/org/incendo/cloud/Command.java b/cloud-core/src/main/java/org/incendo/cloud/Command.java index 6d2b6b3d4..88e0d3f5f 100644 --- a/cloud-core/src/main/java/org/incendo/cloud/Command.java +++ b/cloud-core/src/main/java/org/incendo/cloud/Command.java @@ -471,6 +471,27 @@ private Builder( ); } + /** + * Adds command meta with no value to the internal command meta-map + * + * @param key meta key + * @return new builder instance using the inserted meta key + */ + @API(status = API.Status.STABLE) + public @NonNull Builder meta(final @NonNull CloudKey key) { + final CommandMeta commandMeta = CommandMeta.builder().with(this.commandMeta).with(key).build(); + return new Builder<>( + this.commandManager, + commandMeta, + this.senderType, + this.commandComponents, + this.commandExecutionHandler, + this.permission, + this.flags, + this.commandDescription + ); + } + /** * Supplies a command manager instance to the builder. *

diff --git a/cloud-core/src/main/java/org/incendo/cloud/meta/CommandMetaBuilder.java b/cloud-core/src/main/java/org/incendo/cloud/meta/CommandMetaBuilder.java index 995c96eba..b64a521f7 100644 --- a/cloud-core/src/main/java/org/incendo/cloud/meta/CommandMetaBuilder.java +++ b/cloud-core/src/main/java/org/incendo/cloud/meta/CommandMetaBuilder.java @@ -65,6 +65,19 @@ public class CommandMetaBuilder { return this; } + /** + * Stores the given {@code key} with no value. + * + * @param key the key + * @return {@code this} + */ + public @This @NonNull CommandMetaBuilder with( + final @NonNull CloudKey key + ) { + this.map.put(key, new Object()); + return this; + } + /** * Builds a new {@link CommandMeta} instance using the stored {@code key}-{@code value} pairs. *