Skip to content

Commit a29e1bf

Browse files
committed
Add support for multiple bookmarks/chapter names
Clean up info file handling
1 parent 3ccefb4 commit a29e1bf

File tree

5 files changed

+21
-16
lines changed

5 files changed

+21
-16
lines changed

Essentials/src/com/earth2me/essentials/textreader/IText.java

+3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66

77
public interface IText
88
{
9+
// Contains the raw text lines
910
List<String> getLines();
1011

12+
// Chapters contain the names that are displayed automatically if the file doesn't contain a introduction chapter.
1113
List<String> getChapters();
1214

15+
// Bookmarks contains the string mappings from 'chapters' to line numbers.
1316
Map<String, Integer> getBookmarks();
1417
}

Essentials/src/com/earth2me/essentials/textreader/TextInput.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import net.ess3.api.IEssentials;
44
import com.earth2me.essentials.User;
5+
import com.earth2me.essentials.utils.FormatUtil;
56
import com.earth2me.essentials.utils.StringUtil;
67
import java.io.*;
78
import java.lang.ref.SoftReference;
@@ -73,12 +74,15 @@ public TextInput(final CommandSender sender, final String filename, final boolea
7374
{
7475
break;
7576
}
76-
if (line.length() > 0 && line.charAt(0) == '#')
77+
if (line.length() > 1 && line.charAt(0) == '#')
7778
{
78-
bookmarks.put(line.substring(1).toLowerCase(Locale.ENGLISH).replaceAll("&[0-9a-fk]", ""), lineNumber);
79-
chapters.add(line.substring(1).replace('&', '§').replace("§§", "&").trim().replace(" ", "_"));
79+
String[] titles = line.substring(1).trim().replace(" ", "_").split(",");
80+
chapters.add(FormatUtil.replaceFormat(titles[0]));
81+
for (String title : titles) {
82+
bookmarks.put(FormatUtil.stripEssentialsFormat(title.toLowerCase(Locale.ENGLISH)), lineNumber);
83+
}
8084
}
81-
lines.add(line.replace('&', '§').replace("§§", "&"));
85+
lines.add(FormatUtil.replaceFormat(line));
8286
lineNumber++;
8387
}
8488
}

Essentials/src/com/earth2me/essentials/textreader/TextPager.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,6 @@ public void showPage(final String pageStr, final String chapterPageStr, final St
9595
content.append(I18n.capitalCase(title[0])).append(": ");
9696
content.append(title[1]);
9797
}
98-
else if (chapterPageStr != null)
99-
{
100-
content.append(I18n.capitalCase(commandName)).append(": ");
101-
content.append(chapterPageStr);
102-
}
10398
else
10499
{
105100
content.append(I18n.capitalCase(commandName));
@@ -161,7 +156,10 @@ else if (chapterPageStr != null)
161156
final int pages = (chapterend - chapterstart) / 9 + ((chapterend - chapterstart) % 9 > 0 ? 1 : 0);
162157
if (!onePage && commandName != null)
163158
{
164-
sender.sendMessage(_("infoChapterPages", pageStr, page, pages));
159+
StringBuilder content = new StringBuilder();
160+
content.append(I18n.capitalCase(commandName)).append(": ");
161+
content.append(pageStr);
162+
sender.sendMessage(_("infoChapterPages", content, page, pages));
165163
}
166164
for (int i = start; i < chapterend && i < start + (onePage ? 20 : 9); i++)
167165
{

Essentials/src/messages.properties

+3-3
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,10 @@ hour=hour
161161
hours=hours
162162
ignorePlayer=\u00a76You ignore player\u00a7c {0} \u00a76from now on.
163163
illegalDate=Illegal date format.
164-
infoChapter=Select chapter\:
165-
infoChapterPages=\u00a76Chapter {0}, page \u00a7c{1}\u00a76 of \u00a7c{2}\u00a76\:
164+
infoChapter=\u00a76Select chapter\:
165+
infoChapterPages=\u00a7e ---- \u00a76{0} \u00a7e--\u00a76 Page \u00a7c{1}\u00a76 of \u00a7c{2} \u00a7e----
166166
infoPages=\u00a7e ---- \u00a76{2} \u00a7e--\u00a76 Page \u00a7c{0}\u00a76/\u00a7c{1} \u00a7e----
167-
infoUnknownChapter=Unknown chapter.
167+
infoUnknownChapter=\u00a74Unknown chapter.
168168
insufficientFunds=\u00a74Insufficient funds available.
169169
invalidCharge=\u00a74Invalid charge.
170170
invalidFireworkFormat=\u00a76The option \u00a74{0} \u00a76is not a valid value for \u00a74{1}\u00a76.

Essentials/src/messages_en.properties

+3-3
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,10 @@ hour=hour
161161
hours=hours
162162
ignorePlayer=\u00a76You ignore player\u00a7c {0} \u00a76from now on.
163163
illegalDate=Illegal date format.
164-
infoChapter=Select chapter\:
165-
infoChapterPages=\u00a76Chapter {0}, page \u00a7c{1}\u00a76 of \u00a7c{2}\u00a76\:
164+
infoChapter=\u00a76Select chapter\:
165+
infoChapterPages=\u00a7e ---- \u00a76{0} \u00a7e--\u00a76 Page \u00a7c{1}\u00a76 of \u00a7c{2} \u00a7e----
166166
infoPages=\u00a7e ---- \u00a76{2} \u00a7e--\u00a76 Page \u00a7c{0}\u00a76/\u00a7c{1} \u00a7e----
167-
infoUnknownChapter=Unknown chapter.
167+
infoUnknownChapter=\u00a74Unknown chapter.
168168
insufficientFunds=\u00a74Insufficient funds available.
169169
invalidCharge=\u00a74Invalid charge.
170170
invalidFireworkFormat=\u00a76The option \u00a74{0} \u00a76is not a valid value for \u00a74{1}\u00a76.

0 commit comments

Comments
 (0)