Adds an option to only allow saving own books

This commit is contained in:
Kristian Knarvik 2022-08-10 14:52:05 +02:00
parent 5d340af6f2
commit 40512dd771
5 changed files with 30 additions and 2 deletions

View File

@ -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 - 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_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_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 - 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. - 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. This also uses the vanilla behavior where a copy of a copy or tattered book cannot be copied further.

View File

@ -76,6 +76,12 @@ public class CommandSave implements TabExecutor {
return; return;
} }
//Only allow saving of own books if enabled
if (BooksWithoutBordersConfig.getAuthorOnlySave() && !saveToPublicFolder &&
BookHelper.isNotAuthor(player, book)) {
return;
}
String savePath = BookHelper.getBookDirectoryPathString( String savePath = BookHelper.getBookDirectoryPathString(
saveToPublicFolder ? BookDirectory.PUBLIC : BookDirectory.PLAYER, player); saveToPublicFolder ? BookDirectory.PUBLIC : BookDirectory.PLAYER, player);
@ -85,12 +91,14 @@ public class CommandSave implements TabExecutor {
//Make sure the used folders exist //Make sure the used folders exist
File file = new File(savePath); File file = new File(savePath);
if (!file.exists() && !file.mkdir()) { 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; return;
} }
File[] foundFiles = file.listFiles(); File[] foundFiles = file.listFiles();
if (foundFiles == null) { 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; return;
} }

View File

@ -35,6 +35,7 @@ public class BooksWithoutBordersConfig {
private static double bookPriceQuantity; private static double bookPriceQuantity;
private static boolean authorOnlyCopy; private static boolean authorOnlyCopy;
private static boolean authorOnlyUnsign; private static boolean authorOnlyUnsign;
private static boolean authorOnlySave;
private static boolean useYml; private static boolean useYml;
private static boolean adminDecrypt; private static boolean adminDecrypt;
private static boolean formatBooks; private static boolean formatBooks;
@ -117,6 +118,15 @@ public class BooksWithoutBordersConfig {
return authorOnlyUnsign; return authorOnlyUnsign;
} }
/**
* Gets whether a player can only save their own books with /savebook
*
* @return <p>Whether a player can only save their own books</p>
*/
public static boolean getAuthorOnlySave() {
return authorOnlySave;
}
/** /**
* Gets whether to use YML, not TXT, for saving books * 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.ADMIN_AUTO_DECRYPT.getConfigNode(), adminDecrypt);
config.set(ConfigOption.AUTHOR_ONLY_COPY.getConfigNode(), authorOnlyCopy); config.set(ConfigOption.AUTHOR_ONLY_COPY.getConfigNode(), authorOnlyCopy);
config.set(ConfigOption.AUTHOR_ONLY_UNSIGN.getConfigNode(), authorOnlyUnsign); 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); config.set(ConfigOption.CHANGE_GENERATION_ON_COPY.getConfigNode(), changeGenerationOnCopy);
//Handles old book and quill settings //Handles old book and quill settings
@ -314,6 +325,7 @@ public class BooksWithoutBordersConfig {
adminDecrypt = getBoolean(config, ConfigOption.ADMIN_AUTO_DECRYPT); adminDecrypt = getBoolean(config, ConfigOption.ADMIN_AUTO_DECRYPT);
authorOnlyCopy = getBoolean(config, ConfigOption.AUTHOR_ONLY_COPY); authorOnlyCopy = getBoolean(config, ConfigOption.AUTHOR_ONLY_COPY);
authorOnlyUnsign = getBoolean(config, ConfigOption.AUTHOR_ONLY_UNSIGN); authorOnlyUnsign = getBoolean(config, ConfigOption.AUTHOR_ONLY_UNSIGN);
authorOnlySave = getBoolean(config, ConfigOption.AUTHOR_ONLY_SAVE);
firstBooks = config.getStringList(ConfigOption.BOOKS_FOR_NEW_PLAYERS.getConfigNode()); firstBooks = config.getStringList(ConfigOption.BOOKS_FOR_NEW_PLAYERS.getConfigNode());
welcomeMessage = getString(config, ConfigOption.MESSAGE_FOR_NEW_PLAYERS); welcomeMessage = getString(config, ConfigOption.MESSAGE_FOR_NEW_PLAYERS);
formatBooks = getBoolean(config, ConfigOption.FORMAT_AFTER_SIGNING); formatBooks = getBoolean(config, ConfigOption.FORMAT_AFTER_SIGNING);

View File

@ -60,6 +60,11 @@ public enum ConfigOption {
*/ */
AUTHOR_ONLY_UNSIGN("Options.Author_Only_Unsign", false), 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 * Whether to turn Original into Copy when copying books
*/ */

View File

@ -23,6 +23,8 @@ Options:
Author_Only_Copy: false Author_Only_Copy: false
# Whether to only allow the author of a book to unsign it # Whether to only allow the author of a book to unsign it
Author_Only_Unsign: false 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 # Whether to automatically format every book when it's signed
Format_Book_After_Signing: false 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 # Whether to display "COPY" or "COPY_OF_COPY" instead of "ORIGINAL" when a book is copied. This also uses the