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

isOp()?

Comments in 'Plugin Development' started by Legoboy0215, May 15, 2015.

  1. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
  2. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    How can I use that? Can I show like when the isOp() returns true, the server tells the $sender "You are op". And Vice-Versa...
  3. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    PHP:
    // Check If the player is OP:
    if($sender->isOp()){
    }
    // Check if the player is not OP:
    if(!$sender->isOp()){
    }
    //You could use:
    if($sender->isOp()){
       
    $sender->sendMessage("OP: True");
       return 
    true;
    } else{
       
    $sender->sendMessage("OP: False");
       return 
    true;
    }
    // There's a way with one line only but idk it rn
    HotFireyDeath likes this.
  4. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    I would use
    PHP:
    public function isOp(Player $player){
            return 
    $player->isOp;
          }
    Then:
    PHP:
    $sender->sendMessage($this->isOP($player));
  5. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    So, CraftYourBukkit, you mean just use $this->isOp($player));?
    This ia better then the first post then...
  6. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    And, an off-topic question. Why is the return needed? Can we change the return true to return false?
  7. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    First use
    PHP:
    public function isOp(Player $player){
            return 
    $player->isOp// return returns true(if the player is op) or false(if the player is not op)
          
    }
    The use in the command
    PHP:
    $sender->sendMessage("OP: " $this->isOp($player));
    // $this->isOP($player) returns true or false
    So there you cannot change the return. The return true; in a command just means that everything worked. If you would change it to false or don't write it, the Server will think it didn't work correctly and send the player the message: "Usage: /command"
    Legoboy0215 likes this.
  8. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    What does it use? I thought there is a use pocketmine\xxxx\xxxx
  9. PixelGuy75
    Offline

    PixelGuy75 Notable Member Plugin Developer

    Joined:
    Feb 9, 2014
    Posts:
    316
    Plugins:
    2
    Minecraft User:
    PixelGuy75
    use pocketmine\Player
    RekkuzaRage likes this.
  10. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    Code:
    [CRITICAL] Unhandled exception executing command 'isop' in isop: Undefined variable: player
    [NOTICE] UndefinedVariableException: "Undefined variable: player" (E_NOTICE) in "/isoponot/src/legoboy/isopornot/main" at line 32
    
    What error is this?
  11. RekkuzaRage
    Offline

    RekkuzaRage Active Member

    Joined:
    Apr 15, 2014
    Posts:
    252
    Minecraft User:
    RekkuzaRage
    You didn't define the variable player.
  12. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    can I say something like:
    Code:
    $player = $sender
    ?
  13. hoyinm14mc
    Offline

    hoyinm14mc Notable Member Plugin Developer

    Joined:
    Jun 4, 2014
    Posts:
    502
    Plugins:
    9
    Minecraft User:
    hoyinm14mc
    One line:
    PHP:
    $player->sendMessage("You ".($player->isOp() ? "are" "are not")." op!"));
    Legoboy0215 likes this.
  14. hoyinm14mc
    Offline

    hoyinm14mc Notable Member Plugin Developer

    Joined:
    Jun 4, 2014
    Posts:
    502
    Plugins:
    9
    Minecraft User:
    hoyinm14mc
    No need to define $player, change all $player to $sender.
    ($sender must be the one you defined at onCommand(CommandSender))
    RekkuzaRage likes this.
  15. hoyinm14mc
    Offline

    hoyinm14mc Notable Member Plugin Developer

    Joined:
    Jun 4, 2014
    Posts:
    502
    Plugins:
    9
    Minecraft User:
    hoyinm14mc
    isOp() is a function(method), not a variable!
    PHP:
    //It should be
    return $player->isOp();
    RekkuzaRage likes this.
  16. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    So, can I just use the line you gave me? I mean by the one line one..
  17. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    After the one line code, do I need to return $player->isOp();?
  18. RekkuzaRage
    Offline

    RekkuzaRage Active Member

    Joined:
    Apr 15, 2014
    Posts:
    252
    Minecraft User:
    RekkuzaRage
    What does the operator "?" do?
  19. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    This worked great! BTW, you should remove the ")" at the end.
  20. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    For more than 95% of the cases, you should just use hasPermission() and not use isOp().

Share This Page

Advertisement