Make it so vaults being viewed at the same time update in real time

This commit is contained in:
gomeow
2013-05-23 14:36:16 -07:00
parent 5901d45310
commit 12f0a25565
4 changed files with 36 additions and 20 deletions
@@ -48,12 +48,15 @@ public class Listeners implements Listener {
public void saveVault(Player p) {
if(PlayerVaults.IN_VAULT.containsKey(p.getName())) {
Inventory inv = p.getOpenInventory().getTopInventory();
if(inv.getViewers().size() == 1) {
VaultViewInfo info = PlayerVaults.IN_VAULT.get(p.getName());
try {
vm.saveVault(inv, info.getHolder(), info.getNumber());
} catch(IOException e) {
e.printStackTrace();
}
PlayerVaults.OPENINVENTORIES.remove(info.toString());
}
PlayerVaults.IN_VAULT.remove(p.getName());
}
}
@@ -10,6 +10,7 @@ import java.util.logging.Logger;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.Inventory;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
@@ -31,6 +32,7 @@ public class PlayerVaults extends JavaPlugin {
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;
@@ -18,4 +18,8 @@ public class VaultViewInfo {
return this.i;
}
public String toString() {
return this.s + " " + this.i;
}
}
@@ -14,6 +14,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import com.drtshock.playervaults.PlayerVaults;
import com.drtshock.playervaults.commands.VaultViewInfo;
public class VaultManager {
@@ -51,7 +52,11 @@ public class VaultManager {
* TODO: Check to see if the path exists before we get it!
*/
public void loadVault(Player player, String holder, int number) {
VaultViewInfo info = new VaultViewInfo(holder, number);
Inventory inv = null;
if(PlayerVaults.OPENINVENTORIES.containsKey(info.toString())) {
inv = PlayerVaults.OPENINVENTORIES.get(info.toString());
} else {
YamlConfiguration playerFile = playerVaultFile(holder);
if(playerFile.getConfigurationSection("vault" + number) == null) {
inv = Bukkit.createInventory(player, 54, ChatColor.DARK_RED + "Vault #" + String.valueOf(number));
@@ -69,6 +74,8 @@ public class VaultManager {
}
inv = Serialization.toInventory(data, number);
}
PlayerVaults.OPENINVENTORIES.put(info.toString(), inv);
}
player.openInventory(inv);
}