1
0
mirror of https://github.com/essentials/Essentials.git synced 2025-08-28 00:40:05 +02:00

New Sign: Info

Syntax: [info] / [chapter] / [page number] / [cost]
This commit is contained in:
KHobbits
2012-08-06 00:58:35 +01:00
parent 789bc2b73b
commit a440e153c1
4 changed files with 62 additions and 6 deletions

View File

@@ -0,0 +1,54 @@
package com.earth2me.essentials.signs;
import com.earth2me.essentials.ChargeException;
import com.earth2me.essentials.IEssentials;
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.User;
import com.earth2me.essentials.textreader.IText;
import com.earth2me.essentials.textreader.KeywordReplacer;
import com.earth2me.essentials.textreader.TextInput;
import com.earth2me.essentials.textreader.TextPager;
import java.io.IOException;
public class SignInfo extends EssentialsSign
{
public SignInfo()
{
super("Info");
}
@Override
protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException
{
validateTrade(sign, 3, ess);
return true;
}
@Override
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException
{
final Trade charge = getTrade(sign, 3, ess);
charge.isAffordableFor(player);
String chapter = sign.getLine(1);
String page = sign.getLine(2);
final IText input;
try
{
input = new TextInput(player, "info", true, ess);
final IText output = new KeywordReplacer(input, player, ess);
final TextPager pager = new TextPager(output);
pager.showPage(chapter, page, null, player);
}
catch (IOException ex)
{
throw new SignException(ex.getMessage(), ex);
}
charge.charge(player);
return true;
}
}

View File

@@ -10,6 +10,7 @@ public enum Signs
FREE(new SignFree()), FREE(new SignFree()),
GAMEMODE(new SignGameMode()), GAMEMODE(new SignGameMode()),
HEAL(new SignHeal()), HEAL(new SignHeal()),
INFO(new SignInfo()),
KIT(new SignKit()), KIT(new SignKit()),
MAIL(new SignMail()), MAIL(new SignMail()),
PROTECTION(new SignProtection()), PROTECTION(new SignProtection()),

View File

@@ -48,7 +48,7 @@ public class TextPager
final int start = onePage ? 0 : (page - 1) * 9; final int start = onePage ? 0 : (page - 1) * 9;
final int pages = lines.size() / 9 + (lines.size() % 9 > 0 ? 1 : 0); final int pages = lines.size() / 9 + (lines.size() % 9 > 0 ? 1 : 0);
if (!onePage) if (!onePage && commandName != null)
{ {
StringBuilder content = new StringBuilder(); StringBuilder content = new StringBuilder();
final String[] title = commandName.split(" ", 2); final String[] title = commandName.split(" ", 2);
@@ -72,7 +72,7 @@ public class TextPager
{ {
sender.sendMessage(lines.get(i)); sender.sendMessage(lines.get(i));
} }
if (!onePage && page < pages) if (!onePage && page < pages && commandName != null)
{ {
sender.sendMessage(_("readNextPage", commandName, page + 1)); sender.sendMessage(_("readNextPage", commandName, page + 1));
} }
@@ -130,7 +130,7 @@ public class TextPager
} }
int pages = end / 9 + (end % 9 > 0 ? 1 : 0); int pages = end / 9 + (end % 9 > 0 ? 1 : 0);
if (!onePage) if (!onePage && commandName != null)
{ {
sender.sendMessage(_("infoPages", page, pages, I18n.capitalCase(commandName))); sender.sendMessage(_("infoPages", page, pages, I18n.capitalCase(commandName)));
@@ -139,7 +139,7 @@ public class TextPager
{ {
sender.sendMessage(lines.get(i)); sender.sendMessage(lines.get(i));
} }
if (!onePage && page < pages) if (!onePage && page < pages && commandName != null)
{ {
sender.sendMessage(_("readNextPage", commandName, page + 1)); sender.sendMessage(_("readNextPage", commandName, page + 1));
} }
@@ -183,7 +183,7 @@ public class TextPager
final int page = chapterpage + 1; final int page = chapterpage + 1;
final int pages = (chapterend - chapterstart) / 9 + ((chapterend - chapterstart) % 9 > 0 ? 1 : 0); final int pages = (chapterend - chapterstart) / 9 + ((chapterend - chapterstart) % 9 > 0 ? 1 : 0);
if (!onePage) if (!onePage && commandName != null)
{ {
sender.sendMessage(_("infoChapterPages", pageStr, page, pages)); sender.sendMessage(_("infoChapterPages", pageStr, page, pages));
} }
@@ -191,7 +191,7 @@ public class TextPager
{ {
sender.sendMessage(lines.get(i)); sender.sendMessage(lines.get(i));
} }
if (!onePage && page < pages) if (!onePage && page < pages && commandName != null)
{ {
sender.sendMessage(_("readNextPage", commandName, pageStr + " " + (page + 1))); sender.sendMessage(_("readNextPage", commandName, pageStr + " " + (page + 1)));
} }

View File

@@ -218,6 +218,7 @@ enabledSigns:
#- enchant #- enchant
#- gamemode #- gamemode
#- heal #- heal
#- info
#- spawnmob #- spawnmob
#- repair #- repair
#- time #- time