mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-11 10:12:06 -07:00
Implementation of the EntityDamage*Events.
Many files were added to enable the correct hooking of these events, and a new event EntityDamageByProjectileEvent. EntityDamageByProjectileEvent adds the ability to get the projectile entity (such as an egg) and also set if the projectile 'bounces'. Only two projectiles currently respond to bouncing, Arrow and Fish - were if the fish bounces it means the fish is not hooked. Bouncing is independent of any damage caused via the event. In addition, the changes to EntityDamageEvent that enable setting post-event damage were implemented in all hooks. Finally, a bug in CraftArrow was fixed, where the constructor was not declared public.
This commit is contained in:
committed by
Erik Broes
parent
807de6ee22
commit
ceaf94d5bb
@@ -6,6 +6,7 @@ import org.bukkit.craftbukkit.block.CraftBlock;
|
||||
import org.bukkit.craftbukkit.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.entity.CraftLivingEntity;
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.event.entity.EntityDamageByBlockEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
// CraftBukkit end
|
||||
@@ -96,21 +97,19 @@ public class BlockCactus extends Block {
|
||||
|
||||
public void a(World world, int i, int j, int k, Entity entity) {
|
||||
// CraftBukkit start - ENTITY_DAMAGEBY_BLOCK event
|
||||
CraftEntity toPassIn = null;
|
||||
if (entity instanceof EntityPlayerMP) {
|
||||
toPassIn = new CraftPlayer(((WorldServer) world).getServer(), (EntityPlayerMP) entity);
|
||||
} else if (entity instanceof EntityLiving) {
|
||||
toPassIn = new CraftLivingEntity(((WorldServer) world).getServer(), (EntityLiving) entity);
|
||||
}
|
||||
|
||||
if(toPassIn != null) {
|
||||
if(entity instanceof EntityLiving) {
|
||||
CraftServer server = ((WorldServer) world).getServer();
|
||||
CraftEntity toPassIn = new CraftLivingEntity(server, (EntityLiving) entity);
|
||||
EntityDamageByBlockEvent edbbe = new EntityDamageByBlockEvent(((WorldServer) world).getWorld().getBlockAt(i, j, k), toPassIn, EntityDamageEvent.DamageCause.CONTACT, 1);
|
||||
((WorldServer) world).getServer().getPluginManager().callEvent(edbbe);
|
||||
server.getPluginManager().callEvent(edbbe);
|
||||
|
||||
if (edbbe.isCancelled())
|
||||
return;
|
||||
if (!edbbe.isCancelled()){
|
||||
entity.a(((Entity) (null)), edbbe.getDamage());
|
||||
}
|
||||
return;
|
||||
}
|
||||
// CraftBukkit end TODO: Other entities (when their respective classes are added) hitting a Cactus
|
||||
// CraftBukkit end
|
||||
entity.a(((Entity) (null)), 1);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user