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

[HELP] Errors again n again!

Comments in 'Plugin Development' started by Primus, Apr 8, 2015.

  1. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Tell me what's wrong in it?

    PHP:
    <?php

    namespace PrimusLV\LTest;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\player\Player;
    use 
    pocketmine\server\Server;
    use 
    pocketmine\command\Command;

    class 
    Main extends PluginBase{

        public function 
    onEnable(){
            
    $this->getLogger()->info("Activated");
        }

        public function 
    onDisable(){
            
    $this->getLogger()->info("Deactivated");
        }
    public function 
    onCommand(CommandSender $senderCommand $command$label, array $args){
        if(
    strtolower($command->getName()) === "test"){
            
    $onlinePlayers $this->getServer()->getOnlinePlayers();
            
    $playerNo count($this->getServer()->getOnlinePlayers());
            
    $maxPlayers $this->getServer()->getMaxPlayers(); 
            
    $sender->sendMessage("Currently playing:"$onlinePlayers."/"$maxPlayers ." ");
            return 
    true;
        }

        return 
    false;
    }
    I got this error all the time? i can't get how to create command work >_<!

    Parse error: syntax error, unexpected 'return' (T_RETURN) in C:\PocketMine-MP\plugins\Heal\src\PrimusLV\LTest\Main.php on line 25

    Call Stack:
    0.0156 340224 1. {main}() C:\PocketMine-MP\PocketMine-MP.phar:0
    0.0156 334872 2. require('phar://C:/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/PocketMine.php') C:\PocketMine-MP\PocketMine-MP.phar:1
    0.2652 452064 3. pocketmine\Server->__construct() phar://C:/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/PocketMine.php:442
    1.3300 10636232 4. pocketmine\Server->enablePlugins() phar://C:/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/Server.php:1628
    1.3300 10636304 5. pocketmine\Server->enablePlugin() phar://C:/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/Server.php:1771
    1.3300 10636400 6. pocketmine\plugin\PluginManager->enablePlugin() phar://C:/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/Server.php:1785
    1.3300 10638048 7. pocketmine\plugin\PharPluginLoader->enablePlugin() phar://C:/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/plugin/PluginManager.php:559
    1.3300 10638112 8. pocketmine\plugin\PluginBase->setEnabled() phar://C:/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/plugin/PharPluginLoader.php:123
    1.3300 10638192 9. DevTools\DevTools->onEnable() phar://C:/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/plugin/PluginBase.php:86
    1.3300 10641536 10. pocketmine\plugin\PluginManager->loadPlugins() phar://C:/PocketMine-MP/plugins/DevTools_v1.10.0.phar/src/DevTools/DevTools.php:45
    1.3300 10645728 11. pocketmine\plugin\PluginManager->loadPlugin() phar://C:/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/plugin/PluginManager.php:296
    1.3300 10648544 12. FolderPluginLoader\FolderPluginLoader->loadPlugin() phar://C:/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/plugin/PluginManager.php:152
    1.3300 10651152 13. class_exists() phar://C:/PocketMine-MP/plugins/DevTools_v1.10.0.phar/src/FolderPluginLoader/FolderPluginLoader.php:64
    1.3300 10651328 14. spl_autoload_call() phar://C:/PocketMine-MP/plugins/DevTools_v1.10.0.phar/src/FolderPluginLoader/FolderPluginLoader.php:64
    1.3300 10651360 15. BaseClassLoader->loadClass() phar://C:/PocketMine-MP/plugins/DevTools_v1.10.0.phar/src/FolderPluginLoader/FolderPluginLoader.php:64


    Sorry i'm begginer :D
  2. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    Um... you need one more } at the end, it'll look like this:
    PHP:
    <?php

    namespace PrimusLV\LTest;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\player\Player;
    use 
    pocketmine\server\Server;
    use 
    pocketmine\command\Command;

    class 
    Main extends PluginBase{

        public function 
    onEnable(){
            
    $this->getLogger()->info("Activated");
        }

        public function 
    onDisable(){
            
    $this->getLogger()->info("Deactivated");
        }
    public function 
    onCommand(CommandSender $senderCommand $command$label, array $args){
        if(
    strtolower($command->getName()) === "test"){
            
    $onlinePlayers $this->getServer()->getOnlinePlayers(); # array
            
    $playerN count($this->getServer()->getOnlinePlayers()); # (integer)
            
    $maxPlayers $this->getServer()->getMaxPlayers(); # (integer)
            
    $sender->sendMessage("Currently playing: "$playerN."/"$maxPlayers ." ");
            return 
    true;
        }

        return 
    false;
      }

    #one more here!
    Last edited: May 6, 2016
    Primus likes this.
  3. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    But it's saying that i have unexpected "return"
  4. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Ok ill try to install it now!
  5. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Off topic :D
    Is this right?
    PHP:
    if($this->($sender instanceof player)){
    }
    HotFireyDeath likes this.
  6. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    Exactly, this is because the end of file you would need an extra }.
    Primus and EvolSoft like this.
  7. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    You forgot the class close bracket ("}") ;)
    Primus and HotFireyDeath like this.
  8. Exxarion
    Offline

    Exxarion Active Member Plugin Developer

    Joined:
    Jan 5, 2014
    Posts:
    242
    Plugins:
    1
    Minecraft User:
    Notch
    When it says 'unexpected' something, you forgot to close something. Usually you need to add an extra "}"

    (Sometimes you need to add a ";", but that is a different story ;))
    Primus and HotFireyDeath like this.
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I think you meant to use $playerNo."/"... not $onlinePlayers."/"...
    Primus and HotFireyDeath like this.
  10. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Sorry for bumping an old thread but I wanted to show how helpful this community were.
    Thank you

Share This Page

Advertisement