2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Mon, 28 Mar 2016 19:55:45 -0400
Subject: [PATCH] Only process BlockPhysicsEvent if a plugin has a listener
Saves on some object allocation and processing when no plugin listens to this
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
2024-04-24 03:25:14 +02:00
index b5f305c7d0972438a686d9b3a022156e39b130a2..d5b5eb914278fbd85921c039a8da3492dcbd6168 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
2024-04-24 03:25:14 +02:00
@@ -1520,6 +1520,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2021-06-11 14:02:28 +02:00
while (iterator.hasNext()) {
ServerLevel worldserver = (ServerLevel) iterator.next();
2024-02-01 10:15:57 +01:00
+ worldserver.hasPhysicsEvent = org.bukkit.event.block.BlockPhysicsEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper - BlockPhysicsEvent
2021-06-11 14:02:28 +02:00
this.profiler.push(() -> {
2024-04-24 03:25:14 +02:00
String s = String.valueOf(worldserver);
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
2024-04-24 03:25:14 +02:00
index 6ccc339b8a82c25ba382f1a5609b50cf68f03021..a1e187d2eef9a5dfa41657a90a95ed392c2a919c 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
2024-04-24 03:25:14 +02:00
@@ -226,6 +226,7 @@ public class ServerLevel extends Level implements WorldGenLevel {
2022-06-07 21:55:39 +02:00
// CraftBukkit start
2021-06-11 14:02:28 +02:00
public final LevelStorageSource.LevelStorageAccess convertable;
public final UUID uuid;
2024-01-23 14:34:17 +01:00
+ public boolean hasPhysicsEvent = true; // Paper - BlockPhysicsEvent
2021-06-11 14:02:28 +02:00
2024-01-23 14:34:17 +01:00
public LevelChunk getChunkIfLoaded(int x, int z) {
2021-06-11 14:02:28 +02:00
return this.chunkSource.getChunk(x, z, false);
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
2024-04-24 03:25:14 +02:00
index 0e0ab7b2790c1b7540eeb27eb17099e39a6099d4..2a7d2eea46e05d85ce3e72a69dfd26a671a882ac 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
2024-04-24 03:25:14 +02:00
@@ -491,7 +491,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
2021-06-11 14:02:28 +02:00
// 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) {
2024-01-23 14:34:17 +01:00
+ if (world != null && ((ServerLevel)this).hasPhysicsEvent) { // Paper - BlockPhysicsEvent
2021-06-11 14:02:28 +02:00
BlockPhysicsEvent event = new BlockPhysicsEvent(world.getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()), CraftBlockData.fromData(iblockdata));
this.getCraftServer().getPluginManager().callEvent(event);
diff --git a/src/main/java/net/minecraft/world/level/block/BushBlock.java b/src/main/java/net/minecraft/world/level/block/BushBlock.java
2024-04-24 03:25:14 +02:00
index 75109c79daa724340268438725bbf6d39b955691..a7b4b5600e3c889c69ac22294899713d50b5fe5c 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/level/block/BushBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/BushBlock.java
2023-12-05 20:54:55 +01:00
@@ -28,7 +28,7 @@ public abstract class BushBlock extends Block {
2024-04-24 03:25:14 +02:00
protected BlockState updateShape(BlockState state, Direction direction, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) {
2021-06-11 14:02:28 +02:00
// CraftBukkit start
if (!state.canSurvive(world, pos)) {
- if (!org.bukkit.craftbukkit.event.CraftEventFactory.callBlockPhysicsEvent(world, pos).isCancelled()) {
2022-03-01 06:43:03 +01:00
+ if (!(world instanceof net.minecraft.server.level.ServerLevel && ((net.minecraft.server.level.ServerLevel) world).hasPhysicsEvent) || !org.bukkit.craftbukkit.event.CraftEventFactory.callBlockPhysicsEvent(world, pos).isCancelled()) { // Paper
2021-06-11 14:02:28 +02:00
return Blocks.AIR.defaultBlockState();
}
}
diff --git a/src/main/java/net/minecraft/world/level/block/DoublePlantBlock.java b/src/main/java/net/minecraft/world/level/block/DoublePlantBlock.java
2024-04-24 03:25:14 +02:00
index cb76568cd1f97024c7a40328d9d72dd8a3e72e8b..7fdf744a2be55313cc75c1322f6534f55cf463f5 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/level/block/DoublePlantBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/DoublePlantBlock.java
2023-12-05 20:54:55 +01:00
@@ -102,7 +102,7 @@ public class DoublePlantBlock extends BushBlock {
2021-06-11 14:02:28 +02:00
2023-12-05 20:54:55 +01:00
protected static void preventDropFromBottomPart(Level world, BlockPos pos, BlockState state, Player player) {
2021-06-11 14:02:28 +02:00
// CraftBukkit start
- if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockPhysicsEvent(world, pos).isCancelled()) {
2022-06-08 15:38:56 +02:00
+ if (((net.minecraft.server.level.ServerLevel)world).hasPhysicsEvent && org.bukkit.craftbukkit.event.CraftEventFactory.callBlockPhysicsEvent(world, pos).isCancelled()) { // Paper
2021-06-11 14:02:28 +02:00
return;
}
// CraftBukkit end