Don't create new file when attempting to load cache. Fixes #107
This commit is contained in:
@@ -30,6 +30,7 @@ import java.io.File;
|
||||
* A class that handles all economy operations.
|
||||
*/
|
||||
public class EconomyOperations {
|
||||
|
||||
private static final PlayerVaults PLUGIN = PlayerVaults.getInstance();
|
||||
private static final FileConfiguration BUKKIT_CONFIG = PLUGIN.getConfig();
|
||||
|
||||
|
||||
@@ -25,7 +25,12 @@ import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
/**
|
||||
|
||||
@@ -240,7 +240,10 @@ public class UUIDVaultManager {
|
||||
|
||||
// Should only be run asynchronously
|
||||
public void cachePlayerVaultFile(UUID holder) {
|
||||
cachedVaultFiles.put(holder, loadPlayerVaultFile(holder));
|
||||
YamlConfiguration config = this.loadPlayerVaultFile(holder, false);
|
||||
if (config != null) {
|
||||
this.cachedVaultFiles.put(holder, config);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeCachedPlayerVaultFile(UUID holder) {
|
||||
@@ -264,17 +267,25 @@ public class UUIDVaultManager {
|
||||
}
|
||||
|
||||
public YamlConfiguration loadPlayerVaultFile(UUID holder) {
|
||||
if (!directory.exists()) {
|
||||
directory.mkdir();
|
||||
return this.loadPlayerVaultFile(holder, true);
|
||||
}
|
||||
|
||||
public YamlConfiguration loadPlayerVaultFile(UUID uniqueId, boolean createIfNotFound) {
|
||||
if (!this.directory.exists()) {
|
||||
this.directory.mkdir();
|
||||
}
|
||||
File file = new File(directory, holder.toString() + ".yml");
|
||||
if (!file.exists()) {
|
||||
|
||||
File file = new File(this.directory, uniqueId.toString() + ".yml");
|
||||
if (!file.exists() && createIfNotFound) {
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (IOException e) {
|
||||
// Who cares?
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
return YamlConfiguration.loadConfiguration(file);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user