summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKHobbits <rob@khobbits.co.uk>2013-01-13 16:30:22 +0000
committerKHobbits <rob@khobbits.co.uk>2013-01-13 16:30:22 +0000
commit9fe7712bd670395fd61c698e81316441438044bc (patch)
tree27e10487a3c7fa18b0abec835286fa280507219c
parent18a15ca63c2c68b45b8004c6f2d1f2693407e16b (diff)
downloadEssentials-9fe7712bd670395fd61c698e81316441438044bc.tar
Essentials-9fe7712bd670395fd61c698e81316441438044bc.tar.gz
Essentials-9fe7712bd670395fd61c698e81316441438044bc.tar.lz
Essentials-9fe7712bd670395fd61c698e81316441438044bc.tar.xz
Essentials-9fe7712bd670395fd61c698e81316441438044bc.zip
Clean up TextPager
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/textreader/TextPager.java69
2 files changed, 20 insertions, 51 deletions
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java b/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java
index 0179db0c0..4711ffe40 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java
@@ -82,7 +82,7 @@ public class Commandbalancetop extends EssentialsCommand
cal.setTimeInMillis(cacheage);
final DateFormat format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
sender.sendMessage(_("balanceTop", format.format(cal.getTime())));
- new TextPager(cache).showPage(Integer.toString(page), "", "balancetop", sender);
+ new TextPager(cache).showPage(Integer.toString(page), null, "balancetop", sender);
}
diff --git a/Essentials/src/com/earth2me/essentials/textreader/TextPager.java b/Essentials/src/com/earth2me/essentials/textreader/TextPager.java
index 3242d7509..503606527 100644
--- a/Essentials/src/com/earth2me/essentials/textreader/TextPager.java
+++ b/Essentials/src/com/earth2me/essentials/textreader/TextPager.java
@@ -30,57 +30,10 @@ public class TextPager
List<String> chapters = text.getChapters();
Map<String, Integer> bookmarks = text.getBookmarks();
- if (bookmarks.isEmpty())
- {
- int page = 1;
- try
- {
- page = Integer.parseInt(pageStr);
- }
- catch (Exception ex)
- {
- page = 1;
- }
- if (page < 1)
- {
- page = 1;
- }
-
- final int start = onePage ? 0 : (page - 1) * 9;
- final int pages = lines.size() / 9 + (lines.size() % 9 > 0 ? 1 : 0);
- if (!onePage && commandName != null)
- {
- StringBuilder content = new StringBuilder();
- final String[] title = commandName.split(" ", 2);
- if (title.length > 1)
- {
- content.append(I18n.capitalCase(title[0])).append(": ");
- content.append(title[1]);
- }
- else if (chapterPageStr != null)
- {
- content.append(I18n.capitalCase(commandName)).append(": ");
- content.append(chapterPageStr);
- }
- else
- {
- content.append(I18n.capitalCase(commandName));
- }
- sender.sendMessage(_("infoPages", page, pages, content));
- }
- for (int i = start; i < lines.size() && i < start + (onePage ? 20 : 9); i++)
- {
- sender.sendMessage("§r" + lines.get(i));
- }
- if (!onePage && page < pages && commandName != null)
- {
- sender.sendMessage(_("readNextPage", commandName, page + 1));
- }
- return;
- }
-
if (pageStr == null || pageStr.isEmpty() || pageStr.matches("[0-9]+"))
{
+ //If an info file starts with a chapter title, list the chapters
+ //If not display the text up until the first chapter.
if (lines.get(0).startsWith("#"))
{
if (onePage)
@@ -133,7 +86,23 @@ public class TextPager
if (!onePage && commandName != null)
{
- sender.sendMessage(_("infoPages", page, pages, I18n.capitalCase(commandName)));
+ StringBuilder content = new StringBuilder();
+ final String[] title = commandName.split(" ", 2);
+ if (title.length > 1)
+ {
+ content.append(I18n.capitalCase(title[0])).append(": ");
+ content.append(title[1]);
+ }
+ else if (chapterPageStr != null)
+ {
+ content.append(I18n.capitalCase(commandName)).append(": ");
+ content.append(chapterPageStr);
+ }
+ else
+ {
+ content.append(I18n.capitalCase(commandName));
+ }
+ sender.sendMessage(_("infoPages", page, pages, content));
}
for (int i = start; i < end && i < start + (onePage ? 20 : 9); i++)
{