mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-13 09:19:42 +00:00
New TextPacket, second part!
This commit is contained in:
parent
2c59983672
commit
62ba36b474
@ -95,7 +95,7 @@ use pocketmine\network\protocol\EntityEventPacket;
|
||||
use pocketmine\network\protocol\FullChunkDataPacket;
|
||||
use pocketmine\network\protocol\Info as ProtocolInfo;
|
||||
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\SetDifficultyPacket;
|
||||
@ -2400,14 +2400,29 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$mes = explode("\n", $message);
|
||||
foreach($mes as $m){
|
||||
if($m !== ""){
|
||||
$pk = new MessagePacket();
|
||||
$pk->source = ""; //Do not use this ;)
|
||||
$pk = new TextPacket();
|
||||
$pk->type = TextPacket::TYPE_RAW;
|
||||
$pk->message = $m;
|
||||
$this->dataPacket($pk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function sendTranslation($message, array $parameters = []){
|
||||
if($this->removeFormat !== false){
|
||||
$message = TextFormat::clean($message);
|
||||
foreach($parameters as $k => $v){
|
||||
$parameters[$k] = TextFormat::clean($v);
|
||||
}
|
||||
}
|
||||
|
||||
$pk = new TextPacket();
|
||||
$pk->type = TextPacket::TYPE_TRANSLATION;
|
||||
$pk->message = $message;
|
||||
$pk->parameters = $parameters;
|
||||
$this->dataPacket($pk);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $message Message to be broadcasted
|
||||
* @param string $reason Reason showed in console
|
||||
|
@ -24,8 +24,8 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\level\Level;
|
||||
use pocketmine\math\AxisAlignedBB;
|
||||
use pocketmine\network\protocol\ChatPacket;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\utils\TextFormat;
|
||||
|
||||
class Bed extends Transparent{
|
||||
|
||||
@ -65,10 +65,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->message = "You can only sleep at night";
|
||||
$player->dataPacket($pk);
|
||||
|
||||
$player->sendMessage(TextFormat::GRAY . "You can only sleep at night");
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -89,9 +86,7 @@ class Bed extends Transparent{
|
||||
$b = $blockWest;
|
||||
}else{
|
||||
if($player instanceof Player){
|
||||
$pk = new ChatPacket();
|
||||
$pk->message = "This bed is incomplete";
|
||||
$player->dataPacket($pk);
|
||||
$player->sendMessage(TextFormat::GRAY . "This bed is incomplete");
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -99,9 +94,7 @@ class Bed extends Transparent{
|
||||
}
|
||||
|
||||
if($player instanceof Player and $player->sleepOn($b) === false){
|
||||
$pk = new ChatPacket();
|
||||
$pk->message = "This bed is occupied";
|
||||
$player->dataPacket($pk);
|
||||
$player->sendMessage(TextFormat::GRAY . "This bed is occupied");
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user