SteamWar/SpigotCore
Archiviert
13
0

CMD #141

Zusammengeführt
YoyoNow hat 29 Commits von CMD nach master 2021-12-12 15:58:20 +01:00 zusammengeführt
2 geänderte Dateien mit 57 neuen und 3 gelöschten Zeilen
Nur Änderungen aus Commit 7d94d8dd6c werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -133,6 +133,20 @@ public class CommandPart {
}
public void generateTabComplete(List<String> current, CommandSender commandSender, String[] args, int startIndex) {
if (varArgType != null) {
for (int i = startIndex; i < args.length - 1; i++) {
CheckArgumentResult validArgument = checkArgument(null, commandSender, args, i);
if (!validArgument.success) {
return;
}
}
List<String> strings = typeMapper.tabCompletes(commandSender, Arrays.copyOf(args, args.length - 1), args[args.length - 1]);
if (strings != null) {
current.addAll(strings);
}
return;
}
if (args.length - 1 > startIndex) {
CheckArgumentResult checkArgumentResult = checkArgument(GuardCheckType.TAB_COMPLETE, commandSender, args, startIndex);
if (checkArgumentResult.success && next != null) {

Datei anzeigen

@ -27,14 +27,14 @@ import java.util.ArrayList;
import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.*;
public class SimpleCommandPartTest {
private CommandPart stringCommandPart;
private CommandPart intCommandPart;
private CommandPart chainedCommandPart;
private CommandPart varArgCommandPart;
private CommandPart simpleGuardPart;
@ -46,6 +46,8 @@ public class SimpleCommandPartTest {
chainedCommandPart = new CommandPart(SWCommandUtils.createMapper("hello", "world"), null, null, null, GuardCheckType.COMMAND);
chainedCommandPart.setNext(new CommandPart(SWCommandUtils.MAPPER_FUNCTIONS.get("int"), null, null, null, GuardCheckType.COMMAND));
varArgCommandPart = new CommandPart(SWCommandUtils.createMapper("hello", "world"), null, String.class, null, GuardCheckType.COMMAND);
simpleGuardPart = new CommandPart(SWCommandUtils.createMapper("hello", "world"), (commandSender, guardCheckType, previousArguments, s) -> s.equals("hello") ? GuardResult.DENIED : GuardResult.ALLOWED, null, null, GuardCheckType.COMMAND);
}
@ -119,10 +121,48 @@ public class SimpleCommandPartTest {
public void testChainedCommandTabCompleteOther() {
List<String> tabCompletes = new ArrayList<>();
chainedCommandPart.generateTabComplete(tabCompletes, new TestCommandSender(), new String[]{"hello", ""}, 0);
System.out.println(tabCompletes);
assertThat(tabCompletes.size(), is(0));
}
@Test
public void testVarArgsCommandTabComplete() {
List<String> tabCompletes = new ArrayList<>();
varArgCommandPart.generateTabComplete(tabCompletes, new TestCommandSender(), new String[]{"hello"}, 0);
assertThat(tabCompletes.size(), is(2));
assertThat(tabCompletes.get(0), is("hello"));
assertThat(tabCompletes.get(1), is("world"));
}
@Test
public void testVarArgsCommandTabCompleteDeeper() {
List<String> tabCompletes = new ArrayList<>();
varArgCommandPart.generateTabComplete(tabCompletes, new TestCommandSender(), new String[]{"hello", "world", "hello", "world"}, 0);
System.out.println(tabCompletes);
assertThat(tabCompletes.size(), is(2));
assertThat(tabCompletes.get(0), is("hello"));
assertThat(tabCompletes.get(1), is("world"));
}
@Test
public void testVarArgsCommandArgumentParsing() {
List<Object> argumentArray = new ArrayList<>();
varArgCommandPart.generateArgumentArray(argumentArray, new TestCommandSender(), new String[]{"hello"}, 0);
assertThat(argumentArray.size(), is(1));
assertThat(argumentArray.get(0), instanceOf(String[].class));
assertThat((String[]) argumentArray.get(0), arrayWithSize(1));
assertThat((String[]) argumentArray.get(0), is(new String[]{"hello"}));
}
@Test
public void testVarArgsCommandArgumentParsingDeeper() {
List<Object> argumentArray = new ArrayList<>();
varArgCommandPart.generateArgumentArray(argumentArray, new TestCommandSender(), new String[]{"hello", "world", "hello", "world"}, 0);
assertThat(argumentArray.size(), is(1));
assertThat(argumentArray.get(0), instanceOf(String[].class));
assertThat((String[]) argumentArray.get(0), arrayWithSize(4));
assertThat((String[]) argumentArray.get(0), is(new String[]{"hello", "world", "hello", "world"}));
}
@Test
public void testGuardCommandExecute() {
List<Object> argumentArray = new ArrayList<>();