mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 17:59:48 +00:00
New TextPacket, second part!
This commit is contained in:
@ -32,7 +32,6 @@ use pocketmine\network\protocol\AddPaintingPacket;
|
||||
use pocketmine\network\protocol\AddPlayerPacket;
|
||||
use pocketmine\network\protocol\AdventureSettingsPacket;
|
||||
use pocketmine\network\protocol\AnimatePacket;
|
||||
use pocketmine\network\protocol\ChatPacket;
|
||||
use pocketmine\network\protocol\ContainerClosePacket;
|
||||
use pocketmine\network\protocol\ContainerOpenPacket;
|
||||
use pocketmine\network\protocol\ContainerSetContentPacket;
|
||||
@ -50,7 +49,7 @@ use pocketmine\network\protocol\LevelEventPacket;
|
||||
use pocketmine\network\protocol\DisconnectPacket;
|
||||
use pocketmine\network\protocol\LoginPacket;
|
||||
use pocketmine\network\protocol\PlayStatusPacket;
|
||||
use pocketmine\network\protocol\MessagePacket;
|
||||
use pocketmine\network\protocol\TextPacket;
|
||||
use pocketmine\network\protocol\MoveEntityPacket;
|
||||
use pocketmine\network\protocol\MovePlayerPacket;
|
||||
use pocketmine\network\protocol\PlayerActionPacket;
|
||||
@ -302,7 +301,7 @@ class RakLibInterface implements ServerInstance, SourceInterface{
|
||||
$this->registerPacket(ProtocolInfo::LOGIN_PACKET, LoginPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::PLAY_STATUS_PACKET, PlayStatusPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::DISCONNECT_PACKET, DisconnectPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::MESSAGE_PACKET, MessagePacket::class);
|
||||
$this->registerPacket(ProtocolInfo::TEXT_PACKET, TextPacket::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);
|
||||
@ -340,7 +339,6 @@ class RakLibInterface implements ServerInstance, SourceInterface{
|
||||
$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::TILE_ENTITY_DATA_PACKET, TileEntityDataPacket::class);
|
||||
$this->registerPacket(ProtocolInfo::SET_DIFFICULTY_PACKET, SetDifficultyPacket::class);
|
||||
|
@ -28,6 +28,10 @@ class TextPacket extends DataPacket{
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
const TYPE_RAW = 0;
|
||||
const TYPE_CHAT = 1;
|
||||
const TYPE_TRANSLATION = 2;
|
||||
|
||||
public $type;
|
||||
public $source;
|
||||
public $message;
|
||||
@ -39,15 +43,39 @@ class TextPacket extends DataPacket{
|
||||
|
||||
public function decode(){
|
||||
$this->type = $this->getByte();
|
||||
$this->source = $this->getString();
|
||||
$this->message = $this->getString();
|
||||
switch($this->type){
|
||||
case self::TYPE_CHAT:
|
||||
$this->source = $this->getString();
|
||||
case self::TYPE_RAW:
|
||||
$this->message = $this->getString();
|
||||
break;
|
||||
|
||||
case self::TYPE_TRANSLATION:
|
||||
$this->message = $this->getString();
|
||||
$count = $this->getByte();
|
||||
for($i = 0; $i < $count; ++$count){
|
||||
$this->parameters[] = $this->getString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putByte($this->type);
|
||||
$this->putString($this->source);
|
||||
$this->putString($this->message);
|
||||
switch($this->type){
|
||||
case self::TYPE_CHAT:
|
||||
$this->putString($this->source);
|
||||
case self::TYPE_RAW:
|
||||
$this->putString($this->message);
|
||||
break;
|
||||
|
||||
case self::TYPE_TRANSLATION:
|
||||
$this->putString($this->message);
|
||||
$this->putByte(count($this->parameters));
|
||||
foreach($this->parameters as $p){
|
||||
$this->putString($p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user