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

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

import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.modules.entity.player.ChunkTracker;
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.CommandContext;
import com.hypixel.hytale.server.core.command.system.arguments.types.ArgumentType;
import com.hypixel.hytale.server.core.command.system.arguments.types.ArgTypes;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.command.system.arguments.system.OptionalArg;
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractTargetPlayerCommand;

public class ChunkMaxSendRateCommand extends AbstractTargetPlayerCommand
{
    @Nonnull
    private final OptionalArg<Integer> secArg;
    @Nonnull
    private final OptionalArg<Integer> tickArg;
    
    public ChunkMaxSendRateCommand() {
        super("maxsendrate", "server.commands.chunk.maxsendrate.desc");
        this.secArg = this.withOptionalArg("sec", "server.commands.chunk.maxsendrate.sec.desc", ArgTypes.INTEGER);
        this.tickArg = this.withOptionalArg("tick", "server.commands.chunk.maxsendrate.tick.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 ChunkTracker chunkTracker = store.getComponent(ref, ChunkTracker.getComponentType());
        assert chunkTracker != null;
        if (this.secArg.provided(context)) {
            final int sec = this.secArg.get(context);
            chunkTracker.setMaxChunksPerSecond(sec);
            context.sendMessage(Message.translation("server.commands.chunk.maxsendrate.sec.set").param("value", sec));
        }
        if (this.tickArg.provided(context)) {
            final int tick = this.tickArg.get(context);
            chunkTracker.setMaxChunksPerTick(tick);
            context.sendMessage(Message.translation("server.commands.chunk.maxsendrate.tick.set").param("value", tick));
        }
        context.sendMessage(Message.translation("server.commands.chunk.maxsendrate.summary").param("perSecond", chunkTracker.getMaxChunksPerSecond()).param("perTick", chunkTracker.getMaxChunksPerTick()));
    }
}
