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

plugin code not working, need help

Comments in 'Plugin Development' started by SSLukeY, Aug 12, 2016.

  1. SSLukeY
    Offline

    SSLukeY New Member

    Joined:
    Aug 10, 2016
    Posts:
    2
    Minecraft User:
    SSLukeY
    I'm working on a simple plugin which just tells the user if they are op or not when they type the command, but it is not working as when I typed the command nothing happened, can anyone help me please

    this is my code:

    <?php
    namespace SSLukeY\showRank;
    use pocketmine\plugin\PluginBase;
    use pocketmine\Player;
    use pocketmine\command\Command;
    use pocketmine\command\CommandSender;

    class main extends PluginBase{
    public function onCommand(CommandSender $sender, Command $command, $label, array $args) {
    if (strtolower($command->getName("myrank"))) {
    if ($sender instanceof Player) {
    if ($sender-isOP()) {
    $sender->sendMessage("yes");
    }
    if ($sender->isOP() == false) {
    $sender->sendMessage("no");
    }
    }
    }
    }
    }

    this is my yml file:
    name: showRank
    version: 1.0.0
    main: SSLukeY\showRank\main
    api: 1.0.0
    commands:
    myrank:
    description: show if you are a op or not
  2. JonsMC
    Offline

    JonsMC Active Member

    Joined:
    Jul 26, 2016
    Posts:
    107
    Minecraft User:
    JonsMC
    Try to read your code again next time, it's must be:
    1. $sender->isOp() not $sender-isOP()
    PHP:
    if($sender instanceof Player) {
      if(
    $sender->isOp()) {
         
    $sender->sendMessage("Yes");
        }
    }
    2. Try to use
    PHP:
    if(($command->getName()) == "myrank") {
    3. Use else
    PHP:
    if($sender->isOp()) {
           
    $sender->sendMessage("Yes");
     } else {
         
    $sender->sendMessage("No");
    }
    3. Remeber, plugin.yml is YML, so don't forget to space
  3. JonsMC
    Offline

    JonsMC Active Member

    Joined:
    Jul 26, 2016
    Posts:
    107
    Minecraft User:
    JonsMC
    Also, use api 2.0.0 :)
  4. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    PHP:
     If (strtolower ($command->getName ()) == "myrank"){ 
    @JonsMC $sender->isOp () and $sender->isOP() they two are working too
  5. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Use
    PHP:
    if($command->getName() === "myrank")
    Also... This would work too :D
    PHP:
    $sender->sendMessage($sender->isOp() ? "Yes" "No");
    You also forgot the ">" at the first if statement.
    Primus likes this.
  6. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    PluginBase :: onCommand requires bool value to be returned. If it's a false, then usage message will be shown else not.

    Next time attach an error string.
    DC4CODE likes this.

Share This Page

Advertisement