Treats null book generation as the original
This commit is contained in:
parent
7467645bcd
commit
1100f181be
@ -73,7 +73,7 @@ public class CommandCopy implements TabExecutor {
|
||||
}
|
||||
|
||||
BookMeta bookMeta = (BookMeta) heldBook.getItemMeta();
|
||||
if (BooksWithoutBordersConfig.changeGenerationOnCopy() && bookMeta != null && bookMeta.hasGeneration()) {
|
||||
if (BooksWithoutBordersConfig.changeGenerationOnCopy() && bookMeta != null) {
|
||||
return copyNextGenerationBook(bookMeta, player, copies);
|
||||
} else {
|
||||
//Make sure the player can pay for the copying
|
||||
|
@ -63,7 +63,7 @@ public enum ConfigOption {
|
||||
/**
|
||||
* Whether to turn Original into Copy when copying books
|
||||
*/
|
||||
CHANGE_GENERATION_ON_COPY("Options.Decrease_Generation_On_Copy", false),
|
||||
CHANGE_GENERATION_ON_COPY("Options.Change_Generation_On_Copy", false),
|
||||
|
||||
/**
|
||||
* Whether to automatically format every signed book
|
||||
|
@ -25,7 +25,7 @@ public final class BookHelper {
|
||||
*/
|
||||
public static void increaseGeneration(ItemStack bookItem) {
|
||||
BookMeta bookMeta = (BookMeta) bookItem.getItemMeta();
|
||||
if (BooksWithoutBordersConfig.changeGenerationOnCopy() && bookMeta != null && bookMeta.hasGeneration()) {
|
||||
if (BooksWithoutBordersConfig.changeGenerationOnCopy() && bookMeta != null) {
|
||||
bookMeta.setGeneration(BookHelper.getNextGeneration(bookMeta.getGeneration()));
|
||||
bookItem.setItemMeta(bookMeta);
|
||||
}
|
||||
@ -41,6 +41,9 @@ public final class BookHelper {
|
||||
* @return <p>The next generation of the book</p>
|
||||
*/
|
||||
public static BookMeta.Generation getNextGeneration(BookMeta.Generation currentGeneration) {
|
||||
if (currentGeneration == null) {
|
||||
return BookMeta.Generation.COPY_OF_ORIGINAL;
|
||||
}
|
||||
return switch (currentGeneration) {
|
||||
case ORIGINAL -> BookMeta.Generation.COPY_OF_ORIGINAL;
|
||||
case COPY_OF_ORIGINAL -> BookMeta.Generation.COPY_OF_COPY;
|
||||
|
@ -64,7 +64,7 @@ public final class BookLoader {
|
||||
}
|
||||
|
||||
//Make sure the player can pay for the book
|
||||
if (BooksWithoutBordersConfig.booksHavePrice() &&
|
||||
if (BooksWithoutBordersConfig.booksHavePrice() &&
|
||||
!sender.hasPermission("bookswithoutborders.bypassBookPrice") &&
|
||||
(bookDirectory == BookDirectory.PUBLIC || bookDirectory == BookDirectory.PLAYER) &&
|
||||
EconomyHelper.cannotPayForBookPrinting((Player) sender, numCopies)) {
|
||||
|
@ -41,9 +41,11 @@ public final class BookToFromTextHelper {
|
||||
if (bookMetadata.hasAuthor()) {
|
||||
bookYml.set("Author", bookMetadata.getAuthor());
|
||||
}
|
||||
if (bookMetadata.hasGeneration() && bookMetadata.getGeneration() != null) {
|
||||
bookYml.set("Generation", bookMetadata.getGeneration().name());
|
||||
BookMeta.Generation generation = bookMetadata.getGeneration();
|
||||
if (generation == null) {
|
||||
generation = BookMeta.Generation.ORIGINAL;
|
||||
}
|
||||
bookYml.set("Generation", generation.name());
|
||||
if (bookMetadata.hasPages()) {
|
||||
bookYml.set("Pages", bookMetadata.getPages());
|
||||
}
|
||||
@ -84,15 +86,14 @@ public final class BookToFromTextHelper {
|
||||
PrintWriter printWriter = new PrintWriter(fileWriter);
|
||||
List<String> pages = bookMetadata.getPages();
|
||||
|
||||
String generation;
|
||||
if (bookMetadata.hasGeneration() && bookMetadata.getGeneration() != null) {
|
||||
generation = ":" + bookMetadata.getGeneration().name();
|
||||
} else {
|
||||
generation = "";
|
||||
BookMeta.Generation generation = bookMetadata.getGeneration();
|
||||
if (generation == null) {
|
||||
generation = BookMeta.Generation.ORIGINAL;
|
||||
}
|
||||
String generationString = ":" + generation.name();
|
||||
|
||||
//Save each page of the book as a text line
|
||||
printWriter.println("[Book]" + generation);
|
||||
printWriter.println("[Book]" + generationString);
|
||||
for (String page : pages) {
|
||||
printWriter.println(page);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user