PaperMC/patches/server/0077-Only-process-BlockPhysicsEvent-if-a-plugin-has-a-lis.patch

71 lines
4.8 KiB
Diff
Raw Normal View History

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-10-26 03:13:48 +02:00
index d04ce36f79523417c7c2b49a8324b52ef6a6f0f4..412f97df192788bf38103a4c1754def47931fad4 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-10-26 03:13:48 +02:00
@@ -1621,6 +1621,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
2024-10-22 20:04:31 +02:00
gameprofilerfiller.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-10-25 21:24:15 +02:00
index b80af01529206bf55ed028dac41798f91da22f51..237a0b4dd0e1c437a021e1d2104e6d523b1f745a 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-10-22 20:04:31 +02:00
@@ -230,6 +230,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
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;
+ public boolean hasPhysicsEvent = true; // Paper - BlockPhysicsEvent
2021-06-11 14:02:28 +02: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-10-22 20:04:31 +02:00
index b37aeadf48e112170d64adc7587fdacbf6466aee..9ad531912c4298658915b45b2870539059e8aadd 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-06-13 19:30:39 +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) {
+ 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-10-22 20:04:31 +02:00
index 4db8f94dc279d05ed1cdf52e49ef780025828067..eb324fda54ada3ed7941713a784ed2d686ec8c4b 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
2024-10-22 20:04:31 +02:00
@@ -31,7 +31,7 @@ public abstract class BushBlock extends Block {
2021-06-11 14:02:28 +02:00
// CraftBukkit start
if (!state.canSurvive(world, pos)) {
2024-10-22 20:04:31 +02:00
// 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
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-10-22 20:04:31 +02:00
index 46047e0567af62612aad479fff6bea88903f108a..edb3b6cdb617c48140539728af1373993e78648f 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
2024-10-22 20:04:31 +02:00
@@ -104,7 +104,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