Static ftw. Need to fix saving to file.
This commit is contained in:
+4
-1
@@ -1,6 +1,9 @@
|
||||
# PlayerVaults by drsthock
|
||||
# http://dev.bukkit.org/server-mods/playervaults
|
||||
|
||||
# Whether or not you want to check for updates.
|
||||
# Will not download an update, that is your job :)
|
||||
check-update: true
|
||||
debug-mode: false
|
||||
|
||||
# Worlds that players can't access their vaults.
|
||||
# playervaults.worlds.bypass will override this (default to op).
|
||||
|
||||
@@ -31,15 +31,13 @@ public class Listeners implements Listener {
|
||||
this.plugin = instance;
|
||||
}
|
||||
VaultManager vm = new VaultManager(plugin);
|
||||
Commands commands = new Commands();
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onQuit(PlayerQuitEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if(commands.inVault.containsKey(player.getName())) {
|
||||
if(Commands.inVault.containsKey(player.getName())) {
|
||||
Inventory inv = player.getOpenInventory().getTopInventory();
|
||||
int number = commands.inVault.get(player.getName());
|
||||
int number = Commands.inVault.get(player.getName());
|
||||
try {
|
||||
vm.saveVault(inv, player, number);
|
||||
} catch (IOException e) {
|
||||
@@ -60,9 +58,9 @@ public class Listeners implements Listener {
|
||||
@EventHandler
|
||||
public void onDeath(PlayerDeathEvent event) {
|
||||
Player player = event.getEntity();
|
||||
if(commands.inVault.containsKey(player.getName())) {
|
||||
if(Commands.inVault.containsKey(player.getName())) {
|
||||
Inventory inv = player.getOpenInventory().getTopInventory();
|
||||
int number = commands.inVault.get(player.getName());
|
||||
int number = Commands.inVault.get(player.getName());
|
||||
try {
|
||||
vm.saveVault(inv, player, number);
|
||||
} catch (IOException e) {
|
||||
@@ -74,9 +72,9 @@ public class Listeners implements Listener {
|
||||
@EventHandler
|
||||
public void onTP(PlayerTeleportEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if(commands.inVault.containsKey(player.getName())) {
|
||||
if(Commands.inVault.containsKey(player.getName())) {
|
||||
Inventory inv = player.getOpenInventory().getTopInventory();
|
||||
int number = commands.inVault.get(player.getName());
|
||||
int number = Commands.inVault.get(player.getName());
|
||||
try {
|
||||
vm.saveVault(inv, player, number);
|
||||
} catch (IOException e) {
|
||||
@@ -88,9 +86,9 @@ public class Listeners implements Listener {
|
||||
@EventHandler
|
||||
public void onWorldChange(PlayerChangedWorldEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if(commands.inVault.containsKey(player.getName())) {
|
||||
if(Commands.inVault.containsKey(player.getName())) {
|
||||
Inventory inv = player.getOpenInventory().getTopInventory();
|
||||
int number = commands.inVault.get(player.getName());
|
||||
int number = Commands.inVault.get(player.getName());
|
||||
try {
|
||||
vm.saveVault(inv, player, number);
|
||||
} catch (IOException e) {
|
||||
@@ -101,15 +99,15 @@ public class Listeners implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onClose(InventoryCloseEvent event) {
|
||||
System.out.println(commands.inVault.size());
|
||||
System.out.println(Commands.inVault.size());
|
||||
HumanEntity he = event.getPlayer();
|
||||
if(he instanceof Player) {
|
||||
if(commands.inVault.containsKey(he.getName())) {
|
||||
if(Commands.inVault.containsKey(he.getName())) {
|
||||
System.out.println("haskey :D");
|
||||
Player player = (Player) he;
|
||||
Inventory inv = player.getOpenInventory().getTopInventory();
|
||||
System.out.println("listener inv: " + inv);
|
||||
int number = commands.inVault.get(player.getName());
|
||||
int number = Commands.inVault.get(player.getName());
|
||||
try {
|
||||
vm.saveVault(inv, player, number);
|
||||
} catch (IOException e) {
|
||||
@@ -128,7 +126,7 @@ public class Listeners implements Listener {
|
||||
@EventHandler
|
||||
public void onInteract(PlayerInteractEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if(commands.inVault.containsKey(player.getName()) && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
if(Commands.inVault.containsKey(player.getName()) && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
Block block = event.getClickedBlock();
|
||||
|
||||
/**
|
||||
@@ -155,7 +153,7 @@ public void onInteract(PlayerInteractEvent event) {
|
||||
public void onInteractEntity(PlayerInteractEntityEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
EntityType type = event.getRightClicked().getType();
|
||||
if((type == EntityType.VILLAGER||type==EntityType.MINECART) && commands.inVault.containsKey(player.getName())) {
|
||||
if((type == EntityType.VILLAGER||type==EntityType.MINECART) && Commands.inVault.containsKey(player.getName())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,10 +120,6 @@ public class Main extends JavaPlugin {
|
||||
return getConfig().getBoolean("check-update");
|
||||
}
|
||||
|
||||
public boolean debugMode() {
|
||||
return getConfig().getBoolean("debug-mode");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return disabled worlds.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package me.shock.playervaults.commands;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
@@ -10,7 +10,7 @@ import org.bukkit.entity.Player;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
|
||||
public HashMap<String, Integer> inVault = new HashMap<String, Integer>();
|
||||
public static ConcurrentHashMap<String, Integer> inVault = new ConcurrentHashMap<String, Integer>();
|
||||
|
||||
private String pv = ChatColor.DARK_RED + "[" + ChatColor.WHITE + "PlayerVaults" +
|
||||
ChatColor.DARK_RED + "]" + ChatColor.WHITE + ": ";
|
||||
|
||||
@@ -22,6 +22,7 @@ public class OwnVault {
|
||||
int number = Integer.parseInt(arg0);
|
||||
vm.loadVault(sender, sender.getName(), number);
|
||||
sender.sendMessage(pv + "Opening vault " + ChatColor.GREEN + number);
|
||||
return true;
|
||||
} else {
|
||||
feedback.noPerms(sender);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package me.shock.playervaults.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import me.shock.playervaults.Main;
|
||||
import me.shock.playervaults.commands.Commands;
|
||||
@@ -23,7 +22,6 @@ public class VaultManager {
|
||||
this.plugin = instance;
|
||||
}
|
||||
|
||||
Commands commands = new Commands();
|
||||
String title;
|
||||
private String directory = "plugins" + File.separator + "PlayerVaults" + File.separator + "vaults";
|
||||
|
||||
@@ -35,7 +33,7 @@ public class VaultManager {
|
||||
* @throws IOException
|
||||
*/
|
||||
public void saveVault(Inventory inv, Player player, int number) throws IOException {
|
||||
if(commands.inVault.containsKey(player.getName())) {
|
||||
if(Commands.inVault.containsKey(player.getName())) {
|
||||
System.out.println("savevault");
|
||||
// Get the player's file and serialize the inventory.
|
||||
String ser = Serialization.toBase64(inv);
|
||||
@@ -43,9 +41,6 @@ public class VaultManager {
|
||||
System.out.println("" + inv);
|
||||
// Prepare to save D:
|
||||
file.set("vault" + number + "", ser);
|
||||
if(plugin.debugMode()) {
|
||||
plugin.getLogger().log(Level.INFO, "[PlayerVaults] Saved " + " " + number + " for " + player.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user