Adds missing tab completion
This commit is contained in:
parent
248d3be868
commit
852886e818
@ -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 {
|
||||
|
@ -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<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<>();
|
||||
}
|
||||
}
|
||||
|
@ -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<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
return doTabCompletion(sender, args, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
if (args.length == 1) {
|
||||
return null;
|
||||
} else {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<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<>();
|
||||
}
|
||||
}
|
||||
|
@ -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<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
List<String> options = new ArrayList<>();
|
||||
options.add("<new title>");
|
||||
return options;
|
||||
}
|
||||
}
|
||||
|
@ -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<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user