mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 00:07:30 +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\network\mcpe\NetworkSession;
|
||||
use pocketmine\player\Player;
|
||||
use pocketmine\utils\Utils;
|
||||
use function is_a;
|
||||
|
||||
/**
|
||||
@ -96,10 +97,7 @@ class PlayerCreationEvent extends Event{
|
||||
* @phpstan-param class-string<Player> $class
|
||||
*/
|
||||
public function setPlayerClass($class) : void{
|
||||
if(!is_a($class, $this->baseClass, true)){
|
||||
throw new \RuntimeException("Class $class must extend " . $this->baseClass);
|
||||
}
|
||||
|
||||
Utils::testValidInstance($class, $this->baseClass);
|
||||
$this->playerClass = $class;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user