From 834bb3d486a08f26e499d3774f3e62e03a9b324b Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Thu, 10 Nov 2022 10:51:09 +0300 Subject: [PATCH] interact event fixed --- src/Player.php | 8 ++++++-- src/entity/Entity.php | 7 +++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Player.php b/src/Player.php index 296a0f30..7582c9e2 100755 --- a/src/Player.php +++ b/src/Player.php @@ -1794,7 +1794,11 @@ class Player{ $this->toCraft = []; $target = $this->server->api->entity->get($packet->target); if($target instanceof Entity and $this->entity instanceof Entity and $this->gamemode !== VIEW and $this->blocked === false and ($target instanceof Entity) and $this->entity->distance($target) <= 8){ - $target->interactWith($this->entity, $packet->action); + $data["targetentity"] = $packet->target; + $data["entity"] = $this; + if($this->server->handle("player.interact", $data) !== false){ + $target->interactWith($this->entity, $packet->action); + } } break; @@ -2385,4 +2389,4 @@ class PlayerNull extends Player{ public function __construct(){ } -} \ No newline at end of file +} diff --git a/src/entity/Entity.php b/src/entity/Entity.php index ae38e60b..0b693919 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -762,9 +762,8 @@ class Entity extends Position if($this->class === ENTITY_PLAYER and ($this->server->api->getProperty("pvp") == false or $this->server->difficulty <= 0 or ($e->player->gamemode & 0x01) === 0x01)){ return false; } - $data["targetentity"] = $this; - $data["entity"] = $e; - if($this->server->handle("player.interact", $data) !== false && $action === InteractPacket::ACTION_ATTACK && $e->isPlayer()){ + + if($action === InteractPacket::ACTION_ATTACK && $e->isPlayer()){ $slot = $e->player->getHeldItem(); $damage = $slot->getDamageAgainstOf($e); $this->harm($damage, $e->eid); @@ -1411,4 +1410,4 @@ class Entity extends Position { throw new Exception("Use getHeight or getWidth method instead of this."); } -} \ No newline at end of file +}