typo and some code cleanup
This commit is contained in:
parent
1cb2898173
commit
226c75eefd
@ -45,11 +45,11 @@ public class ConfigHandler {
|
|||||||
@Comment("\nShould every world has its won backup folder?\n")
|
@Comment("\nShould every world has its won backup folder?\n")
|
||||||
public boolean perWorldBackup = false;
|
public boolean perWorldBackup = false;
|
||||||
|
|
||||||
@Comment("\nMaximum number of backups to keep. if 0 then no backup will be deleted based on its amount\n")
|
@Comment("\nMaximum number of backups to keep. If 0 then no backup will be deleted based on its amount\n")
|
||||||
public int backupsToKeep = 10;
|
public int backupsToKeep = 10;
|
||||||
|
|
||||||
@Comment("\nMaximum age of backups to keep in seconds.\n if 0 then backups will not be deleted based on its age \n")
|
@Comment("\nMaximum age of backups to keep in seconds.\n if 0 then backups will not be deleted based on its age \n")
|
||||||
public int maxAge = 0;
|
public long maxAge = 0;
|
||||||
|
|
||||||
@Comment("\nMaximum size of backup folder in kilo bytes. \n")
|
@Comment("\nMaximum size of backup folder in kilo bytes. \n")
|
||||||
public int maxSize = 0;
|
public int maxSize = 0;
|
||||||
@ -70,7 +70,7 @@ public class ConfigHandler {
|
|||||||
public Set<String> playerWhitelist = new HashSet<>();
|
public Set<String> playerWhitelist = new HashSet<>();
|
||||||
|
|
||||||
@Comment("\nPlayers banned from running backup commands besides their sufficient permission level\n")
|
@Comment("\nPlayers banned from running backup commands besides their sufficient permission level\n")
|
||||||
public Set<String> playerBlocklist = new HashSet<>();
|
public Set<String> playerBlacklist = new HashSet<>();
|
||||||
|
|
||||||
@Comment("\nFormat of date&time used to name backup files.\n")
|
@Comment("\nFormat of date&time used to name backup files.\n")
|
||||||
public String dateTimeFormat = "dd.MM.yyyy_HH-mm-ss";
|
public String dateTimeFormat = "dd.MM.yyyy_HH-mm-ss";
|
||||||
|
@ -54,7 +54,7 @@ public class TextileBackup implements ModInitializer {
|
|||||||
try {
|
try {
|
||||||
return ((config.playerWhitelist.contains(ctx.getEntityOrThrow().getEntityName()) ||
|
return ((config.playerWhitelist.contains(ctx.getEntityOrThrow().getEntityName()) ||
|
||||||
ctx.hasPermissionLevel(config.permissionLevel)) &&
|
ctx.hasPermissionLevel(config.permissionLevel)) &&
|
||||||
!config.playerBlocklist.contains(ctx.getEntityOrThrow().getEntityName())) ||
|
!config.playerBlacklist.contains(ctx.getEntityOrThrow().getEntityName())) ||
|
||||||
(ctx.getMinecraftServer().isSinglePlayer() &&
|
(ctx.getMinecraftServer().isSinglePlayer() &&
|
||||||
config.alwaysSingleplayerAllowed);
|
config.alwaysSingleplayerAllowed);
|
||||||
}catch (Exception e){ //Command was called from server console.
|
}catch (Exception e){ //Command was called from server console.
|
||||||
|
@ -40,7 +40,7 @@ public class BlacklistCommand {
|
|||||||
|
|
||||||
builder.append("Currently on the blacklist are: ");
|
builder.append("Currently on the blacklist are: ");
|
||||||
|
|
||||||
for(String name : TextileBackup.config.playerBlocklist){
|
for(String name : TextileBackup.config.playerBlacklist){
|
||||||
builder.append(name);
|
builder.append(name);
|
||||||
builder.append(", ");
|
builder.append(", ");
|
||||||
}
|
}
|
||||||
@ -53,10 +53,10 @@ public class BlacklistCommand {
|
|||||||
private static int executeAdd(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
|
private static int executeAdd(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
|
||||||
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
|
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
|
||||||
|
|
||||||
if(TextileBackup.config.playerBlocklist.contains(player.getEntityName())) {
|
if(TextileBackup.config.playerBlacklist.contains(player.getEntityName())) {
|
||||||
ctx.getSource().sendFeedback(new TranslatableText("Player: %s is already blacklisted.", player.getEntityName()), false);
|
ctx.getSource().sendFeedback(new TranslatableText("Player: %s is already blacklisted.", player.getEntityName()), false);
|
||||||
}else{
|
}else{
|
||||||
TextileBackup.config.playerBlocklist.add(player.getEntityName());
|
TextileBackup.config.playerBlacklist.add(player.getEntityName());
|
||||||
ConfigManager.saveConfig(TextileBackup.config);
|
ConfigManager.saveConfig(TextileBackup.config);
|
||||||
|
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
@ -81,10 +81,10 @@ public class BlacklistCommand {
|
|||||||
private static int executeRemove(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
|
private static int executeRemove(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
|
||||||
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
|
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
|
||||||
|
|
||||||
if(!TextileBackup.config.playerBlocklist.contains(player.getEntityName())) {
|
if(!TextileBackup.config.playerBlacklist.contains(player.getEntityName())) {
|
||||||
ctx.getSource().sendFeedback(new TranslatableText("Player: %s newer was blacklisted.", player.getEntityName()), false);
|
ctx.getSource().sendFeedback(new TranslatableText("Player: %s newer was blacklisted.", player.getEntityName()), false);
|
||||||
}else{
|
}else{
|
||||||
TextileBackup.config.playerBlocklist.remove(player.getEntityName());
|
TextileBackup.config.playerBlacklist.remove(player.getEntityName());
|
||||||
ConfigManager.saveConfig(TextileBackup.config);
|
ConfigManager.saveConfig(TextileBackup.config);
|
||||||
|
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
@ -65,8 +65,8 @@ public class WhitelistCommand {
|
|||||||
builder.append(player.getEntityName());
|
builder.append(player.getEntityName());
|
||||||
builder.append(" added to the whitelist");
|
builder.append(" added to the whitelist");
|
||||||
|
|
||||||
if(TextileBackup.config.playerBlocklist.contains(player.getEntityName())){
|
if(TextileBackup.config.playerBlacklist.contains(player.getEntityName())){
|
||||||
TextileBackup.config.playerBlocklist.remove(player.getEntityName());
|
TextileBackup.config.playerBlacklist.remove(player.getEntityName());
|
||||||
builder.append(" and removed form the blacklist");
|
builder.append(" and removed form the blacklist");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ public class MakeBackupThread implements Runnable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Compressor.createArchive(world, outFile, ctx);
|
ZipCompressor.createArchive(world, outFile, ctx);
|
||||||
|
|
||||||
BackupHelper.executeFileLimit(ctx, server.getWorld(DimensionType.OVERWORLD).getLevelProperties().getLevelName());
|
BackupHelper.executeFileLimit(ctx, server.getWorld(DimensionType.OVERWORLD).getLevelProperties().getLevelName());
|
||||||
|
|
||||||
|
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
A simple backup mod for Fabric
|
||||||
|
Copyright (C) 2020 Szum123321
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.szum123321.textile_backup.core;
|
||||||
|
|
||||||
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
|
import net.szum123321.textile_backup.TextileBackup;
|
||||||
|
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
|
||||||
|
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
|
||||||
|
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream;
|
||||||
|
import org.apache.commons.compress.utils.IOUtils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
|
public class ZipCompressor {
|
||||||
|
public static void createArchive(File in, File out, ServerCommandSource ctx){
|
||||||
|
Utilities.log("Starting compression...", ctx);
|
||||||
|
|
||||||
|
try (ZipOutputStream arc = new ZipOutputStream(new FileOutputStream(out))){
|
||||||
|
arc.setLevel(TextileBackup.config.compression);
|
||||||
|
arc.setComment("Created on: " + Utilities.getDateTimeFormatter().format(LocalDateTime.now()));
|
||||||
|
|
||||||
|
File input = in.getCanonicalFile();
|
||||||
|
int rootPathLength = input.toString().length() + 1;
|
||||||
|
|
||||||
|
Files.walk(input.toPath()).filter(path -> !path.equals(input.toPath()) && path.toFile().isFile() && !TextileBackup.config.fileBlacklist.contains(path.toString().substring(rootPathLength))).forEach(path -> {
|
||||||
|
try{
|
||||||
|
File file = path.toAbsolutePath().toFile();
|
||||||
|
|
||||||
|
ZipEntry entry = new ZipEntry(file.getAbsolutePath().substring(rootPathLength));
|
||||||
|
arc.putNextEntry(entry);
|
||||||
|
entry.setSize(file.length());
|
||||||
|
IOUtils.copy(new FileInputStream(file), arc);
|
||||||
|
arc.closeEntry();
|
||||||
|
}catch (IOException e){
|
||||||
|
TextileBackup.logger.error(e.getMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
TextileBackup.logger.error(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
Utilities.log("Compression finished", ctx);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user