1+ <?php
2+
3+ declare (strict_types = 1 );
4+
5+ namespace imperazim \vendor \customies \item \component ;
6+
7+ use pocketmine \entity \effect \EffectInstance ;
8+ use pocketmine \entity \effect \VanillaEffects ;
9+ use pocketmine \item \Item ;
10+ use pocketmine \player \Player ;
11+ use pocketmine \plugin \Plugin ;
12+ use imperazim \vendor \customies \item \ItemComponents ;
13+
14+ final class OnHitEffectComponent implements ItemComponents {
15+
16+ private EffectInstance $ effect ;
17+ private Plugin $ plugin ;
18+
19+ /**
20+ * Creates a new OnHitEffectComponent to apply an effect to a player when hit with the item.
21+ *
22+ * @param Plugin $plugin The plugin instance to register the event listener.
23+ * @param EffectInstance $effect The effect to apply to the player when hit.
24+ */
25+ public function __construct (Plugin $ plugin , EffectInstance $ effect ) {
26+ $ this ->plugin = $ plugin ;
27+ $ this ->effect = $ effect ;
28+ $ this ->plugin ->getServer ()->getPluginManager ()->registerEvents ($ this , $ plugin );
29+ }
30+
31+ public function getName (): string {
32+ return "minecraft:on_hit_effect " ;
33+ }
34+
35+ public function getValue (): array {
36+ return [
37+ 'effect_id ' => $ this ->effect ->getType ()->getId (),
38+ 'effect_duration ' => $ this ->effect ->getDuration (),
39+ 'effect_amplifier ' => $ this ->effect ->getAmplifier (),
40+ ];
41+ }
42+
43+ public function isProperty (): bool {
44+ return false ;
45+ }
46+
47+ public function applyEffect (Player $ entity ): void {
48+ $ entity ->getEffects ()->add ($ this ->effect );
49+ }
50+ }
0 commit comments