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

package com.hypixel.hytale.server.core.command.commands.debug.component.repulsion;

import com.hypixel.hytale.server.core.universe.PlayerRef;
import javax.annotation.Nullable;
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractTargetPlayerCommand;
import com.hypixel.hytale.component.Ref;
import com.hypixel.hytale.component.ComponentType;
import com.hypixel.hytale.server.core.modules.entity.repulsion.Repulsion;
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.arguments.types.ArgumentType;
import com.hypixel.hytale.server.core.command.system.arguments.types.ArgTypes;
import com.hypixel.hytale.server.core.command.system.arguments.types.EntityWrappedArg;
import com.hypixel.hytale.server.core.modules.entity.repulsion.RepulsionConfig;
import com.hypixel.hytale.server.core.command.system.arguments.system.RequiredArg;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractWorldCommand;
import com.hypixel.hytale.server.core.command.system.AbstractCommand;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractCommandCollection;

public class RepulsionAddCommand extends AbstractCommandCollection
{
    private static final Message MESSAGE_COMMANDS_ERRORS_TARGET_NOT_IN_WORLD;
    
    public RepulsionAddCommand() {
        super("add", "server.commands.repulsion.add.desc");
        this.addSubCommand(new RepulsionAddEntityCommand());
        this.addSubCommand(new RepulsionAddSelfCommand());
    }
    
    static {
        MESSAGE_COMMANDS_ERRORS_TARGET_NOT_IN_WORLD = Message.translation("server.commands.errors.targetNotInWorld");
    }
    
    public static class RepulsionAddEntityCommand extends AbstractWorldCommand
    {
        @Nonnull
        private static final Message MESSAGE_COMMANDS_REPULSION_ADD_ALREADY_ADDED;
        @Nonnull
        private static final Message COMMANDS_REPULSION_ADD_SUCCESS;
        @Nonnull
        private final RequiredArg<RepulsionConfig> repulsionConfigArg;
        @Nonnull
        private final EntityWrappedArg entityArg;
        
        public RepulsionAddEntityCommand() {
            super("entity", "server.commands.repulsion.add.entity.desc");
            this.repulsionConfigArg = this.withRequiredArg("repulsionConfig", "server.commands.repulsion.add.repulsionConfig.desc", ArgTypes.REPULSION_CONFIG);
            this.entityArg = this.withRequiredArg("entity", "server.commands.repulsion.add.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(RepulsionAddCommand.MESSAGE_COMMANDS_ERRORS_TARGET_NOT_IN_WORLD);
                return;
            }
            final RepulsionConfig repulsionConfig = this.repulsionConfigArg.get(context);
            if (store.getArchetype(entityRef).contains(Repulsion.getComponentType())) {
                context.sendMessage(RepulsionAddEntityCommand.MESSAGE_COMMANDS_REPULSION_ADD_ALREADY_ADDED);
                return;
            }
            store.addComponent(entityRef, Repulsion.getComponentType(), new Repulsion(repulsionConfig));
            context.sendMessage(RepulsionAddEntityCommand.COMMANDS_REPULSION_ADD_SUCCESS);
        }
        
        static {
            MESSAGE_COMMANDS_REPULSION_ADD_ALREADY_ADDED = Message.translation("server.commands.repulsion.add.alreadyAdded");
            COMMANDS_REPULSION_ADD_SUCCESS = Message.translation("server.commands.repulsion.add.success");
        }
    }
    
    public static class RepulsionAddSelfCommand extends AbstractTargetPlayerCommand
    {
        @Nonnull
        private static final Message MESSAGE_COMMANDS_REPULSION_ADD_ALREADY_ADDED;
        @Nonnull
        private static final Message MESSAGE_COMMANDS_REPULSION_ADD_SUCCESS;
        @Nonnull
        private final RequiredArg<RepulsionConfig> repulsionConfigArg;
        
        public RepulsionAddSelfCommand() {
            super("self", "server.commands.repulsion.add.self.desc");
            this.repulsionConfigArg = this.withRequiredArg("repulsionConfig", "server.commands.repulsion.add.repulsionConfig.desc", ArgTypes.REPULSION_CONFIG);
        }
        
        @Override
        protected void execute(@Nonnull final CommandContext context, @Nullable final Ref<EntityStore> sourceRef, @Nonnull final Ref<EntityStore> ref, @Nonnull final PlayerRef playerRef, @Nonnull final World world, @Nonnull final Store<EntityStore> store) {
            if (store.getArchetype(ref).contains(Repulsion.getComponentType())) {
                context.sendMessage(RepulsionAddSelfCommand.MESSAGE_COMMANDS_REPULSION_ADD_ALREADY_ADDED);
                return;
            }
            final RepulsionConfig repulsionConfig = this.repulsionConfigArg.get(context);
            store.addComponent(ref, Repulsion.getComponentType(), new Repulsion(repulsionConfig));
            context.sendMessage(RepulsionAddSelfCommand.MESSAGE_COMMANDS_REPULSION_ADD_SUCCESS);
        }
        
        static {
            MESSAGE_COMMANDS_REPULSION_ADD_ALREADY_ADDED = Message.translation("server.commands.repulsion.add.alreadyAdded");
            MESSAGE_COMMANDS_REPULSION_ADD_SUCCESS = Message.translation("server.commands.repulsion.add.success");
        }
    }
}
