mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-13 13:25:16 +00:00
Use NamedTag::class for default expectedClass in CompoundTag->getTag()
This commit is contained in:
parent
4a0ac01697
commit
1b5746fd97
@ -82,10 +82,10 @@ class CompoundTag extends NamedTag implements \ArrayAccess{
|
|||||||
* @return NamedTag|null
|
* @return NamedTag|null
|
||||||
* @throws \RuntimeException if the tag exists and is not of the expected type (if specified)
|
* @throws \RuntimeException if the tag exists and is not of the expected type (if specified)
|
||||||
*/
|
*/
|
||||||
public function getTag(string $name, ?string $expectedClass = null) : ?NamedTag{
|
public function getTag(string $name, string $expectedClass = NamedTag::class) : ?NamedTag{
|
||||||
assert($expectedClass === null or is_a($expectedClass, NamedTag::class, true));
|
assert(is_a($expectedClass, NamedTag::class, true));
|
||||||
$tag = $this->{$name} ?? null;
|
$tag = $this->{$name} ?? null;
|
||||||
if($tag !== null and $expectedClass !== null and !($tag instanceof $expectedClass)){
|
if($tag !== null and !($tag instanceof $expectedClass)){
|
||||||
throw new \RuntimeException("Expected a tag of type $expectedClass, got " . get_class($tag));
|
throw new \RuntimeException("Expected a tag of type $expectedClass, got " . get_class($tag));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user