1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

How can I show the op player ?

Discussion in 'General discussion' started by MusicNOvas, May 16, 2019.

  1. MusicNOvas

    MusicNOvas Spider Jockey

    Messages:
    43
    PHP:
    switch($cmd->getName()){
                
                case 
    "tests":
                    if(
    $sender instanceof Player){
                        
    $sender->sendMessage($sender->getName()/*name of the op player*/ "message");
                        return 
    true;
                    }
            }
     
  2. radondev

    radondev Silverfish

    Messages:
    21
    GitHub:
    radondev
    Simply use:
    PHP:
    $sender->isOp();
    This function can be found in the Player.php.
     
    Last edited: May 18, 2019
    mm899 likes this.
  3. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    PHP:
    $ops implode(", "array_filter($this->getServer()->getOnlinePlayers(), function ($value) {
            return 
    $value->isOp();
        }, 
    ARRAY_FILTER_USE_BOTH));
    You can use array_filter and implode functions
     
    mm899 likes this.
  4. MusicNOvas

    MusicNOvas Spider Jockey

    Messages:
    43
    Sorry I don't know use this i'm not understand all :'(
    sorry, sincerly
     
  5. mm899

    mm899 Spider Jockey

    Messages:
    32
    What exactly is it that you are trying to accomplish? Are you trying to make it that only an OP can run the command?
     
  6. MusicNOvas

    MusicNOvas Spider Jockey

    Messages:
    43
    I want when the player makes / tests the name of the players ops are displayed as a message
     
  7. mm899

    mm899 Spider Jockey

    Messages:
    32
    I see, one sec
     
  8. MusicNOvas

    MusicNOvas Spider Jockey

    Messages:
    43
    Okay
     
  9. mm899

    mm899 Spider Jockey

    Messages:
    32
    PHP:
    switch($cmd->getName()){

                case 
    "tests":
                    if(
    $sender instanceof Player){
                        
    $onlinePlayers $this->getServer()->getOnlinePlayers();
                        
    $serverOps = array();
                        foreach (
    $onlinePlayers as $player)
                        {
                            if(
    $player->isOp())
                            {
                                
    array_push($serverOps$player->getName());
                            }
                        }
                        
    $sender->sendMessage("Online OPS: " implode(" ",$serverOps) . "MESSAGE");
                        return 
    true;
                    }
            }
        }
    Im still taking more OOP php courses, so if this code sucks...im trying :p
     
    MusicNOvas likes this.
  10. MusicNOvas

    MusicNOvas Spider Jockey

    Messages:
    43
    I trying that, thanks for help me
    I'm french, sorry if my English isn't good
     
  11. mm899

    mm899 Spider Jockey

    Messages:
    32
    I hope it works lol
     
  12. MusicNOvas

    MusicNOvas Spider Jockey

    Messages:
    43
    If i want to see the players ops connected how can i do this ?
     
  13. mm899

    mm899 Spider Jockey

    Messages:
    32
    The code I have given should display the online OP players
     
    MusicNOvas likes this.
  14. MusicNOvas

    MusicNOvas Spider Jockey

    Messages:
    43
    HOOO lol sorry i'm not test yet
     
  15. mm899

    mm899 Spider Jockey

    Messages:
    32
    ok
     
  16. MusicNOvas

    MusicNOvas Spider Jockey

    Messages:
    43
    PHP:
    switch($cmd->getName()){
               
                case 
    "test2":
                    if(
    $sender instanceof Player){
                        
    $sender->sendMessage("§a StarLitBinkie is connected");
                        
    $sender->sendMessage("§4 StarLitBinkie is disconnected");
                        return 
    true;
                    }
            }
    Thanks it's work. How can I display name of player who is connected in green and the name of the same player but he is disconnected in red ?
     
  17. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    Wrong section
     
    mm899 likes this.
  18. mm899

    mm899 Spider Jockey

    Messages:
    32
    If you want to do this for offline OPs too, I believe that you will have to store the names off each operator somewhere, then check if the player is online
     
    MusicNOvas likes this.
  19. MusicNOvas

    MusicNOvas Spider Jockey

    Messages:
    43
    t does not help me sorry
     
  20. MusicNOvas

    MusicNOvas Spider Jockey

    Messages:
    43
    Okay thanks.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.