Use onDisable to close inventories
*Untested*
This commit is contained in:
@@ -2,7 +2,6 @@ package com.drtshock.playervaults;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@@ -24,7 +23,6 @@ import org.bukkit.event.player.PlayerInteractEvent;
|
|||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
import org.bukkit.event.server.PluginDisableEvent;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
|
|
||||||
import com.drtshock.playervaults.commands.VaultViewInfo;
|
import com.drtshock.playervaults.commands.VaultViewInfo;
|
||||||
@@ -45,7 +43,7 @@ public class Listeners implements Listener {
|
|||||||
/**
|
/**
|
||||||
* Save a players vault. Sends to method in VaultManager class.
|
* Save a players vault. Sends to method in VaultManager class.
|
||||||
*
|
*
|
||||||
* @param Player p
|
* @param Player The player of whose vault to save
|
||||||
*/
|
*/
|
||||||
public void saveVault(Player p) {
|
public void saveVault(Player p) {
|
||||||
if (PlayerVaults.IN_VAULT.containsKey(p.getName())) {
|
if (PlayerVaults.IN_VAULT.containsKey(p.getName())) {
|
||||||
@@ -62,21 +60,6 @@ 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());
|
||||||
@@ -118,8 +101,6 @@ public class Listeners implements Listener {
|
|||||||
/**
|
/**
|
||||||
* Check if a player is trying to do something while in a vault. Don't let
|
* Check if a player is trying to do something while in a vault. Don't let
|
||||||
* them open up another chest.
|
* them open up another chest.
|
||||||
*
|
|
||||||
* @param PlayerInteractEvent
|
|
||||||
*/
|
*/
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onInteract(PlayerInteractEvent event) {
|
public void onInteract(PlayerInteractEvent event) {
|
||||||
|
|||||||
@@ -9,7 +9,9 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import net.milkbowl.vault.economy.Economy;
|
import net.milkbowl.vault.economy.Economy;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
@@ -25,11 +27,11 @@ import com.drtshock.playervaults.util.VaultManager;
|
|||||||
public class PlayerVaults extends JavaPlugin {
|
public class PlayerVaults extends JavaPlugin {
|
||||||
|
|
||||||
public static PlayerVaults PLUGIN;
|
public static PlayerVaults PLUGIN;
|
||||||
public Logger log;
|
public static Logger log;
|
||||||
public static boolean UPDATE = false;
|
public static boolean UPDATE = false;
|
||||||
public static String NEWVERSION = "";
|
public static String NEWVERSION = "";
|
||||||
public static String LINK = "";
|
public static String LINK = "";
|
||||||
Commands commands;
|
public static Commands commands;
|
||||||
public static HashMap<String, SignSetInfo> SET_SIGN = new HashMap<String, SignSetInfo>();
|
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, VaultViewInfo> IN_VAULT = new HashMap<String, VaultViewInfo>();
|
||||||
public static HashMap<String, Inventory> OPENINVENTORIES = new HashMap<String, Inventory>();
|
public static HashMap<String, Inventory> OPENINVENTORIES = new HashMap<String, Inventory>();
|
||||||
@@ -43,12 +45,13 @@ public class PlayerVaults extends JavaPlugin {
|
|||||||
public static File SIGNS_FILE;
|
public static File SIGNS_FILE;
|
||||||
public static String DIRECTORY = "plugins" + File.separator + "PlayerVaults" + File.separator + "vaults";
|
public static String DIRECTORY = "plugins" + File.separator + "PlayerVaults" + File.separator + "vaults";
|
||||||
public static VaultManager VM;
|
public static VaultManager VM;
|
||||||
|
public static Listeners listener;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
loadLang();
|
loadLang();
|
||||||
log = getServer().getLogger();
|
log = getServer().getLogger();
|
||||||
getServer().getPluginManager().registerEvents(new Listeners(this), this);
|
getServer().getPluginManager().registerEvents(listener = new Listeners(this), this);
|
||||||
loadConfig();
|
loadConfig();
|
||||||
loadSigns();
|
loadSigns();
|
||||||
startMetrics();
|
startMetrics();
|
||||||
@@ -81,6 +84,15 @@ public class PlayerVaults extends JavaPlugin {
|
|||||||
VM = new VaultManager(this);
|
VM = new VaultManager(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
for(Player p:Bukkit.getOnlinePlayers()) {
|
||||||
|
if (IN_VAULT.containsKey(p.getName())) {
|
||||||
|
p.closeInventory();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start metrics
|
* Start metrics
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user