Adding some debug info to /essentials

This commit is contained in:
KHobbits 2011-11-29 17:21:18 +00:00
parent cdbae1631d
commit af7eae6201
3 changed files with 52 additions and 12 deletions

View file

@ -11,6 +11,7 @@ import org.bukkit.plugin.Plugin;
public class AlternativeCommandsHandler
{
private final transient Map<String, List<PluginCommand>> altcommands = new HashMap<String, List<PluginCommand>>();
private final transient Set<String> executed = new HashSet<String>();
private final transient IEssentials ess;
public AlternativeCommandsHandler(final IEssentials ess)
@ -100,7 +101,7 @@ public class AlternativeCommandsHandler
if (commands == null || commands.isEmpty())
{
return null;
}
}
if (commands.size() == 1)
{
return commands.get(0);
@ -114,4 +115,14 @@ public class AlternativeCommandsHandler
// return the first alias
return commands.get(0);
}
public void executed(final String label)
{
executed.add(label);
}
public List<String> disabledCommands()
{
return new ArrayList<String>(executed);
}
}

View file

@ -273,7 +273,8 @@ public class Essentials extends JavaPlugin implements IEssentials
final PluginCommand pc = alternativeCommandsHandler.getAlternative(commandLabel);
if (pc != null)
{
LOGGER.info("Essentials: Alternative command " + commandLabel + " found, using " + pc.getLabel());
alternativeCommandsHandler.executed(commandLabel);
LOGGER.log(Level.FINE,"Essentials: Alternative command " + commandLabel + " found, using " + pc.getLabel());
return pc.execute(sender, commandLabel, args);
}
}

View file

@ -1,6 +1,7 @@
package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Util;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.Location;
@ -23,12 +24,44 @@ public class Commandessentials extends EssentialsCommand
@Override
public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{
if (args.length > 0 && args[0].equalsIgnoreCase("debug"))
{
ess.getSettings().setDebug(!ess.getSettings().isDebug());
sender.sendMessage("Essentials " + ess.getDescription().getVersion() + " debug mode " + (ess.getSettings().isDebug() ? "enabled" : "disabled"));
return;
if (args.length == 0) {
run_disabled(server, sender, commandLabel, args);
}
else if (args[0].equalsIgnoreCase("debug"))
{
run_debug(server, sender, commandLabel, args);
}
else if (args[0].equalsIgnoreCase("nya"))
{
run_nya(server, sender, commandLabel, args);
}
else {
run_reload(server, sender, commandLabel, args);
}
}
private void run_disabled(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{
sender.sendMessage("Essentials " + ess.getDescription().getVersion());
sender.sendMessage("/<command> <reload/debug>");
sender.sendMessage("Essentials blocked the following commands, due to command conflicts:");
sender.sendMessage(Util.joinList(ess.getAlternativeCommandsHandler().disabledCommands()));
}
private void run_debug(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{
ess.getSettings().setDebug(!ess.getSettings().isDebug());
sender.sendMessage("Essentials " + ess.getDescription().getVersion() + " debug mode " + (ess.getSettings().isDebug() ? "enabled" : "disabled"));
}
private void run_reload(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{
ess.reload();
sender.sendMessage(_("essentialsReload", ess.getDescription().getVersion()));
}
private void run_nya(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{
final Map<String, Byte> noteMap = new HashMap<String, Byte>();
noteMap.put("1F#", (byte)0x0);
noteMap.put("1G", (byte)0x1);
@ -54,8 +87,6 @@ public class Commandessentials extends EssentialsCommand
noteMap.put("2D#", (byte)(0x9 + 0xC));
noteMap.put("2E", (byte)(0xA + 0xC));
noteMap.put("2F", (byte)(0xB + 0xC));
if (args.length > 0 && args[0].equalsIgnoreCase("nya"))
{
if (!noteBlocks.isEmpty())
{
return;
@ -106,9 +137,6 @@ public class Commandessentials extends EssentialsCommand
}
}, 20, 2);
return;
}
ess.reload();
sender.sendMessage(_("essentialsReload", ess.getDescription().getVersion()));
}
private void stopTune()