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

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

import com.hypixel.hytale.server.npc.role.RoleUtils;
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.universe.world.World;
import com.hypixel.hytale.server.npc.entities.NPCEntity;
import com.hypixel.hytale.server.core.command.system.CommandContext;
import com.hypixel.hytale.server.core.command.system.AbstractCommand;
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.asset.type.item.config.Item;
import com.hypixel.hytale.server.core.command.system.arguments.system.RequiredArg;

public class NPCGiveCommand extends NPCWorldCommandBase
{
    @Nonnull
    private final RequiredArg<Item> itemArg;
    
    public NPCGiveCommand() {
        super("give", "server.commands.npc.give.desc");
        this.itemArg = this.withRequiredArg("item", "server.commands.npc.give.item.desc", ArgTypes.ITEM_ASSET);
        this.addSubCommand(new GiveNothingCommand());
    }
    
    @Override
    protected void execute(@Nonnull final CommandContext context, @Nonnull final NPCEntity npc, @Nonnull final World world, @Nonnull final Store<EntityStore> store, @Nonnull final Ref<EntityStore> ref) {
        final Item item = this.itemArg.get(context);
        final String itemName = item.getId();
        if (item.getArmor() != null) {
            RoleUtils.setArmor(npc, itemName);
        }
        else {
            RoleUtils.setItemInHand(npc, itemName);
        }
    }
    
    public static class GiveNothingCommand extends NPCWorldCommandBase
    {
        public GiveNothingCommand() {
            super("nothing", "server.commands.npc.give.nothing.desc");
        }
        
        @Override
        protected void execute(@Nonnull final CommandContext context, @Nonnull final NPCEntity npc, @Nonnull final World world, @Nonnull final Store<EntityStore> store, @Nonnull final Ref<EntityStore> ref) {
            RoleUtils.setItemInHand(npc, null);
        }
    }
}
