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

package com.hypixel.hytale.server.core.update.command;

import com.hypixel.hytale.server.core.update.UpdateService;
import com.hypixel.hytale.server.core.update.UpdateModule;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.command.system.CommandContext;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.command.system.basecommands.CommandBase;

public class UpdateCancelCommand extends CommandBase
{
    private static final Message MSG_NOTHING_TO_CANCEL;
    private static final Message MSG_DOWNLOAD_CANCELLED;
    private static final Message MSG_CANCEL_FAILED;
    
    public UpdateCancelCommand() {
        super("cancel", "server.commands.update.cancel.desc");
    }
    
    @Override
    protected void executeSync(@Nonnull final CommandContext context) {
        final UpdateModule updateModule = UpdateModule.get();
        boolean didSomething = false;
        if (updateModule != null && updateModule.cancelDownload()) {
            context.sendMessage(UpdateCancelCommand.MSG_DOWNLOAD_CANCELLED);
            didSomething = true;
        }
        final String stagedVersion = UpdateService.getStagedVersion();
        if (stagedVersion != null || didSomething) {
            if (UpdateService.deleteStagedUpdate()) {
                if (stagedVersion != null) {
                    context.sendMessage(Message.translation("server.commands.update.cancelled").param("version", stagedVersion));
                }
            }
            else if (stagedVersion != null) {
                context.sendMessage(UpdateCancelCommand.MSG_CANCEL_FAILED);
            }
            return;
        }
        context.sendMessage(UpdateCancelCommand.MSG_NOTHING_TO_CANCEL);
    }
    
    static {
        MSG_NOTHING_TO_CANCEL = Message.translation("server.commands.update.nothing_to_cancel");
        MSG_DOWNLOAD_CANCELLED = Message.translation("server.commands.update.download_cancelled");
        MSG_CANCEL_FAILED = Message.translation("server.commands.update.cancel_failed");
    }
}
