Set a player as a passenger on a projectile

Discussion in 'Plugin Development' started by PePsiGam3r, Sep 25, 2014.

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

    PePsiGam3r

    Hello Bukkit, I got a problem with Entity#setPassenger() method, when I set a player as a passenger on a projectile, like EnderPearls or Arrows, it sets the player for 1second maybe and drop them off, it's because the projectile DOES damage the player, is it possible to make it not damaging them?

    Code:java
    1. @EventHandler
    2. public void onThrow(ProjectileLaunchEvent e) {
    3. Projectile prj = e.getEntity();
    4. if (prj instanceof Arrow) {
    5. Arrow pearl = (Arrow) prj;
    6. ProjectileSource shooter = pearl.getShooter();
    7. if (shooter instanceof Player) {
    8. Player p = (Player) shooter;
    9. pearl.setPassenger(p);
    10. }
    11. }
    12. }


    Thanks in advance.
     
  2. Offline

    fireblast709

    PePsiGam3r arrows and exp bottles, use scoreboard teams. The other ones might need custom entities.
     
  3. Offline

    PePsiGam3r

    fireblast709 Why do I need to use scoreboard teams?
    I haven't tried all the projectiles but I guess all of projectiles that can damage players do the same...
     
  4. Offline

    fireblast709

    PePsiGam3r arrows won't damage you if you are in a team with friendly fire off. The other projectiles, however, aren't that nice to you. Their AI causes them to hit something no matter what you do, which in turn causes the entity to 'die'. The reason that you fly a bit is because it will not hit the shooter for 5 ticks.

    A little bit less efficient, you could run a scheduler that uses reflection to reset 'at' (field name based on 1.7.9) to 0, though this still leaves you version dependant due to the certainty that this field will have a different name in the next version.
     
  5. Offline

    PePsiGam3r

    fireblast709 Oh, got it! But the field 'at' is not an integer, but there's a field called attackTicks and it's an integer, which of them should I use?
     
  6. Offline

    fireblast709

    PePsiGam3r net.minecraft.server.v1_7_R4.EntityProjectile has a field 'private int af' ;)
     
  7. Offline

    PePsiGam3r

    Oh, thank you so much.
     
  8. Why not cancel the damage event? It would be version compatible.
     
  9. Offline

    PePsiGam3r

    adventuretc If you cancel the event, the shooter won't be damaged, but the projectile will be deleted.
     
Thread Status:
Not open for further replies.

Share This Page