diff --git a/src/main/java/skywolf46/commandannotation/data/autocomplete/AutoCompleteSupplier.java b/src/main/java/skywolf46/commandannotation/data/autocomplete/AutoCompleteSupplier.java index 286faeb..ad5aa72 100644 --- a/src/main/java/skywolf46/commandannotation/data/autocomplete/AutoCompleteSupplier.java +++ b/src/main/java/skywolf46/commandannotation/data/autocomplete/AutoCompleteSupplier.java @@ -84,13 +84,13 @@ public void editCompletion(ParameterStorage storage, List str) throws Th if (xt.size() == 0) str.clear(); else { - List 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); } } diff --git a/src/test/java/skywolf46/commandannotation/test/CompleterTest.java b/src/test/java/skywolf46/commandannotation/test/CompleterTest.java new file mode 100644 index 0000000..d0939ce --- /dev/null +++ b/src/test/java/skywolf46/commandannotation/test/CompleterTest.java @@ -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 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 test() { + System.out.println("Test"); + return new ArrayList<>(Arrays.asList("Test1", "Test2")); + } +}