Adds missing tab completion

This commit is contained in:
Kristian Knarvik 2021-09-09 02:09:42 +02:00
parent 248d3be868
commit 852886e818
9 changed files with 110 additions and 15 deletions

View File

@ -135,7 +135,7 @@ public class CommandGive implements TabExecutor {
return null; return null;
} else if (argumentCount == 3) { } else if (argumentCount == 3) {
//Number of copies //Number of copies
return TabCompletionHelper.getBooleansAndNumbers(1, 64); return TabCompletionHelper.getBooleansAndNumbers(1, 3);
} else if (argumentCount == 4) { } else if (argumentCount == 4) {
//Signed //Signed
try { try {

View File

@ -3,16 +3,20 @@ package net.knarcraft.bookswithoutborders.command;
import net.knarcraft.bookswithoutborders.BooksWithoutBorders; import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
import net.knarcraft.bookswithoutborders.utility.FileHelper; import net.knarcraft.bookswithoutborders.utility.FileHelper;
import net.knarcraft.bookswithoutborders.utility.InputCleaningHelper; import net.knarcraft.bookswithoutborders.utility.InputCleaningHelper;
import net.knarcraft.bookswithoutborders.utility.TabCompletionHelper;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
/** /**
* Command executor for the load command * Command executor for the load command
*/ */
public class CommandLoad implements CommandExecutor { public class CommandLoad implements TabExecutor {
private final BooksWithoutBorders booksWithoutBorders = BooksWithoutBorders.getInstance(); private final BooksWithoutBorders booksWithoutBorders = BooksWithoutBorders.getInstance();
@ -89,4 +93,35 @@ public class CommandLoad implements CommandExecutor {
} }
} }
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
return doTabCompletion(sender, args, false);
}
/**
* Performs the actual tab completion
* @param sender <p>The sender of the command</p>
* @param args <p>The arguments given</p>
* @param loadPublic <p>Whether to list public files or player files</p>
* @return <p>A list of available choices</p>
*/
protected List<String> 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<>();
}
} }

View File

@ -4,6 +4,8 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import java.util.List;
/** /**
* Command executor for the load public command * Command executor for the load public command
*/ */
@ -14,4 +16,9 @@ public class CommandLoadPublic extends CommandLoad implements CommandExecutor {
return loadBook(sender, args, "public", true); return loadBook(sender, args, "public", true);
} }
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
return doTabCompletion(sender, args, true);
}
} }

View File

@ -6,14 +6,16 @@ import net.knarcraft.bookswithoutborders.utility.BookToFromTextHelper;
import net.knarcraft.bookswithoutborders.utility.FileHelper; import net.knarcraft.bookswithoutborders.utility.FileHelper;
import net.knarcraft.bookswithoutborders.utility.InventoryHelper; import net.knarcraft.bookswithoutborders.utility.InventoryHelper;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BookMeta; import org.bukkit.inventory.meta.BookMeta;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import static net.knarcraft.bookswithoutborders.BooksWithoutBorders.getTitleAuthorSeparator; import static net.knarcraft.bookswithoutborders.BooksWithoutBorders.getTitleAuthorSeparator;
import static net.knarcraft.bookswithoutborders.BooksWithoutBordersSettings.getBookFolder; 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 * Command executor for the save command
*/ */
public class CommandSave implements CommandExecutor { public class CommandSave implements TabExecutor {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
@ -144,4 +146,9 @@ public class CommandSave implements CommandExecutor {
} }
} }
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
return new ArrayList<>();
}
} }

View File

@ -1,13 +1,13 @@
package net.knarcraft.bookswithoutborders.command; package net.knarcraft.bookswithoutborders.command;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
/** /**
* Command executor for the save public command * Command executor for the save public command
*/ */
public class CommandSavePublic extends CommandSave implements CommandExecutor { public class CommandSavePublic extends CommandSave implements TabExecutor {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {

View File

@ -4,16 +4,19 @@ import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
import net.knarcraft.bookswithoutborders.state.ItemSlot; import net.knarcraft.bookswithoutborders.state.ItemSlot;
import net.knarcraft.bookswithoutborders.utility.InventoryHelper; import net.knarcraft.bookswithoutborders.utility.InventoryHelper;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BookMeta; import org.bukkit.inventory.meta.BookMeta;
import java.util.ArrayList;
import java.util.List;
/** /**
* Command executor for the set author command * Command executor for the set author command
*/ */
public class CommandSetAuthor implements CommandExecutor { public class CommandSetAuthor implements TabExecutor {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
@ -45,4 +48,12 @@ public class CommandSetAuthor implements CommandExecutor {
return true; return true;
} }
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
if (args.length == 1) {
return null;
} else {
return new ArrayList<>();
}
}
} }

View File

@ -3,17 +3,21 @@ package net.knarcraft.bookswithoutborders.command;
import net.knarcraft.bookswithoutborders.BooksWithoutBorders; import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
import net.knarcraft.bookswithoutborders.utility.EconomyHelper; import net.knarcraft.bookswithoutborders.utility.EconomyHelper;
import net.knarcraft.bookswithoutborders.utility.InventoryHelper; import net.knarcraft.bookswithoutborders.utility.InventoryHelper;
import net.knarcraft.bookswithoutborders.utility.TabCompletionHelper;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
/** /**
* Command executor for the set book price command * Command executor for the set book price command
*/ */
public class CommandSetBookPrice implements CommandExecutor { public class CommandSetBookPrice implements TabExecutor {
private final BooksWithoutBorders booksWithoutBorders = BooksWithoutBorders.getInstance(); private final BooksWithoutBorders booksWithoutBorders = BooksWithoutBorders.getInstance();
@ -126,4 +130,18 @@ public class CommandSetBookPrice implements CommandExecutor {
return false; return false;
} }
} }
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
int argumentCount = args.length;
if (argumentCount == 1) {
List<String> paymentTypes = new ArrayList<>();
paymentTypes.add("item");
paymentTypes.add("eco");
return paymentTypes;
} else if (argumentCount == 2) {
return TabCompletionHelper.getNumbers(1, 3);
}
return new ArrayList<>();
}
} }

View File

@ -5,17 +5,20 @@ import net.knarcraft.bookswithoutborders.utility.InventoryHelper;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BookMeta; import org.bukkit.inventory.meta.BookMeta;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.List;
/** /**
* Command executor for the set title command * Command executor for the set title command
*/ */
public class CommandSetTitle implements CommandExecutor { public class CommandSetTitle implements TabExecutor {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
@ -61,4 +64,10 @@ public class CommandSetTitle implements CommandExecutor {
return true; return true;
} }
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
List<String> options = new ArrayList<>();
options.add("<new title>");
return options;
}
} }

View File

@ -5,16 +5,19 @@ import net.knarcraft.bookswithoutborders.state.ItemSlot;
import net.knarcraft.bookswithoutborders.utility.InventoryHelper; import net.knarcraft.bookswithoutborders.utility.InventoryHelper;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BookMeta; import org.bukkit.inventory.meta.BookMeta;
import java.util.ArrayList;
import java.util.List;
/** /**
* Command executor for the unsign command * Command executor for the unsign command
*/ */
public class CommandUnSign implements CommandExecutor { public class CommandUnSign implements TabExecutor {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { 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); InventoryHelper.replaceHeldItem(player, newBook, mainHand);
} }
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
return new ArrayList<>();
}
} }