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

package com.hypixel.hytale.server.core.command.commands.world.entity;

import com.hypixel.hytale.component.Ref;
import com.hypixel.hytale.server.core.entity.nameplate.Nameplate;
import com.hypixel.hytale.component.ComponentAccessor;
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.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 com.hypixel.hytale.server.core.command.system.arguments.system.RequiredArg;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.command.system.arguments.types.EntityWrappedArg;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractWorldCommand;

public class EntityNameplateCommand extends AbstractWorldCommand
{
    private static final Message MESSAGE_GENERAL_NO_ENTITY_IN_VIEW;
    private static final Message MESSAGE_COMMANDS_ENTITY_NAMEPLATE_UPDATED;
    @Nonnull
    private final EntityWrappedArg entityArg;
    @Nonnull
    private final RequiredArg<String> textArg;
    
    public EntityNameplateCommand() {
        super("nameplate", "server.commands.entity.nameplate.desc");
        this.entityArg = this.withOptionalArg("entity", "server.commands.entity.nameplate.entity.desc", ArgTypes.ENTITY_ID);
        this.textArg = this.withRequiredArg("text", "server.commands.entity.nameplate.text.desc", ArgTypes.STRING);
        this.addUsageVariant(new Remove());
    }
    
    @Override
    protected void execute(@Nonnull final CommandContext context, @Nonnull final World world, @Nonnull final Store<EntityStore> store) {
        final Ref<EntityStore> entityRef = this.entityArg.get(store, context);
        if (entityRef == null || !entityRef.isValid()) {
            context.sendMessage(EntityNameplateCommand.MESSAGE_GENERAL_NO_ENTITY_IN_VIEW);
            return;
        }
        final String text = this.textArg.get(context);
        store.ensureAndGetComponent(entityRef, Nameplate.getComponentType()).setText(text);
        context.sendMessage(EntityNameplateCommand.MESSAGE_COMMANDS_ENTITY_NAMEPLATE_UPDATED);
    }
    
    static {
        MESSAGE_GENERAL_NO_ENTITY_IN_VIEW = Message.translation("server.general.noEntityInView");
        MESSAGE_COMMANDS_ENTITY_NAMEPLATE_UPDATED = Message.translation("server.commands.entity.nameplate.updated");
    }
    
    public static class Remove extends AbstractWorldCommand
    {
        @Nonnull
        private static final Message MESSAGE_GENERAL_NO_ENTITY_IN_VIEW;
        @Nonnull
        private static final Message MESSAGE_COMMANDS_ENTITY_NAMEPLATE_REMOVED;
        @Nonnull
        private final EntityWrappedArg entityArg;
        
        public Remove() {
            super("server.commands.entity.nameplate.remove.desc");
            this.entityArg = this.withOptionalArg("entity", "server.commands.entity.nameplate.entity.desc", ArgTypes.ENTITY_ID);
        }
        
        @Override
        protected void execute(@Nonnull final CommandContext context, @Nonnull final World world, @Nonnull final Store<EntityStore> store) {
            final Ref<EntityStore> entityRef = this.entityArg.get(store, context);
            if (entityRef == null || !entityRef.isValid()) {
                context.sendMessage(Remove.MESSAGE_GENERAL_NO_ENTITY_IN_VIEW);
                return;
            }
            store.tryRemoveComponent(entityRef, Nameplate.getComponentType());
            context.sendMessage(Remove.MESSAGE_COMMANDS_ENTITY_NAMEPLATE_REMOVED);
        }
        
        static {
            MESSAGE_GENERAL_NO_ENTITY_IN_VIEW = Message.translation("server.general.noEntityInView");
            MESSAGE_COMMANDS_ENTITY_NAMEPLATE_REMOVED = Message.translation("server.commands.entity.nameplate.removed");
        }
    }
}
