Adds a command for changing book generation, and updates README #5

This commit is contained in:
Kristian Knarvik 2022-08-10 02:49:44 +02:00
parent 1eb9c370bc
commit 94375eee4b
7 changed files with 171 additions and 63 deletions

142
README.md
View File

@ -13,90 +13,94 @@ Books without Borders has got your back!
### Features
* Export written books and book and quills to .txt or .yml files
* Import books from files as written books or unsigned books
* Text files can be any length, and the import process fits the content to the correct page length
* Books can be saved privately, or to a directory visible server wide
* Encrypt books to prevent other players from reading them
* Give, encrypt, or decrypt held books with signs
* Give players books via command blocks
* Unsign or copy held books with a simple command
* Give first time players a single book or a set of books when they join
* Configurable option to require certain items or pay via Vault compatible economy to create books via command
* Add lore to any item with a simple command
* Supports adding and saving color to title, lore, and book contents
* Color and formatting codes can be manually turned into formatting using /formatbook
* Formatting and color codes can be turned into formatting once any book is signed. This is enabled through a config
- Export written books and book and quills to .txt or .yml files
- Import books from files as written books or unsigned books
- Text files can be any length, and the import process fits the content to the correct page length
- Books can be saved privately, or to a directory visible server wide
- Encrypt books to prevent other players from reading them
- Give, encrypt, or decrypt held books with signs
- Give players books via command blocks
- Unsign or copy held books with a simple command
- Give first time players a single book or a set of books when they join
- Configurable option to require certain items or pay via Vault compatible economy to create books via command
- Add lore to any item with a simple command
- Supports adding and saving color to title, lore, and book contents
- Color and formatting codes can be manually turned into formatting using /formatbook
- Formatting and color codes can be turned into formatting once any book is signed. This is enabled through a config
value
- Change generation of books. Create tattered books for your RPG server!
#### Group encryption
* Group encryption allows every player with the bookswithoutborders.decrypt.\<group> permission to decrypt the encrypted
- Group encryption allows every player with the bookswithoutborders.decrypt.\<group> permission to decrypt the encrypted
book without using a password.
### Commands:
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)
* /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 - Displays information about commands (and permissions if the user has bookswithoutborders.admin)
- /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
to encrypt the held book
* /deletebook <file name or number> - Deletes the specified file in the player's directory
* /deletepublicbook <file name or number> - Same as deletebook, but deletes files in the public directory
* encryptbook <key> \[encryption style] - Encrypts the book the player is holding. "key" is required and can be any
- /deletebook <file name or number> - Deletes the specified file in the player's directory
- /deletepublicbook <file name or number> - Same as deletebook, but deletes files in the public directory
- 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)
* /givebook <file name or number> <playername> \[# of copies (num)] \[signed (true/false)] - Gives the selected player a
- /formatbook - 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 a
book from your personal directory
* /givepublicbook <file name or number> <playername> \[# of copies (num)] \[signed (true/false)] - Same as givebook, but
- /givepublicbook <file name or number> <playername> \[# of copies (num)] \[signed (true/false)] - Same as givebook, but
uses books from the public directory
* /loadbook <file name or number> \[# of copies] \[signed (true/false)] - Creates a book from the specified file and
- /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
* /loadpublicbook <file name or number> \[# of copies] \[signed (true/false)] - Same as loadbook, but views files in the
- /loadpublicbook <file name or number> \[# of copies] \[signed (true/false)] - Same as loadbook, but views files in the
public directory
* /reload - Reloads BwB's configuration file
* /savebook \[overwrite (true/false)] - Saves the book the player is holding to a text file in a private directory. If
- /reload - Reloads BwB's configuration file
- /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
* /savepublicbook \[overwrite (true/false)] - Same as savebook, but saves files in the public directory
* /setbookauthor <author> - Sets the author of the book the player is holding
* /setbookprice <item/eco> <quantity> - Sets the per-book price to create a book via commands. If "Item", the item in
- /savepublicbook \[overwrite (true/false)] - Same as savebook, but saves files in the public directory
- /setbookauthor <author> - Sets the author of the book the player is holding
- /setbookgeneration <generation> - Sets the generation (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
- /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
- /settitle <title> - Sets the title of the book/item the player is holding
- /unsignbook - Un-signs the book the player is holding
### Permissions:
* bookswithoutborders.* - Grants all permissions
* bookswithoutborders.admin - Grants all permissions
* bookswithoutborders.use - Allows player to use commands to save/load/delete in their personal directory
* bookswithoutborders.alterbooks - Allows player to change books' data such as lore/title/author/formatting and
- bookswithoutborders.* - Grants all permissions
- bookswithoutborders.admin - Grants all permissions
- bookswithoutborders.use - Allows player to use commands to save/load/delete in their personal directory
- bookswithoutborders.alterbooks - Allows player to change books' data such as lore/title/author/formatting and
unsigning books
* bookswithoutborders.format - Allows a player to format a book
* bookswithoutborders.save - Allows a player to save books to their personal directory
* bookswithoutborders.load - Allows player to load books from their personal directory
* bookswithoutborders.delete - Allows player to delete books from their personal directory
* bookswithoutborders.unsign - Allows player to un-sign books
* bookswithoutborders.copy - Allows player to copy books
* bookswithoutborders.loadpublic - Allows player to load from the public directory
* bookswithoutborders.savepublic - Allows player to save to the public directory
* bookswithoutborders.encrypt - Allows player to encrypt books
* bookswithoutborders.groupencrypt - Allows player to use group-based encryption
* bookswithoutborders.decrypt - Allows player to decrypt books
* bookswithoutborders.decrypt.agroup - Allows player to decrypt books group-encrypted for group "agroup"
* bookswithoutborders.signs - Allows player to create signs that give/encrypt/decrypt books
* bookswithoutborders.give - Allows player to give another player one of their privately saved books
* bookswithoutborders.givepublic - Allows a player to give another player a book from the public directory
* bookswithoutborders.settitle - Allows player to set the title of the currently held book
* bookswithoutborders.setauthor - Allows player to set the author of the currently held book
* bookswithoutborders.setlore - Allows player to set the lore of the currently held item
* bookswithoutborders.bypassauthoronlycopy - Allows player to ignore Author_Only_Copy config setting
* bookswithoutborders.bypassbookprice - Allows player to ignore Price_to_create_book config setting
* bookswithoutborders-setbookprice - Allows player to set the cost of creating a book
- bookswithoutborders.reload - Allows player to reload this plugin
- bookswithoutborders.format - Allows a player to format a book
- bookswithoutborders.save - Allows a player to save books to their personal directory
- bookswithoutborders.load - Allows player to load books from their personal directory
- bookswithoutborders.delete - Allows player to delete books from their personal directory
- bookswithoutborders.unsign - Allows player to un-sign books
- bookswithoutborders.copy - Allows player to copy books
- bookswithoutborders.loadpublic - Allows player to load from the public directory
- bookswithoutborders.savepublic - Allows player to save to the public directory
- bookswithoutborders.encrypt - Allows player to encrypt books
- bookswithoutborders.groupencrypt - Allows player to use group-based encryption
- bookswithoutborders.decrypt - Allows player to decrypt books
- bookswithoutborders.decrypt.agroup - Allows player to decrypt books group-encrypted for group "agroup"
- bookswithoutborders.signs - Allows player to create signs that give/encrypt/decrypt books
- bookswithoutborders.give - Allows player to give another player one of their privately saved books
- bookswithoutborders.givepublic - Allows a player to give another player a book from the public directory
- bookswithoutborders.settitle - Allows player to set the title of the currently held book
- bookswithoutborders.setauthor - Allows player to set the author of the currently held book
- bookswithoutborders.setlore - Allows player to set the lore of the currently held item
- bookswithoutborders.bypassauthoronlycopy - Allows player to ignore Author_Only_Copy config setting
- bookswithoutborders.bypassbookprice - Allows player to ignore Price_to_create_book config setting
- 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)
### Signs
@ -116,4 +120,22 @@ fourth line can be empty or contain "dna" for dna-based encryption.
#### Decrypt sign
The **_decrypt_** sign must have **\[Decrypt]** on its second line. The third line must contain the decryption key
The **_decrypt_** sign must have **\[Decrypt]** on its second line. The third line must contain the decryption key
### Configuration options:
- Save_Books_in_Yaml_Format - Whether to use YAML for saved books instead of just storing them as text
- 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
- Lore_line_separator - The separator used to denote a new line in the book/item lore
- Books_for_new_players - A list of books given to new players the first time they join the server
- Message_for_new_players - An optional message displayed to new players the first time they join the server
- Price_to_create_book.Item_type - The item type used as currency for copying books. Use "Economy" to use money instead
of items
- Price_to_create_book.Required_quantity - The quantity of currency required to pay for each book produced
- Admin_Auto_Decrypt - Whether any admin can decrypt any book regardless of the group it was encrypted for
- Author_Only_Copy - Whether to only allow the author of a book to create copies
- 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
- 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 cannot be copied further.

View File

@ -17,6 +17,7 @@ import net.knarcraft.bookswithoutborders.command.CommandSave;
import net.knarcraft.bookswithoutborders.command.CommandSavePublic;
import net.knarcraft.bookswithoutborders.command.CommandSetAuthor;
import net.knarcraft.bookswithoutborders.command.CommandSetBookPrice;
import net.knarcraft.bookswithoutborders.command.CommandSetGeneration;
import net.knarcraft.bookswithoutborders.command.CommandSetLore;
import net.knarcraft.bookswithoutborders.command.CommandSetTitle;
import net.knarcraft.bookswithoutborders.command.CommandUnSign;
@ -167,6 +168,7 @@ public class BooksWithoutBorders extends JavaPlugin {
registerCommand("booksWithoutBorders", new CommandBooksWithoutBorders());
registerCommand("reload", new CommandReload());
registerCommand("formatBook", new CommandFormat());
registerCommand("setBookGeneration", new CommandSetGeneration());
}
/**

View File

@ -84,6 +84,7 @@ public class CommandBooksWithoutBorders implements TabExecutor {
showCommandInfo("saveBook", sender);
showCommandInfo("savePublicBook", sender);
showCommandInfo("setAuthor", sender);
showCommandInfo("setBookGeneration", sender);
showCommandInfo("setBookPrice", sender);
showCommandInfo("setLore", sender);
showCommandInfo("setTitle", sender);

View File

@ -110,7 +110,8 @@ public class CommandCopy implements TabExecutor {
*/
private boolean copyNextGenerationBook(BookMeta bookMeta, Player player, int copies) {
//Copy the vanilla behavior of refusing copying any further
if (bookMeta.getGeneration() == BookMeta.Generation.COPY_OF_COPY) {
if (bookMeta.getGeneration() == BookMeta.Generation.COPY_OF_COPY ||
bookMeta.getGeneration() == BookMeta.Generation.TATTERED) {
BooksWithoutBorders.sendErrorMessage(player, "You cannot copy this book any further. " +
"You must have the original or a direct copy.");
return false;

View File

@ -0,0 +1,74 @@
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 set generation command
*/
public class CommandSetGeneration 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;
}
if (InventoryHelper.notHoldingOneWrittenBookCheck(player, "You must be holding a written book to" +
" change its generation!", "You cannot change the generation of two books at once!")) {
return false;
}
if (args.length < 1) {
BooksWithoutBorders.sendErrorMessage(player, "You must specify the new generation for your book!");
return false;
}
BookMeta.Generation generation;
try {
generation = BookMeta.Generation.valueOf(args[0]);
} catch (IllegalArgumentException exception) {
BooksWithoutBorders.sendErrorMessage(player, "Invalid book generation specified!");
return false;
}
ItemStack heldBook = InventoryHelper.getHeldBook(player, true);
BookMeta bookMeta = (BookMeta) heldBook.getItemMeta();
if (bookMeta != null) {
bookMeta.setGeneration(generation);
heldBook.setItemMeta(bookMeta);
return true;
} else {
BooksWithoutBorders.sendErrorMessage(player, "Unable to get book metadata!");
return false;
}
}
@Nullable
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
@NotNull String[] args) {
if (args.length == 1) {
List<String> generations = new ArrayList<>();
for (BookMeta.Generation generation : BookMeta.Generation.values()) {
generations.add(generation.name());
}
return generations;
}
return new ArrayList<>();
}
}

View File

@ -5,7 +5,7 @@ Options:
Max_Number_of_Duplicates: 5
# The separator used to separate the book title and the book author
Title-Author_Separator: ","
# The separator used to denote a new line in the book lore
# The separator used to denote a new line in the book/item lore
Lore_line_separator: "~"
# A list of books given to new players the first time they join the server
Books_for_new_players: [ ]

View File

@ -53,6 +53,10 @@ commands:
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
setbookgeneration:
description: Sets the generation of the held book
usage: /<command> <generation>
permission: bookswithoutborders.setgeneration
setbookprice:
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>
@ -115,6 +119,7 @@ permissions:
bookswithoutborders.bypassbookprice: true
bookswithoutborders.setbookprice: true
bookswithoutborders.reload: true
bookswithoutborders.setgeneration: true
bookswithoutborders.use:
description: Allows player to use commands to save/load/delete in their personal directory
children:
@ -129,6 +134,7 @@ permissions:
bookswithoutborders.setauthor: true
bookswithoutborders.setlore: true
bookswithoutborders.format: true
bookswithoutborders.setgeneration: true
bookswithoutborders.format:
description: Allows a player to format a book
bookswithoutborders.save:
@ -172,4 +178,6 @@ permissions:
bookswithoutborders.setbookprice:
description: Allows player to set the cost of creating a book
bookswithoutborders.reload:
description: Allows player to reload this plugin
description: Allows player to reload this plugin
bookswithoutborders.setgeneration:
description: Allows player to change the generation of a book (Original, Copy, Copy of Copy)