Makes sure utility classes cannot be extended or instantiated

This commit is contained in:
Kristian Knarvik 2021-09-02 00:23:19 +02:00
parent d84baac9b7
commit bafd30e273
5 changed files with 36 additions and 9 deletions

View File

@ -4,10 +4,12 @@ import java.util.List;
/** /**
* A class for formatting text to fit books * A class for formatting text to fit books
*
* <p>The book formatter</p>
*/ */
public class BookFormatter { public final class BookFormatter {
private BookFormatter() {
}
/** /**
* Formats the last page of a set of pages * Formats the last page of a set of pages

View File

@ -20,7 +20,14 @@ import static net.knarcraft.bookswithoutborders.BooksWithoutBordersSettings.getS
import static net.knarcraft.bookswithoutborders.utility.InputCleaningHelper.cleanString; import static net.knarcraft.bookswithoutborders.utility.InputCleaningHelper.cleanString;
import static net.knarcraft.bookswithoutborders.utility.InputCleaningHelper.fixName; import static net.knarcraft.bookswithoutborders.utility.InputCleaningHelper.fixName;
public class EncryptionHelper { /**
* Helper class for book encryption
*/
public final class EncryptionHelper {
private EncryptionHelper() {
}
/** /**
* Transforms a string key/password into its numerical values * Transforms a string key/password into its numerical values
@ -239,7 +246,7 @@ public class EncryptionHelper {
* @param groupName <p>The group which should be able to decrypt the book</p> * @param groupName <p>The group which should be able to decrypt the book</p>
* @return <p>The new encrypted metadata for the book, or null if encryption failed</p> * @return <p>The new encrypted metadata for the book, or null if encryption failed</p>
*/ */
protected static BookMeta saveEncryptedBookForGroup(Player player, BookMeta bookMetadata, String groupName) { private static BookMeta saveEncryptedBookForGroup(Player player, BookMeta bookMetadata, String groupName) {
String path = getBookFolder() + "Encrypted" + getSlash() + cleanString(groupName) + getSlash(); String path = getBookFolder() + "Encrypted" + getSlash() + cleanString(groupName) + getSlash();
File dirTest = new File(path); File dirTest = new File(path);
//Creates group dir //Creates group dir
@ -294,7 +301,7 @@ public class EncryptionHelper {
* @param key <p>The key to use for encryption</p> * @param key <p>The key to use for encryption</p>
* @return <p>The new encrypted metadata for the book, or null if encryption failed</p> * @return <p>The new encrypted metadata for the book, or null if encryption failed</p>
*/ */
protected static Boolean saveEncryptedBook(Player player, BookMeta bookMetaData, String key) { private static Boolean saveEncryptedBook(Player player, BookMeta bookMetaData, String key) {
String path = getBookFolder() + "Encrypted" + getSlash(); String path = getBookFolder() + "Encrypted" + getSlash();
String fileName = (!bookMetaData.hasTitle()) ? "Untitled," + player.getName() : String fileName = (!bookMetaData.hasTitle()) ? "Untitled," + player.getName() :
bookMetaData.getTitle() + BooksWithoutBorders.titleAuthorSeparator + bookMetaData.getAuthor(); bookMetaData.getTitle() + BooksWithoutBorders.titleAuthorSeparator + bookMetaData.getAuthor();

View File

@ -9,7 +9,14 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class FileHelper { /**
* Helper class for dealing with files
*/
public final class FileHelper {
private FileHelper() {
}
/** /**
* Checks if a file path points to an actual book * Checks if a file path points to an actual book

View File

@ -3,7 +3,14 @@ package net.knarcraft.bookswithoutborders.utility;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class InputCleaningHelper { /**
* Helper class for cleaning input and names
*/
public final class InputCleaningHelper {
private InputCleaningHelper() {
}
/** /**
* Removes null and empty items from a list * Removes null and empty items from a list

View File

@ -11,7 +11,11 @@ import org.bukkit.inventory.meta.BookMeta;
/** /**
* The inventory helper mainly helps with getting and setting books * The inventory helper mainly helps with getting and setting books
*/ */
public class InventoryHelper { public final class InventoryHelper {
private InventoryHelper() {
}
/** /**
* Gets the book the holder is playing * Gets the book the holder is playing