True if the config was loaded successfully
*/ public boolean loadConfig() { - BooksWithoutBorders.getInstance().reloadConfig(); - Configuration config = BooksWithoutBorders.getInstance().getConfig(); + BooksWithoutBorders instance = BooksWithoutBorders.getInstance(); + instance.reloadConfig(); + Configuration config = instance.getConfig(); try { this.bookDuplicateLimit = config.getInt(ConfigOption.MAX_DUPLICATES.getConfigNode(), (Integer) ConfigOption.MAX_DUPLICATES.getDefaultValue()); @@ -327,7 +329,7 @@ public class BwBConfig { this.enableBookshelfPeeking = getBoolean(config, ConfigOption.ENABLE_BOOKSHELF_PEEKING); this.useRealEncryption = getBoolean(config, ConfigOption.USE_REAL_ENCRYPTION); this.allowPreventAdminDecryption = getBoolean(config, ConfigOption.ALLOW_PREVENT_ADMIN_DECRYPTION); - String language = config.getString("language", "en"); + String language = getString(config, ConfigOption.LANGUAGE); this.translator.loadLanguages(BooksWithoutBorders.getInstance().getDataFolder(), "en", language); //Convert string into material diff --git a/src/main/java/net/knarcraft/bookswithoutborders/config/ConfigOption.java b/src/main/java/net/knarcraft/bookswithoutborders/config/ConfigOption.java index 39817a3..07180a4 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/config/ConfigOption.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/config/ConfigOption.java @@ -10,82 +10,87 @@ public enum ConfigOption { /** * The max duplicates of a book that can be saved */ - MAX_DUPLICATES("Options.Max_Number_of_Duplicates", 5), + MAX_DUPLICATES("limit.maxDuplicates", 5), /** * The separator used to separate book title and book author */ - TITLE_AUTHOR_SEPARATOR("Options.Title-Author_Separator", ","), + TITLE_AUTHOR_SEPARATOR("separator.titleAuthor", ","), /** * The separator used to specify a new line in an item's lore */ - LORE_LINE_SEPARATOR("Options.Lore_line_separator", "~"), + LORE_LINE_SEPARATOR("separator.loreLine", "~"), /** * The books given to new players when they first join */ - BOOKS_FOR_NEW_PLAYERS("Options.Books_for_new_players", "[]"), + BOOKS_FOR_NEW_PLAYERS("firstJoin.booksToGive", "[]"), /** * The message to display to new players when they first join */ - MESSAGE_FOR_NEW_PLAYERS("Options.Message_for_new_players", ""), + MESSAGE_FOR_NEW_PLAYERS("firstJoin.welcomeMessage", ""), /** * The item type used to pay for book copying */ - PRICE_ITEM_TYPE("Options.Price_to_create_book.Item_type", ""), + PRICE_ITEM_TYPE("bookPrice.itemType", ""), /** * The amount of items used to pay for book copying */ - PRICE_QUANTITY("Options.Price_to_create_book.Required_quantity", 0.0), + PRICE_QUANTITY("bookPrice.quantity", 0.0), /** * Whether admins should be able to decrypt books for all groups */ - ADMIN_AUTO_DECRYPT("Options.Admin_Auto_Decrypt", false), + ADMIN_AUTO_DECRYPT("encryption.allowAdminBypass", false), /** * Whether only the book author should be able to copy a book */ - AUTHOR_ONLY_COPY("Options.Author_Only_Copy", false), + AUTHOR_ONLY_COPY("authorRestricted.copy", false), /** * Whether only the book author should be able to unsign a book */ - AUTHOR_ONLY_UNSIGN("Options.Author_Only_Unsign", false), + AUTHOR_ONLY_UNSIGN("authorRestricted.unsign", false), /** * Whether a player can only save their own books with /saveBook */ - AUTHOR_ONLY_SAVE("Options.Author_Only_Save", false), + AUTHOR_ONLY_SAVE("authorRestricted.save", false), /** * Whether to turn Original into Copy when copying books */ - CHANGE_GENERATION_ON_COPY("Options.Change_Generation_On_Copy", false), + CHANGE_GENERATION_ON_COPY("functionality.changeBookGenerationOnCopy", false), /** * Whether to automatically format every signed book */ - FORMAT_AFTER_SIGNING("Options.Format_Book_After_Signing", false), + FORMAT_AFTER_SIGNING("functionality.formatBookOnSigning", true), /** * Whether hitting a bookshelf should display information about the contained books */ - ENABLE_BOOKSHELF_PEEKING("Options.Enable_Book_Peeking", true), + ENABLE_BOOKSHELF_PEEKING("functionality.enableBookPeeking", true), /** * Whether to use real AES encryption instead of storing garbled book text, while the full plaintext is stored in a file */ - USE_REAL_ENCRYPTION("Options.Use_Real_Encryption", false), + USE_REAL_ENCRYPTION("encryption.useRealEncryption", false), /** * Whether to allow disabling admin encryption for a real encrypted book */ - ALLOW_PREVENT_ADMIN_DECRYPTION("Options.Allow_Prevent_Admin_Decryption", false), + ALLOW_PREVENT_ADMIN_DECRYPTION("encryption.allowAdminBypassBlocking", false), + + /** + * The language to load from strings.yml + */ + LANGUAGE("language", "en"), ; private final String configNode; diff --git a/src/main/resources/config-migrations.txt b/src/main/resources/config-migrations.txt new file mode 100644 index 0000000..b91f672 --- /dev/null +++ b/src/main/resources/config-migrations.txt @@ -0,0 +1,18 @@ +Options.Language=language +Options.Title-Author_Separator=separator.titleAuthor +Options.Lore_line_separator=separator.loreLine +Options.Price_to_create_book.Item_type=bookPrice.itemType +Options.Price_to_create_book.Required_quantity=bookPrice.quantity +Options.Author_Only_Copy=authorRestricted.copy +Options.Author_Only_Unsign=authorRestricted.unsign +Options.Author_Only_Save=authorRestricted.save +Options.Books_for_new_players=firstJoin.booksToGive +Options.Message_for_new_players=firstJoin.welcomeMessage +Options.Admin_Auto_Decrypt=encryption.allowAdminBypass +Options.Use_Real_Encryption=encryption.useRealEncryption +Options.Allow_Prevent_Admin_Decryption=encryption.allowAdminBypassBlocking +Options.Max_Number_of_Duplicates=limit.maxDuplicates +Options.Format_Book_After_Signing=functionality.formatBookOnSigning +Options.Change_Generation_On_Copy=functionality.changeBookGenerationOnCopy +Options.Enable_Book_Peeking=functionality.enableBookPeeking +Options.Save_Books_in_Yaml_Format= \ No newline at end of file diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 1f13cee..71b5d12 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,45 +1,103 @@ -Options: - # The language to use. Only "en" is built-in, but custom languages can be added - Language: "en" - # The maximum number of duplicates of a saved book allowed - Max_Number_of_Duplicates: 5 +# Books Without Borders configuration file + +# The language to use. Only "en" is built-in, but custom languages can be added. +language: "en" + +# +------------------------------------+ # +# | Limits | # +# +------------------------------------+ # +limit: + # The maximum number of duplicates of a saved book allowed. Note that duplicates are only used for storing unsigned + # books so players can save drafts of their book. Duplicates are not allowed for signed books. + maxDuplicates: 5 + +# +----------------------------------------------------+ # +# | Separators for parsing | # +# +----------------------------------------------------+ # +separator: # The separator used to separate the book title and the book author. While this is a ',' by default for backwards # compatibility, a rarely used character like '¤' is better to prevent restrictions on book titles. - Title-Author_Separator: "," - # 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: [ ] - # An optional message displayed to new players the first time they join the server - Message_for_new_players: "" - # Price settings for book copying - Price_to_create_book: - # The item type used as currency for copying books. Use "Economy" to use money instead of items - Item_type: "" - # The quantity of currency required to pay for each book produced - Required_quantity: 0 - # Whether any admin can decrypt any book regardless of the group it was encrypted for - Admin_Auto_Decrypt: false - # Whether to only allow the author of a book to create copies - Author_Only_Copy: false - # Whether to only allow the author of a book to unsign it - Author_Only_Unsign: false - # Whether to only allow saving a player's own books with /saveBook - Author_Only_Save: false - # Whether to automatically format every book when it's signed - Format_Book_After_Signing: false - # 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. - Change_Generation_On_Copy: false + titleAuthor: "," + + # The separator used to denote a new line in the book/item lore. + loreLine: "~" + +# +---------------------------------------------------+ # +# | New player first join | # +# +---------------------------------------------------+ # +firstJoin: + # A list of books given to new players the first time they join the server. + booksToGive: [ ] + + # An optional message displayed to new players the first time they join the server. + welcomeMessage: "" + +# +-------------------------------------------------+ # +# | Book creation price | # +# +-------------------------------------------------+ # +# You can set the price with the "/setBookPrice" command. +# +-------------------------------------------------+ # +bookPrice: + # The item type used as currency for copying books. Use "Economy" to use money instead of items. + itemType: "" + + # The quantity of currency required to pay for each book produced + # This will be either the economy cost, or the number of items. Decimals are supported, but will be ignored for item + # amount. + quantity: 0 + +# +---------------------------------------------------------------------+ # +# | Enable/Disable author-only restrictions | # +# +---------------------------------------------------------------------+ # +# These options can be useful for survival gameplay, in order to allow some functionality, but still restrict actions to +# players' own books. +# +---------------------------------------------------------------------+ # +authorRestricted: + # Whether to only allow the author of a book to create copies. + copy: false + + # Whether to only allow the author of a book to unsign it. + unsign: false + + # Whether to only allow saving a player's own books with "/saveBook". + save: false + +# +----------------------------------------------------------+ # +# | Enable/Disable functionality | # +# +----------------------------------------------------------+ # +functionality: + # Whether to automatically format every book when it's signed, if the player has permission. + # Formatting is automatically reverted when a book is unsigned, so having this on should generally not cause trouble. + formatBookOnSigning: true + + # Whether to set the generation to "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. + changeBookGenerationOnCopy: false + # Whether to enable hitting a chiseled bookshelf while sneaking to see the shelf's contents. - Enable_Book_Peeking: true + enableBookPeeking: true + +# +-------------------------------------------------+ # +# | Encryption behavior | # +# +-------------------------------------------------+ # +encryption: + # Whether any admin can decrypt any book regardless of the group it was encrypted for, and decrypt normally encrypted + # books without having to supply a password. + allowAdminBypass: false + # Whether to use true AES encryption when encrypting and decrypting books. While the hashed password used for # encryption is still stored in the book file, the readable contents of the book are not. Admin decrypt can be used to - # peek at books, if an admin gets a hold of a book with the same title and author, but only the encrypted AES cypher text is stored in the book. + # peek at books, if an admin gets a hold of a book with the same title and author. Only the encrypted AES cypher + # text is stored in the book, so admins cannot see the contents by looking in the stored encrypted file on the server. + # + # If "allowAdminBypassBlocking" is enabled, admin decryption can be disabled for a book + # when using the "/encryptbook" command. + # # Note that real encryption might alter, corrupt or lose a book's contents, so don't use real encryption with books # that have no backup in in-game book form or saved book form. - Use_Real_Encryption: false + useRealEncryption: false + # Whether to allow players to specifically disable admin decryption for a real encrypted book. This is only available # when real encryption is enabled. It allows a player to prevent the storage of the encryption key in the plugin # folder, meaning that the only way to decrypt the book is to provide the correct key. THIS IS A DANGEROUS OPTION! - Allow_Prevent_Admin_Decryption: false \ No newline at end of file + allowAdminBypassBlocking: false \ No newline at end of file