Cancel certain ender pearl hit player events

Discussion in 'Plugin Development' started by nuno1212sss, Mar 1, 2015.

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

    nuno1212sss

    Hello, I'm creating a spectator plugin(Yes, I know about gamemode 3 but I don't want to use it) and I want to cancel the teleport that is done when an ender pearl hits a player, here is what I have done so far
    Code:
     else if (!damaged.isPlaying() && e.getDamager() instanceof EnderPearl) {
                e.setCancelled(true);
                final Player spec = (Player) e.getEntity();
                final Location initialSpec = spec.getLocation();
                final Vector initialProjectileV = e.getDamager().getVelocity();
                final Location initialProjectileL = e.getDamager().getLocation();
                final EnderPearl p = (EnderPearl) e.getDamager();
                final Player shooter = (Player) p.getShooter();
                p.remove();
                new BukkitRunnable() {
                    public void run() {
                        EnderPearl l = initialProjectileL.getWorld().spawn(initialProjectileL, EnderPearl.class);
                        l.setShooter(shooter);
                        l.setVelocity(initialProjectileV);
                    }
                }.runTaskLater(plugin, 1L);
                new BukkitRunnable() {
                    public void run() {
                        spec.teleport(initialSpec);
                    }
                }.runTaskLater(plugin, 10L);
            }
    This causes the player to get teleported twice.
    Any help would be apreciated.
     
  2. Offline

    bazsi700

    You summon an enderpearl at the hitting location, and you teleport the shooter manually too. The shooter will be teleported from the sumonned enderpearl too. I think it's useless.
     
  3. Offline

    nuno1212sss

    @bazsi700 I know that, but I don't want the first teleport to take place. That's why I cancel the event, but it stills teleports the player
     
  4. Offline

    bazsi700

    Ahh I understood. You cancel the damage event, not the enderpearl. You have to listen to PlayerTeleportEvent, and if it's cause is ENDER_PEARL then cancel it.
     
  5. Offline

    nuno1212sss

    @bazsi700 That will cancel ALL teleports, not just the teleport that I want to be cancelled
     
  6. Offline

    Hex_27

    @nuno1212sss No. If the CAUSE of the event is ENDER_PEARL, then only ender pearl teleports will be cancelled. Not all teleports.
    For your info, enderpearls don't "hit" entities, nor do they damage them, so event.getDamager() would never be an enderpearl.
     
  7. Offline

    nuno1212sss

    @Hex_27 Wrong, they do, and they cancel all the ENDER PEARL teleports, not just the ones that I want :D
     
  8. Offline

    Hex_27

Thread Status:
Not open for further replies.

Share This Page