Getting an arrow's location

Discussion in 'Plugin Development' started by MinecraftMart, Jul 28, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    MinecraftMart

    So when an arrow hits a block or target i need to get its location. I dont know wich event to use. Can someone give me a tip?
     
  2. Offline

    GameplayJDK

    MinecraftMart Try "ProjectileHitEvent" and
    Code:java
    1. if (event.getProjectile() instanceof Arrow) {
    2. Arrow a = (Arrow) event.getProjectile();
    3. Location l = a.getLocation();
    4. //Do things with l
    5. }
     
  3. Offline

    MinecraftMart

    Thank you!

    So at the moment i got this

    Code:java
    1. @EventHandler
    2. public void splashEfect(ProjectileHitEvent e){
    3. if(e.getEntity() instanceof Arrow) {
    4. Bukkit.getLogger().info("bla");
    5. Arrow arrow = (Arrow)e.getEntity();
    6. Entity shooter = (Entity) arrow.getShooter();
    7.  
    8. if(shooter instanceof Player) {
    9. Bukkit.getLogger().info("bla");
    10. Player player = (Player)shooter;
    11. Location arrowlocation = arrow.getLocation();
    12. if(!(player.getItemInHand() == null)){
    13. Bukkit.getLogger().info("bla");
    14. if(player.getInventory().getItemInHand().hasItemMeta()){
    15. Bukkit.getLogger().info("bla");
    16. if(player.getItemInHand().getItemMeta().getDisplayName().contains("Strength")){
    17. Bukkit.getLogger().info("bla");
    18. Potion potion = new Potion(PotionType.STRENGTH, 1);
    19. potion.setSplash(true);
    20. ItemStack itemStack = new ItemStack(Material.POTION);
    21. potion.apply(itemStack);
    22. //line 259 ThrownPotion thrownPotion = ((ProjectileSource) arrowlocation).launchProjectile(ThrownPotion.class);
    23. thrownPotion.setItem(itemStack);
    24. }
    25. }
    26. }
    27.  
    28. }
    29. }
    30. }


    Error:
    Code:
    [21:47:54 ERROR]: Could not pass event ProjectileHitEvent to WitherBow v1.2
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:294) ~[spigot-1.7.9-R0.2.jar:git-Spigot-1486]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62) ~[spigot-1.7.9-R0.2.jar:git-Spigot-1486]
            at org.bukkit.plugin.TimedRegisteredListener.callEvent(TimedRegisteredLi
    stener.java:30) ~[spigot-1.7.9-R0.2.jar:git-Spigot-1486]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:502) [spigot-1.7.9-R0.2.jar:git-Spigot-1486]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:487) [spigot-1.7.9-R0.2.jar:git-Spigot-1486]
            at org.bukkit.craftbukkit.v1_7_R3.event.CraftEventFactory.callProjectile
    HitEvent(CraftEventFactory.java:646) [spigot-1.7.9-R0.2.jar:git-Spigot-1486]
            at net.minecraft.server.v1_7_R3.EntityArrow.h(EntityArrow.java:224) [spi
    got-1.7.9-R0.2.jar:git-Spigot-1486]
            at net.minecraft.server.v1_7_R3.World.entityJoinedWorld(World.java:1622)
    [spigot-1.7.9-R0.2.jar:git-Spigot-1486]
            at net.minecraft.server.v1_7_R3.World.playerJoinedWorld(World.java:1598)
    [spigot-1.7.9-R0.2.jar:git-Spigot-1486]
            at net.minecraft.server.v1_7_R3.World.tickEntities(World.java:1464) [spi
    got-1.7.9-R0.2.jar:git-Spigot-1486]
            at net.minecraft.server.v1_7_R3.WorldServer.tickEntities(WorldServer.jav
    a:516) [spigot-1.7.9-R0.2.jar:git-Spigot-1486]
            at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:6
    93) [spigot-1.7.9-R0.2.jar:git-Spigot-1486]
            at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:2
    83) [spigot-1.7.9-R0.2.jar:git-Spigot-1486]
            at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:5
    83) [spigot-1.7.9-R0.2.jar:git-Spigot-1486]
            at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java
    :489) [spigot-1.7.9-R0.2.jar:git-Spigot-1486]
            at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:6
    28) [spigot-1.7.9-R0.2.jar:git-Spigot-1486]
    Caused by: java.lang.ClassCastException: org.bukkit.Location cannot be cast to o
    rg.bukkit.projectiles.ProjectileSource
            at nl.hotmail.mcpkmart.witherbows.WitherBow.splashEfect(WitherBow.java:2
    59) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0
    _60]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0
    _60]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1
    .7.0_60]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_60]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:292) ~[spigot-1.7.9-R0.2.jar:git-Spigot-1486]
            ... 15 more
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  4. Offline

    BaranCODE

    The problem is happening at this line:

    Code:
    ThrownPotion thrownPotion = ((ProjectileSource) arrowlocation).launchProjectile(ThrownPotion.class);
    You're trying to cast the arrowlocation to a ProjectileSource.
     
  5. Offline

    MinecraftMart

  6. Offline

    GameplayJDK

    MinecraftMart A location can't be a projectile source and it cant lauch a projectile source.
     
  7. Offline

    BaranCODE

    MinecraftMart As GameplayJDK said, you won't be able to do it this way. You could try using world.spawnEntity and see if that suits your needs.
     
    GameplayJDK likes this.
  8. Offline

    Necrodoom

  9. Offline

    MinecraftMart

    What should i use to spawn a potion at that location then?

    Code:java
    1. ThrownPotion thrownPotion = (ThrownPotion)world.spawnEntity(arrowlocation, SOMETHING NEEDS TO GO HERE, DONT KNOW WHAT);


    This? But what should go there?

    Necrodoom

    Huh, i think you need to go to the Forge forums? This bukkit.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  10. Offline

    Giraffeknee

    No he needs to go to spigot forums.
     
  11. Offline

    Iroh

    Locked.
    Seek help where you acquired your server mod.
     
Thread Status:
Not open for further replies.

Share This Page