diff --git a/pom.xml b/pom.xml index 4b93293..8d211b9 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.me.tft_02.soulbound Soulbound - 1.2 + 1.3 Soulbound Soulbound items for your RPG servers! https://github.com/TfT-02/Soulbound @@ -60,21 +60,18 @@ http://ci.citycraft.cn:8080 - &c修复自动获取版本错误... + Debug + &c修复Prevent_Item_Drop设置为TRUE时死亡物品消失的问题... UTF-8 - mengcraft-repo - http://ci.mengcraft.com:8080/plugin/repository/everything/ + spigot-repo + https://hub.spigotmc.org/nexus/content/groups/public/ citycraft-repo - http://ci.citycraft.cn:8800/jenkins/plugin/repository/everything/ - - - spigot-repo - https://hub.spigotmc.org/nexus/content/groups/public/ + ${jenkins.url}/plugin/repository/everything/ @@ -82,7 +79,7 @@ org.spigotmc spigot-api jar - 1.8.3-R0.1-SNAPSHOT + 1.8.8-R0.1-SNAPSHOT cn.citycraft diff --git a/src/main/java/com/me/tft_02/soulbound/listeners/PlayerListener.java b/src/main/java/com/me/tft_02/soulbound/listeners/PlayerListener.java index c6534d3..07316cc 100644 --- a/src/main/java/com/me/tft_02/soulbound/listeners/PlayerListener.java +++ b/src/main/java/com/me/tft_02/soulbound/listeners/PlayerListener.java @@ -37,213 +37,200 @@ import com.me.tft_02.soulbound.util.PlayerData; public class PlayerListener implements Listener { - /** - * Watch PlayerCommandPreprocessEvent events. - * - * @param event - * The event to watch - */ - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onPlayerCommand(final PlayerCommandPreprocessEvent event) { - final Player player = event.getPlayer(); - final ItemStack itemStack = player.getItemInHand(); - final String command = event.getMessage(); + /** + * Watch PlayerCommandPreprocessEvent events. + * + * @param event The event to watch + */ + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onPlayerCommand(final PlayerCommandPreprocessEvent event) { + final Player player = event.getPlayer(); + final ItemStack itemStack = player.getItemInHand(); + final String command = event.getMessage(); - if (ItemUtils.isSoulbound(itemStack) && Config.getBlockedCommands().contains(command)) { - player.sendMessage(ChatColor.RED + "不允许使用命令 " + ChatColor.GOLD + command + ChatColor.RED + " 当拿着绑定物品的时候."); - event.setCancelled(true); - } - } + if (ItemUtils.isSoulbound(itemStack) && Config.getBlockedCommands().contains(command)) { + player.sendMessage(ChatColor.RED + "不允许使用命令 " + ChatColor.GOLD + command + ChatColor.RED + " 当拿着绑定物品的时候."); + event.setCancelled(true); + } + } - /** - * Monitor PlayerCommandPreprocessEvent events. - * - * @param event - * The event to monitor - */ - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onPlayerCommandMonitor(final PlayerCommandPreprocessEvent event) { - final Player player = event.getPlayer(); - final ItemStack inHand = player.getItemInHand(); - final String command = event.getMessage(); - final String[] args = CommandUtils.extractArgs(command); - if (!ItemUtils.isSoulbound(inHand) && Config.getBindCommands().contains(command)) { - ItemUtils.soulbindItem(player, inHand); - return; - } - if (command.contains("kit")) { - Player target; - if (args.length >= 2) { - target = Soulbound.p.getServer().getPlayer(args[1]); - } else { - target = player; - } - if (target == null) { - return; - } - new SoulbindInventoryTask(target, ActionType.KIT).runTask(Soulbound.p); - } - } + /** + * Monitor PlayerCommandPreprocessEvent events. + * + * @param event The event to monitor + */ + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onPlayerCommandMonitor(final PlayerCommandPreprocessEvent event) { + final Player player = event.getPlayer(); + final ItemStack inHand = player.getItemInHand(); + final String command = event.getMessage(); + final String[] args = CommandUtils.extractArgs(command); + if (!ItemUtils.isSoulbound(inHand) && Config.getBindCommands().contains(command)) { + ItemUtils.soulbindItem(player, inHand); + return; + } + if (command.contains("kit")) { + Player target; + if (args.length >= 2) { + target = Soulbound.p.getServer().getPlayer(args[1]); + } else { + target = player; + } + if (target == null) { + return; + } + new SoulbindInventoryTask(target, ActionType.KIT).runTask(Soulbound.p); + } + } - /** - * Watch PlayerInteract events. - * - * @param event - * The event to watch - */ - @EventHandler(priority = EventPriority.LOW) - public void onPlayerInteract(final PlayerInteractEvent event) { - final Player player = event.getPlayer(); - final Action action = event.getAction(); - final ItemStack inHand = player.getItemInHand(); - switch (action) { - case RIGHT_CLICK_BLOCK: - case RIGHT_CLICK_AIR: - case LEFT_CLICK_AIR: - case LEFT_CLICK_BLOCK: - if (ItemUtils.isEquipable(inHand)) { - new UpdateArmorTask(player).runTaskLater(Soulbound.p, 2); - } else if (ItemUtils.isBindOnUse(inHand)) { - ItemUtils.soulbindItem(player, inHand); - } - default: - break; - } - } + /** + * Watch PlayerInteract events. + * + * @param event The event to watch + */ + @EventHandler(priority = EventPriority.LOW) + public void onPlayerInteract(final PlayerInteractEvent event) { + final Player player = event.getPlayer(); + final Action action = event.getAction(); + final ItemStack inHand = player.getItemInHand(); + switch (action) { + case RIGHT_CLICK_BLOCK: + case RIGHT_CLICK_AIR: + case LEFT_CLICK_AIR: + case LEFT_CLICK_BLOCK: + if (ItemUtils.isEquipable(inHand)) { + new UpdateArmorTask(player).runTaskLater(Soulbound.p, 2); + } else if (ItemUtils.isBindOnUse(inHand)) { + ItemUtils.soulbindItem(player, inHand); + } + default: + break; + } + } - /** - * Monitor ServerCommandEvent events. - * - * @param event - * The event to monitor - */ - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onServerCommand(final ServerCommandEvent event) { - final String command = event.getCommand(); - final String[] args = CommandUtils.extractArgs(command); - if (!command.contains("kit")) { - return; - } - if (args.length < 2) { - return; - } - final Player target = Soulbound.p.getServer().getPlayer(args[1]); - new SoulbindInventoryTask(target, ActionType.KIT).runTask(Soulbound.p); - } + /** + * Monitor ServerCommandEvent events. + * + * @param event The event to monitor + */ + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onServerCommand(final ServerCommandEvent event) { + final String command = event.getCommand(); + final String[] args = CommandUtils.extractArgs(command); + if (!command.contains("kit")) { + return; + } + if (args.length < 2) { + return; + } + final Player target = Soulbound.p.getServer().getPlayer(args[1]); + new SoulbindInventoryTask(target, ActionType.KIT).runTask(Soulbound.p); + } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - private void onItemDrop(final PlayerDropItemEvent event) { - final Player player = event.getPlayer(); - final Item item = event.getItemDrop(); - final ItemStack itemStack = item.getItemStack(); - if (Config.getPreventItemDrop()) { - if (ItemUtils.isSoulbound(itemStack) && ItemUtils.isBindedPlayer(player, itemStack)) { - item.setPickupDelay(2 * 20); - event.setCancelled(true); - new UpdateInventoryTask(player).runTask(Soulbound.p); - } - return; - } - if (Config.getDeleteOnDrop()) { - player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1.0F, 1.0F); - event.getItemDrop().remove(); - return; - } - if (ItemsConfig.isActionItem(itemStack, ActionType.DROP_ITEM)) { - ItemUtils.soulbindItem(player, itemStack); - return; - } - } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onItemDrop(final PlayerDropItemEvent event) { + final Player player = event.getPlayer(); + if (!player.isValid()) { + return; + } + final Item item = event.getItemDrop(); + final ItemStack itemStack = item.getItemStack(); + if (Config.getPreventItemDrop()) { + if (ItemUtils.isSoulbound(itemStack) && ItemUtils.isBindedPlayer(player, itemStack)) { + item.setPickupDelay(2 * 20); + event.setCancelled(true); + new UpdateInventoryTask(player).runTask(Soulbound.p); + } + return; + } + if (Config.getDeleteOnDrop()) { + player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1.0F, 1.0F); + event.getItemDrop().remove(); + return; + } + if (ItemsConfig.isActionItem(itemStack, ActionType.DROP_ITEM)) { + ItemUtils.soulbindItem(player, itemStack); + } + } - @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) - private void onItemPickup(final PlayerPickupItemEvent event) { - final Player player = event.getPlayer(); - final Item item = event.getItem(); - final ItemStack itemStack = item.getItemStack(); - if (ItemUtils.isSoulbound(itemStack) && !ItemUtils.isBindedPlayer(player, itemStack)) { - if (Permissions.pickupBypass(player)) { - return; - } - event.setCancelled(true); - return; - } - if (ItemUtils.isBindOnPickup(itemStack)) { - ItemUtils.soulbindItem(player, itemStack); - return; - } - if (ItemsConfig.isActionItem(itemStack, ActionType.PICKUP_ITEM)) { - ItemUtils.soulbindItem(player, itemStack); - return; - } - } + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onItemPickup(final PlayerPickupItemEvent event) { + final Player player = event.getPlayer(); + final Item item = event.getItem(); + final ItemStack itemStack = item.getItemStack(); + if (ItemUtils.isSoulbound(itemStack) && !ItemUtils.isBindedPlayer(player, itemStack)) { + if (Permissions.pickupBypass(player)) { + return; + } + event.setCancelled(true); + return; + } + if (ItemUtils.isBindOnPickup(itemStack)) { + ItemUtils.soulbindItem(player, itemStack); + return; + } + if (ItemsConfig.isActionItem(itemStack, ActionType.PICKUP_ITEM)) { + ItemUtils.soulbindItem(player, itemStack); + } + } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - private void onPlayerDeath(final PlayerDeathEvent event) { - final Player player = event.getEntity(); - final boolean deleteOnDeath = Permissions.deleteOnDeath(player); - final boolean keepOnDeath = Permissions.keepOnDeath(player); - final List items = new ArrayList(); - if (!keepOnDeath && !deleteOnDeath) { - return; - } - for (final ItemStack item : new ArrayList(event.getDrops())) { - if (ItemUtils.isSoulbound(item) && ItemUtils.isBindedPlayer(player, item)) { - if (keepOnDeath) { - items.add(item); - event.getDrops().remove(item); - } else if (deleteOnDeath) { - event.getDrops().remove(item); - } - } - } - PlayerData.storeItemsDeath(player, items); - } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onPlayerDeath(final PlayerDeathEvent event) { + final Player player = event.getEntity(); + final boolean deleteOnDeath = Permissions.deleteOnDeath(player); + final boolean keepOnDeath = Permissions.keepOnDeath(player); + final List items = new ArrayList<>(); + if (!keepOnDeath && !deleteOnDeath) { + return; + } + for (final ItemStack item : new ArrayList<>(event.getDrops())) { + if (ItemUtils.isSoulbound(item) && ItemUtils.isBindedPlayer(player, item)) { + if (keepOnDeath) { + items.add(item); + } + event.getDrops().remove(item); + } + } + PlayerData.storeItemsDeath(player, items); + } - /** - * Monitor PlayerFishEvent events. - * - * @param event - * The event to monitor - */ - @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) - private void onPlayerFish(final PlayerFishEvent event) { - final ItemStack itemInHand = event.getPlayer().getItemInHand(); + /** + * Monitor PlayerFishEvent events. + * + * @param event The event to monitor + */ + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onPlayerFish(final PlayerFishEvent event) { + final ItemStack itemInHand = event.getPlayer().getItemInHand(); + DurabilityUtils.handleInfiniteDurability(itemInHand); + } - DurabilityUtils.handleInfiniteDurability(itemInHand); - } + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onPlayerRespawn(final PlayerRespawnEvent event) { + new SoulbindInventoryTask(event.getPlayer(), ActionType.RESPAWN).runTask(Soulbound.p); + } - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - private void onPlayerRespawn(final PlayerRespawnEvent event) { - new SoulbindInventoryTask(event.getPlayer(), ActionType.RESPAWN).runTask(Soulbound.p); - } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onPlayerRespawnHighest(final PlayerRespawnEvent event) { + final Player player = event.getPlayer(); + if (!Permissions.keepOnDeath(player)) { + return; + } + final ItemStack[] items = PlayerData.retrieveItemsDeath(player).toArray(new ItemStack[0]); + if (items != null) { + player.getInventory().addItem(items); + } + new UpdateInventoryTask(player).runTask(Soulbound.p); + } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - private void onPlayerRespawnHighest(final PlayerRespawnEvent event) { - final Player player = event.getPlayer(); - final boolean keepOnDeath = Permissions.keepOnDeath(player); - if (!keepOnDeath) { - return; - } - List items = new ArrayList(); - items = PlayerData.retrieveItemsDeath(player); - if (items != null) { - for (final ItemStack item : items) { - player.getInventory().addItem(item); - } - } - new UpdateInventoryTask(player).runTask(Soulbound.p); - } - - /** - * Monitor PlayerShearEntityEvent events. - * - * @param event - * The event to monitor - */ - @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) - private void onPlayerShearEntity(final PlayerShearEntityEvent event) { - final ItemStack itemInHand = event.getPlayer().getItemInHand(); - - DurabilityUtils.handleInfiniteDurability(itemInHand); - } + /** + * Monitor PlayerShearEntityEvent events. + * + * @param event The event to monitor + */ + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onPlayerShearEntity(final PlayerShearEntityEvent event) { + final ItemStack itemInHand = event.getPlayer().getItemInHand(); + DurabilityUtils.handleInfiniteDurability(itemInHand); + } } diff --git a/src/main/java/com/me/tft_02/soulbound/util/PlayerData.java b/src/main/java/com/me/tft_02/soulbound/util/PlayerData.java index 853bbd6..c5c9cec 100644 --- a/src/main/java/com/me/tft_02/soulbound/util/PlayerData.java +++ b/src/main/java/com/me/tft_02/soulbound/util/PlayerData.java @@ -18,20 +18,10 @@ public class PlayerData { } public static List retrieveItemsDeath(final Player player) { - final String playerName = player.getName(); - - if (playerSoulboundItems.containsKey(playerName)) { - return playerSoulboundItems.get(playerName); - } else { - return null; - } + return playerSoulboundItems.get(player.getName()); } public static void storeItemsDeath(final Player player, final List items) { - final String playerName = player.getName(); - if (playerSoulboundItems.containsKey(playerName)) { - playerSoulboundItems.put(playerName, null); - } - playerSoulboundItems.put(playerName, items); + playerSoulboundItems.put(player.getName(), items); } }