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

How do I use public function onCommand() {}

Discussion in 'Facepalm' started by Atomization, Aug 9, 2017.

  1. Atomization

    Atomization Baby Zombie

    Messages:
    120
    GitHub:
    iAtomPlaza
    I have been having trouble with that function cause I'm new to the pocketmine api and could use your help.
    this is what I have done so far:

    public function onCommand(CommandSender $sender, Command $command, $label, array $args){

    switch($command->getName()){

    case "set-welcometitle":
    $this->getConfig()->get("title-message") = $sender->getPlayer()->message();
    return true;
    }
    }

    this just crashes the server.

    the plugin is meant to be a welcome message that sends a title to the player, i want to use that command to update the config with the message. How do I do it
     
    Last edited: Aug 9, 2017
  2. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    how do i know?
    you didnt even give us any logs..
    it's not like the helping users here can hack into other pc just to read the log and help you out
     
  3. Atomization

    Atomization Baby Zombie

    Messages:
    120
    GitHub:
    iAtomPlaza
    I just need to know how to use: onCommand() so the user can set a welcome message, how can that be achieved?
     
  4. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    you do
    get the config and set a value say "welcome-message" and set it to what they player want
    then save the config(important)

    when a player join, you get the welcome message by getting the config
    then you tell the player the welcome message
     
  5. Atomization

    Atomization Baby Zombie

    Messages:
    120
    GitHub:
    iAtomPlaza
    I have done that already, i want to be able to set the message with a command using the public function onCommand() {}
     
  6. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    yeah i did just tell you how, provided you read everything
    also dont expect any code form me
     
  7. Atomization

    Atomization Baby Zombie

    Messages:
    120
    GitHub:
    iAtomPlaza
    I still don't understand it so, can you game me some example code so i can study it? that is how I understand most things.
     
  8. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Is it so hard to look at the source code of other plugins? Is it so hard to look at PMMP's config class?
     
  9. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    actually what you did is good!
    now onjoin just $player->send($this->getConfig()->get("title-message")) then you are done
    also you havent even show us logs
     
  10. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    Yes, its so hard.
     
  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.