Only process BlockPhysicsEvent if a plugin has a listener

Saves on some object allocation and processing when no plugin listens to this
This commit is contained in:
Aikar
2016-03-28 19:55:45 -04:00
parent b2671f4dd1
commit 63fa3068c6
5 changed files with 54 additions and 51 deletions

View File

@@ -415,7 +415,7 @@
+ // CraftBukkit start
+ iblockdata1.updateIndirectNeighbourShapes(this, blockposition, k, j - 1); // Don't call an event for the old block to limit event spam
+ CraftWorld world = ((ServerLevel) this).getWorld();
+ if (world != null) {
+ if (world != null && ((ServerLevel)this).hasPhysicsEvent) { // Paper - BlockPhysicsEvent
+ BlockPhysicsEvent event = new BlockPhysicsEvent(world.getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()), CraftBlockData.fromData(iblockdata));
+ this.getCraftServer().getPluginManager().callEvent(event);
+

View File

@@ -16,7 +16,7 @@
+ // CraftBukkit start
+ if (!state.canSurvive(world, pos)) {
+ // Suppress during worldgen
+ if (!(world instanceof Level world1) || !org.bukkit.craftbukkit.event.CraftEventFactory.callBlockPhysicsEvent(world1, pos).isCancelled()) {
+ if (!(world instanceof net.minecraft.server.level.ServerLevel world1 && world1.hasPhysicsEvent) || !org.bukkit.craftbukkit.event.CraftEventFactory.callBlockPhysicsEvent(world1, pos).isCancelled()) { // Paper
+ return Blocks.AIR.defaultBlockState();
+ }
+ }

View File

@@ -5,7 +5,7 @@
protected static void preventDropFromBottomPart(Level world, BlockPos pos, BlockState state, Player player) {
+ // CraftBukkit start
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockPhysicsEvent(world, pos).isCancelled()) {
+ if (((net.minecraft.server.level.ServerLevel)world).hasPhysicsEvent && org.bukkit.craftbukkit.event.CraftEventFactory.callBlockPhysicsEvent(world, pos).isCancelled()) { // Paper
+ return;
+ }
+ // CraftBukkit end