Fix ArgumentMap when the argument accepts space

This commit is contained in:
TheMode 2021-04-09 18:59:24 +02:00
parent b50c2831bf
commit 4b31e27348
2 changed files with 12 additions and 11 deletions

View File

@ -1,7 +1,10 @@
package net.minestom.server.command.builder.arguments;
import com.google.common.annotations.Beta;
import net.minestom.server.command.builder.*;
import net.minestom.server.command.builder.ArgumentCallback;
import net.minestom.server.command.builder.Command;
import net.minestom.server.command.builder.CommandExecutor;
import net.minestom.server.command.builder.NodeMaker;
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
import net.minestom.server.command.builder.suggestion.SuggestionCallback;
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
@ -221,12 +224,11 @@ public abstract class Argument<T> {
* Maps this argument's output to another result.
*
* @param mapper The mapper to use (this argument's input --> desired output)
* @param <O> The type of output expected.
*
* @param <O> The type of output expected.
* @return A new ArgumentMap that can get this complex object type.
*/
@Beta
public <O> ArgumentMap<T, O> map(ArgumentMap.ArgumentMapper<T, O> mapper) {
public <O> @NotNull ArgumentMap<T, O> map(@NotNull ArgumentMap.Mapper<T, O> mapper) {
return new ArgumentMap<>(this, mapper);
}

View File

@ -13,10 +13,10 @@ import org.jetbrains.annotations.NotNull;
public class ArgumentMap<I, O> extends Argument<O> {
final Argument<I> argument;
final ArgumentMapper<I, O> mapper;
final Mapper<I, O> mapper;
protected ArgumentMap(Argument<I> argument, ArgumentMapper<I, O> mapper) {
super(argument.getId());
protected ArgumentMap(@NotNull Argument<I> argument, @NotNull Mapper<I, O> mapper) {
super(argument.getId(), argument.allowSpace(), argument.useRemaining());
this.argument = argument;
this.mapper = mapper;
@ -40,16 +40,15 @@ public class ArgumentMap<I, O> extends Argument<O> {
* @param <O> The desired output type from this lambda.
*/
@FunctionalInterface
public interface ArgumentMapper<I, O> {
public interface Mapper<I, O> {
/**
* Accept's I data from the argument and returns O output
* Accepts 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)
* (E.X. an invalid extension name)
*/
O accept(I i) throws ArgumentSyntaxException;