Skip to content

Commit

Permalink
Fixed config bug that backed up all folders no matter the configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Enayet Hussain committed Aug 8, 2020
1 parent 889e20c commit b01a2c7
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.enayet.minecraft.backuponevent</groupId>
<artifactId>backuponevent</artifactId>
<version>1.6.4-SNAPSHOT</version>
<version>1.6.5-SNAPSHOT</version>

<build>
<plugins>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/backuponevent/BackupOnEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private void createFolder() {
if (!getDataFolder().exists()) {
Bukkit.getLogger().info(Constants.LOG_FOLDER_NOT_EXIST);
Bukkit.getLogger().info((getDataFolder().mkdir() ?
Constants.LOG_FOLDER_CREATED : Constants.LOG_FOLDER_CREAT_FAILED));
Constants.LOG_FOLDER_CREATED : Constants.LOG_FOLDER_CREATE_FAILED));
}
}

Expand All @@ -108,7 +108,7 @@ private boolean pluginIsObsolete() {
Bukkit.getLogger().severe(Constants.LOG_KEY_RETURNED_NULL);
}

Bukkit.getLogger().info(Constants.LOG_OBSELETE);
Bukkit.getLogger().info(Constants.LOG_OBSOLETE);
Bukkit.getLogger().info(Constants.LOG_SHUTTING_DOWN);
return true;

Expand Down
16 changes: 10 additions & 6 deletions src/main/java/backuponevent/BackupRunnable.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package backuponevent;

import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -55,7 +56,7 @@ public void run() {
ZipUtil.ZipDirs(
Constants.TARGET_DIR, // Destination
file,
true, f -> true, // Delete existing?
false, f -> true, // Delete existing?
getAvailableDirs() // Source folders
);

Expand Down Expand Up @@ -93,14 +94,17 @@ static void run(BackupOnEvent plugin, String name) {
private String[] getAvailableDirs() {

// Map of possible folders
Map<String, Boolean> sources = new HashMap<>();
Set<String> worlds = Objects.requireNonNull(plugin.getConfig()
.getConfigurationSection(Constants.BACKUPWORLDS)).getKeys(false);
Map<String, Boolean> availableDir = new HashMap<>();
ConfigurationSection config = plugin.getConfig().getConfigurationSection(Constants.BACKUPWORLDS);
Set<String> worlds = Objects.requireNonNull(config).getKeys(false);

// Only add folders set to true
for (String world: worlds)
sources.put(world, false);
if (config.getBoolean(world))
availableDir.put(world, false);

// Return available folders
return sources.keySet().stream().filter(x -> new File(x).exists()).toArray(String[]::new);
return availableDir.keySet().stream().filter(x -> new File(x).exists()).toArray(String[]::new);

}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/backuponevent/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ class Constants {
private static final String WARNING = ChatColor.YELLOW + "WARNING" + ChatColor.RESET + ": ";
static final String LOG_FOLDER_NOT_EXIST = PREFIX + ChatColor.RED + PLUGIN_NAME + " folder does not exist";
static final String LOG_FOLDER_CREATED = PREFIX + ChatColor.GREEN + PLUGIN_NAME + " folder has been created";
static final String LOG_FOLDER_CREAT_FAILED = PREFIX + ChatColor.RED + "Failed to create " + PLUGIN_NAME + " folder";
static final String LOG_FOLDER_CREATE_FAILED = PREFIX + ChatColor.RED + "Failed to create " + PLUGIN_NAME + " folder";
static final String LOG_KEY_RETURNED_NULL = PREFIX + ChatColor.RED + "Fetching keys returned null!";
static final String LOG_OBSELETE = PREFIX + ChatColor.RED + "Plugin is obsolete as all backups are disabled!";
static final String LOG_OBSOLETE = PREFIX + ChatColor.RED + "Plugin is obsolete as all backups are disabled!";
static final String LOG_SHUTTING_DOWN = PREFIX + ChatColor.RED + "Shutting down plugin...";
static final String LOG_NO_PLAYERS_ONLINE = PREFIX + ChatColor.YELLOW + "No players are online, skipping backup";
static final String LOG_CREATED_BACKUP = PREFIX + ChatColor.GREEN + "Created backup %s";
Expand Down
4 changes: 2 additions & 2 deletions src/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: backuponevent.BackupOnEvent
version: 1.6.4
name: BackupOnEvent
version: 1.6.5
author: Enayet Hussain (enayet123)
main: backuponevent.BackupOnEvent
description: Backs up all worlds based on events
Expand Down

0 comments on commit b01a2c7

Please # to comment.