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

package com.hypixel.hytale.server.core.command.commands.utility.net;

import io.netty.channel.Channel;
import com.hypixel.hytale.server.core.io.netty.LatencySimulationHandler;
import java.util.concurrent.TimeUnit;
import com.hypixel.hytale.component.Store;
import com.hypixel.hytale.server.core.universe.world.World;
import com.hypixel.hytale.server.core.universe.PlayerRef;
import javax.annotation.Nullable;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.component.Ref;
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 com.hypixel.hytale.server.core.command.system.basecommands.AbstractTargetPlayerCommand;
import com.hypixel.hytale.server.core.modules.entity.player.KnockbackPredictionSystems;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.entity.knockback.KnockbackSystems;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.command.system.CommandContext;
import com.hypixel.hytale.server.core.command.system.basecommands.CommandBase;
import com.hypixel.hytale.server.core.command.system.AbstractCommand;
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractCommandCollection;

public class NetworkCommand extends AbstractCommandCollection
{
    public NetworkCommand() {
        super("network", "server.commands.network.desc");
        this.addAliases("net");
        this.addSubCommand(new LatencySimulationCommand());
        this.addSubCommand(new ServerKnockbackCommand());
        this.addSubCommand(new DebugKnockbackCommand());
    }
    
    static class ServerKnockbackCommand extends CommandBase
    {
        ServerKnockbackCommand() {
            super("serverknockback", "server.commands.network.serverknockback.desc");
        }
        
        @Override
        protected void executeSync(@Nonnull final CommandContext context) {
            KnockbackSystems.ApplyPlayerKnockback.DO_SERVER_PREDICTION = !KnockbackSystems.ApplyPlayerKnockback.DO_SERVER_PREDICTION;
            context.sendMessage(Message.translation("server.commands.network.knockbackServerPredictionEnabled").param("enabled", KnockbackSystems.ApplyPlayerKnockback.DO_SERVER_PREDICTION));
        }
    }
    
    static class DebugKnockbackCommand extends CommandBase
    {
        DebugKnockbackCommand() {
            super("debugknockback", "server.commands.network.debugknockback.desc");
        }
        
        @Override
        protected void executeSync(@Nonnull final CommandContext context) {
            KnockbackPredictionSystems.DEBUG_KNOCKBACK_POSITION = !KnockbackPredictionSystems.DEBUG_KNOCKBACK_POSITION;
            context.sendMessage(Message.translation("server.commands.network.knockbackDebugEnabled").param("enabled", KnockbackPredictionSystems.DEBUG_KNOCKBACK_POSITION));
        }
    }
    
    public static class LatencySimulationCommand extends AbstractCommandCollection
    {
        public LatencySimulationCommand() {
            super("latencysimulation", "server.commands.latencySimulation.desc");
            this.addAliases("latsim");
            this.addSubCommand(new Set());
            this.addSubCommand(new Reset());
        }
        
        static class Set extends AbstractTargetPlayerCommand
        {
            @Nonnull
            private final RequiredArg<Integer> delayArg;
            
            Set() {
                super("set", "server.commands.latencySimulation.set.desc");
                this.delayArg = this.withRequiredArg("delay", "server.commands.latencySimulation.set.delay.desc", ArgTypes.INTEGER);
            }
            
            @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) {
                final int delay = this.delayArg.get(context);
                final Channel channel = playerRef.getPacketHandler().getChannel();
                LatencySimulationHandler.setLatency(channel, delay, TimeUnit.MILLISECONDS);
                context.sendMessage(Message.translation("server.commands.latencySimulation.set.success").param("millis", delay));
            }
        }
        
        static class Reset extends AbstractTargetPlayerCommand
        {
            @Nonnull
            private static final Message MESSAGE_COMMANDS_LATENCY_SIMULATION_RESET_SUCCESS;
            
            Reset() {
                super("reset", "server.commands.latencySimulation.reset.desc");
                this.addAliases("clear");
            }
            
            @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) {
                final Channel channel = playerRef.getPacketHandler().getChannel();
                LatencySimulationHandler.setLatency(channel, 0L, TimeUnit.MILLISECONDS);
                context.sendMessage(Reset.MESSAGE_COMMANDS_LATENCY_SIMULATION_RESET_SUCCESS);
            }
            
            static {
                MESSAGE_COMMANDS_LATENCY_SIMULATION_RESET_SUCCESS = Message.translation("server.commands.latencySimulation.reset.success");
            }
        }
    }
}
