Adds tab completion to the delete command
This commit is contained in:
parent
620894f0b1
commit
83c639b7f6
@ -4,11 +4,12 @@ import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
|
||||
import net.knarcraft.bookswithoutborders.utility.FileHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.InputCleaningHelper;
|
||||
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 java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static net.knarcraft.bookswithoutborders.BooksWithoutBordersSettings.getBookFolder;
|
||||
@ -17,7 +18,7 @@ import static net.knarcraft.bookswithoutborders.BooksWithoutBordersSettings.getS
|
||||
/**
|
||||
* Command executor for the delete command
|
||||
*/
|
||||
public class CommandDelete implements CommandExecutor {
|
||||
public class CommandDelete implements TabExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
@ -46,19 +47,14 @@ public class CommandDelete implements CommandExecutor {
|
||||
//Delete the file
|
||||
if (args.length == 1) {
|
||||
List<String> availableBooks = BooksWithoutBorders.getAvailableBooks(sender, deletePublic);
|
||||
if (availableBooks == null) {
|
||||
BooksWithoutBorders.sendErrorMessage(sender, "You must first use /deletebook to create a list of delete-able files!");
|
||||
return false;
|
||||
if (!availableBooks.isEmpty()) {
|
||||
performBookDeletion(sender, args[0], deletePublic);
|
||||
//Update the book list
|
||||
BooksWithoutBorders.updateBooks(sender, deletePublic);
|
||||
return true;
|
||||
} else {
|
||||
if (!availableBooks.isEmpty()) {
|
||||
performBookDeletion(sender, args[0], deletePublic);
|
||||
//Update the book list
|
||||
BooksWithoutBorders.updateBooks(sender, deletePublic);
|
||||
return true;
|
||||
} else {
|
||||
BooksWithoutBorders.sendErrorMessage(sender, "No files available to delete!");
|
||||
return false;
|
||||
}
|
||||
BooksWithoutBorders.sendErrorMessage(sender, "No files available to delete!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
BooksWithoutBorders.sendErrorMessage(sender, "Incorrect number of arguments for this command!");
|
||||
@ -110,4 +106,24 @@ public class CommandDelete implements CommandExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
return doTabCompletion(sender, args, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs tab completion
|
||||
* @param sender <p>The sender of the command</p>
|
||||
* @param args <p>The arguments given</p>
|
||||
* @param deletePublic <p>Whether to delete a public book</p>
|
||||
* @return <p>A list of available arguments</p>
|
||||
*/
|
||||
protected List<String> doTabCompletion(CommandSender sender, String[] args, boolean deletePublic) {
|
||||
int argumentCount = args.length;
|
||||
if (argumentCount == 1) {
|
||||
return BooksWithoutBorders.getAvailableBooks(sender, deletePublic);
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user