Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @EventHandler
- private void onLaunch(final EntityShootBowEvent e) {
- // Make this your main class.
- final JavaPlugin plugin = this;
- if (e.getEntity() instanceof Player) {
- final Player p = (Player) e.getEntity();
- final List<ItemStack> arsenal = new ArrayList<ItemStack>();
- for (ItemStack item : p.getInventory().getContents()) {
- if (item != null && item.getType() == Material.ARROW) {
- // Store all the arrows in the inventory.
- arsenal.add(item.clone());
- }
- }
- new BukkitRunnable() {
- public void run() {
- for (ItemStack item : arsenal) {
- if (!p.getInventory().contains(item)) {
- // This is the arrow ItemStack that was shot as it
- // is no longer there exactly.
- String name = item.getItemMeta().hasDisplayName() ? item.getItemMeta().getDisplayName() : "";
- System.out.println("A(n) " + name + (name.isEmpty() ? "" : " ") + "arrow has been fired.");
- e.getProjectile().setMetadata("ArrowTracker", new FixedMetadataValue(plugin, name));
- return;
- }
- }
- }
- }.runTaskLater(plugin, 0L);
- }
- }
- @EventHandler
- private void onHit(EntityDamageByEntityEvent e) {
- List<MetadataValue> meta = e.getDamager().getMetadata("ArrowTracker");
- String nameMeta = "";
- for (MetadataValue value : meta) {
- // Where 'this' is your main class.
- if (value.getOwningPlugin().equals(this)) {
- nameMeta = value.asString();
- break;
- }
- }
- if (!nameMeta.isEmpty())
- System.out.println("An entity was damaged by a(n) " + nameMeta + " arrow");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement