Fix disable dupe. Consistent spacing.
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.drtshock</groupId>
|
<groupId>com.drtshock</groupId>
|
||||||
<artifactId>PlayerVaults</artifactId>
|
<artifactId>PlayerVaults</artifactId>
|
||||||
<version>3.3.0-SNAPSHOT</version>
|
<version>3.2.1</version>
|
||||||
<name>PlayerVaults</name>
|
<name>PlayerVaults</name>
|
||||||
<url>http://dev.bukkit.org/server-mods/playervaults/</url>
|
<url>http://dev.bukkit.org/server-mods/playervaults/</url>
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ import com.drtshock.playervaults.commands.VaultViewInfo;
|
|||||||
import com.drtshock.playervaults.util.DropOnDeath;
|
import com.drtshock.playervaults.util.DropOnDeath;
|
||||||
import com.drtshock.playervaults.util.Lang;
|
import com.drtshock.playervaults.util.Lang;
|
||||||
import com.drtshock.playervaults.util.VaultManager;
|
import com.drtshock.playervaults.util.VaultManager;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.event.server.PluginDisableEvent;
|
||||||
|
|
||||||
public class Listeners implements Listener {
|
public class Listeners implements Listener {
|
||||||
|
|
||||||
@@ -37,12 +39,11 @@ public class Listeners implements Listener {
|
|||||||
public Listeners(PlayerVaults playerVaults) {
|
public Listeners(PlayerVaults playerVaults) {
|
||||||
this.plugin = playerVaults;
|
this.plugin = playerVaults;
|
||||||
}
|
}
|
||||||
|
|
||||||
VaultManager vm = new VaultManager(plugin);
|
VaultManager vm = new VaultManager(plugin);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save a players vault.
|
* Save a players vault. Sends to method in VaultManager class.
|
||||||
* Sends to method in VaultManager class.
|
*
|
||||||
* @param Player p
|
* @param Player p
|
||||||
*/
|
*/
|
||||||
public void saveVault(Player p) {
|
public void saveVault(Player p) {
|
||||||
@@ -53,7 +54,6 @@ public class Listeners implements Listener {
|
|||||||
try {
|
try {
|
||||||
vm.saveVault(inv, info.getHolder(), info.getNumber());
|
vm.saveVault(inv, info.getHolder(), info.getNumber());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
PlayerVaults.OPENINVENTORIES.remove(info.toString());
|
PlayerVaults.OPENINVENTORIES.remove(info.toString());
|
||||||
}
|
}
|
||||||
@@ -61,6 +61,21 @@ public class Listeners implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save vaults when the plugin disables. Fixes a dupe on server shutdown
|
||||||
|
* with open vaults.
|
||||||
|
*
|
||||||
|
* @param event
|
||||||
|
*/
|
||||||
|
@EventHandler
|
||||||
|
public void onDisableEvent(PluginDisableEvent event) {
|
||||||
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
|
if(PlayerVaults.IN_VAULT.containsKey(p.getName())) {
|
||||||
|
p.closeInventory();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onTeleport(PlayerTeleportEvent event) {
|
public void onTeleport(PlayerTeleportEvent event) {
|
||||||
saveVault(event.getPlayer());
|
saveVault(event.getPlayer());
|
||||||
@@ -101,9 +116,9 @@ public class Listeners implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a player is trying to do something while
|
* Check if a player is trying to do something while in a vault. Don't let
|
||||||
* in a vault.
|
* them open up another chest.
|
||||||
* Don't let them open up another chest.
|
*
|
||||||
* @param PlayerInteractEvent
|
* @param PlayerInteractEvent
|
||||||
*/
|
*/
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@@ -114,8 +129,7 @@ public class Listeners implements Listener {
|
|||||||
Block block = event.getClickedBlock();
|
Block block = event.getClickedBlock();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Different inventories that
|
* Different inventories that we don't want the player to open.
|
||||||
* we don't want the player to open.
|
|
||||||
*/
|
*/
|
||||||
if (block.getType() == Material.CHEST
|
if (block.getType() == Material.CHEST
|
||||||
|| block.getType() == Material.ENDER_CHEST
|
|| block.getType() == Material.ENDER_CHEST
|
||||||
@@ -215,8 +229,8 @@ public class Listeners implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Don't let a player open a trading inventory OR a minecart
|
* Don't let a player open a trading inventory OR a minecart while he has
|
||||||
* while he has his vault open.
|
* his vault open.
|
||||||
*/
|
*/
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onInteractEntity(PlayerInteractEntityEvent event) {
|
public void onInteractEntity(PlayerInteractEntityEvent event) {
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ public class VaultViewInfo {
|
|||||||
return this.i;
|
return this.i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return this.s + " " + this.i;
|
return this.s + " " + this.i;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,13 +23,12 @@ public class VaultManager {
|
|||||||
public VaultManager(PlayerVaults instance) {
|
public VaultManager(PlayerVaults instance) {
|
||||||
this.plugin = instance;
|
this.plugin = instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final String directory = "plugins" + File.separator + "PlayerVaults" + File.separator + "vaults";
|
private final String directory = "plugins" + File.separator + "PlayerVaults" + File.separator + "vaults";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to save player's vault.
|
* Method to save player's vault. Serialize his inventory. Save the
|
||||||
* Serialize his inventory.
|
* vaults.yml
|
||||||
* Save the vaults.yml
|
*
|
||||||
* @param player
|
* @param player
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
@@ -39,15 +38,15 @@ public class VaultManager {
|
|||||||
List<String> list = Serialization.toString(inv);
|
List<String> list = Serialization.toString(inv);
|
||||||
String[] ser = list.toArray(new String[list.size()]);
|
String[] ser = list.toArray(new String[list.size()]);
|
||||||
for (int x = 0; x < ser.length; x++) {
|
for (int x = 0; x < ser.length; x++) {
|
||||||
if(!ser[x].equalsIgnoreCase("null"))
|
if (!ser[x].equalsIgnoreCase("null")) {
|
||||||
yaml.set("vault" + number + "." + x, ser[x]);
|
yaml.set("vault" + number + "." + x, ser[x]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
saveFile(player, yaml);
|
saveFile(player, yaml);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to load player's vault.
|
* Method to load player's vault. Deserialize his inventory
|
||||||
* Deserialize his inventory
|
|
||||||
*
|
*
|
||||||
* TODO: Check to see if the path exists before we get it!
|
* TODO: Check to see if the path exists before we get it!
|
||||||
*/
|
*/
|
||||||
@@ -60,15 +59,13 @@ public class VaultManager {
|
|||||||
YamlConfiguration playerFile = playerVaultFile(holder);
|
YamlConfiguration playerFile = playerVaultFile(holder);
|
||||||
if (playerFile.getConfigurationSection("vault" + number) == null) {
|
if (playerFile.getConfigurationSection("vault" + number) == null) {
|
||||||
inv = Bukkit.createInventory(player, 54, ChatColor.DARK_RED + "Vault #" + String.valueOf(number));
|
inv = Bukkit.createInventory(player, 54, ChatColor.DARK_RED + "Vault #" + String.valueOf(number));
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
List<String> data = new ArrayList<String>();
|
List<String> data = new ArrayList<String>();
|
||||||
for (int x = 0; x < 54; x++) {
|
for (int x = 0; x < 54; x++) {
|
||||||
String line = playerFile.getString("vault" + number + "." + x);
|
String line = playerFile.getString("vault" + number + "." + x);
|
||||||
if (line != null) {
|
if (line != null) {
|
||||||
data.add(line);
|
data.add(line);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
data.add("null");
|
data.add("null");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -80,8 +77,9 @@ public class VaultManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets an inventory without opening it.
|
* Gets an inventory without opening it. Used for dropping a players
|
||||||
* Used for dropping a players inventories on death.
|
* inventories on death.
|
||||||
|
*
|
||||||
* @param player
|
* @param player
|
||||||
* @param number
|
* @param number
|
||||||
* @return the inventory
|
* @return the inventory
|
||||||
@@ -100,6 +98,7 @@ public class VaultManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes a players vault.
|
* Deletes a players vault.
|
||||||
|
*
|
||||||
* @param sender
|
* @param sender
|
||||||
* @param target
|
* @param target
|
||||||
* @param number
|
* @param number
|
||||||
@@ -115,15 +114,14 @@ public class VaultManager {
|
|||||||
}
|
}
|
||||||
if (sender.getName().equalsIgnoreCase(target)) {
|
if (sender.getName().equalsIgnoreCase(target)) {
|
||||||
sender.sendMessage(Lang.TITLE.toString() + Lang.DELETE_VAULT.toString().replace("%v", String.valueOf(number)));
|
sender.sendMessage(Lang.TITLE.toString() + Lang.DELETE_VAULT.toString().replace("%v", String.valueOf(number)));
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
sender.sendMessage(Lang.TITLE.toString() + Lang.DELETE_OTHER_VAULT.toString().replace("%v", String.valueOf(number)).replace("%p", target));
|
sender.sendMessage(Lang.TITLE.toString() + Lang.DELETE_OTHER_VAULT.toString().replace("%v", String.valueOf(number)).replace("%p", target));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the player's vault file.
|
* Get the player's vault file. Create if doesn't exist.
|
||||||
* Create if doesn't exist.
|
*
|
||||||
* @param player
|
* @param player
|
||||||
* @return playerVaultFile file.
|
* @return playerVaultFile file.
|
||||||
*/
|
*/
|
||||||
@@ -137,7 +135,6 @@ public class VaultManager {
|
|||||||
try {
|
try {
|
||||||
file.createNewFile();
|
file.createNewFile();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
YamlConfiguration playerFile = YamlConfiguration.loadConfiguration(file);
|
YamlConfiguration playerFile = YamlConfiguration.loadConfiguration(file);
|
||||||
@@ -146,6 +143,7 @@ public class VaultManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Save the players vault file.
|
* Save the players vault file.
|
||||||
|
*
|
||||||
* @param name
|
* @param name
|
||||||
* @param yaml
|
* @param yaml
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
|
|||||||
Reference in New Issue
Block a user