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

Only getting usage

Comments in 'Plugin Development' started by Artide, Sep 5, 2015.

  1. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    I just made a small plugin but when I run the commands all it does is show the usage.

    PHP:
    public function onCmd(Command $cmdCommandSender $sender$label, array $args){

                switch(
    strtolower($cmd->getName())) {

                    case 
    'sethealth':

                        if(
    $sender->hasPermission("hm.sethealth")) {

                            
    $player $this->getServer()->getPlayerExact($args[0]);

                            if (
    is_numeric($args[1])) $player->setHealth($args[1]);

                            
    $sender->sendMessage(TXT::GREEN $player->getName() . "'s health set to " TXT::RED $args[1]);

                            if (!
    is_numeric($args[1])) $sender->sendMessage(TXT::RED "Invalid number.");

                            if (empty(
    $args[1]) || empty($args[0])) $sender->sendMessage(TXT::RED "Usage: /sethealth <player> <health>");

                            if (
    $player === null$sender->sendMessage(TXT::RED $player->getName() . " is offline.");

                        }

                        return 
    true;
                        break;

                    case 
    'savehealth':

                        if(
    $sender->hasPermission("hm.savehealth")) {

                            
    $player $this->getServer()->getPlayerExact($args[0]);

                            if (
    is_numeric($args[1])) $player->setHealth($args[1]);

                            
    $health = new Config($this->getDataFolder() . "players/" strtolower($player->getName()) . ".yml"Config::YAML);

                            if (
    $health->exists("Health")) {

                                
    $health->set("Health"$args[0]);
                                
    $health->save();

                                
    $sender->sendMessage(TXT::GREEN $player->getName() . "'s health saved. When they join\n they will have the same health you set it to.");

                                return 
    true;

                            }

                            if (!
    is_numeric($args[1])) $sender->sendMessage(TXT::RED "Invalid number.");

                            if (empty(
    $args[1]) || empty($args[0])) $sender->sendMessage(TXT::RED "Usage: /savehealth <player> <health>");

                            return 
    true;
                            break;

                        }

                    case 
    'randhealth':

                        if(
    $sender->hasPermission("hm.randhealth")) {

                            
    $player $this->getServer()->getPlayerExact($args[0]);

                            if (
    is_numeric($args[1]) && is_numeric($args[2]) && $args[1] < $args[2]) {

                                
    $rand $args[1];
                                
    $rand2 $args[2];
                                
    $result mt_rand($rand$rand2);

                                
    $player->setHealth($result);

                                
    $sender->sendMessage(TXT::GREEN $player->getName() . "'s health set to " $result);

                                return 
    true;

                            } elseif (
    $args[1] > $args[2]) {

                                
    $sender->sendMessage(TXT::RED "First number can't be bigger than second number.");
                                return 
    true;

                            }

                            if (!
    is_numeric($args[1])) $sender->sendMessage(TXT::RED "Invalid number.");

                            if (empty(
    $args[1]) || empty($args[0])) $sender->sendMessage(TXT::RED "Usage: /randhealth <player> <health> <health>");

                            if (
    $player === null$sender->sendMessage(TXT::RED $player->getName() . " is offline.");

                            return 
    true;
                            break;

                        }

                    case 
    'gethealth':

                        if(
    $sender->hasPermission("hm.gethealth")){

                            
    $player $this->getServer()->getPlayerExact($args[0]);

                            
    $phealth $player->getHealth();

                            
    $sender->sendMessage(TXT::GREEN $player->getName() . "'s health is " $phealth);

                            if(empty(
    $args[0])) $sender->sendMessage(TXT::RED "Usage: /gethealth <player>");

                            if (
    $player === null$sender->sendMessage(TXT::RED $player->getName() . " is offline.");

                            return 
    true;
                            break;

                        }

                }

        }
  2. DunxandMinecraft
    Offline

    DunxandMinecraft Active Member

    Joined:
    Oct 26, 2014
    Posts:
    158
    Cool.
  3. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    -.- Why do you always comment one word? I was happy someone helped but its just you. :mad:
    Taha_The_Hacker and PEMapModder like this.
  4. DunxandMinecraft
    Offline

    DunxandMinecraft Active Member

    Joined:
    Oct 26, 2014
    Posts:
    158
    Cool Cool

    lol. Sorry

    Do you need any help?
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Anyway, it should be onCommand not onCmd.
  6. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    Huh?
  7. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    Oh ok, thanks. :D
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Likes :p
  9. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    Wait now I'm getting a new error: Declaration of HealthManager\Main::eek:nCommand() must be compatible with pocketmine\command\CommandExecutor::eek:nCommand(pocketmine\command\CommandSender $sender, pocketmine\command\Command $command, $label, array $args)
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Import pocketmine\command\CommandSender
  11. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,706
    Plugins:
    22
    Minecraft User:
    Falkirknh
    Also, the break statements should be outside the if statements, you will get undefined behaviour if you don't break.
    Andrey Nazarchuk and Artide like this.
  12. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    It keeps saying pocketmine\command\CommandExecutor should be complatible with onCommand I don't understand that, help?
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Full message?
    BTW, it is really impolite not to like posts that helped you :D
  14. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    I gave like.:)

    Error: Declaration of HealthManager\Main::eek:nCommand() must be compatible with pocketmine\command\CommandExecutor::eek:nCommand(pocketmine\command\CommandSender $sender, pocketmine\command\Command $command, $label, array $args)
    File: /HealthManager/src/HealthManager/Main
    Line: 15
    Type: E_COMPILE_ERROR

    THIS CRASH WAS CAUSED BY A PLUGIN

    Code:
    [6] use pocketmine\Server;
    [7] use pocketmine\event\Listener;
    [8] use pocketmine\command\Command;
    [9] use pocketmine\plugin\PluginBase;
    [10] use pocketmine\command\CommandSender;
    [11] use pocketmine\command\CommandExecutor;
    [12] use pocketmine\utils\TextFormat as TXT;
    [13] use pocketmine\event\player\PlayerJoinEvent;
    [14]
    [15] class Main extends PluginBase implements Listener{
    [16]
    [17] public function onEnable(){
    [18]
    [19] $log = $this->getLogger();
    [20]
    [21] $log->info("Plugin successfully loaded!");
    [22]
    [23]
    [24] }
    [25]
  15. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    And full code?
    Andrey Nazarchuk likes this.
  16. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Andrey Nazarchuk and Artide like this.
  18. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    Ahhh, thank you very much. I didnt know command function had a format. New php thing learned. xD
  19. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Not PHP. It is just that your declaration has to be the same as its parent class(es), and in this case, the CommandExecutor interface.
    Andrey Nazarchuk and Artide like this.
  20. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    Thanks again.

Share This Page

Advertisement