Fix broken number readers

This commit is contained in:
Alexander Söderberg 2020-09-07 22:21:03 +02:00
parent c5498e26b9
commit 953f85bf74
No known key found for this signature in database
GPG key ID: C0207FF7EA146678
5 changed files with 56 additions and 13 deletions

View file

@ -26,6 +26,7 @@ package com.intellectualsites.commands;
import com.intellectualsites.commands.components.CommandComponent; import com.intellectualsites.commands.components.CommandComponent;
import com.intellectualsites.commands.components.StaticComponent; import com.intellectualsites.commands.components.StaticComponent;
import com.intellectualsites.commands.context.CommandContext; import com.intellectualsites.commands.context.CommandContext;
import com.intellectualsites.commands.exceptions.ComponentParseException;
import com.intellectualsites.commands.exceptions.InvalidSyntaxException; import com.intellectualsites.commands.exceptions.InvalidSyntaxException;
import com.intellectualsites.commands.exceptions.NoPermissionException; import com.intellectualsites.commands.exceptions.NoPermissionException;
import com.intellectualsites.commands.exceptions.NoSuchCommandException; import com.intellectualsites.commands.exceptions.NoSuchCommandException;
@ -147,7 +148,10 @@ public class CommandTree<C extends CommandSender> {
return this.parseCommand(commandContext, commandQueue, child); return this.parseCommand(commandContext, commandQueue, child);
} }
} else if (result.getFailure().isPresent()) { } else if (result.getFailure().isPresent()) {
/* TODO: Return error */ throw new ComponentParseException(result.getFailure().get(), commandContext.getCommandSender(), this.getChain(child)
.stream()
.map(Node::getValue)
.collect(Collectors.toList()));
} }
} }
} }

View file

@ -133,6 +133,7 @@ public class ByteComponent<C extends CommandSender> extends CommandComponent<C,
this.min, this.min,
this.max)); this.max));
} }
inputQueue.remove();
return ComponentParseResult.success(value); return ComponentParseResult.success(value);
} catch (final Exception e) { } catch (final Exception e) {
return ComponentParseResult.failure( return ComponentParseResult.failure(

View file

@ -125,6 +125,7 @@ public class IntegerComponent<C extends CommandSender> extends CommandComponent<
if (value < this.min || value > this.max) { if (value < this.min || value > this.max) {
return ComponentParseResult.failure(new IntegerParseException(input, this.min, this.max)); return ComponentParseResult.failure(new IntegerParseException(input, this.min, this.max));
} }
inputQueue.remove();
return ComponentParseResult.success(value); return ComponentParseResult.success(value);
} catch (final Exception e) { } catch (final Exception e) {
return ComponentParseResult.failure(new IntegerParseException(input, this.min, this.max)); return ComponentParseResult.failure(new IntegerParseException(input, this.min, this.max));

View file

@ -0,0 +1,46 @@
//
// MIT License
//
// Copyright (c) 2020 IntellectualSites
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
package com.intellectualsites.commands.exceptions;
import com.intellectualsites.commands.components.CommandComponent;
import com.intellectualsites.commands.sender.CommandSender;
import javax.annotation.Nonnull;
import java.util.List;
public class ComponentParseException extends CommandParseException {
private final Throwable cause;
public ComponentParseException(@Nonnull final Throwable throwable, @Nonnull final CommandSender commandSender, @Nonnull final List<CommandComponent<?, ?>> currentChain) {
super(commandSender, currentChain);
this.cause = throwable;
}
@Nonnull
public Throwable getCause() {
return this.cause;
}
}

View file

@ -32,6 +32,7 @@ import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Optional; import java.util.Optional;
@ -61,18 +62,8 @@ class CommandTreeTest {
@Test @Test
void getSuggestions() { void getSuggestions() {
} Assertions.assertFalse(commandManager.getCommandTree().getSuggestions(new CommandContext<>(new TestCommandSender()), new LinkedList<>(
Collections.singletonList("test"))).isEmpty());
@Test
void testGetSuggestions() {
}
@Test
void insertCommand() {
}
@Test
void verifyAndRegister() {
} }
} }