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>
<groupId>net.knarcraft</groupId>
<artifactId>books-without-borders</artifactId>
<artifactId>BooksWithoutBorders</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

View File

@ -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);
}
/**

View File

@ -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());
}
}
}

View File

@ -13,76 +13,76 @@ commands:
description: Lists Books Without Borders's commands and uses.
aliases: [ bwb ]
usage: /<command>
give:
description: Gives the held book to another player
givebook:
description: Gives the selected player a book from your personal directory
usage: /<command> <file name or number> <playername> [# of copies (num)] [signed (true/false)]
permission: bookswithoutborders.give
givepublic:
description: Gives a public book to a player
givepublicbook:
description: Same as givebook, but uses books from the public directory
usage: /<command> <file name or number> <playername> [# of copies (num)] [signed (true/false)]
permission: bookswithoutborders.givepublic
decrypt:
description: Decrypts the held book
decryptbook:
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>
permission: bookswithoutborders.decrypt
groupencrypt:
description: Encrypts the held book for the given group
groupencryptbook:
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]
permission: bookswithoutborders.groupencrypt
delete:
description: Deletes a book saved by the executing user
deletebook:
description: Deletes the specified file in the player's directory
usage: /<command> <file name or number>
permission: bookswithoutborders.delete
deletepublic:
description: Deletes a public book
deletepublicbook:
description: Same as deletebook, but deletes files in the public directory
usage: /<command> <file name of number>
permission: bookswithoutborders.admin
copy:
description: Copies the held book
usage: /<command> <copies>
copybook:
description: Copies the book the player is holding
usage: /<command> <# of copies>
permission: bookswithoutborders.copy
unsign:
description: Un-signs the held book, making it writable
unsignbook:
description: Un-signs the book the player is holding
usage: /<command>
permission: bookswithoutborders.unsign
encrypt:
description: Encrypts the held book
encryptbook:
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]
permission: bookswithoutborders.encrypt
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>
permission: bookswithoutborders.setbookprice
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>
permission: bookswithoutborders.setlore
savepublic:
description: Saves the held book to the public books folder
savepublicbook:
description: Same as savebook, but saves files in the public directory
usage: /<command> [overwrite (true/false)]
permission: bookswithoutborders.savepublic
save:
description: Saves the held book to the holding player's folder
savebook:
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)]
permission: bookswithoutborders.save
setauthor:
description: Sets the author of the held book
setbookauthor:
description: Sets the author of the book the player is holding
usage: /<command> <author>
permission: bookswithoutborders.setauthor
settitle:
description: Sets the title of the held book
description: Sets the title of the book/item the player is holding
usage: /<command> <title>
permission: bookswithoutborders.settitle
load:
description: Loads a previously saved book from the holding player's folder
usage: /<command> <file name or number> [copies] [is signed (true/false)]
loadbook:
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> [# of copies] [signed (true/false)]
permission: bookswithoutborders.load
loadpublic:
description: Loads a previously saved book from the public books folder
usage: /<command> <file name or number> [copies] [is signed (true/false)]
loadpublicbook:
description: Same as loadbook, but views files in the public directory
usage: /<command> <file name or number> [# of copies] [signed (true/false)]
permission: bookswithoutborders.loadpublic
reload:
description: Reloads configuration from disk
description: Reloads BwB's configuration file
usage: /<command>
permission: bookswithoutborders.admin
permissions: