Make things not so staticy
This commit is contained in:
@@ -25,7 +25,6 @@ import com.drtshock.playervaults.util.Lang;
|
|||||||
import com.drtshock.playervaults.util.Metrics;
|
import com.drtshock.playervaults.util.Metrics;
|
||||||
import com.drtshock.playervaults.util.Updater;
|
import com.drtshock.playervaults.util.Updater;
|
||||||
import com.drtshock.playervaults.vaultmanagement.UUIDVaultManager;
|
import com.drtshock.playervaults.vaultmanagement.UUIDVaultManager;
|
||||||
import com.drtshock.playervaults.vaultmanagement.VaultManager;
|
|
||||||
import com.drtshock.playervaults.vaultmanagement.VaultViewInfo;
|
import com.drtshock.playervaults.vaultmanagement.VaultViewInfo;
|
||||||
import net.milkbowl.vault.economy.Economy;
|
import net.milkbowl.vault.economy.Economy;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@@ -39,41 +38,32 @@ import org.bukkit.scheduler.BukkitRunnable;
|
|||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
public class PlayerVaults extends JavaPlugin {
|
public class PlayerVaults extends JavaPlugin {
|
||||||
|
|
||||||
// TODO: *reads down* really..? :c
|
private static PlayerVaults instance;
|
||||||
public static PlayerVaults PLUGIN;
|
|
||||||
public static Logger LOG;
|
|
||||||
public static boolean UPDATE = false;
|
|
||||||
public static String NEWVERSION = "";
|
|
||||||
public static String LINK = "";
|
|
||||||
public static Commands commands;
|
|
||||||
public static HashMap<String, SignSetInfo> SET_SIGN = new HashMap<String, SignSetInfo>();
|
|
||||||
public static HashMap<String, VaultViewInfo> IN_VAULT = new HashMap<String, VaultViewInfo>();
|
|
||||||
public static HashMap<String, Inventory> OPENINVENTORIES = new HashMap<String, Inventory>();
|
|
||||||
public static Economy ECON = null;
|
|
||||||
public static boolean DROP_ON_DEATH = false;
|
|
||||||
public static int INVENTORIES_TO_DROP = 0;
|
|
||||||
public static boolean USE_VAULT = false;
|
|
||||||
public static YamlConfiguration LANG;
|
|
||||||
public static File LANG_FILE;
|
|
||||||
public static YamlConfiguration SIGNS;
|
|
||||||
public static File SIGNS_FILE;
|
|
||||||
public static String DIRECTORY = "plugins" + File.separator + "PlayerVaults" + File.separator + "vaults";
|
|
||||||
public static VaultManager VM;
|
|
||||||
public static Listeners listener;
|
|
||||||
private boolean update = false;
|
private boolean update = false;
|
||||||
|
private String newVersion = "";
|
||||||
|
private String link = "";
|
||||||
|
private Commands commands;
|
||||||
|
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 boolean dropOnDeath = false;
|
||||||
|
private boolean useVault = false;
|
||||||
|
private int inventoriesToDrop = 0;
|
||||||
|
private YamlConfiguration signs;
|
||||||
|
private File signsFile;
|
||||||
|
private Listeners listener;
|
||||||
private String name = "";
|
private String name = "";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
PLUGIN = this;
|
instance = this;
|
||||||
getServer().getScheduler().runTask(this, new UUIDConversion()); // Convert to UUID first. Class checks if necessary.
|
getServer().getScheduler().runTask(this, new UUIDConversion()); // Convert to UUID first. Class checks if necessary.
|
||||||
loadLang();
|
loadLang();
|
||||||
new UUIDVaultManager();
|
new UUIDVaultManager();
|
||||||
LOG = getServer().getLogger();
|
|
||||||
getServer().getPluginManager().registerEvents(listener = new Listeners(this), this);
|
getServer().getPluginManager().registerEvents(listener = new Listeners(this), this);
|
||||||
loadConfig();
|
loadConfig();
|
||||||
loadSigns();
|
loadSigns();
|
||||||
@@ -87,12 +77,11 @@ public class PlayerVaults extends JavaPlugin {
|
|||||||
startMetrics();
|
startMetrics();
|
||||||
|
|
||||||
if (getConfig().getBoolean("drop-on-death.enabled")) {
|
if (getConfig().getBoolean("drop-on-death.enabled")) {
|
||||||
DROP_ON_DEATH = true;
|
dropOnDeath = true;
|
||||||
INVENTORIES_TO_DROP = getConfig().getInt("drop-on-death.inventories");
|
inventoriesToDrop = getConfig().getInt("drop-on-death.inventories");
|
||||||
}
|
}
|
||||||
|
|
||||||
new File(DIRECTORY + File.separator + "backups").mkdirs();
|
new File(getDataFolder() + File.separator + "vaults" + File.separator + "backups").mkdirs();
|
||||||
VM = new VaultManager(this);
|
|
||||||
|
|
||||||
if (getConfig().getBoolean("cleanup.enable", false)) {
|
if (getConfig().getBoolean("cleanup.enable", false)) {
|
||||||
getServer().getScheduler().runTaskAsynchronously(this, new Cleanup(getConfig().getInt("cleanup.lastEdit", 30)));
|
getServer().getScheduler().runTaskAsynchronously(this, new Cleanup(getConfig().getInt("cleanup.lastEdit", 30)));
|
||||||
@@ -116,22 +105,20 @@ public class PlayerVaults extends JavaPlugin {
|
|||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
if (IN_VAULT.containsKey(p.getName())) {
|
if (getInVault().containsKey(p.getName())) {
|
||||||
Inventory inv = p.getOpenInventory().getTopInventory();
|
Inventory inv = p.getOpenInventory().getTopInventory();
|
||||||
if (inv.getViewers().size() == 1) {
|
if (inv.getViewers().size() == 1) {
|
||||||
VaultViewInfo info = PlayerVaults.IN_VAULT.get(p.getName());
|
VaultViewInfo info = getInVault().get(p.getName());
|
||||||
try {
|
try {
|
||||||
VM.saveVault(inv, info.getHolder(), info.getNumber());
|
UUIDVaultManager.getInstance().saveVault(inv, p.getUniqueId(), info.getNumber());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
}
|
}
|
||||||
PlayerVaults.OPENINVENTORIES.remove(info.toString());
|
getOpenInventories().remove(info.toString());
|
||||||
}
|
}
|
||||||
PlayerVaults.IN_VAULT.remove(p.getName());
|
getInVault().remove(p.getName());
|
||||||
}
|
}
|
||||||
p.closeInventory();
|
p.closeInventory();
|
||||||
}
|
}
|
||||||
LANG = null;
|
|
||||||
LANG_FILE = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void checkUpdate() {
|
protected void checkUpdate() {
|
||||||
@@ -163,9 +150,9 @@ public class PlayerVaults extends JavaPlugin {
|
|||||||
if (rsp == null) {
|
if (rsp == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ECON = rsp.getProvider();
|
econ = rsp.getProvider();
|
||||||
USE_VAULT = true;
|
useVault = true;
|
||||||
return ECON != null;
|
return econ != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadConfig() {
|
private void loadConfig() {
|
||||||
@@ -183,13 +170,13 @@ public class PlayerVaults extends JavaPlugin {
|
|||||||
try {
|
try {
|
||||||
signs.createNewFile();
|
signs.createNewFile();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOG.severe("PlayerVaults has encountered a fatal error trying to load the signs file.");
|
getLogger().severe("PlayerVaults has encountered a fatal error trying to load the signs file.");
|
||||||
LOG.severe("Please report this error to drtshock and gomeow.");
|
getLogger().severe("Please report this error to drtshock.");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PlayerVaults.SIGNS_FILE = signs;
|
this.signsFile = signs;
|
||||||
PlayerVaults.SIGNS = YamlConfiguration.loadConfiguration(signs);
|
this.signs = YamlConfiguration.loadConfiguration(signs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -198,7 +185,7 @@ public class PlayerVaults extends JavaPlugin {
|
|||||||
* @return The signs.yml config.
|
* @return The signs.yml config.
|
||||||
*/
|
*/
|
||||||
public YamlConfiguration getSigns() {
|
public YamlConfiguration getSigns() {
|
||||||
return PlayerVaults.SIGNS;
|
return this.signs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -206,10 +193,10 @@ public class PlayerVaults extends JavaPlugin {
|
|||||||
*/
|
*/
|
||||||
public void saveSigns() {
|
public void saveSigns() {
|
||||||
try {
|
try {
|
||||||
PlayerVaults.SIGNS.save(PlayerVaults.SIGNS_FILE);
|
signs.save(this.signsFile);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOG.severe("PlayerVaults has encountered an error trying to save the signs file.");
|
getLogger().severe("PlayerVaults has encountered an error trying to save the signs file.");
|
||||||
LOG.severe("Please report this error to drtshock and gomeow.");
|
getLogger().severe("Please report this error to drtshock.");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -272,8 +259,8 @@ public class PlayerVaults extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace(); // So they notice
|
e.printStackTrace(); // So they notice
|
||||||
LOG.severe("[PlayerVaults] Couldn't create language file.");
|
getLogger().severe("[PlayerVaults] Couldn't create language file.");
|
||||||
LOG.severe("[PlayerVaults] This is a fatal error. Now disabling");
|
getLogger().severe("[PlayerVaults] This is a fatal error. Now disabling");
|
||||||
this.setEnabled(false); // Without it loaded, we can't send them messages
|
this.setEnabled(false); // Without it loaded, we can't send them messages
|
||||||
} finally {
|
} finally {
|
||||||
if (defLangStream != null) {
|
if (defLangStream != null) {
|
||||||
@@ -300,32 +287,44 @@ public class PlayerVaults extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Lang.setFile(conf);
|
Lang.setFile(conf);
|
||||||
PlayerVaults.LANG = conf;
|
|
||||||
PlayerVaults.LANG_FILE = lang;
|
|
||||||
try {
|
try {
|
||||||
conf.save(getLangFile());
|
conf.save(lang);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOG.log(Level.WARNING, "PlayerVaults: Failed to save lang.yml.");
|
getLogger().log(Level.WARNING, "PlayerVaults: Failed to save lang.yml.");
|
||||||
LOG.log(Level.WARNING, "PlayerVaults: Report this stack trace to drtshock and gomeow.");
|
getLogger().log(Level.WARNING, "PlayerVaults: Report this stack trace to drtshock and gomeow.");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public HashMap<String, SignSetInfo> getSetSign() {
|
||||||
* Gets the lang.yml config.
|
return this.setSign;
|
||||||
*
|
|
||||||
* @return The lang.yml config.
|
|
||||||
*/
|
|
||||||
public YamlConfiguration getLang() {
|
|
||||||
return LANG;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public HashMap<String, VaultViewInfo> getInVault() {
|
||||||
* Get the lang.yml file.
|
return this.inVault;
|
||||||
*
|
}
|
||||||
* @return The lang.yml file.
|
|
||||||
*/
|
public HashMap<String, Inventory> getOpenInventories() {
|
||||||
public File getLangFile() {
|
return this.openInventories;
|
||||||
return LANG_FILE;
|
}
|
||||||
|
|
||||||
|
public boolean needsUpdate() {
|
||||||
|
return this.update;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNewVersion() {
|
||||||
|
return this.newVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLink() {
|
||||||
|
return this.link;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Economy getEconomy() {
|
||||||
|
return this.econ;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PlayerVaults getInstance() {
|
||||||
|
return instance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,14 +37,15 @@ public class Commands implements CommandExecutor {
|
|||||||
if (cmd.getName().equalsIgnoreCase("pv")) {
|
if (cmd.getName().equalsIgnoreCase("pv")) {
|
||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
Player p = (Player) sender;
|
Player p = (Player) sender;
|
||||||
if (PlayerVaults.IN_VAULT.containsKey(p.getName())) return true; // don't let them open another vault.
|
if (PlayerVaults.getInstance().getInVault().containsKey(p.getName()))
|
||||||
|
return true; // don't let them open another vault.
|
||||||
switch (args.length) {
|
switch (args.length) {
|
||||||
case 1:
|
case 1:
|
||||||
if (VaultOperations.openOwnVault(p, args[0])) {
|
if (VaultOperations.openOwnVault(p, args[0])) {
|
||||||
PlayerVaults.IN_VAULT.put(sender.getName(), new VaultViewInfo(sender.getName(), Integer.parseInt(args[0])));
|
PlayerVaults.getInstance().getInVault().put(sender.getName(), new VaultViewInfo(sender.getName(), Integer.parseInt(args[0])));
|
||||||
} else if (sender.hasPermission("playervaults.admin")) {
|
} else if (sender.hasPermission("playervaults.admin")) {
|
||||||
OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]);
|
OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]);
|
||||||
if(player == null) {
|
if (player == null) {
|
||||||
sender.sendMessage(Lang.TITLE.toString() + "Cannot find player " + args[0]);
|
sender.sendMessage(Lang.TITLE.toString() + "Cannot find player " + args[0]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -67,7 +68,7 @@ public class Commands implements CommandExecutor {
|
|||||||
Player player = Bukkit.getPlayer(args[0]);
|
Player player = Bukkit.getPlayer(args[0]);
|
||||||
if (player == null) break;
|
if (player == null) break;
|
||||||
if (VaultOperations.openOtherVault(p, player, args[1])) {
|
if (VaultOperations.openOtherVault(p, player, args[1])) {
|
||||||
PlayerVaults.IN_VAULT.put(sender.getName(), new VaultViewInfo(args[0], Integer.parseInt(args[1])));
|
PlayerVaults.getInstance().getInVault().put(sender.getName(), new VaultViewInfo(args[0], Integer.parseInt(args[1])));
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(Lang.TITLE.toString() + "Failed to open vault.");
|
sender.sendMessage(Lang.TITLE.toString() + "Failed to open vault.");
|
||||||
}
|
}
|
||||||
@@ -122,7 +123,7 @@ public class Commands implements CommandExecutor {
|
|||||||
sender.sendMessage(Lang.TITLE.toString() + "Usage: /" + label + " <owner> <#>");
|
sender.sendMessage(Lang.TITLE.toString() + "Usage: /" + label + " <owner> <#>");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
PlayerVaults.SET_SIGN.put(sender.getName(), new SignSetInfo(i));
|
PlayerVaults.getInstance().getSetSign().put(sender.getName(), new SignSetInfo(i));
|
||||||
sender.sendMessage(Lang.TITLE.toString() + Lang.CLICK_A_SIGN);
|
sender.sendMessage(Lang.TITLE.toString() + Lang.CLICK_A_SIGN);
|
||||||
} else if (args.length >= 2) {
|
} else if (args.length >= 2) {
|
||||||
int i;
|
int i;
|
||||||
@@ -133,7 +134,7 @@ public class Commands implements CommandExecutor {
|
|||||||
sender.sendMessage(Lang.TITLE.toString() + "Usage: /" + label + " <owner> <#>");
|
sender.sendMessage(Lang.TITLE.toString() + "Usage: /" + label + " <owner> <#>");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
PlayerVaults.SET_SIGN.put(sender.getName(), new SignSetInfo(args[0].toLowerCase(), i));
|
PlayerVaults.getInstance().getSetSign().put(sender.getName(), new SignSetInfo(args[0].toLowerCase(), i));
|
||||||
sender.sendMessage(Lang.TITLE.toString() + Lang.CLICK_A_SIGN);
|
sender.sendMessage(Lang.TITLE.toString() + Lang.CLICK_A_SIGN);
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(Lang.TITLE.toString() + Lang.INVALID_ARGS);
|
sender.sendMessage(Lang.TITLE.toString() + Lang.INVALID_ARGS);
|
||||||
|
|||||||
@@ -18,12 +18,11 @@ package com.drtshock.playervaults.listeners;
|
|||||||
|
|
||||||
import com.drtshock.playervaults.PlayerVaults;
|
import com.drtshock.playervaults.PlayerVaults;
|
||||||
import com.drtshock.playervaults.util.Lang;
|
import com.drtshock.playervaults.util.Lang;
|
||||||
|
import com.drtshock.playervaults.vaultmanagement.UUIDVaultManager;
|
||||||
import com.drtshock.playervaults.vaultmanagement.VaultManager;
|
import com.drtshock.playervaults.vaultmanagement.VaultManager;
|
||||||
import com.drtshock.playervaults.vaultmanagement.VaultOperations;
|
import com.drtshock.playervaults.vaultmanagement.VaultOperations;
|
||||||
import com.drtshock.playervaults.vaultmanagement.VaultViewInfo;
|
import com.drtshock.playervaults.vaultmanagement.VaultViewInfo;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.*;
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
@@ -53,17 +52,17 @@ public class Listeners implements Listener {
|
|||||||
VaultManager vm = new VaultManager(plugin);
|
VaultManager vm = new VaultManager(plugin);
|
||||||
|
|
||||||
public void saveVault(Player player) {
|
public void saveVault(Player player) {
|
||||||
if (PlayerVaults.IN_VAULT.containsKey(player.getName())) {
|
if (PlayerVaults.getInstance().getInVault().containsKey(player.getName())) {
|
||||||
Inventory inv = player.getOpenInventory().getTopInventory();
|
Inventory inv = player.getOpenInventory().getTopInventory();
|
||||||
if (inv.getViewers().size() == 1) {
|
if (inv.getViewers().size() == 1) {
|
||||||
VaultViewInfo info = PlayerVaults.IN_VAULT.get(player.getName());
|
VaultViewInfo info = PlayerVaults.getInstance().getInVault().get(player.getName());
|
||||||
try {
|
try {
|
||||||
vm.saveVault(inv, info.getHolder(), info.getNumber());
|
vm.saveVault(inv, info.getHolder(), info.getNumber());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
}
|
}
|
||||||
PlayerVaults.OPENINVENTORIES.remove(info.toString());
|
PlayerVaults.getInstance().getOpenInventories().remove(info.toString());
|
||||||
}
|
}
|
||||||
PlayerVaults.IN_VAULT.remove(player.getName());
|
PlayerVaults.getInstance().getInVault().remove(player.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,9 +80,9 @@ public class Listeners implements Listener {
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onJoin(PlayerJoinEvent event) {
|
public void onJoin(PlayerJoinEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
if (PlayerVaults.UPDATE && (player.isOp() || player.hasPermission("playervaults.notify"))) {
|
if (PlayerVaults.getInstance().needsUpdate() && (player.isOp() || player.hasPermission("playervaults.notify"))) {
|
||||||
player.sendMessage(ChatColor.GREEN + "Version " + PlayerVaults.NEWVERSION + " of PlayerVaults is up for download!");
|
player.sendMessage(ChatColor.GREEN + "Version " + PlayerVaults.getInstance().getNewVersion() + " of PlayerVaults is up for download!");
|
||||||
player.sendMessage(ChatColor.GREEN + PlayerVaults.LINK + " to view the changelog and download!");
|
player.sendMessage(ChatColor.GREEN + PlayerVaults.getInstance().getLink() + " to view the changelog and download!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,7 +105,7 @@ public class Listeners implements Listener {
|
|||||||
public void onInteract(PlayerInteractEvent event) {
|
public void onInteract(PlayerInteractEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||||
if (PlayerVaults.IN_VAULT.containsKey(player.getName())) {
|
if (PlayerVaults.getInstance().getInVault().containsKey(player.getName())) {
|
||||||
Block block = event.getClickedBlock();
|
Block block = event.getClickedBlock();
|
||||||
// Different inventories that we don't want the player to open.
|
// Different inventories that we don't want the player to open.
|
||||||
if (block.getType() == Material.CHEST
|
if (block.getType() == Material.CHEST
|
||||||
@@ -121,14 +120,14 @@ public class Listeners implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (PlayerVaults.SET_SIGN.containsKey(player.getName())) {
|
if (PlayerVaults.getInstance().getSetSign().containsKey(player.getName())) {
|
||||||
int i = PlayerVaults.SET_SIGN.get(player.getName()).getChest();
|
int i = PlayerVaults.getInstance().getSetSign().get(player.getName()).getChest();
|
||||||
boolean self = PlayerVaults.SET_SIGN.get(player.getName()).isSelf();
|
boolean self = PlayerVaults.getInstance().getSetSign().get(player.getName()).isSelf();
|
||||||
String owner = null;
|
String owner = null;
|
||||||
if (!self) {
|
if (!self) {
|
||||||
owner = PlayerVaults.SET_SIGN.get(player.getName()).getOwner();
|
owner = PlayerVaults.getInstance().getSetSign().get(player.getName()).getOwner();
|
||||||
}
|
}
|
||||||
PlayerVaults.SET_SIGN.remove(player.getName());
|
PlayerVaults.getInstance().getSetSign().remove(player.getName());
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||||
if (event.getClickedBlock().getType() == Material.WALL_SIGN || event.getClickedBlock().getType() == Material.SIGN_POST) {
|
if (event.getClickedBlock().getType() == Material.WALL_SIGN || event.getClickedBlock().getType() == Material.SIGN_POST) {
|
||||||
@@ -163,16 +162,26 @@ public class Listeners implements Listener {
|
|||||||
int y = l.getBlockY();
|
int y = l.getBlockY();
|
||||||
int z = l.getBlockZ();
|
int z = l.getBlockZ();
|
||||||
if (plugin.getSigns().getKeys(false).contains(world + ";;" + x + ";;" + y + ";;" + z)) {
|
if (plugin.getSigns().getKeys(false).contains(world + ";;" + x + ";;" + y + ";;" + z)) {
|
||||||
int num = PlayerVaults.SIGNS.getInt(world + ";;" + x + ";;" + y + ";;" + z + ".chest");
|
int num = PlayerVaults.getInstance().getSigns().getInt(world + ";;" + x + ";;" + y + ";;" + z + ".chest");
|
||||||
if ((player.hasPermission("playervaults.signs.use") && (player.hasPermission("playervaults.signs.bypass") || VaultOperations.checkPerms(player, 99)))) {
|
if ((player.hasPermission("playervaults.signs.use") && (player.hasPermission("playervaults.signs.bypass") || VaultOperations.checkPerms(player, 99)))) {
|
||||||
boolean self = PlayerVaults.SIGNS.getBoolean(world + ";;" + x + ";;" + y + ";;" + z + ".self", false);
|
boolean self = PlayerVaults.getInstance().getSigns().getBoolean(world + ";;" + x + ";;" + y + ";;" + z + ".self", false);
|
||||||
String owner = null;
|
String owner = null;
|
||||||
if (!self) {
|
if (!self) {
|
||||||
owner = PlayerVaults.SIGNS.getString(world + ";;" + x + ";;" + y + ";;" + z + ".owner");
|
owner = PlayerVaults.getInstance().getSigns().getString(world + ";;" + x + ";;" + y + ";;" + z + ".owner");
|
||||||
}
|
}
|
||||||
Inventory inv = PlayerVaults.VM.loadOwnVault((self) ? player.getName() : owner, num, VaultOperations.getMaxVaultSize(player));
|
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(owner);
|
||||||
player.openInventory(inv);
|
if (offlinePlayer == null) {
|
||||||
PlayerVaults.IN_VAULT.put(player.getName(), new VaultViewInfo((self) ? player.getName() : owner, num));
|
player.sendMessage(Lang.TITLE.toString() + Lang.VAULT_DOES_NOT_EXIST.toString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (self) {
|
||||||
|
Inventory inv = UUIDVaultManager.getInstance().loadOwnVault(player, num, VaultOperations.getMaxVaultSize(player));
|
||||||
|
player.openInventory(inv);
|
||||||
|
} else {
|
||||||
|
Inventory inv = UUIDVaultManager.getInstance().loadOtherVault(offlinePlayer.getUniqueId(), num, VaultOperations.getMaxVaultSize(offlinePlayer));
|
||||||
|
player.openInventory(inv);
|
||||||
|
}
|
||||||
|
PlayerVaults.getInstance().getInVault().put(player.getName(), new VaultViewInfo((self) ? player.getName() : owner, num));
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
player.sendMessage(Lang.TITLE.toString() + Lang.OPEN_WITH_SIGN.toString().replace("%v", String.valueOf(num)).replace("%p", (self) ? player.getName() : owner));
|
player.sendMessage(Lang.TITLE.toString() + Lang.OPEN_WITH_SIGN.toString().replace("%v", String.valueOf(num)).replace("%p", (self) ? player.getName() : owner));
|
||||||
} else {
|
} else {
|
||||||
@@ -218,7 +227,7 @@ public class Listeners implements Listener {
|
|||||||
public void onInteractEntity(PlayerInteractEntityEvent event) {
|
public void onInteractEntity(PlayerInteractEntityEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
EntityType type = event.getRightClicked().getType();
|
EntityType type = event.getRightClicked().getType();
|
||||||
if ((type == EntityType.VILLAGER || type == EntityType.MINECART) && PlayerVaults.IN_VAULT.containsKey(player.getName())) {
|
if ((type == EntityType.VILLAGER || type == EntityType.MINECART) && PlayerVaults.getInstance().getInVault().containsKey(player.getName())) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,14 +16,14 @@ public class Cleanup extends BukkitRunnable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
File file = new File(PlayerVaults.DIRECTORY);
|
File file = new File(PlayerVaults.getInstance().getDataFolder(), "vaults");
|
||||||
if (!file.exists()) return;
|
if (!file.exists()) return;
|
||||||
|
|
||||||
long time = System.currentTimeMillis();
|
long time = System.currentTimeMillis();
|
||||||
for (File f : file.listFiles()) {
|
for (File f : file.listFiles()) {
|
||||||
if (time - f.lastModified() > diff) {
|
if (time - f.lastModified() > diff) {
|
||||||
f.delete();
|
f.delete();
|
||||||
PlayerVaults.PLUGIN.getLogger().info("Deleting vault file: " + f.getName());
|
PlayerVaults.getInstance().getLogger().info("Deleting vault file: " + f.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,34 +18,34 @@ public final class UUIDConversion extends BukkitRunnable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
File newDir = new File(PlayerVaults.PLUGIN.getDataFolder(), "uuidvaults");
|
File newDir = new File(PlayerVaults.getInstance().getDataFolder(), "uuidvaults");
|
||||||
if (newDir.exists()) {
|
if (newDir.exists()) {
|
||||||
PlayerVaults.LOG.log(Level.INFO, "Files already converted to UUID.");
|
PlayerVaults.getInstance().getLogger().log(Level.INFO, "Files already converted to UUID.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
newDir.mkdirs();
|
newDir.mkdirs();
|
||||||
|
|
||||||
PlayerVaults.LOG.log(Level.INFO, "********** Starting PlayerVault conversion to UUIDs **********");
|
PlayerVaults.getInstance().getLogger().log(Level.INFO, "********** Starting PlayerVault conversion to UUIDs **********");
|
||||||
PlayerVaults.LOG.log(Level.INFO, "This might take awhile.");
|
PlayerVaults.getInstance().getLogger().log(Level.INFO, "This might take awhile.");
|
||||||
PlayerVaults.LOG.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 still be there as a backup but unused.");
|
||||||
|
|
||||||
for (File file : new File(PlayerVaults.PLUGIN.getDataFolder() + File.separator + "vaults").listFiles()) {
|
for (File file : new File(PlayerVaults.getInstance().getDataFolder() + File.separator + "vaults").listFiles()) {
|
||||||
if (file.isDirectory()) break; // backups folder.
|
if (file.isDirectory()) break; // backups folder.
|
||||||
OfflinePlayer player = Bukkit.getOfflinePlayer(file.getName().replace(".yml", ""));
|
OfflinePlayer player = Bukkit.getOfflinePlayer(file.getName().replace(".yml", ""));
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
PlayerVaults.LOG.log(Level.WARNING, "Unable to convert file because player never joined the server: " + file.getName());
|
PlayerVaults.getInstance().getLogger().log(Level.WARNING, "Unable to convert file because player never joined the server: " + file.getName());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
UUID uuid = player.getUniqueId();
|
UUID uuid = player.getUniqueId();
|
||||||
File newFile = new File(PlayerVaults.PLUGIN.getDataFolder(), "uuidvaults" + File.separator + uuid.toString() + ".yml");
|
File newFile = new File(PlayerVaults.getInstance().getDataFolder(), "uuidvaults" + File.separator + uuid.toString() + ".yml");
|
||||||
file.mkdirs();
|
file.mkdirs();
|
||||||
try {
|
try {
|
||||||
FileUtils.copyFile(file, newFile);
|
FileUtils.copyFile(file, newFile);
|
||||||
PlayerVaults.LOG.log(Level.INFO, "Successfully converted vault file for " + player.getName());
|
PlayerVaults.getInstance().getLogger().log(Level.INFO, "Successfully converted vault file for " + player.getName());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
PlayerVaults.LOG.log(Level.SEVERE, "Couldn't convert vault file for " + player.getName());
|
PlayerVaults.getInstance().getLogger().log(Level.SEVERE, "Couldn't convert vault file for " + player.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PlayerVaults.LOG.log(Level.INFO, "********** Conversion done ;D **********");
|
PlayerVaults.getInstance().getLogger().log(Level.INFO, "********** Conversion done ;D **********");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,14 +50,14 @@ public class EconomyOperations {
|
|||||||
* @return The transaction success.
|
* @return The transaction success.
|
||||||
*/
|
*/
|
||||||
public static boolean payToOpen(Player player, int number) {
|
public static boolean payToOpen(Player player, int number) {
|
||||||
if (!BUKKIT_CONFIG.getBoolean("economy.enabled") || player.hasPermission("playervaults.free") || !PlayerVaults.USE_VAULT) {
|
if (!BUKKIT_CONFIG.getBoolean("economy.enabled") || player.hasPermission("playervaults.free") || PlayerVaults.getInstance().getEconomy() != null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (PlayerVaults.VM.vaultExists(player.getName(), number)) {
|
if (UUIDVaultManager.getInstance().vaultExists(player.getUniqueId(), number)) {
|
||||||
return payToCreate(player);
|
return payToCreate(player);
|
||||||
} else {
|
} else {
|
||||||
double cost = BUKKIT_CONFIG.getDouble("economy.cost-to-create", 100);
|
double cost = BUKKIT_CONFIG.getDouble("economy.cost-to-create", 100);
|
||||||
EconomyResponse resp = PlayerVaults.ECON.withdrawPlayer(player.getName(), cost);
|
EconomyResponse resp = PlayerVaults.getInstance().getEconomy().withdrawPlayer(player.getName(), cost);
|
||||||
if (resp.transactionSuccess()) {
|
if (resp.transactionSuccess()) {
|
||||||
player.sendMessage(Lang.TITLE.toString() + Lang.COST_TO_OPEN.toString().replaceAll("%price", "" + cost));
|
player.sendMessage(Lang.TITLE.toString() + Lang.COST_TO_OPEN.toString().replaceAll("%price", "" + cost));
|
||||||
return true;
|
return true;
|
||||||
@@ -74,12 +74,12 @@ public class EconomyOperations {
|
|||||||
* @return The transaction success
|
* @return The transaction success
|
||||||
*/
|
*/
|
||||||
public static boolean payToCreate(Player player) {
|
public static boolean payToCreate(Player player) {
|
||||||
if (!BUKKIT_CONFIG.getBoolean("economy.enabled") || player.hasPermission("playervaults.free") || !PlayerVaults.USE_VAULT) {
|
if (!BUKKIT_CONFIG.getBoolean("economy.enabled") || player.hasPermission("playervaults.free") || PlayerVaults.getInstance().getEconomy() != null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
double cost = BUKKIT_CONFIG.getDouble("economy.cost-to-create", 100);
|
double cost = BUKKIT_CONFIG.getDouble("economy.cost-to-create", 100);
|
||||||
EconomyResponse resp = PlayerVaults.ECON.withdrawPlayer(player.getName(), cost);
|
EconomyResponse resp = PlayerVaults.getInstance().getEconomy().withdrawPlayer(player.getName(), cost);
|
||||||
if (resp.transactionSuccess()) {
|
if (resp.transactionSuccess()) {
|
||||||
player.sendMessage(Lang.TITLE.toString() + Lang.COST_TO_CREATE.toString().replaceAll("%price", "" + cost));
|
player.sendMessage(Lang.TITLE.toString() + Lang.COST_TO_CREATE.toString().replaceAll("%price", "" + cost));
|
||||||
return true;
|
return true;
|
||||||
@@ -97,7 +97,7 @@ public class EconomyOperations {
|
|||||||
*/
|
*/
|
||||||
public static boolean refundOnDelete(Player player, int number) {
|
public static boolean refundOnDelete(Player player, int number) {
|
||||||
String directory = "plugins" + File.separator + "PlayerVaults" + File.separator + "vaults";
|
String directory = "plugins" + File.separator + "PlayerVaults" + File.separator + "vaults";
|
||||||
if (!BUKKIT_CONFIG.getBoolean("economy.enabled") || player.hasPermission("playervaults.free") || !PlayerVaults.USE_VAULT) {
|
if (!BUKKIT_CONFIG.getBoolean("economy.enabled") || player.hasPermission("playervaults.free") || PlayerVaults.getInstance().getEconomy() != null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
String name = player.getName().toLowerCase();
|
String name = player.getName().toLowerCase();
|
||||||
@@ -113,7 +113,7 @@ public class EconomyOperations {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
double cost = BUKKIT_CONFIG.getDouble("economy.refund-on-delete");
|
double cost = BUKKIT_CONFIG.getDouble("economy.refund-on-delete");
|
||||||
EconomyResponse resp = PlayerVaults.ECON.depositPlayer(player.getName(), cost);
|
EconomyResponse resp = PlayerVaults.getInstance().getEconomy().depositPlayer(player.getName(), cost);
|
||||||
if (resp.transactionSuccess()) {
|
if (resp.transactionSuccess()) {
|
||||||
player.sendMessage(Lang.TITLE.toString() + Lang.REFUND_AMOUNT.toString().replaceAll("%price", String.valueOf(cost)));
|
player.sendMessage(Lang.TITLE.toString() + Lang.REFUND_AMOUNT.toString().replaceAll("%price", String.valueOf(cost)));
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -70,8 +70,8 @@ public class UUIDVaultManager {
|
|||||||
}
|
}
|
||||||
VaultViewInfo info = new VaultViewInfo(player.getUniqueId().toString(), number);
|
VaultViewInfo info = new VaultViewInfo(player.getUniqueId().toString(), number);
|
||||||
Inventory inv = null;
|
Inventory inv = null;
|
||||||
if (PlayerVaults.OPENINVENTORIES.containsKey(info.toString())) {
|
if (PlayerVaults.getInstance().getOpenInventories().containsKey(info.toString())) {
|
||||||
inv = PlayerVaults.OPENINVENTORIES.get(info.toString());
|
inv = PlayerVaults.getInstance().getOpenInventories().get(info.toString());
|
||||||
} else {
|
} else {
|
||||||
YamlConfiguration playerFile = getPlayerVaultFile(player.getUniqueId());
|
YamlConfiguration playerFile = getPlayerVaultFile(player.getUniqueId());
|
||||||
if (playerFile.getConfigurationSection("vault" + number) == null) {
|
if (playerFile.getConfigurationSection("vault" + number) == null) {
|
||||||
@@ -90,7 +90,7 @@ public class UUIDVaultManager {
|
|||||||
inv = getInventory(playerFile, size, number);
|
inv = getInventory(playerFile, size, number);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PlayerVaults.OPENINVENTORIES.put(info.toString(), inv);
|
PlayerVaults.getInstance().getOpenInventories().put(info.toString(), inv);
|
||||||
}
|
}
|
||||||
return inv;
|
return inv;
|
||||||
}
|
}
|
||||||
@@ -107,8 +107,8 @@ public class UUIDVaultManager {
|
|||||||
}
|
}
|
||||||
VaultViewInfo info = new VaultViewInfo(holder.toString(), number);
|
VaultViewInfo info = new VaultViewInfo(holder.toString(), number);
|
||||||
Inventory inv = null;
|
Inventory inv = null;
|
||||||
if (PlayerVaults.OPENINVENTORIES.containsKey(info.toString())) {
|
if (PlayerVaults.getInstance().getOpenInventories().containsKey(info.toString())) {
|
||||||
inv = PlayerVaults.OPENINVENTORIES.get(info.toString());
|
inv = PlayerVaults.getInstance().getOpenInventories().get(info.toString());
|
||||||
} else {
|
} else {
|
||||||
YamlConfiguration playerFile = getPlayerVaultFile(holder);
|
YamlConfiguration playerFile = getPlayerVaultFile(holder);
|
||||||
if (playerFile.getConfigurationSection("vault" + number) == null) {
|
if (playerFile.getConfigurationSection("vault" + number) == null) {
|
||||||
@@ -120,7 +120,7 @@ public class UUIDVaultManager {
|
|||||||
inv = getInventory(playerFile, size, number);
|
inv = getInventory(playerFile, size, number);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PlayerVaults.OPENINVENTORIES.put(info.toString(), inv);
|
PlayerVaults.getInstance().getOpenInventories().put(info.toString(), inv);
|
||||||
}
|
}
|
||||||
return inv;
|
return inv;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,8 +86,8 @@ public class VaultManager {
|
|||||||
}
|
}
|
||||||
VaultViewInfo info = new VaultViewInfo(holder, number);
|
VaultViewInfo info = new VaultViewInfo(holder, number);
|
||||||
Inventory inv = null;
|
Inventory inv = null;
|
||||||
if (PlayerVaults.OPENINVENTORIES.containsKey(info.toString())) {
|
if (PlayerVaults.getInstance().getOpenInventories().containsKey(info.toString())) {
|
||||||
inv = PlayerVaults.OPENINVENTORIES.get(info.toString());
|
inv = PlayerVaults.getInstance().getOpenInventories().get(info.toString());
|
||||||
} else {
|
} else {
|
||||||
YamlConfiguration playerFile = getPlayerVaultFile(holder);
|
YamlConfiguration playerFile = getPlayerVaultFile(holder);
|
||||||
if (playerFile.getConfigurationSection("vault" + number) == null) {
|
if (playerFile.getConfigurationSection("vault" + number) == null) {
|
||||||
@@ -110,7 +110,7 @@ public class VaultManager {
|
|||||||
inv = getInventory(playerFile, size, number);
|
inv = getInventory(playerFile, size, number);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PlayerVaults.OPENINVENTORIES.put(info.toString(), inv);
|
PlayerVaults.getInstance().getOpenInventories().put(info.toString(), inv);
|
||||||
}
|
}
|
||||||
return inv;
|
return inv;
|
||||||
}
|
}
|
||||||
@@ -128,8 +128,8 @@ public class VaultManager {
|
|||||||
}
|
}
|
||||||
VaultViewInfo info = new VaultViewInfo(holder, number);
|
VaultViewInfo info = new VaultViewInfo(holder, number);
|
||||||
Inventory inv = null;
|
Inventory inv = null;
|
||||||
if (PlayerVaults.OPENINVENTORIES.containsKey(info.toString())) {
|
if (PlayerVaults.getInstance().getOpenInventories().containsKey(info.toString())) {
|
||||||
inv = PlayerVaults.OPENINVENTORIES.get(info.toString());
|
inv = PlayerVaults.getInstance().getOpenInventories().get(info.toString());
|
||||||
} else {
|
} else {
|
||||||
YamlConfiguration playerFile = getPlayerVaultFile(holder);
|
YamlConfiguration playerFile = getPlayerVaultFile(holder);
|
||||||
if (playerFile.getConfigurationSection("vault" + number) == null) {
|
if (playerFile.getConfigurationSection("vault" + number) == null) {
|
||||||
@@ -141,7 +141,7 @@ public class VaultManager {
|
|||||||
inv = getInventory(playerFile, size, number);
|
inv = getInventory(playerFile, size, number);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PlayerVaults.OPENINVENTORIES.put(info.toString(), inv);
|
PlayerVaults.getInstance().getOpenInventories().put(info.toString(), inv);
|
||||||
}
|
}
|
||||||
return inv;
|
return inv;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user