From 2aa5ac6c92a0e53ae917cae348d662d014ef9366 Mon Sep 17 00:00:00 2001 From: md_5 Date: Wed, 15 Mar 2017 20:48:47 +1100 Subject: [PATCH] SPIGOT-3128: Shift VehicleCreateEvent calling. --- nms-patches/EntityBoat.patch | 24 +++----- nms-patches/EntityMinecartAbstract.patch | 31 ++++------ nms-patches/World.patch | 56 ++++++++++--------- .../craftbukkit/event/CraftEventFactory.java | 19 +++++-- 4 files changed, 62 insertions(+), 68 deletions(-) diff --git a/nms-patches/EntityBoat.patch b/nms-patches/EntityBoat.patch index 474b0a4260..220125710a 100644 --- a/nms-patches/EntityBoat.patch +++ b/nms-patches/EntityBoat.patch @@ -31,15 +31,7 @@ public EntityBoat(World world) { super(world); this.f = new float[2]; -@@ -48,6 +65,7 @@ - this.lastX = d0; - this.lastY = d1; - this.lastZ = d2; -+ this.world.getServer().getPluginManager().callEvent(new org.bukkit.event.vehicle.VehicleCreateEvent((Vehicle) this.getBukkitEntity())); // CraftBukkit - } - - protected boolean playStepSound() { -@@ -95,6 +113,19 @@ +@@ -95,6 +112,19 @@ if (damagesource instanceof EntityDamageSourceIndirect && damagesource.getEntity() != null && this.w(damagesource.getEntity())) { return false; } else { @@ -59,7 +51,7 @@ this.d(-this.q()); this.b(10); this.setDamage(this.n() + f * 10.0F); -@@ -102,6 +133,15 @@ +@@ -102,6 +132,15 @@ boolean flag = damagesource.getEntity() instanceof EntityHuman && ((EntityHuman) damagesource.getEntity()).abilities.canInstantlyBuild; if (flag || this.n() > 40.0F) { @@ -75,7 +67,7 @@ if (!flag && this.world.getGameRules().getBoolean("doEntityDrops")) { this.a(this.j(), 1, 0.0F); } -@@ -119,9 +159,25 @@ +@@ -119,9 +158,25 @@ public void collide(Entity entity) { if (entity instanceof EntityBoat) { if (entity.getBoundingBox().b < this.getBoundingBox().e) { @@ -101,7 +93,7 @@ super.collide(entity); } -@@ -158,6 +214,7 @@ +@@ -158,6 +213,7 @@ return this.getDirection().e(); } @@ -109,7 +101,7 @@ public void A_() { this.aH = this.aG; this.aG = this.t(); -@@ -178,7 +235,6 @@ +@@ -178,7 +234,6 @@ if (this.n() > 0.0F) { this.setDamage(this.n() - 1.0F); } @@ -117,7 +109,7 @@ this.lastX = this.locX; this.lastY = this.locY; this.lastZ = this.locZ; -@@ -202,6 +258,22 @@ +@@ -202,6 +257,22 @@ this.motZ = 0.0D; } @@ -140,7 +132,7 @@ for (int i = 0; i <= 1; ++i) { if (this.a(i)) { this.f[i] = (float) ((double) this.f[i] + 0.01D); -@@ -593,6 +665,11 @@ +@@ -593,6 +664,11 @@ this.e(this.fallDistance, 1.0F); if (!this.world.isClientSide && !this.dead) { @@ -152,7 +144,7 @@ this.die(); if (this.world.getGameRules().getBoolean("doEntityDrops")) { int i; -@@ -606,6 +683,7 @@ +@@ -606,6 +682,7 @@ } } } diff --git a/nms-patches/EntityMinecartAbstract.patch b/nms-patches/EntityMinecartAbstract.patch index e7b2a9ad40..2760942b2e 100644 --- a/nms-patches/EntityMinecartAbstract.patch +++ b/nms-patches/EntityMinecartAbstract.patch @@ -34,16 +34,7 @@ public EntityMinecartAbstract(World world) { super(world); this.i = true; -@@ -90,6 +110,8 @@ - this.lastX = d0; - this.lastY = d1; - this.lastZ = d2; -+ -+ this.world.getServer().getPluginManager().callEvent(new org.bukkit.event.vehicle.VehicleCreateEvent((Vehicle) this.getBukkitEntity())); // CraftBukkit - } - - public double ay() { -@@ -101,6 +123,19 @@ +@@ -101,6 +121,19 @@ if (this.isInvulnerable(damagesource)) { return false; } else { @@ -63,7 +54,7 @@ this.e(-this.u()); this.d(10); this.ap(); -@@ -108,6 +143,15 @@ +@@ -108,6 +141,15 @@ boolean flag = damagesource.getEntity() instanceof EntityHuman && ((EntityHuman) damagesource.getEntity()).abilities.canInstantlyBuild; if (flag || this.getDamage() > 40.0F) { @@ -79,7 +70,7 @@ this.az(); if (flag && !this.hasCustomName()) { this.die(); -@@ -146,6 +190,14 @@ +@@ -146,6 +188,14 @@ } public void A_() { @@ -94,7 +85,7 @@ if (this.getType() > 0) { this.d(this.getType() - 1); } -@@ -166,7 +218,7 @@ +@@ -166,7 +216,7 @@ i = this.V(); if (this.ak) { @@ -103,7 +94,7 @@ if (!this.isPassenger() && this.al++ >= i) { this.al = i; this.portalCooldown = this.aE(); -@@ -266,6 +318,18 @@ +@@ -266,6 +316,18 @@ } this.setYawPitch(this.yaw, this.pitch); @@ -122,7 +113,7 @@ if (this.v() == EntityMinecartAbstract.EnumMinecartType.RIDEABLE && this.motX * this.motX + this.motZ * this.motZ > 0.01D) { List list = this.world.getEntities(this, this.getBoundingBox().grow(0.20000000298023224D, 0.0D, 0.20000000298023224D), IEntitySelector.a(this)); -@@ -274,8 +338,24 @@ +@@ -274,8 +336,24 @@ Entity entity = (Entity) list.get(l); if (!(entity instanceof EntityHuman) && !(entity instanceof EntityIronGolem) && !(entity instanceof EntityMinecartAbstract) && !this.isVehicle() && !entity.isPassenger()) { @@ -147,7 +138,7 @@ entity.collide(this); } } -@@ -287,6 +367,14 @@ +@@ -287,6 +365,14 @@ Entity entity1 = (Entity) iterator.next(); if (!this.w(entity1) && entity1.isCollidable() && entity1 instanceof EntityMinecartAbstract) { @@ -162,7 +153,7 @@ entity1.collide(this); } } -@@ -297,7 +385,7 @@ +@@ -297,7 +383,7 @@ } protected double o() { @@ -171,7 +162,7 @@ } public void a(int i, int j, int k, boolean flag) {} -@@ -308,16 +396,20 @@ +@@ -308,16 +394,20 @@ this.motX = MathHelper.a(this.motX, -d0, d0); this.motZ = MathHelper.a(this.motZ, -d0, d0); if (this.onGround) { @@ -198,7 +189,7 @@ } } -@@ -505,7 +597,7 @@ +@@ -505,7 +595,7 @@ } protected void r() { @@ -207,7 +198,7 @@ this.motX *= 0.996999979019165D; this.motY *= 0.0D; this.motZ *= 0.996999979019165D; -@@ -780,4 +872,26 @@ +@@ -780,4 +870,26 @@ } } diff --git a/nms-patches/World.patch b/nms-patches/World.patch index c0fda15be2..07afc4b684 100644 --- a/nms-patches/World.patch +++ b/nms-patches/World.patch @@ -272,7 +272,7 @@ int i = MathHelper.floor(entity.locX / 16.0D); int j = MathHelper.floor(entity.locZ / 16.0D); boolean flag = entity.attachedToPlayer; -@@ -793,6 +977,35 @@ +@@ -793,6 +977,37 @@ flag = true; } @@ -296,6 +296,8 @@ + } else if (entity.getBukkitEntity() instanceof org.bukkit.entity.Projectile) { + // Not all projectiles extend EntityProjectile, so check for Bukkit interface instead + event = CraftEventFactory.callProjectileLaunchEvent(entity); ++ } else if (entity.getBukkitEntity() instanceof org.bukkit.entity.Vehicle){ ++ event = CraftEventFactory.callVehicleCreateEvent(entity); + } + + if (event != null && (event.isCancelled() || entity.dead)) { @@ -308,7 +310,7 @@ if (!flag && !this.isChunkLoaded(i, j, false)) { return false; } else { -@@ -815,6 +1028,7 @@ +@@ -815,6 +1030,7 @@ ((IWorldAccess) this.u.get(i)).a(entity); } @@ -316,7 +318,7 @@ } protected void c(Entity entity) { -@@ -822,6 +1036,7 @@ +@@ -822,6 +1038,7 @@ ((IWorldAccess) this.u.get(i)).b(entity); } @@ -324,7 +326,7 @@ } public void kill(Entity entity) { -@@ -857,7 +1072,15 @@ +@@ -857,7 +1074,15 @@ this.getChunkAt(i, j).b(entity); } @@ -341,7 +343,7 @@ this.c(entity); } -@@ -974,7 +1197,7 @@ +@@ -974,7 +1199,7 @@ } public boolean a(AxisAlignedBB axisalignedbb) { @@ -350,7 +352,7 @@ } public int a(float f) { -@@ -1044,6 +1267,11 @@ +@@ -1044,6 +1269,11 @@ for (i = 0; i < this.j.size(); ++i) { entity = (Entity) this.j.get(i); @@ -362,7 +364,7 @@ try { ++entity.ticksLived; -@@ -1092,8 +1320,10 @@ +@@ -1092,8 +1322,10 @@ CrashReportSystemDetails crashreportsystemdetails1; CrashReport crashreport1; @@ -375,7 +377,7 @@ Entity entity1 = entity.bB(); if (entity1 != null) { -@@ -1126,7 +1356,7 @@ +@@ -1126,7 +1358,7 @@ this.getChunkAt(j, l).b(entity); } @@ -384,7 +386,7 @@ this.c(entity); } -@@ -1135,6 +1365,13 @@ +@@ -1135,6 +1367,13 @@ this.methodProfiler.c("blockEntities"); this.M = true; @@ -398,7 +400,7 @@ Iterator iterator = this.tileEntityListTick.iterator(); while (iterator.hasNext()) { -@@ -1145,7 +1382,7 @@ +@@ -1145,7 +1384,7 @@ if (this.isLoaded(blockposition) && this.N.a(blockposition)) { try { @@ -407,7 +409,7 @@ ((ITickable) tileentity).F_(); this.methodProfiler.b(); } catch (Throwable throwable2) { -@@ -1167,11 +1404,13 @@ +@@ -1167,11 +1406,13 @@ } this.M = false; @@ -421,7 +423,7 @@ this.methodProfiler.c("pendingBlockEntities"); if (!this.b.isEmpty()) { -@@ -1179,9 +1418,11 @@ +@@ -1179,9 +1420,11 @@ TileEntity tileentity1 = (TileEntity) this.b.get(i1); if (!tileentity1.y()) { @@ -433,7 +435,7 @@ if (this.isLoaded(tileentity1.getPosition())) { Chunk chunk = this.getChunkAtWorldCoords(tileentity1.getPosition()); -@@ -1189,6 +1430,12 @@ +@@ -1189,6 +1432,12 @@ chunk.a(tileentity1.getPosition(), tileentity1); this.notify(tileentity1.getPosition(), iblockdata, iblockdata, 3); @@ -446,7 +448,7 @@ } } } -@@ -1243,7 +1490,10 @@ +@@ -1243,7 +1492,10 @@ int j = MathHelper.floor(entity.locZ); boolean flag1 = true; @@ -458,7 +460,7 @@ entity.M = entity.locX; entity.N = entity.locY; entity.O = entity.locZ; -@@ -1547,11 +1797,18 @@ +@@ -1547,11 +1799,18 @@ } } @@ -477,7 +479,7 @@ TileEntity tileentity = null; if (this.M) { -@@ -1586,6 +1843,14 @@ +@@ -1586,6 +1845,14 @@ public void setTileEntity(BlockPosition blockposition, @Nullable TileEntity tileentity) { if (!this.E(blockposition)) { if (tileentity != null && !tileentity.y()) { @@ -492,7 +494,7 @@ if (this.M) { tileentity.setPosition(blockposition); Iterator iterator = this.b.iterator(); -@@ -1745,6 +2010,14 @@ +@@ -1745,6 +2012,14 @@ } this.o = MathHelper.a(this.o, 0.0F, 1.0F); @@ -507,7 +509,7 @@ } } } -@@ -1876,7 +2149,10 @@ +@@ -1876,7 +2151,10 @@ } public boolean c(EnumSkyBlock enumskyblock, BlockPosition blockposition) { @@ -519,7 +521,7 @@ return false; } else { int i = 0; -@@ -2043,7 +2319,7 @@ +@@ -2043,7 +2321,7 @@ while (iterator.hasNext()) { Entity entity = (Entity) iterator.next(); @@ -528,7 +530,7 @@ arraylist.add(entity); } } -@@ -2058,7 +2334,7 @@ +@@ -2058,7 +2336,7 @@ while (iterator.hasNext()) { Entity entity = (Entity) iterator.next(); @@ -537,7 +539,7 @@ arraylist.add(entity); } } -@@ -2107,7 +2383,7 @@ +@@ -2107,7 +2385,7 @@ } } @@ -546,7 +548,7 @@ } @Nullable -@@ -2128,8 +2404,17 @@ +@@ -2128,8 +2406,17 @@ while (iterator.hasNext()) { Entity entity = (Entity) iterator.next(); @@ -566,7 +568,7 @@ ++i; } } -@@ -2138,12 +2423,18 @@ +@@ -2138,12 +2425,18 @@ } public void a(Collection collection) { @@ -586,7 +588,7 @@ this.b(entity); } -@@ -2157,7 +2448,13 @@ +@@ -2157,7 +2450,13 @@ IBlockData iblockdata = this.getType(blockposition); AxisAlignedBB axisalignedbb = flag ? null : block.getBlockData().c(this, blockposition); @@ -601,7 +603,7 @@ } public int K() { -@@ -2267,6 +2564,11 @@ +@@ -2267,6 +2566,11 @@ for (int i = 0; i < this.players.size(); ++i) { EntityHuman entityhuman1 = (EntityHuman) this.players.get(i); @@ -613,7 +615,7 @@ if (predicate.apply(entityhuman1)) { double d5 = entityhuman1.d(d0, d1, d2); -@@ -2435,6 +2737,16 @@ +@@ -2435,6 +2739,16 @@ public void everyoneSleeping() {} @@ -630,7 +632,7 @@ public float h(float f) { return (this.p + (this.q - this.p) * f) * this.j(f); } -@@ -2652,7 +2964,7 @@ +@@ -2652,7 +2966,7 @@ int l = j * 16 + 8 - blockposition.getZ(); boolean flag = true; diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index a6c1528349..ad383ffe63 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -63,6 +63,8 @@ import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.meta.BookMeta; import org.bukkit.entity.AbstractHorse; +import org.bukkit.entity.Vehicle; +import org.bukkit.event.vehicle.VehicleCreateEvent; public class CraftEventFactory { public static final DamageSource MELTING = CraftDamageSource.copyOf(DamageSource.BURN); @@ -1015,11 +1017,18 @@ public class CraftEventFactory { return event; } - public static AreaEffectCloudApplyEvent callAreaEffectCloudApplyEvent(EntityAreaEffectCloud cloud, List entities) { - AreaEffectCloudApplyEvent event = new AreaEffectCloudApplyEvent((AreaEffectCloud) cloud.getBukkitEntity(), entities); - cloud.world.getServer().getPluginManager().callEvent(event); - return event; - } + public static AreaEffectCloudApplyEvent callAreaEffectCloudApplyEvent(EntityAreaEffectCloud cloud, List entities) { + AreaEffectCloudApplyEvent event = new AreaEffectCloudApplyEvent((AreaEffectCloud) cloud.getBukkitEntity(), entities); + cloud.world.getServer().getPluginManager().callEvent(event); + return event; + } + + public static VehicleCreateEvent callVehicleCreateEvent(Entity entity) { + Vehicle bukkitEntity = (Vehicle) entity.getBukkitEntity(); + VehicleCreateEvent event = new VehicleCreateEvent(bukkitEntity); + Bukkit.getPluginManager().callEvent(event); + return event; + } public static EntityBreedEvent callEntityBreedEvent(EntityLiving child, EntityLiving mother, EntityLiving father, EntityLiving breeder, ItemStack bredWith, int experience) { org.bukkit.entity.LivingEntity breederEntity = (LivingEntity)(breeder == null ? null : breeder.getBukkitEntity());