|
3 | 3 | import com.gmail.visualbukkit.blocks.ClassInfo; |
4 | 4 | import com.gmail.visualbukkit.blocks.Statement; |
5 | 5 | import com.gmail.visualbukkit.blocks.parameters.ExpressionParameter; |
| 6 | +import com.gmail.visualbukkit.project.BuildContext; |
6 | 7 |
|
7 | | -@SuppressWarnings({"CommentedOutCode", "unused"}) |
| 8 | +@SuppressWarnings("unused") |
8 | 9 | public class StatCompletionsSet extends Statement { |
9 | | -// private final static String FORMAT_METHOD = """ |
10 | | -// public static java.util.List<String> formatList(java.util.List<String> list, String[] args) { |
11 | | -// java.util.List<String> completions = new java.util.ArrayList<>(); |
12 | | -// |
13 | | -// org.bukkit.util.StringUtil.copyPartialMatches(args[0], list, completions); |
14 | | -// java.util.Collections.sort(completions); |
15 | | -// return completions; |
16 | | -// } |
17 | | -// """; |
| 10 | + private final static String FORMAT_METHOD = """ |
| 11 | + public static java.util.List<String> formatList(java.util.List<String> list, String[] args) { |
| 12 | + java.util.List<String> completions = new java.util.ArrayList<>(); |
| 13 | +
|
| 14 | + org.bukkit.util.StringUtil.copyPartialMatches(args[args.length-1], list, completions); |
| 15 | + java.util.Collections.sort(completions); |
| 16 | + return completions; |
| 17 | + } |
| 18 | + """; |
18 | 19 |
|
19 | 20 | public StatCompletionsSet() { |
20 | 21 | super("stat-scompletions-set", "Set Completions", "TabCompletion", "Sets tab completion for your command"); |
21 | 22 | } |
22 | 23 |
|
23 | 24 | @Override |
24 | 25 | public Block createBlock() { |
25 | | - return new Block(this, new ExpressionParameter("Completions", ClassInfo.LIST)) { |
| 26 | + return new Block(this, |
| 27 | + new ExpressionParameter("Completions", ClassInfo.LIST), |
| 28 | + new ExpressionParameter("Format", ClassInfo.BOOLEAN) |
| 29 | + ) { |
26 | 30 | @Override |
27 | 31 | public void update() { |
28 | 32 | super.update(); |
29 | 33 | checkForPluginComponent(CompTabComplete.class); |
30 | 34 | } |
31 | 35 |
|
32 | | -// @Override |
33 | | -// public void prepareBuild(BuildContext buildContext) { |
34 | | -// super.prepareBuild(buildContext); |
35 | | -// buildContext.addUtilMethod(FORMAT_METHOD); |
36 | | -// } |
| 36 | + @Override |
| 37 | + public void prepareBuild(BuildContext buildContext) { |
| 38 | + super.prepareBuild(buildContext); |
| 39 | + buildContext.addUtilMethod(FORMAT_METHOD); |
| 40 | + } |
37 | 41 |
|
38 | 42 | @Override |
39 | 43 | public String toJava() { |
40 | | -// return "if (true) return PluginMain.formatList(" + arg(0) + ", commandArgs);"; |
41 | | - return "if (true) return " + arg(0) + ";"; |
| 44 | + return "if (true) return ((" + arg(1) + " ) ? " + |
| 45 | + "PluginMain.formatList(" + arg(0) + ", commandArgs) : " + arg(0) + ");"; |
42 | 46 | } |
43 | 47 | }; |
44 | 48 | } |
|
0 commit comments