Skip to content

Commit

Permalink
Shifted YAML file saving to use Util method.
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Jun 18, 2018
1 parent db6b6c9 commit a446621
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 42 deletions.
10 changes: 4 additions & 6 deletions src/com/wasteofplastic/askyblock/CoopPlay.java
Expand Up @@ -223,17 +223,15 @@ public void clearMyCoops(Player player) {
}
}

/**
* Called when disabling the plugin
*/
public void saveCoops() {
File coopFile = new File(plugin.getDataFolder(), "coops.yml");
YamlConfiguration coopConfig = new YamlConfiguration();
for (UUID playerUUID : coopPlayers.keySet()) {
coopConfig.set(playerUUID.toString(), getMyCoops(playerUUID));
}
try {
coopConfig.save(coopFile);
} catch (IOException e) {
plugin.getLogger().severe("Could not save coop.yml file!");
}
Util.saveYamlFile(coopConfig, "coops.yml", false);
}

public void loadCoops() {
Expand Down
43 changes: 7 additions & 36 deletions src/com/wasteofplastic/askyblock/GridManager.java
Expand Up @@ -68,13 +68,9 @@ public class GridManager {
private final ASkyBlock plugin;
// 2D islandGrid of islands, x,z
private TreeMap<Integer, TreeMap<Integer, Island>> islandGrid = new TreeMap<>();
// private TreeMap<Integer,TreeMap<Integer,PlayerIsland>> protectionGrid = new
// TreeMap<Integer,TreeMap<Integer,PlayerIsland>>();
// Reverse lookup for owner, if they exists
private final HashMap<UUID, Island> ownershipMap = new HashMap<>();
private File islandFile;
private Island spawn;
private File islandNameFile;
private final YamlConfiguration islandNames = new YamlConfiguration();

/**
Expand All @@ -88,8 +84,7 @@ public GridManager(ASkyBlock plugin) {
private void loadGrid() {
plugin.getLogger().info("Loading island grid...");
islandGrid.clear();
// protectionGrid.clear();
islandNameFile = new File(plugin.getDataFolder(), ISLANDNAMES_FILENAME);
File islandNameFile = new File(plugin.getDataFolder(), ISLANDNAMES_FILENAME);
if (!islandNameFile.exists()) {
try {
islandNameFile.createNewFile();
Expand All @@ -103,7 +98,7 @@ private void loadGrid() {
//e.printStackTrace();
plugin.getLogger().severe("Could not load " + ISLANDNAMES_FILENAME);
}
islandFile = new File(plugin.getDataFolder(), ISLANDS_FILENAME);
File islandFile = new File(plugin.getDataFolder(), ISLANDS_FILENAME);
if (!islandFile.exists()) {
// check if island folder exists
plugin.getLogger().info(ISLANDS_FILENAME + " does not exist. Creating...");
Expand Down Expand Up @@ -452,7 +447,7 @@ public void saveGrid() {
* @param async - true if saving should be done async
*/
public void saveGrid(boolean async) {
final File islandFile = new File(plugin.getDataFolder(), ISLANDS_FILENAME);
//final File islandFile = new File(plugin.getDataFolder(), ISLANDS_FILENAME);
final YamlConfiguration islandYaml = new YamlConfiguration();
// Save the settings config key
List<String> islandSettings = new ArrayList<String>();
Expand All @@ -479,32 +474,12 @@ public void saveGrid(boolean async) {
}
}
}
islandYaml.set(Settings.worldName, islandList);
islandYaml.set(Settings.worldName, islandList);
// Save the file
if (async) {
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
public void run() {
try {
islandYaml.save(islandFile);
} catch (Exception e) {
plugin.getLogger().severe("Could not save " + ISLANDS_FILENAME + "!");
//e.printStackTrace();
}}
});
} else {
try {
islandYaml.save(islandFile);
} catch (Exception e) {
plugin.getLogger().severe("Could not save " + ISLANDS_FILENAME + "! " + e.getMessage());
}
}
Util.saveYamlFile(islandYaml, ISLANDS_FILENAME, async);
// Save any island names
if (islandNames != null) {
try {
islandNames.save(islandNameFile);
} catch (IOException e) {
plugin.getLogger().severe("Could not save islandnames.yml! " + e.getMessage());
}
Util.saveYamlFile(islandNames, ISLANDNAMES_FILENAME, async);
}
}

Expand Down Expand Up @@ -1718,11 +1693,7 @@ public String getIslandName(UUID owner) {
*/
public void setIslandName(UUID owner, String name) {
islandNames.set(owner.toString(), name);
try {
islandNames.save(islandNameFile);
} catch (IOException e) {
plugin.getLogger().severe("Could not save islandnames.yml! " + e.getMessage());
}
Util.saveYamlFile(islandNames, ISLANDNAMES_FILENAME, true);
}

}

0 comments on commit a446621

Please sign in to comment.