Commit Graph

166 Commits

Author SHA1 Message Date
84a16ce69a HandlerList: fixed crash on getting unused priority
these sub-arrays are no longer allocated if no handlers are registered.

fixes #5713
2023-04-21 16:19:15 +01:00
4ba57f2b03 RegisteredListener: use try...finally to stop timings
While event handlers should not throw exceptions, we need to make sure the timings get stopped in the correct order, because the parent Event timer will be stopped due to using a finally block.
If this happens while the handler timing is still running, a second exception will occur, obscuring the real error.
2023-04-16 00:40:43 +01:00
3490e2b06a Mark RegisteredListenerCache as internal 2023-04-11 22:33:44 +01:00
76ebedff6a HandlerList: remove unnecessary variable 2023-04-07 22:58:30 +01:00
3ea8d27a3b HandlerList: improve listener list development to make way for #5678 2023-04-07 22:55:27 +01:00
4724195791 Improved performance of event calls
This change significantly reduces the amount of work done by event handlers. Instead of traversing all of the priorities and event parent chain multiple times, we reduce event handlers down to a simple list, which doesn't require any logic to iterate over.
Previously, calling an event with lots of parents costed more than an event which directly descended from Event.
In addition, we had to do a lot of usually useless work to check all priorities, when in practice, only NORMAL will be used in almost all cases.

This change makes it more cost effective to implement the feature suggested by #5678; however, it will still require additional changes.
2023-04-05 23:02:44 +01:00
f32a853bd4 HandlerList: remove useless isset 2023-04-05 21:37:08 +01:00
b49a9ae81d Added timings for calling events
this gives a somewhat better overview of events, particularly if many plugins are subscribed to the same costly event (e.g. PlayerMoveEvent).

In addition, it allows us to see the frequency that events are occurring.
2023-03-28 17:26:20 +01:00
2751e1ec02 replacing new Vector3(0, 0, 0) with Vector3::zero() (#5640) 2023-03-20 12:54:28 +00:00
ef45180b80 Rename DataPacketPreReceiveEvent -> DataPacketDecodeEvent
thank you @IvanCraft623 for the suggestion
2023-03-16 13:40:37 +00:00
183d1f4038 Implement DataPacketPreReceiveEvent (#5559)
closes #5554

This is called just before the packet is decoded, allowing the event to be used to drop packets from clients without wasting CPU time decoding them. This can be particularly useful for mitigating denial-of-service attacks.
2023-03-15 22:47:19 +00:00
78aea5c34c Merge branch 'stable' into next-minor 2023-01-18 20:46:10 +00:00
d7f40f75d2 PlayerPreLoginEvent: fixed documentation errors 2023-01-18 20:45:49 +00:00
17125ce0e3 Merge branch 'stable' into next-minor 2022-12-23 16:56:54 +00:00
97ef209c5f HandlerList: added missing class-string type for constructor 2022-12-19 16:26:36 +00:00
95d0a3bf41 Merge branch 'stable' into next-minor 2022-12-15 19:38:22 +00:00
4357c110c8 Add the event: WorldParticleEvent (#5428) 2022-12-06 14:19:14 +00:00
99996b62d6 Align PhpDoc @param tags according to PHP-CS-Fixer 2022-12-06 13:21:20 +00:00
fed2a6d917 Add the event: WorldSoundEvent (#5322) 2022-12-06 13:06:40 +00:00
d476a4c1aa Implement a Living::getDisplayName() (#5384) 2022-11-27 19:48:55 +00:00
d79e6354a0 Merge branch 'stable' into next-minor 2022-11-25 14:41:05 +00:00
e5f5fe80f9 BlockGrowEvent: Remove unnecessary Cancellable implementation (#5359)
this is already implemented by BaseBlockChangeEvent
2022-11-23 13:29:23 +00:00
36ab34df29 Implement BlockDeathEvent (#5420)
closes #4711
2022-11-23 12:57:26 +00:00
0c463a8721 PlayerCreationEvent: update woefully inadequate documentation
closes #4581
2022-11-15 21:45:08 +00:00
39e10da88d PlayerChatEvent: replace hardcoded translation key with KnownTranslationKeys constant 2022-11-15 15:15:34 +00:00
c1fbac412e event: ensure that modifications to items expected to be readonly have no effect
this isn't a very glorious fix, but it's the best I have for now.
2022-10-07 11:33:14 +01:00
dce8bd6d21 CS: Standardize new with braces 2022-08-15 17:16:23 +01:00
38d6284671 Use PHP-CS-Fixer to enforce file header presence 2022-06-04 17:34:49 +01:00
179cac45f5 Merge branch 'stable' into next-minor 2022-05-22 16:21:05 +01:00
2ec65ba799 ExplosionPrimeEvent: require a positive explosion radius 2022-05-21 23:22:04 +01:00
3dd7c09351 Improve documentation of ExplosionPrimeEvent and EntityExplodeEvent 2022-05-21 23:00:34 +01:00
afc6e8878d EntityExplodeEvent: clamp yield in range 0-100 2022-05-21 22:44:45 +01:00
331b05c681 Improve documentation of EntitySpawnEvent and EntityDespawnEvent 2022-05-21 22:11:37 +01:00
3abe80184a Update ItemSpawnEvent doc (#5059) 2022-05-21 22:09:21 +01:00
7618b13c6e ItemDespawnEvent: improve documentation 2022-05-21 21:57:14 +01:00
351cd4bfd7 Improve documentation of world-related events 2022-05-21 21:46:53 +01:00
1154c7c1ab PlayerQuitEvent: improve documentation 2022-05-21 21:23:13 +01:00
4a3e42f82e PlayerTransferEvent: add documentation 2022-05-21 21:21:51 +01:00
8ecf9717d6 PlayerItemHeldEvent: add documentation
since some nuances of the intended behaviour were previously unclear...
2022-05-21 21:21:13 +01:00
3ca80b353b InventoryTransactionEvent: rewrite documentation 2022-05-21 21:20:11 +01:00
7d172e2211 PlayerCommandPreprocessEvent: updated documentation 2022-05-21 21:07:29 +01:00
e934e2bd26 PlayerDropItemEvent: updated documentation
this can be triggered by dropping an item outside of the inventory menu while the inventory window is open.
2022-05-21 21:05:27 +01:00
3177d19730 PlayerKickEvent: improved woefully inadequate documentation 2022-05-21 21:03:56 +01:00
82104a8251 UpdateNotifyEvent: updated documentation 2022-05-21 20:32:30 +01:00
e9a17374d1 Rewrite documentation of CommandEvent
no wonder people get the idea to use this shit for banning commands ...
2022-05-21 20:29:25 +01:00
a31bd19b5a Deprecated PlayerCommandPreProcessEvent
to be removed in PM5

see #4284
2022-05-21 20:20:09 +01:00
02cf6ae46c Added PlayerDeathEvent->setKeepXp(), closes #4002 (#4015) 2022-05-21 16:41:14 +01:00
d4b7f66e15 Promote some constructors 2022-05-17 22:34:58 +01:00
c0b15de504 Modernize private static property declarations 2022-05-17 21:55:16 +01:00
eb95e2a97e Modernize private property declarations in src/event 2022-05-17 20:45:50 +01:00