From 218551873749bc5414fb4053ed3ba03d8acd76fe Mon Sep 17 00:00:00 2001 From: john180 Date: Tue, 2 Feb 2016 18:47:43 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E7=A6=81=E6=AD=A2=E5=B0=86=E7=BB=91?= =?UTF-8?q?=E5=AE=9A=E7=89=A9=E5=93=81=E6=94=BE=E7=BD=AE=E5=9C=A8=E7=9B=94?= =?UTF-8?q?=E7=94=B2=E6=9E=B6=E4=B8=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/me/tft_02/soulbound/Soulbound.java | 6 + .../listeners/ArmorStandListener.java | 23 ++ .../soulbound/listeners/PlayerListener.java | 374 +++++++++--------- 3 files changed, 219 insertions(+), 184 deletions(-) create mode 100644 src/main/java/com/me/tft_02/soulbound/listeners/ArmorStandListener.java diff --git a/src/main/java/com/me/tft_02/soulbound/Soulbound.java b/src/main/java/com/me/tft_02/soulbound/Soulbound.java index 7251ff0..25b6e81 100644 --- a/src/main/java/com/me/tft_02/soulbound/Soulbound.java +++ b/src/main/java/com/me/tft_02/soulbound/Soulbound.java @@ -2,6 +2,7 @@ package com.me.tft_02.soulbound; import java.io.File; +import org.bukkit.Bukkit; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; @@ -14,6 +15,7 @@ import com.me.tft_02.soulbound.commands.SoulboundCommand; import com.me.tft_02.soulbound.commands.UnbindCommand; import com.me.tft_02.soulbound.config.Config; import com.me.tft_02.soulbound.config.ItemsConfig; +import com.me.tft_02.soulbound.listeners.ArmorStandListener; import com.me.tft_02.soulbound.listeners.BlockListener; import com.me.tft_02.soulbound.listeners.EntityListener; import com.me.tft_02.soulbound.listeners.InventoryListener; @@ -115,10 +117,14 @@ public class Soulbound extends JavaPlugin { private void registerEvents() { final PluginManager pm = getServer().getPluginManager(); + final String version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3]; pm.registerEvents(new PlayerListener(), this); pm.registerEvents(new InventoryListener(), this); pm.registerEvents(new EntityListener(), this); pm.registerEvents(new BlockListener(), this); + if (version.equals("v1_8_R1") || version.equals("v1_8_R2") || version.equals("v1_8_R3")) { + pm.registerEvents(new ArmorStandListener(), this); + } } private void setupFilePaths() { diff --git a/src/main/java/com/me/tft_02/soulbound/listeners/ArmorStandListener.java b/src/main/java/com/me/tft_02/soulbound/listeners/ArmorStandListener.java new file mode 100644 index 0000000..f3b85c6 --- /dev/null +++ b/src/main/java/com/me/tft_02/soulbound/listeners/ArmorStandListener.java @@ -0,0 +1,23 @@ +package com.me.tft_02.soulbound.listeners; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerArmorStandManipulateEvent; +import org.bukkit.inventory.ItemStack; + +import com.me.tft_02.soulbound.util.ItemUtils; + +public class ArmorStandListener implements Listener { + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onPlayerArmorStandManipulate(PlayerArmorStandManipulateEvent event) { + final Player player = event.getPlayer(); + final ItemStack itemStack = event.getPlayerItem(); + if (itemStack != null && ItemUtils.isSoulbound(itemStack)) { + player.sendMessage(ChatColor.RED + "绑定物品不允许被放置在盔甲架上."); + event.setCancelled(true); + } + } +} 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 d04ea83..0028f2f 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,199 +37,205 @@ import com.me.tft_02.soulbound.util.PlayerData; public class PlayerListener implements Listener { - @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.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(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)) { - event.setCancelled(true); - } - return; - } - if (ItemUtils.isBindOnPickup(itemStack) || ItemsConfig.isActionItem(itemStack, ActionType.PICKUP_ITEM)) { - ItemUtils.soulbindItem(player, itemStack); - } - if(player.getItemOnCursor()!=null && ItemUtils.isSoulbound(player.getItemOnCursor())){ - item.setPickupDelay(40); - event.setCancelled(true); - } - } + @EventHandler(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)) { + event.setCancelled(true); + } + return; + } + if (ItemUtils.isBindOnPickup(itemStack) || ItemsConfig.isActionItem(itemStack, ActionType.PICKUP_ITEM)) { + ItemUtils.soulbindItem(player, itemStack); + } + if (player.getItemOnCursor() != null && ItemUtils.isSoulbound(player.getItemOnCursor())) { + item.setPickupDelay(40); + event.setCancelled(true); + } + } - /** - * Watch PlayerCommandPreprocessEvent events. - * - * @param event The event to watch - */ - @EventHandler(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(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); + } + } - @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); - } + @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) - public void onPlayerFish(final PlayerFishEvent event) { - final ItemStack itemInHand = event.getPlayer().getItemInHand(); - DurabilityUtils.handleInfiniteDurability(itemInHand); - } + /** + * 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); + } - /** - * 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; + } + } - @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) + public 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) + 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); + } - /** - * 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); - } + /** + * 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); + } - /** - * 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); + } } From 059ffb05ecb0f4514b28f7e473263bb35f1b3abf Mon Sep 17 00:00:00 2001 From: john180 Date: Tue, 2 Feb 2016 20:46:48 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E7=BC=96=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/me/tft_02/soulbound/listeners/ArmorStandListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/me/tft_02/soulbound/listeners/ArmorStandListener.java b/src/main/java/com/me/tft_02/soulbound/listeners/ArmorStandListener.java index f3b85c6..1726061 100644 --- a/src/main/java/com/me/tft_02/soulbound/listeners/ArmorStandListener.java +++ b/src/main/java/com/me/tft_02/soulbound/listeners/ArmorStandListener.java @@ -16,7 +16,7 @@ public class ArmorStandListener implements Listener { final Player player = event.getPlayer(); final ItemStack itemStack = event.getPlayerItem(); if (itemStack != null && ItemUtils.isSoulbound(itemStack)) { - player.sendMessage(ChatColor.RED + "绑定物品不允许被放置在盔甲架上."); + player.sendMessage(ChatColor.RED + "缁戝畾鐗╁搧涓嶅厑璁歌鏀剧疆鍦ㄧ洈鐢叉灦涓."); event.setCancelled(true); } }