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

[Bleeding] Moved projectile EntityDamageByEntityEvent's to event factory. Addresses BUKKIT-775

Dieser Commit ist enthalten in:
Feildmaster 2012-02-10 08:32:11 -06:00 committet von EvilSeph
Ursprung 5316c43a82
Commit b06719dd03
7 geänderte Dateien mit 41 neuen und 154 gelöschten Zeilen

Datei anzeigen

@ -6,8 +6,6 @@ import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.entity.Projectile;
import org.bukkit.event.entity.EntityCombustByEntityEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
// CraftBukkit end
@ -169,7 +167,8 @@ public class EntityArrow extends Entity {
if (movingobjectposition != null) {
// CraftBukkit start
ProjectileHitEvent phe = new ProjectileHitEvent((Projectile) this.getBukkitEntity());
Projectile projectile = (Projectile) this.getBukkitEntity();
ProjectileHitEvent phe = new ProjectileHitEvent(projectile);
this.world.getServer().getPluginManager().callEvent(phe);
// CraftBukkit end
if (movingobjectposition.entity != null) {
@ -198,28 +197,8 @@ public class EntityArrow extends Entity {
}
// CraftBukkit end
}
// CraftBukkit start
boolean stick;
if (entity instanceof EntityLiving || entity instanceof EntityComplexPart) {
org.bukkit.entity.Entity damagee = movingobjectposition.entity.getBukkitEntity();
Projectile projectile = (Projectile) this.getBukkitEntity();
EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(projectile, damagee, EntityDamageEvent.DamageCause.PROJECTILE, l);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
stick = !projectile.doesBounce();
} else {
// this function returns if the arrow should stick in or not, i.e. !bounce
stick = movingobjectposition.entity.damageEntity(damagesource, event.getDamage());
}
} else {
stick = movingobjectposition.entity.damageEntity(damagesource, l);
}
if (stick) {
// CraftBukkit end
// CraftBukkit - entity.damageEntity -> event function
if (org.bukkit.craftbukkit.event.CraftEventFactory.handleProjectileEvent(projectile, entity, damagesource, l)) {
if (movingobjectposition.entity instanceof EntityLiving) {
++((EntityLiving) movingobjectposition.entity).aJ;
if (this.n > 0) {

Datei anzeigen

@ -1,14 +1,12 @@
package net.minecraft.server;
import org.bukkit.Bukkit;
// CraftBukkit start
import org.bukkit.Location;
import org.bukkit.entity.Animals;
import org.bukkit.entity.CreatureType;
import org.bukkit.entity.Projectile;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.player.PlayerEggThrowEvent;
// CraftBukkit end
public class EntityEgg extends EntityProjectile {
@ -27,25 +25,7 @@ public class EntityEgg extends EntityProjectile {
protected void a(MovingObjectPosition movingobjectposition) {
// CraftBukkit start
if (movingobjectposition.entity != null) {
boolean stick;
if (movingobjectposition.entity instanceof EntityLiving || movingobjectposition.entity instanceof EntityComplexPart) {
org.bukkit.entity.Entity damagee = movingobjectposition.entity.getBukkitEntity();
Projectile projectile = (Projectile) this.getBukkitEntity();
EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(projectile, damagee, EntityDamageEvent.DamageCause.PROJECTILE, 0);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
stick = !projectile.doesBounce();
} else {
// this function returns if the egg should stick in or not, i.e. !bounce
stick = movingobjectposition.entity.damageEntity(DamageSource.projectile(this, this.shooter), event.getDamage());
}
} else {
stick = movingobjectposition.entity.damageEntity(DamageSource.projectile(this, this.shooter), 0);
}
if (stick) {
if (org.bukkit.craftbukkit.event.CraftEventFactory.handleProjectileEvent((org.bukkit.entity.Projectile) this.getBukkitEntity(), movingobjectposition.entity, DamageSource.projectile(this, this.shooter), 0)) {
; // Original code does nothing *yet*
}
}

Datei anzeigen

@ -3,12 +3,9 @@ package net.minecraft.server;
import java.util.List;
// CraftBukkit start
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.entity.CraftEntity;
import org.bukkit.entity.Explosive;
import org.bukkit.entity.Projectile;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.ExplosionPrimeEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
// CraftBukkit end
@ -181,30 +178,14 @@ public class EntityFireball extends Entity {
protected void a(MovingObjectPosition movingobjectposition) {
if (!this.world.isStatic) {
// CraftBukkit start
ProjectileHitEvent phe = new ProjectileHitEvent((Projectile) this.getBukkitEntity());
Projectile projectile = (Projectile) this.getBukkitEntity();
ProjectileHitEvent phe = new ProjectileHitEvent(projectile);
this.world.getServer().getPluginManager().callEvent(phe);
// CraftBukkit end
if (!this.world.isStatic) {
// CraftBukkit start
if (movingobjectposition.entity != null) {
boolean stick;
if (movingobjectposition.entity instanceof EntityLiving || movingobjectposition.entity instanceof EntityComplexPart) {
org.bukkit.entity.Entity damagee = movingobjectposition.entity.getBukkitEntity();
Projectile projectile = (Projectile) this.getBukkitEntity();
EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(projectile, damagee, EntityDamageEvent.DamageCause.PROJECTILE, 0);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
stick = !projectile.doesBounce();
} else {
// this function returns if the fireball should stick in or not, i.e. !bounce
stick = movingobjectposition.entity.damageEntity(DamageSource.fireball(this, this.shooter), event.getDamage());
}
} else {
stick = movingobjectposition.entity.damageEntity(DamageSource.fireball(this, this.shooter), 0);
}
if (stick) {
if (org.bukkit.craftbukkit.event.CraftEventFactory.handleProjectileEvent(projectile, movingobjectposition.entity, DamageSource.projectile(this, this.shooter), 0)) {
;
}
}

Datei anzeigen

@ -2,13 +2,7 @@ package net.minecraft.server;
import java.util.List;
// CraftBukkit start
import org.bukkit.Bukkit;
import org.bukkit.entity.Projectile;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.player.PlayerFishEvent;
// CraftBukkit end
import org.bukkit.event.player.PlayerFishEvent; // CraftBukkit
public class EntityFishingHook extends Entity {
@ -190,26 +184,8 @@ public class EntityFishingHook extends Entity {
if (movingobjectposition != null) {
if (movingobjectposition.entity != null) {
// CraftBukkit start
boolean stick;
if (movingobjectposition.entity instanceof EntityLiving || movingobjectposition.entity instanceof EntityComplexPart) {
org.bukkit.entity.Entity damagee = movingobjectposition.entity.getBukkitEntity();
Projectile projectile = (Projectile) this.getBukkitEntity();
EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(projectile, damagee, EntityDamageEvent.DamageCause.PROJECTILE, 0);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
stick = !projectile.doesBounce();
} else {
// this function returns if the fish should stick in or not, i.e. !bounce
stick = movingobjectposition.entity.damageEntity(DamageSource.projectile(this, this.owner), event.getDamage());
}
} else {
stick = movingobjectposition.entity.damageEntity(DamageSource.projectile(this, this.owner), 0);
}
if (!stick) {
// CraftBukkit end
// CraftBukkit - entity.damageEntity -> event function
if (!org.bukkit.craftbukkit.event.CraftEventFactory.handleProjectileEvent((org.bukkit.entity.Projectile) this.getBukkitEntity(), entity, DamageSource.projectile(this, this.owner), 0)) {
this.hooked = movingobjectposition.entity;
}
} else {

Datei anzeigen

@ -4,8 +4,6 @@ package net.minecraft.server;
import org.bukkit.Bukkit;
import org.bukkit.entity.Projectile;
import org.bukkit.event.entity.EntityCombustByEntityEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.plugin.PluginManager;
// CraftBukkit end
@ -25,7 +23,8 @@ public class EntitySmallFireball extends EntityFireball {
protected void a(MovingObjectPosition movingobjectposition) {
if (!this.world.isStatic) {
// CraftBukkit start - projectile hit event
ProjectileHitEvent phe = new ProjectileHitEvent((Projectile) this.getBukkitEntity());
Projectile projectile = (Projectile) this.getBukkitEntity();
ProjectileHitEvent phe = new ProjectileHitEvent(projectile);
final PluginManager pluginManager = Bukkit.getPluginManager();
pluginManager.callEvent(phe);
// CraftBukkit end
@ -33,25 +32,9 @@ public class EntitySmallFireball extends EntityFireball {
if (movingEntity != null) {
// CraftBukkit start - entity damage by entity event + combust event
if (!movingEntity.isFireproof()) { // check if not fireproof
boolean stick;
org.bukkit.entity.Entity damagee = movingEntity.getBukkitEntity();
Projectile projectile = (Projectile) this.getBukkitEntity();
if (movingEntity instanceof EntityLiving || movingEntity instanceof EntityComplexPart) {
EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(projectile, damagee, EntityDamageEvent.DamageCause.PROJECTILE, 5);
pluginManager.callEvent(event);
if (event.isCancelled()) {
stick = !projectile.doesBounce();
} else {
// this function returns if the fireball should stick in or not, i.e. !bounce
stick = movingEntity.damageEntity(DamageSource.fireball(this, this.shooter), event.getDamage());
}
} else {
stick = movingEntity.damageEntity(DamageSource.fireball(this, this.shooter), 5);
}
if (stick) {
if (org.bukkit.craftbukkit.event.CraftEventFactory.handleProjectileEvent(projectile, movingobjectposition.entity, DamageSource.projectile(this, this.shooter), 0)) {
// if the fireball 'sticks', ignite the target
EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(projectile, damagee, 5);
pluginManager.callEvent(combustEvent);

Datei anzeigen

@ -1,13 +1,5 @@
package net.minecraft.server;
// CraftBukkit start
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.entity.CraftLivingEntity;
import org.bukkit.entity.Projectile;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
// CraftBukkit end
public class EntitySnowball extends EntityProjectile {
public EntitySnowball(World world) {
@ -29,33 +21,8 @@ public class EntitySnowball extends EntityProjectile {
if (movingobjectposition.entity instanceof EntityBlaze) {
b0 = 3;
}
// CraftBukkit start
final Entity movingEntity = movingobjectposition.entity;
boolean stick = false;
if (movingEntity != null) {
if (movingEntity instanceof EntityLiving || movingEntity instanceof EntityComplexPart) {
org.bukkit.entity.Entity damagee = movingEntity.getBukkitEntity();
Projectile projectile = (Projectile) this.getBukkitEntity();
EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(projectile, damagee, EntityDamageEvent.DamageCause.PROJECTILE, b0);
Bukkit.getPluginManager().callEvent(event);
this.shooter = (projectile.getShooter() == null) ? null : ((CraftLivingEntity) projectile.getShooter()).getHandle();
b0 = event.getDamage();
if (event.isCancelled()) {
stick = !projectile.doesBounce();
} else {
// this function returns if the snowball should stick in or not, i.e. !bounce
stick = movingEntity.damageEntity(DamageSource.projectile(this, this.shooter), b0);
}
} else {
stick = movingEntity.damageEntity(DamageSource.projectile(this, this.shooter), b0);
}
}
if (stick) {
// CraftBukkit end
// CraftBukkit - entity.damageEntity -> event function
if (org.bukkit.craftbukkit.event.CraftEventFactory.handleProjectileEvent((org.bukkit.entity.Projectile) this.getBukkitEntity(), movingobjectposition.entity, DamageSource.projectile(this, this.shooter), b0)) {
;
}
}

Datei anzeigen

@ -5,13 +5,16 @@ import java.util.List;
import java.util.Map;
import net.minecraft.server.ChunkCoordinates;
import net.minecraft.server.DamageSource;
import net.minecraft.server.Entity;
import net.minecraft.server.EntityArrow;
import net.minecraft.server.EntityBlaze;
import net.minecraft.server.EntityCaveSpider;
import net.minecraft.server.EntityChicken;
import net.minecraft.server.EntityComplexPart;
import net.minecraft.server.EntityCow;
import net.minecraft.server.EntityCreeper;
import net.minecraft.server.EntityEnderCrystal;
import net.minecraft.server.EntityEnderDragon;
import net.minecraft.server.EntityEnderman;
import net.minecraft.server.EntityGhast;
@ -20,7 +23,6 @@ import net.minecraft.server.EntityHuman;
import net.minecraft.server.EntityItem;
import net.minecraft.server.EntityMagmaCube;
import net.minecraft.server.EntityLiving;
import net.minecraft.server.EntityMonster;
import net.minecraft.server.EntityMushroomCow;
import net.minecraft.server.EntityPig;
import net.minecraft.server.EntityPigZombie;
@ -40,9 +42,9 @@ import net.minecraft.server.Item;
import net.minecraft.server.ItemStack;
import net.minecraft.server.World;
import net.minecraft.server.WorldServer;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
@ -58,6 +60,7 @@ import org.bukkit.entity.Arrow;
import org.bukkit.entity.CreatureType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.ThrownPotion;
import org.bukkit.event.block.*;
import org.bukkit.event.entity.*;
@ -417,4 +420,22 @@ public class CraftEventFactory {
Bukkit.getPluginManager().callEvent(event);
return event;
}
public static boolean handleProjectileEvent(Projectile projectile, Entity target, DamageSource damagesource, int damage) {
if (target instanceof EntityLiving || target instanceof EntityComplexPart) {
org.bukkit.entity.Entity damagee = target.getBukkitEntity();
EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(projectile, damagee, EntityDamageEvent.DamageCause.PROJECTILE, damage);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
return target.damageEntity(damagesource, damage);
}
} else {
// Other entities have their events (if any) handled in damageEntity
return target.damageEntity(damagesource, damage);
}
return !projectile.doesBounce();
}
}