I get the following error during startup in my plugin. I believe this has something to do with #962
[12:07:30] [Server thread/CRITICAL]: TypeError: "Argument 1 passed to
pocketmine\utils\Binary::writeByte() must be of the type integer, null given, called in
/root/pmmp/src/pocketmine/nbt/NBT.php on line 279" (EXCEPTION) in "/src/pocketmine/utils/Binary"
at line 133
Using the code below.
public function serializeGUI(){
$gpane = Item::get(Item::GLASS_PANE, 0, 1);
$nbt = new CompoundTag("", []);
$nbt->CosmicAction = new IntTag("CosmicAction", CosmicAction::DUEL_SETTINGS);
$nbt->duelsettings = new IntArrayTag('duelsettings', []);
$nbt->locked = new ByteTag('locked', 1);
$gpane->setNamedTag($nbt);
$gpane->setCustomName(" ");
$s_gapple = Item::get(466, 0, 1);
$nbt = new CompoundTag("", []);
$nbt->CosmicAction = new IntTag("CosmicAction", CosmicAction::DUEL_SETTINGS);
$nbt->duelsettings = new IntArrayTag('duelsettings', [0, 1]);
$nbt->ench = new ListTag('ench', []);
$nbt->locked = new ByteTag('locked', 1);
$s_gapple->setNamedTag($nbt); <--- Line 182
$nbt = $s_gapple->getNamedTag();
$s_gapple->setCustomName($this->itemRefresh($nbt->duelsettings->getValue()));
}
private function itemRefresh(array $duelsettings) : string{
return self::DUELSETTINGS_LEVEL_NAME[$duelsettings[0] !== 0 ? $duelsettings[0] : $duelsettings[1]] ?? "";
}
NICE. So it does a bad job of detecting the type of empty TAG_Lists then. Well done shoghi 馃憦
Could you test the referenced commit please?
okay, np
I confess I'm confused how you encountered this issue though... strict types are not currently enabled on any of the NBT components.
Never mind... I forgot passing null to a type-hinted function raises a type error regardless of whether strict types are enabled or not. The commit causing this issue is https://github.com/pmmp/PocketMine-MP/commit/e4e4ef5f2a5b50ad9dc546b08a1f812da43ca0ef due to a type-hint added to Binary::writeByte()
Tested, the commit fixed it!
Also, @Muqsit ,
$gpane = Item::get(Item::GLASS_PANE, 0,
is unneeded, due to meta and amount already being initialized with 0 and 1
@thebigsmileXD yeah I'm aware of that. It was originally written when I used to use a spoon, and since then I got the habit of writing the 2nd and 3rd parameters even though they have the default value. :P
Most helpful comment
Never mind... I forgot passing null to a type-hinted function raises a type error regardless of whether strict types are enabled or not. The commit causing this issue is https://github.com/pmmp/PocketMine-MP/commit/e4e4ef5f2a5b50ad9dc546b08a1f812da43ca0ef due to a type-hint added to
Binary::writeByte()