Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved Whats wrong?

Comments in 'Plugin Development' started by YanSoo, Sep 14, 2016.

  1. YanSoo
    Offline

    YanSoo New Member

    Joined:
    Apr 28, 2016
    Posts:
    23
    Minecraft User:
    YanSoo
    What is wrong with the following code... I'm learning plugin development and this is me code

    PHP:
    <?php

    namespace yansoo\myplugin;

    use 
    pocketmine\plugin\PluginBase;

    class 
    Main extends PluginBase{


              public function 
    onLoad(){
       
    //When plugin loads
                        
    $this->getLogger()->info("Plugin Loading");
      
    //send message to console.
              
    }
              public function 
    onEnable(){
     
    //when plugin enables
                        
    $this->getLogger()->info("Enabled Plugin");
              }
              public function 
    onDisable(){
    //when plugin disables
                        
    $this->getLogger()->info("Plugin Disabled");
              }
    }
      public function 
    onCommand(CommandSender $senderCommand $command$label, array $args){
        
    $commandName $command->getName();
        if(
    $commandName === "info"){
          
    $sender->sendMessage("Welcome to (Servername) Gamemodes and stuff here");
          return 
    true;
        }
        return 
    false;
      }
  2. YanSoo
    Offline

    YanSoo New Member

    Joined:
    Apr 28, 2016
    Posts:
    23
    Minecraft User:
    YanSoo
    code does not work
  3. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Please tell us how exactly it does not work. Also, can you show your plugin.yml?
  4. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    You have to import \pocketmine\command\CommandSender and \pocketmine\command\CommandSender
  5. YanSoo
    Offline

    YanSoo New Member

    Joined:
    Apr 28, 2016
    Posts:
    23
    Minecraft User:
    YanSoo
    omg lol... I missed one of the biggest parts
  6. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Let me show you something...

    PHP:
    package main

    import 
    (
       
    "fmt"
       "net"
       "os"
       "log"
    )

    func main() {
       
    target := "164.132.137.194:25565"
       
    connerror := net.Dial("tcp"target)
       if(
    error != nil) {
         
    log.Fatal(error)
         
    os.Exit(1)
       }
       
    fmt.Println("Connected!")
       
    data := "\xfe"
       
    fmt.Fprint(conndata)
       
    fmt.Println("Sent " data " to " target)

       
    line := make([]byte1024)
       for 
    nerror := conn.Read(line); len(line) > 0n++ {
         if(
    error != nil) {
           
    log.Fatal(error)
           
    os.Exit(3)
         }

         
    fmt.Println("Response:"string(line[:n]))
       }
    }
    Can anyone tell me why this doesn't work if I just say it doesn't?

    Gamecrafter and Muqsit like this.
  7. YanSoo
    Offline

    YanSoo New Member

    Joined:
    Apr 28, 2016
    Posts:
    23
    Minecraft User:
    YanSoo
    [Server thread/CRITICAL]: ParseError: "syntax error, unexpected 'public' (T_PUBLIC), expecting end of file" (EXCEPTION) in "/My Plugin/src/yansoo/myplugin/MyPlugin" at line 26

    PHP:
    <?php
    namespace yansoo\myplugin;


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


    class 
    MyPlugin extends PluginBase{
              public function 
    onLoad(){
       
    //When plugin loads
                        
    $this->getLogger()->info("Plugin Loading");
      
    //send message to console.
              
    }
              public function 
    onEnable(){
     
    //when plugin enables
                        
    $this->getLogger()->info("Enabled Plugin");
              }
              public function 
    onDisable(){
    //when plugin disables
                        
    $this->getLogger()->info("Plugin Disabled");
              }
    }
      public function 
    onCommand(CommandSender $senderCommand $command$label, array $args){
        
    $commandName $command->getName();
        if(
    $commandName === "info"){
          
    $sender->sendMessage("Welcome to (Servername) Gamemodes and stuff here");
          return 
    true;
        }
        return 
    false;
      } 
  8. YanSoo
    Offline

    YanSoo New Member

    Joined:
    Apr 28, 2016
    Posts:
    23
    Minecraft User:
    YanSoo
    crashes server...
  9. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    You're missing "}"

    Each "{" has to pair up with "}" if it doesn't, it's a syntax error.
    ImagicalGamer likes this.
  10. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    He's not missing one. He closed the one from "class MyPlugin..." after onDisable().
  11. YanSoo
    Offline

    YanSoo New Member

    Joined:
    Apr 28, 2016
    Posts:
    23
    Minecraft User:
    YanSoo
    so problem?
  12. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    You're closing the class before onCommand. You have to close it at the very end.
    Muqsit and Jazzwhistle like this.
  13. YanSoo
    Offline

    YanSoo New Member

    Joined:
    Apr 28, 2016
    Posts:
    23
    Minecraft User:
    YanSoo
    :/ broke my server
    Code:
    <?php
    namespace yansoo\myplugin;
    
    
    use pocketmine\plugin\PluginBase;
    use pocketmine\command\Command;
    use pocketmine\command\ComamndSender;
    
    
    class MyPlugin extends PluginBase{
              public function onLoad(){
       //When plugin loads
                        $this->getLogger()->info("Plugin Loading");
      //send message to console.
              }
              public function onEnable(){
     
    //when plugin enables
                        $this->getLogger()->info("Enabled Plugin");
              }
              public function onDisable(){
    //when plugin disables
                        $this->getLogger()->info("Plugin Disabled");
              }
      public function onCommand(CommandSender $sender, Command $command, $label, array $args){
        $commandName = $command->getName();
        if($commandName === "info"){
          $sender->sendMessage("Welcome to (Servername) Gamemodes and stuff here");
          return true;
        }
        return false;
      } 
    I moved the plugin from the folder and it still says bin/php/php.exe exit:127
  14. Jazzwhistle
    Offline

    Jazzwhistle Notable Member

    Joined:
    Dec 27, 2014
    Posts:
    364
    Minecraft User:
    Awzaw
    What craftyourbucket said... You need to move the function onCommand so it's inside the class.
  15. YanSoo
    Offline

    YanSoo New Member

    Joined:
    Apr 28, 2016
    Posts:
    23
    Minecraft User:
    YanSoo
    ok sooooo this???
    PHP:
    <?php
    namespace yansoo\myplugin;


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


    class 
    MyPlugin extends PluginBase{   public function onCommand(CommandSender $senderCommand $command$label, array $args){
        
    $commandName $command->getName();
        if(
    $commandName === "info"){
          
    $sender->sendMessage("Welcome to (Servername) Gamemodes and stuff here");
          return 
    true;
        }
        return 
    false;
      }
              public function 
    onLoad(){
       
    //When plugin loads
                        
    $this->getLogger()->info("Plugin Loading");
      
    //send message to console.
              
    }
              public function 
    onEnable(){
     
    //when plugin enables
                        
    $this->getLogger()->info("Enabled Plugin");
              }
              public function 
    onDisable(){
    //when plugin disables
                        
    $this->getLogger()->info("Plugin Disabled");
              }
  16. Jazzwhistle
    Offline

    Jazzwhistle Notable Member

    Joined:
    Dec 27, 2014
    Posts:
    364
    Minecraft User:
    Awzaw
    No just take the entire function on command, including function onCommand right up to the lady curly bracket for thady function... And move it to directly after any of the others
  17. Jazzwhistle
    Offline

    Jazzwhistle Notable Member

    Joined:
    Dec 27, 2014
    Posts:
    364
    Minecraft User:
    Awzaw
    Code:
    PHP:
    <?php
    
    namespace yansoo\myplugin;
    
    use pocketmine\plugin\PluginBase;
    
    class Main extends PluginBase{
    
    
    public function onLoad(){
       //When plugin loads
                        $this->getLogger()->info("Plugin Loading");
      //send message to console.
              }
    public function onEnable(){
    //when plugin enables
                        $this->getLogger()->info("Enabled Plugin");
              }
    public function onDisable(){
    //when plugin disables
                        $this->getLogger()->info("Plugin Disabled");
              }
    
    public function onCommand(CommandSender $sender, Command $command, $label, array $args){
        $commandName = $command->getName();
        if($commandName === "info"){
          $sender->sendMessage("Welcome to (Servername) Gamemodes and stuff here");
          return true;
        }
        return false;
      }
    }
    
  18. YanSoo
    Offline

    YanSoo New Member

    Joined:
    Apr 28, 2016
    Posts:
    23
    Minecraft User:
    YanSoo
    thanks I get it now
    Last edited: Sep 15, 2016
  19. YanSoo
    Offline

    YanSoo New Member

    Joined:
    Apr 28, 2016
    Posts:
    23
    Minecraft User:
    YanSoo
    Fatal error: Declaration of yansoo\myplugin\Main::0nCommand(yansoo\myplugin\CommandSender $sender, yansoo\myplugin\Command $command, $label, array $args) must be compatible with pocketmine\command\CommandExecutor::0nCommand(pocketmine\command\CommandSender $sender, pocketmine\command\Command $command, $label, array $args) in C:\Users\Yan\Desktop\My Server - Copy\plugins\My Plugin\src\yansoo\myplugin\MyPlugin.php on line 32
  20. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Import the right classes from PocketMine

Share This Page

Advertisement