Hi, I'm having trouble hooking into PlayerGameModeChangeEvent to cancel it, but can't find any API 2.0.0 examples of how to use it. The source code says that it returns a player object and gamemode int, and no event - which is what I'm trying to cancel :-/ I've tried this (adapted from some code I found), and variations with only the 2 arguments for player/newgamemode, and using $player instead of $c->getPlayer... but it doesn't get called whatever I try, even though all other listeners are working fine. PHP: public function onGameModeChange(PlayerKickEvent $k, Player $player, PlayerGameModeChangeEvent $c, Permission $permission, NewGameMode $newGamemode) { if (isset($this->sessions[$c->$player->getName()])) { $c->setCancelled(true); $c->getPlayer->setGamemode(0); $c->getPlayer->sendMessage($this->getMessage("no-cheat")); } } Thanks
PHP: use pocketmine\event\player\PlayerGameModeChangeEvent; public function onPlayerGameModeChangeEvent(PlayerGameModeChangeEvent $event){ $event->setCancelled(true); $event->getPlayer()->sendMessage("no-no!"); } however, this code will cancell ALL gamemode changes. even from the console. You have to add more checks in the code
Thank you very much, I'll try that now. @MCPEPIG I'm writing a parkour plugin, and need to prevent players from switching gamemode (or having a friend change gamemode for them etc)
It all seems like a great idea. Good luck with that. Just pointing put ( just in case anyone is unaware ) Within the SERVER.PROPERTIES there is a part saying Code: force-gamemode= Make that "on" for it to PUBLICALLY force the gamemode to what ever you set the Code: gamemode= (0/1/2/3) to. Just a helpful hint just incase thats what anyone needs