UpdateApplyCommand class
Пакет: com.hypixel.hytale.server.core.update.command
Файл: com/hypixel/hytale/server/core/update/command/UpdateApplyCommand.java
extends: CommandBase
Поля (14)
| Модификаторы | Тип | Имя |
|---|---|---|
|
|
return |
|
Path |
var1 |
|
Path |
var1 |
|
String |
var2 |
|
Path |
var2 |
|
int |
var2 |
|
UpdateConfig |
var3 |
|
Path |
var3 |
|
BackupConfig |
var4 |
|
Path |
var4 |
|
Universe |
var5 |
|
Path |
var5 |
|
Path |
var6 |
|
Path |
var7 |
Методы (7)
| Модификаторы | Возврат | Сигнатура |
|---|---|---|
abstract |
throw new |
IOExceptionthrow new IOException("Failed to clear existing backup directory") |
private |
void |
backupConfigFilesvoid backupConfigFiles() |
private |
void |
backupCurrentFilesvoid backupCurrentFiles() |
|
|
for for(String var6 : CONFIG_FILES) |
|
|
if if(var2 == null) |
|
|
if if(var5 != null) |
abstract |
|
super super("apply", "server.commands.update.apply.desc") |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.server.core.update.command;
class="kw">import com.hypixel.hytale.logger.HytaleLogger;
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.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.CommandBase;
class="kw">import com.hypixel.hytale.server.core.config.BackupConfig;
class="kw">import com.hypixel.hytale.server.core.config.UpdateConfig;
class="kw">import com.hypixel.hytale.server.core.universe.Universe;
class="kw">import com.hypixel.hytale.server.core.update.UpdateService;
class="kw">import com.hypixel.hytale.server.core.util.io.FileUtil;
class="kw">import java.io.IOException;
class="kw">import java.nio.file.Files;
class="kw">import java.nio.file.Path;
class="kw">import java.nio.file.StandardCopyOption;
class="kw">import java.util.logging.Level;
class="kw">import javax.annotation.Nonnull;
class="kw">public class UpdateApplyCommand class="kw">extends CommandBase {
@Nonnull
class="kw">private class="kw">static class="kw">final HytaleLogger LOGGER = HytaleLogger.forEnclosingClass();
@Nonnull
class="kw">private class="kw">static class="kw">final Message MSG_NO_STAGED = Message.translation("server.commands.update.no_staged");
@Nonnull
class="kw">private class="kw">static class="kw">final Message MSG_BACKUP_FAILED = Message.translation("server.commands.update.backup_failed");
@Nonnull
class="kw">private class="kw">final FlagArg confirmFlag = this.withFlagArg("confirm", "server.commands.update.apply.confirm.desc");
class="kw">private class="kw">static class="kw">final String[] CONFIG_FILES = new String[]{"config.json", "permissions.json", "bans.json", "whitelist.json"};
class="kw">public UpdateApplyCommand() {
super("apply", "server.commands.update.apply.desc");
}
@Override
class="kw">protected void executeSync(@Nonnull CommandContext var1) {
String var2 = UpdateService.getStagedVersion();
if (var2 == null) {
var1.sendMessage(MSG_NO_STAGED);
} else if (!this.confirmFlag.get(var1)) {
var1.sendMessage(Message.translation("server.commands.update.apply_confirm_required").param("version", var2));
} else {
if (!UpdateService.isValidUpdateLayout()) {
var1.sendMessage(Message.translation("server.commands.update.applying_no_launcher").param("version", var2));
LOGGER.at(Level.WARNING).log("No launcher script detected - update must be applied manually after shutdown");
} else {
var1.sendMessage(Message.translation("server.commands.update.applying").param("version", var2));
}
UpdateConfig var3 = HytaleServer.get().getConfig().getUpdateConfig();
try {
this.backupCurrentFiles();
BackupConfig var4 = HytaleServer.get().getConfig().getBackupConfig();
if (var3.isRunBackupBeforeUpdate() && var4.getDirectory() != null) {
Universe var5 = Universe.get();
if (var5 != null) {
LOGGER.at(Level.INFO).log("Running server backup before update...");
var5.runBackup().join();
LOGGER.at(Level.INFO).log("Server backup completed");
}
} else if (var3.isRunBackupBeforeUpdate()) {
LOGGER.at(Level.WARNING).log("RunBackupBeforeUpdate is enabled but backups are not configured");
}
if (var3.isBackupConfigBeforeUpdate()) {
this.backupConfigFiles();
}
} catch (IOException var6) {
((HytaleLogger.Api)LOGGER.at(Level.SEVERE).withCause(var6)).log("Failed to create backups before update");
var1.sendMessage(MSG_BACKUP_FAILED);
class="kw">return;
}
HytaleServer.get().shutdownServer(ShutdownReason.UPDATE);
}
}
class="kw">private void backupCurrentFiles() class="kw">throws IOException {
Path var1 = UpdateService.getBackupDir();
Path var2 = var1.resolve("Server");
if (!UpdateService.deleteBackupDir()) {
throw new IOException("Failed to clear existing backup directory");
}
Files.createDirectories(var2);
Path var3 = Path.of("HytaleServer.jar");
if (Files.exists(var3)) {
Files.copy(var3, var2.resolve("HytaleServer.jar"), StandardCopyOption.REPLACE_EXISTING);
}
Path var4 = Path.of("HytaleServer.aot");
if (Files.exists(var4)) {
Files.copy(var4, var2.resolve("HytaleServer.aot"), StandardCopyOption.REPLACE_EXISTING);
}
Path var5 = Path.of("Licenses");
if (Files.exists(var5)) {
FileUtil.copyDirectory(var5, var2.resolve("Licenses"));
}
Path var6 = Path.of("..").resolve("Assets.zip");
if (Files.exists(var6)) {
Files.copy(var6, var1.resolve("Assets.zip"), StandardCopyOption.REPLACE_EXISTING);
}
LOGGER.at(Level.INFO).log("Backed up current server files to %s", var1);
}
class="kw">private void backupConfigFiles() class="kw">throws IOException {
Path var1 = UpdateService.getBackupDir().resolve("Server");
Files.createDirectories(var1);
int var2 = 0;
for (String var6 : CONFIG_FILES) {
Path var7 = Path.of(var6);
if (Files.exists(var7)) {
Files.copy(var7, var1.resolve(var6), StandardCopyOption.REPLACE_EXISTING);
var2++;
}
}
LOGGER.at(Level.INFO).log("Backed up %d config files to %s", var2, var1);
}
}