mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-08 12:48:32 +00:00
Removed copy-pasted code from Player
This commit is contained in:
parent
9efd350e78
commit
a4ec2b7f2c
@ -1047,43 +1047,13 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends an ordered DataPacket to the send buffer
|
|
||||||
*
|
|
||||||
* @param DataPacket $packet
|
* @param DataPacket $packet
|
||||||
* @param bool $needACK
|
* @param bool $needACK
|
||||||
*
|
*
|
||||||
* @return bool|int
|
* @return bool|int
|
||||||
*/
|
*/
|
||||||
public function dataPacket(DataPacket $packet, bool $needACK = false){
|
public function dataPacket(DataPacket $packet, bool $needACK = false){
|
||||||
if(!$this->connected){
|
return $this->sendDataPacket($packet, $needACK, false);
|
||||||
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();
|
|
||||||
|
|
||||||
$this->server->getPluginManager()->callEvent($ev = new DataPacketSendEvent($this, $packet));
|
|
||||||
if($ev->isCancelled()){
|
|
||||||
$timings->stopTiming();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$identifier = $this->interface->putPacket($this, $packet, $needACK, false);
|
|
||||||
|
|
||||||
if($needACK and $identifier !== null){
|
|
||||||
$this->needACK[$identifier] = false;
|
|
||||||
|
|
||||||
$timings->stopTiming();
|
|
||||||
return $identifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
$timings->stopTiming();
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1093,6 +1063,17 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
* @return bool|int
|
* @return bool|int
|
||||||
*/
|
*/
|
||||||
public function directDataPacket(DataPacket $packet, bool $needACK = false){
|
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->connected === false){
|
if($this->connected === false){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1110,7 +1091,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$identifier = $this->interface->putPacket($this, $packet, $needACK, true);
|
$identifier = $this->interface->putPacket($this, $packet, $needACK, $immediate);
|
||||||
|
|
||||||
if($needACK and $identifier !== null){
|
if($needACK and $identifier !== null){
|
||||||
$this->needACK[$identifier] = false;
|
$this->needACK[$identifier] = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user