Help command refresh.

This commit is contained in:
KHobbits 2012-03-23 17:16:09 +00:00
parent d0b94938e0
commit 0a74da88d6
10 changed files with 95 additions and 25 deletions

View file

@ -4,6 +4,7 @@ import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
import com.earth2me.essentials.textreader.*;
import java.util.Locale;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
@ -21,6 +22,7 @@ public class Commandhelp extends EssentialsCommand
IText output;
String pageStr = args.length > 0 ? args[0] : null;
String chapterPageStr = args.length > 1 ? args[1] : null;
String command = commandLabel;
final IText input = new TextInput(user, "help", false, ess);
if (input.getLines().isEmpty())
@ -31,7 +33,12 @@ public class Commandhelp extends EssentialsCommand
}
else
{
output = new HelpInput(user, pageStr, ess);
if (pageStr.length() > 26)
{
pageStr = pageStr.substring(0, 25);
}
output = new HelpInput(user, pageStr.toLowerCase(Locale.ENGLISH), ess);
command = command.concat(" ").concat(pageStr);
pageStr = chapterPageStr;
}
chapterPageStr = null;
@ -41,7 +48,7 @@ public class Commandhelp extends EssentialsCommand
output = new KeywordReplacer(input, user, ess);
}
final TextPager pager = new TextPager(output);
pager.showPage(pageStr, chapterPageStr, commandLabel, user);
pager.showPage(pageStr, chapterPageStr, command, user);
}
@Override

View file

@ -24,33 +24,46 @@ public class HelpInput implements IText
public HelpInput(final User user, final String match, final IEssentials ess) throws IOException
{
boolean reported = false;
final List<String> newLines = new ArrayList<String>();
String pluginName = "";
String pluginNameLow = "";
if (!match.equalsIgnoreCase(""))
{
lines.add(_("helpMatching", match));
}
for (Plugin p : ess.getServer().getPluginManager().getPlugins())
{
try
{
final PluginDescriptionFile desc = p.getDescription();
final Map<String, Map<String, Object>> cmds = desc.getCommands();
pluginName = p.getDescription().getName().toLowerCase(Locale.ENGLISH);
pluginName = p.getDescription().getName();
pluginNameLow = pluginName.toLowerCase(Locale.ENGLISH);
if (pluginNameLow.equals(match))
{
lines.clear();
newLines.clear();
lines.add(_("helpFrom", p.getDescription().getName()));
}
for (Map.Entry<String, Map<String, Object>> k : cmds.entrySet())
{
try
{
if ((!match.equalsIgnoreCase(""))
&& (!k.getKey().toLowerCase(Locale.ENGLISH).contains(match))
if (!match.equalsIgnoreCase("") && (!pluginNameLow.contains(match)) && (!k.getKey().toLowerCase(Locale.ENGLISH).contains(match))
&& (!(k.getValue().get(DESCRIPTION) instanceof String
&& ((String)k.getValue().get(DESCRIPTION)).toLowerCase(Locale.ENGLISH).contains(match)))
&& (!pluginName.contains(match)))
&& ((String)k.getValue().get(DESCRIPTION)).toLowerCase(Locale.ENGLISH).contains(match))))
{
continue;
}
if (pluginName.contains("essentials"))
if (pluginNameLow.contains("essentials"))
{
final String node = "essentials." + k.getKey();
if (!ess.getSettings().isCommandDisabled(k.getKey()) && user.isAuthorized(node))
{
lines.add(_("helpLine", k.getKey(), k.getValue().get(DESCRIPTION)));
newLines.add(_("helpLine", k.getKey(), k.getValue().get(DESCRIPTION)));
}
}
else
@ -67,9 +80,9 @@ public class HelpInput implements IText
{
permissions = value.get(PERMISSIONS);
}
if (user.isAuthorized("essentials.help." + pluginName))
if (user.isAuthorized("essentials.help." + pluginNameLow))
{
lines.add(_("helpLine", k.getKey(), value.get(DESCRIPTION)));
newLines.add(_("helpLine", k.getKey(), value.get(DESCRIPTION)));
}
else if (permissions instanceof List && !((List<Object>)permissions).isEmpty())
{
@ -84,21 +97,21 @@ public class HelpInput implements IText
}
if (enabled)
{
lines.add(_("helpLine", k.getKey(), value.get(DESCRIPTION)));
newLines.add(_("helpLine", k.getKey(), value.get(DESCRIPTION)));
}
}
else if (permissions instanceof String && !"".equals(permissions))
{
if (user.isAuthorized(permissions.toString()))
{
lines.add(_("helpLine", k.getKey(), value.get(DESCRIPTION)));
newLines.add(_("helpLine", k.getKey(), value.get(DESCRIPTION)));
}
}
else
{
if (!ess.getSettings().hidePermissionlessHelp())
{
lines.add(_("helpLine", k.getKey(), value.get(DESCRIPTION)));
newLines.add(_("helpLine", k.getKey(), value.get(DESCRIPTION)));
}
}
}
@ -109,6 +122,17 @@ public class HelpInput implements IText
continue;
}
}
if (!newLines.isEmpty())
{
if (pluginNameLow.equals(match))
{
break;
}
if (match.equalsIgnoreCase(""))
{
lines.add(_("helpPlugin", pluginName, pluginNameLow));
}
}
}
catch (NullPointerException ex)
{
@ -118,12 +142,13 @@ public class HelpInput implements IText
{
if (!reported)
{
logger.log(Level.WARNING, _("commandHelpFailedForPlugin", pluginName), ex);
logger.log(Level.WARNING, _("commandHelpFailedForPlugin", pluginNameLow), ex);
}
reported = true;
continue;
}
}
lines.addAll(newLines);
}
@Override

View file

@ -1,5 +1,6 @@
package com.earth2me.essentials.textreader;
import com.earth2me.essentials.I18n;
import static com.earth2me.essentials.I18n._;
import java.util.List;
import java.util.Locale;
@ -49,7 +50,23 @@ public class TextPager
final int pages = lines.size() / 9 + (lines.size() % 9 > 0 ? 1 : 0);
if (!onePage)
{
sender.sendMessage(_("infoPages", page, pages));
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++)
{
@ -116,7 +133,7 @@ public class TextPager
if (!onePage)
{
sender.sendMessage(_("infoPages", page, pages));
sender.sendMessage(_("infoPages", page, pages, I18n.capitalCase(commandName)));
}
for (int i = start; i < end && i < start + (onePage ? 20 : 9); i++)
{

View file

@ -111,9 +111,12 @@ haveBeenReleased=\u00a77You have been released
heal=\u00a77You have been healed.
healOther=\u00a77Healed {0}.
helpConsole=To view help from the console, type ?.
helpFrom=\u00a77Commands from {0}:
helpLine=\u00a76/{0}\u00a7f: {1}
helpMatching=\u00a77Commands matching "{0}":
helpOp=\u00a7c[HelpOp]\u00a7f \u00a77{0}:\u00a7f {1}
helpPages=Page \u00a7c{0}\u00a7f of \u00a7c{1}\u00a7f:
helpPlugin=\u00a74{0}\u00a7f: Plugin Help: /help {1}
holeInFloor=Hole in floor
homeSet=\u00a77Home set.
homeSetToBed=\u00a77Your home is now set to this bed.
@ -125,7 +128,7 @@ illegalDate=Illegal date format.
infoChapter=Select chapter:
infoChapterPages=Chapter {0}, page \u00a7c{1}\u00a7f of \u00a7c{2}\u00a7f:
infoFileDoesNotExist=File info.txt does not exist. Creating one for you.
infoPages=Page \u00a7c{0}\u00a7f of \u00a7c{1}\u00a7f:
infoPages=\u00a7e ---- \u00a76{2} \u00a7e--\u00a76 Page \u00a74{0}\u00a76/\u00a74{1} \u00a7e----
infoUnknownChapter=Unknown chapter.
invBigger=The other users inventory is bigger than yours.
invRestored=Your inventory has been restored.
@ -133,7 +136,7 @@ invSee=You see the inventory of {0}.
invSeeHelp=Use /invsee to restore your inventory.
invalidCharge=\u00a7cInvalid charge.
invalidHome=Home {0} doesn't exist
invalidMob=Invalid mob type.
invalidMob=Invalid mob type.&
invalidServer=Invalid server!
invalidSignLine=Line {0} on sign is invalid.
invalidWorld=\u00a7cInvalid world.

View file

@ -111,9 +111,12 @@ haveBeenReleased=\u00a77Du er blevet l\u00f8sladt
heal=\u00a77Du er blevet healed.
healOther=\u00a77Healed {0}.
helpConsole=For at se hj\u00e6lp fra konsolen, skriv ?.
helpFrom=\u00a77Commands from {0}:
helpLine=\u00a76/{0}\u00a7f: {1}
helpMatching=\u00a77Commands matching "{0}":
helpOp=\u00a7c[HelpOp]\u00a7f \u00a77{0}:\u00a7f {1}
helpPages=Side \u00a7c{0}\u00a7f af \u00a7c{1}\u00a7f:
helpPlugin=\u00a74{0}\u00a7f: Plugin Help: /help {1}
holeInFloor=Hul i gulv
homeSet=\u00a77Hjem sat.
homeSetToBed=\u00a77Dit hjem er nu sat til denne seng.
@ -125,7 +128,7 @@ illegalDate=Forkert datoformat.
infoChapter=V\u00e6lg kapitel:
infoChapterPages=Kapitel {0}, side \u00a7c{1}\u00a7f af \u00a7c{2}\u00a7f:
infoFileDoesNotExist=Fil info.txt eksisterer ikke. Fixer liiige en for dig.
infoPages=Side \u00a7c{0}\u00a7f af \u00a7c{1}\u00a7f:
infoPages=\u00a7e ---- \u00a76{2} \u00a7e--\u00a76 Side \u00a74{0}\u00a76/\u00a74{1} \u00a7e----
infoUnknownChapter=Ukendt kapitel.
invBigger=Den anden brugers inventory er st\u00f8rre end din.
invRestored=Din inventory er blevet genoprettet.

View file

@ -111,9 +111,12 @@ haveBeenReleased=\u00a77Du wurdest frei gelassen.
heal=\u00a77Du wurdest geheilt.
healOther=\u00a77{0} geheilt.
helpConsole=Um die Hilfe der Konsole zu sehen, schreibe ?.
helpFrom=\u00a77Commands from {0}:
helpLine=\u00a76/{0}\u00a7f: {1}
helpMatching=\u00a77Commands matching "{0}":
helpOp=\u00a7c[Hilfe]\u00a7f \u00a77{0}:\u00a7f {1}
helpPages=Seite \u00a7c{0}\u00a7f von \u00a7c{1}\u00a7f:
helpPlugin=\u00a74{0}\u00a7f: Plugin Help: /help {1}
holeInFloor=Loch im Boden
homeSet=\u00a77Zuhause gesetzt.
homeSetToBed=\u00a77Dein Zuhause ist nun an diesem Bett.
@ -125,7 +128,7 @@ illegalDate=Ung\u00fcltiges Datumsformat.
infoChapter=W\u00e4hle Kapitel:
infoChapterPages=Kapitel {0}, Seite \u00a7c{1}\u00a7f von \u00a7c{2}\u00a7f:
infoFileDoesNotExist=Datei info.txt existiert nicht. Erzeuge eine neue Datei.
infoPages=Seite \u00a7c{0}\u00a7f von \u00a7c{1}\u00a7f:
infoPages=\u00a7e ---- \u00a76{2} \u00a7e--\u00a76 Seite \u00a74{0}\u00a76/\u00a74{1} \u00a7e----
infoUnknownChapter=Unbekanntes Kapitel:
invBigger=Das andere Inventar ist gr\u00f6sser als deins.
invRestored=Dein Inventar wurde wieder hergestellt.

View file

@ -111,9 +111,12 @@ haveBeenReleased=\u00a77You have been released
heal=\u00a77You have been healed.
healOther=\u00a77Healed {0}.
helpConsole=To view help from the console, type ?.
helpFrom=\u00a77Commands from {0}:
helpLine=\u00a76/{0}\u00a7f: {1}
helpMatching=\u00a77Commands matching "{0}":
helpOp=\u00a7c[HelpOp]\u00a7f \u00a77{0}:\u00a7f {1}
helpPages=Page \u00a7c{0}\u00a7f of \u00a7c{1}\u00a7f:
helpPlugin=\u00a74{0}\u00a7f: Plugin Help: /help {1}
holeInFloor=Hole in floor
homeSet=\u00a77Home set.
homeSetToBed=\u00a77Your home is now set to this bed.
@ -125,7 +128,7 @@ illegalDate=Illegal date format.
infoChapter=Select chapter:
infoChapterPages=Chapter {0}, page \u00a7c{1}\u00a7f of \u00a7c{2}\u00a7f:
infoFileDoesNotExist=File info.txt does not exist. Creating one for you.
infoPages=Page \u00a7c{0}\u00a7f of \u00a7c{1}\u00a7f:
infoPages=\u00a7e ---- \u00a76{2} \u00a7e--\u00a76 Page \u00a74{0}\u00a76/\u00a74{1} &e----
infoUnknownChapter=Unknown chapter.
invBigger=The other users inventory is bigger than yours.
invRestored=Your inventory has been restored.

View file

@ -111,9 +111,12 @@ haveBeenReleased=\u00a77Has sido liberado
heal=\u00a77Has sido curado.
healOther=\u00a77Has curado a {0}.
helpConsole=Para obtener ayuda de la consola, escribe ?.
helpFrom=\u00a77Commands from {0}:
helpLine=\u00a76/{0}\u00a7f: {1}
helpMatching=\u00a77Commands matching "{0}":
helpOp=\u00a7c[HelpOp]\u00a7f \u00a77{0}:\u00a7f {1}
helpPages=Pagina \u00a7c{0}\u00a7f de \u00a7c{1}\u00a7f:
helpPlugin=\u00a74{0}\u00a7f: Plugin Help: /help {1}
holeInFloor=Agujero en el suelo
homeSet=\u00a77Hogar establecido.
homeSetToBed=\u00a77Tu hogar esta ahora establecido a esta cama.
@ -125,7 +128,7 @@ illegalDate=Forma de fecha ilegal.
infoChapter=Selecciona una seccion:
infoChapterPages=Seccion {0}, pagina \u00a7c{1}\u00a7f of \u00a7c{2}\u00a7f:
infoFileDoesNotExist=El archivo info.txt no existe. Creando uno para ti.
infoPages=Pagina \u00a7c{0}\u00a7f de \u00a7c{1}\u00a7f:
infoPages=\u00a7e ---- \u00a76{2} \u00a7e--\u00a76 Pagina \u00a74{0}\u00a76/\u00a74{1} \u00a7e----
infoUnknownChapter=Seccion desconocida.
invBigger=El inventario del otro usuario es mas grande que el tuyo
invRestored=Tu inventario ha sido recuperado.

View file

@ -111,9 +111,12 @@ haveBeenReleased=\u00a77Vous avez \u00e9t\u00e9 lib\u00e9r\u00e9.
heal=\u00a77Vous avez \u00e9t\u00e9 soign\u00e9.
healOther=\u00a77{0} a \u00e9t\u00e9 soign\u00e9.
helpConsole=Pour voir l''aide tapez ?
helpFrom=\u00a77Commands from {0}:
helpLine=\u00a76/{0}\u00a7f: {1}
helpMatching=\u00a77Commands matching "{0}":
helpOp=\u00a7c[Aide Admin]\u00a7f \u00a77{0} : \u00a7f {1}
helpPages=Page \u00a7c{0}\u00a7f sur \u00a7c{1}\u00a7f.
helpPlugin=\u00a74{0}\u00a7f: Plugin Help: /help {1}
holeInFloor=Trou dans le Sol.
homeSet=\u00a77R\u00e9sidence d\u00e9finie.
homeSetToBed=\u00a77Votre r\u00e9sidence est d\u00e9sormais li\u00e9e \u00e0 ce lit.
@ -125,7 +128,7 @@ illegalDate=Format de date ill\u00e9gal.
infoChapter=S\u00e9lectionnez le chapitre :
infoChapterPages=Chapitre {0}, page \u00a7c{1}\u00a7f sur \u00a7c{2}\u00a7f:
infoFileDoesNotExist=Le fichier info.txt n'existe pas. Le fichier est en cours de cr\u00e9ation pour vous.
infoPages=Page \u00a7c{0}\u00a7f de \u00a7c{1}\u00a7f.
infoPages=\u00a7e ---- \u00a76{2} \u00a7e--\u00a76 Page \u00a74{0}\u00a76/\u00a74{1} \u00a7e----
infoUnknownChapter=Chapitre inconnu.
invBigger=Les inventaires des autres joueurs sont plus gros que le v\u00f4tre.
invRestored=Votre inventaire vous a \u00e9t\u00e9 rendu.

View file

@ -111,9 +111,12 @@ haveBeenReleased=\u00a77Je bent bevrijdt
heal=\u00a77Je bent genezen.
healOther=\u00a77Je geneezde {0}.
helpConsole=type ? om de consolehelp weer te geven.
helpFrom=\u00a77Commands from {0}:
helpLine=\u00a76/{0}\u00a7f: {1}
helpMatching=\u00a77Commands matching "{0}":
helpOp=\u00a7c[HelpOp]\u00a7f \u00a77{0}:\u00a7f {1}
helpPages=Pagina \u00a7c{0}\u00a7f van de \u00a7c{1}\u00a7f:
helpPlugin=\u00a74{0}\u00a7f: Plugin Help: /help {1}
holeInFloor=Gat in de vloer
homeSet=\u00a77Home ingesteld.
homeSetToBed=\u00a77Je home is is nu verplaatst naar dit bed.
@ -125,7 +128,7 @@ illegalDate=Illegaal data formaat.
infoChapter=Selecteer hoofdstuk:
infoChapterPages=Hoofdstuk {0}, Pagina \u00a7c{1}\u00a7f van de \u00a7c{2}\u00a7f:
infoFileDoesNotExist=Bestand info.txt bestaat niet. Bezig met aanmaken.
infoPages=Pagina \u00a7c{0}\u00a7f van de \u00a7c{1}\u00a7f:
infoPages=\u00a7e ---- \u00a76{2} \u00a7e--\u00a76 Pagina \u00a74{0}\u00a76/\u00a74{1} \u00a7e----
infoUnknownChapter=Onbekend hoofdstuk.
invBigger=De inventory van de andere speler is groter dan die van jou.
invRestored=Je inventory is hersteld.