mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-11 04:17:48 +00:00
PlayerCreationEvent: verify that the class actually exists and is instantiable
this ensures that crashdumps blame the plugin instead of the core on bad classes, such as in this case: https://crash.pmmp.io/view/5331225
This commit is contained in:
parent
2971bf30a5
commit
a4b65d6a3f
@ -26,6 +26,7 @@ namespace pocketmine\event\player;
|
|||||||
use pocketmine\event\Event;
|
use pocketmine\event\Event;
|
||||||
use pocketmine\network\mcpe\NetworkSession;
|
use pocketmine\network\mcpe\NetworkSession;
|
||||||
use pocketmine\player\Player;
|
use pocketmine\player\Player;
|
||||||
|
use pocketmine\utils\Utils;
|
||||||
use function is_a;
|
use function is_a;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -96,10 +97,7 @@ class PlayerCreationEvent extends Event{
|
|||||||
* @phpstan-param class-string<Player> $class
|
* @phpstan-param class-string<Player> $class
|
||||||
*/
|
*/
|
||||||
public function setPlayerClass($class) : void{
|
public function setPlayerClass($class) : void{
|
||||||
if(!is_a($class, $this->baseClass, true)){
|
Utils::testValidInstance($class, $this->baseClass);
|
||||||
throw new \RuntimeException("Class $class must extend " . $this->baseClass);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->playerClass = $class;
|
$this->playerClass = $class;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user