From 40512dd771de3f386cad6aa03caa6565a06ca780 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Wed, 10 Aug 2022 14:52:05 +0200 Subject: [PATCH] Adds an option to only allow saving own books --- README.md | 1 + .../bookswithoutborders/command/CommandSave.java | 12 ++++++++++-- .../config/BooksWithoutBordersConfig.java | 12 ++++++++++++ .../bookswithoutborders/config/ConfigOption.java | 5 +++++ src/main/resources/config.yml | 2 ++ 5 files changed, 30 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8600e53..5e2fa48 100644 --- a/README.md +++ b/README.md @@ -137,6 +137,7 @@ The **_decrypt_** sign must have **\[Decrypt]** on its second line. The third li - 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 +- Author_Only_Save - Whether to only allow saving a player's own books with /savebook - 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 or tattered book cannot be copied further. \ No newline at end of file diff --git a/src/main/java/net/knarcraft/bookswithoutborders/command/CommandSave.java b/src/main/java/net/knarcraft/bookswithoutborders/command/CommandSave.java index d6cd765..4874d26 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/command/CommandSave.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/command/CommandSave.java @@ -76,6 +76,12 @@ public class CommandSave implements TabExecutor { return; } + //Only allow saving of own books if enabled + if (BooksWithoutBordersConfig.getAuthorOnlySave() && !saveToPublicFolder && + BookHelper.isNotAuthor(player, book)) { + return; + } + String savePath = BookHelper.getBookDirectoryPathString( saveToPublicFolder ? BookDirectory.PUBLIC : BookDirectory.PLAYER, player); @@ -85,12 +91,14 @@ public class CommandSave implements TabExecutor { //Make sure the used folders exist File file = new File(savePath); if (!file.exists() && !file.mkdir()) { - BooksWithoutBorders.sendErrorMessage(player, "Saving Failed! If this continues to happen, consult server admin!"); + BooksWithoutBorders.sendErrorMessage(player, "Saving Failed! If this continues to happen, consult" + + " a server admin!"); return; } File[] foundFiles = file.listFiles(); if (foundFiles == null) { - BooksWithoutBorders.sendErrorMessage(player, "Saving Failed! If this continues to happen, consult server admin!"); + BooksWithoutBorders.sendErrorMessage(player, "Saving Failed! If this continues to happen, consult" + + " a server admin!"); return; } diff --git a/src/main/java/net/knarcraft/bookswithoutborders/config/BooksWithoutBordersConfig.java b/src/main/java/net/knarcraft/bookswithoutborders/config/BooksWithoutBordersConfig.java index 1170ad0..e8706a2 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/config/BooksWithoutBordersConfig.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/config/BooksWithoutBordersConfig.java @@ -35,6 +35,7 @@ public class BooksWithoutBordersConfig { private static double bookPriceQuantity; private static boolean authorOnlyCopy; private static boolean authorOnlyUnsign; + private static boolean authorOnlySave; private static boolean useYml; private static boolean adminDecrypt; private static boolean formatBooks; @@ -117,6 +118,15 @@ public class BooksWithoutBordersConfig { return authorOnlyUnsign; } + /** + * Gets whether a player can only save their own books with /savebook + * + * @return

Whether a player can only save their own books

+ */ + public static boolean getAuthorOnlySave() { + return authorOnlySave; + } + /** * Gets whether to use YML, not TXT, for saving books * @@ -278,6 +288,7 @@ public class BooksWithoutBordersConfig { config.set(ConfigOption.ADMIN_AUTO_DECRYPT.getConfigNode(), adminDecrypt); config.set(ConfigOption.AUTHOR_ONLY_COPY.getConfigNode(), authorOnlyCopy); config.set(ConfigOption.AUTHOR_ONLY_UNSIGN.getConfigNode(), authorOnlyUnsign); + config.set(ConfigOption.AUTHOR_ONLY_SAVE.getConfigNode(), authorOnlySave); config.set(ConfigOption.CHANGE_GENERATION_ON_COPY.getConfigNode(), changeGenerationOnCopy); //Handles old book and quill settings @@ -314,6 +325,7 @@ public class BooksWithoutBordersConfig { adminDecrypt = getBoolean(config, ConfigOption.ADMIN_AUTO_DECRYPT); authorOnlyCopy = getBoolean(config, ConfigOption.AUTHOR_ONLY_COPY); authorOnlyUnsign = getBoolean(config, ConfigOption.AUTHOR_ONLY_UNSIGN); + authorOnlySave = getBoolean(config, ConfigOption.AUTHOR_ONLY_SAVE); firstBooks = config.getStringList(ConfigOption.BOOKS_FOR_NEW_PLAYERS.getConfigNode()); welcomeMessage = getString(config, ConfigOption.MESSAGE_FOR_NEW_PLAYERS); formatBooks = getBoolean(config, ConfigOption.FORMAT_AFTER_SIGNING); diff --git a/src/main/java/net/knarcraft/bookswithoutborders/config/ConfigOption.java b/src/main/java/net/knarcraft/bookswithoutborders/config/ConfigOption.java index 23eba32..cc3d1b0 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/config/ConfigOption.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/config/ConfigOption.java @@ -60,6 +60,11 @@ public enum ConfigOption { */ AUTHOR_ONLY_UNSIGN("Options.Author_Only_Unsign", false), + /** + * Whether a player can only save their own books with /savebook + */ + AUTHOR_ONLY_SAVE("Options.Author_Only_Save", false), + /** * Whether to turn Original into Copy when copying books */ diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 54af49d..064a432 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -23,6 +23,8 @@ Options: 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