Skip to content

Commit

Permalink
CommandAnnotation 2.6.1
Browse files Browse the repository at this point in the history
- Fixed @autocomplete with List<String> returning value not applying result
  • Loading branch information
milkyway0308 committed Feb 20, 2021
1 parent 068f38f commit 5b55cf3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ public void editCompletion(ParameterStorage storage, List<String> str) throws Th
if (xt.size() == 0)
str.clear();
else {
List<String> clone = new ArrayList<>(str);
if (!(str.get(0) instanceof String))
if (!(xt.get(0) instanceof String))
throw new Exception();
str.clear();
str.addAll(clone);
str.addAll(xt);
}
} catch (Exception ex) {
ex.printStackTrace();
getChain().handleException(new AutoCompleteTypeMismatchException(xt.get(0)), storage);
}
}
Expand Down
40 changes: 40 additions & 0 deletions src/test/java/skywolf46/commandannotation/test/CompleterTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package skywolf46.commandannotation.test;

import org.junit.Test;
import skywolf46.commandannotation.annotations.autocomplete.AutoComplete;
import skywolf46.commandannotation.data.autocomplete.AutoCompleteSupplier;
import skywolf46.commandannotation.data.methodprocessor.ClassData;
import skywolf46.commandannotation.data.methodprocessor.GlobalData;
import skywolf46.commandannotation.data.methodprocessor.MethodChain;
import skywolf46.commandannotation.util.ParameterMatchedInvoker;
import skywolf46.commandannotation.util.ParameterStorage;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static org.junit.Assert.assertEquals;

public class CompleterTest {

@Test
public void completerTest() {
try {
AutoCompleteSupplier asp = AutoCompleteSupplier.from(new MethodChain(new ClassData(getClass(), new GlobalData()), new ParameterMatchedInvoker(getClass().getMethod("test"), null)));
List<String> test = new ArrayList<>();
asp.editCompletion(new ParameterStorage(), test);
System.out.println(test);
assertEquals(new ArrayList<>(Arrays.asList("Test1", "Test2")), test);
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (Throwable throwable) {
throwable.printStackTrace();
}
}

@AutoComplete
public static List<String> test() {
System.out.println("Test");
return new ArrayList<>(Arrays.asList("Test1", "Test2"));
}
}

0 comments on commit 5b55cf3

Please sign in to comment.