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

package com.hypixel.hytale.server.core.cosmetics.commands;

import java.util.Map;
import com.hypixel.hytale.server.core.cosmetics.CosmeticRegistry;
import com.hypixel.hytale.component.ComponentAccessor;
import com.hypixel.hytale.server.core.entity.AnimationUtils;
import com.hypixel.hytale.protocol.AnimationSlot;
import java.util.Collection;
import com.hypixel.hytale.common.util.StringUtil;
import com.hypixel.hytale.server.core.command.system.CommandUtil;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.cosmetics.Emote;
import com.hypixel.hytale.server.core.cosmetics.CosmeticsModule;
import com.hypixel.hytale.server.core.universe.world.World;
import com.hypixel.hytale.server.core.universe.PlayerRef;
import com.hypixel.hytale.component.Ref;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.component.Store;
import com.hypixel.hytale.server.core.command.system.CommandContext;
import com.hypixel.hytale.protocol.GameMode;
import com.hypixel.hytale.server.core.command.system.arguments.types.ArgumentType;
import com.hypixel.hytale.server.core.command.system.arguments.types.ArgTypes;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.command.system.arguments.system.RequiredArg;
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractPlayerCommand;

public class EmoteCommand extends AbstractPlayerCommand
{
    @Nonnull
    private final RequiredArg<String> emoteArg;
    
    public EmoteCommand() {
        super("emote", "server.commands.emote.desc");
        this.emoteArg = this.withRequiredArg("emote", "server.commands.emote.emote.desc", ArgTypes.STRING);
        this.setPermissionGroup(GameMode.Adventure);
    }
    
    @Override
    protected void execute(@Nonnull final CommandContext context, @Nonnull final Store<EntityStore> store, @Nonnull final Ref<EntityStore> ref, @Nonnull final PlayerRef playerRef, @Nonnull final World world) {
        final CosmeticRegistry cosmeticsRegistry = CosmeticsModule.get().getRegistry();
        final Map<String, Emote> emotes = cosmeticsRegistry.getEmotes();
        final String emoteId = this.emoteArg.get(context);
        final Emote emote = emotes.get(emoteId);
        if (emote == null) {
            context.sendMessage(Message.translation("server.commands.emote.emoteNotFound").param("id", emoteId));
            context.sendMessage(Message.translation("server.general.failed.didYouMean").param("choices", StringUtil.sortByFuzzyDistance(emoteId, emotes.keySet(), CommandUtil.RECOMMEND_COUNT).toString()));
            return;
        }
        AnimationUtils.playAnimation(ref, AnimationSlot.Emote, null, emote.getId(), true, store);
    }
}
