Teleport Bow problem

Discussion in 'Plugin Development' started by monkeymanboy, Apr 14, 2014.

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

    monkeymanboy

    So I haven't touched this plugin in awhile and it looks like the arrow.getShooter() function gets the source and not the entity anymore so what is the new way to get what shot the arrow
    This is the code I am using
    Code:java
    1. @EventHandler
    2. public void EnderBow(ProjectileHitEvent event) {
    3. if(event.getEntity() instanceof Arrow){
    4. Arrow arrow = (Arrow) event.getEntity();
    5. Location arrowloc = (Location) arrow.getLocation();
    6. Entity shooter = arrow.getShooter();
    7. if(shooter instanceof Player) {
    8. Player player = (Player) shooter;
    9. if(player.getItemInHand().getType().equals(Material.BOW)){
    10. ItemMeta im = player.getItemInHand().getItemMeta();
    11. if(im.hasLore())
    12. if(im.getLore().contains("§6The dragons essence")){
    13. arrow.remove();
    14. player.teleport(arrowloc);
    15. }
    16. }
    17. }
    18. }
     
  2. Offline

    Are52Tap

    It is deprecated, meaning "that there is a better way to do it". It would rather of have recieved a ProjectileSource than a Entity. I tried figuring out how to using the ProjectileSource way but I, could not find out how. You may bypass the depreciation by adding
    Code:
    @SuppressWarnings("deprecation")
    after 5 right before the getShooter() and I also tested it and it indeed work. In the future they may make the ProjectileSource a better system.

    So all you need to do is add that part:

    Code:java
    1. @EventHandler
    2. public void EnderBow(ProjectileHitEvent event) {
    3. if(event.getEntity() instanceof Arrow){
    4. Arrow arrow = (Arrow) event.getEntity();
    5. Location arrowloc = (Location) arrow.getLocation();
    6. @SuppressWarnings("deprecation") //This is the code you add
    7. Entity shooter = arrow.getShooter();
    8. if(shooter instanceof Player) {
    9. Player player = (Player) shooter;
    10. if(player.getItemInHand().getType().equals(Material.BOW)){
    11. ItemMeta im = player.getItemInHand().getItemMeta();
    12. if(im.hasLore())
    13. if(im.getLore().contains("§6The dragons essence")){
    14. arrow.remove();
    15. player.teleport(arrowloc);
    16. }
    17. }
    18. }
     
  3. Offline

    monkeymanboy

    Should I cast Entity to it?
     
  4. Offline

    Are52Tap

    All you have to do is add -->@SupressWarnings("deprecation")<--
    I was just saying there is another way of doing it but, adding this will bypass it so you can do it without finding the new way to do it.
    So the code should be this:
    Code:java
    1. @EventHandler
    2. public void EnderBow(ProjectileHitEvent event) {
    3. if(event.getEntity() instanceof Arrow){
    4. Arrow arrow = (Arrow) event.getEntity();
    5. Location arrowloc = (Location) arrow.getLocation();
    6. @SuppressWarnings("deprecation") //THIS IS THE ONLY CODE YOU ADD.
    7. Entity shooter = arrow.getShooter();
    8. if(shooter instanceof Player) {
    9. Player player = (Player) shooter;
    10. if(player.getItemInHand().getType().equals(Material.BOW)){
    11. ItemMeta im = player.getItemInHand().getItemMeta();
    12. if(im.hasLore())
    13. if(im.getLore().contains("§6The dragons essence")){
    14. arrow.remove();
    15. player.teleport(arrowloc);
    16. }
    17. }
    18. }
     
  5. Offline

    monkeymanboy

    I wasn't getting a deprecation error but casting entity to it worked fine I just had to do an if instanceof Entity before so that dispensers don't give an error
     
  6. Offline

    Are52Tap

    Okay glad it works now :).
     
Thread Status:
Not open for further replies.

Share This Page