HashMultimap<String, ICommand> duplicates = HashMultimap.create();
Set<ICommand> cmdList = ReflectionHelper.getPrivateValue(CommandHandler.class, (CommandHandler) server.getCommandManager(), FIELDNAME);
OutputHandler.felog.finer("commandSet size: " + cmdList.size());
ICommand keep;
for (ICommand cmd : cmdList)
{
keep = initials.put(cmd.getCommandName(), cmd);
if (keep != null)
{
OutputHandler.felog.finer("Duplicate command found! Name:" + keep.getCommandName());
duplicates.put(cmd.getCommandName(), cmd);
duplicates.put(cmd.getCommandName(), keep);
continue;
}
CommandHandlerForge.doPermissionReg(cmd);
}
Set<ICommand> toRemove = new HashSet<ICommand>();
keep = null;
Class<? extends ICommand> cmdClass;
int kept = -1, other = -1;
for (String name : duplicates.keySet())
{
keep = null;
kept = -1;
other = -1;
cmdClass = null;
for (ICommand cmd : duplicates.get(name))
{
other = getCommandPriority(cmd);
if (keep == null)
{
kept = other;
if (kept == -1)
{
keep = null;
duplicates.remove(name, cmd);
}
else
{
keep = cmd;
}
continue;
}
if (kept > other)
{
toRemove.add(cmd);
cmdClass = cmd.getClass();
OutputHandler.felog.finer("Removing command '" + cmd.getCommandName() + "' from class: " + cmdClass.getName());
}
else
{
toRemove.add(keep);
cmdClass = keep.getClass();
OutputHandler.felog.finer("Removing command '" + keep.getCommandName() + "' from class: " + cmdClass.getName());
keep = cmd;
kept = other;
}