Don't create new file when attempting to load cache. Fixes #107
This commit is contained in:
@@ -16,7 +16,12 @@
|
||||
*/
|
||||
package com.drtshock.playervaults;
|
||||
|
||||
import com.drtshock.playervaults.commands.*;
|
||||
import com.drtshock.playervaults.commands.ConvertCommand;
|
||||
import com.drtshock.playervaults.commands.DeleteCommand;
|
||||
import com.drtshock.playervaults.commands.SignCommand;
|
||||
import com.drtshock.playervaults.commands.SignSetInfo;
|
||||
import com.drtshock.playervaults.commands.VaultCommand;
|
||||
import com.drtshock.playervaults.commands.WorkbenchCommand;
|
||||
import com.drtshock.playervaults.listeners.Listeners;
|
||||
import com.drtshock.playervaults.listeners.SignListener;
|
||||
import com.drtshock.playervaults.listeners.VaultPreloadListener;
|
||||
@@ -39,7 +44,11 @@ import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -13,7 +13,11 @@ import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ConvertCommand implements CommandExecutor {
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class DeleteCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (VaultOperations.isLocked()) {
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class SignCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (sender.hasPermission("playervaults.signs.set")) {
|
||||
|
||||
@@ -15,6 +15,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class VaultCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (VaultOperations.isLocked()) {
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class WorkbenchCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (sender.hasPermission("playervaults.workbench")) {
|
||||
|
||||
@@ -19,22 +19,21 @@ package com.drtshock.playervaults.listeners;
|
||||
import com.drtshock.playervaults.PlayerVaults;
|
||||
import com.drtshock.playervaults.util.Lang;
|
||||
import com.drtshock.playervaults.vaultmanagement.UUIDVaultManager;
|
||||
import com.drtshock.playervaults.vaultmanagement.VaultOperations;
|
||||
import com.drtshock.playervaults.vaultmanagement.VaultViewInfo;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.bukkit.scheduler.BukkitRunnable;
|
||||
import java.util.UUID;
|
||||
|
||||
public class VaultPreloadListener implements Listener {
|
||||
|
||||
final UUIDVaultManager vm = UUIDVaultManager.getInstance();
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
|
||||
@@ -6,7 +6,13 @@ import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
name: PlayerVaults
|
||||
main: com.drtshock.playervaults.PlayerVaults
|
||||
authors: [drtshock, Koalaaaa]
|
||||
authors: [drtshock, kashike]
|
||||
version: ${project.version}-b${BUILD_NUMBER}
|
||||
website: http://dev.bukkit.org/server-mods/PlayerVaults
|
||||
softdepend: [Vault]
|
||||
|
||||
Reference in New Issue
Block a user