package chikachi.discord.core.config.validator.rules;

import chikachi.discord.core.config.Configuration;
import chikachi.discord.core.config.discord.CommandConfig;
import chikachi.discord.core.config.discord.DiscordChannelConfig;
import chikachi.discord.core.config.validator.IConfigurationValidationRule;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class DuplicatedCommandOrAliasRule implements IConfigurationValidationRule {
    @Override
    public String getHint() {
        return "At least one command or alias is used twice. Please use every command only once. ";
    }

    /**
     * Checks for duplicated commands
     * @return true, if no commands are duplicated
     */
    @Override
    public boolean validate() {
        // Check the global commands first and fill them into the checkMap
        ArrayList<CommandConfig> commands = Configuration.getConfig().discord.channels.generic.commands;
        HashMap<String, Integer> globalCheckMap = new HashMap<>();

        boolean globalConfigValid = commands.stream()
            .noneMatch(commandConfig -> validateCommand(globalCheckMap, commandConfig));
        if (!globalConfigValid)
            return false;

        // Now test the channel configurations.
        for (Map.Entry<Long, DiscordChannelConfig> entry : Configuration.getConfig().discord.channels.channels.entrySet()) {
            HashMap<String, Integer> localCheckMap = new HashMap<>(globalCheckMap);

            for (CommandConfig command : entry.getValue().commands) {
                if (!validateCommand(localCheckMap, command))
                    return false;
            }
        }
        return true;
    }

    private boolean validateCommand(HashMap<String, Integer> checkMap, CommandConfig command) {
        String name = command.getName();
        int newVal = checkMap.getOrDefault(name, 0) + 1;
        if (newVal > 1)
            return false;

        checkMap.put(name, newVal);

        // Check for aliases
        for (String alias : command.getAliases()) {
            int aliasVal = checkMap.getOrDefault(alias, 0) + 1;
            if (aliasVal > 1)
                return false;
            checkMap.put(alias, aliasVal);
        }
        return true;
    }
}

@@ -1024,94 +1024,72 @@
     
-boolean globalConfigValid = commands.stream()%0A            .noneMatch(commandConfig -%3E 
+for (CommandConfig commandConfig : commands) %7B%0A            if (!
 vali
@@ -1131,17 +1131,18 @@
 Config))
-;
+ %7B
 %0A       
@@ -1146,57 +1146,53 @@
     
-if (!globalConfigValid)%0A            return false;
+        return false;%0A            %7D%0A        %7D
 %0A%0A  
@@ -1661,24 +1661,79 @@
 rue;%0A    %7D%0A%0A
+    @SuppressWarnings(%22BooleanMethodIsAlwaysInverted%22)%0A
     private 

Fix for DuplicatedCommandOrAliasRule