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

Command not with /

Discussion in 'Development' started by Palente, Mar 3, 2017.

  1. Palente

    Palente Slime

    Messages:
    75
    GitHub:
    palente
    Hey,
    I want to do command with a ! because i think this is more cool as /.
    Now How to see if player has do the good command
    The command is like that
    !ban {player}.
    I know use PlayerChatevent.
    and i know how to get the message but how to know if player has do the correct usage?
    thanks!
    And sorry i'm french
     
  2. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    You could get the message from PlayerChatEvent, and use $args = explode(" ", $message); Be careful with $args[0], because $args[0] would be the actual command, not the first argument. To check if the first symbol is the one you want it to be, use: if($message[0] === "!") { }
    I hope that helps.
     
  3. Palente

    Palente Slime

    Messages:
    75
    GitHub:
    palente
    Okay,
    $message[0] you mean $args[0]?
    because i have see the function explode
    And they just coold be $args[0]
    But $args[0] can't contain only ! because you said explode " "
    So $args[0] contain "!ban" and $args[1] contain the name.
    I think you mean that if i'm false Tell me please
     
  4. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    PHP:
    /** @var PlayerCommandPreprocessEvent $event */
    $message $event->getMessage();
    if(
    $message[0] === "!"){
        
    $expl explode(" "$message);
        
    $command substr($expl[0], 1);
        
    $expl[0] = "/".$command;
        
    $event->setMessage(implode(" "$expl));
    }
     
  5. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    PHP:
    public function specialCommand (PlayerCommandPreprocessEvent $event) {
        
    $message $event->getMessage();
        if(
    $message[0] == "!") {
            
    $msgParts explode(" "$message); //separate the message by the spaces
            
    $command substr($msgParts[0], 1); //extract command
            
    $msgParts[0] = "/".$command//change the ! into a /
            
    $event->setMessage(implode(" "$msgParts)); //set message to be a proper command for processing
        
    }
    }
     
  6. Jack Noordhuis

    Jack Noordhuis Zombie Pigman Poggit Reviewer

    Messages:
    618
    GitHub:
    JackNoordhuis
    Without using the hacky string as an array and risk throwing errors method:
    PHP:
    public function onPlayerCommandPreprocess(pocketmine\event\player\PlayerCommandPreprocessEvent $event) {
        
    $message $event->getMessage();
        if(
    substr($message01) === "!") {
            
    $message trim($message"!");
            
    $event->setMessage("/" $message);
        }
    }
     
  7. kaliiks

    kaliiks Zombie

    Messages:
    250
    there is a problem if player has changed default command it get original args if

    if I am right
     
  8. Jack Noordhuis

    Jack Noordhuis Zombie Pigman Poggit Reviewer

    Messages:
    618
    GitHub:
    JackNoordhuis
    English?

    The command hasn't been processed yet, hence the event name being 'player command preprocess event'.
     
  9. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Note: These will cause the loss of client prediction (and usage display when PocketMine supports them in API 3.0.0) of commands. Only commands starting with / can be understood by MCPE as commands. Commands not starting with / will cause worse player experience and inconvenience.
     
  10. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Also, please, be independent. Don't use ! commands just because other people do it too -- it's not a symbol of being special; it's a symbol of following the trends passively. Be yourself! This is nothing cool at all if everyone does this.
     
  11. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    :facepalm:
    That's sort of hypocritical because you are saying for everyone to be like each other and use the default /
     
  12. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Maybe you are right, but at least it's more sensible to use the slash than blindly following the trend of using the other symbols, which will only make user experience worse, especially for people who don't know how to do that but just "I wan tis too cuz they have it on their server nd their cool cummon steel the plugon for meee". There isn't even a valid reason to introduce such change.
     
  13. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    On the other hand, of course it's reasonable if you want to reroute command starting with the fullwidth (Unicode) form of slash:
    Code:
     
    Muqsit likes this.
  14. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Yep, it's the same with custom enchants, one server has them and now everyone wants that, even tough it's so useless....
     
  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.