mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 12:18:46 +00:00
AvailableCommandsPacket: deal with dynamic enums
somehow I missed this, thanks @NiclasOlofsson for pointing it out
This commit is contained in:
parent
986077e03c
commit
0d05dcec08
@ -103,6 +103,13 @@ class AvailableCommandsPacket extends DataPacket{
|
|||||||
*/
|
*/
|
||||||
public $commandData = [];
|
public $commandData = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var CommandEnum[]
|
||||||
|
* List of dynamic command enums, also referred to as "soft" enums. These can by dynamically updated mid-game
|
||||||
|
* without resending this packet.
|
||||||
|
*/
|
||||||
|
public $softEnums = [];
|
||||||
|
|
||||||
protected function decodePayload(){
|
protected function decodePayload(){
|
||||||
for($i = 0, $this->enumValuesCount = $this->getUnsignedVarInt(); $i < $this->enumValuesCount; ++$i){
|
for($i = 0, $this->enumValuesCount = $this->getUnsignedVarInt(); $i < $this->enumValuesCount; ++$i){
|
||||||
$this->enumValues[] = $this->getString();
|
$this->enumValues[] = $this->getString();
|
||||||
@ -119,6 +126,10 @@ class AvailableCommandsPacket extends DataPacket{
|
|||||||
for($i = 0, $count = $this->getUnsignedVarInt(); $i < $count; ++$i){
|
for($i = 0, $count = $this->getUnsignedVarInt(); $i < $count; ++$i){
|
||||||
$this->commandData[] = $this->getCommandData();
|
$this->commandData[] = $this->getCommandData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for($i = 0, $count = $this->getUnsignedVarInt(); $i < $count; ++$i){
|
||||||
|
$this->softEnums[] = $this->getSoftEnum();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getEnum() : CommandEnum{
|
protected function getEnum() : CommandEnum{
|
||||||
@ -133,6 +144,18 @@ class AvailableCommandsPacket extends DataPacket{
|
|||||||
return $retval;
|
return $retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getSoftEnum() : CommandEnum{
|
||||||
|
$retval = new CommandEnum();
|
||||||
|
$retval->enumName = $this->getString();
|
||||||
|
|
||||||
|
for($i = 0, $count = $this->getUnsignedVarInt(); $i < $count; ++$i){
|
||||||
|
//Get the enum value from the initial pile of mess
|
||||||
|
$retval->enumValues[] = $this->getString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $retval;
|
||||||
|
}
|
||||||
|
|
||||||
protected function putEnum(CommandEnum $enum){
|
protected function putEnum(CommandEnum $enum){
|
||||||
$this->putString($enum->enumName);
|
$this->putString($enum->enumName);
|
||||||
|
|
||||||
@ -147,6 +170,15 @@ class AvailableCommandsPacket extends DataPacket{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function putSoftEnum(CommandEnum $enum) : void{
|
||||||
|
$this->putString($enum->enumName);
|
||||||
|
|
||||||
|
$this->putUnsignedVarInt(count($enum->enumValues));
|
||||||
|
foreach($enum->enumValues as $value){
|
||||||
|
$this->putString($value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected function getEnumValueIndex() : int{
|
protected function getEnumValueIndex() : int{
|
||||||
if($this->enumValuesCount < 256){
|
if($this->enumValuesCount < 256){
|
||||||
return $this->getByte();
|
return $this->getByte();
|
||||||
@ -334,6 +366,11 @@ class AvailableCommandsPacket extends DataPacket{
|
|||||||
foreach($this->commandData as $data){
|
foreach($this->commandData as $data){
|
||||||
$this->putCommandData($data);
|
$this->putCommandData($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->putUnsignedVarInt(count($this->softEnums));
|
||||||
|
foreach($this->softEnums as $enum){
|
||||||
|
$this->putSoftEnum($enum);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handle(NetworkSession $session) : bool{
|
public function handle(NetworkSession $session) : bool{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user