Output the redirected plugin too.

This commit is contained in:
snowleo 2011-11-29 18:48:52 +01:00
parent 57a0ec9912
commit 0b2a3fcf7f
3 changed files with 28 additions and 18 deletions

View file

@ -1,7 +1,6 @@
package com.earth2me.essentials; package com.earth2me.essentials;
import java.util.*; import java.util.*;
import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.PluginCommand; import org.bukkit.command.PluginCommand;
import org.bukkit.command.PluginCommandYamlParser; import org.bukkit.command.PluginCommandYamlParser;
@ -11,20 +10,21 @@ import org.bukkit.plugin.Plugin;
public class AlternativeCommandsHandler public class AlternativeCommandsHandler
{ {
private final transient Map<String, List<PluginCommand>> altcommands = new HashMap<String, List<PluginCommand>>(); 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 Map<String, String> executed = new HashMap<String, String>();
private final transient IEssentials ess; private final transient IEssentials ess;
public AlternativeCommandsHandler(final IEssentials ess) public AlternativeCommandsHandler(final IEssentials ess)
{ {
this.ess = ess; this.ess = ess;
for (Plugin plugin : ess.getServer().getPluginManager().getPlugins()) for (Plugin plugin : ess.getServer().getPluginManager().getPlugins())
{ {
if (plugin.isEnabled()) { if (plugin.isEnabled())
{
addPlugin(plugin); addPlugin(plugin);
} }
} }
} }
public final void addPlugin(final Plugin plugin) public final void addPlugin(final Plugin plugin)
{ {
if (plugin.getDescription().getMain().contains("com.earth2me.essentials")) if (plugin.getDescription().getMain().contains("com.earth2me.essentials"))
@ -101,28 +101,30 @@ public class AlternativeCommandsHandler
if (commands == null || commands.isEmpty()) if (commands == null || commands.isEmpty())
{ {
return null; return null;
} }
if (commands.size() == 1) if (commands.size() == 1)
{ {
return commands.get(0); return commands.get(0);
} }
// return the first command that is not an alias // return the first command that is not an alias
for (PluginCommand command : commands) { for (PluginCommand command : commands)
if (command.getName().equalsIgnoreCase(label)) { {
if (command.getName().equalsIgnoreCase(label))
{
return command; return command;
} }
} }
// return the first alias // return the first alias
return commands.get(0); return commands.get(0);
} }
public void executed(final String label) public void executed(final String label, final String otherlabel)
{ {
executed.add(label); executed.put(label, otherlabel);
} }
public Set<String> disabledCommands() public Map<String, String> disabledCommands()
{ {
return executed; return executed;
} }
} }

View file

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

View file

@ -45,7 +45,15 @@ public class Commandessentials extends EssentialsCommand
sender.sendMessage("Essentials " + ess.getDescription().getVersion()); sender.sendMessage("Essentials " + ess.getDescription().getVersion());
sender.sendMessage("/<command> <reload/debug>"); sender.sendMessage("/<command> <reload/debug>");
sender.sendMessage("Essentials blocked the following commands, due to command conflicts:"); sender.sendMessage("Essentials blocked the following commands, due to command conflicts:");
sender.sendMessage(Util.joinList(ess.getAlternativeCommandsHandler().disabledCommands())); final StringBuilder disabledCommands = new StringBuilder();
for (Map.Entry<String, String> entry : ess.getAlternativeCommandsHandler().disabledCommands().entrySet())
{
if (disabledCommands.length() > 0) {
disabledCommands.append(", ");
}
disabledCommands.append(entry.getKey()).append(" => ").append(entry.getValue());
}
sender.sendMessage(disabledCommands.toString());
} }
private void run_debug(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception private void run_debug(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception