From 43728d8143a8a64eaa9361fa84a5819e386560ca Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 16 Jun 2022 23:06:53 +0200 Subject: [PATCH] Fix CommandPart Validator for varargs part --- src/de/steamwar/command/AbstractSWCommand.java | 5 ++++- src/de/steamwar/command/AbstractTypeMapper.java | 3 +-- src/de/steamwar/command/AbstractValidator.java | 9 ++++++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/de/steamwar/command/AbstractSWCommand.java b/src/de/steamwar/command/AbstractSWCommand.java index d9a721f..012d96a 100644 --- a/src/de/steamwar/command/AbstractSWCommand.java +++ b/src/de/steamwar/command/AbstractSWCommand.java @@ -72,7 +72,10 @@ public abstract class AbstractSWCommand { List errors = new ArrayList<>(); try { if (!commandList.stream().anyMatch(s -> s.invoke(errors::add, sender, alias, args))) { - errors.forEach(Runnable::run); + if (!errors.isEmpty()) { + errors.forEach(Runnable::run); + return; + } commandHelpList.stream().anyMatch(s -> s.invoke((ignore) -> {}, sender, alias, args)); } } catch (CommandNoHelpException e) { diff --git a/src/de/steamwar/command/AbstractTypeMapper.java b/src/de/steamwar/command/AbstractTypeMapper.java index ca8c50b..4a340d8 100644 --- a/src/de/steamwar/command/AbstractTypeMapper.java +++ b/src/de/steamwar/command/AbstractTypeMapper.java @@ -20,7 +20,6 @@ package de.steamwar.command; import java.util.Collection; -import java.util.function.BiConsumer; public interface AbstractTypeMapper extends AbstractValidator { /** @@ -29,7 +28,7 @@ public interface AbstractTypeMapper extends AbstractValidator { T map(K sender, String[] previousArguments, String s); @Override - default boolean validate(K sender, T value, BiConsumer messageSender) { + default boolean validate(K sender, T value, MessageSender messageSender) { return true; } diff --git a/src/de/steamwar/command/AbstractValidator.java b/src/de/steamwar/command/AbstractValidator.java index a12c0e4..60efd19 100644 --- a/src/de/steamwar/command/AbstractValidator.java +++ b/src/de/steamwar/command/AbstractValidator.java @@ -19,8 +19,6 @@ package de.steamwar.command; -import java.util.function.BiConsumer; - @FunctionalInterface public interface AbstractValidator { @@ -32,5 +30,10 @@ public interface AbstractValidator { * @param messageSender The message sender to send messages to the player. Never send messages directly to the player. * @return The result of the validation. */ - boolean validate(K sender, T value, BiConsumer messageSender); + boolean validate(K sender, T value, MessageSender messageSender); + + @FunctionalInterface + interface MessageSender { + void send(String s, Object... args); + } }