craftbukkit/src/main/java/net/minecraft/server/EntityEnderPearl.java
t00thpick1 6f21d3ca8f [Bleeding] Implement new damage api. Fixes BUKKIT-5326, BUKKIT-3878.
This commit centralizes event handling to where damage is actually applied
to the entity to avoid bugs that have resulted from nodamageticks,
modifications to damage after the event has been called, and similar
mishaps. This also implements new API for getting and setting of
modifications made to the damage amount actually applied to the entity.
This is done by storing the change in the damage amount as each modifier
is applied by vanilla code.

The method that actually damages the armor worn by an entity has been
relocated beneath the event called as to not apply durability loss when
the event has been cancelled.
2014-06-22 15:23:16 -05:00

56 lines
2.4 KiB
Java

package net.minecraft.server;
// CraftBukkit start
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.event.CraftEventFactory;
import org.bukkit.event.player.PlayerTeleportEvent;
// CraftBukkit end
public class EntityEnderPearl extends EntityProjectile {
public EntityEnderPearl(World world) {
super(world);
}
public EntityEnderPearl(World world, EntityLiving entityliving) {
super(world, entityliving);
}
protected void a(MovingObjectPosition movingobjectposition) {
if (movingobjectposition.entity != null) {
movingobjectposition.entity.damageEntity(DamageSource.projectile(this, this.getShooter()), 0.0F);
}
for (int i = 0; i < 32; ++i) {
this.world.addParticle("portal", this.locX, this.locY + this.random.nextDouble() * 2.0D, this.locZ, this.random.nextGaussian(), 0.0D, this.random.nextGaussian());
}
if (!this.world.isStatic) {
if (this.getShooter() != null && this.getShooter() instanceof EntityPlayer) {
EntityPlayer entityplayer = (EntityPlayer) this.getShooter();
if (entityplayer.playerConnection.b().isConnected() && entityplayer.world == this.world) {
// CraftBukkit start - Fire PlayerTeleportEvent
org.bukkit.craftbukkit.entity.CraftPlayer player = entityplayer.getBukkitEntity();
org.bukkit.Location location = getBukkitEntity().getLocation();
location.setPitch(player.getLocation().getPitch());
location.setYaw(player.getLocation().getYaw());
PlayerTeleportEvent teleEvent = new PlayerTeleportEvent(player, player.getLocation(), location, PlayerTeleportEvent.TeleportCause.ENDER_PEARL);
Bukkit.getPluginManager().callEvent(teleEvent);
if (!teleEvent.isCancelled() && !entityplayer.playerConnection.isDisconnected()) {
entityplayer.playerConnection.teleport(teleEvent.getTo());
this.getShooter().fallDistance = 0.0F;
CraftEventFactory.entityDamage = this;
this.getShooter().damageEntity(DamageSource.FALL, 5.0F);
CraftEventFactory.entityDamage = null;
}
// CraftBukkit end
}
}
this.die();
}
}
}