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

Entity audit. Adds checks for null entities, and adds conformity.

Dieser Commit ist enthalten in:
Andrew Ardill 2011-01-21 16:54:30 +11:00
Ursprung 1dad7de4f3
Commit 1cbde901ba
34 geänderte Dateien mit 211 neuen und 173 gelöschten Zeilen

Datei anzeigen

@ -1,11 +1,6 @@
package net.minecraft.server; package net.minecraft.server;
// CraftBukkit start // CraftBukkit start
import org.bukkit.entity.LivingEntity;
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.craftbukkit.CraftServer;
import org.bukkit.event.entity.EntityDamageByBlockEvent; import org.bukkit.event.entity.EntityDamageByBlockEvent;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
@ -102,7 +97,7 @@ public class BlockCactus extends Block {
if(entity instanceof EntityLiving) { if(entity instanceof EntityLiving) {
CraftServer server = ((WorldServer) world).getServer(); CraftServer server = ((WorldServer) world).getServer();
org.bukkit.block.Block damager = ((WorldServer) world).getWorld().getBlockAt(i, j, k); org.bukkit.block.Block damager = ((WorldServer) world).getWorld().getBlockAt(i, j, k);
org.bukkit.entity.Entity damagee = entity.getBukkitEntity(); org.bukkit.entity.Entity damagee = (entity == null)?null:entity.getBukkitEntity();
DamageCause damageType = EntityDamageEvent.DamageCause.CONTACT; DamageCause damageType = EntityDamageEvent.DamageCause.CONTACT;
int damageDone = 1; int damageDone = 1;

Datei anzeigen

@ -9,6 +9,7 @@ import org.bukkit.craftbukkit.entity.CraftBoat;
import org.bukkit.craftbukkit.entity.CraftEntity; import org.bukkit.craftbukkit.entity.CraftEntity;
import org.bukkit.craftbukkit.CraftMappable; import org.bukkit.craftbukkit.CraftMappable;
import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.entity.Vehicle; import org.bukkit.entity.Vehicle;
import org.bukkit.event.Event.Type; import org.bukkit.event.Event.Type;
import org.bukkit.event.vehicle.VehicleCreateEvent; import org.bukkit.event.vehicle.VehicleCreateEvent;
@ -86,7 +87,9 @@ public class EntityBoat extends Entity implements CraftMappable { // CraftBukkit
// CraftBukkit start // CraftBukkit start
private void handleCreation(World world) { private void handleCreation(World world) {
CraftServer server = ((WorldServer) world).getServer(); CraftServer server = ((WorldServer) world).getServer();
VehicleCreateEvent event = new VehicleCreateEvent( Type.VEHICLE_CREATE, (Vehicle) this.getBukkitEntity()); Type eventType = Type.VEHICLE_CREATE;
Vehicle vehicle = (Vehicle) this.getBukkitEntity();
VehicleCreateEvent event = new VehicleCreateEvent(eventType, vehicle);
server.getPluginManager().callEvent(event); server.getPluginManager().callEvent(event);
} }
// CraftBukkit end // CraftBukkit end
@ -97,7 +100,12 @@ public class EntityBoat extends Entity implements CraftMappable { // CraftBukkit
public boolean a(Entity entity, int i) { public boolean a(Entity entity, int i) {
// CraftBukkit start // CraftBukkit start
VehicleDamageEvent event = new VehicleDamageEvent( Type.VEHICLE_DAMAGE, (Vehicle) this.getBukkitEntity(), entity.getBukkitEntity(), i); Type eventType = Type.VEHICLE_DAMAGE;
Vehicle vehicle = (Vehicle) this.getBukkitEntity();
org.bukkit.entity.Entity attacker = (entity == null)?null:entity.getBukkitEntity();
int damage = i;
VehicleDamageEvent event = new VehicleDamageEvent(eventType, vehicle, attacker, damage);
((WorldServer) l).getServer().getPluginManager().callEvent(event); ((WorldServer) l).getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) { if (event.isCancelled()) {
@ -290,7 +298,13 @@ public class EntityBoat extends Entity implements CraftMappable { // CraftBukkit
// CraftBukkit start // CraftBukkit start
CraftServer server = ((WorldServer)l).getServer(); CraftServer server = ((WorldServer)l).getServer();
VehicleMoveEvent event = new VehicleMoveEvent(Type.VEHICLE_MOVE, (Vehicle) this.getBukkitEntity(), new Location(((WorldServer)l).getWorld(), prevX, prevY, prevZ, prevYaw, prevPitch), new Location(((WorldServer)l).getWorld(), p, q, r, v, w)); CraftWorld world = ((WorldServer)l).getWorld();
Type eventType = Type.VEHICLE_MOVE;
Vehicle vehicle = (Vehicle) this.getBukkitEntity();
Location from = new Location(world, prevX, prevY, prevZ, prevYaw, prevPitch);
Location to = new Location(world, p, q, r, v, w);
VehicleMoveEvent event = new VehicleMoveEvent(eventType, vehicle, from, to);
server.getPluginManager().callEvent(event); server.getPluginManager().callEvent(event);
// CraftBukkit end // CraftBukkit end
@ -325,7 +339,11 @@ public class EntityBoat extends Entity implements CraftMappable { // CraftBukkit
// CraftBukkit start // CraftBukkit start
public void c(Entity entity) { public void c(Entity entity) {
CraftServer server = ((WorldServer)l).getServer(); CraftServer server = ((WorldServer)l).getServer();
VehicleEntityCollisionEvent collsionEvent = new VehicleEntityCollisionEvent( Type.VEHICLE_COLLISION_ENTITY, (Vehicle) this.getBukkitEntity(), entity.getBukkitEntity()); Type eventType = Type.VEHICLE_COLLISION_ENTITY;
Vehicle vehicle = (Vehicle) this.getBukkitEntity();
org.bukkit.entity.Entity hitEntity = (entity == null)?null:entity.getBukkitEntity();
VehicleEntityCollisionEvent collsionEvent = new VehicleEntityCollisionEvent(eventType, vehicle, hitEntity);
server.getPluginManager().callEvent(collsionEvent); server.getPluginManager().callEvent(collsionEvent);
if (collsionEvent.isCancelled()) { if (collsionEvent.isCancelled()) {
@ -347,7 +365,11 @@ public class EntityBoat extends Entity implements CraftMappable { // CraftBukkit
if (!l.z) { if (!l.z) {
// CraftBukkit start // CraftBukkit start
CraftServer server = ((WorldServer)l).getServer(); CraftServer server = ((WorldServer)l).getServer();
VehicleEnterEvent event = new VehicleEnterEvent( Type.VEHICLE_ENTER, (Vehicle) this.getBukkitEntity(), entityplayer.getBukkitEntity()); Type eventType = Type.VEHICLE_ENTER;
Vehicle vehicle = (Vehicle) this.getBukkitEntity();
org.bukkit.entity.Entity player = entityplayer.getBukkitEntity();
VehicleEnterEvent event = new VehicleEnterEvent(eventType, vehicle, player);
server.getPluginManager().callEvent(event); server.getPluginManager().callEvent(event);
if (event.isCancelled()) { if (event.isCancelled()) {

Datei anzeigen

@ -196,7 +196,7 @@ public class EntityEgg extends Entity {
} }
} }
// Craftbukkit start // CraftBukkit start
boolean hatching = !this.l.z && W.nextInt(8) == 0; boolean hatching = !this.l.z && W.nextInt(8) == 0;
byte numHatching = (hatching && W.nextInt(32) == 0) ? (byte) 4 : (byte) 1; byte numHatching = (hatching && W.nextInt(32) == 0) ? (byte) 4 : (byte) 1;
if (!hatching) { if (!hatching) {
@ -207,7 +207,7 @@ public class EntityEgg extends Entity {
if (ak instanceof EntityPlayerMP) { if (ak instanceof EntityPlayerMP) {
CraftServer server = ((WorldServer) l).getServer(); CraftServer server = ((WorldServer) l).getServer();
Type eventType = Type.PLAYER_EGG_THROW; Type eventType = Type.PLAYER_EGG_THROW;
Player player = (Player) ak.getBukkitEntity(); Player player = (ak == null)?null:(Player) ak.getBukkitEntity();
PlayerEggThrowEvent event = new PlayerEggThrowEvent(eventType, player, hatching, numHatching, hatchingType); PlayerEggThrowEvent event = new PlayerEggThrowEvent(eventType, player, hatching, numHatching, hatchingType);
server.getPluginManager().callEvent(event); server.getPluginManager().callEvent(event);

Datei anzeigen

@ -13,11 +13,16 @@ public class EntityFallingSand extends Entity {
public EntityFallingSand(World world) { public EntityFallingSand(World world) {
super(world); super(world);
b = 0; b = 0;
// CraftBukkit start
CraftServer server = ((WorldServer) this.l).getServer();
this.bukkitEntity = new CraftFallingSand(server, this);
// CraftBukkit end
} }
public EntityFallingSand(World world, double d, double d1, double d2, int i) { public EntityFallingSand(World world, double d, double d1, double d2, int i) {
super(world); // CraftBukkit start
b = 0; this(world);
// CraftBukkit end
a = i; a = i;
this.i = true; this.i = true;
a(0.98F, 0.98F); a(0.98F, 0.98F);
@ -30,10 +35,6 @@ public class EntityFallingSand extends Entity {
m = d; m = d;
n = d1; n = d1;
o = d2; o = d2;
//CraftBukkit start
CraftServer server = ((WorldServer) this.l).getServer();
this.bukkitEntity = new CraftFallingSand(server, this);
//CraftBukkit end
} }
protected void a() {} protected void a() {}

Datei anzeigen

@ -17,12 +17,9 @@ public class EntityItem extends Entity {
public float d; public float d;
public EntityItem(World world, double d1, double d2, double d3, ItemStack itemstack) { public EntityItem(World world, double d1, double d2, double d3, ItemStack itemstack) {
super(world); // CraftBukkit start
b = 0; this(world);
f = 5; // CraftBukkit end
d = (float) (Math.random() * 3.1415926535897931D * 2D);
a(0.25F, 0.25F);
H = J / 2.0F;
a(d1, d2, d3); a(d1, d2, d3);
a = itemstack; a = itemstack;
v = (float) (Math.random() * 360D); v = (float) (Math.random() * 360D);
@ -30,10 +27,7 @@ public class EntityItem extends Entity {
t = 0.20000000298023224D; t = 0.20000000298023224D;
u = (float) (Math.random() * 0.20000000298023224D - 0.10000000149011612D); u = (float) (Math.random() * 0.20000000298023224D - 0.10000000149011612D);
M = false; M = false;
//CraftBukkit start
CraftServer server = ((WorldServer) this.l).getServer();
this.bukkitEntity = new CraftItem(server, this);
//CraftBukkit end
} }
public EntityItem(World world) { public EntityItem(World world) {
@ -43,6 +37,10 @@ public class EntityItem extends Entity {
d = (float) (Math.random() * 3.1415926535897931D * 2D); d = (float) (Math.random() * 3.1415926535897931D * 2D);
a(0.25F, 0.25F); a(0.25F, 0.25F);
H = J / 2.0F; H = J / 2.0F;
// CraftBukkit start
CraftServer server = ((WorldServer) this.l).getServer();
this.bukkitEntity = new CraftItem(server, this);
// CraftBukkit end
} }
protected void a() {} protected void a() {}

Datei anzeigen

@ -6,10 +6,9 @@ import java.util.Random;
// CraftBukkit start // CraftBukkit start
import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.entity.CraftLivingEntity; import org.bukkit.craftbukkit.entity.CraftLivingEntity;
//CraftBukkit end
import org.bukkit.event.entity.EntityDamageByBlockEvent;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
// CraftBukkit end
public abstract class EntityLiving extends Entity { public abstract class EntityLiving extends Entity {

Datei anzeigen

@ -9,6 +9,7 @@ import org.bukkit.craftbukkit.entity.CraftEntity;
import org.bukkit.craftbukkit.entity.CraftPoweredMinecart; import org.bukkit.craftbukkit.entity.CraftPoweredMinecart;
import org.bukkit.craftbukkit.entity.CraftStorageMinecart; import org.bukkit.craftbukkit.entity.CraftStorageMinecart;
import org.bukkit.craftbukkit.CraftMappable; import org.bukkit.craftbukkit.CraftMappable;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.entity.CraftMinecart; import org.bukkit.craftbukkit.entity.CraftMinecart;
import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.Vehicle; import org.bukkit.entity.Vehicle;
@ -172,7 +173,10 @@ public class EntityMinecart extends Entity implements IInventory, CraftMappable
// CraftBukkit start // CraftBukkit start
private void handleCreation(World world) { private void handleCreation(World world) {
CraftServer server = ((WorldServer) world).getServer(); CraftServer server = ((WorldServer) world).getServer();
VehicleCreateEvent event = new VehicleCreateEvent(Type.VEHICLE_CREATE, (Vehicle) this.getBukkitEntity()); Type eventType = Type.VEHICLE_CREATE;
Vehicle vehicle = (Vehicle) this.getBukkitEntity();
VehicleCreateEvent event = new VehicleCreateEvent(eventType, vehicle);
server.getPluginManager().callEvent(event); server.getPluginManager().callEvent(event);
} }
// CraftBukkit end // CraftBukkit end
@ -183,11 +187,12 @@ public class EntityMinecart extends Entity implements IInventory, CraftMappable
public boolean a(Entity entity, int i) { public boolean a(Entity entity, int i) {
// CraftBukkit start // CraftBukkit start
org.bukkit.entity.Entity passenger = null; Type eventType = Type.VEHICLE_DAMAGE;
if ((EntityLiving)entity != null) { Vehicle vehicle = (Vehicle) this.getBukkitEntity();
passenger = entity.getBukkitEntity(); org.bukkit.entity.Entity passenger = (entity == null)?null:entity.getBukkitEntity();
} int damage = i;
VehicleDamageEvent event = new VehicleDamageEvent(Type.VEHICLE_DAMAGE, (Vehicle) this.getBukkitEntity(), passenger, i);
VehicleDamageEvent event = new VehicleDamageEvent(eventType, vehicle, passenger, damage);
((WorldServer)l).getServer().getPluginManager().callEvent(event); ((WorldServer)l).getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) { if (event.isCancelled()) {
@ -510,7 +515,13 @@ public class EntityMinecart extends Entity implements IInventory, CraftMappable
// CraftBukkit start // CraftBukkit start
CraftServer server = ((WorldServer)this.l).getServer(); CraftServer server = ((WorldServer)this.l).getServer();
VehicleMoveEvent event = new VehicleMoveEvent(Type.VEHICLE_MOVE, (Vehicle) this.getBukkitEntity(), new Location(((WorldServer)this.l).getWorld(), prevX, prevY, prevZ, prevYaw, prevPitch), new Location(((WorldServer)this.l).getWorld(), p, q, r, v, w)); CraftWorld world = ((WorldServer)this.l).getWorld();
Type eventType = Type.VEHICLE_MOVE;
Vehicle vehicle = (Vehicle) this.getBukkitEntity();
Location from = new Location(world, prevX, prevY, prevZ, prevYaw, prevPitch);
Location to = new Location(world, p, q, r, v, w);
VehicleMoveEvent event = new VehicleMoveEvent(eventType , vehicle , from, to);
server.getPluginManager().callEvent(event); server.getPluginManager().callEvent(event);
// CraftBukkit end // CraftBukkit end
@ -646,7 +657,11 @@ public class EntityMinecart extends Entity implements IInventory, CraftMappable
// CraftBukkit start // CraftBukkit start
CraftServer server = ((WorldServer)l).getServer(); CraftServer server = ((WorldServer)l).getServer();
VehicleEntityCollisionEvent collsionEvent = new VehicleEntityCollisionEvent(Type.VEHICLE_COLLISION_ENTITY, (Vehicle) this.getBukkitEntity(), entity.getBukkitEntity()); Type eventType = Type.VEHICLE_COLLISION_ENTITY;
Vehicle vehicle = (Vehicle) this.getBukkitEntity();
org.bukkit.entity.Entity hitEntity = (entity == null)?null:entity.getBukkitEntity();
VehicleEntityCollisionEvent collsionEvent = new VehicleEntityCollisionEvent(eventType, vehicle, hitEntity);
server.getPluginManager().callEvent(collsionEvent); server.getPluginManager().callEvent(collsionEvent);
if (collsionEvent.isCancelled()) { if (collsionEvent.isCancelled()) {
@ -655,7 +670,9 @@ public class EntityMinecart extends Entity implements IInventory, CraftMappable
if ((entity instanceof EntityLiving) && !(entity instanceof EntityPlayer) && d == 0 && s * s + u * u > 0.01D && j == null && entity.k == null) { if ((entity instanceof EntityLiving) && !(entity instanceof EntityPlayer) && d == 0 && s * s + u * u > 0.01D && j == null && entity.k == null) {
if (!collsionEvent.isPickupCancelled()) { if (!collsionEvent.isPickupCancelled()) {
VehicleEnterEvent enterEvent = new VehicleEnterEvent(Type.VEHICLE_ENTER, (Vehicle) this.getBukkitEntity(), entity.getBukkitEntity()); eventType = Type.VEHICLE_ENTER;
VehicleEnterEvent enterEvent = new VehicleEnterEvent(eventType, vehicle, hitEntity);
server.getPluginManager().callEvent(enterEvent); server.getPluginManager().callEvent(enterEvent);
if (!enterEvent.isCancelled()) { if (!enterEvent.isCancelled()) {
@ -772,7 +789,11 @@ public class EntityMinecart extends Entity implements IInventory, CraftMappable
if (!l.z) { if (!l.z) {
// CraftBukkit start // CraftBukkit start
CraftServer server = ((WorldServer) l).getServer(); CraftServer server = ((WorldServer) l).getServer();
VehicleEnterEvent event = new VehicleEnterEvent(Type.VEHICLE_ENTER, (Vehicle) this.getBukkitEntity(), entityplayer.getBukkitEntity()); Type eventType = Type.VEHICLE_ENTER;
Vehicle vehicle = (Vehicle) this.getBukkitEntity();
org.bukkit.entity.Entity player = (entityplayer == null)?null:entityplayer.getBukkitEntity();
VehicleEnterEvent event = new VehicleEnterEvent(eventType, vehicle, player);
server.getPluginManager().callEvent(event); server.getPluginManager().callEvent(event);
if (event.isCancelled()) { if (event.isCancelled()) {

Datei anzeigen

@ -72,7 +72,7 @@ public class EntityMobs extends EntityCreature implements IMobs {
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 damager = this.getBukkitEntity();
org.bukkit.entity.Entity damagee = entity.getBukkitEntity(); org.bukkit.entity.Entity damagee = (entity == null)?null:entity.getBukkitEntity();
DamageCause damageType = EntityDamageEvent.DamageCause.ENTITY_ATTACK; DamageCause damageType = EntityDamageEvent.DamageCause.ENTITY_ATTACK;
int damageDone = c; int damageDone = c;

Datei anzeigen

@ -343,7 +343,7 @@ public abstract class EntityPlayer extends EntityLiving {
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 damager = this.getBukkitEntity();
org.bukkit.entity.Entity damagee = entity.getBukkitEntity(); org.bukkit.entity.Entity damagee = (entity == null)?null:entity.getBukkitEntity();
DamageCause damageType = EntityDamageEvent.DamageCause.ENTITY_ATTACK; DamageCause damageType = EntityDamageEvent.DamageCause.ENTITY_ATTACK;
int damageDone = i; int damageDone = i;

Datei anzeigen

@ -41,7 +41,9 @@ public class EntitySkeleton extends EntityMobs {
if (f1 > 0.5F && l.i(MathHelper.b(p), MathHelper.b(q), MathHelper.b(r)) && W.nextFloat() * 30F < (f1 - 0.4F) * 2.0F) { if (f1 > 0.5F && l.i(MathHelper.b(p), MathHelper.b(q), MathHelper.b(r)) && W.nextFloat() * 30F < (f1 - 0.4F) * 2.0F) {
// CraftBukkit start // CraftBukkit start
CraftServer server = ((WorldServer) l).getServer(); CraftServer server = ((WorldServer) l).getServer();
EntityCombustEvent event = new EntityCombustEvent(Type.ENTITY_COMBUST, this.getBukkitEntity()); Type eventType = Type.ENTITY_COMBUST;
org.bukkit.entity.Entity entity = this.getBukkitEntity();
EntityCombustEvent event = new EntityCombustEvent(eventType, entity);
server.getPluginManager().callEvent(event); server.getPluginManager().callEvent(event);
if (!event.isCancelled()) { if (!event.isCancelled()) {
Z = 300; Z = 300;

Datei anzeigen

@ -8,8 +8,8 @@ import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.entity.CraftSnowball; import org.bukkit.craftbukkit.entity.CraftSnowball;
import org.bukkit.event.entity.EntityDamageByProjectileEvent; import org.bukkit.event.entity.EntityDamageByProjectileEvent;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
//CraftBukkit end
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
// CraftBukkit end
public class EntitySnowball extends Entity { public class EntitySnowball extends Entity {