mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 16:51:42 +00:00
Reorganise some packet methods in Player
This commit is contained in:
parent
ebcce43131
commit
e4000f8f03
@ -1092,89 +1092,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Batch a Data packet into the channel list to send at the end of the tick
|
||||
*
|
||||
* @param DataPacket $packet
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function batchDataPacket(DataPacket $packet) : bool{
|
||||
if(!$this->isConnected()){
|
||||
return false;
|
||||
}
|
||||
|
||||
$timings = Timings::getSendDataPacketTimings($packet);
|
||||
$timings->startTiming();
|
||||
$this->server->getPluginManager()->callEvent($ev = new DataPacketSendEvent($this, $packet));
|
||||
if($ev->isCancelled()){
|
||||
$timings->stopTiming();
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->batchedPackets[] = clone $packet;
|
||||
$timings->stopTiming();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DataPacket $packet
|
||||
* @param bool $needACK
|
||||
*
|
||||
* @return bool|int
|
||||
*/
|
||||
public function dataPacket(DataPacket $packet, bool $needACK = false){
|
||||
return $this->sendDataPacket($packet, $needACK, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DataPacket $packet
|
||||
* @param bool $needACK
|
||||
*
|
||||
* @return bool|int
|
||||
*/
|
||||
public function directDataPacket(DataPacket $packet, bool $needACK = false){
|
||||
return $this->sendDataPacket($packet, $needACK, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DataPacket $packet
|
||||
* @param bool $needACK
|
||||
* @param bool $immediate
|
||||
*
|
||||
* @return bool|int
|
||||
*/
|
||||
public function sendDataPacket(DataPacket $packet, bool $needACK = false, bool $immediate = false){
|
||||
if(!$this->isConnected()){
|
||||
return false;
|
||||
}
|
||||
|
||||
//Basic safety restriction. TODO: improve this
|
||||
if(!$this->loggedIn and !$packet->canBeSentBeforeLogin()){
|
||||
throw new \InvalidArgumentException("Attempted to send " . get_class($packet) . " to " . $this->getName() . " too early");
|
||||
}
|
||||
|
||||
$timings = Timings::getSendDataPacketTimings($packet);
|
||||
$timings->startTiming();
|
||||
try{
|
||||
$this->server->getPluginManager()->callEvent($ev = new DataPacketSendEvent($this, $packet));
|
||||
if($ev->isCancelled()){
|
||||
return false;
|
||||
}
|
||||
|
||||
$identifier = $this->interface->putPacket($this, $packet, $needACK, $immediate);
|
||||
|
||||
if($needACK and $identifier !== null){
|
||||
$this->needACK[$identifier] = false;
|
||||
return $identifier;
|
||||
}
|
||||
|
||||
return true;
|
||||
}finally{
|
||||
$timings->stopTiming();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Vector3 $pos
|
||||
*
|
||||
@ -3118,6 +3035,89 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Batch a Data packet into the channel list to send at the end of the tick
|
||||
*
|
||||
* @param DataPacket $packet
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function batchDataPacket(DataPacket $packet) : bool{
|
||||
if(!$this->isConnected()){
|
||||
return false;
|
||||
}
|
||||
|
||||
$timings = Timings::getSendDataPacketTimings($packet);
|
||||
$timings->startTiming();
|
||||
$this->server->getPluginManager()->callEvent($ev = new DataPacketSendEvent($this, $packet));
|
||||
if($ev->isCancelled()){
|
||||
$timings->stopTiming();
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->batchedPackets[] = clone $packet;
|
||||
$timings->stopTiming();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DataPacket $packet
|
||||
* @param bool $needACK
|
||||
* @param bool $immediate
|
||||
*
|
||||
* @return bool|int
|
||||
*/
|
||||
public function sendDataPacket(DataPacket $packet, bool $needACK = false, bool $immediate = false){
|
||||
if(!$this->isConnected()){
|
||||
return false;
|
||||
}
|
||||
|
||||
//Basic safety restriction. TODO: improve this
|
||||
if(!$this->loggedIn and !$packet->canBeSentBeforeLogin()){
|
||||
throw new \InvalidArgumentException("Attempted to send " . get_class($packet) . " to " . $this->getName() . " too early");
|
||||
}
|
||||
|
||||
$timings = Timings::getSendDataPacketTimings($packet);
|
||||
$timings->startTiming();
|
||||
try{
|
||||
$this->server->getPluginManager()->callEvent($ev = new DataPacketSendEvent($this, $packet));
|
||||
if($ev->isCancelled()){
|
||||
return false;
|
||||
}
|
||||
|
||||
$identifier = $this->interface->putPacket($this, $packet, $needACK, $immediate);
|
||||
|
||||
if($needACK and $identifier !== null){
|
||||
$this->needACK[$identifier] = false;
|
||||
return $identifier;
|
||||
}
|
||||
|
||||
return true;
|
||||
}finally{
|
||||
$timings->stopTiming();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DataPacket $packet
|
||||
* @param bool $needACK
|
||||
*
|
||||
* @return bool|int
|
||||
*/
|
||||
public function dataPacket(DataPacket $packet, bool $needACK = false){
|
||||
return $this->sendDataPacket($packet, $needACK, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DataPacket $packet
|
||||
* @param bool $needACK
|
||||
*
|
||||
* @return bool|int
|
||||
*/
|
||||
public function directDataPacket(DataPacket $packet, bool $needACK = false){
|
||||
return $this->sendDataPacket($packet, $needACK, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transfers a player to another server.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user