I would like to change a command so that when executing the action instead of changing the game mode, the plugin executes a specific command, can anyone help me? if($next == 'creative'){ $gameMode = Server::getGamemodeFromString($next); if($gameMode != -1){ $player->setGamemode($gameMode); } else { if($this->main->cfg->get('debug') == true){ $this->main->getLogger()->warning('Invalid game mode ('.$next.') set in config.yml'); } } } if($next == 'fly'){ $player->setAllowFlight(true);
You would remove the part that sets the gamemode, and instead use PHP: $this->main->getServer()->dispatchCommand(new ConsoleCommandSender(), "command"); If you want the command to be run as the player, replace "new ConsoleCommandSender()" with $player. Otherwise, it will be run through the console. You can replace "command" with any command you want, although it doesn't need a / like if you were running the command in-game. For example, if you want to give Steve a cookie, you could replace "command" with "give Steve cookie 1".
Main could be any object that has a getServer method, but in this case it's most likely a PluginBase. If you use this in your main file (the one extending PluginBase), you can leave out the main-> part and use $this->getServer() directly. I'd recommend to learn the concept of object oriented programming.
@HimbeersaftLP I was just asking because i already Knew the other way thats why i was confused why there was the main-> because i was trying to figure out why you would need that