1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Answer plugin

Discussion in 'Development' started by SJames, May 18, 2019.

  1. SJames

    SJames Spider Jockey

    Messages:
    35
    GitHub:
    sjamese
    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)
     
  2. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    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 ;).
     
  3. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    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.)
     
    GamakCZ likes this.
  4. SJames

    SJames Spider Jockey

    Messages:
    35
    GitHub:
    sjamese
    Thanks for the ideas guys!
    Can you give an exemple for the array? Thanks
     
    Last edited: May 18, 2019
  5. Diduhless

    Diduhless Baby Zombie

    Messages:
    199
    GitHub:
    Diduhless
    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
     
    Last edited: May 20, 2019
  6. SJames

    SJames Spider Jockey

    Messages:
    35
    GitHub:
    sjamese
    Okay, awesome. Can you send me the code please? Thank you
     
  7. neb16

    neb16 Witch

    Messages:
    71
    GitHub:
    developerneb101
    Hey I have also been looking into this. Can you also dm me the code? It will be much appreciated! Thanks :)
     
  8. Diduhless

    Diduhless Baby Zombie

    Messages:
    199
    GitHub:
    Diduhless
    I'll send it tomorrow
     
  9. SJames

    SJames Spider Jockey

    Messages:
    35
    GitHub:
    sjamese
    Okay, much appreciated!
     
  10. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    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) > && $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
     
    GamakCZ and SJames like this.
  11. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Not in a way OP wants it, this just repeats the last command sent when the player types /r
     
    Kyd likes this.
  12. SJames

    SJames Spider Jockey

    Messages:
    35
    GitHub:
    sjamese
    Well.. can you modify it?
     
  13. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    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
     
    Kyd likes this.
  14. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.