// 
// Decompiled by Procyon v0.6.0
// 

package com.hypixel.hytale.server.npc.commands;

import java.util.Iterator;
import com.hypixel.hytale.server.core.command.system.suggestion.SuggestionResult;
import com.hypixel.hytale.server.core.command.system.CommandSender;
import java.util.List;
import java.util.Collection;
import com.hypixel.hytale.common.util.StringUtil;
import com.hypixel.hytale.server.core.command.system.CommandUtil;
import java.awt.Color;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.npc.NPCPlugin;
import com.hypixel.hytale.server.core.command.system.ParseResult;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.flock.commands.NPCFlockCommand;
import com.hypixel.hytale.server.core.command.system.AbstractCommand;
import com.hypixel.hytale.server.npc.asset.builder.BuilderInfo;
import com.hypixel.hytale.server.core.command.system.arguments.types.SingleArgumentType;
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractCommandCollection;

public class NPCCommand extends AbstractCommandCollection
{
    public static final SingleArgumentType<BuilderInfo> NPC_ROLE;
    
    public NPCCommand() {
        super("npc", "server.commands.npc");
        this.addSubCommand(new NPCAllCommand());
        this.addSubCommand(new NPCAppearanceCommand());
        this.addSubCommand(new NPCAttackCommand());
        this.addSubCommand(new NPCBenchmarkCommand());
        this.addSubCommand(new NPCBlackboardCommand());
        this.addSubCommand(new NPCCleanCommand());
        this.addSubCommand(new NPCDebugCommand());
        this.addSubCommand(new NPCDumpCommand());
        this.addSubCommand(new NPCFlockCommand());
        this.addSubCommand(new NPCFreezeCommand());
        this.addSubCommand(new NPCGiveCommand());
        this.addSubCommand(new NPCPathCommand());
        this.addSubCommand(new NPCRoleCommand());
        this.addSubCommand(new NPCRunTestsCommand());
        this.addSubCommand(new NPCSensorStatsCommand());
        this.addSubCommand(new NPCSpawnCommand());
        this.addSubCommand(new NPCStepCommand());
        this.addSubCommand(new NPCTestCommand());
        this.addSubCommand(new NPCThawCommand());
        this.addSubCommand(new NPCMessageCommand());
    }
    
    static {
        NPC_ROLE = new SingleArgumentType<BuilderInfo>("server.commands.parsing.argtype.npcrole.usage", new String[0]) {
            @Override
            public BuilderInfo parse(@Nonnull final String input, @Nonnull final ParseResult parseResult) {
                try {
                    final NPCPlugin npcPlugin = NPCPlugin.get();
                    final int index = npcPlugin.getIndex(input);
                    if (index == Integer.MIN_VALUE) {
                        final List<String> roles = npcPlugin.getRoleTemplateNames(false);
                        parseResult.fail(Message.translation("server.commands.notfound").param("type", "NPC Role").param("id", input).color(Color.RED), Message.translation("server.general.failed.didYouMean").param("choices", StringUtil.sortByFuzzyDistance(input, roles, CommandUtil.RECOMMEND_COUNT).toString()));
                        return null;
                    }
                    final BuilderInfo builderInfo = npcPlugin.getRoleBuilderInfo(index);
                    if (builderInfo == null) {
                        parseResult.fail(Message.translation("server.commands.notfound").param("type", "NPC Role").param("id", input).color(Color.RED));
                        return null;
                    }
                    return builderInfo;
                }
                catch (final Exception e) {
                    parseResult.fail(Message.translation("server.commands.notfound").param("type", "NPC Role").param("id", input).color(Color.RED));
                    return null;
                }
            }
            
            @Override
            public void suggest(@Nonnull final CommandSender sender, @Nonnull String textAlreadyEntered, final int numParametersTyped, @Nonnull final SuggestionResult result) {
                try {
                    final NPCPlugin npcPlugin = NPCPlugin.get();
                    final List<String> roles = npcPlugin.getRoleTemplateNames(false);
                    textAlreadyEntered = textAlreadyEntered.toLowerCase();
                    for (final String role : roles) {
                        if (role.toLowerCase().startsWith(textAlreadyEntered)) {
                            result.suggest(role);
                        }
                    }
                }
                catch (final Exception ex) {}
            }
        };
    }
}
