From 63ab4e3a826c91c7b90a6697f8058f603c622b83 Mon Sep 17 00:00:00 2001 From: Default Date: Tue, 29 Dec 2020 18:52:35 +0100 Subject: [PATCH] added tab completion for commands --- .../com/benjocraeft/sharehealth/Commands.java | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/benjocraeft/sharehealth/Commands.java b/src/main/java/com/benjocraeft/sharehealth/Commands.java index 6415661..04a99ea 100644 --- a/src/main/java/com/benjocraeft/sharehealth/Commands.java +++ b/src/main/java/com/benjocraeft/sharehealth/Commands.java @@ -7,14 +7,51 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabExecutor; import org.bukkit.entity.Player; +import org.bukkit.util.StringUtil; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.List; public class Commands implements TabExecutor { + final private String[] mainSchema = { + "get", "set", "reset", "log" + }; + + final private String[] hasSecondSchema = { + "log", + "get" + }; + + final private String[][] secondSchema = { + { + "on", "off" + }, + { + "max" + } + }; + @Override public List onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) { - return null; + List list = new ArrayList<>(); + + if (strings.length == 1){ + StringUtil.copyPartialMatches(strings[0], Arrays.asList(mainSchema), list); + } + if (strings.length == 2){ + List hasSecondSchemaList = Arrays.asList(hasSecondSchema); + if (hasSecondSchemaList.contains(strings[0])){ + int index = hasSecondSchemaList.indexOf(strings[0]); + List checkList = Arrays.asList(secondSchema[index]); + StringUtil.copyPartialMatches(strings[1], checkList, list); + } + } + + + return list; } @Override