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

package com.hypixel.hytale.builtin.buildertools.commands;

import com.hypixel.hytale.server.core.command.system.arguments.system.Argument;
import com.hypixel.hytale.server.core.entity.entities.player.HotbarManager;
import com.hypixel.hytale.component.ComponentAccessor;
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.codec.validation.Validator;
import com.hypixel.hytale.codec.validation.Validators;
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.FlagArg;
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 HotbarSwitchCommand extends AbstractPlayerCommand
{
    @Nonnull
    private final RequiredArg<Integer> hotbarSlotArg;
    @Nonnull
    private final FlagArg saveInsteadOfLoadArg;
    
    public HotbarSwitchCommand() {
        super("hotbar", "server.commands.hotbar.desc");
        this.hotbarSlotArg = this.withRequiredArg("hotbarSlot", "server.commands.hotbar.hotbarSlot.desc", ArgTypes.INTEGER).addValidator((Validator<Integer>)Validators.range(0, (DataType)9));
        this.saveInsteadOfLoadArg = this.withFlagArg("save", "server.commands.hotbar.save.desc");
        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 HotbarManager hotbarManager = playerComponent.getHotbarManager();
        if (((Argument<Arg, Boolean>)this.saveInsteadOfLoadArg).get(context)) {
            hotbarManager.saveHotbar(ref, this.hotbarSlotArg.get(context).shortValue(), store);
        }
        else {
            hotbarManager.loadHotbar(ref, this.hotbarSlotArg.get(context).shortValue(), store);
        }
    }
}
