diff --git a/cloud-core/src/main/java/cloud/commandframework/context/CommandContext.java b/cloud-core/src/main/java/cloud/commandframework/context/CommandContext.java index 141b9b30..1ab9a2f9 100644 --- a/cloud-core/src/main/java/cloud/commandframework/context/CommandContext.java +++ b/cloud-core/src/main/java/cloud/commandframework/context/CommandContext.java @@ -194,6 +194,19 @@ public final class CommandContext { * @param value Value * @param Value type */ + public void store(final @NonNull CommandArgument keyHolder, final @NonNull T value) { + this.store((CloudKeyHolder) keyHolder, value); + } + + /** + * Store a value in the context map. This will overwrite any existing + * value stored with the same key + * + * @param keyHolder Holder of the identifying key + * @param value Value + * @param Value type + * @since 1.4.0 + */ public void store(final @NonNull CloudKeyHolder keyHolder, final @NonNull T value) { this.internalStorage.put(keyHolder.getKey(), value); } @@ -316,6 +329,20 @@ public final class CommandContext { * @return Value */ @SuppressWarnings("unused") + public @NonNull Optional getOptional(final @NonNull CommandArgument keyHolder) { + return this.getOptional((CloudKeyHolder) keyHolder); + } + + /** + * Get a value from its key. Will return {@link Optional#empty()} + * if no value is stored with the given key + * + * @param keyHolder Holder of the key + * @param Value type + * @return Value + * @since 1.4.0 + */ + @SuppressWarnings("unused") public @NonNull Optional getOptional(final @NonNull CloudKeyHolder keyHolder) { final Object value = this.internalStorage.get(keyHolder.getKey()); if (value != null) { @@ -391,6 +418,20 @@ public final class CommandContext { * @return Stored value * @throws NullPointerException If no such value is stored */ + public @NonNull T get(final @NonNull CommandArgument keyHolder) { + return this.get(keyHolder.getKey()); + } + + /** + * Get a required argument from the context. This will thrown an exception + * if there's no value associated with the given argument + * + * @param keyHolder Holder of the identifying key + * @param Argument type + * @return Stored value + * @throws NullPointerException If no such value is stored + * @since 1.4.0 + */ public @NonNull T get(final @NonNull CloudKeyHolder keyHolder) { return this.get(keyHolder.getKey()); }