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

package com.hypixel.hytale.server.core.command.commands.player.inventory;

import com.hypixel.hytale.server.core.inventory.ItemStack;
import com.hypixel.hytale.server.core.inventory.container.ItemContainer;
import com.hypixel.hytale.server.core.inventory.Inventory;
import com.hypixel.hytale.server.core.entity.entities.Player;
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 com.hypixel.hytale.server.core.command.system.arguments.system.RequiredArg;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractPlayerCommand;

public class ItemStateCommand extends AbstractPlayerCommand
{
    @Nonnull
    private static final Message MESSAGE_COMMANDS_ITEMSTATE_NO_ITEM;
    @Nonnull
    private final RequiredArg<String> stateArg;
    
    public ItemStateCommand() {
        super("itemstate", "server.commands.itemstate.desc");
        this.stateArg = this.withRequiredArg("state", "server.commands.itemstate.state.desc", ArgTypes.STRING);
        this.setPermissionGroup(GameMode.Creative);
    }
    
    @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 Player playerComponent = store.getComponent(ref, Player.getComponentType());
        assert playerComponent != null;
        final Inventory inventory = playerComponent.getInventory();
        final byte activeHotbarSlot = inventory.getActiveHotbarSlot();
        if (activeHotbarSlot == -1) {
            context.sendMessage(ItemStateCommand.MESSAGE_COMMANDS_ITEMSTATE_NO_ITEM);
            return;
        }
        final ItemContainer hotbar = inventory.getHotbar();
        final ItemStack item = hotbar.getItemStack(activeHotbarSlot);
        if (item == null) {
            context.sendMessage(ItemStateCommand.MESSAGE_COMMANDS_ITEMSTATE_NO_ITEM);
            return;
        }
        final String state = this.stateArg.get(context);
        hotbar.setItemStackForSlot(activeHotbarSlot, item.withState(state));
    }
    
    static {
        MESSAGE_COMMANDS_ITEMSTATE_NO_ITEM = Message.translation("server.commands.itemstate.noItem");
    }
}
