Renames most commands and uses the built-in spigot command system for command info

This commit is contained in:
Kristian Knarvik 2021-09-02 14:27:56 +02:00
parent baedfba196
commit fba0f14995
4 changed files with 89 additions and 136 deletions

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>net.knarcraft</groupId> <groupId>net.knarcraft</groupId>
<artifactId>books-without-borders</artifactId> <artifactId>BooksWithoutBorders</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>

View File

@ -105,25 +105,25 @@ public class BooksWithoutBorders extends JavaPlugin {
* Registers all commands used by this plugin * Registers all commands used by this plugin
*/ */
private void registerCommands() { private void registerCommands() {
registerCommand("give", new CommandGive(), new GiveTabCompleter()); registerCommand("giveBook", new CommandGive(), new GiveTabCompleter());
registerCommand("decrypt", new CommandDecrypt(), null); registerCommand("decryptBook", new CommandDecrypt(), null);
registerCommand("groupEncrypt", new CommandGroupEncrypt(), null); registerCommand("groupEncryptBook", new CommandGroupEncrypt(), null);
registerCommand("delete", new CommandDelete(), null); registerCommand("deleteBook", new CommandDelete(), null);
registerCommand("deletePublic", new CommandDeletePublic(), null); registerCommand("deletePublicBook", new CommandDeletePublic(), null);
registerCommand("copy", new CommandCopy(), null); registerCommand("copyBook", new CommandCopy(), null);
registerCommand("unSign", new CommandUnSign(), null); registerCommand("unSignBook", new CommandUnSign(), null);
registerCommand("encrypt", new CommandEncrypt(), null); registerCommand("encryptBook", new CommandEncrypt(), null);
registerCommand("setBookPrice", new CommandSetBookPrice(), null); registerCommand("setBookPrice", new CommandSetBookPrice(), null);
registerCommand("setLore", new CommandSetLore(), null); registerCommand("setLore", new CommandSetLore(), null);
registerCommand("savePublic", new CommandSavePublic(), null); registerCommand("savePublicBook", new CommandSavePublic(), null);
registerCommand("save", new CommandSave(), null); registerCommand("saveBook", new CommandSave(), null);
registerCommand("setAuthor", new CommandSetAuthor(), null); registerCommand("setBookAuthor", new CommandSetAuthor(), null);
registerCommand("setTitle", new CommandSetTitle(), null); registerCommand("setTitle", new CommandSetTitle(), null);
registerCommand("load", new CommandLoad(), null); registerCommand("loadBook", new CommandLoad(), null);
registerCommand("loadPublic", new CommandLoadPublic(), null); registerCommand("loadPublicBook", new CommandLoadPublic(), null);
registerCommand("booksWithoutBorders", new CommandBooksWithoutBorders(), null); registerCommand("booksWithoutBorders", new CommandBooksWithoutBorders(), null);
registerCommand("reload", new CommandReload(), null); registerCommand("reload", new CommandReload(), null);
registerCommand("givePublic", new CommandGivePublic(), null); registerCommand("givePublicBook", new CommandGivePublic(), null);
} }
/** /**

View File

@ -6,12 +6,12 @@ import org.bukkit.Material;
import org.bukkit.command.Command; 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 org.bukkit.command.PluginCommand;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import static net.knarcraft.bookswithoutborders.BooksWithoutBorders.bookPriceQuantity; import static net.knarcraft.bookswithoutborders.BooksWithoutBorders.bookPriceQuantity;
import static net.knarcraft.bookswithoutborders.BooksWithoutBorders.bookPriceType; import static net.knarcraft.bookswithoutborders.BooksWithoutBorders.bookPriceType;
import static net.knarcraft.bookswithoutborders.BooksWithoutBorders.sendErrorMessage; 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.getCommandColor;
import static net.knarcraft.bookswithoutborders.BooksWithoutBordersSettings.getSuccessColor; import static net.knarcraft.bookswithoutborders.BooksWithoutBordersSettings.getSuccessColor;
@ -24,6 +24,9 @@ public class CommandBooksWithoutBorders implements CommandExecutor {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { 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) { if (sender instanceof Player) {
showPlayerCommands(sender); showPlayerCommands(sender);
} else { } else {
@ -38,16 +41,10 @@ public class CommandBooksWithoutBorders implements CommandExecutor {
* @param sender <p>The console which sent the command</p> * @param sender <p>The console which sent the command</p>
*/ */
private void showConsoleCommands(CommandSender sender) { private void showConsoleCommands(CommandSender sender) {
sender.sendMessage(getCommandColor() + "Use: /bwb [Command]");
sender.sendMessage(getCommandColor() + "[] denote parameters");
sender.sendMessage(getCommandColor() + "Commands:"); sender.sendMessage(getCommandColor() + "Commands:");
sender.sendMessage(getCommandColor() + "\nReload:" + getSuccessColor() + " Reloads BwB's config file"); showCommandInfo("reload", sender);
sender.sendMessage(getCommandColor() + "givePublic [file name or number] [player name] [true/false]: " + getSuccessColor()); showCommandInfo("givePublicBook", sender);
sendSuccessMessage(sender, "Gives the selected player a book from the public directory"); showCommandInfo("deletePublicBook", sender);
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");
} }
/** /**
@ -57,9 +54,6 @@ public class CommandBooksWithoutBorders implements CommandExecutor {
*/ */
private void showPlayerCommands(CommandSender sender) { private void showPlayerCommands(CommandSender sender) {
//Lists all commands //Lists all commands
sender.sendMessage(getCommandColor() + "Use: /bwb [Command]");
sender.sendMessage(getCommandColor() + "[] denote parameters");
if (booksWithoutBorders.booksHavePrice()) { if (booksWithoutBorders.booksHavePrice()) {
if (bookPriceType != Material.AIR) { if (bookPriceType != Material.AIR) {
sendErrorMessage(sender, "[" + (int) bookPriceQuantity + " " + bookPriceType.toString() + "(s) are required to create a book]"); 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:"); sender.sendMessage(getCommandColor() + "Commands:");
if (sender.hasPermission("bookswithoutborders.load")) { showCommandInfo("loadBook", sender);
sender.sendMessage(getCommandColor() + "\nLoad [file name or number] [# of copies] [true/false]:"); showCommandInfo("loadPublicBook", sender);
sendSuccessMessage(sender, "Creates a book from the specified file and gives it to the player"); showCommandInfo("saveBook", sender);
sendSuccessMessage(sender, "If no file is specified, a list of available files is returned"); showCommandInfo("savePublicBook", sender);
sendSuccessMessage(sender, "If true is specified the book will be signed, if false it will be"); showCommandInfo("giveBook", sender);
sendSuccessMessage(sender, "unsigned"); showCommandInfo("givePublicBook", sender);
} showCommandInfo("deleteBook", sender);
if (sender.hasPermission("bookswithoutborders.loadPublic")) { showCommandInfo("deletePublicBook", sender);
sender.sendMessage(getCommandColor() + "loadPublic [file name or number] [# of copies] [true/false]:"); showCommandInfo("unsignBook", sender);
sendSuccessMessage(sender, "Same as Load, but views files in the public directory"); showCommandInfo("copyBook", sender);
} showCommandInfo("encryptBook", sender);
if (sender.hasPermission("bookswithoutborders.save")) { showCommandInfo("groupEncryptBook", sender);
sender.sendMessage("\n" + getCommandColor() + "Save [true/false]: " + getSuccessColor() + "Saves the book the player is"); showCommandInfo("decryptBook", sender);
sendSuccessMessage(sender, "holding to a text file in a private directory"); showCommandInfo("setTitle", sender);
sendSuccessMessage(sender, "If true is specified, a book of the same name by the same"); showCommandInfo("setAuthor", sender);
sendSuccessMessage(sender, "author will be overwritten by the new book"); showCommandInfo("setLore", sender);
} showCommandInfo("setBookPrice", sender);
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");
} }
if (sender.hasPermission("bookswithoutborders.unsign")) { /**
sender.sendMessage("\n" + getCommandColor() + "Unsign: " + getSuccessColor() + "Un-signs the book the player is holding"); * 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());
} }
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.");
} }
} }

View File

@ -13,76 +13,76 @@ commands:
description: Lists Books Without Borders's commands and uses. description: Lists Books Without Borders's commands and uses.
aliases: [ bwb ] aliases: [ bwb ]
usage: /<command> usage: /<command>
give: givebook:
description: Gives the held book to another player description: Gives the selected player a book from your personal directory
usage: /<command> <file name or number> <playername> [# of copies (num)] [signed (true/false)] usage: /<command> <file name or number> <playername> [# of copies (num)] [signed (true/false)]
permission: bookswithoutborders.give permission: bookswithoutborders.give
givepublic: givepublicbook:
description: Gives a public book to a player description: Same as givebook, but uses books from the public directory
usage: /<command> <file name or number> <playername> [# of copies (num)] [signed (true/false)] usage: /<command> <file name or number> <playername> [# of copies (num)] [signed (true/false)]
permission: bookswithoutborders.givepublic permission: bookswithoutborders.givepublic
decrypt: decryptbook:
description: Decrypts the held book description: Decrypts the book the player is holding. "key" is required and MUST be IDENTICAL to the key used to encrypt held book
usage: /<command> <key> usage: /<command> <key>
permission: bookswithoutborders.decrypt permission: bookswithoutborders.decrypt
groupencrypt: groupencryptbook:
description: Encrypts the held book for the given group description: Encrypts book so that only players with the bookswithoutborders.decrypt.<group name> permission may decrypt the book by holding and left clicking the book
usage: /<command> <group name> <key> [encryption style] usage: /<command> <group name> <key> [encryption style]
permission: bookswithoutborders.groupencrypt permission: bookswithoutborders.groupencrypt
delete: deletebook:
description: Deletes a book saved by the executing user description: Deletes the specified file in the player's directory
usage: /<command> <file name or number> usage: /<command> <file name or number>
permission: bookswithoutborders.delete permission: bookswithoutborders.delete
deletepublic: deletepublicbook:
description: Deletes a public book description: Same as deletebook, but deletes files in the public directory
usage: /<command> <file name of number> usage: /<command> <file name of number>
permission: bookswithoutborders.admin permission: bookswithoutborders.admin
copy: copybook:
description: Copies the held book description: Copies the book the player is holding
usage: /<command> <copies> usage: /<command> <# of copies>
permission: bookswithoutborders.copy permission: bookswithoutborders.copy
unsign: unsignbook:
description: Un-signs the held book, making it writable description: Un-signs the book the player is holding
usage: /<command> usage: /<command>
permission: bookswithoutborders.unsign permission: bookswithoutborders.unsign
encrypt: encryptbook:
description: Encrypts the held book description: Encrypts the book the player is holding. "key" is required and can be any phrase or number excluding spaces. "style" is not required. Possible values are "DNA" or ""
usage: /<command> <key> [encryption style] usage: /<command> <key> [encryption style]
permission: bookswithoutborders.encrypt permission: bookswithoutborders.encrypt
setbookprice: setbookprice:
description: Sets the price for copying books to a money sum or the held item description: Sets the per-book-price to create a book via commands. If "Item", the item in the player's hand in the amount of [quantity] will be the price. If "Eco", a Vault based economy will be used for price. If neither <Item/Eco> or <quantity> are specified the current price to create books will be removed.
usage: /<command> <item/eco> <quantity> usage: /<command> <item/eco> <quantity>
permission: bookswithoutborders.setbookprice permission: bookswithoutborders.setbookprice
setlore: setlore:
description: Sets the lore of the held item description: Sets the lore of the item the player is holding. Insert the lore_line_separator character to force a new line ("~" by default).
usage: /<command> <new lore> usage: /<command> <new lore>
permission: bookswithoutborders.setlore permission: bookswithoutborders.setlore
savepublic: savepublicbook:
description: Saves the held book to the public books folder description: Same as savebook, but saves files in the public directory
usage: /<command> [overwrite (true/false)] usage: /<command> [overwrite (true/false)]
permission: bookswithoutborders.savepublic permission: bookswithoutborders.savepublic
save: savebook:
description: Saves the held book to the holding player's folder description: Saves the book the player is holding to a text file in a private directory. If true is specified, a book of the same name by the same author will be overwritten by the new book
usage: /<command> [overwrite (true/false)] usage: /<command> [overwrite (true/false)]
permission: bookswithoutborders.save permission: bookswithoutborders.save
setauthor: setbookauthor:
description: Sets the author of the held book description: Sets the author of the book the player is holding
usage: /<command> <author> usage: /<command> <author>
permission: bookswithoutborders.setauthor permission: bookswithoutborders.setauthor
settitle: settitle:
description: Sets the title of the held book description: Sets the title of the book/item the player is holding
usage: /<command> <title> usage: /<command> <title>
permission: bookswithoutborders.settitle permission: bookswithoutborders.settitle
load: loadbook:
description: Loads a previously saved book from the holding player's folder description: Creates a book from the specified file and gives it to the player. If no file is specified, a list of available files is returned. If true is specified the book will be signed, if false it will be unsigned
usage: /<command> <file name or number> [copies] [is signed (true/false)] usage: /<command> <file name or number> [# of copies] [signed (true/false)]
permission: bookswithoutborders.load permission: bookswithoutborders.load
loadpublic: loadpublicbook:
description: Loads a previously saved book from the public books folder description: Same as loadbook, but views files in the public directory
usage: /<command> <file name or number> [copies] [is signed (true/false)] usage: /<command> <file name or number> [# of copies] [signed (true/false)]
permission: bookswithoutborders.loadpublic permission: bookswithoutborders.loadpublic
reload: reload:
description: Reloads configuration from disk description: Reloads BwB's configuration file
usage: /<command> usage: /<command>
permission: bookswithoutborders.admin permission: bookswithoutborders.admin
permissions: permissions: