From ca128c50358eb2899ddd8cec01720f3553e31cb2 Mon Sep 17 00:00:00 2001 From: j502647092 Date: Fri, 12 Jun 2015 21:45:45 +0800 Subject: [PATCH] add VersionCheck while admin join the game... Signed-off-by: j502647092 --- .../RealBackpacks/RealBackpacks.java | 12 +- .../listeners/PlayerListener.java | 172 ++++++++++-------- 2 files changed, 101 insertions(+), 83 deletions(-) diff --git a/src/cn/citycraft/RealBackpacks/RealBackpacks.java b/src/cn/citycraft/RealBackpacks/RealBackpacks.java index 83e0273..b755b4c 100644 --- a/src/cn/citycraft/RealBackpacks/RealBackpacks.java +++ b/src/cn/citycraft/RealBackpacks/RealBackpacks.java @@ -35,13 +35,14 @@ public class RealBackpacks extends JavaPlugin { private static boolean average = false; private static boolean add = false; + public static VersionChecker versionChecker; private boolean usingMysql = false; private boolean vault = true; private boolean usingPermissions = true; private String user = null; private String password = null; - private String url; + private String url; public List backpacks = new ArrayList(); public HashMap> backpackData = new HashMap>(); public HashMap> backpackLore = new HashMap>(); @@ -49,14 +50,13 @@ public class RealBackpacks extends JavaPlugin { public HashMap backpackItems = new HashMap(); public HashMap backpackOverrides = new HashMap(); public HashMap> backpackBlacklist = new HashMap>(); - public HashMap> backpackWhitelist = new HashMap>(); + public HashMap> backpackWhitelist = new HashMap>(); public HashMap playerData = new HashMap(); public HashMap adminFullView = new HashMap(); public List adminRestrictedView = new ArrayList(); - public List slowedPlayers = new ArrayList(); - private VersionChecker versionChecker; + public List slowedPlayers = new ArrayList(); // List key // 0 = Size @@ -358,12 +358,12 @@ public class RealBackpacks extends JavaPlugin { 11, getConfig().getString( "Backpacks." + backpack - + ".IncreasedHungerFeature.extraHungerBarsToDeplete")); + + ".IncreasedHungerFeature.extraHungerBarsToDeplete")); list.add( 12, getConfig().getString( "Backpacks." + backpack - + ".IncreasedHungerFeature.hungerBarsToSubtractWhenEating")); + + ".IncreasedHungerFeature.hungerBarsToSubtractWhenEating")); list.add(13, getConfig().getString("Backpacks." + backpack + ".Purchasable")); list.add(14, getConfig().getString("Backpacks." + backpack + ".Price")); list.add(15, getConfig().getString("Backpacks." + backpack + ".OpenWith")); diff --git a/src/cn/citycraft/RealBackpacks/listeners/PlayerListener.java b/src/cn/citycraft/RealBackpacks/listeners/PlayerListener.java index c5f7a7b..a62b64e 100644 --- a/src/cn/citycraft/RealBackpacks/listeners/PlayerListener.java +++ b/src/cn/citycraft/RealBackpacks/listeners/PlayerListener.java @@ -14,6 +14,7 @@ import org.bukkit.event.block.Action; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.inventory.Inventory; @@ -36,11 +37,82 @@ public class PlayerListener implements Listener { this.plugin = plugin; } + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onDeath(final PlayerDeathEvent e) { + final Player p = e.getEntity(); + final String name = p.getName(); + for (final String backpack : plugin.backpacks) { + if (!p.getInventory().contains(plugin.backpackItems.get(backpack))) { + continue; + } + p.setWalkSpeed(0.2F); + final List key = plugin.backpackData.get(backpack); + if (key.get(5) != null && key.get(5).equalsIgnoreCase("true")) { + // Drop contents + Inventory binv = null; + if (plugin.isUsingMysql()) { + try { + binv = MysqlFunctions.getBackpackInv(name, backpack); + } catch (final SQLException e1) { + e1.printStackTrace(); + } + } else { + FileConfig config = PlayerConfig.getInstance(plugin, name); + if (config.getStringList(backpack + ".Inventory") == null) { + continue; + } + binv = Serialization.toInventory(config.getStringList(backpack + ".Inventory"), + key.get(3), Integer.parseInt(key.get(0))); + } + if (plugin.playerData.containsKey(name)) { + if (p.getItemOnCursor() != null) { + p.setItemOnCursor(null); + } + } + if (binv != null) { + for (final ItemStack item : binv.getContents()) { + if (item != null) { + p.getWorld().dropItemNaturally(p.getLocation(), item); + } + } + } + RBUtil.destroyContents(name, backpack); + } + if (key.get(4) != null && key.get(4).equalsIgnoreCase("true")) { + // Destroy contents + RBUtil.destroyContents(name, backpack); + p.sendMessage(ChatColor.RED + "因为死亡背包物品已销毁..."); + } + if (key.get(6) != null && key.get(6).equalsIgnoreCase("false")) { + // Drop backpack + e.getDrops().remove(plugin.backpackItems.get(backpack)); + } + if (key.get(7) != null && key.get(7).equalsIgnoreCase("true")) { + deadPlayers.put(name, backpack); + } + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onDrop(final PlayerDropItemEvent e) { + final Player p = e.getPlayer(); + final String name = p.getName(); + final ItemStack item = e.getItemDrop().getItemStack(); + if (plugin.slowedPlayers.contains(name)) { + for (final String backpack : plugin.backpacks) { + if (plugin.backpackItems.get(backpack).equals(item)) { + plugin.slowedPlayers.remove(name); + p.setWalkSpeed(0.2F); + break; + } + } + } + } + @EventHandler(priority = EventPriority.HIGH) public void onInteract(final PlayerInteractEvent e) { - if (e.getAction().equals(Action.PHYSICAL)) { + if (e.getAction().equals(Action.PHYSICAL)) return; - } final Action act = e.getAction(); final Player p = e.getPlayer(); @@ -49,7 +121,9 @@ public class PlayerListener implements Listener { if (item.hasItemMeta()) { for (final String backpack : plugin.backpacks) { final List key = plugin.backpackData.get(backpack); - if (item.getItemMeta().hasDisplayName() && item.getItemMeta().getDisplayName().equals(ChatColor.translateAlternateColorCodes('&', key.get(3)))) { + if (item.getItemMeta().hasDisplayName() + && item.getItemMeta().getDisplayName() + .equals(ChatColor.translateAlternateColorCodes('&', key.get(3)))) { if (plugin.isUsingPerms() && !p.hasPermission("rb." + backpack + ".use")) { p.sendMessage(ChatColor.RED + "你没有打开此背包的权限..."); continue; @@ -91,14 +165,20 @@ public class PlayerListener implements Listener { e1.printStackTrace(); } if (inv == null) { - inv = plugin.getServer().createInventory(p, Integer.parseInt(key.get(0)), ChatColor.translateAlternateColorCodes('&', key.get(3))); + inv = plugin.getServer().createInventory(p, + Integer.parseInt(key.get(0)), + ChatColor.translateAlternateColorCodes('&', key.get(3))); } } else { FileConfig config = PlayerConfig.getInstance(plugin, name); if (!config.isSet(backpack + ".Inventory")) { - inv = plugin.getServer().createInventory(p, Integer.parseInt(key.get(0)), ChatColor.translateAlternateColorCodes('&', key.get(3))); + inv = plugin.getServer().createInventory(p, + Integer.parseInt(key.get(0)), + ChatColor.translateAlternateColorCodes('&', key.get(3))); } else { - inv = Serialization.toInventory(config.getStringList(backpack + ".Inventory"), key.get(3), Integer.parseInt(key.get(0))); + inv = Serialization.toInventory( + config.getStringList(backpack + ".Inventory"), key.get(3), + Integer.parseInt(key.get(0))); } } if (p.getOpenInventory().getTopInventory() != null) { @@ -112,19 +192,11 @@ public class PlayerListener implements Listener { } } - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onDrop(final PlayerDropItemEvent e) { - final Player p = e.getPlayer(); - final String name = p.getName(); - final ItemStack item = e.getItemDrop().getItemStack(); - if (plugin.slowedPlayers.contains(name)) { - for (final String backpack : plugin.backpacks) { - if (plugin.backpackItems.get(backpack).equals(item)) { - plugin.slowedPlayers.remove(name); - p.setWalkSpeed(0.2F); - break; - } - } + @EventHandler(priority = EventPriority.HIGH) + public void onJoin(PlayerJoinEvent e) { + Player player = e.getPlayer(); + if (player.hasPermission("rb.reload")) { + RealBackpacks.versionChecker.VersionCheck(player); } } @@ -146,7 +218,7 @@ public class PlayerListener implements Listener { final Inventory inv = p.getInventory(); final Location loc = e.getItem().getLocation(); final ItemStack backpackItem = plugin.backpackItems.get(backpack); - int emptySlots = 0, itemAmount = item.getAmount(); + int emptySlots = 0,itemAmount = item.getAmount(); for (final ItemStack invItem : inv.getContents()) { if (invItem == null) { emptySlots++; @@ -180,69 +252,15 @@ public class PlayerListener implements Listener { } } - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onDeath(final PlayerDeathEvent e) { - final Player p = e.getEntity(); - final String name = p.getName(); - for (final String backpack : plugin.backpacks) { - if (!p.getInventory().contains(plugin.backpackItems.get(backpack))) { - continue; - } - p.setWalkSpeed(0.2F); - final List key = plugin.backpackData.get(backpack); - if (key.get(5) != null && key.get(5).equalsIgnoreCase("true")) { - //Drop contents - Inventory binv = null; - if (plugin.isUsingMysql()) { - try { - binv = MysqlFunctions.getBackpackInv(name, backpack); - } catch (final SQLException e1) { - e1.printStackTrace(); - } - } else { - FileConfig config = PlayerConfig.getInstance(plugin, name); - if (config.getStringList(backpack + ".Inventory") == null) { - continue; - } - binv = Serialization.toInventory(config.getStringList(backpack + ".Inventory"), key.get(3), Integer.parseInt(key.get(0))); - } - if (plugin.playerData.containsKey(name)) { - if (p.getItemOnCursor() != null) { - p.setItemOnCursor(null); - } - } - if (binv != null) { - for (final ItemStack item : binv.getContents()) { - if (item != null) { - p.getWorld().dropItemNaturally(p.getLocation(), item); - } - } - } - RBUtil.destroyContents(name, backpack); - } - if (key.get(4) != null && key.get(4).equalsIgnoreCase("true")) { - //Destroy contents - RBUtil.destroyContents(name, backpack); - p.sendMessage(ChatColor.RED + "因为死亡背包物品已销毁..."); - } - if (key.get(6) != null && key.get(6).equalsIgnoreCase("false")) { - //Drop backpack - e.getDrops().remove(plugin.backpackItems.get(backpack)); - } - if (key.get(7) != null && key.get(7).equalsIgnoreCase("true")) { - deadPlayers.put(name, backpack); - } - } - } - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onRespawn(final PlayerRespawnEvent e) { final Player p = e.getPlayer(); final String name = p.getName(); for (final String backpack : plugin.backpacks) { final List key = plugin.backpackData.get(backpack); - if (key.get(7) != null && key.get(7).equalsIgnoreCase("true") && deadPlayers.get(name) != null && deadPlayers.get(name).equals(backpack)) { - //Keep backpack + if (key.get(7) != null && key.get(7).equalsIgnoreCase("true") + && deadPlayers.get(name) != null && deadPlayers.get(name).equals(backpack)) { + // Keep backpack p.getInventory().addItem(plugin.backpackItems.get(backpack)); p.updateInventory(); deadPlayers.remove(name);