diff --git a/src/main/java/net/knarcraft/bookswithoutborders/command/CommandGive.java b/src/main/java/net/knarcraft/bookswithoutborders/command/CommandGive.java index 408a0f2..a89d76f 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/command/CommandGive.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/command/CommandGive.java @@ -135,7 +135,7 @@ public class CommandGive implements TabExecutor { return null; } else if (argumentCount == 3) { //Number of copies - return TabCompletionHelper.getBooleansAndNumbers(1, 64); + return TabCompletionHelper.getBooleansAndNumbers(1, 3); } else if (argumentCount == 4) { //Signed try { diff --git a/src/main/java/net/knarcraft/bookswithoutborders/command/CommandLoad.java b/src/main/java/net/knarcraft/bookswithoutborders/command/CommandLoad.java index 117b659..39fd8d0 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/command/CommandLoad.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/command/CommandLoad.java @@ -3,16 +3,20 @@ package net.knarcraft.bookswithoutborders.command; import net.knarcraft.bookswithoutborders.BooksWithoutBorders; import net.knarcraft.bookswithoutborders.utility.FileHelper; import net.knarcraft.bookswithoutborders.utility.InputCleaningHelper; +import net.knarcraft.bookswithoutborders.utility.TabCompletionHelper; import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import java.util.ArrayList; +import java.util.List; + /** * Command executor for the load command */ -public class CommandLoad implements CommandExecutor { +public class CommandLoad implements TabExecutor { private final BooksWithoutBorders booksWithoutBorders = BooksWithoutBorders.getInstance(); @@ -89,4 +93,35 @@ public class CommandLoad implements CommandExecutor { } } + @Override + public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { + return doTabCompletion(sender, args, false); + } + + /** + * Performs the actual tab completion + * @param sender

The sender of the command

+ * @param args

The arguments given

+ * @param loadPublic

Whether to list public files or player files

+ * @return

A list of available choices

+ */ + protected List doTabCompletion(CommandSender sender, String[] args, boolean loadPublic) { + int argumentCount = args.length; + if (argumentCount == 1) { + //Return list of books + return BooksWithoutBorders.getAvailableBooks(sender, loadPublic); + } else if (argumentCount == 2) { + //Number of copies + return TabCompletionHelper.getBooleansAndNumbers(1, 3); + } else if (argumentCount == 3) { + //Signed + try { + Integer.parseInt(args[1]); + return TabCompletionHelper.getBooleans(); + } catch (NumberFormatException e) { + return new ArrayList<>(); + } + } + return new ArrayList<>(); + } } diff --git a/src/main/java/net/knarcraft/bookswithoutborders/command/CommandLoadPublic.java b/src/main/java/net/knarcraft/bookswithoutborders/command/CommandLoadPublic.java index 41ce1df..0a1115e 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/command/CommandLoadPublic.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/command/CommandLoadPublic.java @@ -4,6 +4,8 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import java.util.List; + /** * Command executor for the load public command */ @@ -14,4 +16,9 @@ public class CommandLoadPublic extends CommandLoad implements CommandExecutor { return loadBook(sender, args, "public", true); } + @Override + public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { + return doTabCompletion(sender, args, true); + } + } diff --git a/src/main/java/net/knarcraft/bookswithoutborders/command/CommandSave.java b/src/main/java/net/knarcraft/bookswithoutborders/command/CommandSave.java index ec162f0..6444d58 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/command/CommandSave.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/command/CommandSave.java @@ -6,14 +6,16 @@ import net.knarcraft.bookswithoutborders.utility.BookToFromTextHelper; import net.knarcraft.bookswithoutborders.utility.FileHelper; import net.knarcraft.bookswithoutborders.utility.InventoryHelper; import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.BookMeta; import java.io.File; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import static net.knarcraft.bookswithoutborders.BooksWithoutBorders.getTitleAuthorSeparator; import static net.knarcraft.bookswithoutborders.BooksWithoutBordersSettings.getBookFolder; @@ -26,7 +28,7 @@ import static net.knarcraft.bookswithoutborders.utility.InputCleaningHelper.fixN /** * Command executor for the save command */ -public class CommandSave implements CommandExecutor { +public class CommandSave implements TabExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { @@ -144,4 +146,9 @@ public class CommandSave implements CommandExecutor { } } + + @Override + public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { + return new ArrayList<>(); + } } diff --git a/src/main/java/net/knarcraft/bookswithoutborders/command/CommandSavePublic.java b/src/main/java/net/knarcraft/bookswithoutborders/command/CommandSavePublic.java index 1b24240..b02eeae 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/command/CommandSavePublic.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/command/CommandSavePublic.java @@ -1,13 +1,13 @@ package net.knarcraft.bookswithoutborders.command; import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; /** * Command executor for the save public command */ -public class CommandSavePublic extends CommandSave implements CommandExecutor { +public class CommandSavePublic extends CommandSave implements TabExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { diff --git a/src/main/java/net/knarcraft/bookswithoutborders/command/CommandSetAuthor.java b/src/main/java/net/knarcraft/bookswithoutborders/command/CommandSetAuthor.java index a8ec855..bae8db6 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/command/CommandSetAuthor.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/command/CommandSetAuthor.java @@ -4,16 +4,19 @@ import net.knarcraft.bookswithoutborders.BooksWithoutBorders; import net.knarcraft.bookswithoutborders.state.ItemSlot; import net.knarcraft.bookswithoutborders.utility.InventoryHelper; import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.BookMeta; +import java.util.ArrayList; +import java.util.List; + /** * Command executor for the set author command */ -public class CommandSetAuthor implements CommandExecutor { +public class CommandSetAuthor implements TabExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { @@ -45,4 +48,12 @@ public class CommandSetAuthor implements CommandExecutor { return true; } + @Override + public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { + if (args.length == 1) { + return null; + } else { + return new ArrayList<>(); + } + } } diff --git a/src/main/java/net/knarcraft/bookswithoutborders/command/CommandSetBookPrice.java b/src/main/java/net/knarcraft/bookswithoutborders/command/CommandSetBookPrice.java index 885aeca..e191a5b 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/command/CommandSetBookPrice.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/command/CommandSetBookPrice.java @@ -3,17 +3,21 @@ package net.knarcraft.bookswithoutborders.command; import net.knarcraft.bookswithoutborders.BooksWithoutBorders; import net.knarcraft.bookswithoutborders.utility.EconomyHelper; import net.knarcraft.bookswithoutborders.utility.InventoryHelper; +import net.knarcraft.bookswithoutborders.utility.TabCompletionHelper; import org.bukkit.Material; import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import java.util.ArrayList; +import java.util.List; + /** * Command executor for the set book price command */ -public class CommandSetBookPrice implements CommandExecutor { +public class CommandSetBookPrice implements TabExecutor { private final BooksWithoutBorders booksWithoutBorders = BooksWithoutBorders.getInstance(); @@ -126,4 +130,18 @@ public class CommandSetBookPrice implements CommandExecutor { return false; } } + + @Override + public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { + int argumentCount = args.length; + if (argumentCount == 1) { + List paymentTypes = new ArrayList<>(); + paymentTypes.add("item"); + paymentTypes.add("eco"); + return paymentTypes; + } else if (argumentCount == 2) { + return TabCompletionHelper.getNumbers(1, 3); + } + return new ArrayList<>(); + } } diff --git a/src/main/java/net/knarcraft/bookswithoutborders/command/CommandSetTitle.java b/src/main/java/net/knarcraft/bookswithoutborders/command/CommandSetTitle.java index 7b0ab6f..61dab74 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/command/CommandSetTitle.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/command/CommandSetTitle.java @@ -5,17 +5,20 @@ import net.knarcraft.bookswithoutborders.utility.InventoryHelper; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.BookMeta; import org.bukkit.inventory.meta.ItemMeta; +import java.util.ArrayList; +import java.util.List; + /** * Command executor for the set title command */ -public class CommandSetTitle implements CommandExecutor { +public class CommandSetTitle implements TabExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { @@ -61,4 +64,10 @@ public class CommandSetTitle implements CommandExecutor { return true; } + @Override + public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { + List options = new ArrayList<>(); + options.add(""); + return options; + } } diff --git a/src/main/java/net/knarcraft/bookswithoutborders/command/CommandUnSign.java b/src/main/java/net/knarcraft/bookswithoutborders/command/CommandUnSign.java index 3a76f4a..510264b 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/command/CommandUnSign.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/command/CommandUnSign.java @@ -5,16 +5,19 @@ import net.knarcraft.bookswithoutborders.state.ItemSlot; import net.knarcraft.bookswithoutborders.utility.InventoryHelper; import org.bukkit.Material; import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.BookMeta; +import java.util.ArrayList; +import java.util.List; + /** * Command executor for the unsign command */ -public class CommandUnSign implements CommandExecutor { +public class CommandUnSign implements TabExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { @@ -50,4 +53,9 @@ public class CommandUnSign implements CommandExecutor { InventoryHelper.replaceHeldItem(player, newBook, mainHand); } + + @Override + public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { + return new ArrayList<>(); + } }