From c278c2edb5e9d43db1403b3a4c35e1d29eea5a61 Mon Sep 17 00:00:00 2001 From: Momshroom Date: Thu, 12 Dec 2024 01:17:30 -0600 Subject: [PATCH] Add a guard to /autosort to check if an argument was given. --- .../chaws/automaticinventory/commands/AutoSortCommand.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/dev/chaws/automaticinventory/commands/AutoSortCommand.java b/src/main/java/dev/chaws/automaticinventory/commands/AutoSortCommand.java index 17747e1..52c11c2 100644 --- a/src/main/java/dev/chaws/automaticinventory/commands/AutoSortCommand.java +++ b/src/main/java/dev/chaws/automaticinventory/commands/AutoSortCommand.java @@ -6,6 +6,7 @@ import dev.chaws.automaticinventory.messaging.Messages; import dev.chaws.automaticinventory.utilities.Chat; import dev.chaws.automaticinventory.utilities.Level; +import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -25,6 +26,12 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command var playerConfig = PlayerConfig.fromPlayer(player); + // Guard to prevent out of index error + if (args.length < 1) { + Chat.sendMessage(player, ChatColor.GOLD, "Usage: /autosort [chest|inv]"); + return false; + } + var optionName = args[0].toLowerCase(); if (optionName.startsWith("chest")) { if (!AutomaticInventory.hasPermission(Features.SortChests, player)) {