3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-18 12:30:06 +01:00

Fixing some entity damage events

Dieser Commit ist enthalten in:
Andrew Ardill 2011-01-18 10:48:02 +11:00
Ursprung 8088a329cd
Commit ddc30dd6e3
3 geänderte Dateien mit 35 neuen und 16 gelöschten Zeilen

Datei anzeigen

@ -8,9 +8,11 @@ import org.bukkit.craftbukkit.entity.CraftLivingEntity;
import org.bukkit.craftbukkit.entity.CraftMinecart; import org.bukkit.craftbukkit.entity.CraftMinecart;
import org.bukkit.craftbukkit.entity.CraftMonster; import org.bukkit.craftbukkit.entity.CraftMonster;
import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.event.entity.EntityDamageByBlockEvent; import org.bukkit.event.entity.EntityDamageByBlockEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
//CraftBukkit end //CraftBukkit end
public class EntityMobs extends EntityCreature implements IMobs { public class EntityMobs extends EntityCreature implements IMobs {
@ -73,8 +75,12 @@ public class EntityMobs extends EntityCreature implements IMobs {
// CraftBukkit start // CraftBukkit start
if(entity instanceof EntityLiving) { if(entity instanceof EntityLiving) {
CraftServer server = ((WorldServer) l).getServer(); CraftServer server = ((WorldServer) l).getServer();
org.bukkit.entity.Entity damager = this.getBukkitEntity();
org.bukkit.entity.Entity damagee = entity.getBukkitEntity();
DamageCause damageType = EntityDamageEvent.DamageCause.ENTITY_ATTACK;
int damageDone = c;
EntityDamageByEntityEvent edbee = new EntityDamageByEntityEvent(entity.getBukkitEntity(), this.getBukkitEntity(), EntityDamageEvent.DamageCause.ENTITY_ATTACK, c); EntityDamageByEntityEvent edbee = new EntityDamageByEntityEvent(damager, damagee, damageType, damageDone);
server.getPluginManager().callEvent(edbee); server.getPluginManager().callEvent(edbee);
if (!edbee.isCancelled()){ if (!edbee.isCancelled()){

Datei anzeigen

@ -8,6 +8,7 @@ import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
// CraftBukkit end // CraftBukkit end
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
public abstract class EntityPlayer extends EntityLiving { public abstract class EntityPlayer extends EntityLiving {
@ -340,8 +341,12 @@ public abstract class EntityPlayer extends EntityLiving {
// CraftBukkit start // CraftBukkit start
if(entity instanceof EntityLiving) { if(entity instanceof EntityLiving) {
CraftServer server = ((WorldServer) l).getServer(); CraftServer server = ((WorldServer) l).getServer();
org.bukkit.entity.Entity damager = this.getBukkitEntity();
org.bukkit.entity.Entity damagee = entity.getBukkitEntity();
DamageCause damageType = EntityDamageEvent.DamageCause.ENTITY_ATTACK;
int damageDone = i;
EntityDamageByEntityEvent edbee = new EntityDamageByEntityEvent(entity.getBukkitEntity(), this.getBukkitEntity(), EntityDamageEvent.DamageCause.ENTITY_ATTACK, i); EntityDamageByEntityEvent edbee = new EntityDamageByEntityEvent(damager, damagee, damageType, damageDone);
server.getPluginManager().callEvent(edbee); server.getPluginManager().callEvent(edbee);
if (!edbee.isCancelled()){ if (!edbee.isCancelled()){

Datei anzeigen

@ -8,9 +8,13 @@ import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.event.entity.EntityDamageByBlockEvent; import org.bukkit.event.entity.EntityDamageByBlockEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.block.CraftBlock; import org.bukkit.craftbukkit.block.CraftBlock;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
// CraftBukkit end // CraftBukkit end
import java.util.*; import java.util.*;
@ -115,32 +119,36 @@ public class Explosion {
double d14 = (1.0D - d11) * d13; double d14 = (1.0D - d11) * d13;
// CraftBukkit start - explosion damage hook // CraftBukkit start - explosion damage hook
int damage = (int) (((d14 * d14 + d14) / 2D) * 8D * (double) f + 1.0D); CraftServer server = ((WorldServer) i).getServer();
CraftServer servr = ((WorldServer) i).getServer(); org.bukkit.entity.Entity damagee = null;
CraftEntity damagee = null; DamageCause damageType;
if (entity instanceof EntityPlayerMP) { int damageDone = (int) (((d14 * d14 + d14) / 2D) * 8D * (double) f + 1.0D);
damagee = new CraftPlayer(servr, (EntityPlayerMP) entity);
} else if (entity instanceof EntityLiving) { if(entity instanceof EntityLiving) {
damagee = new CraftLivingEntity(servr, (EntityLiving) entity); damagee = entity.getBukkitEntity();
} }
if (e == null) { // Block explosion if (e == null) { // Block explosion
// Craftbukkit TODO: get the x/y/z of the tnt block? // Craftbukkit TODO: get the x/y/z of the tnt block?
EntityDamageByBlockEvent edbbe = new EntityDamageByBlockEvent(null, damagee, EntityDamageEvent.DamageCause.BLOCK_EXPLOSION, damage); damageType = EntityDamageEvent.DamageCause.BLOCK_EXPLOSION;
servr.getPluginManager().callEvent(edbbe); EntityDamageByBlockEvent edbbe = new EntityDamageByBlockEvent(null, damagee, damageType, damageDone);
server.getPluginManager().callEvent(edbbe);
if (!edbbe.isCancelled()) { if (!edbbe.isCancelled()) {
entity.a(e, edbbe.getDamage()); entity.a(e, edbbe.getDamage());
} }
} else { } else {
CraftEntity damager = null; CraftEntity damager = null;
//TODO org.bukkit.entity.Entity damager = e.getBukkitEntity();
if (e instanceof EntityPlayerMP) { if (e instanceof EntityPlayerMP) {
// not possible in normal operations // not possible in normal operations
damager = new CraftPlayer(servr, (EntityPlayerMP) e); damager = new CraftPlayer(server, (EntityPlayerMP) e);
} else if (e instanceof EntityLiving) { } else if (e instanceof EntityLiving) {
damager = new CraftLivingEntity(servr, (EntityLiving) e); damager = new CraftLivingEntity(server, (EntityLiving) e);
} }
EntityDamageByEntityEvent edbbe = new EntityDamageByEntityEvent(damager, damagee, EntityDamageEvent.DamageCause.ENTITY_EXPLOSION, damage); damageType = EntityDamageEvent.DamageCause.ENTITY_ATTACK;
servr.getPluginManager().callEvent(edbbe);
EntityDamageByEntityEvent edbbe = new EntityDamageByEntityEvent(damager, damagee, damageType, damageDone);
server.getPluginManager().callEvent(edbbe);
if (!edbbe.isCancelled()) { if (!edbbe.isCancelled()) {
entity.a(e, edbbe.getDamage()); entity.a(e, edbbe.getDamage());