UpdateDownloadCommand class
Пакет: com.hypixel.hytale.server.core.update.command
Файл: com/hypixel/hytale/server/core/update/command/UpdateDownloadCommand.java
extends: AbstractAsyncCommand
Поля (17)
| Модификаторы | Тип | Имя |
|---|---|---|
final |
Message |
MSG_NOT_AUTHENTICATED |
|
UpdateModule |
var1 |
|
UpdateModule |
var2 |
|
ServerAuthManager |
var2 |
|
AtomicInteger |
var2 |
|
boolean |
var3 |
|
UpdateService |
var3 |
|
ServerAuthManager |
var4 |
|
UpdateService.ProgressCallback |
var4 |
|
UpdateService |
var5 |
|
String |
var5 |
|
UpdateService.DownloadTask |
var5 |
|
UpdateService.ProgressCallback |
var6 |
|
CompletableFuture |
var6 |
|
UpdateService.DownloadTask |
var7 |
|
CompletableFuture |
var8 |
|
int |
var8 |
Методы (15)
| Модификаторы | Возврат | Сигнатура |
|---|---|---|
|
|
if if(Constants.BOOTSTRAP) |
|
|
if if(var4x == null) |
|
|
if if(var2 != null) |
|
|
if if(var2 != null) |
|
|
if if(var3x instanceof CancellationException) |
|
|
if if(var2 != null) |
|
|
if if(var3x == null) |
|
|
if if(var1 != null) |
|
|
if if(var1 != null) |
|
|
if if(var1 != null) |
|
|
if if(var1 != null) |
abstract |
return |
runBootstrapInstallreturn runBootstrapInstall(var1) |
static |
void |
scheduleBootstrapShutdownvoid scheduleBootstrapShutdown() |
abstract |
|
scheduleBootstrapShutdown scheduleBootstrapShutdown() |
abstract |
|
super super("download", "server.commands.update.download.desc") |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.server.core.update.command;
class="kw">import com.hypixel.hytale.common.util.FormatUtil;
class="kw">import com.hypixel.hytale.common.util.java.ManifestUtil;
class="kw">import com.hypixel.hytale.server.core.Constants;
class="kw">import com.hypixel.hytale.server.core.HytaleServer;
class="kw">import com.hypixel.hytale.server.core.Message;
class="kw">import com.hypixel.hytale.server.core.ShutdownReason;
class="kw">import com.hypixel.hytale.server.core.auth.ServerAuthManager;
class="kw">import com.hypixel.hytale.server.core.command.system.CommandContext;
class="kw">import com.hypixel.hytale.server.core.command.system.arguments.system.FlagArg;
class="kw">import com.hypixel.hytale.server.core.command.system.basecommands.AbstractAsyncCommand;
class="kw">import com.hypixel.hytale.server.core.update.UpdateModule;
class="kw">import com.hypixel.hytale.server.core.update.UpdateService;
class="kw">import java.util.concurrent.CancellationException;
class="kw">import java.util.concurrent.CompletableFuture;
class="kw">import java.util.concurrent.TimeUnit;
class="kw">import java.util.concurrent.atomic.AtomicInteger;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">public class UpdateDownloadCommand class="kw">extends AbstractAsyncCommand {
class="kw">private class="kw">static class="kw">final Message MSG_NOT_AUTHENTICATED = Message.translation("server.commands.update.not_authenticated");
class="kw">private class="kw">static class="kw">final Message MSG_CHECK_FAILED = Message.translation("server.commands.update.check_failed");
class="kw">private class="kw">static class="kw">final Message MSG_NO_UPDATE = Message.translation("server.commands.update.no_update");
class="kw">private class="kw">static class="kw">final Message MSG_DOWNLOAD_FAILED = Message.translation("server.commands.update.download_failed");
class="kw">private class="kw">static class="kw">final Message MSG_DOWNLOAD_COMPLETE = Message.translation("server.commands.update.download_complete");
class="kw">private class="kw">static class="kw">final Message MSG_DOWNLOAD_IN_PROGRESS = Message.translation("server.commands.update.download_in_progress");
class="kw">private class="kw">static class="kw">final Message MSG_INVALID_LAYOUT = Message.translation("server.commands.update.invalid_layout_download");
class="kw">private class="kw">static class="kw">final Message MSG_BOOTSTRAP_COMPLETE = Message.translation("server.commands.update.bootstrap_complete");
class="kw">private class="kw">final FlagArg forceFlag = this.withFlagArg("force", "server.commands.update.download.force.desc");
class="kw">public UpdateDownloadCommand() {
super("download", "server.commands.update.download.desc");
}
@Nonnull
@Override
class="kw">protected CompletableFuture<Void> executeAsync(@Nonnull CommandContext var1) {
if (Constants.BOOTSTRAP) {
class="kw">return runBootstrapInstall(var1);
} else {
UpdateModule var2 = UpdateModule.get();
if (var2 != null && var2.isDownloadInProgress()) {
var1.sendMessage(MSG_DOWNLOAD_IN_PROGRESS);
class="kw">return CompletableFuture.completedFuture(null);
} else {
boolean var3 = this.forceFlag.get(var1);
if (!UpdateService.isValidUpdateLayout() && !var3) {
var1.sendMessage(MSG_INVALID_LAYOUT);
class="kw">return CompletableFuture.completedFuture(null);
} else {
ServerAuthManager var4 = ServerAuthManager.getInstance();
if (!var4.hasSessionToken()) {
var1.sendMessage(MSG_NOT_AUTHENTICATED);
class="kw">return CompletableFuture.completedFuture(null);
} else {
UpdateService var5 = new UpdateService();
class="kw">return var5.checkForUpdate(UpdateService.getEffectivePatchline()).thenCompose(var4x -> {
if (var4x == null) {
var1.sendMessage(MSG_CHECK_FAILED);
class="kw">return CompletableFuture.completedFuture(null);
}
if (var2 != null) {
var2.setLatestKnownVersion(var4x);
}
String var5 = ManifestUtil.getImplementationVersion();
if (!var3 && var5 != null && var5.equals(var4x.version)) {
var1.sendMessage(MSG_NO_UPDATE);
class="kw">return CompletableFuture.completedFuture(null);
}
if (var2 != null && !var2.tryAcquireDownloadLock()) {
var1.sendMessage(MSG_DOWNLOAD_IN_PROGRESS);
class="kw">return CompletableFuture.completedFuture(null);
}
var1.sendMessage(Message.translation("server.commands.update.downloading").param("version", var4x.version));
UpdateService.ProgressCallback var6 = progressCallback(var1, var2);
UpdateService.DownloadTask var7 = var5.downloadUpdate(var4x, UpdateService.getStagingDir(), var6);
CompletableFuture var8 = var7.future().whenComplete((var2x, var3x) -> {
if (var2 != null) {
var2.releaseDownloadLock();
}
if (var3x class="kw">instanceof CancellationException) {
UpdateService.deleteStagedUpdate();
} else if (var3x == null && Boolean.TRUE.equals(var2x)) {
var1.sendMessage(MSG_DOWNLOAD_COMPLETE);
if (!UpdateService.isValidUpdateLayout()) {
var1.sendMessage(Message.translation("server.commands.update.download_setup_hint"));
}
} else {
var1.sendMessage(MSG_DOWNLOAD_FAILED);
UpdateService.deleteStagedUpdate();
}
});
if (var2 != null) {
var2.setActiveDownload(var8, var7.thread());
}
class="kw">return var8.thenApply(var0x -> null);
});
}
}
}
}
}
@Nonnull
class="kw">public class="kw">static CompletableFuture<Void> runBootstrapInstall(@Nonnull CommandContext var0) {
UpdateModule var1 = UpdateModule.get();
if (var1 != null && var1.isDownloadInProgress()) {
var0.sendMessage(MSG_DOWNLOAD_IN_PROGRESS);
class="kw">return CompletableFuture.completedFuture(null);
} else {
ServerAuthManager var2 = ServerAuthManager.getInstance();
if (!var2.hasSessionToken()) {
var0.sendMessage(MSG_NOT_AUTHENTICATED);
class="kw">return CompletableFuture.completedFuture(null);
} else {
UpdateService var3 = new UpdateService();
class="kw">return var3.checkForUpdate(UpdateService.getEffectivePatchline()).thenCompose(var3x -> {
if (var3x == null) {
var0.sendMessage(MSG_CHECK_FAILED);
class="kw">return CompletableFuture.completedFuture(null);
}
if (var1 != null) {
var1.setLatestKnownVersion(var3x);
if (!var1.tryAcquireDownloadLock()) {
var0.sendMessage(MSG_DOWNLOAD_IN_PROGRESS);
class="kw">return CompletableFuture.completedFuture(null);
}
}
var0.sendMessage(Message.translation("server.commands.update.downloading").param("version", var3x.version));
UpdateService.ProgressCallback var4 = progressCallback(var0, var1);
UpdateService.DownloadTask var5 = var3.performBootstrapInstall(var3x, var4);
CompletableFuture var6 = var5.future().whenComplete((var2x, var3xx) -> {
if (var1 != null) {
var1.releaseDownloadLock();
}
if (!(var3xx class="kw">instanceof CancellationException)) {
if (var3xx == null && Boolean.TRUE.equals(var2x)) {
var0.sendMessage(MSG_BOOTSTRAP_COMPLETE);
scheduleBootstrapShutdown();
} else {
var0.sendMessage(MSG_DOWNLOAD_FAILED);
}
}
});
if (var1 != null) {
var1.setActiveDownload(var6, var5.thread());
}
class="kw">return var6.thenApply(var0x -> null);
});
}
}
}
@Nonnull
class="kw">private class="kw">static UpdateService.ProgressCallback progressCallback(@Nonnull CommandContext var0, @Nullable UpdateModule var1) {
AtomicInteger var2 = new AtomicInteger(-1);
class="kw">return (var3, var4, var6) -> {
if (var1 != null) {
var1.updateDownloadProgress(var4, var6);
}
int var8 = var3 / 10 * 10;
if (var8 > var2.get()) {
var2.set(var8);
var0.sendMessage(
Message.translation("server.commands.update.download_progress")
.param("percent", String.valueOf(var3))
.param("downloaded", FormatUtil.bytesToString(var4))
.param("total", FormatUtil.bytesToString(var6))
);
}
};
}
class="kw">private class="kw">static void scheduleBootstrapShutdown() {
CompletableFuture.delayedExecutor(500L, TimeUnit.MILLISECONDS).execute(() -> HytaleServer.get().shutdownServer(ShutdownReason.SHUTDOWN));
}
}