diff --git a/src/main/java/dev/plex/fossil/Fossil.java b/src/main/java/dev/plex/fossil/Fossil.java index 62c318d..616ec9a 100644 --- a/src/main/java/dev/plex/fossil/Fossil.java +++ b/src/main/java/dev/plex/fossil/Fossil.java @@ -21,6 +21,7 @@ public final class Fossil extends JavaPlugin { plugin = this; server = plugin.getServer(); getCommand("fossil").setExecutor(new FossilCommand()); + getCommand("fossil").setTabCompleter(new FossilCommand()); } @Override diff --git a/src/main/java/dev/plex/fossil/FossilCommand.java b/src/main/java/dev/plex/fossil/FossilCommand.java index 5c57d90..ddbe920 100644 --- a/src/main/java/dev/plex/fossil/FossilCommand.java +++ b/src/main/java/dev/plex/fossil/FossilCommand.java @@ -1,33 +1,39 @@ package dev.plex.fossil; import java.io.File; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; +import org.bukkit.command.*; import org.bukkit.scheduler.BukkitRunnable; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -public class FossilCommand implements CommandExecutor, IFossil { - private final List FILES = plugin.getConfig().getStringList("plugins"); +public class FossilCommand implements CommandExecutor, TabCompleter, IFossil { + private List FILES = new ArrayList<>(); @Override public boolean onCommand(CommandSender sender, Command command, String s, String[] args) { if (args.length == 0) { sender.sendMessage(Component.text("This server is running Fossil to keep plugins in sync.")); - sender.sendMessage(Component.text("Source code available at https://github.com/plexusorg/Fossil")); + sender.sendMessage(Component.text("Source code available at: https://github.com/plexusorg/Fossil")); return true; } - if (args.length > 1) { + if (args[0].equalsIgnoreCase("update")) { if (!sender.hasPermission("fossil.update")) { sender.sendMessage(Component.text("You do not have permission to use this command!").color(NamedTextColor.RED)); return true; } sender.sendMessage(Component.text("Updating server plugins").color(NamedTextColor.GRAY)); + for (String file : plugin.getConfig().getStringList("plugins")) { + FILES.add(plugin.getPlugin(file)); + } + new BukkitRunnable() { @Override public void run() { @@ -51,7 +57,17 @@ public class FossilCommand implements CommandExecutor, IFossil { } } }.runTaskAsynchronously(plugin); + } else { + return false; } return true; } + + @Override + public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { + if (args.length == 1 && sender.hasPermission("fossil.update")) { + return Collections.singletonList("update"); + } + return Collections.emptyList(); + } } \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 16e6950..ff75f4f 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,4 +1,8 @@ name: Fossil version: '${version}' main: dev.plex.fossil.Fossil -api-version: 1.20 +api-version: 1.19 +commands: + fossil: + description: The main command for Fossil + usage: / [update] \ No newline at end of file