diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 29d3ab302..968b39182 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -748,7 +748,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ if($this->connected === false){ return false; } - $this->server->getPluginManager()->callEvent($ev = DataPacketSendEvent::createEvent($this, $packet)); + $this->server->getPluginManager()->callEvent($ev = $packet->getSendEvent($this)); if($ev->isCancelled()){ return false; } @@ -1288,7 +1288,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ return; } - $this->server->getPluginManager()->callEvent($ev = DataPacketReceiveEvent::createEvent($this, $packet)); + $this->server->getPluginManager()->callEvent($ev = $packet->getReceiveEvent($this)); if($ev->isCancelled()){ return; } diff --git a/src/pocketmine/block/Fence.php b/src/pocketmine/block/Fence.php index a9abe1551..a3575d44c 100644 --- a/src/pocketmine/block/Fence.php +++ b/src/pocketmine/block/Fence.php @@ -48,7 +48,7 @@ class Fence extends Transparent{ $this->y, $this->z + $f2, $this->x + $f1, - $this->y + 1, //TODO: check this, add extra bounding box + $this->y + 1, $this->z + $f3 ); } diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 68df97f32..645ec0c33 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -776,8 +776,7 @@ abstract class Entity extends Location implements Metadatable{ } public function isInsideOfWater(){ - $pos = Vector3::createVector($this->x, $y = ($this->y + $this->getEyeHeight()), $this->z); - $block = $this->level->getBlock($pos->floor()); + $block = $this->level->getBlock(Vector3::createVector(Math::floorFloat($this->x), Math::floorFloat($y = ($this->y + $this->getEyeHeight())), Math::floorFloat($this->z))); if($block instanceof Water){ $f = ($block->y + 1) - ($block->getFluidHeightPercent() - 0.1111111); @@ -788,8 +787,7 @@ abstract class Entity extends Location implements Metadatable{ } public function isInsideOfSolid(){ - $pos = Vector3::createVector($this->x, $y = ($this->y + $this->getEyeHeight()), $this->z); - $block = $this->level->getBlock($pos->floor()); + $block = $this->level->getBlock(Vector3::createVector(Math::floorFloat($this->x), Math::floorFloat($y = ($this->y + $this->getEyeHeight())), Math::floorFloat($this->z))); $bb = $block->getBoundingBox(); diff --git a/src/pocketmine/math/AxisAlignedBB.php b/src/pocketmine/math/AxisAlignedBB.php index c871036b2..b3ba52801 100644 --- a/src/pocketmine/math/AxisAlignedBB.php +++ b/src/pocketmine/math/AxisAlignedBB.php @@ -26,8 +26,8 @@ class AxisAlignedBB{ /** @var AxisAlignedBB[] */ - private static $boundingBoxes = []; - private static $nextBoundingBox = 0; + public static $boundingBoxes = []; + public static $nextBoundingBox = 0; public $minX; public $minY; @@ -126,11 +126,11 @@ class AxisAlignedBB{ $maxZ += $z; } - return self::getBoundingBoxFromPool($minX, $minY, $minZ, $maxX, $maxY, $maxZ); + return AxisAlignedBB::getBoundingBoxFromPool($minX, $minY, $minZ, $maxX, $maxY, $maxZ); } public function grow($x, $y, $z){ - return self::getBoundingBoxFromPool($this->minX - $x, $this->minY - $y, $this->minZ - $z, $this->maxX + $x, $this->maxY + $y, $this->maxZ + $z); + return AxisAlignedBB::getBoundingBoxFromPool($this->minX - $x, $this->minY - $y, $this->minZ - $z, $this->maxX + $x, $this->maxY + $y, $this->maxZ + $z); } public function expand($x, $y, $z){ @@ -156,7 +156,7 @@ class AxisAlignedBB{ } public function shrink($x, $y, $z){ - return self::getBoundingBoxFromPool($this->minX + $x, $this->minY + $y, $this->minZ + $z, $this->maxX - $x, $this->maxY - $y, $this->maxZ - $z); + return AxisAlignedBB::getBoundingBoxFromPool($this->minX + $x, $this->minY + $y, $this->minZ + $z, $this->maxX - $x, $this->maxY - $y, $this->maxZ - $z); } public function contract($x, $y, $z){ @@ -181,7 +181,7 @@ class AxisAlignedBB{ } public function getOffsetBoundingBox($x, $y, $z){ - return self::getBoundingBoxFromPool($this->minX + $x, $this->minY + $y, $this->minZ + $z, $this->maxX + $x, $this->maxY + $y, $this->maxZ + $z); + return AxisAlignedBB::getBoundingBoxFromPool($this->minX + $x, $this->minY + $y, $this->minZ + $z, $this->maxX + $x, $this->maxY + $y, $this->maxZ + $z); } public function calculateXOffset(AxisAlignedBB $bb, $x){ diff --git a/src/pocketmine/network/protocol/DataPacket.php b/src/pocketmine/network/protocol/DataPacket.php index fc175c28d..c99377a45 100644 --- a/src/pocketmine/network/protocol/DataPacket.php +++ b/src/pocketmine/network/protocol/DataPacket.php @@ -23,17 +23,27 @@ namespace pocketmine\network\protocol; #include -use pocketmine\item\Item; #ifndef COMPILE use pocketmine\utils\Binary; #endif +use pocketmine\event\server\DataPacketSendEvent; +use pocketmine\event\server\DataPacketReceiveEvent; +use pocketmine\item\Item; +use pocketmine\Player; + + abstract class DataPacket extends \stdClass{ /** @var DataPacket[] */ public static $pool = []; public static $next = 0; + /** @var DataPacketSendEvent */ + private $sendEvent = null; + /** @var DataPacketReceiveEvent */ + private $receiveEvent = null; + public static function getFromPool(){ if(static::$next >= count(static::$pool)){ static::$pool[] = new static; @@ -48,6 +58,38 @@ abstract class DataPacket extends \stdClass{ static::$next = 0; } + /** + * @param Player $player + * + * @return DataPacketReceiveEvent + */ + public function getReceiveEvent(Player $player){ + if($this->receiveEvent === null){ + $this->receiveEvent = new DataPacketReceiveEvent($player, $this); + }else{ + $this->receiveEvent->setCancelled(false); + $this->receiveEvent->__construct($player, $this); + } + + return $this->receiveEvent; + } + + /** + * @param Player $player + * + * @return DataPacketSendEvent + */ + public function getSendEvent(Player $player){ + if($this->sendEvent === null){ + $this->sendEvent = new DataPacketSendEvent($player, $this); + }else{ + $this->sendEvent->setCancelled(false); + $this->sendEvent->__construct($player, $this); + } + + return $this->sendEvent; + } + private $offset = 0; public $buffer = ""; public $isEncoded = false; diff --git a/src/pocketmine/utils/Binary.php b/src/pocketmine/utils/Binary.php index e18ba5f17..395dca2b0 100644 --- a/src/pocketmine/utils/Binary.php +++ b/src/pocketmine/utils/Binary.php @@ -74,7 +74,7 @@ class Binary{ * @return string */ public static function writeLTriad($value){ - return substr(pack("N", $value), 0, -1); + return substr(pack("V", $value), 0, -1); } /**