Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
优化tab补全
Browse files Browse the repository at this point in the history
  • Loading branch information
Crsuh2er0 committed Sep 10, 2022
1 parent 32c85dc commit c0695b2
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/main/java/cn/lingsmc/lingshttputils/commands/TabComplete.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;

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

Expand All @@ -20,12 +20,26 @@ public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Comman
final String[] root = new String[]{"workers", "help", "reload"};
final String[] worker = new String[]{"start", "stop"};

if (args.length <= 1) {
return Arrays.asList(root);
if (args.length == 1) {
List<String> res = new ArrayList<>();
for (String val : root) {
if (val.contains(args[0])) {
res.add(val);
}
}
return res;
}
if (args.length <= 2 && root[0].equalsIgnoreCase(args[0])) {
return Arrays.asList(worker);

if (args.length == 2 && root[0].equalsIgnoreCase(args[0])) {
List<String> res = new ArrayList<>();
for (String val : worker) {
if (val.contains(args[1])) {
res.add(val);
}
}
return res;
}

return Collections.emptyList();
}
}

0 comments on commit c0695b2

Please # to comment.