Condense and fix a few things
This commit is contained in:
@@ -16,12 +16,10 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
public class Listeners implements Listener {
|
||||
@@ -32,19 +30,24 @@ public class Listeners implements Listener {
|
||||
}
|
||||
VaultManager vm = new VaultManager(plugin);
|
||||
|
||||
@EventHandler
|
||||
public void onQuit(PlayerQuitEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if(Commands.inVault.containsKey(player.getName())) {
|
||||
Inventory inv = player.getOpenInventory().getTopInventory();
|
||||
int number = Commands.inVault.get(player.getName());
|
||||
public void doSaveStuff(Player p) {
|
||||
if(Commands.inVault.containsKey(p.getName())) {
|
||||
Inventory inv = p.getOpenInventory().getTopInventory();
|
||||
int number = Commands.inVault.get(p.getName());
|
||||
try {
|
||||
vm.saveVault(inv, player, number);
|
||||
vm.saveVault(inv, p, number);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onQuit(PlayerQuitEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
doSaveStuff(player);
|
||||
}
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
@@ -58,43 +61,7 @@ public class Listeners implements Listener {
|
||||
@EventHandler
|
||||
public void onDeath(PlayerDeathEvent event) {
|
||||
Player player = event.getEntity();
|
||||
if(Commands.inVault.containsKey(player.getName())) {
|
||||
Inventory inv = player.getOpenInventory().getTopInventory();
|
||||
int number = Commands.inVault.get(player.getName());
|
||||
try {
|
||||
vm.saveVault(inv, player, number);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onTP(PlayerTeleportEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if(Commands.inVault.containsKey(player.getName())) {
|
||||
Inventory inv = player.getOpenInventory().getTopInventory();
|
||||
int number = Commands.inVault.get(player.getName());
|
||||
try {
|
||||
vm.saveVault(inv, player, number);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onWorldChange(PlayerChangedWorldEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if(Commands.inVault.containsKey(player.getName())) {
|
||||
Inventory inv = player.getOpenInventory().getTopInventory();
|
||||
int number = Commands.inVault.get(player.getName());
|
||||
try {
|
||||
vm.saveVault(inv, player, number);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
doSaveStuff(player);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@@ -102,18 +69,8 @@ public class Listeners implements Listener {
|
||||
System.out.println(Commands.inVault.size());
|
||||
HumanEntity he = event.getPlayer();
|
||||
if(he instanceof Player) {
|
||||
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());
|
||||
try {
|
||||
vm.saveVault(inv, player, number);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
doSaveStuff(player);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,13 +8,11 @@ import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import me.shock.playervaults.Listeners;
|
||||
import me.shock.playervaults.commands.Commands;
|
||||
import me.shock.playervaults.util.Metrics;
|
||||
import me.shock.playervaults.util.Updater;
|
||||
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.craftbukkit.libs.jline.internal.Log;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
@@ -27,6 +25,7 @@ public class Main extends JavaPlugin {
|
||||
public static String name = "";
|
||||
Commands commands = new Commands();
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
log = getServer().getLogger();
|
||||
PluginManager pm = getServer().getPluginManager();
|
||||
@@ -43,6 +42,7 @@ public class Main extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
//saveData();
|
||||
}
|
||||
@@ -79,7 +79,7 @@ public class Main extends JavaPlugin {
|
||||
getDataFolder().mkdir();
|
||||
lang.createNewFile();
|
||||
} catch (IOException e) {
|
||||
Log.error("[PlayerVaults] Couldn't create language file.");
|
||||
log.warning("[PlayerVaults] Couldn't create language file.");
|
||||
}
|
||||
/**
|
||||
* Write the config file here.
|
||||
@@ -96,7 +96,7 @@ public class Main extends JavaPlugin {
|
||||
}
|
||||
fos.close();
|
||||
} catch (IOException e) {
|
||||
Log.error("[PlayerVaults] Couldn't write Language file: " + e);
|
||||
log.warning("[PlayerVaults] Couldn't write Language file: " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user