From 4b5ee21872c32ca8f5a98aa9836c76ec8e2f8881 Mon Sep 17 00:00:00 2001 From: stijnb1234 Date: Fri, 21 Feb 2020 10:51:37 +0100 Subject: [PATCH] Added tabcompleter --- .../V10Lift/Commands/V10LiftCommand.java | 3 +- .../V10Lift/Commands/V10LiftTabCompleter.java | 51 +++++++++++++++++++ .../nl/SBDeveloper/V10Lift/V10LiftPlugin.java | 2 + src/main/resources/plugin.yml | 1 + 4 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 src/main/lombok/nl/SBDeveloper/V10Lift/Commands/V10LiftTabCompleter.java diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/Commands/V10LiftCommand.java b/src/main/lombok/nl/SBDeveloper/V10Lift/Commands/V10LiftCommand.java index eabf92b..6452d52 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/Commands/V10LiftCommand.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/Commands/V10LiftCommand.java @@ -1008,7 +1008,8 @@ public class V10LiftCommand implements CommandExecutor { sender.sendMessage("§6/v10lift whois [Name]§f: See information about a lift."); sender.sendMessage("§6/v10lift edit §f: Edit a lift."); sender.sendMessage("§6/v10lift floor [New name]§f: Add/remove/rename a floor."); - sender.sendMessage("§6/v10lift input [Floorname]§f: Add/remove a input."); + sender.sendMessage("§6/v10lift input [Floorname]§f: Add/remove an input."); + sender.sendMessage("§6/v10lift offline [Floorname]§f: Add/remove an offline input."); sender.sendMessage("§6/v10lift build§f: Add/remove blocks to/from a cab."); sender.sendMessage("§6/v10lift rope §f: Add/remove a rope."); sender.sendMessage("§6/v10lift door§f: Add doors to a lift."); diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/Commands/V10LiftTabCompleter.java b/src/main/lombok/nl/SBDeveloper/V10Lift/Commands/V10LiftTabCompleter.java new file mode 100644 index 0000000..81c75fa --- /dev/null +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/Commands/V10LiftTabCompleter.java @@ -0,0 +1,51 @@ +package nl.SBDeveloper.V10Lift.Commands; + +import nl.SBDeveloper.V10Lift.Managers.DataManager; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; + +import javax.annotation.Nonnull; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +public class V10LiftTabCompleter implements TabCompleter { + + @Override + public List onTabComplete(@Nonnull CommandSender commandSender, @Nonnull Command cmd, @Nonnull String label, @Nonnull String[] args) { + if (label.equalsIgnoreCase("v10lift")) { + ArrayList returns = new ArrayList<>(); + if (args.length == 1) { + String[] strs = { "create", "delete", "abort", "whois", "edit", "floor", "input", "build", "rope", "door", "speed", "realistic", "repair", "whitelist", "reload", "help", "start", "stop", "offline" }; + returns.addAll(Arrays.asList(strs)); + } else if (args.length == 2) { + if (args[0].equalsIgnoreCase("floor")) { + returns.add("add"); + returns.add("del"); + returns.add("rename"); + } else if (args[0].equalsIgnoreCase("input")) { + returns.add("add"); + returns.add("del"); + } else if (args[0].equalsIgnoreCase("offline")) { + returns.add("add"); + returns.add("del"); + } else if (args[0].equalsIgnoreCase("whitelist")) { + returns.add("add"); + returns.add("del"); + } else if (args[0].equalsIgnoreCase("rope")) { + returns.add("add"); + returns.add("del"); + } else if (args[0].equalsIgnoreCase("edit")) { + returns.addAll(DataManager.getLifts().keySet()); + } + } + + Collections.sort(returns); + return returns; + } + return null; + } + +} diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/V10LiftPlugin.java b/src/main/lombok/nl/SBDeveloper/V10Lift/V10LiftPlugin.java index c08f3d4..ed575a9 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/V10LiftPlugin.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/V10LiftPlugin.java @@ -3,6 +3,7 @@ package nl.SBDeveloper.V10Lift; import com.fasterxml.jackson.core.JsonProcessingException; import nl.SBDeveloper.V10Lift.API.V10LiftAPI; import nl.SBDeveloper.V10Lift.Commands.V10LiftCommand; +import nl.SBDeveloper.V10Lift.Commands.V10LiftTabCompleter; import nl.SBDeveloper.V10Lift.Listeners.BlockBreakListener; import nl.SBDeveloper.V10Lift.Listeners.EntityDamageListener; import nl.SBDeveloper.V10Lift.Listeners.PlayerInteractListener; @@ -50,6 +51,7 @@ public class V10LiftPlugin extends JavaPlugin { //Load the command Objects.requireNonNull(getCommand("v10lift"), "Internal error! Command not found.").setExecutor(new V10LiftCommand()); + Objects.requireNonNull(getCommand("v10lift"), "Internal error! Command not found.").setTabCompleter(new V10LiftTabCompleter()); //Register the listeners Bukkit.getPluginManager().registerEvents(new PlayerInteractListener(), this); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index c349ebf..83009e5 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -2,6 +2,7 @@ name: V10Lift main: nl.SBDeveloper.V10Lift.V10LiftPlugin version: ${project.version} api-version: "1.13" +author: SBDeveloper commands: v10lift: description: The V10Lift Command \ No newline at end of file