Added option to not backup files.

This commit is contained in:
Szum123321 2020-04-03 11:26:14 +02:00
parent 7611784d86
commit 1cb2898173
5 changed files with 25 additions and 19 deletions

View File

@ -38,6 +38,10 @@ public class ConfigHandler {
@Comment("\nA path to backup folder\n")
public String path = "backup/";
@Comment("\nThis setting allows you to exclude files form being backuped.\n"+
"Be very careful when setting it, as it is easy to make your backuped world unusable!\n")
public Set<String> fileBlacklist = new HashSet<>();
@Comment("\nShould every world has its won backup folder?\n")
public boolean perWorldBackup = false;
@ -63,10 +67,10 @@ public class ConfigHandler {
public boolean alwaysSingleplayerAllowed = true;
@Comment("\nPlayers allowed to run backup commands without sufficient permission level\n")
public Set<String> whitelist = new HashSet<>();
public Set<String> playerWhitelist = new HashSet<>();
@Comment("\nPlayers banned from running backup commands besides their sufficient permission level\n")
public Set<String> blacklist = new HashSet<>();
public Set<String> playerBlocklist = new HashSet<>();
@Comment("\nFormat of date&time used to name backup files.\n")
public String dateTimeFormat = "dd.MM.yyyy_HH-mm-ss";

View File

@ -52,9 +52,9 @@ public class TextileBackup implements ModInitializer {
LiteralArgumentBuilder.<ServerCommandSource>literal("backup")
.requires((ctx) -> {
try {
return ((config.whitelist.contains(ctx.getEntityOrThrow().getEntityName()) ||
return ((config.playerWhitelist.contains(ctx.getEntityOrThrow().getEntityName()) ||
ctx.hasPermissionLevel(config.permissionLevel)) &&
!config.blacklist.contains(ctx.getEntityOrThrow().getEntityName())) ||
!config.playerBlocklist.contains(ctx.getEntityOrThrow().getEntityName())) ||
(ctx.getMinecraftServer().isSinglePlayer() &&
config.alwaysSingleplayerAllowed);
}catch (Exception e){ //Command was called from server console.

View File

@ -40,7 +40,7 @@ public class BlacklistCommand {
builder.append("Currently on the blacklist are: ");
for(String name : TextileBackup.config.blacklist){
for(String name : TextileBackup.config.playerBlocklist){
builder.append(name);
builder.append(", ");
}
@ -53,10 +53,10 @@ public class BlacklistCommand {
private static int executeAdd(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
if(TextileBackup.config.blacklist.contains(player.getEntityName())) {
if(TextileBackup.config.playerBlocklist.contains(player.getEntityName())) {
ctx.getSource().sendFeedback(new TranslatableText("Player: %s is already blacklisted.", player.getEntityName()), false);
}else{
TextileBackup.config.blacklist.add(player.getEntityName());
TextileBackup.config.playerBlocklist.add(player.getEntityName());
ConfigManager.saveConfig(TextileBackup.config);
StringBuilder builder = new StringBuilder();
@ -65,8 +65,8 @@ public class BlacklistCommand {
builder.append(player.getEntityName());
builder.append(" added to the blacklist");
if(TextileBackup.config.whitelist.contains(player.getEntityName())){
TextileBackup.config.whitelist.remove(player.getEntityName());
if(TextileBackup.config.playerWhitelist.contains(player.getEntityName())){
TextileBackup.config.playerWhitelist.remove(player.getEntityName());
builder.append(" and removed form the whitelist");
}
@ -81,10 +81,10 @@ public class BlacklistCommand {
private static int executeRemove(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
if(!TextileBackup.config.blacklist.contains(player.getEntityName())) {
if(!TextileBackup.config.playerBlocklist.contains(player.getEntityName())) {
ctx.getSource().sendFeedback(new TranslatableText("Player: %s newer was blacklisted.", player.getEntityName()), false);
}else{
TextileBackup.config.blacklist.remove(player.getEntityName());
TextileBackup.config.playerBlocklist.remove(player.getEntityName());
ConfigManager.saveConfig(TextileBackup.config);
StringBuilder builder = new StringBuilder();

View File

@ -40,7 +40,7 @@ public class WhitelistCommand {
builder.append("Currently on the whitelist are: ");
for(String name : TextileBackup.config.whitelist){
for(String name : TextileBackup.config.playerWhitelist){
builder.append(name);
builder.append(", ");
}
@ -53,10 +53,10 @@ public class WhitelistCommand {
private static int executeAdd(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
if(TextileBackup.config.whitelist.contains(player.getEntityName())) {
if(TextileBackup.config.playerWhitelist.contains(player.getEntityName())) {
ctx.getSource().sendFeedback(new TranslatableText("Player: %s is already whitelisted.", player.getEntityName()), false);
}else{
TextileBackup.config.whitelist.add(player.getEntityName());
TextileBackup.config.playerWhitelist.add(player.getEntityName());
ConfigManager.saveConfig(TextileBackup.config);
StringBuilder builder = new StringBuilder();
@ -65,8 +65,8 @@ public class WhitelistCommand {
builder.append(player.getEntityName());
builder.append(" added to the whitelist");
if(TextileBackup.config.blacklist.contains(player.getEntityName())){
TextileBackup.config.blacklist.remove(player.getEntityName());
if(TextileBackup.config.playerBlocklist.contains(player.getEntityName())){
TextileBackup.config.playerBlocklist.remove(player.getEntityName());
builder.append(" and removed form the blacklist");
}
@ -81,10 +81,10 @@ public class WhitelistCommand {
private static int executeRemove(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
if(!TextileBackup.config.whitelist.contains(player.getEntityName())) {
if(!TextileBackup.config.playerWhitelist.contains(player.getEntityName())) {
ctx.getSource().sendFeedback(new TranslatableText("Player: %s newer was on the whitelist.", player.getEntityName()), false);
}else{
TextileBackup.config.whitelist.remove(player.getEntityName());
TextileBackup.config.playerWhitelist.remove(player.getEntityName());
ConfigManager.saveConfig(TextileBackup.config);
StringBuilder builder = new StringBuilder();

View File

@ -27,6 +27,7 @@ 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;
@ -40,10 +41,11 @@ public class Compressor {
ZipOutputStream arc = new ZipOutputStream(new FileOutputStream(out));
arc.setLevel(TextileBackup.config.compression);
arc.setComment("Created on: " + Utilities.getDateTimeFormatter().format(LocalDateTime.now()));
int rootPathLength = input.toString().length() + 1;
Files.walk(input.toPath()).filter(path -> !path.equals(input.toPath()) && path.toFile().isFile()).forEach(path -> {
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();