|
8 | 8 | #include "ll/api/memory/Memory.h" |
9 | 9 | #include "ll/api/service/Bedrock.h" |
10 | 10 | #include "mc/common/ActorUniqueID.h" |
| 11 | +#include "mc/deps/core/string/HashedString.h" |
11 | 12 | #include "mc/deps/ecs/WeakEntityRef.h" |
12 | 13 | #include "mc/server/ServerPlayer.h" |
13 | 14 | #include "mc/server/module/VanillaServerGameplayEventListener.h" |
|
19 | 20 | #include "mc/world/actor/player/Player.h" |
20 | 21 | #include "mc/world/actor/player/PlayerItemInUse.h" |
21 | 22 | #include "mc/world/containers/models/LevelContainerModel.h" |
| 23 | +#include "mc/world/effect/EffectDuration.h" |
| 24 | +#include "mc/world/effect/MobEffectInstance.h" |
22 | 25 | #include "mc/world/events/BlockEventCoordinator.h" |
23 | 26 | #include "mc/world/events/EventResult.h" |
24 | 27 | #include "mc/world/events/PlayerOpenContainerEvent.h" |
@@ -596,6 +599,50 @@ LL_TYPE_INSTANCE_HOOK( |
596 | 599 | return origin(actor, location); |
597 | 600 | } |
598 | 601 |
|
| 602 | +LL_TYPE_INSTANCE_HOOK( |
| 603 | + AddEffectHook, |
| 604 | + HookPriority::Normal, |
| 605 | + Player, |
| 606 | + &Player::addEffect, |
| 607 | + void, |
| 608 | + ::MobEffectInstance const& effect |
| 609 | +) { |
| 610 | + IF_LISTENED(EVENT_TYPES::onEffectAdded) { |
| 611 | + if (!CallEvent( |
| 612 | + EVENT_TYPES::onEffectAdded, |
| 613 | + PlayerClass::newPlayer(this), |
| 614 | + String::newString(effect.getComponentName().getString()), |
| 615 | + Number::newNumber(effect.getAmplifier()), |
| 616 | + Number::newNumber(effect.getDuration().getValueForSerialization()) |
| 617 | + )) { |
| 618 | + return; |
| 619 | + } |
| 620 | + } |
| 621 | + IF_LISTENED_END(EVENT_TYPES::onEffectAdded); |
| 622 | + origin(effect); |
| 623 | +} |
| 624 | + |
| 625 | +LL_TYPE_INSTANCE_HOOK( |
| 626 | + RemoveEffectHook, |
| 627 | + HookPriority::Normal, |
| 628 | + Player, |
| 629 | + &Player::$onEffectRemoved, |
| 630 | + void, |
| 631 | + ::MobEffectInstance& effect |
| 632 | +) { |
| 633 | + IF_LISTENED(EVENT_TYPES::onEffectRemoved) { |
| 634 | + if (!CallEvent( |
| 635 | + EVENT_TYPES::onEffectRemoved, |
| 636 | + PlayerClass::newPlayer(this), |
| 637 | + String::newString(effect.getComponentName().getString()) |
| 638 | + )) { |
| 639 | + return; |
| 640 | + } |
| 641 | + } |
| 642 | + IF_LISTENED_END(EVENT_TYPES::onEffectRemoved); |
| 643 | + origin(effect); |
| 644 | +} |
| 645 | + |
599 | 646 | void StartDestroyBlock() { StartDestroyHook::hook(); } |
600 | 647 | void DropItem() { |
601 | 648 | DropItemHook1::hook(); |
@@ -630,4 +677,6 @@ void UseBucketTakeEvent() { |
630 | 677 | void ConsumeTotemEvent() { ConsumeTotemHook::hook(); } |
631 | 678 | void SetArmorEvent() { SetArmorHook::hook(); } |
632 | 679 | void InteractEntityEvent() { InteractEntityHook::hook(); } |
| 680 | +void AddEffectEvent() { AddEffectHook::hook(); } |
| 681 | +void RemoveEffectEvent() { RemoveEffectHook::hook(); } |
633 | 682 | } // namespace lse::events::player |
0 commit comments