Skip to content

Commit 8134b60

Browse files
committed
This is a bugfix update.
1 parent 87fb0b5 commit 8134b60

3 files changed

Lines changed: 71 additions & 1 deletion

File tree

changelogs/1.3.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,7 @@ It is not compatible with plugins written for version 1.3.0 or lower, and plugin
982982
**Example:**
983983
```php
984984
$item->addComponent(new ItemTaskComponent(
985-
DiamondSword::class,
985+
self::class,
986986
function(Player $player, Item $item): void {
987987
$player->sendMessage("You are holding a Diamond Sword!");
988988
},

src/imperazim/vendor/customies/CustomiesManager.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use pocketmine\scheduler\ClosureTask;
1111
use pocketmine\event\player\PlayerDropItemEvent;
1212
use pocketmine\event\player\PlayerInteractEvent;
13+
use pocketmine\event\entity\EntityDamageByEntityEvent;
1314
use pocketmine\event\server\DataPacketSendEvent;
1415
use pocketmine\network\mcpe\protocol\StartGamePacket;
1516
use pocketmine\network\mcpe\protocol\ItemRegistryPacket;
@@ -32,6 +33,7 @@
3233
use imperazim\components\plugin\PluginComponent;
3334
use imperazim\components\plugin\traits\PluginComponentsTrait;
3435

36+
use imperazim\vendor\customies\task\ItemTask;
3537
use imperazim\vendor\customies\item\ItemComponents;
3638
use imperazim\vendor\customies\item\CustomiesItemFactory;
3739
use imperazim\vendor\customies\block\CustomiesBlockFactory;
@@ -165,4 +167,22 @@ public function onTitle(InventoryTransactionEvent $event) : void {
165167
}
166168
}
167169

170+
public function onEntityDamage(EntityDamageByEntityEvent $event): void {
171+
$damager = $event->getDamager();
172+
$entity = $event->getEntity();
173+
174+
// Verifica se o agressor e a vítima são jogadores
175+
if ($damager instanceof Player && $entity instanceof Player) {
176+
$item = $damager->getInventory()->getItemInHand();
177+
178+
// Verifica se o item tem o cjogadores
179+
if ($item instanceof ItemComponents) {
180+
$component = $item->getComponents()['minecraft:on_hit_effect'];
181+
if ($item->hasComponent($component->getName())) {
182+
$component->applyEffect($entity);
183+
}
184+
}
185+
}
186+
}
187+
168188
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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

Comments
 (0)