commit
						231af19958
					
				|  | @ -2,13 +2,13 @@ | |||
| org.gradle.jvmargs=-Xmx1G | ||||
| 
 | ||||
| minecraft_version=1.16.3 | ||||
| yarn_mappings=1.16.3+build.7 | ||||
| loader_version=0.9.3+build.207 | ||||
| yarn_mappings=1.16.3+build.47 | ||||
| loader_version=0.10.5+build.213 | ||||
| 
 | ||||
| #Fabric api | ||||
| fabric_version=0.20.2+build.402-1.16 | ||||
| fabric_version=0.24.3+build.414-1.16 | ||||
| 
 | ||||
| # Mod Properties | ||||
| mod_version = 2.0.1 | ||||
| mod_version = 2.0.2 | ||||
| maven_group = net.szum123321 | ||||
| archives_base_name = textile_backup | ||||
|  | @ -42,13 +42,13 @@ public class ConfigHandler { | |||
|     @Comment("\nShould backup be made on server shutdown?\n") | ||||
|     public boolean shutdownBackup = true; | ||||
| 
 | ||||
|     @Comment("\nShould old world be backed-up?\n") | ||||
|     @Comment("\nShould world be backed up before restoring a backup?\n") | ||||
|     public boolean backupOldWorlds = true; | ||||
| 
 | ||||
|     @Comment("\nShould every world has its won backup folder?\n") | ||||
|     @Comment("\nShould every world have its own backup folder?\n") | ||||
|     public boolean perWorldBackup = true; | ||||
| 
 | ||||
|     @Comment("\nA path to backup folder\n") | ||||
|     @Comment("\nA path to the backup folder\n") | ||||
|     public String path = "backup/"; | ||||
| 
 | ||||
|     @Comment("\nThis setting allows you to exclude files form being backedup.\n"+ | ||||
|  |  | |||
|  | @ -19,6 +19,7 @@ | |||
| package net.szum123321.textile_backup.core; | ||||
| 
 | ||||
| import net.minecraft.server.MinecraftServer; | ||||
| import net.minecraft.server.world.ServerWorld; | ||||
| import net.minecraft.util.registry.Registry; | ||||
| import net.minecraft.util.registry.RegistryKey; | ||||
| import net.minecraft.world.dimension.DimensionType; | ||||
|  | @ -49,6 +50,22 @@ public class Utilities { | |||
| 				.getWorldDirectory(RegistryKey.of(Registry.DIMENSION, DimensionType.OVERWORLD_REGISTRY_KEY.getValue())); | ||||
| 	} | ||||
| 
 | ||||
| 	public static void disableWorldSaving(MinecraftServer server) { | ||||
| 		for (ServerWorld serverWorld : server.getWorlds()) { | ||||
| 			if (serverWorld != null && !serverWorld.savingDisabled) { | ||||
| 				serverWorld.savingDisabled = true; | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	public static void enableWorldSaving(MinecraftServer server) { | ||||
| 		for (ServerWorld serverWorld : server.getWorlds()) { | ||||
| 			if (serverWorld != null && serverWorld.savingDisabled) { | ||||
| 				serverWorld.savingDisabled = false; | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	public static boolean isWindows() { | ||||
| 		return System.getProperty("os.name").toLowerCase().contains("win"); | ||||
| 	} | ||||
|  |  | |||
|  | @ -53,7 +53,10 @@ public class BackupHelper { | |||
| 		if (ctx.shouldSave()) { | ||||
| 			Statics.LOGGER.sendInfo(ctx.getCommandSource(), "Saving server..."); | ||||
| 			Statics.LOGGER.info( "Saving server..."); | ||||
| 			ctx.getServer().save(true, true, false); | ||||
| 
 | ||||
| 			ctx.getServer().save(true, true, true); | ||||
| 
 | ||||
| 			Utilities.disableWorldSaving(ctx.getServer()); | ||||
| 		} | ||||
| 
 | ||||
| 		return new MakeBackupRunnable(ctx); | ||||
|  |  | |||
|  | @ -35,71 +35,75 @@ public class MakeBackupRunnable implements Runnable { | |||
| 
 | ||||
|     @Override | ||||
|     public void run() { | ||||
|         Statics.LOGGER.sendInfo(context.getCommandSource(), "Starting backup"); | ||||
|         Statics.LOGGER.info("Starting backup"); | ||||
| 
 | ||||
|         File world = Utilities.getWorldFolder(context.getServer()); | ||||
| 
 | ||||
|         Statics.LOGGER.trace("Minecraft world is: {}", world); | ||||
| 
 | ||||
|         File outFile = Utilities | ||||
|                 .getBackupRootPath(Utilities.getLevelName(context.getServer())) | ||||
|                 .toPath() | ||||
|                 .resolve(getFileName()) | ||||
|                 .toFile(); | ||||
| 
 | ||||
|         Statics.LOGGER.trace("Outfile is: {}", outFile); | ||||
| 
 | ||||
|         outFile.getParentFile().mkdirs(); | ||||
| 
 | ||||
|         try { | ||||
|             outFile.createNewFile(); | ||||
|         } catch (IOException e) { | ||||
|             Statics.LOGGER.error("An exception occurred when trying to create new backup file!", e); | ||||
|             Statics.LOGGER.sendError(context.getCommandSource(), "An exception occurred when trying to create new backup file!"); | ||||
|             Statics.LOGGER.sendInfo(context.getCommandSource(), "Starting backup"); | ||||
|             Statics.LOGGER.info("Starting backup"); | ||||
| 
 | ||||
|             return; | ||||
|             File world = Utilities.getWorldFolder(context.getServer()); | ||||
| 
 | ||||
|             Statics.LOGGER.trace("Minecraft world is: {}", world); | ||||
| 
 | ||||
|             File outFile = Utilities | ||||
|                     .getBackupRootPath(Utilities.getLevelName(context.getServer())) | ||||
|                     .toPath() | ||||
|                     .resolve(getFileName()) | ||||
|                     .toFile(); | ||||
| 
 | ||||
|             Statics.LOGGER.trace("Outfile is: {}", outFile); | ||||
| 
 | ||||
|             outFile.getParentFile().mkdirs(); | ||||
| 
 | ||||
|             try { | ||||
|                 outFile.createNewFile(); | ||||
|             } catch (IOException e) { | ||||
|                 Statics.LOGGER.error("An exception occurred when trying to create new backup file!", e); | ||||
|                 Statics.LOGGER.sendError(context.getCommandSource(), "An exception occurred when trying to create new backup file!"); | ||||
| 
 | ||||
|                 return; | ||||
|             } | ||||
| 
 | ||||
|             int coreCount; | ||||
| 
 | ||||
|             if(Statics.CONFIG.compressionCoreCountLimit <= 0) { | ||||
|                 coreCount = Runtime.getRuntime().availableProcessors(); | ||||
|             } else { | ||||
|                 coreCount = Math.min(Statics.CONFIG.compressionCoreCountLimit, Runtime.getRuntime().availableProcessors()); | ||||
|             } | ||||
| 
 | ||||
|             Statics.LOGGER.trace("Running compression on {} threads. Available cores = {}", coreCount, Runtime.getRuntime().availableProcessors()); | ||||
| 
 | ||||
|             switch (Statics.CONFIG.format) { | ||||
|                 case ZIP: | ||||
|                     ParallelZipCompressor.createArchive(world, outFile, context, coreCount); | ||||
|                     break; | ||||
| 
 | ||||
|                 case BZIP2: | ||||
|                     ParallelBZip2Compressor.getInstance().createArchive(world, outFile, context, coreCount); | ||||
|                     break; | ||||
| 
 | ||||
|                 case GZIP: | ||||
|                     ParallelGzipCompressor.getInstance().createArchive(world, outFile, context, coreCount); | ||||
|                     break; | ||||
| 
 | ||||
|                 case LZMA: | ||||
|                     LZMACompressor.getInstance().createArchive(world, outFile, context, coreCount); | ||||
|                     break; | ||||
| 
 | ||||
|                 default: | ||||
|                     Statics.LOGGER.warn("Specified compressor ({}) is not supported! Zip will be used instead!", Statics.CONFIG.format); | ||||
|                     Statics.LOGGER.sendError(context.getCommandSource(), "Error! No correct compression format specified! Using default compressor!"); | ||||
| 
 | ||||
|                     ParallelZipCompressor.createArchive(world, outFile, context, coreCount); | ||||
|                     break; | ||||
|             } | ||||
| 
 | ||||
|             BackupHelper.executeFileLimit(context.getCommandSource(), Utilities.getLevelName(context.getServer())); | ||||
| 
 | ||||
|             Statics.LOGGER.sendInfo(context, "Done!"); | ||||
|             Statics.LOGGER.info("Done!"); | ||||
|         } finally { | ||||
|             Utilities.enableWorldSaving(context.getServer()); | ||||
|         } | ||||
| 
 | ||||
|         int coreCount; | ||||
| 
 | ||||
|         if(Statics.CONFIG.compressionCoreCountLimit <= 0) { | ||||
|             coreCount = Runtime.getRuntime().availableProcessors(); | ||||
|         } else { | ||||
|             coreCount = Math.min(Statics.CONFIG.compressionCoreCountLimit, Runtime.getRuntime().availableProcessors()); | ||||
|         } | ||||
| 
 | ||||
|         Statics.LOGGER.trace("Running compression on {} threads. Available cores = {}", coreCount, Runtime.getRuntime().availableProcessors()); | ||||
| 
 | ||||
|         switch (Statics.CONFIG.format) { | ||||
|             case ZIP: | ||||
|                 ParallelZipCompressor.createArchive(world, outFile, context, coreCount); | ||||
|                 break; | ||||
| 
 | ||||
|             case BZIP2: | ||||
|                 ParallelBZip2Compressor.getInstance().createArchive(world, outFile, context, coreCount); | ||||
|                 break; | ||||
| 
 | ||||
|             case GZIP: | ||||
|                 ParallelGzipCompressor.getInstance().createArchive(world, outFile, context, coreCount); | ||||
|                 break; | ||||
| 
 | ||||
|             case LZMA: | ||||
|                 LZMACompressor.getInstance().createArchive(world, outFile, context, coreCount); | ||||
|                 break; | ||||
| 
 | ||||
|             default: | ||||
|                 Statics.LOGGER.warn("Specified compressor ({}) is not supported! Zip will be used instead!", Statics.CONFIG.format); | ||||
|                 Statics.LOGGER.sendError(context.getCommandSource(), "Error! No correct compression format specified! Using default compressor!"); | ||||
| 
 | ||||
|                 ParallelZipCompressor.createArchive(world, outFile, context, coreCount); | ||||
|                 break; | ||||
|         } | ||||
| 
 | ||||
|         BackupHelper.executeFileLimit(context.getCommandSource(), Utilities.getLevelName(context.getServer())); | ||||
| 
 | ||||
|         Statics.LOGGER.sendInfo(context, "Done!"); | ||||
|         Statics.LOGGER.info("Done!"); | ||||
|     } | ||||
| 
 | ||||
|     private String getFileName(){ | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue