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

package com.hypixel.hytale.server.core.command.system.basecommands;

import java.awt.Color;
import java.util.logging.Level;
import com.hypixel.hytale.logger.HytaleLogger;
import java.util.concurrent.Executor;
import java.util.concurrent.CompletableFuture;
import com.hypixel.hytale.server.core.command.system.CommandContext;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.command.system.AbstractCommand;

public abstract class AbstractAsyncCommand extends AbstractCommand
{
    @Nonnull
    private static final Message MESSAGE_MODULES_COMMAND_RUNTIME_ERROR;
    
    public AbstractAsyncCommand(@Nonnull final String name, @Nonnull final String description) {
        super(name, description);
    }
    
    public AbstractAsyncCommand(@Nonnull final String name, @Nonnull final String description, final boolean requiresConfirmation) {
        super(name, description, requiresConfirmation);
    }
    
    public AbstractAsyncCommand(@Nonnull final String description) {
        super(description);
    }
    
    @Override
    protected final CompletableFuture<Void> execute(@Nonnull final CommandContext context) {
        return this.executeAsync(context);
    }
    
    @Nonnull
    protected abstract CompletableFuture<Void> executeAsync(@Nonnull final CommandContext p0);
    
    @Nonnull
    public CompletableFuture<Void> runAsync(@Nonnull final CommandContext context, @Nonnull final Runnable runnable, @Nonnull final Executor executor) {
        return CompletableFuture.runAsync(() -> {
            try {
                runnable.run();
            }
            catch (final Exception e) {
                context.sendMessage(AbstractAsyncCommand.MESSAGE_MODULES_COMMAND_RUNTIME_ERROR);
                AbstractCommand.LOGGER.at(Level.SEVERE).withCause(e).log("Exception while running that command:");
            }
        }, executor);
    }
    
    static {
        MESSAGE_MODULES_COMMAND_RUNTIME_ERROR = Message.translation("server.modules.command.runtimeError").color(Color.RED);
    }
}
