Renames most commands and uses the built-in spigot command system for command info
This commit is contained in:
@ -105,25 +105,25 @@ public class BooksWithoutBorders extends JavaPlugin {
|
||||
* Registers all commands used by this plugin
|
||||
*/
|
||||
private void registerCommands() {
|
||||
registerCommand("give", new CommandGive(), new GiveTabCompleter());
|
||||
registerCommand("decrypt", new CommandDecrypt(), null);
|
||||
registerCommand("groupEncrypt", new CommandGroupEncrypt(), null);
|
||||
registerCommand("delete", new CommandDelete(), null);
|
||||
registerCommand("deletePublic", new CommandDeletePublic(), null);
|
||||
registerCommand("copy", new CommandCopy(), null);
|
||||
registerCommand("unSign", new CommandUnSign(), null);
|
||||
registerCommand("encrypt", new CommandEncrypt(), null);
|
||||
registerCommand("giveBook", new CommandGive(), new GiveTabCompleter());
|
||||
registerCommand("decryptBook", new CommandDecrypt(), null);
|
||||
registerCommand("groupEncryptBook", new CommandGroupEncrypt(), null);
|
||||
registerCommand("deleteBook", new CommandDelete(), null);
|
||||
registerCommand("deletePublicBook", new CommandDeletePublic(), null);
|
||||
registerCommand("copyBook", new CommandCopy(), null);
|
||||
registerCommand("unSignBook", new CommandUnSign(), null);
|
||||
registerCommand("encryptBook", new CommandEncrypt(), null);
|
||||
registerCommand("setBookPrice", new CommandSetBookPrice(), null);
|
||||
registerCommand("setLore", new CommandSetLore(), null);
|
||||
registerCommand("savePublic", new CommandSavePublic(), null);
|
||||
registerCommand("save", new CommandSave(), null);
|
||||
registerCommand("setAuthor", new CommandSetAuthor(), null);
|
||||
registerCommand("savePublicBook", new CommandSavePublic(), null);
|
||||
registerCommand("saveBook", new CommandSave(), null);
|
||||
registerCommand("setBookAuthor", new CommandSetAuthor(), null);
|
||||
registerCommand("setTitle", new CommandSetTitle(), null);
|
||||
registerCommand("load", new CommandLoad(), null);
|
||||
registerCommand("loadPublic", new CommandLoadPublic(), null);
|
||||
registerCommand("loadBook", new CommandLoad(), null);
|
||||
registerCommand("loadPublicBook", new CommandLoadPublic(), null);
|
||||
registerCommand("booksWithoutBorders", new CommandBooksWithoutBorders(), null);
|
||||
registerCommand("reload", new CommandReload(), null);
|
||||
registerCommand("givePublic", new CommandGivePublic(), null);
|
||||
registerCommand("givePublicBook", new CommandGivePublic(), null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -6,12 +6,12 @@ import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import static net.knarcraft.bookswithoutborders.BooksWithoutBorders.bookPriceQuantity;
|
||||
import static net.knarcraft.bookswithoutborders.BooksWithoutBorders.bookPriceType;
|
||||
import static net.knarcraft.bookswithoutborders.BooksWithoutBorders.sendErrorMessage;
|
||||
import static net.knarcraft.bookswithoutborders.BooksWithoutBorders.sendSuccessMessage;
|
||||
import static net.knarcraft.bookswithoutborders.BooksWithoutBordersSettings.getCommandColor;
|
||||
import static net.knarcraft.bookswithoutborders.BooksWithoutBordersSettings.getSuccessColor;
|
||||
|
||||
@ -24,6 +24,9 @@ public class CommandBooksWithoutBorders implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
sender.sendMessage(getCommandColor() + "[] denote optional parameters");
|
||||
sender.sendMessage(getCommandColor() + "<> denote required parameters");
|
||||
sender.sendMessage(getCommandColor() + "In some cases, commands with required parameters can be called with no parameters");
|
||||
if (sender instanceof Player) {
|
||||
showPlayerCommands(sender);
|
||||
} else {
|
||||
@ -38,16 +41,10 @@ public class CommandBooksWithoutBorders implements CommandExecutor {
|
||||
* @param sender <p>The console which sent the command</p>
|
||||
*/
|
||||
private void showConsoleCommands(CommandSender sender) {
|
||||
sender.sendMessage(getCommandColor() + "Use: /bwb [Command]");
|
||||
sender.sendMessage(getCommandColor() + "[] denote parameters");
|
||||
sender.sendMessage(getCommandColor() + "Commands:");
|
||||
sender.sendMessage(getCommandColor() + "\nReload:" + getSuccessColor() + " Reloads BwB's config file");
|
||||
sender.sendMessage(getCommandColor() + "givePublic [file name or number] [player name] [true/false]: " + getSuccessColor());
|
||||
sendSuccessMessage(sender, "Gives the selected player a book from the public directory");
|
||||
sendSuccessMessage(sender, "If no file is specified, a list of available files is returned");
|
||||
sender.sendMessage(getCommandColor() + "deletePublic [file name or number]: " + getSuccessColor() + "Deletes the specified");
|
||||
sendSuccessMessage(sender, "file in the public directory");
|
||||
sendSuccessMessage(sender, "If no file is specified, a list of available files is returned");
|
||||
showCommandInfo("reload", sender);
|
||||
showCommandInfo("givePublicBook", sender);
|
||||
showCommandInfo("deletePublicBook", sender);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -57,9 +54,6 @@ public class CommandBooksWithoutBorders implements CommandExecutor {
|
||||
*/
|
||||
private void showPlayerCommands(CommandSender sender) {
|
||||
//Lists all commands
|
||||
sender.sendMessage(getCommandColor() + "Use: /bwb [Command]");
|
||||
sender.sendMessage(getCommandColor() + "[] denote parameters");
|
||||
|
||||
if (booksWithoutBorders.booksHavePrice()) {
|
||||
if (bookPriceType != Material.AIR) {
|
||||
sendErrorMessage(sender, "[" + (int) bookPriceQuantity + " " + bookPriceType.toString() + "(s) are required to create a book]");
|
||||
@ -69,80 +63,39 @@ public class CommandBooksWithoutBorders implements CommandExecutor {
|
||||
}
|
||||
sender.sendMessage(getCommandColor() + "Commands:");
|
||||
|
||||
if (sender.hasPermission("bookswithoutborders.load")) {
|
||||
sender.sendMessage(getCommandColor() + "\nLoad [file name or number] [# of copies] [true/false]:");
|
||||
sendSuccessMessage(sender, "Creates a book from the specified file and gives it to the player");
|
||||
sendSuccessMessage(sender, "If no file is specified, a list of available files is returned");
|
||||
sendSuccessMessage(sender, "If true is specified the book will be signed, if false it will be");
|
||||
sendSuccessMessage(sender, "unsigned");
|
||||
}
|
||||
if (sender.hasPermission("bookswithoutborders.loadPublic")) {
|
||||
sender.sendMessage(getCommandColor() + "loadPublic [file name or number] [# of copies] [true/false]:");
|
||||
sendSuccessMessage(sender, "Same as Load, but views files in the public directory");
|
||||
}
|
||||
if (sender.hasPermission("bookswithoutborders.save")) {
|
||||
sender.sendMessage("\n" + getCommandColor() + "Save [true/false]: " + getSuccessColor() + "Saves the book the player is");
|
||||
sendSuccessMessage(sender, "holding to a text file in a private directory");
|
||||
sendSuccessMessage(sender, "If true is specified, a book of the same name by the same");
|
||||
sendSuccessMessage(sender, "author will be overwritten by the new book");
|
||||
}
|
||||
if (sender.hasPermission("bookswithoutborders.savePublic")) {
|
||||
sender.sendMessage(getCommandColor() + "savePublic [true/false]: " + getSuccessColor() + "Same as Save,");
|
||||
sendSuccessMessage(sender, "but saves files in the public directory");
|
||||
}
|
||||
if (sender.hasPermission("bookswithoutborders.give")) {
|
||||
sender.sendMessage("\n" + getCommandColor() + "Give [file name or number] [player name] [# of copies] [true/false]:");
|
||||
sendSuccessMessage(sender, "Gives the selected player a book from your personal directory");
|
||||
}
|
||||
if (sender.hasPermission("bookswithoutborders.givePublic")) {
|
||||
sender.sendMessage(getCommandColor() + "givePublic [file name or number] [player name] [# of copies] [true/false]:");
|
||||
sendSuccessMessage(sender, "Same as give, but uses books from the public directory");
|
||||
}
|
||||
if (sender.hasPermission("bookswithoutborders.delete")) {
|
||||
sender.sendMessage(getCommandColor() + "\nDelete [file name or number]: " + getSuccessColor() + "Deletes the specified");
|
||||
sendSuccessMessage(sender, "file in the player's directory");
|
||||
sendSuccessMessage(sender, "If no file is specified, a list of available files is returned");
|
||||
}
|
||||
if (sender.hasPermission("bookswithoutborders.admin")) {
|
||||
sender.sendMessage(getCommandColor() + "deletePublic [file name or number]: " + getSuccessColor() + "Same as Delete,");
|
||||
sendSuccessMessage(sender, "but deletes files in the public directory");
|
||||
sender.sendMessage(getCommandColor() + "\nReload:" + getSuccessColor() + " Reloads BwB's configuration file");
|
||||
}
|
||||
showCommandInfo("loadBook", sender);
|
||||
showCommandInfo("loadPublicBook", sender);
|
||||
showCommandInfo("saveBook", sender);
|
||||
showCommandInfo("savePublicBook", sender);
|
||||
showCommandInfo("giveBook", sender);
|
||||
showCommandInfo("givePublicBook", sender);
|
||||
showCommandInfo("deleteBook", sender);
|
||||
showCommandInfo("deletePublicBook", sender);
|
||||
showCommandInfo("unsignBook", sender);
|
||||
showCommandInfo("copyBook", sender);
|
||||
showCommandInfo("encryptBook", sender);
|
||||
showCommandInfo("groupEncryptBook", sender);
|
||||
showCommandInfo("decryptBook", sender);
|
||||
showCommandInfo("setTitle", sender);
|
||||
showCommandInfo("setAuthor", sender);
|
||||
showCommandInfo("setLore", sender);
|
||||
showCommandInfo("setBookPrice", sender);
|
||||
}
|
||||
|
||||
if (sender.hasPermission("bookswithoutborders.unsign")) {
|
||||
sender.sendMessage("\n" + getCommandColor() + "Unsign: " + getSuccessColor() + "Un-signs the book the player is holding");
|
||||
}
|
||||
if (sender.hasPermission("bookswithoutborders.copy")) {
|
||||
sender.sendMessage("\n" + getCommandColor() + "Copy [number of copies]: " + getSuccessColor() + "Copies the book the player is holding");
|
||||
}
|
||||
|
||||
if (sender.hasPermission("bookswithoutborders.encrypt")) {
|
||||
sender.sendMessage("\n" + getCommandColor() + "Encrypt [key] [style]: " + getSuccessColor() + "Encrypts the book the player is holding");
|
||||
sender.sendMessage(getCommandColor() + "[key]" + getSuccessColor() + " is required and can be any phrase or number excluding spaces");
|
||||
sender.sendMessage(getCommandColor() + "[style]" + getSuccessColor() + " is not required. Possible values are \"DNA\" or \"Magic\"");
|
||||
}
|
||||
if (sender.hasPermission("bookswithoutborders.groupEncrypt")) {
|
||||
sender.sendMessage("\n" + getCommandColor() + "groupEncrypt [group name] [key] [style]: " + getSuccessColor() + "Encrypts book so that only players with the" +
|
||||
"\n bookswithoutborders.decrypt." + getCommandColor() + "[group name]" + getSuccessColor() + " permission may decrypt the book by holding and left clicking the book");
|
||||
}
|
||||
if (sender.hasPermission("bookswithoutborders.decrypt")) {
|
||||
sender.sendMessage("\n" + getCommandColor() + "Decrypt [key]: " + getSuccessColor() + "Decrypts the book the player is holding");
|
||||
sender.sendMessage(getCommandColor() + "[key]" + getSuccessColor() + " is required and MUST be IDENTICAL to the key used to encrypt held book");
|
||||
}
|
||||
if (sender.hasPermission("bookswithoutborders.setTitle")) {
|
||||
sender.sendMessage("\n" + getCommandColor() + "setTitle [title]: " + getSuccessColor() + "Sets the title of the book/item the player is holding");
|
||||
}
|
||||
if (sender.hasPermission("bookswithoutborders.setAuthor")) {
|
||||
sender.sendMessage("\n" + getCommandColor() + "setAuthor [author]: " + getSuccessColor() + "Sets the author of the book the player is holding");
|
||||
}
|
||||
if (sender.hasPermission("bookswithoutborders.setLore")) {
|
||||
sender.sendMessage("\n" + getCommandColor() + "setLore [lore]: " + getSuccessColor() + "Sets the lore of the item the player is holding");
|
||||
sendSuccessMessage(sender, "Insert the lore_line_separator character to force a new line\n[\"~\" by default]");
|
||||
}
|
||||
if (sender.hasPermission("bookswithoutborders.setBookPrice")) {
|
||||
sender.sendMessage("\n" + getCommandColor() + "setBookPrice [Item/Eco] [quantity]: " + getSuccessColor() + "Sets the per-book-price to create a book via commands." +
|
||||
"\nIf [Item], the item in the player's hand in the amount of [quantity] will be the price.\nIf [Eco], a Vault based economy will be used for price." +
|
||||
"\nIf neither [Item/Eco] or [quantity] are specified the current price to create books will be removed.");
|
||||
/**
|
||||
* Shows information about the given command
|
||||
* @param command <p>The command to get information about</p>
|
||||
* @param sender <p>The sender asking to see command info</p>
|
||||
*/
|
||||
private void showCommandInfo(String command, CommandSender sender) {
|
||||
PluginCommand pluginCommand = BooksWithoutBorders.getInstance().getCommand(command);
|
||||
if (pluginCommand != null) {
|
||||
String permission = pluginCommand.getPermission();
|
||||
if (permission == null || sender.hasPermission(permission)) {
|
||||
sender.sendMessage("\n" + getCommandColor() +
|
||||
pluginCommand.getUsage().replace("<command>", pluginCommand.getName()) + ": " +
|
||||
getSuccessColor() + pluginCommand.getDescription());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user