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