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();
|
BookMeta bookMeta = (BookMeta) heldBook.getItemMeta();
|
||||||
if (BooksWithoutBordersConfig.changeGenerationOnCopy() && bookMeta != null && bookMeta.hasGeneration()) {
|
if (BooksWithoutBordersConfig.changeGenerationOnCopy() && bookMeta != null) {
|
||||||
return copyNextGenerationBook(bookMeta, player, copies);
|
return copyNextGenerationBook(bookMeta, player, copies);
|
||||||
} else {
|
} else {
|
||||||
//Make sure the player can pay for the copying
|
//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
|
* 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
|
* Whether to automatically format every signed book
|
||||||
|
@ -25,7 +25,7 @@ public final class BookHelper {
|
|||||||
*/
|
*/
|
||||||
public static void increaseGeneration(ItemStack bookItem) {
|
public static void increaseGeneration(ItemStack bookItem) {
|
||||||
BookMeta bookMeta = (BookMeta) bookItem.getItemMeta();
|
BookMeta bookMeta = (BookMeta) bookItem.getItemMeta();
|
||||||
if (BooksWithoutBordersConfig.changeGenerationOnCopy() && bookMeta != null && bookMeta.hasGeneration()) {
|
if (BooksWithoutBordersConfig.changeGenerationOnCopy() && bookMeta != null) {
|
||||||
bookMeta.setGeneration(BookHelper.getNextGeneration(bookMeta.getGeneration()));
|
bookMeta.setGeneration(BookHelper.getNextGeneration(bookMeta.getGeneration()));
|
||||||
bookItem.setItemMeta(bookMeta);
|
bookItem.setItemMeta(bookMeta);
|
||||||
}
|
}
|
||||||
@ -41,6 +41,9 @@ public final class BookHelper {
|
|||||||
* @return <p>The next generation of the book</p>
|
* @return <p>The next generation of the book</p>
|
||||||
*/
|
*/
|
||||||
public static BookMeta.Generation getNextGeneration(BookMeta.Generation currentGeneration) {
|
public static BookMeta.Generation getNextGeneration(BookMeta.Generation currentGeneration) {
|
||||||
|
if (currentGeneration == null) {
|
||||||
|
return BookMeta.Generation.COPY_OF_ORIGINAL;
|
||||||
|
}
|
||||||
return switch (currentGeneration) {
|
return switch (currentGeneration) {
|
||||||
case ORIGINAL -> BookMeta.Generation.COPY_OF_ORIGINAL;
|
case ORIGINAL -> BookMeta.Generation.COPY_OF_ORIGINAL;
|
||||||
case COPY_OF_ORIGINAL -> BookMeta.Generation.COPY_OF_COPY;
|
case COPY_OF_ORIGINAL -> BookMeta.Generation.COPY_OF_COPY;
|
||||||
|
@ -41,9 +41,11 @@ public final class BookToFromTextHelper {
|
|||||||
if (bookMetadata.hasAuthor()) {
|
if (bookMetadata.hasAuthor()) {
|
||||||
bookYml.set("Author", bookMetadata.getAuthor());
|
bookYml.set("Author", bookMetadata.getAuthor());
|
||||||
}
|
}
|
||||||
if (bookMetadata.hasGeneration() && bookMetadata.getGeneration() != null) {
|
BookMeta.Generation generation = bookMetadata.getGeneration();
|
||||||
bookYml.set("Generation", bookMetadata.getGeneration().name());
|
if (generation == null) {
|
||||||
|
generation = BookMeta.Generation.ORIGINAL;
|
||||||
}
|
}
|
||||||
|
bookYml.set("Generation", generation.name());
|
||||||
if (bookMetadata.hasPages()) {
|
if (bookMetadata.hasPages()) {
|
||||||
bookYml.set("Pages", bookMetadata.getPages());
|
bookYml.set("Pages", bookMetadata.getPages());
|
||||||
}
|
}
|
||||||
@ -84,15 +86,14 @@ public final class BookToFromTextHelper {
|
|||||||
PrintWriter printWriter = new PrintWriter(fileWriter);
|
PrintWriter printWriter = new PrintWriter(fileWriter);
|
||||||
List<String> pages = bookMetadata.getPages();
|
List<String> pages = bookMetadata.getPages();
|
||||||
|
|
||||||
String generation;
|
BookMeta.Generation generation = bookMetadata.getGeneration();
|
||||||
if (bookMetadata.hasGeneration() && bookMetadata.getGeneration() != null) {
|
if (generation == null) {
|
||||||
generation = ":" + bookMetadata.getGeneration().name();
|
generation = BookMeta.Generation.ORIGINAL;
|
||||||
} else {
|
|
||||||
generation = "";
|
|
||||||
}
|
}
|
||||||
|
String generationString = ":" + generation.name();
|
||||||
|
|
||||||
//Save each page of the book as a text line
|
//Save each page of the book as a text line
|
||||||
printWriter.println("[Book]" + generation);
|
printWriter.println("[Book]" + generationString);
|
||||||
for (String page : pages) {
|
for (String page : pages) {
|
||||||
printWriter.println(page);
|
printWriter.println(page);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user