@@ -44,19 +44,41 @@ public class GhostLayer {
44
44
45
45
// These are mostly used for loaded books
46
46
// Note that EditBookScreen has its own bookTitle field that we need to keep track of
47
- public String bookTitle = "" ;
48
- public String bookAuthor = "" ;
47
+ private String bookTitle = "" ;
48
+ private String bookAuthor = "" ;
49
49
50
50
private boolean buttonsInitialized = false ;
51
51
52
52
53
53
public GhostLayer (IGhostBook parent , Screen screenParent , boolean bookIsEditable ) {
54
54
this .parent = parent ;
55
- this .screen = screenParent ; // TODO: Is there a cleaner way to do this?
55
+ this .screen = screenParent ;
56
56
this .bookIsEditable = bookIsEditable ;
57
57
}
58
58
59
59
60
+ public String getBookAuthor (){
61
+ return this .bookAuthor ;
62
+ }
63
+
64
+
65
+ public String getBookTitle (){
66
+ return this .bookTitle ;
67
+ }
68
+
69
+
70
+ /**
71
+ * Set the internal bookTitle field, enforcing the maximum length from SharedConstants
72
+ */
73
+ public void setBookTitle (String title ){
74
+ if (title .length () < SharedConstants .BOOK_TITLE_MAX_LEN ) {
75
+ this .bookTitle = title ;
76
+ } else {
77
+ this .bookTitle = title .substring (0 , SharedConstants .BOOK_TITLE_MAX_LEN );
78
+ }
79
+ }
80
+
81
+
60
82
/**
61
83
* Called by GhostwriterLecternScreen and GhostwriterReadBookScreen
62
84
* Extracts title and author
@@ -65,7 +87,7 @@ public void extractTitleAuthor(ItemStack bookStack) {
65
87
if (bookStack == null ) return ;
66
88
CompoundNBT compoundnbt = bookStack .getTag ();
67
89
if (compoundnbt == null ) return ;
68
- this .bookTitle = compoundnbt .getString ("title" );
90
+ this .setBookTitle ( compoundnbt .getString ("title" ) );
69
91
this .bookAuthor = compoundnbt .getString ("author" );
70
92
}
71
93
@@ -192,7 +214,7 @@ private void addSignaturePages() {
192
214
FileHandler fh = new FileHandler (clip );
193
215
File sigFile = new File (Ghostwriter .FILE_HANDLER .getSignaturePath (), "default.ghb" );
194
216
if (fh .loadBook (sigFile ) && clip .bookInClipboard ) {
195
- this .parent .insertNewPage (this .parent .getBookPageCount (), "" ); // TODO: Is this necessary?
217
+ this .parent .insertNewPage (this .parent .getBookPageCount (), "" );
196
218
Ghostwriter .GLOBAL_CLIPBOARD .miscPages .addAll (clip .pages );
197
219
pasteMultiplePages (this .parent .getBookPageCount () - 1 );
198
220
Ghostwriter .PRINTER .gamePrint (Printer .GRAY + "Signature pages added" );
@@ -260,7 +282,7 @@ private void collapseTop() {
260
282
* Copies a book from the clipboard into the 'real' book
261
283
*/
262
284
public void clipboardToBook (Clipboard fromBook ) {
263
- this .bookTitle = fromBook .title ;
285
+ this .setBookTitle ( fromBook .title ) ;
264
286
this .parent .setBookTitle (this .bookTitle );
265
287
this .parent .replaceBookPages (fromBook .pages );
266
288
if (this .parent .getBookPageCount () == 0 ) this .parent .insertNewPage (0 , "" );
@@ -364,14 +386,6 @@ public void updateButtons() {
364
386
}
365
387
366
388
this .buttonDisableAutoReload .active = this .autoReloadFile != null ;
367
-
368
- // TODO: Is there a better place to do this?
369
- // Trim book title to a max of 32 characters. Anything longer an the book will be marked invalid by
370
- // the client when you try to read it
371
- // updateButtons() is called when the 'sign' button is clicked, so it's a convenient time to check this
372
- if (this .bookTitle .length () > 32 ) {
373
- this .bookTitle = this .bookTitle .substring (0 , 32 );
374
- }
375
389
}
376
390
377
391
0 commit comments