diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..26d33521 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 00000000..cdefd2b7 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 00000000..aa00ffab --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 00000000..f44ba7b0 --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..6546f14f --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..09a0aa93 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..35eb1ddf --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ServerBackup.iml b/ServerBackup.iml new file mode 100644 index 00000000..a589521a --- /dev/null +++ b/ServerBackup.iml @@ -0,0 +1,13 @@ + + + + + + + SPIGOT + + 1 + + + + \ No newline at end of file diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml new file mode 100644 index 00000000..a79fe027 --- /dev/null +++ b/dependency-reduced-pom.xml @@ -0,0 +1,56 @@ + + + 4.0.0 + de.seblii.serverbackup + ServerBackup + 2.10.1 + + + + true + src/main/resources + + + + + maven-shade-plugin + 3.4.0 + + + package + + shade + + + + + + + org.bstats + de.seblii.serverbackup + + + + + + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + org.spigotmc + spigot-api + 1.20.1-R0.1-SNAPSHOT + provided + + + + 16 + 16 + UTF-8 + + diff --git a/pom.xml b/pom.xml index 985fb9f2..17424a2d 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ de.seblii.serverbackup ServerBackup - 2.9.7 + 2.10.1 16 diff --git a/src/net/server_backup/Configuration.java b/src/main/java/net/server_backup/Configuration.java similarity index 97% rename from src/net/server_backup/Configuration.java rename to src/main/java/net/server_backup/Configuration.java index e91ed4a8..0584c364 100644 --- a/src/net/server_backup/Configuration.java +++ b/src/main/java/net/server_backup/Configuration.java @@ -1,231 +1,232 @@ -package net.server_backup; - -import net.server_backup.core.OperationHandler; -import org.bukkit.command.CommandSender; -import org.bukkit.configuration.file.YamlConfiguration; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; - -public class Configuration { - - public static String prefix; - public static String backupDestination = "Backups//"; - - private static File bpInf = new File("plugins//ServerBackup//backupInfo.yml"); - public static YamlConfiguration backupInfo = YamlConfiguration.loadConfiguration(bpInf); - - private static File cloudInf = new File("plugins//ServerBackup//cloudAccess.yml"); - public static YamlConfiguration cloudInfo = YamlConfiguration.loadConfiguration(cloudInf); - - private static File messagesFile = new File("plugins//ServerBackup//messages.yml"); - public static YamlConfiguration messages = YamlConfiguration.loadConfiguration(messagesFile); - - public static void loadUp() { - loadConfig(); - loadCloud(); - loadBackupInfo(); - loadMessages(); - } - - public static void loadConfig() { - if (ServerBackup.getInstance().getConfig().contains("BackupDestination")) { - backupDestination = ServerBackup.getInstance().getConfig().getString("BackupDestination"); - } - - if (!Files.exists(Paths.get(backupDestination))) { - try { - Files.createDirectories(Paths.get(backupDestination)); - } catch (IOException e) { - e.printStackTrace(); - } - } - - File files = new File(backupDestination + "//Files"); - - if (!files.exists()) { - files.mkdir(); - } - - ServerBackup.getInstance().getConfig().options() - .header("BackupTimer = At what time should a Backup be created? The format is: 'hh-mm' e.g. '12-30'." - + "\nDeleteOldBackups = Deletes old backups automatically after a specific time (in days, standard = 7 days)" - + "\nDeleteOldBackups - Type '0' at DeleteOldBackups to disable the deletion of old backups." - + "\nBackupLimiter = Deletes old backups automatically if number of total backups is greater than this number (e.g. if you enter '5' - the oldest backup will be deleted if there are more than 5 backups, so you will always keep the latest 5 backups)" - + "\nBackupLimiter - Type '0' to disable this feature. If you don't type '0' the feature 'DeleteOldBackups' will be disabled and this feature ('BackupLimiter') will be enabled." - + "\nKeepUniqueBackups - Type 'true' to disable the deletion of unique backups. The plugin will keep the newest backup of all backed up worlds or folders, no matter how old it is." - + "\nBlacklist - A list of files/directories that will not be backed up." - + "\nIMPORTANT FTP information: Set 'UploadBackup' to 'true' if you want to store your backups on a ftp server (sftp does not work at the moment - if you host your own server (e.g. vps/root server) you need to set up a ftp server on it)." - + "\nIf you use ftp backups, you can set 'DeleteLocalBackup' to 'true' if you want the plugin to remove the created backup from your server once it has been uploaded to your ftp server." - + "\nCompressBeforeUpload compresses the backup to a zip file before uploading it. Set it to 'false' if you want the files to be uploaded directly to your ftp server." - + "\nJoin the discord server if you need help or have a question: https://discord.gg/rNzngsCWFC"); - ServerBackup.getInstance().getConfig().options().copyDefaults(true); - - ServerBackup.getInstance().getConfig().addDefault("AutomaticBackups", true); - ServerBackup.getInstance().getConfig().addDefault("CommandAfterAutomaticBackup", "/"); - - List days = new ArrayList<>(); - days.add("MONDAY"); - days.add("TUESDAY"); - days.add("WEDNESDAY"); - days.add("THURSDAY"); - days.add("FRIDAY"); - days.add("SATURDAY"); - days.add("SUNDAY"); - - List times = new ArrayList<>(); - times.add("00-00"); - - ServerBackup.getInstance().getConfig().addDefault("BackupTimer.Days", days); - ServerBackup.getInstance().getConfig().addDefault("BackupTimer.Times", times); - - List worlds = new ArrayList<>(); - worlds.add("world"); - worlds.add("world_nether"); - worlds.add("world_the_end"); - - ServerBackup.getInstance().getConfig().addDefault("BackupWorlds", worlds); - - List blacklist = new ArrayList<>(); - blacklist.add("libraries"); - blacklist.add("plugins/ServerBackup/config.yml"); - - ServerBackup.getInstance().getConfig().addDefault("Blacklist", blacklist); - - ServerBackup.getInstance().getConfig().addDefault("DeleteOldBackups", 14); - ServerBackup.getInstance().getConfig().addDefault("BackupLimiter", 0); - - ServerBackup.getInstance().getConfig().addDefault("KeepUniqueBackups", false); - - ServerBackup.getInstance().getConfig().addDefault("UpdateAvailableMessage", true); - ServerBackup.getInstance().getConfig().addDefault("AutomaticUpdates", true); - - ServerBackup.getInstance().getConfig().addDefault("BackupDestination", "Backups//"); - - ServerBackup.getInstance().getConfig().addDefault("CloudBackup.Dropbox", false); - ServerBackup.getInstance().getConfig().addDefault("CloudBackup.Options.Destination", "/"); - ServerBackup.getInstance().getConfig().addDefault("CloudBackup.Options.DeleteLocalBackup", false); - - ServerBackup.getInstance().getConfig().addDefault("Ftp.UploadBackup", false); - ServerBackup.getInstance().getConfig().addDefault("Ftp.DeleteLocalBackup", false); - ServerBackup.getInstance().getConfig().addDefault("Ftp.Server.IP", "127.0.0.1"); - ServerBackup.getInstance().getConfig().addDefault("Ftp.Server.Port", 21); - ServerBackup.getInstance().getConfig().addDefault("Ftp.Server.User", "username"); - ServerBackup.getInstance().getConfig().addDefault("Ftp.Server.Password", "password"); - ServerBackup.getInstance().getConfig().addDefault("Ftp.Server.BackupDirectory", "Backups/"); - - ServerBackup.getInstance().getConfig().addDefault("DynamicBackup", false); - ServerBackup.getInstance().getConfig().addDefault("SendLogMessages", false); - - ServerBackup.getInstance().saveConfig(); - - backupDestination = ServerBackup.getInstance().getConfig().getString("BackupDestination"); - } - - public static void loadCloud() { - if (!cloudInf.exists()) { - try { - cloudInf.createNewFile(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - cloudInfo.options().header("Dropbox - Watch this video for explanation: https://youtu.be/k-0aIohxRUA"); - - if (!cloudInfo.contains("Cloud.Dropbox")) { - cloudInfo.set("Cloud.Dropbox.AppKey", "appKey"); - cloudInfo.set("Cloud.Dropbox.AppSecret", "appSecret"); - } else { - if (cloudInfo.getString("Cloud.Dropbox.AppKey") != "appKey" && !cloudInfo.contains("Cloud.Dropbox.ActivationLink")) { - cloudInfo.set("Cloud.Dropbox.ActivationLink", "https://www.dropbox.com/oauth2/authorize?client_id=" + cloudInfo.getString("Cloud.Dropbox.AppKey") + "&response_type=code&token_access_type=offline"); - if (!cloudInfo.contains("Cloud.Dropbox.AccessToken")) { - cloudInfo.set("Cloud.Dropbox.AccessToken", "accessToken"); - } - } - } - - saveCloud(); - } - - public static void saveCloud() { - try { - cloudInfo.save(cloudInf); - } catch (IOException e) { - e.printStackTrace(); - } - } - - public static void loadBackupInfo() { - if (!bpInf.exists()) { - try { - bpInf.createNewFile(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - saveBackupInfo(); - } - - public static void loadMessages() { - if (!messagesFile.exists()) { - try { - messagesFile.createNewFile(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - Messages.loadMessages(); - } - - public static void saveBackupInfo() { - try { - backupInfo.save(bpInf); - } catch (IOException e) { - e.printStackTrace(); - } - } - - public static void saveMessages() { - try { - messages.save(messagesFile); - } catch (IOException e) { - e.printStackTrace(); - } - } - - public static void reloadConfig(CommandSender sender) { - ServerBackup.getInstance().reloadConfig(); - - OperationHandler.stopTimer(); - OperationHandler.startTimer(); - - String oldDes = backupDestination; - - if (!oldDes - .equalsIgnoreCase(ServerBackup.getInstance().getConfig().getString("BackupDestination"))) { - backupDestination = ServerBackup.getInstance().getConfig() - .getString("BackupDestination"); - - ServerBackup.getInstance().getLogger().log(Level.INFO, - "ServerBackup: Backup destination [" + oldDes + " >> " - + backupDestination + "] updated successfully."); - } - - if (cloudInf.exists()) { - saveCloud(); - } - - loadUp(); - - sender.sendMessage(OperationHandler.processMessage("Command.Reload")); - } - -} +package net.server_backup; + +import net.server_backup.core.OperationHandler; +import org.bukkit.command.CommandSender; +import org.bukkit.configuration.file.YamlConfiguration; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; + +public class Configuration { + + public static String prefix; + public static String backupDestination = "Backups//"; + + private static File bpInf = new File("plugins//ServerBackup//backupInfo.yml"); + public static YamlConfiguration backupInfo = YamlConfiguration.loadConfiguration(bpInf); + + private static File cloudInf = new File("plugins//ServerBackup//cloudAccess.yml"); + public static YamlConfiguration cloudInfo = YamlConfiguration.loadConfiguration(cloudInf); + + private static File messagesFile = new File("plugins//ServerBackup//messages.yml"); + public static YamlConfiguration messages = YamlConfiguration.loadConfiguration(messagesFile); + + public static void loadUp() { + loadConfig(); + loadCloud(); + loadBackupInfo(); + loadMessages(); + } + + public static void loadConfig() { + if (ServerBackup.getInstance().getConfig().contains("BackupDestination")) { + backupDestination = ServerBackup.getInstance().getConfig().getString("BackupDestination"); + } + + if (!Files.exists(Paths.get(backupDestination))) { + try { + Files.createDirectories(Paths.get(backupDestination)); + } catch (IOException e) { + e.printStackTrace(); + } + } + + File files = new File(backupDestination + "//Files"); + + if (!files.exists()) { + files.mkdir(); + } + + ServerBackup.getInstance().getConfig().options() + .header("BackupTimer = At what time should a Backup be created? The format is: 'hh-mm' e.g. '12-30'." + + "\nDeleteOldBackups = Deletes old backups automatically after a specific time (in days, standard = 7 days)" + + "\nDeleteOldBackups - Type '0' at DeleteOldBackups to disable the deletion of old backups." + + "\nBackupLimiter = Deletes old backups automatically if number of total backups is greater than this number (e.g. if you enter '5' - the oldest backup will be deleted if there are more than 5 backups, so you will always keep the latest 5 backups)" + + "\nBackupLimiter - Type '0' to disable this feature. If you don't type '0' the feature 'DeleteOldBackups' will be disabled and this feature ('BackupLimiter') will be enabled." + + "\nKeepUniqueBackups - Type 'true' to disable the deletion of unique backups. The plugin will keep the newest backup of all backed up worlds or folders, no matter how old it is." + + "\nBlacklist - A list of files/directories that will not be backed up." + + "\nIMPORTANT FTP information: Set 'UploadBackup' to 'true' if you want to store your backups on a ftp server (sftp does not work at the moment - if you host your own server (e.g. vps/root server) you need to set up a ftp server on it)." + + "\nIf you use ftp backups, you can set 'DeleteLocalBackup' to 'true' if you want the plugin to remove the created backup from your server once it has been uploaded to your ftp server." + + "\nCompressBeforeUpload compresses the backup to a zip file before uploading it. Set it to 'false' if you want the files to be uploaded directly to your ftp server." + + "\nJoin the discord server if you need help or have a question: https://discord.gg/rNzngsCWFC"); + ServerBackup.getInstance().getConfig().options().copyDefaults(true); + + ServerBackup.getInstance().getConfig().addDefault("AutomaticBackups", true); + ServerBackup.getInstance().getConfig().addDefault("CommandAfterAutomaticBackup", "/"); + + List days = new ArrayList<>(); + days.add("MONDAY"); + days.add("TUESDAY"); + days.add("WEDNESDAY"); + days.add("THURSDAY"); + days.add("FRIDAY"); + days.add("SATURDAY"); + days.add("SUNDAY"); + + List times = new ArrayList<>(); + times.add("00-00"); + + ServerBackup.getInstance().getConfig().addDefault("BackupTimer.Days", days); + ServerBackup.getInstance().getConfig().addDefault("BackupTimer.Times", times); + + List worlds = new ArrayList<>(); + worlds.add("world"); + worlds.add("world_nether"); + worlds.add("world_the_end"); + + ServerBackup.getInstance().getConfig().addDefault("BackupWorlds", worlds); + + List blacklist = new ArrayList<>(); + blacklist.add("libraries"); + blacklist.add("plugins/ServerBackup/config.yml"); + + ServerBackup.getInstance().getConfig().addDefault("Blacklist", blacklist); + + ServerBackup.getInstance().getConfig().addDefault("DeleteOldBackups", 14); + ServerBackup.getInstance().getConfig().addDefault("BackupLimiter", 0); + + ServerBackup.getInstance().getConfig().addDefault("KeepUniqueBackups", false); + + ServerBackup.getInstance().getConfig().addDefault("UpdateAvailableMessage", true); + ServerBackup.getInstance().getConfig().addDefault("AutomaticUpdates", true); + + ServerBackup.getInstance().getConfig().addDefault("BackupDestination", "Backups//"); + + ServerBackup.getInstance().getConfig().addDefault("CloudBackup.Dropbox", false); + ServerBackup.getInstance().getConfig().addDefault("CloudBackup.Options.Destination", "/"); + ServerBackup.getInstance().getConfig().addDefault("CloudBackup.Options.DeleteLocalBackup", false); + + ServerBackup.getInstance().getConfig().addDefault("Ftp.UploadBackup", false); + ServerBackup.getInstance().getConfig().addDefault("Ftp.DeleteLocalBackup", false); + ServerBackup.getInstance().getConfig().addDefault("Ftp.Server.IP", "127.0.0.1"); + ServerBackup.getInstance().getConfig().addDefault("Ftp.Server.Port", 21); + ServerBackup.getInstance().getConfig().addDefault("Ftp.Server.User", "username"); + ServerBackup.getInstance().getConfig().addDefault("Ftp.Server.Password", "password"); + ServerBackup.getInstance().getConfig().addDefault("Ftp.Server.SSL", false); + ServerBackup.getInstance().getConfig().addDefault("Ftp.Server.BackupDirectory", "Backups/"); + + ServerBackup.getInstance().getConfig().addDefault("DynamicBackup", false); + ServerBackup.getInstance().getConfig().addDefault("SendLogMessages", false); + + ServerBackup.getInstance().saveConfig(); + + backupDestination = ServerBackup.getInstance().getConfig().getString("BackupDestination"); + } + + public static void loadCloud() { + if (!cloudInf.exists()) { + try { + cloudInf.createNewFile(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + cloudInfo.options().header("Dropbox - Watch this video for explanation: https://youtu.be/k-0aIohxRUA"); + + if (!cloudInfo.contains("Cloud.Dropbox")) { + cloudInfo.set("Cloud.Dropbox.AppKey", "appKey"); + cloudInfo.set("Cloud.Dropbox.AppSecret", "appSecret"); + } else { + if (cloudInfo.getString("Cloud.Dropbox.AppKey") != "appKey" && !cloudInfo.contains("Cloud.Dropbox.ActivationLink")) { + cloudInfo.set("Cloud.Dropbox.ActivationLink", "https://www.dropbox.com/oauth2/authorize?client_id=" + cloudInfo.getString("Cloud.Dropbox.AppKey") + "&response_type=code&token_access_type=offline"); + if (!cloudInfo.contains("Cloud.Dropbox.AccessToken")) { + cloudInfo.set("Cloud.Dropbox.AccessToken", "accessToken"); + } + } + } + + saveCloud(); + } + + public static void saveCloud() { + try { + cloudInfo.save(cloudInf); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void loadBackupInfo() { + if (!bpInf.exists()) { + try { + bpInf.createNewFile(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + saveBackupInfo(); + } + + public static void loadMessages() { + if (!messagesFile.exists()) { + try { + messagesFile.createNewFile(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + Messages.loadMessages(); + } + + public static void saveBackupInfo() { + try { + backupInfo.save(bpInf); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void saveMessages() { + try { + messages.save(messagesFile); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void reloadConfig(CommandSender sender) { + ServerBackup.getInstance().reloadConfig(); + + OperationHandler.stopTimer(); + OperationHandler.startTimer(); + + String oldDes = backupDestination; + + if (!oldDes + .equalsIgnoreCase(ServerBackup.getInstance().getConfig().getString("BackupDestination"))) { + backupDestination = ServerBackup.getInstance().getConfig() + .getString("BackupDestination"); + + ServerBackup.getInstance().getLogger().log(Level.INFO, + "ServerBackup: Backup destination [" + oldDes + " >> " + + backupDestination + "] updated successfully."); + } + + if (cloudInf.exists()) { + saveCloud(); + } + + loadUp(); + + sender.sendMessage(OperationHandler.processMessage("Command.Reload")); + } + +} diff --git a/src/net/server_backup/Messages.java b/src/main/java/net/server_backup/Messages.java similarity index 98% rename from src/net/server_backup/Messages.java rename to src/main/java/net/server_backup/Messages.java index d8d8aa4f..993d28c8 100644 --- a/src/net/server_backup/Messages.java +++ b/src/main/java/net/server_backup/Messages.java @@ -1,67 +1,67 @@ -package net.server_backup; - -import org.bukkit.configuration.file.YamlConfiguration; - -import java.io.IOException; - -public class Messages { - - private static YamlConfiguration messages = Configuration.messages; - - public static void loadMessages() { - messages.options().header("Use '&nl' to add a new line. Use '&' for color codes (e.g. '&4' for color red). For some messages you can use a placeholder (e.g. '%file%' for file name)." + - "\nMinecraft color codes: https://htmlcolorcodes.com/minecraft-color-codes/"); - messages.options().copyDefaults(true); - - messages.addDefault("Prefix", ""); - - messages.addDefault("Command.Zip.Header", "Zipping Backup..." - + "&nl"); - messages.addDefault("Command.Zip.Footer", "&nl" - + "&nlBackup [%file%] zipped." - + "&nlBackup [%file%] saved."); - messages.addDefault("Command.Unzip.Header", "Unzipping Backup..." - + "&nl"); - messages.addDefault("Command.Unzip.Footer", "&nl" - + "&nlBackup [%file%] unzipped."); - messages.addDefault("Command.Reload", "Config reloaded."); - messages.addDefault("Command.Tasks.Header", "----- Backup tasks -----" - + "&nl"); - messages.addDefault("Command.Tasks.Footer", "&nl" - + "----- Backup tasks -----"); - messages.addDefault("Command.Shutdown.Start", "The server will shut down after backup tasks (check with: '/backup tasks') are finished." - + "&nlYou can cancel the shutdown by running this command again."); - messages.addDefault("Command.Shutdown.Cancel", "Shutdown canceled."); - - messages.addDefault("Info.BackupFinished", "Backup [%file%] saved."); - messages.addDefault("Info.BackupStarted", "Backup [%file%] started."); - messages.addDefault("Info.BackupRemoved", "Backup [%file%] removed."); - messages.addDefault("Info.FtpUpload", "Ftp: Uploading backup [%file%] ..."); - messages.addDefault("Info.FtpUploadSuccess", "Ftp: Upload successfully. Backup stored on ftp server."); - messages.addDefault("Info.FtpDownload", "Ftp: Downloading backup [%file%] ..."); - messages.addDefault("Info.FtpDownloadSuccess", "Ftp: Download successful. Backup downloaded from ftp server."); - - messages.addDefault("Error.NoPermission", "&cI'm sorry but you do not have permission to perform this command."); - messages.addDefault("Error.NoBackups", "No backups found."); - messages.addDefault("Error.NoBackupFound", "No Backup named '%file%' found."); - messages.addDefault("Error.NoBackupSearch", "No backups for search argument '%input%' found."); - messages.addDefault("Error.DeletionFailed", "Error while deleting '%file%'."); - messages.addDefault("Error.FolderExists", "There is already a folder named '%file%'."); - messages.addDefault("Error.ZipExists", "There is already a ZIP file named '%file%.zip'."); - messages.addDefault("Error.NoFtpBackups", "No ftp backups found."); - messages.addDefault("Error.NoTasks", "No backup tasks are running."); - messages.addDefault("Error.AlreadyZip", "%file% is already a ZIP file."); - messages.addDefault("Error.NotAZip", "%file% is not a ZIP file."); - messages.addDefault("Error.NotANumber", "%input% is not a valid number."); - messages.addDefault("Error.BackupFailed", "An error occurred while saving Backup [%file%]. See console for more information."); - messages.addDefault("Error.FtpUploadFailed", "Ftp: Error while uploading backup to ftp server. Check server details in config.yml (ip, port, user, password)."); - messages.addDefault("Error.FtpDownloadFailed", "Ftp: Error while downloading backup to ftp server. Check server details in config.yml (ip, port, user, password)."); - messages.addDefault("Error.FtpLocalDeletionFailed", "Ftp: Local backup deletion failed because the uploaded file was not found on the ftp server. Try again."); - messages.addDefault("Error.FtpNotFound", "Ftp: ftp-backup %file% not found."); - messages.addDefault("Error.FtpConnectionFailed", "Ftp: Error while connecting to FTP server."); - - Configuration.saveMessages(); - - Configuration.prefix = ((messages.getString("Prefix").equals("")) ? messages.getString("Prefix") : (messages.getString("Prefix") + " ")); - } -} +package net.server_backup; + +import org.bukkit.configuration.file.YamlConfiguration; + +import java.io.IOException; + +public class Messages { + + private static YamlConfiguration messages = Configuration.messages; + + public static void loadMessages() { + messages.options().header("Use '&nl' to add a new line. Use '&' for color codes (e.g. '&4' for color red). For some messages you can use a placeholder (e.g. '%file%' for file name)." + + "\nMinecraft color codes: https://htmlcolorcodes.com/minecraft-color-codes/"); + messages.options().copyDefaults(true); + + messages.addDefault("Prefix", ""); + + messages.addDefault("Command.Zip.Header", "Zipping Backup..." + + "&nl"); + messages.addDefault("Command.Zip.Footer", "&nl" + + "&nlBackup [%file%] zipped." + + "&nlBackup [%file%] saved."); + messages.addDefault("Command.Unzip.Header", "Unzipping Backup..." + + "&nl"); + messages.addDefault("Command.Unzip.Footer", "&nl" + + "&nlBackup [%file%] unzipped."); + messages.addDefault("Command.Reload", "Config reloaded."); + messages.addDefault("Command.Tasks.Header", "----- Backup tasks -----" + + "&nl"); + messages.addDefault("Command.Tasks.Footer", "&nl" + + "----- Backup tasks -----"); + messages.addDefault("Command.Shutdown.Start", "The server will shut down after backup tasks (check with: '/backup tasks') are finished." + + "&nlYou can cancel the shutdown by running this command again."); + messages.addDefault("Command.Shutdown.Cancel", "Shutdown canceled."); + + messages.addDefault("Info.BackupFinished", "Backup [%file%] saved."); + messages.addDefault("Info.BackupStarted", "Backup [%file%] started."); + messages.addDefault("Info.BackupRemoved", "Backup [%file%] removed."); + messages.addDefault("Info.FtpUpload", "Ftp: Uploading backup [%file%] ..."); + messages.addDefault("Info.FtpUploadSuccess", "Ftp: Upload successfully. Backup stored on ftp server."); + messages.addDefault("Info.FtpDownload", "Ftp: Downloading backup [%file%] ..."); + messages.addDefault("Info.FtpDownloadSuccess", "Ftp: Download successful. Backup downloaded from ftp server."); + + messages.addDefault("Error.NoPermission", "&cI'm sorry but you do not have permission to perform this command."); + messages.addDefault("Error.NoBackups", "No backups found."); + messages.addDefault("Error.NoBackupFound", "No Backup named '%file%' found."); + messages.addDefault("Error.NoBackupSearch", "No backups for search argument '%input%' found."); + messages.addDefault("Error.DeletionFailed", "Error while deleting '%file%'."); + messages.addDefault("Error.FolderExists", "There is already a folder named '%file%'."); + messages.addDefault("Error.ZipExists", "There is already a ZIP file named '%file%.zip'."); + messages.addDefault("Error.NoFtpBackups", "No ftp backups found."); + messages.addDefault("Error.NoTasks", "No backup tasks are running."); + messages.addDefault("Error.AlreadyZip", "%file% is already a ZIP file."); + messages.addDefault("Error.NotAZip", "%file% is not a ZIP file."); + messages.addDefault("Error.NotANumber", "%input% is not a valid number."); + messages.addDefault("Error.BackupFailed", "An error occurred while saving Backup [%file%]. See console for more information."); + messages.addDefault("Error.FtpUploadFailed", "Ftp: Error while uploading backup to ftp server. Check server details in config.yml (ip, port, user, password)."); + messages.addDefault("Error.FtpDownloadFailed", "Ftp: Error while downloading backup to ftp server. Check server details in config.yml (ip, port, user, password)."); + messages.addDefault("Error.FtpLocalDeletionFailed", "Ftp: Local backup deletion failed because the uploaded file was not found on the ftp server. Try again."); + messages.addDefault("Error.FtpNotFound", "Ftp: ftp-backup %file% not found."); + messages.addDefault("Error.FtpConnectionFailed", "Ftp: Error while connecting to FTP server."); + + Configuration.saveMessages(); + + Configuration.prefix = ((messages.getString("Prefix").equals("")) ? messages.getString("Prefix") : (messages.getString("Prefix") + " ")); + } +} diff --git a/src/net/server_backup/ServerBackup.java b/src/main/java/net/server_backup/ServerBackup.java similarity index 96% rename from src/net/server_backup/ServerBackup.java rename to src/main/java/net/server_backup/ServerBackup.java index 50a8a99a..1996e518 100644 --- a/src/net/server_backup/ServerBackup.java +++ b/src/main/java/net/server_backup/ServerBackup.java @@ -1,60 +1,60 @@ -package net.server_backup; - -import net.server_backup.commands.Executor; -import net.server_backup.commands.TabCompleter; -import net.server_backup.core.DynamicBackup; -import net.server_backup.core.OperationHandler; -import net.server_backup.listeners.JoinListener; -import net.server_backup.utils.BStats; -import org.bukkit.Bukkit; -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.scheduler.BukkitTask; - -import java.util.logging.Level; - -public class ServerBackup extends JavaPlugin { - - private static ServerBackup serverBackup; - - public static ServerBackup getInstance() { - return serverBackup; - } - - @Override - public void onDisable() { - OperationHandler.stopTimer(); - - for (BukkitTask task : Bukkit.getScheduler().getPendingTasks()) { - task.cancel(); - - this.getLogger().log(Level.WARNING, "WARNING - ServerBackup: Task [" + task.getTaskId() - + "] cancelled due to server shutdown. There might be some unfinished Backups."); - } - - Bukkit.getLogger().log(Level.INFO, "ServerBackup: Plugin disabled."); - } - - @Override - public void onEnable() { - serverBackup = this; - - Configuration.loadUp(); - - OperationHandler.startTimer(); - - getCommand("backup").setExecutor(new Executor()); - getCommand("backup").setTabCompleter(new TabCompleter()); - - Bukkit.getPluginManager().registerEvents(new JoinListener(), this); - Bukkit.getPluginManager().registerEvents(new DynamicBackup(), this); - - Bukkit.getLogger().log(Level.INFO, "ServerBackup: Plugin enabled."); - - if (getConfig().getBoolean("UpdateAvailableMessage")) { - OperationHandler.checkVersion(); - } - - BStats.initialize(); - } - -} +package net.server_backup; + +import net.server_backup.commands.Executor; +import net.server_backup.commands.TabCompleter; +import net.server_backup.core.DynamicBackup; +import net.server_backup.core.OperationHandler; +import net.server_backup.listeners.JoinListener; +import net.server_backup.utils.BStats; +import org.bukkit.Bukkit; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitTask; + +import java.util.logging.Level; + +public class ServerBackup extends JavaPlugin { + + private static ServerBackup serverBackup; + + public static ServerBackup getInstance() { + return serverBackup; + } + + @Override + public void onDisable() { + OperationHandler.stopTimer(); + + for (BukkitTask task : Bukkit.getScheduler().getPendingTasks()) { + task.cancel(); + + this.getLogger().log(Level.WARNING, "WARNING - ServerBackup: Task [" + task.getTaskId() + + "] cancelled due to server shutdown. There might be some unfinished Backups."); + } + + Bukkit.getLogger().log(Level.INFO, "ServerBackup: Plugin disabled."); + } + + @Override + public void onEnable() { + serverBackup = this; + + Configuration.loadUp(); + + OperationHandler.startTimer(); + + getCommand("backup").setExecutor(new Executor()); + getCommand("backup").setTabCompleter(new TabCompleter()); + + Bukkit.getPluginManager().registerEvents(new JoinListener(), this); + Bukkit.getPluginManager().registerEvents(new DynamicBackup(), this); + + Bukkit.getLogger().log(Level.INFO, "ServerBackup: Plugin enabled."); + + if (getConfig().getBoolean("UpdateAvailableMessage")) { + OperationHandler.checkVersion(); + } + + BStats.initialize(); + } + +} diff --git a/src/net/server_backup/commands/CommandCreate.java b/src/main/java/net/server_backup/commands/CommandCreate.java similarity index 97% rename from src/net/server_backup/commands/CommandCreate.java rename to src/main/java/net/server_backup/commands/CommandCreate.java index 2f7d8a1b..10ee6233 100644 --- a/src/net/server_backup/commands/CommandCreate.java +++ b/src/main/java/net/server_backup/commands/CommandCreate.java @@ -1,67 +1,67 @@ -package net.server_backup.commands; - -import com.google.common.io.Files; -import net.server_backup.Configuration; -import net.server_backup.ServerBackup; -import net.server_backup.core.Backup; -import net.server_backup.core.OperationHandler; -import org.apache.commons.io.FilenameUtils; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; - -import java.io.File; -import java.io.IOException; - -public class CommandCreate { - - public static void execute(CommandSender sender, String[] args) { - String fileName = args[1]; - - boolean fullBackup = false; - - if (args.length > 2) { - for (int i = 2; i < args.length; i++) { - if (args[i].equalsIgnoreCase("-full")) { - fullBackup = true; - } else { - fileName = fileName + " " + args[i]; - } - } - } - - File file = new File(fileName); - - if (!file.isDirectory() && !args[1].equalsIgnoreCase("@server")) { - Bukkit.getScheduler().runTaskAsynchronously(ServerBackup.getInstance(), new Runnable() { - - @Override - public void run() { - try { - File des = new File(Configuration.backupDestination + "//Files//" - + file.getName().replaceAll("/", "-")); - - if (des.exists()) { - des = new File(des.getPath() - .replaceAll("." + FilenameUtils.getExtension(des.getName()), "") + " " - + String.valueOf(System.currentTimeMillis() / 1000) + "." - + FilenameUtils.getExtension(file.getName())); - } - - Files.copy(file, des); - - sender.sendMessage(OperationHandler.processMessage("Info.BackupFinished").replaceAll("%file%", args[1])); - } catch (IOException e) { - sender.sendMessage(OperationHandler.processMessage("Error.BackupFailed").replaceAll("%file%", args[1])); - e.printStackTrace(); - } - } - - }); - } else { - Backup backup = new Backup(fileName, sender, fullBackup); - - backup.create(); - } - } - -} +package net.server_backup.commands; + +import com.google.common.io.Files; +import net.server_backup.Configuration; +import net.server_backup.ServerBackup; +import net.server_backup.core.Backup; +import net.server_backup.core.OperationHandler; +import org.apache.commons.io.FilenameUtils; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; + +import java.io.File; +import java.io.IOException; + +public class CommandCreate { + + public static void execute(CommandSender sender, String[] args) { + String fileName = args[1]; + + boolean fullBackup = false; + + if (args.length > 2) { + for (int i = 2; i < args.length; i++) { + if (args[i].equalsIgnoreCase("-full")) { + fullBackup = true; + } else { + fileName = fileName + " " + args[i]; + } + } + } + + File file = new File(fileName); + + if (!file.isDirectory() && !args[1].equalsIgnoreCase("@server")) { + Bukkit.getScheduler().runTaskAsynchronously(ServerBackup.getInstance(), new Runnable() { + + @Override + public void run() { + try { + File des = new File(Configuration.backupDestination + "//Files//" + + file.getName().replaceAll("/", "-")); + + if (des.exists()) { + des = new File(des.getPath() + .replaceAll("." + FilenameUtils.getExtension(des.getName()), "") + " " + + String.valueOf(System.currentTimeMillis() / 1000) + "." + + FilenameUtils.getExtension(file.getName())); + } + + Files.copy(file, des); + + sender.sendMessage(OperationHandler.processMessage("Info.BackupFinished").replaceAll("%file%", args[1])); + } catch (IOException e) { + sender.sendMessage(OperationHandler.processMessage("Error.BackupFailed").replaceAll("%file%", args[1])); + e.printStackTrace(); + } + } + + }); + } else { + Backup backup = new Backup(fileName, sender, fullBackup); + + backup.create(); + } + } + +} diff --git a/src/net/server_backup/commands/CommandDropbox.java b/src/main/java/net/server_backup/commands/CommandDropbox.java similarity index 96% rename from src/net/server_backup/commands/CommandDropbox.java rename to src/main/java/net/server_backup/commands/CommandDropbox.java index c0e4c92c..500e9306 100644 --- a/src/net/server_backup/commands/CommandDropbox.java +++ b/src/main/java/net/server_backup/commands/CommandDropbox.java @@ -1,19 +1,19 @@ -package net.server_backup.commands; - -import net.server_backup.ServerBackup; -import net.server_backup.utils.DropboxManager; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; - -public class CommandDropbox { - - public static void execute(CommandSender sender, String[] args) { - if(args[1].equalsIgnoreCase("upload")) { - Bukkit.getScheduler().runTaskAsynchronously(ServerBackup.getInstance(), () -> { - DropboxManager dm = new DropboxManager(sender); - - dm.uploadToDropbox(args[2]); - }); - } - } -} +package net.server_backup.commands; + +import net.server_backup.ServerBackup; +import net.server_backup.utils.DropboxManager; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; + +public class CommandDropbox { + + public static void execute(CommandSender sender, String[] args) { + if(args[1].equalsIgnoreCase("upload")) { + Bukkit.getScheduler().runTaskAsynchronously(ServerBackup.getInstance(), () -> { + DropboxManager dm = new DropboxManager(sender); + + dm.uploadToDropbox(args[2]); + }); + } + } +} diff --git a/src/net/server_backup/commands/CommandFtp.java b/src/main/java/net/server_backup/commands/CommandFtp.java similarity index 97% rename from src/net/server_backup/commands/CommandFtp.java rename to src/main/java/net/server_backup/commands/CommandFtp.java index 82907929..6ef36c31 100644 --- a/src/net/server_backup/commands/CommandFtp.java +++ b/src/main/java/net/server_backup/commands/CommandFtp.java @@ -1,92 +1,92 @@ -package net.server_backup.commands; - -import net.md_5.bungee.api.chat.ClickEvent; -import net.md_5.bungee.api.chat.ComponentBuilder; -import net.md_5.bungee.api.chat.HoverEvent; -import net.md_5.bungee.api.chat.TextComponent; -import net.server_backup.ServerBackup; -import net.server_backup.core.OperationHandler; -import net.server_backup.utils.FtpManager; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import java.util.List; - -public class CommandFtp { - - public static void execute(CommandSender sender, String[] args) { - if (args[1].equalsIgnoreCase("list")) { - Bukkit.getScheduler().runTaskAsynchronously(ServerBackup.getInstance(), () -> { - FtpManager ftpm = new FtpManager(sender); - - List backups = ftpm.getFtpBackupList(false); - - if (backups.size() == 0) { - sender.sendMessage(OperationHandler.processMessage("Error.NoFtpBackups")); - - return; - } - - try { - int page = Integer.valueOf(args[2]); - - if (backups.size() < page * 10 - 9) { - sender.sendMessage("Try a lower value."); - - return; - } - - if (backups.size() <= page * 10 && backups.size() >= page * 10 - 10) { - sender.sendMessage("----- Ftp-Backup " + Integer.valueOf(page * 10 - 9) + "-" - + backups.size() + "/" + backups.size() + " -----"); - } else { - sender.sendMessage("----- Ftp-Backup " + Integer.valueOf(page * 10 - 9) + "-" - + Integer.valueOf(page * 10) + "/" + backups.size() + " -----"); - } - sender.sendMessage(""); - - for (int i = page * 10 - 10; i < backups.size() && i < page * 10; i++) { - if (sender instanceof Player) { - Player p = (Player) sender; - - TextComponent msg = new TextComponent(backups.get(i)); - msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, - new ComponentBuilder("Click to get Backup name").create())); - msg.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, - backups.get(i).split(" ")[1])); - - p.spigot().sendMessage(msg); - } else { - sender.sendMessage(backups.get(i)); - } - } - - int maxPages = backups.size() / 10; - - if (backups.size() % 10 != 0) { - maxPages++; - } - - sender.sendMessage(""); - sender.sendMessage("--------- Page " + page + "/" + maxPages + " ---------"); - } catch (Exception e) { - sender.sendMessage(OperationHandler.processMessage("Error.NotANumber").replaceAll("%input%", args[1])); - } - }); - } else if (args[1].equalsIgnoreCase("download")) { - Bukkit.getScheduler().runTaskAsynchronously(ServerBackup.getInstance(), () -> { - FtpManager ftpm = new FtpManager(sender); - - ftpm.downloadFileFromFtp(args[2]); - }); - } else if (args[1].equalsIgnoreCase("upload")) { - Bukkit.getScheduler().runTaskAsynchronously(ServerBackup.getInstance(), () -> { - FtpManager ftpm = new FtpManager(sender); - - ftpm.uploadFileToFtp(args[2], !ServerBackup.getInstance().getConfig().getBoolean("Ftp.CompressBeforeUpload")); - }); - } - } - -} +package net.server_backup.commands; + +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.ComponentBuilder; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; +import net.server_backup.ServerBackup; +import net.server_backup.core.OperationHandler; +import net.server_backup.utils.FtpManager; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.util.List; + +public class CommandFtp { + + public static void execute(CommandSender sender, String[] args) { + if (args[1].equalsIgnoreCase("list")) { + Bukkit.getScheduler().runTaskAsynchronously(ServerBackup.getInstance(), () -> { + FtpManager ftpm = new FtpManager(sender); + + List backups = ftpm.getFtpBackupList(false); + + if (backups.size() == 0) { + sender.sendMessage(OperationHandler.processMessage("Error.NoFtpBackups")); + + return; + } + + try { + int page = Integer.valueOf(args[2]); + + if (backups.size() < page * 10 - 9) { + sender.sendMessage("Try a lower value."); + + return; + } + + if (backups.size() <= page * 10 && backups.size() >= page * 10 - 10) { + sender.sendMessage("----- Ftp-Backup " + Integer.valueOf(page * 10 - 9) + "-" + + backups.size() + "/" + backups.size() + " -----"); + } else { + sender.sendMessage("----- Ftp-Backup " + Integer.valueOf(page * 10 - 9) + "-" + + Integer.valueOf(page * 10) + "/" + backups.size() + " -----"); + } + sender.sendMessage(""); + + for (int i = page * 10 - 10; i < backups.size() && i < page * 10; i++) { + if (sender instanceof Player) { + Player p = (Player) sender; + + TextComponent msg = new TextComponent(backups.get(i)); + msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, + new ComponentBuilder("Click to get Backup name").create())); + msg.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, + backups.get(i).split(" ")[1])); + + p.spigot().sendMessage(msg); + } else { + sender.sendMessage(backups.get(i)); + } + } + + int maxPages = backups.size() / 10; + + if (backups.size() % 10 != 0) { + maxPages++; + } + + sender.sendMessage(""); + sender.sendMessage("--------- Page " + page + "/" + maxPages + " ---------"); + } catch (Exception e) { + sender.sendMessage(OperationHandler.processMessage("Error.NotANumber").replaceAll("%input%", args[1])); + } + }); + } else if (args[1].equalsIgnoreCase("download")) { + Bukkit.getScheduler().runTaskAsynchronously(ServerBackup.getInstance(), () -> { + FtpManager ftpm = new FtpManager(sender); + + ftpm.downloadFileFromFtp(args[2]); + }); + } else if (args[1].equalsIgnoreCase("upload")) { + Bukkit.getScheduler().runTaskAsynchronously(ServerBackup.getInstance(), () -> { + FtpManager ftpm = new FtpManager(sender); + + ftpm.uploadFileToFtp(args[2], !ServerBackup.getInstance().getConfig().getBoolean("Ftp.CompressBeforeUpload")); + }); + } + } + +} diff --git a/src/net/server_backup/commands/CommandList.java b/src/main/java/net/server_backup/commands/CommandList.java similarity index 97% rename from src/net/server_backup/commands/CommandList.java rename to src/main/java/net/server_backup/commands/CommandList.java index 3e5671d9..9feb0f20 100644 --- a/src/net/server_backup/commands/CommandList.java +++ b/src/main/java/net/server_backup/commands/CommandList.java @@ -1,89 +1,89 @@ -package net.server_backup.commands; - -import net.md_5.bungee.api.chat.ClickEvent; -import net.md_5.bungee.api.chat.ComponentBuilder; -import net.md_5.bungee.api.chat.HoverEvent; -import net.md_5.bungee.api.chat.TextComponent; -import net.server_backup.Configuration; -import net.server_backup.ServerBackup; -import net.server_backup.core.OperationHandler; -import org.apache.commons.io.FileUtils; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import java.io.File; -import java.util.Arrays; - -public class CommandList { - - public static void execute(CommandSender sender, String[] args) { - Bukkit.getScheduler().runTaskAsynchronously(ServerBackup.getInstance(), () -> { - File[] backups = new File(Configuration.backupDestination + "").listFiles(); - - if (backups.length == 0 - || backups.length == 1 && backups[0].getName().equalsIgnoreCase("Files")) { - sender.sendMessage(OperationHandler.processMessage("Error.NoBackups")); - - return; - } - - Arrays.sort(backups); - - try { - int page = Integer.valueOf(args[1]); - - if ((backups.length - 1) < page * 10 - 9) { - sender.sendMessage("Try a lower value."); - - return; - } - - if ((backups.length - 1) <= page * 10 && (backups.length - 1) >= page * 10 - 10) { - sender.sendMessage("----- Backup " + Integer.valueOf(page * 10 - 9) + "-" - + (backups.length - 1) + "/" + (backups.length - 1) + " -----"); - } else { - sender.sendMessage("----- Backup " + Integer.valueOf(page * 10 - 9) + "-" - + Integer.valueOf(page * 10) + "/" + (backups.length - 1) + " -----"); - } - sender.sendMessage(""); - - for (int i = page * 10 - 10; i < (backups.length - 1) && i < page * 10; i++) { - if (backups[0].getName().equalsIgnoreCase("Files")) { - i--; - continue; - } - - double fileSize = (double) FileUtils.sizeOf(backups[i]) / 1000 / 1000; - fileSize = Math.round(fileSize * 100.0) / 100.0; - - if (sender instanceof Player) { - Player p = (Player) sender; - - TextComponent msg = new TextComponent("§7[" + Integer.valueOf(i + 1) + "] §r" - + backups[i].getName() + " §7[" + fileSize + "MB]"); - msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, - new ComponentBuilder("Click to get Backup name").create())); - msg.setClickEvent( - new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, backups[i].getName())); - - p.spigot().sendMessage(msg); - } else { - sender.sendMessage(backups[i].getName()); - } - } - - int maxPages = (backups.length - 1) / 10; - - if ((backups.length - 1) % 10 != 0) { - maxPages++; - } - - sender.sendMessage(""); - sender.sendMessage("-------- Page " + page + "/" + maxPages + " --------"); - } catch (Exception e) { - sender.sendMessage(OperationHandler.processMessage("Error.NotANumber").replaceAll("%input%", args[1])); - } - }); - } +package net.server_backup.commands; + +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.ComponentBuilder; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; +import net.server_backup.Configuration; +import net.server_backup.ServerBackup; +import net.server_backup.core.OperationHandler; +import org.apache.commons.io.FileUtils; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.io.File; +import java.util.Arrays; + +public class CommandList { + + public static void execute(CommandSender sender, String[] args) { + Bukkit.getScheduler().runTaskAsynchronously(ServerBackup.getInstance(), () -> { + File[] backups = new File(Configuration.backupDestination + "").listFiles(); + + if (backups.length == 0 + || backups.length == 1 && backups[0].getName().equalsIgnoreCase("Files")) { + sender.sendMessage(OperationHandler.processMessage("Error.NoBackups")); + + return; + } + + Arrays.sort(backups); + + try { + int page = Integer.valueOf(args[1]); + + if ((backups.length - 1) < page * 10 - 9) { + sender.sendMessage("Try a lower value."); + + return; + } + + if ((backups.length - 1) <= page * 10 && (backups.length - 1) >= page * 10 - 10) { + sender.sendMessage("----- Backup " + Integer.valueOf(page * 10 - 9) + "-" + + (backups.length - 1) + "/" + (backups.length - 1) + " -----"); + } else { + sender.sendMessage("----- Backup " + Integer.valueOf(page * 10 - 9) + "-" + + Integer.valueOf(page * 10) + "/" + (backups.length - 1) + " -----"); + } + sender.sendMessage(""); + + for (int i = page * 10 - 10; i < (backups.length - 1) && i < page * 10; i++) { + if (backups[0].getName().equalsIgnoreCase("Files")) { + i--; + continue; + } + + double fileSize = (double) FileUtils.sizeOf(backups[i]) / 1000 / 1000; + fileSize = Math.round(fileSize * 100.0) / 100.0; + + if (sender instanceof Player) { + Player p = (Player) sender; + + TextComponent msg = new TextComponent("§7[" + Integer.valueOf(i + 1) + "] §r" + + backups[i].getName() + " §7[" + fileSize + "MB]"); + msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, + new ComponentBuilder("Click to get Backup name").create())); + msg.setClickEvent( + new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, backups[i].getName())); + + p.spigot().sendMessage(msg); + } else { + sender.sendMessage(backups[i].getName()); + } + } + + int maxPages = (backups.length - 1) / 10; + + if ((backups.length - 1) % 10 != 0) { + maxPages++; + } + + sender.sendMessage(""); + sender.sendMessage("-------- Page " + page + "/" + maxPages + " --------"); + } catch (Exception e) { + sender.sendMessage(OperationHandler.processMessage("Error.NotANumber").replaceAll("%input%", args[1])); + } + }); + } } \ No newline at end of file diff --git a/src/net/server_backup/commands/CommandRemove.java b/src/main/java/net/server_backup/commands/CommandRemove.java similarity index 95% rename from src/net/server_backup/commands/CommandRemove.java rename to src/main/java/net/server_backup/commands/CommandRemove.java index 4b2a209b..16396ca8 100644 --- a/src/net/server_backup/commands/CommandRemove.java +++ b/src/main/java/net/server_backup/commands/CommandRemove.java @@ -1,20 +1,20 @@ -package net.server_backup.commands; - -import net.server_backup.core.Backup; -import org.bukkit.command.CommandSender; - -public class CommandRemove { - - public static void execute(CommandSender sender, String[] args) { - if (args[1].equalsIgnoreCase("Files")) { - sender.sendMessage("You can not delete the 'Files' backup folder."); - - return; - } - - Backup backup = new Backup(args[1], sender, true); - - backup.remove(); - } - -} +package net.server_backup.commands; + +import net.server_backup.core.Backup; +import org.bukkit.command.CommandSender; + +public class CommandRemove { + + public static void execute(CommandSender sender, String[] args) { + if (args[1].equalsIgnoreCase("Files")) { + sender.sendMessage("You can not delete the 'Files' backup folder."); + + return; + } + + Backup backup = new Backup(args[1], sender, true); + + backup.remove(); + } + +} diff --git a/src/net/server_backup/commands/CommandSearch.java b/src/main/java/net/server_backup/commands/CommandSearch.java similarity index 97% rename from src/net/server_backup/commands/CommandSearch.java rename to src/main/java/net/server_backup/commands/CommandSearch.java index 15be7023..d8b05568 100644 --- a/src/net/server_backup/commands/CommandSearch.java +++ b/src/main/java/net/server_backup/commands/CommandSearch.java @@ -1,106 +1,106 @@ -package net.server_backup.commands; - -import net.md_5.bungee.api.chat.ClickEvent; -import net.md_5.bungee.api.chat.ComponentBuilder; -import net.md_5.bungee.api.chat.HoverEvent; -import net.md_5.bungee.api.chat.TextComponent; -import net.server_backup.Configuration; -import net.server_backup.ServerBackup; -import net.server_backup.core.OperationHandler; -import org.apache.commons.io.FileUtils; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import java.io.File; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -public class CommandSearch { - - public static void execute(CommandSender sender, String[] args) { - Bukkit.getScheduler().runTaskAsynchronously(ServerBackup.getInstance(), () -> { - File[] backups = new File(Configuration.backupDestination + "").listFiles(); - - if (backups.length == 0 - || backups.length == 1 && backups[0].getName().equalsIgnoreCase("Files")) { - sender.sendMessage(OperationHandler.processMessage("Error.NoBackups")); - - return; - } - - List backupsMatch = new ArrayList<>(); - - for (int i = 0; i < backups.length; i++) { - if (backups[i].getName().contains(args[1])) { - backupsMatch.add(backups[i]); - } - } - - if (backupsMatch.size() == 0) { - sender.sendMessage(OperationHandler.processMessage("NoBackupSearch").replaceAll("%input%", args[1])); - - return; - } - - Collections.sort(backupsMatch); - - try { - int page = Integer.valueOf(args[2]); - - if (backups.length < page * 10 - 9) { - sender.sendMessage("Try a lower value."); - - return; - } - - int count = page * 10 - 9; - - if (backupsMatch.size() <= page * 10 && backupsMatch.size() >= page * 10 - 10) { - sender.sendMessage("----- Backup " + Integer.valueOf(page * 10 - 9) + "-" - + backupsMatch.size() + "/" + backupsMatch.size() + " -----"); - } else { - sender.sendMessage("----- Backup " + Integer.valueOf(page * 10 - 9) + "-" - + Integer.valueOf(page * 10) + "/" + backupsMatch.size() + " -----"); - } - sender.sendMessage(""); - - for (File file : backupsMatch) { - if (count <= page * 10 && count <= backupsMatch.size()) { - double fileSize = (double) FileUtils.sizeOf(file) / 1000 / 1000; - fileSize = Math.round(fileSize * 100.0) / 100.0; - - if (sender instanceof Player) { - Player p = (Player) sender; - - TextComponent msg = new TextComponent("§7[" + Integer.valueOf(count) - + "] §r" + file.getName() + " §7[" + fileSize + "MB]"); - msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, - new ComponentBuilder("Click to get Backup name").create())); - msg.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, - "/backup remove " + file.getName())); - - p.spigot().sendMessage(msg); - } else { - sender.sendMessage(file.getName()); - } - } - count++; - } - - int maxPages = backupsMatch.size() / 10; - - if (backupsMatch.size() % 10 != 0) { - maxPages++; - } - - sender.sendMessage(""); - sender.sendMessage("-------- Page " + page + "/" + maxPages + " --------"); - } catch (Exception e) { - sender.sendMessage(OperationHandler.processMessage("Error.NotANumber").replaceAll("%input%", args[2])); - } - }); - } - -} +package net.server_backup.commands; + +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.ComponentBuilder; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; +import net.server_backup.Configuration; +import net.server_backup.ServerBackup; +import net.server_backup.core.OperationHandler; +import org.apache.commons.io.FileUtils; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class CommandSearch { + + public static void execute(CommandSender sender, String[] args) { + Bukkit.getScheduler().runTaskAsynchronously(ServerBackup.getInstance(), () -> { + File[] backups = new File(Configuration.backupDestination + "").listFiles(); + + if (backups.length == 0 + || backups.length == 1 && backups[0].getName().equalsIgnoreCase("Files")) { + sender.sendMessage(OperationHandler.processMessage("Error.NoBackups")); + + return; + } + + List backupsMatch = new ArrayList<>(); + + for (int i = 0; i < backups.length; i++) { + if (backups[i].getName().contains(args[1])) { + backupsMatch.add(backups[i]); + } + } + + if (backupsMatch.size() == 0) { + sender.sendMessage(OperationHandler.processMessage("NoBackupSearch").replaceAll("%input%", args[1])); + + return; + } + + Collections.sort(backupsMatch); + + try { + int page = Integer.valueOf(args[2]); + + if (backups.length < page * 10 - 9) { + sender.sendMessage("Try a lower value."); + + return; + } + + int count = page * 10 - 9; + + if (backupsMatch.size() <= page * 10 && backupsMatch.size() >= page * 10 - 10) { + sender.sendMessage("----- Backup " + Integer.valueOf(page * 10 - 9) + "-" + + backupsMatch.size() + "/" + backupsMatch.size() + " -----"); + } else { + sender.sendMessage("----- Backup " + Integer.valueOf(page * 10 - 9) + "-" + + Integer.valueOf(page * 10) + "/" + backupsMatch.size() + " -----"); + } + sender.sendMessage(""); + + for (File file : backupsMatch) { + if (count <= page * 10 && count <= backupsMatch.size()) { + double fileSize = (double) FileUtils.sizeOf(file) / 1000 / 1000; + fileSize = Math.round(fileSize * 100.0) / 100.0; + + if (sender instanceof Player) { + Player p = (Player) sender; + + TextComponent msg = new TextComponent("§7[" + Integer.valueOf(count) + + "] §r" + file.getName() + " §7[" + fileSize + "MB]"); + msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, + new ComponentBuilder("Click to get Backup name").create())); + msg.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, + "/backup remove " + file.getName())); + + p.spigot().sendMessage(msg); + } else { + sender.sendMessage(file.getName()); + } + } + count++; + } + + int maxPages = backupsMatch.size() / 10; + + if (backupsMatch.size() % 10 != 0) { + maxPages++; + } + + sender.sendMessage(""); + sender.sendMessage("-------- Page " + page + "/" + maxPages + " --------"); + } catch (Exception e) { + sender.sendMessage(OperationHandler.processMessage("Error.NotANumber").replaceAll("%input%", args[2])); + } + }); + } + +} diff --git a/src/net/server_backup/commands/CommandShutdown.java b/src/main/java/net/server_backup/commands/CommandShutdown.java similarity index 96% rename from src/net/server_backup/commands/CommandShutdown.java rename to src/main/java/net/server_backup/commands/CommandShutdown.java index 4105dd16..63a821b4 100644 --- a/src/net/server_backup/commands/CommandShutdown.java +++ b/src/main/java/net/server_backup/commands/CommandShutdown.java @@ -1,20 +1,20 @@ -package net.server_backup.commands; - -import net.server_backup.core.OperationHandler; -import org.bukkit.command.CommandSender; - -public class CommandShutdown { - - public static void execute(CommandSender sender, String[] args) { - if (OperationHandler.shutdownProgress) { - OperationHandler.shutdownProgress = false; - - sender.sendMessage(OperationHandler.processMessage("Command.Shutdown.Cancel")); - } else { - OperationHandler.shutdownProgress = true; - - sender.sendMessage(OperationHandler.processMessage("Command.Shutdown.Start")); - } - } - -} +package net.server_backup.commands; + +import net.server_backup.core.OperationHandler; +import org.bukkit.command.CommandSender; + +public class CommandShutdown { + + public static void execute(CommandSender sender, String[] args) { + if (OperationHandler.shutdownProgress) { + OperationHandler.shutdownProgress = false; + + sender.sendMessage(OperationHandler.processMessage("Command.Shutdown.Cancel")); + } else { + OperationHandler.shutdownProgress = true; + + sender.sendMessage(OperationHandler.processMessage("Command.Shutdown.Start")); + } + } + +} diff --git a/src/net/server_backup/commands/CommandTasks.java b/src/main/java/net/server_backup/commands/CommandTasks.java similarity index 96% rename from src/net/server_backup/commands/CommandTasks.java rename to src/main/java/net/server_backup/commands/CommandTasks.java index 6a47f9e8..55d49da8 100644 --- a/src/net/server_backup/commands/CommandTasks.java +++ b/src/main/java/net/server_backup/commands/CommandTasks.java @@ -1,22 +1,22 @@ -package net.server_backup.commands; - -import net.server_backup.core.OperationHandler; -import org.bukkit.command.CommandSender; - -public class CommandTasks { - - public static void execute(CommandSender sender, String[] args) { - if (OperationHandler.tasks.size() > 0) { - sender.sendMessage(OperationHandler.processMessage("Command.Tasks.Header")); - - for (String task : OperationHandler.tasks) { - sender.sendMessage(task); - } - - sender.sendMessage(OperationHandler.processMessage("Command.Tasks.Footer")); - } else { - sender.sendMessage(OperationHandler.processMessage("Error.NoTasks")); - } - } - -} +package net.server_backup.commands; + +import net.server_backup.core.OperationHandler; +import org.bukkit.command.CommandSender; + +public class CommandTasks { + + public static void execute(CommandSender sender, String[] args) { + if (OperationHandler.tasks.size() > 0) { + sender.sendMessage(OperationHandler.processMessage("Command.Tasks.Header")); + + for (String task : OperationHandler.tasks) { + sender.sendMessage(task); + } + + sender.sendMessage(OperationHandler.processMessage("Command.Tasks.Footer")); + } else { + sender.sendMessage(OperationHandler.processMessage("Error.NoTasks")); + } + } + +} diff --git a/src/net/server_backup/commands/CommandUnzip.java b/src/main/java/net/server_backup/commands/CommandUnzip.java similarity index 97% rename from src/net/server_backup/commands/CommandUnzip.java rename to src/main/java/net/server_backup/commands/CommandUnzip.java index 146c9306..03ff6a29 100644 --- a/src/net/server_backup/commands/CommandUnzip.java +++ b/src/main/java/net/server_backup/commands/CommandUnzip.java @@ -1,44 +1,44 @@ -package net.server_backup.commands; - -import net.server_backup.Configuration; -import net.server_backup.ServerBackup; -import net.server_backup.core.OperationHandler; -import net.server_backup.core.ZipManager; -import org.bukkit.command.CommandSender; - -import java.io.File; - -public class CommandUnzip { - - public static void execute(CommandSender sender, String[] args) { - String filePath = args[1]; - - if (!args[1].contains(".zip")) { - sender.sendMessage(OperationHandler.processMessage("Error.NotAZip").replaceAll("%file%", args[1])); - - return; - } - - File file = new File(Configuration.backupDestination + "//" + filePath); - File newFile = new File( - Configuration - .backupDestination + "//" + filePath.replaceAll(".zip", "")); - - if (!newFile.exists()) { - sender.sendMessage(OperationHandler.processMessage("Command.Unzip.Header")); - - if (file.exists()) { - ZipManager zm = new ZipManager(file.getPath(), - Configuration.backupDestination + "//" + newFile.getName(), sender, - false, true, true); - - zm.unzip(); - } else { - sender.sendMessage(OperationHandler.processMessage("Error.NoBackupFound").replaceAll("%file%", args[1])); - } - } else { - sender.sendMessage(OperationHandler.processMessage("Error.ZipExists").replaceAll("%file%", args[1])); - } - } - -} +package net.server_backup.commands; + +import net.server_backup.Configuration; +import net.server_backup.ServerBackup; +import net.server_backup.core.OperationHandler; +import net.server_backup.core.ZipManager; +import org.bukkit.command.CommandSender; + +import java.io.File; + +public class CommandUnzip { + + public static void execute(CommandSender sender, String[] args) { + String filePath = args[1]; + + if (!args[1].contains(".zip")) { + sender.sendMessage(OperationHandler.processMessage("Error.NotAZip").replaceAll("%file%", args[1])); + + return; + } + + File file = new File(Configuration.backupDestination + "//" + filePath); + File newFile = new File( + Configuration + .backupDestination + "//" + filePath.replaceAll(".zip", "")); + + if (!newFile.exists()) { + sender.sendMessage(OperationHandler.processMessage("Command.Unzip.Header")); + + if (file.exists()) { + ZipManager zm = new ZipManager(file.getPath(), + Configuration.backupDestination + "//" + newFile.getName(), sender, + false, true, true); + + zm.unzip(); + } else { + sender.sendMessage(OperationHandler.processMessage("Error.NoBackupFound").replaceAll("%file%", args[1])); + } + } else { + sender.sendMessage(OperationHandler.processMessage("Error.ZipExists").replaceAll("%file%", args[1])); + } + } + +} diff --git a/src/net/server_backup/commands/CommandZip.java b/src/main/java/net/server_backup/commands/CommandZip.java similarity index 97% rename from src/net/server_backup/commands/CommandZip.java rename to src/main/java/net/server_backup/commands/CommandZip.java index 7e35b28a..51d0f4d0 100644 --- a/src/net/server_backup/commands/CommandZip.java +++ b/src/main/java/net/server_backup/commands/CommandZip.java @@ -1,44 +1,44 @@ -package net.server_backup.commands; - -import net.server_backup.Configuration; -import net.server_backup.core.OperationHandler; -import net.server_backup.core.ZipManager; -import org.bukkit.command.CommandSender; - -import java.io.File; -import java.io.IOException; - -public class CommandZip { - - public static void execute(CommandSender sender, String[] args) { - String filePath = args[1]; - - if (args[1].contains(".zip")) { - sender.sendMessage(OperationHandler.processMessage("Error.AlreadyZip").replaceAll("%file%", args[1])); - return; - } - - File file = new File(Configuration.backupDestination + "//" + filePath); - File newFile = new File(Configuration.backupDestination + "//" + filePath + ".zip"); - - if (!newFile.exists()) { - sender.sendMessage(OperationHandler.processMessage("Command.Zip.Header")); - - if (file.exists()) { - try { - ZipManager zm = new ZipManager(file.getPath(), newFile.getPath(), sender, true, false, - true); - - zm.zip(); - } catch (IOException e) { - e.printStackTrace(); - } - } else { - sender.sendMessage(OperationHandler.processMessage("Error.NoBackupFound").replaceAll("%file%", args[1])); - } - } else { - sender.sendMessage(OperationHandler.processMessage("Error.FolderExists").replaceAll("%file%", args[1])); - } - } - -} +package net.server_backup.commands; + +import net.server_backup.Configuration; +import net.server_backup.core.OperationHandler; +import net.server_backup.core.ZipManager; +import org.bukkit.command.CommandSender; + +import java.io.File; +import java.io.IOException; + +public class CommandZip { + + public static void execute(CommandSender sender, String[] args) { + String filePath = args[1]; + + if (args[1].contains(".zip")) { + sender.sendMessage(OperationHandler.processMessage("Error.AlreadyZip").replaceAll("%file%", args[1])); + return; + } + + File file = new File(Configuration.backupDestination + "//" + filePath); + File newFile = new File(Configuration.backupDestination + "//" + filePath + ".zip"); + + if (!newFile.exists()) { + sender.sendMessage(OperationHandler.processMessage("Command.Zip.Header")); + + if (file.exists()) { + try { + ZipManager zm = new ZipManager(file.getPath(), newFile.getPath(), sender, true, false, + true); + + zm.zip(); + } catch (IOException e) { + e.printStackTrace(); + } + } else { + sender.sendMessage(OperationHandler.processMessage("Error.NoBackupFound").replaceAll("%file%", args[1])); + } + } else { + sender.sendMessage(OperationHandler.processMessage("Error.FolderExists").replaceAll("%file%", args[1])); + } + } + +} diff --git a/src/net/server_backup/commands/Executor.java b/src/main/java/net/server_backup/commands/Executor.java similarity index 97% rename from src/net/server_backup/commands/Executor.java rename to src/main/java/net/server_backup/commands/Executor.java index 4c873d48..dd8b2924 100644 --- a/src/net/server_backup/commands/Executor.java +++ b/src/main/java/net/server_backup/commands/Executor.java @@ -1,93 +1,93 @@ -package net.server_backup.commands; - -import net.server_backup.Configuration; -import net.server_backup.core.OperationHandler; -import org.bukkit.Bukkit; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; - -public class Executor implements CommandExecutor { - - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - - if (sender.hasPermission("backup.admin")) { - if (args.length >= 2) { - if (args[0].equalsIgnoreCase("create")) { - CommandCreate.execute(sender, args); - - return true; - } - } - - if (args.length == 1) { - if (args[0].equalsIgnoreCase("shutdown")) { - CommandShutdown.execute(sender, args); - } else if (args[0].equalsIgnoreCase("list")) { - Bukkit.dispatchCommand(sender, "backup list 1"); - } else if (args[0].equalsIgnoreCase("reload") || args[0].equalsIgnoreCase("rl")) { - Configuration.reloadConfig(sender); - } else if (args[0].equalsIgnoreCase("tasks") || args[0].equalsIgnoreCase("task")) { - CommandTasks.execute(sender, args); - } else { - sendHelp(sender); - } - } else if (args.length == 2) { - if (args[0].equalsIgnoreCase("list")) { - CommandList.execute(sender, args); - } else if (args[0].equalsIgnoreCase("ftp")) { - if (args[1].equalsIgnoreCase("list")) { - Bukkit.dispatchCommand(sender, "backup ftp list 1"); - } - } else if (args[0].equalsIgnoreCase("zip")) { - CommandZip.execute(sender, args); - } else if (args[0].equalsIgnoreCase("unzip")) { - CommandUnzip.execute(sender, args); - } else if (args[0].equalsIgnoreCase("delete") || args[0].equalsIgnoreCase("remove")) { - CommandRemove.execute(sender, args); - } else if (args[0].equalsIgnoreCase("search")) { - Bukkit.dispatchCommand(sender, "backup search " + args[1] + " 1"); - } - } else if (args.length == 3) { - if (args[0].equalsIgnoreCase("search")) { - CommandSearch.execute(sender, args); - } else if (args[0].equalsIgnoreCase("ftp")) { - CommandFtp.execute(sender, args); - } else if (args[0].equalsIgnoreCase("dropbox")) { - CommandDropbox.execute(sender, args); - } - } else { - sendHelp(sender); - } - } else { - sender.sendMessage(OperationHandler.processMessage("Error.NoPermission")); - } - - return false; - } - - private void sendHelp(CommandSender sender) { - sender.sendMessage("/backup reload - reloads the config"); - sender.sendMessage(""); - sender.sendMessage("/backup list - shows a list of 10 backups"); - sender.sendMessage(""); - sender.sendMessage( - "/backup search - shows a list of 10 backups that contain the given search argument"); - sender.sendMessage(""); - sender.sendMessage("/backup create - creates a new backup of a world"); - sender.sendMessage(""); - sender.sendMessage("/backup remove - removes an existing backup"); - sender.sendMessage(""); - sender.sendMessage("/backup zip - zipping folder"); - sender.sendMessage(""); - sender.sendMessage("/backup unzip - unzipping file"); - sender.sendMessage(""); - sender.sendMessage("/backup ftp - download, upload or list ftp backup files"); - sender.sendMessage(""); - sender.sendMessage("/backup dropbox upload - upload a backup to dropbox"); - sender.sendMessage(""); - sender.sendMessage("/backup shutdown - shut downs the server after backup tasks are finished"); - } - -} +package net.server_backup.commands; + +import net.server_backup.Configuration; +import net.server_backup.core.OperationHandler; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; + +public class Executor implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + + if (sender.hasPermission("backup.admin")) { + if (args.length >= 2) { + if (args[0].equalsIgnoreCase("create")) { + CommandCreate.execute(sender, args); + + return true; + } + } + + if (args.length == 1) { + if (args[0].equalsIgnoreCase("shutdown")) { + CommandShutdown.execute(sender, args); + } else if (args[0].equalsIgnoreCase("list")) { + Bukkit.dispatchCommand(sender, "backup list 1"); + } else if (args[0].equalsIgnoreCase("reload") || args[0].equalsIgnoreCase("rl")) { + Configuration.reloadConfig(sender); + } else if (args[0].equalsIgnoreCase("tasks") || args[0].equalsIgnoreCase("task")) { + CommandTasks.execute(sender, args); + } else { + sendHelp(sender); + } + } else if (args.length == 2) { + if (args[0].equalsIgnoreCase("list")) { + CommandList.execute(sender, args); + } else if (args[0].equalsIgnoreCase("ftp")) { + if (args[1].equalsIgnoreCase("list")) { + Bukkit.dispatchCommand(sender, "backup ftp list 1"); + } + } else if (args[0].equalsIgnoreCase("zip")) { + CommandZip.execute(sender, args); + } else if (args[0].equalsIgnoreCase("unzip")) { + CommandUnzip.execute(sender, args); + } else if (args[0].equalsIgnoreCase("delete") || args[0].equalsIgnoreCase("remove")) { + CommandRemove.execute(sender, args); + } else if (args[0].equalsIgnoreCase("search")) { + Bukkit.dispatchCommand(sender, "backup search " + args[1] + " 1"); + } + } else if (args.length == 3) { + if (args[0].equalsIgnoreCase("search")) { + CommandSearch.execute(sender, args); + } else if (args[0].equalsIgnoreCase("ftp")) { + CommandFtp.execute(sender, args); + } else if (args[0].equalsIgnoreCase("dropbox")) { + CommandDropbox.execute(sender, args); + } + } else { + sendHelp(sender); + } + } else { + sender.sendMessage(OperationHandler.processMessage("Error.NoPermission")); + } + + return false; + } + + private void sendHelp(CommandSender sender) { + sender.sendMessage("/backup reload - reloads the config"); + sender.sendMessage(""); + sender.sendMessage("/backup list - shows a list of 10 backups"); + sender.sendMessage(""); + sender.sendMessage( + "/backup search - shows a list of 10 backups that contain the given search argument"); + sender.sendMessage(""); + sender.sendMessage("/backup create - creates a new backup of a world"); + sender.sendMessage(""); + sender.sendMessage("/backup remove - removes an existing backup"); + sender.sendMessage(""); + sender.sendMessage("/backup zip - zipping folder"); + sender.sendMessage(""); + sender.sendMessage("/backup unzip - unzipping file"); + sender.sendMessage(""); + sender.sendMessage("/backup ftp - download, upload or list ftp backup files"); + sender.sendMessage(""); + sender.sendMessage("/backup dropbox upload - upload a backup to dropbox"); + sender.sendMessage(""); + sender.sendMessage("/backup shutdown - shut downs the server after backup tasks are finished"); + } + +} diff --git a/src/net/server_backup/commands/TabCompleter.java b/src/main/java/net/server_backup/commands/TabCompleter.java similarity index 97% rename from src/net/server_backup/commands/TabCompleter.java rename to src/main/java/net/server_backup/commands/TabCompleter.java index c6f884b6..aa835195 100644 --- a/src/net/server_backup/commands/TabCompleter.java +++ b/src/main/java/net/server_backup/commands/TabCompleter.java @@ -1,137 +1,137 @@ -package net.server_backup.commands; - -import net.server_backup.Configuration; -import net.server_backup.utils.FtpManager; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.util.StringUtil; - -import java.io.File; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -public class TabCompleter implements org.bukkit.command.TabCompleter { - - @Override - public List onTabComplete(CommandSender sender, Command cmd, String label, String[] args) { - List completions = new ArrayList<>(); - List commands = new ArrayList<>(); - - if (sender.hasPermission("backup.admin")) { - if (args.length == 1) { - commands.add("reload"); - commands.add("list"); - commands.add("search"); - commands.add("create"); - commands.add("remove"); - commands.add("zip"); - commands.add("unzip"); - commands.add("ftp"); - commands.add("dropbox"); - commands.add("tasks"); - commands.add("shutdown"); - - StringUtil.copyPartialMatches(args[0], commands, completions); - } else if (args.length == 2) { - if (args[0].equalsIgnoreCase("list")) { - File[] backups = new File(Configuration.backupDestination + "").listFiles(); - - int maxPages = backups.length / 10; - - if (backups.length % 10 != 0) { - maxPages++; - } - - for (int i = 1; i < maxPages + 1; i++) { - commands.add(String.valueOf(i)); - } - } else if (args[0].equalsIgnoreCase("remove")) { - File[] backups = new File(Configuration.backupDestination + "").listFiles(); - - for (int i = 0; i < backups.length; i++) { - commands.add(backups[i].getName()); - } - } else if (args[0].equalsIgnoreCase("create")) { - for (World world : Bukkit.getWorlds()) { - commands.add((!Bukkit.getWorldContainer().getPath().equalsIgnoreCase(".")) - ? Bukkit.getWorldContainer() + "/" + world.getName() - : world.getName()); - } - - commands.add("@server"); - } else if (args[0].equalsIgnoreCase("zip")) { - File[] backups = new File(Configuration.backupDestination + "").listFiles(); - - for (File backup : backups) { - if (!backup.getName().endsWith(".zip")) { - commands.add(backup.getName()); - } - } - } else if (args[0].equalsIgnoreCase("unzip")) { - File[] backups = new File(Configuration.backupDestination + "").listFiles(); - - for (File backup : backups) { - if (backup.getName().endsWith(".zip")) { - commands.add(backup.getName()); - } - } - } else if (args[0].equalsIgnoreCase("ftp")) { - commands.add("list"); - commands.add("download"); - commands.add("upload"); - } else if (args[0].equalsIgnoreCase("dropbox")) { - commands.add("upload"); - } - - StringUtil.copyPartialMatches(args[1], commands, completions); - } else if (args.length == 3) { - if (args[0].equalsIgnoreCase("ftp")) { - if (args[1].equalsIgnoreCase("download")) { - FtpManager ftpm = new FtpManager(sender); - - List backups = ftpm.getFtpBackupList(false); - - for (String backup : backups) { - commands.add(backup.split(" ")[1]); - } - } else if (args[1].equalsIgnoreCase("upload")) { - File[] backups = new File(Configuration.backupDestination + "").listFiles(); - - for (File backup : backups) { - if (backup.getName().endsWith(".zip")) { - commands.add(backup.getName()); - } - } - } - - } else if (args[0].equalsIgnoreCase("dropbox")) { - File[] backups = new File(Configuration.backupDestination + "").listFiles(); - - for (File backup : backups) { - if (backup.getName().endsWith(".zip")) { - commands.add(backup.getName()); - } - } - } else if (args[0].equalsIgnoreCase("create")) { - commands.add("-full"); - } - - StringUtil.copyPartialMatches(args[2], commands, completions); - } else if (args.length > 3) { - if (args[0].equalsIgnoreCase("create")) { - commands.add("-full"); - } - - StringUtil.copyPartialMatches(args[args.length - 1], commands, completions); - } - } - - Collections.sort(completions); - - return completions; - } - -} +package net.server_backup.commands; + +import net.server_backup.Configuration; +import net.server_backup.utils.FtpManager; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.util.StringUtil; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class TabCompleter implements org.bukkit.command.TabCompleter { + + @Override + public List onTabComplete(CommandSender sender, Command cmd, String label, String[] args) { + List completions = new ArrayList<>(); + List commands = new ArrayList<>(); + + if (sender.hasPermission("backup.admin")) { + if (args.length == 1) { + commands.add("reload"); + commands.add("list"); + commands.add("search"); + commands.add("create"); + commands.add("remove"); + commands.add("zip"); + commands.add("unzip"); + commands.add("ftp"); + commands.add("dropbox"); + commands.add("tasks"); + commands.add("shutdown"); + + StringUtil.copyPartialMatches(args[0], commands, completions); + } else if (args.length == 2) { + if (args[0].equalsIgnoreCase("list")) { + File[] backups = new File(Configuration.backupDestination + "").listFiles(); + + int maxPages = backups.length / 10; + + if (backups.length % 10 != 0) { + maxPages++; + } + + for (int i = 1; i < maxPages + 1; i++) { + commands.add(String.valueOf(i)); + } + } else if (args[0].equalsIgnoreCase("remove")) { + File[] backups = new File(Configuration.backupDestination + "").listFiles(); + + for (int i = 0; i < backups.length; i++) { + commands.add(backups[i].getName()); + } + } else if (args[0].equalsIgnoreCase("create")) { + for (World world : Bukkit.getWorlds()) { + commands.add((!Bukkit.getWorldContainer().getPath().equalsIgnoreCase(".")) + ? Bukkit.getWorldContainer() + "/" + world.getName() + : world.getName()); + } + + commands.add("@server"); + } else if (args[0].equalsIgnoreCase("zip")) { + File[] backups = new File(Configuration.backupDestination + "").listFiles(); + + for (File backup : backups) { + if (!backup.getName().endsWith(".zip")) { + commands.add(backup.getName()); + } + } + } else if (args[0].equalsIgnoreCase("unzip")) { + File[] backups = new File(Configuration.backupDestination + "").listFiles(); + + for (File backup : backups) { + if (backup.getName().endsWith(".zip")) { + commands.add(backup.getName()); + } + } + } else if (args[0].equalsIgnoreCase("ftp")) { + commands.add("list"); + commands.add("download"); + commands.add("upload"); + } else if (args[0].equalsIgnoreCase("dropbox")) { + commands.add("upload"); + } + + StringUtil.copyPartialMatches(args[1], commands, completions); + } else if (args.length == 3) { + if (args[0].equalsIgnoreCase("ftp")) { + if (args[1].equalsIgnoreCase("download")) { + FtpManager ftpm = new FtpManager(sender); + + List backups = ftpm.getFtpBackupList(false); + + for (String backup : backups) { + commands.add(backup.split(" ")[1]); + } + } else if (args[1].equalsIgnoreCase("upload")) { + File[] backups = new File(Configuration.backupDestination + "").listFiles(); + + for (File backup : backups) { + if (backup.getName().endsWith(".zip")) { + commands.add(backup.getName()); + } + } + } + + } else if (args[0].equalsIgnoreCase("dropbox")) { + File[] backups = new File(Configuration.backupDestination + "").listFiles(); + + for (File backup : backups) { + if (backup.getName().endsWith(".zip")) { + commands.add(backup.getName()); + } + } + } else if (args[0].equalsIgnoreCase("create")) { + commands.add("-full"); + } + + StringUtil.copyPartialMatches(args[2], commands, completions); + } else if (args.length > 3) { + if (args[0].equalsIgnoreCase("create")) { + commands.add("-full"); + } + + StringUtil.copyPartialMatches(args[args.length - 1], commands, completions); + } + } + + Collections.sort(completions); + + return completions; + } + +} diff --git a/src/net/server_backup/core/Backup.java b/src/main/java/net/server_backup/core/Backup.java similarity index 97% rename from src/net/server_backup/core/Backup.java rename to src/main/java/net/server_backup/core/Backup.java index 6fda9ed5..07b73d09 100644 --- a/src/net/server_backup/core/Backup.java +++ b/src/main/java/net/server_backup/core/Backup.java @@ -1,103 +1,103 @@ -package net.server_backup.core; - -import net.server_backup.Configuration; -import net.server_backup.ServerBackup; -import org.apache.commons.io.FileUtils; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import java.io.File; -import java.io.IOException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.TimeZone; -import java.util.logging.Level; - -public class Backup { - - private final String backupFilePath; - private CommandSender sender; - private final boolean isFullBackup; - - public Backup(String backupFilePath, CommandSender sender, boolean isFullBackup) { - this.backupFilePath = backupFilePath; - this.sender = sender; - this.isFullBackup = isFullBackup; - } - - public String getBackupFilePath() { - return backupFilePath; - } - - public void create() { - String filePath = backupFilePath; - File worldFolder = new File(filePath); - - if (filePath.equalsIgnoreCase("@server")) { - filePath = new File(".").getPath(); - worldFolder = new File(filePath); - } - - Date date = new Date(); - SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'~'HH-mm-ss"); - df.setTimeZone(TimeZone.getDefault()); - - File backupFolder = new File(Configuration.backupDestination + "//backup-" + df.format(date) + "-" - + filePath + "//" + filePath); - - if(worldFolder.exists()) { - try { - if (!backupFolder.exists()) { - for (Player all : Bukkit.getOnlinePlayers()) { - if (all.hasPermission("backup.notification")) { - all.sendMessage(OperationHandler.processMessage("Info.BackupStarted").replaceAll("%file%", worldFolder.getName())); - } - } - - ZipManager zm = new ZipManager( - worldFolder.getPath(), Configuration.backupDestination + "//backup-" - + df.format(date) + "-" + filePath.replaceAll("/", "-") + ".zip", - Bukkit.getConsoleSender(), true, true, isFullBackup); - - zm.zip(); - - OperationHandler.tasks.add("CREATE {" + filePath.replace("\\", "/") + "}"); - } else { - Bukkit.getLogger().log(Level.WARNING, "Backup already exists."); - } - } catch (IOException e) { - e.printStackTrace(); - - Bukkit.getLogger().log(Level.WARNING, "Backup failed."); - } - } - } - - public void remove() { - Bukkit.getScheduler().runTaskAsynchronously(ServerBackup.getInstance(), () -> { - File file = new File(Configuration.backupDestination + "//" + backupFilePath); - - if (file.exists()) { - if (file.isDirectory()) { - try { - FileUtils.deleteDirectory(file); - - sender.sendMessage(OperationHandler.processMessage("Info.BackupRemoved").replaceAll("%file%", backupFilePath)); - } catch (IOException e) { - e.printStackTrace(); - - sender.sendMessage(OperationHandler.processMessage("Error.DeletionFailed").replaceAll("%file%", backupFilePath)); - } - } else { - file.delete(); - - sender.sendMessage(OperationHandler.processMessage("Info.BackupRemoved").replaceAll("%file%", backupFilePath)); - } - } else { - sender.sendMessage(OperationHandler.processMessage("Error.NoBackupFound").replaceAll("%file%", backupFilePath)); - } - }); - } - -} +package net.server_backup.core; + +import net.server_backup.Configuration; +import net.server_backup.ServerBackup; +import org.apache.commons.io.FileUtils; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.io.File; +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.TimeZone; +import java.util.logging.Level; + +public class Backup { + + private final String backupFilePath; + private CommandSender sender; + private final boolean isFullBackup; + + public Backup(String backupFilePath, CommandSender sender, boolean isFullBackup) { + this.backupFilePath = backupFilePath; + this.sender = sender; + this.isFullBackup = isFullBackup; + } + + public String getBackupFilePath() { + return backupFilePath; + } + + public void create() { + String filePath = backupFilePath; + File worldFolder = new File(filePath); + + if (filePath.equalsIgnoreCase("@server")) { + filePath = new File(".").getPath(); + worldFolder = new File(filePath); + } + + Date date = new Date(); + SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'~'HH-mm-ss"); + df.setTimeZone(TimeZone.getDefault()); + + File backupFolder = new File(Configuration.backupDestination + "//backup-" + df.format(date) + "-" + + filePath + "//" + filePath); + + if(worldFolder.exists()) { + try { + if (!backupFolder.exists()) { + for (Player all : Bukkit.getOnlinePlayers()) { + if (all.hasPermission("backup.notification")) { + all.sendMessage(OperationHandler.processMessage("Info.BackupStarted").replaceAll("%file%", worldFolder.getName())); + } + } + + ZipManager zm = new ZipManager( + worldFolder.getPath(), Configuration.backupDestination + "//backup-" + + df.format(date) + "-" + filePath.replaceAll("/", "-") + ".zip", + Bukkit.getConsoleSender(), true, true, isFullBackup); + + zm.zip(); + + OperationHandler.tasks.add("CREATE {" + filePath.replace("\\", "/") + "}"); + } else { + Bukkit.getLogger().log(Level.WARNING, "Backup already exists."); + } + } catch (IOException e) { + e.printStackTrace(); + + Bukkit.getLogger().log(Level.WARNING, "Backup failed."); + } + } + } + + public void remove() { + Bukkit.getScheduler().runTaskAsynchronously(ServerBackup.getInstance(), () -> { + File file = new File(Configuration.backupDestination + "//" + backupFilePath); + + if (file.exists()) { + if (file.isDirectory()) { + try { + FileUtils.deleteDirectory(file); + + sender.sendMessage(OperationHandler.processMessage("Info.BackupRemoved").replaceAll("%file%", backupFilePath)); + } catch (IOException e) { + e.printStackTrace(); + + sender.sendMessage(OperationHandler.processMessage("Error.DeletionFailed").replaceAll("%file%", backupFilePath)); + } + } else { + file.delete(); + + sender.sendMessage(OperationHandler.processMessage("Info.BackupRemoved").replaceAll("%file%", backupFilePath)); + } + } else { + sender.sendMessage(OperationHandler.processMessage("Error.NoBackupFound").replaceAll("%file%", backupFilePath)); + } + }); + } + +} diff --git a/src/net/server_backup/core/DynamicBackup.java b/src/main/java/net/server_backup/core/DynamicBackup.java similarity index 97% rename from src/net/server_backup/core/DynamicBackup.java rename to src/main/java/net/server_backup/core/DynamicBackup.java index 525bb3f6..d6789eb1 100644 --- a/src/net/server_backup/core/DynamicBackup.java +++ b/src/main/java/net/server_backup/core/DynamicBackup.java @@ -1,132 +1,132 @@ -package net.server_backup.core; - -import net.server_backup.Configuration; -import net.server_backup.ServerBackup; -import org.bukkit.Bukkit; -import org.bukkit.Chunk; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerMoveEvent; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.logging.Level; - -public class DynamicBackup implements Listener { - - List chunks = Collections.synchronizedList(new ArrayList<>()); - public boolean isSaving = false; - - @EventHandler - public void onPlayerMove(PlayerMoveEvent e) { - if (ServerBackup.getInstance().getConfig().getBoolean("DynamicBackup")) { - if (e.getFrom().getChunk() != e.getTo().getChunk()) { - int regX = e.getTo().getChunk().getX() >> 5; - int regZ = e.getTo().getChunk().getZ() >> 5; - - Bukkit.getScheduler().runTaskAsynchronously(ServerBackup.getInstance(), new Runnable() { - - @Override - public void run() { - String chunkInf = "Data." + e.getTo().getWorld().getName() + ".Chunk." + "r." + regX + "." - + regZ + ".mca"; - - if (!Bukkit.getWorldContainer().toString().equalsIgnoreCase(".")) { - chunkInf = "Data." + Bukkit.getWorldContainer() + "\\" + e.getTo().getWorld().getName() - + ".Chunk." + "r." + regX + "." + regZ + ".mca"; - } - - if (!chunks.contains(e.getTo().getChunk())) { - if (!Configuration.backupInfo.contains(chunkInf)) { - chunks.add(e.getTo().getChunk()); - Configuration.backupInfo.set(chunkInf, chunks.get(chunks.size() - 1).getX()); - Configuration.backupInfo.set(chunkInf, chunks.get(chunks.size() - 1).getZ()); - - saveChanges(); - try { - chunks.remove(e.getTo().getChunk()); - } catch (ArrayIndexOutOfBoundsException ex) { - } - } else { - chunks.add(e.getTo().getChunk()); - Configuration.backupInfo.set(chunkInf, chunks.get(chunks.size() - 1).getWorld()); - - saveChanges(); - try { - chunks.remove(e.getTo().getChunk()); - } catch (ArrayIndexOutOfBoundsException ex) { - } - } - } - } - - }); - } - } - } - - public void saveChanges() { - if (!isSaving) { - isSaving = true; - - Bukkit.getScheduler().runTaskLaterAsynchronously(ServerBackup.getInstance(), new Runnable() { - - @Override - public void run() { - Configuration.saveBackupInfo();; - if (ServerBackup.getInstance().getConfig().getBoolean("SendLogMessages")) { - Bukkit.getLogger().log(Level.INFO, "DynamicBP: file saved."); - } - - isSaving = false; - } - - }, 20 * 5); - } - } - - @EventHandler - public void onJoin(PlayerJoinEvent e) { - if (ServerBackup.getInstance().getConfig().getBoolean("DynamicBackup")) { - Player p = e.getPlayer(); - - int regX = p.getLocation().getChunk().getX() >> 5; - int regZ = p.getLocation().getChunk().getZ() >> 5; - - Bukkit.getScheduler().runTaskAsynchronously(ServerBackup.getInstance(), new Runnable() { - - @Override - public void run() { - String chunkInf = "Data." + p.getLocation().getWorld().getName() + ".Chunk." + "r." + regX + "." - + regZ + ".mca"; - - if (!Bukkit.getWorldContainer().toString().equalsIgnoreCase(".")) { - chunkInf = "Data." + Bukkit.getWorldContainer() + "\\" + p.getLocation().getWorld().getName() - + ".Chunk." + "r." + regX + "." + regZ + ".mca"; - } - - if (!chunks.contains(p.getLocation().getChunk())) { - if (!Configuration.backupInfo.contains(chunkInf)) { - chunks.add(p.getLocation().getChunk()); - Configuration.backupInfo.set(chunkInf + ".X", p.getLocation().getChunk().getX()); - Configuration.backupInfo.set(chunkInf + ".Z", p.getLocation().getChunk().getZ()); - - Configuration.saveBackupInfo(); - chunks.remove(p.getLocation().getChunk()); - } else { - chunks.add(p.getLocation().getChunk()); - Configuration.backupInfo.set(chunkInf, p.getLocation().getChunk().getWorld()); - - Configuration.saveBackupInfo(); - chunks.remove(p.getLocation().getChunk()); - } - } - } - - }); - } - } +package net.server_backup.core; + +import net.server_backup.Configuration; +import net.server_backup.ServerBackup; +import org.bukkit.Bukkit; +import org.bukkit.Chunk; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerMoveEvent; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.logging.Level; + +public class DynamicBackup implements Listener { + + List chunks = Collections.synchronizedList(new ArrayList<>()); + public boolean isSaving = false; + + @EventHandler + public void onPlayerMove(PlayerMoveEvent e) { + if (ServerBackup.getInstance().getConfig().getBoolean("DynamicBackup")) { + if (e.getFrom().getChunk() != e.getTo().getChunk()) { + int regX = e.getTo().getChunk().getX() >> 5; + int regZ = e.getTo().getChunk().getZ() >> 5; + + Bukkit.getScheduler().runTaskAsynchronously(ServerBackup.getInstance(), new Runnable() { + + @Override + public void run() { + String chunkInf = "Data." + e.getTo().getWorld().getName() + ".Chunk." + "r." + regX + "." + + regZ + ".mca"; + + if (!Bukkit.getWorldContainer().toString().equalsIgnoreCase(".")) { + chunkInf = "Data." + Bukkit.getWorldContainer() + "\\" + e.getTo().getWorld().getName() + + ".Chunk." + "r." + regX + "." + regZ + ".mca"; + } + + if (!chunks.contains(e.getTo().getChunk())) { + if (!Configuration.backupInfo.contains(chunkInf)) { + chunks.add(e.getTo().getChunk()); + Configuration.backupInfo.set(chunkInf, chunks.get(chunks.size() - 1).getX()); + Configuration.backupInfo.set(chunkInf, chunks.get(chunks.size() - 1).getZ()); + + saveChanges(); + try { + chunks.remove(e.getTo().getChunk()); + } catch (ArrayIndexOutOfBoundsException ex) { + } + } else { + chunks.add(e.getTo().getChunk()); + Configuration.backupInfo.set(chunkInf, chunks.get(chunks.size() - 1).getWorld()); + + saveChanges(); + try { + chunks.remove(e.getTo().getChunk()); + } catch (ArrayIndexOutOfBoundsException ex) { + } + } + } + } + + }); + } + } + } + + public void saveChanges() { + if (!isSaving) { + isSaving = true; + + Bukkit.getScheduler().runTaskLaterAsynchronously(ServerBackup.getInstance(), new Runnable() { + + @Override + public void run() { + Configuration.saveBackupInfo();; + if (ServerBackup.getInstance().getConfig().getBoolean("SendLogMessages")) { + Bukkit.getLogger().log(Level.INFO, "DynamicBP: file saved."); + } + + isSaving = false; + } + + }, 20 * 5); + } + } + + @EventHandler + public void onJoin(PlayerJoinEvent e) { + if (ServerBackup.getInstance().getConfig().getBoolean("DynamicBackup")) { + Player p = e.getPlayer(); + + int regX = p.getLocation().getChunk().getX() >> 5; + int regZ = p.getLocation().getChunk().getZ() >> 5; + + Bukkit.getScheduler().runTaskAsynchronously(ServerBackup.getInstance(), new Runnable() { + + @Override + public void run() { + String chunkInf = "Data." + p.getLocation().getWorld().getName() + ".Chunk." + "r." + regX + "." + + regZ + ".mca"; + + if (!Bukkit.getWorldContainer().toString().equalsIgnoreCase(".")) { + chunkInf = "Data." + Bukkit.getWorldContainer() + "\\" + p.getLocation().getWorld().getName() + + ".Chunk." + "r." + regX + "." + regZ + ".mca"; + } + + if (!chunks.contains(p.getLocation().getChunk())) { + if (!Configuration.backupInfo.contains(chunkInf)) { + chunks.add(p.getLocation().getChunk()); + Configuration.backupInfo.set(chunkInf + ".X", p.getLocation().getChunk().getX()); + Configuration.backupInfo.set(chunkInf + ".Z", p.getLocation().getChunk().getZ()); + + Configuration.saveBackupInfo(); + chunks.remove(p.getLocation().getChunk()); + } else { + chunks.add(p.getLocation().getChunk()); + Configuration.backupInfo.set(chunkInf, p.getLocation().getChunk().getWorld()); + + Configuration.saveBackupInfo(); + chunks.remove(p.getLocation().getChunk()); + } + } + } + + }); + } + } } \ No newline at end of file diff --git a/src/net/server_backup/core/OperationHandler.java b/src/main/java/net/server_backup/core/OperationHandler.java similarity index 97% rename from src/net/server_backup/core/OperationHandler.java rename to src/main/java/net/server_backup/core/OperationHandler.java index cc3e2c58..4990df04 100644 --- a/src/net/server_backup/core/OperationHandler.java +++ b/src/main/java/net/server_backup/core/OperationHandler.java @@ -1,92 +1,92 @@ -package net.server_backup.core; - -import net.server_backup.Configuration; -import net.server_backup.ServerBackup; -import org.bukkit.Bukkit; - -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.nio.channels.Channels; -import java.nio.channels.ReadableByteChannel; -import java.util.ArrayList; -import java.util.List; -import java.util.Scanner; -import java.util.logging.Level; - -public class OperationHandler { - - public static boolean shutdownProgress = false; - public static boolean isUpdated = false; - - public static List tasks = new ArrayList<>(); - - public static String processMessage(String msgCode) { - return (Configuration.prefix + Configuration.messages.getString(msgCode)).replace("&nl", "\n").replace("&", "§"); - } - - public static void startTimer() { - if (ServerBackup.getInstance().getConfig().getBoolean("AutomaticBackups")) { - Bukkit.getScheduler().runTaskTimerAsynchronously(ServerBackup.getInstance(), new Timer(), 20 * 20, 20 * 20); - } - } - - public static void stopTimer() { - Bukkit.getScheduler().cancelTasks(ServerBackup.getInstance()); - } - - public static void checkVersion() { - ServerBackup.getInstance().getLogger().log(Level.INFO, "ServerBackup: Searching for updates..."); - - Bukkit.getScheduler().runTaskAsynchronously(ServerBackup.getInstance(), () -> { - int resourceID = 79320; - try (InputStream inputStream = (new URL( - "https://api.spigotmc.org/legacy/update.php?resource=" + resourceID)).openStream(); - Scanner scanner = new Scanner(inputStream)) { - if (scanner.hasNext()) { - String latest = scanner.next(); - String current = ServerBackup.getInstance().getDescription().getVersion(); - - int late = Integer.parseInt(latest.replaceAll("\\.", "")); - int curr = Integer.parseInt(current.replaceAll("\\.", "")); - - if (curr >= late) { - ServerBackup.getInstance().getLogger().log(Level.INFO, - "ServerBackup: No updates found. The server is running the latest version."); - } else { - ServerBackup.getInstance().getLogger().log(Level.INFO, "ServerBackup: There is a newer version available - " + latest - + ", you are on - " + current); - - if (ServerBackup.getInstance().getConfig().getBoolean("AutomaticUpdates")) { - ServerBackup.getInstance().getLogger().log(Level.INFO, "ServerBackup: Downloading newest version..."); - - URL url = new URL("https://server-backup.net/assets/downloads/alt/ServerBackup.jar"); - - if (Bukkit.getVersion().contains("1.18") || Bukkit.getVersion().contains("1.19")) { - url = new URL("https://server-backup.net/assets/downloads/ServerBackup.jar"); - } - - try (InputStream in = url.openStream(); - ReadableByteChannel rbc = Channels.newChannel(in); - FileOutputStream fos = new FileOutputStream("plugins/ServerBackup.jar")) { - fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); - - ServerBackup.getInstance().getLogger().log(Level.INFO, - "ServerBackup: Download finished. Please reload the server to complete the update."); - - isUpdated = true; - } - } else { - ServerBackup.getInstance().getLogger().log(Level.INFO, - "ServerBackup: Please download the latest version - https://server-backup.net/"); - } - } - } - } catch (IOException exception) { - ServerBackup.getInstance().getLogger().log(Level.WARNING, - "ServerBackup: Cannot search for updates - " + exception.getMessage()); - } - }); - } -} +package net.server_backup.core; + +import net.server_backup.Configuration; +import net.server_backup.ServerBackup; +import org.bukkit.Bukkit; + +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.nio.channels.Channels; +import java.nio.channels.ReadableByteChannel; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; +import java.util.logging.Level; + +public class OperationHandler { + + public static boolean shutdownProgress = false; + public static boolean isUpdated = false; + + public static List tasks = new ArrayList<>(); + + public static String processMessage(String msgCode) { + return (Configuration.prefix + Configuration.messages.getString(msgCode)).replace("&nl", "\n").replace("&", "§"); + } + + public static void startTimer() { + if (ServerBackup.getInstance().getConfig().getBoolean("AutomaticBackups")) { + Bukkit.getScheduler().runTaskTimerAsynchronously(ServerBackup.getInstance(), new Timer(), 20 * 20, 20 * 20); + } + } + + public static void stopTimer() { + Bukkit.getScheduler().cancelTasks(ServerBackup.getInstance()); + } + + public static void checkVersion() { + ServerBackup.getInstance().getLogger().log(Level.INFO, "ServerBackup: Searching for updates..."); + + Bukkit.getScheduler().runTaskAsynchronously(ServerBackup.getInstance(), () -> { + int resourceID = 79320; + try (InputStream inputStream = (new URL( + "https://api.spigotmc.org/legacy/update.php?resource=" + resourceID)).openStream(); + Scanner scanner = new Scanner(inputStream)) { + if (scanner.hasNext()) { + String latest = scanner.next(); + String current = ServerBackup.getInstance().getDescription().getVersion(); + + int late = Integer.parseInt(latest.replaceAll("\\.", "")); + int curr = Integer.parseInt(current.replaceAll("\\.", "")); + + if (curr >= late) { + ServerBackup.getInstance().getLogger().log(Level.INFO, + "ServerBackup: No updates found. The server is running the latest version."); + } else { + ServerBackup.getInstance().getLogger().log(Level.INFO, "ServerBackup: There is a newer version available - " + latest + + ", you are on - " + current); + + if (ServerBackup.getInstance().getConfig().getBoolean("AutomaticUpdates")) { + ServerBackup.getInstance().getLogger().log(Level.INFO, "ServerBackup: Downloading newest version..."); + + URL url = new URL("https://server-backup.net/assets/downloads/alt/ServerBackup.jar"); + + if (Bukkit.getVersion().contains("1.18") || Bukkit.getVersion().contains("1.19")) { + url = new URL("https://server-backup.net/assets/downloads/ServerBackup.jar"); + } + + try (InputStream in = url.openStream(); + ReadableByteChannel rbc = Channels.newChannel(in); + FileOutputStream fos = new FileOutputStream("plugins/ServerBackup.jar")) { + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + + ServerBackup.getInstance().getLogger().log(Level.INFO, + "ServerBackup: Download finished. Please reload the server to complete the update."); + + isUpdated = true; + } + } else { + ServerBackup.getInstance().getLogger().log(Level.INFO, + "ServerBackup: Please download the latest version - https://server-backup.net/"); + } + } + } + } catch (IOException exception) { + ServerBackup.getInstance().getLogger().log(Level.WARNING, + "ServerBackup: Cannot search for updates - " + exception.getMessage()); + } + }); + } +} diff --git a/src/net/server_backup/core/Timer.java b/src/main/java/net/server_backup/core/Timer.java similarity index 97% rename from src/net/server_backup/core/Timer.java rename to src/main/java/net/server_backup/core/Timer.java index 6413e168..4473a1fd 100644 --- a/src/net/server_backup/core/Timer.java +++ b/src/main/java/net/server_backup/core/Timer.java @@ -1,191 +1,191 @@ -package net.server_backup.core; - -import net.server_backup.Configuration; -import net.server_backup.ServerBackup; -import org.bukkit.Bukkit; - -import java.io.File; -import java.time.LocalDate; -import java.util.*; -import java.util.logging.Level; - -public class Timer implements Runnable { - - List worlds = ServerBackup.getInstance().getConfig().getStringList("BackupWorlds"); - List days = ServerBackup.getInstance().getConfig().getStringList("BackupTimer.Days"); - List times = ServerBackup.getInstance().getConfig().getStringList("BackupTimer.Times"); - - Calendar cal = Calendar.getInstance(); - - short checkMinute = 0; - - @Override - public void run() { - cal = Calendar.getInstance(); - - if (ServerBackup.getInstance().getConfig().getBoolean("AutomaticBackups")) { - short timeCode = (short) (cal.get(Calendar.HOUR_OF_DAY) * 100 + cal.get(Calendar.MINUTE)); - - if (checkMinute != timeCode) { - checkMinute = timeCode; - - boolean isBackupDay = days.stream().filter(d -> d.equalsIgnoreCase(getDayName(cal.get(Calendar.DAY_OF_WEEK)))) - .findFirst().isPresent(); - - if (isBackupDay) { - for (String time : times) { - try { - String[] timeStr = time.split("-"); - - if (timeStr[0].startsWith("0")) { - timeStr[0] = timeStr[0].substring(1); - } - - if (timeStr[1].startsWith("0")) { - timeStr[1] = timeStr[1].substring(1); - } - - byte hour = Byte.valueOf(timeStr[0]); - byte minute = Byte.valueOf(timeStr[1]); - - if ((byte) cal.get(Calendar.HOUR_OF_DAY) == hour && (byte) cal.get(Calendar.MINUTE) == minute) { - for (String world : worlds) { - Backup backup = new Backup(world, Bukkit.getConsoleSender(), - !ServerBackup.getInstance().getConfig().getBoolean("DynamicBackup")); - backup.create(); - } - } - } catch (Exception e) { - ServerBackup.getInstance().getLogger().log(Level.WARNING, - "ServerBackup: Automatic Backup failed. Please check that you set the BackupTimer correctly."); - } - } - } - } - } - - if (ServerBackup.getInstance().getConfig().getInt("BackupLimiter") <= 0) { - if (cal.get(Calendar.HOUR_OF_DAY) == 0 && cal.get(Calendar.MINUTE) == 0) { - if (ServerBackup.getInstance().getConfig().getInt("DeleteOldBackups") <= 0) - return; - - File[] backups = new File(Configuration.backupDestination + "").listFiles(); - - if (backups.length == 0) - return; - - Arrays.sort(backups, Collections.reverseOrder()); - - LocalDate date = LocalDate.now() - .minusDays(ServerBackup.getInstance().getConfig().getInt("DeleteOldBackups")); - - ServerBackup.getInstance().getLogger().log(Level.INFO, ""); - ServerBackup.getInstance().getLogger().log(Level.INFO, "ServerBackup | Backup deletion started..."); - ServerBackup.getInstance().getLogger().log(Level.INFO, ""); - - long time = System.currentTimeMillis(); - - List backupNames = new ArrayList<>(); - - for (int i = 0; i < backups.length; i++) { - try { - String[] backupDateStr = backups[i].getName().split("-"); - LocalDate backupDate = LocalDate.parse( - backupDateStr[1] + "-" + backupDateStr[2] + "-" + backupDateStr[3].split("~")[0]); - String backupName = backupDateStr[6]; - - if (ServerBackup.getInstance().getConfig().getBoolean("KeepUniqueBackups")) { - if (!backupNames.contains(backupName)) { - backupNames.add(backupName); - continue; - } - } - - if (backupDate.isBefore(date.plusDays(1))) { - if (backups[i].exists()) { - backups[i].delete(); - - ServerBackup.getInstance().getLogger().log(Level.INFO, - "Backup [" + backups[i].getName() + "] removed."); - } else { - ServerBackup.getInstance().getLogger().log(Level.WARNING, - "No Backup named '" + backups[i].getName() + "' found."); - } - } - } catch (Exception e) { - } - } - - ServerBackup.getInstance().getLogger().log(Level.INFO, ""); - ServerBackup.getInstance().getLogger().log(Level.INFO, "ServerBackup | Backup deletion finished. [" - + Long.valueOf(System.currentTimeMillis() - time) + "ms]"); - ServerBackup.getInstance().getLogger().log(Level.INFO, ""); - } - } else { - File[] backups = new File(Configuration.backupDestination + "").listFiles(); - Arrays.sort(backups); - - int dobc = ServerBackup.getInstance().getConfig().getInt("BackupLimiter"); - int c = 0; - - while (backups.length > dobc) { - if (backups[c].exists()) { - backups[c].delete(); - - ServerBackup.getInstance().getLogger().log(Level.INFO, - "Backup [" + backups[c].getName() + "] removed."); - } else { - ServerBackup.getInstance().getLogger().log(Level.WARNING, - "No Backup named '" + backups[c].getName() + "' found."); - } - - c++; - dobc++; - } - } - - if (OperationHandler.shutdownProgress) { - if (OperationHandler.tasks.size() == 0) { - ServerBackup.getInstance().getLogger().log(Level.INFO, - "Backup tasks finished. Shutting down server..."); - - Bukkit.shutdown(); - } - } - } - - private String getDayName(int dayNumber) { - if (dayNumber == 1) { - return "SUNDAY"; - } - - if (dayNumber == 2) { - return "MONDAY"; - } - - if (dayNumber == 3) { - return "TUESDAY"; - } - - if (dayNumber == 4) { - return "WEDNESDAY"; - } - - if (dayNumber == 5) { - return "THURSDAY"; - } - - if (dayNumber == 6) { - return "FRIDAY"; - } - - if (dayNumber == 7) { - return "SATURDAY"; - } - - Bukkit.getLogger().log(Level.WARNING, "Error while converting number in day."); - - return null; - } - +package net.server_backup.core; + +import net.server_backup.Configuration; +import net.server_backup.ServerBackup; +import org.bukkit.Bukkit; + +import java.io.File; +import java.time.LocalDate; +import java.util.*; +import java.util.logging.Level; + +public class Timer implements Runnable { + + List worlds = ServerBackup.getInstance().getConfig().getStringList("BackupWorlds"); + List days = ServerBackup.getInstance().getConfig().getStringList("BackupTimer.Days"); + List times = ServerBackup.getInstance().getConfig().getStringList("BackupTimer.Times"); + + Calendar cal = Calendar.getInstance(); + + short checkMinute = 0; + + @Override + public void run() { + cal = Calendar.getInstance(); + + if (ServerBackup.getInstance().getConfig().getBoolean("AutomaticBackups")) { + short timeCode = (short) (cal.get(Calendar.HOUR_OF_DAY) * 100 + cal.get(Calendar.MINUTE)); + + if (checkMinute != timeCode) { + checkMinute = timeCode; + + boolean isBackupDay = days.stream().filter(d -> d.equalsIgnoreCase(getDayName(cal.get(Calendar.DAY_OF_WEEK)))) + .findFirst().isPresent(); + + if (isBackupDay) { + for (String time : times) { + try { + String[] timeStr = time.split("-"); + + if (timeStr[0].startsWith("0")) { + timeStr[0] = timeStr[0].substring(1); + } + + if (timeStr[1].startsWith("0")) { + timeStr[1] = timeStr[1].substring(1); + } + + byte hour = Byte.valueOf(timeStr[0]); + byte minute = Byte.valueOf(timeStr[1]); + + if ((byte) cal.get(Calendar.HOUR_OF_DAY) == hour && (byte) cal.get(Calendar.MINUTE) == minute) { + for (String world : worlds) { + Backup backup = new Backup(world, Bukkit.getConsoleSender(), + !ServerBackup.getInstance().getConfig().getBoolean("DynamicBackup")); + backup.create(); + } + } + } catch (Exception e) { + ServerBackup.getInstance().getLogger().log(Level.WARNING, + "ServerBackup: Automatic Backup failed. Please check that you set the BackupTimer correctly."); + } + } + } + } + } + + if (ServerBackup.getInstance().getConfig().getInt("BackupLimiter") <= 0) { + if (cal.get(Calendar.HOUR_OF_DAY) == 0 && cal.get(Calendar.MINUTE) == 0) { + if (ServerBackup.getInstance().getConfig().getInt("DeleteOldBackups") <= 0) + return; + + File[] backups = new File(Configuration.backupDestination + "").listFiles(); + + if (backups.length == 0) + return; + + Arrays.sort(backups, Collections.reverseOrder()); + + LocalDate date = LocalDate.now() + .minusDays(ServerBackup.getInstance().getConfig().getInt("DeleteOldBackups")); + + ServerBackup.getInstance().getLogger().log(Level.INFO, ""); + ServerBackup.getInstance().getLogger().log(Level.INFO, "ServerBackup | Backup deletion started..."); + ServerBackup.getInstance().getLogger().log(Level.INFO, ""); + + long time = System.currentTimeMillis(); + + List backupNames = new ArrayList<>(); + + for (int i = 0; i < backups.length; i++) { + try { + String[] backupDateStr = backups[i].getName().split("-"); + LocalDate backupDate = LocalDate.parse( + backupDateStr[1] + "-" + backupDateStr[2] + "-" + backupDateStr[3].split("~")[0]); + String backupName = backupDateStr[6]; + + if (ServerBackup.getInstance().getConfig().getBoolean("KeepUniqueBackups")) { + if (!backupNames.contains(backupName)) { + backupNames.add(backupName); + continue; + } + } + + if (backupDate.isBefore(date.plusDays(1))) { + if (backups[i].exists()) { + backups[i].delete(); + + ServerBackup.getInstance().getLogger().log(Level.INFO, + "Backup [" + backups[i].getName() + "] removed."); + } else { + ServerBackup.getInstance().getLogger().log(Level.WARNING, + "No Backup named '" + backups[i].getName() + "' found."); + } + } + } catch (Exception e) { + } + } + + ServerBackup.getInstance().getLogger().log(Level.INFO, ""); + ServerBackup.getInstance().getLogger().log(Level.INFO, "ServerBackup | Backup deletion finished. [" + + Long.valueOf(System.currentTimeMillis() - time) + "ms]"); + ServerBackup.getInstance().getLogger().log(Level.INFO, ""); + } + } else { + File[] backups = new File(Configuration.backupDestination + "").listFiles(); + Arrays.sort(backups); + + int dobc = ServerBackup.getInstance().getConfig().getInt("BackupLimiter"); + int c = 0; + + while (backups.length > dobc) { + if (backups[c].exists()) { + backups[c].delete(); + + ServerBackup.getInstance().getLogger().log(Level.INFO, + "Backup [" + backups[c].getName() + "] removed."); + } else { + ServerBackup.getInstance().getLogger().log(Level.WARNING, + "No Backup named '" + backups[c].getName() + "' found."); + } + + c++; + dobc++; + } + } + + if (OperationHandler.shutdownProgress) { + if (OperationHandler.tasks.size() == 0) { + ServerBackup.getInstance().getLogger().log(Level.INFO, + "Backup tasks finished. Shutting down server..."); + + Bukkit.shutdown(); + } + } + } + + private String getDayName(int dayNumber) { + if (dayNumber == 1) { + return "SUNDAY"; + } + + if (dayNumber == 2) { + return "MONDAY"; + } + + if (dayNumber == 3) { + return "TUESDAY"; + } + + if (dayNumber == 4) { + return "WEDNESDAY"; + } + + if (dayNumber == 5) { + return "THURSDAY"; + } + + if (dayNumber == 6) { + return "FRIDAY"; + } + + if (dayNumber == 7) { + return "SATURDAY"; + } + + Bukkit.getLogger().log(Level.WARNING, "Error while converting number in day."); + + return null; + } + } \ No newline at end of file diff --git a/src/net/server_backup/core/ZipManager.java b/src/main/java/net/server_backup/core/ZipManager.java similarity index 97% rename from src/net/server_backup/core/ZipManager.java rename to src/main/java/net/server_backup/core/ZipManager.java index f0f30053..aef209bf 100644 --- a/src/net/server_backup/core/ZipManager.java +++ b/src/main/java/net/server_backup/core/ZipManager.java @@ -1,276 +1,276 @@ -package net.server_backup.core; - -import net.server_backup.Configuration; -import net.server_backup.ServerBackup; -import net.server_backup.utils.DropboxManager; -import net.server_backup.utils.FtpManager; -import org.apache.commons.io.FileUtils; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.logging.Level; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; -import java.util.zip.ZipOutputStream; - -public class ZipManager { - - private final String sourceFilePath; - private String targetFilePath; - private final CommandSender sender; - private final boolean sendDebugMessage; - private final boolean isSaving; - private final boolean isFullBackup; - - private static boolean isCommandTimerRunning = false; - - public ZipManager(String sourceFilePath, String targetFilePath, CommandSender sender, boolean sendDebugMessage, - boolean isSaving, boolean isFullBackup) { - this.sourceFilePath = sourceFilePath; - this.targetFilePath = targetFilePath; - this.sender = sender; - this.sendDebugMessage = sendDebugMessage; - this.isSaving = isSaving; - this.isFullBackup = isFullBackup; - } - - public void zip() throws IOException { - Bukkit.getScheduler().runTaskAsynchronously(ServerBackup.getInstance(), () -> { - long sTime = System.nanoTime(); - - Bukkit.getLogger().log(Level.INFO, ""); - Bukkit.getLogger().log(Level.INFO, "ServerBackup | Start zipping..."); - Bukkit.getLogger().log(Level.INFO, ""); - - Path p; - try { - p = Files.createFile(Paths.get(targetFilePath)); - } catch (IOException e) { - e.printStackTrace(); - Bukkit.getLogger().log(Level.WARNING, "Error while zipping files."); - return; - } - - try (ZipOutputStream zs = new ZipOutputStream(Files.newOutputStream(p))) { - Path pp = Paths.get(sourceFilePath); - Files.walk(pp).filter(path -> !Files.isDirectory(path)).forEach(path -> { - if (!path.toString().contains(ServerBackup.getInstance().getConfig().getString("BackupDestination") - .replaceAll("/", "")) || !isSaving) { - ZipEntry zipEntry = new ZipEntry(pp.relativize(path).toString()); - - for (String blacklist : ServerBackup.getInstance().getConfig().getStringList("Blacklist")) { - File bl = new File(blacklist); - - if (bl.isDirectory()) { - if (path.toFile().getParent().toString().startsWith(bl.toString()) - || path.toFile().getParent().toString().startsWith(".\\" + bl.toString())) { - return; - } - } else { - if (path.equals(new File(blacklist).toPath()) - || path.equals(new File(".\\" + blacklist).toPath())) { - sender.sendMessage("Found '" + path + "' in blacklist. Skipping file."); - return; - } - } - } - - if (!isFullBackup) { - if (ServerBackup.getInstance().getConfig().getBoolean("DynamicBackup")) { - if (path.getParent().toString().endsWith("region") - || path.getParent().toString().endsWith("entities") - || path.getParent().toString().endsWith("poi")) { - boolean found = false; - if (Configuration.backupInfo - .contains("Data." + path.getParent().getParent().toString() + ".Chunk." - + path.getFileName().toString())) { - found = true; - } - - if (!found) - return; - } - } - } - - try { - if (sendDebugMessage) { - if (ServerBackup.getInstance().getConfig().getBoolean("SendLogMessages")) { - ServerBackup.getInstance().getLogger().log(Level.INFO, - "Zipping '" + path + "'"); - - if (Bukkit.getConsoleSender() != sender) { - sender.sendMessage("Zipping '" + path); - } - } - } - - zs.putNextEntry(zipEntry); - - if (System.getProperty("os.name").startsWith("Windows") - && path.toString().contains("session.lock")) { - } else { - try { - Files.copy(path, zs); - } catch (IOException e) { - e.printStackTrace(); - } - } - - zs.closeEntry(); - } catch (IOException e) { - e.printStackTrace(); - ServerBackup.getInstance().getLogger().log(Level.WARNING, "Error while zipping files."); - } - } - }); - } catch (IOException e) { - e.printStackTrace(); - ServerBackup.getInstance().getLogger().log(Level.WARNING, "Error while zipping files."); - return; - } - - long time = (System.nanoTime() - sTime) / 1000000; - - ServerBackup.getInstance().getLogger().log(Level.INFO, ""); - ServerBackup.getInstance().getLogger().log(Level.INFO, "ServerBackup | Files zipped. [" + time + "ms]"); - ServerBackup.getInstance().getLogger().log(Level.INFO, ""); - - if (!isSaving) { - File file = new File(sourceFilePath); - - try { - FileUtils.deleteDirectory(file); - } catch (IOException e) { - e.printStackTrace(); - } - } - - sender.sendMessage(OperationHandler.processMessage("Command.Zip.Footer").replaceAll("%file%", sourceFilePath)); - - OperationHandler.tasks.remove("CREATE {" + sourceFilePath.replace("\\", "/") + "}"); - - if (!isFullBackup) { - if (ServerBackup.getInstance().getConfig().getBoolean("DynamicBackup")) { - if (!sourceFilePath.equalsIgnoreCase(".")) { - Configuration.backupInfo.set("Data." + sourceFilePath, ""); - - new File(targetFilePath).renameTo(new File(targetFilePath.split("backup")[0] + "dynamic-backup" - + targetFilePath.split("backup")[1])); - targetFilePath = targetFilePath.split("backup")[0] + "dynamic-backup" - + targetFilePath.split("backup")[1]; - - Configuration.saveBackupInfo(); - } - } - } - - if (ServerBackup.getInstance().getConfig().getBoolean("Ftp.UploadBackup")) { - FtpManager ftpm = new FtpManager(sender); - ftpm.uploadFileToFtp(targetFilePath, false); - } - - if (ServerBackup.getInstance().getConfig().getBoolean("CloudBackup.Dropbox")) { - DropboxManager dm = new DropboxManager(sender); - dm.uploadToDropbox(targetFilePath); - } - - for (Player all : Bukkit.getOnlinePlayers()) { - if (all.hasPermission("backup.notification")) { - all.sendMessage(OperationHandler.processMessage("Info.BackupFinished").replaceAll("%file%", sourceFilePath)); - } - } - }); - - if (ServerBackup.getInstance().getConfig().getString("CommandAfterAutomaticBackup") != null && !isCommandTimerRunning) { - if (!ServerBackup.getInstance().getConfig().getString("CommandAfterAutomaticBackup").equalsIgnoreCase("/")) { - isCommandTimerRunning = true; - - new BukkitRunnable() { - @Override - public void run() { - if (OperationHandler.tasks.size() == 0) { - Bukkit.dispatchCommand(Bukkit.getConsoleSender(), ServerBackup.getInstance().getConfig().getString("CommandAfterAutomaticBackup").replaceAll("/", "")); - - isCommandTimerRunning = false; - - cancel(); - } - } - }.runTaskTimer(ServerBackup.getInstance(), 20 * 5, 20 * 5); - } - } - } - - public void unzip() { - Bukkit.getScheduler().runTaskAsynchronously(ServerBackup.getInstance(), () -> { - - long sTime = System.nanoTime(); - - ServerBackup.getInstance().getLogger().log(Level.INFO, ""); - ServerBackup.getInstance().getLogger().log(Level.INFO, "ServerBackup | Start unzipping..."); - ServerBackup.getInstance().getLogger().log(Level.INFO, ""); - - byte[] buffer = new byte[1024]; - try { - File folder = new File(targetFilePath); - if (!folder.exists()) { - folder.mkdir(); - } - ZipInputStream zis = new ZipInputStream(new FileInputStream(sourceFilePath)); - ZipEntry ze = zis.getNextEntry(); - while (ze != null) { - String fileName = ze.getName(); - File newFile = new File(targetFilePath + File.separator + fileName); - - if (sendDebugMessage) { - if (ServerBackup.getInstance().getConfig().getBoolean("SendLogMessages")) { - ServerBackup.getInstance().getLogger().log(Level.INFO, "Unzipping '" + newFile.getPath()); - - if (Bukkit.getConsoleSender() != sender) { - sender.sendMessage("Unzipping '" + newFile.getPath()); - } - } - } - - new File(newFile.getParent()).mkdirs(); - FileOutputStream fos = new FileOutputStream(newFile); - int len; - while ((len = zis.read(buffer)) > 0) { - fos.write(buffer, 0, len); - } - fos.close(); - ze = zis.getNextEntry(); - } - zis.closeEntry(); - zis.close(); - } catch (IOException e) { - e.printStackTrace(); - ServerBackup.getInstance().getLogger().log(Level.WARNING, "Error while unzipping files."); - return; - } - - long time = (System.nanoTime() - sTime) / 1000000; - - ServerBackup.getInstance().getLogger().log(Level.INFO, ""); - ServerBackup.getInstance().getLogger().log(Level.INFO, "ServerBackup | Files unzipped. [" + time + "ms]"); - ServerBackup.getInstance().getLogger().log(Level.INFO, ""); - - File file = new File(sourceFilePath); - - file.delete(); - - sender.sendMessage(OperationHandler.processMessage("Command.Unzip.Footer").replaceAll("%file%", sourceFilePath)); - }); - } - -} +package net.server_backup.core; + +import net.server_backup.Configuration; +import net.server_backup.ServerBackup; +import net.server_backup.utils.DropboxManager; +import net.server_backup.utils.FtpManager; +import org.apache.commons.io.FileUtils; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.logging.Level; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; +import java.util.zip.ZipOutputStream; + +public class ZipManager { + + private final String sourceFilePath; + private String targetFilePath; + private final CommandSender sender; + private final boolean sendDebugMessage; + private final boolean isSaving; + private final boolean isFullBackup; + + private static boolean isCommandTimerRunning = false; + + public ZipManager(String sourceFilePath, String targetFilePath, CommandSender sender, boolean sendDebugMessage, + boolean isSaving, boolean isFullBackup) { + this.sourceFilePath = sourceFilePath; + this.targetFilePath = targetFilePath; + this.sender = sender; + this.sendDebugMessage = sendDebugMessage; + this.isSaving = isSaving; + this.isFullBackup = isFullBackup; + } + + public void zip() throws IOException { + Bukkit.getScheduler().runTaskAsynchronously(ServerBackup.getInstance(), () -> { + long sTime = System.nanoTime(); + + Bukkit.getLogger().log(Level.INFO, ""); + Bukkit.getLogger().log(Level.INFO, "ServerBackup | Start zipping..."); + Bukkit.getLogger().log(Level.INFO, ""); + + Path p; + try { + p = Files.createFile(Paths.get(targetFilePath)); + } catch (IOException e) { + e.printStackTrace(); + Bukkit.getLogger().log(Level.WARNING, "Error while zipping files."); + return; + } + + try (ZipOutputStream zs = new ZipOutputStream(Files.newOutputStream(p))) { + Path pp = Paths.get(sourceFilePath); + Files.walk(pp).filter(path -> !Files.isDirectory(path)).forEach(path -> { + if (!path.toString().contains(ServerBackup.getInstance().getConfig().getString("BackupDestination") + .replaceAll("/", "")) || !isSaving) { + ZipEntry zipEntry = new ZipEntry(pp.relativize(path).toString()); + + for (String blacklist : ServerBackup.getInstance().getConfig().getStringList("Blacklist")) { + File bl = new File(blacklist); + + if (bl.isDirectory()) { + if (path.toFile().getParent().toString().startsWith(bl.toString()) + || path.toFile().getParent().toString().startsWith(".\\" + bl.toString())) { + return; + } + } else { + if (path.equals(new File(blacklist).toPath()) + || path.equals(new File(".\\" + blacklist).toPath())) { + sender.sendMessage("Found '" + path + "' in blacklist. Skipping file."); + return; + } + } + } + + if (!isFullBackup) { + if (ServerBackup.getInstance().getConfig().getBoolean("DynamicBackup")) { + if (path.getParent().toString().endsWith("region") + || path.getParent().toString().endsWith("entities") + || path.getParent().toString().endsWith("poi")) { + boolean found = false; + if (Configuration.backupInfo + .contains("Data." + path.getParent().getParent().toString() + ".Chunk." + + path.getFileName().toString())) { + found = true; + } + + if (!found) + return; + } + } + } + + try { + if (sendDebugMessage) { + if (ServerBackup.getInstance().getConfig().getBoolean("SendLogMessages")) { + ServerBackup.getInstance().getLogger().log(Level.INFO, + "Zipping '" + path + "'"); + + if (Bukkit.getConsoleSender() != sender) { + sender.sendMessage("Zipping '" + path); + } + } + } + + zs.putNextEntry(zipEntry); + + if (System.getProperty("os.name").startsWith("Windows") + && path.toString().contains("session.lock")) { + } else { + try { + Files.copy(path, zs); + } catch (IOException e) { + e.printStackTrace(); + } + } + + zs.closeEntry(); + } catch (IOException e) { + e.printStackTrace(); + ServerBackup.getInstance().getLogger().log(Level.WARNING, "Error while zipping files."); + } + } + }); + } catch (IOException e) { + e.printStackTrace(); + ServerBackup.getInstance().getLogger().log(Level.WARNING, "Error while zipping files."); + return; + } + + long time = (System.nanoTime() - sTime) / 1000000; + + ServerBackup.getInstance().getLogger().log(Level.INFO, ""); + ServerBackup.getInstance().getLogger().log(Level.INFO, "ServerBackup | Files zipped. [" + time + "ms]"); + ServerBackup.getInstance().getLogger().log(Level.INFO, ""); + + if (!isSaving) { + File file = new File(sourceFilePath); + + try { + FileUtils.deleteDirectory(file); + } catch (IOException e) { + e.printStackTrace(); + } + } + + sender.sendMessage(OperationHandler.processMessage("Command.Zip.Footer").replaceAll("%file%", sourceFilePath)); + + OperationHandler.tasks.remove("CREATE {" + sourceFilePath.replace("\\", "/") + "}"); + + if (!isFullBackup) { + if (ServerBackup.getInstance().getConfig().getBoolean("DynamicBackup")) { + if (!sourceFilePath.equalsIgnoreCase(".")) { + Configuration.backupInfo.set("Data." + sourceFilePath, ""); + + new File(targetFilePath).renameTo(new File(targetFilePath.split("backup")[0] + "dynamic-backup" + + targetFilePath.split("backup")[1])); + targetFilePath = targetFilePath.split("backup")[0] + "dynamic-backup" + + targetFilePath.split("backup")[1]; + + Configuration.saveBackupInfo(); + } + } + } + + if (ServerBackup.getInstance().getConfig().getBoolean("Ftp.UploadBackup")) { + FtpManager ftpm = new FtpManager(sender); + ftpm.uploadFileToFtp(targetFilePath, false); + } + + if (ServerBackup.getInstance().getConfig().getBoolean("CloudBackup.Dropbox")) { + DropboxManager dm = new DropboxManager(sender); + dm.uploadToDropbox(targetFilePath); + } + + for (Player all : Bukkit.getOnlinePlayers()) { + if (all.hasPermission("backup.notification")) { + all.sendMessage(OperationHandler.processMessage("Info.BackupFinished").replaceAll("%file%", sourceFilePath)); + } + } + }); + + if (ServerBackup.getInstance().getConfig().getString("CommandAfterAutomaticBackup") != null && !isCommandTimerRunning) { + if (!ServerBackup.getInstance().getConfig().getString("CommandAfterAutomaticBackup").equalsIgnoreCase("/")) { + isCommandTimerRunning = true; + + new BukkitRunnable() { + @Override + public void run() { + if (OperationHandler.tasks.size() == 0) { + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), ServerBackup.getInstance().getConfig().getString("CommandAfterAutomaticBackup").replaceAll("/", "")); + + isCommandTimerRunning = false; + + cancel(); + } + } + }.runTaskTimer(ServerBackup.getInstance(), 20 * 5, 20 * 5); + } + } + } + + public void unzip() { + Bukkit.getScheduler().runTaskAsynchronously(ServerBackup.getInstance(), () -> { + + long sTime = System.nanoTime(); + + ServerBackup.getInstance().getLogger().log(Level.INFO, ""); + ServerBackup.getInstance().getLogger().log(Level.INFO, "ServerBackup | Start unzipping..."); + ServerBackup.getInstance().getLogger().log(Level.INFO, ""); + + byte[] buffer = new byte[1024]; + try { + File folder = new File(targetFilePath); + if (!folder.exists()) { + folder.mkdir(); + } + ZipInputStream zis = new ZipInputStream(new FileInputStream(sourceFilePath)); + ZipEntry ze = zis.getNextEntry(); + while (ze != null) { + String fileName = ze.getName(); + File newFile = new File(targetFilePath + File.separator + fileName); + + if (sendDebugMessage) { + if (ServerBackup.getInstance().getConfig().getBoolean("SendLogMessages")) { + ServerBackup.getInstance().getLogger().log(Level.INFO, "Unzipping '" + newFile.getPath()); + + if (Bukkit.getConsoleSender() != sender) { + sender.sendMessage("Unzipping '" + newFile.getPath()); + } + } + } + + new File(newFile.getParent()).mkdirs(); + FileOutputStream fos = new FileOutputStream(newFile); + int len; + while ((len = zis.read(buffer)) > 0) { + fos.write(buffer, 0, len); + } + fos.close(); + ze = zis.getNextEntry(); + } + zis.closeEntry(); + zis.close(); + } catch (IOException e) { + e.printStackTrace(); + ServerBackup.getInstance().getLogger().log(Level.WARNING, "Error while unzipping files."); + return; + } + + long time = (System.nanoTime() - sTime) / 1000000; + + ServerBackup.getInstance().getLogger().log(Level.INFO, ""); + ServerBackup.getInstance().getLogger().log(Level.INFO, "ServerBackup | Files unzipped. [" + time + "ms]"); + ServerBackup.getInstance().getLogger().log(Level.INFO, ""); + + File file = new File(sourceFilePath); + + file.delete(); + + sender.sendMessage(OperationHandler.processMessage("Command.Unzip.Footer").replaceAll("%file%", sourceFilePath)); + }); + } + +} diff --git a/src/net/server_backup/listeners/JoinListener.java b/src/main/java/net/server_backup/listeners/JoinListener.java similarity index 98% rename from src/net/server_backup/listeners/JoinListener.java rename to src/main/java/net/server_backup/listeners/JoinListener.java index 466fd8e0..967c7902 100644 --- a/src/net/server_backup/listeners/JoinListener.java +++ b/src/main/java/net/server_backup/listeners/JoinListener.java @@ -1,107 +1,107 @@ -package net.server_backup.listeners; - -import net.server_backup.ServerBackup; -import net.server_backup.core.OperationHandler; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; - -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.nio.channels.Channels; -import java.nio.channels.ReadableByteChannel; -import java.util.Scanner; - -public class JoinListener implements Listener { - - @EventHandler - public void onJoin(PlayerJoinEvent e) { - Player p = e.getPlayer(); - - if (p.hasPermission("backup.update")) { - if (ServerBackup.getInstance().getConfig().getBoolean("UpdateAvailableMessage")) { - Bukkit.getScheduler().runTaskAsynchronously(ServerBackup.getInstance(), () -> { - int resourceID = 79320; - try (InputStream inputStream = (new URL( - "https://api.spigotmc.org/legacy/update.php?resource=" + resourceID)).openStream(); - Scanner scanner = new Scanner(inputStream)) { - if (scanner.hasNext()) { - String latest = scanner.next(); - String current = ServerBackup.getInstance().getDescription().getVersion(); - - int late = Integer.parseInt(latest.replaceAll("\\.", "")); - int curr = Integer.parseInt(current.replaceAll("\\.", "")); - - if (curr >= late) { - } else { - if (OperationHandler.isUpdated) { - p.sendMessage("§8=====§fServerBackup§8====="); - p.sendMessage(""); - p.sendMessage("§7There was a newer version available - §a" + latest - + "§7, you are on - §c" + current); - p.sendMessage( - "\n§7The latest version has been downloaded automatically, please reload the server to complete the update."); - p.sendMessage(""); - p.sendMessage("§8=====§9Plugin by Seblii§8====="); - } else { - if (ServerBackup.getInstance().getConfig().getBoolean("AutomaticUpdates")) { - if (p.hasPermission("backup.admin")) { - p.sendMessage("§8=====§fServerBackup§8====="); - p.sendMessage(""); - p.sendMessage("§7There is a newer version available - §a" + latest - + "§7, you are on - §c" + current); - p.sendMessage(""); - p.sendMessage("§8=====§9Plugin by Seblii§8====="); - p.sendMessage(""); - p.sendMessage("ServerBackup§7: Automatic update started..."); - - URL url = new URL( - "https://server-backup.net/assets/downloads/ServerBackup.jar"); - - int bVer = Integer.parseInt( - Bukkit.getVersion().split(" ")[Bukkit.getVersion().split(" ").length - - 1].replaceAll("\\)", "").replaceAll("\\.", "")); - - if (bVer < 118) { - url = new URL( - "https://server-backup.net/assets/downloads/alt/ServerBackup.jar"); - } - - try (InputStream in = url.openStream(); - ReadableByteChannel rbc = Channels.newChannel(in); - FileOutputStream fos = new FileOutputStream( - "plugins/ServerBackup.jar")) { - fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); - - p.sendMessage( - "ServerBackup§7: Download finished. Please reload the server to complete the update."); - - OperationHandler.isUpdated = true; - } - } - } else { - p.sendMessage("§8=====§fServerBackup§8====="); - p.sendMessage(""); - p.sendMessage("§7There is a newer version available - §a" + latest - + "§7, you are on - §c" + current); - p.sendMessage( - "§7Please download the latest version - §4https://server-backup.net/"); - p.sendMessage(""); - p.sendMessage("§8=====§9Plugin by Seblii§8====="); - } - } - } - } - } catch (IOException exception) { - exception.printStackTrace(); - } - }); - } - } - } - -} +package net.server_backup.listeners; + +import net.server_backup.ServerBackup; +import net.server_backup.core.OperationHandler; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; + +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.nio.channels.Channels; +import java.nio.channels.ReadableByteChannel; +import java.util.Scanner; + +public class JoinListener implements Listener { + + @EventHandler + public void onJoin(PlayerJoinEvent e) { + Player p = e.getPlayer(); + + if (p.hasPermission("backup.update")) { + if (ServerBackup.getInstance().getConfig().getBoolean("UpdateAvailableMessage")) { + Bukkit.getScheduler().runTaskAsynchronously(ServerBackup.getInstance(), () -> { + int resourceID = 79320; + try (InputStream inputStream = (new URL( + "https://api.spigotmc.org/legacy/update.php?resource=" + resourceID)).openStream(); + Scanner scanner = new Scanner(inputStream)) { + if (scanner.hasNext()) { + String latest = scanner.next(); + String current = ServerBackup.getInstance().getDescription().getVersion(); + + int late = Integer.parseInt(latest.replaceAll("\\.", "")); + int curr = Integer.parseInt(current.replaceAll("\\.", "")); + + if (curr >= late) { + } else { + if (OperationHandler.isUpdated) { + p.sendMessage("§8=====§fServerBackup§8====="); + p.sendMessage(""); + p.sendMessage("§7There was a newer version available - §a" + latest + + "§7, you are on - §c" + current); + p.sendMessage( + "\n§7The latest version has been downloaded automatically, please reload the server to complete the update."); + p.sendMessage(""); + p.sendMessage("§8=====§9Plugin by Seblii§8====="); + } else { + if (ServerBackup.getInstance().getConfig().getBoolean("AutomaticUpdates")) { + if (p.hasPermission("backup.admin")) { + p.sendMessage("§8=====§fServerBackup§8====="); + p.sendMessage(""); + p.sendMessage("§7There is a newer version available - §a" + latest + + "§7, you are on - §c" + current); + p.sendMessage(""); + p.sendMessage("§8=====§9Plugin by Seblii§8====="); + p.sendMessage(""); + p.sendMessage("ServerBackup§7: Automatic update started..."); + + URL url = new URL( + "https://server-backup.net/assets/downloads/ServerBackup.jar"); + + int bVer = Integer.parseInt( + Bukkit.getVersion().split(" ")[Bukkit.getVersion().split(" ").length + - 1].replaceAll("\\)", "").replaceAll("\\.", "")); + + if (bVer < 118) { + url = new URL( + "https://server-backup.net/assets/downloads/alt/ServerBackup.jar"); + } + + try (InputStream in = url.openStream(); + ReadableByteChannel rbc = Channels.newChannel(in); + FileOutputStream fos = new FileOutputStream( + "plugins/ServerBackup.jar")) { + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + + p.sendMessage( + "ServerBackup§7: Download finished. Please reload the server to complete the update."); + + OperationHandler.isUpdated = true; + } + } + } else { + p.sendMessage("§8=====§fServerBackup§8====="); + p.sendMessage(""); + p.sendMessage("§7There is a newer version available - §a" + latest + + "§7, you are on - §c" + current); + p.sendMessage( + "§7Please download the latest version - §4https://server-backup.net/"); + p.sendMessage(""); + p.sendMessage("§8=====§9Plugin by Seblii§8====="); + } + } + } + } + } catch (IOException exception) { + exception.printStackTrace(); + } + }); + } + } + } + +} diff --git a/src/net/server_backup/utils/BStats.java b/src/main/java/net/server_backup/utils/BStats.java similarity index 97% rename from src/net/server_backup/utils/BStats.java rename to src/main/java/net/server_backup/utils/BStats.java index bacc37c2..b1730c4d 100644 --- a/src/net/server_backup/utils/BStats.java +++ b/src/main/java/net/server_backup/utils/BStats.java @@ -1,72 +1,72 @@ -package net.server_backup.utils; - -import net.server_backup.Configuration; -import net.server_backup.ServerBackup; -import org.apache.commons.io.FileUtils; -import org.bstats.bukkit.Metrics; -import org.bstats.charts.SimplePie; -import org.bstats.charts.SingleLineChart; -import org.bukkit.Bukkit; - -import java.io.File; -import java.util.concurrent.Callable; - -public class BStats { - - public static void initialize() { - Metrics metrics = new Metrics(ServerBackup.getInstance(), 14673); - - metrics.addCustomChart(new SimplePie("player_per_server", new Callable() { - @Override - public String call() throws Exception { - return String.valueOf(Bukkit.getOnlinePlayers().size()); - } - })); - - metrics.addCustomChart(new SimplePie("using_ftp_server", new Callable() { - @Override - public String call() throws Exception { - if (ServerBackup.getInstance().getConfig().getBoolean("Ftp.UploadBackup")) { - return "yes"; - } else { - return "no"; - } - } - })); - - metrics.addCustomChart(new SimplePie("using_dropbox", new Callable() { - @Override - public String call() throws Exception { - if (ServerBackup.getInstance().getConfig().getBoolean("CloudBackup.Dropbox")) { - return "yes"; - } else { - return "no"; - } - } - })); - - metrics.addCustomChart(new SimplePie("using_gdrive", new Callable() { - @Override - public String call() throws Exception { - if (ServerBackup.getInstance().getConfig().getBoolean("CloudBackup.GoogleDrive")) { - return "yes"; - } else { - return "no"; - } - } - })); - - metrics.addCustomChart(new SingleLineChart("total_backup_space", new Callable() { - @Override - public Integer call() throws Exception { - File file = new File(Configuration.backupDestination); - - double fileSize = (double) FileUtils.sizeOf(file) / 1000 / 1000; - fileSize = Math.round(fileSize * 100.0) / 100.0; - - return (int) fileSize; - } - })); - } - -} +package net.server_backup.utils; + +import net.server_backup.Configuration; +import net.server_backup.ServerBackup; +import org.apache.commons.io.FileUtils; +import org.bstats.bukkit.Metrics; +import org.bstats.charts.SimplePie; +import org.bstats.charts.SingleLineChart; +import org.bukkit.Bukkit; + +import java.io.File; +import java.util.concurrent.Callable; + +public class BStats { + + public static void initialize() { + Metrics metrics = new Metrics(ServerBackup.getInstance(), 14673); + + metrics.addCustomChart(new SimplePie("player_per_server", new Callable() { + @Override + public String call() throws Exception { + return String.valueOf(Bukkit.getOnlinePlayers().size()); + } + })); + + metrics.addCustomChart(new SimplePie("using_ftp_server", new Callable() { + @Override + public String call() throws Exception { + if (ServerBackup.getInstance().getConfig().getBoolean("Ftp.UploadBackup")) { + return "yes"; + } else { + return "no"; + } + } + })); + + metrics.addCustomChart(new SimplePie("using_dropbox", new Callable() { + @Override + public String call() throws Exception { + if (ServerBackup.getInstance().getConfig().getBoolean("CloudBackup.Dropbox")) { + return "yes"; + } else { + return "no"; + } + } + })); + + metrics.addCustomChart(new SimplePie("using_gdrive", new Callable() { + @Override + public String call() throws Exception { + if (ServerBackup.getInstance().getConfig().getBoolean("CloudBackup.GoogleDrive")) { + return "yes"; + } else { + return "no"; + } + } + })); + + metrics.addCustomChart(new SingleLineChart("total_backup_space", new Callable() { + @Override + public Integer call() throws Exception { + File file = new File(Configuration.backupDestination); + + double fileSize = (double) FileUtils.sizeOf(file) / 1000 / 1000; + fileSize = Math.round(fileSize * 100.0) / 100.0; + + return (int) fileSize; + } + })); + } + +} diff --git a/src/net/server_backup/utils/DropboxManager.java b/src/main/java/net/server_backup/utils/DropboxManager.java similarity index 97% rename from src/net/server_backup/utils/DropboxManager.java rename to src/main/java/net/server_backup/utils/DropboxManager.java index a32ed7c0..82c67cc1 100644 --- a/src/net/server_backup/utils/DropboxManager.java +++ b/src/main/java/net/server_backup/utils/DropboxManager.java @@ -1,214 +1,214 @@ -package net.server_backup.utils; - -import com.dropbox.core.*; -import com.dropbox.core.oauth.DbxCredential; -import com.dropbox.core.util.IOUtil; -import com.dropbox.core.v2.DbxClientV2; -import com.dropbox.core.v2.files.*; -import net.server_backup.Configuration; -import net.server_backup.ServerBackup; -import net.server_backup.core.OperationHandler; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.Date; -import java.util.logging.Level; - -public class DropboxManager { - - private CommandSender sender; - public DropboxManager(CommandSender sender) { - this.sender = sender; - } - - private static final String ACCESS_TOKEN = Configuration.cloudInfo.getString("Cloud.Dropbox.AccessToken"); - - public void uploadToDropbox(String filePath) { - File file = new File(filePath); - - if (!file.getPath().contains(Configuration.backupDestination.replaceAll("/", ""))) { - file = new File(Configuration.backupDestination + "//" + filePath); - filePath = file.getPath(); - } - - if (!file.exists()) { - sender.sendMessage("Dropbox: Backup '" + file.getName() + "' not found."); - - return; - } - - DbxRequestConfig config = DbxRequestConfig.newBuilder("dropbox/ServerBackupG").build(); - - String appKey = Configuration.cloudInfo.getString("Cloud.Dropbox.AppKey"); - String secretKey = Configuration.cloudInfo.getString("Cloud.Dropbox.AppSecret"); - - DbxClientV2 client = null; - DbxCredential credential = null; - - if(!Configuration.cloudInfo.contains("Cloud.Dropbox.RT")) { - DbxAppInfo appInfo = new DbxAppInfo(appKey, secretKey); - DbxWebAuth webAuth = new DbxWebAuth(config, appInfo); - DbxAuthFinish authFinish = null; - try { - authFinish = webAuth.finishFromCode(ACCESS_TOKEN); - } catch (DbxException e) { - throw new RuntimeException(e); - } - credential = new DbxCredential(authFinish.getAccessToken(), 60L, authFinish.getRefreshToken(), appKey, secretKey); - - Configuration.cloudInfo.set("Cloud.Dropbox.RT", authFinish.getRefreshToken()); - Configuration.saveCloud(); - } else { - credential = new DbxCredential("isly", 0L, Configuration.cloudInfo.getString("Cloud.Dropbox.RT"), appKey, secretKey); - } - - client = new DbxClientV2(config, credential); - - sender.sendMessage("Dropbox: Uploading backup [" + file.getName() + "] ..."); - - String des = ServerBackup.getInstance().getConfig().getString("CloudBackup.Options.Destination").replaceAll("/", ""); - des = "/" + (des.equals("") ? "" : des + "/"); - - if(file.length() > (100 * 1000 * 1000)) { - chunkedUploadFile(sender, client, file, des + file.getName()); - } else { - uploadFile(sender, client, file, des + file.getName()); - } - } - - private static final long CHUNKED_UPLOAD_CHUNK_SIZE = 16L << 20; - private static final int CHUNKED_UPLOAD_MAX_ATTEMPTS = 5; - - static String lastProgress = ""; - - private static void chunkedUploadFile(CommandSender sender, DbxClientV2 dbxClient, File file, String dbxPath) { - long size = file.length(); - - long uploaded = 0L; - DbxException thrown = null; - - IOUtil.ProgressListener progressListener = new IOUtil.ProgressListener() { - long uploadedBytes = 0; - - @Override - public void onProgress(long l) { - getProgress(file.getName(), l + uploadedBytes, size, false); - if (l == CHUNKED_UPLOAD_CHUNK_SIZE) uploadedBytes += CHUNKED_UPLOAD_CHUNK_SIZE; - } - }; - - String sessionId = null; - for (int i = 0; i < CHUNKED_UPLOAD_MAX_ATTEMPTS; ++i) { - if (i > 0) { - Bukkit.getLogger().log(Level.INFO, "Dropbox: Chunk upload failed. Retrying (" + Integer.valueOf(i + 1) + "/" + CHUNKED_UPLOAD_MAX_ATTEMPTS + ")..."); - } - - try (InputStream in = new FileInputStream(file)) { - in.skip(uploaded); - - // Start - if (sessionId == null) { - sessionId = dbxClient.files().uploadSessionStart() - .uploadAndFinish(in) - .getSessionId(); - uploaded += CHUNKED_UPLOAD_CHUNK_SIZE; - getProgress(file.getName(), uploaded, size, false); - } - - UploadSessionCursor cursor = new UploadSessionCursor(sessionId, uploaded); - - // Append - while ((size - uploaded) > CHUNKED_UPLOAD_CHUNK_SIZE) { - dbxClient.files().uploadSessionAppendV2(cursor) - .uploadAndFinish(in); - uploaded += CHUNKED_UPLOAD_CHUNK_SIZE; - getProgress(file.getName(), uploaded, size, false); - cursor = new UploadSessionCursor(sessionId, uploaded); - } - - // Finish - long remaining = size - uploaded; - CommitInfo commitInfo = CommitInfo.newBuilder(dbxPath) - .withMode(WriteMode.ADD) - .withClientModified(new Date(file.lastModified())) - .build(); - dbxClient.files().uploadSessionFinish(cursor, commitInfo).uploadAndFinish(in, remaining, progressListener); - - sender.sendMessage("Dropbox: Upload successfully. Backup stored on your dropbox account."); - getProgress(file.getName(), uploaded, size, true); - - if (ServerBackup.getInstance().getConfig().getBoolean("CloudBackup.Options.DeleteLocalBackup")) { - file.delete(); - System.out.println("File [" + file.getPath() + "] deleted."); - } - return; - } catch (RetryException e) { - thrown = e; - } catch (NetworkIOException e) { - thrown = e; - } catch (UploadSessionFinishErrorException e) { - if (e.errorValue.isLookupFailed() && e.errorValue.getLookupFailedValue().isIncorrectOffset()) { - thrown = e; - uploaded = e.errorValue - .getLookupFailedValue() - .getIncorrectOffsetValue() - .getCorrectOffset(); - } else { - e.printStackTrace(); - return; - } - } catch (DbxException e) { - e.printStackTrace(); - return; - } catch (IOException e) { - e.printStackTrace(); - return; - } - } - - Bukkit.getLogger().log(Level.WARNING, "Dropbox: Too many upload attempts. Check your server's connection and try again." + "\n" + thrown.getMessage()); - } - - private static void uploadFile(CommandSender sender, DbxClientV2 client, File file, String dbxPath) { - OperationHandler.tasks.add("DROPBOX UPLOAD {" + file.getName() + "}"); - - try (InputStream in = new FileInputStream(file.getPath())) { - client.files().uploadBuilder(dbxPath + file.getName()).uploadAndFinish(in); - } catch (UploadErrorException e) { - throw new RuntimeException(e); - } catch (IOException e) { - throw new RuntimeException(e); - } catch (DbxException e) { - throw new RuntimeException(e); - } finally { - sender.sendMessage("Dropbox: Upload successfully. Backup stored on your dropbox account."); - OperationHandler.tasks.remove("DROPBOX UPLOAD {" + file.getName() + "}"); - - if (ServerBackup.getInstance().getConfig().getBoolean("CloudBackup.Options.DeleteLocalBackup")) { - file.delete(); - System.out.println("File [" + file.getPath() + "] deleted."); - } - } - } - - private static String getProgress(String fileName, long uploaded, long size, boolean finished) { - if(lastProgress != "") { - OperationHandler.tasks.remove(lastProgress); - } - - if(!finished) { - String progress = "DROPBOX UPLOAD {" + fileName + ", Progress: " + Math.round((uploaded / (double) size) * 100) + "%}"; - OperationHandler.tasks.add(progress); - lastProgress = progress; - - return progress; - } - - return "DROPBOX UPLOAD {" + fileName + ", Progress: finished}"; - } - -} +package net.server_backup.utils; + +import com.dropbox.core.*; +import com.dropbox.core.oauth.DbxCredential; +import com.dropbox.core.util.IOUtil; +import com.dropbox.core.v2.DbxClientV2; +import com.dropbox.core.v2.files.*; +import net.server_backup.Configuration; +import net.server_backup.ServerBackup; +import net.server_backup.core.OperationHandler; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Date; +import java.util.logging.Level; + +public class DropboxManager { + + private CommandSender sender; + public DropboxManager(CommandSender sender) { + this.sender = sender; + } + + private static final String ACCESS_TOKEN = Configuration.cloudInfo.getString("Cloud.Dropbox.AccessToken"); + + public void uploadToDropbox(String filePath) { + File file = new File(filePath); + + if (!file.getPath().contains(Configuration.backupDestination.replaceAll("/", ""))) { + file = new File(Configuration.backupDestination + "//" + filePath); + filePath = file.getPath(); + } + + if (!file.exists()) { + sender.sendMessage("Dropbox: Backup '" + file.getName() + "' not found."); + + return; + } + + DbxRequestConfig config = DbxRequestConfig.newBuilder("dropbox/ServerBackupG").build(); + + String appKey = Configuration.cloudInfo.getString("Cloud.Dropbox.AppKey"); + String secretKey = Configuration.cloudInfo.getString("Cloud.Dropbox.AppSecret"); + + DbxClientV2 client = null; + DbxCredential credential = null; + + if(!Configuration.cloudInfo.contains("Cloud.Dropbox.RT")) { + DbxAppInfo appInfo = new DbxAppInfo(appKey, secretKey); + DbxWebAuth webAuth = new DbxWebAuth(config, appInfo); + DbxAuthFinish authFinish = null; + try { + authFinish = webAuth.finishFromCode(ACCESS_TOKEN); + } catch (DbxException e) { + throw new RuntimeException(e); + } + credential = new DbxCredential(authFinish.getAccessToken(), 60L, authFinish.getRefreshToken(), appKey, secretKey); + + Configuration.cloudInfo.set("Cloud.Dropbox.RT", authFinish.getRefreshToken()); + Configuration.saveCloud(); + } else { + credential = new DbxCredential("isly", 0L, Configuration.cloudInfo.getString("Cloud.Dropbox.RT"), appKey, secretKey); + } + + client = new DbxClientV2(config, credential); + + sender.sendMessage("Dropbox: Uploading backup [" + file.getName() + "] ..."); + + String des = ServerBackup.getInstance().getConfig().getString("CloudBackup.Options.Destination").replaceAll("/", ""); + des = "/" + (des.equals("") ? "" : des + "/"); + + if(file.length() > (100 * 1000 * 1000)) { + chunkedUploadFile(sender, client, file, des + file.getName()); + } else { + uploadFile(sender, client, file, des + file.getName()); + } + } + + private static final long CHUNKED_UPLOAD_CHUNK_SIZE = 16L << 20; + private static final int CHUNKED_UPLOAD_MAX_ATTEMPTS = 5; + + static String lastProgress = ""; + + private static void chunkedUploadFile(CommandSender sender, DbxClientV2 dbxClient, File file, String dbxPath) { + long size = file.length(); + + long uploaded = 0L; + DbxException thrown = null; + + IOUtil.ProgressListener progressListener = new IOUtil.ProgressListener() { + long uploadedBytes = 0; + + @Override + public void onProgress(long l) { + getProgress(file.getName(), l + uploadedBytes, size, false); + if (l == CHUNKED_UPLOAD_CHUNK_SIZE) uploadedBytes += CHUNKED_UPLOAD_CHUNK_SIZE; + } + }; + + String sessionId = null; + for (int i = 0; i < CHUNKED_UPLOAD_MAX_ATTEMPTS; ++i) { + if (i > 0) { + Bukkit.getLogger().log(Level.INFO, "Dropbox: Chunk upload failed. Retrying (" + Integer.valueOf(i + 1) + "/" + CHUNKED_UPLOAD_MAX_ATTEMPTS + ")..."); + } + + try (InputStream in = new FileInputStream(file)) { + in.skip(uploaded); + + // Start + if (sessionId == null) { + sessionId = dbxClient.files().uploadSessionStart() + .uploadAndFinish(in) + .getSessionId(); + uploaded += CHUNKED_UPLOAD_CHUNK_SIZE; + getProgress(file.getName(), uploaded, size, false); + } + + UploadSessionCursor cursor = new UploadSessionCursor(sessionId, uploaded); + + // Append + while ((size - uploaded) > CHUNKED_UPLOAD_CHUNK_SIZE) { + dbxClient.files().uploadSessionAppendV2(cursor) + .uploadAndFinish(in); + uploaded += CHUNKED_UPLOAD_CHUNK_SIZE; + getProgress(file.getName(), uploaded, size, false); + cursor = new UploadSessionCursor(sessionId, uploaded); + } + + // Finish + long remaining = size - uploaded; + CommitInfo commitInfo = CommitInfo.newBuilder(dbxPath) + .withMode(WriteMode.ADD) + .withClientModified(new Date(file.lastModified())) + .build(); + dbxClient.files().uploadSessionFinish(cursor, commitInfo).uploadAndFinish(in, remaining, progressListener); + + sender.sendMessage("Dropbox: Upload successfully. Backup stored on your dropbox account."); + getProgress(file.getName(), uploaded, size, true); + + if (ServerBackup.getInstance().getConfig().getBoolean("CloudBackup.Options.DeleteLocalBackup")) { + file.delete(); + System.out.println("File [" + file.getPath() + "] deleted."); + } + return; + } catch (RetryException e) { + thrown = e; + } catch (NetworkIOException e) { + thrown = e; + } catch (UploadSessionFinishErrorException e) { + if (e.errorValue.isLookupFailed() && e.errorValue.getLookupFailedValue().isIncorrectOffset()) { + thrown = e; + uploaded = e.errorValue + .getLookupFailedValue() + .getIncorrectOffsetValue() + .getCorrectOffset(); + } else { + e.printStackTrace(); + return; + } + } catch (DbxException e) { + e.printStackTrace(); + return; + } catch (IOException e) { + e.printStackTrace(); + return; + } + } + + Bukkit.getLogger().log(Level.WARNING, "Dropbox: Too many upload attempts. Check your server's connection and try again." + "\n" + thrown.getMessage()); + } + + private static void uploadFile(CommandSender sender, DbxClientV2 client, File file, String dbxPath) { + OperationHandler.tasks.add("DROPBOX UPLOAD {" + file.getName() + "}"); + + try (InputStream in = new FileInputStream(file.getPath())) { + client.files().uploadBuilder(dbxPath + file.getName()).uploadAndFinish(in); + } catch (UploadErrorException e) { + throw new RuntimeException(e); + } catch (IOException e) { + throw new RuntimeException(e); + } catch (DbxException e) { + throw new RuntimeException(e); + } finally { + sender.sendMessage("Dropbox: Upload successfully. Backup stored on your dropbox account."); + OperationHandler.tasks.remove("DROPBOX UPLOAD {" + file.getName() + "}"); + + if (ServerBackup.getInstance().getConfig().getBoolean("CloudBackup.Options.DeleteLocalBackup")) { + file.delete(); + System.out.println("File [" + file.getPath() + "] deleted."); + } + } + } + + private static String getProgress(String fileName, long uploaded, long size, boolean finished) { + if(lastProgress != "") { + OperationHandler.tasks.remove(lastProgress); + } + + if(!finished) { + String progress = "DROPBOX UPLOAD {" + fileName + ", Progress: " + Math.round((uploaded / (double) size) * 100) + "%}"; + OperationHandler.tasks.add(progress); + lastProgress = progress; + + return progress; + } + + return "DROPBOX UPLOAD {" + fileName + ", Progress: finished}"; + } + +} diff --git a/src/net/server_backup/utils/FtpManager.java b/src/main/java/net/server_backup/utils/FtpManager.java similarity index 96% rename from src/net/server_backup/utils/FtpManager.java rename to src/main/java/net/server_backup/utils/FtpManager.java index 431dad2d..b1afe431 100644 --- a/src/net/server_backup/utils/FtpManager.java +++ b/src/main/java/net/server_backup/utils/FtpManager.java @@ -1,425 +1,419 @@ -package net.server_backup.utils; - -import net.server_backup.Configuration; -import net.server_backup.ServerBackup; -import net.server_backup.core.OperationHandler; -import org.apache.commons.io.FileUtils; -import org.apache.commons.net.ftp.FTP; -import org.apache.commons.net.ftp.FTPClient; -import org.apache.commons.net.ftp.FTPFile; -import org.apache.commons.net.ftp.FTPSClient; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; - -import java.io.*; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; - -public class FtpManager { - - private CommandSender sender; - - private static final String server = ServerBackup.getInstance().getConfig().getString("Ftp.Server.IP"); - private static final int port = ServerBackup.getInstance().getConfig().getInt("Ftp.Server.Port"); - private static final String user = ServerBackup.getInstance().getConfig().getString("Ftp.Server.User"); - private static final String pass = ServerBackup.getInstance().getConfig().getString("Ftp.Server.Password"); - - public FtpManager(CommandSender sender) { - this.sender = sender; - } - - boolean isSSL = true; - - ServerBackup backup = ServerBackup.getInstance(); - - public void uploadFileToFtp(String filePath, boolean direct) { - File file = new File(filePath); - - if (!file.getPath().contains(Configuration.backupDestination.replaceAll("/", ""))) { - file = new File(Configuration.backupDestination + "//" + filePath); - filePath = file.getPath(); - } - - if (!file.exists()) { - sender.sendMessage(OperationHandler.processMessage("Error.NoBackupFound").replaceAll("%file%", file.getName())); - - return; - } - - FTPSClient ftpsClient = new FTPSClient(); - FTPClient ftpClient = new FTPClient(); - - try { - if (!isSSL) { - connect(ftpClient); - - sender.sendMessage(OperationHandler.processMessage("Info.FtpUpload").replaceAll("%file%", file.getName())); - OperationHandler.tasks.add("FTP UPLOAD {" + filePath + "}"); - - InputStream inputStream = new FileInputStream(file); - - boolean done = ftpClient.storeFile(file.getName(), inputStream); - - // DEBUG - Bukkit.getLogger().log(Level.INFO, "(BETA) FTP-DEBUG INFO: " + ftpClient.getReplyString()); - Bukkit.getLogger().log(Level.INFO, - "Use this info for reporting ftp related bugs. Ignore it if everything is fine."); - - inputStream.close(); - - if (done) { - sender.sendMessage(OperationHandler.processMessage("Info.FtpUploadSuccess")); - - if (ServerBackup.getInstance().getConfig().getBoolean("Ftp.DeleteLocalBackup")) { - boolean exists = false; - for (FTPFile backup : ftpClient.listFiles()) { - if (backup.getName().equalsIgnoreCase(file.getName())) - exists = true; - } - - if (exists) { - file.delete(); - } else { - sender.sendMessage(OperationHandler.processMessage("Error.FtpLocalDeletionFailed")); - } - } - } else { - sender.sendMessage(OperationHandler.processMessage("Error.FtpUploadFailed")); - } - - OperationHandler.tasks.remove("FTP UPLOAD {" + filePath + "}"); - } else { - try { - connect(ftpsClient); - - InputStream inputStream = new FileInputStream(file); - - boolean done = ftpsClient.storeFile(file.getName(), inputStream); - - // DEBUG - Bukkit.getLogger().log(Level.INFO, "(BETA) FTPS-DEBUG INFO: " + ftpsClient.getReplyString()); - Bukkit.getLogger().log(Level.INFO, - "Use this info for reporting ftp related bugs. Ignore it if everything is fine."); - - inputStream.close(); - - if (done) { - sender.sendMessage(OperationHandler.processMessage("Info.FtpUploadSuccess")); - - if (ServerBackup.getInstance().getConfig().getBoolean("Ftp.DeleteLocalBackup")) { - boolean exists = false; - for (FTPFile backup : ftpsClient.listFiles()) { - if (backup.getName().equalsIgnoreCase(file.getName())) - exists = true; - } - - if (exists) { - file.delete(); - } else { - sender.sendMessage(OperationHandler.processMessage("Error.FtpLocalDeletionFailed")); - } - } - } else { - sender.sendMessage(OperationHandler.processMessage("Error.FtpUploadFailed")); - } - - if (OperationHandler.tasks.contains("FTP UPLOAD {" + filePath + "}")) { - OperationHandler.tasks.remove("FTP UPLOAD {" + filePath + "}"); - } - } catch (Exception e) { - isSSL = false; - uploadFileToFtp(filePath, direct); - } - } - } catch (IOException e) { - sender.sendMessage(OperationHandler.processMessage("Error.FtpUploadFailed")); - e.printStackTrace(); - } finally { - disconnect(ftpsClient); - disconnect(ftpClient); - } - } - - public void downloadFileFromFtp(String filePath) { - File file = new File(filePath); - - FTPSClient ftpsClient = new FTPSClient(); - FTPClient ftpClient = new FTPClient(); - - try { - if (!isSSL) { - connect(ftpClient); - - boolean exists = false; - for (FTPFile backup : ftpClient.listFiles()) { - if (backup.getName().equalsIgnoreCase(file.getName())) - exists = true; - } - - if (!exists) { - sender.sendMessage(OperationHandler.processMessage("Error.FtpNotFound").replaceAll("%file%", file.getName())); - - return; - } - - sender.sendMessage(OperationHandler.processMessage("Info.FtpDownload").replaceAll("%file%", file.getName())); - - OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file)); - boolean success = ftpClient.retrieveFile(file.getName(), outputStream); - outputStream.close(); - - Bukkit.getScheduler().runTaskAsynchronously(ServerBackup.getInstance(), () -> { - File dFile = new File(Configuration.backupDestination + "//" + file.getPath()); - - try { - FileUtils.copyFile(file, dFile); - } catch (IOException e) { - e.printStackTrace(); - } - - if (dFile.exists()) { - file.delete(); - } - }); - - if (success) { - sender.sendMessage(OperationHandler.processMessage("Info.FtpDownloadSuccess")); - } else { - sender.sendMessage(OperationHandler.processMessage("Error.FtpDownloadFailed")); - } - } else { - try { - connect(ftpsClient); - - boolean exists = false; - for (FTPFile backup : ftpsClient.listFiles()) { - if (backup.getName().equalsIgnoreCase(file.getName())) - exists = true; - } - - if (!exists) { - sender.sendMessage(OperationHandler.processMessage("Error.FtpNotFound").replaceAll("%file%", file.getName())); - - return; - } - - sender.sendMessage(OperationHandler.processMessage("Info.FtpDownload").replaceAll("%file%", file.getName())); - - OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file)); - boolean success = ftpsClient.retrieveFile(file.getName(), outputStream); - outputStream.close(); - - Bukkit.getScheduler().runTaskAsynchronously(ServerBackup.getInstance(), () -> { - File dFile = new File(Configuration.backupDestination + "//" + file.getPath()); - - try { - FileUtils.copyFile(file, dFile); - } catch (IOException e) { - e.printStackTrace(); - } - - if (dFile.exists()) { - file.delete(); - } - }); - - if (success) { - sender.sendMessage(OperationHandler.processMessage("Info.FtpDownloadSuccess")); - } else { - sender.sendMessage(OperationHandler.processMessage("Error.FtpDownloadFailed")); - } - } catch (Exception e) { - isSSL = false; - downloadFileFromFtp(filePath); - } - } - } catch (IOException e) { - sender.sendMessage(OperationHandler.processMessage("Error.FtpDownloadFailed")); - e.printStackTrace(); - } finally { - disconnect(ftpsClient); - disconnect(ftpClient); - } - } - - public void deleteFile(String filePath) { - File file = new File(filePath); - - FTPSClient ftpsClient = new FTPSClient(); - FTPClient ftpClient = new FTPClient(); - - try { - if (!isSSL) { - connect(ftpClient); - - boolean exists = false; - for (FTPFile backup : ftpClient.listFiles()) { - if (backup.getName().equalsIgnoreCase(file.getName())) - exists = true; - } - - if (!exists) { - sender.sendMessage(OperationHandler.processMessage("Error.FtpNotFound").replaceAll("%file%", file.getName())); - - return; - } - - sender.sendMessage(OperationHandler.processMessage("Info.FtpDeletion").replaceAll("%file%", file.getName())); - - boolean success = ftpClient.deleteFile(file.getPath()); - - if (success) { - sender.sendMessage(OperationHandler.processMessage("Info.FtpDeletionSuccess")); - } else { - sender.sendMessage(OperationHandler.processMessage("Error.FtpDeletionFailed")); - } - } else { - try { - connect(ftpsClient); - - boolean exists = false; - for (FTPFile backup : ftpsClient.listFiles()) { - if (backup.getName().equalsIgnoreCase(file.getName())) - exists = true; - } - - if (!exists) { - sender.sendMessage(OperationHandler.processMessage("Error.FtpNotFound").replaceAll("%file%", file.getName())); - - return; - } - - sender.sendMessage(OperationHandler.processMessage("Info.FtpDeletion").replaceAll("%file%", file.getName())); - - boolean success = ftpsClient.deleteFile(file.getPath()); - - if (success) { - sender.sendMessage(OperationHandler.processMessage("Info.FtpDeletionSuccess")); - } else { - sender.sendMessage(OperationHandler.processMessage("Error.FtpDeletionFailed")); - } - } catch (Exception e) { - isSSL = false; - deleteFile(filePath); - } - } - } catch (IOException e) { - sender.sendMessage(OperationHandler.processMessage("Error.FtpDeletionFailed")); - e.printStackTrace(); - } finally { - disconnect(ftpsClient); - disconnect(ftpClient); - } - } - - public List getFtpBackupList(boolean rawList) { - List backups = new ArrayList<>(); - - FTPSClient ftpsClient = new FTPSClient(); - FTPClient ftpClient = new FTPClient(); - - try { - connect(ftpClient); - - FTPFile[] files = ftpClient.listFiles(); - - int c = 1; - - for (FTPFile file : files) { - double fileSize = (double) file.getSize() / 1000 / 1000; - fileSize = Math.round(fileSize * 100.0) / 100.0; - - if (rawList) { - backups.add(file.getName() + ":" + file.getSize()); - } else { - backups.add("§7[" + c + "]§f " + file.getName() + " §7[" + fileSize + "MB]"); - } - - c++; - } - } catch (Exception e) { - isSSL = true; - getFtpBackupList(rawList); - - try { - connect(ftpsClient); - - FTPFile[] files = ftpsClient.listFiles(); - - int c = 1; - - for (FTPFile file : files) { - double fileSize = (double) file.getSize() / 1000 / 1000; - fileSize = Math.round(fileSize * 100.0) / 100.0; - - if (rawList) { - backups.add(file.getName() + ":" + fileSize); - } else { - backups.add("§7[" + c + "]§f " + file.getName() + " §7[" + fileSize + "MB]"); - } - - c++; - } - } catch (Exception ex) { - isSSL = false; - getFtpBackupList(rawList); - } - } finally { - disconnect(ftpsClient); - disconnect(ftpClient); - - return backups; - } - } - - private void connect(FTPClient client) throws IOException { - client.connect(server, port); - client.login(user, pass); - client.enterLocalPassiveMode(); - - client.setFileType(FTP.BINARY_FILE_TYPE); - client.setFileTransferMode(FTP.BINARY_FILE_TYPE); - - client.changeWorkingDirectory( - ServerBackup.getInstance().getConfig().getString("Ftp.Server.BackupDirectory")); - } - - private void connect(FTPSClient client) throws IOException { - client.connect(server, port); - client.login(user, pass); - client.enterLocalPassiveMode(); - - client.execPBSZ(0); - client.execPROT("P"); - - client.setFileType(FTP.BINARY_FILE_TYPE); - client.setFileTransferMode(FTP.BINARY_FILE_TYPE); - - client.changeWorkingDirectory( - ServerBackup.getInstance().getConfig().getString("Ftp.Server.BackupDirectory")); - } - - private void disconnect(FTPClient client) { - try { - if (client.isConnected()) { - client.logout(); - client.disconnect(); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - - private void disconnect(FTPSClient client) { - try { - if (client.isConnected()) { - client.logout(); - client.disconnect(); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - -} +package net.server_backup.utils; + +import net.server_backup.Configuration; +import net.server_backup.ServerBackup; +import net.server_backup.core.OperationHandler; +import org.apache.commons.io.FileUtils; +import org.apache.commons.net.ftp.FTP; +import org.apache.commons.net.ftp.FTPClient; +import org.apache.commons.net.ftp.FTPFile; +import org.apache.commons.net.ftp.FTPSClient; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; + +import java.io.*; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; + +public class FtpManager { + + private CommandSender sender; + + private static final String server = ServerBackup.getInstance().getConfig().getString("Ftp.Server.IP"); + private static final int port = ServerBackup.getInstance().getConfig().getInt("Ftp.Server.Port"); + private static final String user = ServerBackup.getInstance().getConfig().getString("Ftp.Server.User"); + private static final String pass = ServerBackup.getInstance().getConfig().getString("Ftp.Server.Password"); + private static final boolean isSSL = ServerBackup.getInstance().getConfig().getBoolean("Ftp.Server.SSL"); + + public FtpManager(CommandSender sender) { + this.sender = sender; + } + + ServerBackup backup = ServerBackup.getInstance(); + + public void uploadFileToFtp(String filePath, boolean direct) { + File file = new File(filePath); + + if (!file.getPath().contains(Configuration.backupDestination.replaceAll("/", ""))) { + file = new File(Configuration.backupDestination + "//" + filePath); + filePath = file.getPath(); + } + + if (!file.exists()) { + sender.sendMessage(OperationHandler.processMessage("Error.NoBackupFound").replaceAll("%file%", file.getName())); + + return; + } + + FTPSClient ftpsClient = new FTPSClient(); + FTPClient ftpClient = new FTPClient(); + + try { + if (!isSSL) { + connect(ftpClient); + + sender.sendMessage(OperationHandler.processMessage("Info.FtpUpload").replaceAll("%file%", file.getName())); + OperationHandler.tasks.add("FTP UPLOAD {" + filePath + "}"); + + InputStream inputStream = new FileInputStream(file); + + boolean done = ftpClient.storeFile(file.getName(), inputStream); + + // DEBUG + Bukkit.getLogger().log(Level.INFO, "(BETA) FTP-DEBUG INFO: " + ftpClient.getReplyString()); + Bukkit.getLogger().log(Level.INFO, + "Use this info for reporting ftp related bugs. Ignore it if everything is fine."); + + inputStream.close(); + + if (done) { + sender.sendMessage(OperationHandler.processMessage("Info.FtpUploadSuccess")); + + if (ServerBackup.getInstance().getConfig().getBoolean("Ftp.DeleteLocalBackup")) { + boolean exists = false; + for (FTPFile backup : ftpClient.listFiles()) { + if (backup.getName().equalsIgnoreCase(file.getName())) + exists = true; + } + + if (exists) { + file.delete(); + } else { + sender.sendMessage(OperationHandler.processMessage("Error.FtpLocalDeletionFailed")); + } + } + } else { + sender.sendMessage(OperationHandler.processMessage("Error.FtpUploadFailed")); + } + + OperationHandler.tasks.remove("FTP UPLOAD {" + filePath + "}"); + } else { + try { + connect(ftpsClient); + + InputStream inputStream = new FileInputStream(file); + + boolean done = ftpsClient.storeFile(file.getName(), inputStream); + + // DEBUG + Bukkit.getLogger().log(Level.INFO, "(BETA) FTPS-DEBUG INFO: " + ftpsClient.getReplyString()); + Bukkit.getLogger().log(Level.INFO, + "Use this info for reporting ftp related bugs. Ignore it if everything is fine."); + + inputStream.close(); + + if (done) { + sender.sendMessage(OperationHandler.processMessage("Info.FtpUploadSuccess")); + + if (ServerBackup.getInstance().getConfig().getBoolean("Ftp.DeleteLocalBackup")) { + boolean exists = false; + for (FTPFile backup : ftpsClient.listFiles()) { + if (backup.getName().equalsIgnoreCase(file.getName())) + exists = true; + } + + if (exists) { + file.delete(); + } else { + sender.sendMessage(OperationHandler.processMessage("Error.FtpLocalDeletionFailed")); + } + } + } else { + sender.sendMessage(OperationHandler.processMessage("Error.FtpUploadFailed")); + } + + if (OperationHandler.tasks.contains("FTP UPLOAD {" + filePath + "}")) { + OperationHandler.tasks.remove("FTP UPLOAD {" + filePath + "}"); + } + } catch (Exception e) { + uploadFileToFtp(filePath, direct); + } + } + } catch (IOException e) { + sender.sendMessage(OperationHandler.processMessage("Error.FtpUploadFailed")); + e.printStackTrace(); + } finally { + disconnect(ftpsClient); + disconnect(ftpClient); + } + } + + public void downloadFileFromFtp(String filePath) { + File file = new File(filePath); + + FTPSClient ftpsClient = new FTPSClient(); + FTPClient ftpClient = new FTPClient(); + + try { + if (!isSSL) { + connect(ftpClient); + + boolean exists = false; + for (FTPFile backup : ftpClient.listFiles()) { + if (backup.getName().equalsIgnoreCase(file.getName())) + exists = true; + } + + if (!exists) { + sender.sendMessage(OperationHandler.processMessage("Error.FtpNotFound").replaceAll("%file%", file.getName())); + + return; + } + + sender.sendMessage(OperationHandler.processMessage("Info.FtpDownload").replaceAll("%file%", file.getName())); + + OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file)); + boolean success = ftpClient.retrieveFile(file.getName(), outputStream); + outputStream.close(); + + Bukkit.getScheduler().runTaskAsynchronously(ServerBackup.getInstance(), () -> { + File dFile = new File(Configuration.backupDestination + "//" + file.getPath()); + + try { + FileUtils.copyFile(file, dFile); + } catch (IOException e) { + e.printStackTrace(); + } + + if (dFile.exists()) { + file.delete(); + } + }); + + if (success) { + sender.sendMessage(OperationHandler.processMessage("Info.FtpDownloadSuccess")); + } else { + sender.sendMessage(OperationHandler.processMessage("Error.FtpDownloadFailed")); + } + } else { + try { + connect(ftpsClient); + + boolean exists = false; + for (FTPFile backup : ftpsClient.listFiles()) { + if (backup.getName().equalsIgnoreCase(file.getName())) + exists = true; + } + + if (!exists) { + sender.sendMessage(OperationHandler.processMessage("Error.FtpNotFound").replaceAll("%file%", file.getName())); + + return; + } + + sender.sendMessage(OperationHandler.processMessage("Info.FtpDownload").replaceAll("%file%", file.getName())); + + OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file)); + boolean success = ftpsClient.retrieveFile(file.getName(), outputStream); + outputStream.close(); + + Bukkit.getScheduler().runTaskAsynchronously(ServerBackup.getInstance(), () -> { + File dFile = new File(Configuration.backupDestination + "//" + file.getPath()); + + try { + FileUtils.copyFile(file, dFile); + } catch (IOException e) { + e.printStackTrace(); + } + + if (dFile.exists()) { + file.delete(); + } + }); + + if (success) { + sender.sendMessage(OperationHandler.processMessage("Info.FtpDownloadSuccess")); + } else { + sender.sendMessage(OperationHandler.processMessage("Error.FtpDownloadFailed")); + } + } catch (Exception e) { + downloadFileFromFtp(filePath); + } + } + } catch (IOException e) { + sender.sendMessage(OperationHandler.processMessage("Error.FtpDownloadFailed")); + e.printStackTrace(); + } finally { + disconnect(ftpsClient); + disconnect(ftpClient); + } + } + + public void deleteFile(String filePath) { + File file = new File(filePath); + + FTPSClient ftpsClient = new FTPSClient(); + FTPClient ftpClient = new FTPClient(); + + try { + if (!isSSL) { + connect(ftpClient); + + boolean exists = false; + for (FTPFile backup : ftpClient.listFiles()) { + if (backup.getName().equalsIgnoreCase(file.getName())) + exists = true; + } + + if (!exists) { + sender.sendMessage(OperationHandler.processMessage("Error.FtpNotFound").replaceAll("%file%", file.getName())); + + return; + } + + sender.sendMessage(OperationHandler.processMessage("Info.FtpDeletion").replaceAll("%file%", file.getName())); + + boolean success = ftpClient.deleteFile(file.getPath()); + + if (success) { + sender.sendMessage(OperationHandler.processMessage("Info.FtpDeletionSuccess")); + } else { + sender.sendMessage(OperationHandler.processMessage("Error.FtpDeletionFailed")); + } + } else { + try { + connect(ftpsClient); + + boolean exists = false; + for (FTPFile backup : ftpsClient.listFiles()) { + if (backup.getName().equalsIgnoreCase(file.getName())) + exists = true; + } + + if (!exists) { + sender.sendMessage(OperationHandler.processMessage("Error.FtpNotFound").replaceAll("%file%", file.getName())); + + return; + } + + sender.sendMessage(OperationHandler.processMessage("Info.FtpDeletion").replaceAll("%file%", file.getName())); + + boolean success = ftpsClient.deleteFile(file.getPath()); + + if (success) { + sender.sendMessage(OperationHandler.processMessage("Info.FtpDeletionSuccess")); + } else { + sender.sendMessage(OperationHandler.processMessage("Error.FtpDeletionFailed")); + } + } catch (Exception e) { + deleteFile(filePath); + } + } + } catch (IOException e) { + sender.sendMessage(OperationHandler.processMessage("Error.FtpDeletionFailed")); + e.printStackTrace(); + } finally { + disconnect(ftpsClient); + disconnect(ftpClient); + } + } + + public List getFtpBackupList(boolean rawList) { + List backups = new ArrayList<>(); + + FTPSClient ftpsClient = new FTPSClient(); + FTPClient ftpClient = new FTPClient(); + + try { + connect(ftpClient); + + FTPFile[] files = ftpClient.listFiles(); + + int c = 1; + + for (FTPFile file : files) { + double fileSize = (double) file.getSize() / 1000 / 1000; + fileSize = Math.round(fileSize * 100.0) / 100.0; + + if (rawList) { + backups.add(file.getName() + ":" + file.getSize()); + } else { + backups.add("§7[" + c + "]§f " + file.getName() + " §7[" + fileSize + "MB]"); + } + + c++; + } + } catch (Exception e) { + getFtpBackupList(rawList); + + try { + connect(ftpsClient); + + FTPFile[] files = ftpsClient.listFiles(); + + int c = 1; + + for (FTPFile file : files) { + double fileSize = (double) file.getSize() / 1000 / 1000; + fileSize = Math.round(fileSize * 100.0) / 100.0; + + if (rawList) { + backups.add(file.getName() + ":" + fileSize); + } else { + backups.add("§7[" + c + "]§f " + file.getName() + " §7[" + fileSize + "MB]"); + } + + c++; + } + } catch (Exception ex) { + getFtpBackupList(rawList); + } + } finally { + disconnect(ftpsClient); + disconnect(ftpClient); + + return backups; + } + } + + private void connect(FTPClient client) throws IOException { + client.connect(server, port); + client.login(user, pass); + client.enterLocalPassiveMode(); + + client.setFileType(FTP.BINARY_FILE_TYPE); + client.setFileTransferMode(FTP.BINARY_FILE_TYPE); + + client.changeWorkingDirectory( + ServerBackup.getInstance().getConfig().getString("Ftp.Server.BackupDirectory")); + } + + private void connect(FTPSClient client) throws IOException { + client.connect(server, port); + client.login(user, pass); + client.enterLocalPassiveMode(); + + client.execPBSZ(0); + client.execPROT("P"); + + client.setFileType(FTP.BINARY_FILE_TYPE); + client.setFileTransferMode(FTP.BINARY_FILE_TYPE); + + client.changeWorkingDirectory( + ServerBackup.getInstance().getConfig().getString("Ftp.Server.BackupDirectory")); + } + + private void disconnect(FTPClient client) { + try { + if (client.isConnected()) { + client.logout(); + client.disconnect(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + private void disconnect(FTPSClient client) { + try { + if (client.isConnected()) { + client.logout(); + client.disconnect(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + +} diff --git a/src/plugin.yml b/src/main/resources/plugin.yml similarity index 87% rename from src/plugin.yml rename to src/main/resources/plugin.yml index 8d75e01f..516b83a1 100644 --- a/src/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,19 +1,19 @@ -name: ServerBackup -author: Seblii -version: '${project.version}' -api-version: 1.18 - -main: de.seblii.serverbackup.ServerBackup - -commands: - backup: - aliases: [serverbackup] - permission: backup.admin - -permissions: - backup.admin: - description: Permission for all backup commands - backup.notification: - description: Permission for receiving information about backups - backup.update: +name: ServerBackup +author: Seblii +version: '${project.version}' +api-version: 1.18 + +main: net.server_backup.ServerBackup + +commands: + backup: + aliases: [serverbackup] + permission: backup.admin + +permissions: + backup.admin: + description: Permission for all backup commands + backup.notification: + description: Permission for receiving information about backups + backup.update: description: Permission for receiving update messages \ No newline at end of file diff --git a/target/ServerBackup-2.10.1.jar b/target/ServerBackup-2.10.1.jar new file mode 100644 index 00000000..acb66e28 Binary files /dev/null and b/target/ServerBackup-2.10.1.jar differ diff --git a/target/classes/net/server_backup/Configuration.class b/target/classes/net/server_backup/Configuration.class new file mode 100644 index 00000000..580df04b Binary files /dev/null and b/target/classes/net/server_backup/Configuration.class differ diff --git a/target/classes/net/server_backup/Messages.class b/target/classes/net/server_backup/Messages.class new file mode 100644 index 00000000..50038b5d Binary files /dev/null and b/target/classes/net/server_backup/Messages.class differ diff --git a/target/classes/net/server_backup/ServerBackup.class b/target/classes/net/server_backup/ServerBackup.class new file mode 100644 index 00000000..397371a3 Binary files /dev/null and b/target/classes/net/server_backup/ServerBackup.class differ diff --git a/target/classes/net/server_backup/commands/CommandCreate$1.class b/target/classes/net/server_backup/commands/CommandCreate$1.class new file mode 100644 index 00000000..96c42153 Binary files /dev/null and b/target/classes/net/server_backup/commands/CommandCreate$1.class differ diff --git a/target/classes/net/server_backup/commands/CommandCreate.class b/target/classes/net/server_backup/commands/CommandCreate.class new file mode 100644 index 00000000..9a6876ce Binary files /dev/null and b/target/classes/net/server_backup/commands/CommandCreate.class differ diff --git a/target/classes/net/server_backup/commands/CommandDropbox.class b/target/classes/net/server_backup/commands/CommandDropbox.class new file mode 100644 index 00000000..ffeca9fc Binary files /dev/null and b/target/classes/net/server_backup/commands/CommandDropbox.class differ diff --git a/target/classes/net/server_backup/commands/CommandFtp.class b/target/classes/net/server_backup/commands/CommandFtp.class new file mode 100644 index 00000000..29576b22 Binary files /dev/null and b/target/classes/net/server_backup/commands/CommandFtp.class differ diff --git a/target/classes/net/server_backup/commands/CommandList.class b/target/classes/net/server_backup/commands/CommandList.class new file mode 100644 index 00000000..cfcba2df Binary files /dev/null and b/target/classes/net/server_backup/commands/CommandList.class differ diff --git a/target/classes/net/server_backup/commands/CommandRemove.class b/target/classes/net/server_backup/commands/CommandRemove.class new file mode 100644 index 00000000..012fcd9a Binary files /dev/null and b/target/classes/net/server_backup/commands/CommandRemove.class differ diff --git a/target/classes/net/server_backup/commands/CommandSearch.class b/target/classes/net/server_backup/commands/CommandSearch.class new file mode 100644 index 00000000..7ed3d0b2 Binary files /dev/null and b/target/classes/net/server_backup/commands/CommandSearch.class differ diff --git a/target/classes/net/server_backup/commands/CommandShutdown.class b/target/classes/net/server_backup/commands/CommandShutdown.class new file mode 100644 index 00000000..453b541f Binary files /dev/null and b/target/classes/net/server_backup/commands/CommandShutdown.class differ diff --git a/target/classes/net/server_backup/commands/CommandTasks.class b/target/classes/net/server_backup/commands/CommandTasks.class new file mode 100644 index 00000000..c7f713ef Binary files /dev/null and b/target/classes/net/server_backup/commands/CommandTasks.class differ diff --git a/target/classes/net/server_backup/commands/CommandUnzip.class b/target/classes/net/server_backup/commands/CommandUnzip.class new file mode 100644 index 00000000..a7310916 Binary files /dev/null and b/target/classes/net/server_backup/commands/CommandUnzip.class differ diff --git a/target/classes/net/server_backup/commands/CommandZip.class b/target/classes/net/server_backup/commands/CommandZip.class new file mode 100644 index 00000000..b6de9be0 Binary files /dev/null and b/target/classes/net/server_backup/commands/CommandZip.class differ diff --git a/target/classes/net/server_backup/commands/Executor.class b/target/classes/net/server_backup/commands/Executor.class new file mode 100644 index 00000000..0dfe5abf Binary files /dev/null and b/target/classes/net/server_backup/commands/Executor.class differ diff --git a/target/classes/net/server_backup/commands/TabCompleter.class b/target/classes/net/server_backup/commands/TabCompleter.class new file mode 100644 index 00000000..d3b79242 Binary files /dev/null and b/target/classes/net/server_backup/commands/TabCompleter.class differ diff --git a/target/classes/net/server_backup/core/Backup.class b/target/classes/net/server_backup/core/Backup.class new file mode 100644 index 00000000..fecac9ce Binary files /dev/null and b/target/classes/net/server_backup/core/Backup.class differ diff --git a/target/classes/net/server_backup/core/DynamicBackup$1.class b/target/classes/net/server_backup/core/DynamicBackup$1.class new file mode 100644 index 00000000..5daea69c Binary files /dev/null and b/target/classes/net/server_backup/core/DynamicBackup$1.class differ diff --git a/target/classes/net/server_backup/core/DynamicBackup$2.class b/target/classes/net/server_backup/core/DynamicBackup$2.class new file mode 100644 index 00000000..53d9c644 Binary files /dev/null and b/target/classes/net/server_backup/core/DynamicBackup$2.class differ diff --git a/target/classes/net/server_backup/core/DynamicBackup$3.class b/target/classes/net/server_backup/core/DynamicBackup$3.class new file mode 100644 index 00000000..dc682430 Binary files /dev/null and b/target/classes/net/server_backup/core/DynamicBackup$3.class differ diff --git a/target/classes/net/server_backup/core/DynamicBackup.class b/target/classes/net/server_backup/core/DynamicBackup.class new file mode 100644 index 00000000..1180a522 Binary files /dev/null and b/target/classes/net/server_backup/core/DynamicBackup.class differ diff --git a/target/classes/net/server_backup/core/OperationHandler.class b/target/classes/net/server_backup/core/OperationHandler.class new file mode 100644 index 00000000..27657092 Binary files /dev/null and b/target/classes/net/server_backup/core/OperationHandler.class differ diff --git a/target/classes/net/server_backup/core/Timer.class b/target/classes/net/server_backup/core/Timer.class new file mode 100644 index 00000000..ff476de3 Binary files /dev/null and b/target/classes/net/server_backup/core/Timer.class differ diff --git a/target/classes/net/server_backup/core/ZipManager$1.class b/target/classes/net/server_backup/core/ZipManager$1.class new file mode 100644 index 00000000..d975c35c Binary files /dev/null and b/target/classes/net/server_backup/core/ZipManager$1.class differ diff --git a/target/classes/net/server_backup/core/ZipManager.class b/target/classes/net/server_backup/core/ZipManager.class new file mode 100644 index 00000000..eb763fe4 Binary files /dev/null and b/target/classes/net/server_backup/core/ZipManager.class differ diff --git a/target/classes/net/server_backup/listeners/JoinListener.class b/target/classes/net/server_backup/listeners/JoinListener.class new file mode 100644 index 00000000..86f680ee Binary files /dev/null and b/target/classes/net/server_backup/listeners/JoinListener.class differ diff --git a/target/classes/net/server_backup/utils/BStats$1.class b/target/classes/net/server_backup/utils/BStats$1.class new file mode 100644 index 00000000..c4f15f58 Binary files /dev/null and b/target/classes/net/server_backup/utils/BStats$1.class differ diff --git a/target/classes/net/server_backup/utils/BStats$2.class b/target/classes/net/server_backup/utils/BStats$2.class new file mode 100644 index 00000000..c2c646c0 Binary files /dev/null and b/target/classes/net/server_backup/utils/BStats$2.class differ diff --git a/target/classes/net/server_backup/utils/BStats$3.class b/target/classes/net/server_backup/utils/BStats$3.class new file mode 100644 index 00000000..993eca8b Binary files /dev/null and b/target/classes/net/server_backup/utils/BStats$3.class differ diff --git a/target/classes/net/server_backup/utils/BStats$4.class b/target/classes/net/server_backup/utils/BStats$4.class new file mode 100644 index 00000000..4388e736 Binary files /dev/null and b/target/classes/net/server_backup/utils/BStats$4.class differ diff --git a/target/classes/net/server_backup/utils/BStats$5.class b/target/classes/net/server_backup/utils/BStats$5.class new file mode 100644 index 00000000..27969ae3 Binary files /dev/null and b/target/classes/net/server_backup/utils/BStats$5.class differ diff --git a/target/classes/net/server_backup/utils/BStats.class b/target/classes/net/server_backup/utils/BStats.class new file mode 100644 index 00000000..6c2fa6c6 Binary files /dev/null and b/target/classes/net/server_backup/utils/BStats.class differ diff --git a/target/classes/net/server_backup/utils/DropboxManager$1.class b/target/classes/net/server_backup/utils/DropboxManager$1.class new file mode 100644 index 00000000..4d87a100 Binary files /dev/null and b/target/classes/net/server_backup/utils/DropboxManager$1.class differ diff --git a/target/classes/net/server_backup/utils/DropboxManager.class b/target/classes/net/server_backup/utils/DropboxManager.class new file mode 100644 index 00000000..260d98d8 Binary files /dev/null and b/target/classes/net/server_backup/utils/DropboxManager.class differ diff --git a/target/classes/net/server_backup/utils/FtpManager.class b/target/classes/net/server_backup/utils/FtpManager.class new file mode 100644 index 00000000..9007363e Binary files /dev/null and b/target/classes/net/server_backup/utils/FtpManager.class differ diff --git a/target/classes/plugin.yml b/target/classes/plugin.yml new file mode 100644 index 00000000..a196615d --- /dev/null +++ b/target/classes/plugin.yml @@ -0,0 +1,19 @@ +name: ServerBackup +author: Seblii +version: '2.10.1' +api-version: 1.18 + +main: net.server_backup.ServerBackup + +commands: + backup: + aliases: [serverbackup] + permission: backup.admin + +permissions: + backup.admin: + description: Permission for all backup commands + backup.notification: + description: Permission for receiving information about backups + backup.update: + description: Permission for receiving update messages \ No newline at end of file diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties new file mode 100644 index 00000000..a16d6498 --- /dev/null +++ b/target/maven-archiver/pom.properties @@ -0,0 +1,3 @@ +artifactId=ServerBackup +groupId=de.seblii.serverbackup +version=2.10.1 diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 00000000..3d659aff --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,35 @@ +net\server_backup\commands\CommandShutdown.class +net\server_backup\utils\BStats$5.class +net\server_backup\core\DynamicBackup$1.class +net\server_backup\commands\CommandCreate$1.class +net\server_backup\listeners\JoinListener.class +net\server_backup\commands\TabCompleter.class +net\server_backup\utils\BStats$3.class +net\server_backup\commands\CommandUnzip.class +net\server_backup\commands\CommandTasks.class +net\server_backup\commands\CommandDropbox.class +net\server_backup\core\Timer.class +net\server_backup\utils\FtpManager.class +net\server_backup\utils\BStats$1.class +net\server_backup\commands\CommandCreate.class +net\server_backup\core\DynamicBackup$2.class +net\server_backup\commands\CommandFtp.class +net\server_backup\commands\CommandSearch.class +net\server_backup\utils\BStats$4.class +net\server_backup\commands\CommandZip.class +net\server_backup\utils\BStats.class +net\server_backup\ServerBackup.class +net\server_backup\commands\Executor.class +net\server_backup\utils\BStats$2.class +net\server_backup\core\Backup.class +net\server_backup\core\DynamicBackup$3.class +net\server_backup\core\ZipManager$1.class +net\server_backup\Messages.class +net\server_backup\core\ZipManager.class +net\server_backup\commands\CommandList.class +net\server_backup\core\OperationHandler.class +net\server_backup\Configuration.class +net\server_backup\utils\DropboxManager$1.class +net\server_backup\utils\DropboxManager.class +net\server_backup\core\DynamicBackup.class +net\server_backup\commands\CommandRemove.class diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 00000000..e270f101 --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,24 @@ +C:\Users\Administrator\IdeaProjects\ServerBackup\src\main\java\net\server_backup\core\ZipManager.java +C:\Users\Administrator\IdeaProjects\ServerBackup\src\main\java\net\server_backup\utils\DropboxManager.java +C:\Users\Administrator\IdeaProjects\ServerBackup\src\main\java\net\server_backup\Configuration.java +C:\Users\Administrator\IdeaProjects\ServerBackup\src\main\java\net\server_backup\utils\BStats.java +C:\Users\Administrator\IdeaProjects\ServerBackup\src\main\java\net\server_backup\commands\CommandFtp.java +C:\Users\Administrator\IdeaProjects\ServerBackup\src\main\java\net\server_backup\commands\CommandSearch.java +C:\Users\Administrator\IdeaProjects\ServerBackup\src\main\java\net\server_backup\commands\CommandRemove.java +C:\Users\Administrator\IdeaProjects\ServerBackup\src\main\java\net\server_backup\commands\CommandShutdown.java +C:\Users\Administrator\IdeaProjects\ServerBackup\src\main\java\net\server_backup\core\DynamicBackup.java +C:\Users\Administrator\IdeaProjects\ServerBackup\src\main\java\net\server_backup\utils\FtpManager.java +C:\Users\Administrator\IdeaProjects\ServerBackup\src\main\java\net\server_backup\core\Timer.java +C:\Users\Administrator\IdeaProjects\ServerBackup\src\main\java\net\server_backup\commands\Executor.java +C:\Users\Administrator\IdeaProjects\ServerBackup\src\main\java\net\server_backup\core\OperationHandler.java +C:\Users\Administrator\IdeaProjects\ServerBackup\src\main\java\net\server_backup\listeners\JoinListener.java +C:\Users\Administrator\IdeaProjects\ServerBackup\src\main\java\net\server_backup\ServerBackup.java +C:\Users\Administrator\IdeaProjects\ServerBackup\src\main\java\net\server_backup\commands\TabCompleter.java +C:\Users\Administrator\IdeaProjects\ServerBackup\src\main\java\net\server_backup\commands\CommandZip.java +C:\Users\Administrator\IdeaProjects\ServerBackup\src\main\java\net\server_backup\commands\CommandList.java +C:\Users\Administrator\IdeaProjects\ServerBackup\src\main\java\net\server_backup\commands\CommandDropbox.java +C:\Users\Administrator\IdeaProjects\ServerBackup\src\main\java\net\server_backup\commands\CommandCreate.java +C:\Users\Administrator\IdeaProjects\ServerBackup\src\main\java\net\server_backup\Messages.java +C:\Users\Administrator\IdeaProjects\ServerBackup\src\main\java\net\server_backup\commands\CommandTasks.java +C:\Users\Administrator\IdeaProjects\ServerBackup\src\main\java\net\server_backup\commands\CommandUnzip.java +C:\Users\Administrator\IdeaProjects\ServerBackup\src\main\java\net\server_backup\core\Backup.java diff --git a/target/original-ServerBackup-2.10.1.jar b/target/original-ServerBackup-2.10.1.jar new file mode 100644 index 00000000..556da531 Binary files /dev/null and b/target/original-ServerBackup-2.10.1.jar differ