2011-11-22 04:00:04 +00:00
|
|
|
package com.earth2me.essentials.textreader;
|
|
|
|
|
2014-03-20 15:54:07 +00:00
|
|
|
import static com.earth2me.essentials.I18n.tl;
|
2011-11-22 04:00:04 +00:00
|
|
|
import com.earth2me.essentials.User;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
2013-10-11 02:44:41 +00:00
|
|
|
import net.ess3.api.IEssentials;
|
2011-11-22 04:00:04 +00:00
|
|
|
import org.bukkit.plugin.Plugin;
|
|
|
|
import org.bukkit.plugin.PluginDescriptionFile;
|
|
|
|
|
|
|
|
|
|
|
|
public class HelpInput implements IText
|
|
|
|
{
|
|
|
|
private static final String DESCRIPTION = "description";
|
|
|
|
private static final String PERMISSION = "permission";
|
|
|
|
private static final String PERMISSIONS = "permissions";
|
2014-02-04 16:11:43 +00:00
|
|
|
private static final Logger logger = Logger.getLogger("Essentials");
|
2011-11-22 04:00:04 +00:00
|
|
|
private final transient List<String> lines = new ArrayList<String>();
|
|
|
|
private final transient List<String> chapters = new ArrayList<String>();
|
|
|
|
private final transient Map<String, Integer> bookmarks = new HashMap<String, Integer>();
|
|
|
|
|
|
|
|
public HelpInput(final User user, final String match, final IEssentials ess) throws IOException
|
|
|
|
{
|
|
|
|
boolean reported = false;
|
2012-03-23 17:16:09 +00:00
|
|
|
final List<String> newLines = new ArrayList<String>();
|
2011-11-22 04:00:04 +00:00
|
|
|
String pluginName = "";
|
2012-03-23 17:16:09 +00:00
|
|
|
String pluginNameLow = "";
|
|
|
|
if (!match.equalsIgnoreCase(""))
|
|
|
|
{
|
2014-03-20 15:54:07 +00:00
|
|
|
lines.add(tl("helpMatching", match));
|
2012-03-23 17:16:09 +00:00
|
|
|
}
|
|
|
|
|
2011-11-22 04:00:04 +00:00
|
|
|
for (Plugin p : ess.getServer().getPluginManager().getPlugins())
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2012-03-23 18:26:19 +00:00
|
|
|
final List<String> pluginLines = new ArrayList<String>();
|
2011-11-22 04:00:04 +00:00
|
|
|
final PluginDescriptionFile desc = p.getDescription();
|
2012-03-01 15:15:37 +00:00
|
|
|
final Map<String, Map<String, Object>> cmds = desc.getCommands();
|
2012-03-23 17:16:09 +00:00
|
|
|
pluginName = p.getDescription().getName();
|
|
|
|
pluginNameLow = pluginName.toLowerCase(Locale.ENGLISH);
|
|
|
|
if (pluginNameLow.equals(match))
|
|
|
|
{
|
|
|
|
lines.clear();
|
|
|
|
newLines.clear();
|
2014-03-20 15:54:07 +00:00
|
|
|
lines.add(tl("helpFrom", p.getDescription().getName()));
|
2012-03-23 17:16:09 +00:00
|
|
|
}
|
2012-12-20 22:54:36 +00:00
|
|
|
final boolean isOnWhitelist = user.isAuthorized("essentials.help." + pluginNameLow);
|
2012-03-23 17:16:09 +00:00
|
|
|
|
2012-03-01 15:15:37 +00:00
|
|
|
for (Map.Entry<String, Map<String, Object>> k : cmds.entrySet())
|
2011-11-22 04:00:04 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2012-03-23 17:16:09 +00:00
|
|
|
if (!match.equalsIgnoreCase("") && (!pluginNameLow.contains(match)) && (!k.getKey().toLowerCase(Locale.ENGLISH).contains(match))
|
2011-11-22 04:00:04 +00:00
|
|
|
&& (!(k.getValue().get(DESCRIPTION) instanceof String
|
2012-03-23 17:16:09 +00:00
|
|
|
&& ((String)k.getValue().get(DESCRIPTION)).toLowerCase(Locale.ENGLISH).contains(match))))
|
2011-11-22 04:00:04 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-03-23 17:16:09 +00:00
|
|
|
if (pluginNameLow.contains("essentials"))
|
2011-11-22 04:00:04 +00:00
|
|
|
{
|
|
|
|
final String node = "essentials." + k.getKey();
|
|
|
|
if (!ess.getSettings().isCommandDisabled(k.getKey()) && user.isAuthorized(node))
|
|
|
|
{
|
2014-03-20 15:54:07 +00:00
|
|
|
pluginLines.add(tl("helpLine", k.getKey(), k.getValue().get(DESCRIPTION)));
|
2011-11-22 04:00:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (ess.getSettings().showNonEssCommandsInHelp())
|
|
|
|
{
|
2012-03-01 15:15:37 +00:00
|
|
|
final Map<String, Object> value = k.getValue();
|
2011-11-22 04:00:04 +00:00
|
|
|
Object permissions = null;
|
|
|
|
if (value.containsKey(PERMISSION))
|
|
|
|
{
|
|
|
|
permissions = value.get(PERMISSION);
|
|
|
|
}
|
|
|
|
else if (value.containsKey(PERMISSIONS))
|
|
|
|
{
|
|
|
|
permissions = value.get(PERMISSIONS);
|
|
|
|
}
|
2012-12-20 22:57:38 +00:00
|
|
|
if (isOnWhitelist || user.isAuthorized("essentials.help." + pluginNameLow + "." + k.getKey()))
|
2011-11-22 04:00:04 +00:00
|
|
|
{
|
2014-03-20 15:54:07 +00:00
|
|
|
pluginLines.add(tl("helpLine", k.getKey(), value.get(DESCRIPTION)));
|
2011-11-22 04:00:04 +00:00
|
|
|
}
|
|
|
|
else if (permissions instanceof List && !((List<Object>)permissions).isEmpty())
|
|
|
|
{
|
|
|
|
boolean enabled = false;
|
|
|
|
for (Object o : (List<Object>)permissions)
|
|
|
|
{
|
2011-11-22 04:41:34 +00:00
|
|
|
if (o instanceof String && user.isAuthorized(o.toString()))
|
2011-11-22 04:00:04 +00:00
|
|
|
{
|
|
|
|
enabled = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (enabled)
|
|
|
|
{
|
2014-03-20 15:54:07 +00:00
|
|
|
pluginLines.add(tl("helpLine", k.getKey(), value.get(DESCRIPTION)));
|
2011-11-22 04:00:04 +00:00
|
|
|
}
|
|
|
|
}
|
2011-11-22 04:41:34 +00:00
|
|
|
else if (permissions instanceof String && !"".equals(permissions))
|
2011-11-22 04:00:04 +00:00
|
|
|
{
|
2011-11-22 04:41:34 +00:00
|
|
|
if (user.isAuthorized(permissions.toString()))
|
|
|
|
{
|
2014-03-20 15:54:07 +00:00
|
|
|
pluginLines.add(tl("helpLine", k.getKey(), value.get(DESCRIPTION)));
|
2011-11-22 04:41:34 +00:00
|
|
|
}
|
2011-11-22 04:00:04 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!ess.getSettings().hidePermissionlessHelp())
|
|
|
|
{
|
2014-03-20 15:54:07 +00:00
|
|
|
pluginLines.add(tl("helpLine", k.getKey(), value.get(DESCRIPTION)));
|
2011-11-22 04:00:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (NullPointerException ex)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
2012-03-23 18:26:19 +00:00
|
|
|
if (!pluginLines.isEmpty())
|
2012-03-23 17:16:09 +00:00
|
|
|
{
|
2012-03-23 18:26:19 +00:00
|
|
|
newLines.addAll(pluginLines);
|
2012-03-23 17:16:09 +00:00
|
|
|
if (pluginNameLow.equals(match))
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (match.equalsIgnoreCase(""))
|
|
|
|
{
|
2014-03-20 15:54:07 +00:00
|
|
|
lines.add(tl("helpPlugin", pluginName, pluginNameLow));
|
2012-03-23 17:16:09 +00:00
|
|
|
}
|
|
|
|
}
|
2011-11-22 04:00:04 +00:00
|
|
|
}
|
|
|
|
catch (NullPointerException ex)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
if (!reported)
|
|
|
|
{
|
2014-03-20 15:54:07 +00:00
|
|
|
logger.log(Level.WARNING, tl("commandHelpFailedForPlugin", pluginNameLow), ex);
|
2011-11-22 04:00:04 +00:00
|
|
|
}
|
|
|
|
reported = true;
|
|
|
|
}
|
|
|
|
}
|
2012-03-23 17:16:09 +00:00
|
|
|
lines.addAll(newLines);
|
2011-11-22 04:00:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<String> getLines()
|
|
|
|
{
|
|
|
|
return lines;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<String> getChapters()
|
|
|
|
{
|
|
|
|
return chapters;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Map<String, Integer> getBookmarks()
|
|
|
|
{
|
|
|
|
return bookmarks;
|
|
|
|
}
|
|
|
|
}
|