Solved What Event would i use

Discussion in 'Plugin Development' started by ChromeHD__, Feb 22, 2014.

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

    ChromeHD__

    Okay i am making a teleport bow plugin and im struggling to find the correct event to use i need it to find the arrow were it lannded and one that allows me to use player.teleport etc i tried one that only uses event.getentity.getshooter(); but its crossed out :(
     
  2. Offline

    Gater12

    ChromeHD__
    Did you listen to ProjectileHitEvent?
     
  3. Offline

    ChromeHD__

  4. Offline

    Niknea

    ChromeHD__ ProjectileHitEvnent is indeed the correct event.
     
  5. Offline

    ChromeHD__

    Niknea
    Code:java
    1. @EventHandler
    2. public void TeleportBow(ProjectileHitEvent e){
    3. Player player = (Player) e.getEntity();
    4. double x = e.getEntity().getLocation().getX();
    5. double y = e.getEntity().getLocation().getY();
    6. double z = e.getEntity().getLocation().getZ();
    7. Location loc = new Location(player.getWorld(), x, y, z);
    8. if(e.getEntity() instanceof Arrow){
    9.  
    10. }else{
    11. player.teleport(loc);
    12. }
    13. }


    Would this code work

    there is a error saying the entity arrow cant cast to player
     
  6. Offline

    jthort

    ChromeHD__ e.getEntity() returns the arrow, not the player who shot the arrow
     
  7. Offline

    NinjaWAffles

    Look at what the 'getEntity()' method returns -- Projectile. Projectile is not a player, thus you cannot cast it to be one. Projectile is referring to what hit the ground (snowball, enderpearl, etc); you'll want to use the method inside of the Projectile class, 'getShooter()' to find out the player who shot it.

    Code:Java
    1. Player player = (Player) e.getEntity().getShooter();
     
    jthort likes this.
  8. Offline

    ChromeHD__

    NinjaWAffles
    1. Player player = (Player) e.getEntity().getShooter();
    it says its depricated any time i go to use it and crosses it out
    Player player =(Player) e.getEntity().getShooter();
     
Thread Status:
Not open for further replies.

Share This Page