mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 00:33:59 +00:00
Improved network packets allocation
This commit is contained in:
parent
3f5b129cf5
commit
db82f76c11
@ -581,7 +581,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
return;
|
||||
}
|
||||
|
||||
$pk = new FullChunkDataPacket;
|
||||
$pk = FullChunkDataPacket::getFromPool();
|
||||
$pk->chunkX = $x;
|
||||
$pk->chunkZ = $z;
|
||||
$pk->data = $payload;
|
||||
@ -645,7 +645,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
|
||||
$this->blocked = false;
|
||||
|
||||
$pk = new SetTimePacket;
|
||||
$pk = SetTimePacket::getFromPool();
|
||||
$pk->time = $this->level->getTime();
|
||||
$pk->started = $this->level->stopTime == false;
|
||||
$this->dataPacket($pk);
|
||||
@ -834,7 +834,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$level = $pos->getLevel();
|
||||
}
|
||||
$this->spawnPosition = new Position($pos->x, $pos->y, $pos->z, $level);
|
||||
$pk = new SetSpawnPositionPacket;
|
||||
$pk = SetSpawnPositionPacket::getFromPool();
|
||||
$pk->x = (int) $this->spawnPosition->x;
|
||||
$pk->y = (int) $this->spawnPosition->y;
|
||||
$pk->z = (int) $this->spawnPosition->z;
|
||||
@ -947,7 +947,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
|
||||
$spawnPosition = $this->getSpawn();
|
||||
|
||||
$pk = new StartGamePacket;
|
||||
$pk = StartGamePacket::getFromPool();
|
||||
$pk->seed = $this->level->getSeed();
|
||||
$pk->x = $this->x;
|
||||
$pk->y = $this->y + $this->getEyeHeight();
|
||||
@ -1017,7 +1017,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$flags |= 0x20; //Show Nametags
|
||||
}
|
||||
|
||||
$pk = new AdventureSettingsPacket;
|
||||
$pk = AdventureSettingsPacket::getFromPool();
|
||||
$pk->flags = $flags;
|
||||
$this->dataPacket($pk);
|
||||
}
|
||||
@ -1125,7 +1125,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
if($to->distance($ev->getTo()) > 0.1){ //If plugins modify the destination
|
||||
$this->teleport($ev->getTo());
|
||||
}else{
|
||||
$pk = new MovePlayerPacket;
|
||||
$pk = MovePlayerPacket::getFromPool();
|
||||
$pk->eid = $this->id;
|
||||
$pk->x = $this->x;
|
||||
$pk->y = $this->y;
|
||||
@ -1140,7 +1140,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
}
|
||||
|
||||
if($revert){
|
||||
$pk = new MovePlayerPacket;
|
||||
$pk = MovePlayerPacket::getFromPool();
|
||||
$pk->eid = 0;
|
||||
$pk->x = $from->x;
|
||||
$pk->y = $from->y + $this->getEyeHeight() + 0.01;
|
||||
@ -1206,11 +1206,11 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
continue;
|
||||
}
|
||||
|
||||
$pk = new TakeItemEntityPacket;
|
||||
$pk = TakeItemEntityPacket::getFromPool();
|
||||
$pk->eid = 0;
|
||||
$pk->target = $entity->getID();
|
||||
$this->dataPacket($pk);
|
||||
$pk = new TakeItemEntityPacket;
|
||||
$pk = TakeItemEntityPacket::getFromPool();
|
||||
$pk->eid = $this->getID();
|
||||
$pk->target = $entity->getID();
|
||||
Server::broadcastPacket($entity->getViewers(), $pk);
|
||||
@ -1240,11 +1240,11 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
break;
|
||||
}
|
||||
|
||||
$pk = new TakeItemEntityPacket;
|
||||
$pk = TakeItemEntityPacket::getFromPool();
|
||||
$pk->eid = 0;
|
||||
$pk->target = $entity->getID();
|
||||
$this->dataPacket($pk);
|
||||
$pk = new TakeItemEntityPacket;
|
||||
$pk = TakeItemEntityPacket::getFromPool();
|
||||
$pk->eid = $this->getID();
|
||||
$pk->target = $entity->getID();
|
||||
Server::broadcastPacket($entity->getViewers(), $pk);
|
||||
@ -1307,11 +1307,11 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
}
|
||||
if($packet->protocol1 !== ProtocolInfo::CURRENT_PROTOCOL){
|
||||
if($packet->protocol1 < ProtocolInfo::CURRENT_PROTOCOL){
|
||||
$pk = new LoginStatusPacket;
|
||||
$pk = LoginStatusPacket::getFromPool();
|
||||
$pk->status = 1;
|
||||
$this->dataPacket($pk);
|
||||
}else{
|
||||
$pk = new LoginStatusPacket;
|
||||
$pk = LoginStatusPacket::getFromPool();
|
||||
$pk->status = 2;
|
||||
$this->dataPacket($pk);
|
||||
}
|
||||
@ -1413,7 +1413,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$this->inventory->setHeldItemSlot(0);
|
||||
}
|
||||
|
||||
$pk = new LoginStatusPacket;
|
||||
$pk = LoginStatusPacket::getFromPool();
|
||||
$pk->status = 0;
|
||||
$this->dataPacket($pk);
|
||||
|
||||
@ -1425,7 +1425,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
|
||||
$this->dead = false;
|
||||
|
||||
$pk = new StartGamePacket;
|
||||
$pk = StartGamePacket::getFromPool();
|
||||
$pk->seed = $this->level->getSeed();
|
||||
$pk->x = $this->x;
|
||||
$pk->y = $this->y;
|
||||
@ -1438,17 +1438,18 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$pk->eid = 0; //Always use EntityID as zero for the actual player
|
||||
$this->dataPacket($pk);
|
||||
|
||||
$pk = new SetTimePacket();
|
||||
$pk = SetTimePacket::getFromPool();
|
||||
$pk->time = $this->level->getTime();
|
||||
$pk->started = $this->level->stopTime == false;
|
||||
$this->dataPacket($pk);
|
||||
|
||||
$pk = new SetSpawnPositionPacket;
|
||||
$pk = SetSpawnPositionPacket::getFromPool();
|
||||
$pk->x = (int) $spawnPosition->x;
|
||||
$pk->y = (int) $spawnPosition->y;
|
||||
$pk->z = (int) $spawnPosition->z;
|
||||
$this->dataPacket($pk);
|
||||
|
||||
$pk = new SetHealthPacket();
|
||||
$pk = SetHealthPacket::getFromPool();
|
||||
$pk->health = $this->getHealth();
|
||||
$this->dataPacket($pk);
|
||||
if($this->getHealth() <= 0){
|
||||
@ -1474,7 +1475,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$revert = ($this->dead === true or $this->spawned !== true);
|
||||
|
||||
if($revert or ($this->forceMovement instanceof Vector3 and $newPos->distance($this->forceMovement) > 0.2)){
|
||||
$pk = new MovePlayerPacket();
|
||||
$pk = MovePlayerPacket::getFromPool();
|
||||
$pk->eid = 0;
|
||||
$pk->x = $this->x;
|
||||
$pk->y = $this->y + $this->getEyeHeight() + 0.01;
|
||||
@ -1565,7 +1566,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$target = $this->level->getBlock($blockVector);
|
||||
$block = $target->getSide($packet->face);
|
||||
|
||||
$pk = new UpdateBlockPacket;
|
||||
$pk = UpdateBlockPacket::getFromPool();
|
||||
$pk->x = $target->x;
|
||||
$pk->y = $target->y;
|
||||
$pk->z = $target->z;
|
||||
@ -1573,7 +1574,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$pk->meta = $target->getDamage();
|
||||
$this->dataPacket($pk);
|
||||
|
||||
$pk = new UpdateBlockPacket;
|
||||
$pk = UpdateBlockPacket::getFromPool();
|
||||
$pk->x = $block->x;
|
||||
$pk->y = $block->y;
|
||||
$pk->z = $block->z;
|
||||
@ -1612,7 +1613,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$target = $this->level->getBlock($blockVector);
|
||||
$block = $target->getSide($packet->face);
|
||||
|
||||
$pk = new UpdateBlockPacket;
|
||||
$pk = UpdateBlockPacket::getFromPool();
|
||||
$pk->x = $target->x;
|
||||
$pk->y = $target->y;
|
||||
$pk->z = $target->z;
|
||||
@ -1620,7 +1621,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$pk->meta = $target->getDamage();
|
||||
$this->dataPacket($pk);
|
||||
|
||||
$pk = new UpdateBlockPacket;
|
||||
$pk = UpdateBlockPacket::getFromPool();
|
||||
$pk->x = $block->x;
|
||||
$pk->y = $block->y;
|
||||
$pk->z = $block->z;
|
||||
@ -1738,7 +1739,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$target = $this->level->getBlock($vector);
|
||||
$tile = $this->level->getTile($vector);
|
||||
|
||||
$pk = new UpdateBlockPacket;
|
||||
$pk = UpdateBlockPacket::getFromPool();
|
||||
$pk->x = $target->x;
|
||||
$pk->y = $target->y;
|
||||
$pk->z = $target->z;
|
||||
@ -1887,7 +1888,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
break;
|
||||
}
|
||||
|
||||
$pk = new AnimatePacket();
|
||||
$pk = AnimatePacket::getFromPool();
|
||||
$pk->eid = $this->getID();
|
||||
$pk->action = $ev->getAnimationType();
|
||||
Server::broadcastPacket($this->getViewers(), $pk);
|
||||
@ -1961,7 +1962,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
break;
|
||||
}
|
||||
|
||||
$pk = new EntityEventPacket();
|
||||
$pk = EntityEventPacket::getFromPool();
|
||||
$pk->eid = 0;
|
||||
$pk->event = 9;
|
||||
$this->dataPacket($pk);
|
||||
@ -2247,7 +2248,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$mes = explode("\n", $message);
|
||||
foreach($mes as $m){
|
||||
if($m !== ""){
|
||||
$pk = new MessagePacket;
|
||||
$pk = MessagePacket::getFromPool();
|
||||
$pk->source = ""; //Do not use this ;)
|
||||
$pk->message = $m;
|
||||
$this->dataPacket($pk);
|
||||
@ -2462,7 +2463,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
public function setHealth($amount){
|
||||
parent::setHealth($amount);
|
||||
if($this->spawned === true){
|
||||
$pk = new SetHealthPacket();
|
||||
$pk = SetHealthPacket::getFromPool();
|
||||
$pk->health = $this->getHealth();
|
||||
$this->dataPacket($pk);
|
||||
}
|
||||
@ -2492,7 +2493,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
parent::attack($damage, $source);
|
||||
|
||||
if($this->getLastDamageCause() === $source){
|
||||
$pk = new EntityEventPacket();
|
||||
$pk = EntityEventPacket::getFromPool();
|
||||
$pk->eid = 0;
|
||||
$pk->event = 2;
|
||||
$this->dataPacket($pk);
|
||||
@ -2537,7 +2538,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$this->forceMovement = $pos;
|
||||
$this->newPosition = $pos;
|
||||
|
||||
$pk = new MovePlayerPacket;
|
||||
$pk = MovePlayerPacket::getFromPool();
|
||||
$pk->eid = 0;
|
||||
$pk->x = $this->x;
|
||||
$pk->y = $this->y + $this->getEyeHeight() + 0.01;
|
||||
|
@ -53,7 +53,7 @@ class Bed extends Transparent{
|
||||
$isNight = ($time >= Level::TIME_NIGHT and $time < Level::TIME_SUNRISE);
|
||||
|
||||
if($player instanceof Player and !$isNight){
|
||||
$pk = new ChatPacket;
|
||||
$pk = ChatPacket::getFromPool();
|
||||
$pk->message = "You can only sleep at night";
|
||||
$player->dataPacket($pk);
|
||||
|
||||
@ -77,7 +77,7 @@ class Bed extends Transparent{
|
||||
$b = $blockWest;
|
||||
}else{
|
||||
if($player instanceof Player){
|
||||
$pk = new ChatPacket;
|
||||
$pk = ChatPacket::getFromPool();
|
||||
$pk->message = "This bed is incomplete";
|
||||
$player->dataPacket($pk);
|
||||
}
|
||||
@ -87,7 +87,7 @@ class Bed extends Transparent{
|
||||
}
|
||||
|
||||
if($player instanceof Player and $player->sleepOn($b) === false){
|
||||
$pk = new ChatPacket;
|
||||
$pk = ChatPacket::getFromPool();
|
||||
$pk->message = "This bed is occupied";
|
||||
$player->dataPacket($pk);
|
||||
}
|
||||
|
@ -271,7 +271,7 @@ abstract class Door extends Transparent{
|
||||
if($player instanceof Player){
|
||||
unset($players[$player->getID()]);
|
||||
}
|
||||
$pk = new LevelEventPacket;
|
||||
$pk = LevelEventPacket::getFromPool();
|
||||
$pk->x = $this->x;
|
||||
$pk->y = $this->y;
|
||||
$pk->z = $this->z;
|
||||
@ -290,7 +290,7 @@ abstract class Door extends Transparent{
|
||||
if($player instanceof Player){
|
||||
unset($players[$player->getID()]);
|
||||
}
|
||||
$pk = new LevelEventPacket;
|
||||
$pk = LevelEventPacket::getFromPool();
|
||||
$pk->x = $this->x;
|
||||
$pk->y = $this->y;
|
||||
$pk->z = $this->z;
|
||||
|
@ -209,7 +209,7 @@ class Arrow extends Projectile{
|
||||
}
|
||||
|
||||
public function spawnTo(Player $player){
|
||||
$pk = new AddEntityPacket();
|
||||
$pk = AddEntityPacket::getFromPool();
|
||||
$pk->type = Arrow::NETWORK_ID;
|
||||
$pk->eid = $this->getID();
|
||||
$pk->x = $this->x;
|
||||
@ -218,7 +218,7 @@ class Arrow extends Projectile{
|
||||
$pk->did = 0; //TODO: send motion here
|
||||
$player->dataPacket($pk);
|
||||
|
||||
$pk = new SetEntityMotionPacket();
|
||||
$pk = SetEntityMotionPacket::getFromPool();
|
||||
$pk->entities = [
|
||||
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
|
||||
];
|
||||
|
@ -219,7 +219,7 @@ class DroppedItem extends Entity{
|
||||
}
|
||||
|
||||
public function spawnTo(Player $player){
|
||||
$pk = new AddItemEntityPacket();
|
||||
$pk = AddItemEntityPacket::getFromPool();
|
||||
$pk->eid = $this->getID();
|
||||
$pk->x = $this->x;
|
||||
$pk->y = $this->y;
|
||||
@ -230,7 +230,7 @@ class DroppedItem extends Entity{
|
||||
$pk->item = $this->getItem();
|
||||
$player->dataPacket($pk);
|
||||
|
||||
$pk = new SetEntityMotionPacket;
|
||||
$pk = SetEntityMotionPacket::getFromPool();
|
||||
$pk->entities = [
|
||||
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
|
||||
];
|
||||
|
@ -270,7 +270,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
$player = [$player];
|
||||
}
|
||||
|
||||
$pk = new SetEntityDataPacket();
|
||||
$pk = SetEntityDataPacket::getFromPool();
|
||||
$pk->eid = $this->id;
|
||||
$pk->metadata = $this->getData();
|
||||
$pk->encode();
|
||||
@ -278,7 +278,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
foreach($player as $p){
|
||||
if($p === $this){
|
||||
/** @var Player $p */
|
||||
$pk2 = new SetEntityDataPacket();
|
||||
$pk2 = SetEntityDataPacket::getFromPool();
|
||||
$pk2->eid = 0;
|
||||
$pk2->metadata = $this->getData();
|
||||
$p->dataPacket($pk2);
|
||||
@ -293,7 +293,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
*/
|
||||
public function despawnFrom(Player $player){
|
||||
if(isset($this->hasSpawned[$player->getID()])){
|
||||
$pk = new RemoveEntityPacket;
|
||||
$pk = RemoveEntityPacket::getFromPool();
|
||||
$pk->eid = $this->id;
|
||||
$player->dataPacket($pk);
|
||||
unset($this->hasSpawned[$player->getID()]);
|
||||
@ -532,7 +532,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
$this->lastPitch = $this->pitch;
|
||||
|
||||
if($this instanceof Human){
|
||||
$pk = new MovePlayerPacket;
|
||||
$pk = MovePlayerPacket::getFromPool();
|
||||
$pk->eid = $this->id;
|
||||
$pk->x = $this->x;
|
||||
$pk->y = $this->y;
|
||||
@ -542,7 +542,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
$pk->bodyYaw = $this->yaw;
|
||||
}else{
|
||||
//TODO: add to move list
|
||||
$pk = new MoveEntityPacket();
|
||||
$pk = MoveEntityPacket::getFromPool();
|
||||
$pk->entities = [
|
||||
[$this->id, $this->x, $this->y + $this->getEyeHeight(), $this->z, $this->yaw, $this->pitch]
|
||||
];
|
||||
@ -556,7 +556,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
$this->lastMotionY = $this->motionY;
|
||||
$this->lastMotionZ = $this->motionZ;
|
||||
|
||||
$pk = new SetEntityMotionPacket;
|
||||
$pk = SetEntityMotionPacket::getFromPool();
|
||||
$pk->entities = [
|
||||
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
|
||||
];
|
||||
@ -726,7 +726,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
$this->level->addEntity($this);
|
||||
if($this instanceof Player){
|
||||
$this->usedChunks = [];
|
||||
$pk = new SetTimePacket();
|
||||
$pk = SetTimePacket::getFromPool();
|
||||
$pk->time = $this->level->getTime();
|
||||
$pk->started = $this->level->stopTime == false;
|
||||
$this->dataPacket($pk);
|
||||
@ -1100,7 +1100,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
|
||||
if(!$this->justCreated){
|
||||
if($this instanceof Player){
|
||||
$pk = new SetEntityMotionPacket;
|
||||
$pk = SetEntityMotionPacket::getFromPool();
|
||||
$pk->entities = [
|
||||
[0, $this->motionX, $this->motionY, $this->motionZ]
|
||||
];
|
||||
|
@ -150,7 +150,7 @@ class FallingBlock extends Entity{
|
||||
}
|
||||
|
||||
public function spawnTo(Player $player){
|
||||
$pk = new AddEntityPacket;
|
||||
$pk = AddEntityPacket::getFromPool();
|
||||
$pk->type = FallingBlock::NETWORK_ID;
|
||||
$pk->eid = $this->getID();
|
||||
$pk->x = $this->x;
|
||||
@ -159,7 +159,7 @@ class FallingBlock extends Entity{
|
||||
$pk->did = -$this->getBlock();
|
||||
$player->dataPacket($pk);
|
||||
|
||||
$pk = new SetEntityMotionPacket;
|
||||
$pk = SetEntityMotionPacket::getFromPool();
|
||||
$pk->entities = [
|
||||
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
|
||||
];
|
||||
|
@ -156,7 +156,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
|
||||
if($player !== $this and !isset($this->hasSpawned[$player->getID()])){
|
||||
$this->hasSpawned[$player->getID()] = $player;
|
||||
|
||||
$pk = new AddPlayerPacket;
|
||||
$pk = AddPlayerPacket::getFromPool();
|
||||
$pk->clientID = 0;
|
||||
if($player->getRemoveFormat()){
|
||||
$pk->username = TextFormat::clean($this->nameTag);
|
||||
@ -174,7 +174,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
|
||||
$pk->metadata = $this->getData();
|
||||
$player->dataPacket($pk);
|
||||
|
||||
$pk = new SetEntityMotionPacket;
|
||||
$pk = SetEntityMotionPacket::getFromPool();
|
||||
$pk->entities = [
|
||||
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
|
||||
];
|
||||
@ -188,7 +188,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
|
||||
|
||||
public function despawnFrom(Player $player){
|
||||
if(isset($this->hasSpawned[$player->getID()])){
|
||||
$pk = new RemovePlayerPacket;
|
||||
$pk = RemovePlayerPacket::getFromPool();
|
||||
$pk->eid = $this->id;
|
||||
$pk->clientID = 0;
|
||||
$player->dataPacket($pk);
|
||||
|
@ -76,7 +76,7 @@ abstract class Living extends Entity implements Damageable{
|
||||
}
|
||||
}
|
||||
|
||||
$pk = new EntityEventPacket();
|
||||
$pk = EntityEventPacket::getFromPool();
|
||||
$pk->eid = $this->getID();
|
||||
$pk->event = 2; //Ouch!
|
||||
Server::broadcastPacket($this->hasSpawned, $pk);
|
||||
|
@ -140,7 +140,7 @@ class PrimedTNT extends Entity implements Explosive{
|
||||
}
|
||||
|
||||
public function spawnTo(Player $player){
|
||||
$pk = new AddEntityPacket();
|
||||
$pk = AddEntityPacket::getFromPool();
|
||||
$pk->type = PrimedTNT::NETWORK_ID;
|
||||
$pk->eid = $this->getID();
|
||||
$pk->x = $this->x;
|
||||
@ -149,7 +149,7 @@ class PrimedTNT extends Entity implements Explosive{
|
||||
$pk->did = 0;
|
||||
$player->dataPacket($pk);
|
||||
|
||||
$pk = new SetEntityMotionPacket();
|
||||
$pk = SetEntityMotionPacket::getFromPool();
|
||||
$pk->entities = [
|
||||
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
|
||||
];
|
||||
|
@ -55,7 +55,7 @@ class Villager extends Creature implements NPC, Ageable{
|
||||
}
|
||||
|
||||
public function spawnTo(Player $player){
|
||||
$pk = new AddMobPacket();
|
||||
$pk = AddMobPacket::getFromPool();
|
||||
$pk->eid = $this->getID();
|
||||
$pk->type = Villager::NETWORK_ID;
|
||||
$pk->x = $this->x;
|
||||
@ -66,7 +66,7 @@ class Villager extends Creature implements NPC, Ageable{
|
||||
$pk->metadata = $this->getData();
|
||||
$player->dataPacket($pk);
|
||||
|
||||
$pk = new SetEntityMotionPacket();
|
||||
$pk = SetEntityMotionPacket::getFromPool();
|
||||
$pk->entities = [
|
||||
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
|
||||
];
|
||||
|
@ -46,7 +46,7 @@ class Zombie extends Monster{
|
||||
|
||||
public function spawnTo(Player $player){
|
||||
|
||||
$pk = new AddMobPacket();
|
||||
$pk = AddMobPacket::getFromPool();
|
||||
$pk->eid = $this->getID();
|
||||
$pk->type = Zombie::NETWORK_ID;
|
||||
$pk->x = $this->x;
|
||||
@ -57,7 +57,7 @@ class Zombie extends Monster{
|
||||
$pk->metadata = $this->getData();
|
||||
$player->dataPacket($pk);
|
||||
|
||||
$pk = new SetEntityMotionPacket();
|
||||
$pk = SetEntityMotionPacket::getFromPool();
|
||||
$pk->entities = [
|
||||
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
|
||||
];
|
||||
|
@ -384,7 +384,7 @@ abstract class BaseInventory implements Inventory{
|
||||
$target = [$target];
|
||||
}
|
||||
|
||||
$pk = new ContainerSetContentPacket();
|
||||
$pk = ContainerSetContentPacket::getFromPool();
|
||||
$pk->slots = [];
|
||||
for($i = 0; $i < $this->getSize(); ++$i){
|
||||
$pk->slots[$i] = $this->getItem($i);
|
||||
@ -409,7 +409,7 @@ abstract class BaseInventory implements Inventory{
|
||||
$target = [$target];
|
||||
}
|
||||
|
||||
$pk = new ContainerSetSlotPacket;
|
||||
$pk = ContainerSetSlotPacket::getFromPool();
|
||||
$pk->slot = $index;
|
||||
$pk->item = clone $this->getItem($index);
|
||||
|
||||
|
@ -43,7 +43,7 @@ class ChestInventory extends ContainerInventory{
|
||||
parent::onOpen($who);
|
||||
|
||||
if(count($this->getViewers()) === 1){
|
||||
$pk = new TileEventPacket;
|
||||
$pk = TileEventPacket::getFromPool();
|
||||
$pk->x = $this->getHolder()->getX();
|
||||
$pk->y = $this->getHolder()->getY();
|
||||
$pk->z = $this->getHolder()->getZ();
|
||||
@ -57,7 +57,7 @@ class ChestInventory extends ContainerInventory{
|
||||
|
||||
public function onClose(Player $who){
|
||||
if(count($this->getViewers()) === 1){
|
||||
$pk = new TileEventPacket;
|
||||
$pk = TileEventPacket::getFromPool();
|
||||
$pk->x = $this->getHolder()->getX();
|
||||
$pk->y = $this->getHolder()->getY();
|
||||
$pk->z = $this->getHolder()->getZ();
|
||||
|
@ -29,7 +29,7 @@ use pocketmine\Player;
|
||||
abstract class ContainerInventory extends BaseInventory{
|
||||
public function onOpen(Player $who){
|
||||
parent::onOpen($who);
|
||||
$pk = new ContainerOpenPacket;
|
||||
$pk = ContainerOpenPacket::getFromPool();
|
||||
$pk->windowid = $who->getWindowId($this);
|
||||
$pk->type = $this->getType()->getNetworkType();
|
||||
$pk->slots = $this->getSize();
|
||||
@ -47,7 +47,7 @@ abstract class ContainerInventory extends BaseInventory{
|
||||
}
|
||||
|
||||
public function onClose(Player $who){
|
||||
$pk = new ContainerClosePacket;
|
||||
$pk = ContainerClosePacket::getFromPool();
|
||||
$pk->windowid = $who->getWindowId($this);
|
||||
$who->dataPacket($pk);
|
||||
parent::onClose($who);
|
||||
|
@ -66,7 +66,7 @@ class PlayerInventory extends BaseInventory{
|
||||
$this->itemInHandIndex = $index;
|
||||
$item = $this->getItemInHand();
|
||||
|
||||
$pk = new PlayerEquipmentPacket;
|
||||
$pk = PlayerEquipmentPacket::getFromPool();
|
||||
$pk->eid = $this->getHolder()->getID();
|
||||
$pk->item = $item->getID();
|
||||
$pk->meta = $item->getDamage();
|
||||
@ -126,7 +126,7 @@ class PlayerInventory extends BaseInventory{
|
||||
|
||||
$item = $this->getItemInHand();
|
||||
|
||||
$pk = new PlayerEquipmentPacket;
|
||||
$pk = PlayerEquipmentPacket::getFromPool();
|
||||
$pk->eid = $this->getHolder()->getID();
|
||||
$pk->item = $item->getID();
|
||||
$pk->meta = $item->getDamage();
|
||||
@ -286,7 +286,7 @@ class PlayerInventory extends BaseInventory{
|
||||
}
|
||||
}
|
||||
|
||||
$pk = new PlayerArmorEquipmentPacket;
|
||||
$pk = PlayerArmorEquipmentPacket::getFromPool();
|
||||
$pk->eid = $this->getHolder()->getID();
|
||||
$pk->slots = $slots;
|
||||
$pk->encode();
|
||||
@ -298,7 +298,7 @@ class PlayerInventory extends BaseInventory{
|
||||
//$pk2 = clone $pk;
|
||||
//$pk2->eid = 0;
|
||||
|
||||
$pk2 = new ContainerSetContentPacket;
|
||||
$pk2 = ContainerSetContentPacket::getFromPool();
|
||||
$pk2->windowid = 0x78; //Armor window id constant
|
||||
$pk2->slots = $armor;
|
||||
$player->dataPacket($pk2);
|
||||
@ -333,7 +333,7 @@ class PlayerInventory extends BaseInventory{
|
||||
$target = [$target];
|
||||
}
|
||||
|
||||
$pk = new ContainerSetContentPacket();
|
||||
$pk = ContainerSetContentPacket::getFromPool();
|
||||
$pk->slots = [];
|
||||
for($i = 0; $i < $this->getSize(); ++$i){ //Do not send armor by error here
|
||||
$pk->slots[$i] = $this->getItem($i);
|
||||
@ -365,7 +365,7 @@ class PlayerInventory extends BaseInventory{
|
||||
$target = [$target];
|
||||
}
|
||||
|
||||
$pk = new ContainerSetSlotPacket;
|
||||
$pk = ContainerSetSlotPacket::getFromPool();
|
||||
$pk->slot = $index;
|
||||
$pk->item = clone $this->getItem($index);
|
||||
|
||||
|
@ -217,7 +217,7 @@ class Explosion{
|
||||
$this->level->setBlockIdAt($block->x, $block->y, $block->z, 0);
|
||||
$send[] = new Vector3($block->x - $source->x, $block->y - $source->y, $block->z - $source->z);
|
||||
}
|
||||
$pk = new ExplodePacket;
|
||||
$pk = ExplodePacket::getFromPool();
|
||||
$pk->x = $this->source->x;
|
||||
$pk->y = $this->source->y;
|
||||
$pk->z = $this->source->z;
|
||||
|
@ -442,7 +442,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
* Changes to this function won't be recorded on the version.
|
||||
*/
|
||||
public function sendTime(){
|
||||
$pk = new SetTimePacket;
|
||||
$pk = SetTimePacket::getFromPool();
|
||||
$pk->time = (int) $this->time;
|
||||
$pk->started = $this->stopTime == false;
|
||||
|
||||
@ -539,7 +539,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
foreach($mini as $blocks){
|
||||
/** @var Block $b */
|
||||
foreach($blocks as $b){
|
||||
$pk = new UpdateBlockPacket();
|
||||
$pk = UpdateBlockPacket::getFromPool();
|
||||
$pk->x = $b->x;
|
||||
$pk->y = $b->y;
|
||||
$pk->z = $b->z;
|
||||
@ -949,7 +949,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
}
|
||||
|
||||
//if($direct === true){
|
||||
$pk = new UpdateBlockPacket;
|
||||
$pk = UpdateBlockPacket::getFromPool();
|
||||
$pk->x = $pos->x;
|
||||
$pk->y = $pos->y;
|
||||
$pk->z = $pos->z;
|
||||
|
@ -83,6 +83,8 @@ use raklib\server\ServerInstance;
|
||||
|
||||
class RakLibInterface implements ServerInstance, SourceInterface{
|
||||
|
||||
private $packetPool = [];
|
||||
|
||||
private $server;
|
||||
/** @var Player[] */
|
||||
private $players = [];
|
||||
@ -103,6 +105,9 @@ class RakLibInterface implements ServerInstance, SourceInterface{
|
||||
private $externalThreaded;
|
||||
|
||||
public function __construct(Server $server){
|
||||
|
||||
$this->registerPackets();
|
||||
|
||||
$this->server = $server;
|
||||
$this->identifiers = new \SplObjectStorage();
|
||||
|
||||
@ -115,6 +120,8 @@ class RakLibInterface implements ServerInstance, SourceInterface{
|
||||
}
|
||||
|
||||
public function doTick(){
|
||||
$this->cleanPacketPool();
|
||||
EncapsulatedPacket::cleanPacketPool();
|
||||
$this->interface->sendTick();
|
||||
}
|
||||
|
||||
@ -218,7 +225,7 @@ class RakLibInterface implements ServerInstance, SourceInterface{
|
||||
if(!$packet->isEncoded){
|
||||
$packet->encode();
|
||||
}
|
||||
$pk = new EncapsulatedPacket();
|
||||
$pk = EncapsulatedPacket::getPacketFromPool();
|
||||
$pk->buffer = $packet->buffer;
|
||||
$pk->reliability = 2;
|
||||
if($needACK === true){
|
||||
@ -232,150 +239,87 @@ class RakLibInterface implements ServerInstance, SourceInterface{
|
||||
return null;
|
||||
}
|
||||
|
||||
private function getPacket($buffer){
|
||||
$pid = ord($buffer{0});
|
||||
switch($pid){ //TODO: more efficient selection based on range
|
||||
case ProtocolInfo::LOGIN_PACKET:
|
||||
$data = new LoginPacket();
|
||||
break;
|
||||
case ProtocolInfo::LOGIN_STATUS_PACKET:
|
||||
$data = new LoginStatusPacket();
|
||||
break;
|
||||
case ProtocolInfo::MESSAGE_PACKET:
|
||||
$data = new MessagePacket();
|
||||
break;
|
||||
case ProtocolInfo::SET_TIME_PACKET:
|
||||
$data = new SetTimePacket();
|
||||
break;
|
||||
case ProtocolInfo::START_GAME_PACKET:
|
||||
$data = new StartGamePacket();
|
||||
break;
|
||||
case ProtocolInfo::ADD_MOB_PACKET:
|
||||
$data = new AddMobPacket();
|
||||
break;
|
||||
case ProtocolInfo::ADD_PLAYER_PACKET:
|
||||
$data = new AddPlayerPacket();
|
||||
break;
|
||||
case ProtocolInfo::REMOVE_PLAYER_PACKET:
|
||||
$data = new RemovePlayerPacket();
|
||||
break;
|
||||
case ProtocolInfo::ADD_ENTITY_PACKET:
|
||||
$data = new AddEntityPacket();
|
||||
break;
|
||||
case ProtocolInfo::REMOVE_ENTITY_PACKET:
|
||||
$data = new RemoveEntityPacket();
|
||||
break;
|
||||
case ProtocolInfo::ADD_ITEM_ENTITY_PACKET:
|
||||
$data = new AddItemEntityPacket();
|
||||
break;
|
||||
case ProtocolInfo::TAKE_ITEM_ENTITY_PACKET:
|
||||
$data = new TakeItemEntityPacket();
|
||||
break;
|
||||
case ProtocolInfo::MOVE_ENTITY_PACKET:
|
||||
$data = new MoveEntityPacket();
|
||||
break;
|
||||
case ProtocolInfo::ROTATE_HEAD_PACKET:
|
||||
$data = new RotateHeadPacket();
|
||||
break;
|
||||
case ProtocolInfo::MOVE_PLAYER_PACKET:
|
||||
$data = new MovePlayerPacket();
|
||||
break;
|
||||
case ProtocolInfo::REMOVE_BLOCK_PACKET:
|
||||
$data = new RemoveBlockPacket();
|
||||
break;
|
||||
case ProtocolInfo::UPDATE_BLOCK_PACKET:
|
||||
$data = new UpdateBlockPacket();
|
||||
break;
|
||||
case ProtocolInfo::ADD_PAINTING_PACKET:
|
||||
$data = new AddPaintingPacket();
|
||||
break;
|
||||
case ProtocolInfo::EXPLODE_PACKET:
|
||||
$data = new ExplodePacket();
|
||||
break;
|
||||
case ProtocolInfo::LEVEL_EVENT_PACKET:
|
||||
$data = new LevelEventPacket();
|
||||
break;
|
||||
case ProtocolInfo::TILE_EVENT_PACKET:
|
||||
$data = new TileEventPacket();
|
||||
break;
|
||||
case ProtocolInfo::ENTITY_EVENT_PACKET:
|
||||
$data = new EntityEventPacket();
|
||||
break;
|
||||
case ProtocolInfo::PLAYER_EQUIPMENT_PACKET:
|
||||
$data = new PlayerEquipmentPacket();
|
||||
break;
|
||||
case ProtocolInfo::PLAYER_ARMOR_EQUIPMENT_PACKET:
|
||||
$data = new PlayerArmorEquipmentPacket();
|
||||
break;
|
||||
case ProtocolInfo::INTERACT_PACKET:
|
||||
$data = new InteractPacket();
|
||||
break;
|
||||
case ProtocolInfo::USE_ITEM_PACKET:
|
||||
$data = new UseItemPacket();
|
||||
break;
|
||||
case ProtocolInfo::PLAYER_ACTION_PACKET:
|
||||
$data = new PlayerActionPacket();
|
||||
break;
|
||||
case ProtocolInfo::HURT_ARMOR_PACKET:
|
||||
$data = new HurtArmorPacket();
|
||||
break;
|
||||
case ProtocolInfo::SET_ENTITY_DATA_PACKET:
|
||||
$data = new SetEntityDataPacket();
|
||||
break;
|
||||
case ProtocolInfo::SET_ENTITY_MOTION_PACKET:
|
||||
$data = new SetEntityMotionPacket();
|
||||
break;
|
||||
case ProtocolInfo::SET_HEALTH_PACKET:
|
||||
$data = new SetHealthPacket();
|
||||
break;
|
||||
case ProtocolInfo::SET_SPAWN_POSITION_PACKET:
|
||||
$data = new SetSpawnPositionPacket();
|
||||
break;
|
||||
case ProtocolInfo::ANIMATE_PACKET:
|
||||
$data = new AnimatePacket();
|
||||
break;
|
||||
case ProtocolInfo::RESPAWN_PACKET:
|
||||
$data = new RespawnPacket();
|
||||
break;
|
||||
case ProtocolInfo::SEND_INVENTORY_PACKET:
|
||||
$data = new SendInventoryPacket();
|
||||
break;
|
||||
case ProtocolInfo::DROP_ITEM_PACKET:
|
||||
$data = new DropItemPacket();
|
||||
break;
|
||||
case ProtocolInfo::CONTAINER_OPEN_PACKET:
|
||||
$data = new ContainerOpenPacket();
|
||||
break;
|
||||
case ProtocolInfo::CONTAINER_CLOSE_PACKET:
|
||||
$data = new ContainerClosePacket();
|
||||
break;
|
||||
case ProtocolInfo::CONTAINER_SET_SLOT_PACKET:
|
||||
$data = new ContainerSetSlotPacket();
|
||||
break;
|
||||
case ProtocolInfo::CONTAINER_SET_DATA_PACKET:
|
||||
$data = new ContainerSetDataPacket();
|
||||
break;
|
||||
case ProtocolInfo::CONTAINER_SET_CONTENT_PACKET:
|
||||
$data = new ContainerSetContentPacket();
|
||||
break;
|
||||
case ProtocolInfo::CHAT_PACKET:
|
||||
$data = new ChatPacket();
|
||||
break;
|
||||
case ProtocolInfo::ADVENTURE_SETTINGS_PACKET:
|
||||
$data = new AdventureSettingsPacket();
|
||||
break;
|
||||
case ProtocolInfo::ENTITY_DATA_PACKET:
|
||||
$data = new EntityDataPacket();
|
||||
break;
|
||||
case ProtocolInfo::UNLOAD_CHUNK_PACKET:
|
||||
$data = new UnloadChunkPacket();
|
||||
break;
|
||||
default:
|
||||
$data = new UnknownPacket();
|
||||
$data->packetID = $pid;
|
||||
break;
|
||||
public function registerPacket($id, $class){
|
||||
$this->packetPool[$id] = $class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
*
|
||||
* @return DataPacket
|
||||
*/
|
||||
public function getPacketFromPool($id){
|
||||
if(isset($this->packetPool[$id])){
|
||||
/** @var DataPacket $class */
|
||||
$class = $this->packetPool[$id];
|
||||
return $class::getFromPool();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function cleanPacketPool(){
|
||||
foreach($this->packetPool as $class){
|
||||
/** @var DataPacket $class */
|
||||
$class::cleanPool();
|
||||
}
|
||||
}
|
||||
|
||||
private function registerPackets(){
|
||||
$this->registerPacket(ProtocolInfo::LOGIN_PACKET, LoginPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::LOGIN_STATUS_PACKET, LoginStatusPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::MESSAGE_PACKET, MessagePacket::class);
|
||||
$this->registerPacket(ProtocolInfo::SET_TIME_PACKET, SetTimePacket::class);
|
||||
$this->registerPacket(ProtocolInfo::START_GAME_PACKET, StartGamePacket::class);
|
||||
$this->registerPacket(ProtocolInfo::ADD_MOB_PACKET, AddMobPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::ADD_PLAYER_PACKET, AddPlayerPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::REMOVE_PLAYER_PACKET, RemovePlayerPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::ADD_ENTITY_PACKET, AddEntityPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::REMOVE_ENTITY_PACKET, RemoveEntityPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::ADD_ITEM_ENTITY_PACKET, AddItemEntityPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::TAKE_ITEM_ENTITY_PACKET, TakeItemEntityPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::MOVE_ENTITY_PACKET, MoveEntityPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::ROTATE_HEAD_PACKET, RotateHeadPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::MOVE_PLAYER_PACKET, MovePlayerPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::REMOVE_BLOCK_PACKET, RemoveBlockPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::UPDATE_BLOCK_PACKET, UpdateBlockPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::ADD_PAINTING_PACKET, AddPaintingPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::EXPLODE_PACKET, ExplodePacket::class);
|
||||
$this->registerPacket(ProtocolInfo::LEVEL_EVENT_PACKET, LevelEventPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::TILE_EVENT_PACKET, TileEventPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::ENTITY_EVENT_PACKET, EntityEventPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::PLAYER_EQUIPMENT_PACKET, PlayerEquipmentPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::PLAYER_ARMOR_EQUIPMENT_PACKET, PlayerArmorEquipmentPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::INTERACT_PACKET, InteractPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::USE_ITEM_PACKET, UseItemPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::PLAYER_ACTION_PACKET, PlayerActionPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::HURT_ARMOR_PACKET, HurtArmorPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::SET_ENTITY_DATA_PACKET, SetEntityDataPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::SET_ENTITY_MOTION_PACKET, SetEntityMotionPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::SET_HEALTH_PACKET, SetHealthPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::SET_SPAWN_POSITION_PACKET, SetSpawnPositionPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::ANIMATE_PACKET, AnimatePacket::class);
|
||||
$this->registerPacket(ProtocolInfo::RESPAWN_PACKET, RespawnPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::SEND_INVENTORY_PACKET, SendInventoryPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::DROP_ITEM_PACKET, DropItemPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::CONTAINER_OPEN_PACKET, ContainerOpenPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::CONTAINER_CLOSE_PACKET, ContainerClosePacket::class);
|
||||
$this->registerPacket(ProtocolInfo::CONTAINER_SET_SLOT_PACKET, ContainerSetSlotPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::CONTAINER_SET_DATA_PACKET, ContainerSetDataPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::CONTAINER_SET_CONTENT_PACKET, ContainerSetContentPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::CHAT_PACKET, ChatPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::ADVENTURE_SETTINGS_PACKET, AdventureSettingsPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::ENTITY_DATA_PACKET, EntityDataPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::UNLOAD_CHUNK_PACKET, UnloadChunkPacket::class);
|
||||
}
|
||||
|
||||
private function getPacket($buffer){
|
||||
$pid = ord($buffer{0});
|
||||
|
||||
if(($data = $this->getPacketFromPool($pid)) === null){
|
||||
$data = UnknownPacket::getFromPool();
|
||||
$data->packetID = $pid;
|
||||
}
|
||||
$data->setBuffer(substr($buffer, 1));
|
||||
|
||||
return $data;
|
||||
|
@ -23,6 +23,9 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class AddEntityPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $eid;
|
||||
public $type;
|
||||
public $x;
|
||||
|
@ -23,6 +23,9 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class AddItemEntityPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $eid;
|
||||
public $item;
|
||||
public $x;
|
||||
|
@ -24,6 +24,9 @@ namespace pocketmine\network\protocol;
|
||||
use pocketmine\utils\Binary;
|
||||
|
||||
class AddMobPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $eid;
|
||||
public $type;
|
||||
public $x;
|
||||
|
@ -23,6 +23,9 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class AddPaintingPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $eid;
|
||||
public $x;
|
||||
public $y;
|
||||
|
@ -24,6 +24,9 @@ namespace pocketmine\network\protocol;
|
||||
use pocketmine\utils\Binary;
|
||||
|
||||
class AddPlayerPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $clientID;
|
||||
public $username;
|
||||
public $eid;
|
||||
|
@ -23,6 +23,9 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class AdventureSettingsPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $flags;
|
||||
|
||||
public function pid(){
|
||||
|
@ -23,6 +23,9 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class AnimatePacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $action;
|
||||
public $eid;
|
||||
|
||||
|
@ -23,6 +23,9 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class ChatPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $message;
|
||||
|
||||
public function pid(){
|
||||
|
@ -23,6 +23,9 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class ContainerClosePacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $windowid;
|
||||
|
||||
public function pid(){
|
||||
|
@ -23,6 +23,9 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class ContainerOpenPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $windowid;
|
||||
public $type;
|
||||
public $slots;
|
||||
|
@ -23,6 +23,9 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class ContainerSetContentPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $windowid;
|
||||
public $slots = [];
|
||||
public $hotbar = [];
|
||||
@ -31,6 +34,12 @@ class ContainerSetContentPacket extends DataPacket{
|
||||
return Info::CONTAINER_SET_CONTENT_PACKET;
|
||||
}
|
||||
|
||||
public function clean(){
|
||||
$this->slots = [];
|
||||
$this->hotbar = [];
|
||||
return parent::clean();
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
$this->windowid = $this->getByte();
|
||||
$count = $this->getShort();
|
||||
|
@ -23,6 +23,9 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class ContainerSetDataPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $windowid;
|
||||
public $property;
|
||||
public $value;
|
||||
|
@ -24,6 +24,9 @@ namespace pocketmine\network\protocol;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class ContainerSetSlotPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $windowid;
|
||||
public $slot;
|
||||
/** @var Item */
|
||||
|
@ -25,6 +25,26 @@ use pocketmine\item\Item;
|
||||
use pocketmine\utils\Binary;
|
||||
|
||||
abstract class DataPacket extends \stdClass{
|
||||
|
||||
/** @var DataPacket[] */
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public static function getFromPool(){
|
||||
if(static::$next >= count(static::$pool)){
|
||||
$pk = static::class;
|
||||
static::$pool[] = new $pk;
|
||||
}
|
||||
return static::$pool[static::$next++]->clean();
|
||||
}
|
||||
|
||||
public static function cleanPool(){
|
||||
if(static::$next > 4096){
|
||||
static::$pool = [];
|
||||
}
|
||||
static::$next = 0;
|
||||
}
|
||||
|
||||
private $offset = 0;
|
||||
public $buffer = "";
|
||||
public $isEncoded = false;
|
||||
@ -172,4 +192,11 @@ abstract class DataPacket extends \stdClass{
|
||||
protected function feof(){
|
||||
return !isset($this->buffer{$this->offset});
|
||||
}
|
||||
|
||||
public function clean(){
|
||||
$this->buffer = null;
|
||||
$this->isEncoded = false;
|
||||
$this->offset = 0;
|
||||
return $this;
|
||||
}
|
||||
}
|
@ -23,6 +23,9 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class DropItemPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $eid;
|
||||
public $unknown;
|
||||
public $item;
|
||||
|
@ -23,6 +23,9 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class EntityDataPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $x;
|
||||
public $y;
|
||||
public $z;
|
||||
|
@ -23,6 +23,9 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class EntityEventPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $eid;
|
||||
public $event;
|
||||
|
||||
|
@ -23,16 +23,24 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class ExplodePacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $x;
|
||||
public $y;
|
||||
public $z;
|
||||
public $radius;
|
||||
public $records;
|
||||
public $records = [];
|
||||
|
||||
public function pid(){
|
||||
return Info::EXPLODE_PACKET;
|
||||
}
|
||||
|
||||
public function clean(){
|
||||
$this->records = [];
|
||||
return parent::clean();
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
|
||||
}
|
||||
|
@ -23,6 +23,9 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class FullChunkDataPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $chunkX;
|
||||
public $chunkZ;
|
||||
public $data;
|
||||
|
@ -23,6 +23,9 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class HurtArmorPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $health;
|
||||
|
||||
public function pid(){
|
||||
|
@ -23,6 +23,9 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class InteractPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $action;
|
||||
public $eid;
|
||||
public $target;
|
||||
|
@ -23,6 +23,9 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class LevelEventPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $evid;
|
||||
public $x;
|
||||
public $y;
|
||||
|
@ -23,6 +23,9 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class LoginPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $username;
|
||||
public $protocol1;
|
||||
public $protocol2;
|
||||
|
@ -23,6 +23,9 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class LoginStatusPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $status;
|
||||
|
||||
public function pid(){
|
||||
|
@ -23,6 +23,9 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class MessagePacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $source;
|
||||
public $message;
|
||||
|
||||
|
@ -23,6 +23,9 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class MoveEntityPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
|
||||
// eid, x, y, z, yaw, pitch
|
||||
/** @var array[] */
|
||||
@ -32,6 +35,11 @@ class MoveEntityPacket extends DataPacket{
|
||||
return Info::MOVE_ENTITY_PACKET;
|
||||
}
|
||||
|
||||
public function clean(){
|
||||
$this->entities = [];
|
||||
return parent::clean();
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
|
||||
}
|
||||
|
@ -23,6 +23,9 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class MovePlayerPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $eid;
|
||||
public $x;
|
||||
public $y;
|
||||
@ -36,6 +39,11 @@ class MovePlayerPacket extends DataPacket{
|
||||
return Info::MOVE_PLAYER_PACKET;
|
||||
}
|
||||
|
||||
public function clean(){
|
||||
$this->teleport = false;
|
||||
return parent::clean();
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
$this->eid = $this->getInt();
|
||||
$this->x = $this->getFloat();
|
||||
|
@ -23,6 +23,9 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class PlayerActionPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $action;
|
||||
public $x;
|
||||
public $y;
|
||||
|
@ -23,6 +23,9 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class PlayerArmorEquipmentPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $eid;
|
||||
public $slots = [];
|
||||
|
||||
|
@ -23,6 +23,9 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class PlayerEquipmentPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $eid;
|
||||
public $item;
|
||||
public $meta;
|
||||
|
@ -23,6 +23,9 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class RemoveBlockPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $eid;
|
||||
public $x;
|
||||
public $y;
|
||||
|
@ -23,6 +23,9 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class RemoveEntityPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $eid;
|
||||
|
||||
public function pid(){
|
||||
|
@ -23,6 +23,9 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class RemovePlayerPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $eid;
|
||||
public $clientID;
|
||||
|
||||
|
@ -23,6 +23,9 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class RespawnPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $eid;
|
||||
public $x;
|
||||
public $y;
|
||||
|
@ -23,6 +23,9 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class RotateHeadPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
|
||||
// eid, yaw
|
||||
/** @var array[] */
|
||||
@ -32,6 +35,11 @@ class RotateHeadPacket extends DataPacket{
|
||||
return Info::ROTATE_HEAD_PACKET;
|
||||
}
|
||||
|
||||
public function clean(){
|
||||
$this->entities = [];
|
||||
return parent::clean();
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
|
||||
}
|
||||
|
@ -23,6 +23,9 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class SendInventoryPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $eid;
|
||||
public $windowid;
|
||||
public $slots = [];
|
||||
|
@ -24,6 +24,9 @@ namespace pocketmine\network\protocol;
|
||||
use pocketmine\utils\Binary;
|
||||
|
||||
class SetEntityDataPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $eid;
|
||||
public $metadata;
|
||||
|
||||
|
@ -23,6 +23,9 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class SetEntityMotionPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
|
||||
// eid, motX, motY, motZ
|
||||
/** @var array[] */
|
||||
@ -32,6 +35,11 @@ class SetEntityMotionPacket extends DataPacket{
|
||||
return Info::SET_ENTITY_MOTION_PACKET;
|
||||
}
|
||||
|
||||
public function clean(){
|
||||
$this->entities = [];
|
||||
return parent::clean();
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
|
||||
}
|
||||
|
@ -23,6 +23,9 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class SetHealthPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $health;
|
||||
|
||||
public function pid(){
|
||||
|
@ -23,6 +23,9 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class SetSpawnPositionPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $x;
|
||||
public $z;
|
||||
public $y;
|
||||
|
@ -25,6 +25,9 @@ namespace pocketmine\network\protocol;
|
||||
use pocketmine\level\Level;
|
||||
|
||||
class SetTimePacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $time;
|
||||
public $started = true;
|
||||
|
||||
|
@ -23,6 +23,9 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class StartGamePacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $seed;
|
||||
public $generator;
|
||||
public $gamemode;
|
||||
|
@ -23,6 +23,9 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class TakeItemEntityPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $target;
|
||||
public $eid;
|
||||
|
||||
|
@ -23,6 +23,9 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class TileEventPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $x;
|
||||
public $y;
|
||||
public $z;
|
||||
|
@ -24,6 +24,9 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class UnknownPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $packetID = -1;
|
||||
|
||||
public function pid(){
|
||||
|
@ -23,6 +23,9 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class UnloadChunkPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $chunkX;
|
||||
public $chunkZ;
|
||||
|
||||
|
@ -23,6 +23,9 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class UpdateBlockPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $x;
|
||||
public $z;
|
||||
public $y;
|
||||
|
@ -23,6 +23,9 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class UseItemPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
public $x;
|
||||
public $y;
|
||||
public $z;
|
||||
|
@ -252,13 +252,13 @@ class Furnace extends Tile implements InventoryHolder, Container{
|
||||
foreach($this->getInventory()->getViewers() as $player){
|
||||
$windowId = $player->getWindowId($this->getInventory());
|
||||
if($windowId > 0){
|
||||
$pk = new ContainerSetDataPacket;
|
||||
$pk = ContainerSetDataPacket::getFromPool();
|
||||
$pk->windowid = $windowId;
|
||||
$pk->property = 0; //Smelting
|
||||
$pk->value = floor($this->namedtag["CookTime"]);
|
||||
$player->dataPacket($pk);
|
||||
|
||||
$pk = new ContainerSetDataPacket;
|
||||
$pk = ContainerSetDataPacket::getFromPool();
|
||||
$pk->windowid = $windowId;
|
||||
$pk->property = 1; //Fire icon
|
||||
$pk->value = $this->namedtag["BurnTicks"];
|
||||
|
@ -36,7 +36,7 @@ abstract class Spawnable extends Tile{
|
||||
|
||||
$nbt = new NBT(NBT::LITTLE_ENDIAN);
|
||||
$nbt->setData($this->getSpawnCompound());
|
||||
$pk = new EntityDataPacket;
|
||||
$pk = EntityDataPacket::getFromPool();
|
||||
$pk->x = $this->x;
|
||||
$pk->y = $this->y;
|
||||
$pk->z = $this->z;
|
||||
|
Loading…
x
Reference in New Issue
Block a user