Hello, I am working on a plugin that teleports the player to the point where the arrow lands. I'm planning to make this work by enchanting arrows or crafting certain arrows. I know how to do all of this, however I have got one problem: How can I establish a kind of connection between the arrow item and the fired projectile, because I want to check whether the fired arrow item has a certain enchantment/metadata while using the ProjectileHitEvent Edit: If anyone has a better idea than using the ProjectileHitEvent I'm open for anything, but I thought that would be the best. Regards, Felix
I've not done much Bukkit in a while, but there's a EntityFireBowEvent (https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/event/entity/EntityShootBowEvent.html), which you could check to see if they have the enchantment on the bow (I'm not too sure how you'd check what arrow was used; it isn't parsed in the event). From there you're given the projectile. You can set some custom Metadata (containing the Player UUID or something), and using the ProjectileHitEvent you could check for custom metadata, and teleport the player whose UUID is there to the spot where it landed. I'll have a think about checking the arrow and see if I come up with anything
Edit: That way works fine but it's just not what I'm looking for. What I wish it to be like is that there's a certain enchantment on the Arrow item. Thank you anyway
I have a code snippet I've used I can supply. Gimme a minute to grab it Whelp now TimTower will merge my posts and I'll get a warning... wish I could delete this post Looks like this was fixed Code: @EventHandler(ignoreCancelled = true) public void onBowShoot(EntityShootBowEvent event){ if(event.getProjectile() instanceof Arrow){ Arrow arrow = (Arrow) event.getProjectile(); if(event.getEntity() instanceof Player) { ItemStack arrowItem = getArrowBeingShot((Player) event.getEntity()); } } } private ItemStack getArrowBeingShot(Player player){ for(ItemStack item : player.getInventory().getContents()) if(item != null && item.getType() == Material.ARROW) return item; return null; } You can use this snippet to get the arrow ItemStack on shot, and can do whatever checks you need on it This fires before the arrow is removed, so you don't need to handle removal logic, or if the arrow is gone. It will all work as desired!
@Kenaex From what I understand you whant to make some kind of enchant on a bow that makes you teleport to the arrow it shoots. In the case you must make a EntityShotBowEvent, get the ItemStack bow that the player just shot from, check to see if it has your enchant, if it does add the shot projectile to a list. Then you must make a projectileHitEvent, if your list contains the arrow entity then you know it was a projectile that was shot using a bow with your enchant.
@Lorinthio I will try using that, thanks @MattTheBeast No, that's not it. I want to have an enchanted ARROW item, not a bow, but thanks anyway Edit: @Lorinthio 's idea worked just fine! Thank you very much