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

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

import java.util.concurrent.Executor;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.component.Store;
import java.util.concurrent.CompletableFuture;
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.universe.world.World;
import com.hypixel.hytale.server.core.command.system.arguments.system.OptionalArg;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.Message;

public abstract class AbstractWorldCommand extends AbstractAsyncCommand
{
    @Nonnull
    private static final Message MESSAGE_COMMANDS_ERRORS_NO_WORLD;
    @Nonnull
    private final OptionalArg<World> worldArg;
    
    public AbstractWorldCommand(@Nonnull final String name, @Nonnull final String description) {
        super(name, description);
        this.worldArg = this.withOptionalArg("world", "server.commands.worldthread.arg.desc", ArgTypes.WORLD);
    }
    
    public AbstractWorldCommand(@Nonnull final String name, @Nonnull final String description, final boolean requiresConfirmation) {
        super(name, description, requiresConfirmation);
        this.worldArg = this.withOptionalArg("world", "server.commands.worldthread.arg.desc", ArgTypes.WORLD);
    }
    
    public AbstractWorldCommand(@Nonnull final String description) {
        super(description);
        this.worldArg = this.withOptionalArg("world", "server.commands.worldthread.arg.desc", ArgTypes.WORLD);
    }
    
    @Nonnull
    @Override
    protected final CompletableFuture<Void> executeAsync(@Nonnull final CommandContext context) {
        final World world = this.worldArg.getProcessed(context);
        if (world == null) {
            context.sendMessage(AbstractWorldCommand.MESSAGE_COMMANDS_ERRORS_NO_WORLD);
            return CompletableFuture.completedFuture((Void)null);
        }
        final Store<EntityStore> store = world.getEntityStore().getStore();
        return this.runAsync(context, () -> this.execute(context, world, store), world);
    }
    
    protected abstract void execute(@Nonnull final CommandContext p0, @Nonnull final World p1, @Nonnull final Store<EntityStore> p2);
    
    static {
        MESSAGE_COMMANDS_ERRORS_NO_WORLD = Message.translation("server.commands.errors.noWorld");
    }
}
