Adds clearBook command #7 and improves README
This commit is contained in:
parent
0fdfd81579
commit
f005b8f8e5
149
README.md
149
README.md
@ -39,71 +39,64 @@ Books without Borders has got your back!
|
|||||||
|
|
||||||
An in-game description of available commands is available through the /bwb command.
|
An in-game description of available commands is available through the /bwb command.
|
||||||
|
|
||||||
- /bookswithoutborders - Displays information about commands (and permissions if the user has bookswithoutborders.admin)
|
| Command | Arguments | Description |
|
||||||
- /copybook <# of copies> - Copies the book the player is holding
|
| --- | --- | --- |
|
||||||
- /decryptbook \<key> - Decrypts the book the player is holding. "key" is required and MUST be IDENTICAL to the key used
|
| /bookswithoutborders | None | Displays information about commands (and permissions if the user has bookswithoutborders.admin) |
|
||||||
to encrypt the held book
|
| /copybook | \<# of copies> | Copies the book the player is holding |
|
||||||
- /deletebook \<file name or number> - Deletes the specified file in the player's directory
|
| /decryptbook | \<key> | Decrypts the book the player is holding. "key" is required and MUST be IDENTICAL to the key used to encrypt the held book |
|
||||||
- /deletepublicbook \<file name or number> - Same as deletebook, but deletes files in the public directory
|
| /deletebook | \<file name or number> | Deletes the specified file in the player's directory |
|
||||||
- encryptbook \<key> \[encryption style] - Encrypts the book the player is holding. "key" is required and can be any
|
| /deletepublicbook | \<file name or number> | Same as deletebook, but deletes files in the public directory |
|
||||||
phrase or number excluding spaces. "style" is not required. Possible values are "DNA" or ""
|
| encryptbook | \<key> \[encryption style] | 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 "" |
|
||||||
- /formatbook - Formats the held written book (converts color and formatting codes to the corresponding formatted text)
|
| /formatbook | None | Formats the held written book (converts color and formatting codes to the corresponding formatted text) |
|
||||||
- /givebook \<file name or number> \<playername> \[# of copies (num)] \[signed (true/false)] - Gives the selected player
|
| /givebook | \<file name or number> \<playername> \[# of copies (num)] \[signed (true/false)] | Gives the selected player a book from your personal directory |
|
||||||
a book from your personal directory
|
| /givepublicbook | \<file name or number> \<playername> \[# of copies (num)] \[signed (true/false)] | Same as givebook, but uses books from the public directory |
|
||||||
- /givepublicbook \<file name or number> \<playername> \[# of copies (num)] \[signed (true/false)] - Same as givebook,
|
| /loadbook | \<file name or number> \[# of copies] \[signed (true/false)] | 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 |
|
||||||
but uses books from the public directory
|
| /loadpublicbook | \<file name or number> \[# of copies] \[signed (true/false)] | Same as loadbook, but views files in the public directory |
|
||||||
- /loadbook \<file name or number> \[# of copies] \[signed (true/false)] - Creates a book from the specified file and
|
| /reload | None | Reloads BwB's configuration file |
|
||||||
gives it to the player. If no file is specified, a list of available files is returned. If true is specified, the book
|
| /savebook | \[overwrite (true/false)] | 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 |
|
||||||
will be signed, if false it will be unsigned
|
| /savepublicbook | \[overwrite (true/false)] | Same as savebook, but saves files in the public directory |
|
||||||
- /loadpublicbook \<file name or number> \[# of copies] \[signed (true/false)] - Same as loadbook, but views files in
|
| /setbookauthor | \<author> | Sets the author of the book the player is holding |
|
||||||
the public directory
|
| /setbookgeneration | \<generation> | Sets the generation of the held book (ORIGINAL, COPY_OF_ORIGINAL, COPY_OF_COPY, TATTERED) |
|
||||||
- /reload - Reloads BwB's configuration file
|
| /setbookprice | \<item/eco> \<quantity> | 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> nor \<quantity> are specified, the current price to create books will be removed. |
|
||||||
- /savebook \[overwrite (true/false)] - Saves the book the player is holding to a text file in a private directory. If
|
| /setlore | \<new lore> | Sets the lore of the item the player is holding. Insert the lore_line_separator character to force a new line ("~" by default) |
|
||||||
true is specified, a book of the same name by the same author will be overwritten by the new book
|
| /settitle | \<title> | Sets the title of the book/item the player is holding |
|
||||||
- /savepublicbook \[overwrite (true/false)] - Same as savebook, but saves files in the public directory
|
| /unsignbook | None | Un-signs the book the player is holding |
|
||||||
- /setbookauthor \<author> - Sets the author of the book the player is holding
|
| /clearbook | None | Removes all text from the held un-signed book |
|
||||||
- /setbookgeneration <generation> - Sets the generation of the held book (ORIGINAL, COPY_OF_ORIGINAL, COPY_OF_COPY,
|
|
||||||
TATTERED)
|
|
||||||
- /setbookprice \<item/eco> \<quantity> - 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> nor \<quantity> are specified, the current price to create books will be removed.
|
|
||||||
- /setlore \<new lore> - Sets the lore of the item the player is holding. Insert the lore_line_separator character to
|
|
||||||
force a new line ("~" by default)
|
|
||||||
- /settitle \<title> - Sets the title of the book/item the player is holding
|
|
||||||
- /unsignbook - Un-signs the book the player is holding
|
|
||||||
|
|
||||||
### Permissions:
|
### Permissions:
|
||||||
|
|
||||||
- bookswithoutborders.* - Grants all permissions
|
| Node | Description |
|
||||||
- bookswithoutborders.admin - Grants all permissions
|
| --- | --- |
|
||||||
- bookswithoutborders.use - Allows player to use commands to save/load/delete in their personal directory
|
| bookswithoutborders.* | Grants all permissions |
|
||||||
- bookswithoutborders.alterbooks - Allows player to change books' data such as lore/title/author/generation/formatting
|
| bookswithoutborders.admin | Grants all permissions |
|
||||||
and unsigning books
|
| bookswithoutborders.use | Allows player to use commands to save/load/delete in their personal directory |
|
||||||
- bookswithoutborders.reload - Allows player to reload this plugin
|
| bookswithoutborders.alterbooks | Allows player to change books' data such as lore/title/author/generation/formatting and un-signing books |
|
||||||
- bookswithoutborders.format - Allows a player to format a book
|
| bookswithoutborders.reload | Allows player to reload this plugin |
|
||||||
- bookswithoutborders.save - Allows a player to save books to their personal directory
|
| bookswithoutborders.format | Allows a player to format a book |
|
||||||
- bookswithoutborders.load - Allows player to load books from their personal directory
|
| bookswithoutborders.save | Allows a player to save books to their personal directory |
|
||||||
- bookswithoutborders.delete - Allows player to delete books from their personal directory
|
| bookswithoutborders.load | Allows player to load books from their personal directory |
|
||||||
- bookswithoutborders.unsign - Allows player to un-sign books
|
| bookswithoutborders.delete | Allows player to delete books from their personal directory |
|
||||||
- bookswithoutborders.copy - Allows player to copy books
|
| bookswithoutborders.unsign | Allows player to un-sign books |
|
||||||
- bookswithoutborders.loadpublic - Allows player to load from the public directory
|
| bookswithoutborders.copy | Allows player to copy books |
|
||||||
- bookswithoutborders.savepublic - Allows player to save to the public directory
|
| bookswithoutborders.loadpublic | Allows player to load from the public directory |
|
||||||
- bookswithoutborders.encrypt - Allows player to encrypt books
|
| bookswithoutborders.savepublic | Allows player to save to the public directory |
|
||||||
- bookswithoutborders.groupencrypt - Allows player to use group-based encryption
|
| bookswithoutborders.encrypt | Allows player to encrypt books |
|
||||||
- bookswithoutborders.decrypt - Allows player to decrypt books
|
| bookswithoutborders.groupencrypt | Allows player to use group-based encryption |
|
||||||
- bookswithoutborders.decrypt.agroup - Allows player to decrypt books group-encrypted for group "agroup"
|
| bookswithoutborders.decrypt | Allows player to decrypt books |
|
||||||
- bookswithoutborders.signs - Allows player to create signs that give/encrypt/decrypt books
|
| bookswithoutborders.decrypt.agroup | Allows player to decrypt books group-encrypted for group "agroup" |
|
||||||
- bookswithoutborders.give - Allows player to give another player one of their privately saved books
|
| bookswithoutborders.signs | Allows player to create signs that give/encrypt/decrypt books |
|
||||||
- bookswithoutborders.givepublic - Allows a player to give another player a book from the public directory
|
| bookswithoutborders.give | Allows player to give another player one of their privately saved books |
|
||||||
- bookswithoutborders.settitle - Allows player to set the title of the currently held book
|
| bookswithoutborders.givepublic | Allows a player to give another player a book from the public directory |
|
||||||
- bookswithoutborders.setauthor - Allows player to set the author of the currently held book
|
| bookswithoutborders.settitle | Allows player to set the title of the currently held book |
|
||||||
- bookswithoutborders.setlore - Allows player to set the lore of the currently held item
|
| bookswithoutborders.setauthor | Allows player to set the author of the currently held book |
|
||||||
- bookswithoutborders.bypassauthoronlycopy - Allows player to ignore Author_Only_Copy config setting
|
| bookswithoutborders.setlore | Allows player to set the lore of the currently held item |
|
||||||
- bookswithoutborders.bypassauthoronlyunsign - Allows player to ignore Author_Only_Unsign config setting
|
| bookswithoutborders.bypassauthoronlycopy | Allows player to ignore Author_Only_Copy config setting |
|
||||||
- bookswithoutborders.bypassauthoronlysave - Allows player to ignore Author_Only_Save config setting
|
| bookswithoutborders.bypassauthoronlyunsign | Allows player to ignore Author_Only_Unsign config setting |
|
||||||
- bookswithoutborders.bypassbookprice - Allows player to ignore Price_to_create_book config setting
|
| bookswithoutborders.bypassauthoronlysave | Allows player to ignore Author_Only_Save config setting |
|
||||||
- bookswithoutborders.setbookprice - Allows player to set the cost of creating a book
|
| bookswithoutborders.bypassbookprice | Allows player to ignore Price_to_create_book config setting |
|
||||||
- bookswithoutborders.setgeneration - Allows player to change the generation of a book (Original, Copy, Copy of Copy)
|
| bookswithoutborders.setbookprice | Allows player to set the cost of creating a book |
|
||||||
|
| bookswithoutborders.setgeneration | Allows player to change the generation of a book (Original, Copy, Copy of Copy) |
|
||||||
|
| bookswithoutborders.clear | Allows player to clear the contents of the held writable book |
|
||||||
|
|
||||||
### Signs
|
### Signs
|
||||||
|
|
||||||
@ -127,19 +120,19 @@ The **_decrypt_** sign must have **\[Decrypt]** on its second line. The third li
|
|||||||
|
|
||||||
### Configuration options:
|
### Configuration options:
|
||||||
|
|
||||||
- Save_Books_in_Yaml_Format - Whether to use YAML for saved books instead of just storing them as text
|
| Option | Description |
|
||||||
- Max_Number_of_Duplicates - The maximum number of duplicates of a saved book allowed
|
| --- | --- |
|
||||||
- Author_Separator - The separator used to separate the book title and the book author
|
| Save_Books_in_Yaml_Format | Whether to use YAML for saved books instead of just storing them as text |
|
||||||
- Lore_line_separator - The separator used to denote a new line in the book/item lore
|
| Max_Number_of_Duplicates | The maximum number of duplicates of a saved book allowed |
|
||||||
- Books_for_new_players - A list of books given to new players the first time they join the server
|
| Author_Separator | The separator used to separate the book title and the book author |
|
||||||
- Message_for_new_players - An optional message displayed to new players the first time they join the server
|
| Lore_line_separator | The separator used to denote a new line in the book/item lore |
|
||||||
- Price_to_create_book.Item_type - The item type used as currency for copying books. Use "Economy" to use money instead
|
| Books_for_new_players | A list of books given to new players the first time they join the server |
|
||||||
of items
|
| Message_for_new_players | An optional message displayed to new players the first time they join the server |
|
||||||
- Price_to_create_book.Required_quantity - The quantity of currency required to pay for each book produced
|
| Price_to_create_book.Item_type | The item type used as currency for copying books. Use "Economy" to use money instead of items |
|
||||||
- Admin_Auto_Decrypt - Whether any admin can decrypt any book regardless of the group it was encrypted for
|
| Price_to_create_book.Required_quantity | The quantity of currency required to pay for each book produced |
|
||||||
- Author_Only_Copy - Whether to only allow the author of a book to create copies
|
| Admin_Auto_Decrypt | Whether any admin can decrypt any book regardless of the group it was encrypted for |
|
||||||
- Author_Only_Unsign - Whether to only allow the author of a book to unsign it
|
| Author_Only_Copy | Whether to only allow the author of a book to create copies |
|
||||||
- Author_Only_Save - Whether to only allow saving a player's own books with /savebook
|
| Author_Only_Unsign | Whether to only allow the author of a book to unsign it |
|
||||||
- Format_Book_After_Signing - Whether to automatically format every book when it's signed
|
| Author_Only_Save | Whether to only allow saving a player's own books with /savebook |
|
||||||
- Change_Generation_On_Copy - Whether to display "COPY" or "COPY_OF_COPY" instead of "ORIGINAL" when a book is copied.
|
| Format_Book_After_Signing | Whether to automatically format every book when it's signed |
|
||||||
This also uses the vanilla behavior where a copy of a copy or tattered book cannot be copied further.
|
| Change_Generation_On_Copy | Whether to display "COPY" or "COPY_OF_COPY" instead of "ORIGINAL" when a book is copied. This also uses the vanilla behavior where a copy of a copy or tattered book cannot be copied further. |
|
@ -1,6 +1,7 @@
|
|||||||
package net.knarcraft.bookswithoutborders;
|
package net.knarcraft.bookswithoutborders;
|
||||||
|
|
||||||
import net.knarcraft.bookswithoutborders.command.CommandBooksWithoutBorders;
|
import net.knarcraft.bookswithoutborders.command.CommandBooksWithoutBorders;
|
||||||
|
import net.knarcraft.bookswithoutborders.command.CommandClear;
|
||||||
import net.knarcraft.bookswithoutborders.command.CommandCopy;
|
import net.knarcraft.bookswithoutborders.command.CommandCopy;
|
||||||
import net.knarcraft.bookswithoutborders.command.CommandDecrypt;
|
import net.knarcraft.bookswithoutborders.command.CommandDecrypt;
|
||||||
import net.knarcraft.bookswithoutborders.command.CommandDelete;
|
import net.knarcraft.bookswithoutborders.command.CommandDelete;
|
||||||
@ -173,6 +174,7 @@ public class BooksWithoutBorders extends JavaPlugin {
|
|||||||
registerCommand("reload", new CommandReload());
|
registerCommand("reload", new CommandReload());
|
||||||
registerCommand("formatBook", new CommandFormat());
|
registerCommand("formatBook", new CommandFormat());
|
||||||
registerCommand("setBookGeneration", new CommandSetGeneration());
|
registerCommand("setBookGeneration", new CommandSetGeneration());
|
||||||
|
registerCommand("clearBook", new CommandClear());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -0,0 +1,48 @@
|
|||||||
|
package net.knarcraft.bookswithoutborders.command;
|
||||||
|
|
||||||
|
import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
|
||||||
|
import net.knarcraft.bookswithoutborders.utility.InventoryHelper;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
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.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Command executor for the clear command
|
||||||
|
*/
|
||||||
|
public class CommandClear implements TabExecutor {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
|
||||||
|
@NotNull String[] args) {
|
||||||
|
if (!(sender instanceof Player player)) {
|
||||||
|
BooksWithoutBorders.sendErrorMessage(sender, "This command can only be used by a player!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
InventoryHelper.notHoldingOneWritableBookCheck(player, "You must be holding a writable book to copy it!",
|
||||||
|
"You cannot copy two books at once!");
|
||||||
|
|
||||||
|
//Clear the player's held book
|
||||||
|
ItemStack heldBook = InventoryHelper.getHeldBook(player, true);
|
||||||
|
BookMeta bookMeta = (BookMeta) heldBook;
|
||||||
|
bookMeta.setPages("");
|
||||||
|
heldBook.setItemMeta(bookMeta);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
|
||||||
|
@NotNull String[] args) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -103,7 +103,7 @@ public final class EconomyHelper {
|
|||||||
private static boolean takeWritableBookPayment(Player player, int itemCost) {
|
private static boolean takeWritableBookPayment(Player player, int itemCost) {
|
||||||
List<ItemStack> books = getPlayersEmptyBooks(player);
|
List<ItemStack> books = getPlayersEmptyBooks(player);
|
||||||
if (countItems(books) < itemCost) {
|
if (countItems(books) < itemCost) {
|
||||||
BooksWithoutBorders.sendErrorMessage(player, itemCost + " " + Material.WRITABLE_BOOK +
|
BooksWithoutBorders.sendErrorMessage(player, itemCost + " empty " + Material.WRITABLE_BOOK +
|
||||||
"(s) are required for this command!");
|
"(s) are required for this command!");
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
|
@ -51,6 +51,31 @@ public final class InventoryHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs checks to validate that a player contains exactly one unwritten book
|
||||||
|
*
|
||||||
|
* @param player <p>The player to validate</p>
|
||||||
|
* @param noBookMessage <p>The message to display if the player is not holding a book</p>
|
||||||
|
* @param twoBooksMessage <p>The message to display if the player is holding one book in each hand</p>
|
||||||
|
* @return <p>False if the player is holding exactly one book</p>
|
||||||
|
*/
|
||||||
|
public static boolean notHoldingOneWritableBookCheck(Player player, String noBookMessage, String twoBooksMessage) {
|
||||||
|
BookHoldingState holdingState = getBookHoldingState(player);
|
||||||
|
|
||||||
|
if (holdingState == BookHoldingState.NONE || holdingState == BookHoldingState.SIGNED_BOTH_HANDS ||
|
||||||
|
holdingState == BookHoldingState.SIGNED_MAIN_HAND || holdingState == BookHoldingState.SIGNED_OFF_HAND) {
|
||||||
|
BooksWithoutBorders.sendErrorMessage(player, noBookMessage);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (holdingState == BookHoldingState.UNSIGNED_BOTH_HANDS) {
|
||||||
|
BooksWithoutBorders.sendErrorMessage(player, twoBooksMessage);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs checks to validate that a player contains exactly one written book
|
* Performs checks to validate that a player contains exactly one written book
|
||||||
*
|
*
|
||||||
|
@ -45,6 +45,10 @@ commands:
|
|||||||
description: Copies the book the player is holding
|
description: Copies the book the player is holding
|
||||||
usage: /<command> <# of copies>
|
usage: /<command> <# of copies>
|
||||||
permission: bookswithoutborders.copy
|
permission: bookswithoutborders.copy
|
||||||
|
clearbook:
|
||||||
|
description: Removes all text from the book the player is holding
|
||||||
|
usage: /<command>
|
||||||
|
permission: bookswithoutborders.clear
|
||||||
unsignbook:
|
unsignbook:
|
||||||
description: Un-signs the book the player is holding
|
description: Un-signs the book the player is holding
|
||||||
usage: /<command>
|
usage: /<command>
|
||||||
@ -130,6 +134,7 @@ permissions:
|
|||||||
bookswithoutborders.alterbooks:
|
bookswithoutborders.alterbooks:
|
||||||
description: Allows player to change books' data such as lore/title/author/generation/formatting and unsigning books
|
description: Allows player to change books' data such as lore/title/author/generation/formatting and unsigning books
|
||||||
children:
|
children:
|
||||||
|
bookswithoutborders.clear: true
|
||||||
bookswithoutborders.unsign: true
|
bookswithoutborders.unsign: true
|
||||||
bookswithoutborders.settitle: true
|
bookswithoutborders.settitle: true
|
||||||
bookswithoutborders.setauthor: true
|
bookswithoutborders.setauthor: true
|
||||||
@ -145,9 +150,11 @@ permissions:
|
|||||||
bookswithoutborders.delete:
|
bookswithoutborders.delete:
|
||||||
description: Allows player to delete books from their personal directory
|
description: Allows player to delete books from their personal directory
|
||||||
bookswithoutborders.unsign:
|
bookswithoutborders.unsign:
|
||||||
description: Allows player to use unsign command
|
description: Allows player to use the unsign command
|
||||||
bookswithoutborders.copy:
|
bookswithoutborders.copy:
|
||||||
description: Allows player to use copy command
|
description: Allows player to use the copy command
|
||||||
|
bookswithoutborders.clear:
|
||||||
|
description: Allows player to use the clear command
|
||||||
bookswithoutborders.loadpublic:
|
bookswithoutborders.loadpublic:
|
||||||
description: Allows player to load from the public directory
|
description: Allows player to load from the public directory
|
||||||
bookswithoutborders.savepublic:
|
bookswithoutborders.savepublic:
|
||||||
|
Loading…
Reference in New Issue
Block a user