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

package com.hypixel.hytale.builtin.commandmacro;

import com.hypixel.hytale.server.core.command.system.arguments.system.Argument;
import com.hypixel.hytale.server.core.command.system.CommandSender;
import java.util.concurrent.TimeUnit;
import com.hypixel.hytale.server.core.Message;
import java.util.concurrent.CompletableFuture;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.command.system.CommandContext;
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 com.hypixel.hytale.server.core.command.system.arguments.system.RequiredArg;
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractAsyncCommand;

public class WaitCommand extends AbstractAsyncCommand
{
    private static final long MILLISECONDS_TO_SECONDS_MULTIPLIER = 1000L;
    public static final Runnable EMPTY_RUNNABLE;
    private final RequiredArg<Float> timeArg;
    private final FlagArg printArg;
    
    public WaitCommand() {
        super("wait", "server.commands.wait.desc");
        this.timeArg = (RequiredArg)this.withRequiredArg("time", "server.commands.wait.arg.time", ArgTypes.FLOAT).addValidator((Validator<Float>)Validators.greaterThan((DataType)0.0f)).addValidator(Validators.lessThan(1000.0f));
        this.printArg = this.withFlagArg("print", "server.commands.wait.arg.print");
    }
    
    @Nonnull
    @Override
    protected CompletableFuture<Void> executeAsync(@Nonnull final CommandContext context) {
        final CommandSender sender = context.sender();
        final Runnable runnable = ((Argument<Arg, Boolean>)this.printArg).get(context) ? (() -> sender.sendMessage(Message.translation("server.commands.wait.complete"))) : WaitCommand.EMPTY_RUNNABLE;
        return CompletableFuture.runAsync(runnable, CompletableFuture.delayedExecutor((long)(this.timeArg.get(context) * 1000.0f), TimeUnit.MILLISECONDS));
    }
    
    static {
        EMPTY_RUNNABLE = (() -> {});
    }
}
