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

I need help in my PLUGIN

Discussion in 'Plugin Help' started by girlx189, Aug 14, 2018.

  1. girlx189

    girlx189 Spider

    Messages:
    10
    I need help in my plugin allert (my message in sendTip)

    I am asking for the code on sendTip my message /allert (mymessage)


    PHP:
    <?php

    namespace Allert;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;

    class 
    Main extends PluginBase{
        
        public function 
    onEnable(){
            
    $this->getLogger()->info("[Allert] On");
        }
        public function 
    onCommand(CommandSender $senderCommand $command$label, array $args){
       if(
    strtolower($command->getName()) === "alert"){
          
    $sender->sendTip("[Allert] $args (mymessage)");
           return 
    true;
       }

    }
    }
     
  2. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    $sender->sendTip($args);
     
  3. girlx189

    girlx189 Spider

    Messages:
    10
    does not display message
     
  4. girlx189

    girlx189 Spider

    Messages:
    10
    does not display message
     
  5. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    add : bool on the function
     
  6. girlx189

    girlx189 Spider

    Messages:
    10
    how?
     
  7. girlx189

    girlx189 Spider

    Messages:
    10
    public function onCommand(CommandSender $sender, Command $command, $label, array $args) bool{
    ?
     
  8. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    PHP:
    public function onCommand(CommandSender $senderCommand $commandstring $label, array $args) : bool{
     
  9. girlx189

    girlx189 Spider

    Messages:
    10
    Error:
    >allert kd
    [Server] [23:50:18] [Server thread/INFO]: An unknown error occurred while attempting to perform this command
    [Server] [23:50:18] [Server thread/CRITICAL]: Unhandled exception executing command 'allert kd' in allert: Call to undefined method pocketmine\command\ConsoleCommandSender::sendTip()
    [Server] [23:50:18] [Server thread/CRITICAL]: Error: "Call to undefined method pocketmine\command\ConsoleCommandSender::sendTip()" (EXCEPTION) in "myzip:///komedadrop.zip#allert/allert/allert/allert/src/alert/Main" at line 16
    PHP:
    <?php

    namespace alert;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;

    class 
    Main extends PluginBase{
        
        public function 
    onEnable(){
            
    $this->getLogger()->info("drop");
        }
        public function 
    onCommand(CommandSender $senderCommand $command$label, array $args) : bool{
       if(
    strtolower($command->getName()) === "allert"){
      
    Line 16     -                $sender->sendTip($args);
       }

    }
    }
     
  10. girlx189

    girlx189 Spider

    Messages:
    10
    help???
     
  11. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    You have to send the Tip to players only. You can't run the command in the console, because Tips can only be displayed to Players.
    Otherwise, it should work. It won't display properly if you have BasicHUD or another plugin that sends Tips very often.
     
  12. girlx189

    girlx189 Spider

    Messages:
    10
    Add code to /allert ksksk
    Title Player: [Allert] ksksk
    /Allert
    Usage /allert message
    Help code!
     
  13. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    You need to check if $sender is an instance of the Player class before sending the tip to make sure the plugin doesn't crash when using from console.

    PHP:
    if (!$sender instanceof Player) {
      
    $sender->sendMessage("Please use this command ingame!");
      return 
    true;
    }
    also make sure to add a use statement for pocketmine\Player so php knows what Class you're meaning with Player.
     
    corytortoise likes this.
  14. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    He does not use the command from the console probably...
     
  15. RyanShaw

    RyanShaw Witch

    Messages:
    69
    Read the error, she is sending it from console.
    @girlx189 If you go in game that command should make the tip pop up on your own screen
    PHP:
    <?php

    namespace alert;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;

    class 
    Main extends PluginBase{
      
        public function 
    onEnable(){
            
    $this->getLogger()->info("drop");
        }
        public function 
    onCommand(CommandSender $senderCommand $commandstring $label, array $args) :bool{
       if(
    strtolower($command->getName()) === "allert"){
       
    $sender->sendTip(implode(" ",$args));
       }
       return 
    true;
       }
    }
    Also you need to implode $args, you cant put an array in a string
     
    Last edited: Aug 15, 2018
    OnTheVerge and corytortoise like this.
  16. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
  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.