dropped unnecessary accessors in BackupContext (record)
This commit is contained in:
parent
fd02df7022
commit
27aa40027c
@ -6,7 +6,7 @@ yarn_mappings=1.19+build.4
|
||||
loader_version=0.14.8
|
||||
|
||||
#Fabric api
|
||||
fabric_version=0.56.0+1.19
|
||||
fabric_version=0.56.1+1.19
|
||||
|
||||
#Cloth Config
|
||||
cloth_version=7.0.72
|
||||
@ -15,12 +15,12 @@ cloth_version=7.0.72
|
||||
modmenu_version=4.0.0
|
||||
|
||||
#Lazy DFU for faster dev start
|
||||
lazydfu_version=0.1.2
|
||||
lazydfu_version=v0.1.3
|
||||
|
||||
#Hash of commit form which parallel gzip will be build
|
||||
pgzip_commit_hash=af5f5c297e735f3f2df7aa4eb0e19a5810b8aff6
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 2.3.1
|
||||
mod_version = 2.4.0
|
||||
maven_group = net.szum123321
|
||||
archives_base_name = textile_backup
|
@ -120,7 +120,7 @@ public class TextileLogger {
|
||||
}
|
||||
|
||||
public void sendInfo(BackupContext context, String msg, Object... args) {
|
||||
sendInfo(context.getCommandSource(), msg, args);
|
||||
sendInfo(context.commandSource(), msg, args);
|
||||
}
|
||||
|
||||
public void sendError(ServerCommandSource source, String msg, Object... args) {
|
||||
@ -128,7 +128,7 @@ public class TextileLogger {
|
||||
}
|
||||
|
||||
public void sendError(BackupContext context, String msg, Object... args) {
|
||||
sendError(context.getCommandSource(), msg, args);
|
||||
sendError(context.commandSource(), msg, args);
|
||||
}
|
||||
|
||||
public void sendToPlayerAndLog(Level level, ServerCommandSource source, String msg, Object... args) {
|
||||
@ -142,7 +142,7 @@ public class TextileLogger {
|
||||
}
|
||||
|
||||
public void sendInfoAL(BackupContext context, String msg, Object... args) {
|
||||
sendInfoAL(context.getCommandSource(), msg, args);
|
||||
sendInfoAL(context.commandSource(), msg, args);
|
||||
}
|
||||
|
||||
public void sendErrorAL(ServerCommandSource source, String msg, Object... args) {
|
||||
@ -150,6 +150,6 @@ public class TextileLogger {
|
||||
}
|
||||
|
||||
public void sendErrorAL(BackupContext context, String msg, Object... args) {
|
||||
sendErrorAL(context.getCommandSource(), msg, args);
|
||||
sendErrorAL(context.commandSource(), msg, args);
|
||||
}
|
||||
}
|
||||
|
@ -33,18 +33,6 @@ public record BackupContext(@NotNull MinecraftServer server,
|
||||
boolean save,
|
||||
String comment) {
|
||||
|
||||
public MinecraftServer getServer() {
|
||||
return server;
|
||||
}
|
||||
|
||||
public ServerCommandSource getCommandSource() {
|
||||
return commandSource;
|
||||
}
|
||||
|
||||
public ActionInitiator getInitiator() {
|
||||
return initiator;
|
||||
}
|
||||
|
||||
public boolean startedByPlayer() {
|
||||
return initiator == ActionInitiator.Player;
|
||||
}
|
||||
@ -53,14 +41,6 @@ public record BackupContext(@NotNull MinecraftServer server,
|
||||
return save;
|
||||
}
|
||||
|
||||
public String getComment() {
|
||||
return comment;
|
||||
}
|
||||
|
||||
public UUID getInitiatorUUID() {
|
||||
return initiator.equals(ActionInitiator.Player) && commandSource.getEntity() != null ? commandSource.getEntity().getUuid(): Util.NIL_UUID;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private MinecraftServer server;
|
||||
private ServerCommandSource commandSource;
|
||||
|
@ -41,7 +41,7 @@ public class BackupHelper {
|
||||
|
||||
public static Runnable create(BackupContext ctx) {
|
||||
if(config.get().broadcastBackupStart) {
|
||||
Utilities.notifyPlayers(ctx.getServer(),
|
||||
Utilities.notifyPlayers(ctx.server(),
|
||||
"Warning! Server backup will begin shortly. You may experience some lag."
|
||||
);
|
||||
} else {
|
||||
@ -52,12 +52,12 @@ public class BackupHelper {
|
||||
|
||||
builder.append("Backup started ");
|
||||
|
||||
builder.append(ctx.getInitiator().getPrefix());
|
||||
builder.append(ctx.initiator().getPrefix());
|
||||
|
||||
if(ctx.startedByPlayer())
|
||||
builder.append(ctx.getCommandSource().getDisplayName().getString());
|
||||
builder.append(ctx.commandSource().getDisplayName().getString());
|
||||
else
|
||||
builder.append(ctx.getInitiator().getName());
|
||||
builder.append(ctx.initiator().getName());
|
||||
|
||||
builder.append(" on: ");
|
||||
builder.append(Utilities.getDateTimeFormatter().format(LocalDateTime.now()));
|
||||
@ -67,10 +67,10 @@ public class BackupHelper {
|
||||
if (ctx.shouldSave()) {
|
||||
log.sendInfoAL(ctx, "Saving server...");
|
||||
|
||||
ctx.getServer().getPlayerManager().saveAllPlayerData();
|
||||
ctx.server().getPlayerManager().saveAllPlayerData();
|
||||
|
||||
try {
|
||||
ctx.getServer().save(false, true, true);
|
||||
ctx.server().save(false, true, true);
|
||||
} catch (Exception e) {
|
||||
log.sendErrorAL(ctx,"An exception occurred when trying to save the world!");
|
||||
}
|
||||
|
@ -49,32 +49,30 @@ public class MakeBackupRunnable implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Utilities.disableWorldSaving(context.getServer());
|
||||
Utilities.disableWorldSaving(context.server());
|
||||
Statics.disableWatchdog = true;
|
||||
|
||||
Utilities.updateTMPFSFlag(context.getServer());
|
||||
Utilities.updateTMPFSFlag(context.server());
|
||||
|
||||
log.sendInfoAL(context, "Starting backup");
|
||||
|
||||
Path world = Utilities.getWorldFolder(context.getServer());
|
||||
Path world = Utilities.getWorldFolder(context.server());
|
||||
|
||||
log.trace("Minecraft world is: {}", world);
|
||||
|
||||
Path outFile = Utilities
|
||||
.getBackupRootPath(Utilities.getLevelName(context.getServer()))
|
||||
.getBackupRootPath(Utilities.getLevelName(context.server()))
|
||||
.resolve(getFileName());
|
||||
|
||||
log.trace("Outfile is: {}", outFile);
|
||||
|
||||
// outFile.getParentFile().mkdirs();
|
||||
|
||||
try {
|
||||
//outFile.createNewFile();
|
||||
Files.createDirectories(outFile.getParent());
|
||||
Files.createFile(outFile);
|
||||
} catch (IOException e) {
|
||||
log.error("An exception occurred when trying to create new backup file!", e);
|
||||
|
||||
if(context.getInitiator() == ActionInitiator.Player)
|
||||
if(context.initiator() == ActionInitiator.Player)
|
||||
log.sendError(context, "An exception occurred when trying to create new backup file!");
|
||||
|
||||
return;
|
||||
@ -92,10 +90,13 @@ public class MakeBackupRunnable implements Runnable {
|
||||
|
||||
switch (config.get().format) {
|
||||
case ZIP -> {
|
||||
if (coreCount > 1 && !Statics.disableTMPFiles)
|
||||
if (coreCount > 1 && !Statics.disableTMPFiles) {
|
||||
ParallelZipCompressor.getInstance().createArchive(world, outFile, context, coreCount);
|
||||
else
|
||||
log.trace("Using PARALLEL Zip Compressor. Threads: {}", coreCount);
|
||||
} else {
|
||||
ZipCompressor.getInstance().createArchive(world, outFile, context, coreCount);
|
||||
log.trace("Using REGULAR Zip Compressor. Threads: {}");
|
||||
}
|
||||
}
|
||||
case BZIP2 -> ParallelBZip2Compressor.getInstance().createArchive(world, outFile, context, coreCount);
|
||||
case GZIP -> ParallelGzipCompressor.getInstance().createArchive(world, outFile, context, coreCount);
|
||||
@ -105,26 +106,20 @@ public class MakeBackupRunnable implements Runnable {
|
||||
}
|
||||
}.createArchive(world, outFile, context, coreCount);
|
||||
case TAR -> new AbstractTarArchiver().createArchive(world, outFile, context, coreCount);
|
||||
default -> {
|
||||
log.warn("Specified compressor ({}) is not supported! Zip will be used instead!", config.get().format);
|
||||
if (context.getInitiator() == ActionInitiator.Player)
|
||||
log.sendError(context.getCommandSource(), "Error! No correct compression format specified! Using default compressor!");
|
||||
ZipCompressor.getInstance().createArchive(world, outFile, context, coreCount);
|
||||
}
|
||||
}
|
||||
|
||||
BackupHelper.executeFileLimit(context.getCommandSource(), Utilities.getLevelName(context.getServer()));
|
||||
BackupHelper.executeFileLimit(context.commandSource(), Utilities.getLevelName(context.server()));
|
||||
|
||||
if(config.get().broadcastBackupDone) {
|
||||
Utilities.notifyPlayers(
|
||||
context.getServer(),
|
||||
context.server(),
|
||||
"Done!"
|
||||
);
|
||||
} else {
|
||||
log.sendInfoAL(context, "Done!");
|
||||
}
|
||||
} finally {
|
||||
Utilities.enableWorldSaving(context.getServer());
|
||||
Utilities.enableWorldSaving(context.server());
|
||||
Statics.disableWatchdog = false;
|
||||
}
|
||||
}
|
||||
@ -133,7 +128,7 @@ public class MakeBackupRunnable implements Runnable {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
return Utilities.getDateTimeFormatter().format(now) +
|
||||
(context.getComment() != null ? "#" + context.getComment().replaceAll("[\\\\/:*?\"<>|#]", "") : "") +
|
||||
(context.comment() != null ? "#" + context.comment().replaceAll("[\\\\/:*?\"<>|#]", "") : "") +
|
||||
config.get().format.getCompleteString();
|
||||
}
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ public abstract class AbstractCompressor {
|
||||
} catch (IOException e) {
|
||||
log.error("An exception occurred while trying to compress: {}", inputFile.relativize(file).toString(), e);
|
||||
|
||||
if (ctx.getInitiator() == ActionInitiator.Player)
|
||||
if (ctx.initiator() == ActionInitiator.Player)
|
||||
log.sendError(ctx, "Something went wrong while compressing files!");
|
||||
}
|
||||
});
|
||||
@ -67,14 +67,14 @@ public abstract class AbstractCompressor {
|
||||
For help see: https://github.com/Szum123321/textile_backup/wiki/ZIP-Problems
|
||||
In case this isn't it here's also the exception itself""", e);
|
||||
|
||||
if(ctx.getInitiator() == ActionInitiator.Player) {
|
||||
if(ctx.initiator() == ActionInitiator.Player) {
|
||||
log.sendError(ctx, "Backup failed. The file is corrupt.");
|
||||
log.error("For help see: https://github.com/Szum123321/textile_backup/wiki/ZIP-Problems");
|
||||
}
|
||||
} catch (IOException | InterruptedException | ExecutionException e) {
|
||||
log.error("An exception occurred!", e);
|
||||
} catch (Exception e) {
|
||||
if(ctx.getInitiator() == ActionInitiator.Player)
|
||||
if(ctx.initiator() == ActionInitiator.Player)
|
||||
log.sendError(ctx, "Something went wrong while compressing files!");
|
||||
} finally {
|
||||
close();
|
||||
|
@ -72,9 +72,6 @@ public class RestoreBackupRunnable implements Runnable {
|
||||
worldFile.getParent(),
|
||||
ctx.restoreableFile().getFile().getFileName().toString());
|
||||
|
||||
//leave it as it is
|
||||
//tmp.toFile().deleteOnExit();
|
||||
|
||||
log.info("Starting decompression...");
|
||||
|
||||
if (ctx.restoreableFile().getArchiveFormat() == ConfigPOJO.ArchiveFormat.ZIP)
|
||||
|
Loading…
Reference in New Issue
Block a user