Do a bit more cleanup, and shuffle a few things around
This commit is contained in:
@@ -51,7 +51,7 @@ public class PlayerVaults extends JavaPlugin {
|
||||
private HashMap<String, SignSetInfo> setSign = new HashMap<>();
|
||||
private HashMap<String, VaultViewInfo> inVault = new HashMap<>();
|
||||
private HashMap<String, Inventory> openInventories = new HashMap<>();
|
||||
private static Economy econ = null;
|
||||
private Economy economy = null;
|
||||
private boolean dropOnDeath = false;
|
||||
private boolean useVault = false;
|
||||
private int inventoriesToDrop = 0;
|
||||
@@ -73,7 +73,7 @@ public class PlayerVaults extends JavaPlugin {
|
||||
getCommand("pvdel").setExecutor(new DeleteCommand());
|
||||
getCommand("pvsign").setExecutor(new SignCommand());
|
||||
getCommand("workbench").setExecutor(new WorkbenchCommand());
|
||||
setupEconomy();
|
||||
useVault = setupEconomy();
|
||||
startMetrics();
|
||||
|
||||
if (getConfig().getBoolean("drop-on-death.enabled")) {
|
||||
@@ -81,8 +81,6 @@ public class PlayerVaults extends JavaPlugin {
|
||||
inventoriesToDrop = getConfig().getInt("drop-on-death.inventories");
|
||||
}
|
||||
|
||||
new File(getDataFolder() + File.separator + "vaults" + File.separator + "backups").mkdirs();
|
||||
|
||||
if (getConfig().getBoolean("cleanup.enable", false)) {
|
||||
getServer().getScheduler().runTaskAsynchronously(this, new Cleanup(getConfig().getInt("cleanup.lastEdit", 30)));
|
||||
}
|
||||
@@ -104,20 +102,24 @@ public class PlayerVaults extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
if (getInVault().containsKey(p.getName())) {
|
||||
Inventory inv = p.getOpenInventory().getTopInventory();
|
||||
if (inv.getViewers().size() == 1) {
|
||||
VaultViewInfo info = getInVault().get(p.getName());
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (this.inVault.containsKey(player.getName())) {
|
||||
Inventory inventory = player.getOpenInventory().getTopInventory();
|
||||
if (inventory.getViewers().size() == 1) {
|
||||
VaultViewInfo info = this.inVault.get(player.getName());
|
||||
try {
|
||||
UUIDVaultManager.getInstance().saveVault(inv, p.getUniqueId(), info.getNumber());
|
||||
UUIDVaultManager.getInstance().saveVault(inventory, player.getUniqueId(), info.getNumber());
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
getOpenInventories().remove(info.toString());
|
||||
|
||||
this.openInventories.remove(info.toString());
|
||||
}
|
||||
getInVault().remove(p.getName());
|
||||
|
||||
this.inVault.remove(player.getName());
|
||||
}
|
||||
p.closeInventory();
|
||||
|
||||
player.closeInventory();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,7 +127,7 @@ public class PlayerVaults extends JavaPlugin {
|
||||
if (getConfig().getBoolean("check-update", true)) {
|
||||
final PlayerVaults plugin = this;
|
||||
final File file = this.getFile();
|
||||
final Updater.UpdateType updateType = (getConfig().getBoolean("download-update", true) ? Updater.UpdateType.DEFAULT : Updater.UpdateType.NO_DOWNLOAD);
|
||||
final Updater.UpdateType updateType = getConfig().getBoolean("download-update", true) ? Updater.UpdateType.DEFAULT : Updater.UpdateType.NO_DOWNLOAD;
|
||||
getServer().getScheduler().runTaskAsynchronously(this, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -146,13 +148,15 @@ public class PlayerVaults extends JavaPlugin {
|
||||
if (getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||
return false;
|
||||
}
|
||||
RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
|
||||
if (rsp == null) {
|
||||
|
||||
RegisteredServiceProvider<Economy> provider = getServer().getServicesManager().getRegistration(Economy.class);
|
||||
if (provider == null) {
|
||||
return false;
|
||||
}
|
||||
econ = rsp.getProvider();
|
||||
useVault = true;
|
||||
return econ != null;
|
||||
|
||||
economy = provider.getProvider();
|
||||
|
||||
return economy != null;
|
||||
}
|
||||
|
||||
private void loadConfig() {
|
||||
@@ -280,12 +284,14 @@ public class PlayerVaults extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
YamlConfiguration conf = YamlConfiguration.loadConfiguration(lang);
|
||||
for (Lang item : Lang.values()) {
|
||||
if (conf.getString(item.getPath()) == null) {
|
||||
conf.set(item.getPath(), item.getDefault());
|
||||
}
|
||||
}
|
||||
|
||||
Lang.setFile(conf);
|
||||
try {
|
||||
conf.save(lang);
|
||||
@@ -321,13 +327,24 @@ public class PlayerVaults extends JavaPlugin {
|
||||
}
|
||||
|
||||
public Economy getEconomy() {
|
||||
return econ;
|
||||
return this.economy;
|
||||
}
|
||||
|
||||
public boolean isEconomyEnabled() {
|
||||
return this.getConfig().getBoolean("economy.enabled", false) && this.useVault;
|
||||
}
|
||||
|
||||
public File getVaultData() {
|
||||
return new File(this.getDataFolder(), "uuidvaults");
|
||||
}
|
||||
|
||||
public File getBackupsFolder() {
|
||||
File folder = new File(this.getVaultData(), "backups");
|
||||
folder.mkdirs();
|
||||
|
||||
return folder;
|
||||
}
|
||||
|
||||
public static PlayerVaults getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import org.bukkit.scheduler.BukkitRunnable;
|
||||
import java.io.File;
|
||||
|
||||
public class Cleanup extends BukkitRunnable {
|
||||
|
||||
private long diff;
|
||||
|
||||
public Cleanup(int diff) {
|
||||
@@ -15,14 +14,17 @@ public class Cleanup extends BukkitRunnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
File file = PlayerVaults.getInstance().getVaultData();
|
||||
if (!file.exists()) return;
|
||||
File directory = PlayerVaults.getInstance().getVaultData();
|
||||
if (!directory.exists()) {
|
||||
// folder doesn't exist, don't run
|
||||
return;
|
||||
}
|
||||
|
||||
long time = System.currentTimeMillis();
|
||||
for (File f : file.listFiles()) {
|
||||
if (time - f.lastModified() > diff) {
|
||||
f.delete();
|
||||
PlayerVaults.getInstance().getLogger().info("Deleting vault file: " + f.getName());
|
||||
for (File file : directory.listFiles()) {
|
||||
if (time - file.lastModified() > diff) {
|
||||
PlayerVaults.getInstance().getLogger().info("Deleting vault file (cleanup): " + file.getName());
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,14 +8,12 @@ import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Class to convert vaults by name to vaults by UUID.
|
||||
*/
|
||||
public final class UUIDConversion extends BukkitRunnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
File newDir = PlayerVaults.getInstance().getVaultData();
|
||||
@@ -23,11 +21,12 @@ public final class UUIDConversion extends BukkitRunnable {
|
||||
PlayerVaults.getInstance().getLogger().log(Level.INFO, "Files already converted to UUID.");
|
||||
return;
|
||||
}
|
||||
|
||||
newDir.mkdirs();
|
||||
|
||||
PlayerVaults.getInstance().getLogger().log(Level.INFO, "********** Starting PlayerVault conversion to UUIDs **********");
|
||||
PlayerVaults.getInstance().getLogger().log(Level.INFO, "This might take awhile.");
|
||||
PlayerVaults.getInstance().getLogger().log(Level.INFO, "plugins/PlayerVaults/vaults will still be there as a backup but unused.");
|
||||
PlayerVaults.getInstance().getLogger().log(Level.INFO, "plugins/PlayerVaults/vaults will remain as a backup.");
|
||||
|
||||
for (File file : new File(PlayerVaults.getInstance().getDataFolder() + File.separator + "vaults").listFiles()) {
|
||||
if (file.isDirectory()) continue; // backups folder.
|
||||
@@ -37,8 +36,7 @@ public final class UUIDConversion extends BukkitRunnable {
|
||||
break;
|
||||
}
|
||||
|
||||
UUID uuid = player.getUniqueId();
|
||||
File newFile = new File(PlayerVaults.getInstance().getVaultData(), uuid.toString() + ".yml");
|
||||
File newFile = new File(PlayerVaults.getInstance().getVaultData(), player.getUniqueId().toString() + ".yml");
|
||||
file.mkdirs();
|
||||
try {
|
||||
Files.copy(file, newFile);
|
||||
|
||||
@@ -20,26 +20,18 @@ import com.drtshock.playervaults.PlayerVaults;
|
||||
import com.drtshock.playervaults.util.Lang;
|
||||
import net.milkbowl.vault.economy.EconomyResponse;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* A class that handles all economy operations.
|
||||
*/
|
||||
public class EconomyOperations {
|
||||
|
||||
private static YamlConfiguration BUKKIT_CONFIG = new YamlConfiguration();
|
||||
public static PlayerVaults PLUGIN;
|
||||
|
||||
public EconomyOperations(PlayerVaults instance) throws IOException, InvalidConfigurationException {
|
||||
PLUGIN = instance;
|
||||
File config = new File(PLUGIN.getDataFolder(), "config.yml");
|
||||
BUKKIT_CONFIG.load(config);
|
||||
}
|
||||
private static PlayerVaults PLUGIN = PlayerVaults.getInstance();
|
||||
private static FileConfiguration BUKKIT_CONFIG = PLUGIN.getConfig();
|
||||
|
||||
/**
|
||||
* Have a player pay to open a vault.
|
||||
@@ -50,9 +42,10 @@ public class EconomyOperations {
|
||||
* @return The transaction success.
|
||||
*/
|
||||
public static boolean payToOpen(Player player, int number) {
|
||||
if (!BUKKIT_CONFIG.getBoolean("economy.enabled") || player.hasPermission("playervaults.free") || PlayerVaults.getInstance().getEconomy() != null) {
|
||||
if (!PLUGIN.isEconomyEnabled() || player.hasPermission("playervaults.free")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (UUIDVaultManager.getInstance().vaultExists(player.getUniqueId(), number)) {
|
||||
return payToCreate(player);
|
||||
} else {
|
||||
@@ -63,6 +56,7 @@ public class EconomyOperations {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -74,7 +68,7 @@ public class EconomyOperations {
|
||||
* @return The transaction success
|
||||
*/
|
||||
public static boolean payToCreate(Player player) {
|
||||
if (!BUKKIT_CONFIG.getBoolean("economy.enabled") || player.hasPermission("playervaults.free") || PlayerVaults.getInstance().getEconomy() != null) {
|
||||
if (!PLUGIN.isEconomyEnabled() || player.hasPermission("playervaults.free")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -84,6 +78,7 @@ public class EconomyOperations {
|
||||
player.sendMessage(Lang.TITLE.toString() + Lang.COST_TO_CREATE.toString().replaceAll("%price", "" + cost));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -96,15 +91,14 @@ public class EconomyOperations {
|
||||
* @return The transaction success.
|
||||
*/
|
||||
public static boolean refundOnDelete(Player player, int number) {
|
||||
String directory = "plugins" + File.separator + "PlayerVaults" + File.separator + "vaults";
|
||||
if (!BUKKIT_CONFIG.getBoolean("economy.enabled") || player.hasPermission("playervaults.free") || PlayerVaults.getInstance().getEconomy() != null) {
|
||||
if (!PLUGIN.isEconomyEnabled() || player.hasPermission("playervaults.free")) {
|
||||
return true;
|
||||
}
|
||||
String name = player.getName().toLowerCase();
|
||||
File file = new File(directory + File.separator + name.toLowerCase() + ".yml");
|
||||
YamlConfiguration playerFile = YamlConfiguration.loadConfiguration(file);
|
||||
if (file.exists()) {
|
||||
if (playerFile.getString("vault" + number) == null) {
|
||||
|
||||
File playerFile = new File(PLUGIN.getVaultData(), player.getUniqueId().toString() + ".yml");
|
||||
if (playerFile.exists()) {
|
||||
YamlConfiguration playerData = YamlConfiguration.loadConfiguration(playerFile);
|
||||
if (playerData.getString("vault" + number) == null) {
|
||||
player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.VAULT_DOES_NOT_EXIST);
|
||||
return false;
|
||||
}
|
||||
@@ -112,12 +106,14 @@ public class EconomyOperations {
|
||||
player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.VAULT_DOES_NOT_EXIST);
|
||||
return false;
|
||||
}
|
||||
|
||||
double cost = BUKKIT_CONFIG.getDouble("economy.refund-on-delete");
|
||||
EconomyResponse resp = PlayerVaults.getInstance().getEconomy().depositPlayer(player.getName(), cost);
|
||||
if (resp.transactionSuccess()) {
|
||||
player.sendMessage(Lang.TITLE.toString() + Lang.REFUND_AMOUNT.toString().replaceAll("%price", String.valueOf(cost)));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,6 +134,7 @@ public class Serialization {
|
||||
}
|
||||
return serialized;
|
||||
}
|
||||
|
||||
public static Map<String, Object> recreateMap(Map<String, Object> original) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.putAll(original);
|
||||
|
||||
@@ -241,7 +241,7 @@ public class UUIDVaultManager {
|
||||
public void saveFile(UUID holder, YamlConfiguration yaml) throws IOException {
|
||||
File file = new File(directory, holder.toString() + ".yml");
|
||||
if (file.exists()) {
|
||||
file.renameTo(new File(directory, "backups" + File.separator + holder.toString() + ".yml"));
|
||||
file.renameTo(new File(PlayerVaults.getInstance().getBackupsFolder(), holder.toString() + ".yml"));
|
||||
}
|
||||
yaml.save(file);
|
||||
}
|
||||
|
||||
@@ -261,7 +261,7 @@ public class VaultManager {
|
||||
public void saveFile(String holder, YamlConfiguration yaml) throws IOException {
|
||||
File file = new File(directory + File.separator + holder.toLowerCase() + ".yml");
|
||||
if (file.exists()) {
|
||||
file.renameTo(new File(directory + File.separator + "backups" + File.separator + holder.toLowerCase() + ".yml"));
|
||||
file.renameTo(new File(PlayerVaults.getInstance().getBackupsFolder(), holder.toLowerCase() + ".yml"));
|
||||
}
|
||||
yaml.save(file);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
name: PlayerVaults
|
||||
main: com.drtshock.playervaults.PlayerVaults
|
||||
authors: [drtshock, gomeow, Chester]
|
||||
authors: [drtshock, Koalaaaa]
|
||||
version: ${project.version}
|
||||
website: http://dev.bukkit.org/server-mods/PlayerVaults
|
||||
softdepend: [Vault]
|
||||
commands:
|
||||
pv:
|
||||
description: Open a vault with /pv <number>
|
||||
aliases: ['vault', 'chest', 'playervaults']
|
||||
aliases: [vault, chest, playervaults]
|
||||
pvdel:
|
||||
description: Delete a vault.
|
||||
aliases: [vaultdel]
|
||||
|
||||
Reference in New Issue
Block a user