Hello! I wanna develop a plugin that introduces the /r command. So, when someone messages you, you type /r <text> without typing any name and the plugin sends the message to the other person. I would need some ideas how to do this... My initial idea is: When a player messages an other player I would save the name of the sender and the receiver in a separate file and every time someone types /r, the plugin would check that file. If his name is there the plugin would send the message to the other person, else a error will be sended to the sender..(sorry for my bad english)
You needn't save it to the files, just save it to public $players = []; You can check if player sent message through PlayerCommandPreprocessEvent. However you idea may work .
I/O might cause a bit of a slowdown with the response time. (not too bad but using a variable with an array is better.)
I've already developed this in my own plugin, I'll send you the code asap Also I'd rather making a new class for each player with a global variable instead of making an array There's no need of any file btw
Hey I have also been looking into this. Can you also dm me the code? It will be much appreciated! Thanks
PHP: public $lastCommands = array();public function onPlayerCommandPreprocess(\pocketmine\event\player\PlayerCommandPreprocessEvent $event) : void{ $args = explode(" ", $event->getMessage()); $command = array_shift($args); $player = $event->getPlayer(); if(strlen($command) > 1 && $command[0] == "/" && $command !== "/r"){ $this->lastCommands[$player->getRawUniqueId()] = ltrim($command, '/') . " " . implode(" ", $args); }}//when /r is executed$lastCommand = $this->lastCommands[$player->getRawUniqueId()];if(is_null($lastCommand)){ //no command return;}\pocketmine\Server::getInstance()->distpatchCommand($commandSender, $lastCommand); this may work
lmfao why didn't you just register a command?? using the preprocess event does the same thing but the client will attempt to block it it it isn't registered. Also, they're not looking for code to run the last command. they want to send a message of their choice to the last person who messaged them using /tell or /msg
I have a published plugin on poggit for /r. You can take a look at the code here https://github.com/jasonwynn10/SimpleReplies/blob/master/src/jasonwynn10/SimpleReplies/Main.php