From dfae6ad5f8dd07dc4608f5babd7676767237b1a0 Mon Sep 17 00:00:00 2001 From: LeoDog896 Date: Tue, 6 Apr 2021 22:12:30 -0400 Subject: [PATCH] Documentation and visibility changes --- .../server/command/builder/ArgumentMapper.java | 16 ++++++++++++++++ .../command/builder/arguments/Argument.java | 8 ++++++++ .../command/builder/arguments/ArgumentMap.java | 5 +++-- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/minestom/server/command/builder/ArgumentMapper.java b/src/main/java/net/minestom/server/command/builder/ArgumentMapper.java index 73efefab7..07b944fd3 100644 --- a/src/main/java/net/minestom/server/command/builder/ArgumentMapper.java +++ b/src/main/java/net/minestom/server/command/builder/ArgumentMapper.java @@ -2,9 +2,25 @@ package net.minestom.server.command.builder; import net.minestom.server.command.builder.exception.ArgumentSyntaxException; +/** + * Represents a lambda that can turn an input into an output + * that also allows the throwing of ArgumentSyntaxException + * + * @param The input expected from the Argument + * @param The desired output type from this lambda. + */ @FunctionalInterface public interface ArgumentMapper { + /** + * Accept's I data from the argument and returns O output + * + * @param i The input processed from an argument + * + * @return The complex data type that came as a result from this argument + * @throws ArgumentSyntaxException If the input can not be turned into the desired output + * (E.X. an invalid extension name) + */ O accept(I i) throws ArgumentSyntaxException; } diff --git a/src/main/java/net/minestom/server/command/builder/arguments/Argument.java b/src/main/java/net/minestom/server/command/builder/arguments/Argument.java index f1db86f3f..2f9dd2d6c 100644 --- a/src/main/java/net/minestom/server/command/builder/arguments/Argument.java +++ b/src/main/java/net/minestom/server/command/builder/arguments/Argument.java @@ -217,6 +217,14 @@ public abstract class Argument { return suggestionCallback != null; } + /** + * Maps this argument's output to another result. + * + * @param mapper The mapper to use (this argument's input --> desired output) + * @param The type of output expected. + * + * @return A new ArgumentMap that can get this complex object type. + */ public ArgumentMap map(ArgumentMapper mapper) { return new ArgumentMap<>(this, mapper); } diff --git a/src/main/java/net/minestom/server/command/builder/arguments/ArgumentMap.java b/src/main/java/net/minestom/server/command/builder/arguments/ArgumentMap.java index 68983df80..9a7949203 100644 --- a/src/main/java/net/minestom/server/command/builder/arguments/ArgumentMap.java +++ b/src/main/java/net/minestom/server/command/builder/arguments/ArgumentMap.java @@ -6,7 +6,8 @@ import net.minestom.server.command.builder.exception.ArgumentSyntaxException; import org.jetbrains.annotations.NotNull; /** - * Represents an argument that maps an existing argument to a vlaue. + * Represents an argument that maps an existing argument to a value. + * * @param The input (any object) * @param The output (any object) */ @@ -15,7 +16,7 @@ public class ArgumentMap extends Argument { final Argument argument; final ArgumentMapper mapper; - public ArgumentMap(Argument argument, ArgumentMapper mapper) { + protected ArgumentMap(Argument argument, ArgumentMapper mapper) { super(argument.getId()); this.argument = argument;