Status command and cleanup.
This commit is contained in:
parent
aca7dba943
commit
ca56fcc671
6 changed files with 59 additions and 6 deletions
|
@ -1,7 +1,9 @@
|
|||
# ExtBackup
|
||||
|
||||
Minimal Minecraft backup mod, relying on external backup tools.
|
||||
|
||||
## Why?
|
||||
|
||||
The regular well-known backup mods lack the sophistication of dedicated backup tools.
|
||||
|
||||
ExtBackup does not care about storage, retention, rotating old backups, freeing up space or any of that stuff.
|
||||
|
@ -10,13 +12,16 @@ program can be as simple or as complicated as you want it to be. Connect your Mi
|
|||
whatever you like and backup your worlds however you like.
|
||||
|
||||
## Target audience
|
||||
ExtBackup is aimed at server owners. It's so far only tested on Linux and does not offer much configuration. It just
|
||||
|
||||
ExtBackup is aimed at server owners. It's so far only tested on Linux and does not offer much configuration. It just
|
||||
runs the program with the Minecraft directory as current working directory. It may well work on Windows, or it may not.
|
||||
|
||||
## Acknowledgements
|
||||
|
||||
* [MelanX](https://modrinth.com/user/MelanX) for [Simple Backups](https://modrinth.com/mod/simple-backups) which formed
|
||||
the base for ExtBackup 2.0, the NeoForge version.
|
||||
* [LatvianModder](https://github.com/LatvianModder) for his work on [FTB-Backups](https://github.com/FTBTeam/FTB-Backups)
|
||||
* [LatvianModder](https://github.com/LatvianModder) for his work
|
||||
on [FTB-Backups](https://github.com/FTBTeam/FTB-Backups)
|
||||
where I stole a lot of the code for the Forge Version.
|
||||
* [alexbobp](https://github.com/alexbobp) and the [elytra](https://github.com/elytra) group for
|
||||
[BTFU](https://github.com/elytra/BTFU), which gave me the idea but didn't go quite far enough.
|
||||
|
|
|
@ -115,7 +115,9 @@ public class BackupThread extends Thread {
|
|||
try {
|
||||
Process backup = pb.start();
|
||||
returnValue = backup.waitFor();
|
||||
if (returnValue != 0) { throw new IOException("Backup process returned non-zero result!");}
|
||||
if (returnValue != 0) {
|
||||
throw new IOException("Backup process returned non-zero result!");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ExtBackup.LOGGER.error("Something went wrong with the Backup script!");
|
||||
ExtBackup.LOGGER.error("Check your Backups.");
|
||||
|
@ -123,7 +125,7 @@ public class BackupThread extends Thread {
|
|||
}
|
||||
}
|
||||
|
||||
private static class Timer {
|
||||
public static class Timer {
|
||||
|
||||
private static final SimpleDateFormat SECONDS = new SimpleDateFormat("s.SSS");
|
||||
private static final SimpleDateFormat MINUTES = new SimpleDateFormat("mm:ss");
|
||||
|
|
|
@ -13,6 +13,7 @@ import net.neoforged.neoforge.network.PacketDistributor;
|
|||
import net.neoforged.neoforge.network.registration.NetworkRegistry;
|
||||
import net.sweevo.jinks.commands.BackupCommand;
|
||||
import net.sweevo.jinks.commands.PauseCommand;
|
||||
import net.sweevo.jinks.commands.StatusCommand;
|
||||
import net.sweevo.jinks.config.CommonConfig;
|
||||
import net.sweevo.jinks.config.ServerConfig;
|
||||
import net.sweevo.jinks.network.Pause;
|
||||
|
@ -30,6 +31,7 @@ public class EventListener {
|
|||
event.getDispatcher().register(Commands.literal(ExtBackup.MODID)
|
||||
.requires(stack -> ServerConfig.commandsCheatsDisabled() || stack.hasPermission(2))
|
||||
.then(BackupCommand.register())
|
||||
.then(StatusCommand.register())
|
||||
.then(PauseCommand.register()));
|
||||
}
|
||||
|
||||
|
|
42
src/main/java/net/sweevo/jinks/commands/StatusCommand.java
Normal file
42
src/main/java/net/sweevo/jinks/commands/StatusCommand.java
Normal file
|
@ -0,0 +1,42 @@
|
|||
package net.sweevo.jinks.commands;
|
||||
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.builder.ArgumentBuilder;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.sweevo.jinks.BackupData;
|
||||
import net.sweevo.jinks.BackupThread;
|
||||
import net.sweevo.jinks.ExtBackup;
|
||||
import net.sweevo.jinks.config.CommonConfig;
|
||||
|
||||
public class StatusCommand implements Command<CommandSourceStack> {
|
||||
|
||||
|
||||
private StatusCommand() {
|
||||
}
|
||||
|
||||
public static ArgumentBuilder<CommandSourceStack, ?> register() {
|
||||
return Commands.literal("backup")
|
||||
.then(Commands.literal("status")
|
||||
.executes(new StatusCommand()));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int run(CommandContext<CommandSourceStack> context) {
|
||||
BackupData data = BackupData.get(context.getSource().getServer());
|
||||
String paused = data.isPaused() ? "true" : "false";
|
||||
String nextUp = BackupThread.Timer.getTimer(data.getLastSaved() + CommonConfig.getTimer());
|
||||
ServerPlayer player = context.getSource().getPlayer();
|
||||
if (player != null) {
|
||||
player.sendSystemMessage(BackupThread.component(player, "extbackup.status_message", paused, nextUp).withStyle(Style.EMPTY.withColor(ChatFormatting.GOLD)));
|
||||
} else {
|
||||
ExtBackup.LOGGER.info("Backups paused: {} - Next backup: {}", paused, nextUp);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"extbackup.backup_started": "Backup gestartet...",
|
||||
"extbackup.backup_finished": "Backup fertiggestellt in %s",
|
||||
"extbackup.backups_paused": "Backups pausiert"
|
||||
"extbackup.backups_paused": "Backups pausiert",
|
||||
"extbackup.status_message": "Backups pausiert: %s. - Nächstes Backup: %s"
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"extbackup.backup_started": "Backup started...",
|
||||
"extbackup.backup_finished": "Backup completed in %s",
|
||||
"extbackup.backups_paused": "Backups paused"
|
||||
"extbackup.backups_paused": "Backups paused",
|
||||
"extbackup.status_message": "Backups paused: %s. - Next backup: %s"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue