From af7eae6201702950268758a2b993c4bdc4f7b45c Mon Sep 17 00:00:00 2001 From: KHobbits Date: Tue, 29 Nov 2011 17:21:18 +0000 Subject: Adding some debug info to /essentials --- .../essentials/AlternativeCommandsHandler.java | 13 +++++- .../src/com/earth2me/essentials/Essentials.java | 3 +- .../essentials/commands/Commandessentials.java | 46 +++++++++++++++++----- 3 files changed, 51 insertions(+), 11 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/AlternativeCommandsHandler.java b/Essentials/src/com/earth2me/essentials/AlternativeCommandsHandler.java index a9291e629..a16f8031a 100644 --- a/Essentials/src/com/earth2me/essentials/AlternativeCommandsHandler.java +++ b/Essentials/src/com/earth2me/essentials/AlternativeCommandsHandler.java @@ -11,6 +11,7 @@ import org.bukkit.plugin.Plugin; public class AlternativeCommandsHandler { private final transient Map> altcommands = new HashMap>(); + private final transient Set executed = new HashSet(); 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 disabledCommands() + { + return new ArrayList(executed); + } } diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java index 15419b014..f82aec91a 100644 --- a/Essentials/src/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/com/earth2me/essentials/Essentials.java @@ -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); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java b/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java index cc541299d..7701bf575 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java @@ -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")) + if (args.length == 0) { + run_disabled(server, sender, commandLabel, args); + } + else if (args[0].equalsIgnoreCase("debug")) { - ess.getSettings().setDebug(!ess.getSettings().isDebug()); - sender.sendMessage("Essentials " + ess.getDescription().getVersion() + " debug mode " + (ess.getSettings().isDebug() ? "enabled" : "disabled")); - return; + 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("/ "); + 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 noteMap = new HashMap(); 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() -- cgit v1.2.3