mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-26 18:39:23 +00:00
Skip BlockPhysicsEvent if no listeners
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
|
||||
Date: Sun, 3 Aug 2025 22:29:34 +0800
|
||||
Subject: [PATCH] Skip BlockPhysicsEvent if no listeners
|
||||
|
||||
BlockPhysicsEvent creates new CraftBlock instance and clones CraftBlockData when constructed it.
|
||||
It's a defensive programming stratgy and expensive if there are many neighbor updates.
|
||||
However, there is no plugin listening to this event sometimes, so that just add a check to not
|
||||
call it if no listeners listening to it.
|
||||
|
||||
diff --git a/net/minecraft/world/level/redstone/NeighborUpdater.java b/net/minecraft/world/level/redstone/NeighborUpdater.java
|
||||
index 332b33a004ab11150cca0cc2cefc26d0286648f5..3bbdfc1f1df1eaf76c3fdf977845a24c7f26ceb3 100644
|
||||
--- a/net/minecraft/world/level/redstone/NeighborUpdater.java
|
||||
+++ b/net/minecraft/world/level/redstone/NeighborUpdater.java
|
||||
@@ -49,6 +49,7 @@ public interface NeighborUpdater {
|
||||
static void executeUpdate(Level level, BlockState state, BlockPos pos, Block neighborBlock, @Nullable Orientation orientation, boolean movedByPiston, BlockPos sourcePos) {
|
||||
// Paper end - Add source block to BlockPhysicsEvent
|
||||
try {
|
||||
+ if (org.bukkit.event.block.BlockPhysicsEvent.getHandlerList().getRegisteredListeners().length != 0) { // Leaf - Skip BlockPhysicsEvent if no listeners
|
||||
// CraftBukkit start
|
||||
org.bukkit.event.block.BlockPhysicsEvent event = new org.bukkit.event.block.BlockPhysicsEvent(org.bukkit.craftbukkit.block.CraftBlock.at(level, pos), org.bukkit.craftbukkit.block.data.CraftBlockData.fromData(state), org.bukkit.craftbukkit.block.CraftBlock.at(level, sourcePos)); // Paper - Add source block to BlockPhysicsEvent
|
||||
level.getCraftServer().getPluginManager().callEvent(event);
|
||||
@@ -57,6 +58,7 @@ public interface NeighborUpdater {
|
||||
return;
|
||||
}
|
||||
// CraftBukkit end
|
||||
+ } // Leaf - Skip BlockPhysicsEvent if no listeners
|
||||
state.handleNeighborChanged(level, pos, neighborBlock, orientation, movedByPiston);
|
||||
// Spigot start
|
||||
} catch (StackOverflowError ex) {
|
||||
Reference in New Issue
Block a user