Hello, this has worked for me before in another one of my plugins but now it seems to not be. I first tried the following code with an if statement instead of switch but here's what I got. PHP: public function onCommandPreProcess(PlayerCommandPreprocessEvent $event){ $cmd = explode(" ", $event->getMessage()); if(!in_array($event->getPlayer()->getName(), $this->loggedIn)){ switch($cmd[0]){ case "login": case "register": break; default: $event->setCancelled(true); $event->getPlayer()->sendMessage(TextFormat::RED."Please login first."); break; } } } The message "Please login first" is being sent to the player but the event is not cancelling. Anyone know why?
Can you please elaborate on what you mean by "the event is not cancelling"? Is the message being processed as a chat message / command? Can you verify that the priority of your event listener is highest?
I figured it out, but so I don't have to create a new thread, how do you set the priority of the event listener?
Use this PHP: public function onCommandPreProcess(PlayerCommandPreprocessEvent $event){ $cmd = explode(" ", $event->getMessage()); if(!in_array($event->getPlayer()->getName(), $this->loggedIn)){ switch($cmd[0]){ case "login": case "register": break; default: $event->getPlayer()->sendMessage(TextFormat::RED."Please login first."); $event->setCancelled(true); break; } } }
Cancelling an event can be done at any time while the method is running. It does not need to be done last.