Skip to content

Commit

Permalink
Add a guard to /autosort to check if an argument was given.
Browse files Browse the repository at this point in the history
  • Loading branch information
Momshroom committed Dec 12, 2024
1 parent f2f37b0 commit c278c2e
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)) {
Expand Down

0 comments on commit c278c2e

Please sign in to comment.